Пример #1
0
def test_event_fund_wallet(web3, hosted_wallet):
    """Send some funds int the wallet and see that we get the event of the deposit."""

    listener, events = create_contract_listener(hosted_wallet.contract)

    # value = get_wallet_balance(testnet_wallet_contract_address)
    txid = send_balance_to_contract(hosted_wallet, TEST_VALUE)
    confirm_transaction(web3, txid)

    update_count = listener.poll()

    assert update_count == 1
    assert len(events) == 1
    event_name, input_data = events[0]
    assert event_name == "Deposit"
    assert input_data["value"] == to_wei(TEST_VALUE)

    # Deposit some more, should generate one new event
    txid = send_balance_to_contract(hosted_wallet, TEST_VALUE)
    confirm_transaction(web3, txid)

    update_count = listener.poll()

    assert update_count == 1
    assert len(events) == 2
    event_name, input_data = events[1]
    assert event_name == "Deposit"
    assert input_data["value"] == to_wei(TEST_VALUE)
Пример #2
0
def test_fund_crowdsale(web3, hosted_wallet, token):
    """When we fund crowdsale tokens get created."""

    contract = token.contract
    test_fund = Decimal(1000)  # ETH

    listener, events = create_contract_listener(contract)

    contract.call().investorCount() == 0

    txid = send_balance_to_contract(token.contract, test_fund, gas=1000000)
    confirm_transaction(web3, txid)
    update_count = listener.poll()

    # receipt = web3.eth.getTransactionReceipt(txid)
    # print("Gas used by funding is ", receipt["cumulativeGas"])

    # Check the transfer event arrives
    assert update_count == 2  # Buy + Transfer
    assert len(events) == 2
    event_name, input_data = events[0]
    assert event_name == "Buy"
    assert input_data["eth"] == to_wei(test_fund, "ether")
    assert input_data["tokens"] == 2000

    # Check balances
    web3.eth.getBalance(MULTISIG) == to_wei(test_fund * 2, "ether")
    contract.call().weiRaised() == to_wei(test_fund, "ether")
    contract.call().investorCount() == 1
Пример #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)
Пример #4
0
def test_cap(web3, hosted_wallet, token, coinbase):
    """Transactions that would exceed cap is rejected."""

    test_fund = wei_to_eth(CAP + 1)

    txid = send_balance_to_contract(token.contract, test_fund, gas=1000000)
    with pytest.raises(TransactionConfirmationError):
        confirm_transaction(web3, txid)
Пример #5
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)
Пример #6
0
def test_fund_wallet(web3, coinbase, hosted_wallet):
    """Send some funds int the wallet and see the balance updates."""

    current_balance = wei_to_eth(web3.eth.getBalance(hosted_wallet.address))

    # value = get_wallet_balance(wallet_contract_address)
    txid = send_balance_to_contract(hosted_wallet, TEST_VALUE)

    wait_tx(web3, txid)

    new_balance = hosted_wallet.get_balance()

    assert new_balance == current_balance + TEST_VALUE
Пример #7
0
def topped_up_hosted_wallet(web3, hosted_wallet):
    """Wallet with ensured amount of funds."""

    txid = send_balance_to_contract(hosted_wallet, TOP_UP_VALUE)
    wait_tx(web3, txid)
    return hosted_wallet
Пример #8
0
def topped_up_hosted_wallet(web3, hosted_wallet):
    """Wallet with ensured amount of funds."""

    txid = send_balance_to_contract(hosted_wallet, TOP_UP_VALUE)
    wait_tx(web3, txid)
    return hosted_wallet