diff --git a/src/index.test.ts b/src/index.test.ts index b8f34c85..40300993 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -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:
', + key: '0x6de85eaf5d982b4e5da00000
', + 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:
', + dynamicKeyParts: '0x9139def55c73c12bcda9c44f12326686e3948634', + }, + ]); + + assert.deepStrictEqual(result[0].value, []); + assert.deepStrictEqual(result[1].value, []); + }); }); }); diff --git a/src/lib/decodeData.ts b/src/lib/decodeData.ts index 9cbe885e..12bf00c1 100644 --- a/src/lib/decodeData.ts +++ b/src/lib/decodeData.ts @@ -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.`, );