lbry-sdk/tests/integration/test_transactions.py

40 lines
1.7 KiB
Python
Raw Normal View History

2018-06-08 05:47:46 +02:00
import asyncio
from orchstr8.testcase import IntegrationTestCase
from torba.constants import COIN
class BasicTransactionTests(IntegrationTestCase):
VERBOSE = True
2018-06-14 03:37:02 +02:00
async def test_sending_and_receiving(self):
2018-06-08 05:47:46 +02:00
account1, account2 = self.account, self.wallet.generate_account(self.ledger)
2018-06-12 16:02:04 +02:00
await account1.ensure_address_gap().asFuture(asyncio.get_event_loop())
2018-06-08 05:47:46 +02:00
self.assertEqual(await self.get_balance(account1), 0)
self.assertEqual(await self.get_balance(account2), 0)
2018-06-12 16:02:04 +02:00
address = await account1.receiving.get_or_create_usable_address().asFuture(asyncio.get_event_loop())
2018-06-08 05:47:46 +02:00
sendtxid = await self.blockchain.send_to_address(address.decode(), 5.5)
2018-06-14 02:57:57 +02:00
await self.on_transaction(sendtxid) #mempool
2018-06-12 16:02:04 +02:00
await self.blockchain.generate(1)
2018-06-14 02:57:57 +02:00
await self.on_transaction(sendtxid) #confirmed
2018-06-08 05:47:46 +02:00
self.assertEqual(await self.get_balance(account1), int(5.5*COIN))
self.assertEqual(await self.get_balance(account2), 0)
2018-06-12 16:02:04 +02:00
address = await account2.receiving.get_or_create_usable_address().asFuture(asyncio.get_event_loop())
tx = await self.ledger.transaction_class.pay(
2018-06-14 02:57:57 +02:00
[self.ledger.transaction_class.output_class.pay_pubkey_hash(2*COIN, self.ledger.address_to_hash160(address))],
2018-06-12 16:02:04 +02:00
[account1], account1
).asFuture(asyncio.get_event_loop())
2018-06-14 02:57:57 +02:00
await self.blockchain.decode_raw_transaction(tx)
2018-06-08 05:47:46 +02:00
await self.broadcast(tx)
2018-06-14 02:57:57 +02:00
await self.on_transaction(tx.hex_id.decode()) #mempool
await self.blockchain.generate(1)
await self.on_transaction(tx.hex_id.decode()) #confirmed
2018-06-08 05:47:46 +02:00
2018-06-14 02:57:57 +02:00
self.assertEqual(round(await self.get_balance(account1)/COIN, 1), 3.5)
self.assertEqual(round(await self.get_balance(account2)/COIN, 1), 2.0)