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

Unit test case uncommented for complete protocol with mock contract f… #66

Merged
merged 1 commit into from
Dec 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions contracts/ProtocolVersioned.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ contract ProtocolVersioned {
/// protocol if they disagree with the new proposed protocol
/// @dev from OpenST ^v1.0 this constant will be set to a significant value
/// ~ 1 week at 15 seconds per block
uint256 constant public PROTOCOL_TRANSFER_BLOCKS_TO_WAIT = 40320;
uint256 constant private PROTOCOL_TRANSFER_BLOCKS_TO_WAIT = 40320;

/*
* Storage
Expand Down Expand Up @@ -99,7 +99,7 @@ contract ProtocolVersioned {
require(_proposedProtocol != openSTProtocol);
require(proposedProtocol == address(0));

earliestTransferHeight = block.number + PROTOCOL_TRANSFER_BLOCKS_TO_WAIT;
earliestTransferHeight = block.number + blocksToWaitForProtocolTransfer();
proposedProtocol = _proposedProtocol;

ProtocolTransferInitiated(openSTProtocol, _proposedProtocol, earliestTransferHeight);
Expand Down Expand Up @@ -142,4 +142,8 @@ contract ProtocolVersioned {
return true;
}

function blocksToWaitForProtocolTransfer() public pure returns (uint256) {
return PROTOCOL_TRANSFER_BLOCKS_TO_WAIT;
}

}
41 changes: 41 additions & 0 deletions contracts/ProtocolVersionedMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
pragma solidity ^0.4.17;

// Copyright 2017 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.
//
// ----------------------------------------------------------------------------
// Common: ProtocolVersionedMock.sol
//
// http://www.simpletoken.org/
//
// ----------------------------------------------------------------------------

import "./ProtocolVersioned.sol";

/// @title ProtocolVersionedMock
/// @dev Overrides certain durational constants and getters to ease testing ProtocolVersioned
contract ProtocolVersionedMock is ProtocolVersioned {
uint256 private constant PROTOCOL_TRANSFER_BLOCKS_TO_WAIT = 3;

/*
* Public functions
*/
function ProtocolVersionedMock(address _protocol)
ProtocolVersioned(_protocol)
public { }

function blocksToWaitForProtocolTransfer() public pure returns (uint256) {
return PROTOCOL_TRANSFER_BLOCKS_TO_WAIT;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasonklein curious to know if blocksToWaitForProtocolTransfer is needed in ProtocolVersionedMock.sol?

This method is already there in ProtocolVersioned.sol. I guess solidity should inherit blocksToWaitForProtocolTransfer from ProtocolVersioned.sol to ProtocolVersionedMock.sol.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abhayks1: sorry, I merged before I saw this question! Yes, you need to overwrite because
ProtocolVersioned.blocksToWaitForProtocolTransfer points to the PROTOCOL_TRANSFER_BLOCKS_TO_WAIT constant scoped to it, and not scoped to ProtocolVersionedMock.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Banks for clarifying. Solidity is little different in method overriding as compared to other languages like Java, Ruby :)

}
7 changes: 4 additions & 3 deletions test/ProtocolVersioned.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const ProtocolVersioned_utils = require('./ProtocolVersioned_utils.js');
contract('ProtocolVersioned', function(accounts) {
const openSTProtocol = accounts[1];
const proposedProtocol = accounts[2];
const PROTOCOL_TRANSFER_BLOCKS_TO_WAIT = 40320;
const PROTOCOL_TRANSFER_BLOCKS_TO_WAIT = 3;

var result = null;
var earliestTransferHeight = null;
Expand Down Expand Up @@ -105,6 +105,7 @@ contract('ProtocolVersioned', function(accounts) {
* @dev commented because the wait time is set to 1 week (40320 blocks)
* needs to be mocked in v0.9.2
* https://github.com/OpenSTFoundation/openst-protocol/issues/57
*/

describe ('CompleteProtocolTransfer', async () => {
before(async () => {
Expand All @@ -123,7 +124,7 @@ contract('ProtocolVersioned', function(accounts) {
var wait = PROTOCOL_TRANSFER_BLOCKS_TO_WAIT - 2;

for (var i = 0; i < wait; i++) {
await Utils.expectThrow(protocolVersioned.completeProtocolTransfer({ from: proposedProtocol }));
await Utils.expectThrow(protocolVersioned.completeProtocolTransfer({ from: proposedProtocol }));
}
})

Expand All @@ -142,8 +143,8 @@ contract('ProtocolVersioned', function(accounts) {
assert.equal(newTransferHeight.toNumber(), 0);
ProtocolVersioned_utils.checkProtocolTransferCompletedEvent(result.logs[0], proposedProtocol);
})

});
*/

describe ('RevokeProtocolTransfer', async () => {
before(async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/ProtocolVersioned_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//
// ----------------------------------------------------------------------------

var ProtocolVersioned = artifacts.require("./ProtocolVersioned.sol");
var ProtocolVersioned = artifacts.require("./ProtocolVersionedMock.sol");

/// @dev Deploy
module.exports.deployProtocolVersioned = async (artifacts, accounts) => {
Expand Down
2 changes: 1 addition & 1 deletion test/SimpleStake_integrated.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ contract('SimpleStake', function(accounts) {
});

it("Protocol transfer wait blocktime", async() => {
Assert.equal(await simpleStake.PROTOCOL_TRANSFER_BLOCKS_TO_WAIT.call(),
Assert.equal(await simpleStake.blocksToWaitForProtocolTransfer.call(),
PROTOCOL_TRANSFER_BLOCKS_TO_WAIT);
});
});
Expand Down