Skip to content

Commit

Permalink
test: repair tests that import helpers from root
Browse files Browse the repository at this point in the history
  • Loading branch information
b00ste committed Feb 28, 2024
1 parent bd41894 commit 971bf80
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 26 deletions.
81 changes: 58 additions & 23 deletions packages/lsp16-contracts/tests/LSP16UniversalFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);

Expand All @@ -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]);

Expand All @@ -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]);

Expand All @@ -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]);

Expand Down Expand Up @@ -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);

Expand All @@ -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, {
Expand All @@ -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,
Expand Down Expand Up @@ -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]);

Expand Down Expand Up @@ -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]);

Expand Down Expand Up @@ -379,16 +406,21 @@ 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,
]);

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]);

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
});

Expand Down Expand Up @@ -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);
});

Expand Down
15 changes: 13 additions & 2 deletions packages/lsp2-contracts/tests/LSP2UtilsLibrary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
20 changes: 19 additions & 1 deletion packages/lsp25-contracts/tests/LSP25MultiChannelNonce.test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 971bf80

Please sign in to comment.