def test_getNextVestingIndex(self): self.h_endow(MASTER, self.escrow.address, 100 * UNIT) alice = fresh_account() time = block_time() times = [time + to_seconds(weeks=i) for i in range(1, 6)] self.assertEqual(self.getNextVestingIndex(alice), 0) for i in range(len(times)): self.appendVestingEntry(MASTER, alice, times[i], UNIT) for i in range(len(times)): fast_forward(to_seconds(weeks=1) + 30) self.assertEqual(self.getNextVestingIndex(alice), i) self.vest(alice) self.assertEqual(self.getNextVestingIndex(alice), i + 1)
def test_getNextVestingQuantity(self): self.h_endow(MASTER, self.escrow.address, 100 * UNIT) alice = fresh_account() time = block_time() entries = [[time + to_seconds(weeks=i), i * UNIT] for i in range(1, 6)] self.assertEqual(self.getNextVestingQuantity(alice), 0) for i in range(len(entries)): self.appendVestingEntry(MASTER, alice, entries[i][0], entries[i][1]) for i in range(len(entries)): fast_forward(to_seconds(weeks=1) + 30) self.assertEqual(self.getNextVestingQuantity(alice), entries[i][1]) self.vest(alice) self.assertEqual(self.getNextVestingQuantity(alice), 0 if i == len(entries) - 1 else entries[i + 1][1])
def test_vestingTimes(self): alice = fresh_account() time = block_time() times = [time + to_seconds(weeks=i) for i in range(1, 6)] self.appendVestingEntry(MASTER, alice, times[0], UNIT) self.assertEqual(self.getVestingTime(alice, 0), times[0]) for i in range(1, len(times)): self.appendVestingEntry(MASTER, alice, times[i], UNIT) for i in range(1, len(times)): self.assertEqual(self.getVestingTime(alice, i), times[i])
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_numVestingEntries(self): alice = fresh_account() time = block_time() times = [time + to_seconds(weeks=i) for i in range(1, 6)] 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_appendVestingEntry(self): alice, bob = fresh_accounts(2) amount = 16 * UNIT self.h_endow(MASTER, self.escrow.address, amount) time = block_time() # Should not be able to vest in the past self.assertReverts(self.appendVestingEntry, MASTER, alice, 0, UNIT) self.assertReverts(self.appendVestingEntry, MASTER, alice, time - 1, UNIT) self.assertReverts(self.appendVestingEntry, MASTER, alice, time, UNIT) # Vesting quantities should be nonzero self.assertReverts(self.appendVestingEntry, MASTER, alice, time + to_seconds(weeks=2), 0) self.appendVestingEntry(MASTER, alice, time + to_seconds(weeks=2), amount) self.vest(alice) self.assertEqual(self.h_balanceOf(alice), 0) fast_forward(weeks=3) self.vest(alice) self.assertEqual(self.h_balanceOf(alice), amount) self.h_transfer(alice, MASTER, amount) time = block_time() t1 = time + to_seconds(weeks=1) t2 = time + to_seconds(weeks=2) self.appendVestingEntry(MASTER, alice, t1, amount) self.assertReverts(self.appendVestingEntry, MASTER, alice, time + to_seconds(days=1), amount) self.assertReverts(self.appendVestingEntry, MASTER, alice, time + to_seconds(weeks=1), amount) self.appendVestingEntry(MASTER, alice, t2, amount + 1) self.assertEqual(self.getVestingQuantity(alice, 1), amount) self.assertEqual(self.getVestingQuantity(alice, 2), amount + 1) self.assertEqual(self.getVestingTime(alice, 1), t1) self.assertEqual(self.getVestingTime(alice, 2), t2) self.assertEqual(self.numVestingEntries(alice), 3)
def fast_forward(seconds=0, minutes=0, hours=0, days=0, weeks=0): global time_fast_forwarded total_time = to_seconds(seconds, minutes, hours, days, weeks) time_fast_forwarded += total_time W3.providers[0].make_request("evm_increaseTime", [total_time]) force_mine_block()
def test_setupDuration(self): self.assertEqual(self.contractConstructionTime + to_seconds(weeks=1), self.setupExpiryTime())
def test_setupDuration(self): self.assertEqual(to_seconds(weeks=1), self.setupDuration())