Esempio n. 1
0
 def __init__(self, address: bytes, **kwargs: Any) -> None:
     if self.needs_bytecode_linking:
         raise BytecodeLinkingError(
             "Contract cannot be instantiated until its bytecode is linked."
         )
     validate_address(address)
     # todo: remove automatic checksumming of address once web3 dep is updated in pytest-ethereum
     super(LinkableContract,
           self).__init__(address=to_checksum_address(address), **kwargs)
Esempio n. 2
0
 def get_contract_instance(self, name: ContractName,
                           address: Address) -> Contract:
     """
     Will return a ``Web3.contract`` instance generated from the contract type data available
     in ``Package.manifest`` and the provided ``address``. The provided ``address`` must be
     valid on the connected chain available through ``Package.w3``.
     """
     validate_address(address)
     validate_contract_name(name)
     try:
         self.manifest["contract_types"][name]["abi"]
     except KeyError:
         raise InsufficientAssetsError(
             "Package does not have the ABI required to generate a contract instance "
             f"for contract: {name} at address: {address}.")
     contract_kwargs = generate_contract_factory_kwargs(
         self.manifest["contract_types"][name])
     canonical_address = to_canonical_address(address)
     contract_instance = self.w3.eth.contract(address=canonical_address,
                                              **contract_kwargs)
     return contract_instance
Esempio n. 3
0
def _deployment(
    contract_instance: str,
    contract_type: str,
    deployment_bytecode: Dict[str, Any],
    runtime_bytecode: Dict[str, Any],
    compiler: Dict[str, Any],
    block_uri: URI,
    address: HexStr,
    tx: HexStr,
    block: HexStr,
    manifest: Manifest,
) -> Manifest:
    validate_address(address)
    if not is_BIP122_block_uri(block_uri):
        raise ManifestBuildingError(f"{block_uri} is not a valid BIP122 URI.")

    if tx:
        if not is_string(tx) and not is_hex(tx):
            raise ManifestBuildingError(
                f"Transaction hash: {tx} is not a valid hexstring"
            )

    if block:
        if not is_string(block) and not is_hex(block):
            raise ManifestBuildingError(f"Block hash: {block} is not a valid hexstring")
    # todo: validate db, rb and compiler are properly formatted dicts
    deployment_data = _build_deployments_object(
        contract_type,
        deployment_bytecode,
        runtime_bytecode,
        compiler,
        address,
        tx,
        block,
        manifest,
    )
    return assoc_in(
        manifest, ["deployments", block_uri, contract_instance], deployment_data
    )
Esempio n. 4
0
def test_validate_address_rejects_incorrectly_formatted_adresses(address):
    with pytest.raises(ValidationError):
        validate_address(address)
Esempio n. 5
0
def test_validate_address_accepts_canonicalized_addresses(address):
    result = validate_address(address)
    assert result is None