starknet 3.2.0 → 3.5.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 (67) hide show
  1. package/.eslintrc +2 -1
  2. package/CHANGELOG.md +32 -0
  3. package/__tests__/account.test.ts +11 -21
  4. package/__tests__/accountContract.test.ts +15 -27
  5. package/__tests__/contract.test.ts +156 -59
  6. package/__tests__/utils/utils.browser.test.ts +1 -3
  7. package/account/default.d.ts +6 -0
  8. package/account/default.js +129 -0
  9. package/contract/contractFactory.d.ts +36 -0
  10. package/contract/contractFactory.js +218 -0
  11. package/contract/default.d.ts +143 -0
  12. package/{contract.js → contract/default.js} +357 -86
  13. package/contract/index.d.ts +3 -0
  14. package/contract/index.js +28 -0
  15. package/contract/interface.d.ts +79 -0
  16. package/contract/interface.js +8 -0
  17. package/dist/account/default.d.ts +6 -1
  18. package/dist/account/default.js +99 -0
  19. package/dist/contract/contractFactory.d.ts +32 -0
  20. package/dist/contract/contractFactory.js +102 -0
  21. package/dist/contract/default.d.ts +121 -0
  22. package/dist/{contract.js → contract/default.js} +321 -73
  23. package/dist/contract/index.d.ts +3 -0
  24. package/dist/contract/index.js +15 -0
  25. package/dist/contract/interface.d.ts +72 -0
  26. package/dist/contract/interface.js +9 -0
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.js +1 -1
  29. package/dist/provider/default.d.ts +10 -5
  30. package/dist/provider/default.js +29 -11
  31. package/dist/provider/interface.d.ts +8 -2
  32. package/dist/types/api.d.ts +6 -0
  33. package/dist/types/contract.d.ts +5 -0
  34. package/dist/types/contract.js +2 -0
  35. package/dist/types/index.d.ts +1 -0
  36. package/dist/types/index.js +1 -0
  37. package/dist/types/lib.d.ts +11 -1
  38. package/dist/utils/transaction.d.ts +1 -2
  39. package/index.d.ts +1 -1
  40. package/index.js +1 -1
  41. package/package.json +1 -1
  42. package/provider/default.d.ts +10 -5
  43. package/provider/default.js +41 -21
  44. package/provider/interface.d.ts +8 -2
  45. package/src/account/default.ts +109 -1
  46. package/src/contract/contractFactory.ts +78 -0
  47. package/src/contract/default.ts +622 -0
  48. package/src/contract/index.ts +3 -0
  49. package/src/contract/interface.ts +87 -0
  50. package/src/index.ts +1 -1
  51. package/src/provider/default.ts +29 -19
  52. package/src/provider/interface.ts +9 -2
  53. package/src/types/api.ts +7 -0
  54. package/src/types/contract.ts +5 -0
  55. package/src/types/index.ts +1 -0
  56. package/src/types/lib.ts +12 -1
  57. package/src/utils/transaction.ts +1 -2
  58. package/types/api.d.ts +6 -0
  59. package/types/contract.d.ts +5 -0
  60. package/types/contract.js +2 -0
  61. package/types/index.d.ts +1 -0
  62. package/types/index.js +1 -0
  63. package/types/lib.d.ts +11 -1
  64. package/utils/transaction.d.ts +1 -2
  65. package/contract.d.ts +0 -98
  66. package/dist/contract.d.ts +0 -94
  67. 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,35 @@
