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
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)
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
def test_lists(): assert convert(["1 ether"], list) == [int(1e18)]
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'."
def test_ether_conversions(value, unit): actual = convert(value=f"{value} {unit}", type=int) expected = int(value * ETHER_UNITS[unit]) assert actual == expected
def test_no_registered_converter(): with pytest.raises(Exception): convert(value="something", type=ChecksumAddress)
def test_bad_type(): with pytest.raises(Exception): convert(value="something", type=float)
def test_ether_conversions(value, unit): assert convert(value=f"{value} {unit}", type=int) == int(value * ETHER_UNITS[unit])
def test_convert_timedelta_timestamp(): delta = timedelta(days=2, hours=2, minutes=12) assert convert(delta, int) == int( (datetime.now(timezone.utc) + delta).timestamp())
def test_convert_string_timestamp(args): assert convert(args, int) == 1634300112