Exemplo n.º 1
0
 def packed_reward_proof_data(self, non_closing_signature: Signature) -> bytes:
     """Return reward proof data serialized to binary"""
     return pack_reward_proof(
         monitoring_service_contract_address=to_checksum_address(self.msc_address),
         chain_id=self.chain_id,
         token_network_address=HexAddress(to_checksum_address(self.token_network_address)),
         non_closing_participant=HexAddress(to_checksum_address(self.non_closing_participant)),
         non_closing_signature=non_closing_signature,
         reward_amount=self.reward_amount,
     )
def encode_call_script(actions, spec_id=1):
    result = create_executor_id(spec_id)
    for to, calldata in actions:
        addr_bytes = Web3.toBytes(hexstr=HexAddress(to)).hex()
        calldata_bytes = strip_byte_prefix(calldata)
        length = eth_abi.encode_single('int256',
                                       len(calldata_bytes) // 2).hex()
        result += addr_bytes + length[56:] + calldata_bytes
    return result
Exemplo n.º 3
0
def pack_reward_proof(
    chain_id: ChainID,
    token_network_address: TokenNetworkAddress,
    reward_amount: TokenAmount,
    monitoring_service_contract_address: MonitoringServiceAddress,
    non_closing_participant: Address,
    non_closing_signature: Signature,
) -> bytes:
    return proofs.pack_reward_proof(
        monitoring_service_contract_address=to_checksum_address(
            monitoring_service_contract_address),
        chain_id=chain_id,
        token_network_address=HexAddress(
            to_checksum_address(token_network_address)),
        non_closing_participant=HexAddress(
            to_checksum_address(non_closing_participant)),
        non_closing_signature=non_closing_signature,
        reward_amount=reward_amount,
    )
def test_user_deposit_deployment_with_wrong_one_to_n_address() -> None:
    """ContractVerifier.verify_user_deposit_deployment raises on a wrong OneToN address"""
    token_addr = HexAddress(
        HexStr("0xDa12Dc74D2d0881749CCd9330ac4f0aecda5686a"))
    user_deposit_constructor_arguments = [token_addr, UINT256_MAX]
    wrong_one_to_n_address = FAKE_ADDRESS
    user_deposit_mock = MagicMock()
    mock_token_address = MagicMock()
    mock_token_address.call.return_value = token_addr
    user_deposit_mock.functions.token.return_value = mock_token_address

    with pytest.raises(RuntimeError):
        _verify_user_deposit_deployment(
            user_deposit=user_deposit_mock,
            constructor_arguments=user_deposit_constructor_arguments,
            token_address=token_addr,
            user_deposit_whole_balance_limit=UINT256_MAX,
            one_to_n_address=wrong_one_to_n_address,
            monitoring_service_address=HexAddress(
                HexStr("0xb7765972d78B6C97bB0a5a6b7529DC1fb64aA287")),
        )
Exemplo n.º 5
0
def test_logfilter_with_nonexistent_event(web3: Web3) -> None:
    """ Try to create a LogFilter with a nonexistent event """

    with pytest.raises(ValueError):
        LogFilter(
            web3=web3,
            abi=[],
            address=HexAddress("0xfake"),
            event_name="ev0",
            from_block=0,
            to_block="latest",
        )
def test_deploy_services_with_controller(mock_deploy: MagicMock,
                                         mock_verify: MagicMock,
                                         privkey_file: IO) -> None:
    """Calling deploy raiden command"""
    with patch.object(Eth, "get_balance", return_value=1):
        runner = CliRunner()
        result = runner.invoke(
            services,
            deploy_services_arguments(
                privkey=privkey_file.name,
                save_info=None,
                service_registry_controller=HexAddress(HexStr("0x" +
                                                              "1" * 40)),
                token_network_registry_address=FAKE_ADDRESS,
            ),
        )
        assert result.exception is None
        assert result.exit_code == 0
        mock_deploy.assert_called_once()
        mock_verify.assert_called_once()
Exemplo n.º 7
0
from enum import IntEnum

from eth_typing.evm import HexAddress
from eth_utils.units import units

from raiden_contracts.utils.signature import private_key_to_address

MAX_UINT256 = 2**256 - 1
MAX_UINT192 = 2**192 - 1
MAX_UINT32 = 2**32 - 1
FAKE_ADDRESS = "0x03432"
EMPTY_ADDRESS = HexAddress("0x0000000000000000000000000000000000000000")
EMPTY_BALANCE_HASH = b"\x00" * 32
EMPTY_ADDITIONAL_HASH = b"\x00" * 32
EMPTY_LOCKSROOT = b"\x00" * 32
EMPTY_SIGNATURE = b"\x00" * 65
passphrase = "0"
FAUCET_PRIVATE_KEY = "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
FAUCET_ADDRESS = private_key_to_address(FAUCET_PRIVATE_KEY)
FAUCET_ALLOWANCE = 100 * int(units["ether"])
CONTRACT_DEPLOYER_ADDRESS = FAUCET_ADDRESS


class TestLockIndex(IntEnum):
    EXPIRATION = 0
    AMOUNT = 1
    SECRETHASH = 2
    SECRET = 3
Exemplo n.º 8
0
# gas price strategy
APPLY_GAS_PRICE_STRATEGY: bool = environ.get("APPLY_GAS_PRICE_STRATEGY",
                                             "False") in (
                                                 "true",
                                                 "True",
                                             )
MAX_TX_WAIT_SECONDS: int = int(environ.get("MAX_TX_WAIT_SECONDS", "120"))

# maximum gas spent on oracle vote
ORACLE_VOTE_GAS_LIMIT: Wei = Wei(int(environ["ORACLE_VOTE_GAS_LIMIT"]))

# how long to wait for transaction to mine
TRANSACTION_TIMEOUT: int = int(environ["TRANSACTION_TIMEOUT"])

# how long to wait before processing again
PROCESS_INTERVAL: int = int(environ["PROCESS_INTERVAL"])

# contracts
POOL_CONTRACT_ADDRESS: ChecksumAddress = ChecksumAddress(
    HexAddress(HexStr(environ["POOL_CONTRACT_ADDRESS"])))
ORACLES_CONTRACT_ADDRESS: ChecksumAddress = ChecksumAddress(
    HexAddress(HexStr(environ["ORACLES_CONTRACT_ADDRESS"])))
REWARD_ETH_CONTRACT_ADDRESS: ChecksumAddress = ChecksumAddress(
    HexAddress(HexStr(environ["REWARD_ETH_CONTRACT_ADDRESS"])))
STAKED_ETH_CONTRACT_ADDRESS: ChecksumAddress = ChecksumAddress(
    HexAddress(HexStr(environ["STAKED_ETH_CONTRACT_ADDRESS"])))

# credentials
# TODO: consider reading from file
ORACLE_PRIVATE_KEY: str = environ["ORACLE_PRIVATE_KEY"]