Skip to content

Commit

Permalink
Merge pull request #66 from OpenSTFoundation/unit_case_protocol_versi…
Browse files Browse the repository at this point in the history
…oning

Unit test case uncommented for complete protocol with mock contract f…
  • Loading branch information
jasonklein authored Dec 14, 2017
2 parents 6c99394 + 2c3595b commit f9c2ccc
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
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;
}
}
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

0 comments on commit f9c2ccc

Please sign in to comment.