Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Try to work on tests on top of upgrades #462

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ describe('Running @erc725/erc725.js tests...', () => {
name: 'ThisKeyDoesNotExist',
key: '0xb12a0af5f83066646eb63c96bf29dcb827024d9a33189f5a61652a03951d1fbe',
value: null,
nonDynamicName: 'ThisKeyDoesNotExist',
};

assert.deepStrictEqual(data, expectedResult);
Expand All @@ -240,6 +241,7 @@ describe('Running @erc725/erc725.js tests...', () => {
keyType: 'Array',
valueContent: 'Address',
valueType: 'address',
nonDynamicName: 'NonExistingArray[]',
},
],
ERC725_CONTRACT_ADDRESS,
Expand All @@ -251,6 +253,7 @@ describe('Running @erc725/erc725.js tests...', () => {
name: 'NonExistingArray[]',
key: '0xd6cbdbfc8d25c9ce4720b5fe6fa8fc536803944271617bf5425b4bd579195840',
value: [],
nonDynamicName: 'NonExistingArray[]',
});

const dataArray = await erc725.getData(['NonExistingArray[]']);
Expand All @@ -259,6 +262,7 @@ describe('Running @erc725/erc725.js tests...', () => {
name: 'NonExistingArray[]',
key: '0xd6cbdbfc8d25c9ce4720b5fe6fa8fc536803944271617bf5425b4bd579195840',
value: [],
nonDynamicName: 'NonExistingArray[]',
},
]);
});
Expand All @@ -284,6 +288,7 @@ describe('Running @erc725/erc725.js tests...', () => {
{
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
nonDynamicName: 'LSP3Profile',
value: {
verification: {
method: 'keccak256(utf8)',
Expand All @@ -296,6 +301,7 @@ describe('Running @erc725/erc725.js tests...', () => {
name: 'LSP1UniversalReceiverDelegate',
key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47',
value: '0x36e4Eb6Ee168EF54B1E8e850ACBE51045214B313',
nonDynamicName: 'LSP1UniversalReceiverDelegate',
},
];

Expand Down Expand Up @@ -359,6 +365,7 @@ describe('Running @erc725/erc725.js tests...', () => {
name: 'LSP1UniversalReceiverDelegate',
key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47',
value: '0x36e4Eb6Ee168EF54B1E8e850ACBE51045214B313',
nonDynamicName: 'LSP1UniversalReceiverDelegate',
});
});
});
Expand Down Expand Up @@ -400,7 +407,9 @@ describe('Running @erc725/erc725.js tests...', () => {
]);
assert.deepStrictEqual(data[0], {
key: '0x4b80742de2bf82acb36300009139def55c73c12bcda9c44f12326686e3948634',
name: 'AddressPermissions:Permissions:9139def55c73c12bcda9c44f12326686e3948634',
name: 'AddressPermissions:Permissions:<address>',
nonDynamicName:
'AddressPermissions:Permissions:0x9139def55c73c12bcda9c44f12326686e3948634',
value:
'0x0000000000000000000000000000000000000000000000000000000000000002',
});
Expand Down Expand Up @@ -444,7 +453,9 @@ describe('Running @erc725/erc725.js tests...', () => {
]);
assert.deepStrictEqual(data[0], {
key: '0x6de85eaf5d982b4e5da000009139def55c73c12bcda9c44f12326686e3948634',
name: 'LSP4CreatorsMap:9139def55c73c12bcda9c44f12326686e3948634',
name: 'LSP4CreatorsMap:<address>',
nonDynamicName:
'LSP4CreatorsMap:0x9139def55c73c12bcda9c44f12326686e3948634',
value: ['0x24871b3d', 0],
});
});
Expand Down Expand Up @@ -472,6 +483,7 @@ describe('Running @erc725/erc725.js tests...', () => {
{
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
nonDynamicName: 'LSP3Profile',
value: {
verification: {
method: 'keccak256(utf8)',
Expand All @@ -484,6 +496,7 @@ describe('Running @erc725/erc725.js tests...', () => {
name: 'LSP1UniversalReceiverDelegate',
key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47',
value: '0x36e4Eb6Ee168EF54B1E8e850ACBE51045214B313',
nonDynamicName: 'LSP1UniversalReceiverDelegate',
},
];

Expand Down Expand Up @@ -532,6 +545,7 @@ describe('Running @erc725/erc725.js tests...', () => {
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: null,
nonDynamicName: 'LSP3Profile',
});
});

Expand All @@ -546,7 +560,7 @@ describe('Running @erc725/erc725.js tests...', () => {
'0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000035697066733a2f2f516d6245724b6833466a73415236596a73546a485a4e6d364d6344703661527438324674637639414a4a765a62640000000000000000000000',
},
{
key: '0x74ac2555c10b9349e78f0000b74a88c43bcf691bd7a851f6603cb1868f6fc147', // LSP12IssuedAssetsMap:b74a88C43BCf691bd7A851f6603cb1868f6fc147
key: '0x74ac2555c10b9349e78f0000b74a88c43bcf691bd7a851f6603cb1868f6fc147', // LSP12IssuedAssetsMap:0x0cb74a88C43BCf691bd7A851f6603cb1868f6fc147
richtera marked this conversation as resolved.
Show resolved Hide resolved
value:
'0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000141098603b193d276f5fa176cc02007b609f9dae6b000000000000000000000000',
},
Expand Down Expand Up @@ -599,16 +613,20 @@ describe('Running @erc725/erc725.js tests...', () => {
{
key: '0x48643a15ac5407a175674ab0f8c92df5ae90694dac72ebf0a058fb2599e3b06a',
name: 'MyURL',
nonDynamicName: 'MyURL',
value: 'ipfs://QmbErKh3FjsAR6YjsTjHZNm6McDp6aRt82Ftcv9AJJvZbd',
},
{
key: '0x74ac2555c10b9349e78f0000b74a88c43bcf691bd7a851f6603cb1868f6fc147',
name: 'LSP12IssuedAssetsMap:b74a88C43BCf691bd7A851f6603cb1868f6fc147',
name: 'LSP12IssuedAssetsMap:<address>',
nonDynamicName:
'LSP12IssuedAssetsMap:0xb74a88C43BCf691bd7A851f6603cb1868f6fc147',
value: '0x1098603B193d276f5fA176CC02007B609F9DAE6b',
},
{
key: '0xeafec4d89fa9619884b600005ef83ad9559033e6e941db7d7c495acdce616347',
name: 'SupportedStandards:LSP3Profile',
nonDynamicName: 'SupportedStandards:LSP3Profile',
value: '0x5ef83ad9',
},
]);
Expand Down Expand Up @@ -704,6 +722,7 @@ describe('Running @erc725/erc725.js tests...', () => {
key: testJSONURLSchema.key,
name: testJSONURLSchema.name,
value: JSON.parse(jsonString),
nonDynamicName: testJSONURLSchema.name,
});
});

Expand Down Expand Up @@ -743,7 +762,9 @@ describe('Running @erc725/erc725.js tests...', () => {
});

assert.deepStrictEqual(result, {
name: 'JSONForAddress:cafecafecafecafecafecafecafecafecafecafe',
name: 'JSONForAddress:<address>',
nonDynamicName:
'JSONForAddress:0xcafecafecafecafecafecafecafecafecafecafe',
key: '0x84b02f6e50a0a0819a4f0000cafecafecafecafecafecafecafecafecafecafe',
value: JSON.parse(jsonString),
});
Expand Down Expand Up @@ -817,7 +838,7 @@ describe('Running @erc725/erc725.js tests...', () => {
const result = await erc725.getData(
schemaElement.dynamicKeyParts
? {
keyName: schemaElement.key,
keyName: schemaElement.name,
dynamicKeyParts: schemaElement.dynamicKeyParts,
}
: schemaElement.key,
Expand All @@ -826,6 +847,7 @@ describe('Running @erc725/erc725.js tests...', () => {
name: schemaElement.name,
key: schemaElement.key,
value: schemaElement.expectedResult,
nonDynamicName: schemaElement.nonDynamicName,
});
});

Expand All @@ -838,7 +860,7 @@ describe('Running @erc725/erc725.js tests...', () => {
const result = await erc725.getData(
schemaElement.dynamicKeyParts
? {
keyName: schemaElement.key,
keyName: schemaElement.name,
dynamicKeyParts: schemaElement.dynamicKeyParts,
}
: schemaElement.key,
Expand All @@ -847,6 +869,7 @@ describe('Running @erc725/erc725.js tests...', () => {
name: schemaElement.name,
key: schemaElement.key,
value: schemaElement.expectedResult,
nonDynamicName: schemaElement.nonDynamicName,
});
});
});
Expand Down Expand Up @@ -1136,6 +1159,7 @@ describe('Running @erc725/erc725.js tests...', () => {
const result = erc725.encodeData([
{
keyName: schemaElement.name,
dynamicKeyParts: schemaElement.dynamicKeyParts,
value: schemaElement.expectedResult,
},
]);
Expand Down Expand Up @@ -1979,7 +2003,7 @@ describe('decodeMappingKey', () => {
[
{
type: 'bytes16',
value: '00000000000000000000000012345678',
value: '0x12345678000000000000000000000000',
},
],
);
Expand Down
6 changes: 3 additions & 3 deletions src/lib/decodeData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,9 @@ describe('decodeData', () => {
schemas,
);

expect(decodedData.map(({ name }) => name)).to.eql([
'MyKeyName2:aaaabbbbccccddddeeeeffff111122223333444455556666777788889999aaaa:true',
'MyDynamicKey2:cafecafecafecafecafecafecafecafecafecafe',
expect(decodedData.map(({ nonDynamicName }) => nonDynamicName)).to.eql([
'MyKeyName2:0xaaaabbbbccccddddeeeeffff111122223333444455556666777788889999aaaa:true',
'MyDynamicKey2:0xcafecafecafecafecafecafecafecafecafecafe',
'KeyTwo',
]);
});
Expand Down
7 changes: 5 additions & 2 deletions src/lib/decodeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,12 @@ export function decodeData(
}
console.error(error);
}
const { key, name, nonDynamicName } = schemaElement;
return {
key: schemaElement.key,
name: schemaElement.name,
key,
name,
...(nonDynamicName ? { nonDynamicName } : { nonDynamicName: name }),
...(dynamicKeyParts ? { dynamicKeyParts } : {}),
value: decodedValue,
};
};
Expand Down
20 changes: 13 additions & 7 deletions src/lib/decodeMappingKey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ describe('decodeDynamicKeyParts', () => {
key: {
name: 'MyKeyName:<bytes4>',
encoded:
'0x35e6950bc8d21a1699e5000000000000000000000000000000000000abcd1234',
'0x35e6950bc8d21a1699e50000abcd123400000000000000000000000000000000',
},
dynamicKeyParts: [{ type: 'bytes4', value: 'abcd1234' }],
dynamicKeyParts: [{ type: 'bytes4', value: '0xabcd1234' }],
},
{
key: {
Expand All @@ -57,7 +57,8 @@ describe('decodeDynamicKeyParts', () => {
dynamicKeyParts: [
{
type: 'bytes32',
value: 'aaaabbbbccccddddeeeeffff1111222233334444',
value:
'0xaaaabbbbccccddddeeeeffff1111222233334444000000000000000000000000',
},
],
},
Expand Down Expand Up @@ -94,10 +95,10 @@ describe('decodeDynamicKeyParts', () => {
key: {
name: 'MyKeyName:<bytes2>:<uint32>',
encoded:
'0x35e6950bc8d20000ffff000000000000000000000000000000000000f342d33d',
'0x35e6950bc8d2ffff0000000000000000000000000000000000000000f342d33d',
},
dynamicKeyParts: [
{ type: 'bytes2', value: 'ffff' },
{ type: 'bytes2', value: '0xffff' },
{ type: 'uint32', value: 4081242941 },
],
},
Expand Down Expand Up @@ -127,7 +128,8 @@ describe('decodeDynamicKeyParts', () => {
dynamicKeyParts: [
{
type: 'bytes32',
value: 'aaaabbbbccccddddeeeeffff1111222233334444',
value:
'0xaaaabbbbccccddddeeeeffff1111222233334444000000000000000000000000',
},
],
},
Expand All @@ -138,7 +140,11 @@ describe('decodeDynamicKeyParts', () => {
'0x35e6950bc8d2aaaabbbb00000000000000000000000000000000000000000001',
},
dynamicKeyParts: [
{ type: 'bytes32', value: 'aaaabbbb' },
{
type: 'bytes32',
value:
'0xaaaabbbb00000000000000000000000000000000000000000000000000000000',
},
{ type: 'bool', value: true },
],
},
Expand Down
18 changes: 8 additions & 10 deletions src/lib/decodeMappingKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @date 2022
*/

import { padLeft } from 'web3-utils';
import { padLeft, padRight } from 'web3-utils';
import { isHex } from 'web3-validator';
import { decodeValueType } from './encoder';
import { ERC725JSONSchema } from '../types/ERC725JSONSchema';
Expand All @@ -45,18 +45,16 @@ function decodeKeyPart(

let decodedKey: string | number | boolean | undefined;
const type = keyPartName.slice(1, keyPartName.length - 1);

if (type === 'bool')
if (type === 'bool') {
decodedKey = encodedKeyPart.slice(encodedKeyPart.length - 1) === '1';
else if (type.includes('uint'))
} else if (type.includes('uint'))
decodedKey = Number.parseInt(encodedKeyPart, 16);
else if (type.includes('bytes')) {
const bytesLength = Number.parseInt(type.replace('bytes', ''), 10) * 2;
const sliceFrom =
encodedKeyPart.length - bytesLength < 0
? 0
: encodedKeyPart.length - bytesLength;
decodedKey = encodedKeyPart.slice(sliceFrom);
const charLength = Number.parseInt(type.replace('bytes', ''), 10) * 2;
decodedKey = padRight(
`0x${encodedKeyPart.slice(0, charLength)}`,
charLength,
);
} else if (type === 'address') {
// this is required if the 2nd word is an address in a MappingWithGrouping
const leftPaddedAddress = padLeft(`0x${encodedKeyPart}`, 40);
Expand Down
Loading