diff --git a/test/ERC20_tests/ERC20_expense.tests.js b/test/ERC20_tests/ERC20_expense.tests.js index b114fc0..2d96865 100644 --- a/test/ERC20_tests/ERC20_expense.tests.js +++ b/test/ERC20_tests/ERC20_expense.tests.js @@ -11,228 +11,20 @@ var ERC20RelativeExpenseWithPeriod = artifacts.require('./ERC20RelativeExpenseWi var ERC20AbsoluteExpenseWithPeriodSliding = artifacts.require('./ERC20AbsoluteExpenseWithPeriodSliding'); var ERC20RelativeExpenseWithPeriodSliding = artifacts.require('./ERC20RelativeExpenseWithPeriodSliding'); -async function passHours (hours) { - await web3.currentProvider.sendAsync({ - jsonrpc: '2.0', - method: 'evm_increaseTime', - params: [3600 * hours * 1000], - id: new Date().getTime(), - }, function (err) { if (err) console.log('err:', err); }); -} - - -async function checkMinNeed (targets, flowArr, needArr) { - for(var i=0; i { var token; - var store; - var daoBase; - - var issueTokens; - var manageGroups; - var addNewProposal; - var upgradeDaoContract; - var addNewTask; - var startTask; - var startBounty; - var modifyMoneyscheme; - var withdrawDonations; - var setRootERC20Receiver; - var burnTokens; - - var tokenAmount = 1e10; + var multiplier = 1e10; const creator = accounts[0]; const employee1 = accounts[1]; @@ -241,16 +33,9 @@ contract('ERC20Expense', (accounts) => { beforeEach(async () => { token = await StandardToken.new(); - await token.mint(accounts[0], 1e15); - await token.mint(accounts[1], 1e15); - await token.mint(accounts[2], 1e15); - await token.mint(accounts[3], 1e15); - await token.mint(accounts[4], 1e15); - await token.mint(accounts[5], 1e15); - await token.mint(accounts[6], 1e15); - await token.mint(accounts[7], 1e15); - await token.mint(accounts[8], 1e15); - await token.mint(accounts[9], 1e15); + for(var i=0; i<10; i++) { + await token.mint(accounts[i], 1e15); + } }); it('1: Should revert when trying to add rel to abs splitter', async () => { @@ -261,103 +46,102 @@ contract('ERC20Expense', (accounts) => { await splitter.addChild(rel.address).should.be.rejectedWith('revert'); }); - - it('2: should process tokenAmount with ERC20AbsoluteExpenseWithPeriod, then 25 hours, then tokenAmount needs again', async () => { + it('2: should process amount with ERC20AbsoluteExpenseWithPeriod, then 25 hours, then amount needs again', async () => { var timePeriod = 25; var callParams = { from: creator, gasPrice: 0 }; var struct = {}; var balance0 = await token.balanceOf(creator); - Employee1 = await ERC20AbsoluteExpenseWithPeriod.new(token.address,1000*tokenAmount, 1000*tokenAmount, timePeriod, callParams); + Employee1 = await ERC20AbsoluteExpenseWithPeriod.new(token.address,1000*multiplier, 1000*multiplier, timePeriod, callParams); - await token.approve(Employee1.address, 1000*tokenAmount, {from:outsider}); - await Employee1.processTokens(1000*tokenAmount, 1000*tokenAmount, {from: outsider, gasPrice: 0 }); + await token.approve(Employee1.address, 1000*multiplier, {from:outsider}); + await Employee1.processTokens(1000*multiplier, 1000*multiplier, {from: outsider, gasPrice: 0 }); await Employee1.flush({ from: outsider }).should.be.rejectedWith('revert'); await Employee1.flush({ from: creator, gasPrice: 0 }); var balance = await token.balanceOf(creator); - assert.equal((new web3.BigNumber(balance).sub(balance0)).toNumber(), 1000*tokenAmount, 'Should get tokenAmount'); + assert.equal((new web3.BigNumber(balance).sub(balance0)).toNumber(), 1000*multiplier, 'Should get amount'); var needsEmployee1 = await Employee1.isNeeds({ from: creator }); - assert.equal(needsEmployee1, false, 'Dont need tokenAmount, because he got it'); + assert.equal(needsEmployee1, false, 'Dont need amount, because he got it'); await passHours(timePeriod); var needsEmployee2 = await Employee1.isNeeds({ from: creator }); - assert.equal(needsEmployee2, true, 'Need tokenAmount, because 24 hours passed'); + assert.equal(needsEmployee2, true, 'Need amount, because 24 hours passed'); - var need = await Employee1.getTotalNeeded(10000*tokenAmount); - assert.equal(need.toNumber(), 1000*tokenAmount); + var need = await Employee1.getTotalNeeded(10000*multiplier); + assert.equal(need.toNumber(), 1000*multiplier); - var min = await Employee1.getMinNeeded(10000*tokenAmount); - assert.equal(min.toNumber(), 1000*tokenAmount); + var min = await Employee1.getMinNeeded(10000*multiplier); + assert.equal(min.toNumber(), 1000*multiplier); - await token.approve(Employee1.address, 1000*tokenAmount, {from:outsider}); - await Employee1.processTokens(1000*tokenAmount, 1000*tokenAmount, {from: outsider, gasPrice: 0 }); + await token.approve(Employee1.address, 1000*multiplier, {from:outsider}); + await Employee1.processTokens(1000*multiplier, 1000*multiplier, {from: outsider, gasPrice: 0 }); await Employee1.flush({ from: creator, gasPrice: 0 }); var balance2 = await token.balanceOf(creator); - assert.equal((new web3.BigNumber(balance2).sub(balance0)).toNumber(), 2000*tokenAmount, 'Should get tokenAmount'); + assert.equal((new web3.BigNumber(balance2).sub(balance0)).toNumber(), 2000*multiplier, 'Should get amount'); var needsEmployee3 = await Employee1.isNeeds({ from: creator }); - assert.equal(needsEmployee3, false, 'Dont need tokenAmount, because he got it'); + assert.equal(needsEmployee3, false, 'Dont need amount, because he got it'); }); - it('3: should process tokenAmount with ERC20AbsoluteExpenseWithPeriod, then 75 hours, then tokenAmount needs again x3', async () => { + it('3: should process amount with ERC20AbsoluteExpenseWithPeriod, then 75 hours, then amount needs again x3', async () => { var timePeriod = 25; var callParams = { from: creator, gasPrice: 0 }; var struct = {}; var balance0 = await token.balanceOf(creator); - Employee1 = await ERC20AbsoluteExpenseWithPeriodSliding.new(token.address,1000*tokenAmount, 1000*tokenAmount, timePeriod, callParams); + Employee1 = await ERC20AbsoluteExpenseWithPeriodSliding.new(token.address,1000*multiplier, 1000*multiplier, timePeriod, callParams); - await token.approve(Employee1.address, 1000*tokenAmount, {from:outsider}); + await token.approve(Employee1.address, 1000*multiplier, {from:outsider}); - await Employee1.processTokens(1000*tokenAmount, 1000*tokenAmount, {from: outsider, gasPrice: 0 }); + await Employee1.processTokens(1000*multiplier, 1000*multiplier, {from: outsider, gasPrice: 0 }); await Employee1.flush({ from: outsider }).should.be.rejectedWith('revert'); await Employee1.flush({ from: creator, gasPrice: 0 }); var balance = await token.balanceOf(creator); - assert.equal(balance.toNumber() - balance0.toNumber(), 1000*tokenAmount, 'Should get tokenAmount'); + assert.equal(balance.toNumber() - balance0.toNumber(), 1000*multiplier, 'Should get amount'); var needsEmployee1 = await Employee1.isNeeds({ from: creator }); - assert.equal(needsEmployee1, false, 'Dont need tokenAmount, because he got it'); - var need = await Employee1.getTotalNeeded(10000*tokenAmount); + assert.equal(needsEmployee1, false, 'Dont need amount, because he got it'); + var need = await Employee1.getTotalNeeded(10000*multiplier); assert.equal(need.toNumber(), 0); await passHours(1*timePeriod); - var need = await Employee1.getTotalNeeded(10000*tokenAmount); - assert.equal(need.toNumber(), 1000*tokenAmount); + var need = await Employee1.getTotalNeeded(10000*multiplier); + assert.equal(need.toNumber(), 1000*multiplier); await passHours(1*timePeriod); - var need = await Employee1.getTotalNeeded(10000*tokenAmount); - assert.equal(need.toNumber(), 2000*tokenAmount); + var need = await Employee1.getTotalNeeded(10000*multiplier); + assert.equal(need.toNumber(), 2000*multiplier); await passHours(1*timePeriod); - var need = await Employee1.getTotalNeeded(10000*tokenAmount); - assert.equal(need.toNumber(), 3000*tokenAmount); + var need = await Employee1.getTotalNeeded(10000*multiplier); + assert.equal(need.toNumber(), 3000*multiplier); var needsEmployee2 = await Employee1.isNeeds({ from: creator }); - assert.equal(needsEmployee2, true, 'Need tokenAmount, because 24 hours passed'); + assert.equal(needsEmployee2, true, 'Need amount, because 24 hours passed'); - await token.approve(Employee1.address, 4000*tokenAmount, {from:outsider}); - await Employee1.processTokens(4000*tokenAmount, 4000*tokenAmount, {from: outsider, gasPrice: 0 }).should.be.rejectedWith('revert'); - await token.approve(Employee1.address, 2000*tokenAmount, {from:outsider}); - await Employee1.processTokens(2000*tokenAmount, 2000*tokenAmount, {from: outsider, gasPrice: 0 }).should.be.rejectedWith('revert'); + await token.approve(Employee1.address, 4000*multiplier, {from:outsider}); + await Employee1.processTokens(4000*multiplier, 4000*multiplier, {from: outsider, gasPrice: 0 }).should.be.rejectedWith('revert'); + await token.approve(Employee1.address, 2000*multiplier, {from:outsider}); + await Employee1.processTokens(2000*multiplier, 2000*multiplier, {from: outsider, gasPrice: 0 }).should.be.rejectedWith('revert'); - await token.approve(Employee1.address, 3000*tokenAmount, {from:outsider}); - await Employee1.processTokens(3000*tokenAmount, 3000*tokenAmount, {from: outsider, gasPrice: 0 }); + await token.approve(Employee1.address, 3000*multiplier, {from:outsider}); + await Employee1.processTokens(3000*multiplier, 3000*multiplier, {from: outsider, gasPrice: 0 }); await Employee1.flush({ from: creator, gasPrice: 0 }); var balance2 = await token.balanceOf(creator); - assert.equal(balance2.toNumber() - balance0.toNumber(), 4000*tokenAmount, 'Should get tokenAmount'); + assert.equal(balance2.toNumber() - balance0.toNumber(), 4000*multiplier, 'Should get amount'); var needsEmployee3 = await Employee1.isNeeds({ from: creator }); - assert.equal(needsEmployee3, false, 'Dont need tokenAmount, because he got it'); + assert.equal(needsEmployee3, false, 'Dont need amount, because he got it'); }); - it('4: Splitter should access tokenAmount then close then not accept', async () => { + it('4: Splitter should access amount then close then not accept', async () => { var callParams = { from: creator, gasPrice: 0 }; var balance0 = await token.balanceOf(creator); @@ -367,97 +151,97 @@ contract('ERC20Expense', (accounts) => { await Splitter.addChild(tax.address, callParams); var need1 = await Splitter.isNeeds({ from: creator }); - var totalNeed1 = await Splitter.getTotalNeeded(1000*tokenAmount); - assert.equal(need1, true, 'should need tokenAmount'); - assert.equal(totalNeed1.toNumber(), 1000*tokenAmount, 'should be 10% of 1000 tokenAmount'); + var totalNeed1 = await Splitter.getTotalNeeded(1000*multiplier); + assert.equal(need1, true, 'should need amount'); + assert.equal(totalNeed1.toNumber(), 1000*multiplier, 'should be 10% of 1000 amount'); await Splitter.close(callParams); var need3 = await Splitter.isNeeds({ from: creator }); - var totalNeed3 = await Splitter.getTotalNeeded(1000*tokenAmount); - assert.equal(need3, false, 'should not need tokenAmount'); - assert.equal(totalNeed3.toNumber(), 0, 'should be 0 tokenAmount'); + var totalNeed3 = await Splitter.getTotalNeeded(1000*multiplier); + assert.equal(need3, false, 'should not need amount'); + assert.equal(totalNeed3.toNumber(), 0, 'should be 0 amount'); - await token.approve(Splitter.address, 1000*tokenAmount, {from:outsider}); - await Splitter.processTokens(1000*tokenAmount, 1000*tokenAmount, {from: outsider, gasPrice: 0 }).should.be.rejectedWith('revert'); + await token.approve(Splitter.address, 1000*multiplier, {from:outsider}); + await Splitter.processTokens(1000*multiplier, 1000*multiplier, {from: outsider, gasPrice: 0 }).should.be.rejectedWith('revert'); await Splitter.open(callParams); var need3 = await Splitter.isNeeds({ from: creator }); - var totalNeed3 = await Splitter.getTotalNeeded(1000*tokenAmount); - assert.equal(need3, true, 'should not need tokenAmount'); - assert.equal(totalNeed3.toNumber(), 1000*tokenAmount, 'should be 0 tokenAmount'); + var totalNeed3 = await Splitter.getTotalNeeded(1000*multiplier); + assert.equal(need3, true, 'should not need amount'); + assert.equal(totalNeed3.toNumber(), 1000*multiplier, 'should be 0 amount'); - await token.approve(Splitter.address, 1000*tokenAmount, {from:outsider}); - await Splitter.processTokens(1000*tokenAmount, 1000*tokenAmount, {from: outsider, gasPrice: 0 }) + await token.approve(Splitter.address, 1000*multiplier, {from:outsider}); + await Splitter.processTokens(1000*multiplier, 1000*multiplier, {from: outsider, gasPrice: 0 }) var taxBalance = await token.balanceOf(tax.address); - assert.equal(taxBalance.toNumber(), 1000*tokenAmount, 'Tax receiver should get 100 tokenAmount'); + assert.equal(taxBalance.toNumber(), 1000*multiplier, 'Tax receiver should get 100 amount'); }); - it('5: should process tokenAmount with ERC20Splitter + 3 ERC20AbsoluteExpense', async () => { + it('5: should process amount with ERC20Splitter + 3 ERC20AbsoluteExpense', async () => { // create ERC20Splitter var erc20TopDownSplitter = await ERC20Splitter.new(token.address); - var erc20AbsoluteExpense1 = await ERC20AbsoluteExpense.new(token.address,1*tokenAmount, 1*tokenAmount, { from: creator, gasPrice: 0 }); - var erc20AbsoluteExpense2 = await ERC20AbsoluteExpense.new(token.address,2*tokenAmount, 2*tokenAmount, { from: creator, gasPrice: 0 }); - var erc20AbsoluteExpense3 = await ERC20AbsoluteExpense.new(token.address,3*tokenAmount, 3*tokenAmount, { from: creator, gasPrice: 0 }); + var erc20AbsoluteExpense1 = await ERC20AbsoluteExpense.new(token.address,1*multiplier, 1*multiplier, { from: creator, gasPrice: 0 }); + var erc20AbsoluteExpense2 = await ERC20AbsoluteExpense.new(token.address,2*multiplier, 2*multiplier, { from: creator, gasPrice: 0 }); + var erc20AbsoluteExpense3 = await ERC20AbsoluteExpense.new(token.address,3*multiplier, 3*multiplier, { from: creator, gasPrice: 0 }); // // add 3 ERC20AbsoluteExpense outputs to the splitter await erc20TopDownSplitter.addChild(erc20AbsoluteExpense1.address); await erc20TopDownSplitter.addChild(erc20AbsoluteExpense2.address); await erc20TopDownSplitter.addChild(erc20AbsoluteExpense3.address); - // now send some tokenAmount to the revenue endpoint - await token.approve(erc20TopDownSplitter.address, 6*tokenAmount, {from:creator}); - await erc20TopDownSplitter.processTokens(6*tokenAmount, 6*tokenAmount, {from: creator }); + // now send some amount to the revenue endpoint + await token.approve(erc20TopDownSplitter.address, 6*multiplier, {from:creator}); + await erc20TopDownSplitter.processTokens(6*multiplier, 6*multiplier, {from: creator }); - // tokenAmount should end up in the outputs + // multiplier should end up in the outputs var erc20AbsoluteExpense1Balance = await token.balanceOf(erc20AbsoluteExpense1.address); - assert.equal(erc20AbsoluteExpense1Balance.toNumber(), 1*tokenAmount, 'resource point received tokenAmount from splitter'); + assert.equal(erc20AbsoluteExpense1Balance.toNumber(), 1*multiplier, 'resource point received amount from splitter'); var erc20AbsoluteExpense2Balance = await token.balanceOf(erc20AbsoluteExpense2.address); - assert.equal(erc20AbsoluteExpense2Balance.toNumber(), 2*tokenAmount, 'resource point received tokenAmount from splitter'); + assert.equal(erc20AbsoluteExpense2Balance.toNumber(), 2*multiplier, 'resource point received amount from splitter'); var erc20AbsoluteExpense3Balance = await token.balanceOf(erc20AbsoluteExpense3.address); - assert.equal(erc20AbsoluteExpense3Balance.toNumber(), 3*tokenAmount, 'resource point received tokenAmount from splitter'); + assert.equal(erc20AbsoluteExpense3Balance.toNumber(), 3*multiplier, 'resource point received amount from splitter'); }); - it('6: should process tokenAmount with ERC20Splitter + 3 ERC20AbsoluteExpense', async () => { + it('6: should process amount with ERC20Splitter + 3 ERC20AbsoluteExpense', async () => { // create ERC20Splitter var erc20UnsortedSplitter = await ERC20Splitter.new(token.address); - var erc20AbsoluteExpense1 = await ERC20AbsoluteExpense.new(token.address,1*tokenAmount, 1*tokenAmount, { from: creator, gasPrice: 0 }); - var erc20AbsoluteExpense2 = await ERC20AbsoluteExpense.new(token.address,2*tokenAmount, 2*tokenAmount, { from: creator, gasPrice: 0 }); - var erc20AbsoluteExpense3 = await ERC20AbsoluteExpense.new(token.address,3*tokenAmount, 3*tokenAmount, { from: creator, gasPrice: 0 }); + var erc20AbsoluteExpense1 = await ERC20AbsoluteExpense.new(token.address,1*multiplier, 1*multiplier, { from: creator, gasPrice: 0 }); + var erc20AbsoluteExpense2 = await ERC20AbsoluteExpense.new(token.address,2*multiplier, 2*multiplier, { from: creator, gasPrice: 0 }); + var erc20AbsoluteExpense3 = await ERC20AbsoluteExpense.new(token.address,3*multiplier, 3*multiplier, { from: creator, gasPrice: 0 }); // // add 3 ERC20AbsoluteExpense outputs to the splitter await erc20UnsortedSplitter.addChild(erc20AbsoluteExpense1.address); await erc20UnsortedSplitter.addChild(erc20AbsoluteExpense2.address); await erc20UnsortedSplitter.addChild(erc20AbsoluteExpense3.address); - // now send some tokenAmount to the revenue endpoint - await token.approve(erc20UnsortedSplitter.address, 6*tokenAmount, {from:creator}); - await erc20UnsortedSplitter.processTokens(6*tokenAmount, 6*tokenAmount, {from: creator }); + // now send some amount to the revenue endpoint + await token.approve(erc20UnsortedSplitter.address, 6*multiplier, {from:creator}); + await erc20UnsortedSplitter.processTokens(6*multiplier, 6*multiplier, {from: creator }); - // tokenAmount should end up in the outputs + // multiplier should end up in the outputs var erc20AbsoluteExpense1Balance = await token.balanceOf(erc20AbsoluteExpense1.address); - assert.equal(erc20AbsoluteExpense1Balance.toNumber(), 1*tokenAmount, 'resource point received tokenAmount from splitter'); + assert.equal(erc20AbsoluteExpense1Balance.toNumber(), 1*multiplier, 'resource point received amount from splitter'); var erc20AbsoluteExpense2Balance = await token.balanceOf(erc20AbsoluteExpense2.address); - assert.equal(erc20AbsoluteExpense2Balance.toNumber(), 2*tokenAmount, 'resource point received tokenAmount from splitter'); + assert.equal(erc20AbsoluteExpense2Balance.toNumber(), 2*multiplier, 'resource point received amount from splitter'); var erc20AbsoluteExpense3Balance = await token.balanceOf(erc20AbsoluteExpense3.address); - assert.equal(erc20AbsoluteExpense3Balance.toNumber(), 3*tokenAmount, 'resource point received tokenAmount from splitter'); + assert.equal(erc20AbsoluteExpense3Balance.toNumber(), 3*multiplier, 'resource point received amount from splitter'); }); - it('7: should process tokenAmount in structure o-> o-> o-o-o', async () => { + it('7: should process amount in structure o-> o-> o-o-o', async () => { var AllOutputs = await ERC20Splitter.new(token.address,{ from: creator, gasPrice: 0 }); var Salaries = await ERC20Splitter.new(token.address,{ from: creator, gasPrice: 0 }); - var Employee1 = await ERC20AbsoluteExpense.new(token.address,1000*tokenAmount, 1000*tokenAmount, { from: creator, gasPrice: 0 }); - var Employee2 = await ERC20AbsoluteExpense.new(token.address,1500*tokenAmount, 1500*tokenAmount, { from: creator, gasPrice: 0 }); - var Employee3 = await ERC20AbsoluteExpense.new(token.address,800*tokenAmount, 800*tokenAmount, { from: creator, gasPrice: 0 }); + var Employee1 = await ERC20AbsoluteExpense.new(token.address,1000*multiplier, 1000*multiplier, { from: creator, gasPrice: 0 }); + var Employee2 = await ERC20AbsoluteExpense.new(token.address,1500*multiplier, 1500*multiplier, { from: creator, gasPrice: 0 }); + var Employee3 = await ERC20AbsoluteExpense.new(token.address,800*multiplier, 800*multiplier, { from: creator, gasPrice: 0 }); await AllOutputs.addChild(Salaries.address, { from: creator, gasPrice: 0 }); @@ -465,380 +249,205 @@ contract('ERC20Expense', (accounts) => { await Salaries.addChild(Employee2.address, { from: creator, gasPrice: 0 }); await Salaries.addChild(Employee3.address, { from: creator, gasPrice: 0 }); - var Employee1Needs = await Employee1.getTotalNeeded(3300*tokenAmount); - assert.equal(Employee1Needs.toNumber() / tokenAmount, 1000, 'Employee1 Needs 1000 tokenAmount'); - var Employee2Needs = await Employee2.getTotalNeeded(3300*tokenAmount); - assert.equal(Employee2Needs.toNumber() / tokenAmount, 1500, 'Employee1 Needs 1500 tokenAmount'); - var Employee3Needs = await Employee3.getTotalNeeded(3300*tokenAmount); - assert.equal(Employee3Needs.toNumber() / tokenAmount, 800, 'Employee1 Needs 800 tokenAmount'); + var Employee1Needs = await Employee1.getTotalNeeded(3300*multiplier); + assert.equal(Employee1Needs.toNumber() / multiplier, 1000, 'Employee1 Needs 1000 amount'); + var Employee2Needs = await Employee2.getTotalNeeded(3300*multiplier); + assert.equal(Employee2Needs.toNumber() / multiplier, 1500, 'Employee1 Needs 1500 amount'); + var Employee3Needs = await Employee3.getTotalNeeded(3300*multiplier); + assert.equal(Employee3Needs.toNumber() / multiplier, 800, 'Employee1 Needs 800 amount'); - var SalariesNeeds = await Salaries.getTotalNeeded(3300*tokenAmount); - assert.equal(SalariesNeeds.toNumber() / tokenAmount, 3300, 'Salaries Needs 3300 tokenAmount'); + var SalariesNeeds = await Salaries.getTotalNeeded(3300*multiplier); + assert.equal(SalariesNeeds.toNumber() / multiplier, 3300, 'Salaries Needs 3300 amount'); - var SalariesMinNeeds = await Salaries.getMinNeeded(3300*tokenAmount); - assert.equal(SalariesNeeds.toNumber() / tokenAmount, 3300, 'Salaries min Needs 3300 tokenAmount'); + var SalariesMinNeeds = await Salaries.getMinNeeded(3300*multiplier); + assert.equal(SalariesNeeds.toNumber() / multiplier, 3300, 'Salaries min Needs 3300 amount'); - var AllOutputsNeeds = await AllOutputs.getTotalNeeded(3300*tokenAmount); - assert.equal(AllOutputsNeeds.toNumber() / tokenAmount, 3300, 'AllOutputs Needs 3300 tokenAmount'); - var MinOutpultsNeeds = await AllOutputs.getMinNeeded(3300*tokenAmount); - assert.equal(AllOutputsNeeds.toNumber() / tokenAmount, 3300, 'AllOutputs Needs min 3300 tokenAmount'); + var AllOutputsNeeds = await AllOutputs.getTotalNeeded(3300*multiplier); + assert.equal(AllOutputsNeeds.toNumber() / multiplier, 3300, 'AllOutputs Needs 3300 amount'); + var MinOutpultsNeeds = await AllOutputs.getMinNeeded(3300*multiplier); + assert.equal(AllOutputsNeeds.toNumber() / multiplier, 3300, 'AllOutputs Needs min 3300 amount'); var OutputChildrenCount = await AllOutputs.getChildrenCount(); assert.equal(OutputChildrenCount.toNumber(), 1, 'OutputChildrenCount should be 1'); var SalariesChildrenCount = await Salaries.getChildrenCount(); assert.equal(SalariesChildrenCount.toNumber(), 3, 'SalariesChildrenCount should be 3'); - var th = await token.approve(Salaries.address, 3300*tokenAmount, {from:creator}); - await Salaries.processTokens(3300*tokenAmount, 3300*tokenAmount, {from: creator, gasPrice: 0 }); + var th = await token.approve(Salaries.address, 3300*multiplier, {from:creator}); + await Salaries.processTokens(3300*multiplier, 3300*multiplier, {from: creator, gasPrice: 0 }); }); - it('8: should process tokenAmount in structure o-> o-o-o, while minAmount != totalAmount', async () => { + it('8: should process amount in structure o-> o-o-o, while minAmount != totalAmount', async () => { var Salaries = await ERC20Splitter.new(token.address,{ from: creator, gasPrice: 0 }); - var Employee1 = await ERC20AbsoluteExpense.new(token.address,1000*tokenAmount, 500*tokenAmount, { from: creator, gasPrice: 0 }); - var Employee2 = await ERC20AbsoluteExpense.new(token.address,800*tokenAmount, 200*tokenAmount, { from: creator, gasPrice: 0 }); - var Employee3 = await ERC20AbsoluteExpense.new(token.address,1500*tokenAmount, 500*tokenAmount, { from: creator, gasPrice: 0 }); + var Employee1 = await ERC20AbsoluteExpense.new(token.address,1000*multiplier, 500*multiplier, { from: creator, gasPrice: 0 }); + var Employee2 = await ERC20AbsoluteExpense.new(token.address,800*multiplier, 200*multiplier, { from: creator, gasPrice: 0 }); + var Employee3 = await ERC20AbsoluteExpense.new(token.address,1500*multiplier, 500*multiplier, { from: creator, gasPrice: 0 }); await Salaries.addChild(Employee1.address, { from: creator, gasPrice: 0 }); await Salaries.addChild(Employee2.address, { from: creator, gasPrice: 0 }); await Salaries.addChild(Employee3.address, { from: creator, gasPrice: 0 }); - var Employee1Needs = await Employee1.getTotalNeeded(3300*tokenAmount); - assert.equal(Employee1Needs.toNumber() / tokenAmount, 1000); - var Employee2Needs = await Employee2.getTotalNeeded(3300*tokenAmount); - assert.equal(Employee2Needs.toNumber() / tokenAmount, 800); - var Employee3Needs = await Employee3.getTotalNeeded(3300*tokenAmount); - assert.equal(Employee3Needs.toNumber() / tokenAmount, 1500); - - var SalariesNeeds = await Salaries.getTotalNeeded(3300*tokenAmount); - assert.equal(SalariesNeeds.toNumber() / tokenAmount, 3300, 'Salaries Needs 3300 tokenAmount'); - - assert.equal((await Salaries.getMinNeeded(100*tokenAmount)).toNumber() / tokenAmount, 0); - assert.equal((await Salaries.getMinNeeded(200*tokenAmount)).toNumber() / tokenAmount, 200); - assert.equal((await Salaries.getMinNeeded(300*tokenAmount)).toNumber() / tokenAmount, 200); - assert.equal((await Salaries.getMinNeeded(400*tokenAmount)).toNumber() / tokenAmount, 400); - assert.equal((await Salaries.getMinNeeded(500*tokenAmount)).toNumber() / tokenAmount, 500); - assert.equal((await Salaries.getMinNeeded(600*tokenAmount)).toNumber() / tokenAmount, 500); - assert.equal((await Salaries.getMinNeeded(700*tokenAmount)).toNumber() / tokenAmount, 700); - assert.equal((await Salaries.getMinNeeded(800*tokenAmount)).toNumber() / tokenAmount, 700); - assert.equal((await Salaries.getMinNeeded(900*tokenAmount)).toNumber() / tokenAmount, 900); - assert.equal((await Salaries.getMinNeeded(1000*tokenAmount)).toNumber() / tokenAmount, 1000); - assert.equal((await Salaries.getMinNeeded(1100*tokenAmount)).toNumber() / tokenAmount, 1000); - assert.equal((await Salaries.getMinNeeded(1200*tokenAmount)).toNumber() / tokenAmount, 1200); - assert.equal((await Salaries.getMinNeeded(1300*tokenAmount)).toNumber() / tokenAmount, 1200); - assert.equal((await Salaries.getMinNeeded(1400*tokenAmount)).toNumber() / tokenAmount, 1400); - assert.equal((await Salaries.getMinNeeded(1500*tokenAmount)).toNumber() / tokenAmount, 1400); - assert.equal((await Salaries.getMinNeeded(1600*tokenAmount)).toNumber() / tokenAmount, 1600); - assert.equal((await Salaries.getMinNeeded(1700*tokenAmount)).toNumber() / tokenAmount, 1600); - assert.equal((await Salaries.getMinNeeded(1800*tokenAmount)).toNumber() / tokenAmount, 1800); - assert.equal((await Salaries.getMinNeeded(1900*tokenAmount)).toNumber() / tokenAmount, 1800); - assert.equal((await Salaries.getMinNeeded(2000*tokenAmount)).toNumber() / tokenAmount, 1800); - assert.equal((await Salaries.getMinNeeded(2100*tokenAmount)).toNumber() / tokenAmount, 1800); - assert.equal((await Salaries.getMinNeeded(2200*tokenAmount)).toNumber() / tokenAmount, 1800); - assert.equal((await Salaries.getMinNeeded(2300*tokenAmount)).toNumber() / tokenAmount, 2300); - assert.equal((await Salaries.getMinNeeded(2400*tokenAmount)).toNumber() / tokenAmount, 2300); - assert.equal((await Salaries.getMinNeeded(2500*tokenAmount)).toNumber() / tokenAmount, 2300); - assert.equal((await Salaries.getMinNeeded(2600*tokenAmount)).toNumber() / tokenAmount, 2300); - assert.equal((await Salaries.getMinNeeded(2700*tokenAmount)).toNumber() / tokenAmount, 2300); - assert.equal((await Salaries.getMinNeeded(2800*tokenAmount)).toNumber() / tokenAmount, 2800); - assert.equal((await Salaries.getMinNeeded(2900*tokenAmount)).toNumber() / tokenAmount, 2800); - assert.equal((await Salaries.getMinNeeded(3000*tokenAmount)).toNumber() / tokenAmount, 2800); - assert.equal((await Salaries.getMinNeeded(3100*tokenAmount)).toNumber() / tokenAmount, 2800); - assert.equal((await Salaries.getMinNeeded(3200*tokenAmount)).toNumber() / tokenAmount, 2800); - assert.equal((await Salaries.getMinNeeded(3300*tokenAmount)).toNumber() / tokenAmount, 3300); - assert.equal((await Salaries.getMinNeeded(3400*tokenAmount)).toNumber() / tokenAmount, 3300); - assert.equal((await Salaries.getMinNeeded(3500*tokenAmount)).toNumber() / tokenAmount, 3300); - - var th = await token.approve(Salaries.address, 700*tokenAmount, {from:creator}); - await Salaries.processTokens(700*tokenAmount, 700*tokenAmount, {from: creator, gasPrice: 0 }); - - assert.equal((await Salaries.getMinNeeded(100*tokenAmount)).toNumber() / tokenAmount, 0); - assert.equal((await Salaries.getMinNeeded(200*tokenAmount)).toNumber() / tokenAmount, 200); - assert.equal((await Salaries.getMinNeeded(300*tokenAmount)).toNumber() / tokenAmount, 200); - assert.equal((await Salaries.getMinNeeded(400*tokenAmount)).toNumber() / tokenAmount, 400); - assert.equal((await Salaries.getMinNeeded(500*tokenAmount)).toNumber() / tokenAmount, 500); - assert.equal((await Salaries.getMinNeeded(600*tokenAmount)).toNumber() / tokenAmount, 500); - assert.equal((await Salaries.getMinNeeded(700*tokenAmount)).toNumber() / tokenAmount, 700); - assert.equal((await Salaries.getMinNeeded(800*tokenAmount)).toNumber() / tokenAmount, 700); - assert.equal((await Salaries.getMinNeeded(900*tokenAmount)).toNumber() / tokenAmount, 900); - assert.equal((await Salaries.getMinNeeded(1000*tokenAmount)).toNumber() / tokenAmount, 900); - assert.equal((await Salaries.getMinNeeded(1100*tokenAmount)).toNumber() / tokenAmount, 1100); - assert.equal((await Salaries.getMinNeeded(1200*tokenAmount)).toNumber() / tokenAmount, 1100); - assert.equal((await Salaries.getMinNeeded(1300*tokenAmount)).toNumber() / tokenAmount, 1100); - assert.equal((await Salaries.getMinNeeded(1400*tokenAmount)).toNumber() / tokenAmount, 1100); - assert.equal((await Salaries.getMinNeeded(1500*tokenAmount)).toNumber() / tokenAmount, 1100); - assert.equal((await Salaries.getMinNeeded(1600*tokenAmount)).toNumber() / tokenAmount, 1600); - assert.equal((await Salaries.getMinNeeded(1700*tokenAmount)).toNumber() / tokenAmount, 1600); - assert.equal((await Salaries.getMinNeeded(1800*tokenAmount)).toNumber() / tokenAmount, 1600); - assert.equal((await Salaries.getMinNeeded(1900*tokenAmount)).toNumber() / tokenAmount, 1600); - assert.equal((await Salaries.getMinNeeded(2000*tokenAmount)).toNumber() / tokenAmount, 1600); - assert.equal((await Salaries.getMinNeeded(2100*tokenAmount)).toNumber() / tokenAmount, 2100); - assert.equal((await Salaries.getMinNeeded(2200*tokenAmount)).toNumber() / tokenAmount, 2100); - assert.equal((await Salaries.getMinNeeded(2300*tokenAmount)).toNumber() / tokenAmount, 2100); - assert.equal((await Salaries.getMinNeeded(2400*tokenAmount)).toNumber() / tokenAmount, 2100); - assert.equal((await Salaries.getMinNeeded(2500*tokenAmount)).toNumber() / tokenAmount, 2100); - assert.equal((await Salaries.getMinNeeded(2600*tokenAmount)).toNumber() / tokenAmount, 2600); - assert.equal((await Salaries.getMinNeeded(2700*tokenAmount)).toNumber() / tokenAmount, 2600); - assert.equal((await Salaries.getMinNeeded(2800*tokenAmount)).toNumber() / tokenAmount, 2600); - assert.equal((await Salaries.getMinNeeded(2900*tokenAmount)).toNumber() / tokenAmount, 2600); - assert.equal((await Salaries.getMinNeeded(3000*tokenAmount)).toNumber() / tokenAmount, 2600); - assert.equal((await Salaries.getMinNeeded(3100*tokenAmount)).toNumber() / tokenAmount, 2600); - assert.equal((await Salaries.getMinNeeded(3200*tokenAmount)).toNumber() / tokenAmount, 2600); - assert.equal((await Salaries.getMinNeeded(3300*tokenAmount)).toNumber() / tokenAmount, 2600); - assert.equal((await Salaries.getMinNeeded(3400*tokenAmount)).toNumber() / tokenAmount, 2600); - assert.equal((await Salaries.getMinNeeded(3500*tokenAmount)).toNumber() / tokenAmount, 2600); - - var th = await token.approve(Salaries.address, 900*tokenAmount, {from:creator}); - await Salaries.processTokens(900*tokenAmount, 900*tokenAmount, {from: creator, gasPrice: 0 }); - - assert.equal((await Salaries.getMinNeeded(100*tokenAmount)).toNumber() / tokenAmount, 0); - assert.equal((await Salaries.getMinNeeded(200*tokenAmount)).toNumber() / tokenAmount, 200); - assert.equal((await Salaries.getMinNeeded(300*tokenAmount)).toNumber() / tokenAmount, 200); - assert.equal((await Salaries.getMinNeeded(400*tokenAmount)).toNumber() / tokenAmount, 200); - assert.equal((await Salaries.getMinNeeded(500*tokenAmount)).toNumber() / tokenAmount, 200); - assert.equal((await Salaries.getMinNeeded(600*tokenAmount)).toNumber() / tokenAmount, 200); - assert.equal((await Salaries.getMinNeeded(700*tokenAmount)).toNumber() / tokenAmount, 700); - assert.equal((await Salaries.getMinNeeded(800*tokenAmount)).toNumber() / tokenAmount, 700); - assert.equal((await Salaries.getMinNeeded(900*tokenAmount)).toNumber() / tokenAmount, 700); - assert.equal((await Salaries.getMinNeeded(1000*tokenAmount)).toNumber() / tokenAmount, 700); - assert.equal((await Salaries.getMinNeeded(1100*tokenAmount)).toNumber() / tokenAmount, 700); - assert.equal((await Salaries.getMinNeeded(1200*tokenAmount)).toNumber() / tokenAmount, 1200); - assert.equal((await Salaries.getMinNeeded(1300*tokenAmount)).toNumber() / tokenAmount, 1200); - assert.equal((await Salaries.getMinNeeded(1400*tokenAmount)).toNumber() / tokenAmount, 1200); - assert.equal((await Salaries.getMinNeeded(1500*tokenAmount)).toNumber() / tokenAmount, 1200); - assert.equal((await Salaries.getMinNeeded(1600*tokenAmount)).toNumber() / tokenAmount, 1200); - assert.equal((await Salaries.getMinNeeded(1700*tokenAmount)).toNumber() / tokenAmount, 1700); - assert.equal((await Salaries.getMinNeeded(1800*tokenAmount)).toNumber() / tokenAmount, 1700); - assert.equal((await Salaries.getMinNeeded(1900*tokenAmount)).toNumber() / tokenAmount, 1700); - assert.equal((await Salaries.getMinNeeded(2000*tokenAmount)).toNumber() / tokenAmount, 1700); - assert.equal((await Salaries.getMinNeeded(2100*tokenAmount)).toNumber() / tokenAmount, 1700); - assert.equal((await Salaries.getMinNeeded(2200*tokenAmount)).toNumber() / tokenAmount, 1700); - assert.equal((await Salaries.getMinNeeded(2300*tokenAmount)).toNumber() / tokenAmount, 1700); - assert.equal((await Salaries.getMinNeeded(2400*tokenAmount)).toNumber() / tokenAmount, 1700); - assert.equal((await Salaries.getMinNeeded(2500*tokenAmount)).toNumber() / tokenAmount, 1700); - assert.equal((await Salaries.getMinNeeded(2600*tokenAmount)).toNumber() / tokenAmount, 1700); - assert.equal((await Salaries.getMinNeeded(2700*tokenAmount)).toNumber() / tokenAmount, 1700); - assert.equal((await Salaries.getMinNeeded(2800*tokenAmount)).toNumber() / tokenAmount, 1700); - assert.equal((await Salaries.getMinNeeded(2900*tokenAmount)).toNumber() / tokenAmount, 1700); - assert.equal((await Salaries.getMinNeeded(3000*tokenAmount)).toNumber() / tokenAmount, 1700); - assert.equal((await Salaries.getMinNeeded(3100*tokenAmount)).toNumber() / tokenAmount, 1700); - assert.equal((await Salaries.getMinNeeded(3200*tokenAmount)).toNumber() / tokenAmount, 1700); - assert.equal((await Salaries.getMinNeeded(3300*tokenAmount)).toNumber() / tokenAmount, 1700); - assert.equal((await Salaries.getMinNeeded(3400*tokenAmount)).toNumber() / tokenAmount, 1700); - assert.equal((await Salaries.getMinNeeded(3500*tokenAmount)).toNumber() / tokenAmount, 1700); - - var th = await token.approve(Salaries.address, 200*tokenAmount, {from:creator}); - await Salaries.processTokens(200*tokenAmount, 200*tokenAmount, {from: creator, gasPrice: 0 }); - - var th = await token.approve(Salaries.address, 1500*tokenAmount, {from:creator}); - await Salaries.processTokens(1500*tokenAmount, 1500*tokenAmount, {from: creator, gasPrice: 0 }); - - var th = await token.approve(Salaries.address, 200*tokenAmount, {from:creator}); - await Salaries.processTokens(200*tokenAmount, 200*tokenAmount, {from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); + var Employee1Needs = await Employee1.getTotalNeeded(3300*multiplier); + assert.equal(Employee1Needs.toNumber() / multiplier, 1000); + var Employee2Needs = await Employee2.getTotalNeeded(3300*multiplier); + assert.equal(Employee2Needs.toNumber() / multiplier, 800); + var Employee3Needs = await Employee3.getTotalNeeded(3300*multiplier); + assert.equal(Employee3Needs.toNumber() / multiplier, 1500); + + var SalariesNeeds = await Salaries.getTotalNeeded(3300*multiplier); + assert.equal(SalariesNeeds.toNumber() / multiplier, 3300, 'Salaries Needs 3300 amount'); + await checkNeededArrs(Salaries, multiplier, + [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500], + [0, 200, 200, 400, 500, 500, 700, 700, 900, 1000, 1000, 1200, 1200, 1400, 1400, 1600, 1600, 1800, 1800, 1800, 1800, 1800, 2300, 2300, 2300, 2300, 2300, 2800, 2800, 2800, 2800, 2800, 3300, 3300, 3300] + ); + + var th = await token.approve(Salaries.address, 700*multiplier, {from:creator}); + await Salaries.processTokens(700*multiplier, 700*multiplier, {from: creator, gasPrice: 0 }); + await checkNeededArrs(Salaries, multiplier, + [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500], + [0, 200, 200, 400, 500, 500, 700, 700, 900, 900, 1100, 1100, 1100, 1100, 1100, 1600, 1600, 1600, 1600, 1600, 2100, 2100, 2100, 2100, 2100, 2600, 2600, 2600, 2600, 2600, 2600, 2600, 2600, 2600, 2600] + ); + + var th = await token.approve(Salaries.address, 900*multiplier, {from:creator}); + await Salaries.processTokens(900*multiplier, 900*multiplier, {from: creator, gasPrice: 0 }); + await checkNeededArrs(Salaries, multiplier, + [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500], + [0, 200, 200, 200, 200, 200, 700, 700, 700, 700, 700, 1200, 1200, 1200, 1200, 1200, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700] + ) + + var th = await token.approve(Salaries.address, 200*multiplier, {from:creator}); + await Salaries.processTokens(200*multiplier, 200*multiplier, {from: creator, gasPrice: 0 }); + var th = await token.approve(Salaries.address, 1500*multiplier, {from:creator}); + await Salaries.processTokens(1500*multiplier, 1500*multiplier, {from: creator, gasPrice: 0 }); + var th = await token.approve(Salaries.address, 200*multiplier, {from:creator}); + await Salaries.processTokens(200*multiplier, 200*multiplier, {from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); }); - it('9: should process tokenAmount with a scheme just like in the paper: 75/25 others, send MORE than minNeed; ', async () => { - const CURRENT_INPUT = 30900; - var e1 = 1000; - var e2 = 1500; - var e3 = 800; - var office = 500; - var internet = 300; - var t1 = 500; - var t2 = 300; - var t3 = 1000; - var b1 = 10000; - var b2 = 10000; - var b3 = 20000; - var reserve = 750000; - var dividends = 250000; - - var struct = await createStructure(token, creator, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - - var splitterParams = await getSplitterParams(struct, CURRENT_INPUT, tokenAmount, creator); - - await totalAndMinNeedsAsserts(splitterParams, CURRENT_INPUT, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); + it('9: should process amount with a scheme just like in the paper: 75/25 others, send MORE than minNeed; ', async () => { + var params = {token:token.address, CURRENT_INPUT:30900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:750000, dividends:250000} + + var struct = await createStructure(params, ERC20AbsoluteExpense, ERC20RelativeExpense, ERC20Splitter); + + var splitterParams = await getSplitterParams(struct, params); + + await totalAndMinNeedsAsserts(splitterParams, params); await structureAsserts(splitterParams); - await token.approve(struct.AllOutputs.address, CURRENT_INPUT*tokenAmount, {from:creator}); - await struct.AllOutputs.processTokens(CURRENT_INPUT*tokenAmount, CURRENT_INPUT*tokenAmount, {from: creator, gasPrice: 0 }); + await token.approve(struct.AllOutputs.address, params.CURRENT_INPUT*multiplier, {from:creator}); + await struct.AllOutputs.processTokens(params.CURRENT_INPUT*multiplier, params.CURRENT_INPUT*multiplier, {from: creator, gasPrice: 0 }); - var balances = await getBalances(token, struct); - await balancesAsserts(balances, CURRENT_INPUT, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - await splitterBalancesAsserts(balances, tokenAmount, 0, 0, 0, 0, 0, 0, 0); + var balances = await getBalances(struct, token.balanceOf); + await balancesAsserts(balances, params); + await splitterBalancesAsserts(balances); }); - it('10: should process tokenAmount with a scheme just like in the paper: 75/25 others, send EQUAL to minNeed', async () => { - const CURRENT_INPUT = 5900; - var e1 = 1000; - var e2 = 1500; - var e3 = 800; - var office = 500; - var internet = 300; - var t1 = 500; - var t2 = 300; - var t3 = 1000; - var b1 = 10000; - var b2 = 10000; - var b3 = 20000; - var reserve = 750000; - var dividends = 250000; - - var struct = await createStructure(token, creator, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - var splitterParams = await getSplitterParams(struct, CURRENT_INPUT, tokenAmount, creator); - - await totalAndMinNeedsAsserts(splitterParams, CURRENT_INPUT, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); + it('10: should process amount with a scheme just like in the paper: 75/25 others, send EQUAL to minNeed', async () => { + var params = {token:token.address, CURRENT_INPUT:5900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:750000, dividends:250000} + + var struct = await createStructure(params, ERC20AbsoluteExpense, ERC20RelativeExpense, ERC20Splitter); + var splitterParams = await getSplitterParams(struct, params); + + await totalAndMinNeedsAsserts(splitterParams, params); await structureAsserts(splitterParams); // console.log('------------ struct.AllOutputs.address ', struct); - await token.approve(struct.AllOutputs.address, CURRENT_INPUT*tokenAmount, {from:creator}); - await struct.AllOutputs.processTokens(CURRENT_INPUT*tokenAmount, CURRENT_INPUT*tokenAmount, {from: creator, gasPrice: 0 }); + await token.approve(struct.AllOutputs.address, params.CURRENT_INPUT*multiplier, {from:creator}); + await struct.AllOutputs.processTokens(params.CURRENT_INPUT*multiplier, params.CURRENT_INPUT*multiplier, {from: creator, gasPrice: 0 }); - var balances = await getBalances(token, struct); - await balancesAsserts(balances, CURRENT_INPUT, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, 0, 0, 0, 0, 0); - await splitterBalancesAsserts(balances, tokenAmount, 0, 0, 0, 0, 0, 0, 0); + var balances = await getBalances(struct, token.balanceOf); + await balancesAsserts(balances, params); + await splitterBalancesAsserts(balances); }); - it('11: should not process tokenAmount: send LESS than minNeed', async () => { - const CURRENT_INPUT = 5900; - var e1 = 1000; - var e2 = 1500; - var e3 = 800; - var office = 500; - var internet = 300; - var t1 = 500; - var t2 = 300; - var t3 = 1000; - var b1 = 10000; - var b2 = 10000; - var b3 = 20000; - var reserve = 750000; - var dividends = 250000; - - var struct = await createStructure(token, creator, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - var splitterParams = await getSplitterParams(struct, CURRENT_INPUT, tokenAmount, creator); - await totalAndMinNeedsAsserts(splitterParams, CURRENT_INPUT, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); + it('11: should not process multiplier: send LESS than minNeed', async () => { + var params = {token:token.address, CURRENT_INPUT:5900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:750000, dividends:250000} + + var struct = await createStructure(params, ERC20AbsoluteExpense, ERC20RelativeExpense, ERC20Splitter); + var splitterParams = await getSplitterParams(struct, params); + await totalAndMinNeedsAsserts(splitterParams, params); await structureAsserts(splitterParams); - await token.approve(struct.AllOutputs.address, 1000*tokenAmount, {from:creator}); - await struct.AllOutputs.processTokens(1000*tokenAmount, 1000*tokenAmount, {from: creator }).should.be.rejectedWith('revert'); - await token.approve(struct.AllOutputs.address, 1000*tokenAmount, {from:creator}); - await struct.AllOutputs.processTokens(1000000*tokenAmount, 1000*tokenAmount, {from: creator }).should.be.rejectedWith('revert'); - await token.approve(struct.AllOutputs.address, 1000000*tokenAmount, {from:creator}); - await struct.AllOutputs.processTokens(1000*tokenAmount, 1000000*tokenAmount, {from: creator }).should.be.rejectedWith('revert'); + await token.approve(struct.AllOutputs.address, 1000*multiplier, {from:creator}); + await struct.AllOutputs.processTokens(1000*multiplier, 1000*multiplier, {from: creator }).should.be.rejectedWith('revert'); + await token.approve(struct.AllOutputs.address, 1000*multiplier, {from:creator}); + await struct.AllOutputs.processTokens(1000000*multiplier, 1000*multiplier, {from: creator }).should.be.rejectedWith('revert'); + await token.approve(struct.AllOutputs.address, 1000000*multiplier, {from:creator}); + await struct.AllOutputs.processTokens(1000*multiplier, 1000000*multiplier, {from: creator }).should.be.rejectedWith('revert'); }); - it('12: should process tokenAmount with a scheme just like in the paper: 10/15 others, send MORE than minNeed; ', async () => { - const CURRENT_INPUT = 20900; - var e1 = 1000; - var e2 = 1500; - var e3 = 800; - var office = 500; - var internet = 300; - var t1 = 500; - var t2 = 300; - var t3 = 1000; - var b1 = 10000; - var b2 = 10000; - var b3 = 20000; - var reserve = 850000; - var dividends = 150000; - - var struct = await createStructure(token, creator, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - var splitterParams = await getSplitterParams(struct, CURRENT_INPUT, tokenAmount, creator); - await totalAndMinNeedsAsserts(splitterParams, CURRENT_INPUT, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); + it('12: should process amount with a scheme just like in the paper: 10/15 others, send MORE than minNeed; ', async () => { + var params = {token:token.address, CURRENT_INPUT:20900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:850000, dividends:150000} + + var struct = await createStructure(params, ERC20AbsoluteExpense, ERC20RelativeExpense, ERC20Splitter); + var splitterParams = await getSplitterParams(struct, params); + await totalAndMinNeedsAsserts(splitterParams, params); await structureAsserts(splitterParams); - await token.approve(struct.AllOutputs.address, CURRENT_INPUT*tokenAmount, {from:creator}); - await struct.AllOutputs.processTokens(CURRENT_INPUT*tokenAmount, CURRENT_INPUT*tokenAmount, {from: creator, gasPrice: 0 }); + await token.approve(struct.AllOutputs.address, params.CURRENT_INPUT*multiplier, {from:creator}); + await struct.AllOutputs.processTokens(params.CURRENT_INPUT*multiplier, params.CURRENT_INPUT*multiplier, {from: creator, gasPrice: 0 }); - var balances = await getBalances(token, struct); - await balancesAsserts(balances, CURRENT_INPUT, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - await splitterBalancesAsserts(balances, tokenAmount, 0, 0, 0, 0, 0, 0, 0); + var balances = await getBalances(struct, token.balanceOf); + await balancesAsserts(balances, params); + await splitterBalancesAsserts(balances); }); - it('13: should NOT process tokenAmount (splitter can not accumulate tokenAmount) with a scheme just like in the paper: 10/15 others, send MORE than minNeed; ', async () => { - const CURRENT_INPUT = 20900; - var e1 = 1000; - var e2 = 1500; - var e3 = 800; - var office = 500; - var internet = 300; - var t1 = 500; - var t2 = 300; - var t3 = 1000; - var b1 = 10000; - var b2 = 10000; - var b3 = 20000; - var reserve = 100000; - var dividends = 150000; - - var struct = await createStructure(token, creator, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - var splitterParams = await getSplitterParams(struct, CURRENT_INPUT, tokenAmount, creator); - await totalAndMinNeedsAsserts(splitterParams, CURRENT_INPUT, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); + it('13: should NOT process amount (splitter can not accumulate amount) with a scheme just like in the paper: 10/15 others, send MORE than minNeed; ', async () => { + var params = {token:token.address, CURRENT_INPUT:30900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:100000, dividends:250000} + + var struct = await createStructure(params, ERC20AbsoluteExpense, ERC20RelativeExpense, ERC20Splitter); + var splitterParams = await getSplitterParams(struct, params); + await totalAndMinNeedsAsserts(splitterParams, params); await structureAsserts(splitterParams); - await token.approve(struct.AllOutputs.address, CURRENT_INPUT*tokenAmount, {from:creator}); - await struct.AllOutputs.processTokens(CURRENT_INPUT*tokenAmount, CURRENT_INPUT*tokenAmount, {from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); + await token.approve(struct.AllOutputs.address, params.CURRENT_INPUT*multiplier, {from:creator}); + await struct.AllOutputs.processTokens(params.CURRENT_INPUT*multiplier, params.CURRENT_INPUT*multiplier, {from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); }); - it('14: should process tokenAmount with a scheme just like in the paper: 10/15 others, send EQUAL to minNeed; ', async () => { - const CURRENT_INPUT = 5900; - var e1 = 1000; - var e2 = 1500; - var e3 = 800; - var office = 500; - var internet = 300; - var t1 = 500; - var t2 = 300; - var t3 = 1000; - var b1 = 10000; - var b2 = 10000; - var b3 = 20000; - var reserve = 100000; - var dividends = 150000; - - var struct = await createStructure(token, creator, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - var splitterParams = await getSplitterParams(struct, CURRENT_INPUT, tokenAmount, creator); - await totalAndMinNeedsAsserts(splitterParams, CURRENT_INPUT, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); + it('14: should process amount with a scheme just like in the paper: 10/15 others, send EQUAL to minNeed; ', async () => { + var params = {token:token.address, CURRENT_INPUT:5900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:850000, dividends:150000} + + var struct = await createStructure(params, ERC20AbsoluteExpense, ERC20RelativeExpense, ERC20Splitter); + var splitterParams = await getSplitterParams(struct, params); + await totalAndMinNeedsAsserts(splitterParams, params); await structureAsserts(splitterParams); - await token.approve(struct.AllOutputs.address, CURRENT_INPUT*tokenAmount, {from:creator}); - await struct.AllOutputs.processTokens(CURRENT_INPUT*tokenAmount, CURRENT_INPUT*tokenAmount, {from: creator, gasPrice: 0 }); + await token.approve(struct.AllOutputs.address, params.CURRENT_INPUT*multiplier, {from:creator}); + await struct.AllOutputs.processTokens(params.CURRENT_INPUT*multiplier, params.CURRENT_INPUT*multiplier, {from: creator, gasPrice: 0 }); - var balances = await getBalances(token, struct); - await balancesAsserts(balances, CURRENT_INPUT, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, 0, 0, 0, 0, 0); - await splitterBalancesAsserts(balances, tokenAmount, 0, 0, 0, 0, 0, 0, 0); + var balances = await getBalances(struct, token.balanceOf); + await balancesAsserts(balances, params); + await splitterBalancesAsserts(balances); }); - it('15: should not process tokenAmount: send LESS than minNeed; ', async () => { - const CURRENT_INPUT = 30900; - var e1 = 1000; - var e2 = 1500; - var e3 = 800; - var office = 500; - var internet = 300; - var t1 = 500; - var t2 = 300; - var t3 = 1000; - var b1 = 10000; - var b2 = 10000; - var b3 = 20000; - var reserve = 100000; - var dividends = 150000; - - var struct = await createStructure(token, creator, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - var splitterParams = await getSplitterParams(struct, CURRENT_INPUT, tokenAmount, creator); - await totalAndMinNeedsAsserts(splitterParams, CURRENT_INPUT, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); + it('15: should not process multiplier: send LESS than minNeed; ', async () => { + var params = {token:token.address, CURRENT_INPUT:30900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:750000, dividends:250000} + + var struct = await createStructure(params, ERC20AbsoluteExpense, ERC20RelativeExpense, ERC20Splitter); + var splitterParams = await getSplitterParams(struct, params); + await totalAndMinNeedsAsserts(splitterParams, params); await structureAsserts(splitterParams); - await token.approve(struct.AllOutputs.address, 1000*tokenAmount, {from:creator}); - await struct.AllOutputs.processTokens(1000*tokenAmount, 1000*tokenAmount, {from: creator }).should.be.rejectedWith('revert'); - await token.approve(struct.AllOutputs.address, 1000*tokenAmount, {from:creator}); - await struct.AllOutputs.processTokens(1000000*tokenAmount, 1000*tokenAmount, {from: creator }).should.be.rejectedWith('revert'); - await token.approve(struct.AllOutputs.address, 1000000*tokenAmount, {from:creator}); - await struct.AllOutputs.processTokens(1000*tokenAmount, 1000000*tokenAmount, {from: creator }).should.be.rejectedWith('revert'); + await token.approve(struct.AllOutputs.address, 1000*multiplier, {from:creator}); + await struct.AllOutputs.processTokens(1000*multiplier, 1000*multiplier, {from: creator }).should.be.rejectedWith('revert'); + await token.approve(struct.AllOutputs.address, 1000*multiplier, {from:creator}); + await struct.AllOutputs.processTokens(1000000*multiplier, 1000*multiplier, {from: creator }).should.be.rejectedWith('revert'); + await token.approve(struct.AllOutputs.address, 1000000*multiplier, {from:creator}); + await struct.AllOutputs.processTokens(1000*multiplier, 1000000*multiplier, {from: creator }).should.be.rejectedWith('revert'); }); - it('16: should process tokenAmount with ERC20Splitter + 3 ERC20RelativeExpenseWithPeriod', async () => { + it('16: should process amount with ERC20Splitter + 3 ERC20RelativeExpenseWithPeriod', async () => { // create ERC20Splitter var splitter = await ERC20Splitter.new(token.address); @@ -854,57 +463,40 @@ contract('ERC20Expense', (accounts) => { var targets = [splitter, rel1, rel2, rel3]; var flowArr = [1000, 1000, 1000, 1000]; - await checkMinNeed(targets, flowArr, [0, 0, 0, 0]); - await checkTotalNeed(targets, flowArr, [720, 100, 250, 370]); - await checkIsNeed(targets, [true, true, true, true]); - - // now send some tokenAmount to the revenue endpoint - await token.approve(splitter.address, 720*tokenAmount, {from:creator}); - await splitter.processTokens(1000*tokenAmount, 720*tokenAmount, {from: creator}); + await checkParamsCycle(targets, flowArr, [0, 0, 0, 0], [720, 100, 250, 370], [true, true, true, true]); - assert.equal((await token.balanceOf(rel1.address)).toNumber(), 100*tokenAmount); - assert.equal((await token.balanceOf(rel2.address)).toNumber(), 250*tokenAmount); - assert.equal((await token.balanceOf(rel3.address)).toNumber(), 370*tokenAmount); + // now send some amount to the revenue endpoint + await token.approve(splitter.address, 720*multiplier, {from:creator}); + await splitter.processTokens(1000*multiplier, 720*multiplier, {from: creator}); - await checkMinNeed(targets, flowArr, [0, 0, 0, 0]); - await checkTotalNeed(targets, flowArr, [0, 0, 0, 0]); - await checkIsNeed(targets, [false, false, false, false]); + assert.equal((await token.balanceOf(rel1.address)).toNumber(), 100*multiplier); + assert.equal((await token.balanceOf(rel2.address)).toNumber(), 250*multiplier); + assert.equal((await token.balanceOf(rel3.address)).toNumber(), 370*multiplier); + await checkParamsCycle(targets, flowArr, [0, 0, 0, 0], [0, 0, 0, 0], [false, false, false, false]); await passHours(24); - await checkMinNeed(targets, flowArr, [0, 0, 0, 0]); - await checkTotalNeed(targets, flowArr, [350, 100, 250, 0]); - await checkIsNeed(targets, [true, true, true, false]); - + await checkParamsCycle(targets, flowArr, [0, 0, 0, 0], [350, 100, 250, 0], [true, true, true, false]); await passHours(24); - await checkMinNeed(targets, flowArr, [0, 0, 0, 0]); - await checkTotalNeed(targets, flowArr, [720, 100, 250, 370]); - await checkIsNeed(targets, [true, true, true, true]); + await checkParamsCycle(targets, flowArr, [0, 0, 0, 0], [720, 100, 250, 370], [true, true, true, true]); - await token.approve(splitter.address, 720*tokenAmount, {from:creator}); - await splitter.processTokens(1000*tokenAmount, 720*tokenAmount, {from: creator }); + await token.approve(splitter.address, 720*multiplier, {from:creator}); + await splitter.processTokens(1000*multiplier, 720*multiplier, {from: creator }); - await checkMinNeed(targets, flowArr, [0, 0, 0, 0]); - await checkTotalNeed(targets, flowArr, [0, 0, 0, 0]); - await checkIsNeed(targets, [false, false, false, false]); + await checkParamsCycle(targets, flowArr, [0, 0, 0, 0], [0, 0, 0, 0], [false, false, false, false]); - // tokenAmount should end up in the outputs - assert.equal((await token.balanceOf(rel1.address)).toNumber(), 200*tokenAmount); - assert.equal((await token.balanceOf(rel2.address)).toNumber(), 500*tokenAmount); - assert.equal((await token.balanceOf(rel3.address)).toNumber(), 740*tokenAmount); + // multiplier should end up in the outputs + assert.equal((await token.balanceOf(rel1.address)).toNumber(), 200*multiplier); + assert.equal((await token.balanceOf(rel2.address)).toNumber(), 500*multiplier); + assert.equal((await token.balanceOf(rel3.address)).toNumber(), 740*multiplier); await passHours(24); + await checkParamsCycle(targets, flowArr, [0, 0, 0, 0], [350, 100, 250, 0], [true, true, true, false]); - await checkMinNeed(targets, flowArr, [0, 0, 0, 0]); - await checkTotalNeed(targets, flowArr, [350, 100, 250, 0]); - await checkIsNeed(targets, [true, true, true, false]); - - await token.approve(splitter.address, 350*tokenAmount, {from:creator}); - await splitter.processTokens(1000*tokenAmount, 350*tokenAmount, {from: creator }); + await token.approve(splitter.address, 350*multiplier, {from:creator}); + await splitter.processTokens(1000*multiplier, 350*multiplier, {from: creator }); - await checkMinNeed(targets, flowArr, [0, 0, 0, 0]); - await checkTotalNeed(targets, flowArr, [0, 0, 0, 0]); - await checkIsNeed(targets, [false, false, false, false]); + await checkParamsCycle(targets, flowArr, [0, 0, 0, 0], [0, 0, 0, 0], [false, false, false, false]); }); }); \ No newline at end of file diff --git a/test/ERC20_tests/ERC20_fund.tests.js b/test/ERC20_tests/ERC20_fund.tests.js index 4dc292e..cdd7668 100644 --- a/test/ERC20_tests/ERC20_fund.tests.js +++ b/test/ERC20_tests/ERC20_fund.tests.js @@ -8,28 +8,16 @@ var ERC20RelativeExpense = artifacts.require('./ERC20RelativeExpense'); var ERC20AbsoluteExpenseWithPeriod = artifacts.require('./ERC20AbsoluteExpenseWithPeriod'); var ERC20RelativeExpenseWithPeriod = artifacts.require('./ERC20RelativeExpenseWithPeriod'); var ERC20AbsoluteExpenseWithPeriodSliding = artifacts.require('./ERC20AbsoluteExpenseWithPeriodSliding'); -const getEId = o => o.logs.filter(l => l.event == 'elementAdded')[0].args._eId.toNumber(); -const KECCAK256 = x => web3.sha3(x); - -async function passHours (hours) { - await web3.currentProvider.sendAsync({ - jsonrpc: '2.0', - method: 'evm_increaseTime', - params: [3600 * hours * 1000], - id: new Date().getTime(), - }, function (err) { if (err) console.log('err:', err); }); -} - -const BigNumber = web3.BigNumber; require('chai') .use(require('chai-as-promised')) - .use(require('chai-bignumber')(BigNumber)) + .use(require('chai-bignumber')(web3.BigNumber)) .should(); +const {passHours} = require('../helpers/utils'); + contract('ERC20Fund', (accounts) => { var token; - let tokenAmount = 1e7; const creator = accounts[0]; const employee1 = accounts[1]; @@ -38,19 +26,12 @@ contract('ERC20Fund', (accounts) => { beforeEach(async () => { token = await StandardToken.new(); - await token.mint(accounts[0], 1e25); - await token.mint(accounts[1], 1e25); - await token.mint(accounts[2], 1e25); - await token.mint(accounts[3], 1e25); - await token.mint(accounts[4], 1e25); - await token.mint(accounts[5], 1e25); - await token.mint(accounts[6], 1e25); - await token.mint(accounts[7], 1e25); - await token.mint(accounts[8], 1e25); - await token.mint(accounts[9], 1e25); + for(var i=0; i<10; i++) { + await token.mint(accounts[i], 1e25); + } }); - it('Should collect tokenAmount, then revert if more, then flush', async () => { + it('Should collect, then revert if more, then flush', async () => { let fund = await ERC20AbsoluteExpense.new(token.address,1e18, 0); var totalNeed = await fund.getTotalNeeded(1e22); @@ -99,7 +80,7 @@ contract('ERC20Fund', (accounts) => { assert.equal(isNeed, false); }); - it('Should collect tokenAmount (periodic, not accumulate debt), then time passed, then need tokenAmount again', async () => { + it('Should collect (periodic, not accumulate debt), then time passed, then need again', async () => { let fund = await ERC20AbsoluteExpenseWithPeriod.new(token.address,1e18, 0, 24); var totalNeed = await fund.getTotalNeeded(1e22); @@ -163,7 +144,7 @@ contract('ERC20Fund', (accounts) => { assert.equal(isNeed, false); }); - it('Should collect tokenAmount (periodic, accumulate debt), then time passed, then need tokenAmount again', async () => { + it('Should collect (periodic, accumulate debt), then time passed, then need again', async () => { let fund = await ERC20AbsoluteExpenseWithPeriodSliding.new(token.address,1e18, 0, 24); var totalNeed = await fund.getTotalNeeded(1e22); @@ -224,7 +205,7 @@ contract('ERC20Fund', (accounts) => { assert.equal(isNeed, false); }); - it('Should collect tokenAmount (periodic, accumulate debt), then time passed, then need tokenAmount again', async () => { + it('Should collect (periodic, accumulate debt), then time passed, then need again', async () => { let fund = await ERC20AbsoluteExpenseWithPeriodSliding.new(token.address,1e18, 0, 24); var totalNeed = await fund.getTotalNeeded(1e22); var isNeed = await fund.isNeeds(); diff --git a/test/ERC20_tests/ERC20_table.tests.js b/test/ERC20_tests/ERC20_table.tests.js index 9465372..d4869db 100644 --- a/test/ERC20_tests/ERC20_table.tests.js +++ b/test/ERC20_tests/ERC20_table.tests.js @@ -9,204 +9,19 @@ var ERC20RelativeExpense = artifacts.require('./ERC20RelativeExpense'); var ERC20AbsoluteExpenseWithPeriod = artifacts.require('./ERC20AbsoluteExpenseWithPeriod'); var ERC20RelativeExpenseWithPeriod = artifacts.require('./ERC20RelativeExpenseWithPeriod'); -var getEId = o => o.logs.filter(l => l.event == 'NodeAdded')[0].args._eId.toNumber(); - -function KECCAK256 (x) { - return web3.sha3(x); -} - -const BigNumber = web3.BigNumber; - require('chai') .use(require('chai-as-promised')) - .use(require('chai-bignumber')(BigNumber)) + .use(require('chai-bignumber')(web3.BigNumber)) .should(); -function KECCAK256 (x) { - return web3.sha3(x); -} - -async function createStructure(token, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends) { - var o = {}; - o.erc20Table = await ERC20Table.new(token.address); - - o.AllOutputsId = getEId(await o.erc20Table.addSplitter()); - o.SpendsId = getEId(await o.erc20Table.addSplitter()); - o.SalariesId = getEId(await o.erc20Table.addSplitter()); - o.Employee1Id = getEId(await o.erc20Table.addAbsoluteExpense(e1 * tokenAmount, e1 * tokenAmount, false, false, 0)); - o.Employee2Id = getEId(await o.erc20Table.addAbsoluteExpense(e2 * tokenAmount, e2 * tokenAmount, false, false, 0)); - o.Employee3Id = getEId(await o.erc20Table.addAbsoluteExpense(e3 * tokenAmount, e3 * tokenAmount, false, false, 0)); - o.OtherId = getEId(await o.erc20Table.addSplitter()); - o.OfficeId = getEId(await o.erc20Table.addAbsoluteExpense(office * tokenAmount, office * tokenAmount, false, false, 0)); - o.InternetId = getEId(await o.erc20Table.addAbsoluteExpense(internet * tokenAmount, internet * tokenAmount, false, false, 0)); - o.TasksId = getEId(await o.erc20Table.addSplitter()); - o.Task1Id = getEId(await o.erc20Table.addAbsoluteExpense(t1 * tokenAmount, t1 * tokenAmount, false, false, 0)); - o.Task2Id = getEId(await o.erc20Table.addAbsoluteExpense(t2 * tokenAmount, t2 * tokenAmount, false, false, 0)); - o.Task3Id = getEId(await o.erc20Table.addAbsoluteExpense(t3 * tokenAmount, t3 * tokenAmount, false, false, 0)); - o.BonusesId = getEId(await o.erc20Table.addSplitter()); - o.Bonus1Id = getEId(await o.erc20Table.addRelativeExpense(b1, false, false, 0)); - o.Bonus2Id = getEId(await o.erc20Table.addRelativeExpense(b2, false, false, 0)); - o.Bonus3Id = getEId(await o.erc20Table.addRelativeExpense(b3, false, false, 0)); - o.RestId = getEId(await o.erc20Table.addSplitter()); - o.DividendsFundId = getEId(await o.erc20Table.addAbsoluteExpense(dividends * tokenAmount, 0, false, false, 0)); - o.ReserveFundId = getEId(await o.erc20Table.addAbsoluteExpense(reserve * tokenAmount, 0, false, false, 0)); - - await o.erc20Table.addChildAt(o.AllOutputsId, o.SpendsId); - await o.erc20Table.addChildAt(o.SpendsId, o.SalariesId); - await o.erc20Table.addChildAt(o.SalariesId, o.Employee1Id); - await o.erc20Table.addChildAt(o.SalariesId, o.Employee2Id); - await o.erc20Table.addChildAt(o.SalariesId, o.Employee3Id); - await o.erc20Table.addChildAt(o.SpendsId, o.OtherId); - await o.erc20Table.addChildAt(o.OtherId, o.OfficeId); - await o.erc20Table.addChildAt(o.OtherId, o.InternetId); - await o.erc20Table.addChildAt(o.SpendsId, o.TasksId); - await o.erc20Table.addChildAt(o.TasksId, o.Task1Id); - await o.erc20Table.addChildAt(o.TasksId, o.Task2Id); - await o.erc20Table.addChildAt(o.TasksId, o.Task3Id); - await o.erc20Table.addChildAt(o.AllOutputsId, o.BonusesId); - await o.erc20Table.addChildAt(o.BonusesId, o.Bonus1Id); - await o.erc20Table.addChildAt(o.BonusesId, o.Bonus2Id); - await o.erc20Table.addChildAt(o.BonusesId, o.Bonus3Id); - await o.erc20Table.addChildAt(o.AllOutputsId, o.RestId); - await o.erc20Table.addChildAt(o.RestId, o.DividendsFundId); - await o.erc20Table.addChildAt(o.RestId, o.ReserveFundId); - return o; -} - -async function totalAndMinNeedsAsserts (tokenAmount, i, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends) { - var totalSpend = e1 + e2 + e3 + t1 + t2 + t3 + office + internet; - var bonusesSpendPercent = (CURRENT_INPUT - totalSpend) / 1000000; - var rest = CURRENT_INPUT - totalSpend - (bonusesSpendPercent * (b1 + b2 + b3)); - - var dividendsAmount = 0; - var reserveAmount = 0; - if(rest<=0){ - - }else if(rest<=dividends){ - dividendsAmount = rest; - reserveAmount = 0; - }else{ - dividendsAmount = dividends; - reserveAmount = rest - dividendsAmount; - } - var allNeeds = totalSpend + (bonusesSpendPercent * (b1 + b2 + b3)) + (dividendsAmount + reserveAmount); - - assert.equal((new web3.BigNumber(i.AllOutputsTotalNeed).div(tokenAmount)).toNumber(), allNeeds, `AllOutputs Total Need should be ${allNeeds}`); - assert.equal((new web3.BigNumber(i.AllOutputsMinNeed).div(tokenAmount)).toNumber(), totalSpend, `AllOutputs min Need should be ${totalSpend}`); - assert.equal((new web3.BigNumber(i.SpendsTotalNeed).div(tokenAmount)).toNumber(), totalSpend, `Spends Total Need should be ${totalSpend}`); - assert.equal((new web3.BigNumber(i.SpendsMinNeed).div(tokenAmount)).toNumber(), totalSpend, `Spends min Need should be ${totalSpend}`); - assert.equal((new web3.BigNumber(i.SalariesTotalNeed).div(tokenAmount)).toNumber(), e1 + e2 + e3, `Salaries Total Need should be ${e1 + e2 + e3}`); - assert.equal((new web3.BigNumber(i.SalariesMinNeed).div(tokenAmount)).toNumber(), e1 + e2 + e3, `Salaries min Need should be ${e1 + e2 + e3}`); - assert.equal((new web3.BigNumber(i.OtherTotalNeed).div(tokenAmount)).toNumber(), office + internet, `Other Total Need should be ${office + internet}`); - assert.equal((new web3.BigNumber(i.OtherMinNeed).div(tokenAmount)).toNumber(), office + internet, `Other min Need should be ${office + internet}`); - assert.equal((new web3.BigNumber(i.TasksTotalNeed).div(tokenAmount)).toNumber(), t1 + t2 + t3, `Tasks Total Need should be ${t1 + t2 + t3}`); - assert.equal((new web3.BigNumber(i.TasksMinNeed).div(tokenAmount)).toNumber(), t1 + t2 + t3, `Tasks min Need should be ${t1 + t2 + t3}`); - assert.equal((new web3.BigNumber(i.BonusesTotalNeed).div(tokenAmount)).toNumber(), (b1 + b2 + b3) * CURRENT_INPUT / 1000000, `Bonuses Total Need should be ${(b1 + b2 + b3) * CURRENT_INPUT / 1000000}`); - assert.equal((new web3.BigNumber(i.BonusesMinNeed).div(tokenAmount)).toNumber(), 0, `Bonuses min Need should be ${0}`); - assert.equal((new web3.BigNumber(i.RestTotalNeed).div(tokenAmount)).toNumber(), CURRENT_INPUT, `Rest Total Need should be ${rest}`); - assert.equal((new web3.BigNumber(i.RestMinNeed).div(tokenAmount)).toNumber(), 0, `Rest min Need should be ${0}`); -} - -async function getBalances (i) { - var o = {}; - o.Employee1Balance = await i.erc20Table.balanceAt(i.Employee1Id); - o.Employee2Balance = await i.erc20Table.balanceAt(i.Employee2Id); - o.Employee3Balance = await i.erc20Table.balanceAt(i.Employee3Id); - o.OfficeBalance = await i.erc20Table.balanceAt(i.OfficeId); - o.InternetBalance = await i.erc20Table.balanceAt(i.InternetId); - o.Task1Balance = await i.erc20Table.balanceAt(i.Task1Id); - o.Task2Balance = await i.erc20Table.balanceAt(i.Task2Id); - o.Task3Balance = await i.erc20Table.balanceAt(i.Task3Id); - o.ReserveBalance = await i.erc20Table.balanceAt(i.ReserveFundId); - o.DividendsBalance = await i.erc20Table.balanceAt(i.DividendsFundId); - o.Bonus1Balance = await i.erc20Table.balanceAt(i.Bonus1Id); - o.Bonus2Balance = await i.erc20Table.balanceAt(i.Bonus2Id); - o.Bonus3Balance = await i.erc20Table.balanceAt(i.Bonus3Id); - o.AllOutputsBalance = await i.erc20Table.balanceAt(i.AllOutputsId); - o.SpendsBalance = await i.erc20Table.balanceAt(i.SpendsId); - o.SalariesBalance = await i.erc20Table.balanceAt(i.SalariesId); - o.OtherBalance = await i.erc20Table.balanceAt(i.OtherId); - o.TasksBalance = await i.erc20Table.balanceAt(i.TasksId); - o.BonusesBalance = await i.erc20Table.balanceAt(i.BonusesId); - o.RestBalance = await i.erc20Table.balanceAt(i.RestId); - - return o; -} - -async function getSplitterParams (tokenAmount, i, CURRENT_INPUT) { - var o = {}; - o.AllOutputsTotalNeed = await i.erc20Table.getTotalNeededAt(i.AllOutputsId, CURRENT_INPUT * tokenAmount); - o.AllOutputsMinNeed = await i.erc20Table.getMinNeededAt(i.AllOutputsId, CURRENT_INPUT * tokenAmount); - o.AllOutputsChildrenCount = await i.erc20Table.getChildrenCountAt(i.AllOutputsId); - o.SpendsTotalNeed = await i.erc20Table.getTotalNeededAt(i.SpendsId, CURRENT_INPUT * tokenAmount); - o.SpendsMinNeed = await i.erc20Table.getMinNeededAt(i.SpendsId, CURRENT_INPUT * tokenAmount); - o.SpendsChildrenCount = await i.erc20Table.getChildrenCountAt(i.SpendsId); - o.SalariesTotalNeed = await i.erc20Table.getTotalNeededAt(i.SalariesId, CURRENT_INPUT * tokenAmount); - o.SalariesMinNeed = await i.erc20Table.getMinNeededAt(i.SalariesId, CURRENT_INPUT * tokenAmount); - o.SalariesChildrenCount = await i.erc20Table.getChildrenCountAt(i.SalariesId); - o.OtherTotalNeed = await i.erc20Table.getTotalNeededAt(i.OtherId, CURRENT_INPUT * tokenAmount); - o.OtherMinNeed = await i.erc20Table.getMinNeededAt(i.OtherId, CURRENT_INPUT * tokenAmount); - o.OtherChildrenCount = await i.erc20Table.getChildrenCountAt(i.OtherId); - o.TasksTotalNeed = await i.erc20Table.getTotalNeededAt(i.TasksId, CURRENT_INPUT * tokenAmount); - o.TasksMinNeed = await i.erc20Table.getMinNeededAt(i.TasksId, CURRENT_INPUT * tokenAmount); - o.TasksChildrenCount = await i.erc20Table.getChildrenCountAt(i.TasksId); - o.BonusesTotalNeed = await i.erc20Table.getTotalNeededAt(i.BonusesId, CURRENT_INPUT * tokenAmount); - o.BonusesMinNeed = await i.erc20Table.getMinNeededAt(i.BonusesId, CURRENT_INPUT * tokenAmount); - o.BonusesChildrenCount = await i.erc20Table.getChildrenCountAt(i.BonusesId); - o.RestTotalNeed = await i.erc20Table.getTotalNeededAt(i.RestId, CURRENT_INPUT * tokenAmount); - o.RestMinNeed = await i.erc20Table.getMinNeededAt(i.RestId, CURRENT_INPUT * tokenAmount); - o.RestChildrenCount = await i.erc20Table.getChildrenCountAt(i.RestId); - - return o; -} - -async function structureAsserts (i) { - assert.equal(i.AllOutputsChildrenCount.toNumber(), 3, 'Children count should be 3'); - assert.equal(i.SpendsChildrenCount.toNumber(), 3, 'Children count should be 3'); - assert.equal(i.SalariesChildrenCount.toNumber(), 3, 'Children count should be 3'); - assert.equal(i.OtherChildrenCount.toNumber(), 2, 'Children count should be 2'); - assert.equal(i.TasksChildrenCount.toNumber(), 3, 'Children count should be 3'); - assert.equal(i.BonusesChildrenCount.toNumber(), 3, 'Children count should be 3'); - assert.equal(i.RestChildrenCount.toNumber(), 2, 'Children count should be 2'); -} - -async function balancesAsserts (tokenAmount, i, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends) { - var totalSpend = e1 + e2 + e3 + t1 + t2 + t3 + office + internet; - var bonusesSpendPercent = (CURRENT_INPUT - totalSpend) / 1000000; - var rest = CURRENT_INPUT - totalSpend - (bonusesSpendPercent * (b1 + b2 + b3)); - - var dividendsAmount = 0; - var reserveAmount = 0; - if((rest<=dividends)&&(rest>0)){ - dividendsAmount = rest; - reserveAmount = 0; - }else{ - dividendsAmount = dividends; - reserveAmount = rest - dividendsAmount; - } - - assert.equal((new web3.BigNumber(i.Employee1Balance).div(tokenAmount)).toNumber(), e1, `Employee1 balance should be ${e1} tokenAmount`); - assert.equal((new web3.BigNumber(i.Employee2Balance).div(tokenAmount)).toNumber(), e2, `Employee2 balance should be ${e2} tokenAmount`); - assert.equal((new web3.BigNumber(i.Employee3Balance).div(tokenAmount)).toNumber(), e3, `Employee3 balance should be ${e3} tokenAmount`); - assert.equal((new web3.BigNumber(i.OfficeBalance).div(tokenAmount)).toNumber(), office, `Office balance should be ${office} tokenAmount`); - assert.equal((new web3.BigNumber(i.InternetBalance).div(tokenAmount)).toNumber(), internet, `Internet balance should be ${internet} tokenAmount`); - assert.equal((new web3.BigNumber(i.Task1Balance).div(tokenAmount)).toNumber(), t1, `Task1 balance should be ${t1} tokenAmount`); - assert.equal((new web3.BigNumber(i.Task2Balance).div(tokenAmount)).toNumber(), t2, `Task2 balance should be ${t2} tokenAmount`); - assert.equal((new web3.BigNumber(i.Task3Balance).div(tokenAmount)).toNumber(), t3, `Task3 balance should be ${t3} tokenAmount`); - assert.equal((new web3.BigNumber(i.Bonus1Balance).div(tokenAmount)).toNumber(), bonusesSpendPercent * b1, `Bonus1 balance should be ${bonusesSpendPercent * b1} tokenAmount`); - assert.equal((new web3.BigNumber(i.Bonus2Balance).div(tokenAmount)).toNumber(), bonusesSpendPercent * b2, `Bonus2 balance should be ${bonusesSpendPercent * b2} tokenAmount`); - assert.equal((new web3.BigNumber(i.Bonus3Balance).div(tokenAmount)).toNumber(), bonusesSpendPercent * b3, `Bonus3 balance should be ${bonusesSpendPercent * b3} tokenAmount`); - assert.equal((new web3.BigNumber(i.DividendsBalance).div(tokenAmount)).toNumber(), dividendsAmount, `Dividends balance should be ${dividendsAmount} tokenAmount`); - assert.equal((new web3.BigNumber(i.ReserveBalance).div(tokenAmount)).toNumber(), reserveAmount, `Reserve balance should be ${reserveAmount} tokenAmount`); - -} +const {createStructureTable, totalAndMinNeedsAssertsTable, getBalancesTable, + getSplitterParamsTable, structureAssertsTable, balancesAssertsTable} = require('../helpers/structures'); + +const {passHours, getNodeId} = require('../helpers/utils'); contract('ERC20Table tests', (accounts) => { var token; - var store; - var daoBase; - - var tokenAmount = 1e12; + var multiplier = 1e12; var isPeriodic = false; var isAccumulateDebt = false; var periodHours = 0; @@ -219,376 +34,294 @@ contract('ERC20Table tests', (accounts) => { beforeEach(async () => { token = await StandardToken.new(); - await token.mint(accounts[0], 1e30); - await token.mint(accounts[1], 1e30); - await token.mint(accounts[2], 1e30); - await token.mint(accounts[3], 1e30); - await token.mint(accounts[4], 1e30); - await token.mint(accounts[5], 1e30); - await token.mint(accounts[6], 1e30); - await token.mint(accounts[7], 1e30); - await token.mint(accounts[8], 1e30); - await token.mint(accounts[9], 1e30); + for(var i=0; i<10; i++) { + await token.mint(accounts[i], 1e30); + } }); // 0->•abs - it('1: should process tokenAmount with ERC20Splitter + 3 ERC20AbsoluteExpense', async () => { - let erc20Table = await ERC20Table.new(token.address); - var output1 = await ERC20AbsoluteExpense.new(token.address,tokenAmount, tokenAmount); - var output2 = await ERC20AbsoluteExpense.new(token.address,2 * tokenAmount, 2 * tokenAmount); - var output3 = await ERC20AbsoluteExpense.new(token.address,3 * tokenAmount, 3 * tokenAmount); - let splitterId = getEId(await erc20Table.addSplitter()); - let AbsoluteExpense1Id = getEId(await erc20Table.addAbsoluteExpense(1 * tokenAmount, 1 * tokenAmount, isPeriodic, isAccumulateDebt, periodHours)); - let AbsoluteExpense2Id = getEId(await erc20Table.addAbsoluteExpense(2 * tokenAmount, 2 * tokenAmount, isPeriodic, isAccumulateDebt, periodHours)); - let AbsoluteExpense3Id = getEId(await erc20Table.addAbsoluteExpense(3 * tokenAmount, 3 * tokenAmount, isPeriodic, isAccumulateDebt, periodHours)); + it('1: should process with ERC20Splitter + 3 ERC20AbsoluteExpense', async () => { + let table = await ERC20Table.new(token.address); + var output1 = await ERC20AbsoluteExpense.new(token.address,multiplier, multiplier); + var output2 = await ERC20AbsoluteExpense.new(token.address,2 * multiplier, 2 * multiplier); + var output3 = await ERC20AbsoluteExpense.new(token.address,3 * multiplier, 3 * multiplier); + let splitterId = getNodeId(await table.addSplitter()); + let AbsoluteExpense1Id = getNodeId(await table.addAbsoluteExpense(1 * multiplier, 1 * multiplier, isPeriodic, isAccumulateDebt, periodHours)); + let AbsoluteExpense2Id = getNodeId(await table.addAbsoluteExpense(2 * multiplier, 2 * multiplier, isPeriodic, isAccumulateDebt, periodHours)); + let AbsoluteExpense3Id = getNodeId(await table.addAbsoluteExpense(3 * multiplier, 3 * multiplier, isPeriodic, isAccumulateDebt, periodHours)); // add 3 ERC20AbsoluteExpense outputs to the splitter - await erc20Table.addChildAt(splitterId, AbsoluteExpense1Id); - await erc20Table.addChildAt(splitterId, AbsoluteExpense2Id); - await erc20Table.addChildAt(splitterId, AbsoluteExpense3Id); + await table.addChildAt(splitterId, AbsoluteExpense1Id); + await table.addChildAt(splitterId, AbsoluteExpense2Id); + await table.addChildAt(splitterId, AbsoluteExpense3Id); - var id1 = await erc20Table.getChildIdAt(splitterId, 0); - var id2 = await erc20Table.getChildIdAt(splitterId, 1); - var id3 = await erc20Table.getChildIdAt(splitterId, 2); + var id1 = await table.getChildIdAt(splitterId, 0); + var id2 = await table.getChildIdAt(splitterId, 1); + var id3 = await table.getChildIdAt(splitterId, 2); assert.equal(id1, AbsoluteExpense1Id); assert.equal(id2, AbsoluteExpense2Id); assert.equal(id3, AbsoluteExpense3Id); - var totalNeed = await erc20Table.getTotalNeeded(6 * tokenAmount); - assert.equal(totalNeed, 6 * tokenAmount); - var minNeed = await erc20Table.getMinNeeded(0);/*minNeedFix*/ - assert.equal(minNeed, 6 * tokenAmount); - var need1 = await erc20Table.isNeeds(); + var totalNeed = await table.getTotalNeeded(6 * multiplier); + assert.equal(totalNeed, 6 * multiplier); + var minNeed = await table.getMinNeeded(0);/*minNeedFix*/ + assert.equal(minNeed, 6 * multiplier); + var need1 = await table.isNeeds(); assert.equal(need1, true); - // now send some tokenAmount to the revenue endpoint - await token.approve(erc20Table.address, 6 * tokenAmount, {from:creator}); - await erc20Table.processTokens(6 * tokenAmount, 6 * tokenAmount, {from: creator }); + // now send some to the revenue endpoint + await token.approve(table.address, 6 * multiplier, {from:creator}); + await table.processTokens(6 * multiplier, 6 * multiplier, {from: creator }); - // tokenAmount should end up in the outputs - var absoluteExpense1Balance = await erc20Table.balanceAt(AbsoluteExpense1Id); - assert.equal(absoluteExpense1Balance.toNumber(), 1 * tokenAmount, 'resource point received tokenAmount from splitter'); + // should end up in the outputs + var absoluteExpense1Balance = await table.balanceAt(AbsoluteExpense1Id); + assert.equal(absoluteExpense1Balance.toNumber(), 1 * multiplier, 'resource point received from splitter'); - var absoluteExpense2Balance = await erc20Table.balanceAt(AbsoluteExpense2Id); - assert.equal(absoluteExpense2Balance.toNumber(), 2 * tokenAmount, 'resource point received tokenAmount from splitter'); + var absoluteExpense2Balance = await table.balanceAt(AbsoluteExpense2Id); + assert.equal(absoluteExpense2Balance.toNumber(), 2 * multiplier, 'resource point received from splitter'); - var absoluteExpense3Balance = await erc20Table.balanceAt(AbsoluteExpense3Id); - assert.equal(absoluteExpense3Balance.toNumber(), 3 * tokenAmount, 'resource point received tokenAmount from splitter'); + var absoluteExpense3Balance = await table.balanceAt(AbsoluteExpense3Id); + assert.equal(absoluteExpense3Balance.toNumber(), 3 * multiplier, 'resource point received from splitter'); - assert.equal((await erc20Table.getTotalNeededAt(AbsoluteExpense1Id, 6 * tokenAmount)).toNumber(), 0); - assert.equal((await erc20Table.getTotalNeededAt(AbsoluteExpense2Id, 6 * tokenAmount)).toNumber(), 0); - assert.equal((await erc20Table.getTotalNeededAt(AbsoluteExpense3Id, 6 * tokenAmount)).toNumber(), 0); + assert.equal((await table.getTotalNeededAt(AbsoluteExpense1Id, 6 * multiplier)).toNumber(), 0); + assert.equal((await table.getTotalNeededAt(AbsoluteExpense2Id, 6 * multiplier)).toNumber(), 0); + assert.equal((await table.getTotalNeededAt(AbsoluteExpense3Id, 6 * multiplier)).toNumber(), 0); - var totalNeed = await erc20Table.getTotalNeeded(6 * tokenAmount); - assert.equal(totalNeed.toNumber(), 0 * tokenAmount); - var minNeed = await erc20Table.getMinNeeded(0);/*minNeedFix*/ - assert.equal(minNeed.toNumber(), 0 * tokenAmount); + var totalNeed = await table.getTotalNeeded(6 * multiplier); + assert.equal(totalNeed.toNumber(), 0 * multiplier); + var minNeed = await table.getMinNeeded(0);/*minNeedFix*/ + assert.equal(minNeed.toNumber(), 0 * multiplier); - var need2 = await erc20Table.isNeeds(); + var need2 = await table.isNeeds(); assert.equal(need2, false); var b1 = await token.balanceOf(accounts[9]); - await erc20Table.flushToAt(AbsoluteExpense1Id, accounts[9], { gasPrice: 0 }); + await table.flushToAt(AbsoluteExpense1Id, accounts[9], { gasPrice: 0 }); var b2 = await token.balanceOf(accounts[9]); - assert.equal(b2.sub(b1).toNumber(), 1 * tokenAmount); + assert.equal(b2.sub(b1).toNumber(), 1 * multiplier); var b1 = await token.balanceOf(accounts[9]); - await erc20Table.flushToAt(AbsoluteExpense2Id, accounts[9], { gasPrice: 0 }); + await table.flushToAt(AbsoluteExpense2Id, accounts[9], { gasPrice: 0 }); var b2 = await token.balanceOf(accounts[9]); - assert.equal(b2.sub(b1).toNumber(), 2 * tokenAmount); + assert.equal(b2.sub(b1).toNumber(), 2 * multiplier); var b1 = await token.balanceOf(accounts[9]); - await erc20Table.flushToAt(AbsoluteExpense3Id, accounts[9], { gasPrice: 0 }); + await table.flushToAt(AbsoluteExpense3Id, accounts[9], { gasPrice: 0 }); var b2 = await token.balanceOf(accounts[9]); - assert.equal(b2.sub(b1).toNumber(), 3 * tokenAmount); + assert.equal(b2.sub(b1).toNumber(), 3 * multiplier); - var absoluteExpense1Balance = await erc20Table.balanceAt(AbsoluteExpense1Id); - assert.equal(absoluteExpense1Balance.toNumber(), 0 * tokenAmount, 'resource point received tokenAmount from splitter'); + var absoluteExpense1Balance = await table.balanceAt(AbsoluteExpense1Id); + assert.equal(absoluteExpense1Balance.toNumber(), 0 * multiplier, 'resource point received from splitter'); - var absoluteExpense2Balance = await erc20Table.balanceAt(AbsoluteExpense2Id); - assert.equal(absoluteExpense2Balance.toNumber(), 0 * tokenAmount, 'resource point received tokenAmount from splitter'); + var absoluteExpense2Balance = await table.balanceAt(AbsoluteExpense2Id); + assert.equal(absoluteExpense2Balance.toNumber(), 0 * multiplier, 'resource point received from splitter'); - var absoluteExpense3Balance = await erc20Table.balanceAt(AbsoluteExpense3Id); - assert.equal(absoluteExpense3Balance.toNumber(), 0 * tokenAmount, 'resource point received tokenAmount from splitter'); - var need2 = await erc20Table.isNeeds(); + var absoluteExpense3Balance = await table.balanceAt(AbsoluteExpense3Id); + assert.equal(absoluteExpense3Balance.toNumber(), 0 * multiplier, 'resource point received from splitter'); + var need2 = await table.isNeeds(); }); - it('2: should process tokenAmount with ERC20Splitter + 3 ERC20AbsoluteExpense', async () => { - let erc20Table = await ERC20Table.new(token.address); + it('2: should process with ERC20Splitter + 3 ERC20AbsoluteExpense', async () => { + let table = await ERC20Table.new(token.address); - let unsortedSplitterId = getEId(await erc20Table.addSplitter()); - let AbsoluteExpense1Id = getEId(await erc20Table.addAbsoluteExpense(tokenAmount, tokenAmount, isPeriodic, isAccumulateDebt, periodHours)); - let AbsoluteExpense2Id = getEId(await erc20Table.addAbsoluteExpense(2 * tokenAmount, 2 * tokenAmount, isPeriodic, isAccumulateDebt, periodHours)); - let AbsoluteExpense3Id = getEId(await erc20Table.addAbsoluteExpense(3 * tokenAmount, 3 * tokenAmount, isPeriodic, isAccumulateDebt, periodHours)); - - await erc20Table.addChildAt(unsortedSplitterId, AbsoluteExpense1Id); - await erc20Table.addChildAt(unsortedSplitterId, AbsoluteExpense2Id); - await erc20Table.addChildAt(unsortedSplitterId, AbsoluteExpense3Id); - - // now send some tokenAmount to the revenue endpoint - let totalNeed = await erc20Table.getTotalNeeded(6 * tokenAmount); - assert.equal(totalNeed, 6 * tokenAmount); - let minNeed = await erc20Table.getMinNeeded(0);/*minNeedFix*/ - assert.equal(minNeed, 6 * tokenAmount); - - await token.approve(erc20Table.address, 6 * tokenAmount, {from:creator}); - await erc20Table.processTokens(6 * tokenAmount, 6 * tokenAmount, {from: creator }); - // tokenAmount should end up in the outputs - var absoluteExpense1Balance = await erc20Table.balanceAt(AbsoluteExpense1Id); - assert.equal(absoluteExpense1Balance.toNumber(), 1 * tokenAmount, 'resource point received tokenAmount from splitter'); - - var absoluteExpense2Balance = await erc20Table.balanceAt(AbsoluteExpense2Id); - assert.equal(absoluteExpense2Balance.toNumber(), 2 * tokenAmount, 'resource point received tokenAmount from splitter'); - - var absoluteExpense3Balance = await erc20Table.balanceAt(AbsoluteExpense3Id); - assert.equal(absoluteExpense3Balance.toNumber(), 3 * tokenAmount, 'resource point received tokenAmount from splitter'); + let unsortedSplitterId = getNodeId(await table.addSplitter()); + let AbsoluteExpense1Id = getNodeId(await table.addAbsoluteExpense(multiplier, multiplier, isPeriodic, isAccumulateDebt, periodHours)); + let AbsoluteExpense2Id = getNodeId(await table.addAbsoluteExpense(2 * multiplier, 2 * multiplier, isPeriodic, isAccumulateDebt, periodHours)); + let AbsoluteExpense3Id = getNodeId(await table.addAbsoluteExpense(3 * multiplier, 3 * multiplier, isPeriodic, isAccumulateDebt, periodHours)); + + await table.addChildAt(unsortedSplitterId, AbsoluteExpense1Id); + await table.addChildAt(unsortedSplitterId, AbsoluteExpense2Id); + await table.addChildAt(unsortedSplitterId, AbsoluteExpense3Id); + + // now send some to the revenue endpoint + let totalNeed = await table.getTotalNeeded(6 * multiplier); + assert.equal(totalNeed, 6 * multiplier); + let minNeed = await table.getMinNeeded(0);/*minNeedFix*/ + assert.equal(minNeed, 6 * multiplier); + + await token.approve(table.address, 6 * multiplier, {from:creator}); + await table.processTokens(6 * multiplier, 6 * multiplier, {from: creator }); + // should end up in the outputs + var absoluteExpense1Balance = await table.balanceAt(AbsoluteExpense1Id); + assert.equal(absoluteExpense1Balance.toNumber(), 1 * multiplier, 'resource point received from splitter'); + + var absoluteExpense2Balance = await table.balanceAt(AbsoluteExpense2Id); + assert.equal(absoluteExpense2Balance.toNumber(), 2 * multiplier, 'resource point received from splitter'); + + var absoluteExpense3Balance = await table.balanceAt(AbsoluteExpense3Id); + assert.equal(absoluteExpense3Balance.toNumber(), 3 * multiplier, 'resource point received from splitter'); }); - it('3: should process tokenAmount with a scheme just like in the paper: 75/25 others, send MORE than minNeed; ', async () => { - const tokenAmount = 1e12; - const CURRENT_INPUT = 30900; - let e1 = 1000; - let e2 = 1500; - let e3 = 800; - let office = 500; - let internet = 300; - let t1 = 500; - let t2 = 300; - let t3 = 1000; - // 5900 - let b1 = 10000; - let b2 = 10000; - let b3 = 20000; - //4% of 25K = 1000 - let reserve = 750000; - let dividends = 250000; - - let struct = await createStructure(token, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - let splitterParams = await getSplitterParams(tokenAmount, struct, CURRENT_INPUT, creator); - await totalAndMinNeedsAsserts(tokenAmount, splitterParams, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - await structureAsserts(splitterParams); - - await token.approve(struct.erc20Table.address, CURRENT_INPUT * tokenAmount, {from:creator}); - await struct.erc20Table.processTokens(CURRENT_INPUT * tokenAmount, CURRENT_INPUT * tokenAmount, {from: creator, gasPrice: 0 }); - - let balances = await getBalances(struct); - await balancesAsserts(tokenAmount, balances, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); + it('3: should process with a scheme just like in the paper: 75/25 others, send MORE than minNeed; ', async () => { + var params = {token:token.address, CURRENT_INPUT:30900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:750000, dividends:250000} + + let struct = await createStructureTable(params, ERC20Table); + let splitterParams = await getSplitterParamsTable(struct, params); + await totalAndMinNeedsAssertsTable(splitterParams, params); + await structureAssertsTable(splitterParams); + + await token.approve(struct.table.address, params.CURRENT_INPUT * multiplier, {from:creator}); + await struct.table.processTokens(params.CURRENT_INPUT * multiplier, params.CURRENT_INPUT * multiplier, {from: creator, gasPrice: 0 }); + + let balances = await getBalancesTable(struct); + await balancesAssertsTable(balances, params); }); - it('4: should process tokenAmount with a scheme just like in the paper: 75/25 others, send EQUAL to minNeed', async () => { - const tokenAmount = 1e12; - const CURRENT_INPUT = 5900; - let e1 = 1000; - let e2 = 1500; - let e3 = 800; - let office = 500; - let internet = 300; - let t1 = 500; - let t2 = 300; - let t3 = 1000; - let b1 = 10000; - let b2 = 10000; - let b3 = 20000; - let reserve = 750000; - let dividends = 250000; - - let struct = await createStructure(token, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - let splitterParams = await getSplitterParams(tokenAmount, struct, CURRENT_INPUT, creator); - await totalAndMinNeedsAsserts(tokenAmount, splitterParams, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - await structureAsserts(splitterParams); - - await token.approve(struct.erc20Table.address, CURRENT_INPUT * tokenAmount, {from:creator}); - await struct.erc20Table.processTokens(CURRENT_INPUT * tokenAmount, CURRENT_INPUT * tokenAmount, {from: creator, gasPrice: 0 }); - - let balances = await getBalances(struct); - await balancesAsserts(tokenAmount, balances, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, 0, 0, 0, 0, 0); + it('4: should process with a scheme just like in the paper: 75/25 others, send EQUAL to minNeed', async () => { + var params = {token:token.address, CURRENT_INPUT:5900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:750000, dividends:250000} + + let struct = await createStructureTable(params, ERC20Table); + let splitterParams = await getSplitterParamsTable(struct, params); + await totalAndMinNeedsAssertsTable(splitterParams, params); + await structureAssertsTable(splitterParams); + + await token.approve(struct.table.address, params.CURRENT_INPUT * multiplier, {from:creator}); + await struct.table.processTokens(params.CURRENT_INPUT * multiplier, params.CURRENT_INPUT * multiplier, {from: creator, gasPrice: 0 }); + + let balances = await getBalancesTable(struct); + await balancesAssertsTable(balances, params); }); - it('5: should not process tokenAmount: send LESS than minNeed', async () => { - const tokenAmount = 1e12; - const CURRENT_INPUT = 5900; - let e1 = 1000; - let e2 = 1500; - let e3 = 800; - let office = 500; - let internet = 300; - let t1 = 500; - let t2 = 300; - let t3 = 1000; - let b1 = 10000; - let b2 = 10000; - let b3 = 20000; - let reserve = 750000; - let dividends = 250000; - - let struct = await createStructure(token, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - let splitterParams = await getSplitterParams(tokenAmount, struct, CURRENT_INPUT, creator); - await totalAndMinNeedsAsserts(tokenAmount, splitterParams, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - await structureAsserts(splitterParams); - - await token.approve(struct.erc20Table.address, CURRENT_INPUT * tokenAmount, {from:creator}); - await struct.erc20Table.processTokens(CURRENT_INPUT * tokenAmount / 100, CURRENT_INPUT * tokenAmount, {from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); - await token.approve(struct.erc20Table.address, CURRENT_INPUT * tokenAmount / 100, {from:creator}); - await struct.erc20Table.processTokens(CURRENT_INPUT * tokenAmount, CURRENT_INPUT * tokenAmount / 100, {from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); - await token.approve(struct.erc20Table.address, CURRENT_INPUT * tokenAmount, {from:creator}); - await struct.erc20Table.processTokens(CURRENT_INPUT * tokenAmount / 100, CURRENT_INPUT * tokenAmount, {from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); + it('5: should not process multiplier: send LESS than minNeed', async () => { + var params = {token:token.address, CURRENT_INPUT:30900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:750000, dividends:250000} + + let struct = await createStructureTable(params, ERC20Table); + let splitterParams = await getSplitterParamsTable(struct, params); + await totalAndMinNeedsAssertsTable(splitterParams, params); + await structureAssertsTable(splitterParams); + + await token.approve(struct.table.address, params.CURRENT_INPUT * multiplier, {from:creator}); + await struct.table.processTokens(params.CURRENT_INPUT * multiplier / 100, params.CURRENT_INPUT * multiplier, {from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); + await token.approve(struct.table.address, params.CURRENT_INPUT * multiplier / 100, {from:creator}); + await struct.table.processTokens(params.CURRENT_INPUT * multiplier, params.CURRENT_INPUT * multiplier / 100, {from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); + await token.approve(struct.table.address, params.CURRENT_INPUT * multiplier, {from:creator}); + await struct.table.processTokens(params.CURRENT_INPUT * multiplier / 100, params.CURRENT_INPUT * multiplier, {from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); }); - it('6: should process tokenAmount with a scheme just like in the paper: 10/15 others, send MORE than minNeed; ', async () => { - const tokenAmount = 1e12; - const CURRENT_INPUT = 20900; - let e1 = 1000; - let e2 = 1500; - let e3 = 800; - let office = 500; - let internet = 300; - let t1 = 500; - let t2 = 300; - let t3 = 1000; - // 5900 -> 4% of 15000 -> - let b1 = 10000; - let b2 = 10000; - let b3 = 20000; - let reserve = 750000; - let dividends = 250000; - - let struct = await createStructure(token, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - let splitterParams = await getSplitterParams(tokenAmount, struct, CURRENT_INPUT, creator); - await totalAndMinNeedsAsserts(tokenAmount, splitterParams, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - await structureAsserts(splitterParams); - - await token.approve(struct.erc20Table.address, CURRENT_INPUT * tokenAmount, {from:creator}); - await struct.erc20Table.processTokens(CURRENT_INPUT * tokenAmount, CURRENT_INPUT * tokenAmount, {from: creator, gasPrice: 0 }); - - let balances = await getBalances(struct); - await balancesAsserts(tokenAmount, balances, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); + it('6: should process with a scheme just like in the paper: 10/15 others, send MORE than minNeed; ', async () => { + var params = {token:token.address, CURRENT_INPUT:20900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:750000, dividends:250000} + + let struct = await createStructureTable(params, ERC20Table); + let splitterParams = await getSplitterParamsTable(struct, params); + await totalAndMinNeedsAssertsTable(splitterParams, params); + await structureAssertsTable(splitterParams); + + await token.approve(struct.table.address, params.CURRENT_INPUT * multiplier, {from:creator}); + await struct.table.processTokens(params.CURRENT_INPUT * multiplier, params.CURRENT_INPUT * multiplier, {from: creator, gasPrice: 0 }); + + let balances = await getBalancesTable(struct); + await balancesAssertsTable(balances, params); }); - it('7: should process tokenAmount with a scheme just like in the paper: 10/15 others, send EQUAL to minNeed; ', async () => { - const tokenAmount = 1e12; - const CURRENT_INPUT = 5900; - let e1 = 1000; - let e2 = 1500; - let e3 = 800; - let office = 500; - let internet = 300; - let t1 = 500; - let t2 = 300; - let t3 = 1000; - let b1 = 10000; - let b2 = 10000; - let b3 = 20000; - let reserve = 750000; - let dividends = 250000; - - let struct = await createStructure(token, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - let splitterParams = await getSplitterParams(tokenAmount, struct, CURRENT_INPUT, creator); - await totalAndMinNeedsAsserts(tokenAmount, splitterParams, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - await structureAsserts(splitterParams); - - await token.approve(struct.erc20Table.address, CURRENT_INPUT * tokenAmount, {from:creator}); - await struct.erc20Table.processTokens(CURRENT_INPUT * tokenAmount, CURRENT_INPUT * tokenAmount, {from: creator, gasPrice: 0 }); - - let balances = await getBalances(struct); - await balancesAsserts(tokenAmount, balances, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, 0, 0, 0, 0, 0); + it('7: should process with a scheme just like in the paper: 10/15 others, send EQUAL to minNeed; ', async () => { + var params = {token:token.address, CURRENT_INPUT:5900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:750000, dividends:250000} + + let struct = await createStructureTable(params, ERC20Table); + let splitterParams = await getSplitterParamsTable(struct, params); + await totalAndMinNeedsAssertsTable(splitterParams, params); + await structureAssertsTable(splitterParams); + + await token.approve(struct.table.address, params.CURRENT_INPUT * multiplier, {from:creator}); + await struct.table.processTokens(params.CURRENT_INPUT * multiplier, params.CURRENT_INPUT * multiplier, {from: creator, gasPrice: 0 }); + + let balances = await getBalancesTable(struct); + await balancesAssertsTable(balances, params); }); - it('8: should not process tokenAmount: send LESS than minNeed; ', async () => { - const tokenAmount = 1e12; - const CURRENT_INPUT = 30900; - let e1 = 1000; - let e2 = 1500; - let e3 = 800; - let office = 500; - let internet = 300; - let t1 = 500; - let t2 = 300; - let t3 = 1000; - let b1 = 10000; - let b2 = 10000; - let b3 = 20000; - let reserve = 750000; - let dividends = 250000; - - let struct = await createStructure(token, tokenAmount, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - let splitterParams = await getSplitterParams(tokenAmount, struct, CURRENT_INPUT, creator); - await totalAndMinNeedsAsserts(tokenAmount, splitterParams, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - await structureAsserts(splitterParams); - - await token.approve(struct.erc20Table.address, CURRENT_INPUT * tokenAmount, {from:creator}); - await struct.erc20Table.processTokens(CURRENT_INPUT * tokenAmount / 100, CURRENT_INPUT * tokenAmount, {from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); - await token.approve(struct.erc20Table.address, CURRENT_INPUT * tokenAmount / 100, {from:creator}); - await struct.erc20Table.processTokens(CURRENT_INPUT * tokenAmount, CURRENT_INPUT * tokenAmount / 100, {from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); - await token.approve(struct.erc20Table.address, CURRENT_INPUT * tokenAmount, {from:creator}); - await struct.erc20Table.processTokens(CURRENT_INPUT * tokenAmount / 100, CURRENT_INPUT * tokenAmount, {from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); + it('8: should not process multiplier: send LESS than minNeed; ', async () => { + var params = {token:token.address, CURRENT_INPUT:30900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:750000, dividends:250000} + + let struct = await createStructureTable(params, ERC20Table); + let splitterParams = await getSplitterParamsTable(struct, params); + await totalAndMinNeedsAssertsTable(splitterParams, params); + await structureAssertsTable(splitterParams); + + await token.approve(struct.table.address, params.CURRENT_INPUT * multiplier, {from:creator}); + await struct.table.processTokens(params.CURRENT_INPUT * multiplier / 100, params.CURRENT_INPUT * multiplier, {from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); + await token.approve(struct.table.address, params.CURRENT_INPUT * multiplier / 100, {from:creator}); + await struct.table.processTokens(params.CURRENT_INPUT * multiplier, params.CURRENT_INPUT * multiplier / 100, {from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); + await token.approve(struct.table.address, params.CURRENT_INPUT * multiplier, {from:creator}); + await struct.table.processTokens(params.CURRENT_INPUT * multiplier / 100, params.CURRENT_INPUT * multiplier, {from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); }); - it('9: should process tokenAmount when opened and not process when closed with ERC20Splitter + 3 ERC20AbsoluteExpense', async () => { - let erc20Table = await ERC20Table.new(token.address); + it('9: should process when opened and not process when closed with ERC20Splitter + 3 ERC20AbsoluteExpense', async () => { + let table = await ERC20Table.new(token.address); - let splitterId = getEId(await erc20Table.addSplitter()); - let AbsoluteExpense1Id = getEId(await erc20Table.addAbsoluteExpense(tokenAmount, tokenAmount, isPeriodic, isAccumulateDebt, periodHours)); - let AbsoluteExpense2Id = getEId(await erc20Table.addAbsoluteExpense(2 * tokenAmount, 2 * tokenAmount, isPeriodic, isAccumulateDebt, periodHours)); - let AbsoluteExpense3Id = getEId(await erc20Table.addAbsoluteExpense(3 * tokenAmount, 3 * tokenAmount, isPeriodic, isAccumulateDebt, periodHours)); + let splitterId = getNodeId(await table.addSplitter()); + let AbsoluteExpense1Id = getNodeId(await table.addAbsoluteExpense(multiplier, multiplier, isPeriodic, isAccumulateDebt, periodHours)); + let AbsoluteExpense2Id = getNodeId(await table.addAbsoluteExpense(2 * multiplier, 2 * multiplier, isPeriodic, isAccumulateDebt, periodHours)); + let AbsoluteExpense3Id = getNodeId(await table.addAbsoluteExpense(3 * multiplier, 3 * multiplier, isPeriodic, isAccumulateDebt, periodHours)); // add 3 ERC20AbsoluteExpense outputs to the splitter - await erc20Table.addChildAt(splitterId, AbsoluteExpense1Id); - await erc20Table.addChildAt(splitterId, AbsoluteExpense2Id); - await erc20Table.addChildAt(splitterId, AbsoluteExpense3Id); - - var totalNeed = await erc20Table.getTotalNeeded(6 * tokenAmount); - assert.equal(totalNeed, 6 * tokenAmount); - var minNeed = await erc20Table.getMinNeeded(0);/*minNeedFix*/ - assert.equal(minNeed, 6 * tokenAmount); - - var isOpen1At = await erc20Table.isOpenAt(AbsoluteExpense1Id); - var isOpen2At = await erc20Table.isOpenAt(AbsoluteExpense2Id); - var isOpen3At = await erc20Table.isOpenAt(AbsoluteExpense3Id); + await table.addChildAt(splitterId, AbsoluteExpense1Id); + await table.addChildAt(splitterId, AbsoluteExpense2Id); + await table.addChildAt(splitterId, AbsoluteExpense3Id); + + var totalNeed = await table.getTotalNeeded(6 * multiplier); + assert.equal(totalNeed, 6 * multiplier); + var minNeed = await table.getMinNeeded(0);/*minNeedFix*/ + assert.equal(minNeed, 6 * multiplier); + + var isOpen1At = await table.isOpenAt(AbsoluteExpense1Id); + var isOpen2At = await table.isOpenAt(AbsoluteExpense2Id); + var isOpen3At = await table.isOpenAt(AbsoluteExpense3Id); assert.equal(isOpen1At, true); assert.equal(isOpen2At, true); assert.equal(isOpen3At, true); - await erc20Table.closeAt(AbsoluteExpense3Id); + await table.closeAt(AbsoluteExpense3Id); - var totalNeed = await erc20Table.getTotalNeeded(6 * tokenAmount); - assert.equal(totalNeed.toNumber(), 3 * tokenAmount); - var minNeed = await erc20Table.getMinNeeded(0);/*minNeedFix*/ - assert.equal(minNeed, 3 * tokenAmount); + var totalNeed = await table.getTotalNeeded(6 * multiplier); + assert.equal(totalNeed.toNumber(), 3 * multiplier); + var minNeed = await table.getMinNeeded(0);/*minNeedFix*/ + assert.equal(minNeed, 3 * multiplier); - await erc20Table.closeAt(AbsoluteExpense1Id); + await table.closeAt(AbsoluteExpense1Id); - var totalNeed = await erc20Table.getTotalNeeded(6 * tokenAmount); - assert.equal(totalNeed, 2 * tokenAmount); - var minNeed = await erc20Table.getMinNeeded(0);/*minNeedFix*/ - assert.equal(minNeed, 2 * tokenAmount); + var totalNeed = await table.getTotalNeeded(6 * multiplier); + assert.equal(totalNeed, 2 * multiplier); + var minNeed = await table.getMinNeeded(0);/*minNeedFix*/ + assert.equal(minNeed, 2 * multiplier); - var isOpen1At = await erc20Table.isOpenAt(AbsoluteExpense1Id); - var isOpen2At = await erc20Table.isOpenAt(AbsoluteExpense2Id); - var isOpen3At = await erc20Table.isOpenAt(AbsoluteExpense3Id); + var isOpen1At = await table.isOpenAt(AbsoluteExpense1Id); + var isOpen2At = await table.isOpenAt(AbsoluteExpense2Id); + var isOpen3At = await table.isOpenAt(AbsoluteExpense3Id); assert.equal(isOpen1At, false); assert.equal(isOpen2At, true); assert.equal(isOpen3At, false); - await erc20Table.openAt(AbsoluteExpense3Id); - var isOpen1At = await erc20Table.isOpenAt(AbsoluteExpense1Id); - var isOpen2At = await erc20Table.isOpenAt(AbsoluteExpense2Id); - var isOpen3At = await erc20Table.isOpenAt(AbsoluteExpense3Id); + await table.openAt(AbsoluteExpense3Id); + var isOpen1At = await table.isOpenAt(AbsoluteExpense1Id); + var isOpen2At = await table.isOpenAt(AbsoluteExpense2Id); + var isOpen3At = await table.isOpenAt(AbsoluteExpense3Id); assert.equal(isOpen1At, false); assert.equal(isOpen2At, true); assert.equal(isOpen3At, true); - // now send some tokenAmount to the revenue endpoint - await token.approve(erc20Table.address, 5 * tokenAmount, {from:creator}); - await erc20Table.processTokens(5 * tokenAmount, 5 * tokenAmount, {from: creator }); + // now send some to the revenue endpoint + await token.approve(table.address, 5 * multiplier, {from:creator}); + await table.processTokens(5 * multiplier, 5 * multiplier, {from: creator }); - // tokenAmount should end up in the outputs - var absoluteExpense1Balance = await erc20Table.balanceAt(AbsoluteExpense1Id); - assert.equal(absoluteExpense1Balance.toNumber(), 0 * tokenAmount, 'resource point received tokenAmount from splitter'); + // should end up in the outputs + var absoluteExpense1Balance = await table.balanceAt(AbsoluteExpense1Id); + assert.equal(absoluteExpense1Balance.toNumber(), 0 * multiplier, 'resource point received from splitter'); - var absoluteExpense2Balance = await erc20Table.balanceAt(AbsoluteExpense2Id); - assert.equal(absoluteExpense2Balance.toNumber(), 2 * tokenAmount, 'resource point received tokenAmount from splitter'); + var absoluteExpense2Balance = await table.balanceAt(AbsoluteExpense2Id); + assert.equal(absoluteExpense2Balance.toNumber(), 2 * multiplier, 'resource point received from splitter'); - var absoluteExpense3Balance = await erc20Table.balanceAt(AbsoluteExpense3Id); - assert.equal(absoluteExpense3Balance.toNumber(), 3 * tokenAmount, 'resource point received tokenAmount from splitter'); + var absoluteExpense3Balance = await table.balanceAt(AbsoluteExpense3Id); + assert.equal(absoluteExpense3Balance.toNumber(), 3 * multiplier, 'resource point received from splitter'); }); }); diff --git a/test/helpers/structures.js b/test/helpers/structures.js new file mode 100644 index 0000000..470712a --- /dev/null +++ b/test/helpers/structures.js @@ -0,0 +1,391 @@ +const {getNodeId} = require('../helpers/utils'); + +async function checkParamsCycle (targets, flowArr, minNeedArr, totalNeedArr, isNeedArr) { + for(var i=0; i o.logs.filter(l => l.event == 'NodeAdded')[0].args._eId.toNumber(); + +const BigNumber = web3.BigNumber; + +module.exports = { + passHours, + getNodeId +} \ No newline at end of file diff --git a/test/wei_tests/wei_expense.tests.js b/test/wei_tests/wei_expense.tests.js index a339727..38bb850 100644 --- a/test/wei_tests/wei_expense.tests.js +++ b/test/wei_tests/wei_expense.tests.js @@ -9,228 +9,20 @@ var WeiRelativeExpenseWithPeriod = artifacts.require('./WeiRelativeExpenseWithPe var WeiAbsoluteExpenseWithPeriodSliding = artifacts.require('./WeiAbsoluteExpenseWithPeriodSliding'); var WeiRelativeExpenseWithPeriodSliding = artifacts.require('./WeiRelativeExpenseWithPeriodSliding'); -async function passHours (hours) { - await web3.currentProvider.sendAsync({ - jsonrpc: '2.0', - method: 'evm_increaseTime', - params: [3600 * hours * 1000], - id: new Date().getTime(), - }, function (err) { if (err) console.log('err:', err); }); -} - - -async function checkMinNeed (targets, flowArr, needArr) { - for(var i=0; i { var token; - var store; - var daoBase; - - var issueTokens; - var manageGroups; - var addNewProposal; - var upgradeDaoContract; - var addNewTask; - var startTask; - var startBounty; - var modifyMoneyscheme; - var withdrawDonations; - var setRootWeiReceiver; - var burnTokens; - - var money = 1e14; + var multiplier = 1e14; const creator = accounts[0]; const employee1 = accounts[1]; @@ -246,93 +38,93 @@ contract('WeiExpense', (accounts) => { }); - it('should process money with WeiAbsoluteExpenseWithPeriod, then 25 hours, then money needs again', async () => { + it('should process with WeiAbsoluteExpenseWithPeriod, then 25 hours, then needs again', async () => { var timePeriod = 25; var callParams = { from: creator, gasPrice: 0 }; var struct = {}; var balance0 = await web3.eth.getBalance(creator); - Employee1 = await WeiAbsoluteExpenseWithPeriod.new(1000*money, 1000*money, timePeriod, callParams); + Employee1 = await WeiAbsoluteExpenseWithPeriod.new(1000*multiplier, 1000*multiplier, timePeriod, callParams); - await Employee1.processFunds(1000*money, { value: 1000*money, from: outsider, gasPrice: 0 }); + await Employee1.processFunds(1000*multiplier, { value: 1000*multiplier, from: outsider, gasPrice: 0 }); await Employee1.flush({ from: outsider }).should.be.rejectedWith('revert'); await Employee1.flush({ from: creator, gasPrice: 0 }); var balance = await web3.eth.getBalance(creator); - assert.equal(balance.toNumber() - balance0.toNumber(), 1000*money, 'Should get money'); + assert.equal(balance.toNumber() - balance0.toNumber(), 1000*multiplier, 'Should get amount'); var needsEmployee1 = await Employee1.isNeeds({ from: creator }); - assert.equal(needsEmployee1, false, 'Dont need money, because he got it'); + assert.equal(needsEmployee1, false, 'Dont need amount, because he got it'); await passHours(timePeriod); var needsEmployee2 = await Employee1.isNeeds({ from: creator }); - assert.equal(needsEmployee2, true, 'Need money, because 24 hours passed'); + assert.equal(needsEmployee2, true, 'Need amount, because 24 hours passed'); - var need = await Employee1.getTotalNeeded(10000*money); - assert.equal(need.toNumber(), 1000*money); + var need = await Employee1.getTotalNeeded(10000*multiplier); + assert.equal(need.toNumber(), 1000*multiplier); - var min = await Employee1.getMinNeeded(10000*money); - assert.equal(min.toNumber(), 1000*money); + var min = await Employee1.getMinNeeded(10000*multiplier); + assert.equal(min.toNumber(), 1000*multiplier); - await Employee1.processFunds(1000*money, { value: 1000*money, from: outsider, gasPrice: 0 }); + await Employee1.processFunds(1000*multiplier, { value: 1000*multiplier, from: outsider, gasPrice: 0 }); await Employee1.flush({ from: creator, gasPrice: 0 }); var balance2 = await web3.eth.getBalance(creator); - assert.equal(balance2.toNumber() - balance0.toNumber(), 2000*money, 'Should get money'); + assert.equal(balance2.toNumber() - balance0.toNumber(), 2000*multiplier, 'Should get amount'); var needsEmployee3 = await Employee1.isNeeds({ from: creator }); - assert.equal(needsEmployee3, false, 'Dont need money, because he got it'); + assert.equal(needsEmployee3, false, 'Dont need amount, because he got it'); }); - it('should process money with WeiAbsoluteExpenseWithPeriod, then 75 hours, then money needs again x3', async () => { + it('should process with WeiAbsoluteExpenseWithPeriod, then 75 hours, then needs again x3', async () => { var timePeriod = 25; var callParams = { from: creator, gasPrice: 0 }; var struct = {}; var balance0 = await web3.eth.getBalance(creator); - Employee1 = await WeiAbsoluteExpenseWithPeriodSliding.new(1000*money, 1000*money, timePeriod, callParams); + Employee1 = await WeiAbsoluteExpenseWithPeriodSliding.new(1000*multiplier, 1000*multiplier, timePeriod, callParams); - await Employee1.processFunds(1000*money, { value: 1000*money, from: outsider, gasPrice: 0 }); + await Employee1.processFunds(1000*multiplier, { value: 1000*multiplier, from: outsider, gasPrice: 0 }); await Employee1.flush({ from: outsider }).should.be.rejectedWith('revert'); await Employee1.flush({ from: creator, gasPrice: 0 }); var balance = await web3.eth.getBalance(creator); - assert.equal(balance.toNumber() - balance0.toNumber(), 1000*money, 'Should get money'); + assert.equal(balance.toNumber() - balance0.toNumber(), 1000*multiplier, 'Should get amount'); - // var needsEmployee1 = await Employee1.isNeeds({ from: creator }); - // assert.equal(needsEmployee1, false, 'Dont need money, because he got it'); - // var need = await Employee1.getTotalNeeded(10000*money); - // assert.equal(need.toNumber(), 0); + var needsEmployee1 = await Employee1.isNeeds({ from: creator }); + assert.equal(needsEmployee1, false, 'Dont need amount, because he got it'); + var need = await Employee1.getTotalNeeded(10000*multiplier); + assert.equal(need.toNumber(), 0); - // await passHours(1*timePeriod); - // var need = await Employee1.getTotalNeeded(10000*money); - // assert.equal(need.toNumber(), 1000*money); + await passHours(1*timePeriod); + var need = await Employee1.getTotalNeeded(10000*multiplier); + assert.equal(need.toNumber(), 1000*multiplier); - // await passHours(1*timePeriod); - // var need = await Employee1.getTotalNeeded(10000*money); - // assert.equal(need.toNumber(), 2000*money); + await passHours(1*timePeriod); + var need = await Employee1.getTotalNeeded(10000*multiplier); + assert.equal(need.toNumber(), 2000*multiplier); - // await passHours(1*timePeriod); - // var need = await Employee1.getTotalNeeded(10000*money); - // assert.equal(need.toNumber(), 3000*money); + await passHours(1*timePeriod); + var need = await Employee1.getTotalNeeded(10000*multiplier); + assert.equal(need.toNumber(), 3000*multiplier); - // var needsEmployee2 = await Employee1.isNeeds({ from: creator }); - // assert.equal(needsEmployee2, true, 'Need money, because 24 hours passed'); + var needsEmployee2 = await Employee1.isNeeds({ from: creator }); + assert.equal(needsEmployee2, true, 'Need amount, because 24 hours passed'); - // await Employee1.processFunds(4000*money, { value: 4000*money, from: outsider, gasPrice: 0 }).should.be.rejectedWith('revert'); - // await Employee1.processFunds(2000*money, { value: 2000*money, from: outsider, gasPrice: 0 }).should.be.rejectedWith('revert'); + await Employee1.processFunds(4000*multiplier, { value: 4000*multiplier, from: outsider, gasPrice: 0 }).should.be.rejectedWith('revert'); + await Employee1.processFunds(2000*multiplier, { value: 2000*multiplier, from: outsider, gasPrice: 0 }).should.be.rejectedWith('revert'); - // await Employee1.processFunds(3000*money, { value: 3000*money, from: outsider, gasPrice: 0 }); - // await Employee1.flush({ from: creator, gasPrice: 0 }); + await Employee1.processFunds(3000*multiplier, { value: 3000*multiplier, from: outsider, gasPrice: 0 }); + await Employee1.flush({ from: creator, gasPrice: 0 }); - // var balance2 = await web3.eth.getBalance(creator); - // assert.equal(balance2.toNumber() - balance0.toNumber(), 4000*money, 'Should get money'); + var balance2 = await web3.eth.getBalance(creator); + assert.equal(balance2.toNumber() - balance0.toNumber(), 4000*multiplier, 'Should get amount'); - // var needsEmployee3 = await Employee1.isNeeds({ from: creator }); - // assert.equal(needsEmployee3, false, 'Dont need money, because he got it'); + var needsEmployee3 = await Employee1.isNeeds({ from: creator }); + assert.equal(needsEmployee3, false, 'Dont need amount, because he got it'); }); - it('Splitter should access money then close then not accept', async () => { + it('Splitter should access then close then not accept', async () => { var callParams = { from: creator, gasPrice: 0 }; var balance0 = await web3.eth.getBalance(creator); @@ -342,457 +134,281 @@ contract('WeiExpense', (accounts) => { await Splitter.addChild(tax.address, callParams); var need1 = await Splitter.isNeeds({ from: creator }); - var totalNeed1 = await Splitter.getTotalNeeded(1000*money); - assert.equal(need1, true, 'should need money'); - assert.equal(totalNeed1.toNumber(), 1000*money, 'should be 10% of 1000 money'); + var totalNeed1 = await Splitter.getTotalNeeded(1000*multiplier); + assert.equal(need1, true, 'should need amount'); + assert.equal(totalNeed1.toNumber(), 1000*multiplier, 'should be 10% of 1000 amount'); await Splitter.close(callParams); var need3 = await Splitter.isNeeds({ from: creator }); - var totalNeed3 = await Splitter.getTotalNeeded(1000*money); - assert.equal(need3, false, 'should not need money'); - assert.equal(totalNeed3.toNumber(), 0, 'should be 0 money'); + var totalNeed3 = await Splitter.getTotalNeeded(1000*multiplier); + assert.equal(need3, false, 'should not need amount'); + assert.equal(totalNeed3.toNumber(), 0, 'should be 0 amount'); - await Splitter.processFunds(1000*money, { value: 1000*money, from: outsider, gasPrice: 0 }).should.be.rejectedWith('revert'); + await Splitter.processFunds(1000*multiplier, { value: 1000*multiplier, from: outsider, gasPrice: 0 }).should.be.rejectedWith('revert'); await Splitter.open(callParams); var need3 = await Splitter.isNeeds({ from: creator }); - var totalNeed3 = await Splitter.getTotalNeeded(1000*money); - assert.equal(need3, true, 'should not need money'); - assert.equal(totalNeed3.toNumber(), 1000*money, 'should be 0 money'); + var totalNeed3 = await Splitter.getTotalNeeded(1000*multiplier); + assert.equal(need3, true, 'should not need amount'); + assert.equal(totalNeed3.toNumber(), 1000*multiplier, 'should be 0 amount'); - await Splitter.processFunds(1000*money, { value: 1000*money, from: outsider, gasPrice: 0 }) + await Splitter.processFunds(1000*multiplier, { value: 1000*multiplier, from: outsider, gasPrice: 0 }) var taxBalance = await web3.eth.getBalance(tax.address); - assert.equal(taxBalance.toNumber(), 1000*money, 'Tax receiver should get 100 money'); - + assert.equal(taxBalance.toNumber(), 1000*multiplier, 'Tax receiver should get 100 amount'); }); - it('should process money with WeiSplitter + 3 WeiAbsoluteExpense', async () => { + it('should process with WeiSplitter + 3 WeiAbsoluteExpense', async () => { // create WeiSplitter var weiTopDownSplitter = await WeiSplitter.new(); - var weiAbsoluteExpense1 = await WeiAbsoluteExpense.new(1*money, 1*money, { from: creator, gasPrice: 0 }); - var weiAbsoluteExpense2 = await WeiAbsoluteExpense.new(2*money, 2*money, { from: creator, gasPrice: 0 }); - var weiAbsoluteExpense3 = await WeiAbsoluteExpense.new(3*money, 3*money, { from: creator, gasPrice: 0 }); + var weiAbsoluteExpense1 = await WeiAbsoluteExpense.new(1*multiplier, 1*multiplier, { from: creator, gasPrice: 0 }); + var weiAbsoluteExpense2 = await WeiAbsoluteExpense.new(2*multiplier, 2*multiplier, { from: creator, gasPrice: 0 }); + var weiAbsoluteExpense3 = await WeiAbsoluteExpense.new(3*multiplier, 3*multiplier, { from: creator, gasPrice: 0 }); // // add 3 WeiAbsoluteExpense outputs to the splitter await weiTopDownSplitter.addChild(weiAbsoluteExpense1.address); await weiTopDownSplitter.addChild(weiAbsoluteExpense2.address); await weiTopDownSplitter.addChild(weiAbsoluteExpense3.address); - // now send some money to the revenue endpoint - await weiTopDownSplitter.processFunds(6*money, { value: 6*money, from: creator }); + // now send some to the revenue endpoint + await weiTopDownSplitter.processFunds(6*multiplier, { value: 6*multiplier, from: creator }); - // money should end up in the outputs + // should end up in the outputs var weiAbsoluteExpense1Balance = await web3.eth.getBalance(weiAbsoluteExpense1.address); - assert.equal(weiAbsoluteExpense1Balance.toNumber(), 1*money, 'resource point received money from splitter'); + assert.equal(weiAbsoluteExpense1Balance.toNumber(), 1*multiplier, 'resource point received from splitter'); var weiAbsoluteExpense2Balance = await web3.eth.getBalance(weiAbsoluteExpense2.address); - assert.equal(weiAbsoluteExpense2Balance.toNumber(), 2*money, 'resource point received money from splitter'); + assert.equal(weiAbsoluteExpense2Balance.toNumber(), 2*multiplier, 'resource point received from splitter'); var weiAbsoluteExpense3Balance = await web3.eth.getBalance(weiAbsoluteExpense3.address); - assert.equal(weiAbsoluteExpense3Balance.toNumber(), 3*money, 'resource point received money from splitter'); + assert.equal(weiAbsoluteExpense3Balance.toNumber(), 3*multiplier, 'resource point received from splitter'); }); - it('should process money with WeiSplitter + 3 WeiAbsoluteExpense', async () => { + it('should process with WeiSplitter + 3 WeiAbsoluteExpense', async () => { // create WeiSplitter var weiUnsortedSplitter = await WeiSplitter.new(); - var weiAbsoluteExpense1 = await WeiAbsoluteExpense.new(1*money, 1*money, { from: creator, gasPrice: 0 }); - var weiAbsoluteExpense2 = await WeiAbsoluteExpense.new(2*money, 2*money, { from: creator, gasPrice: 0 }); - var weiAbsoluteExpense3 = await WeiAbsoluteExpense.new(3*money, 3*money, { from: creator, gasPrice: 0 }); + var weiAbsoluteExpense1 = await WeiAbsoluteExpense.new(1*multiplier, 1*multiplier, { from: creator, gasPrice: 0 }); + var weiAbsoluteExpense2 = await WeiAbsoluteExpense.new(2*multiplier, 2*multiplier, { from: creator, gasPrice: 0 }); + var weiAbsoluteExpense3 = await WeiAbsoluteExpense.new(3*multiplier, 3*multiplier, { from: creator, gasPrice: 0 }); // // add 3 WeiAbsoluteExpense outputs to the splitter await weiUnsortedSplitter.addChild(weiAbsoluteExpense1.address); await weiUnsortedSplitter.addChild(weiAbsoluteExpense2.address); await weiUnsortedSplitter.addChild(weiAbsoluteExpense3.address); - // now send some money to the revenue endpoint - await weiUnsortedSplitter.processFunds(6*money, { value: 6*money, from: creator }); + // now send some to the revenue endpoint + await weiUnsortedSplitter.processFunds(6*multiplier, { value: 6*multiplier, from: creator }); - // money should end up in the outputs + // should end up in the outputs var weiAbsoluteExpense1Balance = await web3.eth.getBalance(weiAbsoluteExpense1.address); - assert.equal(weiAbsoluteExpense1Balance.toNumber(), 1*money, 'resource point received money from splitter'); + assert.equal(weiAbsoluteExpense1Balance.toNumber(), 1*multiplier, 'resource point received from splitter'); var weiAbsoluteExpense2Balance = await web3.eth.getBalance(weiAbsoluteExpense2.address); - assert.equal(weiAbsoluteExpense2Balance.toNumber(), 2*money, 'resource point received money from splitter'); + assert.equal(weiAbsoluteExpense2Balance.toNumber(), 2*multiplier, 'resource point received from splitter'); var weiAbsoluteExpense3Balance = await web3.eth.getBalance(weiAbsoluteExpense3.address); - assert.equal(weiAbsoluteExpense3Balance.toNumber(), 3*money, 'resource point received money from splitter'); + assert.equal(weiAbsoluteExpense3Balance.toNumber(), 3*multiplier, 'resource point received from splitter'); }); - it('should process money in structure o-> o-> o-o-o', async () => { - var AllOutpults = await WeiSplitter.new({ from: creator, gasPrice: 0 }); + it('should process in structure o-> o-> o-o-o', async () => { + var AllOutputs = await WeiSplitter.new({ from: creator, gasPrice: 0 }); var Salaries = await WeiSplitter.new({ from: creator, gasPrice: 0 }); - var Employee1 = await WeiAbsoluteExpense.new(1000*money, 1000*money, { from: creator, gasPrice: 0 }); - var Employee2 = await WeiAbsoluteExpense.new(1500*money, 1500*money, { from: creator, gasPrice: 0 }); - var Employee3 = await WeiAbsoluteExpense.new(800*money, 800*money, { from: creator, gasPrice: 0 }); + var Employee1 = await WeiAbsoluteExpense.new(1000*multiplier, 1000*multiplier, { from: creator, gasPrice: 0 }); + var Employee2 = await WeiAbsoluteExpense.new(1500*multiplier, 1500*multiplier, { from: creator, gasPrice: 0 }); + var Employee3 = await WeiAbsoluteExpense.new(800*multiplier, 800*multiplier, { from: creator, gasPrice: 0 }); - await AllOutpults.addChild(Salaries.address, { from: creator, gasPrice: 0 }); + await AllOutputs.addChild(Salaries.address, { from: creator, gasPrice: 0 }); await Salaries.addChild(Employee1.address, { from: creator, gasPrice: 0 }); await Salaries.addChild(Employee2.address, { from: creator, gasPrice: 0 }); await Salaries.addChild(Employee3.address, { from: creator, gasPrice: 0 }); - var Employee1Needs = await Employee1.getTotalNeeded(3300*money); - assert.equal(Employee1Needs.toNumber() / money, 1000, 'Employee1 Needs 1000 money'); - var Employee2Needs = await Employee2.getTotalNeeded(3300*money); - assert.equal(Employee2Needs.toNumber() / money, 1500, 'Employee1 Needs 1500 money'); - var Employee3Needs = await Employee3.getTotalNeeded(3300*money); - assert.equal(Employee3Needs.toNumber() / money, 800, 'Employee1 Needs 800 money'); + var Employee1Needs = await Employee1.getTotalNeeded(3300*multiplier); + assert.equal(Employee1Needs.toNumber() / multiplier, 1000, 'Employee1 Needs 1000 amount'); + var Employee2Needs = await Employee2.getTotalNeeded(3300*multiplier); + assert.equal(Employee2Needs.toNumber() / multiplier, 1500, 'Employee1 Needs 1500 amount'); + var Employee3Needs = await Employee3.getTotalNeeded(3300*multiplier); + assert.equal(Employee3Needs.toNumber() / multiplier, 800, 'Employee1 Needs 800 amount'); - var SalariesNeeds = await Salaries.getTotalNeeded(3300*money); - assert.equal(SalariesNeeds.toNumber() / money, 3300, 'Salaries Needs 3300 money'); + var SalariesNeeds = await Salaries.getTotalNeeded(3300*multiplier); + assert.equal(SalariesNeeds.toNumber() / multiplier, 3300, 'Salaries Needs 3300 amount'); - var SalariesMinNeeds = await Salaries.getMinNeeded(3300*money); - assert.equal(SalariesNeeds.toNumber() / money, 3300, 'Salaries min Needs 3300 money'); + var SalariesMinNeeds = await Salaries.getMinNeeded(3300*multiplier); + assert.equal(SalariesNeeds.toNumber() / multiplier, 3300, 'Salaries min Needs 3300 amount'); - var AllOutpultsNeeds = await AllOutpults.getTotalNeeded(3300*money); - assert.equal(AllOutpultsNeeds.toNumber() / money, 3300, 'AllOutpults Needs 3300 money'); - var MinOutpultsNeeds = await AllOutpults.getMinNeeded(3300*money); - assert.equal(AllOutpultsNeeds.toNumber() / money, 3300, 'AllOutpults Needs min 3300 money'); - var OutputChildrenCount = await AllOutpults.getChildrenCount(); + var AllOutputsNeeds = await AllOutputs.getTotalNeeded(3300*multiplier); + assert.equal(AllOutputsNeeds.toNumber() / multiplier, 3300, 'AllOutputs Needs 3300 amount'); + var MinOutpultsNeeds = await AllOutputs.getMinNeeded(3300*multiplier); + assert.equal(AllOutputsNeeds.toNumber() / multiplier, 3300, 'AllOutputs Needs min 3300 amount'); + var OutputChildrenCount = await AllOutputs.getChildrenCount(); assert.equal(OutputChildrenCount.toNumber(), 1, 'OutputChildrenCount should be 1'); var SalariesChildrenCount = await Salaries.getChildrenCount(); assert.equal(SalariesChildrenCount.toNumber(), 3, 'SalariesChildrenCount should be 3'); - var th = await Salaries.processFunds(3300*money, { value: 3300*money, from: creator, gasPrice: 0 }); + var th = await Salaries.processFunds(3300*multiplier, { value: 3300*multiplier, from: creator, gasPrice: 0 }); }); - it('should process money in structure o-> o-o-o, while minAmount != totalAmount', async () => { + it('should process in structure o-> o-o-o, while minAmount != totalAmount', async () => { var Salaries = await WeiSplitter.new({ from: creator, gasPrice: 0 }); - var Employee1 = await WeiAbsoluteExpense.new(1000*money, 500*money, { from: creator, gasPrice: 0 }); - var Employee2 = await WeiAbsoluteExpense.new(800*money, 200*money, { from: creator, gasPrice: 0 }); - var Employee3 = await WeiAbsoluteExpense.new(1500*money, 500*money, { from: creator, gasPrice: 0 }); + var Employee1 = await WeiAbsoluteExpense.new(1000*multiplier, 500*multiplier, { from: creator, gasPrice: 0 }); + var Employee2 = await WeiAbsoluteExpense.new(800*multiplier, 200*multiplier, { from: creator, gasPrice: 0 }); + var Employee3 = await WeiAbsoluteExpense.new(1500*multiplier, 500*multiplier, { from: creator, gasPrice: 0 }); await Salaries.addChild(Employee1.address, { from: creator, gasPrice: 0 }); await Salaries.addChild(Employee2.address, { from: creator, gasPrice: 0 }); await Salaries.addChild(Employee3.address, { from: creator, gasPrice: 0 }); - var Employee1Needs = await Employee1.getTotalNeeded(3300*money); - assert.equal(Employee1Needs.toNumber() / money, 1000); - var Employee2Needs = await Employee2.getTotalNeeded(3300*money); - assert.equal(Employee2Needs.toNumber() / money, 800); - var Employee3Needs = await Employee3.getTotalNeeded(3300*money); - assert.equal(Employee3Needs.toNumber() / money, 1500); - - var SalariesNeeds = await Salaries.getTotalNeeded(3300*money); - assert.equal(SalariesNeeds.toNumber() / money, 3300, 'Salaries Needs 3300 money'); - - assert.equal((await Salaries.getMinNeeded(100*money)).toNumber() / money, 0); - assert.equal((await Salaries.getMinNeeded(200*money)).toNumber() / money, 200); - assert.equal((await Salaries.getMinNeeded(300*money)).toNumber() / money, 200); - assert.equal((await Salaries.getMinNeeded(400*money)).toNumber() / money, 400); - assert.equal((await Salaries.getMinNeeded(500*money)).toNumber() / money, 500); - assert.equal((await Salaries.getMinNeeded(600*money)).toNumber() / money, 500); - assert.equal((await Salaries.getMinNeeded(700*money)).toNumber() / money, 700); - assert.equal((await Salaries.getMinNeeded(800*money)).toNumber() / money, 700); - assert.equal((await Salaries.getMinNeeded(900*money)).toNumber() / money, 900); - assert.equal((await Salaries.getMinNeeded(1000*money)).toNumber() / money, 1000); - assert.equal((await Salaries.getMinNeeded(1100*money)).toNumber() / money, 1000); - assert.equal((await Salaries.getMinNeeded(1200*money)).toNumber() / money, 1200); - assert.equal((await Salaries.getMinNeeded(1300*money)).toNumber() / money, 1200); - assert.equal((await Salaries.getMinNeeded(1400*money)).toNumber() / money, 1400); - assert.equal((await Salaries.getMinNeeded(1500*money)).toNumber() / money, 1400); - assert.equal((await Salaries.getMinNeeded(1600*money)).toNumber() / money, 1600); - assert.equal((await Salaries.getMinNeeded(1700*money)).toNumber() / money, 1600); - assert.equal((await Salaries.getMinNeeded(1800*money)).toNumber() / money, 1800); - assert.equal((await Salaries.getMinNeeded(1900*money)).toNumber() / money, 1800); - assert.equal((await Salaries.getMinNeeded(2000*money)).toNumber() / money, 1800); - assert.equal((await Salaries.getMinNeeded(2100*money)).toNumber() / money, 1800); - assert.equal((await Salaries.getMinNeeded(2200*money)).toNumber() / money, 1800); - assert.equal((await Salaries.getMinNeeded(2300*money)).toNumber() / money, 2300); - assert.equal((await Salaries.getMinNeeded(2400*money)).toNumber() / money, 2300); - assert.equal((await Salaries.getMinNeeded(2500*money)).toNumber() / money, 2300); - assert.equal((await Salaries.getMinNeeded(2600*money)).toNumber() / money, 2300); - assert.equal((await Salaries.getMinNeeded(2700*money)).toNumber() / money, 2300); - assert.equal((await Salaries.getMinNeeded(2800*money)).toNumber() / money, 2800); - assert.equal((await Salaries.getMinNeeded(2900*money)).toNumber() / money, 2800); - assert.equal((await Salaries.getMinNeeded(3000*money)).toNumber() / money, 2800); - assert.equal((await Salaries.getMinNeeded(3100*money)).toNumber() / money, 2800); - assert.equal((await Salaries.getMinNeeded(3200*money)).toNumber() / money, 2800); - assert.equal((await Salaries.getMinNeeded(3300*money)).toNumber() / money, 3300); - assert.equal((await Salaries.getMinNeeded(3400*money)).toNumber() / money, 3300); - assert.equal((await Salaries.getMinNeeded(3500*money)).toNumber() / money, 3300); - - var th = await Salaries.processFunds(700*money, { value:700*money, from: creator, gasPrice: 0 }); - - assert.equal((await Salaries.getMinNeeded(100*money)).toNumber() / money, 0); - assert.equal((await Salaries.getMinNeeded(200*money)).toNumber() / money, 200); - assert.equal((await Salaries.getMinNeeded(300*money)).toNumber() / money, 200); - assert.equal((await Salaries.getMinNeeded(400*money)).toNumber() / money, 400); - assert.equal((await Salaries.getMinNeeded(500*money)).toNumber() / money, 500); - assert.equal((await Salaries.getMinNeeded(600*money)).toNumber() / money, 500); - assert.equal((await Salaries.getMinNeeded(700*money)).toNumber() / money, 700); - assert.equal((await Salaries.getMinNeeded(800*money)).toNumber() / money, 700); - assert.equal((await Salaries.getMinNeeded(900*money)).toNumber() / money, 900); - assert.equal((await Salaries.getMinNeeded(1000*money)).toNumber() / money, 900); - assert.equal((await Salaries.getMinNeeded(1100*money)).toNumber() / money, 1100); - assert.equal((await Salaries.getMinNeeded(1200*money)).toNumber() / money, 1100); - assert.equal((await Salaries.getMinNeeded(1300*money)).toNumber() / money, 1100); - assert.equal((await Salaries.getMinNeeded(1400*money)).toNumber() / money, 1100); - assert.equal((await Salaries.getMinNeeded(1500*money)).toNumber() / money, 1100); - assert.equal((await Salaries.getMinNeeded(1600*money)).toNumber() / money, 1600); - assert.equal((await Salaries.getMinNeeded(1700*money)).toNumber() / money, 1600); - assert.equal((await Salaries.getMinNeeded(1800*money)).toNumber() / money, 1600); - assert.equal((await Salaries.getMinNeeded(1900*money)).toNumber() / money, 1600); - assert.equal((await Salaries.getMinNeeded(2000*money)).toNumber() / money, 1600); - assert.equal((await Salaries.getMinNeeded(2100*money)).toNumber() / money, 2100); - assert.equal((await Salaries.getMinNeeded(2200*money)).toNumber() / money, 2100); - assert.equal((await Salaries.getMinNeeded(2300*money)).toNumber() / money, 2100); - assert.equal((await Salaries.getMinNeeded(2400*money)).toNumber() / money, 2100); - assert.equal((await Salaries.getMinNeeded(2500*money)).toNumber() / money, 2100); - assert.equal((await Salaries.getMinNeeded(2600*money)).toNumber() / money, 2600); - assert.equal((await Salaries.getMinNeeded(2700*money)).toNumber() / money, 2600); - assert.equal((await Salaries.getMinNeeded(2800*money)).toNumber() / money, 2600); - assert.equal((await Salaries.getMinNeeded(2900*money)).toNumber() / money, 2600); - assert.equal((await Salaries.getMinNeeded(3000*money)).toNumber() / money, 2600); - assert.equal((await Salaries.getMinNeeded(3100*money)).toNumber() / money, 2600); - assert.equal((await Salaries.getMinNeeded(3200*money)).toNumber() / money, 2600); - assert.equal((await Salaries.getMinNeeded(3300*money)).toNumber() / money, 2600); - assert.equal((await Salaries.getMinNeeded(3400*money)).toNumber() / money, 2600); - assert.equal((await Salaries.getMinNeeded(3500*money)).toNumber() / money, 2600); - - var th = await Salaries.processFunds(900*money, { value:900*money, from: creator, gasPrice: 0 }); - - assert.equal((await Salaries.getMinNeeded(100*money)).toNumber() / money, 0); - assert.equal((await Salaries.getMinNeeded(200*money)).toNumber() / money, 200); - assert.equal((await Salaries.getMinNeeded(300*money)).toNumber() / money, 200); - assert.equal((await Salaries.getMinNeeded(400*money)).toNumber() / money, 200); - assert.equal((await Salaries.getMinNeeded(500*money)).toNumber() / money, 200); - assert.equal((await Salaries.getMinNeeded(600*money)).toNumber() / money, 200); - assert.equal((await Salaries.getMinNeeded(700*money)).toNumber() / money, 700); - assert.equal((await Salaries.getMinNeeded(800*money)).toNumber() / money, 700); - assert.equal((await Salaries.getMinNeeded(900*money)).toNumber() / money, 700); - assert.equal((await Salaries.getMinNeeded(1000*money)).toNumber() / money, 700); - assert.equal((await Salaries.getMinNeeded(1100*money)).toNumber() / money, 700); - assert.equal((await Salaries.getMinNeeded(1200*money)).toNumber() / money, 1200); - assert.equal((await Salaries.getMinNeeded(1300*money)).toNumber() / money, 1200); - assert.equal((await Salaries.getMinNeeded(1400*money)).toNumber() / money, 1200); - assert.equal((await Salaries.getMinNeeded(1500*money)).toNumber() / money, 1200); - assert.equal((await Salaries.getMinNeeded(1600*money)).toNumber() / money, 1200); - assert.equal((await Salaries.getMinNeeded(1700*money)).toNumber() / money, 1700); - assert.equal((await Salaries.getMinNeeded(1800*money)).toNumber() / money, 1700); - assert.equal((await Salaries.getMinNeeded(1900*money)).toNumber() / money, 1700); - assert.equal((await Salaries.getMinNeeded(2000*money)).toNumber() / money, 1700); - assert.equal((await Salaries.getMinNeeded(2100*money)).toNumber() / money, 1700); - assert.equal((await Salaries.getMinNeeded(2200*money)).toNumber() / money, 1700); - assert.equal((await Salaries.getMinNeeded(2300*money)).toNumber() / money, 1700); - assert.equal((await Salaries.getMinNeeded(2400*money)).toNumber() / money, 1700); - assert.equal((await Salaries.getMinNeeded(2500*money)).toNumber() / money, 1700); - assert.equal((await Salaries.getMinNeeded(2600*money)).toNumber() / money, 1700); - assert.equal((await Salaries.getMinNeeded(2700*money)).toNumber() / money, 1700); - assert.equal((await Salaries.getMinNeeded(2800*money)).toNumber() / money, 1700); - assert.equal((await Salaries.getMinNeeded(2900*money)).toNumber() / money, 1700); - assert.equal((await Salaries.getMinNeeded(3000*money)).toNumber() / money, 1700); - assert.equal((await Salaries.getMinNeeded(3100*money)).toNumber() / money, 1700); - assert.equal((await Salaries.getMinNeeded(3200*money)).toNumber() / money, 1700); - assert.equal((await Salaries.getMinNeeded(3300*money)).toNumber() / money, 1700); - assert.equal((await Salaries.getMinNeeded(3400*money)).toNumber() / money, 1700); - assert.equal((await Salaries.getMinNeeded(3500*money)).toNumber() / money, 1700); - - var th = await Salaries.processFunds(200*money, { value:200*money, from: creator, gasPrice: 0 }); - - var th = await Salaries.processFunds(1500*money, { value:1500*money, from: creator, gasPrice: 0 }); - - var th = await Salaries.processFunds(200*money, { value:200*money, from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); + var Employee1Needs = await Employee1.getTotalNeeded(3300*multiplier); + assert.equal(Employee1Needs.toNumber() / multiplier, 1000); + var Employee2Needs = await Employee2.getTotalNeeded(3300*multiplier); + assert.equal(Employee2Needs.toNumber() / multiplier, 800); + var Employee3Needs = await Employee3.getTotalNeeded(3300*multiplier); + assert.equal(Employee3Needs.toNumber() / multiplier, 1500); + + var SalariesNeeds = await Salaries.getTotalNeeded(3300*multiplier); + assert.equal(SalariesNeeds.toNumber() / multiplier, 3300, 'Salaries Needs 3300 amount'); + await checkNeededArrs(Salaries, multiplier, + [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500], + [0, 200, 200, 400, 500, 500, 700, 700, 900, 1000, 1000, 1200, 1200, 1400, 1400, 1600, 1600, 1800, 1800, 1800, 1800, 1800, 2300, 2300, 2300, 2300, 2300, 2800, 2800, 2800, 2800, 2800, 3300, 3300, 3300] + ); + + var th = await Salaries.processFunds(700*multiplier, { value:700*multiplier, from: creator, gasPrice: 0 }); + await checkNeededArrs(Salaries, multiplier, + [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500], + [0, 200, 200, 400, 500, 500, 700, 700, 900, 900, 1100, 1100, 1100, 1100, 1100, 1600, 1600, 1600, 1600, 1600, 2100, 2100, 2100, 2100, 2100, 2600, 2600, 2600, 2600, 2600, 2600, 2600, 2600, 2600, 2600] + ); + + var th = await Salaries.processFunds(900*multiplier, { value:900*multiplier, from: creator, gasPrice: 0 }); + await checkNeededArrs(Salaries, multiplier, + [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500], + [0, 200, 200, 200, 200, 200, 700, 700, 700, 700, 700, 1200, 1200, 1200, 1200, 1200, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700] + ) + + var th = await Salaries.processFunds(200*multiplier, { value:200*multiplier, from: creator, gasPrice: 0 }); + var th = await Salaries.processFunds(1500*multiplier, { value:1500*multiplier, from: creator, gasPrice: 0 }); + var th = await Salaries.processFunds(200*multiplier, { value:200*multiplier, from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); }); - it('should process money with a scheme just like in the paper: 75/25 others, send MORE than minNeed; ', async () => { - const CURRENT_INPUT = 30900; - var e1 = 1000; - var e2 = 1500; - var e3 = 800; - var office = 500; - var internet = 300; - var t1 = 500; - var t2 = 300; - var t3 = 1000; - var b1 = 10000; - var b2 = 10000; - var b3 = 20000; - var reserve = 750000; - var dividends = 250000; - - var struct = await createStructure(creator, money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - - var splitterParams = await getSplitterParams(struct, CURRENT_INPUT, money, creator); - - await totalAndMinNeedsAsserts(splitterParams, CURRENT_INPUT, money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); + it('should process with a scheme just like in the paper: 75/25 others, send MORE than minNeed; ', async () => { + var params = {CURRENT_INPUT:30900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:750000, dividends:250000} + + var struct = await createStructure(params, WeiAbsoluteExpense, WeiRelativeExpense, WeiSplitter); + + var splitterParams = await getSplitterParams(struct, params); + + await totalAndMinNeedsAsserts(splitterParams, params); await structureAsserts(splitterParams); - await struct.AllOutpults.processFunds(CURRENT_INPUT*money, { value: CURRENT_INPUT*money, from: creator, gasPrice: 0 }); + await struct.AllOutputs.processFunds(params.CURRENT_INPUT*multiplier, { value: params.CURRENT_INPUT*multiplier, from: creator, gasPrice: 0 }); - var balances = await getBalances(struct); - await balancesAsserts(balances, CURRENT_INPUT, money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - await splitterBalancesAsserts(balances, money, 0, 0, 0, 0, 0, 0, 0); + var balances = await getBalances(struct, web3.eth.getBalance); + await balancesAsserts(balances, params); + await splitterBalancesAsserts(balances); }); - it('should process money with a scheme just like in the paper: 75/25 others, send EQUAL to minNeed', async () => { - const CURRENT_INPUT = 5900; - var e1 = 1000; - var e2 = 1500; - var e3 = 800; - var office = 500; - var internet = 300; - var t1 = 500; - var t2 = 300; - var t3 = 1000; - var b1 = 10000; - var b2 = 10000; - var b3 = 20000; - var reserve = 750000; - var dividends = 250000; - - var struct = await createStructure(creator, money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - var splitterParams = await getSplitterParams(struct, CURRENT_INPUT, money, creator); - - await totalAndMinNeedsAsserts(splitterParams, CURRENT_INPUT, money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); + it('should process with a scheme just like in the paper: 75/25 others, send EQUAL to minNeed', async () => { + var params = {CURRENT_INPUT:5900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:750000, dividends:250000} + + var struct = await createStructure(params, WeiAbsoluteExpense, WeiRelativeExpense, WeiSplitter); + var splitterParams = await getSplitterParams(struct, params); + + await totalAndMinNeedsAsserts(splitterParams, params); await structureAsserts(splitterParams); - await struct.AllOutpults.processFunds(CURRENT_INPUT*money, { value: CURRENT_INPUT*money, from: creator, gasPrice: 0 }); + await struct.AllOutputs.processFunds(params.CURRENT_INPUT*multiplier, { value: params.CURRENT_INPUT*multiplier, from: creator, gasPrice: 0 }); - var balances = await getBalances(struct); - await balancesAsserts(balances, CURRENT_INPUT, money, e1, e2, e3, office, internet, t1, t2, t3, 0, 0, 0, 0, 0); - await splitterBalancesAsserts(balances, money, 0, 0, 0, 0, 0, 0, 0); + var balances = await getBalances(struct, web3.eth.getBalance); + await balancesAsserts(balances, params); + await splitterBalancesAsserts(balances); }); - it('should not process money: send LESS than minNeed', async () => { - const CURRENT_INPUT = 5900; - var e1 = 1000; - var e2 = 1500; - var e3 = 800; - var office = 500; - var internet = 300; - var t1 = 500; - var t2 = 300; - var t3 = 1000; - var b1 = 10000; - var b2 = 10000; - var b3 = 20000; - var reserve = 750000; - var dividends = 250000; - - var struct = await createStructure(creator, money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - var splitterParams = await getSplitterParams(struct, CURRENT_INPUT, money, creator); - await totalAndMinNeedsAsserts(splitterParams, CURRENT_INPUT, money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); + it('should not process multiplier: send LESS than minNeed', async () => { + var params = {CURRENT_INPUT:5900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:750000, dividends:250000} + + var struct = await createStructure(params, WeiAbsoluteExpense, WeiRelativeExpense, WeiSplitter); + var splitterParams = await getSplitterParams(struct, params); + await totalAndMinNeedsAsserts(splitterParams, params); await structureAsserts(splitterParams); - await struct.AllOutpults.processFunds(1000*money, { value: 1000*money, from: creator }).should.be.rejectedWith('revert'); - await struct.AllOutpults.processFunds(1000000*money, { value: 1000*money, from: creator }).should.be.rejectedWith('revert'); - await struct.AllOutpults.processFunds(1000*money, { value: 1000000*money, from: creator }).should.be.rejectedWith('revert'); + await struct.AllOutputs.processFunds(1000*multiplier, { value: 1000*multiplier, from: creator }).should.be.rejectedWith('revert'); + await struct.AllOutputs.processFunds(1000000*multiplier, { value: 1000*multiplier, from: creator }).should.be.rejectedWith('revert'); + await struct.AllOutputs.processFunds(1000*multiplier, { value: 1000000*multiplier, from: creator }).should.be.rejectedWith('revert'); }); - it('should process money with a scheme just like in the paper: 10/15 others, send MORE than minNeed; ', async () => { - const CURRENT_INPUT = 20900; - var e1 = 1000; - var e2 = 1500; - var e3 = 800; - var office = 500; - var internet = 300; - var t1 = 500; - var t2 = 300; - var t3 = 1000; - var b1 = 10000; - var b2 = 10000; - var b3 = 20000; - var reserve = 850000; - var dividends = 150000; - - var struct = await createStructure(creator, money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - var splitterParams = await getSplitterParams(struct, CURRENT_INPUT, money, creator); - await totalAndMinNeedsAsserts(splitterParams, CURRENT_INPUT, money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); + it('should process with a scheme just like in the paper: 10/15 others, send MORE than minNeed; ', async () => { + var params = {CURRENT_INPUT:20900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:850000, dividends:150000} + + var struct = await createStructure(params, WeiAbsoluteExpense, WeiRelativeExpense, WeiSplitter); + var splitterParams = await getSplitterParams(struct, params); + await totalAndMinNeedsAsserts(splitterParams, params); await structureAsserts(splitterParams); - await struct.AllOutpults.processFunds(CURRENT_INPUT*money, { value: CURRENT_INPUT*money, from: creator, gasPrice: 0 }); + await struct.AllOutputs.processFunds(params.CURRENT_INPUT*multiplier, { value: params.CURRENT_INPUT*multiplier, from: creator, gasPrice: 0 }); - var balances = await getBalances(struct); - await balancesAsserts(balances, CURRENT_INPUT, money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - await splitterBalancesAsserts(balances, money, 0, 0, 0, 0, 0, 0, 0); + var balances = await getBalances(struct, web3.eth.getBalance); + await balancesAsserts(balances, params); + await splitterBalancesAsserts(balances); }); - it('should NOT process money (splitter can not accumulate money) with a scheme just like in the paper: 10/15 others, send MORE than minNeed; ', async () => { - const CURRENT_INPUT = 20900; - var e1 = 1000; - var e2 = 1500; - var e3 = 800; - var office = 500; - var internet = 300; - var t1 = 500; - var t2 = 300; - var t3 = 1000; - var b1 = 10000; - var b2 = 10000; - var b3 = 20000; - var reserve = 100000; - var dividends = 150000; - - var struct = await createStructure(creator, money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - var splitterParams = await getSplitterParams(struct, CURRENT_INPUT, money, creator); - await totalAndMinNeedsAsserts(splitterParams, CURRENT_INPUT, money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); + it('should NOT process (splitter can not accumulate amount) with a scheme just like in the paper: 10/15 others, send MORE than minNeed; ', async () => { + var params = {CURRENT_INPUT:20900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:100000, dividends:150000} + + var struct = await createStructure(params, WeiAbsoluteExpense, WeiRelativeExpense, WeiSplitter); + var splitterParams = await getSplitterParams(struct, params); + await totalAndMinNeedsAsserts(splitterParams, params); await structureAsserts(splitterParams); - await struct.AllOutpults.processFunds(CURRENT_INPUT*money, { value: CURRENT_INPUT*money, from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); + await struct.AllOutputs.processFunds(params.CURRENT_INPUT*multiplier, { value: params.CURRENT_INPUT*multiplier, from: creator, gasPrice: 0 }).should.be.rejectedWith('revert'); }); - it('should process money with a scheme just like in the paper: 10/15 others, send EQUAL to minNeed; ', async () => { - const CURRENT_INPUT = 5900; - var e1 = 1000; - var e2 = 1500; - var e3 = 800; - var office = 500; - var internet = 300; - var t1 = 500; - var t2 = 300; - var t3 = 1000; - var b1 = 10000; - var b2 = 10000; - var b3 = 20000; - var reserve = 100000; - var dividends = 150000; - - var struct = await createStructure(creator, money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - var splitterParams = await getSplitterParams(struct, CURRENT_INPUT, money, creator); - await totalAndMinNeedsAsserts(splitterParams, CURRENT_INPUT, money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); + it('should process with a scheme just like in the paper: 10/15 others, send EQUAL to minNeed; ', async () => { + var params = {CURRENT_INPUT:5900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:100000, dividends:150000} + + var struct = await createStructure(params, WeiAbsoluteExpense, WeiRelativeExpense, WeiSplitter); + var splitterParams = await getSplitterParams(struct, params); + await totalAndMinNeedsAsserts(splitterParams, params); await structureAsserts(splitterParams); - await struct.AllOutpults.processFunds(CURRENT_INPUT*money, { value: CURRENT_INPUT*money, from: creator, gasPrice: 0 }); + await struct.AllOutputs.processFunds(params.CURRENT_INPUT*multiplier, { value: params.CURRENT_INPUT*multiplier, from: creator, gasPrice: 0 }); - var balances = await getBalances(struct); - await balancesAsserts(balances, CURRENT_INPUT, money, e1, e2, e3, office, internet, t1, t2, t3, 0, 0, 0, 0, 0); - await splitterBalancesAsserts(balances, money, 0, 0, 0, 0, 0, 0, 0); + var balances = await getBalances(struct, web3.eth.getBalance); + await balancesAsserts(balances, params); + await splitterBalancesAsserts(balances); }); - it('should not process money: send LESS than minNeed; ', async () => { - const CURRENT_INPUT = 30900; - var e1 = 1000; - var e2 = 1500; - var e3 = 800; - var office = 500; - var internet = 300; - var t1 = 500; - var t2 = 300; - var t3 = 1000; - var b1 = 10000; - var b2 = 10000; - var b3 = 20000; - var reserve = 100000; - var dividends = 150000; - - var struct = await createStructure(creator, money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - var splitterParams = await getSplitterParams(struct, CURRENT_INPUT, money, creator); - await totalAndMinNeedsAsserts(splitterParams, CURRENT_INPUT, money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); + it('should not process multiplier: send LESS than minNeed; ', async () => { + var params = {CURRENT_INPUT:20900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:850000, dividends:150000} + + var struct = await createStructure(params, WeiAbsoluteExpense, WeiRelativeExpense, WeiSplitter); + var splitterParams = await getSplitterParams(struct, params); + await totalAndMinNeedsAsserts(splitterParams, params); await structureAsserts(splitterParams); - await struct.AllOutpults.processFunds(1000*money, { value: 1000*money, from: creator }).should.be.rejectedWith('revert'); - await struct.AllOutpults.processFunds(1000000*money, { value: 1000*money, from: creator }).should.be.rejectedWith('revert'); - await struct.AllOutpults.processFunds(1000*money, { value: 1000000*money, from: creator }).should.be.rejectedWith('revert'); + await struct.AllOutputs.processFunds(1000*multiplier, { value: 1000*multiplier, from: creator }).should.be.rejectedWith('revert'); + await struct.AllOutputs.processFunds(1000000*multiplier, { value: 1000*multiplier, from: creator }).should.be.rejectedWith('revert'); + await struct.AllOutputs.processFunds(1000*multiplier, { value: 1000000*multiplier, from: creator }).should.be.rejectedWith('revert'); }); - it('should process money with WeiSplitter + 3 WeiRelativeExpenseWithPeriod', async () => { + it('should process with WeiSplitter + 3 WeiRelativeExpenseWithPeriod', async () => { // create WeiSplitter var splitter = await WeiSplitter.new(); @@ -807,55 +423,34 @@ contract('WeiExpense', (accounts) => { var targets = [splitter, rel1, rel2, rel3]; var flowArr = [1000, 1000, 1000, 1000]; + await checkParamsCycle(targets, flowArr, [0, 0, 0, 0], [720, 100, 250, 370], [true, true, true, true]); - await checkMinNeed(targets, flowArr, [0, 0, 0, 0]); - await checkTotalNeed(targets, flowArr, [720, 100, 250, 370]); - await checkIsNeed(targets, [true, true, true, true]); - - // now send some money to the revenue endpoint - await splitter.processFunds(1000*money, {value:720*money, from: creator}); + // now send some to the revenue endpoint + await splitter.processFunds(1000*multiplier, {value:720*multiplier, from: creator}); - assert.equal((await web3.eth.getBalance(rel1.address)).toNumber(), 100*money); - assert.equal((await web3.eth.getBalance(rel2.address)).toNumber(), 250*money); - assert.equal((await web3.eth.getBalance(rel3.address)).toNumber(), 370*money); - - await checkMinNeed(targets, flowArr, [0, 0, 0, 0]); - await checkTotalNeed(targets, flowArr, [0, 0, 0, 0]); - await checkIsNeed(targets, [false, false, false, false]); + assert.equal((await web3.eth.getBalance(rel1.address)).toNumber(), 100*multiplier); + assert.equal((await web3.eth.getBalance(rel2.address)).toNumber(), 250*multiplier); + assert.equal((await web3.eth.getBalance(rel3.address)).toNumber(), 370*multiplier); + await checkParamsCycle(targets, flowArr, [0, 0, 0, 0], [0, 0, 0, 0], [false, false, false, false]); await passHours(24); - - await checkMinNeed(targets, flowArr, [0, 0, 0, 0]); - await checkTotalNeed(targets, flowArr, [350, 100, 250, 0]); - await checkIsNeed(targets, [true, true, true, false]); + await checkParamsCycle(targets, flowArr, [0, 0, 0, 0], [350, 100, 250, 0], [true, true, true, false]); await passHours(24); + await checkParamsCycle(targets, flowArr, [0, 0, 0, 0], [720, 100, 250, 370], [true, true, true, true]); - await checkMinNeed(targets, flowArr, [0, 0, 0, 0]); - await checkTotalNeed(targets, flowArr, [720, 100, 250, 370]); - await checkIsNeed(targets, [true, true, true, true]); - - await splitter.processFunds(1000*money, { value: 720*money, from: creator }); + await splitter.processFunds(1000*multiplier, { value: 720*multiplier, from: creator }); + await checkParamsCycle(targets, flowArr, [0, 0, 0, 0], [0, 0, 0, 0], [false, false, false, false]); - await checkMinNeed(targets, flowArr, [0, 0, 0, 0]); - await checkTotalNeed(targets, flowArr, [0, 0, 0, 0]); - await checkIsNeed(targets, [false, false, false, false]); - - // money should end up in the outputs - assert.equal((await web3.eth.getBalance(rel1.address)).toNumber(), 200*money); - assert.equal((await web3.eth.getBalance(rel2.address)).toNumber(), 500*money); - assert.equal((await web3.eth.getBalance(rel3.address)).toNumber(), 740*money); + // should end up in the outputs + assert.equal((await web3.eth.getBalance(rel1.address)).toNumber(), 200*multiplier); + assert.equal((await web3.eth.getBalance(rel2.address)).toNumber(), 500*multiplier); + assert.equal((await web3.eth.getBalance(rel3.address)).toNumber(), 740*multiplier); await passHours(24); + await checkParamsCycle(targets, flowArr, [0, 0, 0, 0], [350, 100, 250, 0], [true, true, true, false]); - await checkMinNeed(targets, flowArr, [0, 0, 0, 0]); - await checkTotalNeed(targets, flowArr, [350, 100, 250, 0]); - await checkIsNeed(targets, [true, true, true, false]); - - await splitter.processFunds(1000*money, { value: 350*money, from: creator }); - - await checkMinNeed(targets, flowArr, [0, 0, 0, 0]); - await checkTotalNeed(targets, flowArr, [0, 0, 0, 0]); - await checkIsNeed(targets, [false, false, false, false]); + await splitter.processFunds(1000*multiplier, { value: 350*multiplier, from: creator }); + await checkParamsCycle(targets, flowArr, [0, 0, 0, 0], [0, 0, 0, 0], [false, false, false, false]); }); }); \ No newline at end of file diff --git a/test/wei_tests/wei_fund.tests.js b/test/wei_tests/wei_fund.tests.js index 3056eb8..e51383e 100644 --- a/test/wei_tests/wei_fund.tests.js +++ b/test/wei_tests/wei_fund.tests.js @@ -6,36 +6,20 @@ var WeiRelativeExpense = artifacts.require('./WeiRelativeExpense'); var WeiAbsoluteExpenseWithPeriod = artifacts.require('./WeiAbsoluteExpenseWithPeriod'); var WeiRelativeExpenseWithPeriod = artifacts.require('./WeiRelativeExpenseWithPeriod'); var WeiAbsoluteExpenseWithPeriodSliding = artifacts.require('./WeiAbsoluteExpenseWithPeriodSliding'); -const getEId = o => o.logs.filter(l => l.event == 'elementAdded')[0].args._eId.toNumber(); -const KECCAK256 = x => web3.sha3(x); - -async function passHours (hours) { - await web3.currentProvider.sendAsync({ - jsonrpc: '2.0', - method: 'evm_increaseTime', - params: [3600 * hours * 1000], - id: new Date().getTime(), - }, function (err) { if (err) console.log('err:', err); }); -} - -const BigNumber = web3.BigNumber; require('chai') .use(require('chai-as-promised')) - .use(require('chai-bignumber')(BigNumber)) + .use(require('chai-bignumber')(web3.BigNumber)) .should(); -contract('WeiFund', (accounts) => { - let money = web3.toWei(0.001, 'ether'); +const {passHours} = require('../helpers/utils'); +contract('WeiFund', (accounts) => { const creator = accounts[0]; const employee1 = accounts[1]; const employee2 = accounts[2]; const outsider = accounts[3]; - beforeEach(async () => { - }); - it('Should collect money, then revert if more, then flush', async () => { let fund = await WeiAbsoluteExpense.new(1e18, 0); @@ -80,7 +64,7 @@ contract('WeiFund', (accounts) => { assert.equal(isNeed, false); }); - it('Should collect money (periodic, not accumulate debt), then time passed, then need money again', async () => { + it('Should collect (periodic, not accumulate debt), then time passed, then need again', async () => { let fund = await WeiAbsoluteExpenseWithPeriod.new(1e18, 0, 24); var totalNeed = await fund.getTotalNeeded(1e22); @@ -141,7 +125,7 @@ contract('WeiFund', (accounts) => { assert.equal(isNeed, false); }); - it('Should collect money (periodic, accumulate debt), then time passed, then need money again', async () => { + it('Should collect (periodic, accumulate debt), then time passed, then need again', async () => { let fund = await WeiAbsoluteExpenseWithPeriodSliding.new(1e18, 0, 24); var totalNeed = await fund.getTotalNeeded(1e22); @@ -199,7 +183,7 @@ contract('WeiFund', (accounts) => { assert.equal(isNeed, false); }); - it('Should collect money (periodic, accumulate debt), then time passed, then need money again', async () => { + it('Should collect (periodic, accumulate debt), then time passed, then need again', async () => { let fund = await WeiAbsoluteExpenseWithPeriodSliding.new(1e18, 0, 24); var totalNeed = await fund.getTotalNeeded(1e22); var isNeed = await fund.isNeeds(); diff --git a/test/wei_tests/wei_scheme.tests.js b/test/wei_tests/wei_scheme.tests.js index dfd35f7..7df658b 100644 --- a/test/wei_tests/wei_scheme.tests.js +++ b/test/wei_tests/wei_scheme.tests.js @@ -6,17 +6,11 @@ var WeiRelativeExpenseWithPeriod = artifacts.require('./WeiRelativeExpenseWithPe var DefaultMoneyflowSchemeWithUnpackers = artifacts.require('./DefaultMoneyflowSchemeWithUnpackers'); -function KECCAK256 (x) { - return web3.sha3(x); -} - contract('Scheme', (accounts) => { let token; - let store; - let daoBase; let moneyflowScheme; - let money = web3.toWei(0.001, 'ether'); + let money = 1e14; const creator = accounts[0]; const employee1 = accounts[1]; diff --git a/test/wei_tests/wei_table.tests.js b/test/wei_tests/wei_table.tests.js index db87077..36f6b07 100644 --- a/test/wei_tests/wei_table.tests.js +++ b/test/wei_tests/wei_table.tests.js @@ -7,205 +7,19 @@ var WeiRelativeExpense = artifacts.require('./WeiRelativeExpense'); var WeiAbsoluteExpenseWithPeriod = artifacts.require('./WeiAbsoluteExpenseWithPeriod'); var WeiRelativeExpenseWithPeriod = artifacts.require('./WeiRelativeExpenseWithPeriod'); -var getEId = o => o.logs.filter(l => l.event == 'NodeAdded')[0].args._eId.toNumber(); - -function KECCAK256 (x) { - return web3.sha3(x); -} - -const BigNumber = web3.BigNumber; - require('chai') .use(require('chai-as-promised')) - .use(require('chai-bignumber')(BigNumber)) + .use(require('chai-bignumber')(web3.BigNumber)) .should(); -function KECCAK256 (x) { - return web3.sha3(x); -} - -async function createStructure (money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends) { - var o = {}; - - o.weiTable = await WeiTable.new(); - - o.AllOutpultsId = getEId(await o.weiTable.addSplitter()); - o.SpendsId = getEId(await o.weiTable.addSplitter()); - o.SalariesId = getEId(await o.weiTable.addSplitter()); - o.Employee1Id = getEId(await o.weiTable.addAbsoluteExpense(e1 * money, e1 * money, false, false, 0)); - o.Employee2Id = getEId(await o.weiTable.addAbsoluteExpense(e2 * money, e2 * money, false, false, 0)); - o.Employee3Id = getEId(await o.weiTable.addAbsoluteExpense(e3 * money, e3 * money, false, false, 0)); - o.OtherId = getEId(await o.weiTable.addSplitter()); - o.OfficeId = getEId(await o.weiTable.addAbsoluteExpense(office * money, office * money, false, false, 0)); - o.InternetId = getEId(await o.weiTable.addAbsoluteExpense(internet * money, internet * money, false, false, 0)); - o.TasksId = getEId(await o.weiTable.addSplitter()); - o.Task1Id = getEId(await o.weiTable.addAbsoluteExpense(t1 * money, t1 * money, false, false, 0)); - o.Task2Id = getEId(await o.weiTable.addAbsoluteExpense(t2 * money, t2 * money, false, false, 0)); - o.Task3Id = getEId(await o.weiTable.addAbsoluteExpense(t3 * money, t3 * money, false, false, 0)); - o.BonusesId = getEId(await o.weiTable.addSplitter()); - o.Bonus1Id = getEId(await o.weiTable.addRelativeExpense(b1, false, false, 0)); - o.Bonus2Id = getEId(await o.weiTable.addRelativeExpense(b2, false, false, 0)); - o.Bonus3Id = getEId(await o.weiTable.addRelativeExpense(b3, false, false, 0)); - o.RestId = getEId(await o.weiTable.addSplitter()); - o.DividendsFundId = getEId(await o.weiTable.addAbsoluteExpense(dividends * money, 0, false, false, 0)); - o.ReserveFundId = getEId(await o.weiTable.addAbsoluteExpense(reserve * money, 0, false, false, 0)); - - await o.weiTable.addChildAt(o.AllOutpultsId, o.SpendsId); - await o.weiTable.addChildAt(o.SpendsId, o.SalariesId); - await o.weiTable.addChildAt(o.SalariesId, o.Employee1Id); - await o.weiTable.addChildAt(o.SalariesId, o.Employee2Id); - await o.weiTable.addChildAt(o.SalariesId, o.Employee3Id); - await o.weiTable.addChildAt(o.SpendsId, o.OtherId); - await o.weiTable.addChildAt(o.OtherId, o.OfficeId); - await o.weiTable.addChildAt(o.OtherId, o.InternetId); - await o.weiTable.addChildAt(o.SpendsId, o.TasksId); - await o.weiTable.addChildAt(o.TasksId, o.Task1Id); - await o.weiTable.addChildAt(o.TasksId, o.Task2Id); - await o.weiTable.addChildAt(o.TasksId, o.Task3Id); - await o.weiTable.addChildAt(o.AllOutpultsId, o.BonusesId); - await o.weiTable.addChildAt(o.BonusesId, o.Bonus1Id); - await o.weiTable.addChildAt(o.BonusesId, o.Bonus2Id); - await o.weiTable.addChildAt(o.BonusesId, o.Bonus3Id); - await o.weiTable.addChildAt(o.AllOutpultsId, o.RestId); - await o.weiTable.addChildAt(o.RestId, o.DividendsFundId); - await o.weiTable.addChildAt(o.RestId, o.ReserveFundId); - return o; -} - -async function totalAndMinNeedsAsserts (money, i, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends) { - var totalSpend = e1 + e2 + e3 + t1 + t2 + t3 + office + internet; - var bonusesSpendPercent = (CURRENT_INPUT - totalSpend) / 1000000; - var rest = CURRENT_INPUT - totalSpend - (bonusesSpendPercent * (b1 + b2 + b3)); - - var dividendsAmount = 0; - var reserveAmount = 0; - if(rest<=0){ - - }else if(rest<=dividends){ - dividendsAmount = rest; - reserveAmount = 0; - }else{ - dividendsAmount = dividends; - reserveAmount = rest - dividendsAmount; - } - var allNeeds = totalSpend + (bonusesSpendPercent * (b1 + b2 + b3)) + (dividendsAmount + reserveAmount); - - assert.equal((new web3.BigNumber(i.AllOutpultsTotalNeed).div(money)).toNumber(), allNeeds, `AllOutpults Total Need should be ${allNeeds}`); - assert.equal((new web3.BigNumber(i.AllOutpultsMinNeed).div(money)).toNumber(), totalSpend, `AllOutpults min Need should be ${totalSpend}`); - assert.equal((new web3.BigNumber(i.SpendsTotalNeed).div(money)).toNumber(), totalSpend, `Spends Total Need should be ${totalSpend}`); - assert.equal((new web3.BigNumber(i.SpendsMinNeed).div(money)).toNumber(), totalSpend, `Spends min Need should be ${totalSpend}`); - assert.equal((new web3.BigNumber(i.SalariesTotalNeed).div(money)).toNumber(), e1 + e2 + e3, `Salaries Total Need should be ${e1 + e2 + e3}`); - assert.equal((new web3.BigNumber(i.SalariesMinNeed).div(money)).toNumber(), e1 + e2 + e3, `Salaries min Need should be ${e1 + e2 + e3}`); - assert.equal((new web3.BigNumber(i.OtherTotalNeed).div(money)).toNumber(), office + internet, `Other Total Need should be ${office + internet}`); - assert.equal((new web3.BigNumber(i.OtherMinNeed).div(money)).toNumber(), office + internet, `Other min Need should be ${office + internet}`); - assert.equal((new web3.BigNumber(i.TasksTotalNeed).div(money)).toNumber(), t1 + t2 + t3, `Tasks Total Need should be ${t1 + t2 + t3}`); - assert.equal((new web3.BigNumber(i.TasksMinNeed).div(money)).toNumber(), t1 + t2 + t3, `Tasks min Need should be ${t1 + t2 + t3}`); - assert.equal((new web3.BigNumber(i.BonusesTotalNeed).div(money)).toNumber(), (b1 + b2 + b3) * CURRENT_INPUT / 1000000, `Bonuses Total Need should be ${(b1 + b2 + b3) * CURRENT_INPUT / 1000000}`); - assert.equal((new web3.BigNumber(i.BonusesMinNeed).div(money)).toNumber(), 0, `Bonuses min Need should be ${0}`); - assert.equal((new web3.BigNumber(i.RestTotalNeed).div(money)).toNumber(), CURRENT_INPUT, `Rest Total Need should be ${rest}`); - assert.equal((new web3.BigNumber(i.RestMinNeed).div(money)).toNumber(), 0, `Rest min Need should be ${0}`); -} - -async function getBalances (i) { - var o = {}; - o.Employee1Balance = await i.weiTable.balanceAt(i.Employee1Id); - o.Employee2Balance = await i.weiTable.balanceAt(i.Employee2Id); - o.Employee3Balance = await i.weiTable.balanceAt(i.Employee3Id); - o.OfficeBalance = await i.weiTable.balanceAt(i.OfficeId); - o.InternetBalance = await i.weiTable.balanceAt(i.InternetId); - o.Task1Balance = await i.weiTable.balanceAt(i.Task1Id); - o.Task2Balance = await i.weiTable.balanceAt(i.Task2Id); - o.Task3Balance = await i.weiTable.balanceAt(i.Task3Id); - o.ReserveBalance = await i.weiTable.balanceAt(i.ReserveFundId); - o.DividendsBalance = await i.weiTable.balanceAt(i.DividendsFundId); - o.Bonus1Balance = await i.weiTable.balanceAt(i.Bonus1Id); - o.Bonus2Balance = await i.weiTable.balanceAt(i.Bonus2Id); - o.Bonus3Balance = await i.weiTable.balanceAt(i.Bonus3Id); - o.AllOutpultsBalance = await i.weiTable.balanceAt(i.AllOutpultsId); - o.SpendsBalance = await i.weiTable.balanceAt(i.SpendsId); - o.SalariesBalance = await i.weiTable.balanceAt(i.SalariesId); - o.OtherBalance = await i.weiTable.balanceAt(i.OtherId); - o.TasksBalance = await i.weiTable.balanceAt(i.TasksId); - o.BonusesBalance = await i.weiTable.balanceAt(i.BonusesId); - o.RestBalance = await i.weiTable.balanceAt(i.RestId); - - return o; -} - -async function getSplitterParams (money, i, CURRENT_INPUT) { - var o = {}; - o.AllOutpultsTotalNeed = await i.weiTable.getTotalNeededAt(i.AllOutpultsId, CURRENT_INPUT * money); - o.AllOutpultsMinNeed = await i.weiTable.getMinNeededAt(i.AllOutpultsId, CURRENT_INPUT * money); - o.AllOutpultsChildrenCount = await i.weiTable.getChildrenCountAt(i.AllOutpultsId); - o.SpendsTotalNeed = await i.weiTable.getTotalNeededAt(i.SpendsId, CURRENT_INPUT * money); - o.SpendsMinNeed = await i.weiTable.getMinNeededAt(i.SpendsId, CURRENT_INPUT * money); - o.SpendsChildrenCount = await i.weiTable.getChildrenCountAt(i.SpendsId); - o.SalariesTotalNeed = await i.weiTable.getTotalNeededAt(i.SalariesId, CURRENT_INPUT * money); - o.SalariesMinNeed = await i.weiTable.getMinNeededAt(i.SalariesId, CURRENT_INPUT * money); - o.SalariesChildrenCount = await i.weiTable.getChildrenCountAt(i.SalariesId); - o.OtherTotalNeed = await i.weiTable.getTotalNeededAt(i.OtherId, CURRENT_INPUT * money); - o.OtherMinNeed = await i.weiTable.getMinNeededAt(i.OtherId, CURRENT_INPUT * money); - o.OtherChildrenCount = await i.weiTable.getChildrenCountAt(i.OtherId); - o.TasksTotalNeed = await i.weiTable.getTotalNeededAt(i.TasksId, CURRENT_INPUT * money); - o.TasksMinNeed = await i.weiTable.getMinNeededAt(i.TasksId, CURRENT_INPUT * money); - o.TasksChildrenCount = await i.weiTable.getChildrenCountAt(i.TasksId); - o.BonusesTotalNeed = await i.weiTable.getTotalNeededAt(i.BonusesId, CURRENT_INPUT * money); - o.BonusesMinNeed = await i.weiTable.getMinNeededAt(i.BonusesId, CURRENT_INPUT * money); - o.BonusesChildrenCount = await i.weiTable.getChildrenCountAt(i.BonusesId); - o.RestTotalNeed = await i.weiTable.getTotalNeededAt(i.RestId, CURRENT_INPUT * money); - o.RestMinNeed = await i.weiTable.getMinNeededAt(i.RestId, CURRENT_INPUT * money); - o.RestChildrenCount = await i.weiTable.getChildrenCountAt(i.RestId); - - return o; -} - -async function structureAsserts (i) { - assert.equal(i.AllOutpultsChildrenCount.toNumber(), 3, 'Children count should be 3'); - assert.equal(i.SpendsChildrenCount.toNumber(), 3, 'Children count should be 3'); - assert.equal(i.SalariesChildrenCount.toNumber(), 3, 'Children count should be 3'); - assert.equal(i.OtherChildrenCount.toNumber(), 2, 'Children count should be 2'); - assert.equal(i.TasksChildrenCount.toNumber(), 3, 'Children count should be 3'); - assert.equal(i.BonusesChildrenCount.toNumber(), 3, 'Children count should be 3'); - assert.equal(i.RestChildrenCount.toNumber(), 2, 'Children count should be 2'); -} - -async function balancesAsserts (money, i, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends) { - var totalSpend = e1 + e2 + e3 + t1 + t2 + t3 + office + internet; - var bonusesSpendPercent = (CURRENT_INPUT - totalSpend) / 1000000; - var rest = CURRENT_INPUT - totalSpend - (bonusesSpendPercent * (b1 + b2 + b3)); - - var dividendsAmount = 0; - var reserveAmount = 0; - if((rest<=dividends)&&(rest>0)){ - dividendsAmount = rest; - reserveAmount = 0; - }else{ - dividendsAmount = dividends; - reserveAmount = rest - dividendsAmount; - } - - assert.equal((new web3.BigNumber(i.Employee1Balance).div(money)).toNumber(), e1, `Employee1 balance should be ${e1} money`); - assert.equal((new web3.BigNumber(i.Employee2Balance).div(money)).toNumber(), e2, `Employee2 balance should be ${e2} money`); - assert.equal((new web3.BigNumber(i.Employee3Balance).div(money)).toNumber(), e3, `Employee3 balance should be ${e3} money`); - assert.equal((new web3.BigNumber(i.OfficeBalance).div(money)).toNumber(), office, `Office balance should be ${office} money`); - assert.equal((new web3.BigNumber(i.InternetBalance).div(money)).toNumber(), internet, `Internet balance should be ${internet} money`); - assert.equal((new web3.BigNumber(i.Task1Balance).div(money)).toNumber(), t1, `Task1 balance should be ${t1} money`); - assert.equal((new web3.BigNumber(i.Task2Balance).div(money)).toNumber(), t2, `Task2 balance should be ${t2} money`); - assert.equal((new web3.BigNumber(i.Task3Balance).div(money)).toNumber(), t3, `Task3 balance should be ${t3} money`); - assert.equal((new web3.BigNumber(i.Bonus1Balance).div(money)).toNumber(), bonusesSpendPercent * b1, `Bonus1 balance should be ${bonusesSpendPercent * b1} money`); - assert.equal((new web3.BigNumber(i.Bonus2Balance).div(money)).toNumber(), bonusesSpendPercent * b2, `Bonus2 balance should be ${bonusesSpendPercent * b2} money`); - assert.equal((new web3.BigNumber(i.Bonus3Balance).div(money)).toNumber(), bonusesSpendPercent * b3, `Bonus3 balance should be ${bonusesSpendPercent * b3} money`); - assert.equal((new web3.BigNumber(i.DividendsBalance).div(money)).toNumber(), dividendsAmount, `Dividends balance should be ${dividendsAmount} money`); - assert.equal((new web3.BigNumber(i.ReserveBalance).div(money)).toNumber(), reserveAmount, `Reserve balance should be ${reserveAmount} money`); - -} +const {createStructureTable, totalAndMinNeedsAssertsTable, getBalancesTable, + getSplitterParamsTable, structureAssertsTable, balancesAssertsTable} = require('../helpers/structures'); + +const {passHours, getNodeId} = require('../helpers/utils'); contract('WeiTable tests', (accounts) => { var token; - var store; - var daoBase; - - var money = 1e12; + var multiplier = 1e12; var isPeriodic = false; var isAccumulateDebt = false; var periodHours = 0; @@ -217,350 +31,275 @@ contract('WeiTable tests', (accounts) => { const outsider = accounts[3]; // // 0->•abs - it('should process money with WeiSplitter + 3 WeiAbsoluteExpense', async () => { - let weiTable = await WeiTable.new(); - var output1 = await WeiAbsoluteExpense.new(money, money); - var output2 = await WeiAbsoluteExpense.new(2 * money, 2 * money); - var output3 = await WeiAbsoluteExpense.new(3 * money, 3 * money); - let splitterId = getEId(await weiTable.addSplitter()); - let AbsoluteExpense1Id = getEId(await weiTable.addAbsoluteExpense(1 * money, 1 * money, isPeriodic, isAccumulateDebt, periodHours)); - let AbsoluteExpense2Id = getEId(await weiTable.addAbsoluteExpense(2 * money, 2 * money, isPeriodic, isAccumulateDebt, periodHours)); - let AbsoluteExpense3Id = getEId(await weiTable.addAbsoluteExpense(3 * money, 3 * money, isPeriodic, isAccumulateDebt, periodHours)); + it('should process with WeiSplitter + 3 WeiAbsoluteExpense', async () => { + let table = await WeiTable.new(); + var output1 = await WeiAbsoluteExpense.new(multiplier, multiplier); + var output2 = await WeiAbsoluteExpense.new(2 * multiplier, 2 * multiplier); + var output3 = await WeiAbsoluteExpense.new(3 * multiplier, 3 * multiplier); + let splitterId = getNodeId(await table.addSplitter()); + let AbsoluteExpense1Id = getNodeId(await table.addAbsoluteExpense(1 * multiplier, 1 * multiplier, isPeriodic, isAccumulateDebt, periodHours)); + let AbsoluteExpense2Id = getNodeId(await table.addAbsoluteExpense(2 * multiplier, 2 * multiplier, isPeriodic, isAccumulateDebt, periodHours)); + let AbsoluteExpense3Id = getNodeId(await table.addAbsoluteExpense(3 * multiplier, 3 * multiplier, isPeriodic, isAccumulateDebt, periodHours)); // add 3 WeiAbsoluteExpense outputs to the splitter - await weiTable.addChildAt(splitterId, AbsoluteExpense1Id); - await weiTable.addChildAt(splitterId, AbsoluteExpense2Id); - await weiTable.addChildAt(splitterId, AbsoluteExpense3Id); + await table.addChildAt(splitterId, AbsoluteExpense1Id); + await table.addChildAt(splitterId, AbsoluteExpense2Id); + await table.addChildAt(splitterId, AbsoluteExpense3Id); - var id1 = await weiTable.getChildIdAt(splitterId, 0); - var id2 = await weiTable.getChildIdAt(splitterId, 1); - var id3 = await weiTable.getChildIdAt(splitterId, 2); + var id1 = await table.getChildIdAt(splitterId, 0); + var id2 = await table.getChildIdAt(splitterId, 1); + var id3 = await table.getChildIdAt(splitterId, 2); assert.equal(id1, AbsoluteExpense1Id); assert.equal(id2, AbsoluteExpense2Id); assert.equal(id3, AbsoluteExpense3Id); - var totalNeed = await weiTable.getTotalNeeded(6 * money); - assert.equal(totalNeed, 6 * money); - var minNeed = await weiTable.getMinNeeded(0);/*minNeedFix*/ - assert.equal(minNeed, 6 * money); - var need1 = await weiTable.isNeeds(); + var totalNeed = await table.getTotalNeeded(6 * multiplier); + assert.equal(totalNeed, 6 * multiplier); + var minNeed = await table.getMinNeeded(0);/*minNeedFix*/ + assert.equal(minNeed, 6 * multiplier); + var need1 = await table.isNeeds(); assert.equal(need1, true); - // now send some money to the revenue endpoint - await weiTable.processFunds(6 * money, { value: 6 * money, from: creator }); + // now send some to the revenue endpoint + await table.processFunds(6 * multiplier, { value: 6 * multiplier, from: creator }); - // money should end up in the outputs - var absoluteExpense1Balance = await weiTable.balanceAt(AbsoluteExpense1Id); - assert.equal(absoluteExpense1Balance.toNumber(), 1 * money, 'resource point received money from splitter'); + // should end up in the outputs + var absoluteExpense1Balance = await table.balanceAt(AbsoluteExpense1Id); + assert.equal(absoluteExpense1Balance.toNumber(), 1 * multiplier, 'resource point received from splitter'); - var absoluteExpense2Balance = await weiTable.balanceAt(AbsoluteExpense2Id); - assert.equal(absoluteExpense2Balance.toNumber(), 2 * money, 'resource point received money from splitter'); + var absoluteExpense2Balance = await table.balanceAt(AbsoluteExpense2Id); + assert.equal(absoluteExpense2Balance.toNumber(), 2 * multiplier, 'resource point received from splitter'); - var absoluteExpense3Balance = await weiTable.balanceAt(AbsoluteExpense3Id); - assert.equal(absoluteExpense3Balance.toNumber(), 3 * money, 'resource point received money from splitter'); + var absoluteExpense3Balance = await table.balanceAt(AbsoluteExpense3Id); + assert.equal(absoluteExpense3Balance.toNumber(), 3 * multiplier, 'resource point received from splitter'); - assert.equal((await weiTable.getTotalNeededAt(AbsoluteExpense1Id, 6 * money)).toNumber(), 0); - assert.equal((await weiTable.getTotalNeededAt(AbsoluteExpense2Id, 6 * money)).toNumber(), 0); - assert.equal((await weiTable.getTotalNeededAt(AbsoluteExpense3Id, 6 * money)).toNumber(), 0); + assert.equal((await table.getTotalNeededAt(AbsoluteExpense1Id, 6 * multiplier)).toNumber(), 0); + assert.equal((await table.getTotalNeededAt(AbsoluteExpense2Id, 6 * multiplier)).toNumber(), 0); + assert.equal((await table.getTotalNeededAt(AbsoluteExpense3Id, 6 * multiplier)).toNumber(), 0); - var totalNeed = await weiTable.getTotalNeeded(6 * money); - assert.equal(totalNeed.toNumber(), 0 * money); - var minNeed = await weiTable.getMinNeeded(0);/*minNeedFix*/ - assert.equal(minNeed.toNumber(), 0 * money); + var totalNeed = await table.getTotalNeeded(6 * multiplier); + assert.equal(totalNeed.toNumber(), 0 * multiplier); + var minNeed = await table.getMinNeeded(0);/*minNeedFix*/ + assert.equal(minNeed.toNumber(), 0 * multiplier); - var need2 = await weiTable.isNeeds(); + var need2 = await table.isNeeds(); assert.equal(need2, false); var b1 = await web3.eth.getBalance(accounts[9]); - await weiTable.flushToAt(AbsoluteExpense1Id, accounts[9], { gasPrice: 0 }); + await table.flushToAt(AbsoluteExpense1Id, accounts[9], { gasPrice: 0 }); var b2 = await web3.eth.getBalance(accounts[9]); - assert.equal(b2.sub(b1).toNumber(), 1 * money); + assert.equal(b2.sub(b1).toNumber(), 1 * multiplier); var b1 = await web3.eth.getBalance(accounts[9]); - await weiTable.flushToAt(AbsoluteExpense2Id, accounts[9], { gasPrice: 0 }); + await table.flushToAt(AbsoluteExpense2Id, accounts[9], { gasPrice: 0 }); var b2 = await web3.eth.getBalance(accounts[9]); - assert.equal(b2.sub(b1).toNumber(), 2 * money); + assert.equal(b2.sub(b1).toNumber(), 2 * multiplier); var b1 = await web3.eth.getBalance(accounts[9]); - await weiTable.flushToAt(AbsoluteExpense3Id, accounts[9], { gasPrice: 0 }); + await table.flushToAt(AbsoluteExpense3Id, accounts[9], { gasPrice: 0 }); var b2 = await web3.eth.getBalance(accounts[9]); - assert.equal(b2.sub(b1).toNumber(), 3 * money); + assert.equal(b2.sub(b1).toNumber(), 3 * multiplier); - var absoluteExpense1Balance = await weiTable.balanceAt(AbsoluteExpense1Id); - assert.equal(absoluteExpense1Balance.toNumber(), 0 * money, 'resource point received money from splitter'); + var absoluteExpense1Balance = await table.balanceAt(AbsoluteExpense1Id); + assert.equal(absoluteExpense1Balance.toNumber(), 0 * multiplier, 'resource point received from splitter'); - var absoluteExpense2Balance = await weiTable.balanceAt(AbsoluteExpense2Id); - assert.equal(absoluteExpense2Balance.toNumber(), 0 * money, 'resource point received money from splitter'); + var absoluteExpense2Balance = await table.balanceAt(AbsoluteExpense2Id); + assert.equal(absoluteExpense2Balance.toNumber(), 0 * multiplier, 'resource point received from splitter'); - var absoluteExpense3Balance = await weiTable.balanceAt(AbsoluteExpense3Id); - assert.equal(absoluteExpense3Balance.toNumber(), 0 * money, 'resource point received money from splitter'); - var need2 = await weiTable.isNeeds(); + var absoluteExpense3Balance = await table.balanceAt(AbsoluteExpense3Id); + assert.equal(absoluteExpense3Balance.toNumber(), 0 * multiplier, 'resource point received from splitter'); + var need2 = await table.isNeeds(); }); - it('should process money with WeiSplitter + 3 WeiAbsoluteExpense', async () => { - let weiTable = await WeiTable.new(); + it('should process with WeiSplitter + 3 WeiAbsoluteExpense', async () => { + let table = await WeiTable.new(); - let unsortedSplitterId = getEId(await weiTable.addSplitter()); - let AbsoluteExpense1Id = getEId(await weiTable.addAbsoluteExpense(money, money, isPeriodic, isAccumulateDebt, periodHours)); - let AbsoluteExpense2Id = getEId(await weiTable.addAbsoluteExpense(2 * money, 2 * money, isPeriodic, isAccumulateDebt, periodHours)); - let AbsoluteExpense3Id = getEId(await weiTable.addAbsoluteExpense(3 * money, 3 * money, isPeriodic, isAccumulateDebt, periodHours)); - - await weiTable.addChildAt(unsortedSplitterId, AbsoluteExpense1Id); - await weiTable.addChildAt(unsortedSplitterId, AbsoluteExpense2Id); - await weiTable.addChildAt(unsortedSplitterId, AbsoluteExpense3Id); - - // now send some money to the revenue endpoint - let totalNeed = await weiTable.getTotalNeeded(6 * money); - assert.equal(totalNeed, 6 * money); - let minNeed = await weiTable.getMinNeeded(0);/*minNeedFix*/ - assert.equal(minNeed, 6 * money); - - await weiTable.processFunds(6 * money, { value: 6 * money, from: creator }); - // money should end up in the outputs - var absoluteExpense1Balance = await weiTable.balanceAt(AbsoluteExpense1Id); - assert.equal(absoluteExpense1Balance.toNumber(), 1 * money, 'resource point received money from splitter'); - - var absoluteExpense2Balance = await weiTable.balanceAt(AbsoluteExpense2Id); - assert.equal(absoluteExpense2Balance.toNumber(), 2 * money, 'resource point received money from splitter'); - - var absoluteExpense3Balance = await weiTable.balanceAt(AbsoluteExpense3Id); - assert.equal(absoluteExpense3Balance.toNumber(), 3 * money, 'resource point received money from splitter'); + let unsortedSplitterId = getNodeId(await table.addSplitter()); + let AbsoluteExpense1Id = getNodeId(await table.addAbsoluteExpense(multiplier, multiplier, isPeriodic, isAccumulateDebt, periodHours)); + let AbsoluteExpense2Id = getNodeId(await table.addAbsoluteExpense(2 * multiplier, 2 * multiplier, isPeriodic, isAccumulateDebt, periodHours)); + let AbsoluteExpense3Id = getNodeId(await table.addAbsoluteExpense(3 * multiplier, 3 * multiplier, isPeriodic, isAccumulateDebt, periodHours)); + + await table.addChildAt(unsortedSplitterId, AbsoluteExpense1Id); + await table.addChildAt(unsortedSplitterId, AbsoluteExpense2Id); + await table.addChildAt(unsortedSplitterId, AbsoluteExpense3Id); + + // now send some to the revenue endpoint + let totalNeed = await table.getTotalNeeded(6 * multiplier); + assert.equal(totalNeed, 6 * multiplier); + let minNeed = await table.getMinNeeded(0);/*minNeedFix*/ + assert.equal(minNeed, 6 * multiplier); + + await table.processFunds(6 * multiplier, { value: 6 * multiplier, from: creator }); + // should end up in the outputs + var absoluteExpense1Balance = await table.balanceAt(AbsoluteExpense1Id); + assert.equal(absoluteExpense1Balance.toNumber(), 1 * multiplier, 'resource point received from splitter'); + + var absoluteExpense2Balance = await table.balanceAt(AbsoluteExpense2Id); + assert.equal(absoluteExpense2Balance.toNumber(), 2 * multiplier, 'resource point received from splitter'); + + var absoluteExpense3Balance = await table.balanceAt(AbsoluteExpense3Id); + assert.equal(absoluteExpense3Balance.toNumber(), 3 * multiplier, 'resource point received from splitter'); }); - it('should process money with a scheme just like in the paper: 75/25 others, send MORE than minNeed; ', async () => { - const money = 1e12; - const CURRENT_INPUT = 30900; - let e1 = 1000; - let e2 = 1500; - let e3 = 800; - let office = 500; - let internet = 300; - let t1 = 500; - let t2 = 300; - let t3 = 1000; - // 5900 - let b1 = 10000; - let b2 = 10000; - let b3 = 20000; - //4% of 25K = 1000 - let reserve = 750000; - let dividends = 250000; - - let struct = await createStructure(money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - let splitterParams = await getSplitterParams(money, struct, CURRENT_INPUT, creator); - await totalAndMinNeedsAsserts(money, splitterParams, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - await structureAsserts(splitterParams); - - await struct.weiTable.processFunds(CURRENT_INPUT * money, { value: CURRENT_INPUT * money, gasPrice: 0 }); - - let balances = await getBalances(struct); - await balancesAsserts(money, balances, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); + it('should process with a scheme just like in the paper: 75/25 others, send MORE than minNeed; ', async () => { + var params = {CURRENT_INPUT:30900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:750000, dividends:250000} + + let struct = await createStructureTable(params, WeiTable); + let splitterParams = await getSplitterParamsTable(struct, params); + await totalAndMinNeedsAssertsTable(splitterParams, params); + await structureAssertsTable(splitterParams); + + await struct.table.processFunds(params.CURRENT_INPUT * multiplier, { value: params.CURRENT_INPUT * multiplier, gasPrice: 0 }); + + let balances = await getBalancesTable(struct); + await balancesAssertsTable(balances, params); }); - it('should process money with a scheme just like in the paper: 75/25 others, send EQUAL to minNeed', async () => { - const money = 1e12; - const CURRENT_INPUT = 5900; - let e1 = 1000; - let e2 = 1500; - let e3 = 800; - let office = 500; - let internet = 300; - let t1 = 500; - let t2 = 300; - let t3 = 1000; - let b1 = 10000; - let b2 = 10000; - let b3 = 20000; - let reserve = 750000; - let dividends = 250000; - - let struct = await createStructure(money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - let splitterParams = await getSplitterParams(money, struct, CURRENT_INPUT, creator); - await totalAndMinNeedsAsserts(money, splitterParams, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - await structureAsserts(splitterParams); - - await struct.weiTable.processFunds(CURRENT_INPUT * money, { value: CURRENT_INPUT * money, gasPrice: 0 }); - - let balances = await getBalances(struct); - await balancesAsserts(money, balances, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, 0, 0, 0, 0, 0); + it('should process with a scheme just like in the paper: 75/25 others, send EQUAL to minNeed', async () => { + var params = {CURRENT_INPUT:5900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:750000, dividends:250000} + + let struct = await createStructureTable(params, WeiTable); + let splitterParams = await getSplitterParamsTable(struct, params); + await totalAndMinNeedsAssertsTable(splitterParams, params); + await structureAssertsTable(splitterParams); + + await struct.table.processFunds(params.CURRENT_INPUT * multiplier, { value: params.CURRENT_INPUT * multiplier, gasPrice: 0 }); + + let balances = await getBalancesTable(struct); + await balancesAssertsTable(balances, params); }); - it('should not process money: send LESS than minNeed', async () => { - const money = 1e12; - const CURRENT_INPUT = 5900; - let e1 = 1000; - let e2 = 1500; - let e3 = 800; - let office = 500; - let internet = 300; - let t1 = 500; - let t2 = 300; - let t3 = 1000; - let b1 = 10000; - let b2 = 10000; - let b3 = 20000; - let reserve = 750000; - let dividends = 250000; - - let struct = await createStructure(money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - let splitterParams = await getSplitterParams(money, struct, CURRENT_INPUT, creator); - await totalAndMinNeedsAsserts(money, splitterParams, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - await structureAsserts(splitterParams); - - await struct.weiTable.processFunds(CURRENT_INPUT * money / 100, { value: CURRENT_INPUT * money, gasPrice: 0 }).should.be.rejectedWith('revert'); - await struct.weiTable.processFunds(CURRENT_INPUT * money, { value: CURRENT_INPUT * money / 100, gasPrice: 0 }).should.be.rejectedWith('revert'); - await struct.weiTable.processFunds(CURRENT_INPUT * money / 100, { value: CURRENT_INPUT * money, gasPrice: 0 }).should.be.rejectedWith('revert'); + it('should not process multiplier: send LESS than minNeed', async () => { + var params = {CURRENT_INPUT:5900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:750000, dividends:250000} + + let struct = await createStructureTable(params, WeiTable); + let splitterParams = await getSplitterParamsTable(struct, params); + await totalAndMinNeedsAssertsTable(splitterParams, params); + await structureAssertsTable(splitterParams); + + await struct.table.processFunds(params.CURRENT_INPUT * multiplier / 100, { value: params.CURRENT_INPUT * multiplier, gasPrice: 0 }).should.be.rejectedWith('revert'); + await struct.table.processFunds(params.CURRENT_INPUT * multiplier, { value: params.CURRENT_INPUT * multiplier / 100, gasPrice: 0 }).should.be.rejectedWith('revert'); + await struct.table.processFunds(params.CURRENT_INPUT * multiplier / 100, { value: params.CURRENT_INPUT * multiplier, gasPrice: 0 }).should.be.rejectedWith('revert'); }); - it('should process money with a scheme just like in the paper: 10/15 others, send MORE than minNeed; ', async () => { - const money = 1e12; - const CURRENT_INPUT = 20900; - let e1 = 1000; - let e2 = 1500; - let e3 = 800; - let office = 500; - let internet = 300; - let t1 = 500; - let t2 = 300; - let t3 = 1000; - // 5900 -> 4% of 15000 -> - let b1 = 10000; - let b2 = 10000; - let b3 = 20000; - let reserve = 750000; - let dividends = 250000; - - let struct = await createStructure(money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - let splitterParams = await getSplitterParams(money, struct, CURRENT_INPUT, creator); - await totalAndMinNeedsAsserts(money, splitterParams, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - await structureAsserts(splitterParams); - - await struct.weiTable.processFunds(CURRENT_INPUT * money, { value: CURRENT_INPUT * money, gasPrice: 0 }); - - let balances = await getBalances(struct); - await balancesAsserts(money, balances, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); + it('should process with a scheme just like in the paper: 10/15 others, send MORE than minNeed; ', async () => { + var params = {CURRENT_INPUT:20900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:750000, dividends:250000} + + let struct = await createStructureTable(params, WeiTable); + let splitterParams = await getSplitterParamsTable(struct, params); + await totalAndMinNeedsAssertsTable(splitterParams, params); + await structureAssertsTable(splitterParams); + + await struct.table.processFunds(params.CURRENT_INPUT * multiplier, { value: params.CURRENT_INPUT * multiplier, gasPrice: 0 }); + + let balances = await getBalancesTable(struct); + await balancesAssertsTable(balances, params); }); - it('should process money with a scheme just like in the paper: 10/15 others, send EQUAL to minNeed; ', async () => { - const money = 1e12; - const CURRENT_INPUT = 5900; - let e1 = 1000; - let e2 = 1500; - let e3 = 800; - let office = 500; - let internet = 300; - let t1 = 500; - let t2 = 300; - let t3 = 1000; - let b1 = 10000; - let b2 = 10000; - let b3 = 20000; - let reserve = 750000; - let dividends = 250000; - - let struct = await createStructure(money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - let splitterParams = await getSplitterParams(money, struct, CURRENT_INPUT, creator); - await totalAndMinNeedsAsserts(money, splitterParams, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - await structureAsserts(splitterParams); - - await struct.weiTable.processFunds(CURRENT_INPUT * money, { value: CURRENT_INPUT * money, gasPrice: 0 }); - - let balances = await getBalances(struct); - await balancesAsserts(money, balances, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, 0, 0, 0, 0, 0); + it('should process with a scheme just like in the paper: 10/15 others, send EQUAL to minNeed; ', async () => { + var params = {CURRENT_INPUT:5900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:750000, dividends:250000} + + let struct = await createStructureTable(params, WeiTable); + let splitterParams = await getSplitterParamsTable(struct, params); + await totalAndMinNeedsAssertsTable(splitterParams, params); + await structureAssertsTable(splitterParams); + + await struct.table.processFunds(params.CURRENT_INPUT * multiplier, { value: params.CURRENT_INPUT * multiplier, gasPrice: 0 }); + + let balances = await getBalancesTable(struct); + await balancesAssertsTable(balances, params); }); - it('should not process money: send LESS than minNeed; ', async () => { - const money = 1e12; - const CURRENT_INPUT = 30900; - let e1 = 1000; - let e2 = 1500; - let e3 = 800; - let office = 500; - let internet = 300; - let t1 = 500; - let t2 = 300; - let t3 = 1000; - let b1 = 10000; - let b2 = 10000; - let b3 = 20000; - let reserve = 750000; - let dividends = 250000; - - let struct = await createStructure(money, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - let splitterParams = await getSplitterParams(money, struct, CURRENT_INPUT, creator); - await totalAndMinNeedsAsserts(money, splitterParams, CURRENT_INPUT, e1, e2, e3, office, internet, t1, t2, t3, b1, b2, b3, reserve, dividends); - await structureAsserts(splitterParams); - - await struct.weiTable.processFunds(CURRENT_INPUT * money / 100, { value: CURRENT_INPUT * money, gasPrice: 0 }).should.be.rejectedWith('revert'); - await struct.weiTable.processFunds(CURRENT_INPUT * money, { value: CURRENT_INPUT * money / 100, gasPrice: 0 }).should.be.rejectedWith('revert'); - await struct.weiTable.processFunds(CURRENT_INPUT * money / 100, { value: CURRENT_INPUT * money, gasPrice: 0 }).should.be.rejectedWith('revert'); + it('should not process multiplier: send LESS than minNeed; ', async () => { + var params = {CURRENT_INPUT:5900, multiplier:multiplier, + e1:1000, e2:1500, e3:800, office:500, internet:300, t1:500, t2:300, t3:1000, + b1:10000, b2:10000, b3:20000, reserve:750000, dividends:250000} + + let struct = await createStructureTable(params, WeiTable); + let splitterParams = await getSplitterParamsTable(struct, params); + await totalAndMinNeedsAssertsTable(splitterParams, params); + await structureAssertsTable(splitterParams); + + await struct.table.processFunds(params.CURRENT_INPUT * multiplier / 100, { value: params.CURRENT_INPUT * multiplier, gasPrice: 0 }).should.be.rejectedWith('revert'); + await struct.table.processFunds(params.CURRENT_INPUT * multiplier, { value: params.CURRENT_INPUT * multiplier / 100, gasPrice: 0 }).should.be.rejectedWith('revert'); + await struct.table.processFunds(params.CURRENT_INPUT * multiplier / 100, { value: params.CURRENT_INPUT * multiplier, gasPrice: 0 }).should.be.rejectedWith('revert'); }); - it('should process money when opened and not process when closed with WeiSplitter + 3 WeiAbsoluteExpense', async () => { - let weiTable = await WeiTable.new(); + it('should process when opened and not process when closed with WeiSplitter + 3 WeiAbsoluteExpense', async () => { + let table = await WeiTable.new(); - let splitterId = getEId(await weiTable.addSplitter()); - let AbsoluteExpense1Id = getEId(await weiTable.addAbsoluteExpense(money, money, isPeriodic, isAccumulateDebt, periodHours)); - let AbsoluteExpense2Id = getEId(await weiTable.addAbsoluteExpense(2 * money, 2 * money, isPeriodic, isAccumulateDebt, periodHours)); - let AbsoluteExpense3Id = getEId(await weiTable.addAbsoluteExpense(3 * money, 3 * money, isPeriodic, isAccumulateDebt, periodHours)); + let splitterId = getNodeId(await table.addSplitter()); + let AbsoluteExpense1Id = getNodeId(await table.addAbsoluteExpense(multiplier, multiplier, isPeriodic, isAccumulateDebt, periodHours)); + let AbsoluteExpense2Id = getNodeId(await table.addAbsoluteExpense(2 * multiplier, 2 * multiplier, isPeriodic, isAccumulateDebt, periodHours)); + let AbsoluteExpense3Id = getNodeId(await table.addAbsoluteExpense(3 * multiplier, 3 * multiplier, isPeriodic, isAccumulateDebt, periodHours)); // add 3 WeiAbsoluteExpense outputs to the splitter - await weiTable.addChildAt(splitterId, AbsoluteExpense1Id); - await weiTable.addChildAt(splitterId, AbsoluteExpense2Id); - await weiTable.addChildAt(splitterId, AbsoluteExpense3Id); - - var totalNeed = await weiTable.getTotalNeeded(6 * money); - assert.equal(totalNeed, 6 * money); - var minNeed = await weiTable.getMinNeeded(0);/*minNeedFix*/ - assert.equal(minNeed, 6 * money); - - var isOpen1At = await weiTable.isOpenAt(AbsoluteExpense1Id); - var isOpen2At = await weiTable.isOpenAt(AbsoluteExpense2Id); - var isOpen3At = await weiTable.isOpenAt(AbsoluteExpense3Id); + await table.addChildAt(splitterId, AbsoluteExpense1Id); + await table.addChildAt(splitterId, AbsoluteExpense2Id); + await table.addChildAt(splitterId, AbsoluteExpense3Id); + + var totalNeed = await table.getTotalNeeded(6 * multiplier); + assert.equal(totalNeed, 6 * multiplier); + var minNeed = await table.getMinNeeded(0);/*minNeedFix*/ + assert.equal(minNeed, 6 * multiplier); + + var isOpen1At = await table.isOpenAt(AbsoluteExpense1Id); + var isOpen2At = await table.isOpenAt(AbsoluteExpense2Id); + var isOpen3At = await table.isOpenAt(AbsoluteExpense3Id); assert.equal(isOpen1At, true); assert.equal(isOpen2At, true); assert.equal(isOpen3At, true); - await weiTable.closeAt(AbsoluteExpense3Id); + await table.closeAt(AbsoluteExpense3Id); - var totalNeed = await weiTable.getTotalNeeded(6 * money); - assert.equal(totalNeed.toNumber(), 3 * money); - var minNeed = await weiTable.getMinNeeded(0);/*minNeedFix*/ - assert.equal(minNeed, 3 * money); + var totalNeed = await table.getTotalNeeded(6 * multiplier); + assert.equal(totalNeed.toNumber(), 3 * multiplier); + var minNeed = await table.getMinNeeded(0);/*minNeedFix*/ + assert.equal(minNeed, 3 * multiplier); - await weiTable.closeAt(AbsoluteExpense1Id); + await table.closeAt(AbsoluteExpense1Id); - var totalNeed = await weiTable.getTotalNeeded(6 * money); - assert.equal(totalNeed, 2 * money); - var minNeed = await weiTable.getMinNeeded(0);/*minNeedFix*/ - assert.equal(minNeed, 2 * money); + var totalNeed = await table.getTotalNeeded(6 * multiplier); + assert.equal(totalNeed, 2 * multiplier); + var minNeed = await table.getMinNeeded(0);/*minNeedFix*/ + assert.equal(minNeed, 2 * multiplier); - var isOpen1At = await weiTable.isOpenAt(AbsoluteExpense1Id); - var isOpen2At = await weiTable.isOpenAt(AbsoluteExpense2Id); - var isOpen3At = await weiTable.isOpenAt(AbsoluteExpense3Id); + var isOpen1At = await table.isOpenAt(AbsoluteExpense1Id); + var isOpen2At = await table.isOpenAt(AbsoluteExpense2Id); + var isOpen3At = await table.isOpenAt(AbsoluteExpense3Id); assert.equal(isOpen1At, false); assert.equal(isOpen2At, true); assert.equal(isOpen3At, false); - await weiTable.openAt(AbsoluteExpense3Id); - var isOpen1At = await weiTable.isOpenAt(AbsoluteExpense1Id); - var isOpen2At = await weiTable.isOpenAt(AbsoluteExpense2Id); - var isOpen3At = await weiTable.isOpenAt(AbsoluteExpense3Id); + await table.openAt(AbsoluteExpense3Id); + var isOpen1At = await table.isOpenAt(AbsoluteExpense1Id); + var isOpen2At = await table.isOpenAt(AbsoluteExpense2Id); + var isOpen3At = await table.isOpenAt(AbsoluteExpense3Id); assert.equal(isOpen1At, false); assert.equal(isOpen2At, true); assert.equal(isOpen3At, true); - // now send some money to the revenue endpoint - await weiTable.processFunds(5 * money, { value: 5 * money, from: creator }); + // now send some to the revenue endpoint + await table.processFunds(5 * multiplier, { value: 5 * multiplier, from: creator }); - // money should end up in the outputs - var absoluteExpense1Balance = await weiTable.balanceAt(AbsoluteExpense1Id); - assert.equal(absoluteExpense1Balance.toNumber(), 0 * money, 'resource point received money from splitter'); + // should end up in the outputs + var absoluteExpense1Balance = await table.balanceAt(AbsoluteExpense1Id); + assert.equal(absoluteExpense1Balance.toNumber(), 0 * multiplier, 'resource point received from splitter'); - var absoluteExpense2Balance = await weiTable.balanceAt(AbsoluteExpense2Id); - assert.equal(absoluteExpense2Balance.toNumber(), 2 * money, 'resource point received money from splitter'); + var absoluteExpense2Balance = await table.balanceAt(AbsoluteExpense2Id); + assert.equal(absoluteExpense2Balance.toNumber(), 2 * multiplier, 'resource point received from splitter'); - var absoluteExpense3Balance = await weiTable.balanceAt(AbsoluteExpense3Id); - assert.equal(absoluteExpense3Balance.toNumber(), 3 * money, 'resource point received money from splitter'); + var absoluteExpense3Balance = await table.balanceAt(AbsoluteExpense3Id); + assert.equal(absoluteExpense3Balance.toNumber(), 3 * multiplier, 'resource point received from splitter'); }); -}); +}); \ No newline at end of file