|
|
|
@ -1,7 +1,7 @@ |
|
|
|
|
/* eslint-disable @typescript-eslint/no-floating-promises */ |
|
|
|
|
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; |
|
|
|
|
import { expect } from 'chai'; |
|
|
|
|
import { ContractTransaction } from 'ethers'; |
|
|
|
|
import { BigNumberish, ContractTransaction } from 'ethers'; |
|
|
|
|
import { ethers } from 'hardhat'; |
|
|
|
|
|
|
|
|
|
import { utils } from '@hyperlane-xyz/utils'; |
|
|
|
@ -24,6 +24,14 @@ const destination = 2; |
|
|
|
|
const destinationWithoutRouter = 3; |
|
|
|
|
const body = '0xdeadbeef'; |
|
|
|
|
|
|
|
|
|
interface GasPaymentParams { |
|
|
|
|
// The amount of destination gas being paid for
|
|
|
|
|
gasAmount: BigNumberish; |
|
|
|
|
// The amount of native tokens paid
|
|
|
|
|
payment: BigNumberish; |
|
|
|
|
refundAddress: string; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
describe('Router', async () => { |
|
|
|
|
let router: TestRouter, |
|
|
|
|
mailbox: TestMailbox, |
|
|
|
@ -153,7 +161,7 @@ describe('Router', async () => { |
|
|
|
|
const runDispatchFunctionTests = async ( |
|
|
|
|
dispatchFunction: ( |
|
|
|
|
destinationDomain: number, |
|
|
|
|
interchainGasPayment?: number, |
|
|
|
|
gasPaymentParams: GasPaymentParams, |
|
|
|
|
) => Promise<ContractTransaction>, |
|
|
|
|
expectGasPayment: boolean, |
|
|
|
|
) => { |
|
|
|
@ -165,17 +173,21 @@ describe('Router', async () => { |
|
|
|
|
return expected ? assertion : assertion.not; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const testGasPaymentParams: GasPaymentParams = { |
|
|
|
|
gasAmount: 4321, |
|
|
|
|
payment: 1234, |
|
|
|
|
refundAddress: '0xc0ffee0000000000000000000000000000000000', |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
it('dispatches a message', async () => { |
|
|
|
|
await expect(dispatchFunction(destination)).to.emit( |
|
|
|
|
mailbox, |
|
|
|
|
'Dispatch', |
|
|
|
|
); |
|
|
|
|
await expect( |
|
|
|
|
dispatchFunction(destination, testGasPaymentParams), |
|
|
|
|
).to.emit(mailbox, 'Dispatch'); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it(`${ |
|
|
|
|
expectGasPayment ? 'pays' : 'does not pay' |
|
|
|
|
} interchain gas`, async () => {
|
|
|
|
|
const testInterchainGasPayment = 1234; |
|
|
|
|
const { id } = await inferMessageValues( |
|
|
|
|
mailbox, |
|
|
|
|
router.address, |
|
|
|
@ -184,17 +196,21 @@ describe('Router', async () => { |
|
|
|
|
'', |
|
|
|
|
); |
|
|
|
|
const assertion = expectAssertion( |
|
|
|
|
expect(dispatchFunction(destination, testInterchainGasPayment)).to, |
|
|
|
|
expect(dispatchFunction(destination, testGasPaymentParams)).to, |
|
|
|
|
expectGasPayment, |
|
|
|
|
); |
|
|
|
|
await assertion |
|
|
|
|
.emit(interchainGasPaymaster, 'GasPayment') |
|
|
|
|
.withArgs(id, testInterchainGasPayment); |
|
|
|
|
.withArgs( |
|
|
|
|
id, |
|
|
|
|
testGasPaymentParams.gasAmount, |
|
|
|
|
testGasPaymentParams.payment, |
|
|
|
|
); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('reverts when dispatching a message to an unenrolled remote router', async () => { |
|
|
|
|
await expect( |
|
|
|
|
dispatchFunction(destinationWithoutRouter), |
|
|
|
|
dispatchFunction(destinationWithoutRouter, testGasPaymentParams), |
|
|
|
|
).to.be.revertedWith( |
|
|
|
|
`No router enrolled for domain. Did you specify the right domain ID?`, |
|
|
|
|
); |
|
|
|
@ -210,13 +226,15 @@ describe('Router', async () => { |
|
|
|
|
|
|
|
|
|
describe('#dispatchWithGas', () => { |
|
|
|
|
runDispatchFunctionTests( |
|
|
|
|
(destinationDomain, interchainGasPayment = 0) => |
|
|
|
|
(destinationDomain, gasPaymentParams) => |
|
|
|
|
router.dispatchWithGas( |
|
|
|
|
destinationDomain, |
|
|
|
|
'0x', |
|
|
|
|
interchainGasPayment, |
|
|
|
|
gasPaymentParams.gasAmount, |
|
|
|
|
gasPaymentParams.payment, |
|
|
|
|
gasPaymentParams.refundAddress, |
|
|
|
|
{ |
|
|
|
|
value: interchainGasPayment, |
|
|
|
|
value: gasPaymentParams.payment, |
|
|
|
|
}, |
|
|
|
|
), |
|
|
|
|
true, |
|
|
|
|