diff --git a/README.md b/README.md index bed8103..8e3f4b0 100644 --- a/README.md +++ b/README.md @@ -119,18 +119,15 @@ open tarpaulin-report.html ``` || Uncovered Lines: -|| contracts/fiberrouter-base/src/contract.rs: 17, 23, 25-26, 28-29, 40, 46-49, 51, 53-58, 60-64, 66-71, 76, 80-81, 84-85, 88-89, 92-93, 95-96, 99-101, 104-105, 108-109, 112-113, 115-116, 119, 127-129, 132, 134-140, 142, 145-146, 148-151, 154, 162-164, 166, 168-174, 176, 179-180, 182-187, 191-194, 198-200, 203-205, 209-210 -|| contracts/fundmanager-base/src/contract.rs: 45, 51-54, 56-61, 63-64, 66-67, 70-75, 77-81, 83-88, 102, 128, 152, 179, 204, 229, 255, 261, 264, 267, 277-279, 311, 331, 353, 373, 378, 427, 430, 453, 473, 476, 479, 533-536, 538-539, 541-543, 545-546, 548, 557-561, 571, 574, 579, 590, 595-599, 605, 611-613, 615-620, 626-633, 653, 674, 677, 683-684, 686-691, 693, 695, 706-707 -|| packages/fiberrouter/src/event.rs: 11-14, 25-28 -|| packages/fundmanager/src/helpers.rs: 14-15, 18, 23-27, 29 -|| packages/fundmanager/src/query.rs: 39-43 +|| contracts/fiberrouter-base/src/contract.rs: 48 +|| contracts/fundmanager-base/src/contract.rs: 623, 662 || Tested/Total Lines: -|| contracts/fiberrouter-base/src/contract.rs: 0/103 +0.00% -|| contracts/fundmanager-base/src/contract.rs: 253/368 +0.00% -|| packages/fiberrouter/src/event.rs: 0/8 +0.00% -|| packages/fundmanager/src/event.rs: 54/54 +0.00% -|| packages/fundmanager/src/helpers.rs: 0/9 +0.00% -|| packages/fundmanager/src/query.rs: 0/5 +0.00% +|| contracts/fiberrouter-base/src/contract.rs: 91/92 +20.65% +|| contracts/fundmanager-base/src/contract.rs: 337/339 +0.00% +|| packages/fiberrouter/src/event.rs: 8/8 +0.00% +|| packages/fundmanager/src/event.rs: 55/55 +0.00% +|| packages/fundmanager/src/helpers.rs: 9/9 +0.00% +|| packages/fundmanager/src/query.rs: 5/5 +0.00% || -56.12% coverage, 307/547 lines covered, +0.00% change in coverage +99.41% coverage, 505/508 lines covered, +3.74% change in coverage ``` diff --git a/contracts/fiberrouter-base/src/contract.rs b/contracts/fiberrouter-base/src/contract.rs index 74bd4a8..417650a 100644 --- a/contracts/fiberrouter-base/src/contract.rs +++ b/contracts/fiberrouter-base/src/contract.rs @@ -188,3 +188,404 @@ pub fn query_pool(deps: Deps) -> StdResult { pub fn migrate(_: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { Ok(Response::default()) } + +#[cfg(test)] +mod test { + use cosmwasm_std::{ + attr, from_binary, to_binary, BalanceResponse, BankQuery, QueryRequest, Response, Uint128, + }; + + use fiberrouter::{FiberRouterExecuteMsg, FiberRouterQueryMsg, MigrateMsg}; + + use crate::error::ContractError; + use crate::msg::InstantiateMsg; + use crate::state::OWNER; + + use crate::contract::{ + execute, execute_ownership_transfer, execute_set_pool, execute_swap, + execute_withdraw_signed, instantiate, migrate, query, query_owner, query_pool, ExecuteEnv, + }; + + use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info, MOCK_CONTRACT_ADDR}; + + #[test] + fn test_initialization() { + let owner = "address_to_be_owner"; + let pool = "address_to_be_pool"; + let deployer = "some_address"; + + let mut deps = mock_dependencies(); + let env = mock_env(); + let info = mock_info(deployer, &[]); + let msg = InstantiateMsg { + owner: owner.to_string(), + pool: pool.to_string(), + }; + + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); + + assert_eq!(query_owner(deps.as_ref()).unwrap(), owner.to_string()); + assert_eq!(OWNER.load(&deps.storage).unwrap(), owner.to_string()); + assert_eq!(query_pool(deps.as_ref()).unwrap(), pool.to_string()); + } + + #[test] + fn test_ownership_transfer() { + let mut deps = mock_dependencies(); + let msg = InstantiateMsg { + owner: "cudos167mthp8jzz40f2vjz6m8x2m77lkcnp7nxsk5ym".to_string(), + pool: "cudos167mthp8jzz40f2vjz6m8x2m77lkcnp7nxsk5ym".to_string(), + }; + let env = mock_env(); + let info = mock_info("cudos167mthp8jzz40f2vjz6m8x2m77lkcnp7nxsk5ym", &[]); + instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); + + let eenv = ExecuteEnv { + deps: deps.as_mut(), + info: info.clone(), + }; + execute_ownership_transfer( + eenv, + "cudos1qu6xuvc3jy2m5wuk9nzvh4z57teq8j3p3q6huh".to_string(), + ) + .unwrap(); + let owner = query_owner(deps.as_ref()).unwrap(); + assert_eq!( + "cudos1qu6xuvc3jy2m5wuk9nzvh4z57teq8j3p3q6huh".to_string(), + owner + ); + } + + #[test] + fn test_execute_ownership_transfer_catch_err_unauthorized() { + let first_owner = "address_to_be_first_owner"; + let second_owner = "address_to_be_second_owner"; + let pool = "address_to_be_pool"; + + let mut deps = mock_dependencies(); + let env = mock_env(); + let info = mock_info(first_owner, &[]); + let msg = InstantiateMsg { + owner: first_owner.to_string(), + pool: pool.to_string(), + }; + + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); + + let execute_env = ExecuteEnv { + deps: deps.as_mut(), + info: mock_info("other_address", &[]), + }; + + assert_eq!( + execute_ownership_transfer(execute_env, second_owner.to_string()) + .unwrap_err() + .to_string(), + (ContractError::Unauthorized {}).to_string() + ); + } + + #[test] + fn test_set_pool() { + let mut deps = mock_dependencies(); + let msg = InstantiateMsg { + owner: "cudos167mthp8jzz40f2vjz6m8x2m77lkcnp7nxsk5ym".to_string(), + pool: "cudos167mthp8jzz40f2vjz6m8x2m77lkcnp7nxsk5ym".to_string(), + }; + let env = mock_env(); + let info = mock_info("cudos167mthp8jzz40f2vjz6m8x2m77lkcnp7nxsk5ym", &[]); + instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); + + let eenv = ExecuteEnv { + deps: deps.as_mut(), + info: info.clone(), + }; + execute_set_pool( + eenv, + "cudos1qu6xuvc3jy2m5wuk9nzvh4z57teq8j3p3q6huh".to_string(), + ) + .unwrap(); + let owner = query_pool(deps.as_ref()).unwrap(); + assert_eq!( + "cudos1qu6xuvc3jy2m5wuk9nzvh4z57teq8j3p3q6huh".to_string(), + owner + ); + } + + #[test] + fn test_execute_set_pool_catch_err_unauthorized() { + let first_owner = "address_to_be_first_owner"; + let pool = "address_to_be_pool"; + let second_pool = "address_to_be_second_pool"; + + let mut deps = mock_dependencies(); + let env = mock_env(); + let info = mock_info(first_owner, &[]); + let msg = InstantiateMsg { + owner: first_owner.to_string(), + pool: pool.to_string(), + }; + + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); + + let execute_env = ExecuteEnv { + deps: deps.as_mut(), + info: mock_info("other_address", &[]), + }; + + assert_eq!( + execute_set_pool(execute_env, second_pool.to_string()) + .unwrap_err() + .to_string(), + (ContractError::Unauthorized {}).to_string() + ); + } + + #[test] + fn test_execute_withdraw_signed() { + let owner = "address_to_be_owner"; + let pool = "address_to_be_pool"; + let mut deps = mock_dependencies(); + let env = mock_env(); + let info = mock_info(owner, &[]); + let msg = InstantiateMsg { + owner: owner.to_string(), + pool: pool.to_string(), + }; + + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); + + ///////////////////////////////////////////////////////////// + + // let signer = "0x8929cbb11fdd5798db5f638a5002235c6412f13f".to_string(); + let token = "token_address".to_string(); + let amount = Uint128::from(1000u128); + let salt = "salt".to_string(); + let signature = + "dada130255a447ecf434a2df9193e6fbba663e4546c35c075cd6eea21d8c7cb1714b9b65a4f7f604ff6aad55fba73f8c36514a512bbbba03709b37069194f8a41b"; + + let execute_env = ExecuteEnv { + deps: deps.as_mut(), + info: mock_info( + MOCK_CONTRACT_ADDR, + &[cosmwasm_std::Coin { + denom: token.clone(), + amount: amount, + }], + ), + }; + + let rsp = execute_withdraw_signed( + execute_env, + owner.to_string(), + token.clone(), + Uint128::from(700u128), + salt.clone(), + signature.to_string(), + ) + .unwrap(); + + assert_eq!( + rsp.attributes, + vec![ + attr("action", "withdraw_signed".to_string()), + attr("payee", owner.to_string()), + attr("token", token.clone()), + attr("amount", Uint128::from(700u128)) + ] + ) + } + + #[test] + fn test_execute_swap() { + let owner = "address_to_be_owner"; + let pool = "address_to_be_pool"; + let mut deps = mock_dependencies(); + let env = mock_env(); + let info = mock_info(owner, &[]); + let msg = InstantiateMsg { + owner: owner.to_string(), + pool: pool.to_string(), + }; + + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); + + ///////////////////////////////////////////////////////////// + + let token = "token_address".to_string(); + let amount = Uint128::from(700u128); + + let execute_env = ExecuteEnv { + deps: deps.as_mut(), + info: mock_info( + owner, + &[cosmwasm_std::Coin { + denom: token.clone(), + amount: amount, + }], + ), + }; + + let rsp = execute_swap( + execute_env, + "137".to_string(), + "token_address_out_chain".to_string(), + "user_address_out_chain".to_string(), + ) + .unwrap(); + + assert_eq!( + rsp.attributes, + vec![ + attr("action", "swap".to_string()), + attr("target_chain_id", "137".to_string()), + attr("target_token", "token_address_out_chain".to_string()), + attr("target_address", "user_address_out_chain".to_string()), + ] + ); + + let res = deps + .querier + .handle_query(&QueryRequest::Bank(BankQuery::Balance { + address: owner.to_string(), + denom: token.clone(), + })) + .unwrap() + .unwrap(); + + let balance: BalanceResponse = from_binary(&res).unwrap(); + assert_eq!(balance.amount.to_string(), "0token_address"); + } + + #[test] + fn test_migrate() { + let owner = "address_to_be_owner"; + let pool = "address_to_be_pool"; + let mut deps = mock_dependencies(); + let env = mock_env(); + let info = mock_info(owner, &[]); + let msg = InstantiateMsg { + owner: owner.to_string(), + pool: pool.to_string(), + }; + + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); + + let rsp = migrate(deps.as_mut(), env.clone(), MigrateMsg {}).unwrap(); + assert_eq!(rsp, Response::default()); + } + + #[test] + fn test_execute_query_multitest() { + let owner = "address_to_be_owner"; + let pool = "address_to_be_pool"; + let mut deps = mock_dependencies(); + let env = mock_env(); + let info = mock_info(owner, &[]); + let msg = InstantiateMsg { + owner: owner.to_string(), + pool: pool.to_string(), + }; + + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); + + ///////////////////////////////////////////////////////////// + + let rsp = execute( + deps.as_mut(), + env.clone(), + info.clone(), + FiberRouterExecuteMsg::TransferOwnership { + new_owner: "address_to_be_owner_2".to_string(), + }, + ) + .unwrap(); + + assert_eq!( + rsp.attributes, + vec![ + attr("action", "transfer_ownership".to_string()), + attr("prev_owner", owner.to_string()), + attr("new_owner", "address_to_be_owner_2".to_string()) + ] + ); + + let token = "token_address".to_string(); + let salt = "salt".to_string(); + let signature = + "dada130255a447ecf434a2df9193e6fbba663e4546c35c075cd6eea21d8c7cb1714b9b65a4f7f604ff6aad55fba73f8c36514a512bbbba03709b37069194f8a41b"; + + let rsp = execute( + deps.as_mut(), + env.clone(), + info.clone(), + FiberRouterExecuteMsg::WithdrawSigned { + payee: owner.to_string(), + token: token.clone(), + amount: Uint128::from(700u128), + salt: salt.clone(), + signature: signature.to_string(), + }, + ) + .unwrap(); + + assert_eq!( + rsp.attributes, + vec![ + attr("action", "withdraw_signed".to_string()), + attr("payee", owner.to_string()), + attr("token", token.clone()), + attr("amount", Uint128::from(700u128)), + ] + ); + + let rsp = execute( + deps.as_mut(), + env.clone(), + mock_info( + owner, + &[cosmwasm_std::Coin { + denom: token.clone(), + amount: Uint128::from(777u128), + }], + ), + FiberRouterExecuteMsg::Swap { + target_chain_id: "137".to_string(), + target_token: "token_address_out_chain".to_string(), + target_address: "user_address_out_chain".to_string(), + }, + ) + .unwrap(); + + assert_eq!( + rsp.attributes, + vec![ + attr("action", "swap".to_string()), + attr("target_chain_id", "137".to_string()), + attr("target_token", "token_address_out_chain".to_string()), + attr("target_address", "user_address_out_chain".to_string()) + ] + ); + + let rsp = query(deps.as_ref(), env.clone(), FiberRouterQueryMsg::Owner {}).unwrap(); + assert_eq!( + rsp.to_string(), + to_binary(&"address_to_be_owner_2".to_string()) + .unwrap() + .to_string() + ); + + let rsp = query(deps.as_ref(), env.clone(), FiberRouterQueryMsg::Pool {}).unwrap(); + assert_eq!( + rsp.to_string(), + to_binary(&pool.to_string()).unwrap().to_string() + ); + } +} diff --git a/contracts/fundmanager-base/src/contract.rs b/contracts/fundmanager-base/src/contract.rs index 401a6fd..73f88c0 100644 --- a/contracts/fundmanager-base/src/contract.rs +++ b/contracts/fundmanager-base/src/contract.rs @@ -679,7 +679,8 @@ pub fn migrate(_: DepsMut, _env: Env, _msg: MigrateMsg) -> Result = query_signers(deps.as_ref(), None, None).unwrap(); assert_eq!(signers.len(), 1); @@ -1213,7 +1226,7 @@ mod test { } #[test] - fn test_execute_add_signer__catch_err_unauthorized() { + fn test_execute_add_signer_catch_err_unauthorized() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -1222,7 +1235,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -1244,7 +1258,7 @@ mod test { } #[test] - fn test_execute_add_signer__catch_err_invalid_ethereum_address() { + fn test_execute_add_signer_catch_err_invalid_ethereum_address() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -1253,7 +1267,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -1281,7 +1296,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -1291,10 +1307,11 @@ mod test { info: info.clone(), }; - execute_add_signer( + let res = execute_add_signer( execute_env, "0x8929cbb11fdd5798db5f638a5002235c6412f13f".to_string(), ); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -1302,10 +1319,11 @@ mod test { info: info.clone(), }; - execute_add_signer( + let res = execute_add_signer( execute_env, "0x8929cbb11fdd5798db5f638a5002235c6412f26a".to_string(), ); + assert_eq!(res.is_err(), false); let signers: Vec = query_signers(deps.as_ref(), None, None).unwrap(); assert_eq!(signers.len(), 2); @@ -1353,7 +1371,7 @@ mod test { } #[test] - fn test_execute_remove_signer__catch_err_unauthorized() { + fn test_execute_remove_signer_catch_err_unauthorized() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -1362,7 +1380,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -1372,10 +1391,11 @@ mod test { info: info.clone(), }; - execute_add_signer( + let res = execute_add_signer( execute_env, "0x8929cbb11fdd5798db5f638a5002235c6412f13f".to_string(), ); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -1383,10 +1403,11 @@ mod test { info: info.clone(), }; - execute_add_signer( + let res = execute_add_signer( execute_env, "0x8929cbb11fdd5798db5f638a5002235c6412f26a".to_string(), ); + assert_eq!(res.is_err(), false); let signers: Vec = query_signers(deps.as_ref(), None, None).unwrap(); assert_eq!(signers.len(), 2); @@ -1418,7 +1439,7 @@ mod test { } #[test] - fn test_execute_remove_signer__catch_err_not_signer() { + fn test_execute_remove_signer_catch_err_not_signer() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -1427,7 +1448,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -1437,10 +1459,11 @@ mod test { info: info.clone(), }; - execute_add_signer( + let res = execute_add_signer( execute_env, "0x8929cbb11fdd5798db5f638a5002235c6412f13f".to_string(), ); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -1448,10 +1471,11 @@ mod test { info: info.clone(), }; - execute_add_signer( + let res = execute_add_signer( execute_env, "0x8929cbb11fdd5798db5f638a5002235c6412f26a".to_string(), ); + assert_eq!(res.is_err(), false); let signers: Vec = query_signers(deps.as_ref(), None, None).unwrap(); assert_eq!(signers.len(), 2); @@ -1492,7 +1516,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -1502,7 +1527,8 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, "token_address".to_string()); + let res = execute_add_foundry_asset(execute_env, "token_address".to_string()); + assert_eq!(res.is_err(), false); assert_eq!( is_foundry_asset(&deps.storage, "token_address".to_string()), true @@ -1536,7 +1562,7 @@ mod test { } #[test] - fn test_execute_add_foundry_asset__catch_err_unauthorized() { + fn test_execute_add_foundry_asset_catch_err_unauthorized() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -1545,7 +1571,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -1564,7 +1591,7 @@ mod test { } #[test] - fn test_execute_add_foundry_asset__catch_err_invalid_token() { + fn test_execute_add_foundry_asset_catch_err_invalid_token() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -1573,7 +1600,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -1601,7 +1629,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -1611,7 +1640,8 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, "token_address".to_string()); + let res = execute_add_foundry_asset(execute_env, "token_address".to_string()); + assert_eq!(res.is_err(), false); assert_eq!( is_foundry_asset(&deps.storage, "token_address".to_string()), true @@ -1623,7 +1653,8 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, "token_address_2".to_string()); + let res = execute_add_foundry_asset(execute_env, "token_address_2".to_string()); + assert_eq!(res.is_err(), false); assert_eq!( is_foundry_asset(&deps.storage, "token_address_2".to_string()), true @@ -1657,7 +1688,7 @@ mod test { } #[test] - fn test_execute_remove_foundry_asset__catch_err_unauthorized() { + fn test_execute_remove_foundry_asset_catch_err_unauthorized() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -1666,7 +1697,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -1676,7 +1708,9 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, "token_address".to_string()); + let res = execute_add_foundry_asset(execute_env, "token_address".to_string()); + assert_eq!(res.is_err(), false); + assert_eq!( is_foundry_asset(&deps.storage, "token_address".to_string()), true @@ -1688,7 +1722,8 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, "token_address_2".to_string()); + let res = execute_add_foundry_asset(execute_env, "token_address_2".to_string()); + assert_eq!(res.is_err(), false); assert_eq!( is_foundry_asset(&deps.storage, "token_address_2".to_string()), true @@ -1709,7 +1744,7 @@ mod test { } #[test] - fn test_execute_remove_foundry_asset__catch_err_invalid_token() { + fn test_execute_remove_foundry_asset_catch_err_invalid_token() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -1718,7 +1753,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -1728,7 +1764,8 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, "token_address".to_string()); + let res = execute_add_foundry_asset(execute_env, "token_address".to_string()); + assert_eq!(res.is_err(), false); assert_eq!( is_foundry_asset(&deps.storage, "token_address".to_string()), true @@ -1740,7 +1777,8 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, "token_address_2".to_string()); + let res = execute_add_foundry_asset(execute_env, "token_address_2".to_string()); + assert_eq!(res.is_err(), false); assert_eq!( is_foundry_asset(&deps.storage, "token_address_2".to_string()), true @@ -1761,7 +1799,7 @@ mod test { } #[test] - fn test_execute_remove_foundry_asset__catch_err_not_foundry_asset() { + fn test_execute_remove_foundry_asset_catch_err_not_foundry_asset() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -1770,7 +1808,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -1780,7 +1819,8 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, "token_address".to_string()); + let res = execute_add_foundry_asset(execute_env, "token_address".to_string()); + assert_eq!(res.is_err(), false); assert_eq!( is_foundry_asset(&deps.storage, "token_address".to_string()), true @@ -1792,7 +1832,8 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, "token_address_2".to_string()); + let res = execute_add_foundry_asset(execute_env, "token_address_2".to_string()); + assert_eq!(res.is_err(), false); assert_eq!( is_foundry_asset(&deps.storage, "token_address_2".to_string()), true @@ -1822,7 +1863,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -1835,7 +1877,8 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, token.clone()); + let res = execute_add_foundry_asset(execute_env, token.clone()); + assert_eq!(res.is_err(), false); assert_eq!(is_foundry_asset(&deps.storage, token.clone()), true); let execute_env = ExecuteEnv { @@ -1896,7 +1939,7 @@ mod test { } #[test] - fn test_execute_add_liquidity__catch_err_not_foundry_asset() { + fn test_execute_add_liquidity_catch_err_not_foundry_asset() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -1905,7 +1948,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -1931,7 +1975,7 @@ mod test { } #[test] - fn test_execute_add_liquidity__catch_err__invalid_deposit_if_more_1_token() { + fn test_execute_add_liquidity_catch_err_invalid_deposit_if_more_1_token() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -1940,7 +1984,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -1953,7 +1998,8 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, token.clone()); + let res = execute_add_foundry_asset(execute_env, token.clone()); + assert_eq!(res.is_err(), false); assert_eq!(is_foundry_asset(&deps.storage, token.clone()), true); let execute_env = ExecuteEnv { @@ -1990,7 +2036,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -2003,7 +2050,8 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, token.clone()); + let res = execute_add_foundry_asset(execute_env, token.clone()); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2017,7 +2065,8 @@ mod test { ), }; - execute_add_liquidity(execute_env); + let res = execute_add_liquidity(execute_env); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2045,7 +2094,7 @@ mod test { } #[test] - fn test_execute_remove_liquidity__catch_err__not_foundry_asset() { + fn test_execute_remove_liquidity_catch_err_not_foundry_asset() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -2054,12 +2103,12 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// let token = "token_address".to_string(); - let amount = Uint128::from(1000u128); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2076,7 +2125,7 @@ mod test { } #[test] - fn test_execute_remove_liquidity__catch_err__liquidity_does_not_exist() { + fn test_execute_remove_liquidity_catch_err_liquidity_does_not_exist() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -2085,7 +2134,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -2098,7 +2148,8 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, token.clone()); + let res = execute_add_foundry_asset(execute_env, token.clone()); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2112,7 +2163,8 @@ mod test { ), }; - execute_add_liquidity(execute_env); + let res = execute_add_liquidity(execute_env); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2129,7 +2181,7 @@ mod test { } #[test] - fn test_execute_remove_liquidity__catch_err__invalid_token() { + fn test_execute_remove_liquidity_catch_err_invalid_token() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -2138,7 +2190,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -2151,7 +2204,8 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, token.clone()); + let res = execute_add_foundry_asset(execute_env, token.clone()); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2165,7 +2219,8 @@ mod test { ), }; - execute_add_liquidity(execute_env); + let res = execute_add_liquidity(execute_env); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2182,7 +2237,7 @@ mod test { } #[test] - fn test_execute_remove_liquidity__catch_err__zero_amount() { + fn test_execute_remove_liquidity_catch_err_zero_amount() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -2191,7 +2246,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -2204,7 +2260,8 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, token.clone()); + let res = execute_add_foundry_asset(execute_env, token.clone()); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2218,7 +2275,8 @@ mod test { ), }; - execute_add_liquidity(execute_env); + let res = execute_add_liquidity(execute_env); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2244,7 +2302,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -2255,12 +2314,6 @@ mod test { let signature = "dada130255a447ecf434a2df9193e6fbba663e4546c35c075cd6eea21d8c7cb1714b9b65a4f7f604ff6aad55fba73f8c36514a512bbbba03709b37069194f8a41b"; - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; - let signer = get_signer( &deps.api, env.block.chain_id, @@ -2279,7 +2332,8 @@ mod test { info: info.clone(), }; - execute_add_signer(execute_env, signer.to_string()); + let res = execute_add_signer(execute_env, signer.to_string()); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2287,7 +2341,8 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, token.clone()); + let res = execute_add_foundry_asset(execute_env, token.clone()); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2327,7 +2382,7 @@ mod test { } #[test] - fn test_execute_withdraw_signed__catch_err_invalid_token_address() { + fn test_execute_withdraw_signed_catch_err_invalid_token_address() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -2336,7 +2391,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -2365,7 +2421,8 @@ mod test { info: info.clone(), }; - execute_add_signer(execute_env, signer.to_string()); + let res = execute_add_signer(execute_env, signer.to_string()); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2373,7 +2430,8 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, token.clone()); + let res = execute_add_foundry_asset(execute_env, token.clone()); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2403,7 +2461,7 @@ mod test { } #[test] - fn test_execute_withdraw_signed__catch_err_zero_amount() { + fn test_execute_withdraw_signed_catch_err_zero_amount() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -2412,7 +2470,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -2423,12 +2482,6 @@ mod test { let signature = "dada130255a447ecf434a2df9193e6fbba663e4546c35c075cd6eea21d8c7cb1714b9b65a4f7f604ff6aad55fba73f8c36514a512bbbba03709b37069194f8a41b"; - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; - let signer = get_signer( &deps.api, env.block.chain_id, @@ -2447,7 +2500,8 @@ mod test { info: info.clone(), }; - execute_add_signer(execute_env, signer.to_string()); + let res = execute_add_signer(execute_env, signer.to_string()); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2455,7 +2509,8 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, token.clone()); + let res = execute_add_foundry_asset(execute_env, token.clone()); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2485,7 +2540,7 @@ mod test { } #[test] - fn test_execute_withdraw_signed__catch_err_not_foundry_asset() { + fn test_execute_withdraw_signed_catch_err_not_foundry_asset() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -2494,7 +2549,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -2505,12 +2561,6 @@ mod test { let signature = "dada130255a447ecf434a2df9193e6fbba663e4546c35c075cd6eea21d8c7cb1714b9b65a4f7f604ff6aad55fba73f8c36514a512bbbba03709b37069194f8a41b"; - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; - let signer = get_signer( &deps.api, env.block.chain_id, @@ -2529,7 +2579,8 @@ mod test { info: info.clone(), }; - execute_add_signer(execute_env, signer.to_string()); + let res = execute_add_signer(execute_env, signer.to_string()); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2559,7 +2610,7 @@ mod test { } #[test] - fn test_execute_withdraw_signed__catch_err_invalid_signer() { + fn test_execute_withdraw_signed_catch_err_invalid_signer() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -2568,7 +2619,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -2579,39 +2631,15 @@ mod test { let signature = "dada130255a447ecf434a2df9193e6fbba663e4546c35c075cd66ea21d8c7cb1714b9b65a4f7f604ff6aad55fba73f8c36514a512bbbba03709b37069194bba41b"; - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; - - let signer = get_signer( - &deps.api, - env.block.chain_id, - owner.to_string(), - token.clone(), - Uint128::from(700u128), - salt.clone(), - signature.to_string(), - ); - let env = mock_env(); - - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; - - // execute_add_signer(execute_env, signer.to_string()); - let execute_env = ExecuteEnv { deps: deps.as_mut(), env: env.clone(), info: info.clone(), }; - execute_add_foundry_asset(execute_env, token.clone()); + let res = execute_add_foundry_asset(execute_env, token.clone()); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2641,7 +2669,7 @@ mod test { } #[test] - fn test_execute_withdraw_signed__catch_err_used_salt() { + fn test_execute_withdraw_signed_catch_err_used_salt() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -2650,7 +2678,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -2661,12 +2690,6 @@ mod test { let signature = "dada130255a447ecf434a2df9193e6fbba663e4546c35c075cd66ea21d8c7cb1714b9b65a4f7f604ff6aad55fba73f8c36514a512bbbba03709b37069194bba41b"; - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; - let signer = get_signer( &deps.api, env.block.chain_id, @@ -2685,7 +2708,8 @@ mod test { info: info.clone(), }; - execute_add_signer(execute_env, signer.to_string()); + let res = execute_add_signer(execute_env, signer.to_string()); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2693,15 +2717,11 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, token.clone()); - - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; + let res = execute_add_foundry_asset(execute_env, token.clone()); + assert_eq!(res.is_err(), false); - add_used_message(&mut deps.storage, salt.clone()); + let res = add_used_message(&mut deps.storage, salt.clone()); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2740,7 +2760,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -2753,7 +2774,43 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, token.clone()); + let res = execute_add_foundry_asset(execute_env, token.clone()); + assert_eq!(res.is_err(), false); + + // execute swap before setting fee and ensure fee is considered as zero + let execute_env = ExecuteEnv { + deps: deps.as_mut(), + env: env.clone(), + info: mock_info( + owner, + &[cosmwasm_std::Coin { + denom: token.clone(), + amount: amount, + }], + ), + }; + + let rsp = execute_swap( + execute_env, + "137".to_string(), + "token_address_out_chain".to_string(), + "user_address_out_chain".to_string(), + ) + .unwrap(); + + assert_eq!( + rsp.attributes, + vec![ + attr("action", "swap".to_string()), + attr("from", owner.to_string()), + attr("token", token.clone()), + attr("amount", amount), + attr("fee_amount", "0".to_string()), + attr("target_chain_id", "137".to_string()), + attr("target_token", "token_address_out_chain".to_string()), + attr("target_address", "user_address_out_chain".to_string()), + ] + ); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2761,7 +2818,8 @@ mod test { info: info.clone(), }; - let rsp = execute_set_fee(execute_env, token.clone(), Uint128::from(2000u128)).unwrap(); + let rsp = execute_set_fee(execute_env, token.clone(), Uint128::from(2000u128)); + assert_eq!(rsp.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2810,7 +2868,7 @@ mod test { assert_eq!(balance.amount.to_string(), "0token_address"); } #[test] - fn test_execute_swap__catch_err_more_1_fund() { + fn test_execute_swap_catch_err_more_1_fund() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -2819,7 +2877,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -2832,7 +2891,8 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, token.clone()); + let res = execute_add_foundry_asset(execute_env, token.clone()); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2866,7 +2926,7 @@ mod test { } #[test] - fn test_execute_swap__catch_err_invalid_target_info() { + fn test_execute_swap_catch_err_invalid_target_info() { let owner = "address_to_be_owner"; let mut deps = mock_dependencies(); let env = mock_env(); @@ -2875,7 +2935,8 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// @@ -2888,7 +2949,8 @@ mod test { info: info.clone(), }; - execute_add_foundry_asset(execute_env, token.clone()); + let res = execute_add_foundry_asset(execute_env, token.clone()); + assert_eq!(res.is_err(), false); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -2925,16 +2987,11 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; - let rsp = execute( deps.as_mut(), env.clone(), @@ -2957,12 +3014,6 @@ mod test { let owner = "address_to_be_owner_2"; let info = mock_info(owner, &[]); - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; - let rsp = execute( deps.as_mut(), env.clone(), @@ -2973,38 +3024,31 @@ mod test { }, ) .unwrap(); + assert_eq!( + rsp.attributes, + vec![ + attr("action", "set_fee".to_string()), + attr("fee", "22".to_string()), + attr("token", "token_address".to_string()), + attr("from", owner.to_string()) + ] + ); let query_res = query_fee(deps.as_ref(), "token_address".to_string()).unwrap(); assert_eq!(query_res.token, "token_address".to_string()); assert_eq!(query_res.amount, Uint128::from(22u128)); - // ! ISSUE - // ! assert_eq!( - // rsp.attributes, - // vec![ - // attr("action", "add_signer".to_string()), - // attr("amount", Uint128::from(22u128)), - // attr("token", "token_address".to_string()), - // attr("from", owner.to_string()) - // ] - // ); - let execute_env = ExecuteEnv { deps: deps.as_mut(), env: env.clone(), info: info.clone(), }; - execute_add_signer( + let res = execute_add_signer( execute_env, "0x8929cbb11fdd5798db5f638a5002235c6412f13f".to_string(), ); - - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; + assert_eq!(res.is_err(), false); let rsp = execute( deps.as_mut(), @@ -3039,12 +3083,6 @@ mod test { ] ); - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; - let rsp = execute( deps.as_mut(), env.clone(), @@ -3074,27 +3112,15 @@ mod test { ] ); - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; - - let rsp = execute( + let res = execute( deps.as_mut(), env.clone(), info.clone(), FundManagerExecuteMsg::AddFoundryAsset { token: "token_address_mock".to_string(), }, - ) - .unwrap(); - - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; + ); + assert_eq!(res.is_err(), false); let rsp = execute( deps.as_mut(), @@ -3120,12 +3146,6 @@ mod test { ] ); - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; - let rsp = execute( deps.as_mut(), env.clone(), @@ -3145,18 +3165,6 @@ mod test { ] ); - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: mock_info( - owner, - &[cosmwasm_std::Coin { - denom: "token_address".to_string(), - amount: Uint128::from(22u128), - }], - ), - }; - let rsp = execute( deps.as_mut(), env.clone(), @@ -3190,12 +3198,6 @@ mod test { ] ); - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; - let rsp = execute( deps.as_mut(), env.clone(), @@ -3228,17 +3230,10 @@ mod test { ); let token = "token_address".to_string(); - let amount = Uint128::from(1000u128); let salt = "salt".to_string(); let signature = "dada130255a447ecf434a2df9193e6fbba663e4546c35c075cd6eea21d8c7cb1714b9b65a4f7f604ff6aad55fba73f8c36514a512bbbba03709b37069194f8a41b"; - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; - let signer = get_signer( &deps.api, env.block.chain_id, @@ -3257,19 +3252,8 @@ mod test { info: info.clone(), }; - execute_add_signer(execute_env, signer.to_string()); - - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: mock_info( - MOCK_CONTRACT_ADDR, - &[cosmwasm_std::Coin { - denom: token.clone(), - amount: amount, - }], - ), - }; + let res = execute_add_signer(execute_env, signer.to_string()); + assert_eq!(res.is_err(), false); let rsp = execute( deps.as_mut(), @@ -3299,18 +3283,6 @@ mod test { ] ); - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: mock_info( - owner, - &[cosmwasm_std::Coin { - denom: token.clone(), - amount: Uint128::from(777u128), - }], - ), - }; - let rsp = execute( deps.as_mut(), env.clone(), @@ -3350,10 +3322,9 @@ mod test { owner: owner.to_string(), token: token.clone(), }, - ); - - // assert_eq!(Liquidity::to_normal(rsp, &deps.api), "token_address".to_string()); - // assert_eq!(rsp.amount, Uint128::from(12u128)); + ) + .unwrap(); + assert_eq!(rsp.to_string(), "eyJ1c2VyIjoiYWRkcmVzc190b19iZV9vd25lcl8yIiwidG9rZW4iOiJ0b2tlbl9hZGRyZXNzIiwiYW1vdW50IjoiMTIifQ=="); let rsp = query(deps.as_ref(), env.clone(), FundManagerQueryMsg::Owner {}).unwrap(); @@ -3371,20 +3342,7 @@ mod test { }, ) .unwrap(); - - // assert_eq!(); - - let rsp = query( - deps.as_ref(), - env.clone(), - FundManagerQueryMsg::AllLiquidity { - start_after: None, - limit: None, - }, - ) - .unwrap(); - - // assert_eq!(); + assert_eq!(rsp.to_string(), "W3sidXNlciI6ImFkZHJlc3NfdG9fYmVfb3duZXJfMiIsInRva2VuIjoidG9rZW5fYWRkcmVzcyIsImFtb3VudCI6IjEyIn1d"); let rsp = query( deps.as_ref(), @@ -3395,8 +3353,7 @@ mod test { }, ) .unwrap(); - - // assert_eq!(); + assert_eq!(rsp.to_string(), "WyIweDg5MjljYmIxMWZkZDU3OThkYjVmNjM4YTUwMDIyMzVjNjQxMmYyNmEiLCIweGFkN2Y4MWNkMTg0NGMyMzk0MzQ5ZjIyMDY4Y2VmNjUxMTkwNGUwOGUiXQ=="); let rsp = query( deps.as_ref(), @@ -3407,8 +3364,7 @@ mod test { }, ) .unwrap(); - - // assert_eq!(); + assert_eq!(rsp.to_string(), "WyJ0b2tlbl9hZGRyZXNzIl0="); let rsp = query( deps.as_ref(), @@ -3418,8 +3374,10 @@ mod test { }, ) .unwrap(); - - // assert_eq!(); + assert_eq!( + rsp.to_string(), + "eyJ0b2tlbiI6InRva2VuX2FkZHJlc3MiLCJhbW91bnQiOiIyMiJ9" + ); let rsp = query_liquidity( deps.as_ref(), @@ -3439,20 +3397,14 @@ mod test { info: info.clone(), }; - execute_remove_signer( + let res = execute_remove_signer( execute_env, "0x8929cbb11fdd5798db5f638a5002235c6412f26a".to_string(), ); - - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; + assert_eq!(res.is_err(), false); let rsp = read_signers(&deps.storage, None, None); - - // assert_eq!(rsp.to_string(), "".to_string()); + assert_eq!(rsp.len(), 1); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -3460,11 +3412,11 @@ mod test { info: info.clone(), }; - execute_remove_signer(execute_env, signer.to_string()); + let res = execute_remove_signer(execute_env, signer.to_string()); + assert_eq!(res.is_err(), false); let rsp = read_signers(&deps.storage, None, None); - - // assert_eq!(rsp.to_string(), "".to_string()); + assert_eq!(rsp.len(), 0); let execute_env = ExecuteEnv { deps: deps.as_mut(), @@ -3472,11 +3424,11 @@ mod test { info: info.clone(), }; - execute_remove_foundry_asset(execute_env, "token_address".to_string()); + let res = execute_remove_foundry_asset(execute_env, "token_address".to_string()); + assert_eq!(res.is_err(), false); let rsp = read_foundry_assets(&deps.storage, None, None); - - // assert_eq!(rsp.to_string(), "".to_string()); + assert_eq!(rsp.len(), 0); } #[test] fn test_migrate() { @@ -3488,16 +3440,11 @@ mod test { owner: owner.to_string(), }; - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg); + assert_eq!(res.is_err(), false); ///////////////////////////////////////////////////////////// - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; - let rsp = migrate(deps.as_mut(), env.clone(), MigrateMsg {}).unwrap(); assert_eq!(rsp, Response::default()); @@ -3505,26 +3452,10 @@ mod test { #[test] fn test_ethereum_address_raw() { - let owner = "address_to_be_owner"; - let mut deps = mock_dependencies(); - let env = mock_env(); - let info = mock_info(owner, &[]); - let msg = InstantiateMsg { - owner: owner.to_string(), - }; - - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); - - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; - // 0x910266349a2aaca44ce909b6845e8c1ab75f475e // [4, 66, 91, 185, 143, 51, 145, 149, 174, 15, 8, 226, 58, 172, 220, 172, 176, 8, 58, 211, 123, 186, 203, 240, 64, 112, 233, 120, 16, 129, 196, 206, 212, 201, 204, 154, 66, 211, 181, 116, 10, 250, 253, 162, 211, 110, 216, 254, 162, 49, 63, 48, 133, 29, 153, 127, 95, 97, 178, 42, 20, 244, 83, 87, 235] let signer = "0x910266349a2aaca44ce909b6845e8c1ab75f475e".to_string(); - let mut pubkey_vec: Vec = Vec::from([ + let pubkey_vec: Vec = Vec::from([ 4, 66, 91, 185, 143, 51, 145, 149, 174, 15, 8, 226, 58, 172, 220, 172, 176, 8, 58, 211, 123, 186, 203, 240, 64, 112, 233, 120, 16, 129, 196, 206, 212, 201, 204, 154, 66, 211, 181, 116, 10, 250, 253, 162, 211, 110, 216, 254, 162, 49, 63, 48, 133, 29, 153, 127, @@ -3537,28 +3468,8 @@ mod test { } #[test] - fn test_ethereum_address_raw__catch_err_empty_key() { - let owner = "address_to_be_owner"; - let mut deps = mock_dependencies(); - let env = mock_env(); - let info = mock_info(owner, &[]); - let msg = InstantiateMsg { - owner: owner.to_string(), - }; - - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); - - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; - - // 0x910266349a2aaca44ce909b6845e8c1ab75f475e - // [4, 66, 91, 185, 143, 51, 145, 149, 174, 15, 8, 226, 58, 172, 220, 172, 176, 8, 58, 211, 123, 186, 203, 240, 64, 112, 233, 120, 16, 129, 196, 206, 212, 201, 204, 154, 66, 211, 181, 116, 10, 250, 253, 162, 211, 110, 216, 254, 162, 49, 63, 48, 133, 29, 153, 127, 95, 97, 178, 42, 20, 244, 83, 87, 235] - let signer = "0x910266349a2aaca44ce909b6845e8c1ab75f475e".to_string(); - let mut pubkey_vec: Vec = Vec::from([]); - + fn test_ethereum_address_raw_catch_err_empty_key() { + let pubkey_vec: Vec = Vec::from([]); assert_eq!( ethereum_address_raw(&pubkey_vec).unwrap_err().to_string(), "Generic error: Public key must not be empty".to_string() @@ -3566,27 +3477,10 @@ mod test { } #[test] - fn test_ethereum_address_raw__catch_err_invalid_key() { - let owner = "address_to_be_owner"; - let mut deps = mock_dependencies(); - let env = mock_env(); - let info = mock_info(owner, &[]); - let msg = InstantiateMsg { - owner: owner.to_string(), - }; - - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); - - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; - + fn test_ethereum_address_raw_catch_err_invalid_key() { // 0x910266349a2aaca44ce909b6845e8c1ab75f475e // [4, 66, 91, 185, 143, 51, 145, 149, 174, 15, 8, 226, 58, 172, 220, 172, 176, 8, 58, 211, 123, 186, 203, 240, 64, 112, 233, 120, 16, 129, 196, 206, 212, 201, 204, 154, 66, 211, 181, 116, 10, 250, 253, 162, 211, 110, 216, 254, 162, 49, 63, 48, 133, 29, 153, 127, 95, 97, 178, 42, 20, 244, 83, 87, 235] - let signer = "0x910266349a2aaca44ce909b6845e8c1ab75f475e".to_string(); - let mut pubkey_vec: Vec = Vec::from([ + let pubkey_vec: Vec = Vec::from([ 5, 66, 91, 185, 143, 51, 145, 149, 174, 15, 8, 226, 58, 172, 220, 172, 176, 8, 58, 211, 123, 186, 203, 240, 64, 112, 233, 120, 16, 129, 196, 206, 212, 201, 204, 154, 66, 211, 181, 116, 10, 250, 253, 162, 211, 110, 216, 254, 162, 49, 63, 48, 133, 29, 153, 127, @@ -3600,27 +3494,10 @@ mod test { } #[test] - fn test_ethereum_address_raw__catch_err_invalid_length() { - let owner = "address_to_be_owner"; - let mut deps = mock_dependencies(); - let env = mock_env(); - let info = mock_info(owner, &[]); - let msg = InstantiateMsg { - owner: owner.to_string(), - }; - - instantiate(deps.as_mut(), env.clone(), info.clone(), msg); - - let execute_env = ExecuteEnv { - deps: deps.as_mut(), - env: env.clone(), - info: info.clone(), - }; - + fn test_ethereum_address_raw_catch_err_invalid_length() { // 0x910266349a2aaca44ce909b6845e8c1ab75f475e // [4, 66, 91, 185, 143, 51, 145, 149, 174, 15, 8, 226, 58, 172, 220, 172, 176, 8, 58, 211, 123, 186, 203, 240, 64, 112, 233, 120, 16, 129, 196, 206, 212, 201, 204, 154, 66, 211, 181, 116, 10, 250, 253, 162, 211, 110, 216, 254, 162, 49, 63, 48, 133, 29, 153, 127, 95, 97, 178, 42, 20, 244, 83, 87, 235] - let signer = "0x910266349a2aaca44ce909b6845e8c1ab75f475e".to_string(); - let mut pubkey_vec: Vec = Vec::from([ + let pubkey_vec: Vec = Vec::from([ 4, 66, 91, 185, 143, 51, 145, 149, 174, 15, 8, 226, 58, 172, 220, 172, 176, 8, 58, 211, 123, 186, 203, 240, 64, 112, 233, 120, 16, 129, 196, 206, 212, 201, 204, 154, 66, 211, 181, 116, 10, 250, 253, 162, 211, 110, 216, 254, 162, 49, 63, 48, 133, 29, 153, 127,