Exemplo n.º 1
0
def xxx_test_upgrade_wallet(web3: Web3):

    # Check we get somewhat valid ids
    contract_def = get_compiled_contract_cached("OwnedRegistrar")
    registrar_contract, txid = deploy_contract(web3, contract_def)

    # Deploy wallet contract body
    contract_def = get_compiled_contract_cached("Wallet")
    wallet_contract, txid = deploy_contract(web3, contract_def)

    # Register wallet contract body
    txid = registrar_contract.transact().setAddr("wallet", wallet_contract.address)
    confirm_transaction(web3, txid)

    # Deploy relay against the registered wallet
    contract_def = get_compiled_contract_cached("Relay")
    relay, txid = deploy_contract(web3, contract_def, constructor_arguments=[registrar_contract.address, "wallet"])

    # Test relayed wallet. We use Wallet ABI
    # against Relay contract.
    contract_def = get_compiled_contract_cached("Wallet")
    relayed_wallet = get_contract(web3, contract_def, relay.address)
    assert relayed_wallet.call().version() == "1.0"

    #
    # Upgrade wallet
    #

    # Deploy wallet contract body
    contract_def = get_compiled_contract_cached("Wallet")
    wallet_contract, txid = deploy_contract(web3, contract_def)
Exemplo n.º 2
0
def xxx_test_upgrade_wallet(web3: Web3):

    # Check we get somewhat valid ids
    contract_def = get_compiled_contract_cached("OwnedRegistrar")
    registrar_contract, txid = deploy_contract(web3, contract_def)

    # Deploy wallet contract body
    contract_def = get_compiled_contract_cached("Wallet")
    wallet_contract, txid = deploy_contract(web3, contract_def)

    # Register wallet contract body
    txid = registrar_contract.transact().setAddr("wallet",
                                                 wallet_contract.address)
    confirm_transaction(web3, txid)

    # Deploy relay against the registered wallet
    contract_def = get_compiled_contract_cached("Relay")
    relay, txid = deploy_contract(
        web3,
        contract_def,
        constructor_arguments=[registrar_contract.address, "wallet"])

    # Test relayed wallet. We use Wallet ABI
    # against Relay contract.
    contract_def = get_compiled_contract_cached("Wallet")
    relayed_wallet = get_contract(web3, contract_def, relay.address)
    assert relayed_wallet.call().version() == "1.0"

    #
    # Upgrade wallet
    #

    # Deploy wallet contract body
    contract_def = get_compiled_contract_cached("Wallet")
    wallet_contract, txid = deploy_contract(web3, contract_def)
Exemplo n.º 3
0
def xxx_test_registrar_based_wallet(web3: Web3, coinbase):
    """Create registrar contract and register a wallet against it."""

    wei_amount = to_wei(TEST_VALUE)

    # Check we get somewhat valid ids
    contract_def = get_compiled_contract_cached("OwnedRegistrar")
    registrar_contract, txid = deploy_contract(web3, contract_def)

    # Deploy wallet contract body
    wallet_contract_def = get_compiled_contract_cached("Wallet")
    wallet_contract, txid = deploy_contract(web3, wallet_contract_def)
    assert wallet_contract.call().version().decode("utf-8") == "1.0"

    # Register wallet contract body
    assert wallet_contract.address
    txid = registrar_contract.transact().setAddr(b"wallet",
                                                 wallet_contract.address)
    confirm_transaction(web3, txid)

    # Check registration succeeded
    assert decode_addr(
        registrar_contract.call().addr(b"wallet")) == wallet_contract.address

    # Deploy relay against the registered wallet
    contract_def = get_compiled_contract_cached("Relay")
    assert registrar_contract.address
    relay, txid = deploy_contract(
        web3,
        contract_def,
        constructor_arguments=[registrar_contract.address, "wallet"])

    # Test relayed wallet. We use Wallet ABI
    # against Relay contract.
    contract_def = get_compiled_contract_cached("Wallet")
    relayed_wallet = get_contract(web3, contract_def, relay.address)

    # Check relay internal data structures
    assert decode_addr(
        relay.call().registrarAddr()) == registrar_contract.address
    assert relay.call().name() == b"wallet"

    # We point to the wallet implementation
    impl_addr = decode_addr(relay.call().getImplAddr())
    assert impl_addr == wallet_contract.address

    # Read a public variable through relay contract
    assert relayed_wallet.call().version().decode("utf-8") == "1.0"

    # Deposit some ETH
    txid = send_balance_to_contract(relayed_wallet.address, wei_amount)
    confirm_transaction(web3, txid)
    assert relayed_wallet.web3.eth.getBalance(relayed_wallet.address,
                                              wei_amount)

    # Withdraw ETH back
    relayed_wallet.transact().withdraw(coinbase, wei_amount)
    confirm_transaction(web3, txid)
    assert relayed_wallet.web3.eth.getBalance(relayed_wallet.address, 0)
