Beispiel #1
0
def test_bad_type():
    with pytest.raises(ConversionError) as err:
        convert(value="something", type=float)

    expected = (
        "Type '<class 'float'>' must be one of [ChecksumAddress, bytes, int, Decimal, list, tuple]."
    )
    assert str(err.value) == expected
Beispiel #2
0
def test_transfer_without_value_send_everything_true(sender, receiver):
    initial_balance = receiver.balance
    sender.transfer(receiver, send_everything=True)
    assert receiver.balance > initial_balance, "Receiver has same balance after transfer"
    assert sender.balance < convert("1 finney",
                                    int), "Sender balance is not nominal"
    with pytest.raises(ValueError) as err:
        sender.transfer(receiver, send_everything=True)
    assert "Sender does not have enough to cover transaction value and gas:" in str(
        err.value)
Beispiel #3
0
def test_transfer(sender, receiver):
    initial_balance = receiver.balance
    sender.transfer(receiver, "1 gwei")
    expected = initial_balance + convert("1 gwei", int)
    assert receiver.balance == expected
Beispiel #4
0
def test_lists():
    assert convert(["1 ether"], list) == [int(1e18)]
Beispiel #5
0
def test_no_registered_converter():
    with pytest.raises(ConversionError) as err:
        convert(value="something", type=ChecksumAddress)

    assert str(err.value) == "No conversion registered to handle 'something'."
Beispiel #6
0
def test_ether_conversions(value, unit):
    actual = convert(value=f"{value} {unit}", type=int)
    expected = int(value * ETHER_UNITS[unit])
    assert actual == expected
Beispiel #7
0
def test_no_registered_converter():
    with pytest.raises(Exception):
        convert(value="something", type=ChecksumAddress)
Beispiel #8
0
def test_bad_type():
    with pytest.raises(Exception):
        convert(value="something", type=float)
Beispiel #9
0
def test_ether_conversions(value, unit):
    assert convert(value=f"{value} {unit}", type=int) == int(value * ETHER_UNITS[unit])
Beispiel #10
0
def test_convert_timedelta_timestamp():
    delta = timedelta(days=2, hours=2, minutes=12)
    assert convert(delta, int) == int(
        (datetime.now(timezone.utc) + delta).timestamp())
Beispiel #11
0
def test_convert_string_timestamp(args):
    assert convert(args, int) == 1634300112