starknet 4.8.0 → 4.10.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 +46 -0
- package/README.md +1 -3
- package/__mocks__/ERC20.json +32561 -29055
- package/__tests__/account.test.ts +32 -24
- package/__tests__/contract.test.ts +25 -14
- package/__tests__/defaultProvider.test.ts +91 -240
- package/__tests__/fixtures.ts +10 -2
- package/__tests__/rpcProvider.test.ts +8 -16
- package/__tests__/sequencerProvider.test.ts +17 -10
- package/__tests__/udc.test.ts +41 -0
- package/__tests__/utils/merkle.test.ts +98 -3
- package/__tests__/utils/typedData.test.ts +3 -3
- package/account/default.d.ts +12 -44
- package/account/default.js +305 -61
- package/account/interface.d.ts +96 -8
- package/constants.d.ts +8 -1
- package/constants.js +8 -1
- package/contract/default.d.ts +11 -27
- package/contract/default.js +105 -121
- package/contract/interface.d.ts +5 -2
- package/dist/account/default.d.ts +12 -44
- package/dist/account/default.js +305 -61
- package/dist/account/interface.d.ts +96 -8
- package/dist/constants.d.ts +8 -1
- package/dist/constants.js +8 -1
- package/dist/contract/default.d.ts +11 -27
- package/dist/contract/default.js +105 -121
- package/dist/contract/interface.d.ts +5 -2
- package/dist/provider/default.d.ts +8 -3
- package/dist/provider/default.js +31 -4
- package/dist/provider/interface.d.ts +67 -5
- package/dist/provider/rpc.d.ts +10 -3
- package/dist/provider/rpc.js +98 -10
- package/dist/provider/sequencer.d.ts +11 -4
- package/dist/provider/sequencer.js +89 -18
- package/dist/signer/default.d.ts +5 -2
- package/dist/signer/default.js +25 -3
- package/dist/signer/interface.d.ts +29 -2
- package/dist/types/api/index.d.ts +0 -6
- package/dist/types/api/openrpc.d.ts +24 -2
- package/dist/types/api/sequencer.d.ts +22 -7
- package/dist/types/index.d.ts +1 -1
- package/dist/types/lib.d.ts +36 -2
- package/dist/types/provider.d.ts +15 -10
- package/dist/types/signer.d.ts +14 -1
- package/dist/utils/hash.d.ts +2 -0
- package/dist/utils/hash.js +13 -2
- package/dist/utils/merkle.js +2 -4
- package/dist/utils/number.d.ts +1 -0
- package/dist/utils/number.js +3 -1
- package/dist/utils/responseParser/rpc.d.ts +2 -6
- package/dist/utils/responseParser/rpc.js +0 -11
- package/dist/utils/responseParser/sequencer.js +4 -14
- package/package.json +1 -1
- package/provider/default.d.ts +8 -3
- package/provider/default.js +31 -4
- package/provider/interface.d.ts +67 -5
- package/provider/rpc.d.ts +10 -3
- package/provider/rpc.js +98 -10
- package/provider/sequencer.d.ts +11 -4
- package/provider/sequencer.js +89 -18
- package/signer/default.d.ts +5 -2
- package/signer/default.js +25 -3
- package/signer/interface.d.ts +29 -2
- package/src/account/default.ts +243 -55
- package/src/account/interface.ts +132 -7
- package/src/constants.ts +8 -0
- package/src/contract/default.ts +124 -141
- package/src/contract/interface.ts +5 -2
- package/src/provider/default.ts +43 -5
- package/src/provider/interface.ts +92 -7
- package/src/provider/rpc.ts +93 -15
- package/src/provider/sequencer.ts +87 -14
- package/src/signer/default.ts +56 -4
- package/src/signer/interface.ts +33 -2
- package/src/types/api/index.ts +0 -4
- package/src/types/api/openrpc.ts +28 -2
- package/src/types/api/sequencer.ts +32 -9
- package/src/types/index.ts +1 -1
- package/src/types/lib.ts +43 -2
- package/src/types/provider.ts +27 -11
- package/src/types/signer.ts +18 -1
- package/src/utils/hash.ts +46 -1
- package/src/utils/merkle.ts +2 -4
- package/src/utils/number.ts +2 -0
- package/src/utils/responseParser/rpc.ts +4 -20
- package/src/utils/responseParser/sequencer.ts +2 -0
- package/types/api/index.d.ts +0 -6
- package/types/api/openrpc.d.ts +24 -2
- package/types/api/sequencer.d.ts +22 -7
- package/types/index.d.ts +1 -1
- package/types/lib.d.ts +36 -2
- package/types/provider.d.ts +15 -10
- package/types/signer.d.ts +14 -1
- package/utils/hash.d.ts +2 -0
- package/utils/hash.js +13 -2
- package/utils/merkle.js +2 -4
- package/utils/number.d.ts +1 -0
- package/utils/number.js +3 -1
- package/utils/responseParser/rpc.d.ts +2 -6
- package/utils/responseParser/rpc.js +0 -11
- package/utils/responseParser/sequencer.js +4 -14
- package/www/docs/API/account.md +170 -11
- package/www/docs/API/contract.md +39 -3
- package/www/docs/API/provider.md +310 -17
- package/www/docs/API/signer.md +56 -2
- package/www/guides/erc20.md +13 -7
|
@@ -3,7 +3,13 @@ import { isBN } from 'bn.js';
|
|
|
3
3
|
import typedDataExample from '../__mocks__/typedDataExample.json';
|
|
4
4
|
import { Account, Contract, Provider, number, stark } from '../src';
|
|
5
5
|
import { toBN } from '../src/utils/number';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
compiledErc20,
|
|
8
|
+
compiledTestDapp,
|
|
9
|
+
getERC20DeployPayload,
|
|
10
|
+
getTestAccount,
|
|
11
|
+
getTestProvider,
|
|
12
|
+
} from './fixtures';
|
|
7
13
|
|
|
8
14
|
describe('deploy and test Wallet', () => {
|
|
9
15
|
const provider = getTestProvider();
|
|
@@ -15,26 +21,18 @@ describe('deploy and test Wallet', () => {
|
|
|
15
21
|
beforeAll(async () => {
|
|
16
22
|
expect(account).toBeInstanceOf(Account);
|
|
17
23
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
const erc20DeployPayload = getERC20DeployPayload(account.address);
|
|
25
|
+
|
|
26
|
+
const erc20Response = await provider.deployContract(erc20DeployPayload);
|
|
21
27
|
|
|
22
28
|
erc20Address = erc20Response.contract_address;
|
|
23
29
|
erc20 = new Contract(compiledErc20.abi, erc20Address, provider);
|
|
24
30
|
|
|
25
31
|
await provider.waitForTransaction(erc20Response.transaction_hash);
|
|
26
32
|
|
|
27
|
-
const
|
|
28
|
-
contractAddress: erc20Address,
|
|
29
|
-
entrypoint: 'mint',
|
|
30
|
-
calldata: [account.address, '1000'],
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
await provider.waitForTransaction(mintResponse.transaction_hash);
|
|
33
|
+
const x = await erc20.balanceOf(account.address);
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
expect(number.toBN(x.res as string).toString()).toStrictEqual(number.toBN(1000).toString());
|
|
35
|
+
expect(number.toBN(x[0].low).toString()).toStrictEqual(number.toBN(1000).toString());
|
|
38
36
|
|
|
39
37
|
const dappResponse = await provider.deployContract({
|
|
40
38
|
contract: compiledTestDapp,
|
|
@@ -45,34 +43,34 @@ describe('deploy and test Wallet', () => {
|
|
|
45
43
|
});
|
|
46
44
|
|
|
47
45
|
test('estimate fee', async () => {
|
|
48
|
-
const { overall_fee } = await account.
|
|
46
|
+
const { overall_fee } = await account.estimateInvokeFee({
|
|
49
47
|
contractAddress: erc20Address,
|
|
50
48
|
entrypoint: 'transfer',
|
|
51
|
-
calldata: [erc20.address, '10'],
|
|
49
|
+
calldata: [erc20.address, '10', '0'],
|
|
52
50
|
});
|
|
53
51
|
expect(isBN(overall_fee)).toBe(true);
|
|
54
52
|
});
|
|
55
53
|
|
|
56
54
|
test('read balance of wallet', async () => {
|
|
57
|
-
const x = await erc20.
|
|
55
|
+
const x = await erc20.balanceOf(account.address);
|
|
58
56
|
|
|
59
|
-
expect(number.toBN(x.
|
|
57
|
+
expect(number.toBN(x[0].low).toString()).toStrictEqual(number.toBN(1000).toString());
|
|
60
58
|
});
|
|
61
59
|
|
|
62
60
|
test('execute by wallet owner', async () => {
|
|
63
61
|
const { transaction_hash } = await account.execute({
|
|
64
62
|
contractAddress: erc20Address,
|
|
65
63
|
entrypoint: 'transfer',
|
|
66
|
-
calldata: [erc20.address, '10'],
|
|
64
|
+
calldata: [erc20.address, '10', '0'],
|
|
67
65
|
});
|
|
68
66
|
|
|
69
67
|
await provider.waitForTransaction(transaction_hash);
|
|
70
68
|
});
|
|
71
69
|
|
|
72
70
|
test('read balance of wallet after transfer', async () => {
|
|
73
|
-
const {
|
|
71
|
+
const { balance } = await erc20.balanceOf(account.address);
|
|
74
72
|
|
|
75
|
-
expect(
|
|
73
|
+
expect(balance.low).toStrictEqual(toBN(990));
|
|
76
74
|
});
|
|
77
75
|
|
|
78
76
|
test('execute with custom nonce', async () => {
|
|
@@ -82,7 +80,7 @@ describe('deploy and test Wallet', () => {
|
|
|
82
80
|
{
|
|
83
81
|
contractAddress: erc20Address,
|
|
84
82
|
entrypoint: 'transfer',
|
|
85
|
-
calldata: [account.address, '10'],
|
|
83
|
+
calldata: [account.address, '10', '0'],
|
|
86
84
|
},
|
|
87
85
|
undefined,
|
|
88
86
|
{ nonce }
|
|
@@ -130,7 +128,7 @@ describe('deploy and test Wallet', () => {
|
|
|
130
128
|
const mintResponse = await account.execute({
|
|
131
129
|
contractAddress: erc20Address,
|
|
132
130
|
entrypoint: 'mint',
|
|
133
|
-
calldata: [wallet, '1000'],
|
|
131
|
+
calldata: [wallet, '1000', '0'],
|
|
134
132
|
});
|
|
135
133
|
|
|
136
134
|
await provider.waitForTransaction(mintResponse.transaction_hash);
|
|
@@ -143,8 +141,18 @@ describe('deploy and test Wallet', () => {
|
|
|
143
141
|
});
|
|
144
142
|
|
|
145
143
|
test('estimate gas fee for `mint`', async () => {
|
|
146
|
-
const res = await erc20.estimateFee.mint(wallet, '10');
|
|
144
|
+
const res = await erc20.estimateFee.mint(wallet, ['10', '0']);
|
|
147
145
|
expect(res).toHaveProperty('overall_fee');
|
|
148
146
|
});
|
|
147
|
+
|
|
148
|
+
test('Declare ERC20 contract', async () => {
|
|
149
|
+
const declareTx = await account.declare({
|
|
150
|
+
contract: compiledErc20,
|
|
151
|
+
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
|
|
152
|
+
});
|
|
153
|
+
await provider.waitForTransaction(declareTx.transaction_hash);
|
|
154
|
+
|
|
155
|
+
expect(declareTx.class_hash).toBeDefined();
|
|
156
|
+
});
|
|
149
157
|
});
|
|
150
158
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isBN } from 'bn.js';
|
|
2
2
|
|
|
3
3
|
import { Contract, ContractFactory, stark } from '../src';
|
|
4
|
+
import { DeployContractPayload } from '../src/types/lib';
|
|
4
5
|
import { getSelectorFromName } from '../src/utils/hash';
|
|
5
6
|
import { BigNumberish, toBN } from '../src/utils/number';
|
|
6
7
|
import { compileCalldata } from '../src/utils/stark';
|
|
@@ -8,6 +9,7 @@ import {
|
|
|
8
9
|
compiledErc20,
|
|
9
10
|
compiledMulticall,
|
|
10
11
|
compiledTypeTransformation,
|
|
12
|
+
getERC20DeployPayload,
|
|
11
13
|
getTestProvider,
|
|
12
14
|
} from './fixtures';
|
|
13
15
|
|
|
@@ -21,9 +23,12 @@ describe('class Contract {}', () => {
|
|
|
21
23
|
let contract: Contract;
|
|
22
24
|
|
|
23
25
|
beforeAll(async () => {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
}
|
|
26
|
+
const erc20DeployPayload = getERC20DeployPayload(wallet);
|
|
27
|
+
|
|
28
|
+
const { contract_address, transaction_hash } = await provider.deployContract(
|
|
29
|
+
erc20DeployPayload
|
|
30
|
+
);
|
|
31
|
+
|
|
27
32
|
erc20 = new Contract(compiledErc20.abi, contract_address!, provider);
|
|
28
33
|
await provider.waitForTransaction(transaction_hash);
|
|
29
34
|
// Deploy Multicall
|
|
@@ -39,21 +44,21 @@ describe('class Contract {}', () => {
|
|
|
39
44
|
});
|
|
40
45
|
|
|
41
46
|
test('populate transaction for initial balance of that account', async () => {
|
|
42
|
-
const res = await erc20.populateTransaction.
|
|
47
|
+
const res = await erc20.populateTransaction.balanceOf(wallet);
|
|
43
48
|
expect(res).toHaveProperty('contractAddress');
|
|
44
49
|
expect(res).toHaveProperty('entrypoint');
|
|
45
50
|
expect(res).toHaveProperty('calldata');
|
|
46
51
|
});
|
|
47
52
|
|
|
48
53
|
test('estimate gas fee for `mint` should fail when connected to the provider', async () => {
|
|
49
|
-
expect(erc20.estimateFee.mint(wallet, '10')).rejects.toThrow();
|
|
54
|
+
expect(erc20.estimateFee.mint(wallet, ['10', '0'])).rejects.toThrow();
|
|
50
55
|
});
|
|
51
56
|
|
|
52
57
|
test('read initial balance of that account', async () => {
|
|
53
|
-
const result = await erc20.
|
|
58
|
+
const result = await erc20.balanceOf(wallet);
|
|
54
59
|
const [res] = result;
|
|
55
|
-
expect(res).toStrictEqual(toBN(
|
|
56
|
-
expect(res).toStrictEqual(result.
|
|
60
|
+
expect(res.low).toStrictEqual(toBN(1000));
|
|
61
|
+
expect(res).toStrictEqual(result.balance);
|
|
57
62
|
});
|
|
58
63
|
|
|
59
64
|
test('read balance in a multicall', async () => {
|
|
@@ -61,7 +66,7 @@ describe('class Contract {}', () => {
|
|
|
61
66
|
const args2 = {};
|
|
62
67
|
const calls = [
|
|
63
68
|
erc20.address,
|
|
64
|
-
getSelectorFromName('
|
|
69
|
+
getSelectorFromName('balanceOf'),
|
|
65
70
|
Object.keys(args1).length,
|
|
66
71
|
...compileCalldata(args1),
|
|
67
72
|
|
|
@@ -190,21 +195,27 @@ describe('class Contract {}', () => {
|
|
|
190
195
|
|
|
191
196
|
describe('class ContractFactory {}', () => {
|
|
192
197
|
let erc20Address: string;
|
|
198
|
+
const wallet = stark.randomAddress();
|
|
199
|
+
let erc20DeployPayload: DeployContractPayload;
|
|
200
|
+
|
|
193
201
|
beforeAll(async () => {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
202
|
+
erc20DeployPayload = getERC20DeployPayload(wallet);
|
|
203
|
+
|
|
204
|
+
const { contract_address, transaction_hash } = await provider.deployContract(
|
|
205
|
+
erc20DeployPayload
|
|
206
|
+
);
|
|
207
|
+
|
|
197
208
|
await provider.waitForTransaction(transaction_hash);
|
|
198
209
|
erc20Address = contract_address;
|
|
199
210
|
});
|
|
200
211
|
test('deployment of new contract', async () => {
|
|
201
212
|
const factory = new ContractFactory(compiledErc20, provider);
|
|
202
|
-
const erc20 = await factory.deploy();
|
|
213
|
+
const erc20 = await factory.deploy(erc20DeployPayload.constructorCalldata);
|
|
203
214
|
expect(erc20 instanceof Contract);
|
|
204
215
|
});
|
|
205
216
|
test('wait for deployment transaction', async () => {
|
|
206
217
|
const factory = new ContractFactory(compiledErc20, provider);
|
|
207
|
-
const contract = await factory.deploy();
|
|
218
|
+
const contract = await factory.deploy(erc20DeployPayload.constructorCalldata);
|
|
208
219
|
expect(contract.deployed()).resolves.not.toThrow();
|
|
209
220
|
});
|
|
210
221
|
test('attach new contract', async () => {
|
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BlockNumber,
|
|
3
|
-
DeclareContractResponse,
|
|
4
|
-
DeployContractResponse,
|
|
5
|
-
GetBlockResponse,
|
|
6
|
-
stark,
|
|
7
|
-
} from '../src';
|
|
1
|
+
import { BlockNumber, GetBlockResponse, stark } from '../src';
|
|
8
2
|
import { toBN } from '../src/utils/number';
|
|
9
|
-
import {
|
|
10
|
-
compiledErc20,
|
|
11
|
-
compiledOpenZeppelinAccount,
|
|
12
|
-
describeIfNotDevnet,
|
|
13
|
-
getTestProvider,
|
|
14
|
-
} from './fixtures';
|
|
3
|
+
import { getERC20DeployPayload, getTestProvider } from './fixtures';
|
|
15
4
|
|
|
16
5
|
const { compileCalldata } = stark;
|
|
17
6
|
|
|
@@ -24,11 +13,14 @@ describe('defaultProvider', () => {
|
|
|
24
13
|
let exampleBlock: GetBlockResponse;
|
|
25
14
|
let exampleBlockNumber: BlockNumber;
|
|
26
15
|
let exampleBlockHash: string;
|
|
16
|
+
const wallet = stark.randomAddress();
|
|
27
17
|
|
|
28
18
|
beforeAll(async () => {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
}
|
|
19
|
+
const erc20DeployPayload = getERC20DeployPayload(wallet);
|
|
20
|
+
|
|
21
|
+
const { contract_address, transaction_hash } = await testProvider.deployContract(
|
|
22
|
+
erc20DeployPayload
|
|
23
|
+
);
|
|
32
24
|
await testProvider.waitForTransaction(transaction_hash);
|
|
33
25
|
exampleTransactionHash = transaction_hash;
|
|
34
26
|
exampleContractAddress = contract_address;
|
|
@@ -39,27 +31,47 @@ describe('defaultProvider', () => {
|
|
|
39
31
|
});
|
|
40
32
|
|
|
41
33
|
describe('endpoints', () => {
|
|
42
|
-
test(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
test(`getBlock(blockHash=${exampleBlockHash}, blockNumber=undefined)`, () => {
|
|
47
|
-
return expect(testProvider.getBlock(exampleBlockHash)).resolves.not.toThrow();
|
|
34
|
+
test('deployContract()', () => {
|
|
35
|
+
expect(exampleContractAddress).toBeTruthy();
|
|
36
|
+
expect(exampleTransactionHash).toBeTruthy();
|
|
48
37
|
});
|
|
49
38
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
39
|
+
describe('getBlock', () => {
|
|
40
|
+
test('getBlock(blockIdentifier=latest)', async () => {
|
|
41
|
+
expect(exampleBlock).not.toBeNull();
|
|
42
|
+
const { block_number, timestamp } = exampleBlock;
|
|
43
|
+
expect(typeof block_number).toEqual('number');
|
|
44
|
+
return expect(typeof timestamp).toEqual('number');
|
|
45
|
+
});
|
|
54
46
|
|
|
55
|
-
|
|
47
|
+
test(`getBlock(blockHash=undefined, blockNumber=${exampleBlockNumber})`, async () => {
|
|
48
|
+
const block = await testProvider.getBlock(exampleBlockNumber);
|
|
49
|
+
expect(block).toHaveProperty('block_hash');
|
|
50
|
+
expect(block).toHaveProperty('parent_hash');
|
|
51
|
+
expect(block).toHaveProperty('block_number');
|
|
52
|
+
expect(block).toHaveProperty('status');
|
|
53
|
+
expect(block).toHaveProperty('new_root');
|
|
54
|
+
expect(block).toHaveProperty('timestamp');
|
|
55
|
+
expect(block).toHaveProperty('transactions');
|
|
56
|
+
expect(Array.isArray(block.transactions)).toBe(true);
|
|
57
|
+
});
|
|
56
58
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
test(`getBlock(blockHash=${exampleBlockHash}, blockNumber=undefined)`, async () => {
|
|
60
|
+
const block = await testProvider.getBlock(exampleBlockHash);
|
|
61
|
+
expect(block).toHaveProperty('block_hash');
|
|
62
|
+
expect(block).toHaveProperty('parent_hash');
|
|
63
|
+
expect(block).toHaveProperty('block_number');
|
|
64
|
+
expect(block).toHaveProperty('status');
|
|
65
|
+
expect(block).toHaveProperty('new_root');
|
|
66
|
+
expect(block).toHaveProperty('timestamp');
|
|
67
|
+
expect(block).toHaveProperty('transactions');
|
|
68
|
+
expect(Array.isArray(block.transactions)).toBe(true);
|
|
69
|
+
});
|
|
59
70
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
71
|
+
test('getBlock() -> { blockNumber }', async () => {
|
|
72
|
+
const block = await testProvider.getBlock('latest');
|
|
73
|
+
return expect(block).toHaveProperty('block_number');
|
|
74
|
+
});
|
|
63
75
|
});
|
|
64
76
|
|
|
65
77
|
test('getNonce()', async () => {
|
|
@@ -67,6 +79,13 @@ describe('defaultProvider', () => {
|
|
|
67
79
|
return expect(nonce).toEqual('0x0');
|
|
68
80
|
});
|
|
69
81
|
|
|
82
|
+
test('getClassAt(contractAddress, blockNumber="latest")', async () => {
|
|
83
|
+
const classResponse = await testProvider.getClassAt(exampleContractAddress);
|
|
84
|
+
|
|
85
|
+
expect(classResponse).toHaveProperty('program');
|
|
86
|
+
expect(classResponse).toHaveProperty('entry_points_by_type');
|
|
87
|
+
});
|
|
88
|
+
|
|
70
89
|
describe('getStorageAt', () => {
|
|
71
90
|
test('with "key" type of number', () => {
|
|
72
91
|
return expect(testProvider.getStorageAt(exampleContractAddress, 0)).resolves.not.toThrow();
|
|
@@ -85,7 +104,7 @@ describe('defaultProvider', () => {
|
|
|
85
104
|
});
|
|
86
105
|
});
|
|
87
106
|
|
|
88
|
-
test('getTransaction() - successful transaction', async () => {
|
|
107
|
+
test('getTransaction() - successful deploy transaction', async () => {
|
|
89
108
|
const transaction = await testProvider.getTransaction(exampleTransactionHash);
|
|
90
109
|
|
|
91
110
|
expect(transaction).toHaveProperty('transaction_hash');
|
|
@@ -94,219 +113,51 @@ describe('defaultProvider', () => {
|
|
|
94
113
|
test('getTransactionReceipt() - successful transaction', async () => {
|
|
95
114
|
const transactionReceipt = await testProvider.getTransactionReceipt(exampleTransactionHash);
|
|
96
115
|
|
|
97
|
-
|
|
116
|
+
expect(transactionReceipt).toHaveProperty('actual_fee');
|
|
117
|
+
expect(transactionReceipt).toHaveProperty('transaction_hash');
|
|
118
|
+
expect(transactionReceipt).toHaveProperty('status');
|
|
119
|
+
expect(transactionReceipt).toHaveProperty('actual_fee');
|
|
98
120
|
});
|
|
99
121
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
test('callContract() - gateway error', async () => {
|
|
113
|
-
return expect(
|
|
114
|
-
testProvider.callContract({
|
|
115
|
-
contractAddress: exampleContractAddress,
|
|
116
|
-
entrypoint: 'non_existent_entrypoint',
|
|
117
|
-
calldata: compileCalldata({
|
|
118
|
-
user: '0xdeadbeef',
|
|
119
|
-
}),
|
|
120
|
-
})
|
|
121
|
-
).rejects.toThrowError();
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
describe('addTransaction()', () => {
|
|
126
|
-
test('declareContract()', async () => {
|
|
127
|
-
const response = await testProvider.declareContract({
|
|
128
|
-
contract: compiledErc20,
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
expect(response.transaction_hash).toBeDefined();
|
|
132
|
-
expect(response.class_hash).toBeDefined();
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test('deployContract()', async () => {
|
|
136
|
-
const response = await testProvider.deployContract({
|
|
137
|
-
contract: compiledOpenZeppelinAccount,
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
expect(response.transaction_hash).toBeDefined();
|
|
141
|
-
expect(response.contract_address).toBeDefined();
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
describeIfNotDevnet('Provider', () => {
|
|
146
|
-
const provider = getTestProvider();
|
|
147
|
-
let latestBlock;
|
|
148
|
-
describe(`Provider methods if not devnet`, () => {
|
|
149
|
-
describe('getBlock', () => {
|
|
150
|
-
test('getBlock by tag pending', async () => {
|
|
151
|
-
latestBlock = await provider.getBlock();
|
|
152
|
-
expect(latestBlock).toHaveProperty('block_hash');
|
|
153
|
-
expect(latestBlock).toHaveProperty('parent_hash');
|
|
154
|
-
expect(latestBlock).toHaveProperty('block_number');
|
|
155
|
-
expect(latestBlock).toHaveProperty('status');
|
|
156
|
-
expect(latestBlock).toHaveProperty('new_root');
|
|
157
|
-
expect(latestBlock).toHaveProperty('timestamp');
|
|
158
|
-
expect(latestBlock).toHaveProperty('transactions');
|
|
159
|
-
expect(Array.isArray(latestBlock.transactions)).toBe(true);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
test('getBlock by Hash', async () => {
|
|
163
|
-
const block = await provider.getBlock(latestBlock.block_hash);
|
|
164
|
-
expect(block).toHaveProperty('block_hash');
|
|
165
|
-
expect(block).toHaveProperty('parent_hash');
|
|
166
|
-
expect(block).toHaveProperty('block_number');
|
|
167
|
-
expect(block).toHaveProperty('status');
|
|
168
|
-
expect(block).toHaveProperty('new_root');
|
|
169
|
-
expect(block).toHaveProperty('timestamp');
|
|
170
|
-
expect(block).toHaveProperty('transactions');
|
|
171
|
-
expect(Array.isArray(block.transactions)).toBe(true);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
test('getBlock by Number', async () => {
|
|
175
|
-
const block = await provider.getBlock(latestBlock.block_number);
|
|
176
|
-
expect(block).toHaveProperty('block_hash');
|
|
177
|
-
expect(block).toHaveProperty('parent_hash');
|
|
178
|
-
expect(block).toHaveProperty('block_number');
|
|
179
|
-
expect(block).toHaveProperty('status');
|
|
180
|
-
expect(block).toHaveProperty('new_root');
|
|
181
|
-
expect(block).toHaveProperty('timestamp');
|
|
182
|
-
expect(block).toHaveProperty('transactions');
|
|
183
|
-
expect(Array.isArray(block.transactions)).toBe(true);
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
describe('getStorageAt', () => {
|
|
188
|
-
test('pending', async () => {
|
|
189
|
-
const storage = await provider.getStorageAt(
|
|
190
|
-
'0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
|
|
191
|
-
'0'
|
|
192
|
-
);
|
|
193
|
-
expect(typeof storage).toBe('string');
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
test('Block Hash 0x7104702055c2a5773a870ceada9552ec659d69c18053b14078983f07527dea8', async () => {
|
|
197
|
-
const storage = await provider.getStorageAt(
|
|
198
|
-
'0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
|
|
199
|
-
'0',
|
|
200
|
-
'0x7225762c7ff5e7e5f0867f0a8e73594df4f44f05a65375339a76398e8ae3e64'
|
|
201
|
-
);
|
|
202
|
-
expect(typeof storage).toBe('string');
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
describe('getTransaction', () => {
|
|
207
|
-
test('Deploy Transaction Hash 0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348', async () => {
|
|
208
|
-
const transaction = await provider.getTransaction(
|
|
209
|
-
'0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
expect(transaction.transaction_hash).toBeTruthy();
|
|
213
|
-
expect(transaction.contract_address).toBeTruthy();
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
test('Invoke Transaction Hash 0x2a56c636f45761c99a67ecdf0f185a6d5fe5239924ed9a4886fddbfaf3227b', async () => {
|
|
217
|
-
const transaction = await provider.getTransaction(
|
|
218
|
-
'0x2a56c636f45761c99a67ecdf0f185a6d5fe5239924ed9a4886fddbfaf3227b'
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
expect(transaction.transaction_hash).toBeTruthy();
|
|
222
|
-
expect(transaction.contract_address).toBeTruthy();
|
|
223
|
-
expect(Array.isArray(transaction.calldata)).toBe(true);
|
|
224
|
-
expect(Array.isArray(transaction.signature)).toBe(true);
|
|
225
|
-
expect(transaction.max_fee).toBeTruthy();
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
test('Declare Transaction Hash 0x79b130f2e808db6ab4b83f0182f016a128d73752b849e5b0221c2b3a35a87ea', async () => {
|
|
229
|
-
const transaction = await provider.getTransaction(
|
|
230
|
-
'0x79b130f2e808db6ab4b83f0182f016a128d73752b849e5b0221c2b3a35a87ea'
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
expect(transaction.max_fee).toBeTruthy();
|
|
234
|
-
expect(transaction.transaction_hash).toBeTruthy();
|
|
235
|
-
expect(transaction).toHaveProperty('nonce');
|
|
236
|
-
expect(transaction).toHaveProperty('version');
|
|
237
|
-
});
|
|
122
|
+
describe('callContract()', () => {
|
|
123
|
+
test('callContract()', () => {
|
|
124
|
+
return expect(
|
|
125
|
+
testProvider.callContract({
|
|
126
|
+
contractAddress: exampleContractAddress,
|
|
127
|
+
entrypoint: 'balanceOf',
|
|
128
|
+
calldata: compileCalldata({
|
|
129
|
+
user: '0x9ff64f4ab0e1fe88df4465ade98d1ea99d5732761c39279b8e1374fa943e9b',
|
|
130
|
+
}),
|
|
131
|
+
})
|
|
132
|
+
).resolves.not.toThrow();
|
|
238
133
|
});
|
|
239
134
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
135
|
+
test('callContract() - user wallet', () => {
|
|
136
|
+
return expect(
|
|
137
|
+
testProvider
|
|
138
|
+
.callContract({
|
|
139
|
+
contractAddress: exampleContractAddress,
|
|
140
|
+
entrypoint: 'balanceOf',
|
|
141
|
+
calldata: compileCalldata({
|
|
142
|
+
user: wallet,
|
|
143
|
+
}),
|
|
144
|
+
})
|
|
145
|
+
.then((res) => {
|
|
146
|
+
expect(Array.isArray(res.result)).toBe(true);
|
|
147
|
+
})
|
|
148
|
+
).resolves.not.toThrow();
|
|
251
149
|
});
|
|
252
150
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
await Promise.all([
|
|
264
|
-
provider.waitForTransaction(deployResponse.transaction_hash),
|
|
265
|
-
provider.waitForTransaction(declareResponse.transaction_hash),
|
|
266
|
-
]);
|
|
267
|
-
({ block_number: blockNumber } = await provider.getBlock('latest'));
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
describe('deployContract', () => {
|
|
271
|
-
test('response', () => {
|
|
272
|
-
expect(deployResponse.contract_address).toBeTruthy();
|
|
273
|
-
expect(deployResponse.transaction_hash).toBeTruthy();
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
describe('declareContract', () => {
|
|
278
|
-
test('response', async () => {
|
|
279
|
-
expect(declareResponse.class_hash).toBeTruthy();
|
|
280
|
-
expect(declareResponse.transaction_hash).toBeTruthy();
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
describe('getClassAt', () => {
|
|
285
|
-
test('response', async () => {
|
|
286
|
-
const classResponse = await provider.getClassAt(contractAddress, blockNumber);
|
|
287
|
-
|
|
288
|
-
expect(classResponse).toHaveProperty('program');
|
|
289
|
-
expect(classResponse).toHaveProperty('entry_points_by_type');
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
describe('callContract', () => {
|
|
294
|
-
test('result', () => {
|
|
295
|
-
return expect(
|
|
296
|
-
provider
|
|
297
|
-
.callContract({
|
|
298
|
-
contractAddress: deployResponse.contract_address,
|
|
299
|
-
entrypoint: 'balance_of',
|
|
300
|
-
calldata: compileCalldata({
|
|
301
|
-
user: '0x9ff64f4ab0e1fe88df4465ade98d1ea99d5732761c39279b8e1374fa943e9b',
|
|
302
|
-
}),
|
|
303
|
-
})
|
|
304
|
-
.then((res) => {
|
|
305
|
-
expect(Array.isArray(res.result)).toBe(true);
|
|
306
|
-
})
|
|
307
|
-
).resolves.not.toThrow();
|
|
308
|
-
});
|
|
309
|
-
});
|
|
151
|
+
test('callContract() - gateway error', async () => {
|
|
152
|
+
return expect(
|
|
153
|
+
testProvider.callContract({
|
|
154
|
+
contractAddress: exampleContractAddress,
|
|
155
|
+
entrypoint: 'non_existent_entrypoint',
|
|
156
|
+
calldata: compileCalldata({
|
|
157
|
+
user: '0xdeadbeef',
|
|
158
|
+
}),
|
|
159
|
+
})
|
|
160
|
+
).rejects.toThrowError();
|
|
310
161
|
});
|
|
311
162
|
});
|
|
312
163
|
});
|
package/__tests__/fixtures.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
|
|
3
3
|
import { Account, ProviderInterface, RpcProvider, SequencerProvider, ec, json } from '../src';
|
|
4
|
-
import { CompiledContract } from '../src/types';
|
|
4
|
+
import { CompiledContract, DeployContractPayload } from '../src/types';
|
|
5
|
+
import { encodeShortString } from '../src/utils/shortString';
|
|
5
6
|
|
|
6
7
|
const readContract = (name: string): CompiledContract =>
|
|
7
8
|
json.parse(fs.readFileSync(`./__mocks__/${name}.json`).toString('ascii'));
|
|
@@ -27,7 +28,7 @@ const IS_RPC_DEVNET = Boolean(
|
|
|
27
28
|
);
|
|
28
29
|
const IS_SEQUENCER = !IS_RPC;
|
|
29
30
|
const IS_SEQUENCER_DEVNET = !BASE_URL.includes('starknet.io');
|
|
30
|
-
export const IS_SEQUENCER_GOERLI = BASE_URL === 'https://alpha4.starknet.io';
|
|
31
|
+
export const IS_SEQUENCER_GOERLI = BASE_URL === 'https://alpha4-2.starknet.io';
|
|
31
32
|
export const IS_DEVNET = IS_SEQUENCER ? IS_SEQUENCER_DEVNET : IS_RPC_DEVNET;
|
|
32
33
|
|
|
33
34
|
export const getTestProvider = () => {
|
|
@@ -71,3 +72,10 @@ const describeIf = (condition: boolean) => (condition ? describe : describe.skip
|
|
|
71
72
|
export const describeIfSequencer = describeIf(IS_DEVNET);
|
|
72
73
|
export const describeIfRpc = describeIf(IS_RPC);
|
|
73
74
|
export const describeIfNotDevnet = describeIf(!IS_DEVNET);
|
|
75
|
+
|
|
76
|
+
export const getERC20DeployPayload = (recipient: string): DeployContractPayload => {
|
|
77
|
+
return {
|
|
78
|
+
contract: compiledErc20,
|
|
79
|
+
constructorCalldata: [encodeShortString('Token'), encodeShortString('ERC20'), recipient],
|
|
80
|
+
};
|
|
81
|
+
};
|