From 2b4c245785397f2d2745004baca8cc3c00484d4c Mon Sep 17 00:00:00 2001 From: Rinse Date: Fri, 22 Mar 2024 17:20:36 +0000 Subject: [PATCH] fix(edit): throw if user tries to edit a remote sub --- src/cli/commands/subplebbit/edit.ts | 2 ++ test/cli/edit.subplebbit.test.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/src/cli/commands/subplebbit/edit.ts b/src/cli/commands/subplebbit/edit.ts index f17d69b..e7fc0bd 100644 --- a/src/cli/commands/subplebbit/edit.ts +++ b/src/cli/commands/subplebbit/edit.ts @@ -49,6 +49,8 @@ export default class Edit extends BaseCommand { const editOptions: SubplebbitEditOptions = DataObjectParser.transpose(lodash.omit(flags, ["plebbitRpcApiUrl"]))["_data"]; log("Edit options parsed:", editOptions); const plebbit = await this._connectToPlebbitRpc(flags.plebbitRpcApiUrl.toString()); + const localSubs = await plebbit.listSubplebbits(); + if (!localSubs.includes(args.address)) this.error("Can't edit a remote subplebbit, make sure you're editing a local sub"); const sub = await plebbit.createSubplebbit({ address: args.address }); const mergedSubState = lodash.pick(sub.toJSONInternalRpc(), Object.keys(editOptions)); diff --git a/test/cli/edit.subplebbit.test.ts b/test/cli/edit.subplebbit.test.ts index 3c80e0f..ae12892 100644 --- a/test/cli/edit.subplebbit.test.ts +++ b/test/cli/edit.subplebbit.test.ts @@ -23,6 +23,7 @@ describe("plebbit subplebbit edit", () => { before(() => { const plebbitInstanceFake = sandbox.fake.resolves({ createSubplebbit: sandbox.fake.resolves({ edit: editFake, ...currentSubProps, toJSONInternalRpc: () => currentSubProps }), + listSubplebbits: sandbox.fake.resolves(["plebbit.eth"]), destroy: () => {} }); //@ts-expect-error