@@ -11,6 +11,7 @@ import "wormhole-solidity-sdk/testing/helpers/WormholeSimulator.sol";
11
11
import "openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Proxy.sol " ;
12
12
import "./libraries/TransceiverHelpers.sol " ;
13
13
import "./libraries/NttManagerHelpers.sol " ;
14
+ import "wormhole-solidity-sdk/libraries/BytesParsing.sol " ;
14
15
15
16
pragma solidity >= 0.8.8 < 0.9.0 ;
16
17
@@ -19,6 +20,7 @@ contract TestRateLimit is Test, IRateLimiterEvents {
19
20
20
21
using TrimmedAmountLib for uint256 ;
21
22
using TrimmedAmountLib for TrimmedAmount;
23
+ using BytesParsing for bytes ;
22
24
23
25
uint16 constant chainId = 7 ;
24
26
@@ -731,54 +733,64 @@ contract TestRateLimit is Test, IRateLimiterEvents {
731
733
return transceivers;
732
734
}
733
735
736
+ function expectRevert (
737
+ address contractAddress ,
738
+ bytes memory encodedSignature ,
739
+ string memory expectedRevert
740
+ ) internal {
741
+ (bool success , bytes memory result ) = contractAddress.call (
742
+ encodedSignature
743
+ );
744
+ require (! success, "call did not revert " );
745
+
746
+ console.log ("result: %s " , result.length );
747
+ // // compare revert strings
748
+ bytes32 expectedRevertHash = keccak256 (abi.encode (expectedRevert));
749
+ (bytes memory res ,) = result.slice (4 , result.length - 4 );
750
+ bytes32 actualRevertHash = keccak256 (abi.encodePacked (res));
751
+ require (
752
+ expectedRevertHash == actualRevertHash,
753
+ "call did not revert as expected "
754
+ );
755
+ }
756
+
734
757
// transfer tokens from user_A to user_B
735
758
// this consumes capacity on the outbound side
736
759
// send tokens from user_B to user_A
737
760
// this consumes capacity on the inbound side
738
761
// send tokens from user_A to user_B
739
762
// this should consume capacity on the outbound side
740
763
// and backfill the inbound side
741
- function testFuzz_CircularFlowBackFilling (uint64 mintAmt , uint256 transferAmt ) public {
742
- mintAmt = uint64 (bound (mintAmt, 2 , type (uint256 ).max));
743
- transferAmt = uint64 (bound (transferAmt, 1 , mintAmt - 1 ));
764
+ function testFuzz_CircularFlowBackFilling (uint256 mintAmt , uint256 transferAmt ) public {
765
+ mintAmt = bound (mintAmt, 1 , type (uint256 ).max);
766
+ // enforces transferAmt <= mintAmt
767
+ transferAmt = bound (transferAmt, 0 , mintAmt);
744
768
745
769
(address user_A , address user_B , DummyToken token , uint8 decimals ) = setupToken ();
746
770
747
- TrimmedAmount mintAmount = packTrimmedAmount (mintAmt, 8 );
771
+ // allow for amounts greater than uint64 to check if [`setOutboundLimit`] reverts
772
+ // on amounts greater than u64 MAX.
773
+ if (mintAmt.scale (decimals, 8 ) > type (uint64 ).max) {
774
+ vm.expectRevert ("SafeCast: value doesn't fit in 64 bits " );
775
+ nttManager.setOutboundLimit (mintAmt);
776
+
777
+ return ;
778
+ }
779
+
780
+ nttManager.setOutboundLimit (mintAmt);
781
+ TrimmedAmount mintAmount = mintAmt.trim (decimals, 8 );
748
782
token.mintDummy (address (user_A), mintAmount.untrim (decimals));
749
783
nttManager.setOutboundLimit (mintAmount.untrim (decimals));
750
784
751
- // transfer 10 tokens
752
785
vm.startPrank (user_A);
753
-
754
- // TrimmedAmount memory transferAmount = TrimmedAmount(transferAmt, 8);
755
786
token.approve (address (nttManager), type (uint256 ).max);
756
787
757
- // TODO: also fuzz the fromDecimals?
758
-
759
- // allow for amounts greater than uint64 to check if [`transfer`] reverts
760
- // on amounts greater than u64 MAX.
761
788
TrimmedAmount transferAmount = transferAmt.trim (decimals, 8 );
762
789
763
790
// check error conditions
791
+ // revert if amount to be transferred is 0
764
792
if (transferAmount.getAmount () == 0 ) {
765
- vm.expectRevert ();
766
- // transfer tokens from user_A -> user_B via the nttManager
767
- nttManager.transfer (
768
- transferAmount.untrim (decimals),
769
- chainId,
770
- toWormholeFormat (user_B),
771
- false ,
772
- new bytes (1 )
773
- );
774
-
775
- return ;
776
- }
777
-
778
- if (transferAmount.getAmount () > type (uint64 ).max) {
779
- bytes4 selector = bytes4 (keccak256 ("AmountTooLarge(uint256) " ));
780
- vm.expectRevert (abi.encodeWithSelector (selector, transferAmt));
781
-
793
+ vm.expectRevert (abi.encodeWithSelector (INttManager.ZeroAmount.selector ));
782
794
nttManager.transfer (
783
795
transferAmount.untrim (decimals),
784
796
chainId,
0 commit comments