Exemple #1
0
    async def test_new_signature_model(self):
        address1, address2 = await self.account.receiving.get_addresses(
            limit=2, only_usable=True)
        sendtxid1 = await self.blockchain.send_to_address(address1, 5)
        sendtxid2 = await self.blockchain.send_to_address(address2, 5)
        await self.blockchain.generate(1)
        await asyncio.wait([
            self.on_transaction_id(sendtxid1),
            self.on_transaction_id(sendtxid2)
        ])

        self.assertEqual(d2l(await self.account.get_balance()), '10.0')

        cert, key = generate_certificate()
        cert_tx = await Transaction.claim('@bar', cert, l2d('1.0'), address1,
                                          [self.account], self.account)
        claim = ClaimDict.load_dict(example_claim_dict)
        claim = claim.sign(key,
                           address1,
                           cert_tx.outputs[0].claim_id,
                           name='foo',
                           curve=SECP256k1,
                           force_detached=True)
        claim_tx = await Transaction.claim('foo', claim, l2d('1.0'), address1,
                                           [self.account], self.account)

        await self.broadcast(cert_tx)
        await self.broadcast(claim_tx)
        await self.ledger.wait(claim_tx)
        await self.blockchain.generate(1)
        await self.ledger.wait(claim_tx)

        response = await self.ledger.resolve(0, 10, 'lbry://@bar/foo')
        self.assertIn('lbry://@bar/foo', response)
        self.assertIn('claim', response['lbry://@bar/foo'])
Exemple #2
0
 async def claim_new_channel(self, channel_name, amount, account):
     address = await account.receiving.get_or_create_usable_address()
     cert, key = generate_certificate()
     tx = await Transaction.claim(channel_name, cert, amount, address,
                                  [account], account)
     await account.ledger.broadcast(tx)
     account.add_certificate_private_key(tx.outputs[0].ref, key.decode())
     # TODO: release reserved tx outputs in case anything fails by this point
     return tx
Exemple #3
0
    async def claim_new_channel(self, channel_name, amount, account):
        address = await account.receiving.get_or_create_usable_address()
        cert, key = generate_certificate()
        tx = await Transaction.claim(channel_name, cert, amount, address,
                                     [account], account)
        await account.ledger.broadcast(tx)
        account.add_certificate_private_key(tx.outputs[0].ref, key.decode())
        # TODO: release reserved tx outputs in case anything fails by this point

        await self.old_db.save_claims([
            self._old_get_temp_claim_info(tx, tx.outputs[0], address, cert,
                                          channel_name, dewies_to_lbc(amount))
        ]).asFuture(asyncio.get_event_loop())
        return tx
Exemple #4
0
    async def test_new_signature_model_from_unserializable_claim(self):
        address1, address2 = await self.account.receiving.get_addresses(
            limit=2, only_usable=True)
        sendtxid1 = await self.blockchain.send_to_address(address1, 5)
        sendtxid2 = await self.blockchain.send_to_address(address2, 5)
        await self.blockchain.generate(1)
        await asyncio.wait([
            self.on_transaction_id(sendtxid1),
            self.on_transaction_id(sendtxid2)
        ])

        self.assertEqual(d2l(await self.account.get_balance()), '10.0')

        cert, key = generate_certificate()
        cert_tx = await Transaction.claim('@bar', cert, l2d('1.0'), address1,
                                          [self.account], self.account)
        original = ClaimDict.load_dict(example_claim_dict).serialized
        altered = original + b'\x00\x01\x02\x30\x50\x80\x99'  # pretend this extra trash is from some unknown protobuf

        # manually sign
        signer = get_signer(SECP256k1).load_pem(key)
        signature = signer.sign(
            b'foo',
            decode_address(address1),
            altered,
            binascii.unhexlify(cert_tx.outputs[0].claim_id),
        )
        detached_sig = Signature(
            NAMED_SECP256K1(signature,
                            binascii.unhexlify(cert_tx.outputs[0].claim_id),
                            altered))
        claim_tx = await Transaction.claim('foo', detached_sig, l2d('1.0'),
                                           address1, [self.account],
                                           self.account)

        await self.broadcast(cert_tx)
        await self.broadcast(claim_tx)
        await self.ledger.wait(claim_tx)
        await self.blockchain.generate(1)
        await self.ledger.wait(claim_tx)

        response = await self.ledger.resolve(0, 10, 'lbry://@bar/foo')
        self.assertIn('lbry://@bar/foo', response)
        self.assertIn('claim', response['lbry://@bar/foo'])
Exemple #5
0
    async def test_creating_updating_and_abandoning_claim_with_channel(self):

        await self.account.ensure_address_gap()

        address1, address2 = await self.account.receiving.get_addresses(
            limit=2, only_usable=True)
        sendtxid1 = await self.blockchain.send_to_address(address1, 5)
        sendtxid2 = await self.blockchain.send_to_address(address2, 5)
        await self.blockchain.generate(1)
        await asyncio.wait([
            self.on_transaction_id(sendtxid1),
            self.on_transaction_id(sendtxid2)
        ])

        self.assertEqual(d2l(await self.account.get_balance()), '10.0')

        cert, key = generate_certificate()
        cert_tx = await Transaction.claim('@bar', cert, l2d('1.0'), address1,
                                          [self.account], self.account)
        claim = ClaimDict.load_dict(example_claim_dict)
        claim = claim.sign(key,
                           address1,
                           cert_tx.outputs[0].claim_id,
                           name='foo')
        claim_tx = await Transaction.claim('foo', claim, l2d('1.0'), address1,
                                           [self.account], self.account)

        await self.broadcast(cert_tx)
        await self.broadcast(claim_tx)
        await asyncio.wait([  # mempool
            self.ledger.wait(claim_tx),
            self.ledger.wait(cert_tx)
        ])
        await self.blockchain.generate(1)
        await asyncio.wait([  # confirmed
            self.ledger.wait(claim_tx),
            self.ledger.wait(cert_tx)
        ])

        self.assertEqual(d2l(await self.account.get_balance()), '7.985786')
        self.assertEqual(
            d2l(await self.account.get_balance(include_claims=True)),
            '9.985786')

        response = await self.ledger.resolve(0, 10, 'lbry://@bar/foo')
        self.assertIn('lbry://@bar/foo', response)
        self.assertIn('claim', response['lbry://@bar/foo'])

        abandon_tx = await Transaction.abandon([claim_tx.outputs[0]],
                                               [self.account], self.account)
        await self.broadcast(abandon_tx)
        await self.ledger.wait(abandon_tx)
        await self.blockchain.generate(1)
        await self.ledger.wait(abandon_tx)

        response = await self.ledger.resolve(0, 10, 'lbry://@bar/foo')
        self.assertNotIn('claim', response['lbry://@bar/foo'])

        # checks for expected format in inexistent URIs
        response = await self.ledger.resolve(0, 10, 'lbry://404',
                                             'lbry://@404')
        self.assertEqual('URI lbry://404 cannot be resolved',
                         response['lbry://404']['error'])
        self.assertEqual('URI lbry://@404 cannot be resolved',
                         response['lbry://@404']['error'])