-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(fix) Fix behaviour when scale == 0 (feat) Start of V4 tests
- Loading branch information
1 parent
0034e16
commit b2a3f4c
Showing
4 changed files
with
204 additions
and
33 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
48 changes: 48 additions & 0 deletions
48
smart-contracts/test/periphery/TokenManagerDeployers/TestTokenManagerDeployer.sol
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,48 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity 0.8.20; | ||
|
||
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; | ||
import {TokenManagerUpgradeableV4, ITokenManagerV4Events} from "contracts/periphery/TokenManagerV4/TokenManagerUpgradeableV4.sol"; | ||
import {ITokenManager, ITokenManagerFees, ITokenManagerStructs, ITokenManagerEvents} from "contracts/periphery/TokenManagerV2/TokenManagerUpgradeableV2.sol"; | ||
import {ITokenManagerFeesEvents} from "contracts/periphery/TokenManagerV2/TokenManagerFees.sol"; | ||
import {IRelayer} from "contracts/core/Relayer.sol"; | ||
import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol"; | ||
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | ||
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
import {TestToken} from "test/Helpers.sol"; | ||
import {LockAndReleaseTokenManagerDeployer} from "test/periphery/TokenManagerDeployers/LockAndReleaseTokenManagerDeployer.sol"; | ||
|
||
contract TestTokenManagerUpgradeableV4 is TokenManagerUpgradeableV4 { | ||
event TransferEvent(address indexed token, address indexed from, uint indexed amount); | ||
event AcceptEvent(address indexed token, address indexed from, uint indexed amount); | ||
|
||
constructor() { | ||
_disableInitializers(); | ||
} | ||
|
||
function initialize(uint fees) external initializer { | ||
__TokenManager_init(address(0)); | ||
_setFees(fees); | ||
} | ||
|
||
function _handleTransfer(address token, address from, uint amount) internal override { | ||
emit TransferEvent(token, from, amount); | ||
} | ||
|
||
function _handleAccept(address token, address recipient, uint amount) internal override { | ||
emit AcceptEvent(token, recipient, amount); | ||
} | ||
|
||
} | ||
|
||
abstract contract TestTokenManagerDeployer { | ||
function deployTestTokenManagerV4(uint fees) public returns (TestTokenManagerUpgradeableV4) { | ||
address implementation = address(new TestTokenManagerUpgradeableV4()); | ||
address proxy = address(new ERC1967Proxy(implementation, | ||
abi.encodeCall( | ||
TestTokenManagerUpgradeableV4.initialize, | ||
fees))); | ||
return TestTokenManagerUpgradeableV4(proxy); | ||
} | ||
|
||
} |
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
114 changes: 114 additions & 0 deletions
114
smart-contracts/test/periphery/TokenManagerV4/TokenManagerUpgradeableV4.t.sol
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,114 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity 0.8.20; | ||
|
||
import {Tester} from "test/Tester.sol"; | ||
import {TokenManagerUpgradeableV4, ITokenManagerV4Events} from "contracts/periphery/TokenManagerV4/TokenManagerUpgradeableV4.sol"; | ||
import {ITokenManager, ITokenManagerFees, ITokenManagerStructs, ITokenManagerEvents} from "contracts/periphery/TokenManagerV2/TokenManagerUpgradeableV2.sol"; | ||
import {ITokenManagerFeesEvents} from "contracts/periphery/TokenManagerV2/TokenManagerFees.sol"; | ||
import {IRelayer} from "contracts/core/Relayer.sol"; | ||
import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol"; | ||
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | ||
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
import {TestToken} from "test/Helpers.sol"; | ||
import { TestTokenManagerDeployer } from "test/periphery/TokenManagerDeployers/TestTokenManagerDeployer.sol"; | ||
|
||
|
||
contract TokenManagerUpgradeableV4Tests is Tester, ITokenManagerStructs, ITokenManagerEvents, ITokenManagerV4Events, TestTokenManagerDeployer { | ||
address deployer = vm.addr(1); | ||
address user = vm.createWallet("user").addr; | ||
uint fees = 0.1 ether; | ||
TokenManagerUpgradeableV4 tokenManager; | ||
TestToken token1; | ||
address remoteTokenAddr = vm.createWallet("remoteToken").addr; | ||
address remoteTokenManagerAddr = vm.createWallet("remoteTokenManager").addr; | ||
uint remoteChainId = 101; | ||
RemoteToken remoteToken = | ||
RemoteToken({ | ||
token: remoteTokenAddr, | ||
tokenManager: remoteTokenManagerAddr, | ||
chainId: remoteChainId | ||
}); | ||
uint transferAmount = 10 ether; | ||
|
||
function setUp() external { | ||
vm.startPrank(deployer); | ||
tokenManager = deployTestTokenManagerV4(fees); | ||
token1 = new TestToken(transferAmount); | ||
vm.stopPrank(); | ||
} | ||
|
||
// You shouldn't be able to remove a token without being the owner | ||
function test_removeTokenPermissions() external { | ||
startHoax(deployer); | ||
assertEq(tokenManager.owner(), deployer); | ||
|
||
tokenManager.registerTokenWithScale(address(token1), remoteToken, 2); | ||
{ | ||
RemoteToken memory tokrec; | ||
int8 tokscale; | ||
(tokrec, tokscale) = tokenManager.getRemoteTokenWithScale(address(token1), remoteChainId); | ||
assertEq(tokrec.chainId, remoteChainId); | ||
assertEq(tokrec.token, remoteTokenAddr); | ||
assertEq(tokrec.tokenManager, remoteTokenManagerAddr); | ||
assertEq(tokscale, 2); | ||
} | ||
vm.stopPrank(); | ||
|
||
startHoax(user); | ||
vm.expectRevert(); | ||
tokenManager.removeToken(address(token1), remoteChainId); | ||
vm.stopPrank(); | ||
} | ||
|
||
// You shouldn't be able to register a token without being the owner. | ||
function test_registerWithScalePermissions() external { | ||
startHoax(user); | ||
vm.expectRevert(); | ||
tokenManager.registerTokenWithScale(address(token1), remoteToken, 0); | ||
|
||
// Scale for unregistered tokens should be 0 | ||
RemoteToken memory tokrec; | ||
int8 tokscale; | ||
(tokrec, tokscale) = tokenManager.getRemoteTokenWithScale(address(token1), 101); | ||
assertEq(tokrec.chainId, 0); | ||
assertEq(tokrec.token, address(0)); | ||
assertEq(tokrec.tokenManager, address(0)); | ||
assertEq(tokscale, 0); | ||
|
||
vm.stopPrank(); | ||
} | ||
|
||
|
||
// Legacy registrations are handled by other tests. | ||
|
||
// Test the registration function. | ||
function test_registerWithScale() external { | ||
startHoax(deployer); | ||
|
||
assertEq(tokenManager.owner(), deployer); | ||
|
||
tokenManager.registerTokenWithScale(address(token1), remoteToken, 2); | ||
{ | ||
RemoteToken memory tokrec; | ||
int8 tokscale; | ||
(tokrec, tokscale) = tokenManager.getRemoteTokenWithScale(address(token1), remoteChainId); | ||
assertEq(tokrec.chainId, remoteChainId); | ||
assertEq(tokrec.token, remoteTokenAddr); | ||
assertEq(tokrec.tokenManager, remoteTokenManagerAddr); | ||
assertEq(tokscale, 2); | ||
} | ||
|
||
tokenManager.removeToken(address(token1), remoteChainId); | ||
{ | ||
RemoteToken memory tokrec; | ||
int8 tokscale; | ||
(tokrec, tokscale) = tokenManager.getRemoteTokenWithScale(address(token1), remoteChainId); | ||
assertEq(tokrec.chainId, 0); | ||
assertEq(tokrec.token, address(0)); | ||
assertEq(tokrec.tokenManager, address(0)); | ||
assertEq(tokscale, 0); | ||
} | ||
|
||
vm.stopPrank(); | ||
} | ||
} |