diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d54fa2f..ca26891 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,22 +1,53 @@ name: Rust +# Cancel a currently running workflow from the same PR, branch or tag when a new workflow is +# triggered (ref https://stackoverflow.com/a/72408109) +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + on: push: - branches: [ "master" ] + branches: ["master"] pull_request: - branches: [ "master" ] + branches: ["master"] env: CARGO_TERM_COLOR: always + TOOLCHAIN_LINT: nightly-2023-11-13 jobs: build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Build + run: cargo build --verbose + lint: runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install nightly toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ env.TOOLCHAIN_LINT }} + components: rustfmt, clippy, rust-src + override: true + + - name: Fmt + run: cargo +${{ env.TOOLCHAIN_LINT }} fmt --all -- --check + + - name: Clippy + uses: actions-rs-plus/clippy-check@v2 + with: + toolchain: ${{ env.TOOLCHAIN_LINT }} + args: --all-targets --all-features -- -D warnings + + test: + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose + - uses: actions/checkout@v3 + - name: Run tests + run: cargo test --verbose diff --git a/src/build_upgrade.rs b/src/build_upgrade.rs index b49d1fd..94f99e6 100644 --- a/src/build_upgrade.rs +++ b/src/build_upgrade.rs @@ -50,9 +50,9 @@ pub(crate) async fn build_upgrade(prefs: UpgradeArgs) { // Parse the CLI inputs and return a typed struct with all the details needed. fn parse_inputs(prefs: UpgradeArgs) -> UpgradeDetails { let mut networks = Vec::new(); - let relay_version = String::from(prefs.relay_version.trim_start_matches("v")); + let relay_version = String::from(prefs.relay_version.trim_start_matches('v')); let paras_version = if let Some(user_para_version) = prefs.parachain_version { - String::from(user_para_version.trim_start_matches("v")) + String::from(user_para_version.trim_start_matches('v')) } else { relay_version.clone() }; @@ -106,7 +106,7 @@ fn parse_inputs(prefs: UpgradeArgs) -> UpgradeDetails { make_version_directory(directory.as_str()); - return UpgradeDetails { relay, networks, directory, output_file } + UpgradeDetails { relay, networks, directory, output_file } } // Create a directory into which to place runtime blobs and the final call data. @@ -117,7 +117,7 @@ fn make_version_directory(dir_name: &str) { } // Convert a semver version (e.g. "1.2.3") to an integer runtime version (e.g. 1002003). -fn semver_to_intver(semver: &String) -> String { +fn semver_to_intver(semver: &str) -> String { // M.m.p => M_mmm_ppp let points = semver.bytes().enumerate().filter(|(_, b)| *b == b'.').map(|(i, _)| i).collect::>(); @@ -186,7 +186,7 @@ fn generate_authorize_upgrade_calls(upgrade_details: &UpgradeDetails) -> Vec Vec Vec Vec Vec Vec CallInfo { println!("\nGenerating Relay Chain upgrade call. The runtime hash is logged if you would like to verify it with srtool.\n"); let runtime_version = semver_to_intver(&upgrade_details.relay.version); - let upgrade_call = match upgrade_details.relay.network { + match upgrade_details.relay.network { Network::Kusama => { use kusama_relay::runtime_types::frame_system::pallet::Call as SystemCall; @@ -288,7 +288,7 @@ fn generate_relay_upgrade_call(upgrade_details: &UpgradeDetails) -> CallInfo { ); let runtime = fs::read(path).expect("Should give a valid file path"); let runtime_hash = blake2_256(&runtime); - println!("Kusama Relay Chain Runtime Hash: 0x{}", hex::encode(&runtime_hash)); + println!("Kusama Relay Chain Runtime Hash: 0x{}", hex::encode(runtime_hash)); CallInfo::from_runtime_call(NetworkRuntimeCall::Kusama(KusamaRuntimeCall::System( SystemCall::set_code { code: runtime }, @@ -303,15 +303,14 @@ fn generate_relay_upgrade_call(upgrade_details: &UpgradeDetails) -> CallInfo { ); let runtime = fs::read(path).expect("Should give a valid file path"); let runtime_hash = blake2_256(&runtime); - println!("Polkadot Relay Chain Runtime Hash: 0x{}", hex::encode(&runtime_hash)); + println!("Polkadot Relay Chain Runtime Hash: 0x{}", hex::encode(runtime_hash)); CallInfo::from_runtime_call(NetworkRuntimeCall::Polkadot(PolkadotRuntimeCall::System( SystemCall::set_code { code: runtime }, ))) }, _ => panic!("Not a Relay Chain"), - }; - upgrade_call + } } // Take the parachain authorization calls and the Relay Chain call, and batch them into one call @@ -407,7 +406,7 @@ async fn send_as_superuser_from_kusama(auth: &CallInfo) -> KusamaRuntimeCall { }, }; - let (ref_time, proof_size) = get_weight(&auth).await; + let (ref_time, proof_size) = get_weight(auth).await; let para_id = auth.network.get_para_id().unwrap(); KusamaRuntimeCall::XcmPallet(XcmCall::send { dest: Box::new(VersionedMultiLocation::V3(MultiLocation { @@ -447,7 +446,7 @@ async fn send_as_superuser_from_polkadot(auth: &CallInfo) -> PolkadotRuntimeCall }, }; - let (ref_time, proof_size) = get_weight(&auth).await; + let (ref_time, proof_size) = get_weight(auth).await; let para_id = auth.network.get_para_id().unwrap(); PolkadotRuntimeCall::XcmPallet(XcmCall::send { dest: Box::new(VersionedMultiLocation::V3(MultiLocation { diff --git a/src/submit_referendum.rs b/src/submit_referendum.rs index b033c71..3a59000 100644 --- a/src/submit_referendum.rs +++ b/src/submit_referendum.rs @@ -121,7 +121,7 @@ fn parse_inputs(prefs: ReferendumArgs) -> ProposalDetails { AppsUiLink }; - return ProposalDetails { + ProposalDetails { proposal, track, dispatch, @@ -140,7 +140,7 @@ pub(crate) async fn generate_calls(proposal_details: &ProposalDetails) -> Possib NetworkTrack::KusamaRoot => { use kusama_relay::runtime_types::frame_support::dispatch::RawOrigin; kusama_non_fellowship_referenda( - &proposal_details, + proposal_details, KusamaOriginCaller::system(RawOrigin::Root), ) }, @@ -150,11 +150,11 @@ pub(crate) async fn generate_calls(proposal_details: &ProposalDetails) -> Possib match kusama_track { // Whitelisted calls are special. KusamaOpenGovOrigin::WhitelistedCaller => - kusama_fellowship_referenda(&proposal_details), + kusama_fellowship_referenda(proposal_details), // All other Kusama origins. _ => kusama_non_fellowship_referenda( - &proposal_details, + proposal_details, KusamaOriginCaller::Origins(kusama_track.clone()), ), } @@ -164,7 +164,7 @@ pub(crate) async fn generate_calls(proposal_details: &ProposalDetails) -> Possib NetworkTrack::PolkadotRoot => { use polkadot_relay::runtime_types::frame_support::dispatch::RawOrigin; polkadot_non_fellowship_referenda( - &proposal_details, + proposal_details, PolkadotOriginCaller::system(RawOrigin::Root), ) }, @@ -173,11 +173,11 @@ pub(crate) async fn generate_calls(proposal_details: &ProposalDetails) -> Possib NetworkTrack::Polkadot(polkadot_track) => { match polkadot_track { PolkadotOpenGovOrigin::WhitelistedCaller => - polkadot_fellowship_referenda(&proposal_details).await, + polkadot_fellowship_referenda(proposal_details).await, // All other Polkadot origins. _ => polkadot_non_fellowship_referenda( - &proposal_details, + proposal_details, PolkadotOriginCaller::Origins(polkadot_track.clone()), ), } @@ -626,21 +626,21 @@ fn handle_batch_of_calls(output: &Output, batch: Vec) { _ => panic!("no other chains are needed for this"), } } - if kusama_relay_batch.len() > 0 { + if !kusama_relay_batch.is_empty() { let batch = KusamaRuntimeCall::Utility(KusamaUtilityCall::force_batch { calls: kusama_relay_batch, }); println!("\nBatch to submit on Kusama Relay Chain:"); print_output(output, &NetworkRuntimeCall::Kusama(batch)); } - if polkadot_relay_batch.len() > 0 { + if !polkadot_relay_batch.is_empty() { let batch = PolkadotRuntimeCall::Utility(PolkadotRelayUtilityCall::force_batch { calls: polkadot_relay_batch, }); println!("\nBatch to submit on Polkadot Relay Chain:"); print_output(output, &NetworkRuntimeCall::Polkadot(batch)); } - if polkadot_collectives_batch.len() > 0 { + if !polkadot_collectives_batch.is_empty() { let batch = CollectivesRuntimeCall::Utility(CollectivesUtilityCall::force_batch { calls: polkadot_collectives_batch, }); diff --git a/src/tests.rs b/src/tests.rs index 8bedc28..3bf2c44 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,449 +1,424 @@ -#[cfg(test)] -mod tests { - use crate::polkadot_relay::runtime_types::frame_system::pallet::Call as PolkadotRelaySystemCall; - use crate::{ - submit_referendum::{generate_calls, get_proposal_bytes}, - CallInfo, CallOrHash, KusamaOpenGovOrigin, Network, NetworkRuntimeCall, - PolkadotOpenGovOrigin, PolkadotRuntimeCall, ProposalDetails, Weight, - }; - - fn polkadot_whitelist_remark_user_input() -> ProposalDetails { - use crate::DispatchTimeWrapper::*; - use crate::NetworkTrack::*; - use crate::Output::*; - return ProposalDetails { - // `system.remark("opengov-submit test")` - proposal: String::from("0x00004c6f70656e676f762d7375626d69742074657374"), - track: Polkadot(PolkadotOpenGovOrigin::WhitelistedCaller), - dispatch: After(10), - output: AppsUiLink, - output_len_limit: 1_000, - print_batch: true, - transact_weight_override: Some(Weight { - ref_time: 1_000_000_000, - proof_size: 1_000_000, - }), - } +use crate::polkadot_relay::runtime_types::frame_system::pallet::Call as PolkadotRelaySystemCall; +use crate::{ + submit_referendum::{generate_calls, get_proposal_bytes}, + CallInfo, CallOrHash, KusamaOpenGovOrigin, Network, NetworkRuntimeCall, PolkadotOpenGovOrigin, + PolkadotRuntimeCall, ProposalDetails, Weight, +}; + +fn polkadot_whitelist_remark_user_input() -> ProposalDetails { + use crate::DispatchTimeWrapper::*; + use crate::NetworkTrack::*; + use crate::Output::*; + ProposalDetails { + // `system.remark("opengov-submit test")` + proposal: String::from("0x00004c6f70656e676f762d7375626d69742074657374"), + track: Polkadot(PolkadotOpenGovOrigin::WhitelistedCaller), + dispatch: After(10), + output: AppsUiLink, + output_len_limit: 1_000, + print_batch: true, + transact_weight_override: Some(Weight { ref_time: 1_000_000_000, proof_size: 1_000_000 }), } +} - fn polkadot_staking_validator_user_input() -> ProposalDetails { - use crate::DispatchTimeWrapper::*; - use crate::NetworkTrack::*; - use crate::Output::*; - return ProposalDetails { - // `staking.increase_validator_count(50)` - proposal: String::from("0x070ac8"), - track: Polkadot(PolkadotOpenGovOrigin::StakingAdmin), - dispatch: After(10), - output: AppsUiLink, - output_len_limit: 1_000, - print_batch: true, - transact_weight_override: Some(Weight { - ref_time: 1_000_000_000, - proof_size: 1_000_000, - }), - } +fn polkadot_staking_validator_user_input() -> ProposalDetails { + use crate::DispatchTimeWrapper::*; + use crate::NetworkTrack::*; + use crate::Output::*; + ProposalDetails { + // `staking.increase_validator_count(50)` + proposal: String::from("0x070ac8"), + track: Polkadot(PolkadotOpenGovOrigin::StakingAdmin), + dispatch: After(10), + output: AppsUiLink, + output_len_limit: 1_000, + print_batch: true, + transact_weight_override: Some(Weight { ref_time: 1_000_000_000, proof_size: 1_000_000 }), } +} - fn polkadot_root_remark_user_input() -> ProposalDetails { - use crate::DispatchTimeWrapper::*; - use crate::NetworkTrack::*; - use crate::Output::*; - return ProposalDetails { - // `system.remark("opengov-submit test")` - proposal: String::from("0x00004c6f70656e676f762d7375626d69742074657374"), - track: PolkadotRoot, - dispatch: After(10), - output: AppsUiLink, - output_len_limit: 1_000, - print_batch: true, - transact_weight_override: Some(Weight { - ref_time: 1_000_000_000, - proof_size: 1_000_000, - }), - } +fn polkadot_root_remark_user_input() -> ProposalDetails { + use crate::DispatchTimeWrapper::*; + use crate::NetworkTrack::*; + use crate::Output::*; + ProposalDetails { + // `system.remark("opengov-submit test")` + proposal: String::from("0x00004c6f70656e676f762d7375626d69742074657374"), + track: PolkadotRoot, + dispatch: After(10), + output: AppsUiLink, + output_len_limit: 1_000, + print_batch: true, + transact_weight_override: Some(Weight { ref_time: 1_000_000_000, proof_size: 1_000_000 }), } +} - fn kusama_whitelist_remark_user_input() -> ProposalDetails { - use crate::DispatchTimeWrapper::*; - use crate::NetworkTrack::*; - use crate::Output::*; - return ProposalDetails { - // `system.remark("opengov-submit test")` - proposal: String::from("0x00004c6f70656e676f762d7375626d69742074657374"), - track: Kusama(KusamaOpenGovOrigin::WhitelistedCaller), - dispatch: At(100_000_000), - output: AppsUiLink, - output_len_limit: 1_000, - print_batch: true, - transact_weight_override: Some(Weight { - ref_time: 1_000_000_000, - proof_size: 1_000_000, - }), - } +fn kusama_whitelist_remark_user_input() -> ProposalDetails { + use crate::DispatchTimeWrapper::*; + use crate::NetworkTrack::*; + use crate::Output::*; + ProposalDetails { + // `system.remark("opengov-submit test")` + proposal: String::from("0x00004c6f70656e676f762d7375626d69742074657374"), + track: Kusama(KusamaOpenGovOrigin::WhitelistedCaller), + dispatch: At(100_000_000), + output: AppsUiLink, + output_len_limit: 1_000, + print_batch: true, + transact_weight_override: Some(Weight { ref_time: 1_000_000_000, proof_size: 1_000_000 }), } +} - fn kusama_staking_validator_user_input() -> ProposalDetails { - use crate::DispatchTimeWrapper::*; - use crate::NetworkTrack::*; - use crate::Output::*; - return ProposalDetails { - // `staking.increase_validator_count(50)` - proposal: String::from("0x060ac8"), - track: Kusama(KusamaOpenGovOrigin::StakingAdmin), - dispatch: At(100_000_000), - output: AppsUiLink, - output_len_limit: 1_000, - print_batch: true, - transact_weight_override: Some(Weight { - ref_time: 1_000_000_000, - proof_size: 1_000_000, - }), - } +fn kusama_staking_validator_user_input() -> ProposalDetails { + use crate::DispatchTimeWrapper::*; + use crate::NetworkTrack::*; + use crate::Output::*; + ProposalDetails { + // `staking.increase_validator_count(50)` + proposal: String::from("0x060ac8"), + track: Kusama(KusamaOpenGovOrigin::StakingAdmin), + dispatch: At(100_000_000), + output: AppsUiLink, + output_len_limit: 1_000, + print_batch: true, + transact_weight_override: Some(Weight { ref_time: 1_000_000_000, proof_size: 1_000_000 }), } +} - fn kusama_root_remark_user_input() -> ProposalDetails { - use crate::DispatchTimeWrapper::*; - use crate::NetworkTrack::*; - use crate::Output::*; - return ProposalDetails { - // `system.remark("opengov-submit test")` - proposal: String::from("0x00004c6f70656e676f762d7375626d69742074657374"), - track: KusamaRoot, - dispatch: After(10), - output: AppsUiLink, - output_len_limit: 1_000, - print_batch: true, - transact_weight_override: Some(Weight { - ref_time: 1_000_000_000, - proof_size: 1_000_000, - }), - } +fn kusama_root_remark_user_input() -> ProposalDetails { + use crate::DispatchTimeWrapper::*; + use crate::NetworkTrack::*; + use crate::Output::*; + ProposalDetails { + // `system.remark("opengov-submit test")` + proposal: String::from("0x00004c6f70656e676f762d7375626d69742074657374"), + track: KusamaRoot, + dispatch: After(10), + output: AppsUiLink, + output_len_limit: 1_000, + print_batch: true, + transact_weight_override: Some(Weight { ref_time: 1_000_000_000, proof_size: 1_000_000 }), } +} - fn limited_length_user_input() -> ProposalDetails { - use crate::DispatchTimeWrapper::*; - use crate::NetworkTrack::*; - use crate::Output::*; - return ProposalDetails { - // `system.remark("opengov-submit test")` - proposal: String::from("0x00004c6f70656e676f762d7375626d69742074657374"), - track: Polkadot(PolkadotOpenGovOrigin::StakingAdmin), - dispatch: After(10), - output: AppsUiLink, - output_len_limit: 5, // very limiting - print_batch: true, - transact_weight_override: Some(Weight { - ref_time: 1_000_000_000, - proof_size: 1_000_000, - }), - } +fn limited_length_user_input() -> ProposalDetails { + use crate::DispatchTimeWrapper::*; + use crate::NetworkTrack::*; + use crate::Output::*; + ProposalDetails { + // `system.remark("opengov-submit test")` + proposal: String::from("0x00004c6f70656e676f762d7375626d69742074657374"), + track: Polkadot(PolkadotOpenGovOrigin::StakingAdmin), + dispatch: After(10), + output: AppsUiLink, + output_len_limit: 5, // very limiting + print_batch: true, + transact_weight_override: Some(Weight { ref_time: 1_000_000_000, proof_size: 1_000_000 }), } +} - #[test] - fn call_info_from_bytes_works() { - let proposal_details = polkadot_whitelist_remark_user_input(); - let proposal_bytes = get_proposal_bytes(proposal_details.proposal); - let proposal_call_info = CallInfo::from_bytes(&proposal_bytes, Network::Polkadot); - - let remark_to_verify = PolkadotRuntimeCall::System(PolkadotRelaySystemCall::remark { - remark: b"opengov-submit test".to_vec(), - }); - - let hash_to_verify = "0x8821e8db19b8e34b62ee8bc618a5ed3eecb9761d7d81349b00aa5ce5dfca2534"; - let verification_bytes = - hex::decode(hash_to_verify.trim_start_matches("0x")).expect("Valid hash"); - - assert_eq!(proposal_call_info.get_polkadot_call().expect("polkadot"), remark_to_verify); - assert_eq!(proposal_call_info.encoded, proposal_bytes); - assert_eq!(proposal_call_info.hash, &verification_bytes[..]); - assert_eq!(proposal_call_info.length, 22u32); - - let bad_remark = PolkadotRuntimeCall::System(PolkadotRelaySystemCall::remark { - remark: b"another remark".to_vec(), - }); - let bad_remark_hash = "0x8821e8db19b8e34b62ee8bc618a5ed3eecb9761d7d81349b00aa5ce5dfca2534"; - let bad_verification = - hex::decode(bad_remark_hash.trim_start_matches("0x")).expect("Valid hash"); - assert_ne!(proposal_call_info.get_polkadot_call().expect("polkadot"), bad_remark); - assert_eq!(proposal_call_info.hash, &bad_verification[..]); - } +#[test] +fn call_info_from_bytes_works() { + let proposal_details = polkadot_whitelist_remark_user_input(); + let proposal_bytes = get_proposal_bytes(proposal_details.proposal); + let proposal_call_info = CallInfo::from_bytes(&proposal_bytes, Network::Polkadot); + + let remark_to_verify = PolkadotRuntimeCall::System(PolkadotRelaySystemCall::remark { + remark: b"opengov-submit test".to_vec(), + }); + + let hash_to_verify = "0x8821e8db19b8e34b62ee8bc618a5ed3eecb9761d7d81349b00aa5ce5dfca2534"; + let verification_bytes = + hex::decode(hash_to_verify.trim_start_matches("0x")).expect("Valid hash"); + + assert_eq!(proposal_call_info.get_polkadot_call().expect("polkadot"), remark_to_verify); + assert_eq!(proposal_call_info.encoded, proposal_bytes); + assert_eq!(proposal_call_info.hash, &verification_bytes[..]); + assert_eq!(proposal_call_info.length, 22u32); + + let bad_remark = PolkadotRuntimeCall::System(PolkadotRelaySystemCall::remark { + remark: b"another remark".to_vec(), + }); + let bad_remark_hash = "0x8821e8db19b8e34b62ee8bc618a5ed3eecb9761d7d81349b00aa5ce5dfca2534"; + let bad_verification = + hex::decode(bad_remark_hash.trim_start_matches("0x")).expect("Valid hash"); + assert_ne!(proposal_call_info.get_polkadot_call().expect("polkadot"), bad_remark); + assert_eq!(proposal_call_info.hash, &bad_verification[..]); +} - #[test] - fn call_info_from_runtime_call_works() { - let remark_to_verify = PolkadotRuntimeCall::System(PolkadotRelaySystemCall::remark { - remark: b"opengov-submit test".to_vec(), - }); - let call_info = CallInfo::from_runtime_call(NetworkRuntimeCall::Polkadot(remark_to_verify)); +#[test] +fn call_info_from_runtime_call_works() { + let remark_to_verify = PolkadotRuntimeCall::System(PolkadotRelaySystemCall::remark { + remark: b"opengov-submit test".to_vec(), + }); + let call_info = CallInfo::from_runtime_call(NetworkRuntimeCall::Polkadot(remark_to_verify)); - let encoded_to_verify = - hex::decode("0x00004c6f70656e676f762d7375626d69742074657374".trim_start_matches("0x")) - .expect("Valid encoded"); + let encoded_to_verify = + hex::decode("0x00004c6f70656e676f762d7375626d69742074657374".trim_start_matches("0x")) + .expect("Valid encoded"); - let hash_to_verify = "0x8821e8db19b8e34b62ee8bc618a5ed3eecb9761d7d81349b00aa5ce5dfca2534"; - let verification_bytes = - hex::decode(hash_to_verify.trim_start_matches("0x")).expect("Valid hash"); + let hash_to_verify = "0x8821e8db19b8e34b62ee8bc618a5ed3eecb9761d7d81349b00aa5ce5dfca2534"; + let verification_bytes = + hex::decode(hash_to_verify.trim_start_matches("0x")).expect("Valid hash"); - assert_eq!(call_info.encoded, encoded_to_verify); - assert_eq!(call_info.hash, &verification_bytes[..]); - assert_eq!(call_info.length, 22u32); - } + assert_eq!(call_info.encoded, encoded_to_verify); + assert_eq!(call_info.hash, &verification_bytes[..]); + assert_eq!(call_info.length, 22u32); +} - #[tokio::test] - async fn it_starts_polkadot_non_fellowship_referenda_correctly() { - let proposal_details = polkadot_staking_validator_user_input(); - let calls = generate_calls(&proposal_details).await; - - let public_preimage = - hex::decode("0x0a000c070ac8".trim_start_matches("0x")).expect("Valid call"); - let public_referendum = hex::decode("0x1500160002439a93279b25a49bf366c9fe1b06d4fc342f46b5a3b2734dcffe0c56c12b28ef03000000010a000000".trim_start_matches("0x")).expect("Valid call"); - - assert!(calls.preimage_for_whitelist_call.is_none(), "it must not generate this call"); - assert!(calls.fellowship_referendum_submission.is_none(), "it must not generate this call"); - - assert!(calls.preimage_for_public_referendum.is_some(), "it must generate this call"); - if let Some((coh, length)) = calls.preimage_for_public_referendum { - match coh { - CallOrHash::Call(public_preimage_generated) => { - let call_info = CallInfo::from_runtime_call(public_preimage_generated); - assert_eq!(call_info.encoded, public_preimage); - assert_eq!(length, 6u32); - }, - CallOrHash::Hash(_) => panic!("call length within the limit"), - } - } +#[tokio::test] +async fn it_starts_polkadot_non_fellowship_referenda_correctly() { + let proposal_details = polkadot_staking_validator_user_input(); + let calls = generate_calls(&proposal_details).await; - assert!(calls.public_referendum_submission.is_some(), "it must generate this call"); - if let Some(public_referendum_generated) = calls.public_referendum_submission { - let call_info = CallInfo::from_runtime_call(public_referendum_generated); - assert_eq!(call_info.encoded, public_referendum); - } - } + let public_preimage = + hex::decode("0x0a000c070ac8".trim_start_matches("0x")).expect("Valid call"); + let public_referendum = hex::decode("0x1500160002439a93279b25a49bf366c9fe1b06d4fc342f46b5a3b2734dcffe0c56c12b28ef03000000010a000000".trim_start_matches("0x")).expect("Valid call"); - #[tokio::test] - async fn it_starts_polkadot_fellowship_referenda_correctly() { - // Fellowship XCM Send - // 0x1f0003010003082f0000060302286bee02093d008817008821e8db19b8e34b62ee8bc618a5ed3eecb9761d7d81349b00aa5ce5dfca2534 - // 0xadb9e4e4165f92f984690cac8816898978b7dfc8aff6db735ffd5ec9b0430097 - let proposal_details = polkadot_whitelist_remark_user_input(); - let calls = generate_calls(&proposal_details).await; - - let fellowship_preimage = hex::decode("0x2b00dc1f0003010003082f0000060302286bee02093d008817008821e8db19b8e34b62ee8bc618a5ed3eecb9761d7d81349b00aa5ce5dfca2534".trim_start_matches("0x")).expect("Valid call"); - let fellowship_referendum = hex::decode("0x3d003e0202adb9e4e4165f92f984690cac8816898978b7dfc8aff6db735ffd5ec9b043009737000000010a000000".trim_start_matches("0x")).expect("Valid call"); - let public_preimage = hex::decode( - "0x0a0060170300004c6f70656e676f762d7375626d69742074657374".trim_start_matches("0x"), - ) - .expect("Valid call"); - let public_referendum = hex::decode("0x1500160d02e1ee5465c2c6cf6c8249591e1ddccb7b435e7797e4f58108b170d8ad43a313a918000000010a000000".trim_start_matches("0x")).expect("Valid call"); - - assert!(calls.preimage_for_whitelist_call.is_some(), "it must generate this call"); - if let Some((coh, length)) = calls.preimage_for_whitelist_call { - match coh { - CallOrHash::Call(fellowship_preimage_generated) => { - let call_info = CallInfo::from_runtime_call(fellowship_preimage_generated); - assert_eq!(call_info.encoded, fellowship_preimage); - assert_eq!(length, 58u32); - }, - CallOrHash::Hash(_) => panic!("call length within the limit"), - } - } + assert!(calls.preimage_for_whitelist_call.is_none(), "it must not generate this call"); + assert!(calls.fellowship_referendum_submission.is_none(), "it must not generate this call"); - assert!(calls.preimage_for_public_referendum.is_some(), "it must generate this call"); - if let Some((coh, length)) = calls.preimage_for_public_referendum { - match coh { - CallOrHash::Call(public_preimage_generated) => { - let call_info = CallInfo::from_runtime_call(public_preimage_generated); - assert_eq!(call_info.encoded, public_preimage); - assert_eq!(length, 27u32); - }, - CallOrHash::Hash(_) => panic!("call length within the limit"), - } + assert!(calls.preimage_for_public_referendum.is_some(), "it must generate this call"); + if let Some((coh, length)) = calls.preimage_for_public_referendum { + match coh { + CallOrHash::Call(public_preimage_generated) => { + let call_info = CallInfo::from_runtime_call(public_preimage_generated); + assert_eq!(call_info.encoded, public_preimage); + assert_eq!(length, 6u32); + }, + CallOrHash::Hash(_) => panic!("call length within the limit"), } + } - assert!(calls.fellowship_referendum_submission.is_some(), "it must generate this call"); - if let Some(fellowship_referendum_generated) = calls.fellowship_referendum_submission { - let call_info = CallInfo::from_runtime_call(fellowship_referendum_generated); - assert_eq!(call_info.encoded, fellowship_referendum); - } + assert!(calls.public_referendum_submission.is_some(), "it must generate this call"); + if let Some(public_referendum_generated) = calls.public_referendum_submission { + let call_info = CallInfo::from_runtime_call(public_referendum_generated); + assert_eq!(call_info.encoded, public_referendum); + } +} - assert!(calls.public_referendum_submission.is_some(), "it must generate this call"); - if let Some(public_referendum_generated) = calls.public_referendum_submission { - let call_info = CallInfo::from_runtime_call(public_referendum_generated); - assert_eq!(call_info.encoded, public_referendum); +#[tokio::test] +async fn it_starts_polkadot_fellowship_referenda_correctly() { + // Fellowship XCM Send + // 0x1f0003010003082f0000060302286bee02093d008817008821e8db19b8e34b62ee8bc618a5ed3eecb9761d7d81349b00aa5ce5dfca2534 + // 0xadb9e4e4165f92f984690cac8816898978b7dfc8aff6db735ffd5ec9b0430097 + let proposal_details = polkadot_whitelist_remark_user_input(); + let calls = generate_calls(&proposal_details).await; + + let fellowship_preimage = hex::decode("0x2b00dc1f0003010003082f0000060302286bee02093d008817008821e8db19b8e34b62ee8bc618a5ed3eecb9761d7d81349b00aa5ce5dfca2534".trim_start_matches("0x")).expect("Valid call"); + let fellowship_referendum = hex::decode("0x3d003e0202adb9e4e4165f92f984690cac8816898978b7dfc8aff6db735ffd5ec9b043009737000000010a000000".trim_start_matches("0x")).expect("Valid call"); + let public_preimage = hex::decode( + "0x0a0060170300004c6f70656e676f762d7375626d69742074657374".trim_start_matches("0x"), + ) + .expect("Valid call"); + let public_referendum = hex::decode("0x1500160d02e1ee5465c2c6cf6c8249591e1ddccb7b435e7797e4f58108b170d8ad43a313a918000000010a000000".trim_start_matches("0x")).expect("Valid call"); + + assert!(calls.preimage_for_whitelist_call.is_some(), "it must generate this call"); + if let Some((coh, length)) = calls.preimage_for_whitelist_call { + match coh { + CallOrHash::Call(fellowship_preimage_generated) => { + let call_info = CallInfo::from_runtime_call(fellowship_preimage_generated); + assert_eq!(call_info.encoded, fellowship_preimage); + assert_eq!(length, 58u32); + }, + CallOrHash::Hash(_) => panic!("call length within the limit"), } } - #[tokio::test] - async fn it_starts_polkadot_root_referenda_correctly() { - let proposal_details = polkadot_root_remark_user_input(); - let calls = generate_calls(&proposal_details).await; - - let public_preimage = hex::decode( - "0x0a005800004c6f70656e676f762d7375626d69742074657374".trim_start_matches("0x"), - ) - .expect("Valid call"); - let public_referendum = hex::decode("0x15000000028821e8db19b8e34b62ee8bc618a5ed3eecb9761d7d81349b00aa5ce5dfca253416000000010a000000".trim_start_matches("0x")).expect("Valid call"); - - assert!(calls.preimage_for_whitelist_call.is_none(), "it must not generate this call"); - assert!(calls.fellowship_referendum_submission.is_none(), "it must not generate this call"); - - assert!(calls.preimage_for_public_referendum.is_some(), "it must generate this call"); - if let Some((coh, length)) = calls.preimage_for_public_referendum { - match coh { - CallOrHash::Call(public_preimage_generated) => { - let call_info = CallInfo::from_runtime_call(public_preimage_generated); - assert_eq!(call_info.encoded, public_preimage); - assert_eq!(length, 25u32); - }, - CallOrHash::Hash(_) => panic!("call length within the limit"), - } + assert!(calls.preimage_for_public_referendum.is_some(), "it must generate this call"); + if let Some((coh, length)) = calls.preimage_for_public_referendum { + match coh { + CallOrHash::Call(public_preimage_generated) => { + let call_info = CallInfo::from_runtime_call(public_preimage_generated); + assert_eq!(call_info.encoded, public_preimage); + assert_eq!(length, 27u32); + }, + CallOrHash::Hash(_) => panic!("call length within the limit"), } + } - assert!(calls.public_referendum_submission.is_some(), "it must generate this call"); - if let Some(public_referendum_generated) = calls.public_referendum_submission { - let call_info = CallInfo::from_runtime_call(public_referendum_generated); - assert_eq!(call_info.encoded, public_referendum); - } + assert!(calls.fellowship_referendum_submission.is_some(), "it must generate this call"); + if let Some(fellowship_referendum_generated) = calls.fellowship_referendum_submission { + let call_info = CallInfo::from_runtime_call(fellowship_referendum_generated); + assert_eq!(call_info.encoded, fellowship_referendum); } - #[tokio::test] - async fn it_starts_kusama_non_fellowship_referenda_correctly() { - let proposal_details = kusama_staking_validator_user_input(); - let calls = generate_calls(&proposal_details).await; - - let public_preimage = - hex::decode("0x20000c060ac8".trim_start_matches("0x")).expect("Valid call"); - let public_referendum = hex::decode("0x15002b00028fd8848a8f93980f5cea2de1c11f29ed7dced592aa207218a2e0ae5b78b9fffb030000000000e1f505".trim_start_matches("0x")).expect("Valid call"); - - assert!(calls.preimage_for_whitelist_call.is_none(), "it must not generate this call"); - assert!(calls.fellowship_referendum_submission.is_none(), "it must not generate this call"); - - assert!(calls.preimage_for_public_referendum.is_some(), "it must generate this call"); - if let Some((coh, length)) = calls.preimage_for_public_referendum { - match coh { - CallOrHash::Call(public_preimage_generated) => { - let call_info = CallInfo::from_runtime_call(public_preimage_generated); - assert_eq!(call_info.encoded, public_preimage); - assert_eq!(length, 6u32); - }, - CallOrHash::Hash(_) => panic!("call length within the limit"), - } - } + assert!(calls.public_referendum_submission.is_some(), "it must generate this call"); + if let Some(public_referendum_generated) = calls.public_referendum_submission { + let call_info = CallInfo::from_runtime_call(public_referendum_generated); + assert_eq!(call_info.encoded, public_referendum); + } +} + +#[tokio::test] +async fn it_starts_polkadot_root_referenda_correctly() { + let proposal_details = polkadot_root_remark_user_input(); + let calls = generate_calls(&proposal_details).await; + + let public_preimage = hex::decode( + "0x0a005800004c6f70656e676f762d7375626d69742074657374".trim_start_matches("0x"), + ) + .expect("Valid call"); + let public_referendum = hex::decode("0x15000000028821e8db19b8e34b62ee8bc618a5ed3eecb9761d7d81349b00aa5ce5dfca253416000000010a000000".trim_start_matches("0x")).expect("Valid call"); + + assert!(calls.preimage_for_whitelist_call.is_none(), "it must not generate this call"); + assert!(calls.fellowship_referendum_submission.is_none(), "it must not generate this call"); - assert!(calls.public_referendum_submission.is_some(), "it must generate this call"); - if let Some(public_referendum_generated) = calls.public_referendum_submission { - let call_info = CallInfo::from_runtime_call(public_referendum_generated); - assert_eq!(call_info.encoded, public_referendum); + assert!(calls.preimage_for_public_referendum.is_some(), "it must generate this call"); + if let Some((coh, length)) = calls.preimage_for_public_referendum { + match coh { + CallOrHash::Call(public_preimage_generated) => { + let call_info = CallInfo::from_runtime_call(public_preimage_generated); + assert_eq!(call_info.encoded, public_preimage); + assert_eq!(length, 25u32); + }, + CallOrHash::Hash(_) => panic!("call length within the limit"), } } - #[tokio::test] - async fn it_starts_kusama_fellowship_referenda_correctly() { - let proposal_details = kusama_whitelist_remark_user_input(); - let calls = generate_calls(&proposal_details).await; - - let fellowship_preimage = hex::decode( - "0x2000882c008821e8db19b8e34b62ee8bc618a5ed3eecb9761d7d81349b00aa5ce5dfca2534" - .trim_start_matches("0x"), - ) - .expect("Valid call"); - let fellowship_referendum = hex::decode("0x17002b0f02749aff5c635d7ebf11a5199f92cf566d7ae0244fa6c26da5c6e70a215a35c59522000000010a000000".trim_start_matches("0x")).expect("Valid call"); - let public_preimage = hex::decode( - "0x2000602c0300004c6f70656e676f762d7375626d69742074657374".trim_start_matches("0x"), - ) - .expect("Valid call"); - let public_referendum = hex::decode("0x15002b0d022c1a994725955d3635ce1969e52f25b79b4f8c9685637e63e8eff59ba3f8a9d0180000000000e1f505".trim_start_matches("0x")).expect("Valid call"); - - assert!(calls.preimage_for_whitelist_call.is_some(), "it must generate this call"); - if let Some((coh, length)) = calls.preimage_for_whitelist_call { - match coh { - CallOrHash::Call(fellowship_preimage_generated) => { - let call_info = CallInfo::from_runtime_call(fellowship_preimage_generated); - assert_eq!(call_info.encoded, fellowship_preimage); - assert_eq!(length, 37u32); - }, - CallOrHash::Hash(_) => panic!("call length within the limit"), - } - } + assert!(calls.public_referendum_submission.is_some(), "it must generate this call"); + if let Some(public_referendum_generated) = calls.public_referendum_submission { + let call_info = CallInfo::from_runtime_call(public_referendum_generated); + assert_eq!(call_info.encoded, public_referendum); + } +} - assert!(calls.preimage_for_public_referendum.is_some(), "it must generate this call"); - if let Some((coh, length)) = calls.preimage_for_public_referendum { - match coh { - CallOrHash::Call(public_preimage_generated) => { - let call_info = CallInfo::from_runtime_call(public_preimage_generated); - assert_eq!(call_info.encoded, public_preimage); - assert_eq!(length, 27u32); - }, - CallOrHash::Hash(_) => panic!("call length within the limit"), - } - } +#[tokio::test] +async fn it_starts_kusama_non_fellowship_referenda_correctly() { + let proposal_details = kusama_staking_validator_user_input(); + let calls = generate_calls(&proposal_details).await; - assert!(calls.fellowship_referendum_submission.is_some(), "it must generate this call"); - if let Some(fellowship_referendum_generated) = calls.fellowship_referendum_submission { - let call_info = CallInfo::from_runtime_call(fellowship_referendum_generated); - assert_eq!(call_info.encoded, fellowship_referendum); - } + let public_preimage = + hex::decode("0x20000c060ac8".trim_start_matches("0x")).expect("Valid call"); + let public_referendum = hex::decode("0x15002b00028fd8848a8f93980f5cea2de1c11f29ed7dced592aa207218a2e0ae5b78b9fffb030000000000e1f505".trim_start_matches("0x")).expect("Valid call"); + + assert!(calls.preimage_for_whitelist_call.is_none(), "it must not generate this call"); + assert!(calls.fellowship_referendum_submission.is_none(), "it must not generate this call"); - assert!(calls.public_referendum_submission.is_some(), "it must generate this call"); - if let Some(public_referendum_generated) = calls.public_referendum_submission { - let call_info = CallInfo::from_runtime_call(public_referendum_generated); - assert_eq!(call_info.encoded, public_referendum); + assert!(calls.preimage_for_public_referendum.is_some(), "it must generate this call"); + if let Some((coh, length)) = calls.preimage_for_public_referendum { + match coh { + CallOrHash::Call(public_preimage_generated) => { + let call_info = CallInfo::from_runtime_call(public_preimage_generated); + assert_eq!(call_info.encoded, public_preimage); + assert_eq!(length, 6u32); + }, + CallOrHash::Hash(_) => panic!("call length within the limit"), } } - #[tokio::test] - async fn it_starts_kusama_root_referenda_correctly() { - let proposal_details = kusama_root_remark_user_input(); - let calls = generate_calls(&proposal_details).await; - - let public_preimage = hex::decode( - "0x20005800004c6f70656e676f762d7375626d69742074657374".trim_start_matches("0x"), - ) - .expect("Valid call"); - let public_referendum = hex::decode("0x15000000028821e8db19b8e34b62ee8bc618a5ed3eecb9761d7d81349b00aa5ce5dfca253416000000010a000000".trim_start_matches("0x")).expect("Valid call"); - - assert!(calls.preimage_for_whitelist_call.is_none(), "it must not generate this call"); - assert!(calls.fellowship_referendum_submission.is_none(), "it must not generate this call"); - - assert!(calls.preimage_for_public_referendum.is_some(), "it must generate this call"); - if let Some((coh, length)) = calls.preimage_for_public_referendum { - match coh { - CallOrHash::Call(public_preimage_generated) => { - let call_info = CallInfo::from_runtime_call(public_preimage_generated); - assert_eq!(call_info.encoded, public_preimage); - assert_eq!(length, 25u32); - }, - CallOrHash::Hash(_) => panic!("call length within the limit"), - } + assert!(calls.public_referendum_submission.is_some(), "it must generate this call"); + if let Some(public_referendum_generated) = calls.public_referendum_submission { + let call_info = CallInfo::from_runtime_call(public_referendum_generated); + assert_eq!(call_info.encoded, public_referendum); + } +} + +#[tokio::test] +async fn it_starts_kusama_fellowship_referenda_correctly() { + let proposal_details = kusama_whitelist_remark_user_input(); + let calls = generate_calls(&proposal_details).await; + + let fellowship_preimage = hex::decode( + "0x2000882c008821e8db19b8e34b62ee8bc618a5ed3eecb9761d7d81349b00aa5ce5dfca2534" + .trim_start_matches("0x"), + ) + .expect("Valid call"); + let fellowship_referendum = hex::decode("0x17002b0f02749aff5c635d7ebf11a5199f92cf566d7ae0244fa6c26da5c6e70a215a35c59522000000010a000000".trim_start_matches("0x")).expect("Valid call"); + let public_preimage = hex::decode( + "0x2000602c0300004c6f70656e676f762d7375626d69742074657374".trim_start_matches("0x"), + ) + .expect("Valid call"); + let public_referendum = hex::decode("0x15002b0d022c1a994725955d3635ce1969e52f25b79b4f8c9685637e63e8eff59ba3f8a9d0180000000000e1f505".trim_start_matches("0x")).expect("Valid call"); + + assert!(calls.preimage_for_whitelist_call.is_some(), "it must generate this call"); + if let Some((coh, length)) = calls.preimage_for_whitelist_call { + match coh { + CallOrHash::Call(fellowship_preimage_generated) => { + let call_info = CallInfo::from_runtime_call(fellowship_preimage_generated); + assert_eq!(call_info.encoded, fellowship_preimage); + assert_eq!(length, 37u32); + }, + CallOrHash::Hash(_) => panic!("call length within the limit"), } + } - assert!(calls.public_referendum_submission.is_some(), "it must generate this call"); - if let Some(public_referendum_generated) = calls.public_referendum_submission { - let call_info = CallInfo::from_runtime_call(public_referendum_generated); - assert_eq!(call_info.encoded, public_referendum); + assert!(calls.preimage_for_public_referendum.is_some(), "it must generate this call"); + if let Some((coh, length)) = calls.preimage_for_public_referendum { + match coh { + CallOrHash::Call(public_preimage_generated) => { + let call_info = CallInfo::from_runtime_call(public_preimage_generated); + assert_eq!(call_info.encoded, public_preimage); + assert_eq!(length, 27u32); + }, + CallOrHash::Hash(_) => panic!("call length within the limit"), } } - #[test] - fn it_creates_constrained_print_output() { - let proposal_details = limited_length_user_input(); - let proposal_bytes = get_proposal_bytes(proposal_details.proposal); - let proposal_call_info = CallInfo::from_bytes(&proposal_bytes, Network::Polkadot); - let (coh, length) = - proposal_call_info.create_print_output(proposal_details.output_len_limit); + assert!(calls.fellowship_referendum_submission.is_some(), "it must generate this call"); + if let Some(fellowship_referendum_generated) = calls.fellowship_referendum_submission { + let call_info = CallInfo::from_runtime_call(fellowship_referendum_generated); + assert_eq!(call_info.encoded, fellowship_referendum); + } - let expected_hash = hex::decode( - "0x8821e8db19b8e34b62ee8bc618a5ed3eecb9761d7d81349b00aa5ce5dfca2534" - .trim_start_matches("0x"), - ) - .expect("Valid hash"); + assert!(calls.public_referendum_submission.is_some(), "it must generate this call"); + if let Some(public_referendum_generated) = calls.public_referendum_submission { + let call_info = CallInfo::from_runtime_call(public_referendum_generated); + assert_eq!(call_info.encoded, public_referendum); + } +} +#[tokio::test] +async fn it_starts_kusama_root_referenda_correctly() { + let proposal_details = kusama_root_remark_user_input(); + let calls = generate_calls(&proposal_details).await; + + let public_preimage = hex::decode( + "0x20005800004c6f70656e676f762d7375626d69742074657374".trim_start_matches("0x"), + ) + .expect("Valid call"); + let public_referendum = hex::decode("0x15000000028821e8db19b8e34b62ee8bc618a5ed3eecb9761d7d81349b00aa5ce5dfca253416000000010a000000".trim_start_matches("0x")).expect("Valid call"); + + assert!(calls.preimage_for_whitelist_call.is_none(), "it must not generate this call"); + assert!(calls.fellowship_referendum_submission.is_none(), "it must not generate this call"); + + assert!(calls.preimage_for_public_referendum.is_some(), "it must generate this call"); + if let Some((coh, length)) = calls.preimage_for_public_referendum { match coh { - CallOrHash::Call(_) => panic!("this should not have a call"), - CallOrHash::Hash(h) => { - assert_eq!(h, &expected_hash[..]); + CallOrHash::Call(public_preimage_generated) => { + let call_info = CallInfo::from_runtime_call(public_preimage_generated); + assert_eq!(call_info.encoded, public_preimage); + assert_eq!(length, 25u32); }, + CallOrHash::Hash(_) => panic!("call length within the limit"), } - assert_eq!(length, proposal_call_info.length); } + + assert!(calls.public_referendum_submission.is_some(), "it must generate this call"); + if let Some(public_referendum_generated) = calls.public_referendum_submission { + let call_info = CallInfo::from_runtime_call(public_referendum_generated); + assert_eq!(call_info.encoded, public_referendum); + } +} + +#[test] +fn it_creates_constrained_print_output() { + let proposal_details = limited_length_user_input(); + let proposal_bytes = get_proposal_bytes(proposal_details.proposal); + let proposal_call_info = CallInfo::from_bytes(&proposal_bytes, Network::Polkadot); + let (coh, length) = proposal_call_info.create_print_output(proposal_details.output_len_limit); + + let expected_hash = hex::decode( + "0x8821e8db19b8e34b62ee8bc618a5ed3eecb9761d7d81349b00aa5ce5dfca2534" + .trim_start_matches("0x"), + ) + .expect("Valid hash"); + + match coh { + CallOrHash::Call(_) => panic!("this should not have a call"), + CallOrHash::Hash(h) => { + assert_eq!(h, &expected_hash[..]); + }, + } + assert_eq!(length, proposal_call_info.length); } diff --git a/src/types.rs b/src/types.rs index c236b92..f024164 100644 --- a/src/types.rs +++ b/src/types.rs @@ -174,14 +174,14 @@ impl CallInfo { NetworkRuntimeCall::PolkadotBridgeHub(cc) => (Network::PolkadotBridgeHub, cc.encode()), }; let hash = blake2_256(&encoded); - let length: u32 = (*&encoded.len()).try_into().unwrap(); + let length: u32 = (encoded.len()).try_into().unwrap(); Self { network, encoded: encoded.to_vec(), hash, length } } // Construct `Self` for some `network` given some `encoded` bytes. pub(super) fn from_bytes(encoded: &Vec, network: Network) -> Self { - let hash = blake2_256(&encoded); - let length = (*&encoded.len()).try_into().unwrap(); + let hash = blake2_256(encoded); + let length = (encoded.len()).try_into().unwrap(); Self { network, encoded: encoded.to_vec(), hash, length } } @@ -193,7 +193,7 @@ impl CallInfo { Ok(::decode(&mut &bytes[..]) .unwrap()) }, - _ => return Err("not a kusama call"), + _ => Err("not a kusama call"), } } @@ -210,7 +210,7 @@ impl CallInfo { ) .unwrap()) }, - _ => return Err("not a kusama asset hub call"), + _ => Err("not a kusama asset hub call"), } } @@ -227,7 +227,7 @@ impl CallInfo { ) .unwrap()) }, - _ => return Err("not a kusama bridge hub call"), + _ => Err("not a kusama bridge hub call"), } } @@ -239,7 +239,7 @@ impl CallInfo { Ok(::decode(&mut &bytes[..]) .unwrap()) }, - _ => return Err("not a polkadot call"), + _ => Err("not a polkadot call"), } } @@ -256,7 +256,7 @@ impl CallInfo { ) .unwrap()) }, - _ => return Err("not a polkadot asset hub call"), + _ => Err("not a polkadot asset hub call"), } } @@ -270,7 +270,7 @@ impl CallInfo { Ok(::decode(&mut &bytes[..]) .unwrap()) }, - _ => return Err("not a polkadot collectives call"), + _ => Err("not a polkadot collectives call"), } } @@ -287,7 +287,7 @@ impl CallInfo { ) .unwrap()) }, - _ => return Err("not a polkadot bridge hub call"), + _ => Err("not a polkadot bridge hub call"), } } @@ -327,11 +327,10 @@ impl CallInfo { // length. This is because the call is `preimage.note_preimage(call)`, so the outer pallet/call // indices have a length of 2 bytes. pub(super) fn create_print_output(&self, length_limit: u32) -> (CallOrHash, u32) { - let print_output: CallOrHash; - if self.length > length_limit { - print_output = CallOrHash::Hash(self.hash); + let print_output = if self.length > length_limit { + CallOrHash::Hash(self.hash) } else { - print_output = match &self.network { + match &self.network { Network::Kusama => { let kusama_call = self.get_kusama_call().expect("kusama"); CallOrHash::Call(NetworkRuntimeCall::Kusama(kusama_call)) @@ -346,8 +345,8 @@ impl CallInfo { CallOrHash::Call(NetworkRuntimeCall::PolkadotCollectives(collectives_call)) }, _ => panic!("to do"), - }; - } + } + }; (print_output, self.length) } }