def deploy_contracts(cls): sources = [ 'tests/contracts/PublicEST.sol', 'contracts/ExternStateToken.sol', 'contracts/TokenState.sol', 'contracts/Proxy.sol' ] compiled, cls.event_maps = cls.compileAndMapEvents(sources) proxy_contract, _ = attempt_deploy(compiled, "Proxy", MASTER, [MASTER]) tokenstate, _ = attempt_deploy(compiled, 'TokenState', MASTER, [MASTER, MASTER]) token_contract, construction_txr = attempt_deploy( compiled, 'PublicEST', MASTER, [ proxy_contract.address, "Test Token", "TEST", 1000 * UNIT, tokenstate.address, MASTER ]) token_abi = compiled['PublicEST']['abi'] token_event_dict = generate_topic_event_map(token_abi) proxied_token = W3.eth.contract(address=proxy_contract.address, abi=token_abi) mine_txs([ tokenstate.functions.setBalanceOf(MASTER, 1000 * UNIT).transact( {'from': MASTER}), tokenstate.functions.setAssociatedContract( token_contract.address).transact({'from': MASTER}), proxy_contract.functions.setTarget( token_contract.address).transact({'from': MASTER}) ]) return proxy_contract, proxied_token, compiled, token_contract, token_abi, token_event_dict, tokenstate
def test_change_state(self): lucky_one = fresh_account() print() # Deploy contract and old tokenstate _old_tokenstate, _ = attempt_deploy(self.compiled, 'TokenState', MASTER, [MASTER, MASTER]) old_tokenstate = TokenStateInterface(_old_tokenstate, 'TokenState') _token, _ = attempt_deploy(self.compiled, 'ExternStateToken', MASTER, [ self.proxy.address, old_tokenstate.contract.address, "Test Token", "TEST", 1000 * UNIT, 18, MASTER ]) token = ExternStateTokenInterface(_token, 'ExternStateToken') mine_txs([ self.proxy.functions.setTarget(token.contract.address).transact( {"from": MASTER}) ]) old_tokenstate.setAssociatedContract(MASTER, token.contract.address) self.assertEqual(token.balanceOf(lucky_one), 0) self.assertEqual(old_tokenstate.balanceOf(lucky_one), 0) # Deploy new tokenstate and swap it out with the existing one. _new_tokenstate, _ = attempt_deploy(self.compiled, 'TokenState', MASTER, [MASTER, MASTER]) new_tokenstate = TokenStateInterface(_new_tokenstate, 'TokenState') new_tokenstate.setBalanceOf(MASTER, lucky_one, UNIT) new_tokenstate.setAssociatedContract(MASTER, token.contract.address) token.setTokenState(MASTER, new_tokenstate.contract.address) self.assertEqual(token.tokenState(), new_tokenstate.contract.address) self.assertEqual(token.balanceOf(lucky_one), UNIT) self.assertEqual(new_tokenstate.balanceOf(lucky_one), UNIT)
def deploy_public_court(): print("Deployment Initiated. \n") compiled = attempt(compile_contracts, [SOLIDITY_SOURCES], "Compiling contracts...") court_abi = compiled['PublicCourt']['abi'] havven_contract, havven_txr = attempt_deploy(compiled, 'PublicHavven', MASTER, [MASTER]) nomin_contract, nomin_txr = attempt_deploy( compiled, 'EtherNomin', MASTER, [havven_contract.address, MASTER, MASTER, 1000 * UNIT, MASTER]) court_contract, court_txr = attempt_deploy( compiled, 'PublicCourt', MASTER, [havven_contract.address, nomin_contract.address, MASTER]) txs = [ havven_contract.functions.setNomin(nomin_contract.address).transact( {'from': MASTER}), nomin_contract.functions.setCourt(court_contract.address).transact( {'from': MASTER}) ] attempt(mine_txs, [txs], "Linking contracts... ") print("\nDeployment complete.\n") return havven_contract, nomin_contract, court_contract, court_abi
def deploy_public_contracts(): print("Deployment initiated.\n") compiled = attempt(compile_contracts, [SOLIDITY_SOURCES], "Compiling contracts... ") # Deploy contracts havven_contract, hvn_txr = attempt_deploy(compiled, 'PublicHavven', MASTER, [MASTER]) nomin_contract, nom_txr = attempt_deploy( compiled, 'PublicEtherNomin', MASTER, [havven_contract.address, MASTER, MASTER, 1000 * UNIT, MASTER]) court_contract, court_txr = attempt_deploy( compiled, 'FakeCourt', MASTER, [havven_contract.address, nomin_contract.address, MASTER]) # Hook up each of those contracts to each other txs = [ havven_contract.functions.setNomin(nomin_contract.address).transact( {'from': MASTER}), nomin_contract.functions.setCourt(court_contract.address).transact( {'from': MASTER}) ] attempt(mine_txs, [txs], "Linking contracts... ") print("\nDeployment complete.\n") return havven_contract, nomin_contract, court_contract
def deploy_public_havven(): print("Deployment initiated.\n") compiled = attempt(compile_contracts, [SOLIDITY_SOURCES], "Compiling contracts... ") # Deploy contracts havven_contract, hvn_txr = attempt_deploy(compiled, 'PublicHavven', MASTER, [MASTER]) hvn_block = W3.eth.blockNumber nomin_contract, nom_txr = attempt_deploy( compiled, 'EtherNomin', MASTER, [havven_contract.address, MASTER, MASTER, 1000 * UNIT, MASTER]) court_contract, court_txr = attempt_deploy( compiled, 'Court', MASTER, [havven_contract.address, nomin_contract.address, MASTER]) escrow_contract, escrow_txr = attempt_deploy( compiled, 'HavvenEscrow', MASTER, [MASTER, havven_contract.address, nomin_contract.address]) # Hook up each of those contracts to each other txs = [ havven_contract.functions.setNomin(nomin_contract.address).transact( {'from': MASTER}), nomin_contract.functions.setCourt(court_contract.address).transact( {'from': MASTER}) ] attempt(mine_txs, [txs], "Linking contracts... ") havven_event_dict = generate_topic_event_map( compiled['PublicHavven']['abi']) print("\nDeployment complete.\n") return havven_contract, nomin_contract, court_contract, escrow_contract, hvn_block, havven_event_dict
def test_provide_state(self): tokenstate, _ = attempt_deploy(self.compiled, 'TokenState', MASTER, [MASTER, self.token_contract.address]) token, _ = attempt_deploy(self.compiled, 'ExternStateToken', MASTER, [ self.proxy.address, "Test Token", "TEST", 1000 * UNIT, tokenstate.address, DUMMY ]) self.assertEqual(token.functions.tokenState().call(), tokenstate.address)
def setUpClass(cls): cls.assertReverts = assertReverts cls.the_owner = DUMMY cls.compiled = compile_contracts( [ExternStateProxyToken_SOURCE, TokenState_SOURCE, Proxy_SOURCE], remappings=['""=contracts']) cls.token_abi = cls.compiled['PublicExternStateProxyToken']['abi'] cls.token_event_dict = generate_topic_event_map(cls.token_abi) cls.token_real, cls.construction_txr = attempt_deploy( cls.compiled, 'PublicExternStateProxyToken', MASTER, [ "Test Token", "TEST", 1000 * UNIT, cls.the_owner, ZERO_ADDRESS, cls.the_owner ]) cls.tokenstate = W3.eth.contract( address=cls.token_real.functions.state().call(), abi=cls.compiled['TokenState']['abi']) mine_tx( cls.token_real.functions.setState(cls.tokenstate.address).transact( {'from': cls.the_owner})) cls.tokenproxy, _ = attempt_deploy( cls.compiled, 'Proxy', MASTER, [cls.token_real.address, cls.the_owner]) mine_tx( cls.token_real.functions.setProxy(cls.tokenproxy.address).transact( {'from': cls.the_owner})) cls.token = W3.eth.contract( address=cls.tokenproxy.address, abi=cls.compiled['PublicExternStateProxyToken']['abi']) cls.owner = lambda self: cls.token.functions.owner().call() cls.totalSupply = lambda self: cls.token.functions.totalSupply().call() cls.state = lambda self: cls.token.functions.state().call() cls.name = lambda self: cls.token.functions.name().call() cls.symbol = lambda self: cls.token.functions.symbol().call() cls.balanceOf = lambda self, account: cls.token.functions.balanceOf( account).call() cls.allowance = lambda self, account, spender: cls.token.functions.allowance( account, spender).call() cls.setState = lambda self, sender, new_state: mine_tx( cls.token.functions.setState(new_state).transact({'from': sender})) cls.transfer_byProxy = lambda self, sender, to, value: mine_tx( cls.token.functions.transfer_byProxy(to, value).transact( {'from': sender})) cls.approve = lambda self, sender, spender, value: mine_tx( cls.token.functions.approve(spender, value).transact( {'from': sender})) cls.transferFrom_byProxy = lambda self, sender, fromAccount, to, value: mine_tx( cls.token.functions.transferFrom_byProxy(fromAccount, to, value). transact({'from': sender}))
def test_provide_state(self): tokenstate, _ = attempt_deploy( self.compiled, 'TokenState', MASTER, [self.the_owner, self.token_real.address]) token, _ = attempt_deploy( self.compiled, 'PublicExternStateProxyToken', MASTER, ["Test Token", "TEST", 1000 * UNIT, MASTER, ZERO_ADDRESS, DUMMY]) self.assertNotEqual(token.functions.state().call(), ZERO_ADDRESS) token, _ = attempt_deploy(self.compiled, 'PublicExternStateProxyToken', MASTER, [ "Test Token", "TEST", 1000 * UNIT, MASTER, tokenstate.address, DUMMY ]) self.assertEqual(token.functions.state().call(), tokenstate.address)
def test_provide_tokenstate(self): feetoken, _ = attempt_deploy(self.compiled, 'FeeToken', MASTER, [ self.proxy.address, "Test Fee Token", "FEE", 0, UNIT // 20, self.fee_authority, DUMMY ]) self.assertNotEqual(feetoken.functions.tokenState().call(), ZERO_ADDRESS)
def deployContracts(cls): cls.owner = MASTER cls.associate = DUMMY tokenstate, cls.deploy_tx = attempt_deploy(cls.compiled, 'TokenState', MASTER, [cls.owner, cls.associate]) return tokenstate
def setUpClass(cls): cls.assertReverts = assertReverts compiled = compile_contracts([ERC20Token_SOURCE]) cls.erc20_abi = compiled['ERC20Token']['abi'] cls.erc20_event_dict = generate_topic_event_map(cls.erc20_abi) cls.erc20token, cls.construction_txr = attempt_deploy( compiled, 'ERC20Token', MASTER, ["Test Token", "TEST", 1000 * UNIT, MASTER]) cls.totalSupply = lambda self: cls.erc20token.functions.totalSupply( ).call() cls.name = lambda self: cls.erc20token.functions.name().call() cls.symbol = lambda self: cls.erc20token.functions.symbol().call() cls.balanceOf = lambda self, account: cls.erc20token.functions.balanceOf( account).call() cls.allowance = lambda self, account, spender: cls.erc20token.functions.allowance( account, spender).call() cls.transfer = lambda self, sender, to, value: mine_tx( cls.erc20token.functions.transfer(to, value).transact( {'from': sender})) cls.approve = lambda self, sender, spender, value: mine_tx( cls.erc20token.functions.approve(spender, value).transact( {'from': sender})) cls.transferFrom = lambda self, sender, fromAccount, to, value: mine_tx( cls.erc20token.functions.transferFrom(fromAccount, to, value). transact({'from': sender}))
def setUpClass(cls): cls.assertReverts = assertReverts compiled = compile_contracts([MATH_MODULE_SOURCE], remappings=['""=contracts']) cls.math, tx_receipt = attempt_deploy(compiled, 'PublicMath', MASTER, []) cls.addIsSafe = lambda self, x, y: cls.math.functions.pubAddIsSafe( x, y).call() cls.safeAdd = lambda self, x, y: cls.math.functions.pubSafeAdd( x, y).call() cls.subIsSafe = lambda self, x, y: cls.math.functions.pubSubIsSafe( x, y).call() cls.safeSub = lambda self, x, y: cls.math.functions.pubSafeSub( x, y).call() cls.mulIsSafe = lambda self, x, y: cls.math.functions.pubMulIsSafe( x, y).call() cls.safeMul = lambda self, x, y: cls.math.functions.pubSafeMul( x, y).call() cls.safeMul_dec = lambda self, x, y: cls.math.functions.pubSafeMul_dec( x, y).call() cls.divIsSafe = lambda self, x, y: cls.math.functions.pubDivIsSafe( x, y).call() cls.safeDiv = lambda self, x, y: cls.math.functions.pubSafeDiv( x, y).call() cls.safeDiv_dec = lambda self, x, y: cls.math.functions.pubSafeDiv_dec( x, y).call() cls.intToDec = lambda self, i: cls.math.functions.pubIntToDec(i).call()
def setUpClass(cls): cls.assertReverts = assertReverts cls.assertClose = assertClose compiled = compile_contracts([SD_SOURCE], remappings=['""=contracts']) cls.sd, txr = attempt_deploy(compiled, 'PayableSD', MASTER, [MASTER, DUMMY]) cls.owner = lambda self: cls.sd.functions.owner().call() cls.nominateOwner = lambda self, sender, newOwner: mine_tx( cls.sd.functions.nominateOwner(newOwner).transact({'from': sender}) ) cls.acceptOwnership = lambda self, sender: mine_tx( cls.sd.functions.acceptOwnership().transact({'from': sender})) cls.initiationTime = lambda self: cls.sd.functions.initiationTime( ).call() cls.beneficiary = lambda self: cls.sd.functions.beneficiary().call() cls.setBeneficiary = lambda self, sender, beneficiary: mine_tx( cls.sd.functions.setBeneficiary(beneficiary).transact( {'from': sender})) cls.initiateSelfDestruct = lambda self, sender: mine_tx( cls.sd.functions.initiateSelfDestruct().transact({'from': sender})) cls.terminateSelfDestruct = lambda self, sender: mine_tx( cls.sd.functions.terminateSelfDestruct().transact({'from': sender} )) cls.selfDestruct = lambda self, sender: mine_tx( cls.sd.functions.selfDestruct().transact({'from': sender})) send_value(MASTER, cls.sd.address, 10 * UNIT)
def setUpClass(cls): cls.assertReverts = assertReverts compiled = compile_contracts([OWNED_SOURCE]) cls.owned, txr = attempt_deploy(compiled, 'Owned', MASTER, [MASTER]) cls.owner = lambda self: cls.owned.functions.owner().call() cls.setOwner = lambda self, sender, newOwner: mine_tx(cls.owned.functions.setOwner(newOwner).transact({'from': sender}))
def test_provide_state(self): feestate, _ = attempt_deploy(self.compiled, 'TokenState', MASTER, [MASTER, self.feetoken.address]) feetoken, _ = attempt_deploy( self.compiled, 'PublicExternStateProxyFeeToken', MASTER, [ "Test Fee Token", "FEE", UNIT // 20, self.fee_authority, ZERO_ADDRESS, DUMMY ]) self.assertNotEqual(feetoken.functions.state().call(), ZERO_ADDRESS) feetoken, _ = attempt_deploy( self.compiled, 'PublicExternStateProxyFeeToken', MASTER, [ "Test Fee Token", "FEE", UNIT // 20, self.fee_authority, feestate.address, DUMMY ]) self.assertEqual(feetoken.functions.state().call(), feestate.address)
def deploy_public_contracts(): print("Deployment initiated.\n") compiled = attempt(compile_contracts, [SOLIDITY_SOURCES], "Compiling contracts... ") # Deploy contracts havven_contract, hvn_txr = attempt_deploy(compiled, 'PublicHavven', MASTER, [ZERO_ADDRESS, MASTER]) nomin_contract, nom_txr = attempt_deploy( compiled, 'PublicEtherNomin', MASTER, [ havven_contract.address, MASTER, MASTER, 1000 * UNIT, MASTER, ZERO_ADDRESS ]) court_contract, court_txr = attempt_deploy( compiled, 'FakeCourt', MASTER, [havven_contract.address, nomin_contract.address, MASTER]) # Install proxies havven_proxy, _ = attempt_deploy(compiled, 'Proxy', MASTER, [havven_contract.address, MASTER]) mine_tx( havven_contract.functions.setProxy(havven_proxy.address).transact( {'from': MASTER})) proxy_havven = W3.eth.contract(address=havven_proxy.address, abi=compiled['PublicHavven']['abi']) nomin_proxy, _ = attempt_deploy(compiled, 'Proxy', MASTER, [nomin_contract.address, MASTER]) mine_tx( nomin_contract.functions.setProxy(nomin_proxy.address).transact( {'from': MASTER})) proxy_nomin = W3.eth.contract(address=nomin_proxy.address, abi=compiled['PublicEtherNomin']['abi']) # Hook up each of those contracts to each other txs = [ havven_contract.functions.setNomin(nomin_contract.address).transact( {'from': MASTER}), nomin_contract.functions.setCourt(court_contract.address).transact( {'from': MASTER}) ] attempt(mine_txs, [txs], "Linking contracts... ") print("\nDeployment complete.\n") return proxy_havven, proxy_nomin, havven_proxy, nomin_proxy, havven_contract, nomin_contract, court_contract
def deployContracts(cls): sources = ["tests/contracts/PublicMath.sol"] compiled, cls.event_maps = cls.compileAndMapEvents( sources, remappings=['""=contracts']) math, tx_receipt = attempt_deploy(compiled, 'PublicMath', MASTER, []) return math
def setUpClass(cls): sources = ["contracts/Owned.sol"] cls.compiled, cls.event_maps = cls.compileAndMapEvents(sources) cls.event_map = cls.event_maps['Owned'] cls.owned_contract, cls.deploy_tx = attempt_deploy( cls.compiled, 'Owned', MASTER, [MASTER]) cls.owned = OwnedInterface(cls.owned_contract, "Owned")
def deployContracts(cls): sources = [ "contracts/Pausable.sol", "tests/contracts/TestablePausable.sol" ] compiled, cls.event_maps = cls.compileAndMapEvents(sources) pausableContract, _ = attempt_deploy(compiled, 'TestablePausable', MASTER, [cls.contractOwner]) return pausableContract
def setUpClass(cls): cls.assertReverts = assertReverts compiled = compile_contracts([SETUP_SOURCE], remappings=['""=contracts']) cls.setup, txr = attempt_deploy(compiled, 'OneWeekSetup', MASTER, []) cls.contractConstructionTime = block_time(txr.blockNumber) cls.testFunc = lambda self: cls.setup.functions.testFunc().call() cls.setupExpiryTime = lambda self: cls.setup.functions.publicSetupExpiryTime().call()
def deployContracts(cls): sources = [ "tests/contracts/PublicHavven.sol", "tests/contracts/PublicNomin.sol", "contracts/IssuanceController.sol" ] compiled, cls.event_maps = cls.compileAndMapEvents(sources) nomin_abi = compiled['PublicNomin']['abi'] havven_abi = compiled['PublicHavven']['abi'] issuance_controller_abi = compiled['IssuanceController']['abi'] 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=havven_abi) proxied_nomin = W3.eth.contract(address=nomin_proxy.address, abi=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 // 2, [], ZERO_ADDRESS ]) nomin_contract, nom_txr = attempt_deploy( compiled, 'PublicNomin', MASTER, [ nomin_proxy.address, nomin_tokenstate.address, havven_contract.address, 0, MASTER ]) 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}), ]) issuanceControllerContract, _ = attempt_deploy( compiled, 'IssuanceController', MASTER, [ cls.contractOwner, cls.fundsWallet, havven_contract.address, nomin_contract.address, cls.oracleAddress, cls.usdToEthPrice, cls.usdToHavPrice ]) return havven_proxy, proxied_havven, nomin_proxy, proxied_nomin, havven_contract, nomin_contract, nomin_abi, issuanceControllerContract
def deployContracts(): sources = [ "tests/contracts/PublicFeeToken.sol", "contracts/FeeToken.sol", "contracts/TokenState.sol" ] compiled = compile_contracts(sources, remappings=['""=contracts']) feetoken_abi = compiled['PublicFeeToken']['abi'] proxy, _ = attempt_deploy(compiled, "Proxy", MASTER, [MASTER]) proxied_feetoken = W3.eth.contract(address=proxy.address, abi=feetoken_abi) feetoken_event_dict = generate_topic_event_map(feetoken_abi) feestate, txr = attempt_deploy(compiled, "TokenState", MASTER, [MASTER, MASTER]) feetoken_contract_1, construction_txr_1 = attempt_deploy( compiled, "PublicFeeToken", MASTER, [ proxy.address, feestate.address, "Test Fee Token", "FEE", 1000 * UNIT, UNIT // 20, MASTER, MASTER ]) feetoken_contract_2, construction_txr_2 = attempt_deploy( compiled, "PublicFeeToken", MASTER, [ proxy.address, feestate.address, "Test Fee Token 2", "FEE", 1000 * UNIT, UNIT // 20, MASTER, MASTER ]) mine_txs([ proxy.functions.setTarget(feetoken_contract_1.address).transact( {'from': MASTER}), feestate.functions.setBalanceOf(DUMMY, 1000 * UNIT).transact( {'from': MASTER}), feestate.functions.setAssociatedContract( feetoken_contract_1.address).transact({'from': MASTER}), feetoken_contract_1.functions.setTokenState( feestate.address).transact({'from': MASTER}) ]) return compiled, proxy, proxied_feetoken, feetoken_contract_1, feetoken_contract_2, feetoken_event_dict, feestate
def deployContracts(cls): sources = [ "tests/contracts/PublicHavven.sol", "tests/contracts/PublicNomin.sol", "tests/contracts/FakeCourt.sol", "contracts/Havven.sol" ] print("Deployment initiated.\n") compiled, cls.event_maps = cls.compileAndMapEvents(sources) # 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['PublicNomin']['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 // 2, [], ZERO_ADDRESS ]) nomin_contract, nom_txr = attempt_deploy( compiled, 'PublicNomin', MASTER, [ nomin_proxy.address, nomin_tokenstate.address, havven_contract.address, 0, MASTER ]) court_contract, court_txr = attempt_deploy( compiled, 'FakeCourt', MASTER, [havven_contract.address, nomin_contract.address, MASTER]) # Hook up each of those contracts to each other 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.setCourt(court_contract.address).transact( {'from': MASTER}) ]) print("\nDeployment complete.\n") return havven_proxy, proxied_havven, nomin_proxy, proxied_nomin, havven_contract, nomin_contract, court_contract
def deployContracts(cls): sources = ["tests/contracts/PublicNomin.sol", "tests/contracts/FakeCourt.sol", "contracts/Havven.sol"] compiled, cls.event_maps = cls.compileAndMapEvents(sources) 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['Havven']['abi']) proxied_nomin = W3.eth.contract(address=nomin_proxy.address, abi=compiled['PublicNomin']['abi']) nomin_state, txr = attempt_deploy( compiled, "TokenState", MASTER, [MASTER, MASTER] ) nomin_contract, _ = attempt_deploy( compiled, 'PublicNomin', MASTER, [nomin_proxy.address, nomin_state.address, MASTER, 0, MASTER] ) havven_contract, _ = attempt_deploy( compiled, "Havven", MASTER, [havven_proxy.address, ZERO_ADDRESS, MASTER, MASTER, UNIT//2, [], ZERO_ADDRESS] ) fake_court, _ = attempt_deploy(compiled, 'FakeCourt', MASTER, []) mine_txs([ nomin_state.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.setCourt(fake_court.address).transact({'from': MASTER}), nomin_contract.functions.setHavven(havven_contract.address).transact({'from': MASTER}) ]) return havven_proxy, proxied_havven, nomin_proxy, proxied_nomin, nomin_contract, havven_contract, fake_court, nomin_state
def setUpClass(cls): cls.assertReverts = assertReverts compiled = compile_contracts([OWNED_SOURCE]) cls.owned, txr = attempt_deploy(compiled, 'Owned', MASTER, [MASTER]) cls.owner = lambda self: cls.owned.functions.owner().call() cls.nominatedOwner = lambda self: cls.owned.functions.nominatedOwner().call() cls.nominateOwner = lambda self, sender, newOwner: mine_tx( cls.owned.functions.nominateOwner(newOwner).transact({'from': sender})) cls.acceptOwnership = lambda self, sender: mine_tx( cls.owned.functions.acceptOwnership().transact({'from': sender})) cls.owned_event_map = generate_topic_event_map(compiled['Owned']['abi'])
def setUpClass(cls): cls.sd_duration = 60 * 60 * 24 * 7 * 4 cls.contract_balance = 10 * UNIT sources = ["tests/contracts/PayableSD.sol"] cls.compiled, cls.event_maps = cls.compileAndMapEvents( sources, remappings=['""=contracts']) cls.event_map = cls.event_maps['SelfDestructible'] cls.sd_contract, cls.deploy_tx = attempt_deploy( cls.compiled, 'PayableSD', MASTER, [MASTER]) cls.sd = SelfDestructibleInterface(cls.sd_contract, 'SelfDestructible') cls.sd.setSelfDestructBeneficiary(MASTER, DUMMY) # Send some value to the contract so that we can test receipt of funds by beneficiary send_value(MASTER, cls.sd_contract.address, cls.contract_balance)
def setUpClass(cls): cls.assertReverts = assertReverts cls.compiled = compile_contracts([TokenState_SOURCE], remappings=['""=contracts']) cls.owner = MASTER cls.associate = DUMMY cls.tokenstate, _ = attempt_deploy(cls.compiled, 'TokenState', MASTER, [cls.owner, cls.associate]) cls.state_owner = lambda self: cls.tokenstate.functions.owner().call() cls.associatedContract = lambda self: cls.tokenstate.functions.associatedContract().call() cls.balanceOf = lambda self, acc: cls.tokenstate.functions.balanceOf(acc).call() cls.allowance = lambda self, frm, to: cls.tokenstate.functions.allowance(frm, to).call() cls.setAssociatedContract = lambda self, sender, addr: mine_tx( cls.tokenstate.functions.setAssociatedContract(addr).transact({'from': sender})) cls.setAllowance = lambda self, sender, tokenOwner, spender, value: mine_tx( cls.tokenstate.functions.setAllowance(tokenOwner, spender, value).transact({'from': sender})) cls.setBalanceOf = lambda self, sender, account, value: mine_tx( cls.tokenstate.functions.setBalanceOf(account, value).transact({'from': sender}))
def deployContracts(cls): print("Deployment initiated.\n") sources = [ "tests/contracts/PublicHavven.sol", "contracts/Nomin.sol", "contracts/HavvenEscrow.sol" ] compiled, cls.event_maps = cls.compileAndMapEvents(sources) # 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, cls.initial_price, [], 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]) # Hook up each of those contracts to each other 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']) print("\nDeployment complete.\n") return havven_proxy, proxied_havven, nomin_proxy, proxied_nomin, havven_contract, nomin_contract, escrow_contract, hvn_block, havven_event_dict
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 setUpClass(cls): cls.assertReverts = assertReverts cls.initial_beneficiary, cls.fee_authority, cls.token_owner = fresh_accounts( 3) cls.compiled = compile_contracts( [ExternStateProxyFeeToken_SOURCE, Proxy_SOURCE, TokenState_SOURCE], remappings=['""=contracts']) cls.feetoken_abi = cls.compiled['PublicExternStateProxyFeeToken'][ 'abi'] cls.feetoken_event_dict = generate_topic_event_map(cls.feetoken_abi) cls.feetoken_real, cls.construction_txr = attempt_deploy( cls.compiled, "PublicExternStateProxyFeeToken", MASTER, [ "Test Fee Token", "FEE", UNIT // 20, cls.fee_authority, ZERO_ADDRESS, cls.token_owner ]) cls.feestate, txr = attempt_deploy(cls.compiled, "TokenState", MASTER, [cls.token_owner, cls.token_owner]) mine_tx( cls.feestate.functions.setBalanceOf(cls.initial_beneficiary, 1000 * UNIT).transact( {'from': cls.token_owner})) mine_tx( cls.feestate.functions.setAssociatedContract( cls.feetoken_real.address).transact({'from': cls.token_owner})) cls.feetoken_proxy, _ = attempt_deploy( cls.compiled, 'Proxy', MASTER, [cls.feetoken_real.address, cls.token_owner]) mine_tx( cls.feetoken_real.functions.setProxy( cls.feetoken_proxy.address).transact({'from': cls.token_owner})) cls.feetoken = W3.eth.contract( address=cls.feetoken_proxy.address, abi=cls.compiled['PublicExternStateProxyFeeToken']['abi']) mine_tx( cls.feetoken_real.functions.setState( cls.feestate.address).transact({'from': cls.token_owner})) cls.owner = lambda self: cls.feetoken.functions.owner().call() cls.totalSupply = lambda self: cls.feetoken.functions.totalSupply( ).call() cls.state = lambda self: cls.feetoken.functions.state().call() cls.name = lambda self: cls.feetoken.functions.name().call() cls.symbol = lambda self: cls.feetoken.functions.symbol().call() cls.balanceOf = lambda self, account: self.feetoken.functions.balanceOf( account).call() cls.allowance = lambda self, account, spender: self.feetoken.functions.allowance( account, spender).call() cls.transferFeeRate = lambda self: cls.feetoken.functions.transferFeeRate( ).call() cls.maxTransferFeeRate = lambda self: cls.feetoken.functions.maxTransferFeeRate( ).call() cls.feePool = lambda self: cls.feetoken.functions.feePool().call() cls.feeAuthority = lambda self: cls.feetoken.functions.feeAuthority( ).call() cls.transferFeeIncurred = lambda self, value: cls.feetoken.functions.transferFeeIncurred( value).call() cls.transferPlusFee = lambda self, value: cls.feetoken.functions.transferPlusFee( value).call() cls.priceToSpend = lambda self, value: cls.feetoken.functions.priceToSpend( value).call() cls.nominateOwner = lambda self, sender, address: mine_tx( cls.feetoken.functions.nominateOwner(address).transact( {'from': sender})) cls.acceptOwnership = lambda self, sender: mine_tx( cls.feetoken.functions.acceptOwnership().transact({'from': sender} )) cls.setTransferFeeRate = lambda self, sender, new_fee_rate: mine_tx( cls.feetoken.functions.setTransferFeeRate(new_fee_rate).transact( {'from': sender})) cls.setFeeAuthority = lambda self, sender, new_fee_authority: mine_tx( cls.feetoken.functions.setFeeAuthority(new_fee_authority).transact( {'from': sender})) cls.setState = lambda self, sender, new_state: mine_tx( cls.feetoken.functions.setState(new_state).transact( {'from': sender})) cls.transfer_byProxy = lambda self, sender, to, value: mine_tx( cls.feetoken.functions.transfer_byProxy(to, value).transact( {'from': sender})) cls.approve = lambda self, sender, spender, value: mine_tx( cls.feetoken.functions.approve(spender, value).transact( {'from': sender})) cls.transferFrom_byProxy = lambda self, sender, fromAccount, to, value: mine_tx( cls.feetoken.functions.transferFrom_byProxy( fromAccount, to, value).transact({'from': sender})) cls.withdrawFee = lambda self, sender, account, value: mine_tx( cls.feetoken_real.functions.withdrawFee(account, value).transact( {'from': sender})) cls.donateToFeePool = lambda self, sender, value: mine_tx( cls.feetoken.functions.donateToFeePool(value).transact( {'from': sender})) cls.debug_messageSender = lambda self: cls.feetoken_real.functions._messageSender( ).call() cls.debug_optionalProxy = lambda self, sender: mine_tx( cls.feetoken.functions._optionalProxy_tester().transact( {'from': sender})) cls.debug_optionalProxy_direct = lambda self, sender: mine_tx( cls.feetoken_real.functions._optionalProxy_tester().transact( {'from': sender}))