Esempio n. 1
0
    def test_13_make_transaction(self):
        print("\n-----", sys._getframe().f_code.co_name, "-----")
        for i, cl in enumerate(clients):
            user = cl['user_id']
            other_user = (i + 1) % client_num

            txobj = bbclib.make_transaction(event_num=1,
                                            witness=True,
                                            format_type=fmt)
            txobj.events[0].add(
                reference_index=0,
                mandatory_approver=clients[other_user]['user_id'])
            bbclib.add_event_asset(txobj,
                                   event_idx=0,
                                   asset_group_id=asset_group_id,
                                   user_id=user,
                                   asset_body=b"data=%d" % i)
            reference = bbclib.add_reference_to_transaction(
                txobj, asset_group_id, transactions[i], 0)
            ret = cl['app'].gather_signatures(txobj, reference_obj=reference)
            assert ret
            dat = msg_processor[i].synchronize()
            assert dat[KeyType.status] == ESUCCESS
            result = dat[KeyType.result]
            txobj.references[result[0]].add_signature(user_id=result[1],
                                                      signature=result[2])

            txobj.digest()
            cl['app'].insert_transaction(txobj)
            dat = msg_processor[i].synchronize()
            assert KeyType.transaction_id in dat
            assert dat[KeyType.transaction_id] == txobj.transaction_id
            transactions[i] = txobj
Esempio n. 2
0
    def test_12_make_transaction(self):
        print("\n-----", sys._getframe().f_code.co_name, "-----")
        for i, cl in enumerate(clients):
            print("---- start transaction ---")
            user = cl['user_id']
            other_user = (i + 1) % client_num

            transactions[i] = bbclib.make_transaction(event_num=1,
                                                      witness=True,
                                                      format_type=fmt)
            transactions[i].events[0].add(
                mandatory_approver=clients[other_user]['user_id'])
            bbclib.add_event_asset(transactions[i],
                                   event_idx=0,
                                   asset_group_id=asset_group_id,
                                   user_id=user,
                                   asset_body=b"data=%d" % i)

            transactions[i].witness.add_witness(user_id=cl['user_id'])
            sig = transactions[i].sign(keypair=cl['keypair'])
            transactions[i].add_signature(user_id=cl['user_id'], signature=sig)

            transactions[i].digest()
            print("register transaction=",
                  binascii.b2a_hex(transactions[i].transaction_id))
            cl['app'].insert_transaction(transactions[i])
            print("  ----> wait insert")
            dat = msg_processor[i].synchronize()
            assert KeyType.transaction_id in dat
            assert dat[
                KeyType.transaction_id] == transactions[i].transaction_id
            print("    ==> got insert")
        time.sleep(2)
