From 063a249eaa60bca9d5f51f059cd97034442be298 Mon Sep 17 00:00:00 2001 From: felixfaisal Date: Tue, 10 Oct 2023 06:46:09 +0000 Subject: [PATCH 01/15] fix: add deps for test --- tee-worker/litentry/core/stf-task/receiver/Cargo.toml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tee-worker/litentry/core/stf-task/receiver/Cargo.toml b/tee-worker/litentry/core/stf-task/receiver/Cargo.toml index 4a35022dd6..84bc0b902a 100644 --- a/tee-worker/litentry/core/stf-task/receiver/Cargo.toml +++ b/tee-worker/litentry/core/stf-task/receiver/Cargo.toml @@ -45,6 +45,16 @@ lc-identity-verification = { path = "../../identity-verification", default-featu lc-stf-task-sender = { path = "../sender", default-features = false } litentry-primitives = { path = "../../../primitives", default-features = false } +[dev-dependencies] +sgx_crypto_helper = { version = "1.1.6", git = "https://github.com/apache/incubator-teaclave-sgx-sdk", branch = "master" } +itp-test = { path = "../../../../core-primitives/test" } +itp-top-pool-author = { path = "../../../../core-primitives/top-pool-author", features = ["mocks"] } +itp-top-pool = { path = "../../../../core-primitives/top-pool", features = ["mocks"] } +itp-stf-executor = { path = "../../../../core-primitives/stf-executor", features = ["mocks"] } +base58 = "0.2" +jsonrpc-core = { version = "18" } +lazy_static = { version = "1.1.0" } + [features] default = ["std"] sgx = [ From 57d5147d4fa46a1a43eec4625ec6c608c469405e Mon Sep 17 00:00:00 2001 From: felixfaisal Date: Tue, 10 Oct 2023 06:47:40 +0000 Subject: [PATCH 02/15] fix: add mock mod --- tee-worker/litentry/core/stf-task/receiver/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tee-worker/litentry/core/stf-task/receiver/src/lib.rs b/tee-worker/litentry/core/stf-task/receiver/src/lib.rs index e1b34e4736..f547a7a4df 100644 --- a/tee-worker/litentry/core/stf-task/receiver/src/lib.rs +++ b/tee-worker/litentry/core/stf-task/receiver/src/lib.rs @@ -58,6 +58,9 @@ use log::{debug, error, info}; use std::{boxed::Box, format, string::String, sync::Arc}; use threadpool::ThreadPool; +#[cfg(test)] +mod mock; + #[derive(Debug, thiserror::Error, Clone)] pub enum Error { #[error("Request error: {0}")] From 65dd1a4d43402eaf0b52985e5d8a780f046d13d1 Mon Sep 17 00:00:00 2001 From: felixfaisal Date: Tue, 10 Oct 2023 06:48:11 +0000 Subject: [PATCH 03/15] feat: mock.rs for test --- .../core/stf-task/receiver/src/mock.rs | 305 ++++++++++++++++++ 1 file changed, 305 insertions(+) create mode 100644 tee-worker/litentry/core/stf-task/receiver/src/mock.rs diff --git a/tee-worker/litentry/core/stf-task/receiver/src/mock.rs b/tee-worker/litentry/core/stf-task/receiver/src/mock.rs new file mode 100644 index 0000000000..2e62b76739 --- /dev/null +++ b/tee-worker/litentry/core/stf-task/receiver/src/mock.rs @@ -0,0 +1,305 @@ +use super::*; +use base58::FromBase58; +use codec::Decode; +use itp_sgx_crypto::ed25519_derivation::DeriveEd25519; +use itp_stf_executor::mocks::StfEnclaveSignerMock; +use itp_test::mock::{ + handle_state_mock::HandleStateMock, onchain_mock::OnchainMock, + shielding_crypto_mock::ShieldingCryptoMock, +}; +// use itp_top_pool_author::mocks::AuthorApiMock; +use ita_stf::{hash::TrustedOperationOrHash, Getter, TrustedCall, TrustedGetterSigned}; +use itp_top_pool::primitives::PoolFuture; +use itp_top_pool_author::{error::Result, traits::OnBlockImported}; +use itp_types::AccountId; +use jsonrpc_core::{futures::future::ready, Error as RpcError}; +use lazy_static::lazy_static; +use lc_stf_task_sender::{ + stf_task_sender::{SendStfRequest, StfRequestSender}, + AssertionBuildRequest, +}; +use litentry_primitives::Assertion; +use sgx_crypto_helper::{rsa3072::Rsa3072KeyPair, RsaKeyPair}; +use sp_core::{blake2_256, ed25519::Pair as Ed25519Pair, sr25519, Pair}; +use std::{ + collections::HashMap, + marker::PhantomData, + sync::{ + mpsc, + mpsc::{Receiver, Sender}, + Mutex, RwLock, + }, + thread, + time::Duration, + vec::Vec, +}; + +lazy_static! { + static ref GLOBAL_MOCK_AUTHOR_API: Arc>>>> = + Arc::new(Mutex::new(None)); +} + +pub const COMMON_SEED: &[u8] = + b"crouch whisper apple ladder skull blouse ridge oven despair cloth pony"; + +pub fn init_global_mock_author_api() -> Result>> { + let (sender, receiver) = std::sync::mpsc::channel(); + let mut stf_task_storage = GLOBAL_MOCK_AUTHOR_API.lock().unwrap(); + *stf_task_storage = Some(sender); + Ok(receiver) +} + +#[test] +fn test_mock_context() { + let shielding_key = ShieldingCryptoMock::default(); + let author_mock: AuthorApiMock = AuthorApiMock::default(); + let stf_enclave_signer_mock = StfEnclaveSignerMock::default(); + let handle_state_mock = HandleStateMock::default(); + let onchain_mock = OnchainMock::default(); + let context = StfTaskContext::new( + shielding_key.clone(), + author_mock.into(), + stf_enclave_signer_mock.into(), + handle_state_mock.into(), + onchain_mock.into(), + ); + let handle = thread::spawn(move || { + run_stf_task_receiver(Arc::new(context)).unwrap(); + }); + + let sender = StfRequestSender::default(); + + let s: String = String::from("751h9re4VmXYTEyFtsVPDm7H8PHgbz9D3guUSd1vKyUf"); + let s = s.from_base58().unwrap(); + let mrenclave: [u8; 32] = s.clone().try_into().unwrap(); + let shard: ShardIdentifier = ShardIdentifier::decode(&mut &s[..]).unwrap(); + + let seed = blake2_256(COMMON_SEED).to_vec(); + let pair = sr25519::Pair::from_seed_slice(&seed) + .expect("Failed to create a key pair from the provided seed"); + let public_id = pair.public(); + + let request: RequestType = AssertionBuildRequest { + shard, + signer: public_id.into(), + enclave_account: public_id.into(), + who: public_id.into(), + assertion: Assertion::A1, + identities: vec![], + top_hash: H256::zero(), + req_ext_hash: H256::zero(), + } + .into(); + + sender.send_stf_request(request).unwrap(); + + let request: RequestType = AssertionBuildRequest { + shard, + signer: public_id.into(), + enclave_account: public_id.into(), + who: public_id.into(), + assertion: Assertion::A6, + identities: vec![], + top_hash: H256::zero(), + req_ext_hash: H256::zero(), + } + .into(); + + sender.send_stf_request(request).unwrap(); + + let mut expected_output: Vec = vec![Assertion::A1, Assertion::A6]; + + let receiver = init_global_mock_author_api().unwrap(); + while let Ok(ext) = receiver.recv() { + let decrypted = shielding_key.decrypt(&ext).unwrap(); + let decoded: TrustedOperation = Decode::decode(&mut decrypted.as_ref()).unwrap(); + match decoded { + TrustedOperation::direct_call(trusted_call_signed) => + if let TrustedCall::request_vc_callback(_, _, assertion, ..) = + trusted_call_signed.call + { + println!("Received Request VC Callback for: {:?}", assertion); + assert_eq!(expected_output.remove(0), assertion); + }, + _ => { + // Do nothing + }, + } + if expected_output.len() == 0 { + break + } + // println!("Trusted Operation: {:?}", decoded) + } + + // handle.join().unwrap(); +} + +#[test] +fn test_run_stf_task_receiver() {} + +// We cannot use the AuthorApiMock as it is because it doesn't implement watch_top, +// So we have to create our own AuthorApiMock +#[derive(Default)] +pub struct AuthorApiMock { + tops: RwLock>>>, + _phantom: PhantomData<(Hash, BlockHash)>, + pub remove_attempts: RwLock, +} + +impl AuthorApiMock { + fn decode_trusted_operation(mut encoded_operation: &[u8]) -> Option { + TrustedOperation::decode(&mut encoded_operation).ok() + } + + fn decode_trusted_getter_signed(mut encoded_operation: &[u8]) -> Option { + TrustedGetterSigned::decode(&mut encoded_operation).ok() + } + + fn remove_top( + &self, + bytes_or_hash: Vec>, + shard: ShardIdentifier, + _inblock: bool, + ) -> Result> { + let hashes = bytes_or_hash + .into_iter() + .map(|x| match x { + TrustedOperationOrHash::Hash(h) => h, + TrustedOperationOrHash::OperationEncoded(bytes) => { + let top: TrustedOperation = + TrustedOperation::decode(&mut bytes.as_slice()).unwrap(); + top.hash() + }, + TrustedOperationOrHash::Operation(op) => op.hash(), + }) + .collect::>(); + + let mut tops_lock = self.tops.write().unwrap(); + + // Note: Not important for the test + // match tops_lock.get_mut(&shard) { + // Some(tops_encoded) => { + // let removed_tops = tops_encoded + // .drain_filter(|t| hashes.contains(&blake2_256(t).into())) + // .map(|t| blake2_256(&t).into()) + // .collect::>(); + // Ok(removed_tops) + // }, + // None => Ok(Vec::new()), + // } + Ok(Vec::new()) + } +} + +impl AuthorApi for AuthorApiMock { + fn submit_top(&self, extrinsic: Vec, shard: ShardIdentifier) -> PoolFuture { + let mut write_lock = self.tops.write().unwrap(); + let extrinsics = write_lock.entry(shard).or_default(); + extrinsics.push(extrinsic); + Box::pin(ready(Ok(H256::default()))) + } + + fn hash_of(&self, xt: &TrustedOperation) -> H256 { + xt.hash() + } + + fn pending_tops(&self, shard: ShardIdentifier) -> Result>> { + let extrinsics = self.tops.read().unwrap().get(&shard).cloned(); + Ok(extrinsics.unwrap_or_default()) + } + + fn get_pending_trusted_getters(&self, shard: ShardIdentifier) -> Vec { + self.tops + .read() + .unwrap() + .get(&shard) + .map(|encoded_operations| { + let mut trusted_getters: Vec = Vec::new(); + for encoded_operation in encoded_operations { + if let Some(g) = Self::decode_trusted_getter_signed(encoded_operation) { + trusted_getters.push(TrustedOperation::get(Getter::trusted(g))); + } + } + trusted_getters + }) + .unwrap_or_default() + } + + fn get_pending_trusted_calls(&self, shard: ShardIdentifier) -> Vec { + self.tops + .read() + .unwrap() + .get(&shard) + .map(|encoded_operations| { + let mut trusted_operations: Vec = Vec::new(); + for encoded_operation in encoded_operations { + if let Some(o) = Self::decode_trusted_operation(encoded_operation) { + trusted_operations.push(o); + } + } + trusted_operations + }) + .unwrap_or_default() + } + + fn get_pending_trusted_calls_for( + &self, + shard: ShardIdentifier, + account: &AccountId, + ) -> Vec { + self.tops + .read() + .unwrap() + .get(&shard) + .map(|encoded_operations| { + let mut trusted_operations: Vec = Vec::new(); + for encoded_operation in encoded_operations { + if let Some(o) = Self::decode_trusted_operation(encoded_operation) { + if o.signed_caller_account().as_ref() == Some(account) { + trusted_operations.push(o); + } + } + } + trusted_operations + }) + .unwrap_or_default() + } + + fn get_shards(&self) -> Vec { + self.tops.read().unwrap().keys().cloned().collect() + } + + fn remove_calls_from_pool( + &self, + shard: ShardIdentifier, + executed_calls: Vec<(TrustedOperationOrHash, bool)>, + ) -> Vec> { + let mut remove_attempts_lock = self.remove_attempts.write().unwrap(); + *remove_attempts_lock += 1; + + let mut failed_to_remove = Vec::new(); + for (executed_call, inblock) in executed_calls { + if self.remove_top(vec![executed_call.clone()], shard, inblock).is_err() { + failed_to_remove.push(executed_call); + } + } + failed_to_remove + } + + fn watch_top(&self, ext: Vec, _shard: ShardIdentifier) -> PoolFuture { + let sender_guard = GLOBAL_MOCK_AUTHOR_API.lock().unwrap(); + let sender = &*sender_guard; + sender.as_ref().expect("Not yet initialized").send(ext).unwrap(); + Box::pin(ready(Ok([0u8; 32].into()))) + } + + fn update_connection_state(&self, _updates: Vec<(H256, (Vec, bool))>) {} + + fn swap_rpc_connection_hash(&self, _old_hash: H256, _new_hash: H256) {} +} + +impl OnBlockImported for AuthorApiMock { + type Hash = H256; + + fn on_block_imported(&self, _hashes: &[Self::Hash], _block_hash: H256) {} +} From a1b649e3da48e46517c073c1d38d32d544556cf2 Mon Sep 17 00:00:00 2001 From: felixfaisal Date: Tue, 10 Oct 2023 06:59:25 +0000 Subject: [PATCH 04/15] fix: add artificial lag for test feature --- .../core/stf-task/receiver/src/handler/assertion.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tee-worker/litentry/core/stf-task/receiver/src/handler/assertion.rs b/tee-worker/litentry/core/stf-task/receiver/src/handler/assertion.rs index d9c885e92b..085e5ebacb 100644 --- a/tee-worker/litentry/core/stf-task/receiver/src/handler/assertion.rs +++ b/tee-worker/litentry/core/stf-task/receiver/src/handler/assertion.rs @@ -57,8 +57,13 @@ where // create the initial credential // TODO: maybe we can further simplify this let mut credential = match self.req.assertion.clone() { - Assertion::A1 => lc_assertion_build::a1::build(&self.req), - + Assertion::A1 => { + #[cfg(test)] + { + std::thread::sleep(core::time::Duration::from_secs(2)); + } + lc_assertion_build::a1::build(&self.req) + }, Assertion::A2(guild_id) => lc_assertion_build::a2::build(&self.req, guild_id), Assertion::A3(guild_id, channel_id, role_id) => From 7b2d689be972d7af84bd9791c0e527ea2d9810e7 Mon Sep 17 00:00:00 2001 From: felixfaisal Date: Tue, 10 Oct 2023 07:20:21 +0000 Subject: [PATCH 05/15] fix: cleanup code --- .../core/stf-task/receiver/src/lib.rs | 3 + .../core/stf-task/receiver/src/mock.rs | 96 ++----------------- .../core/stf-task/receiver/src/test.rs | 60 ++++++++++++ 3 files changed, 72 insertions(+), 87 deletions(-) create mode 100644 tee-worker/litentry/core/stf-task/receiver/src/test.rs diff --git a/tee-worker/litentry/core/stf-task/receiver/src/lib.rs b/tee-worker/litentry/core/stf-task/receiver/src/lib.rs index f547a7a4df..8bd1543beb 100644 --- a/tee-worker/litentry/core/stf-task/receiver/src/lib.rs +++ b/tee-worker/litentry/core/stf-task/receiver/src/lib.rs @@ -61,6 +61,9 @@ use threadpool::ThreadPool; #[cfg(test)] mod mock; +#[cfg(test)] +mod test; + #[derive(Debug, thiserror::Error, Clone)] pub enum Error { #[error("Request error: {0}")] diff --git a/tee-worker/litentry/core/stf-task/receiver/src/mock.rs b/tee-worker/litentry/core/stf-task/receiver/src/mock.rs index 2e62b76739..cc6ab58631 100644 --- a/tee-worker/litentry/core/stf-task/receiver/src/mock.rs +++ b/tee-worker/litentry/core/stf-task/receiver/src/mock.rs @@ -1,36 +1,22 @@ use super::*; use base58::FromBase58; use codec::Decode; -use itp_sgx_crypto::ed25519_derivation::DeriveEd25519; -use itp_stf_executor::mocks::StfEnclaveSignerMock; -use itp_test::mock::{ - handle_state_mock::HandleStateMock, onchain_mock::OnchainMock, - shielding_crypto_mock::ShieldingCryptoMock, -}; -// use itp_top_pool_author::mocks::AuthorApiMock; -use ita_stf::{hash::TrustedOperationOrHash, Getter, TrustedCall, TrustedGetterSigned}; +use ita_stf::{hash::TrustedOperationOrHash, Getter, TrustedGetterSigned}; use itp_top_pool::primitives::PoolFuture; use itp_top_pool_author::{error::Result, traits::OnBlockImported}; use itp_types::AccountId; use jsonrpc_core::{futures::future::ready, Error as RpcError}; use lazy_static::lazy_static; -use lc_stf_task_sender::{ - stf_task_sender::{SendStfRequest, StfRequestSender}, - AssertionBuildRequest, -}; +use lc_stf_task_sender::AssertionBuildRequest; use litentry_primitives::Assertion; -use sgx_crypto_helper::{rsa3072::Rsa3072KeyPair, RsaKeyPair}; -use sp_core::{blake2_256, ed25519::Pair as Ed25519Pair, sr25519, Pair}; +use sp_core::{blake2_256, sr25519, Pair}; use std::{ collections::HashMap, marker::PhantomData, sync::{ - mpsc, mpsc::{Receiver, Sender}, Mutex, RwLock, }, - thread, - time::Duration, vec::Vec, }; @@ -49,29 +35,9 @@ pub fn init_global_mock_author_api() -> Result>> { Ok(receiver) } -#[test] -fn test_mock_context() { - let shielding_key = ShieldingCryptoMock::default(); - let author_mock: AuthorApiMock = AuthorApiMock::default(); - let stf_enclave_signer_mock = StfEnclaveSignerMock::default(); - let handle_state_mock = HandleStateMock::default(); - let onchain_mock = OnchainMock::default(); - let context = StfTaskContext::new( - shielding_key.clone(), - author_mock.into(), - stf_enclave_signer_mock.into(), - handle_state_mock.into(), - onchain_mock.into(), - ); - let handle = thread::spawn(move || { - run_stf_task_receiver(Arc::new(context)).unwrap(); - }); - - let sender = StfRequestSender::default(); - +pub fn construct_assertion_request(assertion: Assertion) -> RequestType { let s: String = String::from("751h9re4VmXYTEyFtsVPDm7H8PHgbz9D3guUSd1vKyUf"); let s = s.from_base58().unwrap(); - let mrenclave: [u8; 32] = s.clone().try_into().unwrap(); let shard: ShardIdentifier = ShardIdentifier::decode(&mut &s[..]).unwrap(); let seed = blake2_256(COMMON_SEED).to_vec(); @@ -84,59 +50,15 @@ fn test_mock_context() { signer: public_id.into(), enclave_account: public_id.into(), who: public_id.into(), - assertion: Assertion::A1, - identities: vec![], - top_hash: H256::zero(), - req_ext_hash: H256::zero(), - } - .into(); - - sender.send_stf_request(request).unwrap(); - - let request: RequestType = AssertionBuildRequest { - shard, - signer: public_id.into(), - enclave_account: public_id.into(), - who: public_id.into(), - assertion: Assertion::A6, + assertion, identities: vec![], top_hash: H256::zero(), req_ext_hash: H256::zero(), } .into(); - - sender.send_stf_request(request).unwrap(); - - let mut expected_output: Vec = vec![Assertion::A1, Assertion::A6]; - - let receiver = init_global_mock_author_api().unwrap(); - while let Ok(ext) = receiver.recv() { - let decrypted = shielding_key.decrypt(&ext).unwrap(); - let decoded: TrustedOperation = Decode::decode(&mut decrypted.as_ref()).unwrap(); - match decoded { - TrustedOperation::direct_call(trusted_call_signed) => - if let TrustedCall::request_vc_callback(_, _, assertion, ..) = - trusted_call_signed.call - { - println!("Received Request VC Callback for: {:?}", assertion); - assert_eq!(expected_output.remove(0), assertion); - }, - _ => { - // Do nothing - }, - } - if expected_output.len() == 0 { - break - } - // println!("Trusted Operation: {:?}", decoded) - } - - // handle.join().unwrap(); + request } -#[test] -fn test_run_stf_task_receiver() {} - // We cannot use the AuthorApiMock as it is because it doesn't implement watch_top, // So we have to create our own AuthorApiMock #[derive(Default)] @@ -158,10 +80,10 @@ impl AuthorApiMock { fn remove_top( &self, bytes_or_hash: Vec>, - shard: ShardIdentifier, + _shard: ShardIdentifier, _inblock: bool, ) -> Result> { - let hashes = bytes_or_hash + let _hashes = bytes_or_hash .into_iter() .map(|x| match x { TrustedOperationOrHash::Hash(h) => h, @@ -174,7 +96,7 @@ impl AuthorApiMock { }) .collect::>(); - let mut tops_lock = self.tops.write().unwrap(); + // let mut tops_lock = self.tops.write().unwrap(); // Note: Not important for the test // match tops_lock.get_mut(&shard) { diff --git a/tee-worker/litentry/core/stf-task/receiver/src/test.rs b/tee-worker/litentry/core/stf-task/receiver/src/test.rs new file mode 100644 index 0000000000..9a5cfb8290 --- /dev/null +++ b/tee-worker/litentry/core/stf-task/receiver/src/test.rs @@ -0,0 +1,60 @@ +use super::*; +use mock::*; + +use codec::Decode; +use ita_stf::TrustedCall; +use itp_stf_executor::mocks::StfEnclaveSignerMock; +use itp_test::mock::{ + handle_state_mock::HandleStateMock, onchain_mock::OnchainMock, + shielding_crypto_mock::ShieldingCryptoMock, +}; +use lc_stf_task_sender::stf_task_sender::{SendStfRequest, StfRequestSender}; +use litentry_primitives::Assertion; + +#[test] +fn test_threadpool_behaviour() { + let shielding_key = ShieldingCryptoMock::default(); + let author_mock: AuthorApiMock = AuthorApiMock::default(); + let stf_enclave_signer_mock = StfEnclaveSignerMock::default(); + let handle_state_mock = HandleStateMock::default(); + let onchain_mock = OnchainMock::default(); + let context = StfTaskContext::new( + shielding_key.clone(), + author_mock.into(), + stf_enclave_signer_mock.into(), + handle_state_mock.into(), + onchain_mock.into(), + ); + let _handle = std::thread::spawn(move || { + run_stf_task_receiver(Arc::new(context)).unwrap(); + }); + + let sender = StfRequestSender::default(); + let receiver = init_global_mock_author_api().unwrap(); + + sender.send_stf_request(construct_assertion_request(Assertion::A1)).unwrap(); + sender.send_stf_request(construct_assertion_request(Assertion::A6)).unwrap(); + + // As you see in the expected output, We receive A6 first even though A1 is requested first and is put to sleep + let mut expected_output: Vec = vec![Assertion::A6, Assertion::A1]; + + while let Ok(ext) = receiver.recv() { + let decrypted = shielding_key.decrypt(&ext).unwrap(); + let decoded: TrustedOperation = Decode::decode(&mut decrypted.as_ref()).unwrap(); + match decoded { + TrustedOperation::direct_call(trusted_call_signed) => + if let TrustedCall::request_vc_callback(_, _, assertion, ..) = + trusted_call_signed.call + { + println!("Received Request VC Callback for: {:?}", assertion); + assert_eq!(expected_output.remove(0), assertion); + }, + _ => { + // Do nothing + }, + } + if expected_output.len() == 0 { + break + } + } +} From 506766f4469148698961cc47df57dab1de046a98 Mon Sep 17 00:00:00 2001 From: felixfaisal Date: Tue, 10 Oct 2023 10:35:11 +0000 Subject: [PATCH 06/15] fix: failing CI Test --- tee-worker/litentry/core/stf-task/receiver/src/test.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tee-worker/litentry/core/stf-task/receiver/src/test.rs b/tee-worker/litentry/core/stf-task/receiver/src/test.rs index 9a5cfb8290..2e7fcdfda4 100644 --- a/tee-worker/litentry/core/stf-task/receiver/src/test.rs +++ b/tee-worker/litentry/core/stf-task/receiver/src/test.rs @@ -30,11 +30,14 @@ fn test_threadpool_behaviour() { }); let sender = StfRequestSender::default(); - let receiver = init_global_mock_author_api().unwrap(); + + // Sleep in order to initialize the components + std::thread::sleep(core::time::Duration::from_secs(2)); sender.send_stf_request(construct_assertion_request(Assertion::A1)).unwrap(); sender.send_stf_request(construct_assertion_request(Assertion::A6)).unwrap(); + let receiver = init_global_mock_author_api().unwrap(); // As you see in the expected output, We receive A6 first even though A1 is requested first and is put to sleep let mut expected_output: Vec = vec![Assertion::A6, Assertion::A1]; @@ -46,7 +49,6 @@ fn test_threadpool_behaviour() { if let TrustedCall::request_vc_callback(_, _, assertion, ..) = trusted_call_signed.call { - println!("Received Request VC Callback for: {:?}", assertion); assert_eq!(expected_output.remove(0), assertion); }, _ => { From 5e8ffa6798b610a64b5f39c405b7a7b01d70e06c Mon Sep 17 00:00:00 2001 From: felixfaisal Date: Wed, 11 Oct 2023 12:15:17 +0000 Subject: [PATCH 07/15] fix: add timeout into the test --- tee-worker/litentry/core/stf-task/receiver/src/test.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tee-worker/litentry/core/stf-task/receiver/src/test.rs b/tee-worker/litentry/core/stf-task/receiver/src/test.rs index 2e7fcdfda4..290bdd59b7 100644 --- a/tee-worker/litentry/core/stf-task/receiver/src/test.rs +++ b/tee-worker/litentry/core/stf-task/receiver/src/test.rs @@ -41,6 +41,9 @@ fn test_threadpool_behaviour() { // As you see in the expected output, We receive A6 first even though A1 is requested first and is put to sleep let mut expected_output: Vec = vec![Assertion::A6, Assertion::A1]; + let timeout_duration = core::time::Duration::from_secs(30); + let start_time = std::time::Instant::now(); + while let Ok(ext) = receiver.recv() { let decrypted = shielding_key.decrypt(&ext).unwrap(); let decoded: TrustedOperation = Decode::decode(&mut decrypted.as_ref()).unwrap(); @@ -58,5 +61,10 @@ fn test_threadpool_behaviour() { if expected_output.len() == 0 { break } + + // Timeout condition + if start_time.elapsed() > timeout_duration { + assert!(false, "Test exceeded the 60-second timeout"); + } } } From 20f10ff3df696f4e37f4243145902602fee3f0d7 Mon Sep 17 00:00:00 2001 From: felixfaisal Date: Wed, 11 Oct 2023 12:39:31 +0000 Subject: [PATCH 08/15] refactor: match condition --- .../core/stf-task/receiver/src/test.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tee-worker/litentry/core/stf-task/receiver/src/test.rs b/tee-worker/litentry/core/stf-task/receiver/src/test.rs index 290bdd59b7..baad2c9984 100644 --- a/tee-worker/litentry/core/stf-task/receiver/src/test.rs +++ b/tee-worker/litentry/core/stf-task/receiver/src/test.rs @@ -2,7 +2,7 @@ use super::*; use mock::*; use codec::Decode; -use ita_stf::TrustedCall; +use ita_stf::{TrustedCall, TrustedCallSigned}; use itp_stf_executor::mocks::StfEnclaveSignerMock; use itp_test::mock::{ handle_state_mock::HandleStateMock, onchain_mock::OnchainMock, @@ -47,16 +47,12 @@ fn test_threadpool_behaviour() { while let Ok(ext) = receiver.recv() { let decrypted = shielding_key.decrypt(&ext).unwrap(); let decoded: TrustedOperation = Decode::decode(&mut decrypted.as_ref()).unwrap(); - match decoded { - TrustedOperation::direct_call(trusted_call_signed) => - if let TrustedCall::request_vc_callback(_, _, assertion, ..) = - trusted_call_signed.call - { - assert_eq!(expected_output.remove(0), assertion); - }, - _ => { - // Do nothing - }, + if let TrustedOperation::direct_call(TrustedCallSigned { + call: TrustedCall::request_vc_callback(_, _, assertion, ..), + .. + }) = decoded + { + assert_eq!(expected_output.remove(0), assertion); } if expected_output.len() == 0 { break From 2c693b5ee2da9e2fd994b5d8f9ffe28255e71552 Mon Sep 17 00:00:00 2001 From: felixfaisal Date: Mon, 16 Oct 2023 12:50:08 +0000 Subject: [PATCH 09/15] fix: test for exhausting workers --- .../core/stf-task/receiver/src/test.rs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tee-worker/litentry/core/stf-task/receiver/src/test.rs b/tee-worker/litentry/core/stf-task/receiver/src/test.rs index baad2c9984..c1cf4b5a73 100644 --- a/tee-worker/litentry/core/stf-task/receiver/src/test.rs +++ b/tee-worker/litentry/core/stf-task/receiver/src/test.rs @@ -63,4 +63,35 @@ fn test_threadpool_behaviour() { assert!(false, "Test exceeded the 60-second timeout"); } } + + // Exhaust all workers with A1 + sender.send_stf_request(construct_assertion_request(Assertion::A1)).unwrap(); + sender.send_stf_request(construct_assertion_request(Assertion::A1)).unwrap(); + sender.send_stf_request(construct_assertion_request(Assertion::A1)).unwrap(); + sender.send_stf_request(construct_assertion_request(Assertion::A1)).unwrap(); + // Submit A6, it will wait until the threads are free + sender.send_stf_request(construct_assertion_request(Assertion::A6)).unwrap(); + + let mut expected_output: Vec = + vec![Assertion::A1, Assertion::A1, Assertion::A1, Assertion::A1, Assertion::A6]; + + while let Ok(ext) = receiver.recv() { + let decrypted = shielding_key.decrypt(&ext).unwrap(); + let decoded: TrustedOperation = Decode::decode(&mut decrypted.as_ref()).unwrap(); + if let TrustedOperation::direct_call(TrustedCallSigned { + call: TrustedCall::request_vc_callback(_, _, assertion, ..), + .. + }) = decoded + { + assert_eq!(expected_output.remove(0), assertion); + } + if expected_output.len() == 0 { + break + } + + // Timeout condition + if start_time.elapsed() > timeout_duration { + assert!(false, "Test exceeded the 60-second timeout"); + } + } } From 9323137b0b23ad9d4843c2e3d57874d36b2f056f Mon Sep 17 00:00:00 2001 From: felixfaisal Date: Mon, 16 Oct 2023 15:52:08 +0000 Subject: [PATCH 10/15] refactor: using existing AuthorApiMock --- .../top-pool-author/Cargo.toml | 3 +- .../top-pool-author/src/mocks.rs | 22 +- .../core/stf-task/receiver/src/mock.rs | 189 +----------------- .../core/stf-task/receiver/src/test.rs | 3 + 4 files changed, 26 insertions(+), 191 deletions(-) diff --git a/tee-worker/core-primitives/top-pool-author/Cargo.toml b/tee-worker/core-primitives/top-pool-author/Cargo.toml index 5c0f9377f0..ff047eabfb 100644 --- a/tee-worker/core-primitives/top-pool-author/Cargo.toml +++ b/tee-worker/core-primitives/top-pool-author/Cargo.toml @@ -33,6 +33,7 @@ log = { version = "0.4", default-features = false } sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } +lazy_static = { version = "1.1.0", optional = true } [dev-dependencies] futures = { version = "0.3" } @@ -73,7 +74,7 @@ sgx = [ "litentry-primitives/sgx", ] test = ["itp-test/sgx", "itp-top-pool/mocks"] -mocks = [] +mocks = ["lazy_static"] sidechain = [] offchain-worker = [] teeracle = [] diff --git a/tee-worker/core-primitives/top-pool-author/src/mocks.rs b/tee-worker/core-primitives/top-pool-author/src/mocks.rs index 11d3b385c9..018a5c249f 100644 --- a/tee-worker/core-primitives/top-pool-author/src/mocks.rs +++ b/tee-worker/core-primitives/top-pool-author/src/mocks.rs @@ -37,8 +37,21 @@ use itp_stf_primitives::types::AccountId; use itp_top_pool::primitives::PoolFuture; use itp_types::ShardIdentifier; use jsonrpc_core::{futures::future::ready, Error as RpcError}; +use lazy_static::lazy_static; use sp_core::{blake2_256, H256}; -use std::{boxed::Box, collections::HashMap, marker::PhantomData, vec, vec::Vec}; +use std::{ + boxed::Box, + collections::HashMap, + marker::PhantomData, + sync::{mpsc::Sender, Arc, Mutex}, + vec, + vec::Vec, +}; + +lazy_static! { + pub static ref GLOBAL_MOCK_AUTHOR_API: Arc>>>> = + Arc::new(Mutex::new(None)); +} #[derive(Default)] pub struct AuthorApiMock { @@ -185,8 +198,11 @@ impl AuthorApi for AuthorApiMock { failed_to_remove } - fn watch_top(&self, _ext: Vec, _shard: ShardIdentifier) -> PoolFuture { - todo!() + fn watch_top(&self, ext: Vec, _shard: ShardIdentifier) -> PoolFuture { + let sender_guard = GLOBAL_MOCK_AUTHOR_API.lock().unwrap(); + let sender = &*sender_guard; + sender.as_ref().expect("Not yet initialized").send(ext).unwrap(); + Box::pin(ready(Ok([0u8; 32].into()))) } fn update_connection_state(&self, _updates: Vec<(H256, (Vec, bool))>) {} diff --git a/tee-worker/litentry/core/stf-task/receiver/src/mock.rs b/tee-worker/litentry/core/stf-task/receiver/src/mock.rs index cc6ab58631..570f5fed26 100644 --- a/tee-worker/litentry/core/stf-task/receiver/src/mock.rs +++ b/tee-worker/litentry/core/stf-task/receiver/src/mock.rs @@ -1,29 +1,11 @@ use super::*; use base58::FromBase58; use codec::Decode; -use ita_stf::{hash::TrustedOperationOrHash, Getter, TrustedGetterSigned}; -use itp_top_pool::primitives::PoolFuture; -use itp_top_pool_author::{error::Result, traits::OnBlockImported}; -use itp_types::AccountId; -use jsonrpc_core::{futures::future::ready, Error as RpcError}; -use lazy_static::lazy_static; +use itp_top_pool_author::{error::Result, mocks::GLOBAL_MOCK_AUTHOR_API}; use lc_stf_task_sender::AssertionBuildRequest; use litentry_primitives::Assertion; use sp_core::{blake2_256, sr25519, Pair}; -use std::{ - collections::HashMap, - marker::PhantomData, - sync::{ - mpsc::{Receiver, Sender}, - Mutex, RwLock, - }, - vec::Vec, -}; - -lazy_static! { - static ref GLOBAL_MOCK_AUTHOR_API: Arc>>>> = - Arc::new(Mutex::new(None)); -} +use std::{sync::mpsc::Receiver, vec::Vec}; pub const COMMON_SEED: &[u8] = b"crouch whisper apple ladder skull blouse ridge oven despair cloth pony"; @@ -58,170 +40,3 @@ pub fn construct_assertion_request(assertion: Assertion) -> RequestType { .into(); request } - -// We cannot use the AuthorApiMock as it is because it doesn't implement watch_top, -// So we have to create our own AuthorApiMock -#[derive(Default)] -pub struct AuthorApiMock { - tops: RwLock>>>, - _phantom: PhantomData<(Hash, BlockHash)>, - pub remove_attempts: RwLock, -} - -impl AuthorApiMock { - fn decode_trusted_operation(mut encoded_operation: &[u8]) -> Option { - TrustedOperation::decode(&mut encoded_operation).ok() - } - - fn decode_trusted_getter_signed(mut encoded_operation: &[u8]) -> Option { - TrustedGetterSigned::decode(&mut encoded_operation).ok() - } - - fn remove_top( - &self, - bytes_or_hash: Vec>, - _shard: ShardIdentifier, - _inblock: bool, - ) -> Result> { - let _hashes = bytes_or_hash - .into_iter() - .map(|x| match x { - TrustedOperationOrHash::Hash(h) => h, - TrustedOperationOrHash::OperationEncoded(bytes) => { - let top: TrustedOperation = - TrustedOperation::decode(&mut bytes.as_slice()).unwrap(); - top.hash() - }, - TrustedOperationOrHash::Operation(op) => op.hash(), - }) - .collect::>(); - - // let mut tops_lock = self.tops.write().unwrap(); - - // Note: Not important for the test - // match tops_lock.get_mut(&shard) { - // Some(tops_encoded) => { - // let removed_tops = tops_encoded - // .drain_filter(|t| hashes.contains(&blake2_256(t).into())) - // .map(|t| blake2_256(&t).into()) - // .collect::>(); - // Ok(removed_tops) - // }, - // None => Ok(Vec::new()), - // } - Ok(Vec::new()) - } -} - -impl AuthorApi for AuthorApiMock { - fn submit_top(&self, extrinsic: Vec, shard: ShardIdentifier) -> PoolFuture { - let mut write_lock = self.tops.write().unwrap(); - let extrinsics = write_lock.entry(shard).or_default(); - extrinsics.push(extrinsic); - Box::pin(ready(Ok(H256::default()))) - } - - fn hash_of(&self, xt: &TrustedOperation) -> H256 { - xt.hash() - } - - fn pending_tops(&self, shard: ShardIdentifier) -> Result>> { - let extrinsics = self.tops.read().unwrap().get(&shard).cloned(); - Ok(extrinsics.unwrap_or_default()) - } - - fn get_pending_trusted_getters(&self, shard: ShardIdentifier) -> Vec { - self.tops - .read() - .unwrap() - .get(&shard) - .map(|encoded_operations| { - let mut trusted_getters: Vec = Vec::new(); - for encoded_operation in encoded_operations { - if let Some(g) = Self::decode_trusted_getter_signed(encoded_operation) { - trusted_getters.push(TrustedOperation::get(Getter::trusted(g))); - } - } - trusted_getters - }) - .unwrap_or_default() - } - - fn get_pending_trusted_calls(&self, shard: ShardIdentifier) -> Vec { - self.tops - .read() - .unwrap() - .get(&shard) - .map(|encoded_operations| { - let mut trusted_operations: Vec = Vec::new(); - for encoded_operation in encoded_operations { - if let Some(o) = Self::decode_trusted_operation(encoded_operation) { - trusted_operations.push(o); - } - } - trusted_operations - }) - .unwrap_or_default() - } - - fn get_pending_trusted_calls_for( - &self, - shard: ShardIdentifier, - account: &AccountId, - ) -> Vec { - self.tops - .read() - .unwrap() - .get(&shard) - .map(|encoded_operations| { - let mut trusted_operations: Vec = Vec::new(); - for encoded_operation in encoded_operations { - if let Some(o) = Self::decode_trusted_operation(encoded_operation) { - if o.signed_caller_account().as_ref() == Some(account) { - trusted_operations.push(o); - } - } - } - trusted_operations - }) - .unwrap_or_default() - } - - fn get_shards(&self) -> Vec { - self.tops.read().unwrap().keys().cloned().collect() - } - - fn remove_calls_from_pool( - &self, - shard: ShardIdentifier, - executed_calls: Vec<(TrustedOperationOrHash, bool)>, - ) -> Vec> { - let mut remove_attempts_lock = self.remove_attempts.write().unwrap(); - *remove_attempts_lock += 1; - - let mut failed_to_remove = Vec::new(); - for (executed_call, inblock) in executed_calls { - if self.remove_top(vec![executed_call.clone()], shard, inblock).is_err() { - failed_to_remove.push(executed_call); - } - } - failed_to_remove - } - - fn watch_top(&self, ext: Vec, _shard: ShardIdentifier) -> PoolFuture { - let sender_guard = GLOBAL_MOCK_AUTHOR_API.lock().unwrap(); - let sender = &*sender_guard; - sender.as_ref().expect("Not yet initialized").send(ext).unwrap(); - Box::pin(ready(Ok([0u8; 32].into()))) - } - - fn update_connection_state(&self, _updates: Vec<(H256, (Vec, bool))>) {} - - fn swap_rpc_connection_hash(&self, _old_hash: H256, _new_hash: H256) {} -} - -impl OnBlockImported for AuthorApiMock { - type Hash = H256; - - fn on_block_imported(&self, _hashes: &[Self::Hash], _block_hash: H256) {} -} diff --git a/tee-worker/litentry/core/stf-task/receiver/src/test.rs b/tee-worker/litentry/core/stf-task/receiver/src/test.rs index c1cf4b5a73..9339705ac5 100644 --- a/tee-worker/litentry/core/stf-task/receiver/src/test.rs +++ b/tee-worker/litentry/core/stf-task/receiver/src/test.rs @@ -8,6 +8,7 @@ use itp_test::mock::{ handle_state_mock::HandleStateMock, onchain_mock::OnchainMock, shielding_crypto_mock::ShieldingCryptoMock, }; +use itp_top_pool_author::mocks::AuthorApiMock; use lc_stf_task_sender::stf_task_sender::{SendStfRequest, StfRequestSender}; use litentry_primitives::Assertion; @@ -75,6 +76,8 @@ fn test_threadpool_behaviour() { let mut expected_output: Vec = vec![Assertion::A1, Assertion::A1, Assertion::A1, Assertion::A1, Assertion::A6]; + let start_time = std::time::Instant::now(); + while let Ok(ext) = receiver.recv() { let decrypted = shielding_key.decrypt(&ext).unwrap(); let decoded: TrustedOperation = Decode::decode(&mut decrypted.as_ref()).unwrap(); From d88126a1bd720253df99df8c91b47dd25b2187ca Mon Sep 17 00:00:00 2001 From: felixfaisal Date: Mon, 16 Oct 2023 16:37:49 +0000 Subject: [PATCH 11/15] refactor: add comment --- tee-worker/core-primitives/top-pool-author/src/mocks.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tee-worker/core-primitives/top-pool-author/src/mocks.rs b/tee-worker/core-primitives/top-pool-author/src/mocks.rs index 018a5c249f..4f34e546a6 100644 --- a/tee-worker/core-primitives/top-pool-author/src/mocks.rs +++ b/tee-worker/core-primitives/top-pool-author/src/mocks.rs @@ -199,6 +199,7 @@ impl AuthorApi for AuthorApiMock { } fn watch_top(&self, ext: Vec, _shard: ShardIdentifier) -> PoolFuture { + // Note: The below implementation is specific for litentry/core/stf-task/receiver/test.rs let sender_guard = GLOBAL_MOCK_AUTHOR_API.lock().unwrap(); let sender = &*sender_guard; sender.as_ref().expect("Not yet initialized").send(ext).unwrap(); From 0c3720bd6438dd0086c75ce9440631233bd7d90d Mon Sep 17 00:00:00 2001 From: felixfaisal Date: Wed, 18 Oct 2023 15:31:11 +0000 Subject: [PATCH 12/15] fix: update mutex --- .../core-primitives/top-pool-author/src/mocks.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tee-worker/core-primitives/top-pool-author/src/mocks.rs b/tee-worker/core-primitives/top-pool-author/src/mocks.rs index 4f34e546a6..bb5c3e5f16 100644 --- a/tee-worker/core-primitives/top-pool-author/src/mocks.rs +++ b/tee-worker/core-primitives/top-pool-author/src/mocks.rs @@ -39,15 +39,23 @@ use itp_types::ShardIdentifier; use jsonrpc_core::{futures::future::ready, Error as RpcError}; use lazy_static::lazy_static; use sp_core::{blake2_256, H256}; +#[cfg(not(feature = "std"))] +use std::sync::SgxMutex as Mutex; use std::{ boxed::Box, collections::HashMap, marker::PhantomData, - sync::{mpsc::Sender, Arc, Mutex}, + sync::{mpsc::Sender, Arc}, vec, vec::Vec, }; +#[cfg(all(feature = "std", feature = "sgx"))] +compile_error!("feature \"std\" and feature \"sgx\" cannot be enabled at the same time"); + +#[cfg(feature = "std")] +use std::sync::Mutex; + lazy_static! { pub static ref GLOBAL_MOCK_AUTHOR_API: Arc>>>> = Arc::new(Mutex::new(None)); From 429aee1e2945f972c13a7a28e6c434377096b1f8 Mon Sep 17 00:00:00 2001 From: felixfaisal Date: Tue, 24 Oct 2023 06:32:54 +0000 Subject: [PATCH 13/15] fix: update time and add lock file --- tee-worker/Cargo.lock | 7 +++++++ .../core/stf-task/receiver/src/handler/assertion.rs | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tee-worker/Cargo.lock b/tee-worker/Cargo.lock index 60f3d1b1fd..e0da6818c5 100644 --- a/tee-worker/Cargo.lock +++ b/tee-worker/Cargo.lock @@ -5313,6 +5313,7 @@ dependencies = [ "itp-types", "jsonrpc-core 18.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 18.0.0 (git+https://github.com/scs/jsonrpc?branch=no_std_v18)", + "lazy_static", "litentry-primitives", "log 0.4.19", "parity-scale-codec", @@ -6144,6 +6145,7 @@ dependencies = [ name = "lc-stf-task-receiver" version = "0.1.0" dependencies = [ + "base58", "frame-support", "futures 0.3.28", "futures 0.3.8", @@ -6156,8 +6158,12 @@ dependencies = [ "itp-sgx-externalities", "itp-stf-executor", "itp-stf-state-handler", + "itp-test", + "itp-top-pool", "itp-top-pool-author", "itp-types", + "jsonrpc-core 18.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static", "lc-assertion-build", "lc-credentials", "lc-data-providers", @@ -6166,6 +6172,7 @@ dependencies = [ "litentry-primitives", "log 0.4.19", "parity-scale-codec", + "sgx_crypto_helper", "sgx_tstd", "sp-core", "thiserror 1.0.44", diff --git a/tee-worker/litentry/core/stf-task/receiver/src/handler/assertion.rs b/tee-worker/litentry/core/stf-task/receiver/src/handler/assertion.rs index 085e5ebacb..21e15684dc 100644 --- a/tee-worker/litentry/core/stf-task/receiver/src/handler/assertion.rs +++ b/tee-worker/litentry/core/stf-task/receiver/src/handler/assertion.rs @@ -60,7 +60,7 @@ where Assertion::A1 => { #[cfg(test)] { - std::thread::sleep(core::time::Duration::from_secs(2)); + std::thread::sleep(core::time::Duration::from_secs(5)); } lc_assertion_build::a1::build(&self.req) }, From 0d52802397506cf12763b1fc3a401b014c158d98 Mon Sep 17 00:00:00 2001 From: felixfaisal Date: Wed, 25 Oct 2023 06:18:23 +0000 Subject: [PATCH 14/15] fix: trying something for CI --- .../core/stf-task/receiver/src/test.rs | 33 ------------------- 1 file changed, 33 deletions(-) diff --git a/tee-worker/litentry/core/stf-task/receiver/src/test.rs b/tee-worker/litentry/core/stf-task/receiver/src/test.rs index 9339705ac5..cb83600c61 100644 --- a/tee-worker/litentry/core/stf-task/receiver/src/test.rs +++ b/tee-worker/litentry/core/stf-task/receiver/src/test.rs @@ -64,37 +64,4 @@ fn test_threadpool_behaviour() { assert!(false, "Test exceeded the 60-second timeout"); } } - - // Exhaust all workers with A1 - sender.send_stf_request(construct_assertion_request(Assertion::A1)).unwrap(); - sender.send_stf_request(construct_assertion_request(Assertion::A1)).unwrap(); - sender.send_stf_request(construct_assertion_request(Assertion::A1)).unwrap(); - sender.send_stf_request(construct_assertion_request(Assertion::A1)).unwrap(); - // Submit A6, it will wait until the threads are free - sender.send_stf_request(construct_assertion_request(Assertion::A6)).unwrap(); - - let mut expected_output: Vec = - vec![Assertion::A1, Assertion::A1, Assertion::A1, Assertion::A1, Assertion::A6]; - - let start_time = std::time::Instant::now(); - - while let Ok(ext) = receiver.recv() { - let decrypted = shielding_key.decrypt(&ext).unwrap(); - let decoded: TrustedOperation = Decode::decode(&mut decrypted.as_ref()).unwrap(); - if let TrustedOperation::direct_call(TrustedCallSigned { - call: TrustedCall::request_vc_callback(_, _, assertion, ..), - .. - }) = decoded - { - assert_eq!(expected_output.remove(0), assertion); - } - if expected_output.len() == 0 { - break - } - - // Timeout condition - if start_time.elapsed() > timeout_duration { - assert!(false, "Test exceeded the 60-second timeout"); - } - } } From 789ccb165e7b72ce054f676665709dccfc580f82 Mon Sep 17 00:00:00 2001 From: felixfaisal Date: Mon, 20 Nov 2023 04:44:49 +0000 Subject: [PATCH 15/15] fix: update deps import --- tee-worker/core-primitives/top-pool-author/src/mocks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tee-worker/core-primitives/top-pool-author/src/mocks.rs b/tee-worker/core-primitives/top-pool-author/src/mocks.rs index e88f831e4a..5c4b8bb3c0 100644 --- a/tee-worker/core-primitives/top-pool-author/src/mocks.rs +++ b/tee-worker/core-primitives/top-pool-author/src/mocks.rs @@ -39,7 +39,7 @@ use itp_types::{DecryptableRequest, ShardIdentifier}; use jsonrpc_core::{futures::future::ready, Error as RpcError}; use lazy_static::lazy_static; use sp_core::{blake2_256, H256}; -#[cfg(not(feature = "std"))] +#[cfg(feature = "sgx")] use std::sync::SgxMutex as Mutex; use std::{ boxed::Box,