Skip to content

Commit

Permalink
chore: Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
kulikthebird committed Aug 28, 2024
1 parent 0d2ebb6 commit 2626432
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions packages/vm/src/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ where
Q: Querier + 'static,
{
instance.set_storage_readonly(false);
// TODO tkulik: Add test for a conditional migrate call
call_raw(
instance,
"migrate",
Expand Down Expand Up @@ -738,7 +737,7 @@ mod tests {
use crate::testing::{
mock_env, mock_info, mock_instance, mock_instance_with_options, MockInstanceOptions,
};
use cosmwasm_std::{coins, from_json, to_json_string, Empty};
use cosmwasm_std::{coins, from_json, to_json_string, Addr, Empty};
use sha2::{Digest, Sha256};

static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
Expand Down Expand Up @@ -898,6 +897,45 @@ mod tests {
);
}

#[test]
fn call_migrate_with_info_works() {
let mut instance = mock_instance(CONTRACT, &[]);

// init
let info = mock_info(&instance.api().addr_make("creator"), &coins(1000, "earth"));
let verifier = instance.api().addr_make("verifies");
let beneficiary = instance.api().addr_make("benefits");
let msg = format!(r#"{{"verifier": "{verifier}", "beneficiary": "{beneficiary}"}}"#);
call_instantiate::<_, _, _, Empty>(&mut instance, &mock_env(), &info, msg.as_bytes())
.unwrap()
.unwrap();

// change the verifier via migrate
let someone_else = instance.api().addr_make("someone else");
let msg = format!(r#"{{"verifier": "{someone_else}"}}"#);
let migrate_info = MigrateInfo {
sender: Addr::unchecked(someone_else.clone()),
old_migrate_version: Some(33),
};
let _res = call_migrate_with_info::<_, _, _, Empty>(
&mut instance,
&mock_env(),
msg.as_bytes(),
&migrate_info,
)
.unwrap()
.unwrap();

// query the new_verifier with verifier
let msg = br#"{"verifier":{}}"#;
let contract_result = call_query(&mut instance, &mock_env(), msg).unwrap();
let query_response = contract_result.unwrap();
assert_eq!(
query_response,
format!(r#"{{"verifier":"{}"}}"#, someone_else).as_bytes(),
);
}

#[test]
fn call_query_works() {
let mut instance = mock_instance(CONTRACT, &[]);
Expand Down

0 comments on commit 2626432

Please sign in to comment.