Skip to content

Commit

Permalink
Merge pull request #205 from varasev/RewardByBlock-fix
Browse files Browse the repository at this point in the history
(Fix) Return empty results for zero input address in `RewardByBlock.reward` function
  • Loading branch information
varasev committed Dec 29, 2018
2 parents b0fc878 + 2665442 commit 862c6e7
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 1 deletion.
7 changes: 6 additions & 1 deletion contracts/ProxyStorage.sol
Expand Up @@ -52,7 +52,8 @@ contract ProxyStorage is EternalStorage, IProxyStorage {
BallotsStorage,
PoaConsensus,
ValidatorMetadata,
ProxyStorage
ProxyStorage,
RewardByBlock
}

event ProxyInitialized(
Expand Down Expand Up @@ -210,6 +211,10 @@ contract ProxyStorage is EternalStorage, IProxyStorage {
).upgradeTo(_contractAddress);
} else if (_contractType == uint256(ContractTypes.ProxyStorage)) {
success = IEternalStorageProxy(this).upgradeTo(_contractAddress);
} else if (_contractType == uint256(ContractTypes.RewardByBlock)) {
success = IEternalStorageProxy(
getRewardByBlock()
).upgradeTo(_contractAddress);
}
if (success) {
emit AddressSet(_contractType, _contractAddress);
Expand Down
5 changes: 5 additions & 0 deletions contracts/RewardByBlock.sol
Expand Up @@ -68,6 +68,11 @@ contract RewardByBlock is EternalStorage, IRewardByBlock {

address miningKey = benefactors[0];

if (miningKey == address(0)) {
// Return empty arrays
return (new address[](0), new uint256[](0));
}

require(_isMiningActive(miningKey));

uint256 extraLength = extraReceiversLength();
Expand Down
14 changes: 14 additions & 0 deletions test/proxy_storage_test.js
Expand Up @@ -272,6 +272,20 @@ contract('ProxyStorage [all features]', function (accounts) {
await proxyStorageEternalStorage.version.call()
);
})
it('sets rewardByBlock', async () => {
const rewardByBlockNew = await RewardByBlock.new();

await proxyStorage.setVotingToChangeProxyMock(accounts[4]);
await setContractAddress(9, rewardByBlockNew.address, true, {from: accounts[4]});
await proxyStorage.setVotingToChangeProxyMock(votingToChangeProxyEternalStorage.address);

const eternalProxyAddress = await proxyStorage.getRewardByBlock.call();
const eternalProxy = await EternalStorageProxy.at(eternalProxyAddress);

rewardByBlockNew.address.should.be.equal(
await eternalProxy.implementation.call()
)
})
})
describe('#upgradeTo', async () => {
it('may only be called by ProxyStorage (itself)', async () => {
Expand Down
14 changes: 14 additions & 0 deletions test/proxy_storage_upgrade_test.js
Expand Up @@ -279,6 +279,20 @@ contract('ProxyStorage upgraded [all features]', function (accounts) {
await proxyStorageEternalStorage.version.call()
);
})
it('sets rewardByBlock', async () => {
const rewardByBlockNew = await RewardByBlock.new();

await proxyStorage.setVotingToChangeProxyMock(accounts[4]);
await setContractAddress(9, rewardByBlockNew.address, true, {from: accounts[4]});
await proxyStorage.setVotingToChangeProxyMock(votingToChangeProxyEternalStorage.address);

const eternalProxyAddress = await proxyStorage.getRewardByBlock.call();
const eternalProxy = await EternalStorageProxy.at(eternalProxyAddress);

rewardByBlockNew.address.should.be.equal(
await eternalProxy.implementation.call()
)
})
})
})

Expand Down
9 changes: 9 additions & 0 deletions test/voting_to_change_proxy_test.js
Expand Up @@ -473,6 +473,15 @@ contract('VotingToChangeProxyAddress [all features]', function (accounts) {
await deployAndTest({contractType, newAddress})
newAddress.should.be.equal(await proxyStorageEternalStorage.implementation.call());
})
it('should change RewardByBlock implementation', async () => {
const contractType = 9;
const rewardByBlockNew = await RewardByBlock.new();
const newAddress = rewardByBlockNew.address;
await deployAndTest({contractType, newAddress})
const eternalProxyAddress = await proxyStorageMock.getRewardByBlock.call();
const eternalProxy = await EternalStorageProxy.at(eternalProxyAddress);
newAddress.should.be.equal(await eternalProxy.implementation.call());
})
it('prevents double finalize', async () => {
let newAddress1 = accounts[4];
let newAddress2 = accounts[5];
Expand Down
9 changes: 9 additions & 0 deletions test/voting_to_change_proxy_upgrade_test.js
Expand Up @@ -480,6 +480,15 @@ contract('VotingToChangeProxyAddress upgraded [all features]', function (account
await deployAndTest({contractType, newAddress})
newAddress.should.be.equal(await proxyStorageEternalStorage.implementation.call());
})
it('should change RewardByBlock implementation', async () => {
const contractType = 9;
const rewardByBlockNew = await RewardByBlock.new();
const newAddress = rewardByBlockNew.address;
await deployAndTest({contractType, newAddress})
const eternalProxyAddress = await proxyStorageMock.getRewardByBlock.call();
const eternalProxy = await EternalStorageProxy.at(eternalProxyAddress);
newAddress.should.be.equal(await eternalProxy.implementation.call());
})
it('prevents double finalize', async () => {
let newAddress1 = accounts[4];
let newAddress2 = accounts[5];
Expand Down

0 comments on commit 862c6e7

Please sign in to comment.