From d4fa3cb66802f71f0fda2021b5f30e2b4cbbf74f Mon Sep 17 00:00:00 2001 From: CJ42 Date: Thu, 29 Feb 2024 05:59:12 -0700 Subject: [PATCH] chore: import only ethers methods used + address review comments --- .gitignore | 4 +- dodoc/config.ts | 10 +- packages/lsp0-contracts/hardhat.config.ts | 2 +- packages/lsp1-contracts/hardhat.config.ts | 2 +- packages/lsp10-contracts/hardhat.config.ts | 2 +- packages/lsp12-contracts/hardhat.config.ts | 2 +- packages/lsp14-contracts/hardhat.config.ts | 2 +- packages/lsp16-contracts/hardhat.config.ts | 2 +- packages/lsp17-contracts/hardhat.config.ts | 2 +- .../hardhat.config.ts | 2 +- .../lsp1delegate-contracts/hardhat.config.ts | 2 +- packages/lsp2-contracts/hardhat.config.ts | 2 +- packages/lsp20-contracts/hardhat.config.ts | 2 +- packages/lsp23-contracts/hardhat.config.ts | 2 +- packages/lsp25-contracts/hardhat.config.ts | 2 +- packages/lsp3-contracts/hardhat.config.ts | 2 +- packages/lsp4-contracts/hardhat.config.ts | 2 +- packages/lsp5-contracts/hardhat.config.ts | 2 +- packages/lsp6-contracts/hardhat.config.ts | 2 +- packages/lsp7-contracts/hardhat.config.ts | 2 +- packages/lsp8-contracts/hardhat.config.ts | 2 +- packages/lsp9-contracts/hardhat.config.ts | 2 +- .../hardhat.config.ts | 2 +- scripts/ci/docs-generate.ts | 4 +- template/hardhat.config.ts | 2 +- tests/LSP17Extensions/helpers/UserOp.ts | 30 +- .../LSP1UniversalReceiver.behaviour.ts | 6 +- .../SetData/AllowedERC725YDataKeys.test.ts | 391 +++++++++--------- .../Interactions/PermissionStaticCall.test.ts | 24 +- tests/Reentrancy/LSP6/LSP6Reentrancy.test.ts | 45 +- ...gleExecuteToSingleExecuteRelayCall.test.ts | 15 +- tests/utils/helpers.ts | 53 ++- tests/utils/tokens.ts | 4 +- 33 files changed, 314 insertions(+), 316 deletions(-) diff --git a/.gitignore b/.gitignore index b9e42798d..9f29c4817 100644 --- a/.gitignore +++ b/.gitignore @@ -135,9 +135,7 @@ forge-cache/ gas_benchmark.md # Exclude build output folders -/common -/module -/contracts.ts +/**/contracts.ts /devdocs /userdocs diff --git a/dodoc/config.ts b/dodoc/config.ts index 795fdab4f..0d0bec201 100644 --- a/dodoc/config.ts +++ b/dodoc/config.ts @@ -1,4 +1,4 @@ -import { ethers } from 'ethers'; +import { keccak256, toUtf8Bytes } from 'ethers'; import { HelperContent } from 'squirrelly/dist/types/containers'; export const dodocConfig = { @@ -331,9 +331,7 @@ const generateAdditionalMethodInfo = (contract: string, code: string) => { ) { infoBlock += `- Function signature: \`${formatedCode}\`\n` + - `- Function selector: \`${ethers - .keccak256(ethers.toUtf8Bytes(formatedCode)) - .substring(0, 10)}\``; + `- Function selector: \`${keccak256(toUtf8Bytes(formatedCode)).substring(0, 10)}\``; } return infoBlock; @@ -350,7 +348,7 @@ const generateAdditionalEventInfo = (contract: string, code: string) => { .toLowerCase()})\n` + `- Solidity implementation: [\`${contract}.sol\`](${contractLink})\n` + `- Event signature: \`${formatedCode}\`\n` + - `- Event topic hash: \`${ethers.keccak256(ethers.toUtf8Bytes(formatedCode))}\`` + `- Event topic hash: \`${keccak256(toUtf8Bytes(formatedCode))}\`` ); }; @@ -365,7 +363,7 @@ const generateAdditionalErrorInfo = (contract: string, code: string) => { .toLowerCase()})\n` + `- Solidity implementation: [\`${contract}.sol\`](${contractLink})\n` + `- Error signature: \`${formatedCode}\`\n` + - `- Error hash: \`${ethers.keccak256(ethers.toUtf8Bytes(formatedCode)).substring(0, 10)}\`` + `- Error hash: \`${keccak256(toUtf8Bytes(formatedCode)).substring(0, 10)}\`` ); }; diff --git a/packages/lsp0-contracts/hardhat.config.ts b/packages/lsp0-contracts/hardhat.config.ts index 3abbdc450..722f3e905 100644 --- a/packages/lsp0-contracts/hardhat.config.ts +++ b/packages/lsp0-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/lsp1-contracts/hardhat.config.ts b/packages/lsp1-contracts/hardhat.config.ts index 61d817cdb..1f9e172b9 100755 --- a/packages/lsp1-contracts/hardhat.config.ts +++ b/packages/lsp1-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/lsp10-contracts/hardhat.config.ts b/packages/lsp10-contracts/hardhat.config.ts index 61d817cdb..1f9e172b9 100755 --- a/packages/lsp10-contracts/hardhat.config.ts +++ b/packages/lsp10-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/lsp12-contracts/hardhat.config.ts b/packages/lsp12-contracts/hardhat.config.ts index 61d817cdb..1f9e172b9 100644 --- a/packages/lsp12-contracts/hardhat.config.ts +++ b/packages/lsp12-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/lsp14-contracts/hardhat.config.ts b/packages/lsp14-contracts/hardhat.config.ts index 0dbbcd62d..4e12de17e 100755 --- a/packages/lsp14-contracts/hardhat.config.ts +++ b/packages/lsp14-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/lsp16-contracts/hardhat.config.ts b/packages/lsp16-contracts/hardhat.config.ts index 4dd6b3a54..6a0df5c2a 100644 --- a/packages/lsp16-contracts/hardhat.config.ts +++ b/packages/lsp16-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/lsp17-contracts/hardhat.config.ts b/packages/lsp17-contracts/hardhat.config.ts index 61d817cdb..1f9e172b9 100644 --- a/packages/lsp17-contracts/hardhat.config.ts +++ b/packages/lsp17-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/lsp17contractextension-contracts/hardhat.config.ts b/packages/lsp17contractextension-contracts/hardhat.config.ts index 61d817cdb..1f9e172b9 100644 --- a/packages/lsp17contractextension-contracts/hardhat.config.ts +++ b/packages/lsp17contractextension-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/lsp1delegate-contracts/hardhat.config.ts b/packages/lsp1delegate-contracts/hardhat.config.ts index 7135783f0..515203eae 100644 --- a/packages/lsp1delegate-contracts/hardhat.config.ts +++ b/packages/lsp1delegate-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/lsp2-contracts/hardhat.config.ts b/packages/lsp2-contracts/hardhat.config.ts index 61d817cdb..1f9e172b9 100755 --- a/packages/lsp2-contracts/hardhat.config.ts +++ b/packages/lsp2-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/lsp20-contracts/hardhat.config.ts b/packages/lsp20-contracts/hardhat.config.ts index 61d817cdb..1f9e172b9 100755 --- a/packages/lsp20-contracts/hardhat.config.ts +++ b/packages/lsp20-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/lsp23-contracts/hardhat.config.ts b/packages/lsp23-contracts/hardhat.config.ts index bd647b8b8..8377906b9 100644 --- a/packages/lsp23-contracts/hardhat.config.ts +++ b/packages/lsp23-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/lsp25-contracts/hardhat.config.ts b/packages/lsp25-contracts/hardhat.config.ts index 61d817cdb..1f9e172b9 100644 --- a/packages/lsp25-contracts/hardhat.config.ts +++ b/packages/lsp25-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/lsp3-contracts/hardhat.config.ts b/packages/lsp3-contracts/hardhat.config.ts index 61d817cdb..1f9e172b9 100644 --- a/packages/lsp3-contracts/hardhat.config.ts +++ b/packages/lsp3-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/lsp4-contracts/hardhat.config.ts b/packages/lsp4-contracts/hardhat.config.ts index 61d817cdb..1f9e172b9 100644 --- a/packages/lsp4-contracts/hardhat.config.ts +++ b/packages/lsp4-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/lsp5-contracts/hardhat.config.ts b/packages/lsp5-contracts/hardhat.config.ts index 61d817cdb..1f9e172b9 100644 --- a/packages/lsp5-contracts/hardhat.config.ts +++ b/packages/lsp5-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/lsp6-contracts/hardhat.config.ts b/packages/lsp6-contracts/hardhat.config.ts index 61d817cdb..1f9e172b9 100644 --- a/packages/lsp6-contracts/hardhat.config.ts +++ b/packages/lsp6-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/lsp7-contracts/hardhat.config.ts b/packages/lsp7-contracts/hardhat.config.ts index 61d817cdb..1f9e172b9 100644 --- a/packages/lsp7-contracts/hardhat.config.ts +++ b/packages/lsp7-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/lsp8-contracts/hardhat.config.ts b/packages/lsp8-contracts/hardhat.config.ts index 61d817cdb..1f9e172b9 100644 --- a/packages/lsp8-contracts/hardhat.config.ts +++ b/packages/lsp8-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/lsp9-contracts/hardhat.config.ts b/packages/lsp9-contracts/hardhat.config.ts index 61d817cdb..1f9e172b9 100644 --- a/packages/lsp9-contracts/hardhat.config.ts +++ b/packages/lsp9-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/packages/universalprofile-contracts/hardhat.config.ts b/packages/universalprofile-contracts/hardhat.config.ts index 61d817cdb..1f9e172b9 100644 --- a/packages/universalprofile-contracts/hardhat.config.ts +++ b/packages/universalprofile-contracts/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/scripts/ci/docs-generate.ts b/scripts/ci/docs-generate.ts index d2bb95c51..f736a607e 100644 --- a/scripts/ci/docs-generate.ts +++ b/scripts/ci/docs-generate.ts @@ -2,7 +2,7 @@ import fs from 'fs'; import path from 'path'; import { task } from 'hardhat/config'; import { TASK_COMPILE } from 'hardhat/builtin-tasks/task-names'; -import { ethers } from 'ethers'; +import { keccak256, toUtf8Bytes } from 'ethers'; import pluralize from 'pluralize'; import { mkdir, rm, stat, writeFile } from 'fs/promises'; import { CompilerOutputContract } from 'hardhat/types'; @@ -239,7 +239,7 @@ task('ts-gen', 'Generate NatSpec documentation automatically on compilation') } = allMembers; for (const [sig, member] of Object.entries(allMembers)) { - const hash = ethers.keccak256(ethers.toUtf8Bytes(sig)); + const hash = keccak256(toUtf8Bytes(sig)); member.hash = member.type === 'event' ? hash : hash.slice(0, 10); } diff --git a/template/hardhat.config.ts b/template/hardhat.config.ts index 61d817cdb..1f9e172b9 100644 --- a/template/hardhat.config.ts +++ b/template/hardhat.config.ts @@ -16,7 +16,7 @@ import { resolve } from 'path'; import '@nomicfoundation/hardhat-toolbox'; // additional hardhat plugins -// import 'hardhat-packager'; +import 'hardhat-packager'; import 'hardhat-contract-sizer'; import 'hardhat-deploy'; diff --git a/tests/LSP17Extensions/helpers/UserOp.ts b/tests/LSP17Extensions/helpers/UserOp.ts index 28eb97ca2..428445043 100644 --- a/tests/LSP17Extensions/helpers/UserOp.ts +++ b/tests/LSP17Extensions/helpers/UserOp.ts @@ -1,10 +1,19 @@ -import { getBytes, dataSlice, keccak256, BytesLike } from 'ethers'; +import { + getBytes, + dataSlice, + keccak256, + BytesLike, + toBigInt, + toBeHex, + hexlify, + toNumber, +} from 'ethers'; import { Wallet } from 'ethers'; import { AddressZero, callDataCost } from './utils'; import { ecsign, toRpcSig, keccak256 as keccak256_buffer } from 'ethereumjs-util'; import { Create2Factory } from './Create2Factory'; import { EntryPoint } from '@account-abstraction/contracts'; -import { ethers } from 'ethers'; +import { AbiCoder } from 'ethers'; import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'; import * as typ from './solidityTypes'; import { ethers as hreEther } from 'hardhat'; @@ -26,7 +35,7 @@ export interface UserOperation { export function packUserOp(op: UserOperation, forSignature = true): string { if (forSignature) { // Encoding the UserOperation object fields into a single string for signature - return ethers.AbiCoder.defaultAbiCoder().encode( + return AbiCoder.defaultAbiCoder().encode( [ 'address', 'uint256', @@ -54,7 +63,7 @@ export function packUserOp(op: UserOperation, forSignature = true): string { ); } else { // Encoding the UserOperation object fields into a single string including the signature - return ethers.AbiCoder.defaultAbiCoder().encode( + return AbiCoder.defaultAbiCoder().encode( [ 'address', 'uint256', @@ -88,7 +97,7 @@ export function packUserOp(op: UserOperation, forSignature = true): string { export function getUserOpHash(op: UserOperation, entryPoint: string, chainId: number): string { const userOpHash = keccak256(packUserOp(op, true)); // Encoding the UserOperation hash, entryPoint address, and chainId for final hash computation - const enc = ethers.AbiCoder.defaultAbiCoder().encode( + const enc = AbiCoder.defaultAbiCoder().encode( ['bytes32', 'address', 'uint256'], [userOpHash, entryPoint, chainId], ); @@ -189,14 +198,13 @@ export async function fillUserOp( data: initCallData, gasLimit: 10e6, }); - op1.verificationGasLimit = - ethers.toBigInt(DefaultsForUserOp.verificationGasLimit) + initEstimate; + op1.verificationGasLimit = toBigInt(DefaultsForUserOp.verificationGasLimit) + initEstimate; } } if (op1.nonce == null) { if (provider == null) throw new Error('must have entryPoint to autofill nonce'); - const signerKeyAsUint192 = ethers.toBeHex(ethers.toBigInt(signer.address)); + const signerKeyAsUint192 = toBeHex(toBigInt(signer.address)); try { op1.nonce = await entryPoint.getNonce(op1.sender, signerKeyAsUint192); @@ -209,7 +217,7 @@ export async function fillUserOp( const gasEtimated = await provider.estimateGas({ from: entryPoint?.target, to: op1.sender, - data: ethers.hexlify(op1.callData as BytesLike), + data: hexlify(op1.callData as BytesLike), }); op1.callGasLimit = gasEtimated; @@ -242,9 +250,7 @@ export async function fillAndSign( const op2 = await fillUserOp(op, signer, entryPoint); const chainId = await provider.getNetwork().then((net) => net.chainId); - const message = getBytes( - getUserOpHash(op2, entryPoint.target as string, ethers.toNumber(chainId)), - ); + const message = getBytes(getUserOpHash(op2, entryPoint.target as string, toNumber(chainId))); return { ...op2, diff --git a/tests/LSP1UniversalReceiver/LSP1UniversalReceiver.behaviour.ts b/tests/LSP1UniversalReceiver/LSP1UniversalReceiver.behaviour.ts index db741b94f..06a894e93 100644 --- a/tests/LSP1UniversalReceiver/LSP1UniversalReceiver.behaviour.ts +++ b/tests/LSP1UniversalReceiver/LSP1UniversalReceiver.behaviour.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { ethers } from 'hardhat'; +import { parseEther } from 'ethers'; import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'; // types @@ -159,7 +159,7 @@ export const shouldBehaveLikeLSP1 = (buildContext: () => Promise { - const valueSent = ethers.parseEther('3'); + const valueSent = parseEther('3'); before(async () => { context = await buildContext(); @@ -193,7 +193,7 @@ export const shouldBehaveLikeLSP1 = (buildContext: () => Promise { await context.accounts[0].sendTransaction({ to: lsp1CheckerAddress, - value: ethers.parseEther('50'), + value: parseEther('50'), }); }); diff --git a/tests/LSP20CallVerification/LSP6/SetData/AllowedERC725YDataKeys.test.ts b/tests/LSP20CallVerification/LSP6/SetData/AllowedERC725YDataKeys.test.ts index 902cab268..bddd939c4 100644 --- a/tests/LSP20CallVerification/LSP6/SetData/AllowedERC725YDataKeys.test.ts +++ b/tests/LSP20CallVerification/LSP6/SetData/AllowedERC725YDataKeys.test.ts @@ -1,5 +1,4 @@ import { expect } from 'chai'; -import { ethers } from 'hardhat'; import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'; // constants @@ -12,7 +11,7 @@ import { setupKeyManager } from '../../../utils/fixtures'; // helpers import { encodeCompactBytesArray, decodeCompactBytes } from '../../../utils/helpers'; -import { BytesLike } from 'ethers'; +import { BytesLike, keccak256, hexlify, toUtf8Bytes, randomBytes } from 'ethers'; export type TestCase = { datakeyToSet: BytesLike; @@ -27,10 +26,10 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( describe('keyType: Singleton', () => { let controllerCanSetOneKey: SignerWithAddress, controllerCanSetManyKeys: SignerWithAddress; - const customKey1 = ethers.keccak256(ethers.toUtf8Bytes('CustomKey1')); - const customKey2 = ethers.keccak256(ethers.toUtf8Bytes('CustomKey2')); - const customKey3 = ethers.keccak256(ethers.toUtf8Bytes('CustomKey3')); - const customKey4 = ethers.keccak256(ethers.toUtf8Bytes('CustomKey4')); + const customKey1 = keccak256(toUtf8Bytes('CustomKey1')); + const customKey2 = keccak256(toUtf8Bytes('CustomKey2')); + const customKey3 = keccak256(toUtf8Bytes('CustomKey3')); + const customKey4 = keccak256(toUtf8Bytes('CustomKey4')); before(async () => { context = await buildContext(); @@ -110,7 +109,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( describe('when setting one key', () => { it('should pass when setting the right key', async () => { const key = customKey1; - const newValue = ethers.hexlify(ethers.toUtf8Bytes('Some data')); + const newValue = hexlify(toUtf8Bytes('Some data')); await context.universalProfile.connect(controllerCanSetOneKey).setData(key, newValue); @@ -119,8 +118,8 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( }); it('should fail when setting the wrong key', async () => { - const key = ethers.keccak256(ethers.toUtf8Bytes('NotAllowedKey')); - const newValue = ethers.hexlify(ethers.toUtf8Bytes('Some data')); + const key = keccak256(toUtf8Bytes('NotAllowedKey')); + const newValue = hexlify(toUtf8Bytes('Some data')); await expect( context.universalProfile.connect(controllerCanSetOneKey).setData(key, newValue), @@ -133,14 +132,14 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( describe('when setting multiple keys', () => { it('should fail when the list contains none of the allowed keys', async () => { const keys = [ - ethers.keccak256(ethers.toUtf8Bytes('XXXXXXXXXX')), - ethers.keccak256(ethers.toUtf8Bytes('YYYYYYYYYY')), - ethers.keccak256(ethers.toUtf8Bytes('ZZZZZZZZZZ')), + keccak256(toUtf8Bytes('XXXXXXXXXX')), + keccak256(toUtf8Bytes('YYYYYYYYYY')), + keccak256(toUtf8Bytes('ZZZZZZZZZZ')), ]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Value XXXXXXXX')), - ethers.hexlify(ethers.toUtf8Bytes('Value YYYYYYYY')), - ethers.hexlify(ethers.toUtf8Bytes('Value ZZZZZZZZ')), + hexlify(toUtf8Bytes('Value XXXXXXXX')), + hexlify(toUtf8Bytes('Value YYYYYYYY')), + hexlify(toUtf8Bytes('Value ZZZZZZZZ')), ]; await expect( @@ -153,13 +152,13 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should fail, even if the list contains the allowed key', async () => { const keys = [ customKey1, - ethers.keccak256(ethers.toUtf8Bytes('XXXXXXXXXX')), - ethers.keccak256(ethers.toUtf8Bytes('YYYYYYYYYY')), + keccak256(toUtf8Bytes('XXXXXXXXXX')), + keccak256(toUtf8Bytes('YYYYYYYYYY')), ]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Custom Value 1')), - ethers.hexlify(ethers.toUtf8Bytes('Value XXXXXXXX')), - ethers.hexlify(ethers.toUtf8Bytes('Value YYYYYYYY')), + hexlify(toUtf8Bytes('Custom Value 1')), + hexlify(toUtf8Bytes('Value XXXXXXXX')), + hexlify(toUtf8Bytes('Value YYYYYYYY')), ]; await expect( @@ -175,9 +174,9 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should pass when the input is all the allowed keys', async () => { const keys = [customKey2, customKey3, customKey4]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Some data 1')), - ethers.hexlify(ethers.toUtf8Bytes('Some data 2')), - ethers.hexlify(ethers.toUtf8Bytes('Some data 3')), + hexlify(toUtf8Bytes('Some data 1')), + hexlify(toUtf8Bytes('Some data 2')), + hexlify(toUtf8Bytes('Some data 3')), ]; await context.universalProfile.connect(controllerCanSetManyKeys).setDataBatch(keys, values); @@ -189,14 +188,14 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should fail when the input contains none of the allowed keys', async () => { const keys = [ - ethers.keccak256(ethers.toUtf8Bytes('XXXXXXXXXX')), - ethers.keccak256(ethers.toUtf8Bytes('YYYYYYYYYY')), - ethers.keccak256(ethers.toUtf8Bytes('ZZZZZZZZZZ')), + keccak256(toUtf8Bytes('XXXXXXXXXX')), + keccak256(toUtf8Bytes('YYYYYYYYYY')), + keccak256(toUtf8Bytes('ZZZZZZZZZZ')), ]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Value XXXXXXXX')), - ethers.hexlify(ethers.toUtf8Bytes('Value YYYYYYYY')), - ethers.hexlify(ethers.toUtf8Bytes('Value ZZZZZZZZ')), + hexlify(toUtf8Bytes('Value XXXXXXXX')), + hexlify(toUtf8Bytes('Value YYYYYYYY')), + hexlify(toUtf8Bytes('Value ZZZZZZZZ')), ]; await expect( @@ -209,7 +208,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( describe('when setting one key', () => { it('should pass when trying to set the 1st allowed key', async () => { const key = customKey2; - const newValue = ethers.hexlify(ethers.toUtf8Bytes('Some data')); + const newValue = hexlify(toUtf8Bytes('Some data')); await context.universalProfile.connect(controllerCanSetManyKeys).setData(key, newValue); @@ -219,7 +218,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should pass when trying to set the 2nd allowed key', async () => { const key = customKey3; - const newValue = ethers.hexlify(ethers.toUtf8Bytes('Some data')); + const newValue = hexlify(toUtf8Bytes('Some data')); await context.universalProfile.connect(controllerCanSetManyKeys).setData(key, newValue); @@ -229,7 +228,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should pass when trying to set the 3rd allowed key', async () => { const key = customKey4; - const newValue = ethers.hexlify(ethers.toUtf8Bytes('Some data')); + const newValue = hexlify(toUtf8Bytes('Some data')); await context.universalProfile.connect(controllerCanSetManyKeys).setData(key, newValue); @@ -238,8 +237,8 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( }); it('should fail when setting a not-allowed Singleton key', async () => { - const key = ethers.keccak256(ethers.toUtf8Bytes('NotAllowedKey')); - const newValue = ethers.hexlify(ethers.toUtf8Bytes('Some data')); + const key = keccak256(toUtf8Bytes('NotAllowedKey')); + const newValue = hexlify(toUtf8Bytes('Some data')); await expect( context.universalProfile.connect(controllerCanSetManyKeys).setData(key, newValue), @@ -254,8 +253,8 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('the input is the first two (subset) allowed keys', async () => { const keys = [customKey2, customKey3]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Some data 1')), - ethers.hexlify(ethers.toUtf8Bytes('Some data 2')), + hexlify(toUtf8Bytes('Some data 1')), + hexlify(toUtf8Bytes('Some data 2')), ]; await context.universalProfile @@ -269,8 +268,8 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('the input is the last two (subset) allowed keys', async () => { const keys = [customKey3, customKey4]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Some data 1')), - ethers.hexlify(ethers.toUtf8Bytes('Some data 2')), + hexlify(toUtf8Bytes('Some data 1')), + hexlify(toUtf8Bytes('Some data 2')), ]; await context.universalProfile @@ -284,8 +283,8 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('the input is the first + last (subset) allowed keys', async () => { const keys = [customKey2, customKey4]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Some data 1')), - ethers.hexlify(ethers.toUtf8Bytes('Some data 2')), + hexlify(toUtf8Bytes('Some data 1')), + hexlify(toUtf8Bytes('Some data 2')), ]; await context.universalProfile @@ -303,13 +302,13 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('1st key in input = 1st allowed key. Other 2 keys = not allowed', async () => { const keys = [ customKey2, - ethers.keccak256(ethers.toUtf8Bytes('XXXXXXXXXX')), - ethers.keccak256(ethers.toUtf8Bytes('YYYYYYYYYY')), + keccak256(toUtf8Bytes('XXXXXXXXXX')), + keccak256(toUtf8Bytes('YYYYYYYYYY')), ]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Custom Value 2')), - ethers.hexlify(ethers.toUtf8Bytes('Value XXXXXXXX')), - ethers.hexlify(ethers.toUtf8Bytes('Value YYYYYYYY')), + hexlify(toUtf8Bytes('Custom Value 2')), + hexlify(toUtf8Bytes('Value XXXXXXXX')), + hexlify(toUtf8Bytes('Value YYYYYYYY')), ]; await expect( @@ -321,14 +320,14 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('2nd key in input = 1st allowed key. Other 2 keys = not allowed', async () => { const keys = [ - ethers.keccak256(ethers.toUtf8Bytes('XXXXXXXXXX')), + keccak256(toUtf8Bytes('XXXXXXXXXX')), customKey2, - ethers.keccak256(ethers.toUtf8Bytes('YYYYYYYYYY')), + keccak256(toUtf8Bytes('YYYYYYYYYY')), ]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Value XXXXXXXX')), - ethers.hexlify(ethers.toUtf8Bytes('Custom Value 2')), - ethers.hexlify(ethers.toUtf8Bytes('Value YYYYYYYY')), + hexlify(toUtf8Bytes('Value XXXXXXXX')), + hexlify(toUtf8Bytes('Custom Value 2')), + hexlify(toUtf8Bytes('Value YYYYYYYY')), ]; await expect( @@ -340,14 +339,14 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('3rd key in input = 1st allowed key. Other 2 keys = not allowed', async () => { const keys = [ - ethers.keccak256(ethers.toUtf8Bytes('XXXXXXXXXX')), - ethers.keccak256(ethers.toUtf8Bytes('YYYYYYYYYY')), + keccak256(toUtf8Bytes('XXXXXXXXXX')), + keccak256(toUtf8Bytes('YYYYYYYYYY')), customKey2, ]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Value XXXXXXXX')), - ethers.hexlify(ethers.toUtf8Bytes('Value YYYYYYYY')), - ethers.hexlify(ethers.toUtf8Bytes('Custom Value 2')), + hexlify(toUtf8Bytes('Value XXXXXXXX')), + hexlify(toUtf8Bytes('Value YYYYYYYY')), + hexlify(toUtf8Bytes('Custom Value 2')), ]; await expect( @@ -360,13 +359,13 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('1st key in input = 2nd allowed key. Other 2 keys = not allowed', async () => { const keys = [ customKey3, - ethers.keccak256(ethers.toUtf8Bytes('XXXXXXXXXX')), - ethers.keccak256(ethers.toUtf8Bytes('YYYYYYYYYY')), + keccak256(toUtf8Bytes('XXXXXXXXXX')), + keccak256(toUtf8Bytes('YYYYYYYYYY')), ]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Custom Value 2')), - ethers.hexlify(ethers.toUtf8Bytes('Value XXXXXXXX')), - ethers.hexlify(ethers.toUtf8Bytes('Value YYYYYYYY')), + hexlify(toUtf8Bytes('Custom Value 2')), + hexlify(toUtf8Bytes('Value XXXXXXXX')), + hexlify(toUtf8Bytes('Value YYYYYYYY')), ]; await expect( @@ -378,14 +377,14 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('2nd key in input = 2nd allowed key. Other 2 keys = not allowed', async () => { const keys = [ - ethers.keccak256(ethers.toUtf8Bytes('XXXXXXXXXX')), + keccak256(toUtf8Bytes('XXXXXXXXXX')), customKey3, - ethers.keccak256(ethers.toUtf8Bytes('YYYYYYYYYY')), + keccak256(toUtf8Bytes('YYYYYYYYYY')), ]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Value XXXXXXXX')), - ethers.hexlify(ethers.toUtf8Bytes('Custom Value 3')), - ethers.hexlify(ethers.toUtf8Bytes('Value YYYYYYYY')), + hexlify(toUtf8Bytes('Value XXXXXXXX')), + hexlify(toUtf8Bytes('Custom Value 3')), + hexlify(toUtf8Bytes('Value YYYYYYYY')), ]; await expect( @@ -397,14 +396,14 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('3rd key in input = 2nd allowed key. Other 2 keys = not allowed', async () => { const keys = [ - ethers.keccak256(ethers.toUtf8Bytes('XXXXXXXXXX')), - ethers.keccak256(ethers.toUtf8Bytes('YYYYYYYYYY')), + keccak256(toUtf8Bytes('XXXXXXXXXX')), + keccak256(toUtf8Bytes('YYYYYYYYYY')), customKey3, ]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Value XXXXXXXX')), - ethers.hexlify(ethers.toUtf8Bytes('Value YYYYYYYY')), - ethers.hexlify(ethers.toUtf8Bytes('Custom Value 3')), + hexlify(toUtf8Bytes('Value XXXXXXXX')), + hexlify(toUtf8Bytes('Value YYYYYYYY')), + hexlify(toUtf8Bytes('Custom Value 3')), ]; await expect( @@ -417,13 +416,13 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('1st key in input = 3rd allowed key. Other 2 keys = not allowed', async () => { const keys = [ customKey4, - ethers.keccak256(ethers.toUtf8Bytes('XXXXXXXXXX')), - ethers.keccak256(ethers.toUtf8Bytes('YYYYYYYYYY')), + keccak256(toUtf8Bytes('XXXXXXXXXX')), + keccak256(toUtf8Bytes('YYYYYYYYYY')), ]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Custom Value 4')), - ethers.hexlify(ethers.toUtf8Bytes('Value XXXXXXXX')), - ethers.hexlify(ethers.toUtf8Bytes('Value YYYYYYYY')), + hexlify(toUtf8Bytes('Custom Value 4')), + hexlify(toUtf8Bytes('Value XXXXXXXX')), + hexlify(toUtf8Bytes('Value YYYYYYYY')), ]; await expect( @@ -435,14 +434,14 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('2nd key in input = 3rd allowed key. Other 2 keys = not allowed', async () => { const keys = [ - ethers.keccak256(ethers.toUtf8Bytes('XXXXXXXXXX')), + keccak256(toUtf8Bytes('XXXXXXXXXX')), customKey4, - ethers.keccak256(ethers.toUtf8Bytes('YYYYYYYYYY')), + keccak256(toUtf8Bytes('YYYYYYYYYY')), ]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Value XXXXXXXX')), - ethers.hexlify(ethers.toUtf8Bytes('Custom Value 4')), - ethers.hexlify(ethers.toUtf8Bytes('Value YYYYYYYY')), + hexlify(toUtf8Bytes('Value XXXXXXXX')), + hexlify(toUtf8Bytes('Custom Value 4')), + hexlify(toUtf8Bytes('Value YYYYYYYY')), ]; await expect( @@ -454,14 +453,14 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('3rd key in input = 3rd allowed key. Other 2 keys = not allowed', async () => { const keys = [ - ethers.keccak256(ethers.toUtf8Bytes('XXXXXXXXXX')), - ethers.keccak256(ethers.toUtf8Bytes('YYYYYYYYYY')), + keccak256(toUtf8Bytes('XXXXXXXXXX')), + keccak256(toUtf8Bytes('YYYYYYYYYY')), customKey4, ]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Value XXXXXXXX')), - ethers.hexlify(ethers.toUtf8Bytes('Value YYYYYYYY')), - ethers.hexlify(ethers.toUtf8Bytes('Custom Value 4')), + hexlify(toUtf8Bytes('Value XXXXXXXX')), + hexlify(toUtf8Bytes('Value YYYYYYYY')), + hexlify(toUtf8Bytes('Custom Value 4')), ]; await expect( @@ -472,16 +471,12 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( }); it('1st key in input = not allowed key. Other 2 keys = allowed', async () => { - const keys = [ - ethers.keccak256(ethers.toUtf8Bytes('XXXXXXXXXX')), - customKey2, - customKey3, - ]; + const keys = [keccak256(toUtf8Bytes('XXXXXXXXXX')), customKey2, customKey3]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Value XXXXXXXX')), - ethers.hexlify(ethers.toUtf8Bytes('Custom Value 2')), - ethers.hexlify(ethers.toUtf8Bytes('Custom Value 3')), + hexlify(toUtf8Bytes('Value XXXXXXXX')), + hexlify(toUtf8Bytes('Custom Value 2')), + hexlify(toUtf8Bytes('Custom Value 3')), ]; await expect( @@ -492,15 +487,11 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( }); it('2nd key in input = not allowed key. Other 2 keys = allowed', async () => { - const keys = [ - customKey2, - ethers.keccak256(ethers.toUtf8Bytes('XXXXXXXXXX')), - customKey3, - ]; + const keys = [customKey2, keccak256(toUtf8Bytes('XXXXXXXXXX')), customKey3]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Custom Value 2')), - ethers.hexlify(ethers.toUtf8Bytes('Value XXXXXXXX')), - ethers.hexlify(ethers.toUtf8Bytes('Custom Value 3')), + hexlify(toUtf8Bytes('Custom Value 2')), + hexlify(toUtf8Bytes('Value XXXXXXXX')), + hexlify(toUtf8Bytes('Custom Value 3')), ]; await expect( @@ -511,16 +502,12 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( }); it('3rd key in input = not allowed key. Other 2 keys = allowed', async () => { - const keys = [ - customKey2, - customKey3, - ethers.keccak256(ethers.toUtf8Bytes('XXXXXXXXXX')), - ]; + const keys = [customKey2, customKey3, keccak256(toUtf8Bytes('XXXXXXXXXX'))]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Custom Value 2')), - ethers.hexlify(ethers.toUtf8Bytes('Custom Value 3')), - ethers.hexlify(ethers.toUtf8Bytes('Value XXXXXXXX')), + hexlify(toUtf8Bytes('Custom Value 2')), + hexlify(toUtf8Bytes('Custom Value 3')), + hexlify(toUtf8Bytes('Value XXXXXXXX')), ]; await expect( @@ -540,13 +527,13 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( customKey2, customKey3, customKey4, - ethers.keccak256(ethers.toUtf8Bytes('XXXXXXXXXX')), + keccak256(toUtf8Bytes('XXXXXXXXXX')), ]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Some Data for customKey2')), - ethers.hexlify(ethers.toUtf8Bytes('Some Data for customKey3')), - ethers.hexlify(ethers.toUtf8Bytes('Some Data for customKey4')), - ethers.hexlify(ethers.toUtf8Bytes('Value XXXXXXXX')), + hexlify(toUtf8Bytes('Some Data for customKey2')), + hexlify(toUtf8Bytes('Some Data for customKey3')), + hexlify(toUtf8Bytes('Some Data for customKey4')), + hexlify(toUtf8Bytes('Value XXXXXXXX')), ]; await expect( @@ -563,21 +550,21 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( customKey2, customKey3, customKey4, - ethers.keccak256(ethers.toUtf8Bytes('XXXXXXXXXX')), - ethers.keccak256(ethers.toUtf8Bytes('YYYYYYYYYY')), - ethers.keccak256(ethers.toUtf8Bytes('ZZZZZZZZZZ')), - ethers.keccak256(ethers.toUtf8Bytes('AAAAAAAAAA')), - ethers.keccak256(ethers.toUtf8Bytes('BBBBBBBBBB')), + keccak256(toUtf8Bytes('XXXXXXXXXX')), + keccak256(toUtf8Bytes('YYYYYYYYYY')), + keccak256(toUtf8Bytes('ZZZZZZZZZZ')), + keccak256(toUtf8Bytes('AAAAAAAAAA')), + keccak256(toUtf8Bytes('BBBBBBBBBB')), ]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Custom Value 2')), - ethers.hexlify(ethers.toUtf8Bytes('Custom Value 3')), - ethers.hexlify(ethers.toUtf8Bytes('Custom Value 4')), - ethers.hexlify(ethers.toUtf8Bytes('Value XXXXXXXX')), - ethers.hexlify(ethers.toUtf8Bytes('Value YYYYYYYY')), - ethers.hexlify(ethers.toUtf8Bytes('Value ZZZZZZZZ')), - ethers.hexlify(ethers.toUtf8Bytes('Value AAAAAAAA')), - ethers.hexlify(ethers.toUtf8Bytes('Value BBBBBBBB')), + hexlify(toUtf8Bytes('Custom Value 2')), + hexlify(toUtf8Bytes('Custom Value 3')), + hexlify(toUtf8Bytes('Custom Value 4')), + hexlify(toUtf8Bytes('Value XXXXXXXX')), + hexlify(toUtf8Bytes('Value YYYYYYYY')), + hexlify(toUtf8Bytes('Value ZZZZZZZZ')), + hexlify(toUtf8Bytes('Value AAAAAAAA')), + hexlify(toUtf8Bytes('Value BBBBBBBB')), ]; await expect( @@ -604,15 +591,15 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( customKey4, ]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Some Data for customKey2')), - ethers.hexlify(ethers.toUtf8Bytes('Some Data for customKey4')), - ethers.hexlify(ethers.toUtf8Bytes('Some Data for customKey3')), - ethers.hexlify(ethers.toUtf8Bytes('Some Data (override 1) for customKey2')), - ethers.hexlify(ethers.toUtf8Bytes('Some Data (override 1) for customKey3')), - ethers.hexlify(ethers.toUtf8Bytes('Some Data (override 2) for customKey2')), - ethers.hexlify(ethers.toUtf8Bytes('Some Data (override 1) for customKey4')), - ethers.hexlify(ethers.toUtf8Bytes('Some Data (override 2) for customKey3')), - ethers.hexlify(ethers.toUtf8Bytes('Some Data (override 2) for customKey4')), + hexlify(toUtf8Bytes('Some Data for customKey2')), + hexlify(toUtf8Bytes('Some Data for customKey4')), + hexlify(toUtf8Bytes('Some Data for customKey3')), + hexlify(toUtf8Bytes('Some Data (override 1) for customKey2')), + hexlify(toUtf8Bytes('Some Data (override 1) for customKey3')), + hexlify(toUtf8Bytes('Some Data (override 2) for customKey2')), + hexlify(toUtf8Bytes('Some Data (override 1) for customKey4')), + hexlify(toUtf8Bytes('Some Data (override 2) for customKey3')), + hexlify(toUtf8Bytes('Some Data (override 2) for customKey4')), ]; await context.universalProfile @@ -640,8 +627,8 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( describe('when address can set any key', () => { describe('when setting one key', () => { it('should pass when setting any random key', async () => { - const key = ethers.hexlify(ethers.randomBytes(32)); - const value = ethers.hexlify(ethers.toUtf8Bytes('Some data')); + const key = hexlify(randomBytes(32)); + const value = hexlify(toUtf8Bytes('Some data')); await context.universalProfile.connect(context.mainController).setData(key, value); @@ -653,14 +640,14 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( describe('when setting multiple keys', () => { it('should pass when setting any multiple keys', async () => { const keys = [ - ethers.hexlify(ethers.randomBytes(32)), - ethers.hexlify(ethers.randomBytes(32)), - ethers.hexlify(ethers.randomBytes(32)), + hexlify(randomBytes(32)), + hexlify(randomBytes(32)), + hexlify(randomBytes(32)), ]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('Some data 1')), - ethers.hexlify(ethers.toUtf8Bytes('Some data 2')), - ethers.hexlify(ethers.toUtf8Bytes('Some data 3')), + hexlify(toUtf8Bytes('Some data 1')), + hexlify(toUtf8Bytes('Some data 2')), + hexlify(toUtf8Bytes('Some data 3')), ]; await context.universalProfile.connect(context.mainController).setDataBatch(keys, values); @@ -715,7 +702,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( describe('when setting one key', () => { it('should pass when setting SupportedStandards:LSPX', async () => { const mappingKey = LSPXKey; - const mappingValue = ethers.hexlify(ethers.toUtf8Bytes('0x24ae6f23')); + const mappingValue = hexlify(toUtf8Bytes('0x24ae6f23')); await context.universalProfile .connect(controllerCanSetMappingKeys) @@ -727,7 +714,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should pass when overriding SupportedStandards:LSPX', async () => { const mappingKey = LSPXKey; - const mappingValue = ethers.hexlify(ethers.toUtf8Bytes('0x24ae6f23')); + const mappingValue = hexlify(toUtf8Bytes('0x24ae6f23')); await context.universalProfile .connect(controllerCanSetMappingKeys) @@ -739,7 +726,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should pass when setting SupportedStandards:LSPY', async () => { const mappingKey = LSPYKey; - const mappingValue = ethers.hexlify(ethers.toUtf8Bytes('0x5e8d18c5')); + const mappingValue = hexlify(toUtf8Bytes('0x5e8d18c5')); await context.universalProfile .connect(controllerCanSetMappingKeys) @@ -751,7 +738,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should pass when setting SupportedStandards:LSPZ', async () => { const mappingKey = LSPZKey; - const mappingValue = ethers.hexlify(ethers.toUtf8Bytes('0x25b71a36')); + const mappingValue = hexlify(toUtf8Bytes('0x25b71a36')); await context.universalProfile .connect(controllerCanSetMappingKeys) @@ -841,9 +828,9 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( '0xcccccccccccccccccccccccccccccccc00000000000000000000000022222222', ]; const randomMappingValues = [ - ethers.hexlify(ethers.toUtf8Bytes('Random Mapping Value 1')), - ethers.hexlify(ethers.toUtf8Bytes('Random Mapping Value 2')), - ethers.hexlify(ethers.toUtf8Bytes('Random Mapping Value 3')), + hexlify(toUtf8Bytes('Random Mapping Value 1')), + hexlify(toUtf8Bytes('Random Mapping Value 2')), + hexlify(toUtf8Bytes('Random Mapping Value 3')), ]; await expect( @@ -863,8 +850,8 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( ]; const mappingValues = [ '0x24ae6f23', - ethers.hexlify(ethers.toUtf8Bytes('Random Mapping Value 1')), - ethers.hexlify(ethers.toUtf8Bytes('Random Mapping Value 2')), + hexlify(toUtf8Bytes('Random Mapping Value 1')), + hexlify(toUtf8Bytes('Random Mapping Value 2')), ]; await expect( @@ -883,7 +870,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should pass when setting any random Mapping key', async () => { const randomMappingKey = '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa00000000000000000000000011111111'; - const randomMappingValue = ethers.hexlify(ethers.toUtf8Bytes('Random Mapping Value')); + const randomMappingValue = hexlify(toUtf8Bytes('Random Mapping Value')); await context.universalProfile .connect(context.mainController) @@ -902,9 +889,9 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( '0xcccccccccccccccccccccccccccccccc00000000000000000000000022222222', ]; const randomMappingValues = [ - ethers.hexlify(ethers.toUtf8Bytes('Random Mapping Value 1')), - ethers.hexlify(ethers.toUtf8Bytes('Random Mapping Value 2')), - ethers.hexlify(ethers.toUtf8Bytes('Random Mapping Value 3')), + hexlify(toUtf8Bytes('Random Mapping Value 1')), + hexlify(toUtf8Bytes('Random Mapping Value 2')), + hexlify(toUtf8Bytes('Random Mapping Value 3')), ]; await context.universalProfile @@ -963,7 +950,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should pass when setting array key length MyArray[]', async () => { const key = arrayKeyLength; // eg: MyArray[].length = 10 elements - const value = ethers.hexlify(ethers.toUtf8Bytes('0x0a')); + const value = hexlify(toUtf8Bytes('0x0a')); await context.universalProfile.connect(controllerCanSetArrayKeys).setData(key, value); @@ -973,7 +960,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should pass when setting 1st array element MyArray[0]', async () => { const key = arrayKeyElement1; - const value = ethers.hexlify(ethers.toUtf8Bytes('0xaaaaaaaa')); + const value = hexlify(toUtf8Bytes('0xaaaaaaaa')); await context.universalProfile.connect(controllerCanSetArrayKeys).setData(key, value); @@ -983,7 +970,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should pass when setting 2nd array element MyArray[1]', async () => { const key = arrayKeyElement2; - const value = ethers.hexlify(ethers.toUtf8Bytes('0xbbbbbbbb')); + const value = hexlify(toUtf8Bytes('0xbbbbbbbb')); await context.universalProfile.connect(controllerCanSetArrayKeys).setData(key, value); @@ -993,7 +980,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should pass when setting 3rd array element MyArray[3]', async () => { const key = arrayKeyElement3; - const value = ethers.hexlify(ethers.toUtf8Bytes('0xcccccccc')); + const value = hexlify(toUtf8Bytes('0xcccccccc')); await context.universalProfile.connect(controllerCanSetArrayKeys).setData(key, value); @@ -1065,8 +1052,8 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( describe('Testing bytes32(0) (= zero key) edge cases', () => { let controllerCanSetSomeKeys: SignerWithAddress; - const customKey1 = ethers.keccak256(ethers.toUtf8Bytes('CustomKey1')); - const customKey2 = ethers.keccak256(ethers.toUtf8Bytes('CustomKey2')); + const customKey1 = keccak256(toUtf8Bytes('CustomKey1')); + const customKey2 = keccak256(toUtf8Bytes('CustomKey2')); const zeroKey = '0x0000000000000000000000000000000000000000000000000000000000000000'; @@ -1110,7 +1097,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( [{ allowedDataKey: customKey1 }, { allowedDataKey: customKey2 }].forEach((testCase) => { it(`should pass when setting a data key listed in the allowed ERC725Y data keys: ${testCase.allowedDataKey}`, async () => { const key = testCase.allowedDataKey; - const value = ethers.hexlify(ethers.toUtf8Bytes('some value for ' + key)); + const value = hexlify(toUtf8Bytes('some value for ' + key)); await context.universalProfile.connect(controllerCanSetSomeKeys).setData(key, value); @@ -1121,24 +1108,24 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( [ { - datakeyToSet: ethers.keccak256(ethers.toUtf8Bytes('Some random data key 1')), + datakeyToSet: keccak256(toUtf8Bytes('Some random data key 1')), }, { - datakeyToSet: ethers.keccak256(ethers.toUtf8Bytes('Some random data key 2')), + datakeyToSet: keccak256(toUtf8Bytes('Some random data key 2')), }, { - datakeyToSet: ethers.keccak256(ethers.toUtf8Bytes('Some random data key 3')), + datakeyToSet: keccak256(toUtf8Bytes('Some random data key 3')), }, { - datakeyToSet: ethers.keccak256(ethers.toUtf8Bytes('Some random data key 4')), + datakeyToSet: keccak256(toUtf8Bytes('Some random data key 4')), }, { - datakeyToSet: ethers.keccak256(ethers.toUtf8Bytes('Some random data key 5')), + datakeyToSet: keccak256(toUtf8Bytes('Some random data key 5')), }, ].forEach((testCase) => { it(`should revert when trying to set any random data key (e.g: ${testCase.datakeyToSet})`, async () => { const key = testCase.datakeyToSet; - const value = ethers.hexlify(ethers.toUtf8Bytes('some value for ' + key)); + const value = hexlify(toUtf8Bytes('some value for ' + key)); await expect( context.universalProfile.connect(controllerCanSetSomeKeys).setData(key, value), @@ -1150,7 +1137,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should revert when trying to set bytes31(0) dynamic key, not in AllowedERC725YDataKeys', async () => { const key = bytes31DynamicKey; - const value = ethers.hexlify(ethers.toUtf8Bytes('some value for ' + key)); + const value = hexlify(toUtf8Bytes('some value for ' + key)); await expect(context.universalProfile.connect(controllerCanSetSomeKeys).setData(key, value)) .to.be.revertedWithCustomError(context.keyManager, 'NotAllowedERC725YDataKey') @@ -1159,7 +1146,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should pass and allow to set the bytes32(0) data key', async () => { const key = zeroKey; - const value = ethers.hexlify(ethers.toUtf8Bytes('some value for ' + key)); + const value = hexlify(toUtf8Bytes('some value for ' + key)); await context.universalProfile.connect(controllerCanSetSomeKeys).setData(key, value); @@ -1169,9 +1156,9 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should pass when trying to set an array of data keys that includes bytes32(0) (= zero data key)', async () => { const keys = [customKey1, customKey2, zeroKey]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('some value for ' + keys[0])), - ethers.hexlify(ethers.toUtf8Bytes('some value for ' + keys[1])), - ethers.hexlify(ethers.toUtf8Bytes('some value for ' + keys[2])), + hexlify(toUtf8Bytes('some value for ' + keys[0])), + hexlify(toUtf8Bytes('some value for ' + keys[1])), + hexlify(toUtf8Bytes('some value for ' + keys[2])), ]; await context.universalProfile.connect(controllerCanSetSomeKeys).setDataBatch(keys, values); @@ -1182,9 +1169,9 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should revert when trying to set an array of data keys including a dynamic bytes31(0) data key, not in AllowedERC725YDataKeys', async () => { const keys = [customKey1, customKey2, bytes31DynamicKey]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('some value for ' + keys[0])), - ethers.hexlify(ethers.toUtf8Bytes('some value for ' + keys[1])), - ethers.hexlify(ethers.toUtf8Bytes('some value for ' + keys[2])), + hexlify(toUtf8Bytes('some value for ' + keys[0])), + hexlify(toUtf8Bytes('some value for ' + keys[1])), + hexlify(toUtf8Bytes('some value for ' + keys[2])), ]; await expect( @@ -1197,9 +1184,9 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should revert when trying to set an array of data keys including a dynamic bytes20(0) data key, not in AllowedERC725YDataKeys', async () => { const keys = [customKey1, customKey2, bytes20DynamicKey]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('some value for ' + keys[0])), - ethers.hexlify(ethers.toUtf8Bytes('some value for ' + keys[1])), - ethers.hexlify(ethers.toUtf8Bytes('some value for ' + keys[2])), + hexlify(toUtf8Bytes('some value for ' + keys[0])), + hexlify(toUtf8Bytes('some value for ' + keys[1])), + hexlify(toUtf8Bytes('some value for ' + keys[2])), ]; await expect( @@ -1242,7 +1229,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( [{ allowedDataKey: customKey1 }, { allowedDataKey: customKey2 }].forEach((testCase) => { it(`should pass when setting a data key listed in the allowed ERC725Y data keys: ${testCase.allowedDataKey}`, async () => { const key = testCase.allowedDataKey; - const value = ethers.hexlify(ethers.toUtf8Bytes('some value for ' + key)); + const value = hexlify(toUtf8Bytes('some value for ' + key)); await context.universalProfile.connect(controllerCanSetSomeKeys).setData(key, value); @@ -1253,24 +1240,24 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( [ { - datakeyToSet: ethers.keccak256(ethers.toUtf8Bytes('Some random data key 1')), + datakeyToSet: keccak256(toUtf8Bytes('Some random data key 1')), }, { - datakeyToSet: ethers.keccak256(ethers.toUtf8Bytes('Some random data key 2')), + datakeyToSet: keccak256(toUtf8Bytes('Some random data key 2')), }, { - datakeyToSet: ethers.keccak256(ethers.toUtf8Bytes('Some random data key 3')), + datakeyToSet: keccak256(toUtf8Bytes('Some random data key 3')), }, { - datakeyToSet: ethers.keccak256(ethers.toUtf8Bytes('Some random data key 4')), + datakeyToSet: keccak256(toUtf8Bytes('Some random data key 4')), }, { - datakeyToSet: ethers.keccak256(ethers.toUtf8Bytes('Some random data key 5')), + datakeyToSet: keccak256(toUtf8Bytes('Some random data key 5')), }, ].forEach((testCase) => { it(`should revert when trying to set any random data key (e.g: ${testCase.datakeyToSet})`, async () => { const key = testCase.datakeyToSet; - const value = ethers.hexlify(ethers.toUtf8Bytes('some value for ' + key)); + const value = hexlify(toUtf8Bytes('some value for ' + key)); await expect( context.universalProfile.connect(controllerCanSetSomeKeys).setData(key, value), @@ -1282,7 +1269,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should allow setting up a key with a prefix of 31 null bytes, as bytes31(0) is part of AllowedERC725YDataKeys', async () => { const key = bytes31DynamicKey; - const value = ethers.hexlify(ethers.toUtf8Bytes('some value for ' + key)); + const value = hexlify(toUtf8Bytes('some value for ' + key)); await context.universalProfile.connect(controllerCanSetSomeKeys).setData(key, value); @@ -1292,7 +1279,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should allow setting up a key with a prefix of 20 null bytes, as bytes20(0) is part of AllowedERC725YDataKeys', async () => { const key = bytes20DynamicKey; - const value = ethers.hexlify(ethers.toUtf8Bytes('some value for ' + key)); + const value = hexlify(toUtf8Bytes('some value for ' + key)); await context.universalProfile.connect(controllerCanSetSomeKeys).setData(key, value); @@ -1302,7 +1289,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should pass and allow to set the bytes32(0) data key', async () => { const key = zeroKey; - const value = ethers.hexlify(ethers.toUtf8Bytes('some value for ' + key)); + const value = hexlify(toUtf8Bytes('some value for ' + key)); await context.universalProfile.connect(controllerCanSetSomeKeys).setData(key, value); @@ -1312,9 +1299,9 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should pass when setting an array of data keys that includes bytes32(0) (= zero data key)', async () => { const keys = [customKey1, customKey2, zeroKey]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('some value for ' + keys[0])), - ethers.hexlify(ethers.toUtf8Bytes('some value for ' + keys[1])), - ethers.hexlify(ethers.toUtf8Bytes('some value for ' + keys[2])), + hexlify(toUtf8Bytes('some value for ' + keys[0])), + hexlify(toUtf8Bytes('some value for ' + keys[1])), + hexlify(toUtf8Bytes('some value for ' + keys[2])), ]; await context.universalProfile.connect(controllerCanSetSomeKeys).setDataBatch(keys, values); @@ -1325,9 +1312,9 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should pass when trying to set an array of data keys including a dynamic bytes24(0) data key, because bytes20(0) dynamic data ke is in AllowedERC725YDataKeys', async () => { const keys = [customKey1, customKey2, bytes24DynamicKey]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('some value for ' + keys[0])), - ethers.hexlify(ethers.toUtf8Bytes('some value for ' + keys[1])), - ethers.hexlify(ethers.toUtf8Bytes('some value for ' + keys[2])), + hexlify(toUtf8Bytes('some value for ' + keys[0])), + hexlify(toUtf8Bytes('some value for ' + keys[1])), + hexlify(toUtf8Bytes('some value for ' + keys[2])), ]; await context.universalProfile.connect(controllerCanSetSomeKeys).setDataBatch(keys, values); @@ -1338,9 +1325,9 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( it('should revert when trying to set an array of data keys including a dynamic bytes19(0) data key, not in AllowedERC725YDataKeys', async () => { const keys = [customKey1, customKey2, bytes19DynamicKey]; const values = [ - ethers.hexlify(ethers.toUtf8Bytes('some value for ' + keys[0])), - ethers.hexlify(ethers.toUtf8Bytes('some value for ' + keys[1])), - ethers.hexlify(ethers.toUtf8Bytes('some value for ' + keys[2])), + hexlify(toUtf8Bytes('some value for ' + keys[0])), + hexlify(toUtf8Bytes('some value for ' + keys[1])), + hexlify(toUtf8Bytes('some value for ' + keys[2])), ]; await expect( @@ -1394,7 +1381,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( ].forEach((testCase) => { it(`e.g: ${testCase.datakeyToSet}`, async () => { const key = testCase.datakeyToSet; - const value = ethers.hexlify(ethers.toUtf8Bytes('some value for ' + key)); + const value = hexlify(toUtf8Bytes('some value for ' + key)); await context.universalProfile.connect(controllerCanSetSomeKeys).setData(key, value); @@ -1427,7 +1414,7 @@ export const shouldBehaveLikeAllowedERC725YDataKeys = ( ].forEach((testCase) => { it(`should revert (e.g: ${testCase.datakeyToSet})`, async () => { const key = testCase.datakeyToSet; - const value = ethers.hexlify(ethers.toUtf8Bytes('some value for ' + key)); + const value = hexlify(toUtf8Bytes('some value for ' + key)); await expect( context.universalProfile.connect(controllerCanSetSomeKeys).setData(key, value), diff --git a/tests/LSP6KeyManager/Interactions/PermissionStaticCall.test.ts b/tests/LSP6KeyManager/Interactions/PermissionStaticCall.test.ts index 17c9785f1..e5bffa74a 100644 --- a/tests/LSP6KeyManager/Interactions/PermissionStaticCall.test.ts +++ b/tests/LSP6KeyManager/Interactions/PermissionStaticCall.test.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { ethers } from 'ethers'; +import { hashMessage, parseEther, toUtf8Bytes } from 'ethers'; import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'; import { @@ -166,7 +166,7 @@ export const shouldBehaveLikePermissionStaticCall = ( }); it('should revert with error `ERC725X_MsgValueDisallowedInStaticCall` if `value` param is not 0', async () => { - const LyxAmount = ethers.parseEther('3'); + const LyxAmount = parseEther('3'); const targetContractPayload = targetContract.interface.encodeFunctionData('getName'); @@ -191,7 +191,7 @@ export const shouldBehaveLikePermissionStaticCall = ( it('should pass and return data when `value` param is 0', async () => { const message = 'some message to sign'; const signature = await context.mainController.signMessage(message); - const messageHash = ethers.hashMessage(message); + const messageHash = hashMessage(message); const erc1271ContractPayload = signatureValidator.interface.encodeFunctionData( 'isValidSignature', @@ -216,11 +216,11 @@ export const shouldBehaveLikePermissionStaticCall = ( }); it('should revert with error `ERC725X_MsgValueDisallowedInStaticCall` if `value` param is not 0', async () => { - const lyxAmount = ethers.parseEther('3'); + const lyxAmount = parseEther('3'); const message = 'some message to sign'; const signature = await context.mainController.signMessage(message); - const messageHash = ethers.hashMessage(message); + const messageHash = hashMessage(message); const erc1271ContractPayload = signatureValidator.interface.encodeFunctionData( 'isValidSignature', @@ -252,7 +252,7 @@ export const shouldBehaveLikePermissionStaticCall = ( context.mainController.address, context.mainController.address, 1, - ethers.toUtf8Bytes('some data'), + toUtf8Bytes('some data'), ], ); @@ -279,7 +279,7 @@ export const shouldBehaveLikePermissionStaticCall = ( }); it('should revert with error `ERC725X_MsgValueDisallowedInStaticCall` if `value` param is not 0', async () => { - const lyxAmount = ethers.parseEther('3'); + const lyxAmount = parseEther('3'); // the params are not relevant for this test and just used as placeholders. const onERC721Payload = onERC721ReceivedContract.interface.encodeFunctionData( @@ -288,7 +288,7 @@ export const shouldBehaveLikePermissionStaticCall = ( context.mainController.address, context.mainController.address, 1, - ethers.toUtf8Bytes('some data'), + toUtf8Bytes('some data'), ], ); @@ -332,7 +332,7 @@ export const shouldBehaveLikePermissionStaticCall = ( }); it('should revert with error `ERC725X_MsgValueDisallowedInStaticCall` if `value` parameter is not 0', async () => { - const lyxAmount = ethers.parseEther('3'); + const lyxAmount = parseEther('3'); const targetContractPayload = targetContract.interface.encodeFunctionData('setName', [ 'modified name', @@ -655,7 +655,7 @@ export const shouldBehaveLikePermissionStaticCall = ( it('should revert with error `ERC725X_MsgValueDisallowedInStaticCall` when `value` param is not 0', async () => { const randomContract = await new TargetContract__factory(context.accounts[0]).deploy(); - const lyxAmount = ethers.parseEther('3'); + const lyxAmount = parseEther('3'); const payload = context.universalProfile.interface.encodeFunctionData('execute', [ OPERATION_TYPES.STATICCALL, @@ -815,7 +815,7 @@ export const shouldBehaveLikePermissionStaticCall = ( const executePayload = context.universalProfile.interface.encodeFunctionData('execute', [ OPERATION_TYPES.STATICCALL, await allowedTargetContracts[0].getAddress(), - ethers.parseEther('3'), + parseEther('3'), targetPayload, ]); @@ -857,7 +857,7 @@ export const shouldBehaveLikePermissionStaticCall = ( const executePayload = context.universalProfile.interface.encodeFunctionData('execute', [ OPERATION_TYPES.STATICCALL, await allowedTargetContracts[1].getAddress(), - ethers.parseEther('3'), + parseEther('3'), targetPayload, ]); diff --git a/tests/Reentrancy/LSP6/LSP6Reentrancy.test.ts b/tests/Reentrancy/LSP6/LSP6Reentrancy.test.ts index 2aafc0ec2..0432f25fc 100644 --- a/tests/Reentrancy/LSP6/LSP6Reentrancy.test.ts +++ b/tests/Reentrancy/LSP6/LSP6Reentrancy.test.ts @@ -1,5 +1,13 @@ import { expect } from 'chai'; -import { ethers } from 'ethers'; +import { + hexlify, + keccak256, + parseEther, + solidityPacked, + toUtf8Bytes, + ZeroAddress, + ZeroHash, +} from 'ethers'; import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'; import { EIP191Signer } from '@lukso/eip191-signer.js'; @@ -82,7 +90,7 @@ export const shouldBehaveLikeLSP6ReentrancyScenarios = ( combineCallTypes(CALLTYPE.VALUE, CALLTYPE.CALL), combineCallTypes(CALLTYPE.VALUE, CALLTYPE.CALL), ], - [signer.address, ethers.ZeroAddress], + [signer.address, ZeroAddress], ['0xffffffff', '0xffffffff'], ['0xffffffff', '0xffffffff'], ), @@ -93,7 +101,7 @@ export const shouldBehaveLikeLSP6ReentrancyScenarios = ( // Fund Universal Profile with some LYXe await context.mainController.sendTransaction({ to: await context.universalProfile.getAddress(), - value: ethers.parseEther('10'), + value: parseEther('10'), }); }); @@ -105,7 +113,7 @@ export const shouldBehaveLikeLSP6ReentrancyScenarios = ( const transferPayload = context.universalProfile.interface.encodeFunctionData('execute', [ OPERATION_TYPES.CALL, await maliciousContract.getAddress(), - ethers.parseEther('1'), + parseEther('1'), '0x', ]); @@ -151,13 +159,13 @@ export const shouldBehaveLikeLSP6ReentrancyScenarios = ( const executeRelayCallPayload = context.universalProfile.interface.encodeFunctionData( 'execute', - [OPERATION_TYPES.CALL, signer.address, ethers.parseEther('1'), '0x'], + [OPERATION_TYPES.CALL, signer.address, parseEther('1'), '0x'], ); const HARDHAT_CHAINID = 31337; const valueToSend = 0; - const encodedMessage = ethers.solidityPacked( + const encodedMessage = solidityPacked( ['uint256', 'uint256', 'uint256', 'uint256', 'uint256', 'bytes'], [ LSP25_VERSION, @@ -201,7 +209,7 @@ export const shouldBehaveLikeLSP6ReentrancyScenarios = ( const transferPayload = context.universalProfile.interface.encodeFunctionData('execute', [ OPERATION_TYPES.CALL, await maliciousContract.getAddress(), - ethers.parseEther('1'), + parseEther('1'), '0x', ]); @@ -249,7 +257,7 @@ export const shouldBehaveLikeLSP6ReentrancyScenarios = ( const transferPayload = context.universalProfile.interface.encodeFunctionData('execute', [ OPERATION_TYPES.CALL, await URDDummy.getAddress(), - ethers.parseEther('1'), + parseEther('1'), '0x', ]); @@ -273,9 +281,9 @@ export const shouldBehaveLikeLSP6ReentrancyScenarios = ( ); const newAttackerContractBalance = await provider.getBalance(await URDDummy.getAddress()); - expect(newAccountBalance).to.equal(initialAccountBalance - ethers.parseEther('2')); + expect(newAccountBalance).to.equal(initialAccountBalance - parseEther('2')); expect(newAttackerContractBalance).to.equal( - initialAttackerContractBalance + ethers.parseEther('2'), + initialAttackerContractBalance + parseEther('2'), ); }); @@ -283,10 +291,8 @@ export const shouldBehaveLikeLSP6ReentrancyScenarios = ( const universalReceiverDelegateDataUpdater = await new UniversalReceiverDelegateDataUpdater__factory(context.mainController).deploy(); - const randomHardcodedKey = ethers.keccak256(ethers.toUtf8Bytes('some random data key')); - const randomHardcodedValue = ethers.hexlify( - ethers.toUtf8Bytes('some random text for the data value'), - ); + const randomHardcodedKey = keccak256(toUtf8Bytes('some random data key')); + const randomHardcodedValue = hexlify(toUtf8Bytes('some random text for the data value')); const setDataPayload = context.universalProfile.interface.encodeFunctionData( 'setDataBatch', @@ -311,18 +317,13 @@ export const shouldBehaveLikeLSP6ReentrancyScenarios = ( const universalReceiverDelegatePayload = universalReceiverDelegateDataUpdater.interface.encodeFunctionData( 'universalReceiverDelegate', - [ - ethers.ZeroAddress, - 0, - LSP1_TYPE_IDS.LSP7Tokens_SenderNotification, - '0xcafecafecafecafe', - ], + [ZeroAddress, 0, LSP1_TYPE_IDS.LSP7Tokens_SenderNotification, '0xcafecafecafecafe'], ); const executePayload = context.universalProfile.interface.encodeFunctionData('execute', [ OPERATION_TYPES.CALL, await universalReceiverDelegateDataUpdater.getAddress(), - ethers.parseEther('0'), + parseEther('0'), universalReceiverDelegatePayload, ]); @@ -412,7 +413,7 @@ export const shouldBehaveLikeLSP6ReentrancyScenarios = ( await context.keyManager.connect(context.mainController).execute(payload); - const result = await context.universalProfile['getData(bytes32)'](ethers.ZeroHash); + const result = await context.universalProfile['getData(bytes32)'](ZeroHash); expect(result).to.equal('0xaabbccdd'); }); diff --git a/tests/Reentrancy/LSP6/SingleExecuteToSingleExecuteRelayCall.test.ts b/tests/Reentrancy/LSP6/SingleExecuteToSingleExecuteRelayCall.test.ts index e00f21456..51c51ee03 100644 --- a/tests/Reentrancy/LSP6/SingleExecuteToSingleExecuteRelayCall.test.ts +++ b/tests/Reentrancy/LSP6/SingleExecuteToSingleExecuteRelayCall.test.ts @@ -1,8 +1,7 @@ import { expect } from 'chai'; -import { ethers } from 'hardhat'; // types -import { BytesLike } from 'ethers'; +import { BytesLike, hexlify, keccak256, parseEther, toUtf8Bytes } from 'ethers'; import { SingleReentrancyRelayer__factory, UniversalProfile__factory } from '../../../types'; // constants @@ -37,7 +36,7 @@ export const testSingleExecuteToSingleExecuteRelayCall = ( let executePayload: BytesLike; before(async () => { - context = await buildContext(ethers.parseEther('10')); + context = await buildContext(parseEther('10')); reentrancyContext = await buildReentrancyContext(context); const reentrantCallPayload = @@ -109,18 +108,18 @@ export const testSingleExecuteToSingleExecuteRelayCall = ( ); expect(await provider.getBalance(await context.universalProfile.getAddress())).to.equal( - ethers.parseEther('10'), + parseEther('10'), ); await context.keyManager.connect(reentrancyContext.caller).execute(executePayload); expect(await provider.getBalance(await context.universalProfile.getAddress())).to.equal( - ethers.parseEther('9'), + parseEther('9'), ); expect( await provider.getBalance(await reentrancyContext.singleReentarncyRelayer.getAddress()), - ).to.equal(ethers.parseEther('1')); + ).to.equal(parseEther('1')); }); }); @@ -182,8 +181,8 @@ export const testSingleExecuteToSingleExecuteRelayCall = ( await context.keyManager.connect(reentrancyContext.caller).execute(executePayload); - const hardcodedKey = ethers.keccak256(ethers.toUtf8Bytes('SomeRandomTextUsed')); - const hardcodedValue = ethers.hexlify(ethers.toUtf8Bytes('SomeRandomTextUsed')); + const hardcodedKey = keccak256(toUtf8Bytes('SomeRandomTextUsed')); + const hardcodedValue = hexlify(toUtf8Bytes('SomeRandomTextUsed')); expect(await context.universalProfile.getData(hardcodedKey)).to.equal(hardcodedValue); }); diff --git a/tests/utils/helpers.ts b/tests/utils/helpers.ts index bdcbc3fc2..56597a2a7 100644 --- a/tests/utils/helpers.ts +++ b/tests/utils/helpers.ts @@ -1,14 +1,26 @@ -import { BytesLike } from 'ethers'; +import { + BytesLike, + AbiCoder, + Wallet, + toBigInt, + zeroPadValue, + toBeHex, + getNumber, + concat, + solidityPacked, +} from 'ethers'; import hre from 'hardhat'; -const { ethers } = hre; +const { + ethers: { provider: hreProvider }, +} = hre; import { LSP6KeyManager } from '../../types/index.js'; // constants import { LSP25_VERSION } from '@lukso/lsp25-contracts'; import { EIP191Signer } from '@lukso/eip191-signer.js'; -export const abiCoder = ethers.AbiCoder.defaultAbiCoder(); -export const provider = ethers.provider; +export const abiCoder = AbiCoder.defaultAbiCoder(); +export const provider = hreProvider; export const AddressOffset = '000000000000000000000000'; export const EMPTY_PAYLOAD = '0x'; @@ -53,7 +65,7 @@ export function getRandomAddresses(count: number): string[] { for (let ii = 0; ii < count; ii++) { // addresses stored under ERC725Y storage have always lowercases character. // therefore, disable the checksum by converting to lowercase to avoid failing tests - const randomAddress = ethers.Wallet.createRandom().address.toLowerCase(); + const randomAddress = Wallet.createRandom().address.toLowerCase(); addresses.push(randomAddress); } @@ -61,34 +73,33 @@ export function getRandomAddresses(count: number): string[] { } export function combinePermissions(..._permissions: string[]) { - let result: bigint = ethers.toBigInt(0); + let result: bigint = toBigInt(0); _permissions.forEach((permission) => { - const permissionAsBN = ethers.toBigInt(permission); + const permissionAsBN = toBigInt(permission); result = result | permissionAsBN; }); - return ethers.zeroPadValue(ethers.toBeHex(result), 32); + return zeroPadValue(toBeHex(result), 32); } export function combineCallTypes(..._callTypes: string[]) { - let result: bigint = ethers.toBigInt(0); + let result: bigint = toBigInt(0); _callTypes.forEach((callType) => { - const callTypeAsBN = ethers.toBigInt(callType); + const callTypeAsBN = toBigInt(callType); result = result | callTypeAsBN; }); - return ethers.zeroPadValue(ethers.toBeHex(result), 4); + return zeroPadValue(toBeHex(result), 4); } export function encodeCompactBytesArray(inputKeys: BytesLike[]) { let compactBytesArray = '0x'; for (let i = 0; i < inputKeys.length; i++) { compactBytesArray += - ethers - .zeroPadValue(ethers.toBeHex(inputKeys[i].toString().substring(2).length / 2), 2) - .substring(2) + inputKeys[i].toString().substring(2); + zeroPadValue(toBeHex(inputKeys[i].toString().substring(2).length / 2), 2).substring(2) + + inputKeys[i].toString().substring(2); } return compactBytesArray; @@ -98,9 +109,7 @@ export function decodeCompactBytes(compactBytesArray: BytesLike) { let pointer = 2; const keysToExport: BytesLike[] = []; while (pointer < compactBytesArray.length) { - const length = ethers.getNumber( - '0x' + compactBytesArray.toString().substring(pointer, pointer + 4), - ); + const length = getNumber('0x' + compactBytesArray.toString().substring(pointer, pointer + 4)); keysToExport.push( '0x' + compactBytesArray.toString().substring(pointer + 4, pointer + 2 * (length + 2)), ); @@ -139,11 +148,11 @@ export function createValidityTimestamps( startingTimestamp: number, endingTimestamp: number, ): bigint { - const concatenatedHex = ethers.concat([ - ethers.zeroPadValue(ethers.toBeHex(startingTimestamp), 16), - ethers.zeroPadValue(ethers.toBeHex(endingTimestamp), 16), + const concatenatedHex = concat([ + zeroPadValue(toBeHex(startingTimestamp), 16), + zeroPadValue(toBeHex(endingTimestamp), 16), ]); - return ethers.toBigInt(concatenatedHex); + return toBigInt(concatenatedHex); } export async function signLSP6ExecuteRelayCall( @@ -163,7 +172,7 @@ export async function signLSP6ExecuteRelayCall( payload: _payload, }; - const encodedMessage = ethers.solidityPacked( + const encodedMessage = solidityPacked( ['uint256', 'uint256', 'uint256', 'uint256', 'uint256', 'bytes'], [ signedMessageParams.lsp25Version, diff --git a/tests/utils/tokens.ts b/tests/utils/tokens.ts index 37f4f807d..49e3bbb0d 100644 --- a/tests/utils/tokens.ts +++ b/tests/utils/tokens.ts @@ -1,6 +1,6 @@ -import * as ethers from 'ethers'; +import { zeroPadValue, toBeHex, toBigInt } from 'ethers'; import type { BigNumberish, BytesLike } from 'ethers'; export const tokenIdAsBytes32 = (tokenId: BigNumberish): BytesLike => { - return ethers.zeroPadValue(ethers.toBeHex(ethers.toBigInt(tokenId)), 32); + return zeroPadValue(toBeHex(toBigInt(tokenId)), 32); };