From 143ea7cfb99c2f64a2b50c9a392ee284ed29e477 Mon Sep 17 00:00:00 2001 From: CJ42 Date: Thu, 19 Oct 2023 11:55:39 +0100 Subject: [PATCH] fix: encode LSP2 array length as 16 bytes long --- src/lib/classes/lsp8-identifiable-digital-asset.spec.ts | 1 - src/lib/classes/proxy-deployer.spec.ts | 2 +- src/lib/services/universal-profile.service.spec.ts | 7 +++---- src/lib/services/universal-profile.service.ts | 2 +- test/digital-asset.utils.ts | 2 +- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/lib/classes/lsp8-identifiable-digital-asset.spec.ts b/src/lib/classes/lsp8-identifiable-digital-asset.spec.ts index 5c9ca44f..e597b49c 100644 --- a/src/lib/classes/lsp8-identifiable-digital-asset.spec.ts +++ b/src/lib/classes/lsp8-identifiable-digital-asset.spec.ts @@ -15,7 +15,6 @@ import { lsp4DigitalAsset } from '../../../test/lsp4-digital-asset.mock'; import { JSONURL_KNOWN_HASH_FUNCTIONS } from '../helpers/config.helper'; import { ProxyDeployer } from './proxy-deployer'; -import ERC725 from '@erc725/erc725.js'; jest.setTimeout(30000); jest.useRealTimers(); diff --git a/src/lib/classes/proxy-deployer.spec.ts b/src/lib/classes/proxy-deployer.spec.ts index acc9dd9a..196a70cb 100644 --- a/src/lib/classes/proxy-deployer.spec.ts +++ b/src/lib/classes/proxy-deployer.spec.ts @@ -1,5 +1,5 @@ -import { ethers, SignerWithAddress } from 'hardhat'; import { hexlify, randomBytes } from 'ethers/lib/utils'; +import { ethers, SignerWithAddress } from 'hardhat'; import { ProxyDeployer } from './proxy-deployer'; diff --git a/src/lib/services/universal-profile.service.spec.ts b/src/lib/services/universal-profile.service.spec.ts index 4fbb286b..7cdebdc0 100644 --- a/src/lib/services/universal-profile.service.spec.ts +++ b/src/lib/services/universal-profile.service.spec.ts @@ -17,7 +17,6 @@ describe('LSP3Account Service', () => { }); describe('prepareSetDataParameters', () => { - let abiCoder; let universalProfile, universalReceiverDelegate; beforeAll(async () => { @@ -42,7 +41,7 @@ describe('LSP3Account Service', () => { // AddressPermissions[] array length should be 1 const totalPermissionsSet = valuesToSet[keysToSet.indexOf(ERC725YDataKeys.LSP6['AddressPermissions[]'].length)]; - const expectedLength = abiCoder.encode(['uint256'], [2]); + const expectedLength = ethers.utils.hexZeroPad(2, 16); expect(totalPermissionsSet).toEqual(expectedLength); // controller address should have default permissions set @@ -80,7 +79,7 @@ describe('LSP3Account Service', () => { // AddressPermissions[] array length should be 2 const totalPermissionsSet = valuesToSet[keysToSet.indexOf(ERC725YDataKeys.LSP6['AddressPermissions[]'].length)]; - const expectedLength = abiCoder.encode(['uint256'], [controllerAddresses.length + 1]); + const expectedLength = ethers.utils.hexZeroPad(controllerAddresses.length + 1, 16); expect(totalPermissionsSet).toEqual(expectedLength); for (let index = 0; index < controllerAddresses.length; index++) { @@ -121,7 +120,7 @@ describe('LSP3Account Service', () => { // AddressPermissions[] array length should be 11 (including Universal Receiver Delegate address) const totalPermissionsSet = valuesToSet[keysToSet.indexOf(ERC725YDataKeys.LSP6['AddressPermissions[]'].length)]; - const expectedLength = abiCoder.encode(['uint256'], [controllerAddresses.length + 1]); + const expectedLength = ethers.utils.hexZeroPad(controllerAddresses.length + 1, 16); expect(totalPermissionsSet).toEqual(expectedLength); for (let index = 0; index < controllerAddresses.length; index++) { diff --git a/src/lib/services/universal-profile.service.ts b/src/lib/services/universal-profile.service.ts index 3fdea990..6160084f 100644 --- a/src/lib/services/universal-profile.service.ts +++ b/src/lib/services/universal-profile.service.ts @@ -441,7 +441,7 @@ export async function prepareSetDataParameters( const valuesToSet = [ universalReceiverDelegateAddress, ERC725.encodePermissions({ SUPER_SETDATA: true, REENTRANCY: true }), - ethers.utils.defaultAbiCoder.encode(['uint256'], [controllerPermissions.length + 1]), + ethers.utils.hexZeroPad(ethers.utils.hexlify(controllerAddresses.length + 1), 16), ...controllerAddresses, ...controllerPermissions, universalReceiverDelegateAddress, diff --git a/test/digital-asset.utils.ts b/test/digital-asset.utils.ts index 8aa53b4a..dc094366 100644 --- a/test/digital-asset.utils.ts +++ b/test/digital-asset.utils.ts @@ -6,7 +6,7 @@ export async function testDeployWithSpecifiedCreators( digitalAsset: LSP7Mintable | LSP8Mintable, creators: string[] ) { - const [creatorArrayLength] = await digitalAsset.getData( + const creatorArrayLength = await digitalAsset.getData( ERC725YDataKeys.LSP4['LSP4Creators[]'].length );