コード例 #1
0
ファイル: test_bbclib.py プロジェクト: luomin/bbc1
    def test_05_transaction_with_reference2(self):
        print("\n-----", sys._getframe().f_code.co_name, "-----")
        asset1 = BBcAsset()
        asset1.add(user_id=user_id, asset_body=b'ccccc')
        event = BBcEvent(asset_group_id=asset_group_id)
        event.add(asset=asset1, option_approver_num_numerator=1, option_approver_num_denominator=2)
        event.add(option_approver=user_id)
        event.add(option_approver=user_id2)

        global transaction1
        transaction1 = BBcTransaction()
        transaction1.add(event=event)
        reference = BBcReference(asset_group_id=asset_group_id,
                                 transaction=transaction1, ref_transaction=transaction2, event_index_in_ref=0)
        transaction1.add(reference=reference)
        dummy_cross_ref = BBcCrossRef(domain_id=domain_id, transaction_id=transaction1_id)
        transaction2.add(cross_ref=dummy_cross_ref)

        sig = transaction1.sign(key_type=KeyType.ECDSA_SECP256k1,
                                private_key=keypair2.private_key, public_key=keypair2.public_key)
        if sig is None:
            print(bbclib.error_text)
            assert sig
        reference.add_signature(user_id=user_id2, signature=sig)
        sig = transaction1.sign(key_type=KeyType.ECDSA_SECP256k1,
                                private_key=keypair1.private_key, public_key=keypair1.public_key)
        if sig is None:
            print(bbclib.error_text)
            assert sig
        reference.add_signature(user_id=user_id, signature=sig)

        print(transaction1)
コード例 #2
0
ファイル: test_bbclib.py プロジェクト: luomin/bbc1
    def test_06_transaction_with_relation_and_witness(self):
        print("\n-----", sys._getframe().f_code.co_name, "-----")
        asset1 = BBcAsset()
        asset1.add(user_id=user_id, asset_body=b'ccccc')
        transaction1 = bbclib.make_transaction_with_relation(asset_group_id=asset_group_id, asset=asset1)
        bbclib.add_relation_pointer(transaction1.relations[0], transaction2.digest(), None)

        transaction1 = bbclib.make_transaction_with_witness(transaction1)
        transaction1.witness.add_witness(user_id)
        transaction1.witness.add_witness(user_id2)

        sig = transaction1.sign(key_type=KeyType.ECDSA_SECP256k1, 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(key_type=KeyType.ECDSA_SECP256k1, 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)
コード例 #3
0
    def test_04_transaction2_with_reference(self):
        print("-----", sys._getframe().f_code.co_name, "-----")
        global transaction2, event3, asset3
        asset3 = BBcAsset()
        asset3.add(asset_body=b'bbbbbbb', user_id=user_id)
        event3 = BBcEvent(asset_group_id=asset_group_id)
        event3.add(asset=asset3, option_approver_num_numerator=1, option_approver_num_denominator=2)
        event3.add(option_approver=user_id)
        event3.add(option_approver=user_id2)

        transaction2 = BBcTransaction()
        transaction2.add(event=event3)
        reference2 = BBcReference(asset_group_id=asset_group_id,
                                  transaction=transaction2, ref_transaction=transaction1, event_index_in_ref=0)
        transaction2.add(reference=reference2)
        dummy_cross_ref3 = BBcCrossRef(transaction_id=transaction1_id, asset_group_id=asset_group_id)
        dummy_cross_ref4 = BBcCrossRef(transaction_id=transaction2_id, asset_group_id=asset_group_id)
        transaction2.add(cross_ref=[dummy_cross_ref3, dummy_cross_ref4])

        sig = transaction2.sign(key_type=KeyType.ECDSA_SECP256k1_XY,
                                private_key=keypair1.private_key,
                                public_key=keypair1.public_key)
        if sig is None:
            print(bbclib.error_text)
            assert sig
        reference2.add_signature(user_id=user_id, signature=sig)

        transaction2.dump()
コード例 #4
0
ファイル: test_bbclib.py プロジェクト: luomin/bbc1
    def test_01_asset(self):
        print("\n-----", sys._getframe().f_code.co_name, "-----")
        global asset1, asset2
        asset1 = BBcAsset()
        asset1.add(asset_body=b'12345678', user_id=user_id)
        asset2 = BBcAsset()
        asset2.add(asset_file=asset_content, user_id=user_id)

        # --- for checking serialization function ---
        digest = asset1.digest()
        dat = asset1.serialize()
        print("Digest:", binascii.b2a_hex(digest))
        print("Serialized data:", binascii.b2a_hex(dat))
        asset_tmp = BBcAsset()
        asset_tmp.deserialize(dat)
        print("body_len:", asset_tmp.asset_body_size)
        if asset_tmp.asset_body_size > 0:
            print("body:", binascii.b2a_hex(asset_tmp.asset_body))
        print("digest:", binascii.b2a_hex(asset_tmp.asset_id))