starknet 4.15.0 → 4.16.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.
- package/CHANGELOG.md +21 -0
- package/__tests__/account.test.ts +76 -16
- package/__tests__/contract.test.ts +184 -186
- package/dist/index.d.ts +78 -95
- package/dist/index.global.js +116 -133
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +116 -133
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +116 -133
- package/dist/index.mjs.map +1 -1
- package/index.d.ts +78 -95
- package/index.global.js +116 -133
- package/index.global.js.map +1 -1
- package/index.js +116 -133
- package/index.js.map +1 -1
- package/index.mjs +116 -133
- package/index.mjs.map +1 -1
- package/package.json +3 -2
- package/src/account/default.ts +69 -53
- package/src/account/interface.ts +44 -44
- package/src/contract/default.ts +8 -10
- package/src/contract/interface.ts +5 -7
- package/src/provider/default.ts +10 -22
- package/src/provider/interface.ts +4 -22
- package/src/provider/rpc.ts +34 -47
- package/src/provider/sequencer.ts +35 -47
- package/src/types/account.ts +13 -4
- package/src/types/lib.ts +0 -1
- package/www/docs/API/account.md +4 -6
- package/www/docs/API/provider.md +2 -27
- package/www/guides/intro.md +33 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
# [4.16.0](https://github.com/0xs34n/starknet.js/compare/v4.15.1...v4.16.0) (2022-12-12)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- blockIdentifier null on call from constructed function ([c88fbf0](https://github.com/0xs34n/starknet.js/commit/c88fbf0cdfc57e1150275a34c15900d6c81802d3))
|
|
6
|
+
- default pathfinder does't have pending block ([4619188](https://github.com/0xs34n/starknet.js/commit/4619188e21e5cc9a811c59bcf2923c4382661635))
|
|
7
|
+
- sequencer defaults, remove defaultProvider default blockIdentifier, spelling, class ([555a9a3](https://github.com/0xs34n/starknet.js/commit/555a9a3982bc1a742776119df5dee5d701209a0d))
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
- multi deploy reimplemented ([10e609a](https://github.com/0xs34n/starknet.js/commit/10e609a1af584df65942477b264ad7809b5c70c9))
|
|
12
|
+
- return precalculated address from deploy ([5e40224](https://github.com/0xs34n/starknet.js/commit/5e402246841bdf9117a9ee96799833fc6f68d16b))
|
|
13
|
+
|
|
14
|
+
## [4.15.1](https://github.com/0xs34n/starknet.js/compare/v4.15.0...v4.15.1) (2022-12-07)
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
- add testnet 2 compatibility to test ([b83f35b](https://github.com/0xs34n/starknet.js/commit/b83f35bbfc0c2a6c84318a473ca816cc053f5806))
|
|
19
|
+
- delete only on test ([e13db57](https://github.com/0xs34n/starknet.js/commit/e13db577b7d40073707d78e57f63e65b6472c446))
|
|
20
|
+
- lib chainid test ([e820572](https://github.com/0xs34n/starknet.js/commit/e820572a9eafe732dae3d1bbde5f63279c000be7))
|
|
21
|
+
|
|
1
22
|
# [4.15.0](https://github.com/0xs34n/starknet.js/compare/v4.14.0...v4.15.0) (2022-12-05)
|
|
2
23
|
|
|
3
24
|
### Bug Fixes
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { isBN } from 'bn.js';
|
|
2
2
|
|
|
3
3
|
import typedDataExample from '../__mocks__/typedDataExample.json';
|
|
4
|
-
import { Account, Contract,
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { Account, Contract, Provider, number, stark } from '../src';
|
|
5
|
+
import { getKeyPair, sign } from '../src/utils/ellipticCurve';
|
|
6
|
+
import { parseUDCEvent } from '../src/utils/events';
|
|
7
|
+
import { feeTransactionVersion, pedersen } from '../src/utils/hash';
|
|
8
|
+
import { cleanHex, hexToDecimalString, toBN } from '../src/utils/number';
|
|
7
9
|
import { encodeShortString } from '../src/utils/shortString';
|
|
8
10
|
import { randomAddress } from '../src/utils/stark';
|
|
9
11
|
import {
|
|
@@ -169,14 +171,30 @@ describe('deploy and test Wallet', () => {
|
|
|
169
171
|
|
|
170
172
|
test('Get the stark name of the account and account from stark name (using starknet.id)', async () => {
|
|
171
173
|
// Deploy naming contract
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
174
|
+
const namingResponse = await account.declareDeploy({
|
|
175
|
+
contract: compiledNamingContract,
|
|
176
|
+
classHash: '0x3f2f8c80ab2d404bcfb4182e8528708e4efa2c646dd711bdd7b721ecc6111f7',
|
|
177
|
+
});
|
|
178
|
+
const namingAddress = namingResponse.deploy.contract_address;
|
|
175
179
|
|
|
176
180
|
// Deploy Starknet id contract
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
181
|
+
const idResponse = await account.declareDeploy({
|
|
182
|
+
contract: compiledStarknetId,
|
|
183
|
+
classHash: '0x1eb5a8308760d82321cb3ee8967581bb1d38348c7d2f082a07580040c52217c',
|
|
184
|
+
});
|
|
185
|
+
const idAddress = idResponse.deploy.contract_address;
|
|
186
|
+
|
|
187
|
+
// Create signature from private key
|
|
188
|
+
const whitelistingPublicKey =
|
|
189
|
+
'1893860513534673656759973582609638731665558071107553163765293299136715951024';
|
|
190
|
+
const whitelistingPrivateKey =
|
|
191
|
+
'301579081698031303837612923223391524790804435085778862878979120159194507372';
|
|
192
|
+
const hashed = pedersen([
|
|
193
|
+
pedersen([toBN('18925'), toBN('1922775124')]),
|
|
194
|
+
toBN(hexToDecimalString(account.address)),
|
|
195
|
+
]);
|
|
196
|
+
const keyPair = getKeyPair(toBN(whitelistingPrivateKey));
|
|
197
|
+
const signed = sign(keyPair, hashed);
|
|
180
198
|
|
|
181
199
|
const { transaction_hash } = await account.execute([
|
|
182
200
|
{
|
|
@@ -186,7 +204,7 @@ describe('deploy and test Wallet', () => {
|
|
|
186
204
|
idAddress, // starknetid_contract_addr
|
|
187
205
|
'0', // pricing_contract_addr
|
|
188
206
|
account.address, // admin
|
|
189
|
-
|
|
207
|
+
whitelistingPublicKey, // whitelisting_key
|
|
190
208
|
'0', // l1_contract
|
|
191
209
|
],
|
|
192
210
|
},
|
|
@@ -200,11 +218,11 @@ describe('deploy and test Wallet', () => {
|
|
|
200
218
|
entrypoint: 'whitelisted_mint',
|
|
201
219
|
calldata: [
|
|
202
220
|
'18925', // Domain encoded "ben"
|
|
203
|
-
'
|
|
221
|
+
'1922775124', // Expiry
|
|
204
222
|
'1', // Starknet id linked
|
|
205
223
|
account.address, // receiver_address
|
|
206
|
-
|
|
207
|
-
|
|
224
|
+
signed[0], // sig 0 for whitelist
|
|
225
|
+
signed[1], // sig 1 for whitelist
|
|
208
226
|
],
|
|
209
227
|
},
|
|
210
228
|
{
|
|
@@ -261,7 +279,7 @@ describe('deploy and test Wallet', () => {
|
|
|
261
279
|
expect(deployResponse.salt).toBeDefined();
|
|
262
280
|
});
|
|
263
281
|
|
|
264
|
-
test('UDC Deploy', async () => {
|
|
282
|
+
test('UDC Deploy unique', async () => {
|
|
265
283
|
const salt = randomAddress(); // use random salt
|
|
266
284
|
|
|
267
285
|
const deployment = await account.deploy({
|
|
@@ -272,12 +290,54 @@ describe('deploy and test Wallet', () => {
|
|
|
272
290
|
account.address,
|
|
273
291
|
],
|
|
274
292
|
salt,
|
|
275
|
-
unique: true,
|
|
293
|
+
unique: true,
|
|
276
294
|
});
|
|
295
|
+
expect(deployment).toHaveProperty('transaction_hash');
|
|
277
296
|
|
|
278
|
-
|
|
297
|
+
// check pre-calculated address
|
|
298
|
+
const txReceipt = await provider.waitForTransaction(deployment.transaction_hash);
|
|
299
|
+
const udcEvent = parseUDCEvent(txReceipt);
|
|
300
|
+
expect(cleanHex(deployment.contract_address[0])).toBe(cleanHex(udcEvent.contract_address));
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test('UDC Deploy non-unique', async () => {
|
|
304
|
+
const salt = randomAddress(); // use random salt
|
|
279
305
|
|
|
306
|
+
const deployment = await account.deploy({
|
|
307
|
+
classHash: erc20ClassHash,
|
|
308
|
+
constructorCalldata: [
|
|
309
|
+
encodeShortString('Token'),
|
|
310
|
+
encodeShortString('ERC20'),
|
|
311
|
+
account.address,
|
|
312
|
+
],
|
|
313
|
+
salt,
|
|
314
|
+
unique: false,
|
|
315
|
+
});
|
|
280
316
|
expect(deployment).toHaveProperty('transaction_hash');
|
|
317
|
+
|
|
318
|
+
// check pre-calculated address
|
|
319
|
+
const txReceipt = await provider.waitForTransaction(deployment.transaction_hash);
|
|
320
|
+
const udcEvent = parseUDCEvent(txReceipt);
|
|
321
|
+
expect(cleanHex(deployment.contract_address[0])).toBe(cleanHex(udcEvent.contract_address));
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
test('UDC multi Deploy', async () => {
|
|
325
|
+
const deployments = await account.deploy([
|
|
326
|
+
{
|
|
327
|
+
classHash: '0x04367b26fbb92235e8d1137d19c080e6e650a6889ded726d00658411cc1046f5',
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
classHash: erc20ClassHash,
|
|
331
|
+
constructorCalldata: [
|
|
332
|
+
encodeShortString('Token'),
|
|
333
|
+
encodeShortString('ERC20'),
|
|
334
|
+
account.address,
|
|
335
|
+
],
|
|
336
|
+
},
|
|
337
|
+
]);
|
|
338
|
+
expect(deployments).toHaveProperty('transaction_hash');
|
|
339
|
+
expect(deployments.contract_address[0]).toBeDefined();
|
|
340
|
+
expect(deployments.contract_address[1]).toBeDefined();
|
|
281
341
|
});
|
|
282
342
|
});
|
|
283
343
|
});
|
|
@@ -13,227 +13,225 @@ import {
|
|
|
13
13
|
getTestProvider,
|
|
14
14
|
} from './fixtures';
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
describe('contract module', () => {
|
|
17
|
+
let erc20Address: string;
|
|
18
|
+
const provider = getTestProvider();
|
|
19
19
|
const wallet = stark.randomAddress();
|
|
20
20
|
const account = getTestAccount(provider);
|
|
21
|
+
const constructorCalldata = [encodeShortString('Token'), encodeShortString('ERC20'), wallet];
|
|
22
|
+
const classHash = '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a';
|
|
21
23
|
|
|
22
|
-
describe('
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
describe('class Contract {}', () => {
|
|
25
|
+
describe('Basic Interaction', () => {
|
|
26
|
+
let erc20Contract: Contract;
|
|
27
|
+
let multicallContract: Contract;
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
beforeAll(async () => {
|
|
30
|
+
const { deploy } = await account.declareDeploy({
|
|
31
|
+
contract: compiledErc20,
|
|
32
|
+
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
|
|
33
|
+
constructorCalldata: [encodeShortString('Token'), encodeShortString('ERC20'), wallet],
|
|
34
|
+
});
|
|
32
35
|
|
|
33
|
-
|
|
36
|
+
erc20Contract = new Contract(compiledErc20.abi, deploy.contract_address!, provider);
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
const { deploy: multicallDeploy } = await account.declareDeploy({
|
|
39
|
+
contract: compiledMulticall,
|
|
40
|
+
classHash: '0x06f94f3229a8d9c1d51cb84f1f5ec306c8552a805e307540727dda53c4936b43',
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
multicallContract = new Contract(
|
|
44
|
+
compiledMulticall.abi,
|
|
45
|
+
multicallDeploy.contract_address!,
|
|
46
|
+
provider
|
|
47
|
+
);
|
|
38
48
|
});
|
|
39
49
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
50
|
+
test('populate transaction for initial balance of that account', async () => {
|
|
51
|
+
const res = await erc20Contract.populateTransaction.balanceOf(wallet);
|
|
52
|
+
expect(res).toHaveProperty('contractAddress');
|
|
53
|
+
expect(res).toHaveProperty('entrypoint');
|
|
54
|
+
expect(res).toHaveProperty('calldata');
|
|
55
|
+
});
|
|
46
56
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
expect(res).toHaveProperty('entrypoint');
|
|
51
|
-
expect(res).toHaveProperty('calldata');
|
|
52
|
-
});
|
|
57
|
+
test('estimate gas fee for `mint` should fail when connected to the provider', async () => {
|
|
58
|
+
expect(erc20Contract.estimateFee.mint(wallet, ['10', '0'])).rejects.toThrow();
|
|
59
|
+
});
|
|
53
60
|
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
test('read initial balance of that account', async () => {
|
|
62
|
+
const result = await erc20Contract.balanceOf(wallet);
|
|
63
|
+
const [res] = result;
|
|
64
|
+
expect(res.low).toStrictEqual(toBN(1000));
|
|
65
|
+
expect(res).toStrictEqual(result.balance);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('read balance in a multicall', async () => {
|
|
69
|
+
const args1 = { user: wallet };
|
|
70
|
+
const args2 = {};
|
|
71
|
+
const calls = [
|
|
72
|
+
erc20Contract.address,
|
|
73
|
+
getSelectorFromName('balanceOf'),
|
|
74
|
+
Object.keys(args1).length,
|
|
75
|
+
...compileCalldata(args1),
|
|
76
|
+
|
|
77
|
+
erc20Contract.address,
|
|
78
|
+
getSelectorFromName('decimals'),
|
|
79
|
+
Object.keys(args2).length,
|
|
80
|
+
...compileCalldata(args2),
|
|
81
|
+
];
|
|
82
|
+
const result = await multicallContract.aggregate(calls);
|
|
83
|
+
const [block_number, res] = result;
|
|
84
|
+
expect(isBN(block_number));
|
|
85
|
+
expect(Array.isArray(res));
|
|
86
|
+
(res as BigNumberish[]).forEach((el) => expect(isBN(el)));
|
|
87
|
+
expect(block_number).toStrictEqual(result.block_number);
|
|
88
|
+
expect(res).toStrictEqual(result.result);
|
|
89
|
+
});
|
|
56
90
|
});
|
|
57
91
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const [res] = result;
|
|
61
|
-
expect(res.low).toStrictEqual(toBN(1000));
|
|
62
|
-
expect(res).toStrictEqual(result.balance);
|
|
63
|
-
});
|
|
92
|
+
describe('Type Transformation', () => {
|
|
93
|
+
let typeTransformedContract: Contract;
|
|
64
94
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
getSelectorFromName('balanceOf'),
|
|
71
|
-
Object.keys(args1).length,
|
|
72
|
-
...compileCalldata(args1),
|
|
73
|
-
|
|
74
|
-
erc20Contract.address,
|
|
75
|
-
getSelectorFromName('decimals'),
|
|
76
|
-
Object.keys(args2).length,
|
|
77
|
-
...compileCalldata(args2),
|
|
78
|
-
];
|
|
79
|
-
const result = await multicallContract.aggregate(calls);
|
|
80
|
-
const [block_number, res] = result;
|
|
81
|
-
expect(isBN(block_number));
|
|
82
|
-
expect(Array.isArray(res));
|
|
83
|
-
(res as BigNumberish[]).forEach((el) => expect(isBN(el)));
|
|
84
|
-
expect(block_number).toStrictEqual(result.block_number);
|
|
85
|
-
expect(res).toStrictEqual(result.result);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('Type Transformation', () => {
|
|
90
|
-
let typeTransformedContract: Contract;
|
|
95
|
+
beforeAll(async () => {
|
|
96
|
+
const { deploy } = await account.declareDeploy({
|
|
97
|
+
contract: compiledTypeTransformation,
|
|
98
|
+
classHash: '0x022a0e662b13d18a2aaa3ee54ae290de6569621b549022c18169c6e7893809ea',
|
|
99
|
+
});
|
|
91
100
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
101
|
+
typeTransformedContract = new Contract(
|
|
102
|
+
compiledTypeTransformation.abi,
|
|
103
|
+
deploy.contract_address!,
|
|
104
|
+
provider
|
|
105
|
+
);
|
|
96
106
|
});
|
|
97
107
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe('Request Type Transformation', () => {
|
|
106
|
-
test('Parsing the felt in request', async () => {
|
|
107
|
-
return expect(typeTransformedContract.request_felt(3)).resolves.not.toThrow();
|
|
108
|
-
});
|
|
108
|
+
describe('Request Type Transformation', () => {
|
|
109
|
+
test('Parsing the felt in request', async () => {
|
|
110
|
+
return expect(typeTransformedContract.request_felt(3)).resolves.not.toThrow();
|
|
111
|
+
});
|
|
109
112
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
test('Parsing the array of felt in request', async () => {
|
|
114
|
+
return expect(
|
|
115
|
+
typeTransformedContract.request_array_of_felts([1, 2])
|
|
116
|
+
).resolves.not.toThrow();
|
|
117
|
+
});
|
|
115
118
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
test('Parsing the struct in request', async () => {
|
|
120
|
+
return expect(
|
|
121
|
+
typeTransformedContract.request_struct({ x: 1, y: 2 })
|
|
122
|
+
).resolves.not.toThrow();
|
|
123
|
+
});
|
|
121
124
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
test('Parsing the array of structs in request', async () => {
|
|
126
|
+
return expect(
|
|
127
|
+
typeTransformedContract.request_array_of_structs([{ x: 1, y: 2 }])
|
|
128
|
+
).resolves.not.toThrow();
|
|
129
|
+
});
|
|
127
130
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
131
|
+
test('Parsing the nested structs in request', async () => {
|
|
132
|
+
return expect(
|
|
133
|
+
typeTransformedContract.request_nested_structs({
|
|
134
|
+
p1: { x: 1, y: 2 },
|
|
135
|
+
p2: { x: 3, y: 4 },
|
|
136
|
+
extra: 5,
|
|
137
|
+
})
|
|
138
|
+
).resolves.not.toThrow();
|
|
139
|
+
});
|
|
137
140
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
+
test('Parsing the tuple in request', async () => {
|
|
142
|
+
return expect(typeTransformedContract.request_tuple([1, 2])).resolves.not.toThrow();
|
|
143
|
+
});
|
|
141
144
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
145
|
+
test('Parsing the multiple types in request', async () => {
|
|
146
|
+
return expect(
|
|
147
|
+
typeTransformedContract.request_mixed_types(2, { x: 1, y: 2 }, [1])
|
|
148
|
+
).resolves.not.toThrow();
|
|
149
|
+
});
|
|
146
150
|
});
|
|
147
|
-
});
|
|
148
151
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
describe('Response Type Transformation', () => {
|
|
153
|
+
test('Parsing the felt in response', async () => {
|
|
154
|
+
const { res } = await typeTransformedContract.get_felt();
|
|
155
|
+
expect(res).toStrictEqual(toBN(4));
|
|
156
|
+
});
|
|
154
157
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
test('Parsing the array of felt in response', async () => {
|
|
159
|
+
const result = await typeTransformedContract.get_array_of_felts();
|
|
160
|
+
const [res] = result;
|
|
161
|
+
expect(res).toStrictEqual([toBN(4), toBN(5)]);
|
|
162
|
+
expect(res).toStrictEqual(result.res);
|
|
163
|
+
});
|
|
161
164
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
165
|
+
test('Parsing the array of structs in response', async () => {
|
|
166
|
+
const result = await typeTransformedContract.get_struct();
|
|
167
|
+
const [res] = result;
|
|
168
|
+
expect(res).toStrictEqual({ x: toBN(1), y: toBN(2) });
|
|
169
|
+
expect(res).toStrictEqual(result.res);
|
|
170
|
+
});
|
|
168
171
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
test('Parsing the array of structs in response', async () => {
|
|
173
|
+
const result = await typeTransformedContract.get_array_of_structs();
|
|
174
|
+
const [res] = result;
|
|
175
|
+
expect(res).toStrictEqual([{ x: toBN(1), y: toBN(2) }]);
|
|
176
|
+
expect(res).toStrictEqual(result.res);
|
|
177
|
+
});
|
|
175
178
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
179
|
+
test('Parsing the nested structs in response', async () => {
|
|
180
|
+
const result = await typeTransformedContract.get_nested_structs();
|
|
181
|
+
const [res] = result;
|
|
182
|
+
expect(res).toStrictEqual({
|
|
183
|
+
p1: { x: toBN(1), y: toBN(2) },
|
|
184
|
+
p2: { x: toBN(3), y: toBN(4) },
|
|
185
|
+
extra: toBN(5),
|
|
186
|
+
});
|
|
187
|
+
expect(res).toStrictEqual(result.res);
|
|
183
188
|
});
|
|
184
|
-
expect(res).toStrictEqual(result.res);
|
|
185
|
-
});
|
|
186
189
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
test('Parsing the tuple in response', async () => {
|
|
191
|
+
const result = await typeTransformedContract.get_tuple();
|
|
192
|
+
const [res] = result;
|
|
193
|
+
expect(res).toStrictEqual([toBN(1), toBN(2), toBN(3)]);
|
|
194
|
+
expect(res).toStrictEqual(result.res);
|
|
195
|
+
});
|
|
193
196
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
197
|
+
test('Parsing the multiple types in response', async () => {
|
|
198
|
+
const result = await typeTransformedContract.get_mixed_types();
|
|
199
|
+
const [tuple, number, array, point] = result;
|
|
200
|
+
expect(tuple).toStrictEqual([toBN(1), toBN(2)]);
|
|
201
|
+
expect(number).toStrictEqual(toBN(3));
|
|
202
|
+
expect(array).toStrictEqual([toBN(4)]);
|
|
203
|
+
expect(point).toStrictEqual({ x: toBN(1), y: toBN(2) });
|
|
204
|
+
expect(tuple).toStrictEqual(result.tuple);
|
|
205
|
+
expect(number).toStrictEqual(result.number);
|
|
206
|
+
expect(array).toStrictEqual(result.array);
|
|
207
|
+
expect(point).toStrictEqual(result.point);
|
|
208
|
+
});
|
|
205
209
|
});
|
|
206
210
|
});
|
|
207
211
|
});
|
|
208
|
-
});
|
|
209
212
|
|
|
210
|
-
describe('class ContractFactory {}', () => {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
213
|
+
describe('class ContractFactory {}', () => {
|
|
214
|
+
beforeAll(async () => {
|
|
215
|
+
await account.declareDeploy({
|
|
216
|
+
contract: compiledErc20,
|
|
217
|
+
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
|
|
218
|
+
constructorCalldata,
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
test('deployment of new contract', async () => {
|
|
222
|
+
const factory = new ContractFactory(compiledErc20, classHash, account);
|
|
223
|
+
const erc20 = await factory.deploy(constructorCalldata);
|
|
224
|
+
expect(erc20 instanceof Contract);
|
|
225
|
+
});
|
|
226
|
+
test('wait for deployment transaction', async () => {
|
|
227
|
+
const factory = new ContractFactory(compiledErc20, classHash, account);
|
|
228
|
+
const contract = await factory.deploy(constructorCalldata);
|
|
229
|
+
expect(contract.deployed()).resolves.not.toThrow();
|
|
230
|
+
});
|
|
231
|
+
test('attach new contract', async () => {
|
|
232
|
+
const factory = new ContractFactory(compiledErc20, classHash, account);
|
|
233
|
+
const erc20 = factory.attach(erc20Address);
|
|
234
|
+
expect(erc20 instanceof Contract);
|
|
222
235
|
});
|
|
223
|
-
});
|
|
224
|
-
test('deployment of new contract', async () => {
|
|
225
|
-
const factory = new ContractFactory(compiledErc20, classHash, account);
|
|
226
|
-
const erc20 = await factory.deploy(constructorCalldata);
|
|
227
|
-
expect(erc20 instanceof Contract);
|
|
228
|
-
});
|
|
229
|
-
test('wait for deployment transaction', async () => {
|
|
230
|
-
const factory = new ContractFactory(compiledErc20, classHash, account);
|
|
231
|
-
const contract = await factory.deploy(constructorCalldata);
|
|
232
|
-
expect(contract.deployed()).resolves.not.toThrow();
|
|
233
|
-
});
|
|
234
|
-
test('attach new contract', async () => {
|
|
235
|
-
const factory = new ContractFactory(compiledErc20, classHash, account);
|
|
236
|
-
const erc20 = factory.attach(erc20Address);
|
|
237
|
-
expect(erc20 instanceof Contract);
|
|
238
236
|
});
|
|
239
237
|
});
|