-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Goal The goal of this PR is to verify that the nonce is correct for the account_id and increase the nonce. And to restrict the transactions that can be called inside a passkey Closes #2030 # Checklist - [x] Chain spec updated - [x] Tests added - [x] Benchmarks added - [x] Weights updated
- Loading branch information
Showing
8 changed files
with
539 additions
and
75 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,72 @@ | ||
#![allow(clippy::unwrap_used)] | ||
use super::*; | ||
|
||
use crate::types::*; | ||
#[allow(unused)] | ||
use crate::Pallet as Passkey; | ||
use frame_benchmarking::{benchmarks, whitelisted_caller}; | ||
use frame_benchmarking::benchmarks; | ||
use frame_support::assert_ok; | ||
use sp_core::{crypto::KeyTypeId, Encode}; | ||
use sp_runtime::{traits::Zero, MultiSignature, RuntimeAppPublic}; | ||
use sp_std::prelude::*; | ||
|
||
pub const TEST_KEY_TYPE_ID: KeyTypeId = KeyTypeId(*b"test"); | ||
|
||
mod app_sr25519 { | ||
use super::TEST_KEY_TYPE_ID; | ||
use sp_core::sr25519; | ||
use sp_runtime::app_crypto::app_crypto; | ||
app_crypto!(sr25519, TEST_KEY_TYPE_ID); | ||
} | ||
|
||
type SignerId = app_sr25519::Public; | ||
|
||
fn generate_payload<T: Config>() -> PasskeyPayload<T> { | ||
let test_account_1_pk = SignerId::generate_pair(None); | ||
let passkey_public_key = [0u8; 33]; | ||
let wrapped_binary = wrap_binary_data(passkey_public_key.to_vec()); | ||
let signature: MultiSignature = | ||
MultiSignature::Sr25519(test_account_1_pk.sign(&wrapped_binary).unwrap().into()); | ||
|
||
let inner_call: <T as Config>::RuntimeCall = | ||
frame_system::Call::<T>::remark { remark: vec![] }.into(); | ||
|
||
let call: PasskeyCall<T> = PasskeyCall { | ||
account_id: T::AccountId::decode(&mut &test_account_1_pk.encode()[..]).unwrap(), | ||
account_nonce: T::Nonce::zero(), | ||
account_ownership_proof: signature, | ||
call: Box::new(inner_call), | ||
}; | ||
let payload = PasskeyPayload { | ||
passkey_public_key, | ||
verifiable_passkey_signature: VerifiablePasskeySignature { | ||
signature: PasskeySignature::default(), | ||
client_data_json: PasskeyClientDataJson::default(), | ||
authenticator_data: PasskeyAuthenticatorData::default(), | ||
}, | ||
passkey_call: call, | ||
}; | ||
payload | ||
} | ||
|
||
benchmarks! { | ||
proxy { | ||
let caller: T::AccountId = whitelisted_caller(); | ||
where_clause { where <T as frame_system::Config>::RuntimeCall: Dispatchable<Info = DispatchInfo> } | ||
|
||
validate { | ||
let payload = generate_payload::<T>(); | ||
}: { | ||
//TODO: should calculate overhead after applying all validations | ||
assert_ok!(Passkey::validate_unsigned(TransactionSource::InBlock, &Call::proxy { payload })); | ||
} | ||
verify { | ||
|
||
pre_dispatch { | ||
let payload = generate_payload::<T>(); | ||
}: { | ||
assert_ok!(Passkey::pre_dispatch(&Call::proxy { payload })); | ||
} | ||
|
||
impl_benchmark_test_suite!( | ||
Passkey, | ||
crate::mock::new_test_ext(), | ||
crate::mock::new_test_ext_keystore(), | ||
crate::mock::Test | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.