def test_is_valid_wait_certificate_2(self): addr = random_name(20) certs = generate_certs(WaitTimer.fixed_duration_blocks) txn_ids, block_hash = generate_txn_ids(10) wait_timer = WaitTimer.create_wait_timer(addr, certs) self.assertIsNotNone(wait_timer) while not wait_timer.is_expired(time.time()): time.sleep(1) wait_cert = WaitCertificate.create_wait_certificate( wait_timer, block_hash) self.assertIsNotNone(wait_cert) # Verify class changes don't affect validity d = wait_cert.duration wait_cert.duration = 0 r = wait_cert.is_valid_wait_certificate(addr, certs, txn_ids) self.assertTrue(r) wait_cert.duration = d lm = wait_cert.local_mean wait_cert.local_mean = wait_cert.local_mean - 1 r = wait_cert.is_valid_wait_certificate(addr, certs, txn_ids) self.assertTrue(r) wait_cert.local_mean = lm pc = wait_cert.previous_certificate_id wait_cert.previous_certificate_id = random_name( pe_sim.IDENTIFIER_LENGTH) r = wait_cert.is_valid_wait_certificate(addr, certs, txn_ids) self.assertTrue(r) wait_cert.previous_certificate_id = pc self.check_enclave_timer_tampering(wait_cert, addr, certs, txn_ids)
def test_serialize(self): addr = random_name(20) previous_cert_id = pe_sim.NULL_IDENTIFIER wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, 5) serialized_wait_timer = wait_timer.serialize() wait_timer2 = pe_sim.deserialize_wait_timer( serialized_wait_timer, wait_timer.signature) self.assertTrue(is_close( wait_timer.duration, wait_timer2.duration, rel_tol=0.0001)) self.assertEqual(wait_timer.request_time, wait_timer2.request_time) self.assertEqual(wait_timer.previous_certificate_id, wait_timer2.previous_certificate_id) self.assertEqual(wait_timer.signature, wait_timer2.signature) # Bad Serial strings with self.assertRaises(TypeError) as context: wait_timer2 = pe_sim.deserialize_wait_timer( None, wait_timer.signature) with self.assertRaises(TypeError) as context: wait_timer2 = pe_sim.deserialize_wait_timer([], wait_timer.signature) with self.assertRaises(TypeError) as context: wait_timer2 = pe_sim.deserialize_wait_timer(8, wait_timer.signature) with self.assertRaises(ValueError) as context: wait_timer2 = pe_sim.deserialize_wait_timer( random_name(len(serialized_wait_timer)), wait_timer.signature) with self.assertRaises(ValueError) as context: wait_timer2 = pe_sim.deserialize_wait_timer( serialized_wait_timer[:len(serialized_wait_timer) / 2], wait_timer.signature) # Bad Types with self.assertRaises(TypeError) as context: wait_timer2 = pe_sim.deserialize_wait_timer(serialized_wait_timer, None) with self.assertRaises(TypeError) as context: wait_timer2 = pe_sim.deserialize_wait_timer(serialized_wait_timer, []) with self.assertRaises(ValueError) as context: wait_timer2 = pe_sim.deserialize_wait_timer( serialized_wait_timer, "") with self.assertRaises(TypeError) as context: wait_timer2 = pe_sim.deserialize_wait_timer( serialized_wait_timer, 7) with self.assertRaises(ValueError) as context: wait_timer2 = pe_sim.deserialize_wait_timer( serialized_wait_timer, random_name(len(wait_timer.signature))) with self.assertRaises(TypeError) as context: wait_timer2 = pe_sim.deserialize_wait_timer(8, wait_timer.signature)
def test_verify(self): wait_cert = self.get_wait_cert() poet.verify_wait_certificate(wait_cert) with self.assertRaises(TypeError) as context: r = poet.verify_wait_certificate([]) self.assertFalse(r) with self.assertRaises(ValueError) as context: poet.verify_wait_certificate(None) with self.assertRaises(TypeError) as context: poet.verify_wait_certificate("3") # tamper with the data d = wait_cert.duration lm = wait_cert.local_mean pc = wait_cert.previous_certificate_id s = wait_cert.signature wait_cert.duration = 1 r = poet.verify_wait_certificate(wait_cert) self.assertFalse(r) # Make sure we restored the data correctly wait_cert.duration = d r = poet.verify_wait_certificate(wait_cert) self.assertTrue(r) wait_cert.local_mean = 1001 r = poet.verify_wait_certificate(wait_cert) self.assertFalse(r) # Make sure we restored the data correctly wait_cert.local_mean = lm r = poet.verify_wait_certificate(wait_cert) self.assertTrue(r) wait_cert.previous_certificate_id = \ random_name(poet.IDENTIFIER_LENGTH) r = poet.verify_wait_certificate(wait_cert) self.assertFalse(r) # Make sure we restored the data correctly wait_cert.previous_certificate_id = pc r = poet.verify_wait_certificate(wait_cert) self.assertTrue(r) wait_cert.signature = random_name(len(wait_cert.signature)) r = poet.verify_wait_certificate(wait_cert) self.assertFalse(r) # Make sure we restored the data correctly wait_cert.signature = s r = poet.verify_wait_certificate(wait_cert) self.assertTrue(r)
def get_wait_timer(self): pid = random_name(poet.IDENTIFIER_LENGTH) addr = random_name(20) # super short local mean to get small duration.. wait_timer = poet.create_wait_timer(addr, pid, 1) while not wait_timer.is_expired(): time.sleep(1) return wait_timer
def get_wait_timer(self): pid = random_name(pe_sim.IDENTIFIER_LENGTH) addr = random_name(20) # super short local mean to get small duration.. wait_timer = pe_sim.create_wait_timer(addr, pid, 1) while not wait_timer.is_expired(): time.sleep(1) return wait_timer
def test_verify(self): wait_cert = self.get_wait_cert() pe_sim.verify_wait_certificate(wait_cert) with self.assertRaises(TypeError) as context: r = pe_sim.verify_wait_certificate([]) self.assertFalse(r) with self.assertRaises(ValueError) as context: pe_sim.verify_wait_certificate(None) with self.assertRaises(TypeError) as context: pe_sim.verify_wait_certificate("3") # tamper with the data d = wait_cert.duration lm = wait_cert.local_mean pc = wait_cert.previous_certificate_id s = wait_cert.signature wait_cert.duration = 1 r = pe_sim.verify_wait_certificate(wait_cert) self.assertFalse(r) # Make sure we restored the data correctly wait_cert.duration = d r = pe_sim.verify_wait_certificate(wait_cert) self.assertTrue(r) wait_cert.local_mean = 1001 r = pe_sim.verify_wait_certificate(wait_cert) self.assertFalse(r) # Make sure we restored the data correctly wait_cert.local_mean = lm r = pe_sim.verify_wait_certificate(wait_cert) self.assertTrue(r) wait_cert.previous_certificate_id = \ random_name(pe_sim.IDENTIFIER_LENGTH) r = pe_sim.verify_wait_certificate(wait_cert) self.assertFalse(r) # Make sure we restored the data correctly wait_cert.previous_certificate_id = pc r = pe_sim.verify_wait_certificate(wait_cert) self.assertTrue(r) wait_cert.signature = random_name(len(wait_cert.signature)) r = pe_sim.verify_wait_certificate(wait_cert) self.assertFalse(r) # Make sure we restored the data correctly wait_cert.signature = s r = pe_sim.verify_wait_certificate(wait_cert) self.assertTrue(r)
def test_serialize(self): addr = random_name(20) previous_cert_id = poet.NULL_IDENTIFIER wait_timer = poet.create_wait_timer(addr, previous_cert_id, 5) serialized_wait_timer = wait_timer.serialize() wait_timer2 = poet.deserialize_wait_timer(serialized_wait_timer, wait_timer.signature) self.assertTrue( is_close(wait_timer.duration, wait_timer2.duration, rel_tol=0.0001)) self.assertEqual(wait_timer.request_time, wait_timer2.request_time) self.assertEqual(wait_timer.previous_certificate_id, wait_timer2.previous_certificate_id) self.assertEqual(wait_timer.signature, wait_timer2.signature) # Bad Serial strings with self.assertRaises(TypeError) as context: wait_timer2 = poet.deserialize_wait_timer(None, wait_timer.signature) with self.assertRaises(TypeError) as context: wait_timer2 = poet.deserialize_wait_timer([], wait_timer.signature) with self.assertRaises(TypeError) as context: wait_timer2 = poet.deserialize_wait_timer(8, wait_timer.signature) with self.assertRaises(ValueError) as context: wait_timer2 = poet.deserialize_wait_timer( random_name(len(serialized_wait_timer)), wait_timer.signature) with self.assertRaises(ValueError) as context: wait_timer2 = poet.deserialize_wait_timer( serialized_wait_timer[:len(serialized_wait_timer) / 2], wait_timer.signature) # Bad Types with self.assertRaises(TypeError) as context: wait_timer2 = poet.deserialize_wait_timer(serialized_wait_timer, None) with self.assertRaises(TypeError) as context: wait_timer2 = poet.deserialize_wait_timer(serialized_wait_timer, []) with self.assertRaises(ValueError) as context: wait_timer2 = poet.deserialize_wait_timer(serialized_wait_timer, "") with self.assertRaises(TypeError) as context: wait_timer2 = poet.deserialize_wait_timer(serialized_wait_timer, 7) with self.assertRaises(ValueError) as context: wait_timer2 = poet.deserialize_wait_timer( serialized_wait_timer, random_name(len(wait_timer.signature))) with self.assertRaises(TypeError) as context: wait_timer2 = poet.deserialize_wait_timer(8, wait_timer.signature)
def test_all_combinations(data): """ Scenario: 1. Create a station 2. Put a measure * Acceptance criteria: - if date in measure it should return 200 - else it should return 400 """ station_name = random_name() measure = dict(data) if data else {} print measure ret = add_station(station_name) assert ret.status_code == 200 ret = put_measures(station_name, measure) if "date" in measure.keys(): # date field is mandatory assert ret.status_code == 200 else: assert ret.status_code == 400
def test_station_deletion(length): """ Scenario: 1. Create a station 2. Delete it 3. Re-delete it * Acceptance criteria: 1. status code 200 2. status code 200 & No duplicate in listing station 3. Status code 400 """ station_name = random_name(length=length) ret = add_station(station_name) assert ret.status_code == 200 _, stations_list = list_stations() assert station_name in stations_list assert stations_list.count(station_name) == 1 ret = del_station(station_name) assert ret.status_code == 200 _, stations_list = list_stations() assert stations_list.count(station_name) == 0 ret = del_station(station_name) assert ret.status_code == 404
def __init__(self, scene): self._fishes = [] self._obstacles = [] self.timer = QTimer() self.timer.timeout.connect(self.update) self.timer.start(TICK) self._scene = scene for i in range(1, 101): color = QColor(randint(0, 255), randint(0, 255), randint(0, 255)) max_speed = 10 fish = Fish(randint(0, scene.width()), randint(0, scene.height()), color, max_speed, name=random_name()) self.add_fish(fish) fish.set_theta(randint(0, 360)) # fish.set_speed(10) for i in range(11): color = QColor(255, 255, 255) obstacle = Obstacle(randint(0, scene.width()), randint(0, scene.height()), color) self.add_obstacle(obstacle)
def test_create(self): addr = random_name(20) previous_cert_id = pe_sim.NULL_IDENTIFIER wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, 100) self.assertEquals(wait_timer.previous_certificate_id, previous_cert_id) self.assertEquals(wait_timer.local_mean, 100) # Random previous cert id previous_cert_id = random_name(pe_sim.IDENTIFIER_LENGTH) # Bad local means with self.assertRaises(TypeError) as context: wait_timer = pe_sim.create_wait_timer([], previous_cert_id, 100) with self.assertRaises(TypeError) as context: wait_timer = pe_sim.create_wait_timer({}, previous_cert_id, 100) with self.assertRaises(TypeError) as context: wait_timer = pe_sim.create_wait_timer(None, previous_cert_id, 100) with self.assertRaises(TypeError) as context: wait_timer = pe_sim.create_wait_timer(8888, previous_cert_id, 100) # Bad local means with self.assertRaises(ValueError) as context: wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, -1) with self.assertRaises(ValueError) as context: wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, 0) with self.assertRaises(TypeError) as context: wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, []) with self.assertRaises(TypeError) as context: wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, None) with self.assertRaises(TypeError) as context: wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, "3") # Bad previous cert len with self.assertRaises(TypeError) as context: wait_timer = pe_sim.create_wait_timer(addr, None, 0) previous_cert_id = "" # to short with self.assertRaises(ValueError) as context: wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, 100) previous_cert_id = random_name(8) # to short with self.assertRaises(ValueError) as context: wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, 100) previous_cert_id = random_name(17) # to long with self.assertRaises(ValueError) as context: wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, 100)
def test_create(self): addr = random_name(20) previous_cert_id = pe_sim.NULL_IDENTIFIER wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, 100) self.assertEqual(wait_timer.previous_certificate_id, previous_cert_id) self.assertEqual(wait_timer.local_mean, 100) # Random previous cert id previous_cert_id = random_name(pe_sim.IDENTIFIER_LENGTH) # Bad local means with self.assertRaises(TypeError) as context: wait_timer = pe_sim.create_wait_timer([], previous_cert_id, 100) with self.assertRaises(TypeError) as context: wait_timer = pe_sim.create_wait_timer({}, previous_cert_id, 100) with self.assertRaises(TypeError) as context: wait_timer = pe_sim.create_wait_timer(None, previous_cert_id, 100) with self.assertRaises(TypeError) as context: wait_timer = pe_sim.create_wait_timer(8888, previous_cert_id, 100) # Bad local means with self.assertRaises(ValueError) as context: wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, -1) with self.assertRaises(ValueError) as context: wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, 0) with self.assertRaises(TypeError) as context: wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, []) with self.assertRaises(TypeError) as context: wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, None) with self.assertRaises(TypeError) as context: wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, "3") # Bad previous cert len with self.assertRaises(TypeError) as context: wait_timer = pe_sim.create_wait_timer(addr, None, 0) previous_cert_id = "" # to short with self.assertRaises(ValueError) as context: wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, 100) previous_cert_id = random_name(8) # to short with self.assertRaises(ValueError) as context: wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, 100) previous_cert_id = random_name(17) # to long with self.assertRaises(ValueError) as context: wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, 100)
def test_verify_audiopass_success(sdk): """ Test a successful audiopass verification of an enrolled user """ name = utils.random_name() utils.enroll_without_exception(sdk, name, "1235") result = utils.verify_audiopass(sdk, name) assert result == 'Verified'
def test_verify_audiopass_single_error(sdk): """ Test an audiopass verification with a single word error. """ name = utils.random_name() utils.enroll_without_exception(sdk, name, "1235") result = utils.verify_audiopass(sdk, name, num_words_wrong=1) assert result == 'Single word error'
def test_enroll_success(sdk): """ Test the successful enrollment of a user. """ name = utils.random_name() utils.enroll_user(sdk, name, "1235") client_info = sdk.client_info(name) assert client_info['state'] == 'enrolled'
def test_is_expired(self): addr = random_name(20) previous_cert_id = pe_sim.NULL_IDENTIFIER wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, 5) start = time.time() while not wait_timer.is_expired(): time.sleep(1) end = time.time() self.assertLessEqual(wait_timer.duration, end - start)
def test_enroll_already_enrolled(sdk): """ Test the enrollment of a user who is already enrolled. """ name = utils.random_name() utils.enroll_without_exception(sdk, name, "2358") with pytest.raises(kex.BadRequestException): utils.enroll_user(sdk, name, "1235")
def test_create(self): # with expired timer -- positive case wait_timer = self.get_wait_timer() wait_cert = poet.create_wait_certificate(wait_timer) self.assertEqual(wait_timer.duration, wait_cert.duration) self.assertEqual(wait_timer.local_mean, wait_cert.local_mean) self.assertEqual(wait_timer.previous_certificate_id, wait_cert.previous_certificate_id) self.assertEquals(len(wait_cert.identifier()), poet.IDENTIFIER_LENGTH) # the initial block does not need to wait, to accelerate # validator launch wait_timer = poet.create_wait_timer(poet.NULL_IDENTIFIER, 1) wait_cert = poet.create_wait_certificate(wait_timer) self.assertEqual(wait_timer.duration, wait_cert.duration) self.assertEqual(wait_timer.local_mean, wait_cert.local_mean) self.assertEqual(wait_timer.previous_certificate_id, wait_cert.previous_certificate_id) # with unexpired timer wait_timer = poet.create_wait_timer( random_name(poet.IDENTIFIER_LENGTH), 1) wait_cert = poet.create_wait_certificate(wait_timer) # with tampered timer wait_timer = poet.create_wait_timer( random_name(poet.IDENTIFIER_LENGTH), 1) wait_timer.duration = 1 wait_cert = poet.create_wait_certificate(wait_timer) self.assertIsNone(wait_cert) wait_timer = poet.create_wait_timer( random_name(poet.IDENTIFIER_LENGTH), 1) wait_timer.local_mean = 1 wait_cert = poet.create_wait_certificate(wait_timer) self.assertIsNone(wait_cert) wait_timer = poet.create_wait_timer( random_name(poet.IDENTIFIER_LENGTH), 1) wait_timer.previous_certificate_id = \ random_name(poet.IDENTIFIER_LENGTH) wait_cert = poet.create_wait_certificate(wait_timer) self.assertIsNone(wait_cert)
def update_ai_data(robot): """ 更新机器人玩家身上的字段 攻城战的 """ ai_player = Player(pk=robot.pk, serverid=0) ai_player.level = robot.level while True: name = random_name() if _check_name(name) == 1: ai_player.name = name break ai_player.gold = ai_player.level * 500 + 5000 ai_player.wood = ai_player.level * 200 + 2000 ai_player.iconId = random.choice(Static.HERO_HERO_ICON_ID) ai_player.powerRank = robot.powerRank # 城墙 # acquire_building(ai_player, 1002002, level = 1 , centerX = 0, centerY = 0, status = 0) # 要塞 playerbuilding = acquire_building(ai_player, 1001001, level=robot.cityLevel, centerX=8, centerY=8, status=0) if ai_player.id == -1: pass # 攻城战保护时间safedTime unix时间 # ai_player.endLockedTime = datetime.datetime.max default_poses = Static.HERO_DEFENCE_POS # 科技树 ai_player.init_wall_warriorIds() for soldier in ai_player.wallWarriorIds: if soldier["soldierId"] == Static.HERO_WALL_SOLDIER_IDS[3]: # 防御塔 soldier["soldierLevel"] = robot.towerLevel # 英雄 defenseList = [] for _i, hero in enumerate(robot.heroes): defenseList.append(hero) defenseList.append(default_poses[_i]) ai_player.defenseSiegeLayout = defenseList defenseHeroIds = ai_player.defenseSiegeLayout[0:len(ai_player. defenseSiegeLayout):2] ai_player.update_siege_defenseHeroIds(defenseHeroIds) ai_player.defenseHeroLayout = defenseList defenseHeroIds = ai_player.defenseHeroLayout[0:len(ai_player. defenseHeroLayout):2] ai_player.update_hero_defenseHeroIds(defenseHeroIds) ai_player.save() return ai_player
def get_wait_timer(self, signup_info=None, addr=None): pid = random_name(poet.IDENTIFIER_LENGTH) if addr is None: addr = random_name(34) if signup_info is None: signup_info = poet.create_signup_info( originator_public_key_hash=self._originator_public_key_hash, nonce=poet.NULL_IDENTIFIER) sealed_data = signup_info.sealed_signup_data # super short local mean to get small duration.. wait_timer = poet.create_wait_timer(sealed_data, addr, pid, 1) while not wait_timer.has_expired(): time.sleep(1) return wait_timer
def get_current_user(req): ip = req.get('REMOTE_ADDR') try: current_user = Anon.get(Anon.ip == ip) except: anon = Anon(ip=ip, name=random_name()) anon.save() current_user = anon return current_user
def test_serialize_2(self): addr = random_name(20) previous_cert_id = pe_sim.NULL_IDENTIFIER wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, 5) serialized_wait_timer = wait_timer.serialize() wait_timer2 = pe_sim.deserialize_wait_timer( serialized_wait_timer, wait_timer.signature) # tampered data wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, 5) wait_timer.duration = 2 serialized_wait_timer = wait_timer.serialize() with self.assertRaises(ValueError) as context: wait_timer2 = pe_sim.deserialize_wait_timer(serialized_wait_timer, wait_timer.signature) wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, 5) wait_timer.request_time = 2 serialized_wait_timer = wait_timer.serialize() with self.assertRaises(ValueError) as context: wait_timer2 = pe_sim.deserialize_wait_timer(serialized_wait_timer, wait_timer.signature) wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, 5) wait_timer.previous_certificate_id = random_name( len(pe_sim.NULL_IDENTIFIER)) serialized_wait_timer = wait_timer.serialize() with self.assertRaises(ValueError) as context: wait_timer2 = pe_sim.deserialize_wait_timer(serialized_wait_timer, wait_timer.signature) wait_timer = pe_sim.create_wait_timer(addr, previous_cert_id, 5) wait_timer.validator_address = random_name(20) serialized_wait_timer = wait_timer.serialize() with self.assertRaises(ValueError) as context: wait_timer2 = pe_sim.deserialize_wait_timer(serialized_wait_timer, wait_timer.signature)
def test_create(self): addr = random_name(34) signup_info = poet.create_signup_info( originator_public_key_hash=self._originator_public_key_hash, nonce=poet.NULL_IDENTIFIER) sealed_data = signup_info.sealed_signup_data block_hash = random_name(32) # the initial block does not need to wait, to accelerate # validator launch wait_timer = poet.create_wait_timer(sealed_data, addr, poet.NULL_IDENTIFIER, 1) wait_cert = \ poet.create_wait_certificate( sealed_data, wait_timer, block_hash) self.assertEqual(wait_timer.duration, wait_cert.duration) self.assertEqual(wait_timer.local_mean, wait_cert.local_mean) self.assertEqual(wait_timer.previous_certificate_id, wait_cert.previous_certificate_id) self.assertEqual(len(wait_cert.identifier()), poet.IDENTIFIER_LENGTH)
def test_wait_certificate(self): addr = random_name(20) certs = generate_certs(WaitTimer.fixed_duration_blocks) txn_ids, block_hash = generate_txn_ids(10) wait_timer = WaitTimer.create_wait_timer(addr, certs) self.assertIsNotNone(wait_timer) while not wait_timer.is_expired(time.time()): time.sleep(1) wait_cert = WaitCertificate.create_wait_certificate( wait_timer, block_hash) self.assertIsNotNone(wait_cert) ewc = wait_cert.enclave_wait_certificate r = wait_cert.is_valid_wait_certificate(addr, certs, txn_ids) self.assertTrue(r) str(wait_cert) swc = WaitCertificate.deserialize_wait_certificate( wait_cert.serialized_cert, wait_cert.signature ) self.assertEquals(wait_cert.previous_certificate_id, swc.previous_certificate_id) self.assertEquals(wait_cert.local_mean, swc.local_mean) self.assertEquals(wait_cert.request_time, swc.request_time) self.assertEquals(wait_cert.duration, swc.duration) self.assertEquals(wait_cert.signature, swc.signature) self.assertEquals(wait_cert.identifier, swc.identifier) self.assertEquals(wait_cert.validator_address, swc.validator_address) self.assertEquals(wait_cert.block_hash, swc.block_hash) swc.is_valid_wait_certificate(addr, certs, txn_ids) dwc = wait_cert.dump() swc = WaitCertificate.deserialize_wait_certificate( dwc["SerializedCert"], dwc["Signature"] ) swc.is_valid_wait_certificate(addr, certs, txn_ids) self.assertEquals(wait_cert.previous_certificate_id, swc.previous_certificate_id) self.assertEquals(wait_cert.local_mean, swc.local_mean) self.assertEquals(wait_cert.request_time, swc.request_time) self.assertEquals(wait_cert.duration, swc.duration) self.assertEquals(wait_cert.signature, swc.signature) self.assertEquals(wait_cert.identifier, swc.identifier) self.assertEquals(wait_cert.validator_address, swc.validator_address) self.assertEquals(wait_cert.block_hash, swc.block_hash)
def test_wait_certificate(self): addr = random_name(20) certs = generate_certs(WaitTimer.fixed_duration_blocks) txn_ids, block_hash = generate_txn_ids(10) wait_timer = WaitTimer.create_wait_timer(addr, certs) self.assertIsNotNone(wait_timer) while not wait_timer.is_expired(time.time()): time.sleep(1) wait_cert = WaitCertificate.create_wait_certificate( wait_timer, block_hash) self.assertIsNotNone(wait_cert) ewc = wait_cert.enclave_wait_certificate r = wait_cert.is_valid_wait_certificate(addr, certs, txn_ids) self.assertTrue(r) str(wait_cert) swc = WaitCertificate.deserialize_wait_certificate( wait_cert.serialized_cert, wait_cert.signature ) self.assertEqual(wait_cert.previous_certificate_id, swc.previous_certificate_id) self.assertEqual(wait_cert.local_mean, swc.local_mean) self.assertEqual(wait_cert.request_time, swc.request_time) self.assertEqual(wait_cert.duration, swc.duration) self.assertEqual(wait_cert.signature, swc.signature) self.assertEqual(wait_cert.identifier, swc.identifier) self.assertEqual(wait_cert.validator_address, swc.validator_address) self.assertEqual(wait_cert.block_hash, swc.block_hash) swc.is_valid_wait_certificate(addr, certs, txn_ids) dwc = wait_cert.dump() swc = WaitCertificate.deserialize_wait_certificate( dwc["SerializedCert"], dwc["Signature"] ) swc.is_valid_wait_certificate(addr, certs, txn_ids) self.assertEqual(wait_cert.previous_certificate_id, swc.previous_certificate_id) self.assertEqual(wait_cert.local_mean, swc.local_mean) self.assertEqual(wait_cert.request_time, swc.request_time) self.assertEqual(wait_cert.duration, swc.duration) self.assertEqual(wait_cert.signature, swc.signature) self.assertEqual(wait_cert.identifier, swc.identifier) self.assertEqual(wait_cert.validator_address, swc.validator_address) self.assertEqual(wait_cert.block_hash, swc.block_hash)
def check_enclave_timer_tampering(self, wait_cert, oid, certs, txn_ids): # now we are going to tamper with the members of the enclave wait # timer object swc = wait_cert.serialized_cert ewt = wait_cert.enclave_wait_certificate d = ewt.duration ewt.duration = 0 wait_cert.serialized_cert = ewt.serialize() r = wait_cert.is_valid_wait_certificate(oid, certs, txn_ids) self.assertFalse(r) ewt.duration = d lm = ewt.local_mean ewt.local_mean = wait_cert.local_mean - 1 wait_cert.serialized_cert = ewt.serialize() r = wait_cert.is_valid_wait_certificate(oid, certs, txn_ids) self.assertFalse(r) ewt.local_mean = lm pc = wait_cert.previous_certificate_id ewt.previous_certificate_id = random_name(pe_sim.IDENTIFIER_LENGTH) ewt.serialized_cert = ewt.serialize() r = wait_cert.is_valid_wait_certificate(oid, certs, txn_ids) self.assertFalse(r) ewt.previous_certificate_id = pc # start up case, no previous certs and NULL_IDENTIFIER addr = random_name(20) block_hash = random_name(32) wait_timer = WaitTimer.create_wait_timer(addr, []) self.assertIsNotNone(wait_timer) wait_cert = WaitCertificate.create_wait_certificate( wait_timer, block_hash) self.assertIsNotNone(wait_cert) r = wait_cert.is_valid_wait_certificate(oid, [], txn_ids) self.assertTrue(r)
def get_wait_cert(self, signup_info=None, addr=None): block_hash = random_name(32) if signup_info is None: signup_info = poet.create_signup_info( originator_public_key_hash=self._originator_public_key_hash, nonce=poet.NULL_IDENTIFIER) sealed_data = signup_info.sealed_signup_data wait_timer = self.get_wait_timer(signup_info=signup_info, addr=addr) return \ poet.create_wait_certificate( sealed_data, wait_timer, block_hash)
def test_create(self): block_hash = random_name(32) addr = random_name(32) # with expired timer -- positive case wait_timer = self.get_wait_timer() wait_cert = pe_sim.create_wait_certificate(wait_timer, block_hash) self.assertEqual(wait_timer.duration, wait_cert.duration) self.assertEqual(wait_timer.local_mean, wait_cert.local_mean) self.assertEqual(wait_timer.previous_certificate_id, wait_cert.previous_certificate_id) self.assertEquals(len(wait_cert.identifier()), pe_sim.IDENTIFIER_LENGTH) # the initial block does not need to wait, to accelerate # validator launch wait_timer = pe_sim.create_wait_timer(addr, pe_sim.NULL_IDENTIFIER, 1) wait_cert = pe_sim.create_wait_certificate(wait_timer, block_hash) self.assertEqual(wait_timer.duration, wait_cert.duration) self.assertEqual(wait_timer.local_mean, wait_cert.local_mean) self.assertEqual(wait_timer.previous_certificate_id, wait_cert.previous_certificate_id) # with unexpired timer wait_timer = pe_sim.create_wait_timer( addr, random_name(pe_sim.IDENTIFIER_LENGTH), 1) wait_cert = pe_sim.create_wait_certificate(wait_timer, block_hash) # with tampered timer wait_timer = pe_sim.create_wait_timer( addr, random_name(pe_sim.IDENTIFIER_LENGTH), 1) wait_timer.duration = 1 wait_cert = pe_sim.create_wait_certificate(wait_timer, block_hash) self.assertIsNone(wait_cert) wait_timer = pe_sim.create_wait_timer( addr, random_name(pe_sim.IDENTIFIER_LENGTH), 1) wait_timer.local_mean = 1 wait_cert = pe_sim.create_wait_certificate(wait_timer, block_hash) self.assertIsNone(wait_cert) wait_timer = pe_sim.create_wait_timer( addr, random_name(pe_sim.IDENTIFIER_LENGTH), 1) wait_timer.previous_certificate_id = \ random_name(pe_sim.IDENTIFIER_LENGTH) wait_cert = pe_sim.create_wait_certificate(wait_timer, block_hash) self.assertIsNone(wait_cert)
def test_basic_pred(nb_samples, timeframe): """ Scenario: 1. Create a station 2. Put nb_samples samples shifted by one hour 3. Request a temperature prediction * Acceptance criteria: - if temperatures for a minimum duration of a day have not been reported the server should reject the request - else it should return a valid temperature """ # Compute the expected prediction date pred_date = timeframe + datetime.timedelta(hours=1) # Create a station name = random_name() ret = add_station(name) assert ret.status_code == 200 # Put measures for idx in range(nb_samples): # Data temperature = random.randint(-50, 60) c_date = timeframe + datetime.timedelta(hours=-idx) # minus 1 hour str_time = c_date.strftime("%Y-%m-%dT%H:%M:%d+00:00") data = {"temperature": temperature, "date": "{0}".format(str_time)} # Put updated measures ret = put_measures(name, data) assert ret.status_code == 200 # Request a prediction err, results = get_pred(name, 'temperature') if nb_samples >= 24: # Ensure prediction is in a valid range assert -50 <= int(results.get('value', 0)) <= 60 # Ensure date prediction equal to last sample +1 hour print results assert results.get('date') == pred_date.strftime("%Y-%m-%dT%H:%M:%d+00:00") else: msg = "It should have failed `Not enough samples to predict`" assert err == 400, msg
def test_verify(self): addr = random_name(34) signup_info = poet.create_signup_info( originator_public_key_hash=self._originator_public_key_hash, nonce=poet.NULL_IDENTIFIER) wait_cert = self.get_wait_cert(signup_info=signup_info, addr=addr) poet.verify_wait_certificate(wait_cert, signup_info.poet_public_key) with self.assertRaises(TypeError): poet.verify_wait_certificate([], signup_info.poet_public_key) with self.assertRaises(TypeError): poet.verify_wait_certificate({}, signup_info.poet_public_key) with self.assertRaises(ValueError): poet.verify_wait_certificate(None, signup_info.poet_public_key) with self.assertRaises(TypeError): poet.verify_wait_certificate("3", signup_info.poet_public_key) with self.assertRaises(TypeError): poet.verify_wait_certificate(3, signup_info.poet_public_key) # Bad public key types with self.assertRaises(TypeError): poet.verify_wait_certificate(wait_cert, []) with self.assertRaises(TypeError): poet.verify_wait_certificate(wait_cert, {}) with self.assertRaises(ValueError): poet.verify_wait_certificate(wait_cert, None) with self.assertRaises(TypeError): poet.verify_wait_certificate(wait_cert, 3) # A different public key other_signup_info = poet.create_signup_info( originator_public_key_hash=create_random_public_key_hash(), nonce=poet.NULL_IDENTIFIER) with self.assertRaises(ValueError): poet.verify_wait_certificate(wait_cert, other_signup_info.poet_public_key)
def test_is_valid_wait_certificate(self): addr = random_name(20) certs = generate_certs(WaitTimer.fixed_duration_blocks) txn_ids, block_hash = generate_txn_ids(10) wait_timer = WaitTimer.create_wait_timer(addr, certs) self.assertIsNotNone(wait_timer) while not wait_timer.is_expired(time.time()): time.sleep(1) wait_cert = WaitCertificate.create_wait_certificate( wait_timer, block_hash) self.assertIsNotNone(wait_cert) r = wait_cert.is_valid_wait_certificate(addr, certs, txn_ids) self.assertTrue(r) # invalid list with self.assertRaises(TypeError) as context: wait_cert.is_valid_wait_certificate(None, certs, txn_ids) with self.assertRaises(TypeError) as context: wait_cert.is_valid_wait_certificate({}, certs, txn_ids) with self.assertRaises(TypeError) as context: wait_cert.is_valid_wait_certificate([], certs, txn_ids) with self.assertRaises(TypeError) as context: wait_cert.is_valid_wait_certificate(555, certs, txn_ids) with self.assertRaises(TypeError) as context: wait_cert.is_valid_wait_certificate(addr, None, txn_ids) with self.assertRaises(TypeError) as context: wait_cert.is_valid_wait_certificate(addr, "test", txn_ids) with self.assertRaises(TypeError) as context: wait_cert.is_valid_wait_certificate(addr, {}, txn_ids) with self.assertRaises(TypeError) as context: wait_cert.is_valid_wait_certificate(addr, 545, txn_ids) with self.assertRaises(TypeError) as context: wait_cert.is_valid_wait_certificate(addr, certs, None) with self.assertRaises(TypeError) as context: wait_cert.is_valid_wait_certificate(addr, certs, {}) with self.assertRaises(TypeError) as context: wait_cert.is_valid_wait_certificate(addr, certs, "test") with self.assertRaises(TypeError) as context: wait_cert.is_valid_wait_certificate(addr, certs, 333)
def generate_names(planet_cx, options): height = options.height font_size = options.font_size random_name = utils.random_name() planet_name = etree.Element('text', id='planet_name') planet_name.set('x', str(planet_cx)) planet_name.set('y', str(0.90 * height)) planet_name.set('font-family', 'Helvetica') planet_name.set('style', 'text-anchor: middle') planet_name.set('font-size', str(font_size)) planet_name.set('fill-opacity', 'null') planet_name.set('fill', '#ffffff') planet_name.set('stroke-width', '0') planet_name.text = random_name return planet_name
def test_create_wait_timer(self): certs = [] # invalid list with self.assertRaises(TypeError) as context: WaitTimer.create_wait_timer(None, certs) with self.assertRaises(TypeError) as context: WaitTimer.create_wait_timer([], certs) with self.assertRaises(TypeError) as context: WaitTimer.create_wait_timer({}, certs) with self.assertRaises(TypeError) as context: WaitTimer.create_wait_timer(555, certs) addr = random_name(20) # invalid list with self.assertRaises(TypeError) as context: WaitTimer.create_wait_timer(addr, None) with self.assertRaises(TypeError) as context: WaitTimer.create_wait_timer(addr, "") with self.assertRaises(TypeError) as context: WaitTimer.create_wait_timer(addr, "XYZZY") with self.assertRaises(TypeError) as context: WaitTimer.create_wait_timer(addr, 555) certs = [] # empty list wait_timer = WaitTimer.create_wait_timer(addr, certs) # this will only catch changes in behavior of local mean calc self.assertEqual(wait_timer.local_mean, 30) certs = generate_certs(WaitTimer.fixed_duration_blocks - 1) wait_timer = WaitTimer.create_wait_timer(addr, certs) # this will only catch changes in behavior of local mean calc # based on the existing defaults... self.assertEqual(wait_timer.local_mean, 2882.388) certs = generate_certs(WaitTimer.fixed_duration_blocks) wait_timer = WaitTimer.create_wait_timer(addr, certs) self.assertEqual(wait_timer.local_mean, 30)
def test_is_expired(self): default_target_wait_time = WaitTimer.target_wait_time WaitTimer.target_wait_time = 1 # normal case addr = random_name(20) certs = generate_certs(WaitTimer.certificate_sample_length) wait_timer = WaitTimer.create_wait_timer(addr, certs) start = time.time() while not wait_timer.is_expired(time.time()): time.sleep(1) end = time.time() self.assertLessEqual(wait_timer.duration, end - start) # tamper with duration wait_timer = WaitTimer.create_wait_timer(addr, certs) d = wait_timer.duration wait_timer.duration = 1 start = time.time() while not wait_timer.is_expired(time.time()): time.sleep(1) end = time.time() self.assertLessEqual(d, end - start) # tamper with request_time wait_timer = WaitTimer.create_wait_timer(addr, certs) wait_timer.request_time = time.time() - wait_timer.duration while not wait_timer.is_expired(time.time()): time.sleep(1) end = time.time() self.assertLessEqual(wait_timer.duration, end - start) # restore default target_wait_time WaitTimer.target_wait_time = default_target_wait_time
def get_wait_cert(self): block_hash = random_name(32) wait_timer = self.get_wait_timer() return pe_sim.create_wait_certificate(wait_timer, block_hash)
def add_ai(): # ai = Ai() table.add_player(random_name(), is_ai=True) return redirect('/', 302)
def create_ai_player(robot): """ TODO : 攻城战的信息要加 """ from playerhero.api import acquire_hero player = Player(pk=robot.pk, serverid=0) while True: name = random_name() if _check_name(name) == 1: player.name = name break player.level = robot.level player.gold = player.level * 500 + 5000 player.wood = player.level * 200 + 2000 player.iconId = random.choice(Static.HERO_HERO_ICON_ID) player.powerRank = robot.powerRank # 新手引导专用机器人,其他类似于建筑物以后再修改 if player.id == -1: # 攻城战保护时间为safedTime unix时间 pass # player.endLockedTime = datetime.datetime.max defenseList = [] powerrank = 0 # # 机器人默认建筑 # 要塞 playerbuilding = acquire_building(player, 1001001, level=robot.cityLevel, centerX=8, centerY=8, status=0) # 城墙 攻城战需要城墙血量 playerbuilding = acquire_building(player, 1002002, level=1, centerX=0, centerY=0, status=0) # 科技树 player.init_wall_warriorIds() for soldier in player.wallWarriorIds: if soldier["soldierId"] == Static.HERO_WALL_SOLDIER_IDS[3]: # 防御塔 soldier["soldierLevel"] = robot.towerLevel default_poses = Static.HERO_DEFENCE_POS i = 0 for hero in robot.heroes: # todo 假数据----------------------- playerhero = acquire_hero( player, int("%s%s" % (hero, str(robot.heroUpgrades[i]).rjust(2, "0"))), star=robot.heroStars[i]) playerhero.level = robot.heroLevels[i] playerhero.star = robot.heroStars[i] playerhero.upgrade = robot.heroUpgrades[i] skillhero = get_heroskill(hero) # todo 暂时假设 ,以后修改 powerrank += playerhero.warrior.hero.powerRank + Static.HERO_STAR_POWERRANKS[ int(playerhero.star / 5) + 1][int(playerhero.warrior.hero.quality - 3)] * playerhero.level + Static.HERO_UPGRADE_POWERRANKS[int( playerhero.upgrade)] for j in range(0, len(skillhero.skillinfo) / 3): skillGid, _, upgrade = skillhero.skillinfo[j * 3:(j + 1) * 3] if upgrade <= playerhero.upgrade: setattr(playerhero, "skill%sLevel" % (j + 1), robot.heroSkillLevels[i]) if j == 0: powerrank += (robot.heroSkillLevels[i] + 1) * Static.HERO_BIGSPELL_POWERRANK_RATIO else: powerrank += (robot.heroSkillLevels[i] + 1) * Static.HERO_SMALLSPELL_POWERRANK_RATIO setattr(playerhero, "skill%sGid" % (j + 1), skillGid) player.update_hero(playerhero, True) defenseList.append(playerhero.pk) defenseList.append(default_poses[i]) i += 1 player.defenseHeroLayout = defenseList defenseHeroIds = player.defenseHeroLayout[0:len(player.defenseHeroLayout ):2] player.update_hero_defenseHeroIds(defenseHeroIds) player.defenseSiegeLayout = defenseList defenseHeroIds = player.defenseSiegeLayout[0:len(player.defenseSiegeLayout ):2] player.update_siege_defenseHeroIds(defenseHeroIds) # if player.id > -10000 and player.level >= Static.PVP_LEVEL: # player.PVP.add_score(robot.score-player.PVP.score) #player.PVP.update() player.save() return player
def get_random_name(): """ Return a random name for a board """ if request.is_ajax: return random_name(separator=u'-')
1. status code 200 2. status code 400 & No duplicate in listing station """ station_name = random_name(length=length) ret = add_station(station_name) assert ret.status_code == 200 _, stations_list = list_stations() assert station_name in stations_list assert stations_list.count(station_name) == 1 ret = add_station(station_name) assert ret.status_code == 400 @pytest.mark.parametrize("name", [random_name(chars=string.punctuation)]) def test_station_creation_fuzz(name): """ Scenario: 1. Create a station with weird characters (punctuations) * Acceptance criteria - Server should reject too weird names """ ret = add_station(name) assert ret.status_code == 400 @pytest.mark.parametrize("length", [1, 16, 32, 64, 128, 256, 512]) def test_station_deletion(length): """
def default_value(self): name = random_name() return name
def test_serialize(self): wait_cert = self.get_wait_cert() serialized_wait_cert = wait_cert.serialize() wait_cert2 = pe_sim.deserialize_wait_certificate( serialized_wait_cert, wait_cert.signature) self.assertTrue( is_close(wait_cert.duration, wait_cert2.duration, rel_tol=0.001)) self.assertEqual(wait_cert.local_mean, wait_cert2.local_mean) self.assertEqual(wait_cert.request_time, wait_cert2.request_time) self.assertEqual(wait_cert.previous_certificate_id, wait_cert.previous_certificate_id) self.assertEqual(wait_cert.signature, wait_cert2.signature) self.assertEqual(wait_cert.identifier(), wait_cert2.identifier()) # Bad Serial strings with self.assertRaises(TypeError) as context: wait_cert2 = pe_sim.deserialize_wait_certificate( None, wait_cert.signature) with self.assertRaises(TypeError) as context: wait_cert2 = pe_sim.deserialize_wait_certificate( [], wait_cert.signature) with self.assertRaises(TypeError) as context: wait_cert2 = pe_sim.deserialize_wait_certificate( 8, wait_cert.signature) with self.assertRaises(ValueError) as context: wait_cert2 = pe_sim.deserialize_wait_certificate( random_name(len(serialized_wait_cert)), wait_cert.signature) with self.assertRaises(ValueError) as context: wait_cert2 = pe_sim.deserialize_wait_certificate( serialized_wait_cert[:len(serialized_wait_cert) / 2], wait_cert.signature) # Bad Types with self.assertRaises(TypeError) as context: wait_cert2 = pe_sim.deserialize_wait_certificate( serialized_wait_cert, None) with self.assertRaises(TypeError) as context: wait_cert2 = pe_sim.deserialize_wait_certificate( serialized_wait_cert, []) with self.assertRaises(ValueError) as context: wait_cert2 = pe_sim.deserialize_wait_certificate( serialized_wait_cert, "") with self.assertRaises(TypeError) as context: wait_cert2 = pe_sim.deserialize_wait_certificate( serialized_wait_cert, 7) with self.assertRaises(ValueError) as context: wait_cert2 = pe_sim.deserialize_wait_certificate( serialized_wait_cert, random_name(len(wait_cert.signature))) with self.assertRaises(TypeError) as context: wait_cert2 = pe_sim.deserialize_wait_certificate( 8, wait_cert.signature) # tampered data wait_cert = self.get_wait_cert() wait_cert.duration = 2 serialized_wait_cert = wait_cert.serialize() with self.assertRaises(ValueError) as context: wait_cert2 = pe_sim.deserialize_wait_certificate( serialized_wait_cert, wait_cert.signature) wait_cert = self.get_wait_cert() wait_cert.request_time = 2 serialized_wait_cert = wait_cert.serialize() with self.assertRaises(ValueError) as context: wait_cert2 = pe_sim.deserialize_wait_certificate( serialized_wait_cert, wait_cert.signature) wait_cert = self.get_wait_cert() wait_cert.previous_certificate_id = random_name( len(pe_sim.NULL_IDENTIFIER)) serialized_wait_cert = wait_cert.serialize() with self.assertRaises(ValueError) as context: wait_cert2 = pe_sim.deserialize_wait_certificate( serialized_wait_cert, wait_cert.signature)
def test_serialize(self): wait_cert = self.get_wait_cert() serialized_wait_cert = wait_cert.serialize() wait_cert2 = poet.deserialize_wait_certificate( serialized_wait_cert, wait_cert.signature) self.assertTrue(is_close( wait_cert.duration, wait_cert2.duration, rel_tol=0.001)) self.assertEqual(wait_cert.local_mean, wait_cert2.local_mean) self.assertEqual(wait_cert.request_time, wait_cert2.request_time) self.assertEqual(wait_cert.previous_certificate_id, wait_cert.previous_certificate_id) self.assertEqual(wait_cert.signature, wait_cert2.signature) self.assertEqual(wait_cert.identifier(), wait_cert2.identifier()) # Bad Serial strings with self.assertRaises(TypeError) as context: wait_cert2 = poet.deserialize_wait_certificate( None, wait_cert.signature) with self.assertRaises(TypeError) as context: wait_cert2 = poet.deserialize_wait_certificate( [], wait_cert.signature) with self.assertRaises(TypeError) as context: wait_cert2 = poet.deserialize_wait_certificate( 8, wait_cert.signature) with self.assertRaises(ValueError) as context: wait_cert2 = poet.deserialize_wait_certificate( random_name(len(serialized_wait_cert)), wait_cert.signature) with self.assertRaises(ValueError) as context: wait_cert2 = poet.deserialize_wait_certificate( serialized_wait_cert[:len(serialized_wait_cert) / 2], wait_cert.signature) # Bad Types with self.assertRaises(TypeError) as context: wait_cert2 = poet.deserialize_wait_certificate( serialized_wait_cert, None) with self.assertRaises(TypeError) as context: wait_cert2 = poet.deserialize_wait_certificate( serialized_wait_cert, []) with self.assertRaises(ValueError) as context: wait_cert2 = poet.deserialize_wait_certificate( serialized_wait_cert, "") with self.assertRaises(TypeError) as context: wait_cert2 = poet.deserialize_wait_certificate( serialized_wait_cert, 7) with self.assertRaises(ValueError) as context: wait_cert2 = poet.deserialize_wait_certificate( serialized_wait_cert, random_name(len(wait_cert.signature))) with self.assertRaises(TypeError) as context: wait_cert2 = poet.deserialize_wait_certificate( 8, wait_cert.signature) # tampered data wait_cert = self.get_wait_cert() wait_cert.duration = 2 serialized_wait_cert = wait_cert.serialize() with self.assertRaises(ValueError) as context: wait_cert2 = poet.deserialize_wait_certificate( serialized_wait_cert, wait_cert.signature) wait_cert = self.get_wait_cert() wait_cert.request_time = 2 serialized_wait_cert = wait_cert.serialize() with self.assertRaises(ValueError) as context: wait_cert2 = poet.deserialize_wait_certificate( serialized_wait_cert, wait_cert.signature) wait_cert = self.get_wait_cert() wait_cert.previous_certificate_id = random_name( len(poet.NULL_IDENTIFIER)) serialized_wait_cert = wait_cert.serialize() with self.assertRaises(ValueError) as context: wait_cert2 = poet.deserialize_wait_certificate( serialized_wait_cert, wait_cert.signature)
def get_wait_cert(self): block_hash = random_name(32) wait_timer = self.get_wait_timer() return poet.create_wait_certificate(wait_timer, block_hash)