Skip to content

Commit

Permalink
(feat) Test compatibility in the reverse direction too
Browse files Browse the repository at this point in the history
  • Loading branch information
rrw-zilliqa committed Jul 15, 2024
1 parent b6f4db8 commit 2a6dd20
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion smart-contracts/test/zilbridge/TestingLockProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
38 changes: 38 additions & 0 deletions smart-contracts/test/zilbridge/ZilBridgeTokenBridge.compat.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 2a6dd20

Please sign in to comment.