Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
b-yap committed Oct 13, 2023
1 parent 22b06e3 commit c388cd8
Showing 1 changed file with 14 additions and 58 deletions.
72 changes: 14 additions & 58 deletions pallets/clients-info/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
mock::{run_test, ClientsInfo, RuntimeOrigin, Test, TestError},
pallet::{AuthorizedAccounts, CurrentClientReleases, PendingClientReleases},
upgrade_client_releases::try_upgrade_current_client_releases,
ClientRelease,
ClientRelease, UriOf,
};
use frame_support::{assert_err, BoundedVec};
use sp_runtime::testing::H256;
Expand Down Expand Up @@ -62,7 +62,6 @@ fn test_client_pending_release_migration() {
});
}

#[cfg(test)]
#[test]
fn authorize_account_should_work() {
run_test(|| {
Expand Down Expand Up @@ -140,63 +139,20 @@ fn test_errors() {
#[test]
fn test_decode_bounded_vec() {
run_test(|| {
let key = vec![0; 255];
let key = BoundedVec::try_from(b"vault".to_vec()).expect("should be able to convert");

CurrentClientReleases::<Test>::insert(
key.clone(),
ClientRelease { uri: vec![1; 255], checksum: H256::default() },
);
let uri_vec = b"http:://localhost:8080".to_vec();
let uri: UriOf<Test> =
BoundedVec::try_from(uri_vec.clone()).expect("should be able to convert");

let client_release =
crate::CurrentClientReleases::<Test>::get(BoundedVec::try_from(key).unwrap());
assert_eq!(client_release.map(|c| c.uri.to_vec()), Some(vec![1; 255]));
});
use crate::{
mock::*,
pallet::{CurrentClientReleases, PendingClientReleases},
upgrade_client_releases::*,
ClientRelease, UriOf,
};
use frame_support::BoundedVec;
use sp_core::H256;
use sp_std::vec;
let checksum: <Test as frame_system::Config>::Hash = H256::default();

#[cfg(test)]
run_test(|| {
let vault_key = b"vault".to_vec();
let pre_migration_pending_releases: HashMap<_, _> = vec![(
vault_key.clone(),
ClientRelease {
uri: BoundedVec::try_from(b"https://github.com/pendulum-chain/spacewalk".to_vec())
.unwrap(),
checksum: H256::default(),
},
)]
.into_iter()
.collect();
pre_migration_pending_releases.iter().for_each(|(key, value)| {
PendingClientReleases::<Test>::insert(
BoundedVec::try_from(key.clone()).unwrap(),
value.clone(),
);
});
let pre_migration_current_releases: HashMap<_, _> = vec![(
vault_key.clone(),
ClientRelease {
uri: BoundedVec::try_from(b"https://github.com/pendulum-chain/spacewalk".to_vec())
.unwrap(),
checksum: H256::default(),
},
)]
.into_iter()
.collect();
pre_migration_current_releases.iter().for_each(|(key, value)| {
CurrentClientReleases::<Test>::insert(
BoundedVec::try_from(key.clone()).unwrap(),
value.clone(),
);
});
try_upgrade_current_client_releases::<Test>();
let pending_releases = PendingClientReleases::<Test>::iter_values().collect::<Vec<_>>();
assert_eq!(pending_releases.is_empty(), true);
let client_release: ClientRelease<UriOf<Test>, <Test as frame_system::Config>::Hash> =
ClientRelease { uri, checksum };

CurrentClientReleases::<Test>::insert(key.clone(), client_release);

let client_release = CurrentClientReleases::<Test>::get(key.clone());
assert_eq!(client_release.map(|c| c.uri.to_vec()), Some(uri_vec));
});
}

0 comments on commit c388cd8

Please sign in to comment.