Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getter function to get message status for a given message hash. #602

Merged
merged 10 commits into from
Jan 22, 2019
43 changes: 41 additions & 2 deletions contracts/gateway/GatewayBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -388,6 +426,7 @@ contract GatewayBase is Organized {
status_ = messageBox.outbox[messageHash_];
}


/* Internal Functions */

/**
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/gateway/TestGatewayBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
91 changes: 91 additions & 0 deletions test/gateway/gateway_base/get_inbox_message_status.js
Original file line number Diff line number Diff line change
@@ -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}`,
);

});

});
91 changes: 91 additions & 0 deletions test/gateway/gateway_base/get_outbox_message_status.js
Original file line number Diff line number Diff line change
@@ -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}`,
);

});

});