starknet 3.4.0 → 3.6.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 (121) hide show
  1. package/.eslintrc +2 -1
  2. package/CHANGELOG.md +45 -0
  3. package/__tests__/account.test.ts +43 -35
  4. package/__tests__/accountContract.test.ts +5 -48
  5. package/__tests__/constancts.ts +2 -0
  6. package/__tests__/contract.test.ts +144 -54
  7. package/__tests__/provider.test.ts +8 -0
  8. package/__tests__/utils/utils.browser.test.ts +1 -3
  9. package/account/default.d.ts +2 -0
  10. package/account/default.js +60 -12
  11. package/account/interface.d.ts +14 -0
  12. package/contract/contractFactory.d.ts +36 -0
  13. package/contract/contractFactory.js +218 -0
  14. package/contract/default.d.ts +143 -0
  15. package/{contract.js → contract/default.js} +372 -86
  16. package/contract/index.d.ts +3 -0
  17. package/contract/index.js +28 -0
  18. package/contract/interface.d.ts +79 -0
  19. package/contract/interface.js +8 -0
  20. package/dist/account/default.d.ts +2 -1
  21. package/dist/account/default.js +47 -9
  22. package/dist/account/interface.d.ts +13 -1
  23. package/dist/contract/contractFactory.d.ts +32 -0
  24. package/dist/contract/contractFactory.js +102 -0
  25. package/dist/contract/default.d.ts +121 -0
  26. package/dist/contract/default.js +648 -0
  27. package/dist/contract/index.d.ts +3 -0
  28. package/dist/contract/index.js +15 -0
  29. package/dist/contract/interface.d.ts +72 -0
  30. package/dist/contract/interface.js +9 -0
  31. package/dist/index.d.ts +1 -1
  32. package/dist/index.js +1 -1
  33. package/dist/provider/default.d.ts +12 -2
  34. package/dist/provider/default.js +20 -6
  35. package/dist/provider/interface.d.ts +3 -1
  36. package/dist/signer/index.d.ts +1 -0
  37. package/dist/signer/index.js +1 -0
  38. package/dist/signer/ledger.d.ts +12 -0
  39. package/dist/signer/ledger.js +138 -0
  40. package/dist/types/api.d.ts +61 -0
  41. package/dist/types/contract.d.ts +5 -0
  42. package/dist/types/contract.js +2 -0
  43. package/dist/types/index.d.ts +1 -0
  44. package/dist/types/index.js +1 -0
  45. package/dist/types/lib.d.ts +11 -1
  46. package/dist/utils/transaction.d.ts +1 -2
  47. package/index.d.ts +1 -1
  48. package/index.js +1 -1
  49. package/package.json +5 -2
  50. package/provider/default.d.ts +12 -1
  51. package/provider/default.js +29 -16
  52. package/provider/interface.d.ts +3 -1
  53. package/signer/index.d.ts +1 -0
  54. package/signer/index.js +1 -0
  55. package/signer/ledger.d.ts +15 -0
  56. package/signer/ledger.js +243 -0
  57. package/src/account/default.ts +25 -4
  58. package/src/account/interface.ts +15 -0
  59. package/src/contract/contractFactory.ts +78 -0
  60. package/src/contract/default.ts +627 -0
  61. package/src/contract/index.ts +3 -0
  62. package/src/contract/interface.ts +87 -0
  63. package/src/index.ts +1 -1
  64. package/src/provider/default.ts +21 -14
  65. package/src/provider/interface.ts +3 -1
  66. package/src/signer/index.ts +1 -0
  67. package/src/signer/ledger.ts +81 -0
  68. package/src/types/api.ts +66 -0
  69. package/src/types/contract.ts +5 -0
  70. package/src/types/index.ts +1 -0
  71. package/src/types/lib.ts +12 -1
  72. package/src/utils/transaction.ts +1 -2
  73. package/tsconfig.json +1 -10
  74. package/types/api.d.ts +61 -0
  75. package/types/contract.d.ts +5 -0
  76. package/types/contract.js +2 -0
  77. package/types/index.d.ts +1 -0
  78. package/types/index.js +1 -0
  79. package/types/lib.d.ts +11 -1
  80. package/utils/transaction.d.ts +1 -2
  81. package/www/README.md +41 -0
  82. package/www/babel.config.js +3 -0
  83. package/www/code-examples/account.js +62 -0
  84. package/www/code-examples/amm.js +49 -0
  85. package/www/code-examples/erc20.js +10 -0
  86. package/www/code-examples/package-lock.json +336 -0
  87. package/www/code-examples/package.json +15 -0
  88. package/www/docs/API/_category_.json +5 -0
  89. package/www/docs/API/account.md +11 -0
  90. package/www/docs/API/contract.md +14 -0
  91. package/www/docs/API/index.md +4 -0
  92. package/www/docs/API/provider.md +10 -0
  93. package/www/docs/API/signer.md +8 -0
  94. package/www/docusaurus.config.js +131 -0
  95. package/www/guides/account.md +60 -0
  96. package/www/guides/cra.md +3 -0
  97. package/www/guides/erc20.md +88 -0
  98. package/www/guides/intro.md +20 -0
  99. package/www/package-lock.json +22285 -0
  100. package/www/package.json +43 -0
  101. package/www/sidebars.js +31 -0
  102. package/www/src/components/HomepageFeatures/index.tsx +67 -0
  103. package/www/src/components/HomepageFeatures/styles.module.css +10 -0
  104. package/www/src/css/custom.css +39 -0
  105. package/www/src/pages/index.module.css +23 -0
  106. package/www/src/pages/index.tsx +40 -0
  107. package/www/src/pages/markdown-page.md +7 -0
  108. package/www/static/.nojekyll +0 -0
  109. package/www/static/img/docusaurus.png +0 -0
  110. package/www/static/img/favicon.ico +0 -0
  111. package/www/static/img/logo.svg +17 -0
  112. package/www/static/img/starknet-1.png +0 -0
  113. package/www/static/img/starknet-2.png +0 -0
  114. package/www/static/img/starknet-3.png +0 -0
  115. package/www/static/img/tutorial/docsVersionDropdown.png +0 -0
  116. package/www/static/img/tutorial/localeDropdown.png +0 -0
  117. package/www/tsconfig.json +8 -0
  118. package/contract.d.ts +0 -98
  119. package/dist/contract.d.ts +0 -94
  120. package/dist/contract.js +0 -389
  121. package/src/contract.ts +0 -357
