lbry-sdk/tests/integration/test_transactions.py

56 lines
2.2 KiB
Python
Raw Normal View History

2018-07-01 17:20:17 -04:00
import asyncio
2018-06-26 20:22:35 -04:00
from orchstr8.testcase import IntegrationTestCase, d2f
2018-06-07 23:47:46 -04:00
from torba.constants import COIN
class BasicTransactionTests(IntegrationTestCase):
2018-07-10 21:23:13 -04:00
VERBOSE = False
2018-06-07 23:47:46 -04:00
2018-06-13 21:37:02 -04:00
async def test_sending_and_receiving(self):
2018-06-07 23:47:46 -04:00
account1, account2 = self.account, self.wallet.generate_account(self.ledger)
2018-08-30 14:40:44 -04:00
yield self.ledger.update_account(account2)
2018-06-07 23:47:46 -04:00
self.assertEqual(await self.get_balance(account1), 0)
self.assertEqual(await self.get_balance(account2), 0)
2018-07-01 17:20:17 -04:00
sendtxids = []
for i in range(5):
2018-07-01 17:20:17 -04:00
address1 = await d2f(account1.receiving.get_or_create_usable_address())
sendtxid = await self.blockchain.send_to_address(address1, 1.1)
2018-07-01 17:20:17 -04:00
sendtxids.append(sendtxid)
await self.on_transaction_id(sendtxid) # mempool
2018-06-12 10:02:04 -04:00
await self.blockchain.generate(1)
2018-07-01 17:20:17 -04:00
await asyncio.wait([ # confirmed
self.on_transaction_id(txid) for txid in sendtxids
])
2018-06-07 23:47:46 -04:00
self.assertEqual(round(await self.get_balance(account1)/COIN, 1), 5.5)
2018-06-26 20:22:35 -04:00
self.assertEqual(round(await self.get_balance(account2)/COIN, 1), 0)
2018-06-07 23:47:46 -04:00
2018-06-26 20:22:35 -04:00
address2 = await d2f(account2.receiving.get_or_create_usable_address())
hash2 = self.ledger.address_to_hash160(address2)
tx = await d2f(self.ledger.transaction_class.create(
[],
2018-06-26 20:22:35 -04:00
[self.ledger.transaction_class.output_class.pay_pubkey_hash(2*COIN, hash2)],
2018-06-12 10:02:04 -04:00
[account1], account1
2018-06-26 20:22:35 -04:00
))
2018-06-07 23:47:46 -04:00
await self.broadcast(tx)
2018-06-26 20:22:35 -04:00
await self.on_transaction(tx) # mempool
2018-06-13 20:57:57 -04:00
await self.blockchain.generate(1)
2018-06-26 20:22:35 -04:00
await self.on_transaction(tx) # confirmed
2018-06-07 23:47:46 -04:00
self.assertEqual(round(await self.get_balance(account1)/COIN, 1), 3.5)
2018-06-26 20:22:35 -04:00
self.assertEqual(round(await self.get_balance(account2)/COIN, 1), 2.0)
2018-07-04 21:30:38 -04:00
2018-07-09 22:02:18 -04:00
utxos = await d2f(self.account.get_unspent_outputs())
tx = await d2f(self.ledger.transaction_class.create(
[self.ledger.transaction_class.input_class.spend(utxos[0])],
[],
[account1], account1
2018-07-09 22:02:18 -04:00
))
await self.broadcast(tx)
await self.on_transaction(tx) # mempool
await self.blockchain.generate(1)
await self.on_transaction(tx) # confirmed