Esempio n. 1
0
    def txn_data2schema_key(self, txn: dict) -> SchemaKey:
        """
        Return schema key from ledger transaction data.

        :param txn: get-schema transaction (by sequence number)
        :return: schema key identified
        """

        rv = None
        if self == Protocol.V1_3:
            rv = SchemaKey(txn['identifier'], txn['data']['name'], txn['data']['version'])
        else:
            txn_txn = txn.get('txn', None) or txn  # may have already run this txn through txn2data() below
            rv = SchemaKey(
                txn_txn['metadata']['from'],
                txn_txn['data']['data']['name'],
                txn_txn['data']['data']['version'])

        return rv
Esempio n. 2
0
def schema_key(s_id: str) -> SchemaKey:
    """
    Return schema key (namedtuple) convenience for schema identifier components.

    :param s_id: schema identifier
    :return: schema key (namedtuple) object
    """

    s_key = s_id.split(':')
    s_key.pop(1)  # take out indy-sdk schema marker: 2 marks indy-sdk schema id

    return SchemaKey(*s_key)
Esempio n. 3
0
async def test_protocol():

    print(Ink.YELLOW('\n\n== Testing Node Pool Protocols =='))

    assert Protocol.V_13.indy() != Protocol.V_14.indy(
    )  # all the same except indy-node 1.3
    assert Protocol.V_14.indy() == Protocol.V_15.indy()
    assert Protocol.V_15.indy() == Protocol.V_16.indy()
    assert Protocol.V_16.indy() == Protocol.V_17.indy()
    assert Protocol.V_17.indy() == Protocol.V_18.indy()
    assert Protocol.V_18.indy() == Protocol.DEFAULT.indy()
    assert Protocol.get('1.8') == Protocol.DEFAULT
    print('\n\n== 1 == Protocol enum values correspond OK to indy values')

    issuer_did = 'ZqhtaRvibYPQ23456789ee'
    seq_no = 123
    assert Protocol.V_13.cred_def_id(issuer_did,
                                     seq_no) == '{}:3:CL:{}'.format(
                                         issuer_did, seq_no)
    assert Protocol.DEFAULT.cred_def_id(issuer_did,
                                        seq_no) == '{}:3:CL:{}:tag'.format(
                                            issuer_did, seq_no)

    assert Protocol.V_13.cd_id_tag(for_box_id=True) == ''
    assert Protocol.V_13.cd_id_tag(
        for_box_id=False
    ) == 'tag'  # indy-sdk refuses empty string on issue-cred-def
    assert Protocol.DEFAULT.cd_id_tag(for_box_id=True) == ':tag'
    assert Protocol.DEFAULT.cd_id_tag(
        for_box_id=False
    ) == 'tag'  # indy-sdk refuses empty string on issue-cred-def
    print(
        '\n\n== 2 == Protocol enum values build cred def id and tags as expected'
    )

    txn_13 = json.loads('''{
        "op": "REPLY",
        "result": {
            "data": {
                "identifier": "WgWxqztrNooG92RXvxSTWv",
                "data": {
                    "name": "green",
                    "version": "1.0",
                    "...": "..."
                },
                "...": "..."
            },
            "txnTime": 1234567890,
            "...": "..."
        },
        "...": "..."
    }''')
    assert json.loads(
        Protocol.V_13.txn2data(txn_13)) == txn_13['result']['data']
    assert Protocol.V_13.txn2epoch(txn_13) == 1234567890
    assert Protocol.V_13.txn_data2schema_key(
        json.loads(Protocol.V_13.txn2data(txn_13))) == SchemaKey(
            'WgWxqztrNooG92RXvxSTWv', 'green', '1.0')

    txn_18 = json.loads('''{
        "op": "REPLY",
        "result": {
            "data": {
                "txn": {
                    "data": {
                        "data": {
                            "name": "green",
                            "version": "1.0",
                            "...": "..."
                        }
                    },
                    "metadata": {
                        "from": "WgWxqztrNooG92RXvxSTWv",
                        "...": "..."
                    },
                    "...": "..."
                },
                "...": "..."
            },
            "txnMetadata": {
                "txnTime": 1234567890,
                "...": "..."
            },
            "...": "..."
        },
        "...": "..."
    }''')
    assert json.loads(
        Protocol.DEFAULT.txn2data(txn_18)) == txn_18['result']['data']['txn']
    assert Protocol.DEFAULT.txn2epoch(txn_18) == 1234567890
    assert Protocol.DEFAULT.txn_data2schema_key(
        json.loads(Protocol.DEFAULT.txn2data(txn_18))) == SchemaKey(
            'WgWxqztrNooG92RXvxSTWv', 'green', '1.0')
    print(
        '\n\n== 3 == Protocol enum values extricate transaction data as expected'
    )