Skip to content

Commit

Permalink
adding test to upgradable contest pool
Browse files Browse the repository at this point in the history
  • Loading branch information
dtutila committed Apr 25, 2018
1 parent edcc71f commit 72556c5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
4 changes: 4 additions & 0 deletions contracts/mocks/ContestPoolMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,8 @@ contract ContestPoolMock is ContestPoolBase {

function _isAfterGraceTime() public view isAfterGraceTime {
}
function getVersion() public pure returns (uint256 ) {
return 2;
}

}
46 changes: 36 additions & 10 deletions test/ContestPoolUpgradableTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ const ContestPoolFactory = artifacts.require("./ContestPoolFactory.sol");
const ContestPoolUpgradable = artifacts.require("./ContestPoolUpgradable.sol");
const BbStorage = artifacts.require("./BbStorage.sol");
const contestPool = artifacts.require("./ContestPool.sol");

const BbUpgrade = artifacts.require("./BbUpgrade.sol");
const ContestPoolMock = artifacts.require("./mocks/ContestPoolMock.sol");
const dateUtil = require('./utils/DateUtil');
const t = require('./utils/TestUtil').title;
const {assertEvent, emptyCallback} = require('./utils/utils');
const stringUtils = require('./utils/StringUtil');

const toMillis = require('./utils/DateUtil').toMillis;
var utils = require("./utils/utils.js");
const config = require("../truffle");


/*
Expand All @@ -15,14 +19,15 @@ const stringUtils = require('./utils/StringUtil');
* @author Douglas Molina <[email protected]>
* @author Guillermo Salazar <[email protected]>
* @author Daniel Tutila <[email protected]>
*
*
*/
contract('ContestPoolUpgradable', accounts => {
let bbStorageInstance;
let contestPoolInstanceA;
let contestPoolInstanceB;
let contestPoolUpgradableInstance;
let contestPoolFactoryInstance;
let bbUpgradeInstance;

let owner = accounts[0];
let manager = accounts[9];
Expand All @@ -44,18 +49,25 @@ contract('ContestPoolUpgradable', accounts => {
const contestNameB = stringUtils.uniqueText('Test2018');

let contestPoolAddressA;
let contestPoolAddressB;
let contestPoolAddressB, contestPoolVersion2Instance;
before('setup suite', async () => {

contestPoolFactoryInstance = await ContestPoolFactory.deployed();
bbStorageInstance = await BbStorage.deployed();
bbUpgradeInstance = await BbUpgrade.deployed();

contestPoolVersion2Instance = await ContestPoolMock.new(
BbStorage.address,
manager
);

console.log('mock->' + contestPoolVersion2Instance.address );
await contestPoolFactoryInstance.createContestPoolDefinition(
contestName,
fee,
startTime,
endTime,
graceTime,
contestName,
fee,
startTime,
endTime,
graceTime,
maxBalance,
managerFee,
ownerFee,
Expand All @@ -77,7 +89,7 @@ contract('ContestPoolUpgradable', accounts => {

const txA = await contestPoolFactoryInstance.createContestPool(
'nameA',
contestName,
contestName,
amountPerPlayer,
{
from: manager,
Expand Down Expand Up @@ -142,4 +154,18 @@ contract('ContestPoolUpgradable', accounts => {
assert.equal(contestNameBBytes32, nameB, "Contest name should be " + contestNameB);
});

it(t('aOwner', 'upgradeContract', 'Should be able to upgrade contest pool contract'), async function () {
const contractName = 'contestPoolBase';

const oldAddress = await bbStorageInstance.getAddress(config.web3.utils.soliditySha3('contract.name', contractName));

const currentVersion = await contestPoolInstanceA.getVersion();
assert.equal(1, currentVersion, "Contest Impl version should be " + 1);
await bbUpgradeInstance.upgradeContract(contractName, contestPoolVersion2Instance.address);

const newVersion = await contestPoolInstanceA.getVersion();
assert.equal(2, newVersion, "Contest Impl version should be " + 2);

});

});

0 comments on commit 72556c5

Please sign in to comment.