Skip to content

Commit

Permalink
fromat
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonAndell committed Nov 1, 2023
1 parent abe833a commit 6cc7551
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 40 deletions.
44 changes: 24 additions & 20 deletions contracts/core-contracts/cw-asset-manager/tests/deposit_test.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
mod setup;
use cosmwasm_std::{Addr, Uint128};
use cw_common::{x_call_msg::XCallMsg as XCallExecuteMsg, asset_manager_msg::ExecuteMsg};
use cw_common::{asset_manager_msg::ExecuteMsg, x_call_msg::XCallMsg as XCallExecuteMsg};
use cw_ibc_rlp_lib::rlp::RlpStream;
use cw_multi_test::Executor;
use cw_xcall_lib::network_address::NetId;

use crate::setup::{
execute_config_x_call, instantiate_contracts, set_default_connection, setup_context,
TestContext, get_event,
execute_config_x_call, get_event, instantiate_contracts, set_default_connection, setup_context,
TestContext,
};
use cw20::{Cw20Contract, Cw20ExecuteMsg};

Expand Down Expand Up @@ -85,7 +85,6 @@ fn test_deposit_expected_for_revert() {
assert_eq!(Uint128::new(100), bl);
}


#[test]
fn test_deposit_revert() {
let mut context = setup_context();
Expand All @@ -96,11 +95,10 @@ fn test_deposit_revert() {
let xcall_connection = context.get_xcall_connection();
context = set_default_connection(context, xcall_connection.clone());


let (mut ctx, _allowance) = increase_allowance(context, Uint128::new(1000));
let user = ctx.sender.clone();

let initial_balance = check_balance(&ctx, &spoke_addr, &user);
let initial_balance = check_balance(&ctx, &spoke_addr, &user);

let deposit_msg = ExecuteMsg::Deposit {
token_address: spoke_addr.to_string(),
Expand All @@ -111,7 +109,13 @@ fn test_deposit_revert() {

let response = ctx
.app
.execute_contract(ctx.sender.clone(), ctx.get_asset_manager_app(), &deposit_msg, &[]).unwrap();
.execute_contract(
ctx.sender.clone(),
ctx.get_asset_manager_app(),
&deposit_msg,
&[],
)
.unwrap();

let event = get_event(&response, "wasm-CallMessageSent").unwrap();
let sequence_no = event.get("sn").unwrap();
Expand All @@ -134,29 +138,29 @@ fn test_deposit_revert() {

let data = stream.out().to_vec();

ctx.app.execute_contract(
xcall_connection.clone(),
ctx.get_xcall_app(),
&XCallExecuteMsg::HandleMessage {
from: NetId::from("icon".to_owned()),
msg: data,
},
&[],
).unwrap();
ctx.app
.execute_contract(
xcall_connection.clone(),
ctx.get_xcall_app(),
&XCallExecuteMsg::HandleMessage {
from: NetId::from("icon".to_owned()),
msg: data,
},
&[],
)
.unwrap();

ctx
.app
ctx.app
.execute_contract(
user.clone(),
ctx.get_xcall_app(),
&XCallExecuteMsg::ExecuteRollback {
sequence_no: sequence_no.parse::<u128>().unwrap()
sequence_no: sequence_no.parse::<u128>().unwrap(),
},
&[],
)
.unwrap();


let bl = check_balance(&ctx, &spoke_addr, &user);
assert_eq!(initial_balance, bl);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn cw20_flow_test() {
assert!(resp.is_err()); //cannot mint tokens from hubtoken app

//use loop to mint tokens from xcall app to alice, bob and carol
vec![alice.to_string(), bob.to_string(), carol.to_string()]
[alice.to_string(), bob.to_string(), carol.to_string()]
.iter()
.for_each(|recipient| {
let _resp = context
Expand All @@ -52,7 +52,7 @@ fn cw20_flow_test() {
});

//check balance of each account, and assert this to be 1000
vec![
[
(alice.to_string(), amount),
(bob.to_string(), amount),
(carol.to_string(), amount),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
mod setup;
use std::str::FromStr;

use cw_common::{x_call_msg::XCallMsg as XCallExecuteMsg, hub_token_msg::ExecuteMsg};
use cw_multi_test::{Executor, AppResponse};
use cw_common::{hub_token_msg::ExecuteMsg, x_call_msg::XCallMsg as XCallExecuteMsg};
use cw_multi_test::Executor;

use cosmwasm_std::{Addr, Uint128};
use cw_common::{data_types::CrossTransfer, network_address::NetworkAddress};

use crate::setup::{execute_setup, instantiate_contracts, mint_token, call_set_xcall_host};
use crate::setup::{call_set_xcall_host, execute_setup, instantiate_contracts, mint_token};
use cw20::BalanceResponse;
use cw20_base::msg::QueryMsg;
use cw_common::network_address::NetId;
Expand Down Expand Up @@ -163,7 +163,7 @@ pub fn cross_transfer_revert_data_test() {
user.clone(),
context.get_hubtoken_app(),
&ExecuteMsg::CrossTransfer {
to: to,
to,
amount: amount.into(),
data: vec![],
},
Expand All @@ -175,7 +175,7 @@ pub fn cross_transfer_revert_data_test() {
let sequence_no = event.get("sn").unwrap();

let balance = balance_of(&context, user.clone());
let expected_balance = Uint128::from(initial_balance - amount);
let expected_balance = (initial_balance - amount);
assert_eq!(balance.balance, expected_balance);

let message_type: u64 = 2;
Expand All @@ -193,29 +193,32 @@ pub fn cross_transfer_revert_data_test() {

let data = stream.out().to_vec();

context.app.execute_contract(
x_call_connection.clone(),
context.get_xcall_app(),
&XCallExecuteMsg::HandleMessage {
from: NetId::from("icon".to_owned()),
msg: data,
},
&[],
).unwrap();
context
.app
.execute_contract(
x_call_connection.clone(),
context.get_xcall_app(),
&XCallExecuteMsg::HandleMessage {
from: NetId::from("icon".to_owned()),
msg: data,
},
&[],
)
.unwrap();

context
.app
.execute_contract(
user.clone(),
context.get_xcall_app(),
&XCallExecuteMsg::ExecuteRollback {
sequence_no: sequence_no.parse::<u128>().unwrap()
sequence_no: sequence_no.parse::<u128>().unwrap(),
},
&[],
)
.unwrap();

let balance = balance_of(&context, user.clone());
println!("{:?}", balance.balance);
assert_eq!(balance.balance, initial_balance);
let balance = balance_of(&context, user.clone());
println!("{:?}", balance.balance);
assert_eq!(balance.balance, initial_balance);
}

0 comments on commit 6cc7551

Please sign in to comment.