Skip to content

Commit

Permalink
factory can migrate outpost
Browse files Browse the repository at this point in the history
  • Loading branch information
BiPhan4 committed Oct 10, 2024
1 parent 46bf7e5 commit e6dd900
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -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
Binary file modified artifacts/outpost_factory.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions cross-contract/contracts/outpost-factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
39 changes: 39 additions & 0 deletions cross-contract/contracts/outpost-factory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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};

Expand Down Expand Up @@ -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<Response, ContractError> {
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::<u64>().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 {
Expand Down
5 changes: 5 additions & 0 deletions cross-contract/contracts/outpost-factory/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
2 changes: 2 additions & 0 deletions e2e/interchaintest/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions e2e/interchaintest/logs/test.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
INFO: 2024/10/10 12:33:54 contract Info is: address:"wasm1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqhs9hr8" contract_info:<code_id:2 creator:"wasm13w0fse6k9tvrq6zn68smdl6ln4s7kmh9fvq8ag" admin:"wasm13w0fse6k9tvrq6zn68smdl6ln4s7kmh9fvq8ag" label:"wasm-contract" created:<block_height:53 > ibc_port_id:"wasm.wasm1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqhs9hr8" >
INFO: 2024/10/10 12:33:58 outpostContractInfo is: address:"wasm1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrss5maay" contract_info:<code_id:1 creator:"wasm1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqhs9hr8" admin:"wasm1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqhs9hr8" label:"storage_outpost-owned by: wasm13w0fse6k9tvrq6zn68smdl6ln4s7kmh9fvq8ag" created:<block_height:55 > ibc_port_id:"wasm.wasm1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrss5maay" >
INFO: 2024/10/10 15:04:39 contract Info is: address:"wasm1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqhs9hr8" contract_info:<code_id:2 creator:"wasm13w0fse6k9tvrq6zn68smdl6ln4s7kmh9fvq8ag" admin:"wasm13w0fse6k9tvrq6zn68smdl6ln4s7kmh9fvq8ag" label:"wasm-contract" created:<block_height:55 > ibc_port_id:"wasm.wasm1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqhs9hr8" >
INFO: 2024/10/10 15:04:43 outpostContractInfo is: address:"wasm1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrss5maay" contract_info:<code_id:1 creator:"wasm1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqhs9hr8" admin:"wasm1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqhs9hr8" label:"storage_outpost-owned by: wasm13w0fse6k9tvrq6zn68smdl6ln4s7kmh9fvq8ag" created:<block_height:57 > ibc_port_id:"wasm.wasm1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrss5maay" >

0 comments on commit e6dd900

Please sign in to comment.