From a7f2375a16d4b3a2c552061f2a526b6acec48c99 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Tue, 4 Dec 2018 20:28:11 +0530 Subject: [PATCH 1/9] Removed activate/deactivate logic from co-gateway. --- contracts/gateway/EIP20CoGateway.sol | 1 - contracts/gateway/EIP20Gateway.sol | 14 ++++++++ contracts/gateway/GatewayBase.sol | 12 ------- test/gateway/eip20_gateway/stake.js | 48 ++++++++++++++++++++-------- 4 files changed, 48 insertions(+), 27 deletions(-) diff --git a/contracts/gateway/EIP20CoGateway.sol b/contracts/gateway/EIP20CoGateway.sol index ebdb35b7..b1d0139b 100644 --- a/contracts/gateway/EIP20CoGateway.sol +++ b/contracts/gateway/EIP20CoGateway.sol @@ -900,7 +900,6 @@ contract EIP20CoGateway is GatewayBase { ) public payable - isActive returns (bytes32 messageHash_) { require( diff --git a/contracts/gateway/EIP20Gateway.sol b/contracts/gateway/EIP20Gateway.sol index 6dc0a059..e592d430 100644 --- a/contracts/gateway/EIP20Gateway.sol +++ b/contracts/gateway/EIP20Gateway.sol @@ -180,6 +180,9 @@ contract EIP20Gateway is GatewayBase { /* public variables */ + /** Specifies if the Gateway is activated for any new process. */ + bool public activated; + /** Escrow address to lock staked fund. */ SimpleStake public stakeVault; @@ -198,6 +201,17 @@ contract EIP20Gateway is GatewayBase { /** Maps messageHash to the Unstake object. */ mapping(bytes32 /*messageHash*/ => Unstake) unstakes; + /* modifiers */ + + /** checks that contract is activated */ + modifier isActive() { + require( + activated == true, + "Contract is restricted to use" + ); + _; + } + /* Constructor */ /** diff --git a/contracts/gateway/GatewayBase.sol b/contracts/gateway/GatewayBase.sol index 37631686..6293a074 100644 --- a/contracts/gateway/GatewayBase.sol +++ b/contracts/gateway/GatewayBase.sol @@ -73,9 +73,6 @@ contract GatewayBase { */ MessageBus.MessageBox messageBox; - /** Specifies if the Gateway is activated for any new process. */ - bool public activated; - /** Organisation address. */ address public organisation; @@ -138,15 +135,6 @@ contract GatewayBase { _; } - /** checks that contract is activated */ - modifier isActive() { - require( - activated == true, - "Contract is restricted to use" - ); - _; - } - /* Constructor */ /** diff --git a/test/gateway/eip20_gateway/stake.js b/test/gateway/eip20_gateway/stake.js index c623e56b..8e30927d 100644 --- a/test/gateway/eip20_gateway/stake.js +++ b/test/gateway/eip20_gateway/stake.js @@ -52,19 +52,7 @@ let mockToken, errorMessage; -async function _setup(accounts) { - - mockToken = await MockToken.new(); - baseToken = await MockToken.new(); - - bountyAmount = new BN(100); - gateway = await Gateway.new( - mockToken.address, - baseToken.address, - accounts[1], //core address - bountyAmount, - accounts[2] // organisation address - ); +async function _setup(accounts, gateway) { helper = new HelperKlass(gateway); gatewayTest = new EIP20GatewayKlass(gateway, mockToken, baseToken); @@ -160,7 +148,20 @@ contract('EIP20Gateway ', function (accounts) { describe('stake', async function () { beforeEach(async function () { - await _setup(accounts); + + mockToken = await MockToken.new(); + baseToken = await MockToken.new(); + + bountyAmount = new BN(100); + gateway = await Gateway.new( + mockToken.address, + baseToken.address, + accounts[1], //core address + bountyAmount, + accounts[2] // organisation address + ); + + await _setup(accounts, gateway); }); it('should fail to stake when stake amount is 0', async function () { @@ -319,6 +320,25 @@ contract('EIP20Gateway ', function (accounts) { await _stake(utils.ResultType.FAIL); }); + it('should fail stake if gateway is not activated.', async function () { + + let mockToken = await MockToken.new(); + let baseToken = await MockToken.new(); + let bountyAmount = new BN(100); + + gateway = await Gateway.new( + mockToken.address, + baseToken.address, + accounts[1], //core address + bountyAmount, + accounts[2] // organisation address + ); + + await _setup(accounts, gateway); + await _prepareData(); + await _stake(utils.ResultType.FAIL); + }); + }); }); From 51e49539049b83be83e5156fb1ab228da580da94 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Wed, 5 Dec 2018 11:28:43 +0530 Subject: [PATCH 2/9] Seperated activate and deactivate unit test logic. --- contracts/gateway/EIP20Gateway.sol | 4 +- contracts/gateway/GatewayBase.sol | 2 +- .../gateway/eip20_gateway/activate_gateway.js | 115 ++++++------------ .../eip20_gateway/deactivate_gateway.js | 54 ++++++++ 4 files changed, 94 insertions(+), 81 deletions(-) create mode 100644 test/gateway/eip20_gateway/deactivate_gateway.js diff --git a/contracts/gateway/EIP20Gateway.sol b/contracts/gateway/EIP20Gateway.sol index e592d430..58228258 100644 --- a/contracts/gateway/EIP20Gateway.sol +++ b/contracts/gateway/EIP20Gateway.sol @@ -207,7 +207,7 @@ contract EIP20Gateway is GatewayBase { modifier isActive() { require( activated == true, - "Contract is restricted to use" + "Gateway is not activated." ); _; } @@ -1036,7 +1036,7 @@ contract EIP20Gateway is GatewayBase { { require( activated == true, - "Gateway is already deactivated" + "Gateway is already deactivated." ); activated = false; return true; diff --git a/contracts/gateway/GatewayBase.sol b/contracts/gateway/GatewayBase.sol index 6293a074..9347c1f8 100644 --- a/contracts/gateway/GatewayBase.sol +++ b/contracts/gateway/GatewayBase.sol @@ -130,7 +130,7 @@ contract GatewayBase { modifier onlyOrganisation() { require( msg.sender == organisation, - "Only organisation can call the function" + "Only organisation can call the function." ); _; } diff --git a/test/gateway/eip20_gateway/activate_gateway.js b/test/gateway/eip20_gateway/activate_gateway.js index f65afc05..90ef12f1 100644 --- a/test/gateway/eip20_gateway/activate_gateway.js +++ b/test/gateway/eip20_gateway/activate_gateway.js @@ -3,90 +3,49 @@ const Gateway = artifacts.require("./EIP20Gateway.sol") const Utils = require('../../../test/test_lib/utils'); - -contract('GatewayBase.sol', function (accounts) { - - describe('Deactivate gateway', async () => { - let gateway; - let organisation = accounts[2]; - - beforeEach(async function () { - - let mockToken = accounts[0], - baseToken = accounts[1], - coreAddress = accounts[2], - bountyAmount = new BN(100); - - gateway = await Gateway.new( - mockToken, - baseToken, - coreAddress, - bountyAmount, - organisation - ); - - let coGateway = accounts[5]; - await gateway.activateGateway(coGateway, {from: organisation}); - - }); - - it('should deactivate if activated', async function () { - - assert((await gateway.deactivateGateway.call({from: organisation}))); - }); - - it('should not deactivate if already deactivated', async function () { - - await gateway.deactivateGateway({from: organisation}); - await Utils.expectThrow(gateway.deactivateGateway.call({from: organisation})); - }); - - it('should deactivated by organization only', async function () { - - await Utils.expectThrow(gateway.deactivateGateway.call({from: accounts[0]})); - }); - +contract('EIP20Gateway.activateGateway()', function (accounts) { + let gateway; + let organisation = accounts[2]; + let coGateway = accounts[5]; + + beforeEach(async function () { + let mockToken = accounts[0], + baseToken = accounts[1], + coreAddress = accounts[2], + bountyAmount = new BN(100); + + gateway = await Gateway.new( + mockToken, + baseToken, + coreAddress, + bountyAmount, + organisation + ); }); - describe('Activate Gateway', async () => { - let gateway; - let organisation = accounts[2]; - let coGateway = accounts[5]; - - beforeEach(async function () { - let mockToken = accounts[0], - baseToken = accounts[1], - coreAddress = accounts[2], - bountyAmount = new BN(100); - - gateway = await Gateway.new( - mockToken, - baseToken, - coreAddress, - bountyAmount, - organisation - ); - }); - - it('should activate if deActivated', async function () { + it('should activate if deActivated', async function () { - assert( - (await gateway.activateGateway.call(coGateway, {from: organisation})), - "Gateway activation failed, activateGateway returned false.", - ); - }); - - it('should not activate if already activated', async function () { + assert( + (await gateway.activateGateway.call(coGateway, {from: organisation})), + "Gateway activation failed, activateGateway returned false.", + ); + }); - await gateway.activateGateway(coGateway, {from: organisation}); - await Utils.expectThrow(gateway.activateGateway.call(coGateway, {from: organisation})); - }); + it('should not activate if already activated', async function () { - it('should be activated by organization only', async function () { + await gateway.activateGateway(coGateway, {from: organisation}); + await Utils.expectRevert( + gateway.activateGateway.call(coGateway, {from: organisation}), + 'Gateway was already activated once.' + ); + }); - await Utils.expectThrow(gateway.activateGateway.call(coGateway, {from: accounts[0]})); - }); + it('should be activated by organization only', async function () { + await Utils.expectRevert( + gateway.activateGateway.call(coGateway, {from: accounts[0]}), + 'Only organisation can call the function.' + ); }); - }); + diff --git a/test/gateway/eip20_gateway/deactivate_gateway.js b/test/gateway/eip20_gateway/deactivate_gateway.js new file mode 100644 index 00000000..ad526e6c --- /dev/null +++ b/test/gateway/eip20_gateway/deactivate_gateway.js @@ -0,0 +1,54 @@ +const Gateway = artifacts.require("./EIP20Gateway.sol") + , BN = require('bn.js'); + +const Utils = require('../../../test/test_lib/utils'); + + +contract('EIP20Gateway.deactivateGateway()', function (accounts) { + + let gateway; + let organisation = accounts[2]; + + beforeEach(async function () { + + let mockToken = accounts[0], + baseToken = accounts[1], + coreAddress = accounts[2], + bountyAmount = new BN(100); + + gateway = await Gateway.new( + mockToken, + baseToken, + coreAddress, + bountyAmount, + organisation + ); + + let coGateway = accounts[5]; + await gateway.activateGateway(coGateway, {from: organisation}); + + }); + + it('should deactivate if activated', async function () { + + assert((await gateway.deactivateGateway.call({from: organisation}))); + }); + + it('should not deactivate if already deactivated', async function () { + + await gateway.deactivateGateway({from: organisation}); + await Utils.expectRevert( + gateway.deactivateGateway.call({from: organisation}), + 'Gateway is already deactivated.' + ); + }); + + it('should deactivated by organization only', async function () { + + await Utils.expectRevert( + gateway.deactivateGateway.call({from: accounts[0]}), + 'Only organisation can call the function.' + ); + }); + +}); From e1da4752a606a1b0e4af673a21bc8a5bcc9c5ca1 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Wed, 5 Dec 2018 20:26:32 +0530 Subject: [PATCH 3/9] Added assert for activate flag in activate and deactivate gateway unit tests --- test/gateway/eip20_gateway/activate_gateway.js | 7 +++++++ test/gateway/eip20_gateway/deactivate_gateway.js | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/test/gateway/eip20_gateway/activate_gateway.js b/test/gateway/eip20_gateway/activate_gateway.js index 90ef12f1..d7854f95 100644 --- a/test/gateway/eip20_gateway/activate_gateway.js +++ b/test/gateway/eip20_gateway/activate_gateway.js @@ -29,6 +29,13 @@ contract('EIP20Gateway.activateGateway()', function (accounts) { (await gateway.activateGateway.call(coGateway, {from: organisation})), "Gateway activation failed, activateGateway returned false.", ); + + await gateway.activateGateway.call(coGateway, {from: organisation}); + + assert( + (await gateway.activated.call()), + 'Activation flag is false but expected as true.' + ); }); it('should not activate if already activated', async function () { diff --git a/test/gateway/eip20_gateway/deactivate_gateway.js b/test/gateway/eip20_gateway/deactivate_gateway.js index ad526e6c..967ab3bd 100644 --- a/test/gateway/eip20_gateway/deactivate_gateway.js +++ b/test/gateway/eip20_gateway/deactivate_gateway.js @@ -32,6 +32,13 @@ contract('EIP20Gateway.deactivateGateway()', function (accounts) { it('should deactivate if activated', async function () { assert((await gateway.deactivateGateway.call({from: organisation}))); + + await gateway.deactivateGateway.call({from: organisation}); + + assert( + !(await gateway.activated.call()), + 'Activation flag is true but expected as false.' + ); }); it('should not deactivate if already deactivated', async function () { From 3eeafc254feaa492c039ccb1e3f8fac7fc0b20c6 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Wed, 5 Dec 2018 21:59:39 +0530 Subject: [PATCH 4/9] Fixed broken tests for active and deactive gateway --- test/gateway/eip20_gateway/activate_gateway.js | 2 +- test/gateway/eip20_gateway/deactivate_gateway.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/gateway/eip20_gateway/activate_gateway.js b/test/gateway/eip20_gateway/activate_gateway.js index d7854f95..fa5c334a 100644 --- a/test/gateway/eip20_gateway/activate_gateway.js +++ b/test/gateway/eip20_gateway/activate_gateway.js @@ -30,7 +30,7 @@ contract('EIP20Gateway.activateGateway()', function (accounts) { "Gateway activation failed, activateGateway returned false.", ); - await gateway.activateGateway.call(coGateway, {from: organisation}); + await gateway.activateGateway(coGateway, {from: organisation}); assert( (await gateway.activated.call()), diff --git a/test/gateway/eip20_gateway/deactivate_gateway.js b/test/gateway/eip20_gateway/deactivate_gateway.js index 967ab3bd..7f5ba1b3 100644 --- a/test/gateway/eip20_gateway/deactivate_gateway.js +++ b/test/gateway/eip20_gateway/deactivate_gateway.js @@ -33,7 +33,7 @@ contract('EIP20Gateway.deactivateGateway()', function (accounts) { assert((await gateway.deactivateGateway.call({from: organisation}))); - await gateway.deactivateGateway.call({from: organisation}); + await gateway.deactivateGateway({from: organisation}); assert( !(await gateway.activated.call()), From 96b2d94e2b141e097f31b6f5842d43c4da64556b Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Mon, 10 Dec 2018 08:49:11 +0530 Subject: [PATCH 5/9] PR feedback comments. --- contracts/gateway/EIP20Gateway.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/gateway/EIP20Gateway.sol b/contracts/gateway/EIP20Gateway.sol index 0b06d184..4a93e3d4 100644 --- a/contracts/gateway/EIP20Gateway.sol +++ b/contracts/gateway/EIP20Gateway.sol @@ -202,7 +202,7 @@ contract EIP20Gateway is GatewayBase { /* modifiers */ - /** checks that contract is activated */ + /** Checks that contract is active. */ modifier isActive() { require( activated == true, From 65612c092012d24c502e80d83e4d8bce63bd7fb8 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Mon, 10 Dec 2018 09:26:09 +0530 Subject: [PATCH 6/9] Fixed broken unit tests --- .../gateway/eip20_gateway/activate_gateway.js | 28 ++----------------- .../eip20_gateway/deactivate_gateway.js | 23 +++++++++------ 2 files changed, 16 insertions(+), 35 deletions(-) diff --git a/test/gateway/eip20_gateway/activate_gateway.js b/test/gateway/eip20_gateway/activate_gateway.js index c0b675d1..fb47c16f 100644 --- a/test/gateway/eip20_gateway/activate_gateway.js +++ b/test/gateway/eip20_gateway/activate_gateway.js @@ -5,7 +5,7 @@ const BN = require('bn.js'); const Utils = require('../../../test/test_lib/utils'); -contract('EIP20Gateway.(de)activateGateway()', function (accounts) { +contract('EIP20Gateway.activateGateway()', function (accounts) { let gateway; let coGateway = accounts[5]; @@ -31,30 +31,6 @@ contract('EIP20Gateway.(de)activateGateway()', function (accounts) { ); }); - it('should deactivate if activated', async function () { - - await gateway.activateGateway(coGateway, { from: owner }); - assert((await gateway.deactivateGateway.call({ from: owner }))); - await gateway.deactivateGateway({ from: owner }); - assert( - !(await gateway.activated.call()), - 'Activation flag is true but expected as false.' - ); - }); - - it('should not deactivate if already deactivated', async function () { - - await gateway.activateGateway(coGateway, { from: owner }); - await gateway.deactivateGateway({ from: owner }); - await Utils.expectThrow(gateway.deactivateGateway.call({ from: owner })); - }); - - it('should deactivated by organization only', async function () { - - await gateway.activateGateway(coGateway, { from: owner }); - await Utils.expectThrow(gateway.deactivateGateway.call({ from: accounts[0] })); - }); - it('should activate if deActivated', async function () { assert( @@ -83,7 +59,7 @@ contract('EIP20Gateway.(de)activateGateway()', function (accounts) { await Utils.expectRevert( gateway.activateGateway.call(coGateway, {from: accounts[0]}), - 'Only organisation can call the function.' + 'Only the organization is allowed to call this method.' ); }); }); diff --git a/test/gateway/eip20_gateway/deactivate_gateway.js b/test/gateway/eip20_gateway/deactivate_gateway.js index 7f5ba1b3..534de4dd 100644 --- a/test/gateway/eip20_gateway/deactivate_gateway.js +++ b/test/gateway/eip20_gateway/deactivate_gateway.js @@ -1,5 +1,6 @@ const Gateway = artifacts.require("./EIP20Gateway.sol") , BN = require('bn.js'); +const MockMembersManager = artifacts.require('MockMembersManager.sol'); const Utils = require('../../../test/test_lib/utils'); @@ -7,7 +8,10 @@ const Utils = require('../../../test/test_lib/utils'); contract('EIP20Gateway.deactivateGateway()', function (accounts) { let gateway; - let organisation = accounts[2]; + let owner = accounts[2]; + let worker = accounts[3]; + let coGateway = accounts[5]; + let membersManager; beforeEach(async function () { @@ -16,24 +20,25 @@ contract('EIP20Gateway.deactivateGateway()', function (accounts) { coreAddress = accounts[2], bountyAmount = new BN(100); + membersManager = await MockMembersManager.new(owner, worker); + gateway = await Gateway.new( mockToken, baseToken, coreAddress, bountyAmount, - organisation + membersManager.address ); - let coGateway = accounts[5]; - await gateway.activateGateway(coGateway, {from: organisation}); + await gateway.activateGateway(coGateway, {from: owner}); }); it('should deactivate if activated', async function () { - assert((await gateway.deactivateGateway.call({from: organisation}))); + assert((await gateway.deactivateGateway.call({from: owner}))); - await gateway.deactivateGateway({from: organisation}); + await gateway.deactivateGateway({from: owner}); assert( !(await gateway.activated.call()), @@ -43,9 +48,9 @@ contract('EIP20Gateway.deactivateGateway()', function (accounts) { it('should not deactivate if already deactivated', async function () { - await gateway.deactivateGateway({from: organisation}); + await gateway.deactivateGateway({from: owner}); await Utils.expectRevert( - gateway.deactivateGateway.call({from: organisation}), + gateway.deactivateGateway.call({from: owner}), 'Gateway is already deactivated.' ); }); @@ -54,7 +59,7 @@ contract('EIP20Gateway.deactivateGateway()', function (accounts) { await Utils.expectRevert( gateway.deactivateGateway.call({from: accounts[0]}), - 'Only organisation can call the function.' + 'Only the organization is allowed to call this method.' ); }); From 00bf3d3e59d744746459725332a502c24efea68a Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Mon, 10 Dec 2018 13:52:22 +0530 Subject: [PATCH 7/9] PR review feedback around unit test cases --- contracts/gateway/EIP20Gateway.sol | 50 +++++++++++-------- contracts/gateway/GatewayBase.sol | 2 +- .../gateway/eip20_gateway/activate_gateway.js | 49 +++++++++++++++--- .../eip20_gateway/deactivate_gateway.js | 11 +++- 4 files changed, 80 insertions(+), 32 deletions(-) diff --git a/contracts/gateway/EIP20Gateway.sol b/contracts/gateway/EIP20Gateway.sol index 066af21a..291900ae 100644 --- a/contracts/gateway/EIP20Gateway.sol +++ b/contracts/gateway/EIP20Gateway.sol @@ -201,7 +201,8 @@ contract EIP20Gateway is GatewayBase { /** Maps messageHash to the Unstake object. */ mapping(bytes32 /*messageHash*/ => Unstake) unstakes; - /* modifiers */ + + /* Modifiers */ /** Checks that contract is active. */ modifier isActive() { @@ -212,6 +213,7 @@ contract EIP20Gateway is GatewayBase { _; } + /* Constructor */ /** @@ -259,6 +261,7 @@ contract EIP20Gateway is GatewayBase { stakeVault = new SimpleStake(_token, address(this)); } + /* External functions */ /** @@ -792,12 +795,12 @@ contract EIP20Gateway is GatewayBase { bytes32 _messageHash, bytes32 _unlockSecret ) - external - returns ( - uint256 redeemAmount_, - uint256 unstakeAmount_, - uint256 rewardAmount_ - ) + external + returns ( + uint256 redeemAmount_, + uint256 unstakeAmount_, + uint256 rewardAmount_ + ) { // Get the inital gas uint256 initialGas = gasleft(); @@ -851,12 +854,12 @@ contract EIP20Gateway is GatewayBase { uint256 _blockHeight, uint256 _messageStatus ) - public - returns ( - uint256 redeemAmount_, - uint256 unstakeAmount_, - uint256 rewardAmount_ - ) + public + returns ( + uint256 redeemAmount_, + uint256 unstakeAmount_, + uint256 rewardAmount_ + ) { // Get the inital gas uint256 initialGas = gasleft(); @@ -912,14 +915,14 @@ contract EIP20Gateway is GatewayBase { function confirmRevertRedeemIntent( bytes32 _messageHash, uint256 _blockHeight, - bytes calldata _rlpEncodedParentNodes - ) - external - returns ( - address redeemer_, - uint256 redeemerNonce_, - uint256 amount_ + ` bytes calldata _rlpEncodedParentNodes ) + external + returns ( + address redeemer_, + uint256 redeemerNonce_, + uint256 amount_ + ) { // Get the initial gas value uint256 initialGas = gasleft(); @@ -985,13 +988,17 @@ contract EIP20Gateway is GatewayBase { * @return success_ `true` if value is set */ function activateGateway( - address _coGatewayAddress + address _coGatewayAddress ) external onlyOrganization returns (bool success_) { + require( + _coGatewayAddress != address(0), + "Co-gateway address must not be zero." + ); require( remoteGateway == address(0), "Gateway was already activated once." @@ -1116,6 +1123,7 @@ contract EIP20Gateway is GatewayBase { _unlockSecret ); } + /** * @notice This is internal method for process unstake called from external * methods which processUnstake(with hashlock) and diff --git a/contracts/gateway/GatewayBase.sol b/contracts/gateway/GatewayBase.sol index f9e8f083..29a0d8dd 100644 --- a/contracts/gateway/GatewayBase.sol +++ b/contracts/gateway/GatewayBase.sol @@ -79,7 +79,7 @@ contract GatewayBase is Organized { CoreInterface public core; /** Path to make Merkle account proof for Gateway/CoGateway contract. */ - bytes internal encodedGatewayPath; +` bytes public encodedGatewayPath; /** * Remote gateway contract address. If this is a gateway contract, then the diff --git a/test/gateway/eip20_gateway/activate_gateway.js b/test/gateway/eip20_gateway/activate_gateway.js index fb47c16f..a74318d9 100644 --- a/test/gateway/eip20_gateway/activate_gateway.js +++ b/test/gateway/eip20_gateway/activate_gateway.js @@ -3,8 +3,9 @@ const MockMembersManager = artifacts.require('MockMembersManager.sol'); const BN = require('bn.js'); const Utils = require('../../../test/test_lib/utils'); +const web3 = require('../../../test/test_lib/web3.js'); - +const zeroAddress = "0x0000000000000000000000000000000000000000"; contract('EIP20Gateway.activateGateway()', function (accounts) { let gateway; @@ -31,34 +32,66 @@ contract('EIP20Gateway.activateGateway()', function (accounts) { ); }); - it('should activate if deActivated', async function () { + it('should activate if not already activated', async function () { + + let isSuccess = await gateway.activateGateway.call(coGateway, {from: owner}); - assert( - (await gateway.activateGateway.call(coGateway, {from: owner})), + assert.strictEqual( + isSuccess, + true, "Gateway activation failed, activateGateway returned false.", ); await gateway.activateGateway(coGateway, {from: owner}); + let isActivated = await gateway.activated.call(); - assert( - (await gateway.activated.call()), + assert.strictEqual( + isActivated, + true, 'Activation flag is false but expected as true.' ); + + let actualCoGateway = await gateway.remoteGateway.call(); + + assert.strictEqual( + coGateway, + actualCoGateway, + "Actual cogateway address is different from expected address." + ); + + let actualEncodedGatewayPath = await gateway.encodedGatewayPath.call(); + let expectedEncodedGatewayPath = web3.utils.sha3(coGateway); + + assert.strictEqual( + expectedEncodedGatewayPath, + actualEncodedGatewayPath, + "Actual encoded gateway path address is different from expected." + ); + }); it('should not activate if already activated', async function () { await gateway.activateGateway(coGateway, {from: owner}); + await Utils.expectRevert( - gateway.activateGateway.call(coGateway, {from: owner}), + gateway.activateGateway(coGateway, {from: owner}), 'Gateway was already activated once.' ); }); + it('should not activate with zero co-gateway address', async function () { + + await Utils.expectRevert( + gateway.activateGateway(zeroAddress, {from: owner}), + 'Co-gateway address must not be zero.' + ); + }); + it('should be activated by organization only', async function () { await Utils.expectRevert( - gateway.activateGateway.call(coGateway, {from: accounts[0]}), + gateway.activateGateway(coGateway, {from: accounts[0]}), 'Only the organization is allowed to call this method.' ); }); diff --git a/test/gateway/eip20_gateway/deactivate_gateway.js b/test/gateway/eip20_gateway/deactivate_gateway.js index 534de4dd..5502c011 100644 --- a/test/gateway/eip20_gateway/deactivate_gateway.js +++ b/test/gateway/eip20_gateway/deactivate_gateway.js @@ -36,12 +36,19 @@ contract('EIP20Gateway.deactivateGateway()', function (accounts) { it('should deactivate if activated', async function () { - assert((await gateway.deactivateGateway.call({from: owner}))); + let isSuccess = await gateway.deactivateGateway.call({from: owner}); + + assert.strictEqual( + isSuccess, + true, + "Gateway deactivation failed, deactivateGateway returned false.", + ); await gateway.deactivateGateway({from: owner}); + let isActivated = await gateway.activated.call(); assert( - !(await gateway.activated.call()), + !isActivated, 'Activation flag is true but expected as false.' ); }); From 48ed97dce7251ecb879f72b951e9d2282b46290e Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Mon, 10 Dec 2018 13:54:42 +0530 Subject: [PATCH 8/9] Changed assert -> assert.strictEqual --- test/gateway/eip20_gateway/deactivate_gateway.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/gateway/eip20_gateway/deactivate_gateway.js b/test/gateway/eip20_gateway/deactivate_gateway.js index 5502c011..1c6b3b29 100644 --- a/test/gateway/eip20_gateway/deactivate_gateway.js +++ b/test/gateway/eip20_gateway/deactivate_gateway.js @@ -47,8 +47,9 @@ contract('EIP20Gateway.deactivateGateway()', function (accounts) { await gateway.deactivateGateway({from: owner}); let isActivated = await gateway.activated.call(); - assert( - !isActivated, + assert.strictEqual( + isActivated, + false, 'Activation flag is true but expected as false.' ); }); From 55535300f4cedc784ccadce83036d73a2eb1f37c Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Mon, 10 Dec 2018 13:57:21 +0530 Subject: [PATCH 9/9] Fixed typo --- contracts/gateway/EIP20Gateway.sol | 2 +- contracts/gateway/GatewayBase.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/gateway/EIP20Gateway.sol b/contracts/gateway/EIP20Gateway.sol index 291900ae..d1055f50 100644 --- a/contracts/gateway/EIP20Gateway.sol +++ b/contracts/gateway/EIP20Gateway.sol @@ -915,7 +915,7 @@ contract EIP20Gateway is GatewayBase { function confirmRevertRedeemIntent( bytes32 _messageHash, uint256 _blockHeight, - ` bytes calldata _rlpEncodedParentNodes + bytes calldata _rlpEncodedParentNodes ) external returns ( diff --git a/contracts/gateway/GatewayBase.sol b/contracts/gateway/GatewayBase.sol index 29a0d8dd..3f8df5ba 100644 --- a/contracts/gateway/GatewayBase.sol +++ b/contracts/gateway/GatewayBase.sol @@ -79,7 +79,7 @@ contract GatewayBase is Organized { CoreInterface public core; /** Path to make Merkle account proof for Gateway/CoGateway contract. */ -` bytes public encodedGatewayPath; + bytes public encodedGatewayPath; /** * Remote gateway contract address. If this is a gateway contract, then the