Add unit tests tha cover submitter not found and incorrect submitter
@@ -1303,6 +1303,75 @@ fn test_authority_selection() {
ext.execute_with(|| {
let submitter = ExecDelivery::select_authority(escrow.clone());
- assert_eq!(submitter.is_ok(), true);
+ assert!(submitter.is_ok());
+ });
+}
+
+#[test]
+fn error_if_keystore_is_empty(){
+ let keystore = KeyStore::new();
+
+ // Alice's escrow account
+ let escrow: AccountId = hex_literal::hex!["8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48"]
+ .into();
+
+ let mut ext = TestExternalities::new_empty();
+ ext.register_extension(KeystoreExt(keystore.into()));
+ ext.execute_with(|| {
+ let submitter = ExecDelivery::select_authority(escrow.clone());
+
+ assert!(submitter.is_err());
+ });
+}
+
+#[test]
+fn error_if_incorrect_escrow_is_submitted(){
+ let keystore = KeyStore::new();
+
+ // Insert Alice's keys
+ const SURI_ALICE: &str = "//Alice";
+ let key_pair_alice = sr25519::Pair::from_string(SURI_ALICE, None).expect("Generates key pair");
+ SyncCryptoStore::insert_unknown(
+ &keystore,
+ KEY_TYPE,
+ SURI_ALICE,
+ key_pair_alice.public().as_ref(),
+ )
+ .expect("Inserts unknown key");
+
+ // Insert Bob's keys
+ const SURI_BOB: &str = "//Bob";
+ let key_pair_bob = sr25519::Pair::from_string(SURI_BOB, None).expect("Generates key pair");
+ SyncCryptoStore::insert_unknown(
+ &keystore,
+ KEY_TYPE,
+ SURI_BOB,
+ key_pair_bob.public().as_ref(),
+ )
+ .expect("Inserts unknown key");
+
+ // Insert Charlie's keys
+ const SURI_CHARLIE: &str = "//Charlie";
+ let key_pair_charlie =
+ sr25519::Pair::from_string(SURI_CHARLIE, None).expect("Generates key pair");
+ SyncCryptoStore::insert_unknown(
+ &keystore,
+ KEY_TYPE,
+ SURI_CHARLIE,
+ key_pair_charlie.public().as_ref(),
+ )
+ .expect("Inserts unknown key");
+
+ // Alice's original account => d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d
+ // Alice's tempered account => a51593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d
+ // The first 3 bytes are changed, thus making the account invalid
+ let escrow: AccountId = hex_literal::hex!["a51593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"].into();
+
+ let mut ext = TestExternalities::new_empty();
+ ext.register_extension(KeystoreExt(keystore.into()));
+ ext.execute_with(|| {
+ let submitter = ExecDelivery::select_authority(escrow.clone());
+
+ assert!(submitter.is_err());
});
}
\ No newline at end of file
