Beispiel #1
0
def test_asset_body_types():

    rate = token_lib.Fraction(-1, 100)
    rate_to_stop = token_lib.Fraction(1, 3)
    time_unit = 60 * 60 * 24 * 30
    expire_after = 60 * 60 * 24 * 180

    vari = token_lib.Variation(0, token_lib.Variation.T_SIMPLE, rate,
                               rate_to_stop, time_unit, expire_after)
    body = token_lib.ValueAssetBody(100, 12345, [vari])

    dat = body.serialize()
    _, body = token_lib.BaseAssetBody.from_serialized_data(0, dat)

    assert body.type == token_lib.BaseAssetBody.T_VALUE

    body = token_lib.ChangeAssetBody(100, 12345, [vari])

    dat = body.serialize()
    _, body = token_lib.BaseAssetBody.from_serialized_data(0, dat)

    assert body.type == token_lib.BaseAssetBody.T_CHANGE

    body = token_lib.IssuedAssetBody(100, 12345, [vari])

    dat = body.serialize()
    _, body = token_lib.BaseAssetBody.from_serialized_data(0, dat)

    assert body.type == token_lib.BaseAssetBody.T_ISSUED
Beispiel #2
0
def test_variation():

    rate = token_lib.Fraction(-1, 10)
    rate_to_stop = token_lib.Fraction(1, 2)
    time_unit = 60 * 60 * 24 * 7
    expire_after = 60 * 60 * 24 * 30

    vari = token_lib.Variation(0, token_lib.Variation.T_SIMPLE, rate,
                               rate_to_stop, time_unit, expire_after)
    vari0 = vari

    dat = vari.serialize()
    idx, vari = token_lib.Variation.from_serialized_data(0, dat)

    assert idx == 1 + 1 + 5 + 5 + 8 + 8
    assert vari.condition == 0
    assert vari.type == token_lib.Variation.T_SIMPLE
    assert vari.rate == rate
    assert vari.rate_to_stop == rate_to_stop
    assert vari.time_unit == time_unit
    assert vari.expire_after == expire_after

    assert vari == vari0
Beispiel #3
0
def test_value_asset_body():

    rate = token_lib.Fraction(-1, 100)
    rate_to_stop = token_lib.Fraction(1, 3)
    time_unit = 60 * 60 * 24 * 30
    expire_after = 60 * 60 * 24 * 180

    vari = token_lib.Variation(0, token_lib.Variation.T_SIMPLE, rate,
                               rate_to_stop, time_unit, expire_after)
    body = token_lib.ValueAssetBody(100, 12345, [vari])

    dat = body.serialize()
    _, body = token_lib.BaseAssetBody.from_serialized_data(0, dat)

    assert body.type == token_lib.BaseAssetBody.T_VALUE
    assert body.value_specified == 100
    assert body.time_of_origin == 12345
    assert body.variation_specs[0].condition == vari.condition
    assert body.variation_specs[0].type == vari.type
    assert body.variation_specs[0].rate == vari.rate
    assert body.variation_specs[0].rate_to_stop == vari.rate_to_stop
    assert body.variation_specs[0].time_unit == vari.time_unit
    assert body.variation_specs[0].expire_after == vari.expire_after
Beispiel #4
0
def test_effective_value():

    rate = token_lib.Fraction(-1, 10)
    rate_to_stop = token_lib.Fraction(1, 2)
    time_unit = 100
    expire_after = 0

    vari = token_lib.Variation(0, token_lib.Variation.T_SIMPLE, rate,
                               rate_to_stop, time_unit, expire_after)
    body = token_lib.ValueAssetBody(100, 10, [vari])

    assert body.get_effective_value(0) == 100
    assert body.get_effective_value(100) == 100
    assert body.get_effective_value(110) == 90
    assert body.get_effective_value(120) == 90
    assert body.get_effective_value(510) == 50
    assert body.get_effective_value(520) == 50
    assert body.get_effective_value(610) == 50
    assert body.get_effective_value(10000) == 50

    rate = token_lib.Fraction(1, 10)
    rate_to_stop = token_lib.Fraction(2, 1)

    vari = token_lib.Variation(0, token_lib.Variation.T_SIMPLE, rate,
                               rate_to_stop, time_unit, expire_after)
    body = token_lib.ValueAssetBody(100, 10, [vari])

    assert body.get_effective_value(0) == 100
    assert body.get_effective_value(100) == 100
    assert body.get_effective_value(110) == 110
    assert body.get_effective_value(120) == 110
    assert body.get_effective_value(1010) == 200
    assert body.get_effective_value(1020) == 200
    assert body.get_effective_value(1110) == 200
    assert body.get_effective_value(10000) == 200

    rate = token_lib.Fraction(-1, 10)
    rate_to_stop = token_lib.Fraction(0, 1)

    vari = token_lib.Variation(0, token_lib.Variation.T_SIMPLE, rate,
                               rate_to_stop, time_unit, expire_after)
    body = token_lib.ValueAssetBody(100, 10, [vari])

    assert body.get_effective_value(0) == 100
    assert body.get_effective_value(100) == 100
    assert body.get_effective_value(110) == 90
    assert body.get_effective_value(120) == 90
    assert body.get_effective_value(1010) == 0
    assert body.get_effective_value(1020) == 0
    assert body.get_effective_value(1110) == 0
    assert body.get_effective_value(10000) == 0

    vari = token_lib.Variation(0, token_lib.Variation.T_COMPOUND, rate,
                               rate_to_stop, time_unit, expire_after)
    body = token_lib.ValueAssetBody(100, 10, [vari])

    assert body.get_effective_value(0) == 100
    assert body.get_effective_value(100) == 100
    assert body.get_effective_value(110) == 90
    assert body.get_effective_value(120) == 90
    assert body.get_effective_value(210) == 81
    assert body.get_effective_value(310) == 72
    assert body.get_effective_value(410) == 65

    vari = token_lib.Variation()
    body = token_lib.ValueAssetBody(100, 10, [vari])

    assert body.get_effective_value(0) == 100
    assert body.get_effective_value(100) == 100
    assert body.get_effective_value(110) == 100
    assert body.get_effective_value(120) == 100
    assert body.get_effective_value(10000) == 100

    vari = token_lib.Variation(type=token_lib.Variation.T_COMPOUND)
    body = token_lib.ValueAssetBody(100, 10, [vari])

    assert body.get_effective_value(0) == 100
    assert body.get_effective_value(100) == 100
    assert body.get_effective_value(110) == 100
    assert body.get_effective_value(120) == 100
    assert body.get_effective_value(10000) == 100

    vari = token_lib.Variation(expire_after=500)
    body = token_lib.ValueAssetBody(100, 10, [vari])

    assert body.get_effective_value(0) == 100
    assert body.get_effective_value(100) == 100
    assert body.get_effective_value(110) == 100
    assert body.get_effective_value(120) == 100
    assert body.get_effective_value(509) == 100
    assert body.get_effective_value(510) == 0
    assert body.get_effective_value(10000) == 0

    body = token_lib.ValueAssetBody(100, 10, [])

    assert body.get_effective_value(0) == 100
    assert body.get_effective_value(510) == 100
    assert body.get_effective_value(10000) == 100