示例#1
0
def verify(_: Any, rpc_provider: URI, contracts_version: Optional[str]) -> None:
    web3 = Web3(HTTPProvider(rpc_provider, request_kwargs={"timeout": 60}))
    web3.middleware_onion.inject(geth_poa_middleware, layer=0)
    print("Web3 provider is", web3.provider)

    verifier = ContractVerifier(web3=web3, contracts_version=contracts_version)
    verifier.verify_deployed_contracts_in_filesystem()
def test_verify_existent_deployment_with_wrong_code(
        token_network_registry_contract: Contract) -> None:
    """ Test verify_deployed_contracts_in_filesystem() with an existent deployment data

    but with a fake web3 that does not return the correct code.
    """
    web3_mock = Mock()
    web3_mock.version.network = 42
    web3_mock.eth.getTransactionReceipt = lambda _: {
        "blockNumber": 10711807,
        "gasUsed": 555366,
        "contractAddress": "0x8Ff327f7ed03cD6Bd5e611E9e404B47d8c9Db81E",
    }
    verifier = ContractVerifier(web3=web3_mock, contracts_version="0.11.1")
    # The Mock returns a wrong block number, so the comparison fails.
    with pytest.raises(RuntimeError):
        verifier.verify_deployed_contracts_in_filesystem()
    with pytest.raises(RuntimeError):
        verifier.verify_deployed_service_contracts_in_filesystem(
            token_address=HexAddress(
                "0x3Aa761BcDB064179a1e37748D8A5F577a177Be5c"),
            user_deposit_whole_balance_limit=2**256 - 1,
            token_network_registry_address=token_network_registry_contract.
            address,
        )
示例#3
0
def test_verify_nonexistent_deployment(user_deposit_whole_balance_limit, ):
    """ Test verify_deployed_contracts_in_filesystem() with a non-existent deployment data. """
    web3_mock = Mock()
    web3_mock.version.network = 1
    # contracts_version 0.10.1 does not contain a main net deployment.
    verifier = ContractVerifier(web3=web3_mock, contracts_version="0.10.1")
    with pytest.raises(RuntimeError):
        verifier.verify_deployed_contracts_in_filesystem()
    with pytest.raises(RuntimeError):
        verifier.verify_deployed_service_contracts_in_filesystem(
            token_address=EMPTY_ADDRESS,
            user_deposit_whole_balance_limit=user_deposit_whole_balance_limit,
        )
def test_verify_nonexistent_deployment(
    user_deposit_whole_balance_limit: int, token_network_registry_address: HexAddress
) -> None:
    """Test verify_deployed_contracts_in_filesystem() with a non-existent deployment data."""
    web3_mock = Mock()
    web3_mock.version.network = 42
    # contracts_version 0.37.0 does not contain a kovan deployment.
    verifier = ContractVerifier(web3=web3_mock, contracts_version=ALDERAAN_VERSION)
    with pytest.raises(RuntimeError):
        verifier.verify_deployed_contracts_in_filesystem()
    with pytest.raises(RuntimeError):
        verifier.verify_deployed_service_contracts_in_filesystem(
            token_address=EMPTY_ADDRESS,
            user_deposit_whole_balance_limit=user_deposit_whole_balance_limit,
            token_network_registry_address=token_network_registry_address,
        )
def test_verify_existent_deployment(token_network_registry_contract: Contract) -> None:
    """Test verify_deployed_contracts_in_filesystem() with an existent deployment data

    but with a fake web3 that returns a wrong block number for deployment.
    """
    web3_mock = Mock()
    web3_mock.version.network = 5
    web3_mock.eth.get_transaction_receipt = lambda _: {"blockNumber": 0}
    verifier = ContractVerifier(web3=web3_mock, contracts_version=ALDERAAN_VERSION)
    # The Mock returns a wrong block number, so the comparison fails.
    with pytest.raises(RuntimeError):
        verifier.verify_deployed_contracts_in_filesystem()
    with pytest.raises(RuntimeError):
        verifier.verify_deployed_service_contracts_in_filesystem(
            token_address=HexAddress(HexStr("0x5Fc523e13fBAc2140F056AD7A96De2cC0C4Cc63A")),
            user_deposit_whole_balance_limit=2**256 - 1,
            token_network_registry_address=token_network_registry_contract.address,
        )
示例#6
0
def test_verify_existent_deployment():
    """ Test verify_deployed_contracts_in_filesystem() with an existent deployment data

    but with a fake web3 that returns a wrong block number for deployment.
    """
    web3_mock = Mock()
    web3_mock.version.network = 42
    web3_mock.eth.getTransactionReceipt = lambda _: {"blockNumber": 0}
    verifier = ContractVerifier(web3=web3_mock, contracts_version="0.11.1")
    # The Mock returns a wrong block number, so the comparison fails.
    with pytest.raises(RuntimeError):
        verifier.verify_deployed_contracts_in_filesystem()
    with pytest.raises(RuntimeError):
        verifier.verify_deployed_service_contracts_in_filesystem(
            token_address=HexAddress(
                "0x3Aa761BcDB064179a1e37748D8A5F577a177Be5c"),
            user_deposit_whole_balance_limit=2**256 - 1,
        )
def test_verify_existent_deployment_with_wrong_code(
    token_network_registry_contract: Contract,
) -> None:
    """Test verify_deployed_contracts_in_filesystem() with an existent deployment data

    but with a fake web3 that does not return the correct code.
    """
    web3_mock = Mock()
    web3_mock.version.network = 5
    web3_mock.eth.get_transaction_receipt = lambda _: {
        "blockNumber": 10711807,
        "gasUsed": 555366,
        "contractAddress": "0x8Ff327f7ed03cD6Bd5e611E9e404B47d8c9Db81E",
    }
    verifier = ContractVerifier(web3=web3_mock, contracts_version=ALDERAAN_VERSION)
    # The Mock returns a wrong block number, so the comparison fails.
    with pytest.raises(RuntimeError):
        verifier.verify_deployed_contracts_in_filesystem()
    with pytest.raises(RuntimeError):
        verifier.verify_deployed_service_contracts_in_filesystem(
            token_address=HexAddress(HexStr("0x5Fc523e13fBAc2140F056AD7A96De2cC0C4Cc63A")),
            user_deposit_whole_balance_limit=2**256 - 1,
            token_network_registry_address=token_network_registry_contract.address,
        )