Skip to content

Commit

Permalink
Add derivation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardocustodio committed Jan 17, 2024
1 parent 6d5629e commit a74d58d
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion lib/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ use crate::{
wallet_trait::{KeyDerive, Wallet},
};
use codec::Encode;
use sp_core::Pair;
use sp_keyring::AccountKeyring;
use subxt::DefaultConfig;
use subxt::{DefaultConfig, Signer};

const EXTRINSIC: &'static str = "2800016400000000000000016400000000000000000000000000000000";
const SIGNED_EXTRINSIC: &'static str = "11028400d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d0128b46d16901b3544e810c23632291ddd224afa4b9bc041df47a7375e1bf3610277eb58041d45fc3ceec2df308601b5139f4f615acf8acf0809d897ddfa695e8e030000002800016400000000000000016400000000000000000000000000000000";
Expand All @@ -23,6 +24,10 @@ const DERIVED_SIGNED_EXTRINSIC: &'static str = "11028400b2955884765612b245243f63
const ALICE_ACCOUNT: &'static str = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY";
const STORE_ACCOUNT: &'static str = "5DyVgr6rw7Z8zytoJ6vcUNW2uCnWweXiyAqBYBotU7YAfTFV";

const MNEMONIC_PHRASE: &'static str = "total east north winner target fitness custom prize drive arrange snap dolphin";

const PAIR_PASSWORD: &'static str = "SuperStrongPassword995@";

#[tokio::test]
async fn wallet_signs() {
let context_provider = Arc::new(MockEfinityDataProvider::new());
Expand Down Expand Up @@ -58,6 +63,37 @@ async fn wallet_reset_nonce() {
wallet.reset_nonce().await.unwrap();
}

#[tokio::test]
async fn wallet_derivation() {
let keypair = sp_core::sr25519::Pair::from_phrase(MNEMONIC_PHRASE, Some(PAIR_PASSWORD)).expect("Failed to create keypair");
let context_provider = Arc::new(MockEfinityDataProvider::new());
let signer = PairSig::new(keypair.0);

assert_eq!(
format!("{}", signer.account_id()),
"5D27GnTkx4J8nreHAvW8fL1irobW7EPEpbhgbeRyVmVv8nsA"
);

let wallet = MockEfinityWallet::new(&context_provider, signer);
let new_wallet = wallet.derive("player_1_id".into(), None).unwrap().0;
assert_eq!(
format!("{}", new_wallet.account_id().await.unwrap()),
"5CS8AddHCnRmEFC9opAPqbrsTRtZ8CwAjKRhdnabCnc1tZZ6"
);

let new_wallet = wallet.derive("player_2_id".into(), None).unwrap().0;
assert_eq!(
format!("{}", new_wallet.account_id().await.unwrap()),
"5CcrdaTD52u2E7Z4wmpwEmmnAdD5eAWRbi4M2ftShwbHQVFT"
);

let new_wallet = wallet.derive("player_9999_id".into(), None).unwrap().0;
assert_eq!(
format!("{}", new_wallet.account_id().await.unwrap()),
"5G97pVHYwVBvcrpzLEhNWaQS8UFLHrxMqtYpE7wp5AQFBs94"
);
}

#[tokio::test]
async fn wallet_derive_works() {
let context_provider = Arc::new(MockEfinityDataProvider::new());
Expand Down

0 comments on commit a74d58d

Please sign in to comment.