Beispiel #1
0
    def deploy(cls, web3, deployer_wallet: Wallet, abi_path: str = '', *args):
        """
        Deploy the DataTokenTemplate and DTFactory contracts to the current network.

        :param web3:
        :param abi_path:
        :param deployer_wallet: Wallet instance

        :return: smartcontract address of this contract
        """
        if not abi_path:
            abi_path = ContractHandler.artifacts_path

        assert abi_path, f'abi_path is required, got {abi_path}'

        w3 = web3
        _json = ContractHandler.read_abi_from_file(cls.CONTRACT_NAME, abi_path)

        _contract = w3.eth.contract(abi=_json['abi'],
                                    bytecode=_json['bytecode'])
        built_tx = _contract.constructor(*args)\
            .buildTransaction({'from': deployer_wallet.address})

        if 'gas' not in built_tx:
            built_tx['gas'] = web3.eth.estimateGas(built_tx)

        raw_tx = deployer_wallet.sign_tx(built_tx)
        logging.debug(
            f'Sending raw tx to deploy contract {cls.CONTRACT_NAME}, signed tx hash: {raw_tx.hex()}'
        )
        tx_hash = web3.eth.sendRawTransaction(raw_tx)

        return cls.get_tx_receipt(tx_hash, timeout=60).contractAddress
def test_read_abi_from_file__example_config__happy_path(example_config):
    assert "https" not in str(ContractHandler.artifacts_path)

    contract_definition = ContractHandler.read_abi_from_file(
        "DTFactory", ContractHandler.artifacts_path)
    assert contract_definition["contractName"] == "DTFactory"
    assert "createToken" in str(contract_definition["abi"])
def test_read_abi_from_file__example_config__bad_contract_name(example_config):
    assert "https" not in str(ContractHandler.artifacts_path)

    base_path = ContractHandler.artifacts_path
    target_filename = os.path.join(base_path, "DTFactoryFOO.json")
    assert not os.path.exists(target_filename)  # should fail due to this

    contract_definition = ContractHandler.read_abi_from_file(
        "DTFactoryFOO", ContractHandler.artifacts_path)
    assert contract_definition is None