@@ -483,16 +483,17 @@ contract TestRelayerEndToEndManual is
483
483
// Register sibling contracts for the manager and endpoint. Endpoints and manager each have the concept of siblings here.
484
484
managerChain1.setSibling (chainId2, bytes32 (uint256 (uint160 (address (managerChain2)))));
485
485
managerChain2.setSibling (chainId1, bytes32 (uint256 (uint160 (address (managerChain1)))));
486
+ }
486
487
488
+ function test_relayerEndpointAuth () public {
489
+ // Set up sensible WH endpoint siblings
487
490
wormholeEndpointChain1.setWormholeSibling (
488
491
chainId2, bytes32 (uint256 (uint160 ((address (wormholeEndpointChain2)))))
489
492
);
490
493
wormholeEndpointChain2.setWormholeSibling (
491
494
chainId1, bytes32 (uint256 (uint160 (address (wormholeEndpointChain1))))
492
495
);
493
- }
494
496
495
- function test_relayerEndpointAuth () public {
496
497
vm.recordLogs ();
497
498
vm.chainId (chainId1);
498
499
@@ -534,30 +535,8 @@ contract TestRelayerEndToEndManual is
534
535
vm.stopPrank ();
535
536
vm.chainId (chainId2);
536
537
537
- // Caller is not proper who to receive messages from
538
538
bytes [] memory a;
539
- wormholeEndpointChain2.setWormholeSibling (chainId1, bytes32 (uint256 (uint160 (address (0x1 )))));
540
- vm.startPrank (relayer);
541
- vm.expectRevert (
542
- abi.encodeWithSelector (
543
- IWormholeEndpoint.InvalidWormholeSibling.selector ,
544
- chainId1,
545
- address (wormholeEndpointChain1)
546
- )
547
- );
548
- wormholeEndpointChain2.receiveWormholeMessages (
549
- vaa.payload,
550
- a,
551
- bytes32 (uint256 (uint160 (address (wormholeEndpointChain1)))),
552
- vaa.emitterChainId,
553
- vaa.hash
554
- );
555
- vm.stopPrank ();
556
539
557
- // Bad manager sibling calling
558
- wormholeEndpointChain2.setWormholeSibling (
559
- chainId1, bytes32 (uint256 (uint160 (address (wormholeEndpointChain1))))
560
- );
561
540
managerChain2.setSibling (chainId1, bytes32 (uint256 (uint160 (address (0x1 )))));
562
541
vm.startPrank (relayer);
563
542
vm.expectRevert (); // bad manager sibling
@@ -624,4 +603,72 @@ contract TestRelayerEndToEndManual is
624
603
vaa.hash // Hash of the VAA being used
625
604
);
626
605
}
606
+
607
+ function test_relayerWithInvalidWHEndpoint () public {
608
+ // Set up dodgy wormhole endpoint siblings
609
+ wormholeEndpointChain2.setWormholeSibling (chainId1, bytes32 (uint256 (uint160 (address (0x1 )))));
610
+ wormholeEndpointChain1.setWormholeSibling (
611
+ chainId2, bytes32 (uint256 (uint160 (address (wormholeEndpointChain2))))
612
+ );
613
+
614
+ vm.recordLogs ();
615
+ vm.chainId (chainId1);
616
+
617
+ // Setting up the transfer
618
+ DummyToken token1 = DummyToken (managerChain1.token ());
619
+
620
+ uint8 decimals = token1.decimals ();
621
+ uint256 sendingAmount = 5 * 10 ** decimals;
622
+ token1.mintDummy (address (userA), 5 * 10 ** decimals);
623
+ vm.startPrank (userA);
624
+ token1.approve (address (managerChain1), sendingAmount);
625
+
626
+ // Send token through the relayer
627
+ {
628
+ vm.deal (userA, 1 ether);
629
+ managerChain1.transfer {
630
+ value: wormholeEndpointChain1.quoteDeliveryPrice (
631
+ chainId2, buildEndpointInstruction (false )
632
+ )
633
+ }(
634
+ sendingAmount,
635
+ chainId2,
636
+ bytes32 (uint256 (uint160 (userB))),
637
+ false ,
638
+ encodeEndpointInstruction (false )
639
+ );
640
+ }
641
+
642
+ // Get the messages from the logs for the sender
643
+ vm.chainId (chainId2);
644
+ Vm.Log[] memory entries = guardian.fetchWormholeMessageFromLog (vm.getRecordedLogs ());
645
+ bytes [] memory encodedVMs = new bytes [](entries.length );
646
+ for (uint256 i = 0 ; i < encodedVMs.length ; i++ ) {
647
+ encodedVMs[i] = guardian.fetchSignedMessageFromLogs (entries[i], chainId1);
648
+ }
649
+
650
+ IWormhole.VM memory vaa = wormhole.parseVM (encodedVMs[0 ]);
651
+
652
+ vm.stopPrank ();
653
+ vm.chainId (chainId2);
654
+
655
+ // Caller is not proper who to receive messages from
656
+ bytes [] memory a;
657
+ vm.startPrank (relayer);
658
+ vm.expectRevert (
659
+ abi.encodeWithSelector (
660
+ IWormholeEndpoint.InvalidWormholeSibling.selector ,
661
+ chainId1,
662
+ address (wormholeEndpointChain1)
663
+ )
664
+ );
665
+ wormholeEndpointChain2.receiveWormholeMessages (
666
+ vaa.payload,
667
+ a,
668
+ bytes32 (uint256 (uint160 (address (wormholeEndpointChain1)))),
669
+ vaa.emitterChainId,
670
+ vaa.hash
671
+ );
672
+ vm.stopPrank ();
673
+ }
627
674
}
0 commit comments