diff --git a/mcs/near/map-cross-chain-service/src/lib.rs b/mcs/near/map-cross-chain-service/src/lib.rs index 379cd9fa..028654fb 100644 --- a/mcs/near/map-cross-chain-service/src/lib.rs +++ b/mcs/near/map-cross-chain-service/src/lib.rs @@ -538,13 +538,13 @@ impl MapCrossChainService { log!("{}{}", TRANSFER_OUT_TYPE, event); } - /// Finish deposit out once the mcs token is burned from MCSToken contract. + /// Finish deposit out once the nep141 token is burned from MCSToken contract or native token is transferred. pub fn finish_deposit_out( &self, event: DepositOutEvent, ) { assert_self(); - assert_eq!(PromiseResult::Successful(vec![]), env::promise_result(0), "burn mcs token failed"); + assert_eq!(PromiseResult::Successful(vec![]), env::promise_result(0), "burn mcs token or call near_deposit() failed"); log!("deposit out: {}", serde_json::to_string(&event).unwrap()); log!("{}{}", DEPOSIT_OUT_TYPE, event); } @@ -585,7 +585,7 @@ impl MapCrossChainService { } #[payable] - pub fn deposit_out_native(&mut self, to: Vec) { + pub fn deposit_out_native(&mut self, to: Vec) -> Promise { self.check_not_paused(PAUSE_DEPOSIT_OUT_NATIVE); self.check_to_account(to.clone(), self.map_chain_id); @@ -607,8 +607,15 @@ impl MapCrossChainService { amount: amount.into(), }; - log!("deposit out: {}", serde_json::to_string(&event).unwrap()); - log!("{}{}", DEPOSIT_OUT_TYPE, event); + ext_wnear_token::ext(self.wrapped_token.parse().unwrap()) + .with_static_gas(NEAR_DEPOSIT_GAS) + .with_attached_deposit(env::attached_deposit()) + .near_deposit() + .then( + Self::ext(env::current_account_id()) + .with_static_gas(FINISH_DEPOSIT_OUT_GAS) + .finish_deposit_out(event) + ) } #[payable] diff --git a/mcs/near/tests/main.rs b/mcs/near/tests/main.rs index 81a1d11f..9cb51fd4 100644 --- a/mcs/near/tests/main.rs +++ b/mcs/near/tests/main.rs @@ -3582,11 +3582,15 @@ async fn test_deposit_out_native() -> anyhow::Result<()> { log!("balance_mcs_0:{}, balance_mcs_1:{}", balance_mcs_0, balance_mcs_1); log!("{}, {}", balance_from_0- balance_from_1, balance_mcs_1 - balance_mcs_0); assert!(balance_from_0 - balance_from_1 > amount); - assert!(balance_mcs_1 - balance_mcs_0 > amount); - assert!((balance_from_0 - balance_from_1 - amount) > (balance_mcs_1 - balance_mcs_0 - amount)); - log!("{}", balance_from_0 - balance_from_1 - amount); - log!("{}", balance_mcs_1 - balance_mcs_0 - amount); + assert!(balance_mcs_1 - balance_mcs_0 < amount); + let balance = wnear + .call(&worker, "ft_balance_of") + .args_json((mcs.id().to_string(), ))? + .view() + .await? + .json::()?; + assert_eq!(amount, balance.0, "wnear balance of mcs contract account == transferred out native token amount"); Ok(()) } @@ -3667,11 +3671,14 @@ async fn test_deposit_out_native_too_small() -> anyhow::Result<()> { log!("balance_mcs_2:{}, balance_mcs_1:{}", balance_mcs_2, balance_mcs_1); log!("{}, {}", balance_from_1- balance_from_2, balance_mcs_2 - balance_mcs_1); assert!(balance_from_1 - balance_from_2 > amount); - assert!(balance_mcs_2 - balance_mcs_1 > amount); - assert!((balance_from_1 - balance_from_2 - amount) > (balance_mcs_2 - balance_mcs_1 - amount)); - log!("{}", balance_from_1 - balance_from_2 - amount); - log!("{}", balance_mcs_2 - balance_mcs_1 - amount); + let balance = wnear + .call(&worker, "ft_balance_of") + .args_json((mcs.id().to_string(), ))? + .view() + .await? + .json::()?; + assert_eq!(amount, balance.0, "wnear balance of mcs contract account == transferred out native token amount"); Ok(()) } @@ -3720,17 +3727,22 @@ async fn test_deposit_out_native_no_deposit() -> anyhow::Result<()> { .await?; assert!(res.is_success(), "deposit_out_native should succeed"); println!("logs: {:?}", res.logs()); - assert!(res.logs().get(1).unwrap().contains(DEPOSIT_OUT_TYPE), "should be deposit out log"); + assert!(res.logs().get(2).unwrap().contains(DEPOSIT_OUT_TYPE), "should be deposit out log"); let balance_from_2 = from.view_account(&worker).await?.balance; let balance_mcs_2 = mcs.view_account(&worker).await?.balance; log!("balance_from_2:{}, balance_from_1:{}", balance_from_2, balance_from_1); log!("balance_mcs_2:{}, balance_mcs_1:{}", balance_mcs_2, balance_mcs_1); log!("{}, {}", balance_from_1- balance_from_2, balance_mcs_2 - balance_mcs_1); assert!(balance_from_1 - balance_from_2 > amount); - assert!(balance_mcs_2 - balance_mcs_1 > amount); - assert!((balance_from_1 - balance_from_2 - amount) > (balance_mcs_2 - balance_mcs_1 - amount)); - log!("{}", balance_from_1 - balance_from_2 - amount); - log!("{}", balance_mcs_2 - balance_mcs_1 - amount); + assert!(balance_mcs_2 - balance_mcs_1 < amount); + + let balance = wnear + .call(&worker, "ft_balance_of") + .args_json((mcs.id().to_string(), ))? + .view() + .await? + .json::()?; + assert_eq!(amount, balance.0, "wnear balance of mcs contract account == transferred out native token amount"); Ok(()) } @@ -4630,7 +4642,7 @@ async fn test_deposit_out_mcs_token_amount_too_large() -> anyhow::Result<()> { .transact() .await; assert!(res.is_err(), "deposit_out_token should failed"); - assert!(res.as_ref().err().unwrap().to_string().contains("burn mcs token failed"), "should be burn mcs token failed error"); + assert!(res.as_ref().err().unwrap().to_string().contains("burn mcs token or call near_deposit() failed"), "should be burn mcs token failed error"); let balance = from .call(&worker, &token_account, "ft_balance_of")