forked from LBRYCommunity/lbry-sdk
tests for transaction_list going through claim creation -> claim update -> claim abandon
This commit is contained in:
parent
fe844581fd
commit
4af830c405
3 changed files with 69 additions and 15 deletions
|
@ -307,7 +307,8 @@ class LbryWalletManager(BaseWalletManager):
|
||||||
'support_info': [],
|
'support_info': [],
|
||||||
'abandon_info': []
|
'abandon_info': []
|
||||||
}
|
}
|
||||||
if all([txi.is_my_account for txi in tx.inputs]):
|
is_my_inputs = all([txi.is_my_account for txi in tx.inputs])
|
||||||
|
if is_my_inputs:
|
||||||
# fees only matter if we are the ones paying them
|
# fees only matter if we are the ones paying them
|
||||||
item['value'] = dewies_to_lbc(tx.net_account_balance+tx.fee)
|
item['value'] = dewies_to_lbc(tx.net_account_balance+tx.fee)
|
||||||
item['fee'] = dewies_to_lbc(-tx.fee)
|
item['fee'] = dewies_to_lbc(-tx.fee)
|
||||||
|
@ -325,34 +326,53 @@ class LbryWalletManager(BaseWalletManager):
|
||||||
'nout': txo.position
|
'nout': txo.position
|
||||||
})
|
})
|
||||||
for txo in tx.my_update_outputs:
|
for txo in tx.my_update_outputs:
|
||||||
item['update_info'].append({
|
if is_my_inputs: # updating my own claim
|
||||||
'address': txo.get_address(account.ledger),
|
previous = None
|
||||||
'balance_delta': dewies_to_lbc(-txo.amount),
|
for txi in tx.inputs:
|
||||||
'amount': dewies_to_lbc(txo.amount),
|
if txi.txo_ref.txo is not None:
|
||||||
'claim_id': txo.claim_id,
|
other_txo = txi.txo_ref.txo
|
||||||
'claim_name': txo.claim_name,
|
if other_txo.is_claim and other_txo.claim_id == txo.claim_id:
|
||||||
'nout': txo.position
|
previous = other_txo
|
||||||
})
|
break
|
||||||
|
if previous is None:
|
||||||
|
raise ValueError(
|
||||||
|
"Invalid claim update state, expected to find previous claim in input."
|
||||||
|
)
|
||||||
|
item['update_info'].append({
|
||||||
|
'address': txo.get_address(account.ledger),
|
||||||
|
'balance_delta': dewies_to_lbc(previous.amount-txo.amount),
|
||||||
|
'amount': dewies_to_lbc(txo.amount),
|
||||||
|
'claim_id': txo.claim_id,
|
||||||
|
'claim_name': txo.claim_name,
|
||||||
|
'nout': txo.position
|
||||||
|
})
|
||||||
|
else: # someone sent us their claim
|
||||||
|
item['update_info'].append({
|
||||||
|
'address': txo.get_address(account.ledger),
|
||||||
|
'balance_delta': dewies_to_lbc(0),
|
||||||
|
'amount': dewies_to_lbc(txo.amount),
|
||||||
|
'claim_id': txo.claim_id,
|
||||||
|
'claim_name': txo.claim_name,
|
||||||
|
'nout': txo.position
|
||||||
|
})
|
||||||
for txo in tx.my_support_outputs:
|
for txo in tx.my_support_outputs:
|
||||||
is_tip = next(tx.my_inputs, None) is None
|
|
||||||
item['support_info'].append({
|
item['support_info'].append({
|
||||||
'address': txo.get_address(account.ledger),
|
'address': txo.get_address(account.ledger),
|
||||||
'balance_delta': dewies_to_lbc(txo.amount if is_tip else -txo.amount),
|
'balance_delta': dewies_to_lbc(txo.amount if not is_my_inputs else -txo.amount),
|
||||||
'amount': dewies_to_lbc(txo.amount),
|
'amount': dewies_to_lbc(txo.amount),
|
||||||
'claim_id': txo.claim_id,
|
'claim_id': txo.claim_id,
|
||||||
'claim_name': txo.claim_name,
|
'claim_name': txo.claim_name,
|
||||||
'is_tip': is_tip,
|
'is_tip': not is_my_inputs,
|
||||||
'nout': txo.position
|
'nout': txo.position
|
||||||
})
|
})
|
||||||
for txo in tx.other_support_outputs:
|
for txo in tx.other_support_outputs:
|
||||||
is_tip = next(tx.my_inputs, None) is not None
|
|
||||||
item['support_info'].append({
|
item['support_info'].append({
|
||||||
'address': txo.get_address(account.ledger),
|
'address': txo.get_address(account.ledger),
|
||||||
'balance_delta': dewies_to_lbc(-txo.amount),
|
'balance_delta': dewies_to_lbc(-txo.amount),
|
||||||
'amount': dewies_to_lbc(txo.amount),
|
'amount': dewies_to_lbc(txo.amount),
|
||||||
'claim_id': txo.claim_id,
|
'claim_id': txo.claim_id,
|
||||||
'claim_name': txo.claim_name,
|
'claim_name': txo.claim_name,
|
||||||
'is_tip': is_tip,
|
'is_tip': is_my_inputs,
|
||||||
'nout': txo.position
|
'nout': txo.position
|
||||||
})
|
})
|
||||||
for txo in tx.my_abandon_outputs:
|
for txo in tx.my_abandon_outputs:
|
||||||
|
|
|
@ -39,6 +39,10 @@ class Output(BaseOutput):
|
||||||
name_fee = len(self.script.values['claim_name']) * ledger.fee_per_name_char
|
name_fee = len(self.script.values['claim_name']) * ledger.fee_per_name_char
|
||||||
return max(name_fee, super().get_fee(ledger))
|
return max(name_fee, super().get_fee(ledger))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_claim(self) -> bool:
|
||||||
|
return self.script.is_claim_name or self.script.is_update_claim
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def claim_id(self) -> str:
|
def claim_id(self) -> str:
|
||||||
if self.script.is_claim_name:
|
if self.script.is_claim_name:
|
||||||
|
@ -57,7 +61,7 @@ class Output(BaseOutput):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def claim(self) -> ClaimDict:
|
def claim(self) -> ClaimDict:
|
||||||
if self.script.is_claim_name or self.script.is_update_claim:
|
if self.is_claim:
|
||||||
return smart_decode(self.script.values['claim'])
|
return smart_decode(self.script.values['claim'])
|
||||||
raise ValueError('Only claim name and claim update have the claim payload.')
|
raise ValueError('Only claim name and claim update have the claim payload.')
|
||||||
|
|
||||||
|
|
|
@ -494,6 +494,36 @@ class ClaimManagement(CommandTestCase):
|
||||||
await self.generate(1)
|
await self.generate(1)
|
||||||
return claim
|
return claim
|
||||||
|
|
||||||
|
async def test_create_update_and_abandon_claim(self):
|
||||||
|
self.assertEqual('10.0', await self.daemon.jsonrpc_account_balance())
|
||||||
|
|
||||||
|
claim = await self.make_claim(amount='2.5') # creates new claim
|
||||||
|
txs = await self.out(self.daemon.jsonrpc_transaction_list())
|
||||||
|
self.assertEqual(len(txs[0]['claim_info']), 1)
|
||||||
|
self.assertEqual(txs[0]['claim_info'][0]['balance_delta'], '-2.5')
|
||||||
|
self.assertEqual(txs[0]['claim_info'][0]['claim_id'], claim['claim_id'])
|
||||||
|
self.assertEqual(txs[0]['value'], '0.0')
|
||||||
|
self.assertEqual(txs[0]['fee'], '-0.020107')
|
||||||
|
self.assertEqual('7.479893', await self.daemon.jsonrpc_account_balance())
|
||||||
|
|
||||||
|
await self.make_claim(amount='1.0') # updates previous claim
|
||||||
|
txs = await self.out(self.daemon.jsonrpc_transaction_list())
|
||||||
|
self.assertEqual(len(txs[0]['update_info']), 1)
|
||||||
|
self.assertEqual(txs[0]['update_info'][0]['balance_delta'], '1.5')
|
||||||
|
self.assertEqual(txs[0]['update_info'][0]['claim_id'], claim['claim_id'])
|
||||||
|
self.assertEqual(txs[0]['value'], '0.0')
|
||||||
|
self.assertEqual(txs[0]['fee'], '-0.0001985')
|
||||||
|
self.assertEqual('8.9796945', await self.daemon.jsonrpc_account_balance())
|
||||||
|
|
||||||
|
await self.out(self.daemon.jsonrpc_claim_abandon(claim['claim_id']))
|
||||||
|
txs = await self.out(self.daemon.jsonrpc_transaction_list())
|
||||||
|
self.assertEqual(len(txs[0]['abandon_info']), 1)
|
||||||
|
self.assertEqual(txs[0]['abandon_info'][0]['balance_delta'], '1.0')
|
||||||
|
self.assertEqual(txs[0]['abandon_info'][0]['claim_id'], claim['claim_id'])
|
||||||
|
self.assertEqual(txs[0]['value'], '0.0')
|
||||||
|
self.assertEqual(txs[0]['fee'], '-0.000107')
|
||||||
|
self.assertEqual('9.9795875', await self.daemon.jsonrpc_account_balance())
|
||||||
|
|
||||||
async def test_update_claim_holding_address(self):
|
async def test_update_claim_holding_address(self):
|
||||||
other_account_id = (await self.daemon.jsonrpc_account_create('second account'))['id']
|
other_account_id = (await self.daemon.jsonrpc_account_create('second account'))['id']
|
||||||
other_account = self.daemon.get_account_or_error(other_account_id)
|
other_account = self.daemon.get_account_or_error(other_account_id)
|
||||||
|
|
Loading…
Reference in a new issue