Пример #1
0
 def test_find(self):
     self.assertTrue(self.linkedlist.find(chain.Block('1')))
     self.assertTrue(self.linkedlist.find('1'))
     self.assertTrue(self.linkedlist.find(chain.Block('4')))
     self.assertTrue(self.linkedlist.find('4'))
     self.assertFalse(self.linkedlist.find(chain.Block('8')))
     self.assertFalse(self.linkedlist.find('8'))
Пример #2
0
 def test_append(self):
     self.assertEqual(self.linkedlist.index, 4)
     self.linkedlist.append(chain.Block('5'))
     self.linkedlist.append(chain.Block('6'))
     self.assertEqual(self.linkedlist.index, 6)
     self.assertEqual(self.linkedlist.header.data, '1')
     self.assertEqual(self.linkedlist.tail.data, '6')
     self.linkedlist.append('7')
     self.linkedlist.append('8')
     self.assertEqual(self.linkedlist.index, 8)
     self.assertEqual(self.linkedlist.header.data, '1')
     self.assertEqual(self.linkedlist.tail.data, '8')
Пример #3
0
    def setUp(self):
        self.block = chain.Block('1')
        self.chain = chain.Chain()
        self.linkedlist = chain.LinkedList()
        self.trns = chain.LinkedList()

        self.chain.add_transaction('1')
        self.chain.add_transaction('2')
        self.chain.add_transaction('3')

        self.linkedlist.append(chain.Block('1'))
        self.linkedlist.append(chain.Block('2'))
        self.linkedlist.append('3')
        self.linkedlist.append('4')
Пример #4
0
 def test_add_block(self):
     temp = self.linkedlist.index
     block = chain.Block(self.trns)
     block.index = self.linkedlist.get_next_index()
     block.time = 0
     block.prev_hash = self.linkedlist.get_tail_hash()
     block.hash = self.chain.hash(self.trns)
     self.linkedlist.append(block)
     self.assertEqual(self.linkedlist.index, temp + 1)
Пример #5
0
def get_highest_block(tips, block_origin, override_block_origin=None):
    if not override_block_origin:
        override_block_origin = block_origin

    highest_block = chain.Block(core.CoreRegTestParams.GENESIS_BLOCK, block_origin)
    highest_block.height = -1

    for tip in get_tips_for_block_origin(tips, block_origin):
        if tip.block_origin is override_block_origin:
            if highest_block.height <= tip.height:
                highest_block = tip
        else:
            if highest_block.height < tip.height:
                highest_block = tip
    return highest_block