async def test_balance(self): address = await self.account.receiving.get_or_create_usable_address() hash160 = self.ledger.address_to_hash160(address) tx = Transaction(is_verified=True)\ .add_outputs([Output.pay_pubkey_hash(100, hash160)]) await self.ledger.db.save_transaction_io('insert', tx, address, hash160, '{}:{}:'.format(tx.id, 1)) self.assertEqual(await self.account.get_balance(), 100) tx = Transaction(is_verified=True)\ .add_outputs([Output.pay_claim_name_pubkey_hash(100, 'foo', b'', hash160)]) await self.ledger.db.save_transaction_io('insert', tx, address, hash160, '{}:{}:'.format(tx.id, 1)) self.assertEqual(await self.account.get_balance(), 100) # claim names don't count towards balance self.assertEqual(await self.account.get_balance(include_claims=True), 200)
def test_get_utxo(self): address = yield self.account.receiving.get_or_create_usable_address() hash160 = self.ledger.address_to_hash160(address) tx = Transaction().add_outputs([Output.pay_pubkey_hash(100, hash160)]) yield self.ledger.db.save_transaction_io('insert', tx, True, address, hash160, '{}:{}:'.format(tx.id, 1)) utxos = yield self.account.get_unspent_outputs() self.assertEqual(len(utxos), 1) tx = Transaction().add_inputs([Input.spend(utxos[0])]) yield self.ledger.db.save_transaction_io('insert', tx, True, address, hash160, '{}:{}:'.format(tx.id, 1)) balance = yield self.account.get_balance(0, include_claims=True) self.assertEqual(balance, 0) utxos = yield self.account.get_unspent_outputs() self.assertEqual(len(utxos), 0)
def test_balance(self): address = yield self.account.receiving.get_or_create_usable_address() hash160 = self.ledger.address_to_hash160(address) tx = Transaction().add_outputs([Output.pay_pubkey_hash(100, hash160)]) yield self.ledger.db.save_transaction_io('insert', tx, True, address, hash160, '{}:{}:'.format(tx.id, 1)) balance = yield self.account.get_balance(0) self.assertEqual(balance, 100) tx = Transaction().add_outputs( [Output.pay_claim_name_pubkey_hash(100, 'foo', b'', hash160)]) yield self.ledger.db.save_transaction_io('insert', tx, True, address, hash160, '{}:{}:'.format(tx.id, 1)) balance = yield self.account.get_balance(0) self.assertEqual(balance, 100) # claim names don't count towards balance balance = yield self.account.get_balance(0, include_claims=True) self.assertEqual(balance, 200)
async def test_sign(self): account = self.ledger.account_class.from_dict( self.ledger, Wallet(), { "seed": "carbon smart garage balance margin twelve chest sword toas" "t envelope bottom stomach absent" }) await account.ensure_address_gap() address1, address2 = await account.receiving.get_addresses(limit=2) pubkey_hash1 = self.ledger.address_to_hash160(address1) pubkey_hash2 = self.ledger.address_to_hash160(address2) tx = Transaction() \ .add_inputs([Input.spend(get_output(int(2*COIN), pubkey_hash1))]) \ .add_outputs([Output.pay_pubkey_hash(int(1.9*COIN), pubkey_hash2)]) await tx.sign([account]) self.assertEqual( hexlify(tx.inputs[0].script.values['signature']), b'304402200dafa26ad7cf38c5a971c8a25ce7d85a076235f146126762296b1223c42ae21e022020ef9eeb8' b'398327891008c5c0be4357683f12cb22346691ff23914f457bf679601')
def get_output(amount=CENT, pubkey_hash=NULL_HASH32): return Transaction() \ .add_outputs([Output.pay_pubkey_hash(amount, pubkey_hash)]) \ .outputs[0]
def get_transaction(txo=None): return Transaction() \ .add_inputs([get_input()]) \ .add_outputs([txo or Output.pay_pubkey_hash(CENT, NULL_HASH32)])
def get_stream_abandon(self, tx): claim = Transaction(tx[0].serialize()).outputs[0] return self._make_tx(Output.pay_pubkey_hash(claim.amount, b'abc'), Input.spend(claim))