Skip to content

Commit e96894e

Browse files
andrew-flemingericglauericnordeloimmrsd
authored
Add cairo account (#387)
Co-authored-by: Eric Lau <[email protected]> Co-authored-by: Eric Nordelo <[email protected]> Co-authored-by: immrsd <[email protected]>
1 parent 670a0ba commit e96894e

25 files changed

+2115
-39
lines changed

packages/core-cairo/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Add Account and EthAccount. ([#387](https://github.com/OpenZeppelin/contracts-wizard/pull/387))
6+
57
- **Breaking changes**:
68
- Use OpenZeppelin Contracts for Cairo v0.15.0. ([#378](https://github.com/OpenZeppelin/contracts-wizard/pull/378))
79
- Use OpenZeppelin Contracts for Cairo v0.16.0. ([#384](https://github.com/OpenZeppelin/contracts-wizard/pull/384))

packages/core-cairo/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The following contract types are supported:
1616
- `erc20`
1717
- `erc721`
1818
- `erc1155`
19+
- `account`
1920
- `custom`
2021

2122
Each contract type has functions/constants as defined below.
@@ -33,6 +34,9 @@ function print(opts?: ERC721Options): string
3334
function print(opts?: ERC1155Options): string
3435
```
3536
```js
37+
function print(opts?: AccountOptions): string
38+
```
39+
```js
3640
function print(opts?: CustomOptions): string
3741
```
3842
Returns a string representation of a contract generated using the provided options. If `opts` is not provided, uses [`defaults`](#defaults).
@@ -48,6 +52,9 @@ const defaults: Required<ERC721Options>
4852
const defaults: Required<ERC1155Options>
4953
```
5054
```js
55+
const defaults: Required<AccountOptions>
56+
```
57+
```js
5158
const defaults: Required<CustomOptions>
5259
```
5360
The default options that are used for [`print`](#print).
@@ -67,6 +74,8 @@ function isAccessControlRequired(opts: Partial<CustomOptions>): boolean
6774
```
6875
Whether any of the provided options require access control to be enabled. If this returns `true`, then calling `print` with the same options would cause the `access` option to default to `'ownable'` if it was `undefined` or `false`.
6976

77+
> Note that account contracts handle permissions differently from the other supported contracts.
78+
Thus, the `account` contract type does not include `isAccessControlRequired`.
7079

7180
### Contract specific functions
7281

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
import test from 'ava';
2+
3+
import { buildAccount, AccountOptions } from './account';
4+
import { printContract } from './print';
5+
6+
import { account } from '.';
7+
8+
function testAccount(title: string, opts: Partial<AccountOptions>) {
9+
test(title, t => {
10+
const c = buildAccount({
11+
name: 'MyAccount',
12+
type: 'stark',
13+
...opts,
14+
});
15+
t.snapshot(printContract(c));
16+
});
17+
}
18+
19+
function testEthAccount(title: string, opts: Partial<AccountOptions>) {
20+
test(title, t => {
21+
const c = buildAccount({
22+
name: 'MyAccount',
23+
type: 'eth',
24+
...opts,
25+
});
26+
t.snapshot(printContract(c));
27+
});
28+
}
29+
30+
/**
31+
* Tests external API for equivalence with internal API
32+
*/
33+
function testAPIEquivalence(title: string, opts?: AccountOptions) {
34+
test(title, t => {
35+
t.is(account.print(opts), printContract(buildAccount({
36+
name: 'MyAccount',
37+
type: 'stark',
38+
declare: true,
39+
deploy: true,
40+
pubkey: true,
41+
...opts,
42+
})));
43+
});
44+
}
45+
46+
testAccount('default full account, mixin + upgradeable', {});
47+
48+
testAccount('default full account, mixin + non-upgradeable', {
49+
upgradeable: false
50+
});
51+
52+
testAccount('explicit full account, mixin + upgradeable', {
53+
name: 'MyAccount',
54+
type: 'stark',
55+
declare: true,
56+
deploy: true,
57+
pubkey: true,
58+
upgradeable: true
59+
});
60+
61+
testAccount('explicit full account, mixin + non-upgradeable', {
62+
name: 'MyAccount',
63+
type: 'stark',
64+
declare: true,
65+
deploy: true,
66+
pubkey: true,
67+
upgradeable: false
68+
});
69+
70+
testAccount('basic account, upgradeable', {
71+
declare: false,
72+
deploy: false,
73+
pubkey: false
74+
});
75+
76+
testAccount('basic account, non-upgradeable', {
77+
declare: false,
78+
deploy: false,
79+
pubkey: false,
80+
upgradeable: false
81+
});
82+
83+
testAccount('account declarer', {
84+
deploy: false,
85+
pubkey: false
86+
});
87+
88+
testAccount('account deployable', {
89+
declare: false,
90+
pubkey: false
91+
});
92+
93+
testAccount('account public key', {
94+
declare: false,
95+
deploy: false,
96+
});
97+
98+
testAccount('account declarer, deployable', {
99+
pubkey: false
100+
});
101+
102+
testAccount('account declarer, public key', {
103+
deploy: false
104+
});
105+
106+
testAccount('account deployable, public key', {
107+
declare: false
108+
});
109+
110+
testEthAccount('default full ethAccount, mixin + upgradeable', {});
111+
112+
testEthAccount('default full ethAccount, mixin + non-upgradeable', {
113+
upgradeable: false
114+
});
115+
116+
testEthAccount('explicit full ethAccount, mixin + upgradeable', {
117+
name: 'MyAccount',
118+
type: 'eth',
119+
declare: true,
120+
deploy: true,
121+
pubkey: true,
122+
upgradeable: true
123+
});
124+
125+
testEthAccount('explicit full ethAccount, mixin + non-upgradeable', {
126+
name: 'MyAccount',
127+
type: 'eth',
128+
declare: true,
129+
deploy: true,
130+
pubkey: true,
131+
upgradeable: false
132+
});
133+
134+
testEthAccount('basic ethAccount, upgradeable', {
135+
declare: false,
136+
deploy: false,
137+
pubkey: false
138+
});
139+
140+
testEthAccount('basic ethAccount, non-upgradeable', {
141+
declare: false,
142+
deploy: false,
143+
pubkey: false,
144+
upgradeable: false
145+
});
146+
147+
testEthAccount('ethAccount declarer', {
148+
deploy: false,
149+
pubkey: false
150+
});
151+
152+
testEthAccount('ethAccount deployable', {
153+
declare: false,
154+
pubkey: false
155+
});
156+
157+
testEthAccount('ethAccount public key', {
158+
declare: false,
159+
deploy: false,
160+
});
161+
162+
testEthAccount('ethAccount declarer, deployable', {
163+
pubkey: false
164+
});
165+
166+
testEthAccount('ethAccount declarer, public key', {
167+
deploy: false
168+
});
169+
170+
testEthAccount('ethAccount deployable, public key', {
171+
declare: false
172+
});
173+
174+
testAPIEquivalence('account API default');
175+
176+
testAPIEquivalence('account API basic', {
177+
name: 'CustomAccount',
178+
type: 'stark',
179+
declare: false,
180+
deploy: false,
181+
pubkey: false,
182+
upgradeable: false,
183+
});
184+
185+
testAPIEquivalence('account API full upgradeable', {
186+
name: 'CustomAccount',
187+
type: 'stark',
188+
declare: true,
189+
deploy: true,
190+
pubkey: true,
191+
upgradeable: true,
192+
});
193+
194+
test('account API assert defaults', async t => {
195+
t.is(account.print(account.defaults), account.print());
196+
});

0 commit comments

Comments
 (0)