|
7 | 7 | const { setERC20TokenBalance } = require("../../_fund"); |
8 | 8 | const { units, usdcUnits } = require("../../helpers"); |
9 | 9 | const { impersonateAndFund } = require("../../../utils/signers"); |
10 | | -const { encodeBalanceCheckMessageBody } = require("./_crosschain-helpers"); |
| 10 | +const { |
| 11 | + encodeBalanceCheckMessageBody, |
| 12 | + encodeCCTPMessage, |
| 13 | +} = require("./_crosschain-helpers"); |
11 | 14 |
|
12 | 15 | const loadFixture = createFixtureLoader(crossChainFixtureUnit); |
13 | 16 | const DAY_IN_SECONDS = 86400; |
@@ -456,6 +459,39 @@ describe("ForkTest: CrossChainRemoteStrategy", function () { |
456 | 459 | await assertVaultTotalValue("1000"); |
457 | 460 | }); |
458 | 461 |
|
| 462 | + it("Should reject direct replay of an already-relayed balance update message", async function () { |
| 463 | + const { messageTransmitter } = fixture; |
| 464 | + await sendBalanceUpdateToMaster(); |
| 465 | + |
| 466 | + const nonce = await crossChainMasterStrategy.lastTransferNonce(); |
| 467 | + const balance = await crossChainRemoteStrategy.checkBalance(usdc.address); |
| 468 | + const latestBlock = await ethers.provider.getBlock("latest"); |
| 469 | + const body = encodeBalanceCheckMessageBody( |
| 470 | + nonce, |
| 471 | + balance, |
| 472 | + false, |
| 473 | + latestBlock.timestamp |
| 474 | + ); |
| 475 | + const encodedMessage = encodeCCTPMessage( |
| 476 | + await crossChainMasterStrategy.peerDomainID(), |
| 477 | + crossChainRemoteStrategy.address, |
| 478 | + crossChainMasterStrategy.address, |
| 479 | + body |
| 480 | + ); |
| 481 | + |
| 482 | + await expect(messageTransmitter.processFront()) |
| 483 | + .to.emit(crossChainMasterStrategy, "RemoteStrategyBalanceUpdated") |
| 484 | + .withArgs(balance); |
| 485 | + await expect(await messageTransmitter.messagesInQueue()).to.eq(0); |
| 486 | + |
| 487 | + const transmitterSigner = await impersonateAndFund(messageTransmitter.address); |
| 488 | + await expect( |
| 489 | + crossChainMasterStrategy |
| 490 | + .connect(transmitterSigner) |
| 491 | + .relay(encodedMessage, "0x") |
| 492 | + ).to.be.revertedWith("Message already processed"); |
| 493 | + }); |
| 494 | + |
459 | 495 | it("Should emit a BalanceCheckIgnored event if balance update message is too old", async function () { |
460 | 496 | const { messageTransmitter, crossChainMasterStrategy } = fixture; |
461 | 497 | await sendBalanceUpdateToMaster(); |
|
0 commit comments