Skip to content

fix unknown-tokens migration #899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions unknown-tokens/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ orml-xcm-support = { path = "../xcm-support", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" }
hex-literal = "0.3.1"

[features]
default = ["std"]
Expand Down
6 changes: 4 additions & 2 deletions unknown-tokens/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ mod v2 {

weight.saturating_accrue(T::DbWeight::get().reads(1));

let old_data = storage_iter::<u128>(module_prefix, storage_prefix).drain();
let old_data = storage_iter::<u128>(module_prefix, storage_prefix)
.drain()
.collect::<Vec<_>>();

for (raw_k, value) in old_data {
let mut full_key = Vec::new();
Expand Down Expand Up @@ -59,7 +61,7 @@ mod v2 {

let old_data = storage_iter::<u128>(module_prefix, storage_prefix)
.drain()
.collect::<sp_std::vec::Vec<_>>();
.collect::<Vec<_>>();

for (raw_k, value) in old_data {
let mut full_key = Vec::new();
Expand Down
14 changes: 13 additions & 1 deletion unknown-tokens/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use mock::*;

use frame_support::{
assert_err, assert_ok,
storage::migration::{get_storage_value, put_storage_value},
storage::{
migration::{get_storage_value, put_storage_value},
unhashed::put_raw,
},
traits::OnRuntimeUpgrade,
};

Expand Down Expand Up @@ -250,3 +253,12 @@ fn from_unversioned_to_v2_storage() {
assert_eq!(crate::Migration::<Runtime>::on_runtime_upgrade(), Weight::zero());
});
}

#[test]
fn migrate_should_not_panic() {
ExtBuilder.build().execute_with(|| {
put_raw(&hex_literal::hex!["8d4649c9ee31ba6b2d10c66f5fcc252e76391a415c3fca956dccff701fe02e98082b3a7e1c0db7de23c07c6f14cc6c51000100411f728d113b5f9fee983dba4cbb22827c05000106080081"], &hex_literal::hex!["0b2493d4010000000000000000000000"]);

crate::Migration::<Runtime>::on_runtime_upgrade();
});
}