Пример #1
0
 def test_CreateABlockChainWhenAddBlockToItThenGetChainShouldReturnAListOfBlocks(
         self):
     blockchain = BlockChain()
     block = Block(0)
     blockchain.add_block(block)
     assert_that(blockchain.get_chain(), instance_of(list))
     assert_that(blockchain.get_chain()[0].index, equal_to(0))
Пример #2
0
 def test_CreateABlockWithoutInputThenItsPropertyShouldBeNone(self):
     block = Block()
     assert_that(block.index, none())
     assert_that(block.time_stamp, none())
     assert_that(block.data, none())
     assert_that(block.pre_hash, none())
     assert_that(block.block_hash, none())
Пример #3
0
 def test_CreateABlockWhenSetAPropertyThenItCouldNotBeSetAgain(self):
     block = Block(0, 0, "hello", "123", "456")
     block.index = 1
     block.time_stamp = 1
     block.data = "bye"
     block.pre_hash = "789"
     block.block_hash = "100"
     assert_that(block.index, equal_to(0))
     assert_that(block.time_stamp, equal_to(0))
     assert_that(block.data, equal_to("hello"))
     assert_that(block.pre_hash, equal_to("123"))
     assert_that(block.block_hash, equal_to("456"))
Пример #4
0
 def convert(self, block_dict: dict):
     if "index" not in block_dict:
         raise ValueError('No Index Value')
     if 'time_stamp' not in block_dict:
         raise ValueError('No Time Stamp Value')
     if 'data' not in block_dict:
         raise ValueError('No Data Value')
     if 'pre_hash' not in block_dict:
         raise ValueError('No PreHash Value')
     if 'block_hash' not in block_dict:
         raise ValueError('No BlockHash Value')
     return Block(int(block_dict['index']), int(block_dict['time_stamp']),
                  block_dict['data'], block_dict['pre_hash'],
                  block_dict['block_hash'])
Пример #5
0
def build_block():
    for x in range(st.NUMBER_COLUMN):
        for y in range(st.NUMBER_ROW):
            if not (x == st.NUMBER_COLUMN / 2 and y == st.NUMBER_ROW / 2):
                block = Block(st.SIZE_BORDER + st.SIZE * x,
                              st.SIZE_BORDER + st.SIZE * y)
                if not random.randint(0,
                                      st.DENSITY_MINES) and block.is_empty():
                    block.is_mine = True
                elif not random.randint(
                        0, st.DENSITY_MONSTERS) and block.is_empty():
                    block.is_monster = True
                elif not random.randint(
                        0, st.DENSITY_SUPERMONSTERS) and block.is_empty():
                    block.is_super_monster = True
Пример #6
0
def restore_blocks(mydb):
    mycol = mydb["blocks"]  #create collection
    mylist = mycol.find()
    for data_block in mylist:
        block = Block(data_block["x"], data_block["y"])
        block.is_mine = data_block["is_mine"]
        block.is_monster = data_block["is_monster"]
        block.is_super_monster = data_block["is_super_monster"]
        block.is_key = data_block["is_key"]
        block.is_exit = data_block["is_exit"]
        block.is_open = data_block["is_open"]
    for blocks in Data.blocks:
        for block in blocks:
            if (not block):
                continue
            elif block.is_open:
                block.restore()