diff --git a/test/evm/hardhat/SpokePool.ExecuteRootBundle.ts b/test/evm/hardhat/SpokePool.ExecuteRootBundle.ts index ae13c31d3..4e35aa9e6 100644 --- a/test/evm/hardhat/SpokePool.ExecuteRootBundle.ts +++ b/test/evm/hardhat/SpokePool.ExecuteRootBundle.ts @@ -98,8 +98,8 @@ describe("SpokePool Root Bundle Execution", function () { totalSolanaDistributions: evmDistributions, mixLeaves: true, chainId: destinationChainId, - evmTokenAddress: destErc20.address, - evmRelayers: [relayer.address, rando.address], + evmTokenAddress: addressToBytes(destErc20.address), + evmRelayers: [addressToBytes(relayer.address), addressToBytes(rando.address)], evmRefundAmounts: [consts.amountToRelay.div(evmDistributions), consts.amountToRelay.div(evmDistributions)], }); @@ -134,8 +134,8 @@ describe("SpokePool Root Bundle Execution", function () { totalSolanaDistributions: evmDistributions, mixLeaves: false, chainId: destinationChainId, - evmTokenAddress: destErc20.address, - evmRelayers: [relayer.address, rando.address], + evmTokenAddress: addressToBytes(destErc20.address), + evmRelayers: [addressToBytes(relayer.address), addressToBytes(rando.address)], evmRefundAmounts: [consts.amountToRelay.div(evmDistributions), consts.amountToRelay.div(evmDistributions)], }); diff --git a/test/svm/utils.ts b/test/svm/utils.ts index bdf9827a5..210e940e7 100644 --- a/test/svm/utils.ts +++ b/test/svm/utils.ts @@ -1,21 +1,20 @@ import { BN, Program } from "@coral-xyz/anchor"; import { Keypair, PublicKey } from "@solana/web3.js"; -import { BigNumber, ethers } from "ethers"; import * as crypto from "crypto"; +import { BigNumber, ethers } from "ethers"; import { SvmSpoke } from "../../target/types/svm_spoke"; +import { MerkleTree } from "@uma/common"; import { - readEvents, - readProgramEvents, calculateRelayHashUint8Array, findProgramAddress, LargeAccountsCoder, + readEvents, + readProgramEvents, } from "../../src/SvmUtils"; -import { MerkleTree } from "@uma/common"; -import { getParamType, keccak256 } from "../../test-utils"; -import { ParamType } from "ethers/lib/utils"; +import { addressToBytes, isBytes32 } from "../../test-utils"; -export { readEvents, readProgramEvents, calculateRelayHashUint8Array, findProgramAddress }; +export { calculateRelayHashUint8Array, findProgramAddress, readEvents, readProgramEvents }; export async function printLogs(connection: any, program: any, tx: any) { const latestBlockHash = await connection.getLatestBlockhash(); @@ -102,6 +101,14 @@ export function buildRelayerRefundMerkleTree({ }): { relayerRefundLeaves: RelayerRefundLeafType[]; merkleTree: MerkleTree } { const relayerRefundLeaves: RelayerRefundLeafType[] = []; + if (evmTokenAddress && !isBytes32(evmTokenAddress)) { + throw new Error("EVM token address must be a bytes32 address"); + } + + if (evmRelayers && evmRelayers.some((address) => !isBytes32(address))) { + throw new Error("EVM relayers must be bytes32 addresses"); + } + const createSolanaLeaf = (index: number) => ({ isSolana: true, leafId: new BN(index), @@ -118,8 +125,8 @@ export function buildRelayerRefundMerkleTree({ leafId: BigNumber.from(index), chainId: BigNumber.from(chainId), amountToReturn: BigNumber.from(0), - l2TokenAddress: evmTokenAddress ?? randomAddress(), - refundAddresses: evmRelayers || [randomAddress(), randomAddress()], + l2TokenAddress: evmTokenAddress ?? addressToBytes(randomAddress()), + refundAddresses: evmRelayers || [addressToBytes(randomAddress()), addressToBytes(randomAddress())], refundAmounts: evmRefundAmounts || [BigNumber.from(randomBigInt()), BigNumber.from(randomBigInt())], } as RelayerRefundLeaf); @@ -179,7 +186,7 @@ export const relayerRefundHashFn = (input: RelayerRefundLeaf | RelayerRefundLeaf const abiCoder = new ethers.utils.AbiCoder(); const encodedData = abiCoder.encode( [ - "tuple( uint256 amountToReturn, uint256 chainId, uint256[] refundAmounts, uint256 leafId, address l2TokenAddress, address[] refundAddresses)", + "tuple( uint256 amountToReturn, uint256 chainId, uint256[] refundAmounts, uint256 leafId, bytes32 l2TokenAddress, bytes32[] refundAddresses)", ], [ { diff --git a/utils/utils.ts b/utils/utils.ts index c06b0e22a..9aceac79e 100644 --- a/utils/utils.ts +++ b/utils/utils.ts @@ -112,6 +112,8 @@ export const bytes32ToAddress = (input: string) => { return ethers.utils.getAddress("0x" + input.slice(26)); }; +export const isBytes32 = (input: string) => /^0x[0-9a-fA-F]{64}$/.test(input); + export async function seedWallet( walletToFund: Signer, tokens: Contract[],