Skip to content

Commit

Permalink
Test changeProxyAdmin
Browse files Browse the repository at this point in the history
  • Loading branch information
sydneyitguy committed Nov 20, 2020
1 parent 13fa58f commit ea243ff
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 32 deletions.
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,60 +34,60 @@ A governance token distribution contract on top of LockUpPool. A maximum of 1.2M
·------------------------------------------------|---------------------------|--------------|----------------------------·
| Solc version: 0.7.1+commit.f4a555be · Optimizer enabled: true · Runs: 1500 · Block limit: 6718946 gas │
·················································|···························|··············|·····························
| Methods · 25 gwei/gas · 484.30 usd/eth │
| Methods · 25 gwei/gas · 495.45 usd/eth │
························|························|·············|·············|··············|··············|··············
| Contract · Method · Min · Max · Avg · # calls · usd (avg) │
························|························|·············|·············|··············|··············|··············
| ERC20Token · addMinter · 72827 · 75612 · 73098 · 32 · 0.89
| ERC20Token · addMinter · 72815 · 75612 · 73164 · 34 · 0.91
························|························|·············|·············|··············|··············|··············
| ERC20Token · approve · 29070 · 46897 · 43962 · 129 · 0.53
| ERC20Token · approve · 29070 · 46897 · 43988 · 133 · 0.54
························|························|·············|·············|··············|··············|··············
| ERC20Token · initialize · 324430 · 369343 · 356528 · 102 · 4.32
| ERC20Token · initialize · 324430 · 369343 · 356342 · 104 · 4.41
························|························|·············|·············|··············|··············|··············
| ERC20Token · mint · - · - · 52871 · 49 · 0.64
| ERC20Token · mint · - · - · 52871 · 51 · 0.65
························|························|·············|·············|··············|··············|··············
| ERC20Token · transfer · 37081 · 52141 · 51421 · 21 · 0.62
| ERC20Token · transfer · 37081 · 52141 · 51421 · 21 · 0.64
························|························|·············|·············|··············|··············|··············
| LockUpPool · addLockUpPool · 71215 · 86311 · 84684 · 37 · 1.03
| LockUpPool · addLockUpPool · 71227 · 86311 · 84684 · 37 · 1.05
························|························|·············|·············|··············|··············|··············
| LockUpPool · claimBonus · 26634 · 105197 · 64009 · 3 · 0.77
| LockUpPool · claimBonus · 26634 · 105197 · 64009 · 3 · 0.79
························|························|·············|·············|··············|··············|··············
| LockUpPool · doLockUp · 185088 · 350039 · 297643 · 46 · 3.60
| LockUpPool · doLockUp · 185088 · 350039 · 297644 · 46 · 3.69
························|························|·············|·············|··············|··············|··············
| LockUpPool · exit · 58256 · 207065 · 134292 · 31 · 1.63
| LockUpPool · exit · 58250 · 207065 · 134293 · 31 · 1.66
························|························|·············|·············|··············|··············|··············
| LockUpPool · initialize · - · - · 116378 · 31 · 1.41
| LockUpPool · initialize · - · - · 116378 · 31 · 1.44
························|························|·············|·············|··············|··············|··············
| LockUpPool · setEmergencyMode · - · - · 28217 · 4 · 0.34
| LockUpPool · setEmergencyMode · - · - · 28217 · 4 · 0.35
························|························|·············|·············|··············|··············|··············
| LockUpPool · updateMaxLimit · 28764 · 28836 · 28800 · 2 · 0.35
| LockUpPool · updateMaxLimit · 28764 · 28836 · 28800 · 2 · 0.36
························|························|·············|·············|··············|··············|··············
| Migrations · setCompleted · - · - · 21204 · 5 · 0.26 │
························|························|·············|·············|··············|··············|··············
| WRNRewardPool · addLockUpRewardPool · 101166 · 224459 · 121812 · 39 · 1.47
| WRNRewardPool · addLockUpRewardPool · 101166 · 224459 · 121603 · 41 · 1.51
························|························|·············|·············|··············|··············|··············
| WRNRewardPool · claimWRN · 146843 · 202655 · 184051 · 6 · 2.23
| WRNRewardPool · claimWRN · 146854 · 202654 · 184054 · 6 · 2.28
························|························|·············|·············|··············|··············|··············
| WRNRewardPool · doLockUp · 304647 · 422522 · 390196 · 30 · 4.72
| WRNRewardPool · claimWRNandBonus · - · - · 200393 · 1 · 2.48
························|························|·············|·············|··············|··············|··············
| WRNRewardPool · exit · 159206 · 290450 · 245126 · 7 · 2.97
| WRNRewardPool · doLockUp · 304635 · 422522 · 391213 · 32 · 4.85
························|························|·············|·············|··············|··············|··············
| WRNRewardPool · initialize · 241822 · 241954 · 241873 · 29 · 2.93
| WRNRewardPool · exit · 159193 · 290449 · 250260 · 8 · 3.10
························|························|·············|·············|··············|··············|··············
| WRNRewardPool · setEmergencyMode · - · - · 28218 · 1 · 0.34
| WRNRewardPool · initialize · 241834 · 241954 · 241873 · 30 · 3.00
························|························|·············|·············|··············|··············|··············
| WRNRewardPool · updatePoolMultiplier · - · - · 223728 · 1 · 2.71
| WRNRewardPool · setEmergencyMode · - · - · 28218 · 1 · 0.35
························|························|·············|·············|··············|··············|··············
| WRNRewardPoolV2Test · setVarAdded · - · - · 44247 · 1 · 0.54 │
| WRNRewardPool · updatePoolMultiplier · - · - · 223728 · 1 · 2.77 │
························|························|·············|·············|··············|··············|··············
| WRNRewardPoolV2Test · setVarAdded · - · - · 44269 · 2 · 0.55 │
························|························|·············|·············|··············|··············|··············
| Deployments · · % of limit · │
·················································|·············|·············|··············|··············|··············
| ERC20Token · - · - · 1926451 · 28.7 % · 23.32 │
·················································|·············|·············|··············|··············|··············
| LockUpPool · - · - · 1950515 · 29 % · 23.62 │
| ERC20Token · - · - · 1926451 · 28.7 % · 23.86 │
·················································|·············|·············|··············|··············|··············
| WRNRewardPool · - · - · 2677676 · 39.9 % · 32.42
| LockUpPool · - · - · 1950515 · 29 % · 24.16
·················································|·············|·············|··············|··············|··············
| WRNRewardPoolV2Test · - · - · 2446820 · 36.4 % · 29.62
| WRNRewardPool · - · - · 2696051 · 40.1 % · 33.39
·------------------------------------------------|-------------|-------------|--------------|--------------|-------------·
```
5 changes: 5 additions & 0 deletions contracts/test/WRNRewardPoolV2Test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ contract WRNRewardPoolV2Test is LockUpPool {
emit WRNClaimed(tokenAddress, msg.sender, amount, block.timestamp);
}

function claimWRNandBonus(address tokenAddress) external {
claimWRN(tokenAddress);
claimBonus(tokenAddress);
}

// V2: Changed from 50 -> 49
uint256[49] private ______gap;
}
Expand Down
20 changes: 16 additions & 4 deletions test/Upgrade.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const ERC20Token = artifacts.require('ERC20Token');
const ERC20Token = artifacts.require('ERC20Token');
const WRNRewardPool = artifacts.require('WRNRewardPool');
const WRNRewardPoolV2Test = artifacts.require('WRNRewardPoolV2Test');
const { expectRevert, time } = require('@openzeppelin/test-helpers');
const { deployProxy, upgradeProxy } = require('@openzeppelin/truffle-upgrades');
const { deployProxy, upgradeProxy, admin } = require('@openzeppelin/truffle-upgrades');

contract('WRNRewardPoolV2Test with upgrades plugin', ([creator, alice]) => {
beforeEach(async () => {
Expand All @@ -15,23 +15,35 @@ contract('WRNRewardPoolV2Test with upgrades plugin', ([creator, alice]) => {
await this.wrn.addMinter(this.wrnRewardPool.address);
await this.wrnRewardPool.addLockUpRewardPool(this.hunt.address, 2, 9999999999999, false);
await this.hunt.approve(this.wrnRewardPool.address, 9999999999999);

this.wrnRewardPoolV2 = await upgradeProxy(this.wrnRewardPool.address, WRNRewardPoolV2Test, { unsafeAllowCustomTypes: true });
});

it('should have the same proxy address', async () => {
this.wrnRewardPoolV2 = await upgradeProxy(this.wrnRewardPool.address, WRNRewardPoolV2Test, { unsafeAllowCustomTypes: true });
assert.equal(this.wrnRewardPool.address, this.wrnRewardPoolV2.address);
});

it('should disable exit function', async () => {
this.wrnRewardPoolV2 = await upgradeProxy(this.wrnRewardPool.address, WRNRewardPoolV2Test, { unsafeAllowCustomTypes: true });
await expectRevert(
this.wrnRewardPool.exit(this.hunt.address, 0, true), // Should be able to call with the same proxy contract
'disabled'
);
});

it('should have a new extended variable', async () => {
this.wrnRewardPoolV2 = await upgradeProxy(this.wrnRewardPool.address, WRNRewardPoolV2Test, { unsafeAllowCustomTypes: true });
await this.wrnRewardPoolV2.setVarAdded(1234); // Should call with the new V2 contract because this function is added (ABI is changed)
assert.equal((await this.wrnRewardPoolV2.varAdded()).valueOf(), 1234);
});

it('should fail if non-admin user try to upgrade', async () => {
await admin.changeProxyAdmin(this.wrnRewardPool.address, alice);

await expectRevert(
upgradeProxy(this.wrnRewardPool.address, WRNRewardPoolV2Test, { unsafeAllowCustomTypes: true }),
'Proxy admin is not the one registered in the network manifest'
);
});

// TODO: How can we renounce ownership? - await admin.transferProxyAdminOwnership('0x0000000000000000000000000000000000000000')?
});
4 changes: 2 additions & 2 deletions truffle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ module.exports = {
reporter: 'eth-gas-reporter',
reporterOptions : {
currency: 'USD',
coinmarketcap: '793664cd-7f8f-470f-867b-9de05f7d411d'
// gasPrice: 25
coinmarketcap: '793664cd-7f8f-470f-867b-9de05f7d411d',
gasPrice: 25
}
},
api_keys: {
Expand Down

0 comments on commit ea243ff

Please sign in to comment.