2018-07-01 23:20:17 +02:00
|
|
|
import asyncio
|
2018-06-27 02:22:35 +02:00
|
|
|
from orchstr8.testcase import IntegrationTestCase, d2f
|
2018-06-08 05:47:46 +02:00
|
|
|
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)
|
|
|
|
|
|
|
|
self.assertEqual(await self.get_balance(account1), 0)
|
|
|
|
self.assertEqual(await self.get_balance(account2), 0)
|
|
|
|
|
2018-07-01 23:20:17 +02:00
|
|
|
sendtxids = []
|
|
|
|
for i in range(9):
|
|
|
|
address1 = await d2f(account1.receiving.get_or_create_usable_address())
|
|
|
|
sendtxid = await self.blockchain.send_to_address(address1.decode(), 1.1)
|
|
|
|
sendtxids.append(sendtxid)
|
|
|
|
await self.on_transaction_id(sendtxid) # mempool
|
2018-06-12 16:02:04 +02:00
|
|
|
await self.blockchain.generate(1)
|
2018-07-01 23:20:17 +02:00
|
|
|
await asyncio.wait([ # confirmed
|
|
|
|
self.on_transaction_id(txid) for txid in sendtxids
|
|
|
|
])
|
2018-06-08 05:47:46 +02:00
|
|
|
|
2018-07-01 23:20:17 +02:00
|
|
|
self.assertEqual(round(await self.get_balance(account1)/COIN, 1), 9.9)
|
2018-06-27 02:22:35 +02:00
|
|
|
self.assertEqual(round(await self.get_balance(account2)/COIN, 1), 0)
|
2018-06-08 05:47:46 +02:00
|
|
|
|
2018-06-27 02:22:35 +02: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.pay(
|
|
|
|
[self.ledger.transaction_class.output_class.pay_pubkey_hash(2*COIN, hash2)],
|
2018-06-12 16:02:04 +02:00
|
|
|
[account1], account1
|
2018-06-27 02:22:35 +02:00
|
|
|
))
|
2018-06-08 05:47:46 +02:00
|
|
|
await self.broadcast(tx)
|
2018-06-27 02:22:35 +02:00
|
|
|
await self.on_transaction(tx) # mempool
|
2018-06-14 02:57:57 +02:00
|
|
|
await self.blockchain.generate(1)
|
2018-06-27 02:22:35 +02:00
|
|
|
await self.on_transaction(tx) # confirmed
|
2018-06-08 05:47:46 +02:00
|
|
|
|
2018-07-01 23:20:17 +02:00
|
|
|
self.assertEqual(round(await self.get_balance(account1)/COIN, 1), 7.9)
|
2018-06-27 02:22:35 +02:00
|
|
|
self.assertEqual(round(await self.get_balance(account2)/COIN, 1), 2.0)
|
2018-07-05 03:30:38 +02:00
|
|
|
|
|
|
|
all_balances = await d2f(self.manager.get_balance())
|
|
|
|
self.assertIn(self.ledger.get_id(), all_balances)
|
|
|
|
self.assertEqual(round(all_balances[self.ledger.get_id()]/COIN, 1), 9.9)
|