diff --git a/test/evm/hardhat/MerkleLib.utils.ts b/test/evm/hardhat/MerkleLib.utils.ts index 2508d7398..39e6aa3a6 100644 --- a/test/evm/hardhat/MerkleLib.utils.ts +++ b/test/evm/hardhat/MerkleLib.utils.ts @@ -7,7 +7,7 @@ import { toBNWeiWithDecimals, createRandomBytes32, Contract, - hexZeroPadAddress, + addressToBytes, } from "../../../utils/utils"; import { amountToReturn, repaymentChainId } from "./constants"; import { MerkleTree } from "../../../utils/MerkleTree"; @@ -110,7 +110,7 @@ export async function constructSingleRelayerRefundTree(l2Token: Contract | Strin const leaves = buildRelayerRefundLeaves( [destinationChainId], // Destination chain ID. [amountToReturn], // amountToReturn. - [hexZeroPadAddress(l2Token as string)], // l2Token. + [addressToBytes(l2Token as string)], // l2Token. [[]], // refundAddresses. [[]] // refundAmounts. ); diff --git a/test/evm/hardhat/SpokePool.Admin.ts b/test/evm/hardhat/SpokePool.Admin.ts index 955c10e13..f51adf376 100644 --- a/test/evm/hardhat/SpokePool.Admin.ts +++ b/test/evm/hardhat/SpokePool.Admin.ts @@ -1,11 +1,4 @@ -import { - expect, - ethers, - Contract, - SignerWithAddress, - getContractFactory, - hexZeroPadAddress, -} from "../../../utils/utils"; +import { expect, ethers, Contract, SignerWithAddress, getContractFactory, addressToBytes } from "../../../utils/utils"; import { hre } from "../../../utils/utils.hre"; import { spokePoolFixture } from "./fixtures/SpokePool.Fixture"; import { destinationChainId, mockRelayerRefundRoot, mockSlowRelayRoot } from "./constants"; @@ -30,7 +23,7 @@ describe("SpokePool Admin Functions", async function () { await expect(spokePool.connect(owner).setEnableRoute(erc20.address, destinationChainId, true)) .to.emit(spokePool, "EnabledDepositRoute") .withArgs(erc20.address, destinationChainId, true); - expect(await spokePool.enabledDepositRoutes(hexZeroPadAddress(erc20.address), destinationChainId)).to.equal(true); + expect(await spokePool.enabledDepositRoutes(addressToBytes(erc20.address), destinationChainId)).to.equal(true); }); it("Pause deposits", async function () { diff --git a/test/evm/hardhat/SpokePool.Deposit.ts b/test/evm/hardhat/SpokePool.Deposit.ts index 4698dbd3a..135744d01 100644 --- a/test/evm/hardhat/SpokePool.Deposit.ts +++ b/test/evm/hardhat/SpokePool.Deposit.ts @@ -8,8 +8,7 @@ import { toWei, randomAddress, BigNumber, - hexZeroPadAddressLowercase, - hexZeroPadAddress, + addressToBytes, bytes32ToAddress, } from "../../../utils/utils"; import { @@ -108,8 +107,8 @@ describe("SpokePool Depositor Logic", async function () { ) .to.emit(spokePool, "V3FundsDeposited") .withArgs( - hexZeroPadAddressLowercase(erc20.address), - hexZeroPadAddressLowercase(ZERO_ADDRESS), + addressToBytes(erc20.address), + addressToBytes(ZERO_ADDRESS), amountToDeposit, amountReceived, destinationChainId, @@ -117,9 +116,9 @@ describe("SpokePool Depositor Logic", async function () { quoteTimestamp, MAX_UINT32, 0, - hexZeroPadAddressLowercase(depositor.address), - hexZeroPadAddressLowercase(recipient.address), - hexZeroPadAddressLowercase(ZERO_ADDRESS), + addressToBytes(depositor.address), + addressToBytes(recipient.address), + addressToBytes(ZERO_ADDRESS), "0x" ); @@ -148,8 +147,8 @@ describe("SpokePool Depositor Logic", async function () { ) .to.emit(spokePool, "V3FundsDeposited") .withArgs( - hexZeroPadAddressLowercase(erc20.address), - hexZeroPadAddressLowercase(ZERO_ADDRESS), + addressToBytes(erc20.address), + addressToBytes(ZERO_ADDRESS), amountToDeposit, amountReceived, destinationChainId, @@ -157,9 +156,9 @@ describe("SpokePool Depositor Logic", async function () { quoteTimestamp, BigNumber.from("0xFFFFFFFF"), 0, - hexZeroPadAddressLowercase(newDepositor), // Depositor is overridden. - hexZeroPadAddressLowercase(recipient.address), - hexZeroPadAddressLowercase(ZERO_ADDRESS), + addressToBytes(newDepositor), // Depositor is overridden. + addressToBytes(recipient.address), + addressToBytes(ZERO_ADDRESS), "0x" ); }); @@ -374,16 +373,16 @@ describe("SpokePool Depositor Logic", async function () { _isAddressOverload = false ) { return [ - _isAddressOverload ? bytes32ToAddress(_relayData.depositor) : hexZeroPadAddress(_relayData.depositor), - _isAddressOverload ? bytes32ToAddress(_relayData.recipient) : hexZeroPadAddress(_relayData.recipient), - _isAddressOverload ? bytes32ToAddress(_relayData.inputToken) : hexZeroPadAddress(_relayData.inputToken), - _isAddressOverload ? bytes32ToAddress(_relayData.outputToken) : hexZeroPadAddress(_relayData.outputToken), + _isAddressOverload ? bytes32ToAddress(_relayData.depositor) : addressToBytes(_relayData.depositor), + _isAddressOverload ? bytes32ToAddress(_relayData.recipient) : addressToBytes(_relayData.recipient), + _isAddressOverload ? bytes32ToAddress(_relayData.inputToken) : addressToBytes(_relayData.inputToken), + _isAddressOverload ? bytes32ToAddress(_relayData.outputToken) : addressToBytes(_relayData.outputToken), _relayData.inputAmount, _relayData.outputAmount, _destinationChainId, _isAddressOverload ? bytes32ToAddress(_relayData.exclusiveRelayer) - : hexZeroPadAddress(_relayData.exclusiveRelayer), + : addressToBytes(_relayData.exclusiveRelayer), _quoteTimestamp, _relayData.fillDeadline, _relayData.exclusivityDeadline, @@ -392,11 +391,11 @@ describe("SpokePool Depositor Logic", async function () { } beforeEach(async function () { relayData = { - depositor: hexZeroPadAddress(depositor.address), - recipient: hexZeroPadAddress(recipient.address), - exclusiveRelayer: hexZeroPadAddress(ZERO_ADDRESS), - inputToken: hexZeroPadAddress(erc20.address), - outputToken: hexZeroPadAddress(randomAddress()), + depositor: addressToBytes(depositor.address), + recipient: addressToBytes(recipient.address), + exclusiveRelayer: addressToBytes(ZERO_ADDRESS), + inputToken: addressToBytes(erc20.address), + outputToken: addressToBytes(randomAddress()), inputAmount: amountToDeposit, outputAmount: amountToDeposit.sub(19), originChainId: originChainId, @@ -511,14 +510,14 @@ describe("SpokePool Depositor Logic", async function () { spokePool .connect(depositor) [depositV3NowBytes]( - hexZeroPadAddress(relayData.depositor), - hexZeroPadAddress(relayData.recipient), - hexZeroPadAddress(relayData.inputToken), - hexZeroPadAddress(relayData.outputToken), + addressToBytes(relayData.depositor), + addressToBytes(relayData.recipient), + addressToBytes(relayData.inputToken), + addressToBytes(relayData.outputToken), relayData.inputAmount, relayData.outputAmount, destinationChainId, - hexZeroPadAddress(relayData.exclusiveRelayer), + addressToBytes(relayData.exclusiveRelayer), fillDeadlineOffset, exclusivityDeadline, relayData.message @@ -526,8 +525,8 @@ describe("SpokePool Depositor Logic", async function () { ) .to.emit(spokePool, "V3FundsDeposited") .withArgs( - hexZeroPadAddressLowercase(relayData.inputToken), - hexZeroPadAddressLowercase(relayData.outputToken), + addressToBytes(relayData.inputToken), + addressToBytes(relayData.outputToken), relayData.inputAmount, relayData.outputAmount, destinationChainId, @@ -536,9 +535,9 @@ describe("SpokePool Depositor Logic", async function () { currentTime, // quoteTimestamp should be current time currentTime + fillDeadlineOffset, // fillDeadline should be current time + offset currentTime, - hexZeroPadAddressLowercase(relayData.depositor), - hexZeroPadAddressLowercase(relayData.recipient), - hexZeroPadAddressLowercase(relayData.exclusiveRelayer), + addressToBytes(relayData.depositor), + addressToBytes(relayData.recipient), + addressToBytes(relayData.exclusiveRelayer), relayData.message ); }); @@ -565,8 +564,8 @@ describe("SpokePool Depositor Logic", async function () { ) .to.emit(spokePool, "V3FundsDeposited") .withArgs( - hexZeroPadAddressLowercase(relayData.inputToken), - hexZeroPadAddressLowercase(relayData.outputToken), + addressToBytes(relayData.inputToken), + addressToBytes(relayData.outputToken), relayData.inputAmount, relayData.outputAmount, destinationChainId, @@ -575,9 +574,9 @@ describe("SpokePool Depositor Logic", async function () { currentTime, // quoteTimestamp should be current time currentTime + fillDeadlineOffset, // fillDeadline should be current time + offset currentTime, - hexZeroPadAddressLowercase(relayData.depositor), - hexZeroPadAddressLowercase(relayData.recipient), - hexZeroPadAddressLowercase(relayData.exclusiveRelayer), + addressToBytes(relayData.depositor), + addressToBytes(relayData.recipient), + addressToBytes(relayData.exclusiveRelayer), relayData.message ); }); @@ -586,8 +585,8 @@ describe("SpokePool Depositor Logic", async function () { await expect(spokePool.connect(depositor)[depositV3Bytes](...depositArgs)) .to.emit(spokePool, "V3FundsDeposited") .withArgs( - hexZeroPadAddressLowercase(relayData.inputToken), - hexZeroPadAddressLowercase(relayData.outputToken), + addressToBytes(relayData.inputToken), + addressToBytes(relayData.outputToken), relayData.inputAmount, relayData.outputAmount, destinationChainId, @@ -596,9 +595,9 @@ describe("SpokePool Depositor Logic", async function () { quoteTimestamp, relayData.fillDeadline, currentTime, - hexZeroPadAddressLowercase(relayData.depositor), - hexZeroPadAddressLowercase(relayData.recipient), - hexZeroPadAddressLowercase(relayData.exclusiveRelayer), + addressToBytes(relayData.depositor), + addressToBytes(relayData.recipient), + addressToBytes(relayData.exclusiveRelayer), relayData.message ); }); @@ -617,8 +616,8 @@ describe("SpokePool Depositor Logic", async function () { ) .to.emit(spokePool, "V3FundsDeposited") .withArgs( - hexZeroPadAddressLowercase(relayData.inputToken), - hexZeroPadAddressLowercase(relayData.outputToken), + addressToBytes(relayData.inputToken), + addressToBytes(relayData.outputToken), relayData.inputAmount, relayData.outputAmount, destinationChainId, @@ -627,9 +626,9 @@ describe("SpokePool Depositor Logic", async function () { relayData.fillDeadline, currentTime, // New depositor - hexZeroPadAddressLowercase(newDepositor), - hexZeroPadAddressLowercase(relayData.recipient), - hexZeroPadAddressLowercase(relayData.exclusiveRelayer), + addressToBytes(newDepositor), + addressToBytes(relayData.recipient), + addressToBytes(relayData.exclusiveRelayer), relayData.message ); expect(await erc20.balanceOf(depositor.address)).to.equal(balanceBefore.sub(amountToDeposit)); @@ -658,15 +657,15 @@ describe("SpokePool Depositor Logic", async function () { depositId, originChainId, updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage ); await spokePool[verifyUpdateV3DepositMessageBytes]( - hexZeroPadAddress(depositor.address), + addressToBytes(depositor.address), depositId, originChainId, updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, signature ); @@ -674,11 +673,11 @@ describe("SpokePool Depositor Logic", async function () { // Reverts if passed in depositor is the signer or if signature is incorrect await expect( spokePool[verifyUpdateV3DepositMessageBytes]( - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), depositId, originChainId, updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, signature ) @@ -690,16 +689,16 @@ describe("SpokePool Depositor Logic", async function () { depositId + 1, originChainId, updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage ); await expect( spokePool[verifyUpdateV3DepositMessageBytes]( - hexZeroPadAddress(depositor.address), + addressToBytes(depositor.address), depositId, originChainId, updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, invalidSignature ) @@ -713,17 +712,17 @@ describe("SpokePool Depositor Logic", async function () { depositId, spokePoolChainId, updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage ); await expect( spokePool .connect(depositor) [speedUpV3DepositBytes]( - hexZeroPadAddress(depositor.address), + addressToBytes(depositor.address), depositId, updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, expectedSignature ) @@ -732,8 +731,8 @@ describe("SpokePool Depositor Logic", async function () { .withArgs( updatedOutputAmount, depositId, - hexZeroPadAddressLowercase(depositor.address), - hexZeroPadAddressLowercase(updatedRecipient), + addressToBytes(depositor.address), + addressToBytes(updatedRecipient), updatedMessage, expectedSignature ); @@ -745,16 +744,16 @@ describe("SpokePool Depositor Logic", async function () { depositId, otherChainId, updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage ); await expect( spokePool[verifyUpdateV3DepositMessageBytes]( - hexZeroPadAddress(depositor.address), + addressToBytes(depositor.address), depositId, otherChainId, updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, invalidSignatureForChain ) @@ -763,10 +762,10 @@ describe("SpokePool Depositor Logic", async function () { spokePool .connect(depositor) [speedUpV3DepositBytes]( - hexZeroPadAddress(depositor.address), + addressToBytes(depositor.address), depositId, updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, invalidSignatureForChain ) @@ -815,8 +814,8 @@ describe("SpokePool Depositor Logic", async function () { .withArgs( updatedOutputAmount, depositId, - hexZeroPadAddressLowercase(depositor.address), - hexZeroPadAddressLowercase(updatedRecipient), + addressToBytes(depositor.address), + addressToBytes(updatedRecipient), updatedMessage, signature ); diff --git a/test/evm/hardhat/SpokePool.ExecuteRootBundle.ts b/test/evm/hardhat/SpokePool.ExecuteRootBundle.ts index 76af268d8..c0326d1ca 100644 --- a/test/evm/hardhat/SpokePool.ExecuteRootBundle.ts +++ b/test/evm/hardhat/SpokePool.ExecuteRootBundle.ts @@ -6,8 +6,7 @@ import { Contract, ethers, BigNumber, - hexZeroPadAddress, - hexZeroPadAddressLowercase, + addressToBytes, } from "../../../utils/utils"; import * as consts from "./constants"; import { spokePoolFixture } from "./fixtures/SpokePool.Fixture"; @@ -22,8 +21,8 @@ async function constructSimpleTree(l2Token: Contract, destinationChainId: number const leaves = buildRelayerRefundLeaves( [destinationChainId, destinationChainId], // Destination chain ID. [consts.amountToReturn, toBN(0)], // amountToReturn. - [hexZeroPadAddress(l2Token.address), hexZeroPadAddress(l2Token.address)], // l2Token. - [[hexZeroPadAddress(relayer.address), hexZeroPadAddress(rando.address)], []], // refundAddresses. + [addressToBytes(l2Token.address), addressToBytes(l2Token.address)], // l2Token. + [[addressToBytes(relayer.address), addressToBytes(rando.address)], []], // refundAddresses. [[consts.amountToRelay, consts.amountToRelay], []] // refundAmounts. ); const leavesRefundAmount = leaves @@ -63,7 +62,7 @@ describe("SpokePool Root Bundle Execution", function () { // Check events. let relayTokensEvents = await spokePool.queryFilter(spokePool.filters.ExecutedRelayerRefundRoot()); - expect(relayTokensEvents[0].args?.l2TokenAddress).to.equal(hexZeroPadAddressLowercase(destErc20.address)); + expect(relayTokensEvents[0].args?.l2TokenAddress).to.equal(addressToBytes(destErc20.address)); expect(relayTokensEvents[0].args?.leafId).to.equal(0); expect(relayTokensEvents[0].args?.chainId).to.equal(destinationChainId); expect(relayTokensEvents[0].args?.amountToReturn).to.equal(consts.amountToReturn); @@ -71,8 +70,8 @@ describe("SpokePool Root Bundle Execution", function () { [consts.amountToRelay, consts.amountToRelay].map((v) => v.toString()) ); expect(relayTokensEvents[0].args?.refundAddresses).to.deep.equal([ - hexZeroPadAddressLowercase(relayer.address), - hexZeroPadAddressLowercase(rando.address), + addressToBytes(relayer.address), + addressToBytes(rando.address), ]); // Should emit TokensBridged event if amountToReturn is positive. @@ -141,8 +140,8 @@ describe("SpokePool Root Bundle Execution", function () { toBN(1), [consts.amountToRelay, consts.amountToRelay, toBN(0)], 0, - hexZeroPadAddress(destErc20.address), - [hexZeroPadAddress(relayer.address), hexZeroPadAddress(rando.address)] + addressToBytes(destErc20.address), + [addressToBytes(relayer.address), addressToBytes(rando.address)] ) ).to.be.revertedWith("InvalidMerkleLeaf"); }); @@ -151,7 +150,7 @@ describe("SpokePool Root Bundle Execution", function () { await expect( spokePool .connect(dataWorker) - .distributeRelayerRefunds(destinationChainId, toBN(1), [], 0, hexZeroPadAddress(destErc20.address), []) + .distributeRelayerRefunds(destinationChainId, toBN(1), [], 0, addressToBytes(destErc20.address), []) ) .to.emit(spokePool, "BridgedToHubPool") .withArgs(toBN(1), destErc20.address); @@ -160,10 +159,10 @@ describe("SpokePool Root Bundle Execution", function () { await expect( spokePool .connect(dataWorker) - .distributeRelayerRefunds(destinationChainId, toBN(1), [], 0, hexZeroPadAddress(destErc20.address), []) + .distributeRelayerRefunds(destinationChainId, toBN(1), [], 0, addressToBytes(destErc20.address), []) ) .to.emit(spokePool, "TokensBridged") - .withArgs(toBN(1), destinationChainId, 0, hexZeroPadAddressLowercase(destErc20.address), dataWorker.address); + .withArgs(toBN(1), destinationChainId, 0, addressToBytes(destErc20.address), dataWorker.address); }); }); describe("amountToReturn = 0", function () { @@ -171,14 +170,14 @@ describe("SpokePool Root Bundle Execution", function () { await expect( spokePool .connect(dataWorker) - .distributeRelayerRefunds(destinationChainId, toBN(0), [], 0, hexZeroPadAddress(destErc20.address), []) + .distributeRelayerRefunds(destinationChainId, toBN(0), [], 0, addressToBytes(destErc20.address), []) ).to.not.emit(spokePool, "BridgedToHubPool"); }); it("does not emit TokensBridged", async function () { await expect( spokePool .connect(dataWorker) - .distributeRelayerRefunds(destinationChainId, toBN(0), [], 0, hexZeroPadAddress(destErc20.address), []) + .distributeRelayerRefunds(destinationChainId, toBN(0), [], 0, addressToBytes(destErc20.address), []) ).to.not.emit(spokePool, "TokensBridged"); }); }); @@ -192,8 +191,8 @@ describe("SpokePool Root Bundle Execution", function () { toBN(1), [consts.amountToRelay, consts.amountToRelay, toBN(0)], 0, - hexZeroPadAddress(destErc20.address), - [hexZeroPadAddress(relayer.address), hexZeroPadAddress(rando.address), hexZeroPadAddress(rando.address)] + addressToBytes(destErc20.address), + [addressToBytes(relayer.address), addressToBytes(rando.address), addressToBytes(rando.address)] ) ).to.changeTokenBalances( destErc20, @@ -212,8 +211,8 @@ describe("SpokePool Root Bundle Execution", function () { toBN(1), [consts.amountToRelay, consts.amountToRelay, toBN(0)], 0, - hexZeroPadAddress(destErc20.address), - [hexZeroPadAddress(relayer.address), hexZeroPadAddress(rando.address), hexZeroPadAddress(rando.address)] + addressToBytes(destErc20.address), + [addressToBytes(relayer.address), addressToBytes(rando.address), addressToBytes(rando.address)] ) ) .to.emit(spokePool, "BridgedToHubPool") diff --git a/test/evm/hardhat/SpokePool.Relay.ts b/test/evm/hardhat/SpokePool.Relay.ts index eca78f472..3e9e7a980 100644 --- a/test/evm/hardhat/SpokePool.Relay.ts +++ b/test/evm/hardhat/SpokePool.Relay.ts @@ -8,8 +8,7 @@ import { randomAddress, createRandomBytes32, BigNumber, - hexZeroPadAddress, - hexZeroPadAddressLowercase, + addressToBytes, bytes32ToAddress, } from "../../../utils/utils"; import { @@ -62,11 +61,11 @@ describe("SpokePool Relayer Logic", async function () { beforeEach(async function () { const fillDeadline = (await spokePool.getCurrentTime()).toNumber() + 1000; relayData = { - depositor: hexZeroPadAddress(depositor.address), - recipient: hexZeroPadAddress(recipient.address), - exclusiveRelayer: hexZeroPadAddress(relayer.address), - inputToken: hexZeroPadAddress(erc20.address), - outputToken: hexZeroPadAddress(destErc20.address), + depositor: addressToBytes(depositor.address), + recipient: addressToBytes(recipient.address), + exclusiveRelayer: addressToBytes(relayer.address), + inputToken: addressToBytes(erc20.address), + outputToken: addressToBytes(destErc20.address), inputAmount: consts.amountToDeposit, outputAmount: consts.amountToDeposit, originChainId: consts.originChainId, @@ -90,7 +89,7 @@ describe("SpokePool Relayer Logic", async function () { await expect( spokePool.connect(relayer).fillRelayV3Internal( relayExecution, - hexZeroPadAddress(relayer.address), + addressToBytes(relayer.address), false // isSlowFill ) ).to.be.revertedWith("ExpiredFillDeadline"); @@ -101,7 +100,7 @@ describe("SpokePool Relayer Logic", async function () { await expect( spokePool.connect(relayer).fillRelayV3Internal( relayExecution, - hexZeroPadAddress(relayer.address), + addressToBytes(relayer.address), false // isSlowFill ) ).to.be.revertedWith("RelayFilled"); @@ -112,14 +111,14 @@ describe("SpokePool Relayer Logic", async function () { await expect( spokePool.connect(relayer).fillRelayV3Internal( relayExecution, - hexZeroPadAddress(relayer.address), + addressToBytes(relayer.address), false // isSlowFill ) ) .to.emit(spokePool, "FilledV3Relay") .withArgs( - hexZeroPadAddressLowercase(relayData.inputToken), - hexZeroPadAddressLowercase(relayData.outputToken), + addressToBytes(relayData.inputToken), + addressToBytes(relayData.outputToken), relayData.inputAmount, relayData.outputAmount, relayExecution.repaymentChainId, @@ -127,13 +126,13 @@ describe("SpokePool Relayer Logic", async function () { relayData.depositId, relayData.fillDeadline, relayData.exclusivityDeadline, - hexZeroPadAddressLowercase(relayData.exclusiveRelayer), - hexZeroPadAddressLowercase(relayer.address), - hexZeroPadAddressLowercase(relayData.depositor), - hexZeroPadAddressLowercase(relayData.recipient), + addressToBytes(relayData.exclusiveRelayer), + addressToBytes(relayer.address), + addressToBytes(relayData.depositor), + addressToBytes(relayData.recipient), relayData.message, [ - hexZeroPadAddressLowercase(relayData.recipient), + addressToBytes(relayData.recipient), relayExecution.updatedMessage, relayExecution.updatedOutputAmount, // Testing that this FillType is not "FastFill" @@ -148,14 +147,14 @@ describe("SpokePool Relayer Logic", async function () { await expect( spokePool.connect(relayer).fillRelayV3Internal( relayExecution, - hexZeroPadAddress(relayer.address), + addressToBytes(relayer.address), true // isSlowFill ) ) .to.emit(spokePool, "FilledV3Relay") .withArgs( - hexZeroPadAddressLowercase(relayData.inputToken), - hexZeroPadAddressLowercase(relayData.outputToken), + addressToBytes(relayData.inputToken), + addressToBytes(relayData.outputToken), relayData.inputAmount, relayData.outputAmount, relayExecution.repaymentChainId, @@ -163,13 +162,13 @@ describe("SpokePool Relayer Logic", async function () { relayData.depositId, relayData.fillDeadline, relayData.exclusivityDeadline, - hexZeroPadAddressLowercase(relayData.exclusiveRelayer), - hexZeroPadAddressLowercase(relayer.address), - hexZeroPadAddressLowercase(relayData.depositor), - hexZeroPadAddressLowercase(relayData.recipient), + addressToBytes(relayData.exclusiveRelayer), + addressToBytes(relayer.address), + addressToBytes(relayData.depositor), + addressToBytes(relayData.recipient), relayData.message, [ - hexZeroPadAddressLowercase(relayData.recipient), + addressToBytes(relayData.recipient), relayExecution.updatedMessage, relayExecution.updatedOutputAmount, // Testing that this FillType is "SlowFill" @@ -183,14 +182,14 @@ describe("SpokePool Relayer Logic", async function () { await expect( spokePool.connect(relayer).fillRelayV3Internal( relayExecution, - hexZeroPadAddressLowercase(relayer.address), + addressToBytes(relayer.address), false // isSlowFill ) ) .to.emit(spokePool, "FilledV3Relay") .withArgs( - hexZeroPadAddressLowercase(relayData.inputToken), - hexZeroPadAddressLowercase(relayData.outputToken), + addressToBytes(relayData.inputToken), + addressToBytes(relayData.outputToken), relayData.inputAmount, relayData.outputAmount, relayExecution.repaymentChainId, @@ -198,13 +197,13 @@ describe("SpokePool Relayer Logic", async function () { relayData.depositId, relayData.fillDeadline, relayData.exclusivityDeadline, - hexZeroPadAddressLowercase(relayData.exclusiveRelayer), - hexZeroPadAddressLowercase(relayer.address), - hexZeroPadAddressLowercase(relayData.depositor), - hexZeroPadAddressLowercase(relayData.recipient), + addressToBytes(relayData.exclusiveRelayer), + addressToBytes(relayer.address), + addressToBytes(relayData.depositor), + addressToBytes(relayData.recipient), relayData.message, [ - hexZeroPadAddressLowercase(relayData.recipient), + addressToBytes(relayData.recipient), relayExecution.updatedMessage, relayExecution.updatedOutputAmount, FillType.FastFill, @@ -216,13 +215,13 @@ describe("SpokePool Relayer Logic", async function () { const _relayData = { ...relayData, // Set recipient == relayer - recipient: hexZeroPadAddress(relayer.address), + recipient: addressToBytes(relayer.address), }; const relayExecution = await getRelayExecutionParams(_relayData, consts.destinationChainId); await expect( spokePool.connect(relayer).fillRelayV3Internal( relayExecution, - hexZeroPadAddress(relayer.address), + addressToBytes(relayer.address), false // isSlowFill ) ).to.not.emit(destErc20, "Transfer"); @@ -234,15 +233,15 @@ describe("SpokePool Relayer Logic", async function () { // Overwrite amount to send to be double the original amount updatedOutputAmount: consts.amountToDeposit.mul(2), // Overwrite recipient to depositor which is not the same as the original recipient - updatedRecipient: hexZeroPadAddress(depositor.address), + updatedRecipient: addressToBytes(depositor.address), }; - expect(_relayExecution.updatedRecipient).to.not.equal(hexZeroPadAddress(relayExecution.updatedRecipient)); + expect(_relayExecution.updatedRecipient).to.not.equal(addressToBytes(relayExecution.updatedRecipient)); expect(_relayExecution.updatedOutputAmount).to.not.equal(relayExecution.updatedOutputAmount); await destErc20.connect(relayer).approve(spokePool.address, _relayExecution.updatedOutputAmount); await expect(() => spokePool.connect(relayer).fillRelayV3Internal( _relayExecution, - hexZeroPadAddress(relayer.address), + addressToBytes(relayer.address), false // isSlowFill ) ).to.changeTokenBalance(destErc20, depositor, consts.amountToDeposit.mul(2)); @@ -250,13 +249,13 @@ describe("SpokePool Relayer Logic", async function () { it("unwraps native token if sending to EOA", async function () { const _relayData = { ...relayData, - outputToken: hexZeroPadAddress(weth.address), + outputToken: addressToBytes(weth.address), }; const relayExecution = await getRelayExecutionParams(_relayData, consts.destinationChainId); await expect(() => spokePool.connect(relayer).fillRelayV3Internal( relayExecution, - hexZeroPadAddress(relayer.address), + addressToBytes(relayer.address), false // isSlowFill ) ).to.changeEtherBalance(recipient, relayExecution.updatedOutputAmount); @@ -264,7 +263,7 @@ describe("SpokePool Relayer Logic", async function () { it("slow fills send native token out of spoke pool balance", async function () { const _relayData = { ...relayData, - outputToken: hexZeroPadAddress(weth.address), + outputToken: addressToBytes(weth.address), }; const relayExecution = await getRelayExecutionParams(_relayData, consts.destinationChainId); await weth.connect(relayer).transfer(spokePool.address, relayExecution.updatedOutputAmount); @@ -272,7 +271,7 @@ describe("SpokePool Relayer Logic", async function () { await expect(() => spokePool.connect(relayer).fillRelayV3Internal( relayExecution, - hexZeroPadAddress(relayer.address), + addressToBytes(relayer.address), true // isSlowFill ) ).to.changeEtherBalance(recipient, relayExecution.updatedOutputAmount); @@ -285,7 +284,7 @@ describe("SpokePool Relayer Logic", async function () { await expect(() => spokePool.connect(relayer).fillRelayV3Internal( relayExecution, - hexZeroPadAddress(relayer.address), + addressToBytes(relayer.address), true // isSlowFill ) ).to.changeTokenBalance(destErc20, spokePool, relayExecution.updatedOutputAmount.mul(-1)); @@ -295,7 +294,7 @@ describe("SpokePool Relayer Logic", async function () { const acrossMessageHandler = await createFake("AcrossMessageHandlerMock"); const _relayData = { ...relayData, - recipient: hexZeroPadAddress(acrossMessageHandler.address), + recipient: addressToBytes(acrossMessageHandler.address), message: "0x1234", }; const relayExecution = await getRelayExecutionParams(_relayData, consts.destinationChainId); @@ -303,7 +302,7 @@ describe("SpokePool Relayer Logic", async function () { // Handler is called with expected params. await spokePool.connect(relayer).fillRelayV3Internal( relayExecution, - hexZeroPadAddress(relayer.address), + addressToBytes(relayer.address), false // isSlowFill ); const test = bytes32ToAddress(_relayData.outputToken); @@ -319,16 +318,14 @@ describe("SpokePool Relayer Logic", async function () { it("fills are not paused", async function () { await spokePool.pauseFills(true); await expect( - spokePool - .connect(relayer) - .fillV3Relay(relayData, consts.repaymentChainId, hexZeroPadAddressLowercase(relayer.address)) + spokePool.connect(relayer).fillV3Relay(relayData, consts.repaymentChainId, addressToBytes(relayer.address)) ).to.be.revertedWith("FillsArePaused"); }); it("reentrancy protected", async function () { const functionCalldata = spokePool.interface.encodeFunctionData("fillV3Relay", [ relayData, consts.repaymentChainId, - hexZeroPadAddressLowercase(relayer.address), + addressToBytes(relayer.address), ]); await expect(spokePool.connect(relayer).callback(functionCalldata)).to.be.revertedWith( "ReentrancyGuard: reentrant call" @@ -338,13 +335,11 @@ describe("SpokePool Relayer Logic", async function () { const _relayData = { ...relayData, // Overwrite exclusive relayer and exclusivity deadline - exclusiveRelayer: hexZeroPadAddress(recipient.address), + exclusiveRelayer: addressToBytes(recipient.address), exclusivityDeadline: relayData.fillDeadline, }; await expect( - spokePool - .connect(relayer) - .fillV3Relay(_relayData, consts.repaymentChainId, hexZeroPadAddressLowercase(relayer.address)) + spokePool.connect(relayer).fillV3Relay(_relayData, consts.repaymentChainId, addressToBytes(relayer.address)) ).to.be.revertedWith("NotExclusiveRelayer"); // Can send it after exclusivity deadline @@ -354,7 +349,7 @@ describe("SpokePool Relayer Logic", async function () { .fillV3Relay( { ..._relayData, exclusivityDeadline: 0 }, consts.repaymentChainId, - hexZeroPadAddressLowercase(relayer.address) + addressToBytes(relayer.address) ) ).to.not.be.reverted; }); @@ -367,9 +362,7 @@ describe("SpokePool Relayer Logic", async function () { // Can send it after exclusivity deadline await expect( - spokePool - .connect(relayer) - .fillV3Relay(_relayData, consts.repaymentChainId, hexZeroPadAddressLowercase(relayer.address)) + spokePool.connect(relayer).fillV3Relay(_relayData, consts.repaymentChainId, addressToBytes(relayer.address)) ).to.not.be.reverted; }); it("can have empty exclusive relayer before exclusivity deadline", async function () { @@ -381,21 +374,17 @@ describe("SpokePool Relayer Logic", async function () { // Can send it before exclusivity deadline if exclusive relayer is empty await expect( - spokePool - .connect(relayer) - .fillV3Relay(_relayData, consts.repaymentChainId, hexZeroPadAddressLowercase(relayer.address)) + spokePool.connect(relayer).fillV3Relay(_relayData, consts.repaymentChainId, addressToBytes(relayer.address)) ).to.not.be.reverted; }); it("calls _fillRelayV3 with expected params", async function () { await expect( - spokePool - .connect(relayer) - .fillV3Relay(relayData, consts.repaymentChainId, hexZeroPadAddressLowercase(relayer.address)) + spokePool.connect(relayer).fillV3Relay(relayData, consts.repaymentChainId, addressToBytes(relayer.address)) ) .to.emit(spokePool, "FilledV3Relay") .withArgs( - hexZeroPadAddressLowercase(relayData.inputToken), - hexZeroPadAddressLowercase(relayData.outputToken), + addressToBytes(relayData.inputToken), + addressToBytes(relayData.outputToken), relayData.inputAmount, relayData.outputAmount, consts.repaymentChainId, // Should be passed-in repayment chain ID @@ -403,13 +392,13 @@ describe("SpokePool Relayer Logic", async function () { relayData.depositId, relayData.fillDeadline, relayData.exclusivityDeadline, - hexZeroPadAddressLowercase(relayData.exclusiveRelayer), - hexZeroPadAddressLowercase(relayer.address), // Should be equal to msg.sender of fillRelayV3 - hexZeroPadAddressLowercase(relayData.depositor), - hexZeroPadAddressLowercase(relayData.recipient), + addressToBytes(relayData.exclusiveRelayer), + addressToBytes(relayer.address), // Should be equal to msg.sender of fillRelayV3 + addressToBytes(relayData.depositor), + addressToBytes(relayData.recipient), relayData.message, [ - hexZeroPadAddressLowercase(relayData.recipient), // updatedRecipient should be equal to recipient + addressToBytes(relayData.recipient), // updatedRecipient should be equal to recipient relayData.message, // updatedMessage should be equal to message relayData.outputAmount, // updatedOutputAmount should be equal to outputAmount // Should be FastFill @@ -430,7 +419,7 @@ describe("SpokePool Relayer Logic", async function () { relayData.depositId, relayData.originChainId, updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage ); }); @@ -438,7 +427,7 @@ describe("SpokePool Relayer Logic", async function () { const _relayData = { ...relayData, // Overwrite exclusive relayer and exclusivity deadline - exclusiveRelayer: hexZeroPadAddress(recipient.address), + exclusiveRelayer: addressToBytes(recipient.address), exclusivityDeadline: relayData.fillDeadline, }; await expect( @@ -447,9 +436,9 @@ describe("SpokePool Relayer Logic", async function () { .fillV3RelayWithUpdatedDeposit( _relayData, consts.repaymentChainId, - hexZeroPadAddressLowercase(relayer.address), + addressToBytes(relayer.address), updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, signature ) @@ -463,9 +452,9 @@ describe("SpokePool Relayer Logic", async function () { exclusivityDeadline: 0, }, consts.repaymentChainId, - hexZeroPadAddressLowercase(relayer.address), + addressToBytes(relayer.address), updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, signature ) @@ -483,17 +472,17 @@ describe("SpokePool Relayer Logic", async function () { .fillV3RelayWithUpdatedDeposit( relayData, consts.repaymentChainId, - hexZeroPadAddressLowercase(relayer.address), + addressToBytes(relayer.address), updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, signature ) ) .to.emit(spokePool, "FilledV3Relay") .withArgs( - hexZeroPadAddressLowercase(relayData.inputToken), - hexZeroPadAddressLowercase(relayData.outputToken), + addressToBytes(relayData.inputToken), + addressToBytes(relayData.outputToken), relayData.inputAmount, relayData.outputAmount, consts.repaymentChainId, // Should be passed-in repayment chain ID @@ -501,14 +490,14 @@ describe("SpokePool Relayer Logic", async function () { relayData.depositId, relayData.fillDeadline, relayData.exclusivityDeadline, - hexZeroPadAddressLowercase(relayData.exclusiveRelayer), - hexZeroPadAddressLowercase(relayer.address), // Should be equal to msg.sender - hexZeroPadAddressLowercase(relayData.depositor), - hexZeroPadAddressLowercase(relayData.recipient), + addressToBytes(relayData.exclusiveRelayer), + addressToBytes(relayer.address), // Should be equal to msg.sender + addressToBytes(relayData.depositor), + addressToBytes(relayData.recipient), relayData.message, [ // Should use passed-in updated params: - hexZeroPadAddressLowercase(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, updatedOutputAmount, // Should be FastFill @@ -526,11 +515,11 @@ describe("SpokePool Relayer Logic", async function () { spokePool .connect(relayer) .fillV3RelayWithUpdatedDeposit( - { ...relayData, depositor: hexZeroPadAddress(relayer.address) }, + { ...relayData, depositor: addressToBytes(relayer.address) }, consts.repaymentChainId, - hexZeroPadAddressLowercase(relayer.address), + addressToBytes(relayer.address), updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, signature ) @@ -542,7 +531,7 @@ describe("SpokePool Relayer Logic", async function () { relayData.depositId + 1, relayData.originChainId, updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage ); await expect( @@ -551,9 +540,9 @@ describe("SpokePool Relayer Logic", async function () { .fillV3RelayWithUpdatedDeposit( relayData, consts.repaymentChainId, - hexZeroPadAddressLowercase(relayer.address), + addressToBytes(relayer.address), updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, otherSignature ) @@ -566,9 +555,9 @@ describe("SpokePool Relayer Logic", async function () { .fillV3RelayWithUpdatedDeposit( { ...relayData, originChainId: relayData.originChainId + 1 }, consts.repaymentChainId, - hexZeroPadAddressLowercase(relayer.address), + addressToBytes(relayer.address), updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, signature ) @@ -581,9 +570,9 @@ describe("SpokePool Relayer Logic", async function () { .fillV3RelayWithUpdatedDeposit( { ...relayData, depositId: relayData.depositId + 1 }, consts.repaymentChainId, - hexZeroPadAddressLowercase(relayer.address), + addressToBytes(relayer.address), updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, signature ) @@ -596,9 +585,9 @@ describe("SpokePool Relayer Logic", async function () { .fillV3RelayWithUpdatedDeposit( relayData, consts.repaymentChainId, - hexZeroPadAddressLowercase(relayer.address), + addressToBytes(relayer.address), updatedOutputAmount.sub(1), - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, signature ) @@ -611,9 +600,9 @@ describe("SpokePool Relayer Logic", async function () { .fillV3RelayWithUpdatedDeposit( relayData, consts.repaymentChainId, - hexZeroPadAddressLowercase(relayer.address), + addressToBytes(relayer.address), updatedOutputAmount, - hexZeroPadAddress(randomAddress()), + addressToBytes(randomAddress()), updatedMessage, signature ) @@ -626,9 +615,9 @@ describe("SpokePool Relayer Logic", async function () { .fillV3RelayWithUpdatedDeposit( relayData, consts.repaymentChainId, - hexZeroPadAddressLowercase(relayer.address), + addressToBytes(relayer.address), updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, createRandomBytes32() ) @@ -642,18 +631,18 @@ describe("SpokePool Relayer Logic", async function () { relayData.depositId, relayData.originChainId, updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage ); await expect( spokePool .connect(relayer) .fillV3RelayWithUpdatedDeposit( - { ...relayData, depositor: hexZeroPadAddress(erc1271.address) }, + { ...relayData, depositor: addressToBytes(erc1271.address) }, consts.repaymentChainId, - hexZeroPadAddressLowercase(relayer.address), + addressToBytes(relayer.address), updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, incorrectSignature ) @@ -662,11 +651,11 @@ describe("SpokePool Relayer Logic", async function () { spokePool .connect(relayer) .fillV3RelayWithUpdatedDeposit( - { ...relayData, depositor: hexZeroPadAddress(erc1271.address) }, + { ...relayData, depositor: addressToBytes(erc1271.address) }, consts.repaymentChainId, - hexZeroPadAddressLowercase(relayer.address), + addressToBytes(relayer.address), updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, signature ) @@ -675,16 +664,16 @@ describe("SpokePool Relayer Logic", async function () { it("cannot send updated fill after original fill", async function () { await spokePool .connect(relayer) - .fillV3Relay(relayData, consts.repaymentChainId, hexZeroPadAddressLowercase(relayer.address)); + .fillV3Relay(relayData, consts.repaymentChainId, addressToBytes(relayer.address)); await expect( spokePool .connect(relayer) .fillV3RelayWithUpdatedDeposit( relayData, consts.repaymentChainId, - hexZeroPadAddressLowercase(relayer.address), + addressToBytes(relayer.address), updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, signature ) @@ -696,16 +685,14 @@ describe("SpokePool Relayer Logic", async function () { .fillV3RelayWithUpdatedDeposit( relayData, consts.repaymentChainId, - hexZeroPadAddressLowercase(relayer.address), + addressToBytes(relayer.address), updatedOutputAmount, - hexZeroPadAddress(updatedRecipient), + addressToBytes(updatedRecipient), updatedMessage, signature ); await expect( - spokePool - .connect(relayer) - .fillV3Relay(relayData, consts.repaymentChainId, hexZeroPadAddressLowercase(relayer.address)) + spokePool.connect(relayer).fillV3Relay(relayData, consts.repaymentChainId, addressToBytes(relayer.address)) ).to.be.revertedWith("RelayFilled"); }); }); diff --git a/test/evm/hardhat/SpokePool.SlowRelay.ts b/test/evm/hardhat/SpokePool.SlowRelay.ts index cf69e43d8..b1ef48fc0 100644 --- a/test/evm/hardhat/SpokePool.SlowRelay.ts +++ b/test/evm/hardhat/SpokePool.SlowRelay.ts @@ -6,8 +6,7 @@ import { toBN, seedContract, seedWallet, - hexZeroPadAddress, - hexZeroPadAddressLowercase, + addressToBytes, } from "../../../utils/utils"; import { spokePoolFixture, V3RelayData, getV3RelayHash, V3SlowFill, FillType } from "./fixtures/SpokePool.Fixture"; import { buildV3SlowRelayTree } from "./MerkleLib.utils"; @@ -41,11 +40,11 @@ describe("SpokePool Slow Relay Logic", async function () { beforeEach(async function () { const fillDeadline = (await spokePool.getCurrentTime()).toNumber() + 1000; relayData = { - depositor: hexZeroPadAddress(depositor.address), - recipient: hexZeroPadAddress(recipient.address), - exclusiveRelayer: hexZeroPadAddress(relayer.address), - inputToken: hexZeroPadAddress(erc20.address), - outputToken: hexZeroPadAddress(destErc20.address), + depositor: addressToBytes(depositor.address), + recipient: addressToBytes(recipient.address), + exclusiveRelayer: addressToBytes(relayer.address), + inputToken: addressToBytes(erc20.address), + outputToken: addressToBytes(destErc20.address), inputAmount: consts.amountToDeposit, outputAmount: fullRelayAmountPostFees, originChainId: consts.originChainId, @@ -83,9 +82,7 @@ describe("SpokePool Slow Relay Logic", async function () { ); // Can fast fill after: - await spokePool - .connect(relayer) - .fillV3Relay(relayData, consts.repaymentChainId, hexZeroPadAddress(relayer.address)); + await spokePool.connect(relayer).fillV3Relay(relayData, consts.repaymentChainId, addressToBytes(relayer.address)); }); it("cannot request if FillStatus is Filled", async function () { const relayHash = getV3RelayHash(relayData, consts.destinationChainId); @@ -113,11 +110,11 @@ describe("SpokePool Slow Relay Logic", async function () { beforeEach(async function () { const fillDeadline = (await spokePool.getCurrentTime()).toNumber() + 1000; relayData = { - depositor: hexZeroPadAddress(depositor.address), - recipient: hexZeroPadAddress(recipient.address), - exclusiveRelayer: hexZeroPadAddress(relayer.address), - inputToken: hexZeroPadAddress(erc20.address), - outputToken: hexZeroPadAddress(destErc20.address), + depositor: addressToBytes(depositor.address), + recipient: addressToBytes(recipient.address), + exclusiveRelayer: addressToBytes(relayer.address), + inputToken: addressToBytes(erc20.address), + outputToken: addressToBytes(destErc20.address), inputAmount: consts.amountToDeposit, outputAmount: fullRelayAmountPostFees, originChainId: consts.originChainId, @@ -169,7 +166,7 @@ describe("SpokePool Slow Relay Logic", async function () { await expect( spokePool .connect(relayer) - .fillV3Relay(slowRelayLeaf.relayData, consts.repaymentChainId, hexZeroPadAddress(relayer.address)) + .fillV3Relay(slowRelayLeaf.relayData, consts.repaymentChainId, addressToBytes(relayer.address)) ).to.be.revertedWith("RelayFilled"); }); it("cannot be used to double send a fill", async function () { @@ -179,7 +176,7 @@ describe("SpokePool Slow Relay Logic", async function () { // Fill before executing slow fill await spokePool .connect(relayer) - .fillV3Relay(slowRelayLeaf.relayData, consts.repaymentChainId, hexZeroPadAddress(relayer.address)); + .fillV3Relay(slowRelayLeaf.relayData, consts.repaymentChainId, addressToBytes(relayer.address)); await expect( spokePool.connect(relayer).executeV3SlowRelayLeaf( slowRelayLeaf, @@ -291,8 +288,8 @@ describe("SpokePool Slow Relay Logic", async function () { ) .to.emit(spokePool, "FilledV3Relay") .withArgs( - hexZeroPadAddressLowercase(relayData.inputToken), - hexZeroPadAddressLowercase(relayData.outputToken), + addressToBytes(relayData.inputToken), + addressToBytes(relayData.outputToken), relayData.inputAmount, relayData.outputAmount, 0, // Sets repaymentChainId to 0. @@ -300,14 +297,14 @@ describe("SpokePool Slow Relay Logic", async function () { relayData.depositId, relayData.fillDeadline, relayData.exclusivityDeadline, - hexZeroPadAddressLowercase(relayData.exclusiveRelayer), - hexZeroPadAddressLowercase(consts.zeroAddress), // Sets relayer address to 0x0 - hexZeroPadAddressLowercase(relayData.depositor), - hexZeroPadAddressLowercase(relayData.recipient), + addressToBytes(relayData.exclusiveRelayer), + addressToBytes(consts.zeroAddress), // Sets relayer address to 0x0 + addressToBytes(relayData.depositor), + addressToBytes(relayData.recipient), relayData.message, [ // Uses relayData.recipient - hexZeroPadAddressLowercase(relayData.recipient), + addressToBytes(relayData.recipient), // Uses relayData.message relayData.message, // Uses slow fill leaf's updatedOutputAmount diff --git a/test/evm/hardhat/chain-specific-spokepools/Arbitrum_SpokePool.ts b/test/evm/hardhat/chain-specific-spokepools/Arbitrum_SpokePool.ts index 1377aaed5..c76ffe94c 100644 --- a/test/evm/hardhat/chain-specific-spokepools/Arbitrum_SpokePool.ts +++ b/test/evm/hardhat/chain-specific-spokepools/Arbitrum_SpokePool.ts @@ -11,7 +11,7 @@ import { seedContract, avmL1ToL2Alias, createFakeFromABI, - hexZeroPadAddress, + addressToBytes, } from "../../../../utils/utils"; import { hre } from "../../../../utils/utils.hre"; import { hubPoolFixture } from "../fixtures/HubPool.Fixture"; @@ -80,7 +80,7 @@ describe("Arbitrum Spoke Pool", function () { it("Only cross domain owner can enable a route", async function () { await expect(arbitrumSpokePool.setEnableRoute(l2Dai, 1, true)).to.be.reverted; await arbitrumSpokePool.connect(crossDomainAlias).setEnableRoute(l2Dai, 1, true); - expect(await arbitrumSpokePool.enabledDepositRoutes(hexZeroPadAddress(l2Dai), 1)).to.equal(true); + expect(await arbitrumSpokePool.enabledDepositRoutes(addressToBytes(l2Dai), 1)).to.equal(true); }); it("Only cross domain owner can whitelist a token pair", async function () { diff --git a/test/evm/hardhat/chain-specific-spokepools/Ethereum_SpokePool.ts b/test/evm/hardhat/chain-specific-spokepools/Ethereum_SpokePool.ts index 04d800d89..1b5966135 100644 --- a/test/evm/hardhat/chain-specific-spokepools/Ethereum_SpokePool.ts +++ b/test/evm/hardhat/chain-specific-spokepools/Ethereum_SpokePool.ts @@ -6,7 +6,7 @@ import { SignerWithAddress, getContractFactory, seedContract, - hexZeroPadAddress, + addressToBytes, } from "../../../../utils/utils"; import { hre } from "../../../../utils/utils.hre"; import { hubPoolFixture } from "../fixtures/HubPool.Fixture"; @@ -55,7 +55,7 @@ describe("Ethereum Spoke Pool", function () { it("Only owner can enable a route", async function () { await expect(spokePool.connect(rando).setEnableRoute(dai.address, 1, true)).to.be.reverted; await spokePool.connect(owner).setEnableRoute(dai.address, 1, true); - expect(await spokePool.enabledDepositRoutes(hexZeroPadAddress(dai.address), 1)).to.equal(true); + expect(await spokePool.enabledDepositRoutes(addressToBytes(dai.address), 1)).to.equal(true); }); it("Only owner can set the hub pool address", async function () { diff --git a/test/evm/hardhat/chain-specific-spokepools/Optimism_SpokePool.ts b/test/evm/hardhat/chain-specific-spokepools/Optimism_SpokePool.ts index f22525538..460e19a3d 100644 --- a/test/evm/hardhat/chain-specific-spokepools/Optimism_SpokePool.ts +++ b/test/evm/hardhat/chain-specific-spokepools/Optimism_SpokePool.ts @@ -10,7 +10,7 @@ import { getContractFactory, seedContract, createFakeFromABI, - hexZeroPadAddress, + addressToBytes, } from "../../../../utils/utils"; import { CCTPTokenMessengerInterface, CCTPTokenMinterInterface } from "../../../../utils/abis"; import { hre } from "../../../../utils/utils.hre"; @@ -94,7 +94,7 @@ describe("Optimism Spoke Pool", function () { await expect(optimismSpokePool.setEnableRoute(l2Dai, 1, true)).to.be.reverted; crossDomainMessenger.xDomainMessageSender.returns(owner.address); await optimismSpokePool.connect(crossDomainMessenger.wallet).setEnableRoute(l2Dai, 1, true); - expect(await optimismSpokePool.enabledDepositRoutes(hexZeroPadAddress(l2Dai), 1)).to.equal(true); + expect(await optimismSpokePool.enabledDepositRoutes(addressToBytes(l2Dai), 1)).to.equal(true); }); it("Only cross domain owner can set the cross domain admin", async function () { diff --git a/test/evm/hardhat/chain-specific-spokepools/Polygon_SpokePool.ts b/test/evm/hardhat/chain-specific-spokepools/Polygon_SpokePool.ts index df82f23fd..9ef4bff15 100644 --- a/test/evm/hardhat/chain-specific-spokepools/Polygon_SpokePool.ts +++ b/test/evm/hardhat/chain-specific-spokepools/Polygon_SpokePool.ts @@ -20,7 +20,7 @@ import { seedWallet, FakeContract, createFakeFromABI, - hexZeroPadAddress, + addressToBytes, } from "../../../../utils/utils"; import { hre } from "../../../../utils/utils.hre"; import { hubPoolFixture } from "../fixtures/HubPool.Fixture"; @@ -156,7 +156,7 @@ describe("Polygon Spoke Pool", function () { .reverted; await polygonSpokePool.connect(fxChild).processMessageFromRoot(0, owner.address, setEnableRouteData); - expect(await polygonSpokePool.enabledDepositRoutes(hexZeroPadAddress(l2Dai), 1)).to.equal(true); + expect(await polygonSpokePool.enabledDepositRoutes(addressToBytes(l2Dai), 1)).to.equal(true); }); it("Only correct caller can initialize a relayer refund", async function () { @@ -261,7 +261,7 @@ describe("Polygon Spoke Pool", function () { const leaves = buildRelayerRefundLeaves( [l2ChainId, l2ChainId], // Destination chain ID. [amountToReturn, ethers.constants.Zero], // amountToReturn. - [hexZeroPadAddress(dai.address), hexZeroPadAddress(dai.address)], // l2Token. + [addressToBytes(dai.address), addressToBytes(dai.address)], // l2Token. [[], []], // refundAddresses. [[], []] // refundAmounts. ); @@ -289,7 +289,7 @@ describe("Polygon Spoke Pool", function () { const leaves = buildRelayerRefundLeaves( [l2ChainId, l2ChainId], // Destination chain ID. [ethers.constants.Zero, ethers.constants.Zero], // amountToReturn. - [hexZeroPadAddress(dai.address), hexZeroPadAddress(dai.address)], // l2Token. + [addressToBytes(dai.address), addressToBytes(dai.address)], // l2Token. [[], []], // refundAddresses. [[], []] // refundAmounts. ); @@ -321,11 +321,11 @@ describe("Polygon Spoke Pool", function () { ]; const currentTime = (await polygonSpokePool.getCurrentTime()).toNumber(); const relayData: V3RelayData = { - depositor: hexZeroPadAddress(owner.address), - recipient: hexZeroPadAddress(acrossMessageHandler.address), - exclusiveRelayer: hexZeroPadAddress(zeroAddress), - inputToken: hexZeroPadAddress(dai.address), - outputToken: hexZeroPadAddress(dai.address), + depositor: addressToBytes(owner.address), + recipient: addressToBytes(acrossMessageHandler.address), + exclusiveRelayer: addressToBytes(zeroAddress), + inputToken: addressToBytes(dai.address), + outputToken: addressToBytes(dai.address), inputAmount: toWei("1"), outputAmount: toWei("1"), originChainId: originChainId, @@ -338,12 +338,12 @@ describe("Polygon Spoke Pool", function () { polygonSpokePool.interface.encodeFunctionData("fillV3Relay", [ relayData, repaymentChainId, - hexZeroPadAddress(relayer.address), + addressToBytes(relayer.address), ]), polygonSpokePool.interface.encodeFunctionData("fillV3Relay", [ { ...relayData, depositId: 1 }, repaymentChainId, - hexZeroPadAddress(relayer.address), + addressToBytes(relayer.address), ]), ]; const otherData = [polygonSpokePool.interface.encodeFunctionData("wrap", [])]; diff --git a/test/evm/hardhat/fixtures/SpokePool.Fixture.ts b/test/evm/hardhat/fixtures/SpokePool.Fixture.ts index 8ff0b51f6..b4943e218 100644 --- a/test/evm/hardhat/fixtures/SpokePool.Fixture.ts +++ b/test/evm/hardhat/fixtures/SpokePool.Fixture.ts @@ -7,7 +7,7 @@ import { ethers, BigNumber, defaultAbiCoder, - hexZeroPadAddress, + addressToBytes, } from "../../../../utils/utils"; import * as consts from "../constants"; diff --git a/utils/utils.ts b/utils/utils.ts index 61bde6750..c06b0e22a 100644 --- a/utils/utils.ts +++ b/utils/utils.ts @@ -103,9 +103,7 @@ export const createRandomBytes32 = () => ethers.utils.hexlify(ethers.utils.rando export const hexZeroPad = (input: string, length: number) => ethers.utils.hexZeroPad(input, length); -export const hexZeroPadAddress = (input: string) => hexZeroPad(input, 32); - -export const hexZeroPadAddressLowercase = (input: string) => hexZeroPad(input.toLowerCase(), 32); +export const addressToBytes = (input: string) => hexZeroPad(input.toLowerCase(), 32); export const bytes32ToAddress = (input: string) => { if (!/^0x[a-fA-F0-9]{64}$/.test(input)) {