Skip to content

Commit

Permalink
chore: finish migration
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrobot committed Oct 31, 2024
1 parent 255467f commit 37ad16a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
11 changes: 0 additions & 11 deletions contracts/swap/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ pub fn estimate_swap_result(
current_swap.amount = swap_estimate.result_quantity;
current_swap.denom = swap_estimate.result_denom;

deps.api.debug(&format!("step: {:?}", step));
deps.api.debug(&format!("current_swap: {:?}", current_swap));

let step_fee = swap_estimate.fee_estimate.expect("fee estimate should be available");

fees.push(step_fee);
Expand Down Expand Up @@ -185,9 +182,6 @@ fn estimate_execution_buy_from_source(
)));
}

deps.api.debug(&format!("average_price: {average_price}"));
deps.api.debug(&format!("result_quantity: {result_quantity}"));

Ok(StepExecutionEstimate {
worst_price,
result_quantity,
Expand Down Expand Up @@ -305,15 +299,10 @@ fn estimate_execution_sell_from_source(
let average_price = get_average_price_from_orders(&top_orders, market.min_price_tick_size, false);
let worst_price = get_worst_price_from_orders(&top_orders);

deps.api.debug(&format!("average_price: {average_price}"));
deps.api.debug(&format!("input_base_quantity: {input_base_quantity}"));

let expected_exchange_quantity = input_base_quantity * average_price;
let fee_estimate = expected_exchange_quantity * fee_percent;
let expected_quantity = expected_exchange_quantity - fee_estimate;

deps.api.debug(&format!("input_base_quantity: {expected_exchange_quantity}"));

Ok(StepExecutionEstimate {
worst_price,
result_quantity: expected_quantity,
Expand Down
24 changes: 12 additions & 12 deletions contracts/swap/src/testing/migration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use injective_std::types::cosmwasm::wasm::v1::{MsgMigrateContract, MsgMigrateCon
use injective_test_tube::{Account, ExecuteResponse, InjectiveTestApp, Module, Runner, Wasm};
use injective_testing::test_tube::utils::store_code;

type V100InstantiateMsg = InstantiateMsg;
type V101InstantiateMsg = InstantiateMsg;

#[test]
#[cfg_attr(not(feature = "integration"), ignore)]
Expand All @@ -31,12 +31,12 @@ fn test_migration() {
],
);

let swap_v100_code_id = wasm.store_code(&wasm_byte_code, None, &owner).unwrap().data.code_id;
let swap_v101_code_id = wasm.store_code(&wasm_byte_code, None, &owner).unwrap().data.code_id;

let swap_v100_address: String = wasm
let swap_v101_address: String = wasm
.instantiate(
swap_v100_code_id,
&V100InstantiateMsg {
swap_v101_code_id,
&V101InstantiateMsg {
admin: Addr::unchecked(owner.address()),
fee_recipient: FeeRecipient::SwapContract,
},
Expand All @@ -53,14 +53,14 @@ fn test_migration() {
.query(
"/cosmwasm.wasm.v1.Query/ContractInfo",
&QueryContractInfoRequest {
address: swap_v100_address.clone(),
address: swap_v101_address.clone(),
},
)
.unwrap();
let contract_info = res.contract_info.unwrap();

assert_eq!(res.address, swap_v100_address);
assert_eq!(contract_info.code_id, swap_v100_code_id);
assert_eq!(res.address, swap_v101_address);
assert_eq!(contract_info.code_id, swap_v101_code_id);
assert_eq!(contract_info.creator, owner.address());
assert_eq!(contract_info.label, "swap-contract");

Expand All @@ -70,7 +70,7 @@ fn test_migration() {
.execute(
MsgMigrateContract {
sender: owner.address(),
contract: swap_v100_address.clone(),
contract: swap_v101_address.clone(),
code_id: swap_v110_code_id,
msg: serde_json_wasm::to_vec(&MigrateMsg {}).unwrap(),
},
Expand All @@ -83,17 +83,17 @@ fn test_migration() {
.query(
"/cosmwasm.wasm.v1.Query/ContractInfo",
&QueryContractInfoRequest {
address: swap_v100_address.clone(),
address: swap_v101_address.clone(),
},
)
.unwrap();

let contract_info = res.contract_info.unwrap();

assert_eq!(res.address, swap_v100_address);
assert_eq!(res.address, swap_v101_address);
assert_eq!(contract_info.code_id, swap_v110_code_id);
assert_eq!(contract_info.creator, owner.address());
assert_eq!(contract_info.label, "swap-contract");

happy_path_two_hops_test(app, owner, swap_v100_address);
happy_path_two_hops_test(app, owner, swap_v101_address);
}
Binary file not shown.
Binary file not shown.

0 comments on commit 37ad16a

Please sign in to comment.