github.com/codingfuture/orig-energi3@v0.8.4/energi/contracts/test/common.js (about) 1 // Copyright 2019 The Energi Core Authors 2 // This file is part of the Energi Core library. 3 // 4 // The Energi Core library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The Energi Core library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the Energi Core library. If not, see <http://www.gnu.org/licenses/>. 16 17 // Energi Governance system is the fundamental part of Energi Core. 18 19 'use strict'; 20 21 exports.mnregistry_config = [ 22 3, 23 2, 24 24*60*60, 25 '10000000000000000000000', // 10,000 NRG 26 ]; 27 exports.mnregistry_config_v2 = [ 28 3, // RequireValidation 29 3, // ValidationPeriods 30 24*60*60, // CleanupPeriod 31 '10000000000000000000000', // 10,000 NRG, 32 1, 33 ]; 34 exports.superblock_cycles = 8; 35 exports.chain_id = 49797; 36 exports.migration_signer = '0x0000000000000000000000000000000012345678'; 37 exports.cpp_signer = '0x2D0bc327d0843CAF6Fd9ae1eFaB0bF7196Fc2FC8'; 38 exports.emergency_signer = '0x73E286b244c17F030F72e98C57FC83015a3C53Fd'; 39 exports.zerofee_callopts = { 40 gas: 250000, // real max is 500000 41 }; 42 exports.mnreg_deploy_opts = { 43 gas: 7000000, 44 }; 45 46 exports.evt_last_block = { 47 fromBlock: 'latest', 48 toBlock: 'latest', 49 }; 50 51 exports.stringifyBN = (web3, o) => { 52 expect(o).is.not.undefined; 53 for (let f in o) { 54 const v = o[f]; 55 56 if (web3.utils.isBN(v)) { 57 o[f] = v.toString(); 58 } 59 } 60 return o; 61 }; 62 63 exports.moveTime = async (web3, seconds) => { 64 expect(seconds).is.not.undefined; 65 await new Promise((resolve, _) => { 66 web3.currentProvider.send({ 67 jsonrpc: "2.0", 68 method: "evm_increaseTime", 69 params: [seconds], 70 id: new Date().getSeconds() 71 }, resolve); 72 }); 73 await new Promise((resolve, _) => { 74 web3.currentProvider.send({ 75 jsonrpc: "2.0", 76 method: "evm_mine", 77 params: [], 78 id: new Date().getSeconds() + 1 79 }, resolve); 80 }); 81 }; 82 83 exports.govPreTests = (s) => { 84 s.it('should refuse migrate() through s.proxy', async () => { 85 try { 86 await s.proxy_abi.migrate(s.fake.address, { from: s.accounts[0] }); 87 s.assert.fail("It must fail"); 88 } catch (e) { 89 s.assert.match(e.message, /Good try/); 90 } 91 }); 92 93 s.it('should refuse destroy() through s.proxy', async () => { 94 try { 95 await s.proxy_abi.destroy(s.fake.address, { from: s.accounts[0] }); 96 s.assert.fail("It must fail"); 97 } catch (e) { 98 s.assert.match(e.message, /Good try/); 99 } 100 }); 101 102 s.it('should refuse migrate() directly', async () => { 103 try { 104 await s.orig.migrate(s.fake.address, { from: s.accounts[0] }); 105 s.assert.fail("It must fail"); 106 } catch (e) { 107 s.assert.match(e.message, /Not proxy/); 108 } 109 }); 110 111 s.it('should refuse destroy() directly', async () => { 112 try { 113 await s.orig.destroy(s.fake.address, { from: s.accounts[0] }); 114 s.assert.fail("It must fail"); 115 } catch (e) { 116 s.assert.match(e.message, /Not proxy/); 117 } 118 }); 119 }; 120 121 exports.govPostTests = (s) => { 122 const MockProposal = s.artifacts.require('MockProposal'); 123 124 s.it('should refuse to accept funds', async () => { 125 try { 126 await s.token_abi.send(s.web3.utils.toWei('1', "ether")); 127 s.assert.fail("It must fail"); 128 } catch (e) { 129 s.assert.match(e.message, /Not supported/); 130 } 131 }); 132 133 if ('storage' in s) s.it('should refuse to accept funds to storage', async () => { 134 try { 135 await s.storage.send(s.web3.utils.toWei('1', "ether")); 136 s.assert.fail("It must fail"); 137 } catch (e) { 138 s.assert.match(e.message, /revert/); 139 } 140 }); 141 142 if ('storage' in s) s.it('should refuse kill() storage', async () => { 143 try { 144 await s.storage.kill(); 145 s.assert.fail("It must fail"); 146 } catch (e) { 147 s.assert.match(e.message, /Not owner/); 148 } 149 }); 150 151 if ('storage' in s) s.it('should refuse setOwner() on storage', async () => { 152 try { 153 await s.storage.setOwner(s.proxy.address); 154 s.assert.fail("It must fail"); 155 } catch (e) { 156 s.assert.match(e.message, /Not owner/); 157 } 158 }); 159 160 s.it('should destroy() after upgrade', async () => { 161 const orig_balance = await s.web3.eth.getBalance(s.orig.address) 162 const { logs } = await s.proxy.proposeUpgrade( 163 s.fake.address, 0, 164 { from: s.accounts[0], value: '1' }); 165 166 s.assert.equal(logs.length, 1); 167 const proposal = await MockProposal.at(logs[0].args['1']); 168 169 await proposal.setAccepted(); 170 await s.proxy.upgrade(proposal.address); 171 172 const fake_balance = await s.web3.eth.getBalance(s.fake.address) 173 s.assert.equal(orig_balance.valueOf(), fake_balance.valueOf()); 174 175 try { 176 await s.orig.proxy(); 177 s.assert.fail("It must fail"); 178 } catch (e) { 179 s.assert.match(e.message, /did it run Out of Gas/); 180 } 181 }); 182 183 if ('storage' in s) s.it('should transfer storage & allow to kill() it', async () => { 184 await s.fake.killStorage(s.storage.address); 185 }); 186 }; 187