Skip to content

Commit

Permalink
1. add a couple more tests
Browse files Browse the repository at this point in the history
2. Remove public from variables in ProxyStorage
3. Remove private methods from KeysManager interface
  • Loading branch information
rstormsf committed Dec 6, 2017
1 parent fab522c commit fdaeb9d
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 21 deletions.
20 changes: 10 additions & 10 deletions contracts/ProxyStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import "./interfaces/IProxyStorage.sol";
contract ProxyStorage is IProxyStorage {
address public masterOfCeremony;
address poaConsensus;
address public keysManager;
address public votingToChangeMinThreshold;
address public votingToChangeKeys;
address public votingToChangeProxy;
address public ballotsStorage;
address keysManager;
address votingToChangeKeys;
address votingToChangeMinThreshold;
address votingToChangeProxy;
address ballotsStorage;
bool public mocInitialized;

enum ContractTypes {
Expand Down Expand Up @@ -56,14 +56,14 @@ contract ProxyStorage is IProxyStorage {
return votingToChangeProxy;
}

function getBallotsStorage() public view returns(address) {
return ballotsStorage;
}

function getPoaConsensus() public view returns(address) {
return poaConsensus;
}

function getBallotsStorage() public view returns(address) {
return ballotsStorage;
}

function initializeAddresses(
address _keysManager,
address _votingToChangeKeys,
Expand All @@ -74,10 +74,10 @@ contract ProxyStorage is IProxyStorage {
{
require(msg.sender == masterOfCeremony);
require(!mocInitialized);
keysManager = _keysManager;
votingToChangeKeys = _votingToChangeKeys;
votingToChangeMinThreshold = _votingToChangeMinThreshold;
votingToChangeProxy = _votingToChangeProxy;
keysManager = _keysManager;
ballotsStorage = _ballotsStorage;
mocInitialized = true;
ProxyInitialized(
Expand Down
9 changes: 0 additions & 9 deletions contracts/interfaces/IKeysManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,4 @@ contract IKeysManager {
function swapVotingKey(address, address) public;
function swapPayoutKey(address, address) public;
function getTime() public view returns(uint256);

function _swapVotingKey(address, address) private;
function _swapPayoutKey(address, address) private;
function _addMiningKey(address) private;
function _addVotingKey(address, address) private;
function _addPayoutKey(address, address) private;
function _removeMiningKey(address) private;
function _removeVotingKey(address) private;
function _removePayoutKey(address) private;
}
36 changes: 35 additions & 1 deletion test/ballots_storage_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract('BallotsStorage [all features]', function (accounts) {
poaNetworkConsensus = await PoaNetworkConsensus.new(masterOfCeremony);
proxyStorage = await ProxyStorageMock.new(poaNetworkConsensus.address, masterOfCeremony);
ballotsStorageMock = await BallotsStorageMock.new(proxyStorage.address);
//votingToChangeMinThresholdMock = await VotingToChangeMinThresholdMock.new(proxyStorage.address);
await poaNetworkConsensus.setProxyStorage(proxyStorage.address);
await proxyStorage.initializeAddresses(keysManager, votingToChangeKeys, votingToChangeMinThreshold, votingToChangeProxy, ballotsStorage);
})
describe('#contstuctor', async () => {
Expand Down Expand Up @@ -60,6 +60,40 @@ contract('BallotsStorage [all features]', function (accounts) {
await ballotsStorageMock.setThreshold(6, 2, {from: accounts[3]}).should.be.fulfilled;
new web3.BigNumber(6).should.be.bignumber.equal(await ballotsStorageMock.getBallotThreshold(2));
})
})
describe('#getTotalNumberOfValidators', async () => {
it('returns total number of validators', async () => {
await proxyStorage.setKeysManagerMock(masterOfCeremony);
await poaNetworkConsensus.addValidator(accounts[1]);
await poaNetworkConsensus.setSystemAddress(masterOfCeremony);
await poaNetworkConsensus.finalizeChange().should.be.fulfilled;
const getValidators = await poaNetworkConsensus.getValidators();
new web3.BigNumber(2).should.be.bignumber.equal(getValidators.length);
new web3.BigNumber(2).should.be.bignumber.equal(await ballotsStorageMock.getTotalNumberOfValidators())
})
})
describe('#getProxyThreshold', async () => {
it('returns total number of validators', async () => {
new web3.BigNumber(1).should.be.bignumber.equal(await ballotsStorageMock.getProxyThreshold())
await proxyStorage.setKeysManagerMock(masterOfCeremony);
await poaNetworkConsensus.addValidator(accounts[1]);
await poaNetworkConsensus.addValidator(accounts[2]);
await poaNetworkConsensus.addValidator(accounts[3]);
await poaNetworkConsensus.addValidator(accounts[4]);
await poaNetworkConsensus.addValidator(accounts[5]);
await poaNetworkConsensus.setSystemAddress(accounts[0]);
await poaNetworkConsensus.finalizeChange().should.be.fulfilled;
const getValidators = await poaNetworkConsensus.getValidators();
new web3.BigNumber(6).should.be.bignumber.equal(getValidators.length);
new web3.BigNumber(4).should.be.bignumber.equal(await ballotsStorageMock.getProxyThreshold())
})
})
describe('#getVotingToChangeThreshold', async () => {
it('returns voting to change min threshold address', async () => {
votingToChangeMinThreshold.should.be.equal(await ballotsStorageMock.getVotingToChangeThreshold())
await proxyStorage.setVotingToChangeMinThresholdMock(accounts[4]);
accounts[4].should.be.equal(await ballotsStorageMock.getVotingToChangeThreshold())
})
})
})

48 changes: 47 additions & 1 deletion test/keys_manager_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ contract('KeysManager [all features]', function (accounts) {
await keysManager.initiateKeys(accounts[2], {from: masterOfCeremony}).should.be.rejectedWith(ERROR_MSG);
})

it('should not allow to initialize already initialized key after validator created mining key', async () => {
await keysManager.initiateKeys(accounts[2], {from: masterOfCeremony}).should.be.fulfilled;
await keysManager.createKeys(accounts[3],accounts[4],accounts[5], {from: accounts[2]}).should.be.fulfilled;
await keysManager.initiateKeys(accounts[2], {from: masterOfCeremony}).should.be.rejectedWith(ERROR_MSG);
})

it('should not equal to master of ceremony', async () => {
await keysManager.initiateKeys(masterOfCeremony, {from: masterOfCeremony}).should.be.rejectedWith(ERROR_MSG);
})
Expand All @@ -66,6 +72,25 @@ contract('KeysManager [all features]', function (accounts) {
await keysManager.initiateKeys(accounts[2], {from: masterOfCeremony}).should.be.fulfilled;
await keysManager.initiateKeys(accounts[3], {from: masterOfCeremony}).should.be.rejectedWith(ERROR_MSG);
})

it('should not allow to initialize more than maxNumberOfInitialKeys', async () => {
let maxNumberOfInitialKeys = await keysManager.maxNumberOfInitialKeys();
maxNumberOfInitialKeys.should.be.bignumber.equal(12);
await keysManager.initiateKeys('0x0000000000000000000000000000000000000001', {from: masterOfCeremony}).should.be.fulfilled;
await keysManager.initiateKeys('0x0000000000000000000000000000000000000002', {from: masterOfCeremony}).should.be.fulfilled;
await keysManager.initiateKeys('0x0000000000000000000000000000000000000003', {from: masterOfCeremony}).should.be.fulfilled;
await keysManager.initiateKeys('0x0000000000000000000000000000000000000004', {from: masterOfCeremony}).should.be.fulfilled;
await keysManager.initiateKeys('0x0000000000000000000000000000000000000005', {from: masterOfCeremony}).should.be.fulfilled;
await keysManager.initiateKeys('0x0000000000000000000000000000000000000006', {from: masterOfCeremony}).should.be.fulfilled;
await keysManager.initiateKeys('0x0000000000000000000000000000000000000007', {from: masterOfCeremony}).should.be.fulfilled;
await keysManager.initiateKeys('0x0000000000000000000000000000000000000008', {from: masterOfCeremony}).should.be.fulfilled;
await keysManager.initiateKeys('0x0000000000000000000000000000000000000009', {from: masterOfCeremony}).should.be.fulfilled;
await keysManager.initiateKeys('0x0000000000000000000000000000000000000010', {from: masterOfCeremony}).should.be.fulfilled;
await keysManager.initiateKeys('0x0000000000000000000000000000000000000011', {from: masterOfCeremony}).should.be.fulfilled;
await keysManager.initiateKeys('0x0000000000000000000000000000000000000012', {from: masterOfCeremony}).should.be.fulfilled;
await keysManager.initiateKeys('0x0000000000000000000000000000000000000013', {from: masterOfCeremony}).should.be.rejectedWith(ERROR_MSG);
})

it('should increment initialKeyCount by 1', async () => {
let initialKeysCount = await keysManager.initialKeysCount();
initialKeysCount.should.be.bignumber.equal(0);
Expand All @@ -74,7 +99,7 @@ contract('KeysManager [all features]', function (accounts) {
initialKeysCount.should.be.bignumber.equal(1);
})

it('should set initialKeys hash to true', async() => {
it('should set initialKeys hash to activated status', async() => {
new web3.BigNumber(0).should.be.bignumber.equal(await keysManager.initialKeys(accounts[1]));
const {logs} = await keysManager.initiateKeys(accounts[1], {from: masterOfCeremony}).should.be.fulfilled;
new web3.BigNumber(1).should.be.bignumber.equal(await keysManager.initialKeys(accounts[1]));
Expand Down Expand Up @@ -135,6 +160,27 @@ contract('KeysManager [all features]', function (accounts) {
const index = await poaNetworkConsensusMock.currentValidatorsLength();
(await poaNetworkConsensusMock.pendingList(index)).should.be.equal(miningKey);
})

it('should set validatorKeys hash', async () => {
let miningKey = accounts[4];
await keysManager.initiateKeys(accounts[1], {from: masterOfCeremony}).should.be.fulfilled;
await keysManager.createKeys(miningKey, accounts[3], accounts[2], {from: accounts[1]});
const validatorKey = await keysManager.validatorKeys(miningKey);
validatorKey.should.be.deep.equal([
accounts[3],
accounts[2],
true,
true,
true
])
})

it('should set validatorKeys hash', async () => {
let miningKey = accounts[4];
await keysManager.initiateKeys(accounts[1], {from: masterOfCeremony}).should.be.fulfilled;
await keysManager.createKeys(miningKey, accounts[3], accounts[2], {from: accounts[1]});
new web3.BigNumber(2).should.be.bignumber.equal(await keysManager.initialKeys(accounts[1]));
})
})

describe('#addMiningKey', async () => {
Expand Down

0 comments on commit fdaeb9d

Please sign in to comment.