From 2a6dd20fe44160c3c82284c9317365e73411bdba Mon Sep 17 00:00:00 2001 From: Richard Watts Date: Mon, 15 Jul 2024 13:50:47 +0100 Subject: [PATCH] (feat) Test compatibility in the reverse direction too --- .../test/zilbridge/TestingLockProxy.sol | 2 +- .../ZilBridgeTokenBridge.compat.t.sol | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/smart-contracts/test/zilbridge/TestingLockProxy.sol b/smart-contracts/test/zilbridge/TestingLockProxy.sol index 51d57dc..9b25147 100644 --- a/smart-contracts/test/zilbridge/TestingLockProxy.sol +++ b/smart-contracts/test/zilbridge/TestingLockProxy.sol @@ -1886,7 +1886,7 @@ contract TestingLockProxy is ReentrancyGuard { return (codehash != accountHash && codehash != 0x0); } - function testing_transferIn(address assetHash, uint256 amount, uint callAmount) public { + function testing_transferIn(address assetHash, uint256 amount, uint callAmount) public payable { _transferIn(assetHash, amount, callAmount); } diff --git a/smart-contracts/test/zilbridge/ZilBridgeTokenBridge.compat.t.sol b/smart-contracts/test/zilbridge/ZilBridgeTokenBridge.compat.t.sol index 565808d..e6cefeb 100644 --- a/smart-contracts/test/zilbridge/ZilBridgeTokenBridge.compat.t.sol +++ b/smart-contracts/test/zilbridge/ZilBridgeTokenBridge.compat.t.sol @@ -183,4 +183,42 @@ contract ZilBridgeTokenBridgeCompatibilityTest is ZilBridgeTokenBridgeCompatibil sourceUser, remoteUser, amount); } + function test_wrappedCompatibilityNative() external { + // Get am amount + uint256 amount = originalTokenSupply; + startHoax(sourceUser); + uint256 gas = 1 ether; + vm.deal(sourceUser, amount + gas); + + uint256 sourceBalance = sourceUser.balance; + uint256 lockBalance = address(lockProxy).balance; + lockProxy.testing_transferIn{value: originalTokenSupply}(address(0), amount, amount); + mockRemoteLockProxy.testing_transferOut(remoteUser, address(remoteBridgedGasToken), amount); + + assertEq(remoteBridgedGasToken.balanceOf(remoteUser), amount); + assertLe(sourceUser.balance, sourceBalance - amount); + assertEq(address(lockProxy).balance, lockBalance + amount); + + // OK. Now transfer it back again. + transferFromRemoteUser(address(0), address(remoteBridgedGasToken), + sourceUser, remoteUser, amount); + } + + function test_wrappedCompatibilityBackward() external { + // Get an amount + uint256 amount = originalTokenSupply; + // Transfer it synthetically to the lock proxy at the remote + startHoax(remoteUser); + nativelyOnRemote.approve(address(mockRemoteLockProxy), amount); + mockRemoteLockProxy.testing_transferIn(address(nativelyOnRemote), amount, amount); + lockProxy.testing_transferOut(sourceUser, address(sourceNativelyOnRemote), amount); + + assertEq(sourceNativelyOnRemote.balanceOf(sourceUser), amount); + assertEq(nativelyOnRemote.balanceOf(remoteUser), 0); + assertEq(nativelyOnRemote.balanceOf(address(mockRemoteLockProxy)), amount); + + // Now transfer it back again + transferToRemoteUser(address(sourceNativelyOnRemote), address(nativelyOnRemote), + sourceUser, remoteUser, originalTokenSupply); + } }