forked from LBRYCommunity/lbry-sdk
claim test
This commit is contained in:
parent
a4e9f3100f
commit
c4273fbef0
3 changed files with 22 additions and 16 deletions
|
@ -1,9 +1,9 @@
|
|||
import asyncio
|
||||
from binascii import hexlify, unhexlify
|
||||
from binascii import hexlify
|
||||
from orchstr8.testcase import IntegrationTestCase
|
||||
from lbryschema.claim import ClaimDict
|
||||
from torba.constants import COIN
|
||||
from lbrynet.wallet.manager import LbryWalletManager
|
||||
from lbrynet.wallet.transaction import Transaction
|
||||
|
||||
|
||||
example_claim_dict = {
|
||||
|
@ -36,7 +36,6 @@ example_claim_dict = {
|
|||
class ClaimTransactionTests(IntegrationTestCase):
|
||||
|
||||
VERBOSE = True
|
||||
WALLET_MANAGER = LbryWalletManager
|
||||
|
||||
async def test_creating_updating_and_abandoning_claim(self):
|
||||
|
||||
|
@ -51,13 +50,14 @@ class ClaimTransactionTests(IntegrationTestCase):
|
|||
self.assertEqual(round(await self.get_balance(self.account)/COIN, 1), 10.0)
|
||||
|
||||
claim = ClaimDict.load_dict(example_claim_dict)
|
||||
tx = self.manager.claim_name(b'foo', 1*COIN, hexlify(claim.serialized))
|
||||
tx = await Transaction.claim(b'foo', claim, 1*COIN, address, [self.account], self.account).asFuture(asyncio.get_event_loop())
|
||||
await self.broadcast(tx)
|
||||
await self.on_transaction(tx.hex_id.decode()) #mempool
|
||||
await self.blockchain.generate(1)
|
||||
await self.on_transaction(tx.hex_id.decode()) #confirmed
|
||||
await asyncio.sleep(5)
|
||||
|
||||
self.assertAlmostEqual(self.manager.get_balance(), 9, places=2)
|
||||
self.assertEqual(round(await self.get_balance(self.account)/COIN, 1), 10.0)
|
||||
|
||||
response = await self.resolve('lbry://foo')
|
||||
print(response)
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import os
|
||||
from twisted.internet import defer
|
||||
|
||||
from lbrynet.database.storage import SQLiteStorage
|
||||
|
||||
from torba.basetransaction import NULL_HASH
|
||||
from torba.constants import COIN
|
||||
from torba.coinselection import CoinSelector
|
||||
from torba.manager import WalletManager as BaseWalletManager
|
||||
|
||||
from lbrynet.wallet.database import WalletDatabase
|
||||
|
||||
|
||||
class BackwardsCompatibleNetwork:
|
||||
def __init__(self, manager):
|
||||
|
@ -22,15 +22,6 @@ class BackwardsCompatibleNetwork:
|
|||
|
||||
class LbryWalletManager(BaseWalletManager):
|
||||
|
||||
def __init__(self, db, **kwargs):
|
||||
super(LbryWalletManager, self).__init__(**kwargs)
|
||||
self.db = db # type: SQLiteStorage
|
||||
|
||||
def create_ledger(self, ledger_class, *args, **kwargs):
|
||||
if issubclass(ledger_class.database_class, self.db.__class__):
|
||||
return ledger_class(*args, db=self.db, **kwargs)
|
||||
return super(LbryWalletManager, self).create_ledger(ledger_class, *args, **kwargs)
|
||||
|
||||
@property
|
||||
def wallet(self):
|
||||
return self
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
import struct
|
||||
from binascii import hexlify
|
||||
from typing import List
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
from torba.baseaccount import BaseAccount
|
||||
from torba.basetransaction import BaseTransaction, BaseInput, BaseOutput
|
||||
from torba.hash import hash160
|
||||
|
||||
from lbryschema.claim import ClaimDict
|
||||
from .script import InputScript, OutputScript
|
||||
|
||||
|
||||
|
@ -32,3 +38,12 @@ class Transaction(BaseTransaction):
|
|||
output = self.outputs[output_index] # type: Output
|
||||
assert output.script.is_claim_name(), 'Not a name claim.'
|
||||
return claim_id_hash(self.hash, output_index)
|
||||
|
||||
@classmethod
|
||||
def claim(cls, name, meta, amount, holding_address, funding_accounts, change_account):
|
||||
# type: (bytes, ClaimDict, int, bytes, List[BaseAccount], BaseAccount) -> defer.Deferred
|
||||
ledger = cls.ensure_all_have_same_ledger(funding_accounts, change_account)
|
||||
claim_output = Output.pay_claim_name_pubkey_hash(
|
||||
amount, name, hexlify(meta.serialized), ledger.address_to_hash160(holding_address)
|
||||
)
|
||||
return cls.pay([claim_output], funding_accounts, change_account)
|
||||
|
|
Loading…
Reference in a new issue