From dbcbd3ca449744355ee059c74ca413fbf86dfd67 Mon Sep 17 00:00:00 2001 From: benk10 Date: Sun, 15 Mar 2020 11:58:33 +0200 Subject: [PATCH] Fix #496 (#497) * Fix #496 * SchemRegistrar test * bump version * Bump version to 39 * version fix --- package-lock.json | 91 +++++++++++++++--------- package.json | 2 +- src/mappings/Controller/mapping.ts | 14 ++-- src/mappings/Controller/schema.graphql | 1 + src/mappings/UController/mapping.ts | 14 ++-- test/0.0.1-rc.16/SchemeRegistrar.spec.ts | 2 + test/0.0.1-rc.16/UController.spec.ts | 15 ++++ test/0.0.1-rc.19/SchemeRegistrar.spec.ts | 2 + test/0.0.1-rc.19/UController.spec.ts | 15 ++++ 9 files changed, 111 insertions(+), 45 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6b23f0b5..ec832228 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@daostack/subgraph", - "version": "0.0.38-3", + "version": "0.0.39-0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1045,7 +1045,7 @@ "bs58": "^4.0.1", "buffer": "^5.4.2", "cids": "~0.7.1", - "concat-stream": "github:hugomrdias/concat-stream#057bc7b5d6d8df26c8cf00a3f151b6721a0a8034", + "concat-stream": "github:hugomrdias/concat-stream#feat/smaller", "debug": "^4.1.0", "detect-node": "^2.0.4", "end-of-stream": "^1.4.1", @@ -1074,7 +1074,7 @@ "multibase": "~0.6.0", "multicodec": "~0.5.1", "multihashes": "~0.4.14", - "ndjson": "github:hugomrdias/ndjson#4db16da6b42e5b39bf300c3a7cde62abb3fa3a11", + "ndjson": "github:hugomrdias/ndjson#feat/readable-stream3", "once": "^1.4.0", "peer-id": "~0.12.3", "peer-info": "~0.15.1", @@ -1549,9 +1549,9 @@ } }, "acorn": { - "version": "5.7.3", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", - "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==" + "version": "5.7.4", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.4.tgz", + "integrity": "sha512-1D++VG7BhrtvQpNbBzovKNc1FLGGEE/oGe7b9xJm/RFHMBeUaUGpluV9RLjZa47YFdPcDAenEYuq9pQPcMdLJg==" }, "acorn-globals": { "version": "4.3.4", @@ -1563,9 +1563,9 @@ }, "dependencies": { "acorn": { - "version": "6.4.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.0.tgz", - "integrity": "sha512-gac8OEcQ2Li1dxIEWGZzsp2BitJxwkwcOm0zHAJLcPJaVvm58FRnk6RkuLRpU1EujipU2ZFODv2P9DLMfnV8mw==" + "version": "6.4.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.1.tgz", + "integrity": "sha512-ZVA9k326Nwrj3Cj9jlh3wGFutC2ZornPNARZwsNYqQYgN0EsV2d53w5RN/co65Ohn4sUAUtb1rSUAOD6XN9idA==" } } }, @@ -1987,7 +1987,8 @@ "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "optional": true }, "string_decoder": { "version": "1.1.1", @@ -3089,7 +3090,8 @@ "console-control-strings": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", - "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=" + "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", + "optional": true }, "contains-path": { "version": "0.1.0", @@ -4452,9 +4454,9 @@ }, "dependencies": { "acorn": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz", - "integrity": "sha512-kL5CuoXA/dgxlBbVrflsflzQ3PAas7RYZB52NOm/6839iVYJgKMJ3cQJD+t2i5+qFa8h3MDpEOJiS64E8JLnSQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.1.tgz", + "integrity": "sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg==", "dev": true } } @@ -5887,7 +5889,8 @@ "ansi-regex": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "optional": true }, "is-fullwidth-code-point": { "version": "1.0.0", @@ -5913,6 +5916,7 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -7792,7 +7796,8 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true + "bundled": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -7810,11 +7815,13 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true + "bundled": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -7827,15 +7834,18 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "concat-map": { "version": "0.0.1", - "bundled": true + "bundled": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -7938,7 +7948,8 @@ }, "inherits": { "version": "2.0.4", - "bundled": true + "bundled": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -7948,6 +7959,7 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -7960,17 +7972,20 @@ "minimatch": { "version": "3.0.4", "bundled": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true + "bundled": true, + "optional": true }, "minipass": { "version": "2.9.0", "bundled": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -7987,6 +8002,7 @@ "mkdirp": { "version": "0.5.1", "bundled": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -8067,7 +8083,8 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true + "bundled": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -8077,6 +8094,7 @@ "once": { "version": "1.4.0", "bundled": true, + "optional": true, "requires": { "wrappy": "1" } @@ -8152,7 +8170,8 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true + "bundled": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -8182,6 +8201,7 @@ "string-width": { "version": "1.0.2", "bundled": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -8199,6 +8219,7 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -8237,11 +8258,13 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true + "bundled": true, + "optional": true }, "yallist": { "version": "3.1.1", - "bundled": true + "bundled": true, + "optional": true } } }, @@ -8735,9 +8758,9 @@ } }, "kind-of": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", - "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==" + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", + "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==" }, "kleur": { "version": "3.0.3", @@ -12386,6 +12409,7 @@ "version": "2.3.6", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", + "optional": true, "requires": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -12399,7 +12423,8 @@ "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "optional": true } } }, @@ -12407,6 +12432,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "optional": true, "requires": { "safe-buffer": "~5.1.0" }, @@ -12414,7 +12440,8 @@ "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "optional": true } } }, @@ -13423,7 +13450,7 @@ "requires": { "underscore": "1.8.3", "web3-core-helpers": "1.0.0-beta.37", - "websocket": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2" + "websocket": "git://github.com/frozeman/WebSocket-Node.git#browserifyCompatible" } }, "web3-shh": { diff --git a/package.json b/package.json index 992cf3df..63cc32d7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@daostack/subgraph", - "version": "0.0.38-3", + "version": "0.0.39-0", "author": "DAOstack (https://www.daostack.io)", "license": "GPL-3.0", "description": "A caching layer for daostack using The Graph", diff --git a/src/mappings/Controller/mapping.ts b/src/mappings/Controller/mapping.ts index 880ae05b..6c59fe09 100644 --- a/src/mappings/Controller/mapping.ts +++ b/src/mappings/Controller/mapping.ts @@ -69,6 +69,7 @@ function insertScheme( controllerScheme.numberOfPreBoostedProposals = BigInt.fromI32(0); controllerScheme.numberOfBoostedProposals = BigInt.fromI32(0); controllerScheme.numberOfExpiredInQueueProposals = BigInt.fromI32(0); + controllerScheme.isRegistered = true; } controllerScheme.dao = avatarAddress.toHex(); controllerScheme.paramsHash = paramsHash; @@ -91,11 +92,12 @@ function insertScheme( controllerScheme.save(); } -function deleteScheme(avatarAddress: Address, scheme: Address): void { - store.remove( - 'ControllerScheme', - crypto.keccak256(concat(avatarAddress, scheme)).toHex(), - ); +function unregisterScheme(avatarAddress: Address, scheme: Address): void { + let controllerScheme = ControllerScheme.load(crypto.keccak256(concat(avatarAddress, scheme)).toHex()); + if (controllerScheme != null) { + controllerScheme.isRegistered = false; + controllerScheme.save(); + } } function insertOrganization( @@ -215,7 +217,7 @@ export function handleRegisterScheme(event: RegisterScheme): void { export function handleUnregisterScheme(event: UnregisterScheme): void { let controller = Controller.bind(event.address); let avatar = controller.avatar(); - deleteScheme(avatar, event.params._scheme); + unregisterScheme(avatar, event.params._scheme); let ent = new ControllerUnregisterScheme(eventId(event)); ent.txHash = event.transaction.hash; diff --git a/src/mappings/Controller/schema.graphql b/src/mappings/Controller/schema.graphql index 2be0ddfb..b99c0ef7 100644 --- a/src/mappings/Controller/schema.graphql +++ b/src/mappings/Controller/schema.graphql @@ -28,6 +28,7 @@ type ControllerScheme @entity { numberOfPreBoostedProposals: BigInt! numberOfBoostedProposals: BigInt! numberOfExpiredInQueueProposals: BigInt! + isRegistered: Boolean! } type ControllerGlobalConstraint @entity { diff --git a/src/mappings/UController/mapping.ts b/src/mappings/UController/mapping.ts index 05c61feb..3b730b6b 100644 --- a/src/mappings/UController/mapping.ts +++ b/src/mappings/UController/mapping.ts @@ -54,6 +54,7 @@ function insertScheme( controllerScheme.numberOfPreBoostedProposals = BigInt.fromI32(0); controllerScheme.numberOfBoostedProposals = BigInt.fromI32(0); controllerScheme.numberOfExpiredInQueueProposals = BigInt.fromI32(0); + controllerScheme.isRegistered = true; } controllerScheme.dao = avatarAddress.toHex(); controllerScheme.paramsHash = paramsHash; @@ -75,11 +76,12 @@ function insertScheme( controllerScheme.save(); } -function deleteScheme(avatarAddress: Address, scheme: Address): void { - store.remove( - 'ControllerScheme', - crypto.keccak256(concat(avatarAddress, scheme)).toHex(), - ); +function unregisterScheme(avatarAddress: Address, scheme: Address): void { + let controllerScheme = ControllerScheme.load(crypto.keccak256(concat(avatarAddress, scheme)).toHex()); + if (controllerScheme != null) { + controllerScheme.isRegistered = false; + controllerScheme.save(); + } } function insertOrganization( @@ -200,7 +202,7 @@ export function handleRegisterScheme(event: RegisterScheme): void { } export function handleUnregisterScheme(event: UnregisterScheme): void { - deleteScheme(event.params._avatar, event.params._scheme); + unregisterScheme(event.params._avatar, event.params._scheme); let ent = new UControllerUnregisterScheme(eventId(event)); ent.txHash = event.transaction.hash; diff --git a/test/0.0.1-rc.16/SchemeRegistrar.spec.ts b/test/0.0.1-rc.16/SchemeRegistrar.spec.ts index 93228e3d..2d1cc5d1 100644 --- a/test/0.0.1-rc.16/SchemeRegistrar.spec.ts +++ b/test/0.0.1-rc.16/SchemeRegistrar.spec.ts @@ -164,6 +164,7 @@ describe('SchemeRegistrar', () => { id } address + isRegistered } }`; @@ -191,6 +192,7 @@ describe('SchemeRegistrar', () => { id: addresses.Avatar.toLowerCase(), }, address: accounts[0].address.toLowerCase(), + isRegistered: true, }); expect((await sendQuery(getDAO)).dao.schemes).toContainEqual( { diff --git a/test/0.0.1-rc.16/UController.spec.ts b/test/0.0.1-rc.16/UController.spec.ts index 16b16fc9..e771e274 100644 --- a/test/0.0.1-rc.16/UController.spec.ts +++ b/test/0.0.1-rc.16/UController.spec.ts @@ -242,6 +242,7 @@ describe('UController', () => { numberOfPreBoostedProposals numberOfBoostedProposals numberOfExpiredInQueueProposals + isRegistered } }`); @@ -260,6 +261,7 @@ describe('UController', () => { numberOfExpiredInQueueProposals: '0', numberOfPreBoostedProposals: '0', numberOfQueuedProposals: '0', + isRegistered: true, }); expect(controllerSchemes).toContainEqual({ dao: { @@ -276,6 +278,19 @@ describe('UController', () => { numberOfExpiredInQueueProposals: '0', numberOfPreBoostedProposals: '0', numberOfQueuedProposals: '0', + isRegistered: true, + }); + + const isRegisteredScheme = await sendQuery(`{ + controllerSchemes(where: { address: "${accounts[3].address.toLowerCase()}" }) { + address + isRegistered + } + }`); + + expect(isRegisteredScheme.controllerSchemes).toContainEqual({ + address: accounts[3].address.toLowerCase(), + isRegistered: false, }); const { ucontrollerAddGlobalConstraints } = await sendQuery(`{ diff --git a/test/0.0.1-rc.19/SchemeRegistrar.spec.ts b/test/0.0.1-rc.19/SchemeRegistrar.spec.ts index 93228e3d..2d1cc5d1 100644 --- a/test/0.0.1-rc.19/SchemeRegistrar.spec.ts +++ b/test/0.0.1-rc.19/SchemeRegistrar.spec.ts @@ -164,6 +164,7 @@ describe('SchemeRegistrar', () => { id } address + isRegistered } }`; @@ -191,6 +192,7 @@ describe('SchemeRegistrar', () => { id: addresses.Avatar.toLowerCase(), }, address: accounts[0].address.toLowerCase(), + isRegistered: true, }); expect((await sendQuery(getDAO)).dao.schemes).toContainEqual( { diff --git a/test/0.0.1-rc.19/UController.spec.ts b/test/0.0.1-rc.19/UController.spec.ts index 16b16fc9..e771e274 100644 --- a/test/0.0.1-rc.19/UController.spec.ts +++ b/test/0.0.1-rc.19/UController.spec.ts @@ -242,6 +242,7 @@ describe('UController', () => { numberOfPreBoostedProposals numberOfBoostedProposals numberOfExpiredInQueueProposals + isRegistered } }`); @@ -260,6 +261,7 @@ describe('UController', () => { numberOfExpiredInQueueProposals: '0', numberOfPreBoostedProposals: '0', numberOfQueuedProposals: '0', + isRegistered: true, }); expect(controllerSchemes).toContainEqual({ dao: { @@ -276,6 +278,19 @@ describe('UController', () => { numberOfExpiredInQueueProposals: '0', numberOfPreBoostedProposals: '0', numberOfQueuedProposals: '0', + isRegistered: true, + }); + + const isRegisteredScheme = await sendQuery(`{ + controllerSchemes(where: { address: "${accounts[3].address.toLowerCase()}" }) { + address + isRegistered + } + }`); + + expect(isRegisteredScheme.controllerSchemes).toContainEqual({ + address: accounts[3].address.toLowerCase(), + isRegistered: false, }); const { ucontrollerAddGlobalConstraints } = await sendQuery(`{