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