From f52f1cf256befecd6973d7dc644d3f66c625cb09 Mon Sep 17 00:00:00 2001 From: Andreas Richter <708186+richtera@users.noreply.github.com> Date: Sat, 6 Apr 2024 14:09:48 -0400 Subject: [PATCH] fix: Add extra test scripts for permissions --- package.json | 12 +++++- src/index.test.ts | 96 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 105 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 82fe37cb..6ac2cc9c 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,11 @@ "main": "build/main/src/index.js", "typings": "build/main/src/index.d.ts", "module": "build/module/src/index.js", - "files": ["build", "schemas", "docs"], + "files": [ + "build", + "schemas", + "docs" + ], "scripts": { "build": "run-p build:*", "build:main": "tsc -p tsconfig.json", @@ -20,7 +24,11 @@ "type": "git", "url": "git+https://github.com/ERC725Alliance/erc725.js" }, - "keywords": ["ethereum", "erc725", "lsp"], + "keywords": [ + "ethereum", + "erc725", + "lsp" + ], "contributors": [ { "name": "Robert McLeod", diff --git a/src/index.test.ts b/src/index.test.ts index db4a4853..f963b2ab 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1536,7 +1536,7 @@ describe('Running @erc725/erc725.js tests...', () => { ); }); - it('should allow editing of permissions', () => { + it('should allow editing of permissions remove from all', () => { const permissions = { ALL_PERMISSIONS: true }; const encoded = encodePermissions(permissions); @@ -1552,6 +1552,28 @@ describe('Running @erc725/erc725.js tests...', () => { ); }); + it('should allow editing of permissions add extra', () => { + const permissions = { ALL_PERMISSIONS: true }; + const encoded = encodePermissions(permissions); + + const decodedPermissions = decodePermissions(encoded); + decodedPermissions.SUPER_DELEGATECALL = true; + decodedPermissions.DELEGATECALL = true; + const reencodePermissions = encodePermissions(decodedPermissions); + const redecodedPermissions = decodePermissions(reencodePermissions); + + assert.strictEqual( + redecodedPermissions.SUPER_DELEGATECALL, + true, + 'Re-reencoded permissions includes SUPER_DELEGATECALL', + ); + assert.strictEqual( + redecodedPermissions.DELEGATECALL, + true, + 'Re-reencoded permissions includes DELEGATECALL', + ); + }); + it('should ignore individual permissions when ALL_PERMISSIONS is set', () => { const permissions = { ALL_PERMISSIONS: true, @@ -1596,6 +1618,78 @@ describe('Running @erc725/erc725.js tests...', () => { ); }); }); + it('Decodes 0xfff...fff admin permission correctly but re-encodes only known', () => { + let decoded = erc725Instance.decodePermissions( + '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', + ); + let reencoded = erc725Instance.encodePermissions(decoded); + assert.deepStrictEqual( + reencoded, + '0x0000000000000000000000000000000000000000000000000000000000ffffff', + ); + assert.deepStrictEqual(erc725Instance.decodePermissions(reencoded), { + CHANGEOWNER: true, + ADDCONTROLLER: true, + EDITPERMISSIONS: true, + ADDEXTENSIONS: true, + CHANGEEXTENSIONS: true, + ADDUNIVERSALRECEIVERDELEGATE: true, + CHANGEUNIVERSALRECEIVERDELEGATE: true, + REENTRANCY: true, + SUPER_TRANSFERVALUE: true, + TRANSFERVALUE: true, + SUPER_CALL: true, + CALL: true, + SUPER_STATICCALL: true, + STATICCALL: true, + SUPER_DELEGATECALL: true, + DELEGATECALL: true, + DEPLOY: true, + SUPER_SETDATA: true, + SETDATA: true, + ENCRYPT: true, + DECRYPT: true, + SIGN: true, + EXECUTE_RELAY_CALL: true, + ERC4337_PERMISSION: true, + ALL_PERMISSIONS: true, + }); + decoded = decodePermissions( + '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', + ); + reencoded = encodePermissions(decoded); + assert.deepStrictEqual( + reencoded, + '0x0000000000000000000000000000000000000000000000000000000000ffffff', + ); + assert.deepStrictEqual(decodePermissions(reencoded), { + CHANGEOWNER: true, + ADDCONTROLLER: true, + EDITPERMISSIONS: true, + ADDEXTENSIONS: true, + CHANGEEXTENSIONS: true, + ADDUNIVERSALRECEIVERDELEGATE: true, + CHANGEUNIVERSALRECEIVERDELEGATE: true, + REENTRANCY: true, + SUPER_TRANSFERVALUE: true, + TRANSFERVALUE: true, + SUPER_CALL: true, + CALL: true, + SUPER_STATICCALL: true, + STATICCALL: true, + SUPER_DELEGATECALL: true, + DELEGATECALL: true, + DEPLOY: true, + SUPER_SETDATA: true, + SETDATA: true, + ENCRYPT: true, + DECRYPT: true, + SIGN: true, + EXECUTE_RELAY_CALL: true, + ERC4337_PERMISSION: true, + ALL_PERMISSIONS: true, + }); + }); it('Decodes 0xfff...fff admin permission correctly', () => { assert.deepStrictEqual( decodePermissions(