diff --git a/contracts/bridge/TokenBridge.sol b/contracts/bridge/TokenBridge.sol index c302fbd..a0e93c9 100644 --- a/contracts/bridge/TokenBridge.sol +++ b/contracts/bridge/TokenBridge.sol @@ -36,10 +36,12 @@ contract TokenBridge is ManagerAccessControl { uint256 public depositTimeLock; uint256 public withdrawTimeLock; + bool public active; constructor(uint256 _timeLock) { depositTimeLock = _timeLock * 2; withdrawTimeLock = _timeLock; + active = true; } /// @notice Register the ERC20 token @@ -79,6 +81,13 @@ contract TokenBridge is ManagerAccessControl { emit ChangeTimeLock(depositTimeLock); } + event ChangeActive(bool); + + function setActive(bool _value) public onlyManager { + active = _value; + emit ChangeActive(_value); + } + enum States { INVALID, OPEN, @@ -137,6 +146,8 @@ contract TokenBridge is ManagerAccessControl { address _withdrawAddress, bytes32 _secretLock ) public onlyInvalidDepositBoxes(_boxID) onlyRegisteredToken(_tokenId) { + // Check if the exchange is activated. + require(active, "E004"); require(_withdrawAddress != address(0), "E003"); ERC20 token = tokens[_tokenId].token; diff --git a/test/bridge/TokenBridgeSwap.test.ts b/test/bridge/TokenBridgeSwap.test.ts index 902f17b..7612ea3 100644 --- a/test/bridge/TokenBridgeSwap.test.ts +++ b/test/bridge/TokenBridgeSwap.test.ts @@ -288,6 +288,54 @@ describe("Test Swap of TokenBridge", () => { }); }); + context("Test the stop function of the swap", async () => { + it("Create key by User", async () => { + const key_buffer = ContractUtils.createKey(); + const lock_buffer = ContractUtils.sha256(key_buffer); + key = ContractUtils.BufferToString(key_buffer); + lock = ContractUtils.BufferToString(lock_buffer); + lock_box_id = ContractUtils.BufferToString(ContractUtils.createLockBoxID()); + }); + + it("Inactive swap in EthNet", async () => { + await bridge_ethnet.connect(manager_signer).setActive(false); + assert.strictEqual(await bridge_ethnet.connect(manager_signer).active(), false); + }); + + it("Open the lock box in EthNet", async () => { + await token_ethnet.connect(user_eth_signer).approve(bridge_ethnet.address, swap_amount.value); + await expect( + bridge_ethnet + .connect(user_eth_signer) + .openDeposit(token_id_ethnet, lock_box_id, swap_amount.value, user_biz.address, lock) + ).to.be.reverted; + }); + + it("Active swap in EthNet", async () => { + await bridge_ethnet.connect(manager_signer).setActive(true); + assert.strictEqual(await bridge_ethnet.connect(manager_signer).active(), true); + }); + + it("Inactive swap in BizNet", async () => { + await bridge_biznet.connect(manager_signer).setActive(false); + assert.strictEqual(await bridge_biznet.connect(manager_signer).active(), false); + }); + + it("Open the lock box in BizNet", async () => { + await token_biznet.connect(user_biz_signer).approve(bridge_biznet.address, swap_amount.value); + await expect( + bridge_biznet + .connect(user_biz_signer) + .openDeposit(token_id_biznet, lock_box_id, swap_amount.value, user_eth.address, lock) + ).to.be.reverted; + }); + + it("Active swap in BizNet", async () => { + await bridge_biznet.connect(manager_signer).setActive(true); + assert.strictEqual(await bridge_biznet.connect(manager_signer).active(), true); + }); + }); + context("Expiry Deposit Lock Box", async () => { const lockBox_expiry = ContractUtils.BufferToString(ContractUtils.createLockBoxID());