Ejemplo n.º 1
0
    def _send_transaction(self, transaction):

        logging.info("About to send {}".format(transaction))

        tx_hash = self.web3.eth.sendRawTransaction(transaction['signedRaw'])

        logging.info("sent {} {}".format(tx_hash, transaction['tx']['nonce']))

        Wait(self.web3).for_receipt(tx_hash, timeout=86400)

        logging.info("waited for receipt {}".format(
            transaction['tx']['nonce']))

        receipt = self.web3.eth.getTransactionReceipt(tx_hash)

        logging.info("got receipt {} {}".format(receipt,
                                                transaction['tx']['nonce']))

        if self._did_oog(receipt, transaction):
            raise AirdropOOGException(
                "OOG occurred when sending {}".format(transaction))

        # final, double-tripple-check whether there was no oog, extra safe
        # just check that some expected log was produced
        # expected log is just log of OMGToken.transfer that was sent to one of the beneficiaries
        # use raw log data
        # reason for being extra safe: to keep going with OOGs is catastrophic
        expected_log = filter(
            lambda log: transaction['rawBatch'][0][0][2:] in log['topics'][2],
            receipt['logs'])

        if not expected_log:
            raise AirdropOOGException(
                "OOG probably occurred when sending {}, with receipt {}".
                format(transaction, receipt))
Ejemplo n.º 2
0
    def deploy_contract(self,
                        contract_identifier,
                        deploy_transaction=None,
                        deploy_args=None,
                        deploy_kwargs=None):
        """
        Same as get_contract but it will also lazily deploy the contract with
        the provided deployment arguments
        """
        contract_data = self.get_contract_data(contract_identifier)
        contract_dependencies = contract_data['ordered_full_dependencies']

        for dependency_name in contract_dependencies:
            self.get_or_deploy_contract(dependency_name,
                                        deploy_transaction=deploy_transaction)

        ContractFactory = self.get_contract_factory(contract_identifier)
        deploy_transaction_hash = ContractFactory.constructor(
            *deploy_args or tuple(), **deploy_kwargs
            or dict()).transact(deploy_transaction)
        contract_address = Wait(
            self.web3).for_contract_address(deploy_transaction_hash)
        self.registrar.set_contract_address(contract_identifier,
                                            contract_address)

        return self.get_contract(contract_identifier), deploy_transaction_hash
Ejemplo n.º 3
0
def prepared_contracts(web3):
    airdropper, omg_token = get_contracts(web3)

    mint_tx = omg_token.transact().mint(airdropper.address, RESERVE_AIRDROP)
    Wait(web3).for_receipt(mint_tx)

    return airdropper, omg_token
Ejemplo n.º 4
0
def deploy_or_at(web3, ContractClass, contract_addr):

    if contract_addr is None:
        deploy_tx = ContractClass.deploy()
        Wait(web3).for_receipt(deploy_tx)
        deploy_receipt = web3.eth.getTransactionReceipt(deploy_tx)
        return ContractClass(address=deploy_receipt['contractAddress'])
    else:
        return ContractClass(address=contract_addr)
Ejemplo n.º 5
0
def test_return_from_contract(web3, prepared_contracts, airdrops):
    """
    Paranoid test asserting that the full reserve of airdrop funds can be recovered by Sender
    """

    airdropper, omg_token = prepared_contracts

    tx = airdropper.transact().multisend(omg_token.address,
                                         web3.eth.accounts[:1],
                                         [RESERVE_AIRDROP])
    Wait(web3).for_receipt(tx)

    check_none_airdropped(airdrops, omg_token)

    assert omg_token.call().balanceOf(airdropper.address) == 0
    assert omg_token.call().balanceOf(web3.eth.accounts[0]) == RESERVE_AIRDROP
Ejemplo n.º 6
0
def test_throw_in_contract_handling(web3, prepared_contracts, transactions,
                                    airdrops):
    _, omg_token = prepared_contracts

    # whoops, omg_token got paused! omg_token should throw now
    pause_tx_hash = omg_token.transact().pause()
    Wait(web3).for_receipt(pause_tx_hash)

    # need to bump nonce in the pre-prepared transactions
    for transaction in transactions:
        transaction['tx']['nonce'] = web3.toHex(
            web3.toDecimal(transaction['tx']['nonce']) + 1)
    signed = Signer(web3).sign_transactions(transactions)

    with pytest.raises(AirdropOOGException):
        Sender(web3).send_transactions(signed, transactions)

    check_none_airdropped(airdrops, omg_token)
Ejemplo n.º 7
0
def wait(web3, kovan_block_time):
    poll_interval = kovan_block_time / 2
    return Wait(web3, poll_interval=poll_interval)
Ejemplo n.º 8
0
 def wait(self):
     return Wait(self.web3)
Ejemplo n.º 9
0
 def wait(self):
     return Wait(self.web3, **self.config.wait_settings)
Ejemplo n.º 10
0
def deploy(web3, ContractClass):
    deploy_tx = ContractClass.deploy()
    Wait(web3).for_receipt(deploy_tx)
    deploy_receipt = web3.eth.getTransactionReceipt(deploy_tx)
    return ContractClass(address=deploy_receipt['contractAddress'])