From 17c27d717e6ae99fe7542554832db6a1a538a151 Mon Sep 17 00:00:00 2001 From: enkogu Date: Mon, 8 Oct 2018 13:54:36 +0800 Subject: [PATCH] #355:Infinite fund --- contracts/moneyflow/ether/WeiFund.sol | 17 ++++++++++++++--- test/moneyflow/wei_fund.tests.js | 3 +-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/contracts/moneyflow/ether/WeiFund.sol b/contracts/moneyflow/ether/WeiFund.sol index 4b950b6..7532b03 100644 --- a/contracts/moneyflow/ether/WeiFund.sol +++ b/contracts/moneyflow/ether/WeiFund.sol @@ -33,7 +33,7 @@ contract WeiFund is IWeiReceiver, IDestination, Ownable { require(!((_isAccumulateDebt)&&(_periodHours==0))); require(!(!(_isPeriodic)&&(_periodHours!=0))); require(!((_isAccumulateDebt)&&(!_isPeriodic))); - require(_neededWei!=0); + require(!((_neededWei==0)&&(_isPeriodic))); neededWei = _neededWei; isPeriodic = _isPeriodic; isAccumulateDebt = _isAccumulateDebt; @@ -60,9 +60,11 @@ contract WeiFund is IWeiReceiver, IDestination, Ownable { function processFunds(uint _currentFlow) public payable { // emit consoleUint('_getDebtMultiplier', _getDebtMultiplier()); require(isNeedsMoney()); + + if(neededWei!=0){ + require(totalWeiReceived+msg.value<=getDebtMultiplier()*neededWei); // protect from extra money + } - require(totalWeiReceived+msg.value<=getDebtMultiplier()*neededWei); // protect from extra money - // require(msg.value==_currentFlow); totalWeiReceived += msg.value; if(getTotalWeiNeeded(msg.value)==0) { momentReceived = block.timestamp; @@ -72,6 +74,11 @@ contract WeiFund is IWeiReceiver, IDestination, Ownable { function getTotalWeiNeeded(uint _inputWei)public view returns(uint) { uint need; + + if(neededWei==0){ + return _inputWei; + } + if(getDebtMultiplier()*neededWei > totalWeiReceived) { need = getDebtMultiplier()*neededWei - totalWeiReceived; }else { @@ -94,6 +101,10 @@ contract WeiFund is IWeiReceiver, IDestination, Ownable { } function isNeedsMoney()public view returns(bool) { + if(neededWei==0){ + return true; + } + return getDebtMultiplier()*neededWei > totalWeiReceived; } diff --git a/test/moneyflow/wei_fund.tests.js b/test/moneyflow/wei_fund.tests.js index d0122db..dacb91b 100644 --- a/test/moneyflow/wei_fund.tests.js +++ b/test/moneyflow/wei_fund.tests.js @@ -48,7 +48,6 @@ contract('WeiFund', (accounts) => { }); it('Should not create fund with wrong args', async () => { - await WeiFund.new(0, false, false, 0).should.be.rejectedWith('revert'); await WeiFund.new(1e18, true, true, 0).should.be.rejectedWith('revert'); await WeiFund.new(1e18, false, true, 24).should.be.rejectedWith('revert'); await WeiFund.new(1e18, false, true, 0).should.be.rejectedWith('revert'); @@ -296,7 +295,7 @@ contract('WeiFund', (accounts) => { let milestone1 = await WeiFund.new(0.1e18, false, false, 0); let milestone2 = await WeiFund.new(0.2e18, false, false, 0); let milestone3 = await WeiFund.new(0.7e18, false, false, 0); - let stabFund = await WeiRelativeExpenseWithPeriod.new(1000000, 0, false); + let stabFund = await WeiFund.new(0, false, false, 0); await splitter.addChild(milestone1.address); await splitter.addChild(milestone2.address); await splitter.addChild(milestone3.address);