starknet 4.17.0 → 4.18.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 +20 -0
- package/README.md +2 -10
- package/dist/index.d.ts +27 -9
- package/dist/index.global.js +30 -13
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +30 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -1
- package/.babelrc +0 -6
- package/.commitlintrc +0 -22
- package/.eslintignore +0 -2
- package/.eslintrc +0 -28
- package/.prettierrc +0 -6
- package/.releaserc +0 -28
- package/CODE_OF_CONDUCT.md +0 -128
- package/CONTRIBUTING.md +0 -52
- package/__mocks__/Account.json +0 -25486
- package/__mocks__/ERC20.json +0 -40027
- package/__mocks__/TestDapp.json +0 -12962
- package/__mocks__/contract.json +0 -33191
- package/__mocks__/l1l2_compiled.json +0 -10107
- package/__mocks__/multicall.json +0 -8139
- package/__mocks__/naming_compiled.json +0 -53283
- package/__mocks__/starknetId_compiled.json +0 -44703
- package/__mocks__/typedDataExample.json +0 -35
- package/__mocks__/typedDataSessionExample.json +0 -42
- package/__mocks__/typedDataStructArrayExample.json +0 -44
- package/__tests__/account.test.ts +0 -345
- package/__tests__/contract.test.ts +0 -249
- package/__tests__/defaultProvider.test.ts +0 -177
- package/__tests__/fixtures.ts +0 -84
- package/__tests__/jest.setup.ts +0 -30
- package/__tests__/rpcProvider.test.ts +0 -132
- package/__tests__/sequencerProvider.test.ts +0 -123
- package/__tests__/utils/__snapshots__/ellipticalCurve.test.ts.snap +0 -5
- package/__tests__/utils/__snapshots__/utils.browser.test.ts.snap +0 -5
- package/__tests__/utils/__snapshots__/utils.test.ts.snap +0 -5
- package/__tests__/utils/address.test.ts +0 -45
- package/__tests__/utils/ellipticalCurve.test.ts +0 -91
- package/__tests__/utils/merkle.test.ts +0 -256
- package/__tests__/utils/shortString.test.ts +0 -22
- package/__tests__/utils/starknetId.test.ts +0 -53
- package/__tests__/utils/transactionHash.test.ts +0 -17
- package/__tests__/utils/typedData.test.ts +0 -223
- package/__tests__/utils/uint256.test.ts +0 -32
- package/__tests__/utils/utils.browser.test.ts +0 -29
- package/__tests__/utils/utils.test.ts +0 -141
- package/img/logo.svg +0 -17
- package/index.d.ts +0 -2683
- package/index.global.js +0 -23192
- package/index.global.js.map +0 -1
- package/index.js +0 -4910
- package/index.js.map +0 -1
- package/index.mjs +0 -4852
- package/index.mjs.map +0 -1
- package/src/account/default.ts +0 -501
- package/src/account/index.ts +0 -2
- package/src/account/interface.ts +0 -309
- package/src/constants.ts +0 -2065
- package/src/contract/contractFactory.ts +0 -88
- package/src/contract/default.ts +0 -425
- package/src/contract/index.ts +0 -3
- package/src/contract/interface.ts +0 -106
- package/src/index.ts +0 -26
- package/src/provider/default.ts +0 -187
- package/src/provider/errors.ts +0 -14
- package/src/provider/index.ts +0 -9
- package/src/provider/interface.ts +0 -281
- package/src/provider/rpc.ts +0 -482
- package/src/provider/sequencer.ts +0 -523
- package/src/provider/utils.ts +0 -100
- package/src/signer/default.ts +0 -99
- package/src/signer/index.ts +0 -2
- package/src/signer/interface.ts +0 -77
- package/src/types/account.ts +0 -43
- package/src/types/api/index.ts +0 -10
- package/src/types/api/openrpc.ts +0 -607
- package/src/types/api/rpc.ts +0 -45
- package/src/types/api/sequencer.ts +0 -369
- package/src/types/contract.ts +0 -5
- package/src/types/index.ts +0 -8
- package/src/types/lib.ts +0 -143
- package/src/types/provider.ts +0 -134
- package/src/types/signer.ts +0 -24
- package/src/utils/address.ts +0 -44
- package/src/utils/calldata.ts +0 -250
- package/src/utils/ellipticCurve.ts +0 -120
- package/src/utils/encode.ts +0 -66
- package/src/utils/events.ts +0 -32
- package/src/utils/fetchPonyfill.ts +0 -5
- package/src/utils/hash.ts +0 -235
- package/src/utils/json.ts +0 -15
- package/src/utils/merkle.ts +0 -69
- package/src/utils/number.ts +0 -98
- package/src/utils/provider.ts +0 -28
- package/src/utils/responseParser/index.ts +0 -28
- package/src/utils/responseParser/rpc.ts +0 -70
- package/src/utils/responseParser/sequencer.ts +0 -135
- package/src/utils/shortString.ts +0 -21
- package/src/utils/stark.ts +0 -57
- package/src/utils/starknetId.ts +0 -116
- package/src/utils/transaction.ts +0 -56
- package/src/utils/typedData/index.ts +0 -247
- package/src/utils/typedData/types.ts +0 -37
- package/src/utils/typedData/utils.ts +0 -16
- package/src/utils/uint256.ts +0 -32
- package/src/utils/url.ts +0 -53
- package/tsconfig.eslint.json +0 -4
- package/tsup.config.ts +0 -9
- package/www/README.md +0 -41
- package/www/babel.config.js +0 -3
- package/www/code-examples/account.js +0 -65
- package/www/code-examples/amm.js +0 -44
- package/www/code-examples/erc20.js +0 -13
- package/www/code-examples/package-lock.json +0 -336
- package/www/code-examples/package.json +0 -15
- package/www/docs/API/_category_.json +0 -5
- package/www/docs/API/account.md +0 -463
- package/www/docs/API/changelog.md +0 -15
- package/www/docs/API/contract.md +0 -135
- package/www/docs/API/contractFactory.md +0 -45
- package/www/docs/API/index.md +0 -3
- package/www/docs/API/provider.md +0 -725
- package/www/docs/API/signer.md +0 -105
- package/www/docs/API/utils.md +0 -374
- package/www/docusaurus.config.js +0 -130
- package/www/guides/account.md +0 -140
- package/www/guides/cra.md +0 -3
- package/www/guides/erc20.md +0 -163
- package/www/guides/intro.md +0 -63
- package/www/package-lock.json +0 -20405
- package/www/package.json +0 -43
- package/www/sidebars.js +0 -31
- package/www/src/components/HomepageFeatures/index.tsx +0 -67
- package/www/src/components/HomepageFeatures/styles.module.css +0 -10
- package/www/src/css/custom.css +0 -39
- package/www/src/pages/index.module.css +0 -23
- package/www/src/pages/index.tsx +0 -40
- package/www/src/pages/markdown-page.md +0 -7
- package/www/static/.nojekyll +0 -0
- package/www/static/img/docusaurus.png +0 -0
- package/www/static/img/favicon.ico +0 -0
- package/www/static/img/logo.svg +0 -17
- package/www/static/img/starknet-1.png +0 -0
- package/www/static/img/starknet-2.png +0 -0
- package/www/static/img/starknet-3.png +0 -0
- package/www/static/img/tutorial/docsVersionDropdown.png +0 -0
- package/www/static/img/tutorial/localeDropdown.png +0 -0
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import { isBN } from 'bn.js';
|
|
2
|
-
|
|
3
|
-
import { Contract, ContractFactory, stark } from '../src';
|
|
4
|
-
import { getSelectorFromName } from '../src/utils/hash';
|
|
5
|
-
import { BigNumberish, toBN } from '../src/utils/number';
|
|
6
|
-
import { encodeShortString } from '../src/utils/shortString';
|
|
7
|
-
import { compileCalldata } from '../src/utils/stark';
|
|
8
|
-
import {
|
|
9
|
-
compiledErc20,
|
|
10
|
-
compiledMulticall,
|
|
11
|
-
compiledTypeTransformation,
|
|
12
|
-
getTestAccount,
|
|
13
|
-
getTestProvider,
|
|
14
|
-
} from './fixtures';
|
|
15
|
-
|
|
16
|
-
describe('contract module', () => {
|
|
17
|
-
let erc20Address: string;
|
|
18
|
-
const provider = getTestProvider();
|
|
19
|
-
const wallet = stark.randomAddress();
|
|
20
|
-
const account = getTestAccount(provider);
|
|
21
|
-
const constructorCalldata = [encodeShortString('Token'), encodeShortString('ERC20'), wallet];
|
|
22
|
-
const classHash = '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a';
|
|
23
|
-
|
|
24
|
-
describe('class Contract {}', () => {
|
|
25
|
-
describe('Basic Interaction', () => {
|
|
26
|
-
let erc20Contract: Contract;
|
|
27
|
-
let multicallContract: Contract;
|
|
28
|
-
|
|
29
|
-
beforeAll(async () => {
|
|
30
|
-
const { deploy } = await account.declareDeploy({
|
|
31
|
-
contract: compiledErc20,
|
|
32
|
-
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
|
|
33
|
-
constructorCalldata: [encodeShortString('Token'), encodeShortString('ERC20'), wallet],
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
erc20Contract = new Contract(compiledErc20.abi, deploy.contract_address!, provider);
|
|
37
|
-
|
|
38
|
-
const { deploy: multicallDeploy } = await account.declareDeploy({
|
|
39
|
-
contract: compiledMulticall,
|
|
40
|
-
classHash: '0x06f94f3229a8d9c1d51cb84f1f5ec306c8552a805e307540727dda53c4936b43',
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
multicallContract = new Contract(
|
|
44
|
-
compiledMulticall.abi,
|
|
45
|
-
multicallDeploy.contract_address!,
|
|
46
|
-
provider
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('populate transaction for initial balance of that account', async () => {
|
|
51
|
-
const res = await erc20Contract.populateTransaction.balanceOf(wallet);
|
|
52
|
-
expect(res).toHaveProperty('contractAddress');
|
|
53
|
-
expect(res).toHaveProperty('entrypoint');
|
|
54
|
-
expect(res).toHaveProperty('calldata');
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('estimate gas fee for `mint` should fail when connected to the provider', async () => {
|
|
58
|
-
expect(erc20Contract.estimateFee.mint(wallet, ['10', '0'])).rejects.toThrow();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('read initial balance of that account', async () => {
|
|
62
|
-
const result = await erc20Contract.balanceOf(wallet);
|
|
63
|
-
const [res] = result;
|
|
64
|
-
expect(res.low).toStrictEqual(toBN(1000));
|
|
65
|
-
expect(res).toStrictEqual(result.balance);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('read balance in a multicall', async () => {
|
|
69
|
-
const args1 = { user: wallet };
|
|
70
|
-
const args2 = {};
|
|
71
|
-
const calls = [
|
|
72
|
-
erc20Contract.address,
|
|
73
|
-
getSelectorFromName('balanceOf'),
|
|
74
|
-
Object.keys(args1).length,
|
|
75
|
-
...compileCalldata(args1),
|
|
76
|
-
|
|
77
|
-
erc20Contract.address,
|
|
78
|
-
getSelectorFromName('decimals'),
|
|
79
|
-
Object.keys(args2).length,
|
|
80
|
-
...compileCalldata(args2),
|
|
81
|
-
];
|
|
82
|
-
const result = await multicallContract.aggregate(calls);
|
|
83
|
-
const [block_number, res] = result;
|
|
84
|
-
expect(isBN(block_number));
|
|
85
|
-
expect(Array.isArray(res));
|
|
86
|
-
(res as BigNumberish[]).forEach((el) => expect(isBN(el)));
|
|
87
|
-
expect(block_number).toStrictEqual(result.block_number);
|
|
88
|
-
expect(res).toStrictEqual(result.result);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe('Type Transformation', () => {
|
|
93
|
-
let typeTransformedContract: Contract;
|
|
94
|
-
|
|
95
|
-
beforeAll(async () => {
|
|
96
|
-
const { deploy } = await account.declareDeploy({
|
|
97
|
-
contract: compiledTypeTransformation,
|
|
98
|
-
classHash: '0x022a0e662b13d18a2aaa3ee54ae290de6569621b549022c18169c6e7893809ea',
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
typeTransformedContract = new Contract(
|
|
102
|
-
compiledTypeTransformation.abi,
|
|
103
|
-
deploy.contract_address!,
|
|
104
|
-
provider
|
|
105
|
-
);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
describe('Request Type Transformation', () => {
|
|
109
|
-
test('Parsing the felt in request', async () => {
|
|
110
|
-
return expect(typeTransformedContract.request_felt(3)).resolves.not.toThrow();
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test('Parsing the array of felt in request', async () => {
|
|
114
|
-
return expect(
|
|
115
|
-
typeTransformedContract.request_array_of_felts([1, 2])
|
|
116
|
-
).resolves.not.toThrow();
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test('Parsing the struct in request', async () => {
|
|
120
|
-
return expect(
|
|
121
|
-
typeTransformedContract.request_struct({ x: 1, y: 2 })
|
|
122
|
-
).resolves.not.toThrow();
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
test('Parsing the array of structs in request', async () => {
|
|
126
|
-
return expect(
|
|
127
|
-
typeTransformedContract.request_array_of_structs([{ x: 1, y: 2 }])
|
|
128
|
-
).resolves.not.toThrow();
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test('Parsing the nested structs in request', async () => {
|
|
132
|
-
return expect(
|
|
133
|
-
typeTransformedContract.request_nested_structs({
|
|
134
|
-
p1: { x: 1, y: 2 },
|
|
135
|
-
p2: { x: 3, y: 4 },
|
|
136
|
-
extra: 5,
|
|
137
|
-
})
|
|
138
|
-
).resolves.not.toThrow();
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
test('Parsing the tuple in request', async () => {
|
|
142
|
-
return expect(typeTransformedContract.request_tuple([1, 2])).resolves.not.toThrow();
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
test('Parsing the multiple types in request', async () => {
|
|
146
|
-
return expect(
|
|
147
|
-
typeTransformedContract.request_mixed_types(2, { x: 1, y: 2 }, [1])
|
|
148
|
-
).resolves.not.toThrow();
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
describe('Response Type Transformation', () => {
|
|
153
|
-
test('Parsing the felt in response', async () => {
|
|
154
|
-
const { res } = await typeTransformedContract.get_felt();
|
|
155
|
-
expect(res).toStrictEqual(toBN(4));
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
test('Parsing the array of felt in response', async () => {
|
|
159
|
-
const result = await typeTransformedContract.get_array_of_felts();
|
|
160
|
-
const [res] = result;
|
|
161
|
-
expect(res).toStrictEqual([toBN(4), toBN(5)]);
|
|
162
|
-
expect(res).toStrictEqual(result.res);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
test('Parsing the array of structs in response', async () => {
|
|
166
|
-
const result = await typeTransformedContract.get_struct();
|
|
167
|
-
const [res] = result;
|
|
168
|
-
expect(res).toStrictEqual({ x: toBN(1), y: toBN(2) });
|
|
169
|
-
expect(res).toStrictEqual(result.res);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
test('Parsing the array of structs in response', async () => {
|
|
173
|
-
const result = await typeTransformedContract.get_array_of_structs();
|
|
174
|
-
const [res] = result;
|
|
175
|
-
expect(res).toStrictEqual([{ x: toBN(1), y: toBN(2) }]);
|
|
176
|
-
expect(res).toStrictEqual(result.res);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
test('Parsing the nested structs in response', async () => {
|
|
180
|
-
const result = await typeTransformedContract.get_nested_structs();
|
|
181
|
-
const [res] = result;
|
|
182
|
-
expect(res).toStrictEqual({
|
|
183
|
-
p1: { x: toBN(1), y: toBN(2) },
|
|
184
|
-
p2: { x: toBN(3), y: toBN(4) },
|
|
185
|
-
extra: toBN(5),
|
|
186
|
-
});
|
|
187
|
-
expect(res).toStrictEqual(result.res);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
test('Parsing the tuple in response', async () => {
|
|
191
|
-
const result = await typeTransformedContract.get_tuple();
|
|
192
|
-
const [res] = result;
|
|
193
|
-
expect(res).toStrictEqual([toBN(1), toBN(2), toBN(3)]);
|
|
194
|
-
expect(res).toStrictEqual(result.res);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
test('Parsing the multiple types in response', async () => {
|
|
198
|
-
const result = await typeTransformedContract.get_mixed_types();
|
|
199
|
-
const [tuple, number, array, point] = result;
|
|
200
|
-
expect(tuple).toStrictEqual([toBN(1), toBN(2)]);
|
|
201
|
-
expect(number).toStrictEqual(toBN(3));
|
|
202
|
-
expect(array).toStrictEqual([toBN(4)]);
|
|
203
|
-
expect(point).toStrictEqual({ x: toBN(1), y: toBN(2) });
|
|
204
|
-
expect(tuple).toStrictEqual(result.tuple);
|
|
205
|
-
expect(number).toStrictEqual(result.number);
|
|
206
|
-
expect(array).toStrictEqual(result.array);
|
|
207
|
-
expect(point).toStrictEqual(result.point);
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
describe('class ContractFactory {}', () => {
|
|
214
|
-
beforeAll(async () => {
|
|
215
|
-
await account.declareDeploy({
|
|
216
|
-
contract: compiledErc20,
|
|
217
|
-
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
|
|
218
|
-
constructorCalldata,
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
test('deployment of new contract', async () => {
|
|
222
|
-
const factory = new ContractFactory(compiledErc20, classHash, account);
|
|
223
|
-
const erc20 = await factory.deploy(
|
|
224
|
-
compileCalldata({
|
|
225
|
-
name: encodeShortString('Token'),
|
|
226
|
-
symbol: encodeShortString('ERC20'),
|
|
227
|
-
recipient: wallet,
|
|
228
|
-
})
|
|
229
|
-
);
|
|
230
|
-
expect(erc20 instanceof Contract);
|
|
231
|
-
});
|
|
232
|
-
test('wait for deployment transaction', async () => {
|
|
233
|
-
const factory = new ContractFactory(compiledErc20, classHash, account);
|
|
234
|
-
const contract = await factory.deploy(
|
|
235
|
-
compileCalldata({
|
|
236
|
-
name: encodeShortString('Token'),
|
|
237
|
-
symbol: encodeShortString('ERC20'),
|
|
238
|
-
recipient: wallet,
|
|
239
|
-
})
|
|
240
|
-
);
|
|
241
|
-
expect(contract.deployed()).resolves.not.toThrow();
|
|
242
|
-
});
|
|
243
|
-
test('attach new contract', async () => {
|
|
244
|
-
const factory = new ContractFactory(compiledErc20, classHash, account);
|
|
245
|
-
const erc20 = factory.attach(erc20Address);
|
|
246
|
-
expect(erc20 instanceof Contract);
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
});
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { BlockNumber, GetBlockResponse, Provider, stark } from '../src';
|
|
2
|
-
import { toBN } from '../src/utils/number';
|
|
3
|
-
import { encodeShortString } from '../src/utils/shortString';
|
|
4
|
-
import { compiledErc20, erc20ClassHash, getTestAccount, getTestProvider } from './fixtures';
|
|
5
|
-
|
|
6
|
-
const { compileCalldata } = stark;
|
|
7
|
-
|
|
8
|
-
const testProvider = new Provider(getTestProvider());
|
|
9
|
-
|
|
10
|
-
describe('defaultProvider', () => {
|
|
11
|
-
let exampleTransactionHash: string;
|
|
12
|
-
let erc20ContractAddress: string;
|
|
13
|
-
let exampleBlock: GetBlockResponse;
|
|
14
|
-
let exampleBlockNumber: BlockNumber;
|
|
15
|
-
let exampleBlockHash: string;
|
|
16
|
-
const wallet = stark.randomAddress();
|
|
17
|
-
const account = getTestAccount(testProvider);
|
|
18
|
-
|
|
19
|
-
beforeAll(async () => {
|
|
20
|
-
expect(testProvider).toBeInstanceOf(Provider);
|
|
21
|
-
|
|
22
|
-
const { deploy } = await account.declareDeploy({
|
|
23
|
-
contract: compiledErc20,
|
|
24
|
-
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
|
|
25
|
-
constructorCalldata: [encodeShortString('Token'), encodeShortString('ERC20'), wallet],
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
exampleTransactionHash = deploy.transaction_hash;
|
|
29
|
-
erc20ContractAddress = deploy.contract_address;
|
|
30
|
-
|
|
31
|
-
exampleBlock = await testProvider.getBlock('latest');
|
|
32
|
-
exampleBlockHash = exampleBlock.block_hash;
|
|
33
|
-
exampleBlockNumber = exampleBlock.block_number;
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('endpoints', () => {
|
|
37
|
-
test('declareDeploy()', () => {
|
|
38
|
-
expect(erc20ContractAddress).toBeTruthy();
|
|
39
|
-
expect(exampleTransactionHash).toBeTruthy();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('getBlock', () => {
|
|
43
|
-
test('getBlock(blockIdentifier=latest)', async () => {
|
|
44
|
-
expect(exampleBlock).not.toBeNull();
|
|
45
|
-
const { block_number, timestamp } = exampleBlock;
|
|
46
|
-
expect(typeof block_number).toEqual('number');
|
|
47
|
-
return expect(typeof timestamp).toEqual('number');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test(`getBlock(blockHash=undefined, blockNumber=${exampleBlockNumber})`, async () => {
|
|
51
|
-
const block = await testProvider.getBlock(exampleBlockNumber);
|
|
52
|
-
expect(block).toHaveProperty('block_hash');
|
|
53
|
-
expect(block).toHaveProperty('parent_hash');
|
|
54
|
-
expect(block).toHaveProperty('block_number');
|
|
55
|
-
expect(block).toHaveProperty('status');
|
|
56
|
-
expect(block).toHaveProperty('new_root');
|
|
57
|
-
expect(block).toHaveProperty('timestamp');
|
|
58
|
-
expect(block).toHaveProperty('transactions');
|
|
59
|
-
expect(Array.isArray(block.transactions)).toBe(true);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test(`getBlock(blockHash=${exampleBlockHash}, blockNumber=undefined)`, async () => {
|
|
63
|
-
const block = await testProvider.getBlock(exampleBlockHash);
|
|
64
|
-
expect(block).toHaveProperty('block_hash');
|
|
65
|
-
expect(block).toHaveProperty('parent_hash');
|
|
66
|
-
expect(block).toHaveProperty('block_number');
|
|
67
|
-
expect(block).toHaveProperty('status');
|
|
68
|
-
expect(block).toHaveProperty('new_root');
|
|
69
|
-
expect(block).toHaveProperty('timestamp');
|
|
70
|
-
expect(block).toHaveProperty('transactions');
|
|
71
|
-
expect(Array.isArray(block.transactions)).toBe(true);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test('getBlock() -> { blockNumber }', async () => {
|
|
75
|
-
const block = await testProvider.getBlock('latest');
|
|
76
|
-
return expect(block).toHaveProperty('block_number');
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test('getNonceForAddress()', async () => {
|
|
81
|
-
const nonce = await testProvider.getNonceForAddress(erc20ContractAddress);
|
|
82
|
-
return expect(toBN(nonce)).toEqual(toBN('0x0'));
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test('getClassAt(contractAddress, blockNumber="latest")', async () => {
|
|
86
|
-
const classResponse = await testProvider.getClassAt(erc20ContractAddress);
|
|
87
|
-
|
|
88
|
-
expect(classResponse).toHaveProperty('program');
|
|
89
|
-
expect(classResponse).toHaveProperty('entry_points_by_type');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// TODO see if feasible to split
|
|
93
|
-
describe('GetClassByHash', () => {
|
|
94
|
-
test('responses', async () => {
|
|
95
|
-
const classResponse = await testProvider.getClassByHash(erc20ClassHash);
|
|
96
|
-
expect(classResponse).toHaveProperty('program');
|
|
97
|
-
expect(classResponse).toHaveProperty('entry_points_by_type');
|
|
98
|
-
expect(classResponse).toHaveProperty('abi');
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe('getStorageAt', () => {
|
|
103
|
-
test('with "key" type of number', () => {
|
|
104
|
-
return expect(testProvider.getStorageAt(erc20ContractAddress, 0)).resolves.not.toThrow();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test('"key" type of string', () => {
|
|
108
|
-
return expect(
|
|
109
|
-
testProvider.getStorageAt(erc20ContractAddress, '0x0')
|
|
110
|
-
).resolves.not.toThrow();
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test('with "key" type of BN', () => {
|
|
114
|
-
return expect(
|
|
115
|
-
testProvider.getStorageAt(erc20ContractAddress, toBN('0x0'))
|
|
116
|
-
).resolves.not.toThrow();
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
test('getTransaction() - successful deploy transaction', async () => {
|
|
121
|
-
const transaction = await testProvider.getTransaction(exampleTransactionHash);
|
|
122
|
-
|
|
123
|
-
expect(transaction).toHaveProperty('transaction_hash');
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
test('getTransactionReceipt() - successful transaction', async () => {
|
|
127
|
-
const transactionReceipt = await testProvider.getTransactionReceipt(exampleTransactionHash);
|
|
128
|
-
|
|
129
|
-
expect(transactionReceipt).toHaveProperty('actual_fee');
|
|
130
|
-
expect(transactionReceipt).toHaveProperty('transaction_hash');
|
|
131
|
-
expect(transactionReceipt).toHaveProperty('status');
|
|
132
|
-
expect(transactionReceipt).toHaveProperty('actual_fee');
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe('callContract()', () => {
|
|
136
|
-
test('callContract()', () => {
|
|
137
|
-
return expect(
|
|
138
|
-
testProvider.callContract({
|
|
139
|
-
contractAddress: erc20ContractAddress,
|
|
140
|
-
entrypoint: 'balanceOf',
|
|
141
|
-
calldata: compileCalldata({
|
|
142
|
-
user: '0x9ff64f4ab0e1fe88df4465ade98d1ea99d5732761c39279b8e1374fa943e9b',
|
|
143
|
-
}),
|
|
144
|
-
})
|
|
145
|
-
).resolves.not.toThrow();
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
test('callContract() - user wallet', () => {
|
|
149
|
-
return expect(
|
|
150
|
-
testProvider
|
|
151
|
-
.callContract({
|
|
152
|
-
contractAddress: erc20ContractAddress,
|
|
153
|
-
entrypoint: 'balanceOf',
|
|
154
|
-
calldata: compileCalldata({
|
|
155
|
-
user: wallet,
|
|
156
|
-
}),
|
|
157
|
-
})
|
|
158
|
-
.then((res) => {
|
|
159
|
-
expect(Array.isArray(res.result)).toBe(true);
|
|
160
|
-
})
|
|
161
|
-
).resolves.not.toThrow();
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
test('callContract() - gateway error', async () => {
|
|
165
|
-
return expect(
|
|
166
|
-
testProvider.callContract({
|
|
167
|
-
contractAddress: erc20ContractAddress,
|
|
168
|
-
entrypoint: 'non_existent_entrypoint',
|
|
169
|
-
calldata: compileCalldata({
|
|
170
|
-
user: '0xdeadbeef',
|
|
171
|
-
}),
|
|
172
|
-
})
|
|
173
|
-
).rejects.toThrowError();
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
});
|
package/__tests__/fixtures.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
import { Account, ProviderInterface, RpcProvider, SequencerProvider, ec, json } from '../src';
|
|
5
|
-
import { CompiledContract } from '../src/types';
|
|
6
|
-
|
|
7
|
-
const readContract = (name: string): CompiledContract =>
|
|
8
|
-
json.parse(
|
|
9
|
-
fs.readFileSync(path.resolve(__dirname, `../__mocks__/${name}.json`)).toString('ascii')
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
export const compiledOpenZeppelinAccount = readContract('Account');
|
|
13
|
-
export const compiledErc20 = readContract('ERC20');
|
|
14
|
-
export const compiledL1L2 = readContract('l1l2_compiled');
|
|
15
|
-
export const compiledTypeTransformation = readContract('contract');
|
|
16
|
-
export const compiledMulticall = readContract('multicall');
|
|
17
|
-
export const compiledTestDapp = readContract('TestDapp');
|
|
18
|
-
export const compiledStarknetId = readContract('starknetId_compiled');
|
|
19
|
-
export const compiledNamingContract = readContract('naming_compiled');
|
|
20
|
-
|
|
21
|
-
/* Default test config based on run `starknet-devnet --seed 0` */
|
|
22
|
-
const DEFAULT_TEST_PROVIDER_SEQUENCER_URL = 'http://127.0.0.1:5050/';
|
|
23
|
-
const DEFAULT_TEST_ACCOUNT_ADDRESS =
|
|
24
|
-
'0x7e00d496e324876bbc8531f2d9a82bf154d1a04a50218ee74cdd372f75a551a';
|
|
25
|
-
const DEFAULT_TEST_ACCOUNT_PRIVATE_KEY = '0xe3e70682c2094cac629f6fbed82c07cd';
|
|
26
|
-
|
|
27
|
-
/* User defined config or default one */
|
|
28
|
-
const BASE_URL = process.env.TEST_PROVIDER_BASE_URL || DEFAULT_TEST_PROVIDER_SEQUENCER_URL;
|
|
29
|
-
const RPC_URL = process.env.TEST_RPC_URL;
|
|
30
|
-
|
|
31
|
-
/* Detect user defined node or sequencer, if none default to sequencer if both default to node */
|
|
32
|
-
const PROVIDER_URL = RPC_URL || BASE_URL;
|
|
33
|
-
|
|
34
|
-
/* Detect is localhost devnet */
|
|
35
|
-
export const IS_LOCALHOST_DEVNET =
|
|
36
|
-
PROVIDER_URL.includes('localhost') || PROVIDER_URL.includes('127.0.0.1');
|
|
37
|
-
|
|
38
|
-
/* Definitions */
|
|
39
|
-
export const IS_RPC = !!RPC_URL;
|
|
40
|
-
export const IS_SEQUENCER = !RPC_URL;
|
|
41
|
-
|
|
42
|
-
export const getTestProvider = (): ProviderInterface => {
|
|
43
|
-
const provider = RPC_URL
|
|
44
|
-
? new RpcProvider({ nodeUrl: RPC_URL })
|
|
45
|
-
: new SequencerProvider({ baseUrl: BASE_URL });
|
|
46
|
-
|
|
47
|
-
if (IS_LOCALHOST_DEVNET) {
|
|
48
|
-
// accelerate the tests when running locally
|
|
49
|
-
const originalWaitForTransaction = provider.waitForTransaction.bind(provider);
|
|
50
|
-
provider.waitForTransaction = (txHash: string, retryInterval?: number) => {
|
|
51
|
-
return originalWaitForTransaction(txHash, retryInterval || 1000);
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return provider;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// test account with fee token balance
|
|
59
|
-
export const getTestAccount = (provider: ProviderInterface) => {
|
|
60
|
-
let testAccountAddress = process.env.TEST_ACCOUNT_ADDRESS;
|
|
61
|
-
let testAccountPrivateKey = process.env.TEST_ACCOUNT_PRIVATE_KEY;
|
|
62
|
-
|
|
63
|
-
if (!IS_LOCALHOST_DEVNET) {
|
|
64
|
-
if (!testAccountPrivateKey) {
|
|
65
|
-
throw new Error('TEST_ACCOUNT_PRIVATE_KEY is not set');
|
|
66
|
-
}
|
|
67
|
-
if (!testAccountAddress) {
|
|
68
|
-
throw new Error('TEST_ACCOUNT_ADDRESS is not set');
|
|
69
|
-
}
|
|
70
|
-
} else {
|
|
71
|
-
testAccountAddress = DEFAULT_TEST_ACCOUNT_ADDRESS;
|
|
72
|
-
testAccountPrivateKey = DEFAULT_TEST_ACCOUNT_PRIVATE_KEY;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return new Account(provider, testAccountAddress, ec.getKeyPair(testAccountPrivateKey));
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const describeIf = (condition: boolean) => (condition ? describe : describe.skip);
|
|
79
|
-
export const describeIfSequencer = describeIf(IS_SEQUENCER);
|
|
80
|
-
export const describeIfRpc = describeIf(IS_RPC);
|
|
81
|
-
export const describeIfNotDevnet = describeIf(!IS_LOCALHOST_DEVNET);
|
|
82
|
-
export const describeIfDevnet = describeIf(IS_LOCALHOST_DEVNET);
|
|
83
|
-
|
|
84
|
-
export const erc20ClassHash = '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a';
|
package/__tests__/jest.setup.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import 'isomorphic-fetch';
|
|
2
|
-
|
|
3
|
-
/* eslint-disable no-console */
|
|
4
|
-
import { register } from 'fetch-intercept';
|
|
5
|
-
|
|
6
|
-
jest.setTimeout(50 * 60 * 1000);
|
|
7
|
-
|
|
8
|
-
if (process.env.DEBUG === 'true') {
|
|
9
|
-
register({
|
|
10
|
-
request(url, config) {
|
|
11
|
-
console.log('[fetch.request]', [url, config]);
|
|
12
|
-
return [url, config];
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
requestError(error) {
|
|
16
|
-
console.log('[fetch.requestError]', error);
|
|
17
|
-
return Promise.reject(error);
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
response(response) {
|
|
21
|
-
console.log('[fetch.response]', response);
|
|
22
|
-
return response;
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
responseError(error) {
|
|
26
|
-
console.log('[fetch.responseError]', error);
|
|
27
|
-
return Promise.reject(error);
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { Account, GetBlockResponse, RpcProvider, ec } from '../src';
|
|
2
|
-
import { StarknetChainId } from '../src/constants';
|
|
3
|
-
import {
|
|
4
|
-
compiledOpenZeppelinAccount,
|
|
5
|
-
describeIfNotDevnet,
|
|
6
|
-
describeIfRpc,
|
|
7
|
-
getTestAccount,
|
|
8
|
-
getTestProvider,
|
|
9
|
-
} from './fixtures';
|
|
10
|
-
|
|
11
|
-
describeIfRpc('RPCProvider', () => {
|
|
12
|
-
const rpcProvider = getTestProvider() as RpcProvider;
|
|
13
|
-
const account = getTestAccount(rpcProvider);
|
|
14
|
-
let accountPublicKey: string;
|
|
15
|
-
|
|
16
|
-
beforeAll(async () => {
|
|
17
|
-
expect(account).toBeInstanceOf(Account);
|
|
18
|
-
const accountKeyPair = ec.genKeyPair();
|
|
19
|
-
accountPublicKey = ec.getStarkKey(accountKeyPair);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('getChainId', async () => {
|
|
23
|
-
const chainId = await rpcProvider.getChainId();
|
|
24
|
-
expect([StarknetChainId.TESTNET2, StarknetChainId.MAINNET, StarknetChainId.TESTNET]).toContain(
|
|
25
|
-
chainId
|
|
26
|
-
);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('getTransactionCount', async () => {
|
|
30
|
-
const count = await rpcProvider.getTransactionCount('latest');
|
|
31
|
-
expect(typeof count).toBe('number');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('getBlockHashAndNumber', async () => {
|
|
35
|
-
const blockHashAndNumber = await rpcProvider.getBlockHashAndNumber();
|
|
36
|
-
expect(blockHashAndNumber).toHaveProperty('block_hash');
|
|
37
|
-
expect(blockHashAndNumber).toHaveProperty('block_number');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('getStateUpdate', async () => {
|
|
41
|
-
const stateUpdate = await rpcProvider.getStateUpdate('latest');
|
|
42
|
-
expect(stateUpdate).toHaveProperty('block_hash');
|
|
43
|
-
expect(stateUpdate).toHaveProperty('new_root');
|
|
44
|
-
expect(stateUpdate).toHaveProperty('old_root');
|
|
45
|
-
expect(stateUpdate).toHaveProperty('state_diff');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
xtest('getProtocolVersion - pathfinder not implement', async () => {
|
|
49
|
-
await rpcProvider.getProtocolVersion();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describeIfNotDevnet('devnet not implement', () => {
|
|
53
|
-
test('getPendingTransactions', async () => {
|
|
54
|
-
const transactions = await rpcProvider.getPendingTransactions();
|
|
55
|
-
expect(Array.isArray(transactions)).toBe(true);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe('RPC methods', () => {
|
|
60
|
-
let latestBlock: GetBlockResponse;
|
|
61
|
-
|
|
62
|
-
beforeAll(async () => {
|
|
63
|
-
latestBlock = await rpcProvider.getBlock('latest');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test('getBlockWithTxHashes', async () => {
|
|
67
|
-
const blockResponse = await rpcProvider.getBlockWithTxHashes(latestBlock.block_number);
|
|
68
|
-
expect(blockResponse).toHaveProperty('transactions');
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('getBlockWithTxs', async () => {
|
|
72
|
-
const blockResponse = await rpcProvider.getBlockWithTxs(latestBlock.block_number);
|
|
73
|
-
expect(blockResponse).toHaveProperty('transactions');
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test('getTransactionByBlockIdAndIndex', async () => {
|
|
77
|
-
const transaction = await rpcProvider.getTransactionByBlockIdAndIndex(
|
|
78
|
-
latestBlock.block_number,
|
|
79
|
-
0
|
|
80
|
-
);
|
|
81
|
-
expect(transaction).toHaveProperty('transaction_hash');
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
xtest('traceBlockTransactions', async () => {
|
|
85
|
-
await rpcProvider.traceBlockTransactions(latestBlock.block_hash);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe('deploy contract related tests', () => {
|
|
89
|
-
let contract_address: string;
|
|
90
|
-
let transaction_hash: string;
|
|
91
|
-
|
|
92
|
-
beforeAll(async () => {
|
|
93
|
-
const { deploy } = await account.declareDeploy({
|
|
94
|
-
contract: compiledOpenZeppelinAccount,
|
|
95
|
-
classHash: '0x03fcbf77b28c96f4f2fb5bd2d176ab083a12a5e123adeb0de955d7ee228c9854',
|
|
96
|
-
constructorCalldata: [accountPublicKey],
|
|
97
|
-
salt: accountPublicKey,
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
contract_address = deploy.contract_address;
|
|
101
|
-
transaction_hash = deploy.transaction_hash;
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
test('declareDeploy()', () => {
|
|
105
|
-
expect(contract_address).toBeTruthy();
|
|
106
|
-
expect(transaction_hash).toBeTruthy();
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test('getTransactionByHash', async () => {
|
|
110
|
-
const transaction = await rpcProvider.getTransactionByHash(transaction_hash);
|
|
111
|
-
expect(transaction).toHaveProperty('transaction_hash');
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test('getClassHashAt', async () => {
|
|
115
|
-
const classHash = await rpcProvider.getClassHashAt(contract_address);
|
|
116
|
-
expect(typeof classHash).toBe('string');
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
xtest('traceTransaction', async () => {
|
|
120
|
-
await rpcProvider.traceTransaction(transaction_hash);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
test('getClass classHash 0x03fcbf77b28c96f4f2fb5bd2d176ab083a12a5e123adeb0de955d7ee228c9854', async () => {
|
|
125
|
-
const contractClass = await rpcProvider.getClass(
|
|
126
|
-
'0x03fcbf77b28c96f4f2fb5bd2d176ab083a12a5e123adeb0de955d7ee228c9854'
|
|
127
|
-
);
|
|
128
|
-
expect(contractClass).toHaveProperty('program');
|
|
129
|
-
expect(contractClass).toHaveProperty('entry_points_by_type');
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
});
|