starknet 3.1.0 → 3.4.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 (71) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/__mocks__/ArgentAccount.json +68548 -51944
  3. package/__mocks__/TestDapp.json +12962 -0
  4. package/__tests__/account.test.ts +63 -50
  5. package/__tests__/accountContract.test.ts +51 -71
  6. package/__tests__/contract.test.ts +32 -20
  7. package/__tests__/fixtures.ts +13 -0
  8. package/__tests__/provider.test.ts +3 -15
  9. package/__tests__/utils/__snapshots__/utils.browser.test.ts.snap +2 -2
  10. package/__tests__/utils/__snapshots__/utils.test.ts.snap +2 -2
  11. package/__tests__/utils/ellipticalCurve.test.ts +20 -13
  12. package/__tests__/utils/utils.test.ts +3 -3
  13. package/account/default.d.ts +10 -4
  14. package/account/default.js +165 -84
  15. package/account/interface.d.ts +2 -2
  16. package/dist/account/default.d.ts +8 -3
  17. package/dist/account/default.js +129 -55
  18. package/dist/account/interface.d.ts +2 -2
  19. package/dist/index.d.ts +1 -0
  20. package/dist/index.js +1 -0
  21. package/dist/provider/default.d.ts +6 -4
  22. package/dist/provider/default.js +42 -17
  23. package/dist/provider/interface.d.ts +5 -1
  24. package/dist/signer/default.d.ts +1 -1
  25. package/dist/signer/default.js +6 -18
  26. package/dist/signer/interface.d.ts +3 -2
  27. package/dist/types/api.d.ts +5 -0
  28. package/dist/types/lib.d.ts +3 -3
  29. package/dist/utils/ellipticCurve.js +1 -1
  30. package/dist/utils/hash.d.ts +12 -2
  31. package/dist/utils/hash.js +37 -9
  32. package/dist/utils/stark.d.ts +0 -8
  33. package/dist/utils/stark.js +1 -14
  34. package/dist/utils/transaction.d.ts +19 -0
  35. package/dist/utils/transaction.js +75 -0
  36. package/dist/utils/typedData/index.d.ts +1 -1
  37. package/dist/utils/typedData/index.js +2 -3
  38. package/index.d.ts +1 -0
  39. package/index.js +1 -0
  40. package/package.json +1 -1
  41. package/provider/default.d.ts +6 -4
  42. package/provider/default.js +55 -19
  43. package/provider/interface.d.ts +5 -1
  44. package/signer/default.d.ts +1 -1
  45. package/signer/default.js +10 -44
  46. package/signer/interface.d.ts +3 -2
  47. package/src/account/default.ts +129 -42
  48. package/src/account/interface.ts +2 -2
  49. package/src/index.ts +1 -0
  50. package/src/provider/default.ts +32 -22
  51. package/src/provider/interface.ts +6 -1
  52. package/src/signer/default.ts +10 -26
  53. package/src/signer/interface.ts +3 -2
  54. package/src/types/api.ts +5 -0
  55. package/src/types/lib.ts +3 -4
  56. package/src/utils/ellipticCurve.ts +1 -1
  57. package/src/utils/hash.ts +39 -12
  58. package/src/utils/stark.ts +1 -14
  59. package/src/utils/transaction.ts +50 -0
  60. package/src/utils/typedData/index.ts +2 -3
  61. package/types/api.d.ts +5 -0
  62. package/types/lib.d.ts +3 -3
  63. package/utils/ellipticCurve.js +1 -1
  64. package/utils/hash.d.ts +15 -6
  65. package/utils/hash.js +42 -10
  66. package/utils/stark.d.ts +0 -8
  67. package/utils/stark.js +0 -14
  68. package/utils/transaction.d.ts +19 -0
  69. package/utils/transaction.js +99 -0
  70. package/utils/typedData/index.d.ts +1 -1
  71. package/utils/typedData/index.js +2 -3
@@ -1,72 +1,59 @@
1
- import fs from 'fs';
2
-
3
1
  import typedDataExample from '../__mocks__/typedDataExample.json';