Esempio n. 3
0
    def test_06_transaction_with_relation_and_witness(self):
        print("\n-----", sys._getframe().f_code.co_name, "-----")
        transaction1 = bbclib.make_transaction(relation_num=1, witness=True)
        bbclib.add_relation_asset(transaction1,
                                  relation_idx=0,
                                  asset_group_id=asset_group_id,
                                  user_id=user_id,
                                  asset_body=b'ccccc')
        bbclib.add_relation_pointer(transaction1,
                                    0,
                                    ref_transaction_id=transaction2.digest())
        transaction1.witness.add_witness(user_id)
        transaction1.witness.add_witness(user_id2)

        sig = transaction1.sign(private_key=keypair2.private_key,
                                public_key=keypair2.public_key)
        if sig is None:
            print(bbclib.error_text)
            assert sig
        transaction1.witness.add_signature(user_id=user_id2, signature=sig)

        sig = transaction1.sign(private_key=keypair1.private_key,
                                public_key=keypair1.public_key)
        if sig is None:
            print(bbclib.error_text)
            assert sig
        transaction1.witness.add_signature(user_id=user_id, signature=sig)

        print(transaction1)
    def test_13_gather_signature(self):
        print("\n-----", sys._getframe().f_code.co_name, "-----")
        prev_tx = transactions[0]
        user = clients[1]['user_id']
        transactions[1] = bbclib.make_transaction(event_num=1)
        bbclib.add_event_asset(transactions[1],
                               event_idx=0,
                               asset_group_id=asset_group_id,
                               user_id=user,
                               asset_body=b'123456')

        reference = bbclib.add_reference_to_transaction(
            transactions[1], asset_group_id, prev_tx, 0)
        clients[1]['app'].gather_signatures(transactions[1],
                                            reference_obj=reference)
        dat = msg_processor[1].synchronize()
        assert dat[KeyType.status] == ESUCCESS
        result = dat[KeyType.result]
        transactions[1].references[result[0]].add_signature(
            user_id=result[1], signature=result[2])

        print(transactions[1])
        transactions[1].digest()
        print("register transaction=",
              binascii.b2a_hex(transactions[1].transaction_id))
        clients[1]['app'].insert_transaction(transactions[1])
        dat = msg_processor[1].synchronize()
        assert KeyType.transaction_id in dat
        assert dat[KeyType.transaction_id] == transactions[1].transaction_id
    def test_02_make_transaction(self):
        print("\n-----", sys._getframe().f_code.co_name, "-----")
        user = clients[0]['user_id']
        kp = clients[0]['keypair']

        transactions1[0] = bbclib.make_transaction(relation_num=1, witness=True, format_type=fmt)
        bbclib.add_relation_asset(transactions1[0], relation_idx=0, asset_group_id=asset_group_id,
                                  user_id=user, asset_body=b'transaction1_0')
        transactions1[0].witness.add_witness(user)
        sig = transactions1[0].sign(keypair=kp)
        transactions1[0].witness.add_signature(user, sig)

        transactions2[0] = bbclib.make_transaction(event_num=1, witness=True, format_type=fmt)
        transactions2[0].events[0].add(mandatory_approver=user)
        bbclib.add_event_asset(transactions2[0], event_idx=0, asset_group_id=asset_group_id,
                               user_id=user, asset_body=b'transaction2_0')
        transactions2[0].witness.add_witness(user)
        sig = transactions2[0].sign(keypair=kp)
        transactions2[0].witness.add_signature(user_id=user, signature=sig)

        for i in range(1, 20):
            k = i - 1
            transactions1[i] = bbclib.make_transaction(relation_num=1, witness=True, format_type=fmt)
            bbclib.add_relation_asset(transactions1[i], 0, asset_group_id=asset_group_id, user_id=user,
                                      asset_body=b'transaction1_%d' % i)
            bbclib.add_relation_pointer(transactions1[i], 0, ref_transaction_id=transactions1[k].transaction_id,
                                        ref_asset_id=transactions1[k].relations[0].asset.asset_id)
            transactions1[i].witness.add_witness(user)
            sig = transactions1[i].sign(keypair=kp)
            transactions1[i].witness.add_signature(user, sig)

            transactions2[i] = bbclib.make_transaction(event_num=1, witness=True, format_type=fmt)
            transactions2[i].events[0].add(mandatory_approver=user)
            bbclib.add_event_asset(transactions2[i], event_idx=0, asset_group_id=asset_group_id,
                                   user_id=user, asset_body=b'transaction2_%d' % i)
            transactions2[i].witness.add_witness(user)
            bbclib.add_reference_to_transaction(transactions2[i], asset_group_id, transactions2[k], 0)
            sig = transactions2[i].sign(keypair=kp)
            transactions2[i].witness.add_signature(user_id=user, signature=sig)
            if i == 9:
                bbclib.add_reference_to_transaction(transactions2[i], asset_group_id, transactions2[5], 0)
            sig = transactions2[i].sign(keypair=kp)
            transactions2[i].references[0].add_signature(user_id=user, signature=sig)
    def test_13_insert_first_transaction(self):
        print("\n-----", sys._getframe().f_code.co_name, "-----")
        user = clients[0]['user_id']
        transactions[0] = bbclib.make_transaction(event_num=2, witness=True)
        transactions[0].events[0].add(reference_index=0,
                                      mandatory_approver=user)
        bbclib.add_event_asset(transactions[0],
                               event_idx=0,
                               asset_group_id=asset_group_id,
                               user_id=user,
                               asset_body=b'123456')
        bbclib.add_event_asset(transactions[0],
                               event_idx=1,
                               asset_group_id=asset_group_id,
                               user_id=user,
                               asset_body=b'abcdefg')

        transactions[0].witness.add_witness(user)
        sig = transactions[0].sign(keypair=clients[0]['keypair'])
        assert sig is not None
        if sig is None:
            print(bbclib.error_text)
            import os
            os._exit(1)
        transactions[0].add_signature(user_id=user, signature=sig)
        print(transactions[0])
        transactions[0].digest()
        global transaction_dat
        transaction_dat = transactions[0].serialize()
        print("register transaction=",
              binascii.b2a_hex(transactions[0].transaction_id))
        clients[0]['app'].insert_transaction(transactions[0])
        dat = msg_processor[0].synchronize()
        assert KeyType.transaction_id in dat
        assert dat[KeyType.transaction_id] == transactions[0].transaction_id
        time.sleep(2)