Skip to content

Commit

Permalink
fix: decoding tuple when no value is fetched
Browse files Browse the repository at this point in the history
Co-authored-by: Felix Hildebrandt <fhildeb@users.noreply.github.com>
  • Loading branch information
CJ42 and fhildeb committed Jan 22, 2024
1 parent afd6885 commit 067feef
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
45 changes: 45 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,51 @@ describe('Running @erc725/erc725.js tests...', () => {
);
});
}

it.only('fetchData and return `[]` for empty tuples', async () => {
const provider = new HttpProvider(
{
returnData: allRawData.filter(
(rawData) =>
rawData.key ===
'0xd154e1e44d32870ff5ade9e8726fd06d0ed6c996f5946dabfdfd46aa6dd2ea99',
),
},
[contractVersion.interface],
);

const erc725js = new ERC725(
[
{
name: 'LSP4CreatorsMap:<address>',
key: '0x6de85eaf5d982b4e5da00000<address>',
keyType: 'Mapping',
valueType: '(bytes4,uint128)',
valueContent: '(Bytes4,Number)',
},
{
name: 'AnotherKeyWithTuple',
key: '0xe285b699bb64c38edb31f6be9fe25f8778b48b260430a16ea4d4cfd1d7ac6d38',
keyType: 'Singleton',
valueType: '(address,address)',
valueContent: '(Address,Address)',
},
],
address,
provider,
);

const result = await erc725js.fetchData([
'AnotherKeyWithTuple',
{
keyName: 'LSP4CreatorsMap:<address>',
dynamicKeyParts: '0x9139def55c73c12bcda9c44f12326686e3948634',
},
]);

assert.deepStrictEqual(result[0].value, []);
assert.deepStrictEqual(result[1].value, []);
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/lib/decodeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const decodeTupleKeyValue = (
0,
);

if (value.length !== 2 + totalBytesLength * 2) {
if (!value || value.length !== 2 + totalBytesLength * 2) {
console.error(
`Trying to decode a value: ${value} which does not match the length of the valueType: ${valueType}. Expected ${totalBytesLength} bytes.`,
);
Expand Down

0 comments on commit 067feef

Please sign in to comment.