示例#1
0
    def test_override_same_height(self):
        private_tip = Block(CBlock(), None)
        private_tip.height = 2

        public_tip = Block(CBlock(), None)
        public_tip.height = 2

        with self.assertRaisesRegexp(ActionException, "private tip.*must > then public tip.*override.*"):
            self.executor.execute(Action.override, private_tip, public_tip)
示例#2
0
    def test_match_lead_public(self):
        private_tip = Block(CBlock(), None)
        private_tip.height = 1

        public_tip = Block(CBlock(), None)
        public_tip.height = 2

        with self.assertRaisesRegexp(ActionException, "private tip.*must >= then public tip.*match.*"):
            self.executor.execute(Action.match, private_tip, public_tip)
示例#3
0
    def test_adopt_same_height(self):
        private_tip = Block(CBlock(), None)
        private_tip.height = 2

        public_tip = Block(CBlock(), None)
        public_tip.height = 2

        with self.assertRaisesRegexp(ActionException, "public tip.*must > then private tip.*adopt.*"):
            self.executor.execute(Action.adopt, private_tip, public_tip)
示例#4
0
    def test_insert_block_initializing_false(self):
        prevBlock = Block(CBlock(), BlockOrigin.private)
        prevBlock.cached_hash = 'hash2'
        prevBlock.height = 45
        block = Block(CBlock(), BlockOrigin.private)
        block.cached_hash = 'hash1'
        self.chain.tips = [prevBlock]
        self.chain.initializing = False

        self.chain.insert_block(prevBlock, block)

        retrieved_block = self.chain.tips[0]
        self.assertEqual(retrieved_block, block)
        self.assertEqual(retrieved_block.transfer_allowed, False)
示例#5
0
    def test_adopt_two_blocks_lead_public(self):
        third_block_chain_b = Block(CBlock(), BlockOrigin.public)
        third_block_chain_b.height = 3
        third_block_chain_b.prevBlock = self.second_block_chain_b
        third_block_chain_b.cached_hash = '3b'

        self.executor.execute(Action.adopt, self.first_block_chain_a, third_block_chain_b)

        self.assertTrue(self.networking.send_inv.called)

        blocks = [block.hash() for block in self.networking.send_inv.call_args[0][0]]

        self.assertEqual(len(blocks), 3)
        self.assertTrue('1b' in blocks)
        self.assertTrue('2b' in blocks)
        self.assertTrue('3b' in blocks)
示例#6
0
    def test_override_two_blocks_lead_private(self):
        third_block_chain_a = Block(CBlock(), BlockOrigin.private)
        third_block_chain_a.height = 3
        third_block_chain_a.prevBlock = self.second_block_chain_a
        third_block_chain_a.cached_hash = '3a'

        self.executor.execute(Action.override, third_block_chain_a, self.first_block_chain_b)

        self.assertTrue(self.networking.send_inv.called)

        blocks = [block.hash() for block in self.networking.send_inv.call_args[0][0]]

        self.assertEqual(len(blocks), 3)
        self.assertTrue('1a' in blocks)
        self.assertTrue('2a' in blocks)
        self.assertTrue('1b' in blocks)
示例#7
0
    def test_insert_block(self):
        prevBlock = Block(CBlock(), BlockOrigin.private)
        prevBlock.cached_hash = 'hash2'
        prevBlock.height = 45
        block = Block(CBlock(), BlockOrigin.private)
        block.cached_hash = 'hash1'
        self.chain.tips = [prevBlock]

        self.chain.insert_block(prevBlock, block)

        self.assertFalse(prevBlock in self.chain.tips)
        self.assertEqual(len(self.chain.tips), 1)

        retrieved_block = self.chain.tips[0]
        self.assertEqual(retrieved_block, block)
        self.assertEqual(retrieved_block.prevBlock, prevBlock)
        self.assertEqual(retrieved_block.height, 46)
示例#8
0
from bitcoin import core
from chain import Block
from chain import BlockOrigin

genesis_hash = core.CoreRegTestParams.GENESIS_BLOCK.GetHash()
genesis_block = Block(core.CoreRegTestParams.GENESIS_BLOCK, BlockOrigin.public)
genesis_block.height = 0
genesis_block.transfer_allowed = True
genesis_block.cblock = core.CoreRegTestParams.GENESIS_BLOCK