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