From 971bf80e5a7882fa0f06b90c3dec3bc998a047da Mon Sep 17 00:00:00 2001 From: b00ste Date: Wed, 28 Feb 2024 20:05:12 +0200 Subject: [PATCH] test: repair tests that import helpers from root --- .../tests/LSP16UniversalFactory.test.ts | 81 +++++++++++++------ .../tests/LSP2UtilsLibrary.test.ts | 15 +++- .../tests/LSP25MultiChannelNonce.test.ts | 20 ++++- 3 files changed, 90 insertions(+), 26 deletions(-) diff --git a/packages/lsp16-contracts/tests/LSP16UniversalFactory.test.ts b/packages/lsp16-contracts/tests/LSP16UniversalFactory.test.ts index 7195284ba..bc4c5e987 100644 --- a/packages/lsp16-contracts/tests/LSP16UniversalFactory.test.ts +++ b/packages/lsp16-contracts/tests/LSP16UniversalFactory.test.ts @@ -23,10 +23,10 @@ import { FallbackContract__factory, } from '../types'; -import web3 from 'web3'; - -import { provider, AddressOffset } from '../../../tests/utils/helpers'; import { UniversalProfile } from '../../../types'; +import { AbiCoder, concat } from 'ethers'; + +const abiCoder = new AbiCoder(); const AccountBytecode = Account__factory.bytecode; const NonPayableConstructorBytecode = NonPayableContract__factory.bytecode; @@ -103,7 +103,10 @@ describe('UniversalFactory contract', () => { const randomAddress = ethers.Wallet.createRandom(); // Set the Owner as the ZeroAddress - const UPBytecode = AccountBytecode + AddressOffset + randomAddress.address.substring(2); + const UPBytecode = concat([ + AccountBytecode, + abiCoder.encode(['address'], [randomAddress.address]), + ]); const bytecodeHash = ethers.solidityPackedKeccak256(['bytes'], [UPBytecode]); @@ -126,7 +129,10 @@ describe('UniversalFactory contract', () => { const randomAddress = ethers.Wallet.createRandom(); - const UPBytecode = AccountBytecode + AddressOffset + randomAddress.address.substr(2); + const UPBytecode = concat([ + AccountBytecode, + abiCoder.encode(['address'], [randomAddress.address]), + ]); const bytecodeHash = ethers.solidityPackedKeccak256(['bytes'], [UPBytecode]); @@ -153,7 +159,10 @@ describe('UniversalFactory contract', () => { const salt1 = ethers.solidityPackedKeccak256(['string'], ['Salt1']); const salt2 = ethers.solidityPackedKeccak256(['string'], ['Salt2']); - const UPBytecode = AccountBytecode + AddressOffset + ethers.ZeroAddress.substr(2); + const UPBytecode = concat([ + AccountBytecode, + abiCoder.encode(['address'], [ethers.ZeroAddress]), + ]); const bytecodeHash = ethers.solidityPackedKeccak256(['bytes'], [UPBytecode]); @@ -179,12 +188,17 @@ describe('UniversalFactory contract', () => { it('should calculate a different address of a contract if the bytecode changed', async () => { const salt = ethers.solidityPackedKeccak256(['string'], ['Salt']); - const UPBytecode1 = AccountBytecode + AddressOffset + ethers.ZeroAddress.substr(2); + const UPBytecode1 = concat([ + AccountBytecode, + abiCoder.encode(['address'], [ethers.ZeroAddress]), + ]); const bytecodeHash1 = ethers.solidityPackedKeccak256(['bytes'], [UPBytecode1]); - const UPBytecode2 = - AccountBytecode + AddressOffset + 'cafecafecafecafecafecafecafecafecafecafe'; + const UPBytecode2 = concat([ + AccountBytecode, + abiCoder.encode(['address'], ['0xcafecafecafecafecafecafecafecafecafecafe']), + ]); const bytecodeHash2 = ethers.solidityPackedKeccak256(['bytes'], [UPBytecode2]); @@ -212,7 +226,10 @@ describe('UniversalFactory contract', () => { const randomAddress = ethers.Wallet.createRandom(); - const UPBytecode = AccountBytecode + AddressOffset + randomAddress.address.substring(2); + const UPBytecode = concat([ + AccountBytecode, + abiCoder.encode(['address'], [randomAddress.address]), + ]); await context.universalFactory.deployCreate2(UPBytecode, salt); @@ -224,8 +241,10 @@ describe('UniversalFactory contract', () => { it('should revert when sending value while deploying a non payable non-initializable contract', async () => { const salt = ethers.solidityPackedKeccak256(['string'], ['OtherSalt']); - const KMBytecode = - NonPayableConstructorBytecode + AddressOffset + ethers.ZeroAddress.substr(2); + const KMBytecode = concat([ + NonPayableConstructorBytecode, + abiCoder.encode(['address'], [ethers.ZeroAddress]), + ]); await expect( context.universalFactory.deployCreate2(KMBytecode, salt, { @@ -251,15 +270,17 @@ describe('UniversalFactory contract', () => { value: valueSent, }); - const balance = await provider.getBalance(contractCreated); + const balance = await ethers.provider.getBalance(contractCreated); expect(balance).to.equal(valueSent); }); it('should deploy an un-initializable contract and get the owner successfully', async () => { const salt = ethers.solidityPackedKeccak256(['string'], ['Salt']); - const UPBytecode = - AccountBytecode + AddressOffset + context.accounts.deployer3.address.substr(2); + const UPBytecode = concat([ + AccountBytecode, + abiCoder.encode(['address'], [context.accounts.deployer3.address]), + ]); const contractCreatedAddress = await context.universalFactory.deployCreate2.staticCall( UPBytecode, @@ -318,7 +339,10 @@ describe('UniversalFactory contract', () => { const salt1 = ethers.solidityPackedKeccak256(['string'], ['Salt1']); const salt2 = ethers.solidityPackedKeccak256(['string'], ['Salt2']); - const UPBytecode = AccountBytecode + AddressOffset + ethers.ZeroAddress.substr(2); + const UPBytecode = concat([ + AccountBytecode, + abiCoder.encode(['address'], [ethers.ZeroAddress]), + ]); const bytecodeHash = ethers.solidityPackedKeccak256(['bytes'], [UPBytecode]); @@ -348,7 +372,10 @@ describe('UniversalFactory contract', () => { it('should calculate a different address of a contract if the initializeCalldata changed', async () => { const salt = ethers.solidityPackedKeccak256(['string'], ['Salt']); - const UPBytecode = AccountBytecode + AddressOffset + ethers.ZeroAddress.substr(2); + const UPBytecode = concat([ + AccountBytecode, + abiCoder.encode(['address'], [ethers.ZeroAddress]), + ]); const bytecodeHash = ethers.solidityPackedKeccak256(['bytes'], [UPBytecode]); @@ -379,7 +406,10 @@ describe('UniversalFactory contract', () => { it('should calculate a different address of a contract if the bytecode changed', async () => { const salt = ethers.solidityPackedKeccak256(['string'], ['Salt']); - const UPBytecode1 = AccountBytecode + AddressOffset + ethers.ZeroAddress.substr(2); + const UPBytecode1 = concat([ + AccountBytecode, + abiCoder.encode(['address'], [ethers.ZeroAddress]), + ]); const initializeCallData = accountBaseContract.interface.encodeFunctionData('initialize', [ context.accounts.deployer1.address, @@ -387,8 +417,10 @@ describe('UniversalFactory contract', () => { const bytecodeHash1 = ethers.solidityPackedKeccak256(['bytes'], [UPBytecode1]); - const UPBytecode2 = - AccountBytecode + AddressOffset + 'cafecafecafecafecafecafecafecafecafecafe'; + const UPBytecode2 = concat([ + AccountBytecode, + abiCoder.encode(['address'], ['0xcafecafecafecafecafecafecafecafecafecafe']), + ]); const bytecodeHash2 = ethers.solidityPackedKeccak256(['bytes'], [UPBytecode2]); @@ -438,7 +470,10 @@ describe('UniversalFactory contract', () => { it('should revert when deploying an initializable contract with sending value unmatched to the msgValue arguments', async () => { const salt = ethers.solidityPackedKeccak256(['string'], ['Salt']); - const UPBytecode = AccountBytecode + AddressOffset + ethers.ZeroAddress.substr(2); + const UPBytecode = concat([ + AccountBytecode, + abiCoder.encode(['address'], [ethers.ZeroAddress]), + ]); const initializeCallData = accountBaseContract.interface.encodeFunctionData('initialize', [ context.accounts.deployer1.address, @@ -517,7 +552,7 @@ describe('UniversalFactory contract', () => { { value: sumValueSent }, ); - const balance = await provider.getBalance(contractCreated); + const balance = await ethers.provider.getBalance(contractCreated); expect(balance).to.equal(sumValueSent); }); @@ -884,7 +919,7 @@ describe('UniversalFactory contract', () => { value: valueSent, }); - const balance = await provider.getBalance(contractCreated); + const balance = await ethers.provider.getBalance(contractCreated); expect(balance).to.equal(valueSent); }); diff --git a/packages/lsp2-contracts/tests/LSP2UtilsLibrary.test.ts b/packages/lsp2-contracts/tests/LSP2UtilsLibrary.test.ts index 3b93fd750..2920a232a 100644 --- a/packages/lsp2-contracts/tests/LSP2UtilsLibrary.test.ts +++ b/packages/lsp2-contracts/tests/LSP2UtilsLibrary.test.ts @@ -2,8 +2,19 @@ import { expect } from 'chai'; import { ethers } from 'hardhat'; import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'; import { LSP2UtilsLibraryTester, LSP2UtilsLibraryTester__factory } from '../types'; - -import { encodeCompactBytesArray } from '../../../tests/utils/helpers'; +import { BytesLike } from 'ethers'; + +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); + } + + return compactBytesArray; +} describe('LSP2Utils', () => { let accounts: SignerWithAddress[]; diff --git a/packages/lsp25-contracts/tests/LSP25MultiChannelNonce.test.ts b/packages/lsp25-contracts/tests/LSP25MultiChannelNonce.test.ts index 607d6253d..01dfc5121 100644 --- a/packages/lsp25-contracts/tests/LSP25MultiChannelNonce.test.ts +++ b/packages/lsp25-contracts/tests/LSP25MultiChannelNonce.test.ts @@ -1,11 +1,29 @@ import { ethers } from 'hardhat'; import { expect } from 'chai'; import { LSP25_VERSION } from '../constants'; -import { LOCAL_PRIVATE_KEYS } from '../../../tests/utils/helpers'; import { EIP191Signer } from '@lukso/eip191-signer.js'; import { LSP25MultiChannelNonceTester, LSP25MultiChannelNonceTester__factory } from '../types'; +/** + * Private keys for the accounts used in the tests. + * These are the private keys for the accounts generated by the hardhat node (local blockchain). + * The private keys are used to sign messages with lsp6-signers.js library. + * + * WARNING! These private keys and their related accounts are publicly known and should never be used in production. + * Any funds sent to them on Mainnet or any other live network WILL BE LOST. + */ +const LOCAL_PRIVATE_KEYS = { + ACCOUNT0: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80', + ACCOUNT1: '0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d', + ACCOUNT2: '0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a', + ACCOUNT3: '0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6', + ACCOUNT4: '0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a', + ACCOUNT5: '0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba', + ACCOUNT6: '0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e', + ACCOUNT7: '0x030ab56c9834360e1c0dba6b9a955b6e127f3166cda462c2472f67e1ba773053', +}; + describe('LSP25MultiChannelNonce', () => { let contract: LSP25MultiChannelNonceTester; let account;