Exemple #1
0
 def setUp(self):
     super().setUp()
     self.web = StubSite(CreateTxResource(self.manager))
     self.manager.wallet.unlock(b'MYPASS')
     self.spent_blocks = add_new_blocks(self.manager, 10)
     self.unspent_blocks = add_blocks_unlock_reward(self.manager)
     add_blocks_unlock_reward(self.manager)
     self.unspent_address = self.manager.wallet.get_unused_address()
     self.unspent_tx = add_new_tx(self.manager, self.unspent_address, 100)
     self.unspent_tx2 = add_new_tx(self.manager, self.unspent_address, 200)
     self.unspent_tx3 = add_new_tx(self.manager, self.unspent_address, 300)
     add_blocks_unlock_reward(self.manager)
        def setUp(self):
            super().setUp()

            self.manager = self.create_peer(network='testnet')

            self.hashes_before = set()
            for genesis in self.manager.tx_storage.get_all_genesis():
                self.hashes_before.add(genesis.hash)

            self.blocks_before = add_new_blocks(self.manager,
                                                3,
                                                advance_clock=1)
            self.blocks_before.extend(add_blocks_unlock_reward(self.manager))
            self.txs_before = add_new_transactions(self.manager, 5)
            for block in self.blocks_before:
                self.hashes_before.add(block.hash)
            for tx in self.txs_before:
                self.hashes_before.add(tx.hash)

            address = self.get_address(0)
            self.root_tx = add_new_tx(self.manager, address=address, value=100)

            self.blocks_after = add_blocks_unlock_reward(self.manager)
            self.txs_after = add_new_transactions(self.manager, 5)
            self.blocks_after.extend(
                add_new_blocks(self.manager, 3, advance_clock=1))

            self.hashes_after = set()
            for block in self.blocks_after:
                self.hashes_after.add(block.hash)
            for tx in self.txs_after:
                self.hashes_after.add(tx.hash)
Exemple #3
0
 def _add_new_transactions(self, manager, num_txs):
     txs = []
     for _ in range(num_txs):
         address = self.get_address(0)
         value = random.choice([5, 10, 15, 20])
         tx = add_new_tx(manager, address, value)
         txs.append(tx)
     return txs
Exemple #4
0
    def test_history_paginate(self):
        # Unlocking wallet
        self.manager.wallet.unlock(b'MYPASS')

        blocks = add_new_blocks(self.manager, 3, advance_clock=1)

        output = blocks[0].outputs[0]
        script_type_out = parse_address_script(output.script)
        address = script_type_out.address
        address_bytes = decode_address(address)

        # Test paginate
        response_history = yield self.web_address_history.get(
            'thin_wallet/address_history', {
                b'addresses[]': address.encode(),
                b'paginate': b'true'
            })

        response_data = response_history.json_value()
        self.assertEqual(len(response_data['history']), 1)
        self.assertEqual(blocks[0].hash.hex(),
                         response_data['history'][0]['tx_id'])
        self.assertFalse(response_data['has_more'])

        new_blocks = add_new_blocks(self.manager,
                                    settings.MAX_TX_ADDRESSES_HISTORY,
                                    advance_clock=1,
                                    address=address_bytes)

        # Test paginate with two pages
        response_history = yield self.web_address_history.get(
            'thin_wallet/address_history', {
                b'addresses[]': address.encode(),
                b'paginate': b'true'
            })

        response_data = response_history.json_value()
        self.assertEqual(len(response_data['history']),
                         settings.MAX_TX_ADDRESSES_HISTORY)
        self.assertTrue(response_data['has_more'])
        self.assertEqual(response_data['first_address'], address)

        # Test paginate with big txs
        tx_count = math.ceil(settings.MAX_INPUTS_OUTPUTS_ADDRESS_HISTORY /
                             settings.MAX_NUM_INPUTS)
        blocks.extend(new_blocks)
        new_blocks = add_new_blocks(self.manager,
                                    tx_count * settings.MAX_NUM_INPUTS -
                                    len(blocks),
                                    advance_clock=1,
                                    address=address_bytes)
        blocks.extend(new_blocks)
        random_address = self.get_address(0)
        add_blocks_unlock_reward(self.manager)

        for i in range(tx_count):
            start_index = i * settings.MAX_NUM_INPUTS
            end_index = start_index + settings.MAX_NUM_INPUTS
            amount = sum(
                [b.outputs[0].value for b in blocks[start_index:end_index]])
            add_new_tx(self.manager, random_address, amount, advance_clock=1)

        response_history = yield self.web_address_history.get(
            'thin_wallet/address_history', {
                b'addresses[]': random_address.encode(),
                b'paginate': b'true'
            })

        response_data = response_history.json_value()
        self.assertTrue(response_data['has_more'])
        # 1 block + 3 big txs
        self.assertEqual(len(response_data['history']), tx_count - 1)

        response_history = yield self.web_address_history.get(
            'thin_wallet/address_history', {
                b'addresses[]': random_address.encode(),
                b'hash': response_data['first_hash'].encode(),
                b'paginate': b'true'
            })

        response_data = response_history.json_value()
        self.assertFalse(response_data['has_more'])
        # The last big tx
        self.assertEqual(len(response_data['history']), 1)