예제 #1
0
def test_participate_with_signed_address(chain, crowdsale, customer,
                                         customer_id, token, private_key):
    """Buy tokens with a proper signed address."""

    address_bytes = get_address_as_bytes(customer)
    sign_data = sign(address_bytes, private_key)

    time_travel(chain, crowdsale.functions.startsAt().call() + 1)
    wei_value = to_wei(1, "ether")
    assert crowdsale.functions.getState().call() == CrowdsaleState.Funding
    crowdsale.functions.buyWithSignedAddress(customer_id, sign_data["v"],
                                             sign_data["r_bytes"],
                                             sign_data["s_bytes"]).transact({
                                                 "from":
                                                 customer,
                                                 "value":
                                                 wei_value
                                             })

    # We got credited
    assert token.functions.balanceOf(customer).call() > 0

    # We have tracked the investor id
    events = crowdsale.events.Invested().createFilter(
        fromBlock=0).get_all_entries()
    assert len(events) == 1
    e = events[0]
    assert e["args"]["investor"] == customer
    assert e["args"]["weiAmount"] == wei_value
    assert e["args"]["customerId"] == customer_id
예제 #2
0
def test_right_pad(pad_contract):
    """Ensure we handle trailing zero in the address correctly."""

    address_bytes = get_address_as_bytes(pad_contract.call().rightPad())
    hash = bitcoin.bin_sha256(address_bytes)
    val = pad_contract.call().getHashRightPad()
    val = force_bytes(val)
    assert hash == val
예제 #3
0
def test_left_pad(pad_contract):
    """Ensure we handle leading zero in the address correctly."""

    address_bytes = get_address_as_bytes(
        pad_contract.functions.leftPad().call())
    hash = bitcoin.bin_sha256(address_bytes)
    val = pad_contract.functions.getHashLeftPad().call()
    val = to_bytes(val)
    assert hash == val
예제 #4
0
def test_participate_bad_signature(chain, crowdsale, customer, customer_id,
                                   token):
    """Investment does not happen with a bad signature.."""

    address_bytes = get_address_as_bytes(customer)
    sign_data = sign(address_bytes, private_key)

    time_travel(chain, crowdsale.call().startsAt() + 1)
    wei_value = to_wei(1, "ether")
    assert crowdsale.call().getState() == CrowdsaleState.Funding

    sign_data["s_bytes"] = b'ABC'  # Corrupt signature data

    with pytest.raises(TransactionFailed):
        crowdsale.transact({
            "from": customer,
            "value": wei_value
        }).buyWithSignedAddress(customer_id, sign_data["v"],
                                sign_data["r_bytes"], sign_data["s_bytes"])