Пример #1
0
    def test_transfer_2of2_offline(self):
        # Send a 2 of 2 transaction from bhive5 which needs bhive4's cosign to send
        # funds but sign the transaction with bhive5's key and then serialize the transaction
        # and deserialize the transaction.  After that, sign with bhive4's key.
        hive = self.bts
        hive.nobroadcast = False
        hive.wallet.unlock("123")
        # hive.wallet.removeAccount("bhive4")
        hive.wallet.removePrivateKeyFromPublicKey(str(PublicKey(self.active_private_key_of_bhive4, prefix=core_unit)))

        tx = TransactionBuilder(use_condenser_api=True, hive_instance=hive)
        tx.appendOps(Transfer(**{"from": 'bhive5',
                                 "to": 'bhive',
                                 "amount": Amount("0.01 HIVE", hive_instance=hive),
                                 "memo": '2 of 2 serialized/deserialized transaction'}))

        tx.appendSigner("bhive5", "active")
        tx.addSigningInformation("bhive5", "active")
        tx.sign()
        tx.clearWifs()
        self.assertEqual(len(tx['signatures']), 1)
        # hive.wallet.removeAccount("bhive5")
        hive.wallet.removePrivateKeyFromPublicKey(str(PublicKey(self.active_private_key_of_bhive5, prefix=core_unit)))
        hive.wallet.addPrivateKey(self.active_private_key_of_bhive4)
        tx.appendMissingSignatures()
        tx.sign(reconstruct_tx=False)
        self.assertEqual(len(tx['signatures']), 2)
        tx.broadcast()
        hive.nobroadcast = True
        hive.wallet.addPrivateKey(self.active_private_key_of_bhive5)
Пример #2
0
 def test_verifyAuthority(self):
     hv = self.bts
     hv.wallet.unlock("123")
     tx = TransactionBuilder(use_condenser_api=True, hive_instance=hv)
     tx.appendOps(Transfer(**{"from": "bhive",
                              "to": "bhive1",
                              "amount": Amount("1.300 HBD", hive_instance=hv),
                              "memo": "Foobar"}))
     account = Account("bhive", hive_instance=hv)
     tx.appendSigner(account, "active")
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     tx.verify_authority()
     self.assertTrue(len(tx["signatures"]) > 0)
Пример #3
0
    def test_Transfer_broadcast(self):
        nodelist = NodeList()
        hv = Hive(node=self.nodes,
                    keys=[self.active_key],
                    nobroadcast=True,
                    expiration=120,
                    num_retries=10)

        tx = TransactionBuilder(use_condenser_api=True, expiration=10, hive_instance=hv)
        tx.appendOps(Transfer(**{"from": "bhive",
                                 "to": "bhive1",
                                 "amount": Amount("1 HIVE", hive_instance=hv),
                                 "memo": ""}))
        tx.appendSigner("bhive", "active")
        tx.sign()
        tx.broadcast()
Пример #4
0
 def test_TransactionConstructor(self):
     hv = self.bts
     opTransfer = Transfer(**{"from": "bhive",
                              "to": "bhive1",
                              "amount": Amount("1 HIVE", hive_instance=hv),
                              "memo": ""})
     tx1 = TransactionBuilder(use_condenser_api=True, hive_instance=hv)
     tx1.appendOps(opTransfer)
     tx = TransactionBuilder(tx1, hive_instance=hv)
     self.assertFalse(tx.is_empty())
     self.assertTrue(len(tx.list_operations()) == 1)
     self.assertTrue(repr(tx) is not None)
     self.assertTrue(str(tx) is not None)
     account = Account("bhive", hive_instance=hv)
     tx.appendSigner(account, "active")
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     self.assertTrue(len(tx["signatures"]) > 0)
Пример #5
0
    def test_transfer_2of2_wallet(self):
        # Send a 2 of 2 transaction from bhive5 which needs bhive4's cosign to send
        # priv key of bhive5 and bhive4 are stored in the wallet
        # appendSigner fetches both keys and signs automatically with both keys.
        hive = self.bts
        hive.nobroadcast = False
        hive.wallet.unlock("123")

        tx = TransactionBuilder(use_condenser_api=True, hive_instance=hive)
        tx.appendOps(Transfer(**{"from": 'bhive5',
                                 "to": 'bhive1',
                                 "amount": Amount("0.01 HIVE", hive_instance=hive),
                                 "memo": '2 of 2 serialized/deserialized transaction'}))

        tx.appendSigner("bhive5", "active")
        tx.sign()
        self.assertEqual(len(tx['signatures']), 2)
        tx.broadcast()
        hive.nobroadcast = True
Пример #6
0
 def test_appendSigner(self):
     nodelist = NodeList()
     hv = Hive(node=self.nodes,
                 keys=[self.active_key],
                 nobroadcast=True,
                 expiration=120,
                 num_retries=10)
     tx = TransactionBuilder(use_condenser_api=True, hive_instance=hv)
     tx.appendOps(Transfer(**{"from": "bhive",
                              "to": "bhive1",
                              "amount": Amount("1 HIVE", hive_instance=hv),
                              "memo": ""}))
     account = Account("bhive", hive_instance=hv)
     with self.assertRaises(
         AssertionError
     ):
         tx.appendSigner(account, "abcdefg")
     tx.appendSigner(account, "active")
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     self.assertTrue(len(tx["signatures"]) > 0)
Пример #7
0
 def test_verifyAuthorityException(self):
     nodelist = NodeList()
     hv = Hive(node=self.nodes,
                 keys=[self.posting_key],
                 nobroadcast=True,
                 expiration=120,
                 num_retries=10)
     tx = TransactionBuilder(use_condenser_api=True, hive_instance=hv)
     tx.appendOps(Transfer(**{"from": "bhive",
                              "to": "bhive1",
                              "amount": Amount("1 HIVE", hive_instance=hv),
                              "memo": ""}))
     account = Account("bhive2", hive_instance=hv)
     tx.appendSigner(account, "active")
     tx.appendWif(self.posting_key)
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     with self.assertRaises(
         exceptions.MissingRequiredActiveAuthority
     ):
         tx.verify_authority()
     self.assertTrue(len(tx["signatures"]) > 0)
Пример #8
0
    def test_transfer_2of2_wif(self):
        nodelist = NodeList()
        # Send a 2 of 2 transaction from elf which needs bhive4'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 bhive4's key.
        hive = Hive(
            node=self.nodes,
            num_retries=10,
            keys=[self.active_private_key_of_bhive5],
            expiration=360,
        )

        tx = TransactionBuilder(use_condenser_api=True, hive_instance=hive)
        tx.appendOps(Transfer(**{"from": 'bhive5',
                                 "to": 'bhive',
                                 "amount": Amount("0.01 HIVE", hive_instance=hive),
                                 "memo": '2 of 2 serialized/deserialized transaction'}))

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

        hive = Hive(
            node=self.nodes,
            num_retries=10,
            keys=[self.active_private_key_of_bhive4],
            expiration=360,
        )
        new_tx = TransactionBuilder(tx=tx_json, hive_instance=hive)
        new_tx.appendMissingSignatures()
        new_tx.sign(reconstruct_tx=False)
        self.assertEqual(len(new_tx['signatures']), 2)
        new_tx.broadcast()