starknet 4.7.0 → 4.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/CONTRIBUTING.md +2 -2
  3. package/__mocks__/ERC20.json +32561 -29055
  4. package/__mocks__/l1l2_compiled.json +10107 -0
  5. package/__tests__/account.test.ts +32 -24
  6. package/__tests__/contract.test.ts +25 -14
  7. package/__tests__/defaultProvider.test.ts +19 -49
  8. package/__tests__/fixtures.ts +11 -1
  9. package/__tests__/rpcProvider.test.ts +6 -15
  10. package/__tests__/sequencerProvider.test.ts +57 -11
  11. package/__tests__/utils/merkle.test.ts +113 -3
  12. package/__tests__/utils/typedData.test.ts +3 -3
  13. package/account/default.d.ts +10 -44
  14. package/account/default.js +255 -61
  15. package/account/interface.d.ts +78 -7
  16. package/constants.d.ts +1 -0
  17. package/constants.js +1 -0
  18. package/contract/default.js +6 -6
  19. package/dist/account/default.d.ts +10 -44
  20. package/dist/account/default.js +255 -61
  21. package/dist/account/interface.d.ts +78 -7
  22. package/dist/constants.d.ts +1 -0
  23. package/dist/constants.js +1 -0
  24. package/dist/contract/default.js +6 -6
  25. package/dist/provider/default.d.ts +8 -3
  26. package/dist/provider/default.js +31 -4
  27. package/dist/provider/interface.d.ts +67 -5
  28. package/dist/provider/rpc.d.ts +7 -2
  29. package/dist/provider/rpc.js +83 -8
  30. package/dist/provider/sequencer.d.ts +9 -3
  31. package/dist/provider/sequencer.js +93 -14
  32. package/dist/signer/default.d.ts +4 -1
  33. package/dist/signer/default.js +22 -0
  34. package/dist/signer/interface.d.ts +27 -2
  35. package/dist/types/api/openrpc.d.ts +24 -2
  36. package/dist/types/api/sequencer.d.ts +43 -23
  37. package/dist/types/lib.d.ts +23 -2
  38. package/dist/types/provider.d.ts +19 -10
  39. package/dist/types/signer.d.ts +14 -1
  40. package/dist/utils/hash.d.ts +8 -0
  41. package/dist/utils/hash.js +28 -2
  42. package/dist/utils/merkle.js +4 -5
  43. package/dist/utils/number.d.ts +5 -0
  44. package/dist/utils/number.js +29 -1
  45. package/dist/utils/responseParser/rpc.d.ts +2 -6
  46. package/dist/utils/responseParser/rpc.js +0 -11
  47. package/dist/utils/responseParser/sequencer.js +11 -33
  48. package/package.json +1 -1
  49. package/provider/default.d.ts +8 -3
  50. package/provider/default.js +31 -4
  51. package/provider/interface.d.ts +67 -5
  52. package/provider/rpc.d.ts +7 -2
  53. package/provider/rpc.js +83 -8
  54. package/provider/sequencer.d.ts +9 -3
  55. package/provider/sequencer.js +93 -14
  56. package/signer/default.d.ts +4 -1
  57. package/signer/default.js +22 -0
  58. package/signer/interface.d.ts +27 -2
  59. package/src/account/default.ts +201 -53
  60. package/src/account/interface.ts +104 -6
  61. package/src/constants.ts +1 -0
  62. package/src/contract/default.ts +6 -6
  63. package/src/provider/default.ts +43 -5
  64. package/src/provider/interface.ts +92 -7
  65. package/src/provider/rpc.ts +86 -12
  66. package/src/provider/sequencer.ts +105 -13
  67. package/src/signer/default.ts +54 -2
  68. package/src/signer/interface.ts +31 -2
  69. package/src/types/api/openrpc.ts +28 -2
  70. package/src/types/api/sequencer.ts +54 -25
  71. package/src/types/lib.ts +30 -2
  72. package/src/types/provider.ts +31 -11
  73. package/src/types/signer.ts +18 -1
  74. package/src/utils/hash.ts +70 -2
  75. package/src/utils/merkle.ts +4 -5
  76. package/src/utils/number.ts +27 -0
  77. package/src/utils/responseParser/rpc.ts +4 -20
  78. package/src/utils/responseParser/sequencer.ts +14 -7
  79. package/types/api/openrpc.d.ts +24 -2
  80. package/types/api/sequencer.d.ts +43 -23
  81. package/types/lib.d.ts +23 -2
  82. package/types/provider.d.ts +19 -10
  83. package/types/signer.d.ts +14 -1
  84. package/utils/hash.d.ts +8 -0
  85. package/utils/hash.js +28 -2
  86. package/utils/merkle.js +4 -5
  87. package/utils/number.d.ts +5 -0
  88. package/utils/number.js +29 -1
  89. package/utils/responseParser/rpc.d.ts +2 -6
  90. package/utils/responseParser/rpc.js +0 -11
  91. package/utils/responseParser/sequencer.js +11 -33
  92. package/www/docs/API/account.md +60 -1
  93. package/www/docs/API/provider.md +320 -23
  94. package/www/guides/account.md +1 -1
  95. package/www/guides/erc20.md +13 -7
