Пример #1
0
def parse_deckspawn_metainfo(protobuf: bytes, version: int) -> dict:
    '''Decode deck_spawn tx op_return protobuf message and validate it,
       Raise error if deck_spawn metainfo incomplete or version mistmatch.'''

    deck = DeckSpawnProto()
    deck.ParseFromString(protobuf)

    error = {
        "error":
        "Deck ({deck}) metainfo incomplete, deck must have a name.".format(
            deck=deck.name)
    }

    if deck.name == "":
        raise InvalidDeckMetainfo(error)

    if deck.version != version:
        raise InvalidDeckVersion({"error", "Deck version mismatch."})

    return {
        "version": deck.version,
        "name": deck.name,
        "issue_mode": deck.issue_mode,
        "number_of_decimals": deck.number_of_decimals,
        "asset_specific_data": deck.asset_specific_data
    }
Пример #2
0
def test_issue_mode_to_enum():
    '''test issue mode to enum conversion'''

    deck = generate_dummy_deck().metainfo_to_protobuf
    deck_meta = DeckSpawn()
    deck_meta.ParseFromString(deck)

    assert isinstance(issue_mode_to_enum(deck_meta,
                      ["CUSTOM", "SINGLET"]), int)
Пример #3
0
def test_deck_issue_mode():
    '''test enum to issue_mode conversion'''

    deck_meta = DeckSpawn()
    deck_meta.issue_mode = 3

    assert isinstance(deck_issue_mode(deck_meta), Generator)
    assert list(deck_issue_mode(deck_meta)) == ['CUSTOM', 'ONCE']

    # Check that we handle NONE mode correctly.
    deck_meta.issue_mode = 0
    assert list(deck_issue_mode(deck_meta)) == ['NONE']