def test_currentBalanceSum(self): """ Testing the value of currentBalanceSum works as intended, Further testing involving this and fee collection will be done in scenario testing """ fee_period = self.targetFeePeriodDurationSeconds() delay = int(fee_period / 10) alice = fresh_account() self.assertEquals(self.balanceOf(alice), 0) start_amt = UNIT * 50 self.endow(MASTER, alice, start_amt) self.assertEquals(self.balanceOf(alice), start_amt) self.assertEquals(self.currentBalanceSum(alice), 0) start_time = block_time() fast_forward(delay) self.adjustFeeEntitlement(alice, alice, self.balanceOf(alice)) end_time = block_time() balance_sum = (end_time - start_time) * start_amt self.assertEquals(self.currentBalanceSum(alice), balance_sum) self.transfer(alice, self.havven_real.address, start_amt) self.assertEquals(self.balanceOf(alice), 0) fast_forward(delay) self.adjustFeeEntitlement(alice, alice, self.balanceOf(alice)) self.assertClose(self.currentBalanceSum(alice), balance_sum)
def test_arithmeticSeriesBalance(self): alice = fresh_account() fee_period = self.havven.feePeriodDuration() n = 50 self.havven.endow(MASTER, alice, n * UNIT) self.havven_updatePrice(self.havven.oracle(), UNIT, block_time()) self.havven.setIssuer(MASTER, alice, True) self.havven.issueNomins(alice, n * UNIT // 20) time_remaining = self.havven.feePeriodDuration( ) + self.havven.feePeriodStartTime() - block_time() fast_forward(time_remaining + 5) self.havven.rolloverFeePeriodIfElapsed(MASTER) for _ in range(n): self.havven.burnNomins(alice, UNIT // 20) fast_forward(fee_period // n) fast_forward(n) # fast forward allow the rollover to happen self.havven.rolloverFeePeriodIfElapsed(MASTER) self.havven.recomputeLastAverageBalance(alice, alice) self.assertClose(self.havven.issuanceLastAverageBalance(alice), n * (n - 1) * UNIT // (2 * n * 20), precision=3)
def test_currentBalanceSum(self): # Testing the value of currentBalanceSum works as intended, # Further testing involving this and fee collection will be done # in scenario testing fee_period = self.havven.feePeriodDuration() delay = int(fee_period / 10) alice = fresh_account() self.assertEqual(self.havven.balanceOf(alice), 0) start_amt = UNIT * 50 self.havven.endow(MASTER, alice, start_amt) self.havven.setIssuer(MASTER, alice, True) self.havven_updatePrice(MASTER, UNIT, block_time() + 1) self.havven.setIssuanceRatio(MASTER, UNIT) self.havven.issueNomins(alice, start_amt) self.assertEqual(self.havven.balanceOf(alice), start_amt) self.assertEqual(self.nomin.balanceOf(alice), start_amt) self.assertEqual(self.havven.issuanceCurrentBalanceSum(alice), 0) start_time = block_time() fast_forward(delay) self.havven.recomputeLastAverageBalance(alice, alice) end_time = block_time() balance_sum = (end_time - start_time) * start_amt self.assertEqual(self.havven.issuanceCurrentBalanceSum(alice), balance_sum) self.havven.burnNomins(alice, start_amt) self.assertEqual(self.nomin.balanceOf(alice), 0) fast_forward(delay) self.havven.recomputeLastAverageBalance(alice, alice) self.assertClose(self.havven.issuanceCurrentBalanceSum(alice), balance_sum)
def test_withdrawHalfFees(self): self.h_endow(MASTER, self.escrow.address, self.h_totalSupply() - (100 * UNIT)) self.h_endow(MASTER, MASTER, 100 * UNIT) self.appendVestingEntry(MASTER, MASTER, block_time() + 100000, self.h_totalSupply() // 2) self.appendVestingEntry(MASTER, DUMMY, block_time() + 100000, self.h_totalSupply() // 2) self.make_nomin_velocity() uncollected = self.n_feePool() self.assertClose(uncollected, 36 * UNIT) self.assertEqual(self.feePool(), 0) # Skip a period so we have a full period with no transfers target_period = self.h_targetFeePeriodDurationSeconds() + 1000 fast_forward(seconds=target_period) # Zero value transfer to roll over the fee period self.h_transfer(MASTER, self.escrow.address, 0) fast_forward(seconds=target_period) # Since escrow contract has most of the global supply, and half of the # escrowed balance, they should get half of the fees. self.withdrawFees(MASTER) self.assertClose(self.n_balanceOf(MASTER), self.n_priceToSpend(18 * UNIT))
def test_withdrawHalfFees(self): self.havven.endow(MASTER, self.escrow.contract.address, self.havven.totalSupply()) self.escrow.appendVestingEntry(MASTER, MASTER, block_time() + 100000, self.havven.totalSupply() // 2) self.escrow.appendVestingEntry(MASTER, DUMMY, block_time() + 100000, self.havven.totalSupply() // 2) self.havven_updatePrice(self.havven.oracle(), UNIT, self.havven.currentTime() + 1) self.havven.setIssuer(MASTER, MASTER, True) self.havven.issueNomins(MASTER, UNIT) # generate 1 UNIT of fees self.havven.setIssuer(MASTER, DUMMY, True) self.havven.issueNomins(DUMMY, UNIT) self.nomin.donateToFeePool(DUMMY, UNIT) fees = self.nomin.feePool() # Skip a period so we have a full period with no transfers fast_forward(self.havven.feePeriodDuration() + 100) self.havven.rolloverFeePeriodIfElapsed(MASTER) self.havven.recomputeLastAverageBalance(MASTER, MASTER) # Since escrow contract has most of the global supply, and half of the # escrowed balance, they should get half of the fees. self.havven.withdrawFees(MASTER) self.assertClose(self.nomin.balanceOf(MASTER) - UNIT, fees / 2) self.havven.withdrawFees(DUMMY) self.assertClose(self.nomin.balanceOf(DUMMY), fees / 2)
def test_event_FeePeriodRollover(self): time = block_time() fee_period = self.havven.feePeriodDuration() fast_forward(fee_period + 10) tx = self.havven.rolloverFeePeriodIfElapsed(MASTER) time = block_time(tx.blockNumber) self.assertEventEquals(self.event_map, tx.logs[0], "FeePeriodRollover", {"timestamp": time}, self.havven_proxy.address)
def test_addRegularVestingSchedule(self): alice, bob, carol, tim, pim = fresh_accounts(5) self.h_endow(MASTER, self.escrow.address, 100 * UNIT) time = block_time() self.addRegularVestingSchedule(MASTER, alice, time + to_seconds(weeks=52), 100 * UNIT, 4) self.assertEqual(self.numVestingEntries(alice), 4) self.vest(alice) self.assertEqual(self.h_balanceOf(alice), 0) fast_forward(to_seconds(weeks=13) + 10) self.vest(alice) self.assertEqual(self.h_balanceOf(alice), 25 * UNIT) fast_forward(to_seconds(weeks=13) + 10) self.vest(alice) self.assertEqual(self.h_balanceOf(alice), 50 * UNIT) fast_forward(to_seconds(weeks=13) + 10) self.vest(alice) self.assertEqual(self.h_balanceOf(alice), 75 * UNIT) fast_forward(to_seconds(weeks=13) + 10) self.vest(alice) self.assertEqual(self.h_balanceOf(alice), 100 * UNIT) fast_forward(to_seconds(weeks=13) + 10) self.vest(alice) self.assertEqual(self.h_balanceOf(alice), 100 * UNIT) time = block_time() + 10000000 bob_periods = 7 self.addRegularVestingSchedule(MASTER, bob, time, UNIT, 7) q = sum(self.getVestingQuantity(bob, i) for i in range(bob_periods)) self.assertEqual(q, UNIT) self.assertEqual(self.getVestingTime(bob, bob_periods - 1), time, UNIT) self.assertReverts(self.addRegularVestingSchedule, MASTER, carol, block_time() - 1, UNIT, 5) self.assertReverts(self.addRegularVestingSchedule, MASTER, carol, 0, UNIT, 5) self.assertReverts(self.addRegularVestingSchedule, MASTER, carol, block_time() + 100000, UNIT, 0) time = block_time() + 10000 self.appendVestingEntry(MASTER, tim, time, UNIT) self.addRegularVestingSchedule(MASTER, pim, time, UNIT, 1) self.assertEqual(self.numVestingEntries(tim), self.numVestingEntries(pim)) self.assertEqual(self.getVestingTime(tim, 0), self.getVestingTime(pim, 0)) self.assertEqual(self.getVestingQuantity(tim, 0), self.getVestingQuantity(pim, 0))
def test_lastAverageBalance(self): # set the block time to be at least 30seconds away from the end of the fee_period fee_period = self.havven.feePeriodDuration() # fast forward next block with some extra padding delay = fee_period + 1 fast_forward(delay) self.havven.rolloverFeePeriodIfElapsed(DUMMY) alice = fresh_account() self.assertEqual(self.havven.balanceOf(alice), 0) start_amt = UNIT * 50 self.havven.endow(MASTER, alice, start_amt) self.havven.setIssuer(MASTER, alice, True) self.havven_updatePrice(MASTER, UNIT, block_time() + 1) self.havven.setIssuanceRatio(MASTER, UNIT) tx_receipt = self.havven.issueNomins(alice, start_amt) self.assertEqual(self.havven.balanceOf(alice), start_amt) self.assertEqual(self.havven.issuanceCurrentBalanceSum(alice), 0) self.assertEqual(self.havven.issuanceLastAverageBalance(alice), 0) self.assertEqual(self.havven.issuanceLastModified(alice), block_time(tx_receipt['blockNumber'])) fast_forward(delay) self.havven.rolloverFeePeriodIfElapsed(DUMMY) fast_forward(fee_period // 2) tx_receipt = self.havven.recomputeLastAverageBalance(alice, alice) block_number = tx_receipt['blockNumber'] duration_since_rollover = block_time( block_number) - self.havven.feePeriodStartTime() balance_sum = duration_since_rollover * start_amt actual = self.havven.issuanceCurrentBalanceSum(alice) expected = balance_sum self.assertClose(actual, expected) time_remaining = self.havven.feePeriodDuration( ) + self.havven.feePeriodStartTime() - block_time() fast_forward(time_remaining - 5) self.havven.burnNomins(alice, start_amt // 2) time_remaining = self.havven.feePeriodDuration( ) + self.havven.feePeriodStartTime() - block_time() fast_forward(time_remaining + 10) self.havven.rolloverFeePeriodIfElapsed(alice) self.havven.recomputeLastAverageBalance(alice, alice) actual = self.havven.issuanceLastAverageBalance(alice) expected = (start_amt * delay) // (self.havven.feePeriodStartTime() - self.havven.lastFeePeriodStartTime()) self.assertClose(actual, expected)
def test_appendVestingEntry(self): alice, bob = fresh_accounts(2) escrow_balance = 20 * UNIT amount = 10 self.havven.endow(MASTER, self.escrow.contract.address, escrow_balance) time = block_time() # Should not be able to add a vestingEntry > havven.totalSupply() self.assertReverts(self.escrow.appendVestingEntry, MASTER, alice, time + to_seconds(weeks=2), self.havven.totalSupply() + 1) # Should not be able to add a vestingEntry > balanceOf escrow account self.assertReverts(self.escrow.appendVestingEntry, MASTER, alice, time + to_seconds(weeks=2), escrow_balance + 1) # Should not be able to vest in the past self.assertReverts(self.escrow.appendVestingEntry, MASTER, alice, 0, UNIT) self.assertReverts(self.escrow.appendVestingEntry, MASTER, alice, time - 1, UNIT) self.assertReverts(self.escrow.appendVestingEntry, MASTER, alice, time, UNIT) # Vesting quantities should be nonzero self.assertReverts(self.escrow.appendVestingEntry, MASTER, alice, time + to_seconds(weeks=2), 0) self.escrow.appendVestingEntry(MASTER, alice, time + to_seconds(weeks=2), amount) self.escrow.vest(alice) self.assertEqual(self.havven.balanceOf(alice), 0) fast_forward(weeks=3) self.escrow.vest(alice) self.assertEqual(self.havven.balanceOf(alice), amount) self.havven.transfer(alice, MASTER, amount) time = block_time() t1 = time + to_seconds(weeks=1) t2 = time + to_seconds(weeks=2) self.escrow.appendVestingEntry(MASTER, alice, t1, amount) self.assertReverts(self.escrow.appendVestingEntry, MASTER, alice, time + to_seconds(days=1), amount) self.assertReverts(self.escrow.appendVestingEntry, MASTER, alice, time + to_seconds(weeks=1), amount) self.escrow.appendVestingEntry(MASTER, alice, t2, amount + 1) self.assertEqual(self.escrow.getVestingQuantity(alice, 1), amount) self.assertEqual(self.escrow.getVestingQuantity(alice, 2), amount + 1) self.assertEqual(self.escrow.getVestingTime(alice, 1), t1) self.assertEqual(self.escrow.getVestingTime(alice, 2), t2) self.assertEqual(self.escrow.numVestingEntries(alice), 3)
def test_collateral(self): alice, bob, charlie, debbie = fresh_accounts(4) self.havven.endow(MASTER, alice, UNIT) self.havven.endow(MASTER, bob, UNIT) self.havven.endow(MASTER, self.escrow.contract.address, 2 * UNIT) self.escrow.appendVestingEntry(MASTER, alice, block_time() + 10000000, UNIT) self.escrow.appendVestingEntry(MASTER, charlie, block_time() + 10000000, UNIT) self.assertEqual(self.havven.collateral(alice), 2 * UNIT) self.assertEqual(self.havven.collateral(bob), UNIT) self.assertEqual(self.havven.collateral(charlie), UNIT) self.assertEqual(self.havven.collateral(debbie), 0)
def test_event_PriceUpdated(self): time = block_time() tx = self.havven_updatePrice(self.havven.oracle(), 10 * UNIT, time) self.assertEventEquals(self.event_map, tx.logs[0], "PriceUpdated", { "newPrice": 10 * UNIT, "timestamp": time }, self.havven_proxy.address)
def test_escrowedFees(self): self.havven.endow(MASTER, self.escrow.contract.address, self.havven.totalSupply()) self.escrow.appendVestingEntry(MASTER, MASTER, block_time() + 100000, self.havven.totalSupply()) self.havven_updatePrice(self.havven.oracle(), UNIT, self.havven.currentTime() + 1) self.havven.setIssuer(MASTER, MASTER, True) self.havven.issueNomins(MASTER, UNIT) # generate 1 UNIT of fees self.nomin.donateToFeePool(MASTER, UNIT) fees = self.nomin.feePool() # Skip a period so we have a full period with no transfers fast_forward(self.havven.feePeriodDuration() + 100) self.havven.rolloverFeePeriodIfElapsed(MASTER) self.havven.recomputeLastAverageBalance(MASTER, MASTER) # Skip a period so we have a full period with no transfers fast_forward(self.havven.feePeriodDuration() + 100) self.havven.rolloverFeePeriodIfElapsed(MASTER) self.havven.recomputeLastAverageBalance(MASTER, MASTER) self.assertEqual(fees, self.havven.lastFeesCollected()) self.havven.withdrawFees(MASTER) self.assertEqual(self.nomin.feePool(), 0) self.assertEqual(self.nomin.balanceOf(MASTER), fees)
def test_cannotExchangeEtherForHavvensIfPriceStale(self): amount = 10 * UNIT havvenAmount = 10000 * UNIT exchanger = self.participantAddresses[0] startingFundsWalletEthBalance = get_eth_balance(self.fundsWallet) # Push a price update self.issuanceController.setPriceStalePeriod(self.contractOwner, 1) timeSent = block_time() self.issuanceController.updatePrices(self.oracleAddress, self.usdToEthPrice, self.usdToHavPrice, timeSent) # Wait so the lastPriceUpdateTime is different to now fast_forward(2) # Set up the contract so it contains some havvens for folks to convert Ether for self.havven.endow(MASTER, self.issuanceControllerContract.address, havvenAmount) self.assertEqual( self.havven.balanceOf(self.issuanceControllerContract.address), havvenAmount) # Attempt transfer self.assertReverts(self.issuanceController.exchangeEtherForHavvens, exchanger, amount) endingFundsWalletEthBalance = get_eth_balance(self.fundsWallet) self.assertEqual( self.havven.balanceOf(self.issuanceControllerContract.address), havvenAmount) self.assertEqual(self.havven.balanceOf(exchanger), 0) self.assertEqual(startingFundsWalletEthBalance, endingFundsWalletEthBalance)
def test_totalVestedBalance(self): alice, bob = fresh_accounts(2) time = block_time() self.havven.endow(MASTER, self.escrow.contract.address, 100 * UNIT) self.assertEqual(self.escrow.totalVestedBalance(), 0) self.escrow.appendVestingEntry(MASTER, bob, time + 100, UNIT) self.assertEqual(self.escrow.totalVestedBalance(), UNIT) self.escrow.appendVestingEntry(MASTER, alice, time + 100, UNIT) self.assertEqual(self.escrow.totalVestedBalance(), 2 * UNIT) self.escrow.purgeAccount(MASTER, alice) self.assertEqual(self.escrow.totalVestedBalance(), UNIT) k = 5 for n in [100 * 2**i for i in range(k)]: self.escrow.appendVestingEntry(MASTER, alice, time + n, n) self.assertEqual(self.escrow.totalVestedBalance(), UNIT + 100 * (2**k - 1)) fast_forward(110) self.escrow.vest(alice) self.assertEqual(self.escrow.totalVestedBalance(), UNIT + 100 * (2**k - 1) - 100)
def test_cannotExchangeNominsForHavvensIfPriceStale(self): exchanger = self.participantAddresses[0] nominsToTransfer = 20 * UNIT self.issuanceController.setPriceStalePeriod(self.contractOwner, 1) # Set up the contract so it contains some nomins and havvens self.nomin.giveNomins(MASTER, exchanger, nominsToTransfer) self.assertEqual(self.nomin.balanceOf(exchanger), nominsToTransfer) self.havven.endow(MASTER, self.issuanceControllerContract.address, 1000 * UNIT) self.assertEqual( self.havven.balanceOf(self.issuanceControllerContract.address), 1000 * UNIT) timeSent = block_time() self.issuanceController.updatePrices(self.oracleAddress, self.usdToEthPrice, self.usdToHavPrice, timeSent) fast_forward(2) # Attempt transfer self.nomin.approve(exchanger, self.issuanceControllerContract.address, nominsToTransfer) self.assertReverts(self.issuanceController.exchangeNominsForHavvens, exchanger, nominsToTransfer) self.assertEqual(self.nomin.balanceOf(exchanger), nominsToTransfer) self.assertEqual( self.havven.balanceOf(self.issuanceControllerContract.address), 1000 * UNIT)
def test_cannotExchangeEtherForNominsIfPriceStale(self): amount = 10 * UNIT nominsBalance = (amount * self.usdToEthPrice) // UNIT base = self.nomin.amountReceived(nominsBalance) self.issuanceController.setPriceStalePeriod(self.contractOwner, 1) timeSent = block_time() self.issuanceController.updatePrices(self.oracleAddress, self.usdToEthPrice, self.usdToHavPrice, timeSent) exchanger = self.participantAddresses[0] startingFundsWalletEthBalance = get_eth_balance(self.fundsWallet) fast_forward(2) # Wait so the lastPriceUpdateTime is different to now # Set up the contract so it contains some nomins for folks to convert Ether for self.nomin.giveNomins(MASTER, self.issuanceControllerContract.address, nominsBalance) self.assertEqual( self.nomin.balanceOf(self.issuanceControllerContract.address), nominsBalance) # Attmpt transfer self.assertReverts(self.issuanceController.exchangeEtherForNomins, exchanger, amount) endingFundsWalletEthBalance = get_eth_balance(self.fundsWallet) self.assertEqual( self.nomin.balanceOf(self.issuanceControllerContract.address), nominsBalance) self.assertEqual(self.nomin.balanceOf(exchanger), 0) self.assertEqual(self.nomin.feePool(), 0) self.assertEqual(startingFundsWalletEthBalance, endingFundsWalletEthBalance)
def test_transferableHavvens(self): alice = fresh_account() self.havven.setIssuer(MASTER, alice, True) self.havven.endow(MASTER, alice, 300 * UNIT) self.havven.endow(MASTER, self.escrow.contract.address, 100 * UNIT) self.escrow.appendVestingEntry(MASTER, alice, block_time() + 10000000, 100 * UNIT) self.havven_updatePrice(self.havven.oracle(), UNIT, self.havven.currentTime() + 1) self.havven.issueNomins(alice, 5 * UNIT) self.assertEqual(self.havven.transferableHavvens(alice), 300 * UNIT) self.havven_updatePrice(self.havven.oracle(), 2 * UNIT, self.havven.currentTime() + 2) self.assertEqual(self.havven.transferableHavvens(alice), 300 * UNIT) self.havven_updatePrice(self.havven.oracle(), UNIT // 2, self.havven.currentTime() + 3) self.assertEqual(self.havven.transferableHavvens(alice), 200 * UNIT) self.havven_updatePrice(self.havven.oracle(), UNIT // 4, self.havven.currentTime() + 4) self.assertEqual(self.havven.transferableHavvens(alice), 0 * UNIT) self.havven_updatePrice(self.havven.oracle(), UNIT // 8, self.havven.currentTime() + 5) self.assertEqual(self.havven.transferableHavvens(alice), 0 * UNIT)
def test_transferFrom_locked_havvens(self): alice, bob, charlie = fresh_accounts(3) self.havven.approve(alice, charlie, 2**256 - 1) self.havven.endow(MASTER, alice, 500 * UNIT) self.havven.endow(MASTER, self.escrow.contract.address, 500 * UNIT) self.escrow.appendVestingEntry(MASTER, alice, block_time() + 10000000, 500 * UNIT) self.havven.setIssuer(MASTER, alice, True) self.havven_updatePrice(self.havven.oracle(), UNIT, self.havven.currentTime() + 1) self.havven.setIssuanceRatio(MASTER, UNIT) self.havven.issueNomins(alice, 400 * UNIT) self.havven.transferFrom(charlie, alice, bob, 500 * UNIT) self.havven.endow(MASTER, alice, 500 * UNIT) self.havven.issueNomins(alice, 100 * UNIT) self.havven.transferFrom(charlie, alice, bob, 500 * UNIT) self.havven.endow(MASTER, alice, 500 * UNIT) self.havven.issueNomins(alice, 100 * UNIT) self.assertReverts(self.havven.transferFrom, charlie, alice, bob, 500 * UNIT) self.havven.transferFrom(charlie, alice, bob, 400 * UNIT) self.havven.endow(MASTER, alice, 400 * UNIT) self.havven.issueNomins(alice, 100 * UNIT) self.assertReverts(self.havven.transferFrom, charlie, alice, bob, 300 * UNIT + 1) self.havven.transferFrom(charlie, alice, bob, 300 * UNIT) self.havven.endow(MASTER, alice, 300 * UNIT) self.havven.issueNomins(alice, 300 * UNIT) self.assertReverts(self.havven.transferFrom, charlie, alice, bob, 1)
def test_initiateSelfDestruct(self): owner = self.sd.owner() notowner = DUMMY self.assertNotEqual(owner, notowner) # Non-owners cannot SD the contract. self.assertReverts(self.sd.initiateSelfDestruct, notowner) # Initiation time starts at 0. self.assertEqual(self.sd.initiationTime(), 0) self.assertFalse(self.sd.selfDestructInitiated()) tx = self.sd.initiateSelfDestruct(owner) # Initiated at the right time. self.assertEqual(self.sd.initiationTime(), block_time(tx['blockNumber'])) self.assertTrue(self.sd.selfDestructInitiated()) # Event is properly emitted. self.assertEventEquals(self.event_map, tx.logs[0], "SelfDestructInitiated", {"selfDestructDelay": self.sd_duration}, location=self.sd_contract.address)
def test_vest(self): alice = fresh_account() self.h_endow(MASTER, self.escrow.address, 100 * UNIT) self.vest(alice) self.assertEqual(self.h_balanceOf(alice), 0) time = block_time() self.appendVestingEntry(MASTER, alice, time + 100, UNIT) self.appendVestingEntry(MASTER, alice, time + 200, UNIT) self.appendVestingEntry(MASTER, alice, time + 300, UNIT) self.appendVestingEntry(MASTER, alice, time + 400, UNIT) self.appendVestingEntry(MASTER, alice, time + 500, UNIT) self.appendVestingEntry(MASTER, alice, time + 600, UNIT) fast_forward(105) self.vest(alice) self.assertEqual(self.h_balanceOf(alice), UNIT) fast_forward(205) self.vest(alice) self.assertEqual(self.h_balanceOf(alice), 3 * UNIT) self.vest(alice) self.assertEqual(self.h_balanceOf(alice), 3 * UNIT) fast_forward(105) self.vest(alice) self.assertEqual(self.h_balanceOf(alice), 4 * UNIT) fast_forward(505) self.vest(alice) self.assertEqual(self.h_balanceOf(alice), 6 * UNIT) self.vest(alice) self.assertEqual(self.h_balanceOf(alice), 6 * UNIT)
def test_purgeAccount(self): alice = fresh_account() time = block_time() + 100 self.h_endow(MASTER, self.escrow.address, 1000 * UNIT) self.appendVestingEntry(MASTER, alice, time, 1000) self.assertReverts(self.purgeAccount, alice, alice) self.assertEqual(self.numVestingEntries(alice), 1) self.assertEqual(self.totalVestedBalance(), 1000) self.assertEqual(self.totalVestedAccountBalance(alice), 1000) self.assertEqual(self.getNextVestingIndex(alice), 0) self.assertEqual(self.getNextVestingTime(alice), time) self.assertEqual(self.getNextVestingQuantity(alice), 1000) tx_receipt = self.purgeAccount(MASTER, alice) self.assertEqual( get_event_data_from_log(self.escrow_event_dict, tx_receipt.logs[0])['event'], 'SchedulePurged') self.assertEqual(self.numVestingEntries(alice), 0) self.assertEqual(self.totalVestedBalance(), 0) self.assertEqual(self.totalVestedAccountBalance(alice), 0) self.assertEqual(self.getNextVestingIndex(alice), 0) self.assertEqual(self.getNextVestingTime(alice), 0) self.assertEqual(self.getNextVestingQuantity(alice), 0)
def test_getVestingScheduleEntry(self): alice = fresh_account() time = block_time() self.h_endow(MASTER, self.escrow.address, 100 * UNIT) self.appendVestingEntry(MASTER, alice, time + 100, 1) self.assertEqual(self.getVestingScheduleEntry(alice, 0), [time + 100, 1])
def test_updatePrices(self): newEthPrice = self.usdToEthPrice + 100 newHavPrice = self.usdToHavPrice + 100 timeSent = block_time() self.issuanceController.updatePrices(self.oracleAddress, newEthPrice, newHavPrice, timeSent) self.assertEqual(self.issuanceController.usdToEthPrice(), newEthPrice) self.assertEqual(self.issuanceController.usdToHavPrice(), newHavPrice) self.assertEqual(self.issuanceController.lastPriceUpdateTime(), timeSent)
def test_updatePricesEvents(self): timeSent = block_time() txr = self.issuanceController.updatePrices(self.oracleAddress, self.usdToEthPrice, self.usdToHavPrice, timeSent) self.assertEventEquals( self.issuanceControllerEventDict, txr.logs[0], 'PricesUpdated', fields={'newEthPrice': self.usdToEthPrice, 'newHavvenPrice': self.usdToHavPrice, 'timeSent': timeSent}, location=self.issuanceControllerContract.address )
def test_maxVestingEntries(self): alice = fresh_account() time = block_time() self.havven.endow(MASTER, self.escrow.contract.address, 200 * UNIT) self.escrow.addRegularVestingSchedule(MASTER, alice, time + to_seconds(weeks=52), 100 * UNIT, 21) self.assertReverts(self.escrow.appendVestingEntry, MASTER, alice, time + to_seconds(weeks=52, days=1), UNIT)
def test_havvenExchangeRate(self): havvenPrice = int(0.5 * UNIT) # 50 cent havvens self.issuanceController.updatePrices(self.oracleAddress, 0, havvenPrice, block_time()) nominsToSend = 10 * UNIT nominsAfterFees = self.nomin.amountReceived(nominsToSend) havvensReceived = self.issuanceController.havvensReceivedForNomins(nominsToSend) self.assertClose(havvensReceived, nominsAfterFees / 0.5)
def test_constructor(self): fee_period = self.havven.feePeriodDuration() self.assertEqual(fee_period, to_seconds(weeks=4)) self.assertGreater(block_time(), 2 * fee_period) self.assertEqual(self.havven.MIN_FEE_PERIOD_DURATION(), to_seconds(days=1)) self.assertEqual(self.havven.MAX_FEE_PERIOD_DURATION(), to_seconds(weeks=26)) self.assertEqual(self.havven.lastFeesCollected(), 0) self.assertEqual(self.havven.nomin(), self.nomin_contract.address) self.assertEqual(self.havven.escrow(), self.escrow_contract.address) self.assertEqual(self.havven.decimals(), 18) self.assertEqual(self.havven.feePeriodStartTime(), block_time(self.construction_block)) self.assertEqual(self.havven.lastFeePeriodStartTime(), block_time(self.construction_block) - fee_period) self.assertEqual(self.havven.lastFeesCollected(), 0) self.assertEqual(self.havven.price(), self.initial_price)
def test_nominExchangeRate(self): ethPrice = 500 * UNIT # $500 ETH self.issuanceController.updatePrices(self.oracleAddress, ethPrice, 0, block_time()) ethToSend = UNIT nominsSent = ethToSend * ethPrice // UNIT nominsReceived = self.nomin.amountReceived(nominsSent) self.assertEqual(self.issuanceController.nominsReceivedForEther(ethToSend), nominsReceived)
def rollover_and_validate(self, duration=None): time = duration if duration is not None else self.havven.feePeriodDuration( ) + 1 fast_forward(time) tx = self.havven.rolloverFeePeriodIfElapsed(DUMMY) rollover_time = block_time(tx.blockNumber) self.assertEventEquals(self.event_map, tx.logs[0], "FeePeriodRollover", {"timestamp": rollover_time}, self.havven_proxy.address)
def test_hasWithdrawnFees(self): issuer = fresh_account() self.havven.endow(MASTER, issuer, UNIT) self.havven.setIssuer(MASTER, issuer, True) self.havven_updatePrice(self.havven.oracle(), UNIT, block_time()) self.havven.issueNomins(issuer, self.havven.maxIssuableNomins(issuer)) self.nomin.generateFees(MASTER, 100 * UNIT) self.rollover_and_validate() self.withdraw_and_validate(issuer)