Skip to content

Commit cc3f362

Browse files
committed
fix: account tests
1 parent 998a2e3 commit cc3f362

File tree

6 files changed

+34
-48
lines changed

6 files changed

+34
-48
lines changed

__tests__/account.test.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ describe('deploy and test Wallet', () => {
2525
contract: compiledErc20,
2626
});
2727

28-
erc20Address = erc20Response.address!;
28+
erc20Address = erc20Response.contract_address!;
2929
erc20 = new Contract(compiledErc20.abi, erc20Address, provider);
30-
expect(erc20Response.code).toBe('TRANSACTION_RECEIVED');
3130

3231
await provider.waitForTransaction(erc20Response.transaction_hash);
3332

@@ -37,8 +36,6 @@ describe('deploy and test Wallet', () => {
3736
calldata: [account.address, '1000'],
3837
});
3938

40-
expect(mintResponse.code).toBe('TRANSACTION_RECEIVED');
41-
4239
await provider.waitForTransaction(mintResponse.transaction_hash);
4340

4441
const x = await erc20.balance_of(account.address);
@@ -48,20 +45,18 @@ describe('deploy and test Wallet', () => {
4845
const dappResponse = await provider.deployContract({
4946
contract: compiledTestDapp,
5047
});
51-
dapp = new Contract(compiledTestDapp.abi, dappResponse.address!, provider);
52-
expect(dappResponse.code).toBe('TRANSACTION_RECEIVED');
48+
dapp = new Contract(compiledTestDapp.abi, dappResponse.contract_address!, provider);
5349

5450
await provider.waitForTransaction(dappResponse.transaction_hash);
5551
});
5652

