diff --git a/Cargo.lock b/Cargo.lock index 2f3461c..4de9fe0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -982,6 +982,7 @@ dependencies = [ "schemars", "serde", "serde-json-wasm 0.5.2", + "serde_json", "storage-outpost", "thiserror", ] @@ -1461,11 +1462,12 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.117" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] diff --git a/artifacts/checksums.txt b/artifacts/checksums.txt index 59ff7ed..bc78652 100644 --- a/artifacts/checksums.txt +++ b/artifacts/checksums.txt @@ -1,5 +1,5 @@ 08b584909077b9fe1a523f20bb2cdc574326a668f2bb1cc48567a4fba0e48069 basic_migration.wasm 894fda7fbfa805761ca6af408d20c148fa59ce0f9999d9c5909bfa8976a8943f basic_migration_v2.wasm -32cbb5537353750902d7f1c2067513034863ae0624004701ea5899ae19677f7b outpost_factory.wasm +8efb48c81f0c0d5c1e6069c18cc30c6d3a9c6be39bbeb4a2dd570e74352d1485 outpost_factory.wasm 2f0770fc02069a2c2034c5e27e57c10558ecd566fe2e7dfa0e549dc62440cf43 outpost_user.wasm 620e109649e140cc2950e18ec676198e48f112ff04c6d5b22cfa75218ccca629 storage_outpost.wasm diff --git a/artifacts/outpost_factory.wasm b/artifacts/outpost_factory.wasm index ee9d6aa..2abeacd 100644 Binary files a/artifacts/outpost_factory.wasm and b/artifacts/outpost_factory.wasm differ diff --git a/cross-contract/contracts/outpost-factory/Cargo.toml b/cross-contract/contracts/outpost-factory/Cargo.toml index 9f80096..45d90cb 100644 --- a/cross-contract/contracts/outpost-factory/Cargo.toml +++ b/cross-contract/contracts/outpost-factory/Cargo.toml @@ -52,6 +52,7 @@ cw-ica-controller = { version = "0.4.2", default-features = false} # The ica_cal schemars = "0.8.10" serde = { version = "1.0.145", default-features = false, features = ["derive"] } serde-json-wasm = "0.5.1" +serde_json = "1.0.128" thiserror = { version = "1.0.31" } [dev-dependencies] diff --git a/cross-contract/contracts/outpost-factory/src/contract.rs b/cross-contract/contracts/outpost-factory/src/contract.rs index f8c1738..0404dc6 100644 --- a/cross-contract/contracts/outpost-factory/src/contract.rs +++ b/cross-contract/contracts/outpost-factory/src/contract.rs @@ -45,6 +45,7 @@ pub fn execute( channel_open_init_options, } => execute::create_outpost(deps, env, info, channel_open_init_options), ExecuteMsg::MapUserOutpost { outpost_owner} => execute::map_user_outpost(deps, env, info, outpost_owner), + ExecuteMsg::MigrateOutpost { outpost_owner, new_outpost_code_id } => execute::migrate_outpost(deps, env, info, outpost_owner, new_outpost_code_id), } } #[cfg_attr(not(feature = "library"), entry_point)] @@ -59,12 +60,14 @@ mod execute { use cosmwasm_std::{Addr, BankMsg, Coin, CosmosMsg, Uint128, Event, to_json_binary}; use storage_outpost::outpost_helpers::StorageOutpostContract; use storage_outpost::types::msg::ExecuteMsg as IcaControllerExecuteMsg; + use storage_outpost::types::msg::MigrateMsg; use storage_outpost::types::state::{CallbackCounter, ChannelState /*ChannelStatus*/}; use storage_outpost::{ outpost_helpers::StorageOutpostCode, types::msg::options::ChannelOpenInitOptions, }; use storage_outpost::types::callback::Callback; + use serde_json_wasm::from_str; use crate::state::{self, USER_ADDR_TO_OUTPOST_ADDR, LOCK}; @@ -168,6 +171,42 @@ mod execute { Ok(Response::new().add_event(event)) // this data is not propagated back up to the tx resp of the 'create_outpost' call } + + pub fn migrate_outpost( + deps: DepsMut, + env: Env, + info: MessageInfo, + outpost_owner: String, + new_outpost_code_id: String, + ) -> Result { + let state = STATE.load(deps.storage)?; + // WARNING: This function is called by the user, so we cannot error:unauthorized if info.sender != admin + + // Find the owner's outpost address + let outpost_address = USER_ADDR_TO_OUTPOST_ADDR.load(deps.storage, &outpost_owner)?; + + let error_msg: String = String::from("Outpost contract address is not a valid bech32 address. Conversion back to addr failed"); + + // Call the outpost's helper API + let storage_outpost_code = StorageOutpostContract::new(deps.api.addr_validate(&outpost_address).expect(&error_msg)); + + // // The outpost's migrate entry point is just '{}' + let migrate_msg = MigrateMsg {}; + + let cast_err: String = String::from("Could not cast new outpost code to u64"); + let new_outpost_code_id_u64 = new_outpost_code_id.parse::().expect(&cast_err); + + let cosmos_msg = storage_outpost_code.migrate( + migrate_msg, + new_outpost_code_id_u64, + )?; + + let mut event = Event::new("Migration: success"); + + // TODO: Save the new code ID of the outpost after migration + + Ok(Response::new().add_message(cosmos_msg).add_event(event)) + } } mod query { diff --git a/cross-contract/contracts/outpost-factory/src/msg.rs b/cross-contract/contracts/outpost-factory/src/msg.rs index 90b9f09..e3d4ede 100644 --- a/cross-contract/contracts/outpost-factory/src/msg.rs +++ b/cross-contract/contracts/outpost-factory/src/msg.rs @@ -17,6 +17,11 @@ pub enum ExecuteMsg { // to execute the below function and map the user's address to their owned outpost MapUserOutpost { outpost_owner: String, // this function is called for a specific purpose of updating a map so nothing is optional + }, + // Let's perform a migration with a cross contract call to see how it goes + MigrateOutpost { + outpost_owner: String, // this function is called for a specific purpose of updating a map so nothing is optional + new_outpost_code_id: String, } } diff --git a/e2e/interchaintest/Readme.md b/e2e/interchaintest/Readme.md index 9a68449..4dca086 100644 --- a/e2e/interchaintest/Readme.md +++ b/e2e/interchaintest/Readme.md @@ -10,6 +10,8 @@ The testing commands are: ``` go test -v . -run TestWithFactoryTestSuite -testify.m TestFactoryCreateOutpost -timeout 12h +go test -v . -run TestWithFactoryTestSuite -testify.m TestMasterMigration -timeout 12h + go test -v . -run TestWithContractTestSuite -testify.m TestIcaContractExecutionTestWithFiletree -timeout 12h go test -v . -run TestWithContractTestSuite -testify.m TestIcaContractExecutionTestWithOwnership -timeout 12h diff --git a/e2e/interchaintest/logs/test.log b/e2e/interchaintest/logs/test.log index 1f5a512..b8370bd 100644 --- a/e2e/interchaintest/logs/test.log +++ b/e2e/interchaintest/logs/test.log @@ -1,2 +1,2 @@ -INFO: 2024/10/10 12:33:54 contract Info is: address:"wasm1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqhs9hr8" contract_info: ibc_port_id:"wasm.wasm1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqhs9hr8" > -INFO: 2024/10/10 12:33:58 outpostContractInfo is: address:"wasm1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrss5maay" contract_info: ibc_port_id:"wasm.wasm1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrss5maay" > +INFO: 2024/10/10 15:04:39 contract Info is: address:"wasm1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqhs9hr8" contract_info: ibc_port_id:"wasm.wasm1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqhs9hr8" > +INFO: 2024/10/10 15:04:43 outpostContractInfo is: address:"wasm1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrss5maay" contract_info: ibc_port_id:"wasm.wasm1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrss5maay" >