Skip to content

Commit 1476461

Browse files
committed
fix: call contract latest block
1 parent a9ea023 commit 1476461

File tree

4 files changed

+5
-65
lines changed

4 files changed

+5
-65
lines changed

__tests__/rpcProvider.test.ts

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import { isBN } from 'bn.js';
2-
3-
import { Account, Contract, RpcProvider } from '../src';
4-
import { toBN } from '../src/utils/number';
5-
import { compiledErc20, describeIfRpc, getTestAccount, getTestProvider } from './fixtures';
1+
import { RpcProvider } from '../src';
2+
import { describeIfRpc, getTestProvider } from './fixtures';
63

74
describeIfRpc('RPCProvider', () => {
85
let provider: RpcProvider;
@@ -17,61 +14,4 @@ describeIfRpc('RPCProvider', () => {
1714
expect(chainId).toBe('0x534e5f474f45524c49');
1815
});
1916
});
20-
21-
describe('Account', () => {
22-
let account: Account;
23-
let erc20Address: string;
24-
let erc20: Contract;
25-
26-
beforeAll(async () => {
27-
account = getTestAccount(provider);
28-
expect(account).toBeInstanceOf(Account);
29-
30-
const erc20Response = await provider.deployContract({
31-
contract: compiledErc20,
32-
});
33-
34-
erc20Address = erc20Response.contract_address;
35-
erc20 = new Contract(compiledErc20.abi, erc20Address, provider);
36-
37-
await provider.waitForTransaction(erc20Response.transaction_hash);
38-
erc20 = new Contract(compiledErc20.abi, erc20Address, provider);
39-
40-
const mintResponse = await account.execute({
41-
contractAddress: erc20Address,
42-
entrypoint: 'mint',
43-
calldata: [account.address, '1000'],
44-
});
45-
46-
await provider.waitForTransaction(mintResponse.transaction_hash);
47-
});
48-
49-
test('estimate fee', async () => {
50-
const { overall_fee, gas_consumed, gas_price } = await account.estimateFee({
51-
contractAddress: erc20Address,
52-
entrypoint: 'transfer',
53-
calldata: [erc20.address, '10'],
54-
});
55-
56-
expect(isBN(overall_fee)).toBe(true);
57-
expect(isBN(gas_consumed)).toBe(true);
58-
expect(isBN(gas_price)).toBe(true);
59-
});
60-
61-
test('execute by wallet owner', async () => {
62-
const { res: before } = await erc20.balance_of(account.address);
63-
64-
const { transaction_hash } = await account.execute({
65-
contractAddress: erc20Address,
66-
entrypoint: 'transfer',
67-
calldata: [erc20.address, '10'],
68-
});
69-
70-
await account.waitForTransaction(transaction_hash);
71-
72-
const { res: after } = await erc20.balance_of(account.address);
73-
74-
expect(toBN(before).sub(toBN(after)).toString(10)).toBe('10');
75-
});
76-
});
7717
});

src/provider/default.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class Provider implements ProviderInterface {
8181

8282
public async callContract(
8383
request: Call,
84-
blockIdentifier: BlockIdentifier = 'pending'
84+
blockIdentifier: BlockIdentifier = 'latest'
8585
): Promise<CallContractResponse> {
8686
return this.provider.callContract(request, blockIdentifier);
8787
}

src/provider/rpc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export class RpcProvider implements ProviderInterface {
195195

196196
public async callContract(
197197
call: Call,
198-
blockIdentifier: BlockIdentifier = 'pending'
198+
blockIdentifier: BlockIdentifier = 'latest'
199199
): Promise<CallContractResponse> {
200200
const result = await this.fetchEndpoint('starknet_call', [
201201
{

src/provider/sequencer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export class SequencerProvider implements ProviderInterface {
203203

204204
public async callContract(
205205
{ contractAddress, entrypoint: entryPointSelector, calldata = [] }: Call,
206-
blockIdentifier: BlockIdentifier = 'pending'
206+
blockIdentifier: BlockIdentifier = 'latest'
207207
): Promise<CallContractResponse> {
208208
return this.fetchEndpoint(
209209
'call_contract',

0 commit comments

Comments
 (0)