starknet 4.13.2 → 4.14.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/CODE_OF_CONDUCT.md +128 -0
- package/README.md +2 -2
- package/__tests__/account.test.ts +38 -14
- package/__tests__/contract.test.ts +70 -57
- package/__tests__/defaultProvider.test.ts +14 -13
- package/__tests__/fixtures.ts +26 -27
- package/__tests__/rpcProvider.test.ts +19 -16
- package/__tests__/sequencerProvider.test.ts +47 -55
- package/__tests__/utils/utils.test.ts +10 -0
- package/dist/index.d.ts +112 -28
- package/dist/index.global.js +511 -453
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +107 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +107 -49
- package/dist/index.mjs.map +1 -1
- package/index.d.ts +112 -28
- package/index.global.js +511 -453
- package/index.global.js.map +1 -1
- package/index.js +107 -49
- package/index.js.map +1 -1
- package/index.mjs +107 -49
- package/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/account/default.ts +29 -7
- package/src/account/interface.ts +71 -5
- package/src/contract/contractFactory.ts +20 -13
- package/src/contract/default.ts +10 -1
- package/src/provider/default.ts +26 -11
- package/src/provider/interface.ts +9 -3
- package/src/provider/rpc.ts +15 -11
- package/src/provider/sequencer.ts +11 -6
- package/src/provider/utils.ts +19 -11
- package/src/types/account.ts +21 -1
- package/src/types/lib.ts +5 -2
- package/src/types/provider.ts +0 -5
- package/src/utils/events.ts +32 -0
- package/src/utils/number.ts +6 -0
- package/www/docs/API/account.md +156 -2
- package/www/docs/API/contractFactory.md +7 -11
- package/www/docs/API/provider.md +5 -9
- package/www/docs/API/utils.md +8 -0
- package/www/guides/account.md +89 -38
- package/www/guides/erc20.md +115 -59
- package/www/guides/intro.md +11 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
# [4.14.0](https://github.com/0xs34n/starknet.js/compare/v4.13.2...v4.14.0) (2022-11-29)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- account test removed provider deployContract ([605c2a9](https://github.com/0xs34n/starknet.js/commit/605c2a9426f8ef5bc3c16803db0055550ca58da3))
|
|
6
|
+
- cleanup after refactor and remove branch split ([f695629](https://github.com/0xs34n/starknet.js/commit/f69562960877bc37d38e2964a88569c9ae9bedca))
|
|
7
|
+
- properly parse blockIdentifier in buildCall function ([d09affd](https://github.com/0xs34n/starknet.js/commit/d09affd57c260eccf2f59c9cb7dd8c668fe8a5b3))
|
|
8
|
+
- remove deployMaxFee from deploy ([6d5fa24](https://github.com/0xs34n/starknet.js/commit/6d5fa2461def5caad3cdd71af8a4e6c61d88092e))
|
|
9
|
+
- rpc tests ([cd913ee](https://github.com/0xs34n/starknet.js/commit/cd913ee93df433eb3730e6aae43dd22b0c8aed32))
|
|
10
|
+
- split getNonce interface ([7b7acd9](https://github.com/0xs34n/starknet.js/commit/7b7acd9f5ebe0b2b97e389fb3a68249dd72224ce))
|
|
11
|
+
- tiping issue ([78aa340](https://github.com/0xs34n/starknet.js/commit/78aa3402131f51e83287eada7499ea01de41efa0))
|
|
12
|
+
- udc require L2 status for deployed contract to be awailable to use ([afba8d0](https://github.com/0xs34n/starknet.js/commit/afba8d068685c1c9b03126e5de13a5dfddb2925e))
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- account deployContract ts overide base class ([dd4502d](https://github.com/0xs34n/starknet.js/commit/dd4502d76fb73f04e8e512336f6e5924c55b2f39))
|
|
17
|
+
- extend acc interface, use deploy estimate fee ([da7392a](https://github.com/0xs34n/starknet.js/commit/da7392a65fa2b261cc1c6916739c1a59ecf9330f))
|
|
18
|
+
- r p.deployCo. C tests, CF fixtures, cleanHex, DeclareDeploy, F Provider, seq.waitFor ret.txRec ([bb50f53](https://github.com/0xs34n/starknet.js/commit/bb50f5312f2b8618a26eaf13f1f851a645f5b670))
|
|
19
|
+
- return from wait Transaction,Account deployContract and declareDeploy ([724975d](https://github.com/0xs34n/starknet.js/commit/724975dd92cc764208e1cf70c6f0d4089f0d363d))
|
|
20
|
+
|
|
1
21
|
## [4.13.2](https://github.com/0xs34n/starknet.js/compare/v4.13.1...v4.13.2) (2022-11-25)
|
|
2
22
|
|
|
3
23
|
### Bug Fixes
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity
|
|
10
|
+
and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
- Demonstrating empathy and kindness toward other people
|
|
21
|
+
- Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
- Giving and gracefully accepting constructive feedback
|
|
23
|
+
- Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
- Focusing on what is best not just for us as individuals, but for the
|
|
26
|
+
overall community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
- The use of sexualized language or imagery, and sexual attention or
|
|
31
|
+
advances of any kind
|
|
32
|
+
- Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
- Public or private harassment
|
|
34
|
+
- Publishing others' private information, such as a physical or email
|
|
35
|
+
address, without their explicit permission
|
|
36
|
+
- Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official e-mail address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
tt@shardlabs.io.
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series
|
|
86
|
+
of actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or
|
|
93
|
+
permanent ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within
|
|
113
|
+
the community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.0, available at
|
|
119
|
+
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
|
122
|
+
enforcement ladder](https://github.com/mozilla/diversity).
|
|
123
|
+
|
|
124
|
+
[homepage]: https://www.contributor-covenant.org
|
|
125
|
+
|
|
126
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
127
|
+
https://www.contributor-covenant.org/faq. Translations are available at
|
|
128
|
+
https://www.contributor-covenant.org/translations.
|
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ $ npm install starknet@next
|
|
|
48
48
|
|
|
49
49
|
Import `starknet` and use the [API](https://www.starknetjs.com/docs/API/)
|
|
50
50
|
|
|
51
|
-
Please refer to the following code example [here](https://github.com/0xs34n/starknet.js-workshop
|
|
51
|
+
Please refer to the following code example [here](https://github.com/0xs34n/starknet.js-workshop)
|
|
52
52
|
|
|
53
53
|
Guides can be found [here](https://www.starknetjs.com/guides/intro)
|
|
54
54
|
|
|
@@ -62,7 +62,7 @@ Guides can be found [here](https://www.starknetjs.com/guides/intro)
|
|
|
62
62
|
- [Braavos - your new wallet on top of StarkNet](https://chrome.google.com/webstore/detail/braavos-wallet/jnlgamecbpmbajjfhmmmlhejkemejdma)
|
|
63
63
|
- [React + Starknet.js boilerplate](https://github.com/fracek/starknet-react-example)
|
|
64
64
|
- [AMM Demo](https://www.starknetswap.com/)
|
|
65
|
-
- [mySwap - the first DeFi app to launch on StarkNet](myswap.xyz)
|
|
65
|
+
- [mySwap - the first DeFi app to launch on StarkNet](https://myswap.xyz)
|
|
66
66
|
|
|
67
67
|
## ✏️ Contributing
|
|
68
68
|
|
|
@@ -3,14 +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 { feeTransactionVersion } from '../src/utils/hash';
|
|
6
|
-
import { toBN } from '../src/utils/number';
|
|
6
|
+
import { hexToDecimalString, toBN } from '../src/utils/number';
|
|
7
7
|
import { encodeShortString } from '../src/utils/shortString';
|
|
8
8
|
import { randomAddress } from '../src/utils/stark';
|
|
9
9
|
import {
|
|
10
10
|
compiledErc20,
|
|
11
11
|
compiledTestDapp,
|
|
12
12
|
erc20ClassHash,
|
|
13
|
-
getERC20DeployPayload,
|
|
14
13
|
getTestAccount,
|
|
15
14
|
getTestProvider,
|
|
16
15
|
} from './fixtures';
|
|
@@ -25,25 +24,29 @@ describe('deploy and test Wallet', () => {
|
|
|
25
24
|
beforeAll(async () => {
|
|
26
25
|
expect(account).toBeInstanceOf(Account);
|
|
27
26
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const declareDeploy = await account.declareDeploy({
|
|
28
|
+
contract: compiledErc20,
|
|
29
|
+
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
|
|
30
|
+
constructorCalldata: [
|
|
31
|
+
encodeShortString('Token'),
|
|
32
|
+
encodeShortString('ERC20'),
|
|
33
|
+
account.address,
|
|
34
|
+
],
|
|
35
|
+
});
|
|
31
36
|
|
|
32
|
-
erc20Address =
|
|
37
|
+
erc20Address = declareDeploy.deploy.contract_address;
|
|
33
38
|
erc20 = new Contract(compiledErc20.abi, erc20Address, provider);
|
|
34
39
|
|
|
35
|
-
await provider.waitForTransaction(erc20Response.transaction_hash);
|
|
36
|
-
|
|
37
40
|
const x = await erc20.balanceOf(account.address);
|
|
38
41
|
|
|
39
42
|
expect(number.toBN(x[0].low).toString()).toStrictEqual(number.toBN(1000).toString());
|
|
40
43
|
|
|
41
|
-
const dappResponse = await
|
|
44
|
+
const dappResponse = await account.declareDeploy({
|
|
42
45
|
contract: compiledTestDapp,
|
|
46
|
+
classHash: '0x04367b26fbb92235e8d1137d19c080e6e650a6889ded726d00658411cc1046f5',
|
|
43
47
|
});
|
|
44
|
-
dapp = new Contract(compiledTestDapp.abi, dappResponse.contract_address!, provider);
|
|
45
48
|
|
|
46
|
-
|
|
49
|
+
dapp = new Contract(compiledTestDapp.abi, dappResponse.deploy.contract_address!, provider);
|
|
47
50
|
});
|
|
48
51
|
|
|
49
52
|
test('estimate fee', async () => {
|
|
@@ -71,7 +74,7 @@ describe('deploy and test Wallet', () => {
|
|
|
71
74
|
calldata: [erc20.address, '10', '0'],
|
|
72
75
|
});
|
|
73
76
|
|
|
74
|
-
await provider.waitForTransaction(transaction_hash);
|
|
77
|
+
await provider.waitForTransaction(transaction_hash, ['ACCEPTED_ON_L2']);
|
|
75
78
|
});
|
|
76
79
|
|
|
77
80
|
test('read balance of wallet after transfer', async () => {
|
|
@@ -110,7 +113,7 @@ describe('deploy and test Wallet', () => {
|
|
|
110
113
|
},
|
|
111
114
|
]);
|
|
112
115
|
|
|
113
|
-
await provider.waitForTransaction(transaction_hash);
|
|
116
|
+
await provider.waitForTransaction(transaction_hash, ['ACCEPTED_ON_L2']);
|
|
114
117
|
|
|
115
118
|
const response = await dapp.get_number(account.address);
|
|
116
119
|
expect(toBN(response.number as string).toString()).toStrictEqual('57');
|
|
@@ -173,7 +176,28 @@ describe('deploy and test Wallet', () => {
|
|
|
173
176
|
await provider.waitForTransaction(declareTx.transaction_hash);
|
|
174
177
|
|
|
175
178
|
expect(declareTx).toHaveProperty('class_hash');
|
|
176
|
-
expect(declareTx.class_hash).toEqual(erc20ClassHash);
|
|
179
|
+
expect(hexToDecimalString(declareTx.class_hash)).toEqual(hexToDecimalString(erc20ClassHash));
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('UDC DeployContract', async () => {
|
|
183
|
+
const deployResponse = await account.deployContract({
|
|
184
|
+
classHash: erc20ClassHash,
|
|
185
|
+
constructorCalldata: [
|
|
186
|
+
encodeShortString('Token'),
|
|
187
|
+
encodeShortString('ERC20'),
|
|
188
|
+
account.address,
|
|
189
|
+
],
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
expect(deployResponse.contract_address).toBeDefined();
|
|
193
|
+
expect(deployResponse.transaction_hash).toBeDefined();
|
|
194
|
+
expect(deployResponse.address).toBeDefined();
|
|
195
|
+
expect(deployResponse.deployer).toBeDefined();
|
|
196
|
+
expect(deployResponse.unique).toBeDefined();
|
|
197
|
+
expect(deployResponse.classHash).toBeDefined();
|
|
198
|
+
expect(deployResponse.calldata_len).toBeDefined();
|
|
199
|
+
expect(deployResponse.calldata).toBeDefined();
|
|
200
|
+
expect(deployResponse.salt).toBeDefined();
|
|
177
201
|
});
|
|
178
202
|
|
|
179
203
|
test('UDC Deploy', async () => {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { isBN } from 'bn.js';
|
|
2
2
|
|
|
3
3
|
import { Contract, ContractFactory, stark } from '../src';
|
|
4
|
-
import { DeployContractPayload } from '../src/types';
|
|
5
4
|
import { getSelectorFromName } from '../src/utils/hash';
|
|
6
5
|
import { BigNumberish, toBN } from '../src/utils/number';
|
|
6
|
+
import { encodeShortString } from '../src/utils/shortString';
|
|
7
7
|
import { compileCalldata } from '../src/utils/stark';
|
|
8
8
|
import {
|
|
9
9
|
compiledErc20,
|
|
10
10
|
compiledMulticall,
|
|
11
11
|
compiledTypeTransformation,
|
|
12
|
-
|
|
12
|
+
getTestAccount,
|
|
13
13
|
getTestProvider,
|
|
14
14
|
} from './fixtures';
|
|
15
15
|
|
|
@@ -17,45 +17,46 @@ const provider = getTestProvider();
|
|
|
17
17
|
|
|
18
18
|
describe('class Contract {}', () => {
|
|
19
19
|
const wallet = stark.randomAddress();
|
|
20
|
+
const account = getTestAccount(provider);
|
|
20
21
|
|
|
21
22
|
describe('Basic Interaction', () => {
|
|
22
|
-
let
|
|
23
|
-
let
|
|
23
|
+
let erc20Contract: Contract;
|
|
24
|
+
let multicallContract: Contract;
|
|
24
25
|
|
|
25
26
|
beforeAll(async () => {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
erc20 = new Contract(compiledErc20.abi, contract_address!, provider);
|
|
33
|
-
await provider.waitForTransaction(transaction_hash);
|
|
34
|
-
// Deploy Multicall
|
|
27
|
+
const { deploy } = await account.declareDeploy({
|
|
28
|
+
contract: compiledErc20,
|
|
29
|
+
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
|
|
30
|
+
constructorCalldata: [encodeShortString('Token'), encodeShortString('ERC20'), wallet],
|
|
31
|
+
});
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
await provider.deployContract({
|
|
38
|
-
contract: compiledMulticall,
|
|
39
|
-
});
|
|
33
|
+
erc20Contract = new Contract(compiledErc20.abi, deploy.contract_address!, provider);
|
|
40
34
|
|
|
41
|
-
|
|
35
|
+
const { deploy: multicallDeploy } = await account.declareDeploy({
|
|
36
|
+
contract: compiledMulticall,
|
|
37
|
+
classHash: '0x06f94f3229a8d9c1d51cb84f1f5ec306c8552a805e307540727dda53c4936b43',
|
|
38
|
+
});
|
|
42
39
|
|
|
43
|
-
|
|
40
|
+
multicallContract = new Contract(
|
|
41
|
+
compiledMulticall.abi,
|
|
42
|
+
multicallDeploy.contract_address!,
|
|
43
|
+
provider
|
|
44
|
+
);
|
|
44
45
|
});
|
|
45
46
|
|
|
46
47
|
test('populate transaction for initial balance of that account', async () => {
|
|
47
|
-
const res = await
|
|
48
|
+
const res = await erc20Contract.populateTransaction.balanceOf(wallet);
|
|
48
49
|
expect(res).toHaveProperty('contractAddress');
|
|
49
50
|
expect(res).toHaveProperty('entrypoint');
|
|
50
51
|
expect(res).toHaveProperty('calldata');
|
|
51
52
|
});
|
|
52
53
|
|
|
53
54
|
test('estimate gas fee for `mint` should fail when connected to the provider', async () => {
|
|
54
|
-
expect(
|
|
55
|
+
expect(erc20Contract.estimateFee.mint(wallet, ['10', '0'])).rejects.toThrow();
|
|
55
56
|
});
|
|
56
57
|
|
|
57
58
|
test('read initial balance of that account', async () => {
|
|
58
|
-
const result = await
|
|
59
|
+
const result = await erc20Contract.balanceOf(wallet);
|
|
59
60
|
const [res] = result;
|
|
60
61
|
expect(res.low).toStrictEqual(toBN(1000));
|
|
61
62
|
expect(res).toStrictEqual(result.balance);
|
|
@@ -65,17 +66,17 @@ describe('class Contract {}', () => {
|
|
|
65
66
|
const args1 = { user: wallet };
|
|
66
67
|
const args2 = {};
|
|
67
68
|
const calls = [
|
|
68
|
-
|
|
69
|
+
erc20Contract.address,
|
|
69
70
|
getSelectorFromName('balanceOf'),
|
|
70
71
|
Object.keys(args1).length,
|
|
71
72
|
...compileCalldata(args1),
|
|
72
73
|
|
|
73
|
-
|
|
74
|
+
erc20Contract.address,
|
|
74
75
|
getSelectorFromName('decimals'),
|
|
75
76
|
Object.keys(args2).length,
|
|
76
77
|
...compileCalldata(args2),
|
|
77
78
|
];
|
|
78
|
-
const result = await
|
|
79
|
+
const result = await multicallContract.aggregate(calls);
|
|
79
80
|
const [block_number, res] = result;
|
|
80
81
|
expect(isBN(block_number));
|
|
81
82
|
expect(Array.isArray(res));
|
|
@@ -86,36 +87,47 @@ describe('class Contract {}', () => {
|
|
|
86
87
|
});
|
|
87
88
|
|
|
88
89
|
describe('Type Transformation', () => {
|
|
89
|
-
let
|
|
90
|
+
let typeTransformedContract: Contract;
|
|
90
91
|
|
|
91
92
|
beforeAll(async () => {
|
|
92
|
-
const {
|
|
93
|
+
const { deploy } = await account.declareDeploy({
|
|
93
94
|
contract: compiledTypeTransformation,
|
|
95
|
+
classHash: '0x022a0e662b13d18a2aaa3ee54ae290de6569621b549022c18169c6e7893809ea',
|
|
94
96
|
});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
|
|
98
|
+
typeTransformedContract = new Contract(
|
|
99
|
+
compiledTypeTransformation.abi,
|
|
100
|
+
deploy.contract_address!,
|
|
101
|
+
provider
|
|
102
|
+
);
|
|
97
103
|
});
|
|
98
104
|
|
|
99
105
|
describe('Request Type Transformation', () => {
|
|
100
106
|
test('Parsing the felt in request', async () => {
|
|
101
|
-
return expect(
|
|
107
|
+
return expect(typeTransformedContract.request_felt(3)).resolves.not.toThrow();
|
|
102
108
|
});
|
|
103
109
|
|
|
104
110
|
test('Parsing the array of felt in request', async () => {
|
|
105
|
-
return expect(
|
|
111
|
+
return expect(
|
|
112
|
+
typeTransformedContract.request_array_of_felts([1, 2])
|
|
113
|
+
).resolves.not.toThrow();
|
|
106
114
|
});
|
|
107
115
|
|
|
108
116
|
test('Parsing the struct in request', async () => {
|
|
109
|
-
return expect(
|
|
117
|
+
return expect(
|
|
118
|
+
typeTransformedContract.request_struct({ x: 1, y: 2 })
|
|
119
|
+
).resolves.not.toThrow();
|
|
110
120
|
});
|
|
111
121
|
|
|
112
122
|
test('Parsing the array of structs in request', async () => {
|
|
113
|
-
return expect(
|
|
123
|
+
return expect(
|
|
124
|
+
typeTransformedContract.request_array_of_structs([{ x: 1, y: 2 }])
|
|
125
|
+
).resolves.not.toThrow();
|
|
114
126
|
});
|
|
115
127
|
|
|
116
128
|
test('Parsing the nested structs in request', async () => {
|
|
117
129
|
return expect(
|
|
118
|
-
|
|
130
|
+
typeTransformedContract.request_nested_structs({
|
|
119
131
|
p1: { x: 1, y: 2 },
|
|
120
132
|
p2: { x: 3, y: 4 },
|
|
121
133
|
extra: 5,
|
|
@@ -124,43 +136,45 @@ describe('class Contract {}', () => {
|
|
|
124
136
|
});
|
|
125
137
|
|
|
126
138
|
test('Parsing the tuple in request', async () => {
|
|
127
|
-
return expect(
|
|
139
|
+
return expect(typeTransformedContract.request_tuple([1, 2])).resolves.not.toThrow();
|
|
128
140
|
});
|
|
129
141
|
|
|
130
142
|
test('Parsing the multiple types in request', async () => {
|
|
131
|
-
return expect(
|
|
143
|
+
return expect(
|
|
144
|
+
typeTransformedContract.request_mixed_types(2, { x: 1, y: 2 }, [1])
|
|
145
|
+
).resolves.not.toThrow();
|
|
132
146
|
});
|
|
133
147
|
});
|
|
134
148
|
|
|
135
149
|
describe('Response Type Transformation', () => {
|
|
136
150
|
test('Parsing the felt in response', async () => {
|
|
137
|
-
const { res } = await
|
|
151
|
+
const { res } = await typeTransformedContract.get_felt();
|
|
138
152
|
expect(res).toStrictEqual(toBN(4));
|
|
139
153
|
});
|
|
140
154
|
|
|
141
155
|
test('Parsing the array of felt in response', async () => {
|
|
142
|
-
const result = await
|
|
156
|
+
const result = await typeTransformedContract.get_array_of_felts();
|
|
143
157
|
const [res] = result;
|
|
144
158
|
expect(res).toStrictEqual([toBN(4), toBN(5)]);
|
|
145
159
|
expect(res).toStrictEqual(result.res);
|
|
146
160
|
});
|
|
147
161
|
|
|
148
162
|
test('Parsing the array of structs in response', async () => {
|
|
149
|
-
const result = await
|
|
163
|
+
const result = await typeTransformedContract.get_struct();
|
|
150
164
|
const [res] = result;
|
|
151
165
|
expect(res).toStrictEqual({ x: toBN(1), y: toBN(2) });
|
|
152
166
|
expect(res).toStrictEqual(result.res);
|
|
153
167
|
});
|
|
154
168
|
|
|
155
169
|
test('Parsing the array of structs in response', async () => {
|
|
156
|
-
const result = await
|
|
170
|
+
const result = await typeTransformedContract.get_array_of_structs();
|
|
157
171
|
const [res] = result;
|
|
158
172
|
expect(res).toStrictEqual([{ x: toBN(1), y: toBN(2) }]);
|
|
159
173
|
expect(res).toStrictEqual(result.res);
|
|
160
174
|
});
|
|
161
175
|
|
|
162
176
|
test('Parsing the nested structs in response', async () => {
|
|
163
|
-
const result = await
|
|
177
|
+
const result = await typeTransformedContract.get_nested_structs();
|
|
164
178
|
const [res] = result;
|
|
165
179
|
expect(res).toStrictEqual({
|
|
166
180
|
p1: { x: toBN(1), y: toBN(2) },
|
|
@@ -171,14 +185,14 @@ describe('class Contract {}', () => {
|
|
|
171
185
|
});
|
|
172
186
|
|
|
173
187
|
test('Parsing the tuple in response', async () => {
|
|
174
|
-
const result = await
|
|
188
|
+
const result = await typeTransformedContract.get_tuple();
|
|
175
189
|
const [res] = result;
|
|
176
190
|
expect(res).toStrictEqual([toBN(1), toBN(2), toBN(3)]);
|
|
177
191
|
expect(res).toStrictEqual(result.res);
|
|
178
192
|
});
|
|
179
193
|
|
|
180
194
|
test('Parsing the multiple types in response', async () => {
|
|
181
|
-
const result = await
|
|
195
|
+
const result = await typeTransformedContract.get_mixed_types();
|
|
182
196
|
const [tuple, number, array, point] = result;
|
|
183
197
|
expect(tuple).toStrictEqual([toBN(1), toBN(2)]);
|
|
184
198
|
expect(number).toStrictEqual(toBN(3));
|
|
@@ -196,30 +210,29 @@ describe('class Contract {}', () => {
|
|
|
196
210
|
describe('class ContractFactory {}', () => {
|
|
197
211
|
let erc20Address: string;
|
|
198
212
|
const wallet = stark.randomAddress();
|
|
199
|
-
|
|
213
|
+
const account = getTestAccount(provider);
|
|
214
|
+
const constructorCalldata = [encodeShortString('Token'), encodeShortString('ERC20'), wallet];
|
|
215
|
+
const classHash = '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a';
|
|
200
216
|
|
|
201
217
|
beforeAll(async () => {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
await provider.waitForTransaction(transaction_hash);
|
|
209
|
-
erc20Address = contract_address;
|
|
218
|
+
await account.declareDeploy({
|
|
219
|
+
contract: compiledErc20,
|
|
220
|
+
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
|
|
221
|
+
constructorCalldata,
|
|
222
|
+
});
|
|
210
223
|
});
|
|
211
224
|
test('deployment of new contract', async () => {
|
|
212
|
-
const factory = new ContractFactory(compiledErc20,
|
|
213
|
-
const erc20 = await factory.deploy(
|
|
225
|
+
const factory = new ContractFactory(compiledErc20, classHash, account);
|
|
226
|
+
const erc20 = await factory.deploy(constructorCalldata);
|
|
214
227
|
expect(erc20 instanceof Contract);
|
|
215
228
|
});
|
|
216
229
|
test('wait for deployment transaction', async () => {
|
|
217
|
-
const factory = new ContractFactory(compiledErc20,
|
|
218
|
-
const contract = await factory.deploy(
|
|
230
|
+
const factory = new ContractFactory(compiledErc20, classHash, account);
|
|
231
|
+
const contract = await factory.deploy(constructorCalldata);
|
|
219
232
|
expect(contract.deployed()).resolves.not.toThrow();
|
|
220
233
|
});
|
|
221
234
|
test('attach new contract', async () => {
|
|
222
|
-
const factory = new ContractFactory(compiledErc20,
|
|
235
|
+
const factory = new ContractFactory(compiledErc20, classHash, account);
|
|
223
236
|
const erc20 = factory.attach(erc20Address);
|
|
224
237
|
expect(erc20 instanceof Contract);
|
|
225
238
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BlockNumber, GetBlockResponse, stark } from '../src';
|
|
2
2
|
import { toBN } from '../src/utils/number';
|
|
3
|
-
import {
|
|
3
|
+
import { encodeShortString } from '../src/utils/shortString';
|
|
4
|
+
import { compiledErc20, erc20ClassHash, getTestAccount, getTestProvider } from './fixtures';
|
|
4
5
|
|
|
5
6
|
const { compileCalldata } = stark;
|
|
6
7
|
|
|
@@ -9,21 +10,21 @@ const testProvider = getTestProvider();
|
|
|
9
10
|
describe('defaultProvider', () => {
|
|
10
11
|
let exampleTransactionHash: string;
|
|
11
12
|
let erc20ContractAddress: string;
|
|
12
|
-
|
|
13
13
|
let exampleBlock: GetBlockResponse;
|
|
14
14
|
let exampleBlockNumber: BlockNumber;
|
|
15
15
|
let exampleBlockHash: string;
|
|
16
16
|
const wallet = stark.randomAddress();
|
|
17
|
+
const account = getTestAccount(testProvider);
|
|
17
18
|
|
|
18
19
|
beforeAll(async () => {
|
|
19
|
-
const
|
|
20
|
+
const { deploy } = await account.declareDeploy({
|
|
21
|
+
contract: compiledErc20,
|
|
22
|
+
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
|
|
23
|
+
constructorCalldata: [encodeShortString('Token'), encodeShortString('ERC20'), wallet],
|
|
24
|
+
});
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
);
|
|
24
|
-
await testProvider.waitForTransaction(transaction_hash);
|
|
25
|
-
exampleTransactionHash = transaction_hash;
|
|
26
|
-
erc20ContractAddress = contract_address;
|
|
26
|
+
exampleTransactionHash = deploy.transaction_hash;
|
|
27
|
+
erc20ContractAddress = deploy.contract_address;
|
|
27
28
|
|
|
28
29
|
exampleBlock = await testProvider.getBlock('latest');
|
|
29
30
|
exampleBlockHash = exampleBlock.block_hash;
|
|
@@ -31,7 +32,7 @@ describe('defaultProvider', () => {
|
|
|
31
32
|
});
|
|
32
33
|
|
|
33
34
|
describe('endpoints', () => {
|
|
34
|
-
test('
|
|
35
|
+
test('declareDeploy()', () => {
|
|
35
36
|
expect(erc20ContractAddress).toBeTruthy();
|
|
36
37
|
expect(exampleTransactionHash).toBeTruthy();
|
|
37
38
|
});
|
|
@@ -74,9 +75,9 @@ describe('defaultProvider', () => {
|
|
|
74
75
|
});
|
|
75
76
|
});
|
|
76
77
|
|
|
77
|
-
test('
|
|
78
|
-
const nonce = await testProvider.
|
|
79
|
-
return expect(nonce).toEqual('0x0');
|
|
78
|
+
test('getNonceForAddress()', async () => {
|
|
79
|
+
const nonce = await testProvider.getNonceForAddress(erc20ContractAddress);
|
|
80
|
+
return expect(toBN(nonce)).toEqual(toBN('0x0'));
|
|
80
81
|
});
|
|
81
82
|
|
|
82
83
|
test('getClassAt(contractAddress, blockNumber="latest")', async () => {
|