From 4d9167dfec86913c909dd53948e0c24006baa5a0 Mon Sep 17 00:00:00 2001 From: Alexander Cyon Date: Fri, 10 Nov 2023 16:31:34 +0100 Subject: [PATCH] add unit test --- .../src/resim/cmd_set_default_account.rs | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/simulator/src/resim/cmd_set_default_account.rs b/simulator/src/resim/cmd_set_default_account.rs index dcc5874447c..e8fa6315d35 100644 --- a/simulator/src/resim/cmd_set_default_account.rs +++ b/simulator/src/resim/cmd_set_default_account.rs @@ -34,4 +34,32 @@ impl SetDefaultAccount { writeln!(out, "Default account updated!").map_err(Error::IOError)?; Ok(()) } -} \ No newline at end of file +} + +#[cfg(test)] +#[test] +fn test_validation() { + let mut out = std::io::stdout(); + let private_key = Secp256k1PrivateKey::from_hex( + "6847c11e2d602548dbf38789e0a1f4543c1e7719e4f591d4aa6e5684f5c13d9c", + ) + .unwrap(); + let public_key = private_key.public_key().to_string(); + + let make_cmd = |key_string: String| { + return SetDefaultAccount { + component_address: SimulatorComponentAddress::from_str( + "account_sim1c9yeaya6pehau0fn7vgavuggeev64gahsh05dauae2uu25njk224xz", + ) + .unwrap(), + private_key: key_string, + owner_badge: SimulatorNonFungibleGlobalId::from_str( + "resource_sim1ngvrads4uj3rgq2v9s78fzhvry05dw95wzf3p9r8skhqusf44dlvmr:#1#", + ) + .unwrap(), + }; + }; + + assert!(make_cmd(private_key.to_hex()).run(&mut out).is_ok()); + assert!(make_cmd(public_key.to_string()).run(&mut out).is_err()); +}