diff --git a/contracts/gateway/GatewayBase.sol b/contracts/gateway/GatewayBase.sol index 3f3a3481..8a1da7ec 100644 --- a/contracts/gateway/GatewayBase.sol +++ b/contracts/gateway/GatewayBase.sol @@ -154,7 +154,7 @@ contract GatewayBase is Organized { * @param _stateRootProvider Contract address which implements * StateRootInterface. * @param _bounty The amount that facilitator will stakes to initiate the - * stake process. + * message transfers. * @param _organization Address of an organization contract. */ constructor( @@ -338,6 +338,44 @@ contract GatewayBase is Organized { emit BountyChangeConfirmed(previousBountyAmount_, changedBountyAmount_); } + /** + * @notice Method to get the outbox message status for the given message + * hash. If message hash does not exist 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. If message hash does not exist 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 inbox * for the given account address. If message hash does not exist @@ -388,6 +426,7 @@ contract GatewayBase is Organized { status_ = messageBox.outbox[messageHash_]; } + /* Internal Functions */ /** @@ -396,7 +435,7 @@ contract GatewayBase is Organized { * * @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 _gasPrice Gas price at which reward is calculated. * @param _initialGas Initial gas at the start of the process. * * @return fee_ Fee amount. diff --git a/contracts/test/gateway/TestGatewayBase.sol b/contracts/test/gateway/TestGatewayBase.sol index 45cb0875..d2de76b3 100644 --- a/contracts/test/gateway/TestGatewayBase.sol +++ b/contracts/test/gateway/TestGatewayBase.sol @@ -39,7 +39,7 @@ contract TestGatewayBase is GatewayBase { * @param _stateRootProvider Contract address which implements * StateRootInterface. * @param _bounty The amount that facilitator will stakes to initiate the - * stake process. + * message transfers. * @param _organization Address of a contract that manages workers. */ constructor( 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_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}`, + ); + + }); + +});