def test_get_blocks_by_public_key(self): block = HalfBlock() block.public_key = "haha" block.sequence_number = 80 self.database.add_block(block) block_return = self.database.get_blocks_by_public_key( public_key="haha") assert block_return[0].public_key == "haha" assert block_return[0].sequence_number == 80
def test_add_and_get_block(self): block1 = HalfBlock() block1.public_key = self.my_public_key1 block2 = HalfBlock() block2.public_key = self.my_public_key2 self.database.add_block(block1) self.database.add_block(block2) results = self.database.get_blocks_by_public_key( public_key=self.my_public_key1) for result in results: block = HalfBlock(result) if block.public_key == self.my_public_key1: block.insert_time = block1.insert_time assert block.insert_time == block1.insert_time if block.public_key == self.my_public_key2: block.insert_time = block2.insert_time assert block == block2
def test_get_latest_sequence_number(self): block3 = HalfBlock() block3.public_key = self.my_public_key3 block3.sequence_number = 1 block4 = HalfBlock() block4.public_key = self.my_public_key3 block4.sequence_number = 2 self.database.add_block(block3) self.database.add_block(block4) sequence_number = self.database.get_latest_sequence_number( public_key=self.my_public_key3) assert sequence_number == 2
def decode_halfblock(self): #self.packet ---> self.(global_time,private_address_to_puncture,public_address_to_puncture,identifier,signature,start_header) offset = 23 self.start_header = self.packet[0:offset] #puncture-request uses NoAuthentication #puncture-request uses DirectDistribution self.global_time, = self.encoder_and_decoder_global_time.unpack_from( self.packet, offset) #print("global time is:" + str(self.global_time)) if len(self.packet) < offset + 14: print("the length is insufficient") self.block = HalfBlock.unpack(self.packet, offset + 8)
def test_get_blocks_since(self): block1 = HalfBlock() block1.public_key = self.my_public_key4 block1.sequence_number = 1 block2 = HalfBlock() block2.public_key = self.my_public_key4 block2.sequence_number = 2 self.database.add_block(block1) self.database.add_block(block2) blocks = self.database.get_blocks_since(sequence_number=2, public_key=self.my_public_key4) assert blocks[0].public_key == self.my_public_key4 assert blocks[0].sequence_number == 2
def test_has_block(self): block3 = HalfBlock() block3.public_key = self.my_public_key3 block4 = HalfBlock() block4.public_key = self.my_public_key4 self.database.add_block(block3) status1 = self.database.has_block(block3) status2 = self.database.has_block(block4) assert status1 == True assert status2 == False