From 099bafbfb672fad647a0d8d4d3f36a793d658c72 Mon Sep 17 00:00:00 2001 From: YamenMerhi Date: Thu, 6 Jul 2023 17:32:06 +0300 Subject: [PATCH 01/11] refactor: support getDataBatch in ERC725Y --- src/constants/constants.ts | 18 +++++++++++- src/provider/providerWrapper.ts | 52 +++++++++++++++++++++++++++++++++ src/types/Method.ts | 1 + 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/constants/constants.ts b/src/constants/constants.ts index ad2c1ea0..76ffae17 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -34,9 +34,17 @@ export const ERC725Y_INTERFACE_IDS = { // - getData(bytes32[]) // - setData(bytes32[],bytes[]) '3.0': '0x714df77c', + // version 5.0.0 removed function overloading + // interface functions: + // - getData(bytes32) + // - setData(bytes32,bytes) + // - getDataBatch(bytes32[]) + // - setDataBatch(bytes32[],bytes[]) + '5.0': '0x629aa694', }; export enum ERC725_VERSION { + ERC725_BATCH = 'ERC725_BATCH', // https://github.com/ERC725Alliance/ERC725/pull/209 ERC725 = 'ERC725', // https://github.com/ERC725Alliance/ERC725/commit/cca7f98cdf243f1ebf1c0a3ae89b1e46931481b0 ERC725_LEGACY = 'ERC725_LEGACY', NOT_ERC725 = 'NOT_ERC725', @@ -52,13 +60,21 @@ export const METHODS: Record = { returnEncoding: Encoding.BYTES, }, [Method.GET_DATA]: { - // https://github.com/ERC725Alliance/erc725/blob/main/docs/ERC-725.md#erc725y + // https://github.com/ERC725Alliance/ERC725/blob/v4.0.0/docs/ERC-725.md#erc725y sig: '0x4e3e6e9c', gas: numberToHex(2000000), gasPrice: numberToHex(100000000), value: numberToHex(0), returnEncoding: Encoding.BYTES_ARRAY, }, + [Method.GET_DATA_BATCH]: { + // https://github.com/ERC725Alliance/ERC725/blob/v5.1.0/docs/ERC-725.md#erc725y + sig: '0xdedff9c6', + gas: numberToHex(2000000), + gasPrice: numberToHex(100000000), + value: numberToHex(0), + returnEncoding: Encoding.BYTES_ARRAY, + }, [Method.OWNER]: { sig: '0x8da5cb5b', gas: numberToHex(2000000), diff --git a/src/provider/providerWrapper.ts b/src/provider/providerWrapper.ts index 09ececdd..7b2d5d86 100644 --- a/src/provider/providerWrapper.ts +++ b/src/provider/providerWrapper.ts @@ -61,6 +61,15 @@ export class ProviderWrapper { } async getErc725YVersion(address: string): Promise { + const isErc725YBatch = await this.supportsInterface( + address, + ERC725Y_INTERFACE_IDS['5.0'], + ); + + if (isErc725YBatch) { + return ERC725_VERSION.ERC725_BATCH; + } + const isErc725Y = await this.supportsInterface( address, ERC725Y_INTERFACE_IDS['3.0'], @@ -197,6 +206,8 @@ export class ProviderWrapper { } switch (erc725Version) { + case ERC725_VERSION.ERC725_BATCH: + return this._getAllDataBatch(address, keyHashes); case ERC725_VERSION.ERC725: return this._getAllData(address, keyHashes); case ERC725_VERSION.ERC725_LEGACY: @@ -206,6 +217,47 @@ export class ProviderWrapper { } } + private async _getAllDataBatch( + address: string, + keyHashes: string[], + ): Promise { + if (this.type === ProviderTypes.ETHEREUM) { + const encodedResults = await this.callContract( + constructJSONRPC( + address, + Method.GET_DATA_BATCH, + abiCoder.encodeParameter('bytes32[]', keyHashes), + ), + ); + + const decodedValues = decodeResult(Method.GET_DATA_BATCH, encodedResults); + + return keyHashes.map((keyHash, index) => ({ + key: keyHash, + value: decodedValues ? decodedValues[index] : decodedValues, + })); + } + + const payload: JsonRpc[] = [ + constructJSONRPC( + address, + Method.GET_DATA_BATCH, + abiCoder.encodeParameter('bytes32[]', keyHashes), + ), + ]; + + const results: any = await this.callContract(payload); + const decodedValues = decodeResult( + Method.GET_DATA_BATCH, + results[0].result, + ); + + return keyHashes.map((key, index) => ({ + key, + value: decodedValues ? decodedValues[index] : decodedValues, + })); + } + private async _getAllData( address: string, keyHashes: string[], diff --git a/src/types/Method.ts b/src/types/Method.ts index 738df487..ddb274d4 100644 --- a/src/types/Method.ts +++ b/src/types/Method.ts @@ -1,6 +1,7 @@ export enum Method { GET_DATA_LEGACY = 'getDataLegacy', // For legacy ERC725 with interface id: 0x2bd57b73 NOTE: I had to add Legacy at the end so the map keys stays unique GET_DATA = 'getData', // For latest ERC725 with interface id: 0x5a988c0f + GET_DATA_BATCH = 'getDataBatch', OWNER = 'owner', SUPPORTS_INTERFACE = 'supportsInterface', // https://eips.ethereum.org/EIPS/eip-165 IS_VALID_SIGNATURE = 'isValidSignature', // https://eips.ethereum.org/EIPS/eip-1271 From 51f2f5804164238275ff1b3a7ac6da45f642ef37 Mon Sep 17 00:00:00 2001 From: YamenMerhi Date: Thu, 6 Jul 2023 17:32:18 +0300 Subject: [PATCH 02/11] test: add e2e tests for luksoTestnet --- src/index.test.ts | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/index.test.ts b/src/index.test.ts index 8b07ade2..a2125625 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -304,6 +304,55 @@ describe('Running @erc725/erc725.js tests...', () => { }); }); + describe('Getting data (using new getDataBatch) in schema by provider [e2e] - luksoTestnet', () => { + const web3 = new Web3('https://rpc.testnet.lukso.network'); + const ERC725_BATCH_CONTRACT_ADDRESS = + '0x4b30900F119E11D2A8CAe18176c4f9840E586Cc4'; + + const e2eSchema: any = [ + { + name: 'LSP3Profile', + key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', + keyType: 'Singleton', + valueContent: 'JSONURL', + valueType: 'bytes', + }, + { + name: 'LSP1UniversalReceiverDelegate', + key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47', + keyType: 'Singleton', + valueContent: 'Address', + valueType: 'address', + }, + ]; + + const e2eResults = [ + { + name: 'LSP3Profile', + key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', + value: { + hashFunction: 'keccak256(utf8)', + hash: '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3', + url: 'ipfs://QmecrGejUQVXpW4zS948pNvcnQrJ1KiAoM6bdfrVcWZsn5', + }, + }, + { + name: 'LSP1UniversalReceiverDelegate', + key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47', + value: '0x36e4Eb6Ee168EF54B1E8e850ACBE51045214B313', + }, + ]; + it('with web3.currentProvider [ERC725Y_BATCH]', async () => { + const erc725 = new ERC725( + e2eSchema, + ERC725_BATCH_CONTRACT_ADDRESS, + web3.currentProvider, + ); + const result = await erc725.getData(); + assert.deepStrictEqual(result, e2eResults); + }); + }); + describe('Get/fetch edge cases [mock]', () => { it('should return null if the JSONURL is not set [fetchData]', async () => { const provider = new HttpProvider( From 94f8c59163bedd6392651546f9815289d345c974 Mon Sep 17 00:00:00 2001 From: Yamen Merhi Date: Tue, 11 Jul 2023 13:11:20 +0300 Subject: [PATCH 03/11] Update index.test.ts --- src/index.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.test.ts b/src/index.test.ts index a2125625..911197a8 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -342,6 +342,7 @@ describe('Running @erc725/erc725.js tests...', () => { value: '0x36e4Eb6Ee168EF54B1E8e850ACBE51045214B313', }, ]; + it('with web3.currentProvider [ERC725Y_BATCH]', async () => { const erc725 = new ERC725( e2eSchema, From cef2dce864b9f15449660f0cd0bfc45bc0951d9c Mon Sep 17 00:00:00 2001 From: Yamen Merhi Date: Thu, 13 Jul 2023 19:55:40 +0300 Subject: [PATCH 04/11] Add comments about version 4 --- src/constants/constants.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/constants/constants.ts b/src/constants/constants.ts index 76ffae17..420f0aa5 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -34,6 +34,7 @@ export const ERC725Y_INTERFACE_IDS = { // - getData(bytes32[]) // - setData(bytes32[],bytes[]) '3.0': '0x714df77c', + // InterfaceId of version 3 == interfaceId of version 4 // version 5.0.0 removed function overloading // interface functions: // - getData(bytes32) From ad34165dd7e33cc994ba687b351bb8927f7978ac Mon Sep 17 00:00:00 2001 From: YamenMerhi Date: Fri, 14 Jul 2023 11:16:20 +0300 Subject: [PATCH 05/11] chore: rename by version instead of feature --- src/constants/constants.ts | 9 ++++++--- src/index.test.ts | 4 ++-- src/provider/providerWrapper.ts | 23 ++++++++++++----------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/constants/constants.ts b/src/constants/constants.ts index 420f0aa5..3f1b511d 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -45,10 +45,13 @@ export const ERC725Y_INTERFACE_IDS = { }; export enum ERC725_VERSION { - ERC725_BATCH = 'ERC725_BATCH', // https://github.com/ERC725Alliance/ERC725/pull/209 - ERC725 = 'ERC725', // https://github.com/ERC725Alliance/ERC725/commit/cca7f98cdf243f1ebf1c0a3ae89b1e46931481b0 - ERC725_LEGACY = 'ERC725_LEGACY', NOT_ERC725 = 'NOT_ERC725', + // The ERC725Y_LEGACY version uses getData(bytes32) function + ERC725_LEGACY = 'ERC725_LEGACY', + // The ERC725_v2 version uses getData(bytes32[]) function, as well as v3 and v4 + ERC725_v2 = 'ERC725', // https://github.com/ERC725Alliance/ERC725/releases/tag/v2.2.0 + // The ERC725_v5 version uses getDataBatch(bytes32[]) function + ERC725_v5 = 'ERC725_v5', // https://github.com/ERC725Alliance/ERC725/releases/tag/v5.0.0 } export const METHODS: Record = { diff --git a/src/index.test.ts b/src/index.test.ts index 911197a8..ca2c64d4 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -306,7 +306,7 @@ describe('Running @erc725/erc725.js tests...', () => { describe('Getting data (using new getDataBatch) in schema by provider [e2e] - luksoTestnet', () => { const web3 = new Web3('https://rpc.testnet.lukso.network'); - const ERC725_BATCH_CONTRACT_ADDRESS = + const ERC725_V5_CONTRACT_ADDRESS = '0x4b30900F119E11D2A8CAe18176c4f9840E586Cc4'; const e2eSchema: any = [ @@ -346,7 +346,7 @@ describe('Running @erc725/erc725.js tests...', () => { it('with web3.currentProvider [ERC725Y_BATCH]', async () => { const erc725 = new ERC725( e2eSchema, - ERC725_BATCH_CONTRACT_ADDRESS, + ERC725_V5_CONTRACT_ADDRESS, web3.currentProvider, ); const result = await erc725.getData(); diff --git a/src/provider/providerWrapper.ts b/src/provider/providerWrapper.ts index 7b2d5d86..d097fae5 100644 --- a/src/provider/providerWrapper.ts +++ b/src/provider/providerWrapper.ts @@ -61,31 +61,32 @@ export class ProviderWrapper { } async getErc725YVersion(address: string): Promise { - const isErc725YBatch = await this.supportsInterface( + const isErc725Yv5 = await this.supportsInterface( address, ERC725Y_INTERFACE_IDS['5.0'], ); - if (isErc725YBatch) { - return ERC725_VERSION.ERC725_BATCH; + if (isErc725Yv5) { + return ERC725_VERSION.ERC725_v5; } - const isErc725Y = await this.supportsInterface( + const isErc725Yv3 = await this.supportsInterface( address, ERC725Y_INTERFACE_IDS['3.0'], ); - if (isErc725Y) { - return ERC725_VERSION.ERC725; + // The version 3 of the package can use the getData function from v2, still compatible + if (isErc725Yv3) { + return ERC725_VERSION.ERC725_v2; } - const isErc725Yv200 = await this.supportsInterface( + const isErc725Yv2 = await this.supportsInterface( address, ERC725Y_INTERFACE_IDS['2.0'], ); - if (isErc725Yv200) { - return ERC725_VERSION.ERC725; + if (isErc725Yv2) { + return ERC725_VERSION.ERC725_v2; } // v0.2.0 and v0.6.0 have the same function signatures for getData, only versions before v0.2.0 requires a different call @@ -206,9 +207,9 @@ export class ProviderWrapper { } switch (erc725Version) { - case ERC725_VERSION.ERC725_BATCH: + case ERC725_VERSION.ERC725_v5: return this._getAllDataBatch(address, keyHashes); - case ERC725_VERSION.ERC725: + case ERC725_VERSION.ERC725_v2: return this._getAllData(address, keyHashes); case ERC725_VERSION.ERC725_LEGACY: return this._getAllDataLegacy(address, keyHashes); From ee8445b1b42236128b0689824c49e49f45a0c996 Mon Sep 17 00:00:00 2001 From: YamenMerhi Date: Fri, 14 Jul 2023 11:20:00 +0300 Subject: [PATCH 06/11] refactor: refactor getAllData into generic function --- src/provider/providerWrapper.ts | 60 +++++++-------------------------- 1 file changed, 12 insertions(+), 48 deletions(-) diff --git a/src/provider/providerWrapper.ts b/src/provider/providerWrapper.ts index d097fae5..a3ae58eb 100644 --- a/src/provider/providerWrapper.ts +++ b/src/provider/providerWrapper.ts @@ -208,9 +208,13 @@ export class ProviderWrapper { switch (erc725Version) { case ERC725_VERSION.ERC725_v5: - return this._getAllDataBatch(address, keyHashes); + return this._getAllDataGeneric( + address, + keyHashes, + Method.GET_DATA_BATCH, + ); case ERC725_VERSION.ERC725_v2: - return this._getAllData(address, keyHashes); + return this._getAllDataGeneric(address, keyHashes, Method.GET_DATA); case ERC725_VERSION.ERC725_LEGACY: return this._getAllDataLegacy(address, keyHashes); default: @@ -218,61 +222,21 @@ export class ProviderWrapper { } } - private async _getAllDataBatch( - address: string, - keyHashes: string[], - ): Promise { - if (this.type === ProviderTypes.ETHEREUM) { - const encodedResults = await this.callContract( - constructJSONRPC( - address, - Method.GET_DATA_BATCH, - abiCoder.encodeParameter('bytes32[]', keyHashes), - ), - ); - - const decodedValues = decodeResult(Method.GET_DATA_BATCH, encodedResults); - - return keyHashes.map((keyHash, index) => ({ - key: keyHash, - value: decodedValues ? decodedValues[index] : decodedValues, - })); - } - - const payload: JsonRpc[] = [ - constructJSONRPC( - address, - Method.GET_DATA_BATCH, - abiCoder.encodeParameter('bytes32[]', keyHashes), - ), - ]; - - const results: any = await this.callContract(payload); - const decodedValues = decodeResult( - Method.GET_DATA_BATCH, - results[0].result, - ); - - return keyHashes.map((key, index) => ({ - key, - value: decodedValues ? decodedValues[index] : decodedValues, - })); - } - - private async _getAllData( + private async _getAllDataGeneric( address: string, keyHashes: string[], + method: Method, ): Promise { if (this.type === ProviderTypes.ETHEREUM) { const encodedResults = await this.callContract( constructJSONRPC( address, - Method.GET_DATA, + method, abiCoder.encodeParameter('bytes32[]', keyHashes), ), ); - const decodedValues = decodeResult(Method.GET_DATA, encodedResults); + const decodedValues = decodeResult(method, encodedResults); return keyHashes.map((keyHash, index) => ({ key: keyHash, @@ -283,13 +247,13 @@ export class ProviderWrapper { const payload: JsonRpc[] = [ constructJSONRPC( address, - Method.GET_DATA, + method, abiCoder.encodeParameter('bytes32[]', keyHashes), ), ]; const results: any = await this.callContract(payload); - const decodedValues = decodeResult(Method.GET_DATA, results[0].result); + const decodedValues = decodeResult(method, results[0].result); return keyHashes.map((key, index) => ({ key, From 3892ade1bc1a3b19ffa7ca9026785d72872bd688 Mon Sep 17 00:00:00 2001 From: YamenMerhi Date: Fri, 14 Jul 2023 11:44:59 +0300 Subject: [PATCH 07/11] test: add types for schema --- src/index.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index ca2c64d4..98dfe3e3 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -249,7 +249,7 @@ describe('Running @erc725/erc725.js tests...', () => { ]); }); - const e2eSchema: any = [ + const e2eSchema: ERC725JSONSchema[] = [ { name: 'LSP3Profile', key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', @@ -309,7 +309,7 @@ describe('Running @erc725/erc725.js tests...', () => { const ERC725_V5_CONTRACT_ADDRESS = '0x4b30900F119E11D2A8CAe18176c4f9840E586Cc4'; - const e2eSchema: any = [ + const e2eSchema: ERC725JSONSchema[] = [ { name: 'LSP3Profile', key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', From 0f611ede9fd3350e1a9db56a36bb5f6b46a8d563 Mon Sep 17 00:00:00 2001 From: YamenMerhi Date: Fri, 14 Jul 2023 12:09:30 +0300 Subject: [PATCH 08/11] chore: resolve linter --- src/constants/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants/constants.ts b/src/constants/constants.ts index 3f1b511d..9de170c7 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -46,7 +46,7 @@ export const ERC725Y_INTERFACE_IDS = { export enum ERC725_VERSION { NOT_ERC725 = 'NOT_ERC725', - // The ERC725Y_LEGACY version uses getData(bytes32) function + // The ERC725Y_LEGACY version uses getData(bytes32) function ERC725_LEGACY = 'ERC725_LEGACY', // The ERC725_v2 version uses getData(bytes32[]) function, as well as v3 and v4 ERC725_v2 = 'ERC725', // https://github.com/ERC725Alliance/ERC725/releases/tag/v2.2.0 From 5e265b489a40ce11a835b18967ae851a7a079c7a Mon Sep 17 00:00:00 2001 From: YamenMerhi Date: Fri, 14 Jul 2023 12:09:41 +0300 Subject: [PATCH 09/11] test: add test cases using HttpProvider --- src/index.test.ts | 122 ++++++++++++++++++++++++++++-------------- test/mockProviders.ts | 2 + 2 files changed, 83 insertions(+), 41 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index 98dfe3e3..054f1b56 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -304,53 +304,93 @@ describe('Running @erc725/erc725.js tests...', () => { }); }); - describe('Getting data (using new getDataBatch) in schema by provider [e2e] - luksoTestnet', () => { - const web3 = new Web3('https://rpc.testnet.lukso.network'); + describe('Getting data (using new getDataBatch) in schema', () => { const ERC725_V5_CONTRACT_ADDRESS = '0x4b30900F119E11D2A8CAe18176c4f9840E586Cc4'; + const web3 = new Web3('https://rpc.testnet.lukso.network'); - const e2eSchema: ERC725JSONSchema[] = [ - { - name: 'LSP3Profile', - key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', - keyType: 'Singleton', - valueContent: 'JSONURL', - valueType: 'bytes', - }, - { - name: 'LSP1UniversalReceiverDelegate', - key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47', - keyType: 'Singleton', - valueContent: 'Address', - valueType: 'address', - }, - ]; + describe('By HttpProvider', () => { + const provider = new HttpProvider( + { + returnData: [ + { + key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47', + value: + '0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001436e4Eb6Ee168EF54B1E8e850ACBE51045214B313000000000000000000000000', + }, + ], + }, + [ERC725Y_INTERFACE_IDS['5.0']], + ); - const e2eResults = [ - { - name: 'LSP3Profile', - key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', - value: { - hashFunction: 'keccak256(utf8)', - hash: '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3', - url: 'ipfs://QmecrGejUQVXpW4zS948pNvcnQrJ1KiAoM6bdfrVcWZsn5', + it('with http provider [ERC725Y_BATCH]', async () => { + const erc725 = new ERC725( + [ + { + name: 'LSP1UniversalReceiverDelegate', + key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47', + keyType: 'Singleton', + valueContent: 'Address', + valueType: 'address', + }, + ], + '0x24464DbA7e7781a21eD86133Ebe88Eb9C0762620', // result is mocked so we can use any address + provider, + ); + + const [result] = await erc725.getData(); + assert.deepStrictEqual(result, { + name: 'LSP1UniversalReceiverDelegate', + key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47', + value: '0x36e4Eb6Ee168EF54B1E8e850ACBE51045214B313', + }); + }); + }); + + describe('By provider [e2e] - luksoTestnet', () => { + const e2eSchema: ERC725JSONSchema[] = [ + { + name: 'LSP3Profile', + key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', + keyType: 'Singleton', + valueContent: 'JSONURL', + valueType: 'bytes', }, - }, - { - name: 'LSP1UniversalReceiverDelegate', - key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47', - value: '0x36e4Eb6Ee168EF54B1E8e850ACBE51045214B313', - }, - ]; + { + name: 'LSP1UniversalReceiverDelegate', + key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47', + keyType: 'Singleton', + valueContent: 'Address', + valueType: 'address', + }, + ]; - it('with web3.currentProvider [ERC725Y_BATCH]', async () => { - const erc725 = new ERC725( - e2eSchema, - ERC725_V5_CONTRACT_ADDRESS, - web3.currentProvider, - ); - const result = await erc725.getData(); - assert.deepStrictEqual(result, e2eResults); + const e2eResults = [ + { + name: 'LSP3Profile', + key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', + value: { + hashFunction: 'keccak256(utf8)', + hash: '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3', + url: 'ipfs://QmecrGejUQVXpW4zS948pNvcnQrJ1KiAoM6bdfrVcWZsn5', + }, + }, + { + name: 'LSP1UniversalReceiverDelegate', + key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47', + value: '0x36e4Eb6Ee168EF54B1E8e850ACBE51045214B313', + }, + ]; + + it('with web3.currentProvider [ERC725Y_BATCH]', async () => { + const erc725 = new ERC725( + e2eSchema, + ERC725_V5_CONTRACT_ADDRESS, + web3.currentProvider, + ); + const result = await erc725.getData(); + assert.deepStrictEqual(result, e2eResults); + }); }); }); diff --git a/test/mockProviders.ts b/test/mockProviders.ts index 70cf2a24..c57e725b 100644 --- a/test/mockProviders.ts +++ b/test/mockProviders.ts @@ -85,6 +85,7 @@ export class HttpProvider { }); break; } + case METHODS[Method.GET_DATA_BATCH].sig: case METHODS[Method.GET_DATA].sig: // The new ERC725Y allows requesting multiple items in one call // getData([A]), getData([A, B, C])... @@ -147,6 +148,7 @@ export class HttpProvider { result = foundResult ? foundResult.value : '0x'; } break; + case METHODS[Method.GET_DATA_BATCH].sig: case METHODS[Method.GET_DATA].sig: { const keyParam = '0x' + payload.params[0].data.slice(138); From 55a08aa93c086b909441ed850743f194a1b84a9c Mon Sep 17 00:00:00 2001 From: YamenMerhi Date: Fri, 14 Jul 2023 12:17:54 +0300 Subject: [PATCH 10/11] chore: missing - rename ERC725 to ERC725_v2 --- src/constants/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants/constants.ts b/src/constants/constants.ts index 9de170c7..f35842f5 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -49,7 +49,7 @@ export enum ERC725_VERSION { // The ERC725Y_LEGACY version uses getData(bytes32) function ERC725_LEGACY = 'ERC725_LEGACY', // The ERC725_v2 version uses getData(bytes32[]) function, as well as v3 and v4 - ERC725_v2 = 'ERC725', // https://github.com/ERC725Alliance/ERC725/releases/tag/v2.2.0 + ERC725_v2 = 'ERC725_v2', // https://github.com/ERC725Alliance/ERC725/releases/tag/v2.2.0 // The ERC725_v5 version uses getDataBatch(bytes32[]) function ERC725_v5 = 'ERC725_v5', // https://github.com/ERC725Alliance/ERC725/releases/tag/v5.0.0 } From 2fd0a8c0686faa035bcbd8e9c1a83ca32ee898af Mon Sep 17 00:00:00 2001 From: YamenMerhi Date: Fri, 14 Jul 2023 17:12:41 +0300 Subject: [PATCH 11/11] refactor: apply type for method --- src/provider/providerWrapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/provider/providerWrapper.ts b/src/provider/providerWrapper.ts index a3ae58eb..3f7026db 100644 --- a/src/provider/providerWrapper.ts +++ b/src/provider/providerWrapper.ts @@ -225,7 +225,7 @@ export class ProviderWrapper { private async _getAllDataGeneric( address: string, keyHashes: string[], - method: Method, + method: Method.GET_DATA | Method.GET_DATA_BATCH, ): Promise { if (this.type === ProviderTypes.ETHEREUM) { const encodedResults = await this.callContract(