5753
test('estimate fee', async () => {
58-
const { amount, unit } = await account.estimateFee({
54+
const { overall_fee } = await account.estimateFee({
5955
contractAddress: erc20Address,
6056
entrypoint: 'transfer',
6157
calldata: [erc20.address, '10'],
6258
});
63-
expect(isBN(amount)).toBe(true);
64-
expect(typeof unit).toBe('string');
59+
expect(isBN(overall_fee)).toBe(true);
6560
});
6661

6762
test('read balance of wallet', async () => {
@@ -71,13 +66,12 @@ describe('deploy and test Wallet', () => {
7166
});
7267

7368
test('execute by wallet owner', async () => {
74-
const { code, transaction_hash } = await account.execute({
69+
const { transaction_hash } = await account.execute({
7570
contractAddress: erc20Address,
7671
entrypoint: 'transfer',
7772
calldata: [erc20.address, '10'],
7873
});
7974

80-
expect(code).toBe('TRANSACTION_RECEIVED');
8175
await provider.waitForTransaction(transaction_hash);
8276
});
8377

@@ -93,7 +87,7 @@ describe('deploy and test Wallet', () => {
9387
entrypoint: 'get_nonce',
9488
});
9589
const nonce = toBN(result[0]).toNumber();
96-
const { code, transaction_hash } = await account.execute(
90+
const { transaction_hash } = await account.execute(
9791
{
9892
contractAddress: erc20Address,
9993
entrypoint: 'transfer',
@@ -103,12 +97,11 @@ describe('deploy and test Wallet', () => {
10397
{ nonce }
10498
);
10599

106-
expect(code).toBe('TRANSACTION_RECEIVED');
107100
await provider.waitForTransaction(transaction_hash);
108101
});
109102

110103
test('execute multiple transactions', async () => {
111-
const { code, transaction_hash } = await account.execute([
104+
const { transaction_hash } = await account.execute([
112105
{
113106
contractAddress: dapp.address,
114107
entrypoint: 'set_number',
@@ -121,7 +114,6 @@ describe('deploy and test Wallet', () => {
121114
},
122115
]);
123116

124-
expect(code).toBe('TRANSACTION_RECEIVED');
125117
await provider.waitForTransaction(transaction_hash);
126118

127119
const response = await dapp.get_number(account.address);
@@ -154,7 +146,7 @@ describe('deploy and test Wallet', () => {
154146

155147
await provider.waitForTransaction(accountResponse.transaction_hash);
156148

157-
newAccount = new Account(provider, accountResponse.address!, starkKeyPair);
149+
newAccount = new Account(provider, accountResponse.contract_address!, starkKeyPair);
158150
});
159151

160152
test('read nonce', async () => {
@@ -178,8 +170,6 @@ describe('deploy and test Wallet', () => {
178170
calldata: [wallet, '1000'],
179171
});
180172

181-
expect(mintResponse.code).toBe('TRANSACTION_RECEIVED');
182-
183173
await provider.waitForTransaction(mintResponse.transaction_hash);
184174
});
185175

@@ -191,8 +181,7 @@ describe('deploy and test Wallet', () => {
191181

192182
test('estimate gas fee for `mint`', async () => {
193183
const res = await erc20.estimateFee.mint(wallet, '10');
194-
expect(res).toHaveProperty('amount');
195-
expect(res).toHaveProperty('unit');
184+
expect(res).toHaveProperty('overall_fee');
196185
});
197186
});
198187
});

src/account/default.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ZERO } from '../constants';
2-
import { ProviderInterface, ProviderOptions } from '../provider';
2+
import { ProviderOptions } from '../provider';
33
import { Provider } from '../provider/default';
44
import { Signer, SignerInterface } from '../signer';
55
import {
@@ -23,7 +23,7 @@ export class Account extends Provider implements AccountInterface {
2323
public signer: SignerInterface;
2424

2525
constructor(
26-
providerOrOptions: ProviderOptions | ProviderInterface,
26+
providerOrOptions: ProviderOptions | Provider,
2727
public address: string,
2828
keyPairOrSigner: KeyPair | SignerInterface
2929
) {
@@ -61,9 +61,9 @@ export class Account extends Provider implements AccountInterface {
6161

6262
const calldata = fromCallsToExecuteCalldataWithNonce(transactions, nonce);
6363
const fetchedEstimate = await super.getEstimateFee(
64-
{ contractAddress: this.address, entrypoint: '__execute__', calldata },
64+
{ contractAddress: this.address, entrypoint: '__execute__', calldata, signature },
6565
blockIdentifier,
66-
signature
66+
{ version }
6767
);
6868

6969
const suggestedMaxFee = estimatedFeeToMaxFee(fetchedEstimate.overall_fee);

src/provider/default.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
Invocation,
1414
InvocationsDetails,
1515
InvokeFunctionResponse,
16-
Signature,
1716
} from '../types';
1817
import { BigNumberish } from '../utils/number';
1918
import { GatewayProvider, GatewayProviderOptions } from './gateway';
@@ -29,8 +28,8 @@ export interface ProviderOptions {
2928
export class Provider implements ProviderInterface {
3029
private provider!: ProviderInterface;
3130

32-
constructor(providerOrOptions?: ProviderOptions | ProviderInterface) {
33-
if (providerOrOptions instanceof ProviderInterface) {
31+
constructor(providerOrOptions?: ProviderOptions | Provider) {
32+
if (providerOrOptions instanceof Provider) {
3433
this.provider = providerOrOptions;
3534
} else if (providerOrOptions && providerOrOptions.rpc) {
3635
this.provider = new RPCProvider(providerOrOptions.rpc);
@@ -55,11 +54,11 @@ export class Provider implements ProviderInterface {
5554
}
5655

5756
public async getEstimateFee(
58-
request: Call,
57+
invocation: Invocation,
5958
blockIdentifier: BlockIdentifier,
60-
signature?: Signature
59+
invocationDetails?: InvocationsDetails
6160
): Promise<EstimateFeeResponse> {
62-
return this.provider.getEstimateFee(request, blockIdentifier, signature);
61+
return this.provider.getEstimateFee(invocation, blockIdentifier, invocationDetails);
6362
}
6463

6564
public async getStorageAt(

src/provider/gateway.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
Invocation,
2121
InvocationsDetails,
2222
InvokeFunctionResponse,
23-
Signature,
2423
} from '../types';
2524
import { getSelectorFromName } from '../utils/hash';
2625
import { parse, parseAlwaysAsBig, stringify } from '../utils/json';
@@ -268,8 +267,8 @@ export class GatewayProvider implements ProviderInterface {
268267
entry_point_selector: getSelectorFromName(functionInvocation.entrypoint),
269268
calldata: bigNumberishArrayToDecimalStringArray(functionInvocation.calldata ?? []),
270269
signature: bigNumberishArrayToDecimalStringArray(functionInvocation.signature ?? []),
271-
max_fee: details.maxFee,
272-
version: details.version,
270+
max_fee: toHex(toBN(details.maxFee || 0)),
271+
version: toHex(toBN(details.version || 0)),
273272
}).then(this.responseParser.parseInvokeFunctionResponse);
274273
}
275274

@@ -303,18 +302,19 @@ export class GatewayProvider implements ProviderInterface {
303302
}
304303

305304
public async getEstimateFee(
306-
call: Call,
305+
invocation: Invocation,
307306
blockIdentifier: BlockIdentifier = 'pending',
308-
signature?: Signature
307+
invocationDetails: InvocationsDetails = {}
309308
): Promise<EstimateFeeResponse> {
310309
return this.fetchEndpoint(
311310
'estimate_fee',
312311
{ blockIdentifier },
313312
{
314-
contract_address: call.contractAddress,
315-
entry_point_selector: getSelectorFromName(call.entrypoint),
316-
calldata: bigNumberishArrayToDecimalStringArray(call.calldata ?? []),
317-
signature: bigNumberishArrayToDecimalStringArray(signature || []),
313+
contract_address: invocation.contractAddress,
314+
entry_point_selector: getSelectorFromName(invocation.entrypoint),
315+
calldata: invocation.calldata ?? [],
316+
signature: bigNumberishArrayToDecimalStringArray(invocation.signature || []),
317+
version: toHex(toBN(invocationDetails?.version || 0)),
318318
}
319319
).then(this.responseParser.parseFeeEstimateResponse);
320320
}

src/provider/interface.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import type {
1414
Invocation,
1515
InvocationsDetails,
1616
InvokeFunctionResponse,
17-
Signature,
1817
} from '../types';
1918
import type { BigNumberish } from '../utils/number';
2019
import { BlockIdentifier } from './utils';
@@ -128,9 +127,9 @@ export abstract class ProviderInterface {
128127
): Promise<InvokeFunctionResponse>;
129128

130129
public abstract getEstimateFee(
131-
request: Call,
130+
request: Invocation,
132131
blockIdentifier: BlockIdentifier,
133-
signature?: Signature
132+
invocationDetails?: InvocationsDetails
134133
): Promise<EstimateFeeResponse>;
135134

136135
public abstract waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;

src/provider/rpc.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
InvocationsDetails,
1717
InvokeFunctionResponse,
1818
RPC,
19-
Signature,
2019
} from '../types';
2120
import { getSelectorFromName } from '../utils/hash';
2221
import { stringify } from '../utils/json';
@@ -130,15 +129,15 @@ export class RPCProvider implements ProviderInterface {
130129
}
131130

132131
public async getEstimateFee(
133-
call: Call,
132+
invocation: Invocation,
134133
blockIdentifier: BlockIdentifier = 'pending',
135-
_signature: Signature = []
134+
_invocationDetails: InvocationsDetails = {}
136135
): Promise<EstimateFeeResponse> {
137136
return this.fetchEndpoint('starknet_estimateFee', [
138137
{
139-
contract_address: call.contractAddress,
140-
entry_point_selector: getSelectorFromName(call.entrypoint),
141-
calldata: parseCalldata(call.calldata),
138+
contract_address: invocation.contractAddress,
139+
entry_point_selector: getSelectorFromName(invocation.entrypoint),
140+
calldata: parseCalldata(invocation.calldata),
142141
},
143142
blockIdentifier,
144143
]).then(this.responseParser.parseFeeEstimateResponse);

0 commit comments

Comments
 (0)