コード例 #1
0
    def test_transfer_2of2_wif(self):
        nodelist = NodeList()
        # Send a 2 of 2 transaction from elf which needs crea4's cosign to send
        # funds but sign the transaction with elf's key and then serialize the transaction
        # and deserialize the transaction.  After that, sign with crea4's key.
        crea = Crea(
            node=self.nodes,
            num_retries=10,
            keys=[self.active_private_key_of_crea5],
            expiration=360,
        )

        tx = TransactionBuilder(use_condenser_api=True, crea_instance=crea)
        tx.appendOps(
            Transfer(
                **{
                    "from": 'crea5',
                    "to": 'crea',
                    "amount": Amount("0.01 CREA", crea_instance=crea),
                    "memo": '2 of 2 serialized/deserialized transaction'
                }))

        tx.appendSigner("crea5", "active")
        tx.addSigningInformation("crea5", "active")
        tx.sign()
        tx.clearWifs()
        self.assertEqual(len(tx['signatures']), 1)
        tx_json = tx.json()
        del crea
        del tx

        crea = Crea(
            node=self.nodes,
            num_retries=10,
            keys=[self.active_private_key_of_crea4],
            expiration=360,
        )
        new_tx = TransactionBuilder(tx=tx_json, crea_instance=crea)
        new_tx.appendMissingSignatures()
        new_tx.sign(reconstruct_tx=False)
        self.assertEqual(len(new_tx['signatures']), 2)
        new_tx.broadcast()
コード例 #2
0
    def test_transfer_2of2_serialized_deserialized(self):
        # Send a 2 of 2 transaction from crea5 which needs crea4's cosign to send
        # funds but sign the transaction with crea5's key and then serialize the transaction
        # and deserialize the transaction.  After that, sign with crea4's key.
        crea = self.bts
        crea.nobroadcast = False
        crea.wallet.unlock("123")
        # crea.wallet.removeAccount("crea4")
        crea.wallet.removePrivateKeyFromPublicKey(
            str(PublicKey(self.active_private_key_of_crea4, prefix=core_unit)))

        tx = TransactionBuilder(use_condenser_api=True, crea_instance=crea)
        tx.appendOps(
            Transfer(
                **{
                    "from": 'crea5',
                    "to": 'crea1',
                    "amount": Amount("0.01 CREA", crea_instance=crea),
                    "memo": '2 of 2 serialized/deserialized transaction'
                }))

        tx.appendSigner("crea5", "active")
        tx.addSigningInformation("crea5", "active")
        tx.sign()
        tx.clearWifs()
        self.assertEqual(len(tx['signatures']), 1)
        # crea.wallet.removeAccount("crea5")
        crea.wallet.removePrivateKeyFromPublicKey(
            str(PublicKey(self.active_private_key_of_crea5, prefix=core_unit)))
        tx_json = tx.json()
        del tx
        new_tx = TransactionBuilder(tx=tx_json, crea_instance=crea)
        self.assertEqual(len(new_tx['signatures']), 1)
        crea.wallet.addPrivateKey(self.active_private_key_of_crea4)
        new_tx.appendMissingSignatures()
        new_tx.sign(reconstruct_tx=False)
        self.assertEqual(len(new_tx['signatures']), 2)
        new_tx.broadcast()
        crea.nobroadcast = True