4
- import {
5
- Account,
6
- CompiledContract,
7
- Contract,
8
- defaultProvider,
9
- ec,
10
- json,
11
- number,
12
- stark,
13
- } from '../src';
2
+ import { Account, Contract, defaultProvider, ec, number, stark } from '../src';
14
3
  import { toBN } from '../src/utils/number';
15
-
16
- const { compileCalldata } = stark;
17
-
18
- const compiledArgentAccount: CompiledContract = json.parse(
19
- fs.readFileSync('./__mocks__/ArgentAccount.json').toString('ascii')
20
- );
21
- const compiledErc20: CompiledContract = json.parse(
22
- fs.readFileSync('./__mocks__/ERC20.json').toString('ascii')
23
- );
4
+ import { compiledArgentAccount, compiledErc20, compiledTestDapp } from './fixtures';
24
5
 
25
6
  describe('deploy and test Wallet', () => {
26
7
  const privateKey = stark.randomAddress();
27
8
 
28
9
  const starkKeyPair = ec.getKeyPair(privateKey);
29
10
  const starkKeyPub = ec.getStarkKey(starkKeyPair);
30
- let walletAddress: string;
11
+ let account: Account;
31
12
  let erc20: Contract;
32
13
  let erc20Address: string;
33
- let account: Account;
14
+ let dapp: Contract;
34
15
 
35
16
  beforeAll(async () => {
36
- const { code: codeErc20, address: erc20AddressLocal } = await defaultProvider.deployContract({
37
- contract: compiledErc20,
38
- });
39
- erc20Address = erc20AddressLocal;
40
- erc20 = new Contract(compiledErc20.abi, erc20Address);
41
-
42
- expect(codeErc20).toBe('TRANSACTION_RECEIVED');
43
-
44
- const { code, address: walletAddressLocal } = await defaultProvider.deployContract({
17
+ const accountResponse = await defaultProvider.deployContract({
45
18
  contract: compiledArgentAccount,
46
- constructorCalldata: compileCalldata({
47
- signer: starkKeyPub,
48
- guardian: '0',
49
- L1_address: '0',
50
- }),
51
19
  addressSalt: starkKeyPub,
52
20
  });
53
- walletAddress = walletAddressLocal;
54
- expect(code).toBe('TRANSACTION_RECEIVED');
21
+ const contract = new Contract(compiledArgentAccount.abi, accountResponse.address);
22
+ expect(accountResponse.code).toBe('TRANSACTION_RECEIVED');
55
23
 
56
- const { code: codeErc20Mint, transaction_hash: txErc20Mint } = await erc20.invoke('mint', {
57
- recipient: walletAddress,
58
- amount: '1000',
24
+ const initializeResponse = await contract.invoke('initialize', {
25
+ signer: starkKeyPub,
26
+ guardian: '0',
59
27
  });
28
+ expect(initializeResponse.code).toBe('TRANSACTION_RECEIVED');
60
29
 
61
- expect(codeErc20Mint).toBe('TRANSACTION_RECEIVED');
30
+ account = new Account(defaultProvider, accountResponse.address, starkKeyPair);
62
31
 
63
- account = new Account(defaultProvider, walletAddressLocal, starkKeyPair);
32
+ const erc20Response = await defaultProvider.deployContract({
33
+ contract: compiledErc20,
34
+ });
35
+ erc20Address = erc20Response.address;
36
+ erc20 = new Contract(compiledErc20.abi, erc20Address);
37
+ expect(erc20Response.code).toBe('TRANSACTION_RECEIVED');
38
+
39
+ const mintResponse = await erc20.invoke('mint', {
40
+ recipient: account.address,
41
+ amount: '1000',
42
+ });
43
+ expect(mintResponse.code).toBe('TRANSACTION_RECEIVED');
64
44
 
65
- await defaultProvider.waitForTx(txErc20Mint);
45
+ const dappResponse = await defaultProvider.deployContract({
46
+ contract: compiledTestDapp,
47
+ });
48
+ dapp = new Contract(compiledTestDapp.abi, dappResponse.address);
49
+ expect(dappResponse.code).toBe('TRANSACTION_RECEIVED');
50
+ await defaultProvider.waitForTransaction(dappResponse.transaction_hash);
66
51
  });
52
+
67
53
  test('same wallet address', () => {
68
- expect(walletAddress).toBe(account.address);
54
+ expect(account.address).toBe(account.address);
69
55
  });
56
+
70
57
  test('read nonce', async () => {
71
58
  const { result } = await account.callContract({
72
59
  contractAddress: account.address,
@@ -76,13 +63,15 @@ describe('deploy and test Wallet', () => {
76
63
 
77
64
  expect(number.toBN(nonce).toString()).toStrictEqual(number.toBN(0).toString());
78
65
  });
66
+
79
67
  test('read balance of wallet', async () => {
80
68
  const { res } = await erc20.call('balance_of', {
81
- user: walletAddress,
69
+ user: account.address,
82
70
  });
83
71
 
84
72
  expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(1000).toString());
85
73
  });
74
+
86
75
  test('execute by wallet owner', async () => {
87
76
  const { code, transaction_hash } = await account.execute({
88
77
  contractAddress: erc20Address,
@@ -91,15 +80,17 @@ describe('deploy and test Wallet', () => {
91
80
  });
92
81
 
93
82
  expect(code).toBe('TRANSACTION_RECEIVED');
94
- await defaultProvider.waitForTx(transaction_hash);
83
+ await defaultProvider.waitForTransaction(transaction_hash);
95
84
  });
85
+
96
86
  test('read balance of wallet after transfer', async () => {
97
87
  const { res } = await erc20.call('balance_of', {
98
- user: walletAddress,
88
+ user: account.address,
99
89
  });
100
90
 
101
91
  expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(990).toString());
102
92
  });
93
+
103
94
  test('execute with custom nonce', async () => {
104
95
  const { result } = await account.callContract({
105
96
  contractAddress: account.address,
@@ -117,8 +108,30 @@ describe('deploy and test Wallet', () => {
117
108
  );
118
109
 
119
110
  expect(code).toBe('TRANSACTION_RECEIVED');
120
- await defaultProvider.waitForTx(transaction_hash);
111
+ await defaultProvider.waitForTransaction(transaction_hash);
121
112
  });
113
+
114
+ 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
+ ]);
127
+
128
+ expect(code).toBe('TRANSACTION_RECEIVED');
129
+ await defaultProvider.waitForTransaction(transaction_hash);
130
+
131
+ const response = await dapp.call('get_number', { user: account.address });
132
+ expect(toBN(response.number as string).toString()).toStrictEqual('57');
133
+ });
134
+
122
135
  test('sign and verify offchain message', async () => {
123
136
  const signature = await account.signMessage(typedDataExample);
124
137
 
@@ -1,18 +1,6 @@
1
- import fs from 'fs';
2
-
3
- import {
4
- CompiledContract,
5
- Contract,
6
- defaultProvider,
7
- ec,
8
- encode,
9
- hash,
10
- json,
11
- number,
12
- stark,
13
- } from '../src';
14
-
15
- const { compileCalldata } = stark;
1
+ import { Contract, defaultProvider, ec, hash, number, stark } from '../src';
2
+ import { transformCallsToMulticallArrays } from '../src/utils/transaction';
3
+ import { compiledArgentAccount, compiledErc20 } from './fixtures';
16
4
 
17
5
  describe('getStarkAccountFromPrivateKey()', () => {
18
6
  test('it works with valid privateKey', () => {
@@ -33,96 +21,87 @@ describe('getStarkAccountFromPrivateKey()', () => {
33
21
  });
34
22
  });
35
23
 
36
- const compiledArgentAccount: CompiledContract = json.parse(
37
- fs.readFileSync('./__mocks__/ArgentAccount.json').toString('ascii')
38
- );
39
- const compiledErc20: CompiledContract = json.parse(
40
- fs.readFileSync('./__mocks__/ERC20.json').toString('ascii')
41
- );
42
-
43
24
  describe('deploy and test Wallet', () => {
44
25
  const privateKey = stark.randomAddress();
45
26
 
46
27
  const starkKeyPair = ec.getKeyPair(privateKey);
47
28
  const starkKeyPub = ec.getStarkKey(starkKeyPair);
48
- let wallet: Contract;
49
- let walletAddress: string;
29
+ let accountContract: Contract;
50
30
  let erc20: Contract;
51
31
  let erc20Address: string;
52
- beforeAll(async () => {
53
- const { code: codeErc20, address: erc20AddressLocal } = await defaultProvider.deployContract({
54
- contract: compiledErc20,
55
- });
56
- erc20Address = erc20AddressLocal;
57
- erc20 = new Contract(compiledErc20.abi, erc20Address);
58
-
59
- expect(codeErc20).toBe('TRANSACTION_RECEIVED');
60
32
 
61
- const { code, address: walletAddressLocal } = await defaultProvider.deployContract({
33
+ beforeAll(async () => {
34
+ const accountResponse = await defaultProvider.deployContract({
62
35
  contract: compiledArgentAccount,
63
- constructorCalldata: compileCalldata({
64
- signer: starkKeyPub,
65
- guardian: '0',
66
- L1_address: '0',
67
- }),
68
36
  addressSalt: starkKeyPub,
69
37
  });
70
- walletAddress = walletAddressLocal;
71
- wallet = new Contract(compiledArgentAccount.abi, walletAddress);
72
- expect(code).toBe('TRANSACTION_RECEIVED');
38
+ accountContract = new Contract(compiledArgentAccount.abi, accountResponse.address);
39
+ expect(accountResponse.code).toBe('TRANSACTION_RECEIVED');
73
40
 
74
- const { code: codeErc20Mint, transaction_hash: txErc20Mint } = await erc20.invoke('mint', {
75
- recipient: walletAddress,
76
- amount: '1000',
41
+ const initializeResponse = await accountContract.invoke('initialize', {
42
+ signer: starkKeyPub,
43
+ guardian: '0',
77
44
  });
45
+ expect(initializeResponse.code).toBe('TRANSACTION_RECEIVED');
78
46
 
79
- expect(codeErc20Mint).toBe('TRANSACTION_RECEIVED');
47
+ const erc20Response = await defaultProvider.deployContract({
48
+ contract: compiledErc20,
49
+ });
50
+ erc20Address = erc20Response.address;
51
+ erc20 = new Contract(compiledErc20.abi, erc20Address);
52
+ expect(erc20Response.code).toBe('TRANSACTION_RECEIVED');
80
53
 
81
- await defaultProvider.waitForTx(txErc20Mint);
54
+ const mintResponse = await erc20.invoke('mint', {
55
+ recipient: accountContract.connectedTo,
56
+ amount: '1000',
57
+ });
58
+ expect(mintResponse.code).toBe('TRANSACTION_RECEIVED');
59
+ await defaultProvider.waitForTransaction(mintResponse.transaction_hash);
82
60
  });
61
+
83
62
  test('read nonce', async () => {
84
- const { nonce } = await wallet.call('get_nonce');
63
+ const { nonce } = await accountContract.call('get_nonce');
85
64
 
86
65
  expect(number.toBN(nonce as string).toString()).toStrictEqual(number.toBN(0).toString());
87
66
  });
67
+
88
68
  test('read balance of wallet', async () => {
89
69
  const { res } = await erc20.call('balance_of', {
90
- user: walletAddress,
70
+ user: accountContract.connectedTo,
91
71
  });
92
72
 
93
73
  expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(1000).toString());
94
74
  });
75
+
95
76
  test('execute by wallet owner', async () => {
96
- const { nonce } = await wallet.call('get_nonce');
97
- const msgHash = encode.addHexPrefix(
98
- hash.hashMessage(
99
- wallet.connectedTo,
100
- erc20Address,
101
- stark.getSelectorFromName('transfer'),
102
- [erc20Address, '10'],
103
- nonce.toString()
104
- )
105
- );
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);
106
85
 
107
86
  const signature = ec.sign(starkKeyPair, msgHash);
108
- const { code, transaction_hash } = await wallet.invoke(
109
- 'execute',
87
+ const { code, transaction_hash } = await accountContract.invoke(
88
+ '__execute__',
110
89
  {
111
- to: erc20Address,
112
- selector: stark.getSelectorFromName('transfer'),
113
- calldata: [erc20Address, '10'],
114
- nonce: nonce.toString(),
90
+ call_array: callArray,
91
+ calldata,
92
+ nonce,
115
93
  },
116
94
  signature
117
95
  );
118
96
 
119
97
  expect(code).toBe('TRANSACTION_RECEIVED');
120
98
 
121
- await defaultProvider.waitForTx(transaction_hash);
99
+ await defaultProvider.waitForTransaction(transaction_hash);
122
100
  });
101
+
123
102
  test('read balance of wallet after transfer', async () => {
124
103
  const { res } = await erc20.call('balance_of', {
125
- user: walletAddress,
104
+ user: accountContract.connectedTo,
126
105
  });
127
106
 
128
107
  expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(990).toString());
@@ -136,7 +115,7 @@ test('build tx', async () => {
136
115
 
137
116
  expect(address).toBe('0x04024999b9574cb7623679ce049a609db62a95098982c5b28ac61abdebd1c82b');
138
117
 
139
- const selector = stark.getSelectorFromName('transfer');
118
+ const selector = hash.getSelectorFromName('transfer');
140
119
 
141
120
  expect(selector).toBe(
142
121
  number.toHex(
@@ -144,18 +123,19 @@ test('build tx', async () => {
144
123
  )
145
124
  );
146
125
 
147
- const msgHash = hash.hashMessage(address, '1', selector, ['6', '7'], '0');
126
+ const calls = [{ contractAddress: '1', entrypoint: 'transfer', calldata: ['6', '7'] }];
127
+ const msgHash = hash.hashMulticall(address, calls, '0', '0');
148
128
  expect(number.toBN(msgHash).toString()).toStrictEqual(
149
129
  number
150
- .toBN('2154230509011102177917341711834485670139815171447919056633262592518907948680')
130
+ .toBN('533725737276146993132325070982049323585915612981489962412873515411469143806')
151
131
  .toString()
152
132
  );
153
133
 
154
134
  const [r, s] = ec.sign(keyPair, msgHash);
155
135
  expect(r.toString()).toBe(
156
- '706800951915233622090196542158919402159816118214143837213294331713137614072'
136
+ '3081830197073374427897814075820860503521735760640862828374253887454357679197'
157
137
  );
158
138
  expect(s.toString()).toBe(
159
- '1857147121895075123389037565321926580259282654271568123966453051614350474888'
139
+ '384293936273611705317490990661155378189310283917528660618713929845936492551'
160
140
  );
161
141
  });
@@ -1,33 +1,25 @@
1
- import fs from 'fs';
2
-
3
1
  import { isBN } from 'bn.js';
4
2
 
5
- import { CompiledContract, Contract, defaultProvider, json, stark } from '../src';
3
+ import { Contract, defaultProvider, stark } from '../src';
4
+ import { getSelectorFromName } from '../src/utils/hash';
6
5
  import { BigNumberish, toBN } from '../src/utils/number';
7
- import { compileCalldata, getSelectorFromName } from '../src/utils/stark';
8
-
9
- const compiledERC20: CompiledContract = json.parse(
10
- fs.readFileSync('./__mocks__/ERC20.json').toString('ascii')
11
- );
12
- const compiledTypeTransformation: CompiledContract = json.parse(
13
- fs.readFileSync('./__mocks__/contract.json').toString('ascii')
14
- );
15
- const compiledMulticall: CompiledContract = json.parse(
16
- fs.readFileSync('./__mocks__/multicall.json').toString('ascii')
17
- );
6
+ import { compileCalldata } from '../src/utils/stark';
7
+ import { compiledErc20, compiledMulticall, compiledTypeTransformation } from './fixtures';
18
8
 
19
9
  describe('class Contract {}', () => {
20
10
  const wallet = stark.randomAddress();
11
+
21
12
  describe('Basic Interaction', () => {
22
13
  let erc20: Contract;
23
14
  let contract: Contract;
15
+
24
16
  beforeAll(async () => {
25
17
  const { code, transaction_hash, address } = await defaultProvider.deployContract({
26
- contract: compiledERC20,
18
+ contract: compiledErc20,
27
19
  });
28
- erc20 = new Contract(compiledERC20.abi, address, defaultProvider);
20
+ erc20 = new Contract(compiledErc20.abi, address, defaultProvider);
29
21
  expect(code).toBe('TRANSACTION_RECEIVED');
30
- await defaultProvider.waitForTx(transaction_hash);
22
+ await defaultProvider.waitForTransaction(transaction_hash);
31
23
 
32
24
  // Deploy Multicall
33
25
 
@@ -43,14 +35,16 @@ describe('class Contract {}', () => {
43
35
 
44
36
  expect(m_code).toBe('TRANSACTION_RECEIVED');
45
37
 
46
- await defaultProvider.waitForTx(m_transaction_hash);
38
+ await defaultProvider.waitForTransaction(m_transaction_hash);
47
39
  });
40
+
48
41
  test('read initial balance of that account', async () => {
49
42
  const { res } = await erc20.call('balance_of', {
50
43
  user: wallet,
51
44
  });
52
45
  expect(res).toStrictEqual(toBN(0));
53
46
  });
47
+
54
48
  test('add 10 test ERC20 to account', async () => {
55
49
  const response = await erc20.invoke('mint', {
56
50
  recipient: wallet,
@@ -58,8 +52,9 @@ describe('class Contract {}', () => {
58
52
  });
59
53
  expect(response.code).toBe('TRANSACTION_RECEIVED');
60
54
 
61
- await defaultProvider.waitForTx(response.transaction_hash);
55
+ await defaultProvider.waitForTransaction(response.transaction_hash);
62
56
  });
57
+
63
58
  test('read balance after mint of that account', async () => {
64
59
  const { res } = await erc20.call('balance_of', {
65
60
  user: wallet,
@@ -67,6 +62,7 @@ describe('class Contract {}', () => {
67
62
 
68
63
  expect(res).toStrictEqual(toBN(10));
69
64
  });
65
+
70
66
  test('read balance in a multicall', async () => {
71
67
  const args1 = { user: wallet };
72
68
  const args2 = {};
@@ -87,25 +83,30 @@ describe('class Contract {}', () => {
87
83
  (result as BigNumberish[]).forEach((el) => expect(isBN(el)));
88
84
  });
89
85
  });
86
+
90
87
  describe('Type Transformation', () => {
91
88
  let contract: Contract;
89
+
92
90
  beforeAll(async () => {
93
91
  const { code, transaction_hash, address } = await defaultProvider.deployContract({
94
92
  contract: compiledTypeTransformation,
95
93
  });
96
94
  contract = new Contract(compiledTypeTransformation.abi, address, defaultProvider);
97
95
  expect(code).toBe('TRANSACTION_RECEIVED');
98
- await defaultProvider.waitForTx(transaction_hash);
96
+ await defaultProvider.waitForTransaction(transaction_hash);
99
97
  });
98
+
100
99
  describe('Request Type Transformation', () => {
101
100
  test('Parsing the felt in request', async () => {
102
101
  return expect(contract.call('request_felt', { num: 3 })).resolves.not.toThrow();
103
102
  });
103
+
104
104
  test('Parsing the array of felt in request', async () => {
105
105
  return expect(
106
106
  contract.call('request_array_of_felts', { arr: [1, 2] })
107
107
  ).resolves.not.toThrow();
108
108
  });
109
+
109
110
  test('Parsing the struct in request', async () => {
110
111
  return expect(
111
112
  contract.call('request_struct', {
@@ -113,11 +114,13 @@ describe('class Contract {}', () => {
113
114
  })
114
115
  ).resolves.not.toThrow();
115
116
  });
117
+
116
118
  test('Parsing the array of structs in request', async () => {
117
119
  return expect(
118
120
  contract.call('request_array_of_structs', { str: [{ x: 1, y: 2 }] })
119
121
  ).resolves.not.toThrow();
120
122
  });
123
+
121
124
  test('Parsing the nested structs in request', async () => {
122
125
  return expect(
123
126
  contract.call('request_nested_structs', {
@@ -129,9 +132,11 @@ describe('class Contract {}', () => {
129
132
  })
130
133
  ).resolves.not.toThrow();
131
134
  });
135
+
132
136
  test('Parsing the tuple in request', async () => {
133
137
  return expect(contract.call('request_tuple', { tup: [1, 2] })).resolves.not.toThrow();
134
138
  });
139
+
135
140
  test('Parsing the multiple types in request', async () => {
136
141
  return expect(
137
142
  contract.call('request_mixed_types', {
@@ -145,23 +150,28 @@ describe('class Contract {}', () => {
145
150
  ).resolves.not.toThrow();
146
151
  });
147
152
  });
153
+
148
154
  describe('Response Type Transformation', () => {
149
155
  test('Parsing the felt in response', async () => {
150
156
  const { res } = await contract.call('get_felt');
151
157
  expect(res).toStrictEqual(toBN(4));
152
158
  });
159
+
153
160
  test('Parsing the array of felt in response', async () => {
154
161
  const { res } = await contract.call('get_array_of_felts');
155
162
  expect(res).toStrictEqual([toBN(4), toBN(5)]);
156
163
  });
164
+
157
165
  test('Parsing the array of structs in response', async () => {
158
166
  const { res } = await contract.call('get_struct');
159
167
  expect(res).toStrictEqual({ x: toBN(1), y: toBN(2) });
160
168
  });
169
+
161
170
  test('Parsing the array of structs in response', async () => {
162
171
  const { res } = await contract.call('get_array_of_structs');
163
172
  expect(res).toStrictEqual([{ x: toBN(1), y: toBN(2) }]);
164
173
  });
174
+
165
175
  test('Parsing the nested structs in response', async () => {
166
176
  const { res } = await contract.call('get_nested_structs');
167
177
  expect(res).toStrictEqual({
@@ -170,10 +180,12 @@ describe('class Contract {}', () => {
170
180
  extra: toBN(5),
171
181
  });
172
182
  });
183
+
173
184
  test('Parsing the tuple in response', async () => {
174
185
  const { res } = await contract.call('get_tuple');
175
186
  expect(res).toStrictEqual([toBN(1), toBN(2), toBN(3)]);
176
187
  });
188
+
177
189
  test('Parsing the multiple types in response', async () => {
178
190
  const { tuple, number, array, point } = await contract.call('get_mixed_types');
179
191
  expect(tuple).toStrictEqual([toBN(1), toBN(2)]);
@@ -0,0 +1,13 @@
1
+ import fs from 'fs';
2
+
3
+ import { json } from '../src';
4
+ import { CompiledContract } from '../src/types';
5
+
6
+ const readContract = (name: string): CompiledContract =>
7
+ json.parse(fs.readFileSync(`./__mocks__/${name}.json`).toString('ascii'));
8
+
9
+ export const compiledArgentAccount = readContract('ArgentAccount');
10
+ export const compiledErc20 = readContract('ERC20');
11
+ export const compiledTypeTransformation = readContract('contract');
12
+ export const compiledMulticall = readContract('multicall');
13
+ export const compiledTestDapp = readContract('TestDapp');
@@ -1,13 +1,8 @@
1
- import fs from 'fs';
2
-
3
- import { CompiledContract, defaultProvider, json, stark } from '../src';
1
+ import { defaultProvider, stark } from '../src';
2
+ import { compiledArgentAccount } from './fixtures';
4
3
 
5
4
  const { compileCalldata } = stark;
6
5
 
7
- const compiledArgentAccount = json.parse(
8
- fs.readFileSync('./__mocks__/ArgentAccount.json').toString('ascii')
9
- );
10
-
11
6
  describe('defaultProvider', () => {
12
7
  describe('feeder gateway endpoints', () => {
13
8
  test('getContractAddresses()', async () => {
@@ -102,15 +97,8 @@ describe('defaultProvider', () => {
102
97
 
103
98
  describe('addTransaction()', () => {
104
99
  test('deployContract()', async () => {
105
- const inputContract = compiledArgentAccount as unknown as CompiledContract;
106
-
107
100
  const response = await defaultProvider.deployContract({
108
- contract: inputContract,
109
- constructorCalldata: compileCalldata({
110
- signer: stark.randomAddress(),
111
- guardian: '0',
112
- L1_address: '0',
113
- }),
101
+ contract: compiledArgentAccount,
114
102
  });
115
103
 
116
104
  expect(response.code).toBe('TRANSACTION_RECEIVED');