From fdaeb9d8858031606eaca9411c3bae9f7cde6718 Mon Sep 17 00:00:00 2001 From: Roman Storm & Viktor Baranov Date: Wed, 6 Dec 2017 13:05:44 -0800 Subject: [PATCH] 1. add a couple more tests 2. Remove public from variables in ProxyStorage 3. Remove private methods from KeysManager interface --- contracts/ProxyStorage.sol | 20 +++++------ contracts/interfaces/IKeysManager.sol | 9 ----- test/ballots_storage_test.js | 36 +++++++++++++++++++- test/keys_manager_test.js | 48 ++++++++++++++++++++++++++- 4 files changed, 92 insertions(+), 21 deletions(-) diff --git a/contracts/ProxyStorage.sol b/contracts/ProxyStorage.sol index 22f3eea..8b83960 100644 --- a/contracts/ProxyStorage.sol +++ b/contracts/ProxyStorage.sol @@ -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 { @@ -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, @@ -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( diff --git a/contracts/interfaces/IKeysManager.sol b/contracts/interfaces/IKeysManager.sol index 50942ca..0cd461d 100644 --- a/contracts/interfaces/IKeysManager.sol +++ b/contracts/interfaces/IKeysManager.sol @@ -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; } \ No newline at end of file diff --git a/test/ballots_storage_test.js b/test/ballots_storage_test.js index 59394f0..66a13cd 100644 --- a/test/ballots_storage_test.js +++ b/test/ballots_storage_test.js @@ -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 () => { @@ -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()) + }) }) }) diff --git a/test/keys_manager_test.js b/test/keys_manager_test.js index a93da31..b77c0db 100644 --- a/test/keys_manager_test.js +++ b/test/keys_manager_test.js @@ -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); }) @@ -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); @@ -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])); @@ -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 () => {