Example #1
0
    def test_last_block(self):
        with set_wallet_dir("test_wallet"):
            with State() as state:
                self.assertIsNotNone(state)

                chain = Chain(state)
                alice_xmss = get_alice_xmss()
                staking_address = bytes(alice_xmss.get_address().encode())

                address_state_dict = dict()
                address_state_dict[staking_address] = AddressState.create(address=staking_address,
                                                                          nonce=0,
                                                                          balance=100,
                                                                          pubhashes=[])

                tmp_block1 = Block.create(staking_address=staking_address,
                                          block_number=0,
                                          reveal_hash=bytes(),
                                          prevblock_headerhash=bytes(),
                                          transactions=[],
                                          duplicate_transactions=OrderedDict(),
                                          vote=VoteMetadata(),
                                          signing_xmss=alice_xmss,
                                          nonce=address_state_dict[staking_address].nonce + 1)

                res = chain.add_block(tmp_block1, address_state_dict, None)
                address_state_dict[staking_address].increase_nonce()
                address_state_dict[staking_address].balance += tmp_block1.block_reward
                self.assertTrue(res)
                self.assertEqual(0, chain.height)           # FIXME: wrong name, it is not height but max_index

                last_block = chain.get_last_block()
                self.assertEqual(tmp_block1, last_block)
Example #2
0
    def test_add_many_and_save(self):
        with set_wallet_dir("test_wallet"):
            with State() as state:
                self.assertIsNotNone(state)

                chain = Chain(state)
                alice_xmss = get_alice_xmss()
                staking_address = bytes(alice_xmss.get_address().encode())

                with patch('qrl.core.config.dev.disk_writes_after_x_blocks'):
                    qrl.core.config.dev.disk_writes_after_x_blocks = 4

                    prev = bytes()
                    address_state_dict = dict()
                    address_state_dict[staking_address] = AddressState.create(
                        address=staking_address,
                        nonce=0,
                        balance=100,
                        pubhashes=[])
                    for i in range(10):
                        tmp_block1 = Block.create(
                            staking_address=staking_address,
                            block_number=i,
                            reveal_hash=bytes(),
                            prevblock_headerhash=prev,
                            transactions=[],
                            duplicate_transactions=OrderedDict(),
                            vote=VoteMetadata(),
                            signing_xmss=alice_xmss,
                            nonce=address_state_dict[staking_address].nonce +
                            1)
                        prev = tmp_block1.headerhash

                        res = chain.add_block(tmp_block1, address_state_dict,
                                              StakeValidatorsTracker(),
                                              b'1001', alice_xmss)

                        address_state_dict[staking_address].increase_nonce()
                        address_state_dict[
                            staking_address].balance += tmp_block1.block_reward

                        self.assertEqual(
                            i, chain.height
                        )  # FIXME: wrong name, it is not height but max_index

                        self.assertTrue(res)

                print(qrl.core.config.dev.disk_writes_after_x_blocks)