Skip to content

Commit

Permalink
Merge pull request #448 from ERC725Alliance/feat/tuple-types
Browse files Browse the repository at this point in the history
feat: allow to pass `number` directly in array when encoding tuples
  • Loading branch information
Hugoo authored May 21, 2024
2 parents b1784ef + f6b4a9d commit 91363c4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,34 @@ describe('Running @erc725/erc725.js tests...', () => {
});
});
});

describe('for tuples', () => {
it('encode `(bytes4,uint128)`', () => {
const schema = {
name: 'LSP4CreatorsMap:<address>',
key: '0x6de85eaf5d982b4e5da00000<address>',
keyType: 'Mapping',
valueType: '(bytes4,uint128)',
valueContent: '(Bytes4,Number)',
};

const expectedEncodedValue =
'0xb3c4928f00000000000000000000000000000005';

const result = ERC725.encodeData(
[
{
keyName: 'LSP4CreatorsMap:<address>',
dynamicKeyParts: address,
value: ['0xb3c4928f', 5],
},
],
[schema],
);

assert.equal(result.values[0], expectedEncodedValue);
});
});
});

describe('Testing utility encoding & decoding functions', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/types/encodeData/JSONURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export type EncodeDataType =
| string[]
| URLDataToEncode
| boolean
| number;
| number
| (string | number)[]; // for tuples such as `(bytes4,uint128)`

export interface EncodeDataReturn {
keys: string[];
Expand Down

0 comments on commit 91363c4

Please sign in to comment.