Skip to content

Commit 041cf8f

Browse files
authored
Change order initial users param (#155)
* fix param order * test fix * only owner access * fix test
1 parent c85fd17 commit 041cf8f

5 files changed

Lines changed: 70 additions & 33 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,16 @@ e.g.: `'[{"id":"cpu","amount":3},{"id":"ram","amount":16772672536},{"id":"disk",
355355
**Create Access List:**
356356

357357
- **Positional:**
358-
`npm run cli createAccessList "My Access List" "MAL" false "0xUser1,0xUser2"`
358+
`npm run cli createAccessList "My Access List" "MAL" "0xUser1,0xUser2" false`
359359

360360
- **Named Options:**
361-
`npm run cli createAccessList --name "My Access List" --symbol "MAL" --transferable false --users "0xUser1,0xUser2"`
361+
`npm run cli createAccessList --name "My Access List" --symbol "MAL" --initial-users "0xUser1,0xUser2" --transferable false`
362362

363363
- Arguments:
364364
- `name`: Name for the access list
365365
- `symbol`: Symbol for the access list
366-
- `transferable`: Whether tokens are transferable (true/false)
367366
- `initialUsers`: Comma-separated list of initial user addresses (optional)
367+
- `transferable`: Whether tokens are transferable (true/false, optional, default: `false`)
368368

369369
---
370370

@@ -490,8 +490,8 @@ e.g.: `'[{"id":"cpu","amount":3},{"id":"ram","amount":16772672536},{"id":"disk",
490490
- **createAccessList:**
491491
`-n, --name <name>`
492492
`-s, --symbol <symbol>`
493-
`-t, --transferable [transferable]` (Default: `false`)
494-
`-u, --users [initialUsers]` (Default: `''`)
493+
`-u, --initial-users [initialUsers]` (Default: `''`)
494+
`-t, --transferable [transferable]` (Default: `false`)
495495

496496
- **addToAccessList:**
497497
`-a, --address <accessListAddress>`

src/cli.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -680,36 +680,36 @@ export async function createCLI() {
680680
.description("Create a new access list contract")
681681
.argument("<name>", "Name for the access list")
682682
.argument("<symbol>", "Symbol for the access list")
683+
.argument(
684+
"[initialUsers]",
685+
"Comma-separated list of initial user addresses",
686+
""
687+
)
683688
.argument(
684689
"[transferable]",
685690
"Whether tokens are transferable (true/false)",
686691
"false"
687692
)
688-
.argument(
689-
"[initialUsers]",
693+
.option("-n, --name <name>", "Name for the access list")
694+
.option("-s, --symbol <symbol>", "Symbol for the access list")
695+
.option(
696+
"-u, --initial-users [initialUsers]",
690697
"Comma-separated list of initial user addresses",
691698
""
692699
)
693-
.option("-n, --name <name>", "Name for the access list")
694-
.option("-s, --symbol <symbol>", "Symbol for the access list")
695700
.option(
696701
"-t, --transferable [transferable]",
697702
"Whether tokens are transferable (true/false)",
698703
"false"
699704
)
700-
.option(
701-
"-u, --users [initialUsers]",
702-
"Comma-separated list of initial user addresses",
703-
""
704-
)
705-
.action(async (name, symbol, transferable, initialUsers, options) => {
705+
.action(async (name, symbol, initialUsers, transferable, options) => {
706706
const { signer, chainId } = await initializeSigner();
707707
const commands = new Commands(signer, chainId);
708708
await commands.createAccessList([
709709
options.name || name,
710710
options.symbol || symbol,
711711
options.transferable || transferable,
712-
options.users || initialUsers,
712+
options.initialUsers || initialUsers,
713713
]);
714714
});
715715

@@ -818,8 +818,8 @@ export async function createCLI() {
818818

819819
program
820820
.command("createBucket")
821-
.description("Create a new persistent-storage bucket gated by a single access list (chain inferred from RPC)")
822-
.argument("<accessListAddress>", "Access list contract address (0x…)")
821+
.description("Create a new persistent-storage bucket. Pass an access list to gate it; omit for owner-only access (chain inferred from RPC)")
822+
.argument("[accessListAddress]", "Access list contract address (0x…); omit for owner-only access")
823823
.action(async (accessListAddress) => {
824824
const { signer, chainId } = await initializeSigner();
825825
const commands = new Commands(signer, chainId);

src/commands.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,17 +1799,17 @@ export class Commands {
17991799
public async createBucket(args: string[]): Promise<void> {
18001800
try {
18011801
const accessListAddress = args[1];
1802-
if (!accessListAddress) {
1803-
console.error(chalk.red("accessListAddress is required"));
1804-
return;
1805-
}
1806-
if (!/^0x[a-fA-F0-9]{40}$/.test(accessListAddress)) {
1807-
console.error(chalk.red(`Invalid access list address: ${accessListAddress}`));
1808-
return;
1802+
let accessLists: Array<{ [chainId: string]: string[] }> = [];
1803+
1804+
if (accessListAddress) {
1805+
if (!/^0x[a-fA-F0-9]{40}$/.test(accessListAddress)) {
1806+
console.error(chalk.red(`Invalid access list address: ${accessListAddress}`));
1807+
return;
1808+
}
1809+
const { chainId } = await this.signer.provider.getNetwork();
1810+
accessLists = [{ [String(chainId)]: [accessListAddress] }];
18091811
}
18101812

1811-
const { chainId } = await this.signer.provider.getNetwork();
1812-
const accessLists = [{ [String(chainId)]: [accessListAddress] }];
18131813
const result = await ProviderInstance.createPersistentStorageBucket(
18141814
this.oceanNodeUrl,
18151815
this.signer,

test/accessList.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ describe("Ocean CLI Access List", function () {
3333
it("should create a new access list contract", async function () {
3434
const name = "TestAccessList";
3535
const symbol = "TAL";
36-
const transferable = "false";
3736

3837
const output = await runCommand(
39-
`npm run cli createAccessList ${name} ${symbol} ${transferable}`
38+
`npm run cli createAccessList ${name} ${symbol}`
4039
);
4140

4241
expect(output).to.include("Access list created successfully");
@@ -58,7 +57,7 @@ describe("Ocean CLI Access List", function () {
5857
const initialUsers = `${testUser1.address},${testUser2.address}`;
5958

6059
const output = await runCommand(
61-
`npm run cli createAccessList ${name} ${symbol} ${transferable} ${initialUsers}`
60+
`npm run cli createAccessList ${name} ${symbol} ${initialUsers} ${transferable}`
6261
);
6362

6463
expect(output).to.include("Access list created successfully");
@@ -238,7 +237,7 @@ describe("Ocean CLI Access List", function () {
238237
describe("Edge Cases", function () {
239238
it("should handle empty initial users list", async function () {
240239
const output = await runCommand(
241-
`npm run cli createAccessList EmptyList EL false ""`
240+
`npm run cli createAccessList EmptyList EL "" false`
242241
);
243242

244243
expect(output).to.include("Access list created successfully");
@@ -263,7 +262,7 @@ describe("Ocean CLI Access List", function () {
263262
describe("E2E Workflow", function () {
264263
it("should complete a full access list workflow", async function () {
265264
const createOutput = await runCommand(
266-
`npm run cli createAccessList WorkflowTest WT false`
265+
`npm run cli createAccessList WorkflowTest WT`
267266
);
268267
expect(createOutput).to.include("Access list created successfully");
269268

test/storage.test.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe("Ocean CLI Persistent Storage", function () {
4141

4242
it("should create an access list and add Alice and Bob", async function () {
4343
const createOutput = await runCommand(
44-
`npm run cli createAccessList StorageTestACL STACL false`
44+
`npm run cli createAccessList StorageTestACL STACL`
4545
);
4646
expect(createOutput).to.include("Access list created successfully");
4747
const addressMatch = createOutput.match(
@@ -122,4 +122,42 @@ describe("Ocean CLI Persistent Storage", function () {
122122
);
123123
expect(listOutput).to.not.include(fileName);
124124
});
125+
126+
describe("Owner-only bucket (no ACL)", function () {
127+
let ownerOnlyBucketId: string;
128+
129+
it("Alice should create a bucket without an access list", async function () {
130+
const output = await runCommand(`npm run cli createBucket`);
131+
expect(output).to.include("Bucket created.");
132+
const idMatch = output.match(
133+
/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
134+
);
135+
if (!idMatch) {
136+
throw new Error("Could not extract bucketId from output");
137+
}
138+
ownerOnlyBucketId = idMatch[0];
139+
expect(output.toLowerCase()).to.include(alice.address.toLowerCase());
140+
});
141+
142+
it("Alice (owner) should upload and list files in the no-ACL bucket", async function () {
143+
const uploadOutput = await runCommand(
144+
`npm run cli addFileToBucket ${ownerOnlyBucketId} ${tempFilePath}`
145+
);
146+
expect(uploadOutput).to.include(fileName);
147+
148+
const listOutput = await runCommand(
149+
`npm run cli listFilesInBucket ${ownerOnlyBucketId}`
150+
);
151+
expect(listOutput).to.include(fileName);
152+
expect(listOutput).to.not.match(/Error listing files/i);
153+
});
154+
155+
it("Bob (not the owner) should not see Alice's files in the no-ACL bucket", async function () {
156+
const bobOutput = await runCommandAs(
157+
BOB_KEY,
158+
`npm run cli listFilesInBucket ${ownerOnlyBucketId}`
159+
);
160+
expect(bobOutput).to.not.include(fileName);
161+
});
162+
});
125163
});

0 commit comments

Comments
 (0)