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_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 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)