Beispiel #1
0
def test_nonetype():
    with pytest.raises(TypeError):
        Fixed(None)
Beispiel #2
0
def test_gt():
    assert Fixed("2 ether") > "1 ether"
    with pytest.raises(TypeError):
        Fixed("2.0") > 1.0
Beispiel #3
0
def test_ge():
    assert Fixed("2 ether") >= "1 ether"
    assert Fixed("2 ether") >= "2 ether"
    with pytest.raises(TypeError):
        Fixed("2.0") >= 2.0
Beispiel #4
0
def test_lt():
    assert Fixed("1 ether") < "2 ether"
    with pytest.raises(TypeError):
        Fixed("1.0") < 1.1
Beispiel #5
0
def test_le():
    assert Fixed("1 ether") <= "2 ether"
    assert Fixed("1 ether") <= "1 ether"
    with pytest.raises(TypeError):
        Fixed("1.0") <= 1.1
Beispiel #6
0
def test_eq():
    assert Fixed("1") == 1
    assert not Fixed("123") == "obviously not a number"
    with pytest.raises(TypeError):
        Fixed("1.0") == 1.0
Beispiel #7
0
def test_ne():
    assert Fixed("1") != 2
    assert Fixed("123") != "obviously not a number"
    with pytest.raises(TypeError):
        Fixed("1.0") != 1.1
Beispiel #8
0
def test_string_with_unit():
    assert Fixed("3.66 ether") == 3660000000000000000
    assert Fixed("89.006 gwei") == 89006000000
Beispiel #9
0
def test_type():
    assert type(Fixed(12)) is Fixed
Beispiel #10
0
def test_str():
    assert Fixed("1000.123456789123456789") == Decimal(
        "1000.123456789123456789")
Beispiel #11
0
def test_hexstr():
    assert Fixed("0xff") == 255
Beispiel #12
0
def test_int():
    assert Fixed(1000) == 1000
Beispiel #13
0
def test_float():
    with pytest.raises(TypeError):
        Fixed(1.99)
Beispiel #14
0
def test_scientific_notation():
    assert Fixed("8.32e26") == 832000000000000000000000000
Beispiel #15
0
def test_bytes():
    assert Fixed(b"\xff") == 255
Beispiel #16
0
def test_success():
    assert to_decimal(123) == 123
    assert to_decimal("-3.1337") == Decimal("-3.1337")
    assert to_decimal("1 ether") == 1000000000000000000
    assert to_decimal(Decimal(42)) == 42
    assert to_decimal(Fixed(6)) == "6"