-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support different Parentchain configs for Integritee, TargetA, TargetB and default to AssetTip for TargetB (aka support Asset Hub) #1652
base: master
Are you sure you want to change the base?
Conversation
let account_data = if let Some(data) = api.get_account_data(&accountid).unwrap() { | ||
data | ||
} else { | ||
AccountData::default() | ||
}; | ||
let account_data = api.get_account_data(&accountid).unwrap().unwrap_or_default(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have changed the implementation. It returns now, our AccountData
instead of the one from the api-client. This simplifies some things.
pub struct ExtrinsicsFactoryMock<C> { | ||
_phantom: PhantomData<C>, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't derive default if the concrete type doesn't implement default. This is a well-known rust bug, and we have to implement default manually.
service/src/account_funding.rs
Outdated
// // Check if this is an integritee chain and Compose a register_sgx_enclave extrinsic | ||
// if let Ok(ra_renewal) = api.get_constant::<Moment>("Teerex", "MaxAttestationRenewalPeriod") { | ||
// info!("[{:?}] this chain has the teerex pallet. estimating RA fees", parentchain_id); | ||
// let nonce = api.get_nonce_of(accountid)?; | ||
// | ||
// let encoded_xt: Bytes = compose_extrinsic_with_nonce!( | ||
// api, | ||
// nonce, | ||
// TEEREX, | ||
// "register_sgx_enclave", | ||
// vec![0u8; SGX_RA_PROOF_MAX_LEN], | ||
// Some(vec![0u8; MAX_URL_LEN]), | ||
// SgxAttestationMethod::Dcap { proxied: false } | ||
// ) | ||
// .encode() | ||
// .into(); | ||
// let tx_fee = | ||
// api.get_fee_details(&encoded_xt, None).unwrap().unwrap().inclusion_fee.unwrap(); | ||
// let ra_fee = tx_fee.base_fee + tx_fee.len_fee + tx_fee.adjusted_weight_fee; | ||
// info!( | ||
// "[{:?}] one enclave registration costs {:?} and needs to be renewed every {:?}h", | ||
// parentchain_id, | ||
// ra_fee, | ||
// ra_renewal / 1_000 / 3_600 | ||
// ); | ||
// min_required_funds += 5 * ra_fee; | ||
// } else { | ||
// info!("[{:?}] this chain has no teerex pallet, no need to add RA fees", parentchain_id); | ||
// } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was from you, what was the plan?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reactivated it, as I saw no reason to change the behaviour.
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
use super::*; | ||
use itp_node_api::{ | ||
api_client::ParentchainApi, | ||
node_api_factory::{CreateNodeApi, Result as NodeApiResult}, | ||
}; | ||
use itp_sgx_temp_dir::TempDir; | ||
use mockall::mock; | ||
|
||
#[test] | ||
fn given_empty_worker_request_when_submitting_then_return_empty_response() { | ||
mock! { | ||
NodeApiFactory {} | ||
impl CreateNodeApi for NodeApiFactory { | ||
fn create_api(&self) -> NodeApiResult<ParentchainApi>; | ||
} | ||
} | ||
|
||
let mock_node_api_factory = Arc::new(MockNodeApiFactory::new()); | ||
let temp_dir = TempDir::new().unwrap(); | ||
let on_chain_ocall = | ||
WorkerOnChainOCall::new(mock_node_api_factory, None, None, temp_dir.path().into()); | ||
|
||
let response = on_chain_ocall | ||
.worker_request(Vec::<u8>::new().encode(), ParentchainId::Integritee.encode()) | ||
.unwrap(); | ||
|
||
assert!(!response.is_empty()); // the encoded empty vector is not empty | ||
let decoded_response: Vec<u8> = Decode::decode(&mut response.as_slice()).unwrap(); | ||
assert!(decoded_response.is_empty()); // decode the response, and we get an empty vector again | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is not really meaningful, and with the generics I could no longer use the mock!
macro.
rpc::{tungstenite_client::TungsteniteRpcClient, Error as RpcClientError}, | ||
}; | ||
|
||
pub type ParentchainApi = Api<ParentchainRuntimeConfig, TungsteniteRpcClient>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this type to prevent ambiguities. We use IntegriteeApi, TargetAApi, TargetBApi in all cases now, or we are generic over traits.
This was mostly accomplished introducing additional type parameters, or generics to support config discrepancies.
Other changes:
ParentchainApi
to prevent ambiguities. We explicitly use nowIntegriteeRpcApi
,TargetARpcApi
, TargetBRpcApi`, or just have generic type parameters.