From 77bb2c526c9c09f08112b25866953fef05e1a71f Mon Sep 17 00:00:00 2001 From: CJ42 Date: Tue, 20 Feb 2024 20:14:33 +0000 Subject: [PATCH] chore: fix remaining tests --- .../LSP17ExtendableTokens.behaviour.ts | 36 +++++++++---------- .../LSP17Extensions/helpers/Create2Factory.ts | 23 ++++++------ tests/LSP17Extensions/helpers/UserOp.ts | 31 ++++++++-------- tests/LSP17Extensions/helpers/utils.ts | 4 +-- .../LSP6KeyManager.behaviour.ts | 2 +- .../LSP6KeyManager/LSP6KeyManagerInit.test.ts | 2 +- .../Relay/MultiChannelNonce.test.ts | 2 +- .../SetData/PermissionSetData.test.ts | 4 +-- .../LSP8Mintable.behaviour.ts | 10 +++--- tests/Reentrancy/LSP6/LSP6Reentrancy.test.ts | 4 +-- 10 files changed, 62 insertions(+), 56 deletions(-) diff --git a/tests/LSP17ContractExtension/LSP17ExtendableTokens.behaviour.ts b/tests/LSP17ContractExtension/LSP17ExtendableTokens.behaviour.ts index 1fe2a037f..d5f2511bc 100644 --- a/tests/LSP17ContractExtension/LSP17ExtendableTokens.behaviour.ts +++ b/tests/LSP17ContractExtension/LSP17ExtendableTokens.behaviour.ts @@ -155,7 +155,7 @@ export const shouldBehaveLikeLSP17 = (buildContext: () => Promise { await expect( context.accounts[0].sendTransaction({ - to: context.contract.address, + to: await context.contract.getAddress(), data: notExistingFunctionSignature, }), ) @@ -172,7 +172,7 @@ export const shouldBehaveLikeLSP17 = (buildContext: () => Promise Promise Promise Promise Promise Promise Promise Promise Promise { await expect( context.accounts[0].sendTransaction({ - to: context.contract.address, + to: await context.contract.getAddress(), data: emitEventFunctionSelector, value: 0, }), @@ -406,7 +406,7 @@ export const shouldBehaveLikeLSP17 = (buildContext: () => Promise { const returnValue = await provider.call({ from: context.accounts[0].address, - to: context.contract.address, + to: await context.contract.getAddress(), data: nameFunctionSelector, }); @@ -428,7 +428,7 @@ export const shouldBehaveLikeLSP17 = (buildContext: () => Promise { const returnValue = await provider.call({ from: context.accounts[0].address, - to: context.contract.address, + to: await context.contract.getAddress(), data: ageFunctionSelector, }); @@ -459,7 +459,7 @@ export const shouldBehaveLikeLSP17 = (buildContext: () => Promise Promise Promise Promise Promise { await expect( context.accounts[0].sendTransaction({ - to: context.contract.address, + to: await context.contract.getAddress(), data: '0x01', }), ).to.be.revertedWithCustomError(context.contract, 'InvalidFunctionSelector'); diff --git a/tests/LSP17Extensions/helpers/Create2Factory.ts b/tests/LSP17Extensions/helpers/Create2Factory.ts index f3efeff45..651cf4657 100644 --- a/tests/LSP17Extensions/helpers/Create2Factory.ts +++ b/tests/LSP17Extensions/helpers/Create2Factory.ts @@ -1,5 +1,5 @@ // from: https://github.com/Arachnid/deterministic-deployment-proxy -import { BigNumberish, JsonRpcProvider, Signer, toBeHex } from 'ethers'; +import { BigNumberish, JsonRpcProvider, Signer, ethers, toBeHex } from 'ethers'; import { getBytes, concat, zeroPadValue, keccak256 } from 'ethers'; import { Provider } from '@ethersproject/providers'; import { TransactionRequest } from '@ethersproject/abstract-provider'; @@ -51,24 +51,25 @@ export class Create2Factory { data: this.getDeployTransactionCallData(initCode, salt), }; if (gasLimit === 'estimate') { - gasLimit = await this.signer.estimateGas(deployTx); + gasLimit = await (await this.signer).estimateGas(deployTx); } if (gasLimit === undefined) { - gasLimit = + gasLimit = ethers.toBigInt( getBytes(initCode) .map((x) => (x === 0 ? 4 : 16)) .reduce((sum, x) => sum + x) + - (200 * initCode.length) / 2 + // actual is usually somewhat smaller (only deposited code, not entire constructor) - 6 * Math.ceil(initCode.length / 64) + // hash price. very minor compared to deposit costs - 32000 + - 21000; + (200 * initCode.length) / 2 + // actual is usually somewhat smaller (only deposited code, not entire constructor) + 6 * Math.ceil(initCode.length / 64) + // hash price. very minor compared to deposit costs + 32000 + + 21000, + ); // deployer requires some extra gas - gasLimit = Math.floor((gasLimit * 64) / 63); + gasLimit = ethers.toBigInt(Math.floor((ethers.toNumber(gasLimit) * 64) / 63)); } - const ret = await this.signer.sendTransaction({ ...deployTx, gasLimit }); + const ret = await (await this.signer).sendTransaction({ ...deployTx, gasLimit }); await ret.wait(); if ((await this.provider.getCode(addr).then((code) => code.length)) === 2) { throw new Error('failed to deploy'); @@ -102,7 +103,9 @@ export class Create2Factory { if (await this._isFactoryDeployed()) { return; } - await (signer ?? this.signer).sendTransaction({ + await ( + await (signer ?? this.signer) + ).sendTransaction({ to: Create2Factory.factoryDeployer, value: BigInt(Create2Factory.factoryDeploymentFee), }); diff --git a/tests/LSP17Extensions/helpers/UserOp.ts b/tests/LSP17Extensions/helpers/UserOp.ts index 3ef0dd21a..28eb97ca2 100644 --- a/tests/LSP17Extensions/helpers/UserOp.ts +++ b/tests/LSP17Extensions/helpers/UserOp.ts @@ -1,4 +1,4 @@ -import { getBytes, dataSlice, keccak256 } from 'ethers'; +import { getBytes, dataSlice, keccak256, BytesLike } from 'ethers'; import { Wallet } from 'ethers'; import { AddressZero, callDataCost } from './utils'; import { ecsign, toRpcSig, keccak256 as keccak256_buffer } from 'ethereumjs-util'; @@ -7,6 +7,7 @@ import { EntryPoint } from '@account-abstraction/contracts'; import { ethers } from 'ethers'; import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'; import * as typ from './solidityTypes'; +import { ethers as hreEther } from 'hardhat'; export interface UserOperation { sender: typ.address; @@ -41,14 +42,14 @@ export function packUserOp(op: UserOperation, forSignature = true): string { [ op.sender, op.nonce, - keccak256(op.initCode), - keccak256(op.callData), + keccak256(op.initCode as BytesLike), + keccak256(op.callData as BytesLike), op.callGasLimit, op.verificationGasLimit, op.preVerificationGas, op.maxFeePerGas, op.maxPriorityFeePerGas, - keccak256(op.paymasterAndData), + keccak256(op.paymasterAndData as BytesLike), ], ); } else { @@ -163,10 +164,10 @@ export async function fillUserOp( entryPoint?: EntryPoint, ): Promise { const op1 = { ...op }; - const provider = entryPoint?.provider; + const provider = hreEther.provider; if (op.initCode != null) { - const initAddr = dataSlice(op1.initCode, 0, 20); - const initCallData = dataSlice(op1.initCode, 20); + const initAddr = dataSlice(op1.initCode as BytesLike, 0, 20); + const initCallData = dataSlice(op1.initCode as BytesLike, 20); if (op1.nonce == null) op1.nonce = 0; if (op1.sender == null) { if (initAddr.toLowerCase() === Create2Factory.contractAddress.toLowerCase()) { @@ -176,7 +177,7 @@ export async function fillUserOp( } else { if (provider == null) throw new Error('no entrypoint/provider'); op1.sender = await entryPoint.callStatic - .getSenderAddress(op1.initCode) + .getSenderAddress(op1.initCode as BytesLike) .catch((e) => e.errorArgs.sender); } } @@ -208,7 +209,7 @@ export async function fillUserOp( const gasEtimated = await provider.estimateGas({ from: entryPoint?.target, to: op1.sender, - data: op1.callData, + data: ethers.hexlify(op1.callData as BytesLike), }); op1.callGasLimit = gasEtimated; @@ -216,9 +217,9 @@ export async function fillUserOp( if (op1.maxFeePerGas == null) { if (provider == null) throw new Error('must have entryPoint to autofill maxFeePerGas'); const block = await provider.getBlock('latest'); - op1.maxFeePerGas = block.baseFeePerGas.add( - op1.maxPriorityFeePerGas ?? DefaultsForUserOp.maxPriorityFeePerGas, - ); + op1.maxFeePerGas = + block.baseFeePerGas + + BigInt(op1.maxPriorityFeePerGas ?? DefaultsForUserOp.maxPriorityFeePerGas); } if (op1.maxPriorityFeePerGas == null) { @@ -237,11 +238,13 @@ export async function fillAndSign( signer: SignerWithAddress, entryPoint?: EntryPoint, ): Promise { - const provider = entryPoint?.provider; + const provider = hreEther.provider; 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, chainId)); + const message = getBytes( + getUserOpHash(op2, entryPoint.target as string, ethers.toNumber(chainId)), + ); return { ...op2, diff --git a/tests/LSP17Extensions/helpers/utils.ts b/tests/LSP17Extensions/helpers/utils.ts index 5af941741..cedceee39 100644 --- a/tests/LSP17Extensions/helpers/utils.ts +++ b/tests/LSP17Extensions/helpers/utils.ts @@ -12,11 +12,11 @@ export function callDataCost(data: string): number { } export async function deployEntryPoint(provider = ethers.provider): Promise { - const create2factory = new Create2Factory(provider); + const create2factory = new Create2Factory(provider as any); const addr = await create2factory.deploy( EntryPoint__factory.bytecode, 0, - process.env.COVERAGE != null ? 20e6 : 8e6, + process.env.COVERAGE != null ? BigInt(20e6) : BigInt(8e6), ); return EntryPoint__factory.connect(addr, await provider.getSigner()); } diff --git a/tests/LSP6KeyManager/LSP6KeyManager.behaviour.ts b/tests/LSP6KeyManager/LSP6KeyManager.behaviour.ts index ae1b2f3d8..c3fdac0a5 100644 --- a/tests/LSP6KeyManager/LSP6KeyManager.behaviour.ts +++ b/tests/LSP6KeyManager/LSP6KeyManager.behaviour.ts @@ -154,7 +154,7 @@ export const shouldInitializeLikeLSP6 = (buildContext: () => Promise { - const account = await context.keyManager.target(); + const account = await context.keyManager['target()'].staticCall(); expect(account).to.equal(await context.universalProfile.getAddress()); }); }); diff --git a/tests/LSP6KeyManager/LSP6KeyManagerInit.test.ts b/tests/LSP6KeyManager/LSP6KeyManagerInit.test.ts index 04168dd5b..4ff2a9285 100644 --- a/tests/LSP6KeyManager/LSP6KeyManagerInit.test.ts +++ b/tests/LSP6KeyManager/LSP6KeyManagerInit.test.ts @@ -38,7 +38,7 @@ describe('LSP6KeyManager with proxy', () => { const accounts = await ethers.getSigners(); const keyManagerBaseContract = await new LSP6KeyManagerInit__factory(accounts[0]).deploy(); - const linkedTarget = await keyManagerBaseContract.target(); + const linkedTarget = await keyManagerBaseContract['target()'].staticCall(); expect(linkedTarget).to.equal(ethers.ZeroAddress); }); diff --git a/tests/LSP6KeyManager/Relay/MultiChannelNonce.test.ts b/tests/LSP6KeyManager/Relay/MultiChannelNonce.test.ts index 98dc65c3e..6513383a7 100644 --- a/tests/LSP6KeyManager/Relay/MultiChannelNonce.test.ts +++ b/tests/LSP6KeyManager/Relay/MultiChannelNonce.test.ts @@ -53,7 +53,7 @@ export const shouldBehaveLikeMultiChannelNonce = (buildContext: () => Promise { it('should revert', async () => { - const channelId = ethers.toBigInt(2 ** 129); + const channelId = ethers.toBigInt('0xffffffffffffffffffffffffffffffffff'); await expect(context.keyManager.getNonce(signer.address, channelId)).to.be.revertedWithPanic; }); diff --git a/tests/LSP6KeyManager/SetData/PermissionSetData.test.ts b/tests/LSP6KeyManager/SetData/PermissionSetData.test.ts index 3cd723028..5cf19926e 100644 --- a/tests/LSP6KeyManager/SetData/PermissionSetData.test.ts +++ b/tests/LSP6KeyManager/SetData/PermissionSetData.test.ts @@ -771,7 +771,7 @@ export const shouldBehaveLikePermissionSetData = (buildContext: () => Promise Promise