def test_vestingQuantities(self): alice = fresh_account() time = block_time() times = [time + to_seconds(weeks=i) for i in range(1, 6)] quantities = [UNIT * i for i in range(1, 6)] self.h_endow(MASTER, self.escrow.address, 100 * UNIT) self.appendVestingEntry(MASTER, alice, times[0], quantities[0]) self.assertEqual(self.getVestingQuantity(alice, 0), quantities[0]) for i in range(1, len(times)): self.appendVestingEntry(MASTER, alice, times[i], quantities[i]) for i in range(1, len(times)): self.assertEqual(self.getVestingQuantity(alice, i), quantities[i])
def test_addRegularVestingSchedule(self): alice, bob, carol, tim, pim = fresh_accounts(5) self.h_endow(MASTER, self.escrow.address, 1000 * 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_numVestingEntries(self): alice = fresh_account() time = block_time() times = [time + to_seconds(weeks=i) for i in range(1, 6)] self.h_endow(MASTER, self.escrow.address, 100 * UNIT) self.assertEqual(self.numVestingEntries(alice), 0) self.appendVestingEntry(MASTER, alice, times[0], UNIT) self.assertEqual(self.numVestingEntries(alice), 1) self.appendVestingEntry(MASTER, alice, times[1], UNIT) self.assertEqual(self.numVestingEntries(alice), 2) self.appendVestingEntry(MASTER, alice, times[2], UNIT) self.appendVestingEntry(MASTER, alice, times[3], UNIT) self.appendVestingEntry(MASTER, alice, times[4], UNIT) self.assertEqual(self.numVestingEntries(alice), 5) self.purgeAccount(MASTER, alice) self.assertEqual(self.numVestingEntries(alice), 0)
def test_escrowedFees(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() + to_seconds(weeks=1), self.h_totalSupply() - 100 * UNIT) self.make_nomin_velocity() self.assertClose(self.n_feePool(), 36 * UNIT) target_period = self.h_targetFeePeriodDurationSeconds() + 1000 fast_forward(seconds=target_period) self.h_transfer(MASTER, self.escrow.address, 0) fast_forward(seconds=target_period) self.h_withdrawFeeEntitlement(MASTER) self.assertEqual(self.n_feePool(), 0) self.assertClose(self.n_balanceOf(MASTER), 36 * UNIT)
def test_setFeePeriodDuration(self): self.havven.setFeePeriodDuration(MASTER, to_seconds(weeks=10)) self.assertEqual(self.havven.feePeriodDuration(), to_seconds(weeks=10))
def test_swap_havven(self): alice, bob = fresh_accounts(2) self.havven.endow(MASTER, self.escrow.contract.address, 200 * UNIT) time = block_time() # Set up escrow schedules for alice and bob to test with. self.escrow.addRegularVestingSchedule(MASTER, alice, time + to_seconds(weeks=52), 100 * UNIT, 4) self.escrow.addRegularVestingSchedule(MASTER, bob, time + to_seconds(weeks=52), 100 * UNIT, 4) # Vest alice's first tranche as usual. fast_forward(to_seconds(weeks=13) + 10) self.escrow.vest(alice) self.assertEqual(self.havven.balanceOf(alice), 25 * UNIT) self.assertEqual(self.havven.balanceOf(self.escrow_contract.address), 175 * UNIT) print() # Deploy the new havven contract, with proxy and all. havven_proxy, _ = attempt_deploy(self.compiled, 'Proxy', MASTER, [MASTER]) havven_contract, _ = attempt_deploy( self.compiled, 'PublicHavven', MASTER, [ havven_proxy.address, self.havven_token_state.address, MASTER, MASTER, UNIT // 2, [], ZERO_ADDRESS ]) proxied_havven = W3.eth.contract( address=havven_proxy.address, abi=self.compiled['PublicHavven']['abi']) new_havven = PublicHavvenInterface(proxied_havven, "Havven") # Connect the contracts together. mine_txs([ self.havven_token_state.functions.setAssociatedContract( havven_contract.address).transact({'from': MASTER}), havven_proxy.functions.setTarget(havven_contract.address).transact( {'from': MASTER}) ]) new_havven.setEscrow(MASTER, self.escrow_contract.address) # This should work if the escrow is pointing at the havven proxy. self.escrow.setHavven(MASTER, proxied_havven.address) # Ensure that the new contract is properly up and running, but with the old state. self.assertEqual(new_havven.balanceOf(alice), 25 * UNIT) self.assertEqual(new_havven.balanceOf(bob), 0) tx = new_havven.transfer(alice, bob, 5 * UNIT) self.assertEqual(new_havven.balanceOf(alice), 20 * UNIT) self.assertEqual(new_havven.balanceOf(bob), 5 * UNIT) self.assertEqual(new_havven.balanceOf(self.escrow_contract.address), 175 * UNIT) # And the event emitted properly, from the proxy. self.assertEventEquals(self.havven_event_dict, tx.logs[0], 'Transfer', fields={ 'from': alice, 'to': bob, 'value': 5 * UNIT }, location=havven_proxy.address) # Vest alice's second tranche, but this time on the new contract. fast_forward(to_seconds(weeks=13) + 10) tx = self.escrow.vest(alice) self.assertEventEquals(self.havven_event_dict, tx.logs[0], 'Transfer', fields={ 'from': self.escrow_contract.address, 'to': alice, 'value': 25 * UNIT }, location=havven_proxy.address) self.assertEventEquals(self.escrow_event_dict, tx.logs[1], 'Vested', fields={ 'beneficiary': alice, 'time': block_time(tx['blockNumber']), 'value': 25 * UNIT }, location=self.escrow_contract.address) self.assertEqual(new_havven.balanceOf(alice), 45 * UNIT) self.assertEqual(new_havven.balanceOf(bob), 5 * UNIT) self.assertEqual(new_havven.balanceOf(self.escrow_contract.address), 150 * UNIT) # The stuff should also work if the escrow is pointing at the underlying havven contract fast_forward(to_seconds(weeks=13) + 10) self.escrow.setHavven(MASTER, havven_contract.address) tx = self.escrow.vest(alice) self.assertEventEquals(self.havven_event_dict, tx.logs[0], 'Transfer', fields={ 'from': self.escrow_contract.address, 'to': alice, 'value': 25 * UNIT }, location=havven_proxy.address) self.assertEventEquals(self.escrow_event_dict, tx.logs[1], 'Vested', fields={ 'beneficiary': alice, 'time': block_time(tx['blockNumber']), 'value': 25 * UNIT }, location=self.escrow_contract.address) self.assertEqual(new_havven.balanceOf(alice), 70 * UNIT) self.assertEqual(new_havven.balanceOf(bob), 5 * UNIT) self.assertEqual(new_havven.balanceOf(self.escrow_contract.address), 125 * UNIT) self.escrow.setHavven(MASTER, proxied_havven.address) fast_forward(to_seconds(weeks=13) + 10) tx = self.escrow.vest(alice) self.assertEqual(new_havven.balanceOf(alice), 95 * UNIT) self.assertEqual(new_havven.balanceOf(bob), 5 * UNIT) self.assertEqual(new_havven.balanceOf(self.escrow_contract.address), 100 * UNIT) # Now verify that vesting still works for bob on the new contract, even though he missed some. tx = self.escrow.vest(bob) self.assertEventEquals(self.havven_event_dict, tx.logs[0], 'Transfer', fields={ 'from': self.escrow_contract.address, 'to': bob, 'value': 100 * UNIT }, location=havven_proxy.address) self.assertEventEquals(self.escrow_event_dict, tx.logs[1], 'Vested', fields={ 'beneficiary': bob, 'time': block_time(tx['blockNumber']), 'value': 100 * UNIT }, location=self.escrow_contract.address) self.assertEqual(new_havven.balanceOf(alice), 95 * UNIT) self.assertEqual(new_havven.balanceOf(bob), 105 * UNIT) self.assertEqual(new_havven.balanceOf(self.escrow_contract.address), 0)
def test_setTargetFeePeriod(self): self.setTargetFeePeriodDuration(MASTER, to_seconds(weeks=10)) self.assertEqual(self.targetFeePeriodDurationSeconds(), to_seconds(weeks=10))