Exemple #1
0
    def test_transfer_2of2_offline(self):
        # Send a 2 of 2 transaction from dpaygo5 which needs dpaygo4's cosign to send
        # funds but sign the transaction with dpaygo5's key and then serialize the transaction
        # and deserialize the transaction.  After that, sign with dpaygo4's key.
        dpay = self.bts
        dpay.nobroadcast = False
        dpay.wallet.unlock("123")
        dpay.wallet.removeAccount("dpaygo4")

        tx = TransactionBuilder(dpay_instance=dpay)
        tx.appendOps(
            Transfer(
                **{
                    "from": 'dpaygo5',
                    "to": 'dpaygo',
                    "amount": '0.01 BBD',
                    "memo": '2 of 2 serialized/deserialized transaction'
                }))

        tx.appendSigner("dpaygo5", "active")
        tx.addSigningInformation("dpaygo5", "active")
        tx.sign()
        tx.clearWifs()
        self.assertEqual(len(tx['signatures']), 1)
        dpay.wallet.removeAccount("dpaygo5")
        dpay.wallet.addPrivateKey(self.active_private_key_of_dpaygo4)
        tx.appendMissingSignatures()
        tx.sign(reconstruct_tx=False)
        self.assertEqual(len(tx['signatures']), 2)
        tx.broadcast()
        dpay.nobroadcast = True
        dpay.wallet.addPrivateKey(self.active_private_key_of_dpaygo5)
Exemple #2
0
 def test_verifyAuthority(self):
     stm = self.bts
     stm.wallet.unlock("123")
     tx = TransactionBuilder(dpay_instance=stm)
     tx.appendOps(
         Transfer(
             **{
                 "from": "dpaygo",
                 "to": "dpaygo1",
                 "amount": "1.33 BEX",
                 "memo": "Foobar"
             }))
     account = Account("dpaygo", dpay_instance=stm)
     tx.appendSigner(account, "active")
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     tx.verify_authority()
     self.assertTrue(len(tx["signatures"]) > 0)
Exemple #3
0
    def test_transfer_2of2_wif(self):
        nodelist = NodeList()
        # Send a 2 of 2 transaction from elf which needs dpaygo4'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 dpaygo4's key.
        dpay = DPay(
            node=nodelist.get_testnet(),
            num_retries=10,
            keys=[self.active_private_key_of_dpaygo5],
            expiration=360,
        )

        tx = TransactionBuilder(dpay_instance=dpay)
        tx.appendOps(
            Transfer(
                **{
                    "from": 'dpaygo5',
                    "to": 'dpaygo',
                    "amount": '0.01 BBD',
                    "memo": '2 of 2 serialized/deserialized transaction'
                }))

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

        dpay = DPay(
            node=nodelist.get_testnet(),
            num_retries=10,
            keys=[self.active_private_key_of_dpaygo4],
            expiration=360,
        )
        new_tx = TransactionBuilder(tx=tx_json, dpay_instance=dpay)
        new_tx.appendMissingSignatures()
        new_tx.sign(reconstruct_tx=False)
        self.assertEqual(len(new_tx['signatures']), 2)
        new_tx.broadcast()
Exemple #4
0
    def test_Transfer_broadcast(self):
        nodelist = NodeList()
        stm = DPay(node=nodelist.get_testnet(),
                   keys=[self.active_key],
                   nobroadcast=True,
                   expiration=120,
                   num_retries=10)

        tx = TransactionBuilder(expiration=10, dpay_instance=stm)
        tx.appendOps(
            Transfer(
                **{
                    "from": "dpaygo",
                    "to": "dpaygo1",
                    "amount": Amount("1 BEX", dpay_instance=stm),
                    "memo": ""
                }))
        tx.appendSigner("dpaygo", "active")
        tx.sign()
        tx.broadcast()
Exemple #5
0
 def test_TransactionConstructor(self):
     stm = self.bts
     opTransfer = Transfer(
         **{
             "from": "dpaygo",
             "to": "dpaygo1",
             "amount": Amount("1 BEX", dpay_instance=stm),
             "memo": ""
         })
     tx1 = TransactionBuilder(dpay_instance=stm)
     tx1.appendOps(opTransfer)
     tx = TransactionBuilder(tx1, dpay_instance=stm)
     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("dpaygo", dpay_instance=stm)
     tx.appendSigner(account, "active")
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     self.assertTrue(len(tx["signatures"]) > 0)
Exemple #6
0
 def test_appendSigner(self):
     nodelist = NodeList()
     stm = DPay(node=nodelist.get_testnet(),
                keys=[self.active_key],
                nobroadcast=True,
                expiration=120,
                num_retries=10)
     tx = TransactionBuilder(dpay_instance=stm)
     tx.appendOps(
         Transfer(
             **{
                 "from": "dpaygo",
                 "to": "dpaygo1",
                 "amount": Amount("1 BEX", dpay_instance=stm),
                 "memo": ""
             }))
     account = Account("dpaygo", dpay_instance=stm)
     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)
Exemple #7
0
    def test_transfer_2of2_wallet(self):
        # Send a 2 of 2 transaction from elf which needs dpaygo4's cosign to send
        # priv key of elf and dpaygo4 are stored in the wallet
        # appendSigner fetches both keys and signs automatically with both keys.
        dpay = self.bts
        dpay.nobroadcast = False
        dpay.wallet.unlock("123")

        tx = TransactionBuilder(dpay_instance=dpay)
        tx.appendOps(
            Transfer(
                **{
                    "from": 'dpaygo5',
                    "to": 'dpaygo1',
                    "amount": '0.01 BBD',
                    "memo": '2 of 2 serialized/deserialized transaction'
                }))

        tx.appendSigner("dpaygo5", "active")
        tx.sign()
        self.assertEqual(len(tx['signatures']), 2)
        tx.broadcast()
        dpay.nobroadcast = True
Exemple #8
0
 def test_verifyAuthorityException(self):
     nodelist = NodeList()
     stm = DPay(node=nodelist.get_testnet(),
                keys=[self.posting_key],
                nobroadcast=True,
                expiration=120,
                num_retries=10)
     tx = TransactionBuilder(dpay_instance=stm)
     tx.appendOps(
         Transfer(
             **{
                 "from": "dpaygo",
                 "to": "dpaygo1",
                 "amount": Amount("1 BEX", dpay_instance=stm),
                 "memo": ""
             }))
     account = Account("dpaygo2", dpay_instance=stm)
     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)