1
+ # [3.5.0](https://github.com/seanjameshan/starknet.js/compare/v3.4.0...v3.5.0) (2022-03-11)
2
+
3
+ ### Bug Fixes
4
+
5
+ - contract test ([a9b4103](https://github.com/seanjameshan/starknet.js/commit/a9b410356baa5c7305da9ba69229c0882f7ae026))
6
+ - **contract-factory:** move more towards ethers.js api ([4caa6ce](https://github.com/seanjameshan/starknet.js/commit/4caa6cee282fe73bc6fb91bea59c620cc42d31a0))
7
+ - **contract:** structure change ([1ef9d2f](https://github.com/seanjameshan/starknet.js/commit/1ef9d2fee0158c9894d5e049f59cc72bfaad2d55))
8
+ - **contract:** tests for new contract interface ([9273f54](https://github.com/seanjameshan/starknet.js/commit/9273f542b087e2940e0d2e88ecbeec58062953bf))
9
+ - enable validateMethodAndArgs on call ([efa63d6](https://github.com/seanjameshan/starknet.js/commit/efa63d6fc7ae77b28f694640833cec73111b175d))
10
+ - reverting validateMethodAndArgs changes ([d847fa8](https://github.com/seanjameshan/starknet.js/commit/d847fa8e4db3563d67861873046f9cb87d0fff8e))
11
+
12
+ ### Features
13
+
14
+ - **contractFactory:** lib expanded with contract factory ([2c9c3d1](https://github.com/seanjameshan/starknet.js/commit/2c9c3d1b60961ddd698dc6b3175fff2f574f03bd))
15
+ - **contract:** implement `contract.deployed() ⇒ Promise<Contract>` ([91f4992](https://github.com/seanjameshan/starknet.js/commit/91f4992a3f612a03ff5cde01d07a487ebb883f6d))
16
+ - **contract:** new contract interface ([01eeae8](https://github.com/seanjameshan/starknet.js/commit/01eeae815619009de195a759891cad9d8ec992c7))
17
+ - **contract:** new contract methods signature ([cc87943](https://github.com/seanjameshan/starknet.js/commit/cc8794362d2f20816aabf7b44596035d644a434d))
18
+ - default contract args ([2a3956d](https://github.com/seanjameshan/starknet.js/commit/2a3956dab88f3e68a513916b1644fa0723c5235f))
19
+ - **provider:** preparation for the fee integration ([c1c231b](https://github.com/seanjameshan/starknet.js/commit/c1c231b6ec803b01af280baf61d0afbc3f9be6bb))
20
+
21
+ # [3.4.0](https://github.com/seanjameshan/starknet.js/compare/v3.3.0...v3.4.0) (2022-03-10)
22
+
23
+ ### Features
24
+
25
+ - **account:** add legacy `addTransaction` method ([94f5d87](https://github.com/seanjameshan/starknet.js/commit/94f5d874c8fb5f6c6586d537b75b92f493a32676))
26
+
27
+ # [3.3.0](https://github.com/seanjameshan/starknet.js/compare/v3.2.0...v3.3.0) (2022-03-08)
28
+
29
+ ### Features
30
+
31
+ - **provider:** add back legacy `invokeFunction` ([dbd00ff](https://github.com/seanjameshan/starknet.js/commit/dbd00ff822456f05df5ba1967d5cd0040b012fc0))
32
+
1
33
  # [3.2.0](https://github.com/seanjameshan/starknet.js/compare/v3.1.0...v3.2.0) (2022-03-04)
2
34
 
3
35
  ### 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({
@@ -47,7 +41,7 @@ describe('deploy and test Wallet', () => {
47
41
  });
48
42
  dapp = new Contract(compiledTestDapp.abi, dappResponse.address);
49
43
  expect(dappResponse.code).toBe('TRANSACTION_RECEIVED');
50
- await defaultProvider.waitForTx(dappResponse.transaction_hash);
44
+ await defaultProvider.waitForTransaction(dappResponse.transaction_hash);
51
45
  });
52
46
 
53
47
  test('same wallet address', () => {
@@ -65,9 +59,7 @@ describe('deploy and test Wallet', () => {
65
59
  });
66
60
 
67
61
  test('read balance of wallet', async () => {
68
- const { res } = await erc20.call('balance_of', {
69
- user: account.address,
70
- });
62
+ const { res } = await erc20.balance_of(account.address);
71
63
 
72
64
  expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(1000).toString());
73
65
  });
@@ -80,13 +72,11 @@ describe('deploy and test Wallet', () => {
80
72
  });
81
73
 
82
74
  expect(code).toBe('TRANSACTION_RECEIVED');
83
- await defaultProvider.waitForTx(transaction_hash);
75
+ await defaultProvider.waitForTransaction(transaction_hash);
84
76
  });
85
77
 
86
78
  test('read balance of wallet after transfer', async () => {
87
- const { res } = await erc20.call('balance_of', {
88
- user: account.address,
89
- });
79
+ const { res } = await erc20.balance_of(account.address);
90
80
 
91
81
  expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(990).toString());
92
82
  });
@@ -108,27 +98,27 @@ describe('deploy and test Wallet', () => {
108
98
  );
109
99
 
110
100
  expect(code).toBe('TRANSACTION_RECEIVED');
111
- await defaultProvider.waitForTx(transaction_hash);
101
+ await defaultProvider.waitForTransaction(transaction_hash);
112
102
  });
113
103
 
114
104
  test('execute multiple transactions', async () => {
115
105
  const { code, transaction_hash } = await account.execute([
116
106
  {
117
- contractAddress: dapp.connectedTo,
107
+ contractAddress: dapp.address,
118
108
  entrypoint: 'set_number',
119
109
  calldata: ['47'],
120
110
  },
121
111
  {
122
- contractAddress: dapp.connectedTo,
112
+ contractAddress: dapp.address,
123
113
  entrypoint: 'increase_number',
124
114
  calldata: ['10'],
125
115
  },
126
116
  ]);
127
117
 
128
118
  expect(code).toBe('TRANSACTION_RECEIVED');
129
- await defaultProvider.waitForTx(transaction_hash);
119
+ await defaultProvider.waitForTransaction(transaction_hash);
130
120
 
131
- const response = await dapp.call('get_number', { user: account.address });
121
+ const response = await dapp.get_number(account.address);
132
122
  expect(toBN(response.number as string).toString()).toStrictEqual('57');
133
123
  });
134
124
 
@@ -38,10 +38,7 @@ describe('deploy and test Wallet', () => {
38
38
  accountContract = new Contract(compiledArgentAccount.abi, accountResponse.address);
39
39
  expect(accountResponse.code).toBe('TRANSACTION_RECEIVED');
40
40
 
41
- const initializeResponse = await accountContract.invoke('initialize', {
42
- signer: starkKeyPub,
43
- guardian: '0',
44
- });
41
+ const initializeResponse = await accountContract.initialize(starkKeyPub, '0');
45
42
  expect(initializeResponse.code).toBe('TRANSACTION_RECEIVED');
46
43
 
47
44
  const erc20Response = await defaultProvider.deployContract({
@@ -51,58 +48,49 @@ describe('deploy and test Wallet', () => {
51
48
  erc20 = new Contract(compiledErc20.abi, erc20Address);
52
49
  expect(erc20Response.code).toBe('TRANSACTION_RECEIVED');
53
50
 
54
- const mintResponse = await erc20.invoke('mint', {
55
- recipient: accountContract.connectedTo,
56
- amount: '1000',
57
- });
51
+ const mintResponse = await erc20.mint(accountContract.address, '1000');
58
52
  expect(mintResponse.code).toBe('TRANSACTION_RECEIVED');
59
- await defaultProvider.waitForTx(mintResponse.transaction_hash);
53
+ await defaultProvider.waitForTransaction(mintResponse.transaction_hash);
60
54
  });
61
55
 
62
56
  test('read nonce', async () => {
63
- const { nonce } = await accountContract.call('get_nonce');
57
+ const { nonce } = await accountContract.get_nonce();
64
58
 
65
59
  expect(number.toBN(nonce as string).toString()).toStrictEqual(number.toBN(0).toString());
66
60
  });
67
61
 
68
62
  test('read balance of wallet', async () => {
69
- const { res } = await erc20.call('balance_of', {
70
- user: accountContract.connectedTo,
71
- });
63
+ const { res } = await erc20.balance_of(accountContract.address);
72
64
 
73
- expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(1000).toString());
65
+ expect(res).toStrictEqual(number.toBN(1000));
74
66
  });
75
67
 
76
68
  test('execute by wallet owner', async () => {
77
- const nonce = (await accountContract.call('get_nonce')).nonce.toString();
69
+ const nonce = (await accountContract.get_nonce()).nonce.toString();
78
70
 
79
71
  const calls = [
80
72
  { contractAddress: erc20Address, entrypoint: 'transfer', calldata: [erc20Address, '10'] },
81
73
  ];
82
- const msgHash = hash.hashMulticall(accountContract.connectedTo, calls, nonce, '0');
74
+ const msgHash = hash.hashMulticall(accountContract.address, calls, nonce, '0');
83
75
 
84
76
  const { callArray, calldata } = transformCallsToMulticallArrays(calls);
85
77
 
86
78
  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
- },
79
+ // eslint-disable-next-line no-underscore-dangle
80
+ const { code, transaction_hash } = await accountContract.__execute__(
81
+ callArray,
82
+ calldata,
83
+ nonce,
94
84
  signature
95
85
  );
96
86
 
97
87
  expect(code).toBe('TRANSACTION_RECEIVED');
98
88
 
99
- await defaultProvider.waitForTx(transaction_hash);
89
+ await defaultProvider.waitForTransaction(transaction_hash);
100
90
  });
101
91
 
102
92
  test('read balance of wallet after transfer', async () => {
103
- const { res } = await erc20.call('balance_of', {
104
- user: accountContract.connectedTo,
105
- });
93
+ const { res } = await erc20.balance_of(accountContract.address);
106
94
 
107
95
  expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(990).toString());
108
96
  });
@@ -1,10 +1,15 @@
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 { compiledErc20, compiledMulticall, compiledTypeTransformation } from './fixtures';
7
+ import {
8
+ compiledArgentAccount,
9
+ compiledErc20,
10
+ compiledMulticall,
11
+ compiledTypeTransformation,
12
+ } from './fixtures';
8
13
 
9
14
  describe('class Contract {}', () => {
10
15
  const wallet = stark.randomAddress();
@@ -19,8 +24,7 @@ describe('class Contract {}', () => {
19
24
  });
20
25
  erc20 = new Contract(compiledErc20.abi, address, defaultProvider);
21
26
  expect(code).toBe('TRANSACTION_RECEIVED');
22
- await defaultProvider.waitForTx(transaction_hash);
23
-
27
+ await defaultProvider.waitForTransaction(transaction_hash);
24
28
  // Deploy Multicall
25
29
 
26
30
  const {
@@ -35,52 +39,59 @@ describe('class Contract {}', () => {
35
39
 
36
40
  expect(m_code).toBe('TRANSACTION_RECEIVED');
37
41
 
38
- await defaultProvider.waitForTx(m_transaction_hash);
42
+ await defaultProvider.waitForTransaction(m_transaction_hash);
43
+ });
44
+
45
+ test('populate transaction for initial balance of that account', async () => {
46
+ const res = await erc20.populateTransaction.balance_of(wallet);
47
+ expect(res).toHaveProperty('contractAddress');
48
+ expect(res).toHaveProperty('entrypoint');
49
+ expect(res).toHaveProperty('calldata');
50
+ expect(res).toHaveProperty('signature');
39
51
  });
40
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
- await defaultProvider.waitForTx(response.transaction_hash);
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
 
@@ -93,106 +104,192 @@ describe('class Contract {}', () => {
93
104
  });
94
105
  contract = new Contract(compiledTypeTransformation.abi, address, defaultProvider);
95
106
  expect(code).toBe('TRANSACTION_RECEIVED');
96
- await defaultProvider.waitForTx(transaction_hash);
107
+ await defaultProvider.waitForTransaction(transaction_hash);
97
108
  });
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);
195
202
  });
196
203
  });
197
204
  });
205
+
206
+ describe('Contract interaction with Account', () => {
207
+ const privateKey = stark.randomAddress();
208
+
209
+ const starkKeyPair = ec.getKeyPair(privateKey);
210
+ const starkKeyPub = ec.getStarkKey(starkKeyPair);
211
+ let account: Account;
212
+ let erc20: Contract;
213
+ let erc20Address: string;
214
+
215
+ beforeAll(async () => {
216
+ const accountResponse = await defaultProvider.deployContract({
217
+ contract: compiledArgentAccount,
218
+ addressSalt: starkKeyPub,
219
+ });
220
+ const contract = new Contract(compiledArgentAccount.abi, accountResponse.address);
221
+ expect(accountResponse.code).toBe('TRANSACTION_RECEIVED');
222
+
223
+ const initializeResponse = await contract.initialize(starkKeyPub, '0');
224
+ expect(initializeResponse.code).toBe('TRANSACTION_RECEIVED');
225
+
226
+ account = new Account(defaultProvider, accountResponse.address, starkKeyPair);
227
+
228
+ const erc20Response = await defaultProvider.deployContract({
229
+ contract: compiledErc20,
230
+ });
231
+ erc20Address = erc20Response.address;
232
+ erc20 = new Contract(compiledErc20.abi, erc20Address, defaultProvider);
233
+ await defaultProvider.waitForTransaction(erc20Response.transaction_hash);
234
+ expect(erc20Response.code).toBe('TRANSACTION_RECEIVED');
235
+
236
+ const mintResponse = await erc20.mint(account.address, '1000');
237
+
238
+ await defaultProvider.waitForTransaction(mintResponse.transaction_hash);
239
+ });
240
+
241
+ test('read balance of wallet', async () => {
242
+ const result = await erc20.balance_of(account.address);
243
+ const [res] = result;
244
+ expect(res).toStrictEqual(toBN(1000));
245
+ expect(res).toStrictEqual(result.res);
246
+ });
247
+
248
+ test('change from provider to account', async () => {
249
+ expect(erc20.providerOrAccount instanceof Provider);
250
+ erc20.connect(account);
251
+ expect(erc20.providerOrAccount instanceof Account);
252
+ });
253
+
254
+ test('read balance of wallet', async () => {
255
+ const { res } = await erc20.balance_of(account.address);
256
+
257
+ expect(res).toStrictEqual(toBN(1000));
258
+ });
259
+
260
+ test('invoke contract by wallet owner', async () => {
261
+ const { transaction_hash, code } = await erc20.transfer(toBN(erc20Address).toString(), 10);
262
+ expect(code).toBe('TRANSACTION_RECEIVED');
263
+ await defaultProvider.waitForTransaction(transaction_hash);
264
+ const { res } = await erc20.balance_of(account.address);
265
+ expect(res).toStrictEqual(toBN(990));
266
+ });
267
+ });
268
+ });
269
+
270
+ describe('class ContractFactory {}', () => {
271
+ let erc20Address: string;
272
+ beforeAll(async () => {
273
+ const { code, transaction_hash, address } = await defaultProvider.deployContract({
274
+ contract: compiledErc20,
275
+ });
276
+ expect(code).toBe('TRANSACTION_RECEIVED');
277
+ await defaultProvider.waitForTransaction(transaction_hash);
278
+ erc20Address = address;
279
+ });
280
+ test('deployment of new contract', async () => {
281
+ const factory = new ContractFactory(compiledErc20);
282
+ const erc20 = await factory.deploy();
283
+ expect(erc20 instanceof Contract);
284
+ });
285
+ test('wait for deployment transaction', async () => {
286
+ const factory = new ContractFactory(compiledErc20);
287
+ const contract = await factory.deploy();
288
+ expect(contract.deployed()).resolves.not.toThrow();
289
+ });
290
+ test('attach new contract', async () => {
291
+ const factory = new ContractFactory(compiledErc20);
292
+ const erc20 = factory.attach(erc20Address);
293
+ expect(erc20 instanceof Contract);
294
+ });
198
295
  });
@@ -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
  });
@@ -6,6 +6,7 @@ import {
6
6
  InvocationsDetails,
7
7
  KeyPair,
8
8
  Signature,
9
+ Transaction,
9
10
  } from '../types';
10
11
  import { BigNumberish } from '../utils/number';
11
12
  import { TypedData } from '../utils/typedData';
@@ -28,6 +29,11 @@ export declare class Account extends Provider implements AccountInterface {
28
29
  abis?: Abi[] | undefined,
29
30
  transactionsDetail?: InvocationsDetails
30
31
  ): Promise<AddTransactionResponse>;
32
+ /**
33
+ * Temporary method to allow dapps on starknet.js v2 to work with Argent X v3
34
+ * @deprecated to remove ASAP
35
+ */
36
+ LEGACY_addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
31
37
  /**
32
38
  * Sign an JSON object with the starknet private key and return the signature
33
39
  *