Exemplo n.º 4
0
def xxx_test_registrar_based_wallet(web3: Web3, coinbase):
    """Create registrar contract and register a wallet against it."""

    wei_amount = to_wei(TEST_VALUE)

    # Check we get somewhat valid ids
    contract_def = get_compiled_contract_cached("OwnedRegistrar")
    registrar_contract, txid = deploy_contract(web3, contract_def)

    # Deploy wallet contract body
    wallet_contract_def = get_compiled_contract_cached("Wallet")
    wallet_contract, txid = deploy_contract(web3, wallet_contract_def)
    assert wallet_contract.call().version().decode("utf-8") == "1.0"

    # Register wallet contract body
    assert wallet_contract.address
    txid = registrar_contract.transact().setAddr(b"wallet", wallet_contract.address)
    confirm_transaction(web3, txid)

    # Check registration succeeded
    assert decode_addr(registrar_contract.call().addr(b"wallet")) == wallet_contract.address

    # Deploy relay against the registered wallet
    contract_def = get_compiled_contract_cached("Relay")
    assert registrar_contract.address
    relay, txid = deploy_contract(web3, contract_def, constructor_arguments=[registrar_contract.address, "wallet"])

    # Test relayed wallet. We use Wallet ABI
    # against Relay contract.
    contract_def = get_compiled_contract_cached("Wallet")
    relayed_wallet = get_contract(web3, contract_def, relay.address)

    # Check relay internal data structures
    assert decode_addr(relay.call().registrarAddr()) == registrar_contract.address
    assert relay.call().name() == b"wallet"

    # We point to the wallet implementation
    impl_addr = decode_addr(relay.call().getImplAddr())
    assert impl_addr == wallet_contract.address

    # Read a public variable through relay contract
    assert relayed_wallet.call().version().decode("utf-8") == "1.0"

    # Deposit some ETH
    txid = send_balance_to_contract(relayed_wallet.address, wei_amount)
    confirm_transaction(web3, txid)
    assert relayed_wallet.web3.eth.getBalance(relayed_wallet.address, wei_amount)

    # Withdraw ETH back
    relayed_wallet.transact().withdraw(coinbase, wei_amount)
    confirm_transaction(web3, txid)
    assert relayed_wallet.web3.eth.getBalance(relayed_wallet.address, 0)
Exemplo n.º 5
0
    def create(cls,
               web3: Web3,
               wait_for_tx_seconds=180,
               gas=1500000,
               args=None,
               contract_name=None) -> "ContractWrapper":
        """Creates a new hosted wallet.

        The cost of deployment is paid from coinbase account.

        :param contract_factory: Which contract we deploy as Populus Contract class. Function that retunrns new Contract instance.

        :return: Populus Contract proxy object for new contract
        """
        abi_data = cls.abi_factory(contract_name)

        if not args:
            args = []

        contract, txid = deploy_contract(web3,
                                         abi_data,
                                         gas=gas,
                                         timeout=wait_for_tx_seconds,
                                         constructor_arguments=args)

        # Use hardcoded version for now
        return cls(contract, version=2, initial_txid=txid)
Exemplo n.º 6
0
    def create(cls, web3: Web3, wait_for_tx_seconds=90, gas=1500000, args=None) -> "ContractWrapper":
        """Creates a new hosted wallet.

        The cost of deployment is paid from coinbase account.

        :param contract_factory: Which contract we deploy as Populus Contract class. Function that retunrns new Contract instance.

        :return: Populus Contract proxy object for new contract
        """
        contract_class = cls.abi_factory()

        contract, txid = deploy_contract(web3, contract_class, gas=gas, timeout=wait_for_tx_seconds, constructor_arguments=args)

        # Use hardcoded version for now
        return cls(contract, version=2, initial_txid=txid)
Exemplo n.º 7
0
def simple_test_contract(web3) -> Contract:
    """Create a contract where we can set a global variable for testing."""

    contract_def = get_compiled_contract_cached("TestContract")
    contract, txid = deploy_contract(web3, contract_def)
    return contract
Exemplo n.º 8
0
def signature_contract(web3):
    contract_def = get_compiled_contract_cached("SignatureVerifier")
    contract, txid = deploy_contract(web3, contract_def)
    return contract
Exemplo n.º 9
0
def decode_data_contract(web3) -> Contract:
    """Create a contract where we can set a global variable for testing."""

    contract_def = get_compiled_contract_cached("DecodeData")
    contract, txid = deploy_contract(web3, contract_def)
    return contract
Exemplo n.º 10
0
def simple_test_contract(web3) -> Contract:
    """Create a contract where we can set a global variable for testing."""

    contract_def = get_compiled_contract_cached("TestContract")
    contract, txid = deploy_contract(web3, contract_def)
    return contract