Unverified Commit 7a44738a authored by Hero Bird's avatar Hero Bird Committed by GitHub

[core] fix unreachable bug in storage2::Stash and add regression test (#425)

parent b302ebcf
Pipeline #94024 failed with stages
in 5 minutes and 16 seconds
...@@ -304,6 +304,7 @@ where ...@@ -304,6 +304,7 @@ where
if prev_vacant == removed_index && next_vacant == removed_index { if prev_vacant == removed_index && next_vacant == removed_index {
// There is no other vacant entry left in the storage stash so // There is no other vacant entry left in the storage stash so
// there is nothing to update. Bail out early. // there is nothing to update. Bail out early.
self.header.last_vacant = self.header.len;
return return
} }
if prev_vacant == next_vacant { if prev_vacant == next_vacant {
......
...@@ -22,6 +22,25 @@ use crate::{ ...@@ -22,6 +22,25 @@ use crate::{
}; };
use ink_primitives::Key; use ink_primitives::Key;
#[test]
fn regression_stash_unreachable_minified() {
// This regression has been discovered in the ERC721 example implementation
// `approved_for_all_works` unit test. The fix was to adjust
// `Stash::remove_vacant_entry` to update `header.last_vacant` if the
// removed index was the last remaining vacant index in the stash.
env::test::run_test::<env::DefaultEnvTypes, _>(|_| {
let mut stash: StorageStash<u32> = StorageStash::new();
stash.put(1);
stash.put(2);
stash.take(0);
stash.put(99);
stash.take(1);
stash.put(99);
Ok(())
})
.unwrap()
}
#[test] #[test]
fn new_works() { fn new_works() {
// `StorageVec::new` // `StorageVec::new`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment