Skip to content

Commit

Permalink
Add test for why identity hash does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpolaczyk committed Jan 15, 2024
1 parent ba5f597 commit 2a8602d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pallets/relay-storage-roots/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
//!
//! This pallet stores the latest `MaxStorageRoots` relay storage roots, which can be used to
//! verify state proofs against an old state of the relay chain.
//!
//!
//! This is useful when the proof needs to be generated by an end user, because
//! by the time their transaction is included in a block, the latest relay
//! block will probably have changed and therefore the proof will be invalid.
//! To avoid that, we expect the user to generate a proof against the latest relay block stored
//! in this pallet. This proof will then be valid as long as that relay block is not removed from
//! here.
//!
//!
//! This pallet SHOULD NOT be used for data that can change quickly, because we allow the user to
//! submit a proof of an old state. Therefore a valid proof does not imply that the current relay
//! state is the expected one.
Expand Down
27 changes: 27 additions & 0 deletions pallets/relay-storage-roots/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,30 @@ fn oldest_items_are_removed_first() {
assert!(RelayStorageRoot::<Test>::get(0).is_none());
});
}

#[test]
fn little_endian_keys_are_handled_properly() {
ExtBuilder::default()
.with_balances(vec![(ALICE, 15)])
.build()
.execute_with(|| {
// If the keys were stored in little endian, 256 would be removed right after being
// inserted
for i in 250..260 {
let relay_state = RelayChainState {
number: i,
state_root: H256::default(),
};
set_current_relay_chain_state(relay_state);
Pallet::<Test>::set_relay_storage_root();
}

// Only the first item has been removed
let keys = RelayStorageRootKeys::<Test>::get();
assert_eq!(
u32::try_from(keys.len()).unwrap(),
<Test as Config>::MaxStorageRoots::get()
);
assert_eq!(keys, vec![256, 257, 258, 259]);
});
}

0 comments on commit 2a8602d

Please sign in to comment.