Skip to content

Commit

Permalink
fix: Add extra test scripts for permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
richtera committed Apr 6, 2024
1 parent 24bda3a commit f52f1cf
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 3 deletions.
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
96 changes: 95 additions & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit f52f1cf

Please sign in to comment.