Exemplo n.º 1
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)
Exemplo n.º 2
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()
Exemplo n.º 3
0
 def test_transactionbuilder(self, node_param):
     if node_param == "instance":
         set_shared_hive_instance(self.bts)
         o = TransactionBuilder()
         self.assertIn(o.hive.rpc.url, self.urls)
         with self.assertRaises(RPCConnection):
             o = TransactionBuilder(hive_instance=Hive(
                 node="https://abc.d", autoconnect=False, num_retries=1))
             o.hive.get_config()
     else:
         set_shared_hive_instance(
             Hive(node="https://abc.d", autoconnect=False, num_retries=1))
         hv = self.bts
         o = TransactionBuilder(hive_instance=hv)
         self.assertIn(o.hive.rpc.url, self.urls)
         with self.assertRaises(RPCConnection):
             o = TransactionBuilder()
             o.hive.get_config()
Exemplo n.º 4
0
 def test_transfer_1of1(self):
     hive = self.bts
     hive.nobroadcast = False
     tx = TransactionBuilder(use_condenser_api=True, hive_instance=hive)
     tx.appendOps(Transfer(**{"from": 'bhive',
                              "to": 'bhive1',
                              "amount": Amount("0.01 HIVE", hive_instance=hive),
                              "memo": '1 of 1 transaction'}))
     self.assertEqual(
         tx["operations"][0]["type"],
         "transfer_operation"
     )
     tx.appendWif(self.active_key)
     tx.sign()
     tx.sign()
     self.assertEqual(len(tx['signatures']), 1)
     tx.broadcast()
     hive.nobroadcast = True
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 7
0
def test_post(wls):
    op1 = operations.Social_action(
        **{
            "account": "guest123",
            "social_action_comment_create": {
                "permlink": 'just-a-test-post',
                "parent_author": "",
                "parent_permlink": "test",
                "title": "just a test post",
                "body": "test post body",
                "json_metadata": '{"app":"wls_python"}'
            }
        })

    op2 = operations.Social_action(
        **{
            "account": "guest123",
            "social_action_comment_update": {
                "permlink": 'just-a-test-post',
                "title": "just a test post",
                "body": "test post body",
            }
        })

    op3 = operations.Vote(
        **{
            'voter': 'guest123',
            'author': 'wlsuser',
            'permlink': 'another-test-post',
            'weight': 10000,
        })

    privateWif = "5K..."
    tx = TransactionBuilder(use_condenser_api=True, hive_instance=wls)
    tx.appendOps(op1)
    tx.appendWif(privateWif)
    tx.sign()
    tx.broadcast()
Exemplo n.º 8
0
from bhive.nodelist import NodeList
from bhivebase.transactions import getBlockParams
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

# example wif
wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"

if __name__ == "__main__":
    hv_online = Hive()
    ref_block_num, ref_block_prefix = getBlockParams(hv_online)
    print("ref_block_num %d - ref_block_prefix %d" %
          (ref_block_num, ref_block_prefix))

    hv = Hive(offline=True)

    op = operations.Transfer({
        'from': 'bhive.app',
        'to': 'thecrazygm',
        'amount': "0.001 HBD",
        'memo': ""
    })
    tb = TransactionBuilder(hive_instance=hv)

    tb.appendOps([op])
    tb.appendWif(wif)
    tb.constructTx(ref_block_num=ref_block_num,
                   ref_block_prefix=ref_block_prefix)
    tx = tb.sign(reconstruct_tx=False)
    print(tx.json())
Exemplo n.º 9
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)
Exemplo n.º 10
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)
Exemplo n.º 11
0
 def test_appendWif(self):
     nodelist = NodeList()
     hv = Hive(node=self.nodes,
                 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": ""}))
     with self.assertRaises(
         MissingKeyError
     ):
         tx.sign()
     with self.assertRaises(
         InvalidWifError
     ):
         tx.appendWif("abcdefg")
     tx.appendWif(self.active_key)
     tx.sign()
     self.assertTrue(len(tx["signatures"]) > 0)
Exemplo n.º 12
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()
Exemplo n.º 13
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)
Exemplo n.º 14
0
    def test_transfer_2of2_simple(self):
        # Send a 2 of 2 transaction from elf which needs bhive4's cosign to send funds
        hive = self.bts
        hive.nobroadcast = False
        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 simple transaction'}))

        tx.appendWif(self.active_private_key_of_bhive5)
        tx.sign()
        tx.clearWifs()
        tx.appendWif(self.active_private_key_of_bhive4)
        tx.sign(reconstruct_tx=False)
        self.assertEqual(len(tx['signatures']), 2)
        tx.broadcast()
        hive.nobroadcast = True
Exemplo n.º 15
0
 def test_emptyTransaction(self):
     hv = self.hv
     tx = TransactionBuilder(hive_instance=hv)
     self.assertTrue(tx.is_empty())
     self.assertTrue(tx["ref_block_num"] is not None)