2018-07-12 21:05:24 +02:00
|
|
|
import tempfile
|
2019-02-12 03:35:07 +01:00
|
|
|
from integration.testcase import CommandTestCase
|
2018-08-17 03:42:38 +02:00
|
|
|
|
2018-07-05 04:16:02 +02:00
|
|
|
|
2018-08-01 04:59:51 +02:00
|
|
|
class EpicAdventuresOfChris45(CommandTestCase):
|
2018-11-04 07:24:41 +01:00
|
|
|
|
2018-10-16 17:03:56 +02:00
|
|
|
async def test_no_this_is_not_a_test_its_an_adventure(self):
|
2018-08-01 04:59:51 +02:00
|
|
|
# Chris45 is an avid user of LBRY and this is his story. It's fact and fiction
|
|
|
|
# and everything in between; it's also the setting of some record setting
|
|
|
|
# integration tests.
|
2018-07-06 07:17:20 +02:00
|
|
|
|
2018-08-01 04:59:51 +02:00
|
|
|
# Chris45 starts everyday by checking his balance.
|
2018-10-16 17:03:56 +02:00
|
|
|
result = await self.daemon.jsonrpc_account_balance()
|
2018-10-03 23:28:17 +02:00
|
|
|
self.assertEqual(result, '10.0')
|
2018-08-01 04:59:51 +02:00
|
|
|
# "10 LBC, yippy! I can do a lot with that.", he thinks to himself,
|
|
|
|
# enthusiastically. But he is hungry so he goes into the kitchen
|
|
|
|
# to make himself a spamdwich.
|
2018-07-10 06:20:37 +02:00
|
|
|
|
2018-08-01 04:59:51 +02:00
|
|
|
# While making the spamdwich he wonders... has anyone on LBRY
|
|
|
|
# registered the @spam channel yet? "I should do that!" he
|
|
|
|
# exclaims and goes back to his computer to do just that!
|
2018-10-16 17:03:56 +02:00
|
|
|
channel = await self.out(self.daemon.jsonrpc_channel_new('@spam', "1.0"))
|
2018-07-17 05:32:37 +02:00
|
|
|
self.assertTrue(channel['success'])
|
2018-10-16 17:03:56 +02:00
|
|
|
await self.confirm_tx(channel['tx']['txid'])
|
2018-07-10 06:20:37 +02:00
|
|
|
|
2018-08-04 03:39:48 +02:00
|
|
|
# Do we have it locally?
|
2018-10-16 17:03:56 +02:00
|
|
|
channels = await self.out(self.daemon.jsonrpc_channel_list())
|
2018-08-04 03:39:48 +02:00
|
|
|
self.assertEqual(len(channels), 1)
|
2018-08-04 18:10:41 +02:00
|
|
|
self.assertEqual(channels[0]['name'], '@spam')
|
2018-08-04 03:39:48 +02:00
|
|
|
|
2018-08-01 04:59:51 +02:00
|
|
|
# As the new channel claim travels through the intertubes and makes its
|
|
|
|
# way into the mempool and then a block and then into the claimtrie,
|
|
|
|
# Chris doesn't sit idly by: he checks his balance!
|
|
|
|
|
2018-10-16 17:03:56 +02:00
|
|
|
result = await self.daemon.jsonrpc_account_balance()
|
2018-10-03 23:28:17 +02:00
|
|
|
self.assertEqual(result, '8.989893')
|
2018-07-22 03:12:33 +02:00
|
|
|
|
2018-10-08 16:54:40 +02:00
|
|
|
# He waits for 6 more blocks (confirmations) to make sure the balance has been settled.
|
2018-10-16 17:03:56 +02:00
|
|
|
await self.generate(6)
|
|
|
|
result = await self.daemon.jsonrpc_account_balance(confirmations=6)
|
2018-10-03 23:28:17 +02:00
|
|
|
self.assertEqual(result, '8.989893')
|
2018-08-01 04:59:51 +02:00
|
|
|
|
2018-08-04 18:10:41 +02:00
|
|
|
# And is the channel resolvable and empty?
|
2019-02-12 03:35:07 +01:00
|
|
|
response = await self.out(self.daemon.jsonrpc_resolve('lbry://@spam'))
|
2018-08-04 18:10:41 +02:00
|
|
|
self.assertIn('lbry://@spam', response)
|
|
|
|
self.assertIn('certificate', response['lbry://@spam'])
|
|
|
|
|
2018-08-01 04:59:51 +02:00
|
|
|
# "What goes well with spam?" ponders Chris...
|
|
|
|
# "A hovercraft with eels!" he exclaims.
|
|
|
|
# "That's what goes great with spam!" he further confirms.
|
2018-07-22 03:12:33 +02:00
|
|
|
|
2018-08-01 04:59:51 +02:00
|
|
|
# And so, many hours later, Chris is finished writing his epic story
|
|
|
|
# about eels driving a hovercraft across the wetlands while eating spam
|
|
|
|
# and decides it's time to publish it to the @spam channel.
|
2018-07-12 21:05:24 +02:00
|
|
|
with tempfile.NamedTemporaryFile() as file:
|
2018-08-01 04:59:51 +02:00
|
|
|
file.write(b'blah blah blah...')
|
|
|
|
file.write(b'[insert long story about eels driving hovercraft]')
|
|
|
|
file.write(b'yada yada yada!')
|
|
|
|
file.write(b'the end')
|
2018-07-12 21:05:24 +02:00
|
|
|
file.flush()
|
2018-10-16 17:03:56 +02:00
|
|
|
claim1 = await self.out(self.daemon.jsonrpc_publish(
|
2018-09-24 06:30:24 +02:00
|
|
|
'hovercraft', '1.0', file_path=file.name, channel_id=channel['claim_id']
|
2018-08-17 03:42:38 +02:00
|
|
|
))
|
2018-08-01 04:59:51 +02:00
|
|
|
self.assertTrue(claim1['success'])
|
2018-10-16 17:03:56 +02:00
|
|
|
await self.confirm_tx(claim1['tx']['txid'])
|
2018-07-30 01:15:06 +02:00
|
|
|
|
2018-08-01 04:59:51 +02:00
|
|
|
# He quickly checks the unconfirmed balance to make sure everything looks
|
|
|
|
# correct.
|
2018-10-16 17:03:56 +02:00
|
|
|
result = await self.daemon.jsonrpc_account_balance()
|
2018-10-03 23:28:17 +02:00
|
|
|
self.assertEqual(result, '7.969786')
|
2018-07-30 01:15:06 +02:00
|
|
|
|
2018-08-01 04:59:51 +02:00
|
|
|
# Also checks that his new story can be found on the blockchain before
|
|
|
|
# giving the link to all his friends.
|
2019-02-12 03:35:07 +01:00
|
|
|
response = await self.out(self.daemon.jsonrpc_resolve('lbry://@spam/hovercraft'))
|
2018-07-30 01:15:06 +02:00
|
|
|
self.assertIn('lbry://@spam/hovercraft', response)
|
2018-08-04 03:39:48 +02:00
|
|
|
self.assertIn('claim', response['lbry://@spam/hovercraft'])
|
2018-07-30 01:15:06 +02:00
|
|
|
|
2018-08-01 04:59:51 +02:00
|
|
|
# He goes to tell everyone about it and in the meantime 5 blocks are confirmed.
|
2018-10-16 17:03:56 +02:00
|
|
|
await self.generate(5)
|
2018-08-01 04:59:51 +02:00
|
|
|
# When he comes back he verifies the confirmed balance.
|
2018-10-16 17:03:56 +02:00
|
|
|
result = await self.daemon.jsonrpc_account_balance()
|
2018-10-03 23:28:17 +02:00
|
|
|
self.assertEqual(result, '7.969786')
|
2018-07-30 01:15:06 +02:00
|
|
|
|
2018-08-01 04:59:51 +02:00
|
|
|
# As people start reading his story they discover some typos and notify
|
|
|
|
# Chris who explains in despair "Oh! Noooooos!" but then remembers
|
|
|
|
# "No big deal! I can update my claim." And so he updates his claim.
|
2018-07-30 01:15:06 +02:00
|
|
|
with tempfile.NamedTemporaryFile() as file:
|
2018-08-01 04:59:51 +02:00
|
|
|
file.write(b'blah blah blah...')
|
|
|
|
file.write(b'[typo fixing sounds being made]')
|
|
|
|
file.write(b'yada yada yada!')
|
2018-07-30 01:15:06 +02:00
|
|
|
file.flush()
|
2018-10-16 17:03:56 +02:00
|
|
|
claim2 = await self.out(self.daemon.jsonrpc_publish(
|
2018-09-24 06:30:24 +02:00
|
|
|
'hovercraft', '1.0', file_path=file.name, channel_name='@spam'
|
2018-08-17 03:42:38 +02:00
|
|
|
))
|
2018-08-01 04:59:51 +02:00
|
|
|
self.assertTrue(claim2['success'])
|
2018-08-04 18:10:41 +02:00
|
|
|
self.assertEqual(claim2['claim_id'], claim1['claim_id'])
|
2018-10-16 17:03:56 +02:00
|
|
|
await self.confirm_tx(claim2['tx']['txid'])
|
2018-08-01 04:59:51 +02:00
|
|
|
|
|
|
|
# After some soul searching Chris decides that his story needs more
|
|
|
|
# heart and a better ending. He takes down the story and begins the rewrite.
|
2018-11-08 00:07:33 +01:00
|
|
|
abandon = await self.out(self.daemon.jsonrpc_claim_abandon(claim1['claim_id'], blocking=False))
|
2018-08-01 04:59:51 +02:00
|
|
|
self.assertTrue(abandon['success'])
|
2018-10-16 17:03:56 +02:00
|
|
|
await self.confirm_tx(abandon['tx']['txid'])
|
2018-08-04 03:39:48 +02:00
|
|
|
|
2018-09-20 19:55:04 +02:00
|
|
|
# And now checks that the claim doesn't resolve anymore.
|
2019-02-12 03:35:07 +01:00
|
|
|
response = await self.out(self.daemon.jsonrpc_resolve('lbry://@spam/hovercraft'))
|
2018-08-04 03:39:48 +02:00
|
|
|
self.assertNotIn('claim', response['lbry://@spam/hovercraft'])
|
2018-08-30 06:04:25 +02:00
|
|
|
|
2018-09-03 17:41:30 +02:00
|
|
|
# After abandoning he just waits for his LBCs to be returned to his account
|
2018-10-16 17:03:56 +02:00
|
|
|
await self.generate(5)
|
|
|
|
result = await self.daemon.jsonrpc_account_balance()
|
2019-03-22 00:46:37 +01:00
|
|
|
self.assertEqual(result, '8.969381')
|
2018-09-03 17:41:30 +02:00
|
|
|
|
2018-09-03 17:41:40 +02:00
|
|
|
# Amidst all this Chris receives a call from his friend Ramsey
|
|
|
|
# who says that it is of utmost urgency that Chris transfer him
|
|
|
|
# 1 LBC to which Chris readily obliges
|
2018-10-16 17:03:56 +02:00
|
|
|
ramsey_account_id = (await self.daemon.jsonrpc_account_create("Ramsey"))['id']
|
2018-09-21 17:40:02 +02:00
|
|
|
ramsey_account = self.daemon.get_account_or_error(ramsey_account_id)
|
2018-10-16 17:03:56 +02:00
|
|
|
ramsey_address = await self.daemon.jsonrpc_address_unused(ramsey_account_id)
|
|
|
|
result = await self.out(self.daemon.jsonrpc_wallet_send('1.0', ramsey_address))
|
2018-09-03 17:41:30 +02:00
|
|
|
self.assertIn("txid", result)
|
2018-10-16 17:03:56 +02:00
|
|
|
await self.confirm_tx(result['txid'])
|
2018-09-03 17:41:30 +02:00
|
|
|
|
2018-09-03 17:41:40 +02:00
|
|
|
# Chris then eagerly waits for 6 confirmations to check his balance and then calls Ramsey to verify whether
|
2018-09-03 17:41:30 +02:00
|
|
|
# he received it or not
|
2018-10-16 17:03:56 +02:00
|
|
|
await self.generate(5)
|
|
|
|
result = await self.daemon.jsonrpc_account_balance()
|
2018-09-03 17:41:40 +02:00
|
|
|
# Chris' balance was correct
|
2019-03-22 00:46:37 +01:00
|
|
|
self.assertEqual(result, '7.969257')
|
2018-09-03 17:41:30 +02:00
|
|
|
|
2018-09-03 17:41:40 +02:00
|
|
|
# Ramsey too assured him that he had received the 1 LBC and thanks him
|
2018-10-16 17:03:56 +02:00
|
|
|
result = await self.daemon.jsonrpc_account_balance(ramsey_account_id)
|
2018-10-03 23:28:17 +02:00
|
|
|
self.assertEqual(result, '1.0')
|
2018-09-03 17:41:30 +02:00
|
|
|
|
2018-09-03 17:41:40 +02:00
|
|
|
# After Chris is done with all the "helping other people" stuff he decides that it's time to
|
|
|
|
# write a new story and publish it to lbry. All he needed was a fresh start and he came up with:
|
|
|
|
with tempfile.NamedTemporaryFile() as file:
|
|
|
|
file.write(b'Amazingly Original First Line')
|
|
|
|
file.write(b'Super plot for the grand novel')
|
|
|
|
file.write(b'Totally un-cliched ending')
|
|
|
|
file.write(b'**Audience Gasps**')
|
|
|
|
file.flush()
|
2018-10-16 21:04:20 +02:00
|
|
|
claim3 = await self.out(self.daemon.jsonrpc_publish(
|
2018-09-24 06:30:24 +02:00
|
|
|
'fresh-start', '1.0', file_path=file.name, channel_name='@spam'
|
2018-09-03 17:41:40 +02:00
|
|
|
))
|
|
|
|
self.assertTrue(claim3['success'])
|
2018-10-16 17:03:56 +02:00
|
|
|
await self.confirm_tx(claim3['tx']['txid'])
|
2018-09-03 17:41:40 +02:00
|
|
|
|
2018-10-16 17:03:56 +02:00
|
|
|
await self.generate(5)
|
2018-09-03 17:41:40 +02:00
|
|
|
|
|
|
|
# He gives the link of his story to all his friends and hopes that this is the much needed break for him
|
|
|
|
uri = 'lbry://@spam/fresh-start'
|
|
|
|
|
|
|
|
# And voila, and bravo and encore! His Best Friend Ramsey read the story and immediately knew this was a hit
|
|
|
|
# Now to keep this claim winning on the lbry blockchain he immediately supports the claim
|
2018-10-16 17:03:56 +02:00
|
|
|
tx = await self.out(self.daemon.jsonrpc_claim_new_support(
|
2018-09-24 06:30:24 +02:00
|
|
|
'fresh-start', claim3['claim_id'], '0.2', account_id=ramsey_account_id
|
2018-09-03 17:41:40 +02:00
|
|
|
))
|
2018-10-16 17:03:56 +02:00
|
|
|
await self.confirm_tx(tx['txid'])
|
2018-09-03 17:41:40 +02:00
|
|
|
|
|
|
|
# And check if his support showed up
|
2019-02-12 03:35:07 +01:00
|
|
|
resolve_result = await self.out(self.daemon.jsonrpc_resolve(uri))
|
2018-09-03 17:41:40 +02:00
|
|
|
# It obviously did! Because, blockchain baby \O/
|
2018-11-30 22:11:23 +01:00
|
|
|
self.assertEqual(resolve_result[uri]['claim']['amount'], '1.0')
|
|
|
|
self.assertEqual(resolve_result[uri]['claim']['effective_amount'], '1.2')
|
|
|
|
self.assertEqual(resolve_result[uri]['claim']['supports'][0]['amount'], '0.2')
|
2018-09-03 17:41:40 +02:00
|
|
|
self.assertEqual(resolve_result[uri]['claim']['supports'][0]['txid'], tx['txid'])
|
2018-10-16 17:03:56 +02:00
|
|
|
await self.generate(5)
|
2018-09-03 17:41:40 +02:00
|
|
|
|
|
|
|
# Now he also wanted to support the original creator of the Award Winning Novel
|
|
|
|
# So he quickly decides to send a tip to him
|
2018-10-16 17:03:56 +02:00
|
|
|
tx = await self.out(
|
2018-09-24 06:30:24 +02:00
|
|
|
self.daemon.jsonrpc_claim_tip(claim3['claim_id'], '0.3', account_id=ramsey_account_id))
|
2018-10-16 17:03:56 +02:00
|
|
|
await self.confirm_tx(tx['txid'])
|
2018-09-03 17:41:40 +02:00
|
|
|
|
|
|
|
# And again checks if it went to the just right place
|
2019-02-12 03:35:07 +01:00
|
|
|
resolve_result = await self.out(self.daemon.jsonrpc_resolve(uri))
|
2018-09-03 17:41:40 +02:00
|
|
|
# Which it obviously did. Because....?????
|
2018-11-30 22:11:23 +01:00
|
|
|
self.assertEqual(resolve_result[uri]['claim']['supports'][1]['amount'], '0.3')
|
2018-09-03 17:41:40 +02:00
|
|
|
self.assertEqual(resolve_result[uri]['claim']['supports'][1]['txid'], tx['txid'])
|
2018-10-16 17:03:56 +02:00
|
|
|
await self.generate(5)
|
2018-09-04 21:05:45 +02:00
|
|
|
|
|
|
|
# Seeing the ravishing success of his novel Chris adds support to his claim too
|
2018-10-16 17:03:56 +02:00
|
|
|
tx = await self.out(self.daemon.jsonrpc_claim_new_support('fresh-start', claim3['claim_id'], '0.4'))
|
|
|
|
await self.confirm_tx(tx['txid'])
|
2018-09-04 21:05:45 +02:00
|
|
|
|
|
|
|
# And check if his support showed up
|
2019-02-12 03:35:07 +01:00
|
|
|
resolve_result = await self.out(self.daemon.jsonrpc_resolve(uri))
|
2018-09-04 21:05:45 +02:00
|
|
|
# It did!
|
2018-11-30 22:11:23 +01:00
|
|
|
self.assertEqual(resolve_result[uri]['claim']['supports'][2]['amount'], '0.4')
|
2018-09-04 21:05:45 +02:00
|
|
|
self.assertEqual(resolve_result[uri]['claim']['supports'][2]['txid'], tx['txid'])
|
2018-10-16 17:03:56 +02:00
|
|
|
await self.generate(5)
|
2018-09-03 17:41:40 +02:00
|
|
|
|
2018-09-20 19:55:04 +02:00
|
|
|
# Now Ramsey who is a singer by profession, is preparing for his new "gig". He has everything in place for that
|
|
|
|
# the instruments, the theatre, the ads, everything, EXCEPT lyrics!! He panicked.. But then he remembered
|
|
|
|
# something, so he un-panicked. He quickly calls up his best bud Chris and requests him to write hit lyrics for
|
|
|
|
# his song, seeing as his novel had smashed all the records, he was the perfect candidate!
|
|
|
|
# .......
|
|
|
|
# Chris agrees.. 17 hours 43 minutes and 14 seconds later, he makes his publish
|
|
|
|
with tempfile.NamedTemporaryFile() as file:
|
|
|
|
file.write(b'The Whale amd The Bookmark')
|
|
|
|
file.write(b'I know right? Totally a hit song')
|
|
|
|
file.write(b'That\'s what goes around for songs these days anyways')
|
|
|
|
file.flush()
|
2018-10-16 21:04:20 +02:00
|
|
|
claim4 = await self.out(self.daemon.jsonrpc_publish(
|
2018-09-24 06:30:24 +02:00
|
|
|
'hit-song', '1.0', file_path=file.name, channel_id=channel['claim_id']
|
2018-09-20 19:55:04 +02:00
|
|
|
))
|
|
|
|
self.assertTrue(claim4['success'])
|
2018-10-16 17:03:56 +02:00
|
|
|
await self.confirm_tx(claim4['tx']['txid'])
|
2018-09-20 19:55:04 +02:00
|
|
|
|
2018-10-16 17:03:56 +02:00
|
|
|
await self.generate(5)
|
2018-09-20 19:55:04 +02:00
|
|
|
|
|
|
|
# He sends the link to Ramsey, all happy and proud
|
|
|
|
uri = 'lbry://@spam/hit-song'
|
|
|
|
|
|
|
|
# But sadly Ramsey wasn't so pleased. It was hard for him to tell Chris...
|
|
|
|
# Chris, though a bit heartbroken, abandoned the claim for now, but instantly started working on new hit lyrics
|
2018-11-08 00:07:33 +01:00
|
|
|
abandon = await self.out(self.daemon.jsonrpc_claim_abandon(txid=claim4['tx']['txid'], nout=0, blocking=False))
|
2018-09-20 19:55:04 +02:00
|
|
|
self.assertTrue(abandon['success'])
|
2018-10-16 17:03:56 +02:00
|
|
|
await self.confirm_tx(abandon['tx']['txid'])
|
2018-09-20 19:55:04 +02:00
|
|
|
|
|
|
|
# He them checks that the claim doesn't resolve anymore.
|
2019-02-12 03:35:07 +01:00
|
|
|
response = await self.out(self.daemon.jsonrpc_resolve(uri))
|
2018-09-20 19:55:04 +02:00
|
|
|
self.assertNotIn('claim', response[uri])
|