Skip to content

Commit 949de76

Browse files
committed
fix: resolve versions utils and test
1 parent fd08f22 commit 949de76

File tree

12 files changed

+267
-254
lines changed

12 files changed

+267
-254
lines changed

__tests__/config/helpers/strategyResolver.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ class StrategyResolver {
7272
process.env.TX_VERSION = process.env.TX_VERSION ?? DEFAULT_GLOBAL_CONFIG.transactionVersion;
7373
}
7474

75-
async getSpecVersion() {
75+
async getNodeSpecVersion() {
7676
const tempProv = new RpcProvider({
7777
nodeUrl: process.env.TEST_RPC_URL,
7878
});
7979

8080
process.env.RPC_SPEC_VERSION = await tempProv.getSpecVersion();
81-
process.env.RPC_FULL_SPEC_VERSION = await tempProv.getSpecificationVersion();
81+
console.log('Detected Spec Version:', process.env.RPC_SPEC_VERSION);
8282
}
8383

8484
async logConfigInfo() {
@@ -96,8 +96,7 @@ class StrategyResolver {
9696
IS_DEVNET: process.env.IS_DEVNET,
9797
IS_RPC: process.env.IS_RPC,
9898
IS_TESTNET: process.env.IS_TESTNET,
99-
'Rpc node spec version': process.env.RPC_SPEC_VERSION,
100-
'Rpc node full spec v.': process.env.RPC_FULL_SPEC_VERSION,
99+
'Detected Spec Version': process.env.RPC_SPEC_VERSION,
101100
});
102101

103102
console.log('Global Test Environment is Ready');
@@ -148,7 +147,7 @@ class StrategyResolver {
148147
if (!this.hasAllAccountEnvs) console.error('Test Setup Environment is NOT Ready');
149148

150149
this.defineTestTransactionVersion();
151-
await this.getSpecVersion();
150+
await this.getNodeSpecVersion();
152151

153152
this.logConfigInfo();
154153
}

__tests__/defaultProvider.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import {
33
BlockNumber,
44
CallData,
55
GetBlockResponse,
6+
isPendingStateUpdate,
67
LibraryError,
78
Provider,
8-
provider,
99
ProviderInterface,
1010
stark,
1111
} from '../src';
@@ -20,8 +20,6 @@ import {
2020
} from './config/fixtures';
2121
import { initializeMatcher } from './config/schema';
2222

23-
const { isPendingStateUpdate } = provider;
24-
2523
describe('defaultProvider', () => {
2624
let testProvider: ProviderInterface;
2725
let account: Account;

__tests__/rpcProvider.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ import {
3030
cairo,
3131
stark,
3232
waitForTransactionOptions,
33+
isVersion,
3334
} from '../src';
3435
import { StarknetChainId } from '../src/global/constants';
3536
import { felt, uint256 } from '../src/utils/calldata/cairo';
3637
import { toBigInt, toHexString } from '../src/utils/num';
37-
import { isVersion } from '../src/utils/provider';
3838
import { isBoolean } from '../src/utils/typed';
3939
import { RpcProvider as BaseRpcProvider } from '../src/provider/rpc';
4040
import { RpcProvider as ExtendedRpcProvider } from '../src/provider/extensions/default';
@@ -75,7 +75,7 @@ describeIfRpc('RPCProvider', () => {
7575
const rawResult = await channel.fetch('starknet_specVersion');
7676
const j = await rawResult.json();
7777
expect(channel.readSpecVersion()).toBeDefined();
78-
expect(isVersion(j.result, await channel.getSpecVersion())).toBeTruthy();
78+
expect(isVersion(j.result, await channel.setupSpecVersion())).toBeTruthy();
7979
});
8080

8181
test('baseFetch override', async () => {

__tests__/utils/provider.test.ts renamed to __tests__/utils/resolve.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { SupportedRpcVersion } from '../../src/global/constants';
2-
import { isVersion, toAnyPatchVersion, isSupportedSpecVersion } from '../../src/utils/provider';
1+
import { isVersion, toAnyPatchVersion, isSupportedSpecVersion, constants } from '../../src';
32

43
describe('isVersion', () => {
54
it('matches exact versions', () => {
@@ -101,7 +100,7 @@ describe('isSupportedSpecVersion', () => {
101100

102101
describe('isSupportedSpecVersion', () => {
103102
it('returns true for exact supported version', () => {
104-
expect(isSupportedSpecVersion(SupportedRpcVersion.v0_7_1)).toBe(true);
103+
expect(isSupportedSpecVersion(constants.SupportedRpcVersion.v0_7_1)).toBe(true);
105104
});
106105

107106
it('returns false for unsupported version', () => {

src/account/default.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { config } from '../global/config';
12
import {
23
OutsideExecutionCallerAny,
34
SNIP9_V1_INTERFACE_ID,
@@ -6,7 +7,13 @@ import {
67
UDC,
78
ZERO,
89
} from '../global/constants';
10+
import { logger } from '../global/logger';
911
import { LibraryError, Provider, ProviderInterface } from '../provider';
12+
import {
13+
ETransactionVersion,
14+
ETransactionVersion3,
15+
ResourceBounds,
16+
} from '../provider/types/spec.type';
1017
import { Signer, SignerInterface } from '../signer';
1118
import {
1219
AccountInvocations,
@@ -27,7 +34,6 @@ import {
2734
DeployContractUDCResponse,
2835
DeployTransactionReceiptResponse,
2936
EstimateFee,
30-
UniversalSuggestedFee,
3137
EstimateFeeAction,
3238
EstimateFeeBulk,
3339
Invocation,
@@ -44,12 +50,8 @@ import {
4450
TypedData,
4551
UniversalDeployerContractPayload,
4652
UniversalDetails,
53+
UniversalSuggestedFee,
4754
} from '../types';
48-
import {
49-
ETransactionVersion,
50-
ETransactionVersion3,
51-
ResourceBounds,
52-
} from '../provider/types/spec.type';
5355
import {
5456
OutsideExecutionVersion,
5557
type OutsideExecution,
@@ -60,7 +62,6 @@ import { CallData } from '../utils/calldata';
6062
import { extractContractHashes, isSierra } from '../utils/contract';
6163
import { parseUDCEvent } from '../utils/events';
6264
import { calculateContractAddressFromHash } from '../utils/hash';
63-
import { isUndefined, isString } from '../utils/typed';
6465
import { isHex, toBigInt, toCairoBool, toHex } from '../utils/num';
6566
import {
6667
buildExecuteFromOutsideCall,
@@ -79,10 +80,9 @@ import {
7980
ZEROFee,
8081
} from '../utils/stark';
8182
import { buildUDCCall, getExecuteCalldata } from '../utils/transaction';
83+
import { isString, isUndefined } from '../utils/typed';
8284
import { getMessageHash } from '../utils/typedData';
8385
import { AccountInterface } from './interface';
84-
import { config } from '../global/config';
85-
import { logger } from '../global/logger';
8686

8787
export class Account extends Provider implements AccountInterface {
8888
public signer: SignerInterface;
@@ -188,7 +188,7 @@ export class Account extends Provider implements AccountInterface {
188188
const chainId = await this.getChainId();
189189

190190
const signerDetails: InvocationsSignerDetails = {
191-
...v3Details(details, await this.channel.getSpecVersion()),
191+
...v3Details(details, await this.channel.setupSpecVersion()),
192192
walletAddress: this.address,
193193
nonce,
194194
maxFee: ZERO,
@@ -201,7 +201,7 @@ export class Account extends Provider implements AccountInterface {
201201
const invocation = await this.buildInvocation(transactions, signerDetails);
202202
return super.getInvokeEstimateFee(
203203
{ ...invocation },
204-
{ ...v3Details(details, await this.channel.getSpecVersion()), version, nonce },
204+
{ ...v3Details(details, await this.channel.setupSpecVersion()), version, nonce },
205205
blockIdentifier,
206206
details.skipValidate
207207
);
@@ -227,7 +227,7 @@ export class Account extends Provider implements AccountInterface {
227227
const chainId = await this.getChainId();
228228

229229
const declareContractTransaction = await this.buildDeclarePayload(payload, {
230-
...v3Details(details, await this.channel.getSpecVersion()),
230+
...v3Details(details, await this.channel.setupSpecVersion()),
231231
nonce,
232232
chainId,
233233
version,
@@ -239,7 +239,7 @@ export class Account extends Provider implements AccountInterface {
239239

240240
return super.getDeclareEstimateFee(
241241
declareContractTransaction,
242-
{ ...v3Details(details, await this.channel.getSpecVersion()), version, nonce },
242+
{ ...v3Details(details, await this.channel.setupSpecVersion()), version, nonce },
243243
blockIdentifier,
244244
details.skipValidate
245245
);
@@ -265,7 +265,7 @@ export class Account extends Provider implements AccountInterface {
265265
const payload = await this.buildAccountDeployPayload(
266266
{ classHash, addressSalt, constructorCalldata, contractAddress },
267267
{
268-
...v3Details(details, await this.channel.getSpecVersion()),
268+
...v3Details(details, await this.channel.setupSpecVersion()),
269269
nonce,
270270
chainId,
271271
version,
@@ -278,7 +278,7 @@ export class Account extends Provider implements AccountInterface {
278278

279279
return super.getDeployAccountEstimateFee(
280280
{ ...payload },
281-
{ ...v3Details(details, await this.channel.getSpecVersion()), version, nonce },
281+
{ ...v3Details(details, await this.channel.setupSpecVersion()), version, nonce },
282282
blockIdentifier,
283283
details.skipValidate
284284
);
@@ -299,7 +299,7 @@ export class Account extends Provider implements AccountInterface {
299299
if (!invocations.length) throw TypeError('Invocations should be non-empty array');
300300
const { nonce, blockIdentifier, version, skipValidate } = details;
301301
const accountInvocations = await this.accountInvocationsFactory(invocations, {
302-
...v3Details(details, await this.channel.getSpecVersion()),
302+
...v3Details(details, await this.channel.setupSpecVersion()),
303303
versions: [
304304
ETransactionVersion.F1, // non-sierra
305305
toTransactionVersion(
@@ -325,7 +325,7 @@ export class Account extends Provider implements AccountInterface {
325325
if (!invocations.length) throw TypeError('Invocations should be non-empty array');
326326
const { nonce, blockIdentifier, skipValidate = true, skipExecute, version } = details;
327327
const accountInvocations = await this.accountInvocationsFactory(invocations, {
328-
...v3Details(details, await this.channel.getSpecVersion()),
328+
...v3Details(details, await this.channel.setupSpecVersion()),
329329
versions: [
330330
ETransactionVersion.V1, // non-sierra
331331
toTransactionVersion(
@@ -368,7 +368,7 @@ export class Account extends Provider implements AccountInterface {
368368
const chainId = await this.getChainId();
369369

370370
const signerDetails: InvocationsSignerDetails = {
371-
...v3Details(transactionsDetail, await this.channel.getSpecVersion()),
371+
...v3Details(transactionsDetail, await this.channel.setupSpecVersion()),
372372
resourceBounds: estimate.resourceBounds,
373373
walletAddress: this.address,
374374
nonce,
@@ -385,7 +385,7 @@ export class Account extends Provider implements AccountInterface {
385385
return this.invokeFunction(
386386
{ contractAddress: this.address, calldata, signature },
387387
{
388-
...v3Details(transactionsDetail, await this.channel.getSpecVersion()),
388+
...v3Details(transactionsDetail, await this.channel.setupSpecVersion()),
389389
resourceBounds: estimate.resourceBounds,
390390
nonce,
391391
maxFee: estimate.maxFee,
@@ -442,7 +442,7 @@ export class Account extends Provider implements AccountInterface {
442442
);
443443

444444
const declareDetails: InvocationsSignerDetails = {
445-
...v3Details(details, await this.channel.getSpecVersion()),
445+
...v3Details(details, await this.channel.setupSpecVersion()),
446446
resourceBounds: estimate.resourceBounds,
447447
maxFee: estimate.maxFee,
448448
nonce: toBigInt(nonce ?? (await this.getNonce())),
@@ -537,7 +537,7 @@ export class Account extends Provider implements AccountInterface {
537537
);
538538

539539
const signature = await this.signer.signDeployAccountTransaction({
540-
...v3Details(details, await this.channel.getSpecVersion()),
540+
...v3Details(details, await this.channel.setupSpecVersion()),
541541
classHash,
542542
constructorCalldata: compiledCalldata,
543543
contractAddress,
@@ -552,7 +552,7 @@ export class Account extends Provider implements AccountInterface {
552552
return this.deployAccountContract(
553553
{ classHash, addressSalt, constructorCalldata, signature },
554554
{
555-
...v3Details(details, await this.channel.getSpecVersion()),
555+
...v3Details(details, await this.channel.setupSpecVersion()),
556556
nonce,
557557
resourceBounds: estimate.resourceBounds,
558558
maxFee: estimate.maxFee,
@@ -741,7 +741,7 @@ export class Account extends Provider implements AccountInterface {
741741
let resourceBounds: ResourceBounds = estimateFeeToBounds(
742742
ZERO,
743743
undefined,
744-
await this.channel.getSpecVersion()
744+
await this.channel.setupSpecVersion()
745745
);
746746

747747
if (version === ETransactionVersion.V3) {
@@ -778,7 +778,7 @@ export class Account extends Provider implements AccountInterface {
778778
return this.estimateDeployFee(payload, details);
779779

780780
default:
781-
return ZEROFee(await this.channel.getSpecVersion());
781+
return ZEROFee(await this.channel.setupSpecVersion());
782782
}
783783
}
784784

@@ -790,7 +790,7 @@ export class Account extends Provider implements AccountInterface {
790790
const signature = !details.skipValidate ? await this.signer.signTransaction(call, details) : [];
791791

792792
return {
793-
...v3Details(details, await this.channel.getSpecVersion()),
793+
...v3Details(details, await this.channel.setupSpecVersion()),
794794
contractAddress: this.address,
795795
calldata,
796796
signature,
@@ -814,7 +814,7 @@ export class Account extends Provider implements AccountInterface {
814814
const signature = !details.skipValidate
815815
? await this.signer.signDeclareTransaction({
816816
...details,
817-
...v3Details(details, await this.channel.getSpecVersion()),
817+
...v3Details(details, await this.channel.setupSpecVersion()),
818818
classHash,
819819
compiledClassHash: compiledClassHash as string, // TODO: TS, cast because optional for v2 and required for v3, thrown if not present
820820
senderAddress: details.walletAddress,
@@ -846,7 +846,7 @@ export class Account extends Provider implements AccountInterface {
846846
const signature = !details.skipValidate
847847
? await this.signer.signDeployAccountTransaction({
848848
...details,
849-
...v3Details(details, await this.channel.getSpecVersion()),
849+
...v3Details(details, await this.channel.setupSpecVersion()),
850850
classHash,
851851
contractAddress,
852852
addressSalt,
@@ -855,7 +855,7 @@ export class Account extends Provider implements AccountInterface {
855855
: [];
856856

857857
return {
858-
...v3Details(details, await this.channel.getSpecVersion()),
858+
...v3Details(details, await this.channel.setupSpecVersion()),
859859
classHash,
860860
addressSalt,
861861
constructorCalldata: compiledCalldata,
@@ -910,7 +910,7 @@ export class Account extends Provider implements AccountInterface {
910910
([] as Invocations).concat(invocations).map(async (transaction, index: number) => {
911911
const txPayload: any = 'payload' in transaction ? transaction.payload : transaction;
912912
const signerDetails = {
913-
...v3Details(details, await this.channel.getSpecVersion()),
913+
...v3Details(details, await this.channel.setupSpecVersion()),
914914
walletAddress: this.address,
915915
nonce: toBigInt(Number(safeNonce) + index),
916916
maxFee: ZERO,

0 commit comments

Comments
 (0)