-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
108 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "forge-std/Test.sol"; | ||
import "forge-std/Vm.sol"; | ||
|
||
import "contracts/prototypes/evm/GatewayEVM.sol"; | ||
import "contracts/prototypes/evm/GatewayEVMUpgradeTest.sol"; | ||
import "contracts/prototypes/evm/ReceiverEVM.sol"; | ||
import "contracts/prototypes/evm/ERC20CustodyNew.sol"; | ||
import "contracts/prototypes/evm/TestERC20.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; | ||
import "../evm/interfaces.sol"; | ||
import {Upgrades} from "openzeppelin-foundry-upgrades/LegacyUpgrades.sol"; | ||
|
||
contract GatewayEVMUUPSUpgradeTest is Test, IGatewayEVMErrors, IGatewayEVMEvents, IReceiverEVMEvents { | ||
using SafeERC20 for IERC20; | ||
event ExecutedV2(address indexed destination, uint256 value, bytes data); | ||
|
||
address proxy; | ||
GatewayEVM gateway; | ||
ReceiverEVM receiver; | ||
ERC20CustodyNew custody; | ||
TestERC20 token; | ||
address owner; | ||
address destination; | ||
address tssAddress; | ||
|
||
function setUp() public { | ||
owner = address(this); | ||
destination = address(0x1234); | ||
tssAddress = address(0x5678); | ||
|
||
token = new TestERC20("test", "TTK"); | ||
|
||
proxy = address(new ERC1967Proxy( | ||
address(new GatewayEVM()), | ||
abi.encodeWithSelector(GatewayEVM.initialize.selector, (tssAddress)) | ||
)); | ||
gateway = GatewayEVM(proxy); | ||
|
||
custody = new ERC20CustodyNew(address(gateway)); | ||
receiver = new ReceiverEVM(); | ||
|
||
gateway.setCustody(address(custody)); | ||
|
||
// Mint initial supply to the owner | ||
token.mint(owner, 1000000); | ||
|
||
// Transfer some tokens to the custody contract | ||
token.transfer(address(custody), 500000); | ||
} | ||
|
||
function testUpgradeAndForwardCallToReceivePayable() public { | ||
address custodyBeforeUpgrade = gateway.custody(); | ||
address tssBeforeUpgrade = gateway.tssAddress(); | ||
|
||
string memory str = "Hello, Foundry!"; | ||
uint256 num = 42; | ||
bool flag = true; | ||
uint256 value = 1 ether; | ||
|
||
vm.prank(owner); | ||
Upgrades.upgradeProxy( | ||
proxy, | ||
"GatewayEVMUpgradeTest.sol", | ||
"", | ||
owner | ||
); | ||
|
||
bytes memory data = abi.encodeWithSignature("receivePayable(string,uint256,bool)", str, num, flag); | ||
GatewayEVMUpgradeTest gatewayUpgradeTest = GatewayEVMUpgradeTest(proxy); | ||
|
||
vm.expectCall(address(receiver), value, data); | ||
vm.expectEmit(true, true, true, true, address(receiver)); | ||
emit ReceivedPayable(address(gateway), value, str, num, flag); | ||
vm.expectEmit(true, true, true, true, address(gateway)); | ||
emit ExecutedV2(address(receiver), value, data); | ||
gateway.execute{value: value}(address(receiver), data); | ||
|
||
assertEq(custodyBeforeUpgrade, gateway.custody()); | ||
assertEq(tssBeforeUpgrade, gateway.tssAddress()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
@openzeppelin/=node_modules/@openzeppelin/ | ||
@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/ | ||
forge-std/=lib/forge-std/src/ |
This file was deleted.
Oops, something went wrong.