Skip to content

Commit

Permalink
UPdated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kayanski committed Nov 18, 2024
1 parent 5105333 commit 9b7d23b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion framework/contracts/account/src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn migrate(mut deps: DepsMut, env: Env, _msg: MigrateMsg) -> AccountResult {

let current_contract_version = get_contract_version(deps.storage)?;
// If we already have an abstract account, we just migrate like normal
if current_contract_version.contract != "abstract::account" {
if current_contract_version.contract == "abstract::account" {
assert_contract_upgrade(deps.storage, ACCOUNT, version)?;
set_contract_version(deps.storage, ACCOUNT, CONTRACT_VERSION)?;
return Ok(AccountResponse::action("migrate"));
Expand Down
1 change: 1 addition & 0 deletions framework/packages/abstract-client/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ impl<Chain: CwEnv> AbstractClientBuilder<Chain> {
/// Deploy abstract with current configuration
pub fn build(&self) -> AbstractClientResult<AbstractClient<Chain>> {
let abstr = Abstract::deploy_on(self.chain.clone(), ())?;
println!("quid");
self.update_ans(&abstr)?;

AbstractClient::new(self.chain.clone())
Expand Down
2 changes: 2 additions & 0 deletions framework/packages/abstract-interface/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,11 @@ impl<Chain: CwEnv> AccountI<Chain> {
}
sub_account_ids.extend(sub_account_ids_page);
}
println!("Upgrades {:?}", sub_account_ids);
for sub_account_id in sub_account_ids {
let abstract_account =
AccountI::load_from(abstract_deployment, AccountId::local(sub_account_id))?;
println!("{:?}", abstract_account.item_query(cw2::CONTRACT)?);
if abstract_account.upgrade_account(abstract_deployment)? {
one_migration_was_successful = true;
}
Expand Down
1 change: 1 addition & 0 deletions interchain/framework-clone-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ cw-orch-clone-testing = { workspace = true }
abstract-std = { workspace = true }
abstract-app = { workspace = true, features = ["test-utils"] }
abstract-testing = { workspace = true }
abstract-account = { workspace = true }
abstract-client = { workspace = true }
abstract-interface = { workspace = true, features = ["daemon"] }
abstract-integration-tests = { path = "../../framework/packages/abstract-integration-tests" }
Expand Down
6 changes: 3 additions & 3 deletions interchain/framework-clone-testing/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cw_orch_clone_testing::CloneTesting;
/// Returns the abstract deployment and sender (=mainnet admin)
pub fn setup(chain: ChainInfo) -> anyhow::Result<(Abstract<CloneTesting>, CloneTesting)> {
let _ = env_logger::builder().is_test(true).try_init();
// Run migration tests against Juno mainnet
// Run migration tests against mainnet
// We set the state file to be able to clone test
std::env::set_var("STATE_FILE", "../scripts/state.json");
let mut app = CloneTesting::new(chain)?;
Expand All @@ -16,7 +16,7 @@ pub fn setup(chain: ChainInfo) -> anyhow::Result<(Abstract<CloneTesting>, CloneT
.wasm_querier()
.code(abstr_deployment.registry.code_id()?)?
.creator;
app.set_sender(creator);
app.set_sender(creator.clone());

Ok((abstr_deployment, app))
Ok((abstr_deployment.call_as(&creator), app))
}
26 changes: 22 additions & 4 deletions interchain/framework-clone-testing/tests/upgrade-account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use cw_orch::{daemon::networks::PION_1, prelude::*};
use cw_orch_clone_testing::CloneTesting;
use semver::Version;

pub const FORBIDDEN_VERSIONS: &[&str] = &["0.24.1-beta.1"];

fn find_old_account() -> anyhow::Result<(CloneTesting, u32, Addr)> {
let (abstr_deployment, chain) = common::setup(PION_1)?;

Expand All @@ -24,7 +26,13 @@ fn find_old_account() -> anyhow::Result<(CloneTesting, u32, Addr)> {
if let Ok(owner) = account.top_level_owner() {
let ver = account.item_query(cw2::CONTRACT)?;
let account_version = Version::parse(&ver.version)?;

if FORBIDDEN_VERSIONS.iter().any(|&s| {
println!("current account version {}", ver.version);
s == ver.version
}) {
bail!("Can't migrate from this version");
}
println!("Keeping {account_version}");
Ok((account_id, owner.address, account_version))
} else {
bail!("No owner for this account")
Expand All @@ -39,6 +47,7 @@ fn find_old_account() -> anyhow::Result<(CloneTesting, u32, Addr)> {
#[test]
fn upgrade_account_iteratively() -> anyhow::Result<()> {
let (chain, account_id, owner) = find_old_account()?;
println!("Found, {account_id}");

let abstr_deployment = Abstract::load_from(chain.call_as(&owner).clone())?;
let account = AccountI::load_from(&abstr_deployment, AccountId::local(account_id))?;
Expand Down Expand Up @@ -79,13 +88,22 @@ fn upgrade_accounts_and_sub_accounts() -> anyhow::Result<()> {

account.upgrade_account(&abstr_deployment)?;
let info_account = account.item_query(cw2::CONTRACT)?;
assert_eq!(info_account.version, TEST_VERSION);
assert_eq!(
info_account.version,
abstract_account::contract::CONTRACT_VERSION
);

let info_sub_account = sub_account.item_query(cw2::CONTRACT)?;
assert_eq!(info_sub_account.version, TEST_VERSION);
assert_eq!(
info_sub_account.version,
abstract_account::contract::CONTRACT_VERSION
);

let info_sub_sub_account = sub_sub_account.item_query(cw2::CONTRACT)?;
assert_eq!(info_sub_sub_account.version, TEST_VERSION);
assert_eq!(
info_sub_sub_account.version,
abstract_account::contract::CONTRACT_VERSION
);

Ok(())
}

0 comments on commit 9b7d23b

Please sign in to comment.