starknet 3.4.0 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +2 -1
- package/CHANGELOG.md +20 -0
- package/__tests__/account.test.ts +7 -17
- package/__tests__/accountContract.test.ts +13 -25
- package/__tests__/contract.test.ts +152 -55
- package/__tests__/utils/utils.browser.test.ts +1 -3
- package/contract/contractFactory.d.ts +36 -0
- package/contract/contractFactory.js +218 -0
- package/contract/default.d.ts +143 -0
- package/{contract.js → contract/default.js} +357 -86
- package/contract/index.d.ts +3 -0
- package/contract/index.js +28 -0
- package/contract/interface.d.ts +79 -0
- package/contract/interface.js +8 -0
- package/dist/contract/contractFactory.d.ts +32 -0
- package/dist/contract/contractFactory.js +102 -0
- package/dist/contract/default.d.ts +121 -0
- package/dist/{contract.js → contract/default.js} +321 -73
- package/dist/contract/index.d.ts +3 -0
- package/dist/contract/index.js +15 -0
- package/dist/contract/interface.d.ts +72 -0
- package/dist/contract/interface.js +9 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/provider/default.d.ts +4 -1
- package/dist/provider/default.js +15 -6
- package/dist/provider/interface.d.ts +3 -1
- package/dist/types/api.d.ts +6 -0
- package/dist/types/contract.d.ts +5 -0
- package/dist/types/contract.js +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/lib.d.ts +11 -1
- package/dist/utils/transaction.d.ts +1 -2
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/provider/default.d.ts +4 -1
- package/provider/default.js +25 -16
- package/provider/interface.d.ts +3 -1
- package/src/contract/contractFactory.ts +78 -0
- package/src/contract/default.ts +622 -0
- package/src/contract/index.ts +3 -0
- package/src/contract/interface.ts +87 -0
- package/src/index.ts +1 -1
- package/src/provider/default.ts +19 -14
- package/src/provider/interface.ts +3 -1
- package/src/types/api.ts +7 -0
- package/src/types/contract.ts +5 -0
- package/src/types/index.ts +1 -0
- package/src/types/lib.ts +12 -1
- package/src/utils/transaction.ts +1 -2
- package/types/api.d.ts +6 -0
- package/types/contract.d.ts +5 -0
- package/types/contract.js +2 -0
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/types/lib.d.ts +11 -1
- package/utils/transaction.d.ts +1 -2
- package/contract.d.ts +0 -98
- package/dist/contract.d.ts +0 -94
- package/src/contract.ts +0 -357
package/.eslintrc
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"class-methods-use-this": 0,
|
|
22
22
|
"import/prefer-default-export": 0,
|
|
23
23
|
"@typescript-eslint/naming-convention": 0,
|
|
24
|
-
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
|
|
24
|
+
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
|
|
25
|
+
"func-names": 0
|
|
25
26
|
}
|
|
26
27
|
}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
# [3.5.0](https://github.com/seanjameshan/starknet.js/compare/v3.4.0...v3.5.0) (2022-03-11)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- contract test ([a9b4103](https://github.com/seanjameshan/starknet.js/commit/a9b410356baa5c7305da9ba69229c0882f7ae026))
|
|
6
|
+
- **contract-factory:** move more towards ethers.js api ([4caa6ce](https://github.com/seanjameshan/starknet.js/commit/4caa6cee282fe73bc6fb91bea59c620cc42d31a0))
|
|
7
|
+
- **contract:** structure change ([1ef9d2f](https://github.com/seanjameshan/starknet.js/commit/1ef9d2fee0158c9894d5e049f59cc72bfaad2d55))
|
|
8
|
+
- **contract:** tests for new contract interface ([9273f54](https://github.com/seanjameshan/starknet.js/commit/9273f542b087e2940e0d2e88ecbeec58062953bf))
|
|
9
|
+
- enable validateMethodAndArgs on call ([efa63d6](https://github.com/seanjameshan/starknet.js/commit/efa63d6fc7ae77b28f694640833cec73111b175d))
|
|
10
|
+
- reverting validateMethodAndArgs changes ([d847fa8](https://github.com/seanjameshan/starknet.js/commit/d847fa8e4db3563d67861873046f9cb87d0fff8e))
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- **contractFactory:** lib expanded with contract factory ([2c9c3d1](https://github.com/seanjameshan/starknet.js/commit/2c9c3d1b60961ddd698dc6b3175fff2f574f03bd))
|
|
15
|
+
- **contract:** implement `contract.deployed() ⇒ Promise<Contract>` ([91f4992](https://github.com/seanjameshan/starknet.js/commit/91f4992a3f612a03ff5cde01d07a487ebb883f6d))
|
|
16
|
+
- **contract:** new contract interface ([01eeae8](https://github.com/seanjameshan/starknet.js/commit/01eeae815619009de195a759891cad9d8ec992c7))
|
|
17
|
+
- **contract:** new contract methods signature ([cc87943](https://github.com/seanjameshan/starknet.js/commit/cc8794362d2f20816aabf7b44596035d644a434d))
|
|
18
|
+
- default contract args ([2a3956d](https://github.com/seanjameshan/starknet.js/commit/2a3956dab88f3e68a513916b1644fa0723c5235f))
|
|
19
|
+
- **provider:** preparation for the fee integration ([c1c231b](https://github.com/seanjameshan/starknet.js/commit/c1c231b6ec803b01af280baf61d0afbc3f9be6bb))
|
|
20
|
+
|
|
1
21
|
# [3.4.0](https://github.com/seanjameshan/starknet.js/compare/v3.3.0...v3.4.0) (2022-03-10)
|
|
2
22
|
|
|
3
23
|
### Features
|
|
@@ -21,10 +21,7 @@ describe('deploy and test Wallet', () => {
|
|
|
21
21
|
const contract = new Contract(compiledArgentAccount.abi, accountResponse.address);
|
|
22
22
|
expect(accountResponse.code).toBe('TRANSACTION_RECEIVED');
|
|
23
23
|
|
|
24
|
-
const initializeResponse = await contract.
|
|
25
|
-
signer: starkKeyPub,
|
|
26
|
-
guardian: '0',
|
|
27
|
-
});
|
|
24
|
+
const initializeResponse = await contract.initialize(starkKeyPub, '0');
|
|
28
25
|
expect(initializeResponse.code).toBe('TRANSACTION_RECEIVED');
|
|
29
26
|
|
|
30
27
|
account = new Account(defaultProvider, accountResponse.address, starkKeyPair);
|
|
@@ -36,10 +33,7 @@ describe('deploy and test Wallet', () => {
|
|
|
36
33
|
erc20 = new Contract(compiledErc20.abi, erc20Address);
|
|
37
34
|
expect(erc20Response.code).toBe('TRANSACTION_RECEIVED');
|
|
38
35
|
|
|
39
|
-
const mintResponse = await erc20.
|
|
40
|
-
recipient: account.address,
|
|
41
|
-
amount: '1000',
|
|
42
|
-
});
|
|
36
|
+
const mintResponse = await erc20.mint(account.address, '1000');
|
|
43
37
|
expect(mintResponse.code).toBe('TRANSACTION_RECEIVED');
|
|
44
38
|
|
|
45
39
|
const dappResponse = await defaultProvider.deployContract({
|
|
@@ -65,9 +59,7 @@ describe('deploy and test Wallet', () => {
|
|
|
65
59
|
});
|
|
66
60
|
|
|
67
61
|
test('read balance of wallet', async () => {
|
|
68
|
-
const { res } = await erc20.
|
|
69
|
-
user: account.address,
|
|
70
|
-
});
|
|
62
|
+
const { res } = await erc20.balance_of(account.address);
|
|
71
63
|
|
|
72
64
|
expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(1000).toString());
|
|
73
65
|
});
|
|
@@ -84,9 +76,7 @@ describe('deploy and test Wallet', () => {
|
|
|
84
76
|
});
|
|
85
77
|
|
|
86
78
|
test('read balance of wallet after transfer', async () => {
|
|
87
|
-
const { res } = await erc20.
|
|
88
|
-
user: account.address,
|
|
89
|
-
});
|
|
79
|
+
const { res } = await erc20.balance_of(account.address);
|
|
90
80
|
|
|
91
81
|
expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(990).toString());
|
|
92
82
|
});
|
|
@@ -114,12 +104,12 @@ describe('deploy and test Wallet', () => {
|
|
|
114
104
|
test('execute multiple transactions', async () => {
|
|
115
105
|
const { code, transaction_hash } = await account.execute([
|
|
116
106
|
{
|
|
117
|
-
contractAddress: dapp.
|
|
107
|
+
contractAddress: dapp.address,
|
|
118
108
|
entrypoint: 'set_number',
|
|
119
109
|
calldata: ['47'],
|
|
120
110
|
},
|
|
121
111
|
{
|
|
122
|
-
contractAddress: dapp.
|
|
112
|
+
contractAddress: dapp.address,
|
|
123
113
|
entrypoint: 'increase_number',
|
|
124
114
|
calldata: ['10'],
|
|
125
115
|
},
|
|
@@ -128,7 +118,7 @@ describe('deploy and test Wallet', () => {
|
|
|
128
118
|
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
129
119
|
await defaultProvider.waitForTransaction(transaction_hash);
|
|
130
120
|
|
|
131
|
-
const response = await dapp.
|
|
121
|
+
const response = await dapp.get_number(account.address);
|
|
132
122
|
expect(toBN(response.number as string).toString()).toStrictEqual('57');
|
|
133
123
|
});
|
|
134
124
|
|
|
@@ -38,10 +38,7 @@ describe('deploy and test Wallet', () => {
|
|
|
38
38
|
accountContract = new Contract(compiledArgentAccount.abi, accountResponse.address);
|
|
39
39
|
expect(accountResponse.code).toBe('TRANSACTION_RECEIVED');
|
|
40
40
|
|
|
41
|
-
const initializeResponse = await accountContract.
|
|
42
|
-
signer: starkKeyPub,
|
|
43
|
-
guardian: '0',
|
|
44
|
-
});
|
|
41
|
+
const initializeResponse = await accountContract.initialize(starkKeyPub, '0');
|
|
45
42
|
expect(initializeResponse.code).toBe('TRANSACTION_RECEIVED');
|
|
46
43
|
|
|
47
44
|
const erc20Response = await defaultProvider.deployContract({
|
|
@@ -51,46 +48,39 @@ describe('deploy and test Wallet', () => {
|
|
|
51
48
|
erc20 = new Contract(compiledErc20.abi, erc20Address);
|
|
52
49
|
expect(erc20Response.code).toBe('TRANSACTION_RECEIVED');
|
|
53
50
|
|
|
54
|
-
const mintResponse = await erc20.
|
|
55
|
-
recipient: accountContract.connectedTo,
|
|
56
|
-
amount: '1000',
|
|
57
|
-
});
|
|
51
|
+
const mintResponse = await erc20.mint(accountContract.address, '1000');
|
|
58
52
|
expect(mintResponse.code).toBe('TRANSACTION_RECEIVED');
|
|
59
53
|
await defaultProvider.waitForTransaction(mintResponse.transaction_hash);
|
|
60
54
|
});
|
|
61
55
|
|
|
62
56
|
test('read nonce', async () => {
|
|
63
|
-
const { nonce } = await accountContract.
|
|
57
|
+
const { nonce } = await accountContract.get_nonce();
|
|
64
58
|
|
|
65
59
|
expect(number.toBN(nonce as string).toString()).toStrictEqual(number.toBN(0).toString());
|
|
66
60
|
});
|
|
67
61
|
|
|
68
62
|
test('read balance of wallet', async () => {
|
|
69
|
-
const { res } = await erc20.
|
|
70
|
-
user: accountContract.connectedTo,
|
|
71
|
-
});
|
|
63
|
+
const { res } = await erc20.balance_of(accountContract.address);
|
|
72
64
|
|
|
73
|
-
expect(
|
|
65
|
+
expect(res).toStrictEqual(number.toBN(1000));
|
|
74
66
|
});
|
|
75
67
|
|
|
76
68
|
test('execute by wallet owner', async () => {
|
|
77
|
-
const nonce = (await accountContract.
|
|
69
|
+
const nonce = (await accountContract.get_nonce()).nonce.toString();
|
|
78
70
|
|
|
79
71
|
const calls = [
|
|
80
72
|
{ contractAddress: erc20Address, entrypoint: 'transfer', calldata: [erc20Address, '10'] },
|
|
81
73
|
];
|
|
82
|
-
const msgHash = hash.hashMulticall(accountContract.
|
|
74
|
+
const msgHash = hash.hashMulticall(accountContract.address, calls, nonce, '0');
|
|
83
75
|
|
|
84
76
|
const { callArray, calldata } = transformCallsToMulticallArrays(calls);
|
|
85
77
|
|
|
86
78
|
const signature = ec.sign(starkKeyPair, msgHash);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
nonce,
|
|
93
|
-
},
|
|
79
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
80
|
+
const { code, transaction_hash } = await accountContract.__execute__(
|
|
81
|
+
callArray,
|
|
82
|
+
calldata,
|
|
83
|
+
nonce,
|
|
94
84
|
signature
|
|
95
85
|
);
|
|
96
86
|
|
|
@@ -100,9 +90,7 @@ describe('deploy and test Wallet', () => {
|
|
|
100
90
|
});
|
|
101
91
|
|
|
102
92
|
test('read balance of wallet after transfer', async () => {
|
|
103
|
-
const { res } = await erc20.
|
|
104
|
-
user: accountContract.connectedTo,
|
|
105
|
-
});
|
|
93
|
+
const { res } = await erc20.balance_of(accountContract.address);
|
|
106
94
|
|
|
107
95
|
expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(990).toString());
|
|
108
96
|
});
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { isBN } from 'bn.js';
|
|
2
2
|
|
|
3
|
-
import { Contract, defaultProvider, stark } from '../src';
|
|
3
|
+
import { Account, Contract, ContractFactory, Provider, defaultProvider, ec, stark } from '../src';
|
|
4
4
|
import { getSelectorFromName } from '../src/utils/hash';
|
|
5
5
|
import { BigNumberish, toBN } from '../src/utils/number';
|
|
6
6
|
import { compileCalldata } from '../src/utils/stark';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
compiledArgentAccount,
|
|
9
|
+
compiledErc20,
|
|
10
|
+
compiledMulticall,
|
|
11
|
+
compiledTypeTransformation,
|
|
12
|
+
} from './fixtures';
|
|
8
13
|
|
|
9
14
|
describe('class Contract {}', () => {
|
|
10
15
|
const wallet = stark.randomAddress();
|
|
@@ -20,7 +25,6 @@ describe('class Contract {}', () => {
|
|
|
20
25
|
erc20 = new Contract(compiledErc20.abi, address, defaultProvider);
|
|
21
26
|
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
22
27
|
await defaultProvider.waitForTransaction(transaction_hash);
|
|
23
|
-
|
|
24
28
|
// Deploy Multicall
|
|
25
29
|
|
|
26
30
|
const {
|
|
@@ -38,49 +42,56 @@ describe('class Contract {}', () => {
|
|
|
38
42
|
await defaultProvider.waitForTransaction(m_transaction_hash);
|
|
39
43
|
});
|
|
40
44
|
|
|
45
|
+
test('populate transaction for initial balance of that account', async () => {
|
|
46
|
+
const res = await erc20.populateTransaction.balance_of(wallet);
|
|
47
|
+
expect(res).toHaveProperty('contractAddress');
|
|
48
|
+
expect(res).toHaveProperty('entrypoint');
|
|
49
|
+
expect(res).toHaveProperty('calldata');
|
|
50
|
+
expect(res).toHaveProperty('signature');
|
|
51
|
+
});
|
|
52
|
+
|
|
41
53
|
test('read initial balance of that account', async () => {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
});
|
|
54
|
+
const result = await erc20.balance_of(wallet);
|
|
55
|
+
const [res] = result;
|
|
45
56
|
expect(res).toStrictEqual(toBN(0));
|
|
57
|
+
expect(res).toStrictEqual(result.res);
|
|
46
58
|
});
|
|
47
59
|
|
|
48
60
|
test('add 10 test ERC20 to account', async () => {
|
|
49
|
-
const response = await erc20.
|
|
50
|
-
recipient: wallet,
|
|
51
|
-
amount: '10',
|
|
52
|
-
});
|
|
61
|
+
const response = await erc20.mint(wallet, '10');
|
|
53
62
|
expect(response.code).toBe('TRANSACTION_RECEIVED');
|
|
54
63
|
|
|
55
64
|
await defaultProvider.waitForTransaction(response.transaction_hash);
|
|
56
65
|
});
|
|
57
66
|
|
|
58
67
|
test('read balance after mint of that account', async () => {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
|
|
68
|
+
const result = await erc20.balance_of(wallet);
|
|
69
|
+
const [res] = result;
|
|
63
70
|
expect(res).toStrictEqual(toBN(10));
|
|
71
|
+
expect(res).toStrictEqual(result.res);
|
|
64
72
|
});
|
|
65
73
|
|
|
66
74
|
test('read balance in a multicall', async () => {
|
|
67
75
|
const args1 = { user: wallet };
|
|
68
76
|
const args2 = {};
|
|
69
77
|
const calls = [
|
|
70
|
-
erc20.
|
|
78
|
+
erc20.address,
|
|
71
79
|
getSelectorFromName('balance_of'),
|
|
72
80
|
Object.keys(args1).length,
|
|
73
81
|
...compileCalldata(args1),
|
|
74
82
|
|
|
75
|
-
erc20.
|
|
83
|
+
erc20.address,
|
|
76
84
|
getSelectorFromName('decimals'),
|
|
77
85
|
Object.keys(args2).length,
|
|
78
86
|
...compileCalldata(args2),
|
|
79
87
|
];
|
|
80
|
-
const
|
|
88
|
+
const result = await contract.aggregate(calls);
|
|
89
|
+
const [block_number, res] = result;
|
|
81
90
|
expect(isBN(block_number));
|
|
82
|
-
expect(Array.isArray(
|
|
83
|
-
(
|
|
91
|
+
expect(Array.isArray(res));
|
|
92
|
+
(res as BigNumberish[]).forEach((el) => expect(isBN(el)));
|
|
93
|
+
expect(block_number).toStrictEqual(result.block_number);
|
|
94
|
+
expect(res).toStrictEqual(result.result);
|
|
84
95
|
});
|
|
85
96
|
});
|
|
86
97
|
|
|
@@ -98,101 +109,187 @@ describe('class Contract {}', () => {
|
|
|
98
109
|
|
|
99
110
|
describe('Request Type Transformation', () => {
|
|
100
111
|
test('Parsing the felt in request', async () => {
|
|
101
|
-
return expect(contract.
|
|
112
|
+
return expect(contract.request_felt(3)).resolves.not.toThrow();
|
|
102
113
|
});
|
|
103
114
|
|
|
104
115
|
test('Parsing the array of felt in request', async () => {
|
|
105
|
-
return expect(
|
|
106
|
-
contract.call('request_array_of_felts', { arr: [1, 2] })
|
|
107
|
-
).resolves.not.toThrow();
|
|
116
|
+
return expect(contract.request_array_of_felts([1, 2])).resolves.not.toThrow();
|
|
108
117
|
});
|
|
109
118
|
|
|
110
119
|
test('Parsing the struct in request', async () => {
|
|
111
|
-
return expect(
|
|
112
|
-
contract.call('request_struct', {
|
|
113
|
-
str: { x: 1, y: 2 },
|
|
114
|
-
})
|
|
115
|
-
).resolves.not.toThrow();
|
|
120
|
+
return expect(contract.request_struct({ x: 1, y: 2 })).resolves.not.toThrow();
|
|
116
121
|
});
|
|
117
122
|
|
|
118
123
|
test('Parsing the array of structs in request', async () => {
|
|
119
|
-
return expect(
|
|
120
|
-
contract.call('request_array_of_structs', { str: [{ x: 1, y: 2 }] })
|
|
121
|
-
).resolves.not.toThrow();
|
|
124
|
+
return expect(contract.request_array_of_structs([{ x: 1, y: 2 }])).resolves.not.toThrow();
|
|
122
125
|
});
|
|
123
126
|
|
|
124
127
|
test('Parsing the nested structs in request', async () => {
|
|
125
128
|
return expect(
|
|
126
|
-
contract.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
extra: 5,
|
|
131
|
-
},
|
|
129
|
+
contract.request_nested_structs({
|
|
130
|
+
p1: { x: 1, y: 2 },
|
|
131
|
+
p2: { x: 3, y: 4 },
|
|
132
|
+
extra: 5,
|
|
132
133
|
})
|
|
133
134
|
).resolves.not.toThrow();
|
|
134
135
|
});
|
|
135
136
|
|
|
136
137
|
test('Parsing the tuple in request', async () => {
|
|
137
|
-
return expect(contract.
|
|
138
|
+
return expect(contract.request_tuple([1, 2])).resolves.not.toThrow();
|
|
138
139
|
});
|
|
139
140
|
|
|
140
141
|
test('Parsing the multiple types in request', async () => {
|
|
141
|
-
return expect(
|
|
142
|
-
contract.call('request_mixed_types', {
|
|
143
|
-
num: 2,
|
|
144
|
-
point: {
|
|
145
|
-
x: 1,
|
|
146
|
-
y: 2,
|
|
147
|
-
},
|
|
148
|
-
arr: [1],
|
|
149
|
-
})
|
|
150
|
-
).resolves.not.toThrow();
|
|
142
|
+
return expect(contract.request_mixed_types(2, { x: 1, y: 2 }, [1])).resolves.not.toThrow();
|
|
151
143
|
});
|
|
152
144
|
});
|
|
153
145
|
|
|
154
146
|
describe('Response Type Transformation', () => {
|
|
155
147
|
test('Parsing the felt in response', async () => {
|
|
156
|
-
const { res } = await contract.
|
|
148
|
+
const { res } = await contract.get_felt();
|
|
157
149
|
expect(res).toStrictEqual(toBN(4));
|
|
158
150
|
});
|
|
159
151
|
|
|
160
152
|
test('Parsing the array of felt in response', async () => {
|
|
161
|
-
const
|
|
153
|
+
const result = await contract.get_array_of_felts();
|
|
154
|
+
const [res] = result;
|
|
162
155
|
expect(res).toStrictEqual([toBN(4), toBN(5)]);
|
|
156
|
+
expect(res).toStrictEqual(result.res);
|
|
163
157
|
});
|
|
164
158
|
|
|
165
159
|
test('Parsing the array of structs in response', async () => {
|
|
166
|
-
const
|
|
160
|
+
const result = await contract.get_struct();
|
|
161
|
+
const [res] = result;
|
|
167
162
|
expect(res).toStrictEqual({ x: toBN(1), y: toBN(2) });
|
|
163
|
+
expect(res).toStrictEqual(result.res);
|
|
168
164
|
});
|
|
169
165
|
|
|
170
166
|
test('Parsing the array of structs in response', async () => {
|
|
171
|
-
const
|
|
167
|
+
const result = await contract.get_array_of_structs();
|
|
168
|
+
const [res] = result;
|
|
172
169
|
expect(res).toStrictEqual([{ x: toBN(1), y: toBN(2) }]);
|
|
170
|
+
expect(res).toStrictEqual(result.res);
|
|
173
171
|
});
|
|
174
172
|
|
|
175
173
|
test('Parsing the nested structs in response', async () => {
|
|
176
|
-
const
|
|
174
|
+
const result = await contract.get_nested_structs();
|
|
175
|
+
const [res] = result;
|
|
177
176
|
expect(res).toStrictEqual({
|
|
178
177
|
p1: { x: toBN(1), y: toBN(2) },
|
|
179
178
|
p2: { x: toBN(3), y: toBN(4) },
|
|
180
179
|
extra: toBN(5),
|
|
181
180
|
});
|
|
181
|
+
expect(res).toStrictEqual(result.res);
|
|
182
182
|
});
|
|
183
183
|
|
|
184
184
|
test('Parsing the tuple in response', async () => {
|
|
185
|
-
const
|
|
185
|
+
const result = await contract.get_tuple();
|
|
186
|
+
const [res] = result;
|
|
186
187
|
expect(res).toStrictEqual([toBN(1), toBN(2), toBN(3)]);
|
|
188
|
+
expect(res).toStrictEqual(result.res);
|
|
187
189
|
});
|
|
188
190
|
|
|
189
191
|
test('Parsing the multiple types in response', async () => {
|
|
190
|
-
const
|
|
192
|
+
const result = await contract.get_mixed_types();
|
|
193
|
+
const [tuple, number, array, point] = result;
|
|
191
194
|
expect(tuple).toStrictEqual([toBN(1), toBN(2)]);
|
|
192
195
|
expect(number).toStrictEqual(toBN(3));
|
|
193
196
|
expect(array).toStrictEqual([toBN(4)]);
|
|
194
197
|
expect(point).toStrictEqual({ x: toBN(1), y: toBN(2) });
|
|
198
|
+
expect(tuple).toStrictEqual(result.tuple);
|
|
199
|
+
expect(number).toStrictEqual(result.number);
|
|
200
|
+
expect(array).toStrictEqual(result.array);
|
|
201
|
+
expect(point).toStrictEqual(result.point);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe('Contract interaction with Account', () => {
|
|
207
|
+
const privateKey = stark.randomAddress();
|
|
208
|
+
|
|
209
|
+
const starkKeyPair = ec.getKeyPair(privateKey);
|
|
210
|
+
const starkKeyPub = ec.getStarkKey(starkKeyPair);
|
|
211
|
+
let account: Account;
|
|
212
|
+
let erc20: Contract;
|
|
213
|
+
let erc20Address: string;
|
|
214
|
+
|
|
215
|
+
beforeAll(async () => {
|
|
216
|
+
const accountResponse = await defaultProvider.deployContract({
|
|
217
|
+
contract: compiledArgentAccount,
|
|
218
|
+
addressSalt: starkKeyPub,
|
|
195
219
|
});
|
|
220
|
+
const contract = new Contract(compiledArgentAccount.abi, accountResponse.address);
|
|
221
|
+
expect(accountResponse.code).toBe('TRANSACTION_RECEIVED');
|
|
222
|
+
|
|
223
|
+
const initializeResponse = await contract.initialize(starkKeyPub, '0');
|
|
224
|
+
expect(initializeResponse.code).toBe('TRANSACTION_RECEIVED');
|
|
225
|
+
|
|
226
|
+
account = new Account(defaultProvider, accountResponse.address, starkKeyPair);
|
|
227
|
+
|
|
228
|
+
const erc20Response = await defaultProvider.deployContract({
|
|
229
|
+
contract: compiledErc20,
|
|
230
|
+
});
|
|
231
|
+
erc20Address = erc20Response.address;
|
|
232
|
+
erc20 = new Contract(compiledErc20.abi, erc20Address, defaultProvider);
|
|
233
|
+
await defaultProvider.waitForTransaction(erc20Response.transaction_hash);
|
|
234
|
+
expect(erc20Response.code).toBe('TRANSACTION_RECEIVED');
|
|
235
|
+
|
|
236
|
+
const mintResponse = await erc20.mint(account.address, '1000');
|
|
237
|
+
|
|
238
|
+
await defaultProvider.waitForTransaction(mintResponse.transaction_hash);
|
|
196
239
|
});
|
|
240
|
+
|
|
241
|
+
test('read balance of wallet', async () => {
|
|
242
|
+
const result = await erc20.balance_of(account.address);
|
|
243
|
+
const [res] = result;
|
|
244
|
+
expect(res).toStrictEqual(toBN(1000));
|
|
245
|
+
expect(res).toStrictEqual(result.res);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test('change from provider to account', async () => {
|
|
249
|
+
expect(erc20.providerOrAccount instanceof Provider);
|
|
250
|
+
erc20.connect(account);
|
|
251
|
+
expect(erc20.providerOrAccount instanceof Account);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test('read balance of wallet', async () => {
|
|
255
|
+
const { res } = await erc20.balance_of(account.address);
|
|
256
|
+
|
|
257
|
+
expect(res).toStrictEqual(toBN(1000));
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
test('invoke contract by wallet owner', async () => {
|
|
261
|
+
const { transaction_hash, code } = await erc20.transfer(toBN(erc20Address).toString(), 10);
|
|
262
|
+
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
263
|
+
await defaultProvider.waitForTransaction(transaction_hash);
|
|
264
|
+
const { res } = await erc20.balance_of(account.address);
|
|
265
|
+
expect(res).toStrictEqual(toBN(990));
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
describe('class ContractFactory {}', () => {
|
|
271
|
+
let erc20Address: string;
|
|
272
|
+
beforeAll(async () => {
|
|
273
|
+
const { code, transaction_hash, address } = await defaultProvider.deployContract({
|
|
274
|
+
contract: compiledErc20,
|
|
275
|
+
});
|
|
276
|
+
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
277
|
+
await defaultProvider.waitForTransaction(transaction_hash);
|
|
278
|
+
erc20Address = address;
|
|
279
|
+
});
|
|
280
|
+
test('deployment of new contract', async () => {
|
|
281
|
+
const factory = new ContractFactory(compiledErc20);
|
|
282
|
+
const erc20 = await factory.deploy();
|
|
283
|
+
expect(erc20 instanceof Contract);
|
|
284
|
+
});
|
|
285
|
+
test('wait for deployment transaction', async () => {
|
|
286
|
+
const factory = new ContractFactory(compiledErc20);
|
|
287
|
+
const contract = await factory.deploy();
|
|
288
|
+
expect(contract.deployed()).resolves.not.toThrow();
|
|
289
|
+
});
|
|
290
|
+
test('attach new contract', async () => {
|
|
291
|
+
const factory = new ContractFactory(compiledErc20);
|
|
292
|
+
const erc20 = factory.attach(erc20Address);
|
|
293
|
+
expect(erc20 instanceof Contract);
|
|
197
294
|
});
|
|
198
295
|
});
|
|
@@ -17,9 +17,7 @@ test('isBrowser', () => {
|
|
|
17
17
|
});
|
|
18
18
|
describe('compressProgram()', () => {
|
|
19
19
|
test('compresses a contract program', () => {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const compressed = stark.compressProgram(inputContract.program);
|
|
20
|
+
const compressed = stark.compressProgram(compiledArgentAccount.program);
|
|
23
21
|
|
|
24
22
|
expect(compressed).toMatchSnapshot();
|
|
25
23
|
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Account } from '../account';
|
|
2
|
+
import { Provider } from '../provider';
|
|
3
|
+
import { Abi, CompiledContract, RawCalldata } from '../types';
|
|
4
|
+
import { BigNumberish } from '../utils/number';
|
|
5
|
+
import { Contract } from './default';
|
|
6
|
+
export declare class ContractFactory {
|
|
7
|
+
abi: Abi;
|
|
8
|
+
compiledContract: CompiledContract;
|
|
9
|
+
providerOrAccount: Provider | Account;
|
|
10
|
+
constructor(
|
|
11
|
+
compiledContract: CompiledContract,
|
|
12
|
+
providerOrAccount?: Provider | Account,
|
|
13
|
+
abi?: Abi
|
|
14
|
+
);
|
|
15
|
+
/**
|
|
16
|
+
* Deploys contract and returns new instance of the Contract
|
|
17
|
+
*
|
|
18
|
+
* @param constructorCalldata - Constructor Calldata
|
|
19
|
+
* @param addressSalt (optional) - Address Salt for deployment
|
|
20
|
+
* @returns deployed Contract
|
|
21
|
+
*/
|
|
22
|
+
deploy(constructorCalldata?: RawCalldata, addressSalt?: BigNumberish): Promise<Contract>;
|
|
23
|
+
/**
|
|
24
|
+
* Attaches to new Provider or Account
|
|
25
|
+
*
|
|
26
|
+
* @param providerOrAccount - new Provider or Account to attach to
|
|
27
|
+
*/
|
|
28
|
+
connect(providerOrAccount: Provider | Account): ContractFactory;
|
|
29
|
+
/**
|
|
30
|
+
* Attaches current abi and provider or account to the new address
|
|
31
|
+
*
|
|
32
|
+
* @param address - Contract address
|
|
33
|
+
* @returns Contract
|
|
34
|
+
*/
|
|
35
|
+
attach(address: string): Contract;
|
|
36
|
+
}
|