starknet 3.12.1 → 3.13.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/.github/workflows/pr.yml +3 -0
- package/.github/workflows/release.yml +4 -0
- package/CHANGELOG.md +39 -0
- package/README.md +2 -0
- package/__mocks__/Account.json +25468 -0
- package/__tests__/account.test.ts +102 -65
- package/__tests__/contract.test.ts +23 -65
- package/__tests__/fixtures.ts +21 -1
- package/__tests__/jest.setup.ts +23 -4
- package/__tests__/provider.test.ts +20 -1
- package/account/index.js +10 -6
- package/contract/default.js +20 -21
- package/contract/index.js +10 -6
- package/dist/account/index.js +5 -1
- package/dist/contract/default.js +18 -18
- package/dist/contract/index.js +5 -1
- package/dist/index.js +5 -1
- package/dist/provider/default.d.ts +1 -1
- package/dist/provider/default.js +35 -49
- package/dist/provider/index.js +5 -1
- package/dist/provider/interface.d.ts +1 -1
- package/dist/provider/utils.js +5 -5
- package/dist/signer/index.js +5 -1
- package/dist/types/api.d.ts +1 -1
- package/dist/types/index.js +5 -1
- package/dist/utils/ellipticCurve.js +1 -1
- package/dist/utils/encode.js +1 -1
- package/dist/utils/hash.js +1 -1
- package/dist/utils/number.js +8 -4
- package/dist/utils/shortString.js +2 -2
- package/dist/utils/typedData/index.d.ts +2 -36
- package/dist/utils/typedData/index.js +8 -4
- package/dist/utils/typedData/types.d.ts +15 -70
- package/dist/utils/typedData/types.js +0 -45
- package/dist/utils/typedData/utils.d.ts +2 -18
- package/dist/utils/typedData/utils.js +4 -3
- package/index.js +10 -6
- package/package.json +33 -31
- package/provider/default.d.ts +1 -1
- package/provider/default.js +44 -65
- package/provider/index.js +10 -6
- package/provider/interface.d.ts +1 -1
- package/provider/utils.js +5 -5
- package/signer/index.js +10 -6
- package/src/provider/default.ts +24 -31
- package/src/provider/interface.ts +1 -1
- package/src/types/api.ts +1 -1
- package/src/utils/typedData/types.ts +15 -68
- package/src/utils/typedData/utils.ts +7 -4
- package/types/api.d.ts +1 -1
- package/types/index.js +10 -6
- package/utils/ellipticCurve.js +1 -1
- package/utils/encode.js +1 -1
- package/utils/hash.js +1 -1
- package/utils/number.js +13 -9
- package/utils/shortString.js +2 -2
- package/utils/typedData/index.d.ts +2 -46
- package/utils/typedData/index.js +15 -13
- package/utils/typedData/types.d.ts +15 -91
- package/utils/typedData/types.js +0 -55
- package/utils/typedData/utils.d.ts +2 -21
- package/utils/typedData/utils.js +4 -3
- package/www/guides/account.md +21 -7
- package/www/guides/erc20.md +15 -27
- package/__tests__/accountContract.test.ts +0 -110
|
@@ -1,49 +1,52 @@
|
|
|
1
1
|
import { isBN } from 'bn.js';
|
|
2
2
|
|
|
3
3
|
import typedDataExample from '../__mocks__/typedDataExample.json';
|
|
4
|
-
import { Account, Contract,
|
|
4
|
+
import { Account, Contract, Provider, ec, number, stark } from '../src';
|
|
5
5
|
import { toBN } from '../src/utils/number';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
compiledErc20,
|
|
8
|
+
compiledOpenZeppelinAccount,
|
|
9
|
+
compiledTestDapp,
|
|
10
|
+
getTestAccount,
|
|
11
|
+
getTestProvider,
|
|
12
|
+
} from './fixtures';
|
|
7
13
|
|
|
8
14
|
describe('deploy and test Wallet', () => {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const starkKeyPair = ec.getKeyPair(privateKey);
|
|
12
|
-
const starkKeyPub = ec.getStarkKey(starkKeyPair);
|
|
13
|
-
let account: Account;
|
|
15
|
+
const account: Account = getTestAccount();
|
|
16
|
+
const provider = getTestProvider();
|
|
14
17
|
let erc20: Contract;
|
|
15
18
|
let erc20Address: string;
|
|
16
19
|
let dapp: Contract;
|
|
17
20
|
|
|
18
21
|
beforeAll(async () => {
|
|
19
|
-
|
|
20
|
-
contract: compiledArgentAccount,
|
|
21
|
-
addressSalt: starkKeyPub,
|
|
22
|
-
});
|
|
23
|
-
const contract = new Contract(compiledArgentAccount.abi, accountResponse.address);
|
|
24
|
-
expect(accountResponse.code).toBe('TRANSACTION_RECEIVED');
|
|
25
|
-
|
|
26
|
-
const initializeResponse = await contract.initialize(starkKeyPub, '0');
|
|
27
|
-
expect(initializeResponse.code).toBe('TRANSACTION_RECEIVED');
|
|
28
|
-
|
|
29
|
-
account = new Account(defaultProvider, accountResponse.address, starkKeyPair);
|
|
22
|
+
expect(account).toBeInstanceOf(Account);
|
|
30
23
|
|
|
31
|
-
const erc20Response = await
|
|
24
|
+
const erc20Response = await provider.deployContract({
|
|
32
25
|
contract: compiledErc20,
|
|
33
26
|
});
|
|
34
27
|
erc20Address = erc20Response.address;
|
|
35
28
|
erc20 = new Contract(compiledErc20.abi, erc20Address);
|
|
36
29
|
expect(erc20Response.code).toBe('TRANSACTION_RECEIVED');
|
|
37
30
|
|
|
38
|
-
|
|
31
|
+
await provider.waitForTransaction(erc20Response.transaction_hash);
|
|
32
|
+
|
|
33
|
+
const mintResponse = await account.execute({
|
|
34
|
+
contractAddress: erc20Address,
|
|
35
|
+
entrypoint: 'mint',
|
|
36
|
+
calldata: [account.address, '1000'],
|
|
37
|
+
});
|
|
38
|
+
|
|
39
39
|
expect(mintResponse.code).toBe('TRANSACTION_RECEIVED');
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
await provider.waitForTransaction(mintResponse.transaction_hash);
|
|
42
|
+
|
|
43
|
+
const dappResponse = await provider.deployContract({
|
|
42
44
|
contract: compiledTestDapp,
|
|
43
45
|
});
|
|
44
46
|
dapp = new Contract(compiledTestDapp.abi, dappResponse.address);
|
|
45
47
|
expect(dappResponse.code).toBe('TRANSACTION_RECEIVED');
|
|
46
|
-
|
|
48
|
+
|
|
49
|
+
await provider.waitForTransaction(dappResponse.transaction_hash);
|
|
47
50
|
});
|
|
48
51
|
|
|
49
52
|
test('estimate fee', async () => {
|
|
@@ -56,20 +59,6 @@ describe('deploy and test Wallet', () => {
|
|
|
56
59
|
expect(typeof unit).toBe('string');
|
|
57
60
|
});
|
|
58
61
|
|
|
59
|
-
test('same wallet address', () => {
|
|
60
|
-
expect(account.address).toBe(account.address);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('read nonce', async () => {
|
|
64
|
-
const { result } = await account.callContract({
|
|
65
|
-
contractAddress: account.address,
|
|
66
|
-
entrypoint: 'get_nonce',
|
|
67
|
-
});
|
|
68
|
-
const nonce = result[0];
|
|
69
|
-
|
|
70
|
-
expect(number.toBN(nonce).toString()).toStrictEqual(number.toBN(0).toString());
|
|
71
|
-
});
|
|
72
|
-
|
|
73
62
|
test('read balance of wallet', async () => {
|
|
74
63
|
const { res } = await erc20.balance_of(account.address);
|
|
75
64
|
|
|
@@ -77,18 +66,14 @@ describe('deploy and test Wallet', () => {
|
|
|
77
66
|
});
|
|
78
67
|
|
|
79
68
|
test('execute by wallet owner', async () => {
|
|
80
|
-
const { code, transaction_hash } = await account.execute(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
},
|
|
86
|
-
undefined,
|
|
87
|
-
{ maxFee: '0' }
|
|
88
|
-
);
|
|
69
|
+
const { code, transaction_hash } = await account.execute({
|
|
70
|
+
contractAddress: erc20Address,
|
|
71
|
+
entrypoint: 'transfer',
|
|
72
|
+
calldata: [erc20.address, '10'],
|
|
73
|
+
});
|
|
89
74
|
|
|
90
75
|
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
91
|
-
await
|
|
76
|
+
await provider.waitForTransaction(transaction_hash);
|
|
92
77
|
});
|
|
93
78
|
|
|
94
79
|
test('read balance of wallet after transfer', async () => {
|
|
@@ -110,33 +95,29 @@ describe('deploy and test Wallet', () => {
|
|
|
110
95
|
calldata: [account.address, '10'],
|
|
111
96
|
},
|
|
112
97
|
undefined,
|
|
113
|
-
{ nonce
|
|
98
|
+
{ nonce }
|
|
114
99
|
);
|
|
115
100
|
|
|
116
101
|
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
117
|
-
await
|
|
102
|
+
await provider.waitForTransaction(transaction_hash);
|
|
118
103
|
});
|
|
119
104
|
|
|
120
105
|
test('execute multiple transactions', async () => {
|
|
121
|
-
const { code, transaction_hash } = await account.execute(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
],
|
|
134
|
-
undefined,
|
|
135
|
-
{ maxFee: '0' }
|
|
136
|
-
);
|
|
106
|
+
const { code, transaction_hash } = await account.execute([
|
|
107
|
+
{
|
|
108
|
+
contractAddress: dapp.address,
|
|
109
|
+
entrypoint: 'set_number',
|
|
110
|
+
calldata: ['47'],
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
contractAddress: dapp.address,
|
|
114
|
+
entrypoint: 'increase_number',
|
|
115
|
+
calldata: ['10'],
|
|
116
|
+
},
|
|
117
|
+
]);
|
|
137
118
|
|
|
138
119
|
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
139
|
-
await
|
|
120
|
+
await provider.waitForTransaction(transaction_hash);
|
|
140
121
|
|
|
141
122
|
const response = await dapp.get_number(account.address);
|
|
142
123
|
expect(toBN(response.number as string).toString()).toStrictEqual('57');
|
|
@@ -147,4 +128,60 @@ describe('deploy and test Wallet', () => {
|
|
|
147
128
|
|
|
148
129
|
expect(await account.verifyMessage(typedDataExample, signature)).toBe(true);
|
|
149
130
|
});
|
|
131
|
+
|
|
132
|
+
describe('new deployed account', () => {
|
|
133
|
+
let newAccount: Account;
|
|
134
|
+
|
|
135
|
+
beforeAll(async () => {
|
|
136
|
+
const starkKeyPair = ec.genKeyPair();
|
|
137
|
+
const starkKeyPub = ec.getStarkKey(starkKeyPair);
|
|
138
|
+
|
|
139
|
+
const accountResponse = await provider.deployContract({
|
|
140
|
+
contract: compiledOpenZeppelinAccount,
|
|
141
|
+
constructorCalldata: [starkKeyPub],
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
await provider.waitForTransaction(accountResponse.transaction_hash);
|
|
145
|
+
|
|
146
|
+
newAccount = new Account(provider, accountResponse.address, starkKeyPair);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('read nonce', async () => {
|
|
150
|
+
const { result } = await account.callContract({
|
|
151
|
+
contractAddress: newAccount.address,
|
|
152
|
+
entrypoint: 'get_nonce',
|
|
153
|
+
});
|
|
154
|
+
const nonce = result[0];
|
|
155
|
+
|
|
156
|
+
expect(number.toBN(nonce).toString()).toStrictEqual(number.toBN(0).toString());
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe('Contract interaction with Account', () => {
|
|
161
|
+
const wallet = stark.randomAddress();
|
|
162
|
+
|
|
163
|
+
beforeAll(async () => {
|
|
164
|
+
const mintResponse = await account.execute({
|
|
165
|
+
contractAddress: erc20Address,
|
|
166
|
+
entrypoint: 'mint',
|
|
167
|
+
calldata: [wallet, '1000'],
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
expect(mintResponse.code).toBe('TRANSACTION_RECEIVED');
|
|
171
|
+
|
|
172
|
+
await provider.waitForTransaction(mintResponse.transaction_hash);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test('change from provider to account', async () => {
|
|
176
|
+
expect(erc20.providerOrAccount instanceof Provider);
|
|
177
|
+
erc20.connect(account);
|
|
178
|
+
expect(erc20.providerOrAccount instanceof Account);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test('estimate gas fee for `mint`', async () => {
|
|
182
|
+
const res = await erc20.estimateFee.mint(wallet, '10');
|
|
183
|
+
expect(res).toHaveProperty('amount');
|
|
184
|
+
expect(res).toHaveProperty('unit');
|
|
185
|
+
});
|
|
186
|
+
});
|
|
150
187
|
});
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { isBN } from 'bn.js';
|
|
2
2
|
|
|
3
|
-
import { Account, Contract, ContractFactory, Provider,
|
|
3
|
+
import { Account, Contract, ContractFactory, Provider, 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
7
|
import {
|
|
8
|
-
compiledArgentAccount,
|
|
9
8
|
compiledErc20,
|
|
10
9
|
compiledMulticall,
|
|
11
10
|
compiledTypeTransformation,
|
|
11
|
+
getTestAccount,
|
|
12
|
+
getTestProvider,
|
|
12
13
|
} from './fixtures';
|
|
13
14
|
|
|
15
|
+
const provider = getTestProvider();
|
|
16
|
+
|
|
14
17
|
describe('class Contract {}', () => {
|
|
15
18
|
const wallet = stark.randomAddress();
|
|
16
19
|
|
|
@@ -19,27 +22,27 @@ describe('class Contract {}', () => {
|
|
|
19
22
|
let contract: Contract;
|
|
20
23
|
|
|
21
24
|
beforeAll(async () => {
|
|
22
|
-
const { code, transaction_hash, address } = await
|
|
25
|
+
const { code, transaction_hash, address } = await provider.deployContract({
|
|
23
26
|
contract: compiledErc20,
|
|
24
27
|
});
|
|
25
|
-
erc20 = new Contract(compiledErc20.abi, address
|
|
28
|
+
erc20 = new Contract(compiledErc20.abi, address!, provider);
|
|
26
29
|
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
27
|
-
await
|
|
30
|
+
await provider.waitForTransaction(transaction_hash);
|
|
28
31
|
// Deploy Multicall
|
|
29
32
|
|
|
30
33
|
const {
|
|
31
34
|
code: m_code,
|
|
32
35
|
transaction_hash: m_transaction_hash,
|
|
33
36
|
address: multicallAddress,
|
|
34
|
-
} = await
|
|
37
|
+
} = await provider.deployContract({
|
|
35
38
|
contract: compiledMulticall,
|
|
36
39
|
});
|
|
37
40
|
|
|
38
|
-
contract = new Contract(compiledMulticall.abi, multicallAddress);
|
|
41
|
+
contract = new Contract(compiledMulticall.abi, multicallAddress!);
|
|
39
42
|
|
|
40
43
|
expect(m_code).toBe('TRANSACTION_RECEIVED');
|
|
41
44
|
|
|
42
|
-
await
|
|
45
|
+
await provider.waitForTransaction(m_transaction_hash);
|
|
43
46
|
});
|
|
44
47
|
|
|
45
48
|
test('populate transaction for initial balance of that account', async () => {
|
|
@@ -61,20 +64,6 @@ describe('class Contract {}', () => {
|
|
|
61
64
|
expect(res).toStrictEqual(result.res);
|
|
62
65
|
});
|
|
63
66
|
|
|
64
|
-
test('add 10 test ERC20 to account', async () => {
|
|
65
|
-
const response = await erc20.mint(wallet, '10');
|
|
66
|
-
expect(response.code).toBe('TRANSACTION_RECEIVED');
|
|
67
|
-
|
|
68
|
-
await defaultProvider.waitForTransaction(response.transaction_hash);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('read balance after mint of that account', async () => {
|
|
72
|
-
const result = await erc20.balance_of(wallet);
|
|
73
|
-
const [res] = result;
|
|
74
|
-
expect(res).toStrictEqual(toBN(10));
|
|
75
|
-
expect(res).toStrictEqual(result.res);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
67
|
test('read balance in a multicall', async () => {
|
|
79
68
|
const args1 = { user: wallet };
|
|
80
69
|
const args2 = {};
|
|
@@ -103,12 +92,12 @@ describe('class Contract {}', () => {
|
|
|
103
92
|
let contract: Contract;
|
|
104
93
|
|
|
105
94
|
beforeAll(async () => {
|
|
106
|
-
const { code, transaction_hash, address } = await
|
|
95
|
+
const { code, transaction_hash, address } = await provider.deployContract({
|
|
107
96
|
contract: compiledTypeTransformation,
|
|
108
97
|
});
|
|
109
|
-
contract = new Contract(compiledTypeTransformation.abi, address
|
|
98
|
+
contract = new Contract(compiledTypeTransformation.abi, address!, provider);
|
|
110
99
|
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
111
|
-
await
|
|
100
|
+
await provider.waitForTransaction(transaction_hash);
|
|
112
101
|
});
|
|
113
102
|
|
|
114
103
|
describe('Request Type Transformation', () => {
|
|
@@ -208,39 +197,24 @@ describe('class Contract {}', () => {
|
|
|
208
197
|
});
|
|
209
198
|
|
|
210
199
|
describe('Contract interaction with Account', () => {
|
|
211
|
-
|
|
200
|
+
const account = getTestAccount();
|
|
212
201
|
let erc20: Contract;
|
|
213
202
|
let erc20Address: string;
|
|
214
203
|
|
|
215
204
|
beforeAll(async () => {
|
|
216
|
-
const
|
|
217
|
-
const starkKeyPub = ec.getStarkKey(starkKeyPair);
|
|
218
|
-
const { address } = await defaultProvider.deployContract({
|
|
219
|
-
contract: compiledArgentAccount,
|
|
220
|
-
addressSalt: starkKeyPub,
|
|
221
|
-
});
|
|
222
|
-
expect(address).toBeDefined();
|
|
223
|
-
account = new Account(defaultProvider, address, starkKeyPair);
|
|
224
|
-
const accountContract = new Contract(compiledArgentAccount.abi, address);
|
|
225
|
-
await accountContract.initialize(starkKeyPub, '0');
|
|
226
|
-
|
|
227
|
-
const erc20Response = await defaultProvider.deployContract({
|
|
205
|
+
const erc20Response = await provider.deployContract({
|
|
228
206
|
contract: compiledErc20,
|
|
229
207
|
});
|
|
230
|
-
erc20Address = erc20Response.address
|
|
231
|
-
erc20 = new Contract(compiledErc20.abi, erc20Address,
|
|
208
|
+
erc20Address = erc20Response.address!;
|
|
209
|
+
erc20 = new Contract(compiledErc20.abi, erc20Address, provider);
|
|
232
210
|
expect(erc20Response.code).toBe('TRANSACTION_RECEIVED');
|
|
233
|
-
await
|
|
234
|
-
|
|
235
|
-
const mintResponse = await erc20.mint(account.address, '1000');
|
|
236
|
-
|
|
237
|
-
await defaultProvider.waitForTransaction(mintResponse.transaction_hash);
|
|
211
|
+
await provider.waitForTransaction(erc20Response.transaction_hash);
|
|
238
212
|
});
|
|
239
213
|
|
|
240
214
|
test('read balance of wallet', async () => {
|
|
241
215
|
const result = await erc20.balance_of(account.address);
|
|
242
216
|
const [res] = result;
|
|
243
|
-
expect(res).toStrictEqual(toBN(
|
|
217
|
+
expect(res).toStrictEqual(toBN(0));
|
|
244
218
|
expect(res).toStrictEqual(result.res);
|
|
245
219
|
});
|
|
246
220
|
|
|
@@ -255,34 +229,18 @@ describe('class Contract {}', () => {
|
|
|
255
229
|
expect(res).toHaveProperty('amount');
|
|
256
230
|
expect(res).toHaveProperty('unit');
|
|
257
231
|
});
|
|
258
|
-
|
|
259
|
-
test('read balance of wallet', async () => {
|
|
260
|
-
const { res } = await erc20.balance_of(account.address);
|
|
261
|
-
|
|
262
|
-
expect(res).toStrictEqual(toBN(1000));
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
test('invoke contract by wallet owner', async () => {
|
|
266
|
-
const { transaction_hash, code } = await erc20.transfer(erc20Address, 10, {
|
|
267
|
-
maxFee: 0,
|
|
268
|
-
});
|
|
269
|
-
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
270
|
-
await defaultProvider.waitForTransaction(transaction_hash);
|
|
271
|
-
const { res } = await erc20.balance_of(account.address);
|
|
272
|
-
expect(res).toStrictEqual(toBN(990));
|
|
273
|
-
});
|
|
274
232
|
});
|
|
275
233
|
});
|
|
276
234
|
|
|
277
235
|
describe('class ContractFactory {}', () => {
|
|
278
236
|
let erc20Address: string;
|
|
279
237
|
beforeAll(async () => {
|
|
280
|
-
const { code, transaction_hash, address } = await
|
|
238
|
+
const { code, transaction_hash, address } = await provider.deployContract({
|
|
281
239
|
contract: compiledErc20,
|
|
282
240
|
});
|
|
283
241
|
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
284
|
-
await
|
|
285
|
-
erc20Address = address
|
|
242
|
+
await provider.waitForTransaction(transaction_hash);
|
|
243
|
+
erc20Address = address!;
|
|
286
244
|
});
|
|
287
245
|
test('deployment of new contract', async () => {
|
|
288
246
|
const factory = new ContractFactory(compiledErc20);
|
package/__tests__/fixtures.ts
CHANGED
|
@@ -1,13 +1,33 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
|
|
3
|
-
import { json } from '../src';
|
|
3
|
+
import { Account, defaultProvider, ec, json } from '../src';
|
|
4
4
|
import { CompiledContract } from '../src/types';
|
|
5
5
|
|
|
6
6
|
const readContract = (name: string): CompiledContract =>
|
|
7
7
|
json.parse(fs.readFileSync(`./__mocks__/${name}.json`).toString('ascii'));
|
|
8
8
|
|
|
9
|
+
export const compiledOpenZeppelinAccount = readContract('Account');
|
|
9
10
|
export const compiledArgentAccount = readContract('ArgentAccount');
|
|
10
11
|
export const compiledErc20 = readContract('ERC20');
|
|
11
12
|
export const compiledTypeTransformation = readContract('contract');
|
|
12
13
|
export const compiledMulticall = readContract('multicall');
|
|
13
14
|
export const compiledTestDapp = readContract('TestDapp');
|
|
15
|
+
|
|
16
|
+
const DEFAULT_TEST_ACCOUNT_ADDRESS =
|
|
17
|
+
'0x6c0a3ca4f79e978f3b7005898aaa49bef4a24aeaa5f10c6a97887516400197e';
|
|
18
|
+
|
|
19
|
+
export const getTestAccount = () => {
|
|
20
|
+
const testAccountAddress = process.env.TEST_ACCOUNT_ADDRESS || DEFAULT_TEST_ACCOUNT_ADDRESS;
|
|
21
|
+
const testAccountPrivateKey = process.env.TEST_ACCOUNT_PRIVATE_KEY;
|
|
22
|
+
|
|
23
|
+
if (!testAccountPrivateKey) {
|
|
24
|
+
throw new Error('TEST_ACCOUNT_PRIVATE_KEY is not set');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return new Account(defaultProvider, testAccountAddress, ec.getKeyPair(testAccountPrivateKey));
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const getTestProvider = () => {
|
|
31
|
+
// Will support both local and remote providers in the future
|
|
32
|
+
return defaultProvider;
|
|
33
|
+
};
|
package/__tests__/jest.setup.ts
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { register } from 'fetch-intercept';
|
|
3
3
|
|
|
4
4
|
jest.setTimeout(50 * 60 * 1000);
|
|
5
5
|
|
|
6
6
|
if (process.env.DEBUG === 'true') {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
register({
|
|
8
|
+
request(url, config) {
|
|
9
|
+
console.log('[fetch.request]', [url, config]);
|
|
10
|
+
return [url, config];
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
requestError(error) {
|
|
14
|
+
console.log('[fetch.requestError]', error);
|
|
15
|
+
return Promise.reject(error);
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
response(response) {
|
|
19
|
+
console.log('[fetch.response]', response);
|
|
20
|
+
return response;
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
responseError(error) {
|
|
24
|
+
console.log('[fetch.responseError]', error);
|
|
25
|
+
return Promise.reject(error);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
9
28
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { defaultProvider, stark } from '../src';
|
|
2
|
+
import { toBN } from '../src/utils/number';
|
|
2
3
|
import { compiledArgentAccount } from './fixtures';
|
|
3
4
|
|
|
4
5
|
const { compileCalldata } = stark;
|
|
@@ -42,7 +43,7 @@ describe('defaultProvider', () => {
|
|
|
42
43
|
)
|
|
43
44
|
).resolves.not.toThrow();
|
|
44
45
|
});
|
|
45
|
-
test('getStorageAt()', () => {
|
|
46
|
+
test('getStorageAt() with "key" type of number', () => {
|
|
46
47
|
return expect(
|
|
47
48
|
defaultProvider.getStorageAt(
|
|
48
49
|
'0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
|
|
@@ -51,6 +52,24 @@ describe('defaultProvider', () => {
|
|
|
51
52
|
)
|
|
52
53
|
).resolves.not.toThrow();
|
|
53
54
|
});
|
|
55
|
+
test('getStorageAt() with "key" type of string', () => {
|
|
56
|
+
return expect(
|
|
57
|
+
defaultProvider.getStorageAt(
|
|
58
|
+
'0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
|
|
59
|
+
'0',
|
|
60
|
+
36663
|
|
61
|
+
)
|
|
62
|
+
).resolves.not.toThrow();
|
|
63
|
+
});
|
|
64
|
+
test('getStorageAt() with "key" type of BN', () => {
|
|
65
|
+
return expect(
|
|
66
|
+
defaultProvider.getStorageAt(
|
|
67
|
+
'0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
|
|
68
|
+
toBN('0x0'),
|
|
69
|
+
36663
|
|
70
|
+
)
|
|
71
|
+
).resolves.not.toThrow();
|
|
72
|
+
});
|
|
54
73
|
test('getStorageAt(blockHash=undefined, blockNumber=null)', () => {
|
|
55
74
|
return expect(
|
|
56
75
|
defaultProvider.getStorageAt(
|
package/account/index.js
CHANGED
|
@@ -4,12 +4,16 @@ var __createBinding =
|
|
|
4
4
|
(Object.create
|
|
5
5
|
? function (o, m, k, k2) {
|
|
6
6
|
if (k2 === undefined) k2 = k;
|
|
7
|
-
Object.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k];
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
13
17
|
}
|
|
14
18
|
: function (o, m, k, k2) {
|
|
15
19
|
if (k2 === undefined) k2 = k;
|
package/contract/default.js
CHANGED
|
@@ -287,10 +287,10 @@ var Contract = /** @class */ (function () {
|
|
|
287
287
|
* @param providerOrAccount (optional) - Provider or Account to attach to
|
|
288
288
|
*/
|
|
289
289
|
function Contract(abi, address, providerOrAccount) {
|
|
290
|
-
var _this = this;
|
|
291
290
|
if (providerOrAccount === void 0) {
|
|
292
291
|
providerOrAccount = provider_1.defaultProvider;
|
|
293
292
|
}
|
|
293
|
+
var _this = this;
|
|
294
294
|
this.address = address;
|
|
295
295
|
this.providerOrAccount = providerOrAccount;
|
|
296
296
|
this.abi = abi;
|
|
@@ -430,7 +430,7 @@ var Contract = /** @class */ (function () {
|
|
|
430
430
|
});
|
|
431
431
|
(0, minimalistic_assert_1.default)(
|
|
432
432
|
invokeableFunctionNames.includes(method),
|
|
433
|
-
(type === 'INVOKE' ? 'invokeable' : 'viewable'
|
|
433
|
+
''.concat(type === 'INVOKE' ? 'invokeable' : 'viewable', ' method not found in abi')
|
|
434
434
|
);
|
|
435
435
|
// ensure args match abi type
|
|
436
436
|
var methodAbi = this.abi.find(function (abi) {
|
|
@@ -446,7 +446,7 @@ var Contract = /** @class */ (function () {
|
|
|
446
446
|
typeof args[argPosition] === 'string' ||
|
|
447
447
|
typeof args[argPosition] === 'number' ||
|
|
448
448
|
args[argPosition] instanceof bn_js_1.default,
|
|
449
|
-
'arg '
|
|
449
|
+
'arg '.concat(input.name, ' should be a felt (string, number, BigNumber)')
|
|
450
450
|
);
|
|
451
451
|
argPosition += 1;
|
|
452
452
|
} else if (input.type in _this.structs && typeof args[argPosition] === 'object') {
|
|
@@ -454,36 +454,36 @@ var Contract = /** @class */ (function () {
|
|
|
454
454
|
var structMembersLength = _this.calculateStructMembers(input.type);
|
|
455
455
|
(0, minimalistic_assert_1.default)(
|
|
456
456
|
args[argPosition].length === structMembersLength,
|
|
457
|
-
'arg should be of length '
|
|
457
|
+
'arg should be of length '.concat(structMembersLength)
|
|
458
458
|
);
|
|
459
459
|
} else {
|
|
460
460
|
_this.structs[input.type].members.forEach(function (_a) {
|
|
461
461
|
var name = _a.name;
|
|
462
462
|
(0,
|
|
463
|
-
minimalistic_assert_1.default)(Object.keys(args[argPosition]).includes(name), 'arg should have a property '
|
|
463
|
+
minimalistic_assert_1.default)(Object.keys(args[argPosition]).includes(name), 'arg should have a property '.concat(name));
|
|
464
464
|
});
|
|
465
465
|
}
|
|
466
466
|
argPosition += 1;
|
|
467
467
|
} else {
|
|
468
468
|
(0, minimalistic_assert_1.default)(
|
|
469
469
|
Array.isArray(args[argPosition]),
|
|
470
|
-
'arg '
|
|
470
|
+
'arg '.concat(input.name, ' should be an Array')
|
|
471
471
|
);
|
|
472
472
|
if (input.type === 'felt*') {
|
|
473
473
|
args[argPosition].forEach(function (felt) {
|
|
474
474
|
(0,
|
|
475
|
-
minimalistic_assert_1.default)(typeof felt === 'string' || typeof felt === 'number' || felt instanceof bn_js_1.default, 'arg '
|
|
475
|
+
minimalistic_assert_1.default)(typeof felt === 'string' || typeof felt === 'number' || felt instanceof bn_js_1.default, 'arg '.concat(input.name, ' should be an array of string, number or BigNumber'));
|
|
476
476
|
});
|
|
477
477
|
argPosition += 1;
|
|
478
478
|
} else if (/\(felt/.test(input.type)) {
|
|
479
479
|
var tupleLength = input.type.split(',').length;
|
|
480
480
|
(0, minimalistic_assert_1.default)(
|
|
481
481
|
args[argPosition].length === tupleLength,
|
|
482
|
-
'arg '
|
|
482
|
+
'arg '.concat(input.name, ' should have ').concat(tupleLength, ' elements in tuple')
|
|
483
483
|
);
|
|
484
484
|
args[argPosition].forEach(function (felt) {
|
|
485
485
|
(0,
|
|
486
|
-
minimalistic_assert_1.default)(typeof felt === 'string' || typeof felt === 'number' || felt instanceof bn_js_1.default, 'arg '
|
|
486
|
+
minimalistic_assert_1.default)(typeof felt === 'string' || typeof felt === 'number' || felt instanceof bn_js_1.default, 'arg '.concat(input.name, ' should be an array of string, number or BigNumber'));
|
|
487
487
|
});
|
|
488
488
|
argPosition += 1;
|
|
489
489
|
} else {
|
|
@@ -495,12 +495,12 @@ var Contract = /** @class */ (function () {
|
|
|
495
495
|
var structMembersLength = _this.calculateStructMembers(arrayType_1);
|
|
496
496
|
(0, minimalistic_assert_1.default)(
|
|
497
497
|
struct.length === structMembersLength,
|
|
498
|
-
'arg should be of length '
|
|
498
|
+
'arg should be of length '.concat(structMembersLength)
|
|
499
499
|
);
|
|
500
500
|
} else {
|
|
501
501
|
(0, minimalistic_assert_1.default)(
|
|
502
502
|
Object.keys(struct).includes(name),
|
|
503
|
-
'arg '
|
|
503
|
+
'arg '.concat(input.name, ' should be an array of ').concat(arrayType_1)
|
|
504
504
|
);
|
|
505
505
|
}
|
|
506
506
|
});
|
|
@@ -616,7 +616,7 @@ var Contract = /** @class */ (function () {
|
|
|
616
616
|
return acc;
|
|
617
617
|
}, parsedCalldata);
|
|
618
618
|
}
|
|
619
|
-
throw Error('Expected '
|
|
619
|
+
throw Error('Expected '.concat(name, ' to be array'));
|
|
620
620
|
case type in this.structs:
|
|
621
621
|
return this.parseCalldataValue(value, type);
|
|
622
622
|
case /\(felt/.test(type):
|
|
@@ -625,7 +625,7 @@ var Contract = /** @class */ (function () {
|
|
|
625
625
|
return (0, number_1.toFelt)(el);
|
|
626
626
|
});
|
|
627
627
|
}
|
|
628
|
-
throw Error('Expected '
|
|
628
|
+
throw Error('Expected '.concat(name, ' to be array'));
|
|
629
629
|
default:
|
|
630
630
|
return (0, number_1.toFelt)(value);
|
|
631
631
|
}
|
|
@@ -673,8 +673,8 @@ var Contract = /** @class */ (function () {
|
|
|
673
673
|
return acc;
|
|
674
674
|
}, []);
|
|
675
675
|
case /\*/.test(type):
|
|
676
|
-
if (parsedResult && parsedResult[name
|
|
677
|
-
var arrLen = parsedResult[name
|
|
676
|
+
if (parsedResult && parsedResult[''.concat(name, '_len')]) {
|
|
677
|
+
var arrLen = parsedResult[''.concat(name, '_len')];
|
|
678
678
|
while (parsedDataArr.length < arrLen) {
|
|
679
679
|
parsedDataArr.push(
|
|
680
680
|
this.parseResponseStruct(responseIterator, output.type.replace('*', ''))
|
|
@@ -703,8 +703,8 @@ var Contract = /** @class */ (function () {
|
|
|
703
703
|
var responseIterator = response.flat()[Symbol.iterator]();
|
|
704
704
|
var resultObject = outputs.flat().reduce(function (acc, output) {
|
|
705
705
|
acc[output.name] = _this.parseResponseField(responseIterator, output, acc);
|
|
706
|
-
if (acc[output.name] && acc[output.name
|
|
707
|
-
delete acc[output.name
|
|
706
|
+
if (acc[output.name] && acc[''.concat(output.name, '_len')]) {
|
|
707
|
+
delete acc[''.concat(output.name, '_len')];
|
|
708
708
|
}
|
|
709
709
|
return acc;
|
|
710
710
|
}, {});
|
|
@@ -742,10 +742,9 @@ var Contract = /** @class */ (function () {
|
|
|
742
742
|
}, 0);
|
|
743
743
|
if (args.length !== inputsLength) {
|
|
744
744
|
throw Error(
|
|
745
|
-
'Invalid number of arguments, expected '
|
|
746
|
-
inputsLength
|
|
747
|
-
|
|
748
|
-
args.length
|
|
745
|
+
'Invalid number of arguments, expected '
|
|
746
|
+
.concat(inputsLength, ' arguments, but got ')
|
|
747
|
+
.concat(args.length)
|
|
749
748
|
);
|
|
750
749
|
}
|
|
751
750
|
// compile calldata
|