github.com/codingfuture/orig-energi3@v0.8.4/energi/contracts/test/BlockRewardV1.spec.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 const MockProxy = artifacts.require('MockProxy'); 22 const MockContract = artifacts.require('MockContract'); 23 const BlockRewardV1 = artifacts.require('BlockRewardV1'); 24 const IBlockReward = artifacts.require('IBlockReward'); 25 26 const common = require('./common'); 27 28 contract("BlockRewardV1", async accounts => { 29 const s = { 30 artifacts, 31 accounts, 32 assert, 33 it, 34 web3, 35 backbone : accounts[5], 36 }; 37 38 before(async () => { 39 s.orig = await BlockRewardV1.deployed(); 40 s.proxy = await MockProxy.at(await s.orig.proxy()); 41 s.fake = await MockContract.new(s.proxy.address); 42 s.proxy_abi = await BlockRewardV1.at(s.proxy.address); 43 s.token_abi = await IBlockReward.at(s.proxy.address); 44 await s.proxy.setImpl(s.orig.address); 45 Object.freeze(s); 46 }); 47 48 describe('common pre', () => common.govPreTests(s) ); 49 50 //--- 51 describe('Primary', () => { 52 const { toBN, toWei } = web3.utils; 53 const backbone_reward = toBN(toWei('2.28', 'ether')); 54 const normal_reward = toBN(toWei('13.7', 'ether')); 55 const superblock_reward = toBN(toWei('184004.56', 'ether')); 56 57 it('should correctly getReward()', async () => { 58 expect(toBN(await s.token_abi.getReward(0)).toString()) 59 .equal(toBN(0).toString()); 60 expect(toBN(await s.token_abi.getReward(1)).toString()) 61 .equal(toBN(normal_reward).toString()); 62 expect(toBN(await s.token_abi.getReward(common.superblock_cycles)).toString()) 63 .equal(toBN(superblock_reward).toString()); 64 }); 65 66 it('should reward()', async () => { 67 const bal_before = toBN(await web3.eth.getBalance(s.backbone)); 68 await s.token_abi.reward({value: superblock_reward}); 69 const bal_after = toBN(await web3.eth.getBalance(s.backbone)); 70 expect(bal_after.sub(bal_before).toString()).equal(backbone_reward.toString()); 71 }); 72 }); 73 74 //--- 75 describe('common post', () => common.govPostTests(s) ); 76 });