コード例 #1
0
def test_currency_properties(mocker):
    mocker.patch.dict(Currency._Currency__currencies, dict(), clear=True)

    c1 = Currency("Sym", "Nam", 2, 1)
    assert c1.symbol == "Sym"
    assert not c1.is_fiat
    assert not c1.is_staked
    assert Currency.all_symbols() == {"SYM"}
    assert Currency.all_symbols(unique=False) == {"SYM", "NAM"}

    c2 = Currency("ZEUR", "EUR", 8, 3)
    assert c2.symbol == "ZEUR"
    assert c2.is_fiat
    assert not c2.is_staked

    c3 = Currency("ZEUR.M", "eur.m", 8, 3)
    assert c3.symbol == "ZEUR.M"
    assert c3.is_fiat
    assert c3.is_staked
    assert c3.is_staked_offchain

    c4 = Currency("XTZ.S", "xtz.s", 8, 3)
    assert c4.symbol == "XTZ.S"
    assert not c4.is_fiat
    assert c4.is_staked
    assert c4.is_staked_onchain
コード例 #2
0
def test_currencypair_singleton(mocker):
    mocker.patch.dict(Currency._Currency__currencies, dict(), clear=True)
    mocker.patch.dict(CurrencyPair._CurrencyPair__currency_pairs,
                      dict(),
                      clear=True)

    assert CurrencyPair.all_symbols() == set()

    c1 = Currency("Sym", "Sym", 2, 1)
    c2 = Currency("Sym2", "Sym2", 2, 1)
    c3 = Currency("ZSYM3", "ZSym3", 2, 1)
    assert Currency.all_symbols() == {"SYM", "SYM2", "ZSYM3"}

    cp1 = CurrencyPair("SYMZSYM3", "SS", "S/S", 1, c1, c3, 0.01)
    cp2 = CurrencyPair("SYM2ZSYM3", "S2S", "S2/S", 6, c2, c3, 100)
    assert CurrencyPair.all_symbols() == {"SYMZSYM3", "SYM2ZSYM3"}
    assert CurrencyPair.all_symbols(
        unique=False) == {"SYMZSYM3", "SYM2ZSYM3"} | {
            "SS",
            "S2S",
        }

    with pytest.raises(AssertionError):
        CurrencyPair("SYMZSYM3", "SSx", "S/Sx", 1, c1, c3, 0.01)

    assert cp1 != cp2

    cpx = CurrencyPair.find("symzsym3")
    assert id(cpx) == id(cp1)

    cpx2 = CurrencyPair.find("ss")
    assert id(cpx) == id(cpx2)

    with pytest.raises(KeyError):
        CurrencyPair.find("sym3")

    with pytest.raises(KeyError):
        CurrencyPair.find("SYM3ZSYM3")
コード例 #3
0
def test_currencypair_properties(mocker):
    mocker.patch.dict(Currency._Currency__currencies, dict(), clear=True)
    mocker.patch.dict(CurrencyPair._CurrencyPair__currency_pairs,
                      dict(),
                      clear=True)

    assert CurrencyPair.all_symbols() == set()

    c1 = Currency("Sym", "Nam", 2, 1)
    c2 = Currency("Sym2", "Nam2", 2, 1)
    c3 = Currency("ZSYM3", "Nam3", 2, 1)
    assert Currency.all_symbols() == {"SYM", "SYM2", "ZSYM3"}
    assert Currency.all_symbols(unique=False) == {"SYM", "SYM2", "ZSYM3"} | {
        "NAM",
        "NAM2",
        "NAM3",
    }
    assert not c1.is_fiat
    assert not c2.is_fiat
    assert c3.is_fiat

    cpcf1 = CurrencyPair("S1", "SS", "S/S", 1, c1, c3, 0.01)
    cpcf2 = CurrencyPair("S2", "S2S", "S2/S", 6, c2, c3, 100)
    cpcc = CurrencyPair("S3", "S3S", "S3/S", 6, c1, c2, 100)
    cpff = CurrencyPair("S4", "S4S", "S4/S", 6, c3, c3, 100)
    assert CurrencyPair.all_symbols() == {"S1", "S2", "S3", "S4"}
    assert CurrencyPair.all_symbols(
        unique=False) == {"S1", "S2", "S3", "S4"} | {
            "SS",
            "S2S",
            "S3S",
            "S4S",
        }

    assert cpcf1.is_fiat2crypto
    assert cpcf2.is_fiat2crypto
    assert cpcc.is_crypto2crypto
    assert cpff.is_fiat2fiat
コード例 #4
0
def test_currency_singleton(mocker):
    mocker.patch.dict(Currency._Currency__currencies, dict(), clear=True)

    assert Currency.all_symbols() == set()

    c1 = Currency("Sym", "Nam", 2, 1)
    assert Currency.all_symbols() == {"SYM"}
    assert Currency.all_symbols(unique=False) == {"SYM", "NAM"}

    _ = Currency("ZSYM2", "ZSym2", 2, 1)
    assert Currency.all_symbols(unique=False) == {"SYM", "NAM", "ZSYM2"}

    with pytest.raises(AssertionError):
        Currency("Sym", "Nam3", 3, 2)

    cx = Currency.find("sym")
    assert id(cx) == id(c1)

    cx2 = Currency.find("nam")
    assert id(cx) == id(cx2)

    with pytest.raises(KeyError):
        Currency.find("sym3")