def setUpClass(cls): cls.havven_proxy, cls.proxied_havven, cls.nomin_proxy, cls.proxied_nomin, cls.havven_contract, cls.nomin_contract = cls.deployContracts( ) cls.event_map = cls.event_maps['Havven'] cls.havven = PublicHavvenInterface(cls.proxied_havven, "Havven") cls.nomin = PublicNominInterface(cls.proxied_nomin, "Nomin") fast_forward(weeks=102)
def setUpClass(cls): cls.havven_proxy, cls.proxied_havven, cls.havven_token_state, cls.nomin_proxy, cls.proxied_nomin, cls.havven_contract, \ cls.nomin_contract, cls.escrow_contract, cls.construction_block, \ cls.escrow_event_dict, cls.havven_event_dict = cls.deployContracts() cls.event_map = cls.event_maps['HavvenEscrow'] cls.havven = PublicHavvenInterface(cls.proxied_havven, "Havven") cls.nomin = PublicNominInterface(cls.proxied_nomin, "Nomin") cls.escrow = PublicHavvenEscrowInterface(cls.escrow_contract, "HavvenEscrow")
def setUpClass(cls): cls.initial_price = UNIT // 2 cls.havven_proxy, cls.proxied_havven, cls.nomin_proxy, cls.proxied_nomin, cls.havven_contract, cls.nomin_contract, cls.escrow_contract = cls.deployContracts( ) cls.havven = PublicHavvenInterface(cls.proxied_havven, "Havven") cls.nomin = PublicNominInterface(cls.proxied_nomin, "Nomin") cls.escrow = PublicHavvenEscrowInterface(cls.escrow_contract, "HavvenEscrow") cls.havven.setIssuanceRatio(MASTER, UNIT // 20) fast_forward(weeks=102)
def setUpClass(cls): # to avoid overflowing in the negative direction (now - feePeriodDuration * 2) fast_forward(weeks=102) cls.havven_proxy, cls.proxied_havven, cls.nomin_proxy, cls.proxied_nomin, \ cls.havven_contract, cls.nomin_contract, cls.court_contract, \ cls.escrow_contract, cls.construction_block, cls.havven_event_dict = cls.deployContracts() cls.event_map = cls.event_maps['Havven'] cls.havven = PublicHavvenInterface(cls.proxied_havven, "Havven") cls.nomin = PublicNominInterface(cls.proxied_nomin, "Nomin") cls.unproxied_havven = PublicHavvenInterface(cls.havven_contract, "UnproxiedHavven") cls.initial_time = cls.havven.lastFeePeriodStartTime() cls.time_fast_forwarded = 0 cls.base_havven_price = UNIT cls.sd_duration = 4 * 7 * 24 * 60 * 60
def setUpClass(cls): cls.havven_proxy, cls.proxied_havven, cls.nomin_proxy, cls.proxied_nomin, cls.havven_contract, cls.nomin_contract, cls.fake_court_contract, cls.escrow_contract = cls.deployContracts( ) cls.havven = PublicHavvenInterface(cls.proxied_havven, "Havven") cls.nomin = PublicNominInterface(cls.proxied_nomin, "Nomin") cls.escrow = PublicHavvenEscrowInterface(cls.escrow_contract, "HavvenEscrow") fast_forward(weeks=102) cls.fake_court = FakeCourtInterface(cls.fake_court_contract, "FakeCourt") cls.fake_court.setNomin(MASTER, cls.nomin_contract.address)
def setUpClass(cls): addresses = fresh_accounts(6) cls.participantAddresses = addresses[2:] cls.contractOwner = MASTER cls.oracleAddress = addresses[0] cls.fundsWallet = addresses[1] cls.usdToEthPrice = 500 * (10 ** 18) cls.usdToHavPrice = int(0.65 * (10 ** 18)) cls.priceStalePeriod = 3 * 60 * 60 cls.havven_proxy, cls.proxied_havven, cls.nomin_proxy, cls.proxied_nomin, cls.havven_contract, cls.nomin_contract, cls.nomin_abi, cls.issuanceControllerContract = cls.deployContracts() cls.issuanceController = IssuanceControllerInterface(cls.issuanceControllerContract, "IssuanceController") cls.havven = PublicHavvenInterface(cls.havven_contract, "Havven") cls.nomin = PublicNominInterface(cls.nomin_contract, "Nomin") cls.issuanceControllerEventDict = cls.event_maps['IssuanceController']
def setUpClass(cls): addresses = fresh_accounts(6) cls.participantAddresses = addresses[2:] cls.contractOwner = MASTER cls.oracleAddress = addresses[0] cls.fundsWallet = addresses[1] cls.usdToEthPrice = 500 * UNIT cls.usdToHavPrice = int(0.65 * UNIT) cls.priceStalePeriod = 3 * 60 * 60 cls.havven_proxy, cls.proxied_havven, cls.nomin_proxy, cls.proxied_nomin, cls.havven_contract, cls.nomin_contract, cls.nomin_abi, cls.issuanceControllerContract = cls.deployContracts( ) cls.issuanceController = IssuanceControllerInterface( cls.issuanceControllerContract, "IssuanceController") cls.havven = PublicHavvenInterface(cls.havven_contract, "Havven") cls.nomin = PublicNominInterface(cls.nomin_contract, "Nomin") cls.issuanceControllerEventDict = cls.event_maps['IssuanceController'] fast_forward( 1 ) # Give the contract constructor a second between its execution and execution of the other functions.
def test_constructor_migration(self): # Ensure issuers list updates issued balances properly... update deploycontracts above. sources = [ "tests/contracts/PublicHavven.sol", "contracts/Nomin.sol", "contracts/HavvenEscrow.sol" ] print() compiled, event_maps = self.compileAndMapEvents(sources) # Initial issued nomin balances #issuer_addresses = [f"0x{'0'*39}{i+1}" for i in range(10)] issuers_all = fresh_accounts(54) issuers = issuers_all[:2] issuer_balances = [77 * UNIT * i for i in range(10)] total_nomins = sum(issuer_balances) # Deploy contracts havven_proxy, _ = attempt_deploy(compiled, 'Proxy', MASTER, [MASTER]) nomin_proxy, _ = attempt_deploy(compiled, 'Proxy', MASTER, [MASTER]) proxied_havven = W3.eth.contract(address=havven_proxy.address, abi=compiled['PublicHavven']['abi']) proxied_nomin = W3.eth.contract(address=nomin_proxy.address, abi=compiled['Nomin']['abi']) havven_tokenstate, _ = attempt_deploy(compiled, 'TokenState', MASTER, [MASTER, MASTER]) nomin_tokenstate, _ = attempt_deploy(compiled, 'TokenState', MASTER, [MASTER, MASTER]) havven_contract, hvn_txr = attempt_deploy( compiled, 'PublicHavven', MASTER, [ havven_proxy.address, havven_tokenstate.address, MASTER, MASTER, UNIT, [], ZERO_ADDRESS ]) hvn_block = W3.eth.blockNumber nomin_contract, nom_txr = attempt_deploy(compiled, 'Nomin', MASTER, [ nomin_proxy.address, nomin_tokenstate.address, havven_contract.address, 0, MASTER ]) escrow_contract, escrow_txr = attempt_deploy( compiled, 'HavvenEscrow', MASTER, [MASTER, havven_contract.address]) mine_txs([ havven_tokenstate.functions.setBalanceOf( havven_contract.address, 100000000 * UNIT).transact({'from': MASTER}), havven_tokenstate.functions.setAssociatedContract( havven_contract.address).transact({'from': MASTER}), nomin_tokenstate.functions.setAssociatedContract( nomin_contract.address).transact({'from': MASTER}), havven_proxy.functions.setTarget(havven_contract.address).transact( {'from': MASTER}), nomin_proxy.functions.setTarget(nomin_contract.address).transact( {'from': MASTER}), havven_contract.functions.setNomin( nomin_contract.address).transact({'from': MASTER}), nomin_contract.functions.setHavven( havven_contract.address).transact({'from': MASTER}), havven_contract.functions.setEscrow( escrow_contract.address).transact({'from': MASTER}) ]) havven_event_dict = generate_topic_event_map( compiled['PublicHavven']['abi']) havven = PublicHavvenInterface(proxied_havven, "Havven") nomin = PublicNominInterface(proxied_nomin, "Nomin") for i in range(len(issuers)): issuer = issuers[i] havven.endow(MASTER, issuer, 1000 * UNIT) havven.setIssuer(MASTER, issuer, True) mine_txs([ havven_contract.functions.updatePrice( UNIT, block_time() + 1).transact({'from': MASTER}) ]) havven.issueNomins(issuer, i * 10 * UNIT) fast_forward(havven.feePeriodDuration() // 20) for i in range(len(issuers)): issuer = issuers[i] havven.endow(MASTER, issuer, 1000 * UNIT) havven.setIssuer(MASTER, issuer, True) mine_txs([ havven_contract.functions.updatePrice( UNIT, block_time() + 1).transact({'from': MASTER}) ]) havven.issueNomins(issuer, (len(issuers) - 1 - i) * 5 * UNIT) fast_forward(havven.feePeriodDuration() // 15) new_havven_contract, txr = attempt_deploy( compiled, 'PublicHavven', MASTER, [ havven_proxy.address, havven_tokenstate.address, MASTER, MASTER, UNIT, issuers_all, havven_contract.address ]) new_havven = PublicHavvenInterface(new_havven_contract, "Havven") self.assertEqual(havven.totalIssuanceData(), new_havven.totalIssuanceData()) self.assertEqual(havven.feePeriodStartTime(), new_havven.feePeriodStartTime()) self.assertEqual(havven.lastFeePeriodStartTime(), new_havven.lastFeePeriodStartTime()) for issuer in issuers: self.assertEqual(havven.isIssuer(issuer), new_havven.isIssuer(issuer)) self.assertEqual(havven.issuanceData(issuer), new_havven.issuanceData(issuer)) self.assertEqual(havven.nominsIssued(issuer), new_havven.nominsIssued(issuer))
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)