@@ -3,7 +3,13 @@ import { isBN } from 'bn.js';
3
3
  import typedDataExample from '../__mocks__/typedDataExample.json';
4
4
  import { Account, Contract, Provider, number, stark } from '../src';
5
5
  import { toBN } from '../src/utils/number';
6
- import { compiledErc20, compiledTestDapp, getTestAccount, getTestProvider } from './fixtures';
6
+ import {
7
+ compiledErc20,
8
+ compiledTestDapp,
9
+ getERC20DeployPayload,
10
+ getTestAccount,
11
+ getTestProvider,
12
+ } from './fixtures';
7
13
 
8
14
  describe('deploy and test Wallet', () => {
9
15
  const provider = getTestProvider();
@@ -15,26 +21,18 @@ describe('deploy and test Wallet', () => {
15
21
  beforeAll(async () => {
16
22
  expect(account).toBeInstanceOf(Account);
17
23
 
18
- const erc20Response = await provider.deployContract({
19
- contract: compiledErc20,
20
- });
24
+ const erc20DeployPayload = getERC20DeployPayload(account.address);
25
+
26
+ const erc20Response = await provider.deployContract(erc20DeployPayload);
21
27
 
22
28
  erc20Address = erc20Response.contract_address;
23
29
  erc20 = new Contract(compiledErc20.abi, erc20Address, provider);
24
30
 
25
31
  await provider.waitForTransaction(erc20Response.transaction_hash);
26
32
 
27
- const mintResponse = await account.execute({
28
- contractAddress: erc20Address,
29
- entrypoint: 'mint',
30
- calldata: [account.address, '1000'],
31
- });
32
-
33
- await provider.waitForTransaction(mintResponse.transaction_hash);
33
+ const x = await erc20.balanceOf(account.address);
34
34
 
35
- const x = await erc20.balance_of(account.address);
36
-
37
- expect(number.toBN(x.res as string).toString()).toStrictEqual(number.toBN(1000).toString());
35
+ expect(number.toBN(x[0].low).toString()).toStrictEqual(number.toBN(1000).toString());
38
36
 
39
37
  const dappResponse = await provider.deployContract({
40
38
  contract: compiledTestDapp,
@@ -45,34 +43,34 @@ describe('deploy and test Wallet', () => {
45
43
  });
46
44
 
47
45
  test('estimate fee', async () => {
48
- const { overall_fee } = await account.estimateFee({
46
+ const { overall_fee } = await account.estimateInvokeFee({
49
47
  contractAddress: erc20Address,
50
48
  entrypoint: 'transfer',
51
- calldata: [erc20.address, '10'],
49
+ calldata: [erc20.address, '10', '0'],
52
50
  });
53
51
  expect(isBN(overall_fee)).toBe(true);
54
52
  });
55
53
 
56
54
  test('read balance of wallet', async () => {
57
- const x = await erc20.balance_of(account.address);
55
+ const x = await erc20.balanceOf(account.address);
58
56
 
59
- expect(number.toBN(x.res as string).toString()).toStrictEqual(number.toBN(1000).toString());
57
+ expect(number.toBN(x[0].low).toString()).toStrictEqual(number.toBN(1000).toString());
60
58
  });
61
59
 
62
60
  test('execute by wallet owner', async () => {
63
61
  const { transaction_hash } = await account.execute({
64
62
  contractAddress: erc20Address,
65
63
  entrypoint: 'transfer',
66
- calldata: [erc20.address, '10'],
64
+ calldata: [erc20.address, '10', '0'],
67
65
  });
68
66
 
69
67
  await provider.waitForTransaction(transaction_hash);
70
68
  });
71
69
 
72
70
  test('read balance of wallet after transfer', async () => {
73
- const { res } = await erc20.balance_of(account.address);
71
+ const { balance } = await erc20.balanceOf(account.address);
74
72
 
75
- expect(res).toStrictEqual(toBN(990));
73
+ expect(balance.low).toStrictEqual(toBN(990));
76
74
  });
77
75
 
78
76
  test('execute with custom nonce', async () => {
@@ -82,7 +80,7 @@ describe('deploy and test Wallet', () => {
82
80
  {
83
81
  contractAddress: erc20Address,
84
82
  entrypoint: 'transfer',
85
- calldata: [account.address, '10'],
83
+ calldata: [account.address, '10', '0'],
86
84
  },
87
85
  undefined,
88
86
  { nonce }
@@ -130,7 +128,7 @@ describe('deploy and test Wallet', () => {
130
128
  const mintResponse = await account.execute({
131
129
  contractAddress: erc20Address,
132
130
  entrypoint: 'mint',
133
- calldata: [wallet, '1000'],
131
+ calldata: [wallet, '1000', '0'],
134
132
  });
135
133
 
136
134
  await provider.waitForTransaction(mintResponse.transaction_hash);
@@ -143,8 +141,18 @@ describe('deploy and test Wallet', () => {
143
141
  });
144
142
 
145
143
  test('estimate gas fee for `mint`', async () => {
146
- const res = await erc20.estimateFee.mint(wallet, '10');
144
+ const res = await erc20.estimateFee.mint(wallet, ['10', '0']);
147
145
  expect(res).toHaveProperty('overall_fee');
148
146
  });
147
+
148
+ test('Declare Account contract', async () => {
149
+ const declareTx = await account.declare({
150
+ contract: compiledErc20,
151
+ classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
152
+ });
153
+ await provider.waitForTransaction(declareTx.transaction_hash);
154
+
155
+ expect(declareTx.class_hash).toBeDefined();
156
+ });
149
157
  });
150
158
  });
@@ -1,6 +1,7 @@
1
1
  import { isBN } from 'bn.js';
2
2
 
3
3
  import { Contract, ContractFactory, stark } from '../src';
4
+ import { DeployContractPayload } from '../src/types/lib';
4
5
  import { getSelectorFromName } from '../src/utils/hash';
5
6
  import { BigNumberish, toBN } from '../src/utils/number';
6
7
  import { compileCalldata } from '../src/utils/stark';
@@ -8,6 +9,7 @@ import {
8
9
  compiledErc20,
9
10
  compiledMulticall,
10
11
  compiledTypeTransformation,
12
+ getERC20DeployPayload,
11
13
  getTestProvider,
12
14
  } from './fixtures';
13
15
 
@@ -21,9 +23,12 @@ describe('class Contract {}', () => {
21
23
  let contract: Contract;
22
24
 
23
25
  beforeAll(async () => {
24
- const { transaction_hash, contract_address } = await provider.deployContract({
25
- contract: compiledErc20,
26
- });
26
+ const erc20DeployPayload = getERC20DeployPayload(wallet);
27
+
28
+ const { contract_address, transaction_hash } = await provider.deployContract(
29
+ erc20DeployPayload
30
+ );
31
+
27
32
  erc20 = new Contract(compiledErc20.abi, contract_address!, provider);
28
33
  await provider.waitForTransaction(transaction_hash);
29
34
  // Deploy Multicall
@@ -39,21 +44,21 @@ describe('class Contract {}', () => {
39
44
  });
40
45
 
41
46
  test('populate transaction for initial balance of that account', async () => {
42
- const res = await erc20.populateTransaction.balance_of(wallet);
47
+ const res = await erc20.populateTransaction.balanceOf(wallet);
43
48
  expect(res).toHaveProperty('contractAddress');
44
49
  expect(res).toHaveProperty('entrypoint');
45
50
  expect(res).toHaveProperty('calldata');
46
51
  });
47
52
 
48
53
  test('estimate gas fee for `mint` should fail when connected to the provider', async () => {
49
- expect(erc20.estimateFee.mint(wallet, '10')).rejects.toThrow();
54
+ expect(erc20.estimateFee.mint(wallet, ['10', '0'])).rejects.toThrow();
50
55
  });
51
56
 
52
57
  test('read initial balance of that account', async () => {
53
- const result = await erc20.balance_of(wallet);
58
+ const result = await erc20.balanceOf(wallet);
54
59
  const [res] = result;
55
- expect(res).toStrictEqual(toBN(0));
56
- expect(res).toStrictEqual(result.res);
60
+ expect(res.low).toStrictEqual(toBN(1000));
61
+ expect(res).toStrictEqual(result.balance);
57
62
  });
58
63
 
59
64
  test('read balance in a multicall', async () => {
@@ -61,7 +66,7 @@ describe('class Contract {}', () => {
61
66
  const args2 = {};
62
67
  const calls = [
63
68
  erc20.address,
64
- getSelectorFromName('balance_of'),
69
+ getSelectorFromName('balanceOf'),
65
70
  Object.keys(args1).length,
66
71
  ...compileCalldata(args1),
67
72
 
@@ -190,21 +195,27 @@ describe('class Contract {}', () => {
190
195
 
191
196
  describe('class ContractFactory {}', () => {
192
197
  let erc20Address: string;
198
+ const wallet = stark.randomAddress();
199
+ let erc20DeployPayload: DeployContractPayload;
200
+
193
201
  beforeAll(async () => {
194
- const { transaction_hash, contract_address } = await provider.deployContract({
195
- contract: compiledErc20,
196
- });
202
+ erc20DeployPayload = getERC20DeployPayload(wallet);
203
+
204
+ const { contract_address, transaction_hash } = await provider.deployContract(
205
+ erc20DeployPayload
206
+ );
207
+
197
208
  await provider.waitForTransaction(transaction_hash);
198
209
  erc20Address = contract_address;
199
210
  });
200
211
  test('deployment of new contract', async () => {
201
212
  const factory = new ContractFactory(compiledErc20, provider);
202
- const erc20 = await factory.deploy();
213
+ const erc20 = await factory.deploy(erc20DeployPayload.constructorCalldata);
203
214
  expect(erc20 instanceof Contract);
204
215
  });
205
216
  test('wait for deployment transaction', async () => {
206
217
  const factory = new ContractFactory(compiledErc20, provider);
207
- const contract = await factory.deploy();
218
+ const contract = await factory.deploy(erc20DeployPayload.constructorCalldata);
208
219
  expect(contract.deployed()).resolves.not.toThrow();
209
220
  });
210
221
  test('attach new contract', async () => {
@@ -1,15 +1,9 @@
1
- import {
2
- BlockNumber,
3
- DeclareContractResponse,
4
- DeployContractResponse,
5
- GetBlockResponse,
6
- stark,
7
- } from '../src';
1
+ import { BlockNumber, DeployContractResponse, GetBlockResponse, stark } from '../src';
8
2
  import { toBN } from '../src/utils/number';
9
3
  import {
10
- compiledErc20,
11
4
  compiledOpenZeppelinAccount,
12
5
  describeIfNotDevnet,
6
+ getERC20DeployPayload,
13
7
  getTestProvider,
14
8
  } from './fixtures';
15
9
 
@@ -24,11 +18,14 @@ describe('defaultProvider', () => {
24
18
  let exampleBlock: GetBlockResponse;
25
19
  let exampleBlockNumber: BlockNumber;
26
20
  let exampleBlockHash: string;
21
+ const wallet = stark.randomAddress();
27
22
 
28
23
  beforeAll(async () => {
29
- const { transaction_hash, contract_address } = await testProvider.deployContract({
30
- contract: compiledErc20,
31
- });
24
+ const erc20DeployPayload = getERC20DeployPayload(wallet);
25
+
26
+ const { contract_address, transaction_hash } = await testProvider.deployContract(
27
+ erc20DeployPayload
28
+ );
32
29
  await testProvider.waitForTransaction(transaction_hash);
33
30
  exampleTransactionHash = transaction_hash;
34
31
  exampleContractAddress = contract_address;
@@ -58,7 +55,7 @@ describe('defaultProvider', () => {
58
55
  });
59
56
 
60
57
  test('getBlock() -> { blockNumber }', async () => {
61
- const block = await testProvider.getBlock();
58
+ const block = await testProvider.getBlock('latest');
62
59
  return expect(block).toHaveProperty('block_number');
63
60
  });
64
61
 
@@ -101,7 +98,7 @@ describe('defaultProvider', () => {
101
98
  return expect(
102
99
  testProvider.callContract({
103
100
  contractAddress: exampleContractAddress,
104
- entrypoint: 'balance_of',
101
+ entrypoint: 'balanceOf',
105
102
  calldata: compileCalldata({
106
103
  user: '0x9ff64f4ab0e1fe88df4465ade98d1ea99d5732761c39279b8e1374fa943e9b',
107
104
  }),
@@ -123,15 +120,6 @@ describe('defaultProvider', () => {
123
120
  });
124
121
 
125
122
  describe('addTransaction()', () => {
126
- test('declareContract()', async () => {
127
- const response = await testProvider.declareContract({
128
- contract: compiledErc20,
129
- });
130
-
131
- expect(response.transaction_hash).toBeDefined();
132
- expect(response.class_hash).toBeDefined();
133
- });
134
-
135
123
  test('deployContract()', async () => {
136
124
  const response = await testProvider.deployContract({
137
125
  contract: compiledOpenZeppelinAccount,
@@ -147,8 +135,8 @@ describe('defaultProvider', () => {
147
135
  let latestBlock;
148
136
  describe(`Provider methods if not devnet`, () => {
149
137
  describe('getBlock', () => {
150
- test('getBlock by tag pending', async () => {
151
- latestBlock = await provider.getBlock();
138
+ test('getBlock by tag latest', async () => {
139
+ latestBlock = await provider.getBlock('latest');
152
140
  expect(latestBlock).toHaveProperty('block_hash');
153
141
  expect(latestBlock).toHaveProperty('parent_hash');
154
142
  expect(latestBlock).toHaveProperty('block_number');
@@ -221,6 +209,7 @@ describe('defaultProvider', () => {
221
209
  expect(transaction.transaction_hash).toBeTruthy();
222
210
  expect(transaction.contract_address).toBeTruthy();
223
211
  expect(Array.isArray(transaction.calldata)).toBe(true);
212
+ // expect(transaction.entry_point_selector).toBeTruthy();
224
213
  expect(Array.isArray(transaction.signature)).toBe(true);
225
214
  expect(transaction.max_fee).toBeTruthy();
226
215
  });
@@ -242,34 +231,22 @@ describe('defaultProvider', () => {
242
231
  const receipt = await provider.getTransactionReceipt(
243
232
  '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
244
233
  );
245
-
246
234
  expect(receipt).toHaveProperty('transaction_hash');
247
235
  expect(receipt).toHaveProperty('status');
248
- expect(receipt).toHaveProperty('status_data');
249
- expect(receipt).toHaveProperty('messages_sent');
250
- expect(receipt).toHaveProperty('l1_origin_message');
251
- expect(receipt).toHaveProperty('events');
236
+ expect(receipt).toHaveProperty('actual_fee');
252
237
  });
253
238
  });
254
239
 
255
240
  describe('Contract methods', () => {
256
241
  let contractAddress: string;
257
242
  let deployResponse: DeployContractResponse;
258
- let declareResponse: DeclareContractResponse;
259
243
  let blockNumber: BlockNumber;
260
244
 
261
245
  beforeAll(async () => {
262
- deployResponse = await provider.deployContract({ contract: compiledErc20 });
263
- console.log(
264
- '🚀 ~ file: defaultProvider.test.ts ~ line 264 ~ beforeAll ~ deployResponse',
265
- deployResponse
266
- );
246
+ const erc20DeployPayload = getERC20DeployPayload(wallet);
247
+ deployResponse = await provider.deployContract(erc20DeployPayload);
267
248
  contractAddress = deployResponse.contract_address;
268
- declareResponse = await provider.declareContract({ contract: compiledErc20 });
269
- await Promise.all([
270
- provider.waitForTransaction(deployResponse.transaction_hash),
271
- provider.waitForTransaction(declareResponse.transaction_hash),
272
- ]);
249
+ await provider.waitForTransaction(deployResponse.transaction_hash);
273
250
  ({ block_number: blockNumber } = await provider.getBlock('latest'));
274
251
  });
275
252
 
@@ -280,13 +257,6 @@ describe('defaultProvider', () => {
280
257
  });
281
258
  });
282
259
 
283
- describe('declareContract', () => {
284
- test('response', async () => {
285
- expect(declareResponse.class_hash).toBeTruthy();
286
- expect(declareResponse.transaction_hash).toBeTruthy();
287
- });
288
- });
289
-
290
260
  describe('getClassAt', () => {
291
261
  test('response', async () => {
292
262
  const classResponse = await provider.getClassAt(contractAddress, blockNumber);
@@ -302,9 +272,9 @@ describe('defaultProvider', () => {
302
272
  provider
303
273
  .callContract({
304
274
  contractAddress: deployResponse.contract_address,
305
- entrypoint: 'balance_of',
275
+ entrypoint: 'balanceOf',
306
276
  calldata: compileCalldata({
307
- user: '0x9ff64f4ab0e1fe88df4465ade98d1ea99d5732761c39279b8e1374fa943e9b',
277
+ user: wallet,
308
278
  }),
309
279
  })
310
280
  .then((res) => {
@@ -1,13 +1,15 @@
1
1
  import fs from 'fs';
2
2
 
3
3
  import { Account, ProviderInterface, RpcProvider, SequencerProvider, ec, json } from '../src';
4
- import { CompiledContract } from '../src/types';
4
+ import { CompiledContract, DeployContractPayload } from '../src/types';
5
+ import { encodeShortString } from '../src/utils/shortString';
5
6
 
6
7
  const readContract = (name: string): CompiledContract =>
7
8
  json.parse(fs.readFileSync(`./__mocks__/${name}.json`).toString('ascii'));
8
9
 
9
10
  export const compiledOpenZeppelinAccount = readContract('Account');
10
11
  export const compiledErc20 = readContract('ERC20');
12
+ export const compiledL1L2 = readContract('l1l2_compiled');
11
13
  export const compiledTypeTransformation = readContract('contract');
12
14
  export const compiledMulticall = readContract('multicall');
13
15
  export const compiledTestDapp = readContract('TestDapp');
@@ -26,6 +28,7 @@ const IS_RPC_DEVNET = Boolean(
26
28
  );
27
29
  const IS_SEQUENCER = !IS_RPC;
28
30
  const IS_SEQUENCER_DEVNET = !BASE_URL.includes('starknet.io');
31
+ export const IS_SEQUENCER_GOERLI = BASE_URL === 'https://alpha4.starknet.io';
29
32
  export const IS_DEVNET = IS_SEQUENCER ? IS_SEQUENCER_DEVNET : IS_RPC_DEVNET;
30
33
 
31
34
  export const getTestProvider = () => {
@@ -69,3 +72,10 @@ const describeIf = (condition: boolean) => (condition ? describe : describe.skip
69
72
  export const describeIfSequencer = describeIf(IS_DEVNET);
70
73
  export const describeIfRpc = describeIf(IS_RPC);
71
74
  export const describeIfNotDevnet = describeIf(!IS_DEVNET);
75
+
76
+ export const getERC20DeployPayload = (recipient: string): DeployContractPayload => {
77
+ return {
78
+ contract: compiledErc20,
79
+ constructorCalldata: [encodeShortString('Token'), encodeShortString('ERC20'), recipient],
80
+ };
81
+ };
@@ -1,6 +1,5 @@
1
1
  import { Account, GetBlockResponse, RpcProvider, ec } from '../src';
2
2
  import {
3
- compiledErc20,
4
3
  compiledOpenZeppelinAccount,
5
4
  describeIfRpc,
6
5
  getTestAccount,
@@ -116,20 +115,12 @@ describeIfRpc('RPCProvider', () => {
116
115
  });
117
116
  });
118
117
 
119
- describe('declare contract related tests', () => {
120
- let class_hash;
121
-
122
- beforeAll(async () => {
123
- ({ class_hash } = await rpcProvider.declareContract({
124
- contract: compiledErc20,
125
- }));
126
- });
127
-
128
- test('getClass', async () => {
129
- const contractClass = await rpcProvider.getClass(class_hash);
130
- expect(contractClass).toHaveProperty('program');
131
- expect(contractClass).toHaveProperty('entry_points_by_type');
132
- });
118
+ test('getClass classHash 0x0733734fa0dab1158bccdfe0df7b0becf3827f908971fac8d39cc73d99ad8645', async () => {
119
+ const contractClass = await rpcProvider.getClass(
120
+ '0x0733734fa0dab1158bccdfe0df7b0becf3827f908971fac8d39cc73d99ad8645'
121
+ );
122
+ expect(contractClass).toHaveProperty('program');
123
+ expect(contractClass).toHaveProperty('entry_points_by_type');
133
124
  });
134
125
 
135
126
  test.todo('getEstimateFee');
@@ -1,9 +1,12 @@
1
1
  import { Contract, Provider, SequencerProvider, stark } from '../src';
2
2
  import { toBN } from '../src/utils/number';
3
3
  import {
4
+ IS_SEQUENCER_GOERLI,
4
5
  compiledErc20,
6
+ compiledL1L2,
5
7
  describeIfNotDevnet,
6
8
  describeIfSequencer,
9
+ getERC20DeployPayload,
7
10
  getTestProvider,
8
11
  } from './fixtures';
9
12
 
@@ -17,7 +20,7 @@ describeIfSequencer('SequencerProvider', () => {
17
20
  sequencerProvider = getTestProvider() as SequencerProvider;
18
21
  customSequencerProvider = new Provider({
19
22
  sequencer: {
20
- baseUrl: 'https://alpha4.starknet.io',
23
+ baseUrl: 'http://127.0.0.1:5050/',
21
24
  feederGatewayUrl: 'feeder_gateway',
22
25
  gatewayUrl: 'gateway',
23
26
  }, // Similar to arguements used in docs
@@ -26,11 +29,15 @@ describeIfSequencer('SequencerProvider', () => {
26
29
 
27
30
  describe('Gateway specific methods', () => {
28
31
  let exampleTransactionHash: string;
32
+ const wallet = stark.randomAddress();
29
33
 
30
34
  beforeAll(async () => {
31
- const { transaction_hash, contract_address } = await sequencerProvider.deployContract({
32
- contract: compiledErc20,
33
- });
35
+ const erc20DeployPayload = getERC20DeployPayload(wallet);
36
+
37
+ const { contract_address, transaction_hash } = await sequencerProvider.deployContract(
38
+ erc20DeployPayload
39
+ );
40
+
34
41
  await sequencerProvider.waitForTransaction(transaction_hash);
35
42
  exampleTransactionHash = transaction_hash;
36
43
  exampleContractAddress = contract_address;
@@ -44,7 +51,7 @@ describeIfSequencer('SequencerProvider', () => {
44
51
 
45
52
  test('transaction trace', async () => {
46
53
  const transactionTrace = await sequencerProvider.getTransactionTrace(exampleTransactionHash);
47
- expect(transactionTrace).toHaveProperty('function_invocation');
54
+ // TODO test optional properties
48
55
  expect(transactionTrace).toHaveProperty('signature');
49
56
  });
50
57
 
@@ -67,19 +74,58 @@ describeIfSequencer('SequencerProvider', () => {
67
74
  const wallet = stark.randomAddress();
68
75
 
69
76
  beforeAll(async () => {
70
- const { contract_address, transaction_hash } = await customSequencerProvider.deployContract({
71
- contract: compiledErc20,
72
- });
77
+ const erc20DeployPayload = getERC20DeployPayload(wallet);
78
+
79
+ const { contract_address, transaction_hash } = await customSequencerProvider.deployContract(
80
+ erc20DeployPayload
81
+ );
73
82
 
74
83
  await customSequencerProvider.waitForTransaction(transaction_hash);
75
84
  erc20 = new Contract(compiledErc20.abi, contract_address, customSequencerProvider);
76
85
  });
77
86
 
78
87
  test('Check ERC20 balance using Custom Sequencer Provider', async () => {
79
- const result = await erc20.balance_of(wallet);
88
+ const result = await erc20.balanceOf(wallet);
80
89
  const [res] = result;
81
- expect(res).toStrictEqual(toBN(0));
82
- expect(res).toStrictEqual(result.res);
90
+ expect(res.low).toStrictEqual(toBN(1000));
91
+ expect(res).toStrictEqual(result.balance);
92
+ });
93
+ });
94
+
95
+ describe('Test Estimate message fee', () => {
96
+ const L1_ADDRESS = '0x8359E4B0152ed5A731162D3c7B0D8D56edB165A0';
97
+ let l1l2ContractAddress: string;
98
+
99
+ beforeAll(async () => {
100
+ if (IS_SEQUENCER_GOERLI) {
101
+ l1l2ContractAddress = '0x2863141e0d9a74e9b484c1f5b1e3a2f6cbb6b84df8233c7c1cbe31334d9aed8';
102
+ } else {
103
+ const { transaction_hash, contract_address } = await sequencerProvider.deployContract({
104
+ contract: compiledL1L2,
105
+ });
106
+ await sequencerProvider.waitForTransaction(transaction_hash);
107
+ l1l2ContractAddress = contract_address;
108
+ }
109
+ });
110
+
111
+ test('estimate message fee', async () => {
112
+ const estimation = await sequencerProvider.estimateMessageFee(
113
+ {
114
+ from_address: L1_ADDRESS,
115
+ to_address: l1l2ContractAddress,
116
+ entry_point_selector: 'deposit',
117
+ payload: ['556', '123'],
118
+ },
119
+ 'latest'
120
+ );
121
+ expect(estimation).toEqual(
122
+ expect.objectContaining({
123
+ overall_fee: expect.anything(),
124
+ gas_price: expect.anything(),
125
+ gas_usage: expect.anything(),
126
+ unit: 'wei',
127
+ })
128
+ );
83
129
  });
84
130
  });
85
131
  });