From fb45615730fb35edeab8aea3261b69df59821629 Mon Sep 17 00:00:00 2001 From: Deepesh Kumar Nath Date: Fri, 18 Jan 2019 15:12:55 +0530 Subject: [PATCH 1/6] Initial code. --- contracts/gateway/GatewayBase.sol | 68 +++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/contracts/gateway/GatewayBase.sol b/contracts/gateway/GatewayBase.sol index a94bc0ff..d95d9b53 100644 --- a/contracts/gateway/GatewayBase.sol +++ b/contracts/gateway/GatewayBase.sol @@ -338,6 +338,74 @@ contract GatewayBase is Organized { emit BountyChangeConfirmed(previousBountyAmount_, changedBountyAmount_); } + /** + * @notice Method to get the outbox message status for the given message + * hash. + * + * @dev If message hash do not exists then it will return undeclared status. + * + * @param _messageHash Message hash to get the status. + * + * @return status_ Message status. + */ + function getOutboxMessageStatus( + bytes32 _messageHash + ) + external + view + returns (MessageBus.MessageStatus status_) + { + status_ = messageBox.outbox[_messageHash]; + } + + /** + * @notice Method to get the inbox message status for the given message + * hash. + * + * @dev If message hash do not exists then it will return undeclared status. + * + * @param _messageHash Message hash to get the status. + * + * @return status_ Message status. + */ + function getInboxMessageStatus( + bytes32 _messageHash + ) + external + view + returns (MessageBus.MessageStatus status_) + { + status_ = messageBox.outbox[_messageHash]; + } + + /** + * @notice Method to get the active message hash and its status from inbox + * for the given account address. + * + * @dev If message hash do not exists for the given account address then + * it will return zero hash and undeclared status. + * + * @param _account Account address + * + * @return messageHash_ Message hash. + * @return status_ Message status. + */ + function getInboxActiveProcess( + address _account + ) + external + view + returns ( + bytes32 messageHash_, + MessageBus.MessageStatus status_ + ) + { + + } + + function getOutboxActiveProcess() { + + } /* Internal Functions */ From cccd0f8b2d15f1a1458629aa368f656eb4db933b Mon Sep 17 00:00:00 2001 From: Deepesh Kumar Nath Date: Fri, 18 Jan 2019 19:47:57 +0530 Subject: [PATCH 2/6] Added test cases --- contracts/gateway/GatewayBase.sol | 33 +++- contracts/test/gateway/TestGatewayBase.sol | 159 ++++++++++++++++++ migrations/2_deploy_contracts.js | 5 +- .../gateway_base/get_inbox_active_process.js | 113 +++++++++++++ .../gateway_base/get_inbox_message_status.js | 91 ++++++++++ .../gateway_base/get_outbox_active_process.js | 113 +++++++++++++ .../gateway_base/get_outbox_message_status.js | 91 ++++++++++ 7 files changed, 598 insertions(+), 7 deletions(-) create mode 100644 contracts/test/gateway/TestGatewayBase.sol create mode 100644 test/gateway/gateway_base/get_inbox_active_process.js create mode 100644 test/gateway/gateway_base/get_inbox_message_status.js create mode 100644 test/gateway/gateway_base/get_outbox_active_process.js create mode 100644 test/gateway/gateway_base/get_outbox_message_status.js diff --git a/contracts/gateway/GatewayBase.sol b/contracts/gateway/GatewayBase.sol index d95d9b53..696c814a 100644 --- a/contracts/gateway/GatewayBase.sol +++ b/contracts/gateway/GatewayBase.sol @@ -375,11 +375,11 @@ contract GatewayBase is Organized { view returns (MessageBus.MessageStatus status_) { - status_ = messageBox.outbox[_messageHash]; + status_ = messageBox.inbox[_messageHash]; } /** - * @notice Method to get the active message hash and its status from inbox + * @notice Method to get the active message hash and its status from outbox * for the given account address. * * @dev If message hash do not exists for the given account address then @@ -400,11 +400,34 @@ contract GatewayBase is Organized { MessageBus.MessageStatus status_ ) { - + messageHash_ = inboxActiveProcess[_account]; + status_ = messageBox.inbox[messageHash_]; } - function getOutboxActiveProcess() { - + /** + * @notice Method to get the active message hash and its status from outbox + * for the given account address. + * + * @dev If message hash do not exists for the given account address then + * it will return zero hash and undeclared status. + * + * @param _account Account address + * + * @return messageHash_ Message hash. + * @return status_ Message status. + */ + function getOutboxActiveProcess( + address _account + ) + external + view + returns ( + bytes32 messageHash_, + MessageBus.MessageStatus status_ + ) + { + messageHash_ = outboxActiveProcess[_account]; + status_ = messageBox.outbox[messageHash_]; } /* Internal Functions */ diff --git a/contracts/test/gateway/TestGatewayBase.sol b/contracts/test/gateway/TestGatewayBase.sol new file mode 100644 index 00000000..cf71af95 --- /dev/null +++ b/contracts/test/gateway/TestGatewayBase.sol @@ -0,0 +1,159 @@ +pragma solidity ^0.5.0; + +import "../../StateRootInterface.sol"; +import "../../gateway/GatewayBase.sol"; +import "../../lib/OrganizationInterface.sol"; + +/** + * @title TestGatewayBase contract. + * + * @notice Used for test only. + */ +contract TestGatewayBase is GatewayBase { + + /* Constructor */ + + /** + * @notice This is used for testing. + * + * @param _stateRootProvider Contract address which implements + * StateRootInterface. + * @param _bounty The amount that facilitator will stakes to initiate the + * stake process. + * @param _organization Address of a contract that manages workers. + */ + constructor( + StateRootInterface _stateRootProvider, + uint256 _bounty, + OrganizationInterface _organization + ) + public + GatewayBase( + _stateRootProvider, + _bounty, + _organization + ) + {} + + /* external functions */ + + /** + * @notice It is used to set a message. + * + * @dev This is used for testing purpose. + * + * @param _intentHash Intent hash. + * @param _nonce Nonce of the message sender address. + * @param _gasPrice Gas price that message sender is ready to pay to + * transfer message. + * @param _gasLimit Gas limit that message sender is ready to pay. + * @param _sender Message sender address. + * @param _hashLock Hash Lock provided by the facilitator. + * + * @return messageHash_ Hash unique for every request. + */ + function setMessage( + bytes32 _intentHash, + uint256 _nonce, + uint256 _gasPrice, + uint256 _gasLimit, + address _sender, + bytes32 _hashLock + ) + external + returns (bytes32 messageHash_) + { + MessageBus.Message memory message = getMessage( + _intentHash, + _nonce, + _gasPrice, + _gasLimit, + _sender, + _hashLock + ); + + messageHash_ = MessageBus.messageDigest( + message.intentHash, + message.nonce, + message.gasPrice, + message.gasLimit, + message.sender, + message.hashLock + ); + + messages[messageHash_] = message; + + } + + /** + * @notice It sets the status of inbox. + * + * @dev This is used for testing purpose. + * + * @param _messageHash It sets the status of the message. + * @param _status It sets the state of the message. + */ + function setInboxStatus( + bytes32 _messageHash, + MessageBus.MessageStatus _status + ) + external + { + messageBox.inbox[_messageHash] = _status; + } + + /** + * @notice It sets the status of outbox. + * + * @dev This is used for testing purpose. + * + * @param _messageHash MessageHash for which status is the be set. + * @param _status Status of the message to be set. + */ + function setOutboxStatus( + bytes32 _messageHash, + MessageBus.MessageStatus _status + ) + external + { + messageBox.outbox[_messageHash] = _status; + } + + /** + * @notice It sets the message hash for active inbox process. + * + * @dev This is used for testing purpose. + * + * @param _account Account address. + * @param _nonce Nonce of account address. + * @param _messageHash MessageHash for which status is the be set. + */ + function setInboxProcess( + address _account, + uint256 _nonce, + bytes32 _messageHash + ) + external + { + super.registerInboxProcess(_account, _nonce, _messageHash); + } + + /** + * @notice It sets the message hash for active outbox process. + * + * @dev This is used for testing purpose. + * + * @param _account Account address. + * @param _nonce Nonce of account address. + * @param _messageHash MessageHash for which status is the be set. + */ + function setOutboxProcess( + address _account, + uint256 _nonce, + bytes32 _messageHash + ) + external + { + super.registerOutboxProcess(_account, _nonce, _messageHash); + } +} diff --git a/migrations/2_deploy_contracts.js b/migrations/2_deploy_contracts.js index d39c2dfa..5a7253c3 100644 --- a/migrations/2_deploy_contracts.js +++ b/migrations/2_deploy_contracts.js @@ -4,6 +4,7 @@ const GatewayBase = artifacts.require("./gateway/GatewayBase.sol"); const EIP20Gateway = artifacts.require("EIP20Gateway"); const MockGatewayLib = artifacts.require("MockGatewayLib"); const MockGatewayBase = artifacts.require("MockGatewayBase"); +const TestGatewayBase = artifacts.require("TestGatewayBase"); const MetaBlock = artifacts.require("../contracts/lib/MetaBlock.sol"); const BlockStore = artifacts.require("../contracts/BlockStore.sol"); const TestEIP20Gateway = artifacts.require("TestEIP20Gateway"); @@ -37,8 +38,8 @@ module.exports = function (deployer) { deployer.deploy(GatewayLib); deployer.deploy(MockGatewayLib); deployer.deploy(MetaBlock); - deployer.link(GatewayLib, [GatewayBase, EIP20Gateway, TestEIP20Gateway, EIP20CoGateway, TestEIP20CoGateway]); - deployer.link(MessageBus, [EIP20CoGateway, TestEIP20CoGateway, TestEIP20Gateway, EIP20Gateway]); + deployer.link(GatewayLib, [GatewayBase, TestGatewayBase, EIP20Gateway, TestEIP20Gateway, EIP20CoGateway, TestEIP20CoGateway]); + deployer.link(MessageBus, [EIP20CoGateway, TestEIP20CoGateway, TestEIP20Gateway, EIP20Gateway, TestGatewayBase]); deployer.link(MockGatewayLib, [MockGatewayBase, TestEIP20Gateway]); deployer.link(MetaBlock, [BlockStore, AuxiliaryBlockStore]); diff --git a/test/gateway/gateway_base/get_inbox_active_process.js b/test/gateway/gateway_base/get_inbox_active_process.js new file mode 100644 index 00000000..41996d60 --- /dev/null +++ b/test/gateway/gateway_base/get_inbox_active_process.js @@ -0,0 +1,113 @@ +// Copyright 2019 OpenST Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ---------------------------------------------------------------------------- +// +// http://www.simpletoken.org/ +// +// ---------------------------------------------------------------------------- + +const GatewayBase = artifacts.require('./TestGatewayBase.sol'); +const BN = require("bn.js"); +const web3 = require('../../test_lib/web3.js'); +const messageBus = require('../../test_lib/message_bus.js'); +const MessageStatusEnum = messageBus.MessageStatusEnum; +const Utils = require('../../../test/test_lib/utils'); +const zeroBytes = Utils.ZERO_BYTES32; + +contract('GatewayBase.getInboxActiveProcess()', function (accounts) { + + let gatewayBase, messageHash, accountAddress; + + beforeEach(async function () { + + gatewayBase = await GatewayBase.new( + accounts[0], + new BN(100), + accounts[1], + ); + + accountAddress = accounts[2]; + messageHash = web3.utils.sha3("message_hash"); + + await gatewayBase.setInboxProcess( + accountAddress, + new BN(1), + messageHash + ); + + }); + + it('should return correct message hash and message status', async function () { + + await gatewayBase.setInboxStatus(messageHash, MessageStatusEnum.Declared); + + let result = await gatewayBase.getInboxActiveProcess(accountAddress); + + assert.strictEqual( + result.status_.eqn(MessageStatusEnum.Declared), + true, + `Message status ${result.status_.toString(10)} must be equal to ${MessageStatusEnum.Declared}`, + ); + + assert.strictEqual( + result.messageHash_, + messageHash, + `Message hash ${result.messageHash_} must be equal to ${messageHash}`, + ); + + // Change the message status. + + await gatewayBase.setInboxStatus(messageHash, MessageStatusEnum.Revoked); + + result = await gatewayBase.getInboxActiveProcess(accountAddress); + + assert.strictEqual( + result.status_.eqn(MessageStatusEnum.Revoked), + true, + `Message status ${result.status_.toString(10)} must be equal to ${MessageStatusEnum.Revoked}`, + ); + + assert.strictEqual( + result.messageHash_, + messageHash, + `Message hash ${result.messageHash_} must be equal to ${messageHash}`, + ); + + }); + + it('should return zero message hash and undeclared message status when the ' + + 'account address does not have active inbox process', async function () { + + await gatewayBase.setInboxStatus(messageHash, MessageStatusEnum.Declared); + + accountAddress = accounts[5]; + + let result = await gatewayBase.getInboxActiveProcess(accountAddress); + + assert.strictEqual( + result.status_.eqn(MessageStatusEnum.Undeclared), + true, + `Message status ${result.status_.toString(10)} must be equal to ${MessageStatusEnum.Undeclared}`, + ); + + assert.strictEqual( + result.messageHash_, + zeroBytes, + `Message hash ${result.messageHash_} must be equal to ${zeroBytes}`, + ); + + }); + +}); diff --git a/test/gateway/gateway_base/get_inbox_message_status.js b/test/gateway/gateway_base/get_inbox_message_status.js new file mode 100644 index 00000000..6f402867 --- /dev/null +++ b/test/gateway/gateway_base/get_inbox_message_status.js @@ -0,0 +1,91 @@ +// Copyright 2019 OpenST Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ---------------------------------------------------------------------------- +// +// http://www.simpletoken.org/ +// +// ---------------------------------------------------------------------------- + +const GatewayBase = artifacts.require('./TestGatewayBase.sol'); +const BN = require("bn.js"); +const web3 = require('../../test_lib/web3.js'); +const messageBus = require('../../test_lib/message_bus.js'); +const MessageStatusEnum = messageBus.MessageStatusEnum; + +contract('GatewayBase.getInboxMessageStatus()', function (accounts) { + + let gatewayBase, messageHash; + + beforeEach(async function () { + + gatewayBase = await GatewayBase.new( + accounts[0], + new BN(100), + accounts[1], + ); + + messageHash = web3.utils.sha3("message_hash"); + + }); + + it('should return correct message status', async function () { + + let status = await gatewayBase.getInboxMessageStatus(messageHash); + + assert.strictEqual( + status.eqn(MessageStatusEnum.Undeclared), + true, + `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.Undeclared}`, + ); + + await gatewayBase.setInboxStatus(messageHash, MessageStatusEnum.Declared); + status = await gatewayBase.getInboxMessageStatus(messageHash); + + assert.strictEqual( + status.eqn(MessageStatusEnum.Declared), + true, + `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.Declared}`, + ); + + await gatewayBase.setInboxStatus(messageHash, MessageStatusEnum.Progressed); + status = await gatewayBase.getInboxMessageStatus(messageHash); + + assert.strictEqual( + status.eqn(MessageStatusEnum.Progressed), + true, + `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.Progressed}`, + ); + + await gatewayBase.setInboxStatus(messageHash, MessageStatusEnum.DeclaredRevocation); + status = await gatewayBase.getInboxMessageStatus(messageHash); + + assert.strictEqual( + status.eqn(MessageStatusEnum.DeclaredRevocation), + true, + `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.DeclaredRevocation}`, + ); + + await gatewayBase.setInboxStatus(messageHash, MessageStatusEnum.Revoked); + status = await gatewayBase.getInboxMessageStatus(messageHash); + + assert.strictEqual( + status.eqn(MessageStatusEnum.Revoked), + true, + `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.Revoked}`, + ); + + }); + +}); diff --git a/test/gateway/gateway_base/get_outbox_active_process.js b/test/gateway/gateway_base/get_outbox_active_process.js new file mode 100644 index 00000000..cc269152 --- /dev/null +++ b/test/gateway/gateway_base/get_outbox_active_process.js @@ -0,0 +1,113 @@ +// Copyright 2019 OpenST Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ---------------------------------------------------------------------------- +// +// http://www.simpletoken.org/ +// +// ---------------------------------------------------------------------------- + +const GatewayBase = artifacts.require('./TestGatewayBase.sol'); +const BN = require("bn.js"); +const web3 = require('../../test_lib/web3.js'); +const messageBus = require('../../test_lib/message_bus.js'); +const MessageStatusEnum = messageBus.MessageStatusEnum; +const Utils = require('../../../test/test_lib/utils'); +const zeroBytes = Utils.ZERO_BYTES32; + +contract('GatewayBase.getOutboxActiveProcess()', function (accounts) { + + let gatewayBase, messageHash, accountAddress; + + beforeEach(async function () { + + gatewayBase = await GatewayBase.new( + accounts[0], + new BN(100), + accounts[1], + ); + + accountAddress = accounts[2]; + messageHash = web3.utils.sha3("message_hash"); + + await gatewayBase.setOutboxProcess( + accountAddress, + new BN(1), + messageHash + ); + + }); + + it('should return correct message hash and message status', async function () { + + await gatewayBase.setOutboxStatus(messageHash, MessageStatusEnum.Declared); + + let result = await gatewayBase.getOutboxActiveProcess(accountAddress); + + assert.strictEqual( + result.status_.eqn(MessageStatusEnum.Declared), + true, + `Message status ${result.status_.toString(10)} must be equal to ${MessageStatusEnum.Declared}`, + ); + + assert.strictEqual( + result.messageHash_, + messageHash, + `Message hash ${result.messageHash_} must be equal to ${messageHash}`, + ); + + // Change the message status. + + await gatewayBase.setOutboxStatus(messageHash, MessageStatusEnum.Revoked); + + result = await gatewayBase.getOutboxActiveProcess(accountAddress); + + assert.strictEqual( + result.status_.eqn(MessageStatusEnum.Revoked), + true, + `Message status ${result.status_.toString(10)} must be equal to ${MessageStatusEnum.Revoked}`, + ); + + assert.strictEqual( + result.messageHash_, + messageHash, + `Message hash ${result.messageHash_} must be equal to ${messageHash}`, + ); + + }); + + it('should return zero message hash and undeclared message status when the ' + + 'account address does not have active outbox process', async function () { + + await gatewayBase.setOutboxStatus(messageHash, MessageStatusEnum.Declared); + + accountAddress = accounts[5]; + + let result = await gatewayBase.getOutboxActiveProcess(accountAddress); + + assert.strictEqual( + result.status_.eqn(MessageStatusEnum.Undeclared), + true, + `Message status ${result.status_.toString(10)} must be equal to ${MessageStatusEnum.Undeclared}`, + ); + + assert.strictEqual( + result.messageHash_, + zeroBytes, + `Message hash ${result.messageHash_} must be equal to ${zeroBytes}`, + ); + + }); + +}); diff --git a/test/gateway/gateway_base/get_outbox_message_status.js b/test/gateway/gateway_base/get_outbox_message_status.js new file mode 100644 index 00000000..20dd702d --- /dev/null +++ b/test/gateway/gateway_base/get_outbox_message_status.js @@ -0,0 +1,91 @@ +// Copyright 2019 OpenST Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ---------------------------------------------------------------------------- +// +// http://www.simpletoken.org/ +// +// ---------------------------------------------------------------------------- + +const GatewayBase = artifacts.require('./TestGatewayBase.sol'); +const BN = require("bn.js"); +const web3 = require('../../test_lib/web3.js'); +const messageBus = require('../../test_lib/message_bus.js'); +const MessageStatusEnum = messageBus.MessageStatusEnum; + +contract('GatewayBase.getOutboxMessageStatus()', function (accounts) { + + let gatewayBase, messageHash; + + beforeEach(async function () { + + gatewayBase = await GatewayBase.new( + accounts[0], + new BN(100), + accounts[1], + ); + + messageHash = web3.utils.sha3("message_hash"); + + }); + + it('should return correct message status', async function () { + + let status = await gatewayBase.getOutboxMessageStatus(messageHash); + + assert.strictEqual( + status.eqn(MessageStatusEnum.Undeclared), + true, + `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.Undeclared}`, + ); + + await gatewayBase.setOutboxStatus(messageHash, MessageStatusEnum.Declared); + status = await gatewayBase.getOutboxMessageStatus(messageHash); + + assert.strictEqual( + status.eqn(MessageStatusEnum.Declared), + true, + `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.Declared}`, + ); + + await gatewayBase.setOutboxStatus(messageHash, MessageStatusEnum.Progressed); + status = await gatewayBase.getOutboxMessageStatus(messageHash); + + assert.strictEqual( + status.eqn(MessageStatusEnum.Progressed), + true, + `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.Progressed}`, + ); + + await gatewayBase.setOutboxStatus(messageHash, MessageStatusEnum.DeclaredRevocation); + status = await gatewayBase.getOutboxMessageStatus(messageHash); + + assert.strictEqual( + status.eqn(MessageStatusEnum.DeclaredRevocation), + true, + `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.DeclaredRevocation}`, + ); + + await gatewayBase.setOutboxStatus(messageHash, MessageStatusEnum.Revoked); + status = await gatewayBase.getOutboxMessageStatus(messageHash); + + assert.strictEqual( + status.eqn(MessageStatusEnum.Revoked), + true, + `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.Revoked}`, + ); + + }); + +}); From 69b7c567cc510a77fc3afbbf70096f5548ccf74c Mon Sep 17 00:00:00 2001 From: Deepesh Kumar Nath Date: Fri, 18 Jan 2019 19:57:45 +0530 Subject: [PATCH 3/6] Code cleanup --- contracts/gateway/GatewayBase.sol | 40 -------- .../gateway_base/get_inbox_message_status.js | 91 ------------------- .../gateway_base/get_outbox_message_status.js | 91 ------------------- 3 files changed, 222 deletions(-) delete mode 100644 test/gateway/gateway_base/get_inbox_message_status.js delete mode 100644 test/gateway/gateway_base/get_outbox_message_status.js diff --git a/contracts/gateway/GatewayBase.sol b/contracts/gateway/GatewayBase.sol index 696c814a..6f1c3298 100644 --- a/contracts/gateway/GatewayBase.sol +++ b/contracts/gateway/GatewayBase.sol @@ -338,46 +338,6 @@ contract GatewayBase is Organized { emit BountyChangeConfirmed(previousBountyAmount_, changedBountyAmount_); } - /** - * @notice Method to get the outbox message status for the given message - * hash. - * - * @dev If message hash do not exists then it will return undeclared status. - * - * @param _messageHash Message hash to get the status. - * - * @return status_ Message status. - */ - function getOutboxMessageStatus( - bytes32 _messageHash - ) - external - view - returns (MessageBus.MessageStatus status_) - { - status_ = messageBox.outbox[_messageHash]; - } - - /** - * @notice Method to get the inbox message status for the given message - * hash. - * - * @dev If message hash do not exists then it will return undeclared status. - * - * @param _messageHash Message hash to get the status. - * - * @return status_ Message status. - */ - function getInboxMessageStatus( - bytes32 _messageHash - ) - external - view - returns (MessageBus.MessageStatus status_) - { - status_ = messageBox.inbox[_messageHash]; - } - /** * @notice Method to get the active message hash and its status from outbox * for the given account address. diff --git a/test/gateway/gateway_base/get_inbox_message_status.js b/test/gateway/gateway_base/get_inbox_message_status.js deleted file mode 100644 index 6f402867..00000000 --- a/test/gateway/gateway_base/get_inbox_message_status.js +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2019 OpenST Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ---------------------------------------------------------------------------- -// -// http://www.simpletoken.org/ -// -// ---------------------------------------------------------------------------- - -const GatewayBase = artifacts.require('./TestGatewayBase.sol'); -const BN = require("bn.js"); -const web3 = require('../../test_lib/web3.js'); -const messageBus = require('../../test_lib/message_bus.js'); -const MessageStatusEnum = messageBus.MessageStatusEnum; - -contract('GatewayBase.getInboxMessageStatus()', function (accounts) { - - let gatewayBase, messageHash; - - beforeEach(async function () { - - gatewayBase = await GatewayBase.new( - accounts[0], - new BN(100), - accounts[1], - ); - - messageHash = web3.utils.sha3("message_hash"); - - }); - - it('should return correct message status', async function () { - - let status = await gatewayBase.getInboxMessageStatus(messageHash); - - assert.strictEqual( - status.eqn(MessageStatusEnum.Undeclared), - true, - `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.Undeclared}`, - ); - - await gatewayBase.setInboxStatus(messageHash, MessageStatusEnum.Declared); - status = await gatewayBase.getInboxMessageStatus(messageHash); - - assert.strictEqual( - status.eqn(MessageStatusEnum.Declared), - true, - `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.Declared}`, - ); - - await gatewayBase.setInboxStatus(messageHash, MessageStatusEnum.Progressed); - status = await gatewayBase.getInboxMessageStatus(messageHash); - - assert.strictEqual( - status.eqn(MessageStatusEnum.Progressed), - true, - `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.Progressed}`, - ); - - await gatewayBase.setInboxStatus(messageHash, MessageStatusEnum.DeclaredRevocation); - status = await gatewayBase.getInboxMessageStatus(messageHash); - - assert.strictEqual( - status.eqn(MessageStatusEnum.DeclaredRevocation), - true, - `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.DeclaredRevocation}`, - ); - - await gatewayBase.setInboxStatus(messageHash, MessageStatusEnum.Revoked); - status = await gatewayBase.getInboxMessageStatus(messageHash); - - assert.strictEqual( - status.eqn(MessageStatusEnum.Revoked), - true, - `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.Revoked}`, - ); - - }); - -}); diff --git a/test/gateway/gateway_base/get_outbox_message_status.js b/test/gateway/gateway_base/get_outbox_message_status.js deleted file mode 100644 index 20dd702d..00000000 --- a/test/gateway/gateway_base/get_outbox_message_status.js +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2019 OpenST Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ---------------------------------------------------------------------------- -// -// http://www.simpletoken.org/ -// -// ---------------------------------------------------------------------------- - -const GatewayBase = artifacts.require('./TestGatewayBase.sol'); -const BN = require("bn.js"); -const web3 = require('../../test_lib/web3.js'); -const messageBus = require('../../test_lib/message_bus.js'); -const MessageStatusEnum = messageBus.MessageStatusEnum; - -contract('GatewayBase.getOutboxMessageStatus()', function (accounts) { - - let gatewayBase, messageHash; - - beforeEach(async function () { - - gatewayBase = await GatewayBase.new( - accounts[0], - new BN(100), - accounts[1], - ); - - messageHash = web3.utils.sha3("message_hash"); - - }); - - it('should return correct message status', async function () { - - let status = await gatewayBase.getOutboxMessageStatus(messageHash); - - assert.strictEqual( - status.eqn(MessageStatusEnum.Undeclared), - true, - `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.Undeclared}`, - ); - - await gatewayBase.setOutboxStatus(messageHash, MessageStatusEnum.Declared); - status = await gatewayBase.getOutboxMessageStatus(messageHash); - - assert.strictEqual( - status.eqn(MessageStatusEnum.Declared), - true, - `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.Declared}`, - ); - - await gatewayBase.setOutboxStatus(messageHash, MessageStatusEnum.Progressed); - status = await gatewayBase.getOutboxMessageStatus(messageHash); - - assert.strictEqual( - status.eqn(MessageStatusEnum.Progressed), - true, - `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.Progressed}`, - ); - - await gatewayBase.setOutboxStatus(messageHash, MessageStatusEnum.DeclaredRevocation); - status = await gatewayBase.getOutboxMessageStatus(messageHash); - - assert.strictEqual( - status.eqn(MessageStatusEnum.DeclaredRevocation), - true, - `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.DeclaredRevocation}`, - ); - - await gatewayBase.setOutboxStatus(messageHash, MessageStatusEnum.Revoked); - status = await gatewayBase.getOutboxMessageStatus(messageHash); - - assert.strictEqual( - status.eqn(MessageStatusEnum.Revoked), - true, - `Message status ${status.toString(10)} must be equal to ${MessageStatusEnum.Revoked}`, - ); - - }); - -}); From 2c1abb6799afe64dbd98494458a8b843091d47b0 Mon Sep 17 00:00:00 2001 From: Deepesh Kumar Nath Date: Fri, 18 Jan 2019 21:27:50 +0530 Subject: [PATCH 4/6] Added licence document --- contracts/gateway/GatewayBase.sol | 16 ++++++++-------- contracts/test/gateway/TestGatewayBase.sol | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/contracts/gateway/GatewayBase.sol b/contracts/gateway/GatewayBase.sol index 6f1c3298..51ad4791 100644 --- a/contracts/gateway/GatewayBase.sol +++ b/contracts/gateway/GatewayBase.sol @@ -345,7 +345,7 @@ contract GatewayBase is Organized { * @dev If message hash do not exists for the given account address then * it will return zero hash and undeclared status. * - * @param _account Account address + * @param _account Account address. * * @return messageHash_ Message hash. * @return status_ Message status. @@ -371,7 +371,7 @@ contract GatewayBase is Organized { * @dev If message hash do not exists for the given account address then * it will return zero hash and undeclared status. * - * @param _account Account address + * @param _account Account address. * * @return messageHash_ Message hash. * @return status_ Message status. @@ -396,13 +396,13 @@ contract GatewayBase is Organized { * @notice Calculate the fee amount which is rewarded to facilitator for * performing message transfers. * - * @param _gasConsumed gas consumption during message confirmation. - * @param _gasLimit maximum amount of gas can be used for reward. - * @param _gasPrice price at which reward is calculated - * @param _initialGas initial gas at the start of the process + * @param _gasConsumed Gas consumption during message confirmation. + * @param _gasLimit Maximum amount of gas can be used for reward. + * @param _gasPrice Price at which reward is calculated. + * @param _initialGas Initial gas at the start of the process. * - * @return fee amount - * @return totalGasConsumed_ total gas consumed during message transfer + * @return fee_ Fee amount. + * @return totalGasConsumed_ Total gas consumed during message transfer. */ function feeAmount( uint256 _gasConsumed, diff --git a/contracts/test/gateway/TestGatewayBase.sol b/contracts/test/gateway/TestGatewayBase.sol index cf71af95..29648212 100644 --- a/contracts/test/gateway/TestGatewayBase.sol +++ b/contracts/test/gateway/TestGatewayBase.sol @@ -1,5 +1,25 @@ pragma solidity ^0.5.0; +// Copyright 2019 OpenST Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ---------------------------------------------------------------------------- +// +// http://www.simpletoken.org/ +// +// ---------------------------------------------------------------------------- + import "../../StateRootInterface.sol"; import "../../gateway/GatewayBase.sol"; import "../../lib/OrganizationInterface.sol"; From 80df2bf8a7cf4ece3f17bbf0472b2787bc1c114d Mon Sep 17 00:00:00 2001 From: Deepesh Kumar Nath Date: Mon, 21 Jan 2019 09:36:59 +0530 Subject: [PATCH 5/6] Code review changes. --- contracts/gateway/GatewayBase.sol | 2 +- contracts/test/gateway/TestGatewayBase.sol | 8 +--- .../gateway_base/get_inbox_active_process.js | 46 ++++++++++++++++++- .../gateway_base/get_outbox_active_process.js | 46 ++++++++++++++++++- 4 files changed, 93 insertions(+), 9 deletions(-) diff --git a/contracts/gateway/GatewayBase.sol b/contracts/gateway/GatewayBase.sol index 51ad4791..18d60834 100644 --- a/contracts/gateway/GatewayBase.sol +++ b/contracts/gateway/GatewayBase.sol @@ -339,7 +339,7 @@ contract GatewayBase is Organized { } /** - * @notice Method to get the active message hash and its status from outbox + * @notice Method to get the active message hash and its status from inbox * for the given account address. * * @dev If message hash do not exists for the given account address then diff --git a/contracts/test/gateway/TestGatewayBase.sol b/contracts/test/gateway/TestGatewayBase.sol index 29648212..45cb0875 100644 --- a/contracts/test/gateway/TestGatewayBase.sol +++ b/contracts/test/gateway/TestGatewayBase.sol @@ -145,17 +145,15 @@ contract TestGatewayBase is GatewayBase { * @dev This is used for testing purpose. * * @param _account Account address. - * @param _nonce Nonce of account address. * @param _messageHash MessageHash for which status is the be set. */ function setInboxProcess( address _account, - uint256 _nonce, bytes32 _messageHash ) external { - super.registerInboxProcess(_account, _nonce, _messageHash); + super.registerInboxProcess(_account, 1, _messageHash); } /** @@ -164,16 +162,14 @@ contract TestGatewayBase is GatewayBase { * @dev This is used for testing purpose. * * @param _account Account address. - * @param _nonce Nonce of account address. * @param _messageHash MessageHash for which status is the be set. */ function setOutboxProcess( address _account, - uint256 _nonce, bytes32 _messageHash ) external { - super.registerOutboxProcess(_account, _nonce, _messageHash); + super.registerOutboxProcess(_account, 1, _messageHash); } } diff --git a/test/gateway/gateway_base/get_inbox_active_process.js b/test/gateway/gateway_base/get_inbox_active_process.js index 41996d60..87beb1b6 100644 --- a/test/gateway/gateway_base/get_inbox_active_process.js +++ b/test/gateway/gateway_base/get_inbox_active_process.js @@ -43,7 +43,6 @@ contract('GatewayBase.getInboxActiveProcess()', function (accounts) { await gatewayBase.setInboxProcess( accountAddress, - new BN(1), messageHash ); @@ -110,4 +109,49 @@ contract('GatewayBase.getInboxActiveProcess()', function (accounts) { }); + it('should return the most recent active process', async function () { + + await gatewayBase.setInboxStatus(messageHash, MessageStatusEnum.Progressed); + + let result = await gatewayBase.getInboxActiveProcess(accountAddress); + + assert.strictEqual( + result.status_.eqn(MessageStatusEnum.Progressed), + true, + `Message status ${result.status_.toString(10)} must be equal to ${MessageStatusEnum.Progressed}`, + ); + + assert.strictEqual( + result.messageHash_, + messageHash, + `Message hash ${result.messageHash_} must be equal to ${messageHash}`, + ); + + // Get the new message hash. + messageHash = web3.utils.sha3("message_hash_1"); + + // Set the new message hash as active inbox process. + await gatewayBase.setInboxProcess( + accountAddress, + messageHash + ); + + await gatewayBase.setInboxStatus(messageHash, MessageStatusEnum.Declared); + + result = await gatewayBase.getInboxActiveProcess(accountAddress); + + assert.strictEqual( + result.status_.eqn(MessageStatusEnum.Declared), + true, + `Message status ${result.status_.toString(10)} must be equal to ${MessageStatusEnum.Declared}`, + ); + + assert.strictEqual( + result.messageHash_, + messageHash, + `Message hash ${result.messageHash_} must be equal to ${messageHash}`, + ); + + }); + }); diff --git a/test/gateway/gateway_base/get_outbox_active_process.js b/test/gateway/gateway_base/get_outbox_active_process.js index cc269152..a6102819 100644 --- a/test/gateway/gateway_base/get_outbox_active_process.js +++ b/test/gateway/gateway_base/get_outbox_active_process.js @@ -43,7 +43,6 @@ contract('GatewayBase.getOutboxActiveProcess()', function (accounts) { await gatewayBase.setOutboxProcess( accountAddress, - new BN(1), messageHash ); @@ -110,4 +109,49 @@ contract('GatewayBase.getOutboxActiveProcess()', function (accounts) { }); + it('should return the most recent active process', async function () { + + await gatewayBase.setOutboxStatus(messageHash, MessageStatusEnum.Progressed); + + let result = await gatewayBase.getOutboxActiveProcess(accountAddress); + + assert.strictEqual( + result.status_.eqn(MessageStatusEnum.Progressed), + true, + `Message status ${result.status_.toString(10)} must be equal to ${MessageStatusEnum.Progressed}`, + ); + + assert.strictEqual( + result.messageHash_, + messageHash, + `Message hash ${result.messageHash_} must be equal to ${messageHash}`, + ); + + // Get the new message hash. + messageHash = web3.utils.sha3("message_hash_1"); + + // Set the new message hash as active inbox process. + await gatewayBase.setOutboxProcess( + accountAddress, + messageHash + ); + + await gatewayBase.setOutboxStatus(messageHash, MessageStatusEnum.Declared); + + result = await gatewayBase.getOutboxActiveProcess(accountAddress); + + assert.strictEqual( + result.status_.eqn(MessageStatusEnum.Declared), + true, + `Message status ${result.status_.toString(10)} must be equal to ${MessageStatusEnum.Declared}`, + ); + + assert.strictEqual( + result.messageHash_, + messageHash, + `Message hash ${result.messageHash_} must be equal to ${messageHash}`, + ); + + }); + }); From f2278f07211a73a82fc47f04a5ebcc4fd1fe301e Mon Sep 17 00:00:00 2001 From: Deepesh Kumar Nath Date: Mon, 21 Jan 2019 17:26:37 +0530 Subject: [PATCH 6/6] PR feddback changes. --- contracts/gateway/GatewayBase.sol | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/contracts/gateway/GatewayBase.sol b/contracts/gateway/GatewayBase.sol index 18d60834..3f3a3481 100644 --- a/contracts/gateway/GatewayBase.sol +++ b/contracts/gateway/GatewayBase.sol @@ -340,10 +340,9 @@ contract GatewayBase is Organized { /** * @notice Method to get the active message hash and its status from inbox - * for the given account address. - * - * @dev If message hash do not exists for the given account address then - * it will return zero hash and undeclared status. + * for the given account address. If message hash does not exist + * for the given account address then it will return zero hash and + * undeclared status. * * @param _account Account address. * @@ -366,10 +365,9 @@ contract GatewayBase is Organized { /** * @notice Method to get the active message hash and its status from outbox - * for the given account address. - * - * @dev If message hash do not exists for the given account address then - * it will return zero hash and undeclared status. + * for the given account address. If message hash does not exist + * for the given account address then it will return zero hash and + * undeclared status. * * @param _account Account address. *