Skip to content

Instantly share code, notes, and snippets.

@Art3miX
Last active February 7, 2023 11:09
Show Gist options
  • Select an option

  • Save Art3miX/10cfaa620780e988251acf71155d2092 to your computer and use it in GitHub Desktop.

Select an option

Save Art3miX/10cfaa620780e988251acf71155d2092 to your computer and use it in GitHub Desktop.
Easy way to update your storage manually in cw-multi-test.
// Long story short, IBC is not support with cw_multi_test, and I have a storage that is updaing based on some IBC call
// Because I can't mock the IBC call, I had to update the storage manually, heres a little helper to do so.
pub fn update_storage(app: &mut App, address: &[u8], function: &mut dyn FnMut(&mut PrefixedStorage)) {
app.init_modules(|_, _, storage| {
let mut namespace = b"contract_data/".to_vec();
namespace.extend_from_slice(address);
let mut prefixed_storage = PrefixedStorage::multilevel(storage, &[b"wasm", &namespace]);
function(&mut prefixed_storage);
})
}
// Basically we do init_modules in app to get the main storage, then we build the prefixedStorage with the correct namespace
// based on the contract address, and we run the provided function with the contract specific storage.
// Here is a simple usage:
pub const DATA: Map<&str, String> = Map::new("some_mock_storage");
pub address = Addr::unchecked("some_address");
pub app = AppBuilder::new().build(|_, _, _| {});
update_storage(&mut app, address.as_bytes(), &mut |storage| {
DATA.save(storage, "some_str", "some_string").unwrap();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment