Skip to content

Commit 9280664

Browse files
authored
Add ERC721Enumerable (#391)
1 parent 4dae94d commit 9280664

File tree

9 files changed

+358
-94
lines changed

9 files changed

+358
-94
lines changed

packages/core-cairo/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Add ERC721Enumerable. ([#391](https://github.com/OpenZeppelin/contracts-wizard/pull/391))
6+
37
## 0.15.0 (2024-09-19)
48

59
- Add Account and EthAccount. ([#387](https://github.com/OpenZeppelin/contracts-wizard/pull/387))

packages/core-cairo/src/contract.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ export interface Argument {
8686
export class ContractBuilder implements Contract {
8787
readonly name: string;
8888
readonly account: boolean;
89-
license: string = 'MIT';
89+
license = 'MIT';
9090
upgradeable = false;
9191

9292
readonly constructorArgs: Argument[] = [];
9393
readonly constructorCode: string[] = [];
9494

95-
private componentsMap: Map<string, Component> = new Map<string, Component>();
96-
private implementedTraitsMap: Map<string, ImplementedTrait> = new Map<string, ImplementedTrait>();
97-
private superVariablesMap: Map<string, Variable> = new Map<string, Variable>();
95+
private componentsMap: Map<string, Component> = new Map();
96+
private implementedTraitsMap: Map<string, ImplementedTrait> = new Map();
97+
private superVariablesMap: Map<string, Variable> = new Map();
9898
private standaloneImportsSet: Set<string> = new Set();
9999
private interfaceFlagsSet: Set<string> = new Set();
100100

@@ -126,7 +126,7 @@ export class ContractBuilder implements Contract {
126126
return this.interfaceFlagsSet;
127127
}
128128

129-
addStandaloneImport(fullyQualified: string) {
129+
addStandaloneImport(fullyQualified: string): void {
130130
this.standaloneImportsSet.add(fullyQualified);
131131
}
132132

@@ -141,7 +141,7 @@ export class ContractBuilder implements Contract {
141141
return !present;
142142
}
143143

144-
addImplToComponent(component: Component, impl: Impl) {
144+
addImplToComponent(component: Component, impl: Impl): void {
145145
this.addComponent(component);
146146
let c = this.componentsMap.get(component.name);
147147
if (c == undefined) {
@@ -153,7 +153,7 @@ export class ContractBuilder implements Contract {
153153
}
154154
}
155155

156-
addSuperVariable(variable: Variable) {
156+
addSuperVariable(variable: Variable): boolean {
157157
if (this.superVariablesMap.has(variable.name)) {
158158
return false;
159159
} else {
@@ -162,7 +162,7 @@ export class ContractBuilder implements Contract {
162162
}
163163
}
164164

165-
addImplementedTrait(baseTrait: BaseImplementedTrait) {
165+
addImplementedTrait(baseTrait: BaseImplementedTrait): ImplementedTrait {
166166
const key = baseTrait.name;
167167
const existingTrait = this.implementedTraitsMap.get(key);
168168
if (existingTrait !== undefined) {
@@ -180,7 +180,7 @@ export class ContractBuilder implements Contract {
180180
}
181181
}
182182

183-
addFunction(baseTrait: BaseImplementedTrait, fn: BaseFunction) {
183+
addFunction(baseTrait: BaseImplementedTrait, fn: BaseFunction): ContractFunction {
184184
const t = this.addImplementedTrait(baseTrait);
185185

186186
const signature = this.getFunctionSignature(fn);
@@ -203,17 +203,17 @@ export class ContractBuilder implements Contract {
203203
return contractFn;
204204
}
205205

206-
private getFunctionSignature(fn: BaseFunction) {
206+
private getFunctionSignature(fn: BaseFunction): string {
207207
return [fn.name, '(', ...fn.args.map(a => a.name), ')'].join('');
208208
}
209209

210-
addFunctionCodeBefore(baseTrait: BaseImplementedTrait, fn: BaseFunction, codeBefore: string) {
210+
addFunctionCodeBefore(baseTrait: BaseImplementedTrait, fn: BaseFunction, codeBefore: string): void {
211211
this.addImplementedTrait(baseTrait);
212212
const existingFn = this.addFunction(baseTrait, fn);
213213
existingFn.codeBefore = [ ...existingFn.codeBefore ?? [], codeBefore ];
214214
}
215215

216-
addConstructorArgument(arg: Argument) {
216+
addConstructorArgument(arg: Argument): void {
217217
for (const existingArg of this.constructorArgs) {
218218
if (existingArg.name == arg.name) {
219219
return;
@@ -222,11 +222,11 @@ export class ContractBuilder implements Contract {
222222
this.constructorArgs.push(arg);
223223
}
224224

225-
addConstructorCode(code: string) {
225+
addConstructorCode(code: string): void {
226226
this.constructorCode.push(code);
227227
}
228228

229-
addInterfaceFlag(flag: string) {
229+
addInterfaceFlag(flag: string): void {
230230
this.interfaceFlagsSet.add(flag);
231231
}
232232
}

packages/core-cairo/src/erc721.test.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import { printContract } from './print';
55

66
import { erc721 } from '.';
77

8+
const allFeaturesON: Partial<ERC721Options> = {
9+
mintable: true,
10+
burnable: true,
11+
pausable: true,
12+
enumerable: true,
13+
upgradeable: true
14+
} as const;
15+
816
function testERC721(title: string, opts: Partial<ERC721Options>) {
917
test(title, t => {
1018
const c = buildERC721({
@@ -51,36 +59,35 @@ testERC721('mintable', {
5159
mintable: true,
5260
});
5361

62+
testERC721('enumerable', {
63+
enumerable: true,
64+
});
65+
66+
testERC721('pausable + enumerable', {
67+
pausable: true,
68+
enumerable: true,
69+
});
70+
5471
testERC721('mintable + roles', {
5572
mintable: true,
5673
access: 'roles',
5774
});
5875

5976
testERC721('full non-upgradeable', {
60-
mintable: true,
61-
pausable: true,
62-
burnable: true,
77+
...allFeaturesON,
6378
upgradeable: false,
6479
});
6580

66-
testERC721('full upgradeable', {
67-
mintable: true,
68-
pausable: true,
69-
burnable: true,
70-
upgradeable: true,
71-
});
81+
testERC721('full upgradeable', allFeaturesON);
7282

7383
testAPIEquivalence('API default');
7484

7585
testAPIEquivalence('API basic', { name: 'CustomToken', symbol: 'CTK' });
7686

7787
testAPIEquivalence('API full upgradeable', {
88+
...allFeaturesON,
7889
name: 'CustomToken',
79-
symbol: 'CTK',
80-
burnable: true,
81-
mintable: true,
82-
pausable: true,
83-
upgradeable: true,
90+
symbol: 'CTK'
8491
});
8592

8693
test('API assert defaults', async t => {
@@ -91,4 +98,6 @@ test('API isAccessControlRequired', async t => {
9198
t.is(erc721.isAccessControlRequired({ mintable: true }), true);
9299
t.is(erc721.isAccessControlRequired({ pausable: true }), true);
93100
t.is(erc721.isAccessControlRequired({ upgradeable: true }), true);
101+
t.is(erc721.isAccessControlRequired({ burnable: true }), false);
102+
t.is(erc721.isAccessControlRequired({ enumerable: true }), false);
94103
});

0 commit comments

Comments
 (0)