package/.eslintrc CHANGED
@@ -21,6 +21,7 @@
21
21
  "class-methods-use-this": 0,
22
22
  "import/prefer-default-export": 0,
23
23
  "@typescript-eslint/naming-convention": 0,
24
- "@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
24
+ "@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
25
+ "func-names": 0
25
26
  }
26
27
  }
package/CHANGELOG.md CHANGED
@@ -1,3 +1,48 @@
1
+ # [3.6.0](https://github.com/seanjameshan/starknet.js/compare/v3.5.1...v3.6.0) (2022-03-24)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **account:** estimate fee transfered from provider to account class ([93e7dd9](https://github.com/seanjameshan/starknet.js/commit/93e7dd941b35bccb67cc426b9ae546801092964c))
6
+ - formatting ([248246f](https://github.com/seanjameshan/starknet.js/commit/248246f2fe75b9897700b955fa98e1779aec1744))
7
+ - link ([494e000](https://github.com/seanjameshan/starknet.js/commit/494e0005c3b1cb86f5de0f25a10cbbe786a87b34))
8
+ - **provider:** estimateFee entrypoint conversion fix ([e40204a](https://github.com/seanjameshan/starknet.js/commit/e40204a2eca5f475fe50a88349fd4890bbc36790))
9
+ - **provider:** estimation fee response type ([ce674ca](https://github.com/seanjameshan/starknet.js/commit/ce674ca632ff70a07d95d685c9bf2f48bebaca20))
10
+
11
+ ### Features
12
+
13
+ - add LedgerSigner class + blind signing ([9b700f3](https://github.com/seanjameshan/starknet.js/commit/9b700f300a91a0967f8827d0ecdd69e531738ec4))
14
+ - **contract:** contract expanded with estimateFee method ([fbaf4ba](https://github.com/seanjameshan/starknet.js/commit/fbaf4bab56ace0917ce7c66ecf90f8e2d0dc7f60))
15
+ - improvements after PR reviewing ([9f30e20](https://github.com/seanjameshan/starknet.js/commit/9f30e20c2e5d2afafe4eae58c597b82dffc3bbe2))
16
+ - new improvements after new PR review ([2e16808](https://github.com/seanjameshan/starknet.js/commit/2e168082b0042f27336946639f3948e91bc5f641))
17
+ - **provider:** provider expanded with getTransactionTrace ([b67361a](https://github.com/seanjameshan/starknet.js/commit/b67361ad7c50218e00273c097426e14814441404))
18
+
19
+ ## [3.5.1](https://github.com/seanjameshan/starknet.js/compare/v3.5.0...v3.5.1) (2022-03-11)
20
+
21
+ ### Bug Fixes
22
+
23
+ - account detection ([b3b3ba7](https://github.com/seanjameshan/starknet.js/commit/b3b3ba74dde72027ba7f0e1234fed34a604fdcec))
24
+ - contract interface ([696116d](https://github.com/seanjameshan/starknet.js/commit/696116d383ba16c587e7ed708f7b47d02610b9d9))
25
+
26
+ # [3.5.0](https://github.com/seanjameshan/starknet.js/compare/v3.4.0...v3.5.0) (2022-03-11)
27
+
28
+ ### Bug Fixes
29
+
30
+ - contract test ([a9b4103](https://github.com/seanjameshan/starknet.js/commit/a9b410356baa5c7305da9ba69229c0882f7ae026))
31
+ - **contract-factory:** move more towards ethers.js api ([4caa6ce](https://github.com/seanjameshan/starknet.js/commit/4caa6cee282fe73bc6fb91bea59c620cc42d31a0))
32
+ - **contract:** structure change ([1ef9d2f](https://github.com/seanjameshan/starknet.js/commit/1ef9d2fee0158c9894d5e049f59cc72bfaad2d55))
33
+ - **contract:** tests for new contract interface ([9273f54](https://github.com/seanjameshan/starknet.js/commit/9273f542b087e2940e0d2e88ecbeec58062953bf))
34
+ - enable validateMethodAndArgs on call ([efa63d6](https://github.com/seanjameshan/starknet.js/commit/efa63d6fc7ae77b28f694640833cec73111b175d))
35
+ - reverting validateMethodAndArgs changes ([d847fa8](https://github.com/seanjameshan/starknet.js/commit/d847fa8e4db3563d67861873046f9cb87d0fff8e))
36
+
37
+ ### Features
38
+
39
+ - **contractFactory:** lib expanded with contract factory ([2c9c3d1](https://github.com/seanjameshan/starknet.js/commit/2c9c3d1b60961ddd698dc6b3175fff2f574f03bd))
40
+ - **contract:** implement `contract.deployed() ⇒ Promise<Contract>` ([91f4992](https://github.com/seanjameshan/starknet.js/commit/91f4992a3f612a03ff5cde01d07a487ebb883f6d))
41
+ - **contract:** new contract interface ([01eeae8](https://github.com/seanjameshan/starknet.js/commit/01eeae815619009de195a759891cad9d8ec992c7))
42
+ - **contract:** new contract methods signature ([cc87943](https://github.com/seanjameshan/starknet.js/commit/cc8794362d2f20816aabf7b44596035d644a434d))
43
+ - default contract args ([2a3956d](https://github.com/seanjameshan/starknet.js/commit/2a3956dab88f3e68a513916b1644fa0723c5235f))
44
+ - **provider:** preparation for the fee integration ([c1c231b](https://github.com/seanjameshan/starknet.js/commit/c1c231b6ec803b01af280baf61d0afbc3f9be6bb))
45
+
1
46
  # [3.4.0](https://github.com/seanjameshan/starknet.js/compare/v3.3.0...v3.4.0) (2022-03-10)
2
47
 
3
48
  ### Features
@@ -21,10 +21,7 @@ describe('deploy and test Wallet', () => {
21
21
  const contract = new Contract(compiledArgentAccount.abi, accountResponse.address);
22
22
  expect(accountResponse.code).toBe('TRANSACTION_RECEIVED');
23
23
 
24
- const initializeResponse = await contract.invoke('initialize', {
25
- signer: starkKeyPub,
26
- guardian: '0',
27
- });
24
+ const initializeResponse = await contract.initialize(starkKeyPub, '0');
28
25
  expect(initializeResponse.code).toBe('TRANSACTION_RECEIVED');
29
26
 
30
27
  account = new Account(defaultProvider, accountResponse.address, starkKeyPair);
@@ -36,10 +33,7 @@ describe('deploy and test Wallet', () => {
36
33
  erc20 = new Contract(compiledErc20.abi, erc20Address);
37
34
  expect(erc20Response.code).toBe('TRANSACTION_RECEIVED');
38
35
 
39
- const mintResponse = await erc20.invoke('mint', {
40
- recipient: account.address,
41
- amount: '1000',
42
- });
36
+ const mintResponse = await erc20.mint(account.address, '1000');
43
37
  expect(mintResponse.code).toBe('TRANSACTION_RECEIVED');
44
38
 
45
39
  const dappResponse = await defaultProvider.deployContract({
@@ -50,6 +44,16 @@ describe('deploy and test Wallet', () => {
50
44
  await defaultProvider.waitForTransaction(dappResponse.transaction_hash);
51
45
  });
52
46
 
47
+ test('estimate fee', async () => {
48
+ const { amount, unit } = await account.estimateFee({
49
+ contractAddress: erc20Address,
50
+ entrypoint: 'transfer',
51
+ calldata: [erc20.address, '10'],
52
+ });
53
+ expect(typeof amount).toBe('number');
54
+ expect(typeof unit).toBe('string');
55
+ });
56
+
53
57
  test('same wallet address', () => {
54
58
  expect(account.address).toBe(account.address);
55
59
  });
@@ -65,30 +69,30 @@ describe('deploy and test Wallet', () => {
65
69
  });
66
70
 
67
71
  test('read balance of wallet', async () => {
68
- const { res } = await erc20.call('balance_of', {
69
- user: account.address,
70
- });
72
+ const { res } = await erc20.balance_of(account.address);
71
73
 
72
74
  expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(1000).toString());
73
75
  });
74
76
 
75
77
  test('execute by wallet owner', async () => {
76
- const { code, transaction_hash } = await account.execute({
77
- contractAddress: erc20Address,
78
- entrypoint: 'transfer',
79
- calldata: [toBN(erc20Address).toString(), '10'],
80
- });
78
+ const { code, transaction_hash } = await account.execute(
79
+ {
80
+ contractAddress: erc20Address,
81
+ entrypoint: 'transfer',
82
+ calldata: [erc20.address, '10'],
83
+ },
84
+ undefined,
85
+ { maxFee: '0' }
86
+ );
81
87
 
82
88
  expect(code).toBe('TRANSACTION_RECEIVED');
83
89
  await defaultProvider.waitForTransaction(transaction_hash);
84
90
  });
85
91
 
86
92
  test('read balance of wallet after transfer', async () => {
87
- const { res } = await erc20.call('balance_of', {
88
- user: account.address,
89
- });
93
+ const { res } = await erc20.balance_of(account.address);
90
94
 
91
- expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(990).toString());
95
+ expect(res).toStrictEqual(toBN(990));
92
96
  });
93
97
 
94
98
  test('execute with custom nonce', async () => {
@@ -101,10 +105,10 @@ describe('deploy and test Wallet', () => {
101
105
  {
102
106
  contractAddress: erc20Address,
103
107
  entrypoint: 'transfer',
104
- calldata: [toBN(erc20Address).toString(), '10'],
108
+ calldata: [account.address, '10'],
105
109
  },
106
110
  undefined,
107
- { nonce }
111
+ { nonce, maxFee: '0' }
108
112
  );
109
113
 
110
114
  expect(code).toBe('TRANSACTION_RECEIVED');
@@ -112,23 +116,27 @@ describe('deploy and test Wallet', () => {
112
116
  });
113
117
 
114
118
  test('execute multiple transactions', async () => {
115
- const { code, transaction_hash } = await account.execute([
116
- {
117
- contractAddress: dapp.connectedTo,
118
- entrypoint: 'set_number',
119
- calldata: ['47'],
120
- },
121
- {
122
- contractAddress: dapp.connectedTo,
123
- entrypoint: 'increase_number',
124
- calldata: ['10'],
125
- },
126
- ]);
119
+ const { code, transaction_hash } = await account.execute(
120
+ [
121
+ {
122
+ contractAddress: dapp.address,
123
+ entrypoint: 'set_number',
124
+ calldata: ['47'],
125
+ },
126
+ {
127
+ contractAddress: dapp.address,
128
+ entrypoint: 'increase_number',
129
+ calldata: ['10'],
130
+ },
131
+ ],
132
+ undefined,
133
+ { maxFee: '0' }
134
+ );
127
135
 
128
136
  expect(code).toBe('TRANSACTION_RECEIVED');
129
137
  await defaultProvider.waitForTransaction(transaction_hash);
130
138
 
131
- const response = await dapp.call('get_number', { user: account.address });
139
+ const response = await dapp.get_number(account.address);
132
140
  expect(toBN(response.number as string).toString()).toStrictEqual('57');
133
141
  });
134
142
 
@@ -1,5 +1,4 @@
1
1
  import { Contract, defaultProvider, ec, hash, number, stark } from '../src';
2
- import { transformCallsToMulticallArrays } from '../src/utils/transaction';
3
2
  import { compiledArgentAccount, compiledErc20 } from './fixtures';
4
3
 
5
4
  describe('getStarkAccountFromPrivateKey()', () => {
@@ -38,10 +37,7 @@ describe('deploy and test Wallet', () => {
38
37
  accountContract = new Contract(compiledArgentAccount.abi, accountResponse.address);
39
38
  expect(accountResponse.code).toBe('TRANSACTION_RECEIVED');
40
39
 
41
- const initializeResponse = await accountContract.invoke('initialize', {
42
- signer: starkKeyPub,
43
- guardian: '0',
44
- });
40
+ const initializeResponse = await accountContract.initialize(starkKeyPub, '0');
45
41
  expect(initializeResponse.code).toBe('TRANSACTION_RECEIVED');
46
42
 
47
43
  const erc20Response = await defaultProvider.deployContract({
@@ -51,60 +47,21 @@ describe('deploy and test Wallet', () => {
51
47
  erc20 = new Contract(compiledErc20.abi, erc20Address);
52
48
  expect(erc20Response.code).toBe('TRANSACTION_RECEIVED');
53
49
 
54
- const mintResponse = await erc20.invoke('mint', {
55
- recipient: accountContract.connectedTo,
56
- amount: '1000',
57
- });
50
+ const mintResponse = await erc20.mint(accountContract.address, '1000');
58
51
  expect(mintResponse.code).toBe('TRANSACTION_RECEIVED');
59
52
  await defaultProvider.waitForTransaction(mintResponse.transaction_hash);
60
53
  });
61
54
 
62
55
  test('read nonce', async () => {
63
- const { nonce } = await accountContract.call('get_nonce');
56
+ const { nonce } = await accountContract.get_nonce();
64
57
 
65
58
  expect(number.toBN(nonce as string).toString()).toStrictEqual(number.toBN(0).toString());
66
59
  });
67
60
 
68
61
  test('read balance of wallet', async () => {
69
- const { res } = await erc20.call('balance_of', {
70
- user: accountContract.connectedTo,
71
- });
72
-
73
- expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(1000).toString());
74
- });
75
-
76
- test('execute by wallet owner', async () => {
77
- const nonce = (await accountContract.call('get_nonce')).nonce.toString();
78
-
79
- const calls = [
80
- { contractAddress: erc20Address, entrypoint: 'transfer', calldata: [erc20Address, '10'] },
81
- ];
82
- const msgHash = hash.hashMulticall(accountContract.connectedTo, calls, nonce, '0');
83
-
84
- const { callArray, calldata } = transformCallsToMulticallArrays(calls);
85
-
86
- const signature = ec.sign(starkKeyPair, msgHash);
87
- const { code, transaction_hash } = await accountContract.invoke(
88
- '__execute__',
89
- {
90
- call_array: callArray,
91
- calldata,
92
- nonce,
93
- },
94
- signature
95
- );
96
-
97
- expect(code).toBe('TRANSACTION_RECEIVED');
98
-
99
- await defaultProvider.waitForTransaction(transaction_hash);
100
- });
101
-
102
- test('read balance of wallet after transfer', async () => {
103
- const { res } = await erc20.call('balance_of', {
104
- user: accountContract.connectedTo,
105
- });
62
+ const { res } = await erc20.balance_of(accountContract.address);
106
63
 
107
- expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(990).toString());
64
+ expect(res).toStrictEqual(number.toBN(1000));
108
65
  });
109
66
  });
110
67
 
@@ -0,0 +1,2 @@
1
+ export const ACCOUNT_ADDRESS = '0x4e5f6f6020ffa7e5761cbe96e932b7c1cbbcace70c0fe22767c5f0abf851a17';
2
+ export const PRIVATE_KEY = '0x0529868a6dc774b36342024c207686af16e84fc157c5eeb3a9d31fa13c0d44c5';
@@ -1,9 +1,10 @@
1
1
  import { isBN } from 'bn.js';
2
2
 
3
- import { Contract, defaultProvider, stark } from '../src';
3
+ import { Account, Contract, ContractFactory, Provider, defaultProvider, ec, stark } from '../src';
4
4
  import { getSelectorFromName } from '../src/utils/hash';
5
5
  import { BigNumberish, toBN } from '../src/utils/number';
6
6
  import { compileCalldata } from '../src/utils/stark';
7
+ import { ACCOUNT_ADDRESS, PRIVATE_KEY } from './constancts';
7
8
  import { compiledErc20, compiledMulticall, compiledTypeTransformation } from './fixtures';
8
9
 
9
10
  describe('class Contract {}', () => {
@@ -20,7 +21,6 @@ describe('class Contract {}', () => {
20
21
  erc20 = new Contract(compiledErc20.abi, address, defaultProvider);
21
22
  expect(code).toBe('TRANSACTION_RECEIVED');
22
23
  await defaultProvider.waitForTransaction(transaction_hash);
23
-
24
24
  // Deploy Multicall
25
25
 
26
26
  const {
@@ -38,49 +38,60 @@ describe('class Contract {}', () => {
38
38
  await defaultProvider.waitForTransaction(m_transaction_hash);
39
39
  });
40
40
 
41
+ test('populate transaction for initial balance of that account', async () => {
42
+ const res = await erc20.populateTransaction.balance_of(wallet);
43
+ expect(res).toHaveProperty('contractAddress');
44
+ expect(res).toHaveProperty('entrypoint');
45
+ expect(res).toHaveProperty('calldata');
46
+ expect(res).toHaveProperty('signature');
47
+ });
48
+
49
+ test('estimate gas fee for `mint` should fail when connected to the provider', async () => {
50
+ expect(erc20.estimateFee.mint(wallet, '10')).rejects.toThrow();
51
+ });
52
+
41
53
  test('read initial balance of that account', async () => {
42
- const { res } = await erc20.call('balance_of', {
43
- user: wallet,
44
- });
54
+ const result = await erc20.balance_of(wallet);
55
+ const [res] = result;
45
56
  expect(res).toStrictEqual(toBN(0));
57
+ expect(res).toStrictEqual(result.res);
46
58
  });
47
59
 
48
60
  test('add 10 test ERC20 to account', async () => {
49
- const response = await erc20.invoke('mint', {
50
- recipient: wallet,
51
- amount: '10',
52
- });
61
+ const response = await erc20.mint(wallet, '10');
53
62
  expect(response.code).toBe('TRANSACTION_RECEIVED');
54
63
 
55
64
  await defaultProvider.waitForTransaction(response.transaction_hash);
56
65
  });
57
66
 
58
67
  test('read balance after mint of that account', async () => {
59
- const { res } = await erc20.call('balance_of', {
60
- user: wallet,
61
- });
62
-
68
+ const result = await erc20.balance_of(wallet);
69
+ const [res] = result;
63
70
  expect(res).toStrictEqual(toBN(10));
71
+ expect(res).toStrictEqual(result.res);
64
72
  });
65
73
 
66
74
  test('read balance in a multicall', async () => {
67
75
  const args1 = { user: wallet };
68
76
  const args2 = {};
69
77
  const calls = [
70
- erc20.connectedTo,
78
+ erc20.address,
71
79
  getSelectorFromName('balance_of'),
72
80
  Object.keys(args1).length,
73
81
  ...compileCalldata(args1),
74
82
 
75
- erc20.connectedTo,
83
+ erc20.address,
76
84
  getSelectorFromName('decimals'),
77
85
  Object.keys(args2).length,
78
86
  ...compileCalldata(args2),
79
87
  ];
80
- const { block_number, result } = await contract.call('aggregate', { calls });
88
+ const result = await contract.aggregate(calls);
89
+ const [block_number, res] = result;
81
90
  expect(isBN(block_number));
82
- expect(Array.isArray(result));
83
- (result as BigNumberish[]).forEach((el) => expect(isBN(el)));
91
+ expect(Array.isArray(res));
92
+ (res as BigNumberish[]).forEach((el) => expect(isBN(el)));
93
+ expect(block_number).toStrictEqual(result.block_number);
94
+ expect(res).toStrictEqual(result.result);
84
95
  });
85
96
  });
86
97
 
@@ -98,101 +109,180 @@ describe('class Contract {}', () => {
98
109
 
99
110
  describe('Request Type Transformation', () => {
100
111
  test('Parsing the felt in request', async () => {
101
- return expect(contract.call('request_felt', { num: 3 })).resolves.not.toThrow();
112
+ return expect(contract.request_felt(3)).resolves.not.toThrow();
102
113
  });
103
114
 
104
115
  test('Parsing the array of felt in request', async () => {
105
- return expect(
106
- contract.call('request_array_of_felts', { arr: [1, 2] })
107
- ).resolves.not.toThrow();
116
+ return expect(contract.request_array_of_felts([1, 2])).resolves.not.toThrow();
108
117
  });
109
118
 
110
119
  test('Parsing the struct in request', async () => {
111
- return expect(
112
- contract.call('request_struct', {
113
- str: { x: 1, y: 2 },
114
- })
115
- ).resolves.not.toThrow();
120
+ return expect(contract.request_struct({ x: 1, y: 2 })).resolves.not.toThrow();
116
121
  });
117
122
 
118
123
  test('Parsing the array of structs in request', async () => {
119
- return expect(
120
- contract.call('request_array_of_structs', { str: [{ x: 1, y: 2 }] })
121
- ).resolves.not.toThrow();
124
+ return expect(contract.request_array_of_structs([{ x: 1, y: 2 }])).resolves.not.toThrow();
122
125
  });
123
126
 
124
127
  test('Parsing the nested structs in request', async () => {
125
128
  return expect(
126
- contract.call('request_nested_structs', {
127
- str: {
128
- p1: { x: 1, y: 2 },
129
- p2: { x: 3, y: 4 },
130
- extra: 5,
131
- },
129
+ contract.request_nested_structs({
130
+ p1: { x: 1, y: 2 },
131
+ p2: { x: 3, y: 4 },
132
+ extra: 5,
132
133
  })
133
134
  ).resolves.not.toThrow();
134
135
  });
135
136
 
136
137
  test('Parsing the tuple in request', async () => {
137
- return expect(contract.call('request_tuple', { tup: [1, 2] })).resolves.not.toThrow();
138
+ return expect(contract.request_tuple([1, 2])).resolves.not.toThrow();
138
139
  });
139
140
 
140
141
  test('Parsing the multiple types in request', async () => {
141
- return expect(
142
- contract.call('request_mixed_types', {
143
- num: 2,
144
- point: {
145
- x: 1,
146
- y: 2,
147
- },
148
- arr: [1],
149
- })
150
- ).resolves.not.toThrow();
142
+ return expect(contract.request_mixed_types(2, { x: 1, y: 2 }, [1])).resolves.not.toThrow();
151
143
  });
152
144
  });
153
145
 
154
146
  describe('Response Type Transformation', () => {
155
147
  test('Parsing the felt in response', async () => {
156
- const { res } = await contract.call('get_felt');
148
+ const { res } = await contract.get_felt();
157
149
  expect(res).toStrictEqual(toBN(4));
158
150
  });
159
151
 
160
152
  test('Parsing the array of felt in response', async () => {
161
- const { res } = await contract.call('get_array_of_felts');
153
+ const result = await contract.get_array_of_felts();
154
+ const [res] = result;
162
155
  expect(res).toStrictEqual([toBN(4), toBN(5)]);
156
+ expect(res).toStrictEqual(result.res);
163
157
  });
164
158
 
165
159
  test('Parsing the array of structs in response', async () => {
166
- const { res } = await contract.call('get_struct');
160
+ const result = await contract.get_struct();
161
+ const [res] = result;
167
162
  expect(res).toStrictEqual({ x: toBN(1), y: toBN(2) });
163
+ expect(res).toStrictEqual(result.res);
168
164
  });
169
165
 
170
166
  test('Parsing the array of structs in response', async () => {
171
- const { res } = await contract.call('get_array_of_structs');
167
+ const result = await contract.get_array_of_structs();
168
+ const [res] = result;
172
169
  expect(res).toStrictEqual([{ x: toBN(1), y: toBN(2) }]);
170
+ expect(res).toStrictEqual(result.res);
173
171
  });
174
172
 
175
173
  test('Parsing the nested structs in response', async () => {
176
- const { res } = await contract.call('get_nested_structs');
174
+ const result = await contract.get_nested_structs();
175
+ const [res] = result;
177
176
  expect(res).toStrictEqual({
178
177
  p1: { x: toBN(1), y: toBN(2) },
179
178
  p2: { x: toBN(3), y: toBN(4) },
180
179
  extra: toBN(5),
181
180
  });
181
+ expect(res).toStrictEqual(result.res);
182
182
  });
183
183
 
184
184
  test('Parsing the tuple in response', async () => {
185
- const { res } = await contract.call('get_tuple');
185
+ const result = await contract.get_tuple();
186
+ const [res] = result;
186
187
  expect(res).toStrictEqual([toBN(1), toBN(2), toBN(3)]);
188
+ expect(res).toStrictEqual(result.res);
187
189
  });
188
190
 
189
191
  test('Parsing the multiple types in response', async () => {
190
- const { tuple, number, array, point } = await contract.call('get_mixed_types');
192
+ const result = await contract.get_mixed_types();
193
+ const [tuple, number, array, point] = result;
191
194
  expect(tuple).toStrictEqual([toBN(1), toBN(2)]);
192
195
  expect(number).toStrictEqual(toBN(3));
193
196
  expect(array).toStrictEqual([toBN(4)]);
194
197
  expect(point).toStrictEqual({ x: toBN(1), y: toBN(2) });
198
+ expect(tuple).toStrictEqual(result.tuple);
199
+ expect(number).toStrictEqual(result.number);
200
+ expect(array).toStrictEqual(result.array);
201
+ expect(point).toStrictEqual(result.point);
202
+ });
203
+ });
204
+ });
205
+
206
+ describe('Contract interaction with Account', () => {
207
+ const starkKeyPair = ec.getKeyPair(PRIVATE_KEY);
208
+ let account: Account;
209
+ let erc20: Contract;
210
+ let erc20Address: string;
211
+
212
+ beforeAll(async () => {
213
+ account = new Account(defaultProvider, ACCOUNT_ADDRESS, starkKeyPair);
214
+
215
+ const erc20Response = await defaultProvider.deployContract({
216
+ contract: compiledErc20,
195
217
  });
218
+ erc20Address = erc20Response.address;
219
+ erc20 = new Contract(compiledErc20.abi, erc20Address, defaultProvider);
220
+ await defaultProvider.waitForTransaction(erc20Response.transaction_hash);
221
+ expect(erc20Response.code).toBe('TRANSACTION_RECEIVED');
222
+
223
+ const mintResponse = await erc20.mint(account.address, '1000');
224
+
225
+ await defaultProvider.waitForTransaction(mintResponse.transaction_hash);
226
+ });
227
+
228
+ test('read balance of wallet', async () => {
229
+ const result = await erc20.balance_of(account.address);
230
+ const [res] = result;
231
+ expect(res).toStrictEqual(toBN(1000));
232
+ expect(res).toStrictEqual(result.res);
196
233
  });
234
+
235
+ test('change from provider to account', async () => {
236
+ expect(erc20.providerOrAccount instanceof Provider);
237
+ erc20.connect(account);
238
+ expect(erc20.providerOrAccount instanceof Account);
239
+ });
240
+
241
+ test('estimate gas fee for `mint`', async () => {
242
+ const res = await erc20.estimateFee.mint(wallet, '10');
243
+ expect(res).toHaveProperty('amount');
244
+ expect(res).toHaveProperty('unit');
245
+ });
246
+
247
+ test('read balance of wallet', async () => {
248
+ const { res } = await erc20.balance_of(account.address);
249
+
250
+ expect(res).toStrictEqual(toBN(1000));
251
+ });
252
+
253
+ test('invoke contract by wallet owner', async () => {
254
+ const { transaction_hash, code } = await erc20.transfer(toBN(erc20Address).toString(), 10);
255
+ expect(code).toBe('TRANSACTION_RECEIVED');
256
+ await defaultProvider.waitForTransaction(transaction_hash);
257
+ const { res } = await erc20.balance_of(account.address);
258
+ expect(res).toStrictEqual(toBN(990));
259
+ });
260
+ });
261
+ });
262
+
263
+ describe('class ContractFactory {}', () => {
264
+ let erc20Address: string;
265
+ beforeAll(async () => {
266
+ const { code, transaction_hash, address } = await defaultProvider.deployContract({
267
+ contract: compiledErc20,
268
+ });
269
+ expect(code).toBe('TRANSACTION_RECEIVED');
270
+ await defaultProvider.waitForTransaction(transaction_hash);
271
+ erc20Address = address;
272
+ });
273
+ test('deployment of new contract', async () => {
274
+ const factory = new ContractFactory(compiledErc20);
275
+ const erc20 = await factory.deploy();
276
+ expect(erc20 instanceof Contract);
277
+ });
278
+ test('wait for deployment transaction', async () => {
279
+ const factory = new ContractFactory(compiledErc20);
280
+ const contract = await factory.deploy();
281
+ expect(contract.deployed()).resolves.not.toThrow();
282
+ });
283
+ test('attach new contract', async () => {
284
+ const factory = new ContractFactory(compiledErc20);
285
+ const erc20 = factory.attach(erc20Address);
286
+ expect(erc20 instanceof Contract);
197
287
  });
198
288
  });
@@ -93,6 +93,14 @@ describe('defaultProvider', () => {
93
93
  })
94
94
  ).resolves.not.toThrow();
95
95
  });
96
+
97
+ test('transaction trace', async () => {
98
+ const transactionTrace = await defaultProvider.getTransactionTrace(
99
+ '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
100
+ );
101
+ expect(transactionTrace).toHaveProperty('function_invocation');
102
+ expect(transactionTrace).toHaveProperty('signature');
103
+ });
96
104
  });
97
105
 
98
106
  describe('addTransaction()', () => {
@@ -17,9 +17,7 @@ test('isBrowser', () => {
17
17
  });
18
18
  describe('compressProgram()', () => {
19
19
  test('compresses a contract program', () => {
20
- const inputContract = compiledArgentAccount as any;
21
-
22
- const compressed = stark.compressProgram(inputContract.program);
20
+ const compressed = stark.compressProgram(compiledArgentAccount.program);
23
21
 
24
22
  expect(compressed).toMatchSnapshot();
25
23
  });
@@ -3,6 +3,7 @@ import {
3
3
  Abi,
4
4
  AddTransactionResponse,
5
5
  Call,
6
+ EstimateFeeResponse,
6
7
  InvocationsDetails,
7
8
  KeyPair,
8
9
  Signature,
@@ -16,6 +17,7 @@ export declare class Account extends Provider implements AccountInterface {
16
17
  private signer;
17
18
  constructor(provider: Provider, address: string, keyPair: KeyPair);
18
19
  getNonce(): Promise<string>;
20
+ estimateFee(calls: Call | Call[]): Promise<EstimateFeeResponse>;
19
21
  /**
20
22
  * Invoke execute function in account contract
21
23
  *