From 84cbb3fcf307b1b86dd96a785363966d98ac5a65 Mon Sep 17 00:00:00 2001 From: Joe Monem Date: Fri, 10 Jan 2025 10:53:56 +0200 Subject: [PATCH 1/9] ref: check fee before calling pay_fee --- packages/std/src/common/actions.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/std/src/common/actions.rs b/packages/std/src/common/actions.rs index 04f4284b1..46334722a 100644 --- a/packages/std/src/common/actions.rs +++ b/packages/std/src/common/actions.rs @@ -2,6 +2,7 @@ use crate::{ ado_contract::{permissioning::is_context_permissioned, ADOContract}, amp::messages::AMPPkt, error::ContractError, + os::aos_querier::AOSQuerier, }; use cosmwasm_std::{ensure, DepsMut, Env, MessageInfo, Response}; @@ -23,8 +24,26 @@ pub fn call_action( info.sender.clone() }; - let fee_msg = - ADOContract::default().pay_fee(deps.storage, &deps.querier, action.to_owned(), payee)?; - - Ok(Response::default().add_submessage(fee_msg)) + let adodb_addr = ADOContract::default().get_adodb_address(deps.storage, &deps.querier)?; + let contract_info = deps + .querier + .query_wasm_contract_info(env.contract.address.clone())?; + let code_id = contract_info.code_id; + // If ADO type is not found, return default response + let ado_type = AOSQuerier::ado_type_getter(&deps.querier, &adodb_addr, code_id)?; + if let Some(ado_type) = ado_type { + if AOSQuerier::action_fee_getter(&deps.querier, &adodb_addr, &ado_type, action)?.is_some() { + let fee_msg = ADOContract::default().pay_fee( + deps.storage, + &deps.querier, + action.to_owned(), + payee, + )?; + Ok(Response::default().add_submessage(fee_msg)) + } else { + Ok(Response::default()) + } + } else { + Ok(Response::default()) + } } From 275757542fadf0e28944381b0c06e875e0e60501 Mon Sep 17 00:00:00 2001 From: Joe Monem Date: Fri, 10 Jan 2025 16:44:47 +0200 Subject: [PATCH 2/9] fix: stop returning error if there's no fee attached to action --- .../src/testing/tests.rs | 45 +++++++++---------- packages/std/src/common/actions.rs | 33 ++++++-------- packages/std/src/os/aos_querier.rs | 1 - 3 files changed, 34 insertions(+), 45 deletions(-) diff --git a/contracts/modules/andromeda-address-list/src/testing/tests.rs b/contracts/modules/andromeda-address-list/src/testing/tests.rs index e53abb909..82ed7a55e 100644 --- a/contracts/modules/andromeda-address-list/src/testing/tests.rs +++ b/contracts/modules/andromeda-address-list/src/testing/tests.rs @@ -1,20 +1,19 @@ -use crate::contract::{execute, instantiate, query}; -use crate::state::PERMISSIONS; -use crate::testing::mock_querier::{mock_dependencies_custom, MOCK_KERNEL_CONTRACT}; +use crate::{ + contract::{execute, instantiate, query}, + state::PERMISSIONS, + testing::mock_querier::{mock_dependencies_custom, MOCK_KERNEL_CONTRACT}, +}; use andromeda_modules::address_list::{ ActorPermission, ActorPermissionResponse, ExecuteMsg, IncludesActorResponse, InstantiateMsg, QueryMsg, }; -use andromeda_std::ado_base::permissioning::LocalPermission; - -use andromeda_std::amp::AndrAddr; -use andromeda_std::error::ContractError; - -use andromeda_testing::economics_msg::generate_economics_message; -use cosmwasm_std::{attr, from_json, Addr, DepsMut, MessageInfo}; +use andromeda_std::{ + ado_base::permissioning::LocalPermission, amp::AndrAddr, error::ContractError, +}; use cosmwasm_std::{ + attr, from_json, testing::{mock_env, mock_info}, - Response, + Addr, DepsMut, MessageInfo, Response, }; fn init(deps: DepsMut, info: MessageInfo) { @@ -88,13 +87,11 @@ fn test_add_remove_actor() { }; let res = execute(deps.as_mut(), env.clone(), info.clone(), msg.clone()).unwrap(); - let expected = Response::default() - .add_attributes(vec![ - attr("action", "add_actor_permission"), - attr("actor", actor.clone()), - attr("permission", permission.to_string()), - ]) - .add_submessage(generate_economics_message("creator", "PermissionActors")); + let expected = Response::default().add_attributes(vec![ + attr("action", "add_actor_permission"), + attr("actor", actor.clone()), + attr("permission", permission.to_string()), + ]); assert_eq!(expected, res); // Check that the actor and permission have been saved. @@ -164,13 +161,11 @@ fn test_add_remove_multiple_actors() { }; let res = execute(deps.as_mut(), env.clone(), info.clone(), msg.clone()).unwrap(); - let expected = Response::default() - .add_attributes(vec![ - attr("action", "add_actor_permission"), - attr("actor", "actor1, actor2"), - attr("permission", permission.to_string()), - ]) - .add_submessage(generate_economics_message("creator", "PermissionActors")); + let expected = Response::default().add_attributes(vec![ + attr("action", "add_actor_permission"), + attr("actor", "actor1, actor2"), + attr("permission", permission.to_string()), + ]); assert_eq!(expected, res); // Check that the actor and permission have been saved. diff --git a/packages/std/src/common/actions.rs b/packages/std/src/common/actions.rs index 46334722a..74814532e 100644 --- a/packages/std/src/common/actions.rs +++ b/packages/std/src/common/actions.rs @@ -25,25 +25,20 @@ pub fn call_action( }; let adodb_addr = ADOContract::default().get_adodb_address(deps.storage, &deps.querier)?; - let contract_info = deps + let code_id = deps .querier - .query_wasm_contract_info(env.contract.address.clone())?; - let code_id = contract_info.code_id; - // If ADO type is not found, return default response - let ado_type = AOSQuerier::ado_type_getter(&deps.querier, &adodb_addr, code_id)?; - if let Some(ado_type) = ado_type { - if AOSQuerier::action_fee_getter(&deps.querier, &adodb_addr, &ado_type, action)?.is_some() { - let fee_msg = ADOContract::default().pay_fee( - deps.storage, - &deps.querier, - action.to_owned(), - payee, - )?; - Ok(Response::default().add_submessage(fee_msg)) - } else { - Ok(Response::default()) - } - } else { - Ok(Response::default()) + .query_wasm_contract_info(env.contract.address.clone())? + .code_id; + + // Check ADO type and fees in one chain + match AOSQuerier::ado_type_getter(&deps.querier, &adodb_addr, code_id)? + .and_then(|ado_type| { + AOSQuerier::action_fee_getter(&deps.querier, &adodb_addr, &ado_type, action).ok() + }) + .map(|_| { + ADOContract::default().pay_fee(deps.storage, &deps.querier, action.to_owned(), payee) + }) { + Some(fee_msg) => Ok(Response::default().add_submessage(fee_msg?)), + None => Ok(Response::default()), } } diff --git a/packages/std/src/os/aos_querier.rs b/packages/std/src/os/aos_querier.rs index f4fbd8a77..e80ef2558 100644 --- a/packages/std/src/os/aos_querier.rs +++ b/packages/std/src/os/aos_querier.rs @@ -182,7 +182,6 @@ impl AOSQuerier { &[ado_type.as_bytes(), action.as_bytes()], )?; let fee: Option = AOSQuerier::query_storage(querier, adodb_addr, &key)?; - Ok(fee) } From 5ed13f4820b8ebbb9611b7c35b9e36c084ad434c Mon Sep 17 00:00:00 2001 From: Joe Monem Date: Tue, 14 Jan 2025 11:41:37 +0200 Subject: [PATCH 3/9] test: remove generate economics message --- .../andromeda-app-contract/src/testing/mod.rs | 24 +- .../andromeda-primitive/src/testing/tests.rs | 7 +- .../src/testing/tests.rs | 105 +------ .../src/testing/tests.rs | 27 +- .../andromeda-splitter/src/testing/tests.rs | 30 +- .../andromeda-timelock/src/testing/tests.rs | 90 +++--- .../src/testing/tests.rs | 60 ++-- .../src/testing/tests.rs | 69 ++--- .../andromeda-cw20/src/testing/tests.rs | 7 +- .../andromeda-ics20/src/testing/tests.rs | 38 +-- .../andromeda-lockdrop/src/testing/tests.rs | 20 +- .../src/testing/tests.rs | 51 +--- .../andromeda-rates/src/testing/tests.rs | 23 +- .../andromeda-auction/src/testing/tests.rs | 289 +++--------------- .../andromeda-crowdfund/src/testing/tests.rs | 191 +----------- .../andromeda-cw721/src/testing/mod.rs | 30 +- .../src/testing/tests.rs | 17 +- 17 files changed, 229 insertions(+), 849 deletions(-) diff --git a/contracts/app/andromeda-app-contract/src/testing/mod.rs b/contracts/app/andromeda-app-contract/src/testing/mod.rs index 54cdc2f46..18d4d89e7 100644 --- a/contracts/app/andromeda-app-contract/src/testing/mod.rs +++ b/contracts/app/andromeda-app-contract/src/testing/mod.rs @@ -1,18 +1,11 @@ -use crate::state::{ADO_DESCRIPTORS, ADO_IDX}; - use super::{contract::*, state::ADO_ADDRESSES}; +use crate::state::{ADO_DESCRIPTORS, ADO_IDX}; use andromeda_app::app::{AppComponent, ComponentType, ExecuteMsg, InstantiateMsg}; use andromeda_std::ado_base::ownership::OwnershipMessage; -// use andromeda_std::amp::AndrAddr; -// use andromeda_std::common::reply::ReplyId; -// use andromeda_std::os::vfs::{convert_component_name, ExecuteMsg as VFSExecuteMsg}; use andromeda_std::testing::mock_querier::{ mock_dependencies_custom, MOCK_ANCHOR_CONTRACT, MOCK_CW20_CONTRACT, MOCK_KERNEL_CONTRACT, }; - use andromeda_std::{ado_base::AndromedaMsg, error::ContractError}; - -use andromeda_testing::economics_msg::generate_economics_message; use cosmwasm_std::{ attr, testing::{mock_env, mock_info}, @@ -332,8 +325,7 @@ fn test_claim_ownership_empty() { }; let res = execute(deps.as_mut(), env, info, msg).unwrap(); - // The message is for the economics contract - assert_eq!(1, res.messages.len()); + assert_eq!(0, res.messages.len()); } #[test] @@ -371,8 +363,7 @@ fn test_claim_ownership_all() { }; let res = execute(deps.as_mut(), env, info, msg).unwrap(); - // The 3rd message is for the economics contract - assert_eq!(3, res.messages.len()); + assert_eq!(2, res.messages.len()); } #[test] @@ -410,8 +401,7 @@ fn test_claim_ownership() { }; let res = execute(deps.as_mut(), env, info, msg).unwrap(); - // The 2nd message is for the economics contract - assert_eq!(2, res.messages.len()); + assert_eq!(1, res.messages.len()); let exec_submsg: SubMsg = SubMsg { id: 200, @@ -429,8 +419,7 @@ fn test_claim_ownership() { }; let expected = Response::new() .add_submessage(exec_submsg) - .add_attributes(vec![attr("method", "claim_ownership")]) - .add_submessage(generate_economics_message("creator", "ClaimOwnership")); + .add_attributes(vec![attr("method", "claim_ownership")]); assert_eq!(expected, res) } @@ -528,8 +517,7 @@ fn test_proxy_message() { .add_attributes(vec![ attr("method", "app_message"), attr("recipient", "token"), - ]) - .add_submessage(generate_economics_message("creator", "ProxyMessage")); + ]); assert_eq!(expected, res) } diff --git a/contracts/data-storage/andromeda-primitive/src/testing/tests.rs b/contracts/data-storage/andromeda-primitive/src/testing/tests.rs index 8aa1202e8..3c98083ea 100644 --- a/contracts/data-storage/andromeda-primitive/src/testing/tests.rs +++ b/contracts/data-storage/andromeda-primitive/src/testing/tests.rs @@ -2,7 +2,6 @@ use crate::contract::{execute, query}; use andromeda_data_storage::primitive::{ ExecuteMsg, GetValueResponse, Primitive, PrimitiveRestriction, QueryMsg, }; -use andromeda_testing::economics_msg::generate_economics_message; use cosmwasm_std::{ coin, from_json, testing::mock_env, BankMsg, Binary, CosmosMsg, Decimal, Response, SubMsg, }; @@ -161,8 +160,7 @@ fn test_set_value_with_tax() { ("sender", "creator"), ("key", "key"), ]) - .add_attribute("value", format!("{value:?}")) - .add_submessage(generate_economics_message("creator", "SetValue")); + .add_attribute("value", format!("{value:?}")); assert_eq!(expected_response, res); // Sent less than amount required for tax @@ -200,8 +198,7 @@ fn test_set_value_with_tax() { ("sender", "creator"), ("key", "key"), ]) - .add_attribute("value", format!("{value:?}")) - .add_submessage(generate_economics_message("creator", "SetValue")); + .add_attribute("value", format!("{value:?}")); assert_eq!(expected_response, res); } diff --git a/contracts/finance/andromeda-conditional-splitter/src/testing/tests.rs b/contracts/finance/andromeda-conditional-splitter/src/testing/tests.rs index 693f733cb..5abaa444d 100644 --- a/contracts/finance/andromeda-conditional-splitter/src/testing/tests.rs +++ b/contracts/finance/andromeda-conditional-splitter/src/testing/tests.rs @@ -6,7 +6,6 @@ use andromeda_std::{ common::{expiration::Expiry, Milliseconds}, error::ContractError, }; -use andromeda_testing::economics_msg::generate_economics_message; use cosmwasm_std::{ attr, from_json, testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}, @@ -198,12 +197,10 @@ fn test_execute_update_lock() { let res = execute(deps.as_mut(), env.clone(), info, msg).unwrap(); assert_eq!( - Response::default() - .add_attributes(vec![ - attr("action", "update_lock"), - attr("locked", lock_time.get_time(&env.block).to_string()) - ]) - .add_submessage(generate_economics_message(OWNER, "UpdateLock")), + Response::default().add_attributes(vec![ + attr("action", "update_lock"), + attr("locked", lock_time.get_time(&env.block).to_string()) + ]), res ); @@ -317,9 +314,7 @@ fn test_execute_update_thresholds() { let info = mock_info(OWNER, &[]); let res = execute(deps.as_mut(), env, info, msg).unwrap(); assert_eq!( - Response::default() - .add_attributes(vec![attr("action", "update_thresholds")]) - .add_submessage(generate_economics_message(OWNER, "UpdateThresholds")), + Response::default().add_attributes(vec![attr("action", "update_thresholds")]), res ); @@ -437,8 +432,7 @@ fn test_execute_send() { ), amp_msg, ]) - .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]) - .add_submessage(generate_economics_message(OWNER, "Send")); + .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]); assert_eq!(res, expected_res); @@ -479,8 +473,7 @@ fn test_execute_send() { ), amp_msg, ]) - .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]) - .add_submessage(generate_economics_message(OWNER, "Send")); + .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]); assert_eq!(res, expected_res); @@ -513,8 +506,7 @@ fn test_execute_send() { let expected_res = Response::new() // No refund for the sender since the percentages add up to 100 .add_submessage(amp_msg) - .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]) - .add_submessage(generate_economics_message(OWNER, "Send")); + .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]); assert_eq!(res, expected_res); } @@ -581,84 +573,6 @@ fn test_execute_send_threshold_not_found() { ); } -// #[test] -// fn test_execute_send_ado_recipient() { -// let mut deps = mock_dependencies_custom(&[]); -// let env = mock_env(); -// let _res: Response = init(deps.as_mut()); - -// let sender_funds_amount = 10000u128; -// let info = mock_info(OWNER, &[Coin::new(sender_funds_amount, "uluna")]); - -// let recip_address1 = "address1".to_string(); -// let recip_percent1 = 10; // 10% - -// let recip_address2 = "address2".to_string(); -// let recip_percent2 = 20; // 20% - -// let recip1 = Recipient::from_string(recip_address1); -// let recip2 = Recipient::from_string(recip_address2); - -// let recipient = vec![ -// AddressFunds { -// recipient: recip1.clone(), -// percent: Decimal::percent(recip_percent1), -// }, -// AddressFunds { -// recipient: recip2.clone(), -// percent: Decimal::percent(recip_percent2), -// }, -// ]; -// let msg = ExecuteMsg::Send {}; - -// let amp_msg_1 = recip1 -// .generate_amp_msg(&deps.as_ref(), Some(vec![Coin::new(1000, "uluna")])) -// .unwrap(); -// let amp_msg_2 = recip2 -// .generate_amp_msg(&deps.as_ref(), Some(vec![Coin::new(2000, "uluna")])) -// .unwrap(); -// let amp_pkt = AMPPkt::new( -// MOCK_CONTRACT_ADDR.to_string(), -// MOCK_CONTRACT_ADDR.to_string(), -// vec![amp_msg_1, amp_msg_2], -// ); -// let amp_msg = amp_pkt -// .to_sub_msg( -// MOCK_KERNEL_CONTRACT, -// Some(vec![Coin::new(1000, "uluna"), Coin::new(2000, "uluna")]), -// 1, -// ) -// .unwrap(); - -// let splitter = ConditionalSplitter { -// recipients: recipient, -// lock: Milliseconds::default(), -// }; - -// CONDITIONAL_SPLITTER -// .save(deps.as_mut().storage, &splitter) -// .unwrap(); - -// let res = execute(deps.as_mut(), env, info.clone(), msg).unwrap(); - -// let expected_res = Response::new() -// .add_submessages(vec![ -// SubMsg::new( -// // refunds remainder to sender -// CosmosMsg::Bank(BankMsg::Send { -// to_address: info.sender.to_string(), -// amount: vec![Coin::new(7000, "uluna")], // 10000 * 0.7 remainder -// }), -// ), -// amp_msg, -// ]) -// .add_attribute("action", "send") -// .add_attribute("sender", "creator") -// .add_submessage(generate_economics_message(OWNER, "Send")); - -// assert_eq!(res, expected_res); -// } - #[test] fn test_handle_packet_exit_with_error_true() { let mut deps = mock_dependencies_custom(&[]); @@ -804,8 +718,7 @@ fn test_update_app_contract() { assert_eq!( Response::new() .add_attribute("action", "update_app_contract") - .add_attribute("address", "app_contract") - .add_submessage(generate_economics_message(OWNER, "UpdateAppContract")), + .add_attribute("address", "app_contract"), res ); } diff --git a/contracts/finance/andromeda-set-amount-splitter/src/testing/tests.rs b/contracts/finance/andromeda-set-amount-splitter/src/testing/tests.rs index bdb3afe79..aafc78d55 100644 --- a/contracts/finance/andromeda-set-amount-splitter/src/testing/tests.rs +++ b/contracts/finance/andromeda-set-amount-splitter/src/testing/tests.rs @@ -6,7 +6,6 @@ use andromeda_std::{ common::{expiration::Expiry, Milliseconds}, error::ContractError, }; -use andromeda_testing::economics_msg::generate_economics_message; use cosmwasm_std::{ attr, coin, coins, from_json, testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}, @@ -79,12 +78,10 @@ fn test_execute_update_lock() { .plus_seconds(current_time) .plus_milliseconds(Milliseconds(879)); assert_eq!( - Response::default() - .add_attributes(vec![ - attr("action", "update_lock"), - attr("locked", new_lock.to_string()) - ]) - .add_submessage(generate_economics_message(OWNER, "UpdateLock")), + Response::default().add_attributes(vec![ + attr("action", "update_lock"), + attr("locked", new_lock.to_string()) + ]), res ); @@ -148,9 +145,7 @@ fn test_execute_update_recipients() { let info = mock_info(OWNER, &[]); let res = execute(deps.as_mut(), env, info, msg).unwrap(); assert_eq!( - Response::default() - .add_attributes(vec![attr("action", "update_recipients")]) - .add_submessage(generate_economics_message(OWNER, "UpdateRecipients")), + Response::default().add_attributes(vec![attr("action", "update_recipients")]), res ); @@ -253,8 +248,7 @@ fn test_execute_send() { ), amp_msg, ]) - .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]) - .add_submessage(generate_economics_message(OWNER, "Send")); + .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]); assert_eq!(res, expected_res); @@ -302,8 +296,7 @@ fn test_execute_send() { ), amp_msg, ]) - .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]) - .add_submessage(generate_economics_message(OWNER, "Send")); + .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]); let res = execute(deps.as_mut(), env, info, msg).unwrap(); assert_eq!(res, expected_res); @@ -378,8 +371,7 @@ fn test_execute_send_ado_recipient() { amp_msg, ]) .add_attribute("action", "send") - .add_attribute("sender", "creator") - .add_submessage(generate_economics_message(OWNER, "Send")); + .add_attribute("sender", "creator"); assert_eq!(res, expected_res); } @@ -532,8 +524,7 @@ fn test_update_app_contract() { assert_eq!( Response::new() .add_attribute("action", "update_app_contract") - .add_attribute("address", "app_contract") - .add_submessage(generate_economics_message(OWNER, "UpdateAppContract")), + .add_attribute("address", "app_contract"), res ); } diff --git a/contracts/finance/andromeda-splitter/src/testing/tests.rs b/contracts/finance/andromeda-splitter/src/testing/tests.rs index 2093922e6..4c2f6f8e1 100644 --- a/contracts/finance/andromeda-splitter/src/testing/tests.rs +++ b/contracts/finance/andromeda-splitter/src/testing/tests.rs @@ -6,7 +6,6 @@ use andromeda_std::{ common::{expiration::Expiry, Milliseconds}, error::ContractError, }; -use andromeda_testing::economics_msg::generate_economics_message; use cosmwasm_std::{ attr, from_json, testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}, @@ -184,12 +183,10 @@ fn test_execute_update_lock() { .plus_seconds(current_time) .plus_milliseconds(Milliseconds(879)); assert_eq!( - Response::default() - .add_attributes(vec![ - attr("action", "update_lock"), - attr("locked", "1571970219879".to_string()) - ]) - .add_submessage(generate_economics_message(OWNER, "UpdateLock")), + Response::default().add_attributes(vec![ + attr("action", "update_lock"), + attr("locked", "1571970219879".to_string()) + ]), res ); @@ -253,9 +250,7 @@ fn test_execute_update_recipients() { let info = mock_info(OWNER, &[]); let res = execute(deps.as_mut(), env, info, msg).unwrap(); assert_eq!( - Response::default() - .add_attributes(vec![attr("action", "update_recipients")]) - .add_submessage(generate_economics_message(OWNER, "UpdateRecipients")), + Response::default().add_attributes(vec![attr("action", "update_recipients")]), res ); @@ -344,8 +339,7 @@ fn test_execute_send() { ), amp_msg, ]) - .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]) - .add_submessage(generate_economics_message(OWNER, "Send")); + .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]); assert_eq!(res, expected_res); @@ -381,8 +375,7 @@ fn test_execute_send() { ), amp_msg.clone(), ]) - .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]) - .add_submessage(generate_economics_message(OWNER, "Send")); + .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]); assert_eq!(res, expected_res); @@ -430,8 +423,7 @@ fn test_execute_send() { ), amp_msg, ]) - .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]) - .add_submessage(generate_economics_message(OWNER, "Send")); + .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]); assert_eq!(res, expected_res); } @@ -507,8 +499,7 @@ fn test_execute_send_ado_recipient() { amp_msg, ]) .add_attribute("action", "send") - .add_attribute("sender", "creator") - .add_submessage(generate_economics_message(OWNER, "Send")); + .add_attribute("sender", "creator"); assert_eq!(res, expected_res); } @@ -655,8 +646,7 @@ fn test_update_app_contract() { assert_eq!( Response::new() .add_attribute("action", "update_app_contract") - .add_attribute("address", "app_contract") - .add_submessage(generate_economics_message(OWNER, "UpdateAppContract")), + .add_attribute("address", "app_contract"), res ); } diff --git a/contracts/finance/andromeda-timelock/src/testing/tests.rs b/contracts/finance/andromeda-timelock/src/testing/tests.rs index bf6ad24f3..19dccb2b0 100644 --- a/contracts/finance/andromeda-timelock/src/testing/tests.rs +++ b/contracts/finance/andromeda-timelock/src/testing/tests.rs @@ -10,7 +10,6 @@ use andromeda_std::{ common::{expiration::Expiry, Milliseconds}, error::ContractError, }; -use andromeda_testing::economics_msg::generate_economics_message; use cosmwasm_std::{ attr, coin, coins, from_json, testing::{mock_env, mock_info}, @@ -34,17 +33,15 @@ fn test_execute_hold_funds() { }; let res = execute(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); - let expected = Response::default() - .add_attributes(vec![ - attr("action", "hold_funds"), - attr("sender", info.sender.to_string()), - attr( - "recipient", - format!("{:?}", Recipient::from_string(info.sender.to_string())), - ), - attr("condition", format!("{:?}", Some(condition.clone()))), - ]) - .add_submessage(generate_economics_message("owner", "HoldFunds")); + let expected = Response::default().add_attributes(vec![ + attr("action", "hold_funds"), + attr("sender", info.sender.to_string()), + attr( + "recipient", + format!("{:?}", Recipient::from_string(info.sender.to_string())), + ), + attr("condition", format!("{:?}", Some(condition.clone()))), + ]); assert_eq!(expected, res); let query_msg = QueryMsg::GetLockedFunds { @@ -140,13 +137,10 @@ fn test_execute_release_funds_no_condition() { amount: info.funds, }; assert_eq!( - Response::new() - .add_message(bank_msg) - .add_attributes(vec![ - attr("action", "release_funds"), - attr("recipient_addr", "owner"), - ]) - .add_submessage(generate_economics_message(owner, "ReleaseFunds")), + Response::new().add_message(bank_msg).add_attributes(vec![ + attr("action", "release_funds"), + attr("recipient_addr", "owner"), + ]), res ); } @@ -189,8 +183,7 @@ fn test_execute_release_multiple_escrows() { .add_attributes(vec![ attr("action", "release_funds"), attr("recipient_addr", "recipient"), - ]) - .add_submessage(generate_economics_message("sender2", "ReleaseFunds")), + ]), res ); } @@ -224,13 +217,10 @@ fn test_execute_release_funds_time_condition() { amount: info.funds, }; assert_eq!( - Response::new() - .add_message(bank_msg) - .add_attributes(vec![ - attr("action", "release_funds"), - attr("recipient_addr", "owner"), - ]) - .add_submessage(generate_economics_message(owner, "ReleaseFunds")), + Response::new().add_message(bank_msg).add_attributes(vec![ + attr("action", "release_funds"), + attr("recipient_addr", "owner"), + ]), res ); } @@ -308,13 +298,10 @@ fn test_execute_release_funds_min_funds_condition() { amount: vec![coin(210, "uusd"), coin(120, "uluna")], }; assert_eq!( - Response::new() - .add_message(bank_msg) - .add_attributes(vec![ - attr("action", "release_funds"), - attr("recipient_addr", "owner"), - ]) - .add_submessage(generate_economics_message(owner, "ReleaseFunds")), + Response::new().add_message(bank_msg).add_attributes(vec![ + attr("action", "release_funds"), + attr("recipient_addr", "owner"), + ]), res ); } @@ -357,13 +344,10 @@ fn test_execute_release_specific_funds_no_condition() { amount: info.funds, }; assert_eq!( - Response::new() - .add_message(bank_msg) - .add_attributes(vec![ - attr("action", "release_funds"), - attr("recipient_addr", "owner"), - ]) - .add_submessage(generate_economics_message(owner, "ReleaseSpecificFunds")), + Response::new().add_message(bank_msg).add_attributes(vec![ + attr("action", "release_funds"), + attr("recipient_addr", "owner"), + ]), res ); } @@ -396,13 +380,10 @@ fn test_execute_release_specific_funds_time_condition() { amount: info.funds, }; assert_eq!( - Response::new() - .add_message(bank_msg) - .add_attributes(vec![ - attr("action", "release_funds"), - attr("recipient_addr", "owner"), - ]) - .add_submessage(generate_economics_message(owner, "ReleaseSpecificFunds")), + Response::new().add_message(bank_msg).add_attributes(vec![ + attr("action", "release_funds"), + attr("recipient_addr", "owner"), + ]), res ); } @@ -452,13 +433,10 @@ fn test_execute_release_specific_funds_min_funds_condition() { amount: vec![coin(210, "uusd"), coin(120, "uluna")], }; assert_eq!( - Response::new() - .add_message(bank_msg) - .add_attributes(vec![ - attr("action", "release_funds"), - attr("recipient_addr", "owner"), - ]) - .add_submessage(generate_economics_message(owner, "ReleaseSpecificFunds")), + Response::new().add_message(bank_msg).add_attributes(vec![ + attr("action", "release_funds"), + attr("recipient_addr", "owner"), + ]), res ); } diff --git a/contracts/finance/andromeda-weighted-distribution-splitter/src/testing/tests.rs b/contracts/finance/andromeda-weighted-distribution-splitter/src/testing/tests.rs index 5b45e82ee..e4eab1357 100644 --- a/contracts/finance/andromeda-weighted-distribution-splitter/src/testing/tests.rs +++ b/contracts/finance/andromeda-weighted-distribution-splitter/src/testing/tests.rs @@ -1,25 +1,22 @@ -use andromeda_std::amp::AndrAddr; -use andromeda_std::common::expiration::Expiry; -use andromeda_std::common::Milliseconds; -use andromeda_std::testing::mock_querier::{mock_dependencies_custom, MOCK_KERNEL_CONTRACT}; +use andromeda_finance::weighted_splitter::{AddressWeight, ExecuteMsg, InstantiateMsg, Splitter}; use andromeda_std::{ - ado_base::InstantiateMsg as BaseInstantiateMsg, ado_contract::ADOContract, - amp::recipient::Recipient, error::ContractError, + ado_base::InstantiateMsg as BaseInstantiateMsg, + ado_contract::ADOContract, + amp::{recipient::Recipient, AndrAddr}, + common::{expiration::Expiry, Milliseconds}, + error::ContractError, + testing::mock_querier::{mock_dependencies_custom, MOCK_KERNEL_CONTRACT}, }; use cosmwasm_std::{ attr, - testing::{mock_env, mock_info}, - Response, Uint128, + testing::{mock_dependencies, mock_env, mock_info}, + BankMsg, Coin, CosmosMsg, DepsMut, QuerierWrapper, Response, SubMsg, Uint128, }; -use cosmwasm_std::{BankMsg, Coin, CosmosMsg, DepsMut, QuerierWrapper, SubMsg}; use crate::{ contract::{execute, instantiate}, state::SPLITTER, }; -use andromeda_finance::weighted_splitter::{AddressWeight, ExecuteMsg, InstantiateMsg, Splitter}; -use andromeda_testing::economics_msg::generate_economics_message; -use cosmwasm_std::testing::mock_dependencies; const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); const MOCK_RECIPIENT1: &str = "recipient1"; const MOCK_RECIPIENT2: &str = "recipient2"; @@ -74,8 +71,7 @@ fn test_update_app_contract() { assert_eq!( Response::new() .add_attribute("action", "update_app_contract") - .add_attribute("address", "app_contract") - .add_submessage(generate_economics_message("owner", "UpdateAppContract")), + .add_attribute("address", "app_contract"), res ); } @@ -184,12 +180,10 @@ fn test_execute_update_lock() { .plus_seconds(current_time) .plus_milliseconds(Milliseconds(879)); assert_eq!( - Response::default() - .add_attributes(vec![ - attr("action", "update_lock"), - attr("locked", new_lock.to_string()) - ]) - .add_submessage(generate_economics_message(OWNER, "UpdateLock")), + Response::default().add_attributes(vec![ + attr("action", "update_lock"), + attr("locked", new_lock.to_string()) + ]), res ); @@ -457,9 +451,7 @@ fn test_execute_remove_recipient() { }; assert_eq!(expected_splitter, splitter); assert_eq!( - Response::default() - .add_attributes(vec![attr("action", "removed_recipient")]) - .add_submessage(generate_economics_message(OWNER, "RemoveRecipient")), + Response::default().add_attributes(vec![attr("action", "removed_recipient")]), res ); @@ -735,9 +727,7 @@ fn test_update_recipient_weight() { }; let res = execute(deps.as_mut(), env, info, msg).unwrap(); assert_eq!( - Response::default() - .add_attributes(vec![attr("action", "updated_recipient_weight")]) - .add_submessage(generate_economics_message(OWNER, "UpdateRecipientWeight")), + Response::default().add_attributes(vec![attr("action", "updated_recipient_weight")]), res ); let splitter = SPLITTER.load(deps.as_ref().storage).unwrap(); @@ -1045,9 +1035,7 @@ fn test_execute_add_recipient() { let res = execute(deps.as_mut(), env, info, msg).unwrap(); assert_eq!( - Response::default() - .add_attributes(vec![attr("action", "added_recipient")]) - .add_submessage(generate_economics_message(OWNER, "AddRecipient")), + Response::default().add_attributes(vec![attr("action", "added_recipient")]), res ); @@ -1154,9 +1142,7 @@ fn test_execute_add_recipient_duplicate_recipient() { let res = execute(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); assert_eq!( - Response::default() - .add_attributes(vec![attr("action", "added_recipient")]) - .add_submessage(generate_economics_message(OWNER, "AddRecipient")), + Response::default().add_attributes(vec![attr("action", "added_recipient")]), res ); // Add a duplicate user @@ -1388,9 +1374,7 @@ fn test_execute_update_recipients() { let info = mock_info(owner, &[]); let res = execute(deps.as_mut(), env, info, msg).unwrap(); assert_eq!( - Response::default() - .add_attributes(vec![attr("action", "update_recipients")]) - .add_submessage(generate_economics_message(OWNER, "UpdateRecipients")), + Response::default().add_attributes(vec![attr("action", "update_recipients")]), res ); @@ -1637,8 +1621,7 @@ fn test_execute_send() { }), ), ]) - .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]) - .add_submessage(generate_economics_message(OWNER, "Send")); + .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]); assert_eq!(res, expected_res); @@ -1659,8 +1642,7 @@ fn test_execute_send() { ), // amp_msg, ]) - .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]) - .add_submessage(generate_economics_message(OWNER, "Send")); + .add_attributes(vec![attr("action", "send"), attr("sender", "creator")]); assert_eq!(res, expected_res); } diff --git a/contracts/fungible-tokens/andromeda-cw20-staking/src/testing/tests.rs b/contracts/fungible-tokens/andromeda-cw20-staking/src/testing/tests.rs index db400829e..430e9ca9a 100644 --- a/contracts/fungible-tokens/andromeda-cw20-staking/src/testing/tests.rs +++ b/contracts/fungible-tokens/andromeda-cw20-staking/src/testing/tests.rs @@ -27,7 +27,6 @@ use andromeda_fungible_tokens::cw20_staking::{ AllocationConfig, AllocationState, Config, Cw20HookMsg, ExecuteMsg, InstantiateMsg, QueryMsg, RewardToken, RewardTokenUnchecked, RewardType, StakerResponse, State, }; -use andromeda_testing::economics_msg::generate_economics_message; use cw_asset::{AssetInfo, AssetInfoUnchecked}; const MOCK_STAKING_TOKEN: &str = "staking_token"; @@ -353,8 +352,7 @@ fn test_stake_unstake_tokens() { .add_attribute("action", "stake_tokens") .add_attribute("sender", "sender") .add_attribute("share", "100") - .add_attribute("amount", "100") - .add_submessage(generate_economics_message(MOCK_STAKING_TOKEN, "Receive")), + .add_attribute("amount", "100"), res ); @@ -392,8 +390,7 @@ fn test_stake_unstake_tokens() { .add_attribute("action", "stake_tokens") .add_attribute("sender", "other_sender") .add_attribute("share", "50") - .add_attribute("amount", "100") - .add_submessage(generate_economics_message(MOCK_STAKING_TOKEN, "Receive")), + .add_attribute("amount", "100"), res ); @@ -445,8 +442,7 @@ fn test_stake_unstake_tokens() { amount: Uint128::new(200) }) .unwrap() - }) - .add_submessage(generate_economics_message("sender", "UnstakeTokens")), + }), res ); @@ -489,8 +485,7 @@ fn test_stake_unstake_tokens() { amount: Uint128::new(100) }) .unwrap() - }) - .add_submessage(generate_economics_message("other_sender", "UnstakeTokens")), + }), res ); @@ -587,8 +582,7 @@ fn test_update_global_indexes() { .add_attribute("action", "update_global_indexes") .add_attribute("cw20:incentive_token", "0.2") .add_attribute("native:uandr", "0") - .add_attribute("native:uusd", "0.4") - .add_submessage(generate_economics_message("owner", "UpdateGlobalIndexes")), + .add_attribute("native:uusd", "0.4"), res ); @@ -648,8 +642,7 @@ fn test_update_global_indexes() { .add_attribute("action", "update_global_indexes") .add_attribute("cw20:incentive_token", "0.2") .add_attribute("native:uandr", "0.4") - .add_attribute("native:uusd", "0.4") - .add_submessage(generate_economics_message("owner", "UpdateGlobalIndexes")), + .add_attribute("native:uusd", "0.4"), res ); @@ -720,8 +713,7 @@ fn test_update_global_indexes_selective() { assert_eq!( Response::new() .add_attribute("action", "update_global_indexes") - .add_attribute("native:uusd", "0.4") - .add_submessage(generate_economics_message("owner", "UpdateGlobalIndexes")), + .add_attribute("native:uusd", "0.4"), res ); @@ -854,8 +846,7 @@ fn test_update_global_indexes_cw20_deposit() { assert_eq!( Response::new() .add_attribute("action", "update_global_indexes") - .add_attribute("cw20:incentive_token", "0.2") - .add_submessage(generate_economics_message(MOCK_INCENTIVE_TOKEN, "Receive")), + .add_attribute("cw20:incentive_token", "0.2"), res ); @@ -1007,7 +998,7 @@ fn test_claim_rewards() { let info = mock_info("user1", &[]); let msg = ExecuteMsg::ClaimRewards {}; - let res = execute(deps.as_mut(), mock_env(), info, msg).unwrap(); + let res = execute(deps.as_mut(), mock_env(), info, msg); assert_eq!( StakerRewardInfo { @@ -1040,9 +1031,8 @@ fn test_claim_rewards() { .add_message(BankMsg::Send { to_address: "user1".to_string(), amount: coins(66, "uusd") - }) - .add_submessage(generate_economics_message("user1", "ClaimRewards")), - res + }), + res.unwrap() ); deps.querier @@ -1051,7 +1041,7 @@ fn test_claim_rewards() { let info = mock_info("user2", &[]); let msg = ExecuteMsg::ClaimRewards {}; - let res = execute(deps.as_mut(), mock_env(), info, msg).unwrap(); + let res = execute(deps.as_mut(), mock_env(), info, msg); assert_eq!( Response::new() @@ -1059,9 +1049,8 @@ fn test_claim_rewards() { .add_message(BankMsg::Send { to_address: "user2".to_string(), amount: coins(33, "uusd") - }) - .add_submessage(generate_economics_message("user2", "ClaimRewards")), - res + }), + res.unwrap() ); assert_eq!( @@ -1227,8 +1216,7 @@ fn test_claim_rewards_allocated() { amount: Uint128::new(25) }) .unwrap(), - }) - .add_submessage(generate_economics_message("user1", "ClaimRewards")), + }), res ); @@ -1284,8 +1272,7 @@ fn test_claim_rewards_allocated() { amount: Uint128::new(25) }) .unwrap(), - }) - .add_submessage(generate_economics_message("user2", "ClaimRewards")), + }), res ); @@ -1406,8 +1393,7 @@ fn test_claim_rewards_allocated_init_timestamp_in_future() { amount: Uint128::new(25) }) .unwrap(), - }) - .add_submessage(generate_economics_message("user1", "ClaimRewards")), + }), res ); @@ -1462,8 +1448,7 @@ fn test_claim_rewards_allocated_init_timestamp_in_future() { amount: Uint128::new(25) }) .unwrap(), - }) - .add_submessage(generate_economics_message("user2", "ClaimRewards")), + }), res ); @@ -1857,8 +1842,7 @@ fn test_add_reward_token() { assert_eq!( Response::new() .add_attribute("action", "add_reward_token") - .add_attribute("added_token", "cw20:incentive_token") - .add_submessage(generate_economics_message("owner", "AddRewardToken")), + .add_attribute("added_token", "cw20:incentive_token"), res ); @@ -2013,8 +1997,7 @@ fn test_remove_reward_token() { Response::new() .add_attribute("action", "remove_reward_token") .add_attribute("number_of_reward_tokens", "0") - .add_attribute("removed_token", "native:uusd") - .add_submessage(generate_economics_message("owner", "RemoveRewardToken")), + .add_attribute("removed_token", "native:uusd"), res ); @@ -2204,8 +2187,7 @@ fn test_claim_rewards_after_remove() { .add_message(BankMsg::Send { to_address: "user1".to_string(), amount: coins(66, "uusd") - }) - .add_submessage(generate_economics_message("user1", "ClaimRewards")), + }), res ); @@ -2229,8 +2211,7 @@ fn test_claim_rewards_after_remove() { .add_message(BankMsg::Send { to_address: "user2".to_string(), amount: coins(33, "uusd") - }) - .add_submessage(generate_economics_message("user2", "ClaimRewards")), + }), res ); @@ -2362,8 +2343,7 @@ fn test_claim_rewards_allocated_after_remove() { amount: Uint128::new(25) }) .unwrap(), - }) - .add_submessage(generate_economics_message("user", "ClaimRewards")), + }), res ); @@ -2433,8 +2413,7 @@ fn test_replace_reward_token() { Response::new() .add_attribute("action", "replace_reward_token") .add_attribute("origin_reward_token", "native:uusd") - .add_attribute("new_reward_token", format!("cw20:{MOCK_INCENTIVE_TOKEN}")) - .add_submessage(generate_economics_message("owner", "ReplaceRewardToken")), + .add_attribute("new_reward_token", format!("cw20:{MOCK_INCENTIVE_TOKEN}")), res ); diff --git a/contracts/fungible-tokens/andromeda-cw20/src/testing/tests.rs b/contracts/fungible-tokens/andromeda-cw20/src/testing/tests.rs index 6bc3115c2..c4851ccf6 100644 --- a/contracts/fungible-tokens/andromeda-cw20/src/testing/tests.rs +++ b/contracts/fungible-tokens/andromeda-cw20/src/testing/tests.rs @@ -8,7 +8,6 @@ use andromeda_std::amp::{AndrAddr, Recipient}; use andromeda_std::common::context::ExecuteContext; use andromeda_std::{error::ContractError, testing::mock_querier::MOCK_KERNEL_CONTRACT}; -use andromeda_testing::economics_msg::generate_economics_message; use cosmwasm_std::{attr, Decimal, Event}; use cosmwasm_std::{ testing::{mock_env, mock_info}, @@ -140,8 +139,7 @@ fn test_transfer() { .add_attribute("action", "transfer") .add_attribute("from", "sender") .add_attribute("to", "other") - .add_attribute("amount", "90") - .add_submessage(generate_economics_message("sender", "Transfer")), + .add_attribute("amount", "90"), res ); @@ -236,8 +234,7 @@ fn test_send() { .into_cosmos_msg("contract") .unwrap(), ) - .add_event(expected_event) - .add_submessage(generate_economics_message("sender", "Send")), + .add_event(expected_event), res ); diff --git a/contracts/fungible-tokens/andromeda-ics20/src/testing/tests.rs b/contracts/fungible-tokens/andromeda-ics20/src/testing/tests.rs index b67b6b71c..715709929 100644 --- a/contracts/fungible-tokens/andromeda-ics20/src/testing/tests.rs +++ b/contracts/fungible-tokens/andromeda-ics20/src/testing/tests.rs @@ -1,25 +1,27 @@ -use crate::contract::{execute, instantiate, query}; -use crate::testing::mock_querier::mock_dependencies_custom; +use crate::{ + contract::{execute, instantiate, query}, + testing::mock_querier::{mock_dependencies_custom, MOCK_CW20_CONTRACT}, +}; use andromeda_fungible_tokens::cw20::{ExecuteMsg, InstantiateMsg, QueryMsg}; -use andromeda_std::ado_base::permissioning::Permission; -use andromeda_std::ado_base::rates::{LocalRate, LocalRateType, LocalRateValue, PercentRate, Rate}; -use andromeda_std::ado_contract::ADOContract; -use andromeda_std::amp::{AndrAddr, Recipient}; -use andromeda_std::common::context::ExecuteContext; - -use andromeda_std::{error::ContractError, testing::mock_querier::MOCK_KERNEL_CONTRACT}; -use andromeda_testing::economics_msg::generate_economics_message; -use cosmwasm_std::{attr, Decimal, Event}; +use andromeda_std::{ + ado_base::{ + permissioning::Permission, + rates::{LocalRate, LocalRateType, LocalRateValue, PercentRate, Rate}, + }, + ado_contract::ADOContract, + amp::{AndrAddr, Recipient}, + common::context::ExecuteContext, + error::ContractError, + testing::mock_querier::MOCK_KERNEL_CONTRACT, +}; use cosmwasm_std::{ + attr, testing::{mock_env, mock_info}, - to_json_binary, Addr, DepsMut, Response, Uint128, + to_json_binary, Addr, Decimal, DepsMut, Event, Response, Uint128, }; - use cw20::{Cw20Coin, Cw20ReceiveMsg}; use cw20_base::state::BALANCES; -use super::mock_querier::MOCK_CW20_CONTRACT; - fn init(deps: DepsMut) -> Response { let msg = InstantiateMsg { name: MOCK_CW20_CONTRACT.into(), @@ -140,8 +142,7 @@ fn test_transfer() { .add_attribute("action", "transfer") .add_attribute("from", "sender") .add_attribute("to", "other") - .add_attribute("amount", "90") - .add_submessage(generate_economics_message("sender", "Transfer")), + .add_attribute("amount", "90"), res ); @@ -236,8 +237,7 @@ fn test_send() { .into_cosmos_msg("contract") .unwrap(), ) - .add_event(expected_event) - .add_submessage(generate_economics_message("sender", "Send")), + .add_event(expected_event), res ); diff --git a/contracts/fungible-tokens/andromeda-lockdrop/src/testing/tests.rs b/contracts/fungible-tokens/andromeda-lockdrop/src/testing/tests.rs index 96e658de2..07cf25d20 100644 --- a/contracts/fungible-tokens/andromeda-lockdrop/src/testing/tests.rs +++ b/contracts/fungible-tokens/andromeda-lockdrop/src/testing/tests.rs @@ -15,7 +15,6 @@ use andromeda_std::{ error::ContractError, testing::mock_querier::MOCK_KERNEL_CONTRACT, }; -use andromeda_testing::economics_msg::generate_economics_message; use cosmwasm_std::{ coin, coins, from_json, testing::{mock_env, mock_info}, @@ -203,8 +202,7 @@ fn test_increase_incentives() { assert_eq!( Response::new() .add_attribute("action", "incentives_increased") - .add_attribute("amount", "100") - .add_submessage(generate_economics_message(MOCK_INCENTIVE_TOKEN, "Receive")), + .add_attribute("amount", "100"), res ); @@ -301,8 +299,7 @@ fn test_deposit_native() { Response::new() .add_attribute("action", "lock_native") .add_attribute("user", "sender") - .add_attribute("ust_deposited", "100") - .add_submessage(generate_economics_message("sender", "DepositNative")), + .add_attribute("ust_deposited", "100"), res ); @@ -419,8 +416,7 @@ fn test_withdraw_native() { }) .add_attribute("action", "withdraw_native") .add_attribute("user", "sender") - .add_attribute("amount", "100") - .add_submessage(generate_economics_message("sender", "WithdrawNative")), + .add_attribute("amount", "100"), res ); @@ -701,9 +697,7 @@ fn test_enable_claims_no_bootstrap_specified() { let res = execute(deps.as_mut(), env.clone(), info.clone(), msg.clone()).unwrap(); assert_eq!( - Response::new() - .add_attribute("action", "enable_claims") - .add_submessage(generate_economics_message("sender", "EnableClaims")), + Response::new().add_attribute("action", "enable_claims"), res ); @@ -858,8 +852,7 @@ fn test_claim_rewards() { amount: Uint128::new(75) }) .unwrap() - }) - .add_submessage(generate_economics_message("user1", "ClaimRewards")), + }), res ); @@ -897,8 +890,7 @@ fn test_claim_rewards() { amount: Uint128::new(25) }) .unwrap() - }) - .add_submessage(generate_economics_message("user2", "ClaimRewards")), + }), res ); diff --git a/contracts/fungible-tokens/andromeda-merkle-airdrop/src/testing/tests.rs b/contracts/fungible-tokens/andromeda-merkle-airdrop/src/testing/tests.rs index 8184c8169..0cc25afab 100644 --- a/contracts/fungible-tokens/andromeda-merkle-airdrop/src/testing/tests.rs +++ b/contracts/fungible-tokens/andromeda-merkle-airdrop/src/testing/tests.rs @@ -9,7 +9,6 @@ use andromeda_std::{ error::ContractError, testing::mock_querier::{MOCK_CW20_CONTRACT, MOCK_KERNEL_CONTRACT}, }; -use andromeda_testing::economics_msg::generate_economics_message; use cosmwasm_schema::{cw_serde, serde::Deserialize}; use cosmwasm_std::{ attr, coin, from_json, @@ -169,13 +168,7 @@ fn test_claim() { }) .unwrap(), })); - assert_eq!( - res.messages, - vec![ - expected, - generate_economics_message(test_data.account.as_str(), "Claim") - ] - ); + assert_eq!(res.messages, vec![expected]); assert_eq!( res.attributes, @@ -256,13 +249,7 @@ fn test_claim() { }) .unwrap(), })); - assert_eq!( - res.messages, - vec![ - expected, - generate_economics_message(test_data.account.as_str(), "Claim") - ] - ); + assert_eq!(res.messages, vec![expected]); assert_eq!( res.attributes, @@ -341,13 +328,7 @@ fn test_claim_native() { denom: MOCK_NATIVE_DENOM.to_string(), }], })); - assert_eq!( - res.messages, - vec![ - expected, - generate_economics_message(test_data.account.as_str(), "Claim") - ] - ); + assert_eq!(res.messages, vec![expected]); assert_eq!( res.attributes, @@ -437,13 +418,7 @@ fn test_multiple_claim() { }) .unwrap(), })); - assert_eq!( - res.messages, - vec![ - expected, - generate_economics_message(account.account.as_str(), "Claim") - ] - ); + assert_eq!(res.messages, vec![expected]); assert_eq!( res.attributes, @@ -588,13 +563,7 @@ fn test_can_burn() { }) .unwrap(), })); - assert_eq!( - res.messages, - vec![ - expected, - generate_economics_message(test_data.account.as_str(), "Claim") - ] - ); + assert_eq!(res.messages, vec![expected]); assert_eq!( res.attributes, @@ -623,10 +592,7 @@ fn test_can_burn() { }) .unwrap(), })); - assert_eq!( - res.messages, - vec![expected, generate_economics_message("owner0000", "Burn")] - ); + assert_eq!(res.messages, vec![expected]); assert_eq!( res.attributes, @@ -688,10 +654,7 @@ fn test_can_burn_native() { denom: MOCK_NATIVE_DENOM.to_string(), }], })); - assert_eq!( - res.messages, - vec![expected, generate_economics_message("owner0000", "Burn")] - ); + assert_eq!(res.messages, vec![expected]); assert_eq!( res.attributes, diff --git a/contracts/modules/andromeda-rates/src/testing/tests.rs b/contracts/modules/andromeda-rates/src/testing/tests.rs index e940dd380..82fec5888 100644 --- a/contracts/modules/andromeda-rates/src/testing/tests.rs +++ b/contracts/modules/andromeda-rates/src/testing/tests.rs @@ -3,19 +3,16 @@ use crate::testing::mock_querier::{ mock_dependencies_custom, MOCK_KERNEL_CONTRACT, MOCK_OWNER, MOCK_RECIPIENT1, }; use andromeda_modules::rates::{ExecuteMsg, InstantiateMsg, QueryMsg, RateResponse}; - -use andromeda_std::ado_base::rates::{LocalRate, LocalRateType, LocalRateValue, RatesResponse}; -use andromeda_std::amp::AndrAddr; -use andromeda_std::common::Funds; -use andromeda_std::testing::mock_querier::{MOCK_CW20_CONTRACT, MOCK_UANDR}; -use andromeda_std::{amp::recipient::Recipient, common::encode_binary}; - -use andromeda_testing::economics_msg::generate_economics_message; -use cosmwasm_std::{attr, Event}; +use andromeda_std::{ + ado_base::rates::{LocalRate, LocalRateType, LocalRateValue, RatesResponse}, + amp::{recipient::Recipient, AndrAddr}, + common::{encode_binary, Funds}, + testing::mock_querier::{MOCK_CW20_CONTRACT, MOCK_UANDR}, +}; use cosmwasm_std::{ - coin, coins, + attr, coin, coins, testing::{mock_env, mock_info}, - BankMsg, CosmosMsg, Response, SubMsg, WasmMsg, + BankMsg, CosmosMsg, Event, Response, SubMsg, WasmMsg, }; use cw20::{Cw20Coin, Cw20ExecuteMsg}; @@ -84,9 +81,7 @@ fn test_andr_receive() { let res = execute(deps.as_mut(), env, info, msg).unwrap(); assert_eq!( - Response::new() - .add_attributes(vec![attr("action", "set_rate")]) - .add_submessage(generate_economics_message("owner", "SetRate")), + Response::new().add_attributes(vec![attr("action", "set_rate")]), res ); } diff --git a/contracts/non-fungible-tokens/andromeda-auction/src/testing/tests.rs b/contracts/non-fungible-tokens/andromeda-auction/src/testing/tests.rs index 91d882573..1937ab603 100644 --- a/contracts/non-fungible-tokens/andromeda-auction/src/testing/tests.rs +++ b/contracts/non-fungible-tokens/andromeda-auction/src/testing/tests.rs @@ -24,19 +24,16 @@ use andromeda_std::{ denom::Asset, encode_binary, expiration::{Expiry, MILLISECONDS_TO_NANOSECONDS_RATIO}, - reply::ReplyId, Milliseconds, }, error::ContractError, - os::economics::ExecuteMsg as EconomicsExecuteMsg, testing::mock_querier::MOCK_KERNEL_CONTRACT, }; use andromeda_std::{amp::Recipient, testing::mock_querier::MOCK_CW20_CONTRACT}; use cosmwasm_std::{ attr, coin, coins, from_json, testing::{mock_dependencies, mock_env, mock_info}, - to_json_binary, Addr, BankMsg, CosmosMsg, Decimal, Deps, DepsMut, Env, Response, SubMsg, - Timestamp, Uint128, WasmMsg, + Addr, BankMsg, CosmosMsg, Decimal, Deps, DepsMut, Env, Response, Timestamp, Uint128, WasmMsg, }; use cw20::{Cw20ExecuteMsg, Cw20ReceiveMsg}; use cw721::Cw721ReceiveMsg; @@ -579,26 +576,12 @@ fn execute_place_bid_multiple_bids() { let res = execute(deps.as_mut(), env.clone(), info.clone(), msg.clone()).unwrap(); assert_eq!( - Response::new() - .add_attributes(vec![ - attr("action", "bid"), - attr("token_id", MOCK_UNCLAIMED_TOKEN), - attr("bidder", info.sender), - attr("amount", "100"), - ]) - // Economics message - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked("sender"), - action: "PlaceBid".to_string() - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - )), + Response::new().add_attributes(vec![ + attr("action", "bid"), + attr("token_id", MOCK_UNCLAIMED_TOKEN), + attr("bidder", info.sender), + attr("amount", "100"), + ]), res ); let mut expected_response = AuctionStateResponse { @@ -634,20 +617,7 @@ fn execute_place_bid_multiple_bids() { attr("token_id", MOCK_UNCLAIMED_TOKEN), attr("bidder", info.sender), attr("amount", "200"), - ]) - // Economics message - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked("other"), - action: "PlaceBid".to_string() - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - )), + ]), res ); @@ -671,20 +641,7 @@ fn execute_place_bid_multiple_bids() { attr("token_id", MOCK_UNCLAIMED_TOKEN), attr("bidder", info.sender), attr("amount", "250"), - ]) - // Economics message - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked("sender"), - action: "PlaceBid".to_string() - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - )), + ]), res ); @@ -1160,27 +1117,14 @@ fn execute_start_auction_after_previous_finished() { let info = mock_info(MOCK_TOKEN_ADDR, &[]); let res = execute(deps.as_mut(), env, info, msg).unwrap(); assert_eq!( - Response::new() - .add_attributes(vec![ - attr("action", "start_auction"), - attr("start_time", "expiration time: 1571801019.880000000"), - attr("end_time", "expiration time: 1571817419.879000000"), - attr("coin_denom", "uusd"), - attr("auction_id", "2"), - attr("whitelist", "None"), - ]) // Economics message - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked(MOCK_TOKEN_ADDR), - action: "ReceiveNft".to_string() - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - )), + Response::new().add_attributes(vec![ + attr("action", "start_auction"), + attr("start_time", "expiration time: 1571801019.880000000"), + attr("end_time", "expiration time: 1571817419.879000000"), + attr("coin_denom", "uusd"), + attr("auction_id", "2"), + attr("whitelist", "None"), + ]), res ); } @@ -1219,20 +1163,7 @@ fn execute_claim_no_bids() { .add_attribute("token_contract", MOCK_TOKEN_ADDR) .add_attribute("recipient", MOCK_TOKEN_OWNER) .add_attribute("winning_bid_amount", Uint128::zero()) - .add_attribute("auction_id", "1") - // Economics message - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked("any_user"), - action: "Claim".to_string() - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - )), + .add_attribute("auction_id", "1"), res ); } @@ -1271,20 +1202,7 @@ fn execute_claim_no_bids_cw20() { .add_attribute("token_contract", MOCK_TOKEN_ADDR) .add_attribute("recipient", MOCK_TOKEN_OWNER) .add_attribute("winning_bid_amount", Uint128::zero()) - .add_attribute("auction_id", "1") - // Economics message - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked("any_user"), - action: "Claim".to_string() - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - )), + .add_attribute("auction_id", "1"), res ); } @@ -1358,20 +1276,7 @@ fn execute_claim_with_tax() { .add_attribute("token_contract", MOCK_TOKEN_ADDR) .add_attribute("recipient", "sender") .add_attribute("winning_bid_amount", Uint128::from(100u128)) - .add_attribute("auction_id", "1") - // Economics message - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked("any_user"), - action: "Claim".to_string() - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - )), + .add_attribute("auction_id", "1"), res ); } @@ -1434,20 +1339,7 @@ fn execute_buy_now() { .add_attribute("token_contract", MOCK_TOKEN_ADDR) .add_attribute("recipient", "sender_2") .add_attribute("bought_at", Uint128::from(500u128)) - .add_attribute("auction_id", "1") - // Economics message - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked("sender_2"), - action: "BuyNow".to_string() - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - )), + .add_attribute("auction_id", "1"), res ); @@ -1535,20 +1427,7 @@ fn execute_claim_with_royalty() { .add_attribute("token_contract", MOCK_TOKEN_ADDR) .add_attribute("recipient", "sender") .add_attribute("winning_bid_amount", Uint128::from(100u128)) - .add_attribute("auction_id", "1") - // Economics message - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked("any_user"), - action: "Claim".to_string() - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - )), + .add_attribute("auction_id", "1"), res ); } @@ -1611,20 +1490,7 @@ fn execute_claim_cw20() { .add_attribute("token_contract", MOCK_TOKEN_ADDR) .add_attribute("recipient", "sender") .add_attribute("winning_bid_amount", Uint128::from(100u128)) - .add_attribute("auction_id", "1") - // Economics message - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked("any_user"), - action: "Claim".to_string() - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - )), + .add_attribute("auction_id", "1"), res ); } @@ -1714,20 +1580,7 @@ fn execute_claim_cw20_with_tax() { .add_attribute("token_contract", MOCK_TOKEN_ADDR) .add_attribute("recipient", "sender") .add_attribute("winning_bid_amount", Uint128::from(100u128)) - .add_attribute("auction_id", "1") - // Economics message - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked("any_user"), - action: "Claim".to_string() - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - )), + .add_attribute("auction_id", "1"), res ); } @@ -1817,29 +1670,15 @@ fn execute_cancel_no_bids() { let res = execute(deps.as_mut(), env, info, msg).unwrap(); assert_eq!( - Response::new() - .add_message(CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: MOCK_TOKEN_ADDR.to_owned(), - msg: encode_binary(&Cw721ExecuteMsg::TransferNft { - recipient: AndrAddr::from_string(MOCK_TOKEN_OWNER.to_owned()), - token_id: MOCK_UNCLAIMED_TOKEN.to_owned() - }) - .unwrap(), - funds: vec![], - })) - // Economics message - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked("owner"), - action: "CancelAuction".to_string() - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - )), + Response::new().add_message(CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: MOCK_TOKEN_ADDR.to_owned(), + msg: encode_binary(&Cw721ExecuteMsg::TransferNft { + recipient: AndrAddr::from_string(MOCK_TOKEN_OWNER.to_owned()), + token_id: MOCK_UNCLAIMED_TOKEN.to_owned() + }) + .unwrap(), + funds: vec![], + })), res ); @@ -1868,29 +1707,15 @@ fn execute_cancel_no_bids_cw20() { let res = execute(deps.as_mut(), env, info, msg).unwrap(); assert_eq!( - Response::new() - .add_message(CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: MOCK_TOKEN_ADDR.to_owned(), - msg: encode_binary(&Cw721ExecuteMsg::TransferNft { - recipient: AndrAddr::from_string(MOCK_TOKEN_OWNER.to_owned()), - token_id: MOCK_UNCLAIMED_TOKEN.to_owned() - }) - .unwrap(), - funds: vec![], - })) - // Economics message - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked("owner"), - action: "CancelAuction".to_string() - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - )), + Response::new().add_message(CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: MOCK_TOKEN_ADDR.to_owned(), + msg: encode_binary(&Cw721ExecuteMsg::TransferNft { + recipient: AndrAddr::from_string(MOCK_TOKEN_OWNER.to_owned()), + token_id: MOCK_UNCLAIMED_TOKEN.to_owned() + }) + .unwrap(), + funds: vec![], + })), res ); @@ -1942,20 +1767,7 @@ fn execute_cancel_with_bids() { .add_message(CosmosMsg::Bank(BankMsg::Send { to_address: "bidder".to_string(), amount: coins(100, "uusd") - })) - // Economics message - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked("owner"), - action: "CancelAuction".to_string() - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - )), + })), res ); @@ -2022,20 +1834,7 @@ fn execute_cancel_with_bids_cw20() { }) .unwrap(), funds: vec![] - })) - // Economics message - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked("owner"), - action: "CancelAuction".to_string() - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - )), + })), res ); diff --git a/contracts/non-fungible-tokens/andromeda-crowdfund/src/testing/tests.rs b/contracts/non-fungible-tokens/andromeda-crowdfund/src/testing/tests.rs index 0930b3d61..e1df1d13c 100644 --- a/contracts/non-fungible-tokens/andromeda-crowdfund/src/testing/tests.rs +++ b/contracts/non-fungible-tokens/andromeda-crowdfund/src/testing/tests.rs @@ -7,15 +7,14 @@ use andromeda_non_fungible_tokens::{ }; use andromeda_std::common::expiration::Expiry; use andromeda_std::{ - common::{reply::ReplyId, MillisecondsExpiration}, + common::MillisecondsExpiration, error::ContractError, - os::economics::ExecuteMsg as EconomicsExecuteMsg, testing::mock_querier::{MOCK_ADO_PUBLISHER, MOCK_KERNEL_CONTRACT}, }; use cosmwasm_std::{ testing::{mock_env, mock_info}, - to_json_binary, Addr, CosmosMsg, DepsMut, Env, Order, Response, Storage, SubMsg, Uint128, - Uint64, WasmMsg, + to_json_binary, Addr, CosmosMsg, DepsMut, Env, Order, Response, Storage, Uint128, Uint64, + WasmMsg, }; use crate::{ @@ -250,20 +249,7 @@ mod test { .add_attribute("level", valid_tier.level.to_string()) .add_attribute("label", valid_tier.label.clone()) .add_attribute("price", valid_tier.price.to_string()) - .add_attribute("limit", valid_tier.limit.unwrap().to_string()) - // Economics message - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked(MOCK_DEFAULT_OWNER), - action: "AddTier".to_string(), - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - ))), + .add_attribute("limit", valid_tier.limit.unwrap().to_string())), }, TierTestCase { name: "add_tier with unauthorized sender".to_string(), @@ -356,20 +342,7 @@ mod test { .add_attribute("level", valid_tier.level.to_string()) .add_attribute("label", valid_tier.label.clone()) .add_attribute("price", valid_tier.price.to_string()) - .add_attribute("limit", valid_tier.limit.unwrap().to_string()) - // Economics message - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked(MOCK_DEFAULT_OWNER), - action: "UpdateTier".to_string(), - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - ))), + .add_attribute("limit", valid_tier.limit.unwrap().to_string())), }, TierTestCase { name: "update_tier with unauthorized sender".to_string(), @@ -459,19 +432,7 @@ mod test { payee: MOCK_DEFAULT_OWNER.to_string(), expected_res: Ok(Response::new() .add_attribute("action", "remove_tier") - .add_attribute("level", valid_tier.level.to_string()) - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked(MOCK_DEFAULT_OWNER), - action: "RemoveTier".to_string(), - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - ))), + .add_attribute("level", valid_tier.level.to_string())), }, TierTestCase { name: "remove_tier with unauthorized sender".to_string(), @@ -554,19 +515,7 @@ mod test { .add_attribute( "end_time", Expiry::FromNow(Milliseconds::from_seconds(100)).to_string(), - ) - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked(MOCK_DEFAULT_OWNER), - action: "StartCampaign".to_string(), - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - ))), + )), }, StartCampaignTestCase { name: "start_campaign with unauthorized sender".to_string(), @@ -701,19 +650,7 @@ mod test { to_address: buyer.to_string(), // Refund sent back as they only were able to mint one. amount: coins(900, MOCK_NATIVE_DENOM), - }) - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked(buyer), - action: "PurchaseTiers".to_string(), - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - ))), + })), payee: buyer.to_string(), start_time: Some(past_time()), end_time: future_time(&env), @@ -907,19 +844,7 @@ mod test { vec![], ) .unwrap(), - ) - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked(MOCK_CW20_CONTRACT), - action: "Receive".to_string(), - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - ))), + )), payee: buyer.to_string(), start_time: Some(past_time()), end_time: future_time(&env), @@ -1128,19 +1053,7 @@ mod test { expected_res: Ok(Response::new() .add_attribute("action", "end_campaign") .add_attribute("result", CampaignStage::SUCCESS.to_string()) - .add_submessage(amp_msg) - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked(MOCK_DEFAULT_OWNER.to_string()), - action: "EndCampaign".to_string(), - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - ))), + .add_submessage(amp_msg)), expected_stage: CampaignStage::SUCCESS, }, EndCampaignTestCase { @@ -1164,19 +1077,7 @@ mod test { vec![], ) .unwrap(), - ) - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked(MOCK_DEFAULT_OWNER.to_string()), - action: "EndCampaign".to_string(), - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - ))), + )), expected_stage: CampaignStage::SUCCESS, }, EndCampaignTestCase { @@ -1189,19 +1090,7 @@ mod test { denom: Asset::Cw20Token(AndrAddr::from_string(MOCK_CW20_CONTRACT.to_string())), expected_res: Ok(Response::new() .add_attribute("action", "end_campaign") - .add_attribute("result", CampaignStage::FAILED.to_string()) - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked(MOCK_DEFAULT_OWNER.to_string()), - action: "EndCampaign".to_string(), - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - ))), + .add_attribute("result", CampaignStage::FAILED.to_string())), expected_stage: CampaignStage::FAILED, }, EndCampaignTestCase { @@ -1314,19 +1203,7 @@ mod test { denom: Asset::NativeToken(MOCK_NATIVE_DENOM.to_string()), expected_res: Ok(Response::new() .add_attribute("action", "discard_campaign") - .add_attribute("result", "DISCARDED") - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked(MOCK_DEFAULT_OWNER), - action: "DiscardCampaign".to_string(), - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - ))), + .add_attribute("result", "DISCARDED")), expected_stage: CampaignStage::DISCARDED, }, DiscardCampaign { @@ -1462,19 +1339,7 @@ mod test { }) .unwrap(), funds: vec![], - })) - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: orderer.clone(), - action: "Claim".to_string(), - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - ))), + }))), }, ClaimTestCase { name: "Claim when native token accepting campaign failed ".to_string(), @@ -1499,19 +1364,7 @@ mod test { .add_message(BankMsg::Send { to_address: orderer.to_string(), amount: coins(10, MOCK_NATIVE_DENOM), // only non presale order refunded - }) - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: orderer.clone(), - action: "Claim".to_string(), - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - ))), + })), }, ClaimTestCase { name: "Claim when cw20 accepting campaign failed ".to_string(), @@ -1543,19 +1396,7 @@ mod test { vec![], ) .unwrap(), - ) - .add_submessage(SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: orderer.clone(), - action: "Claim".to_string(), - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - ))), + )), }, ClaimTestCase { name: "Claim without purchasing in successful campaign".to_string(), diff --git a/contracts/non-fungible-tokens/andromeda-cw721/src/testing/mod.rs b/contracts/non-fungible-tokens/andromeda-cw721/src/testing/mod.rs index 17b576146..f81649dab 100644 --- a/contracts/non-fungible-tokens/andromeda-cw721/src/testing/mod.rs +++ b/contracts/non-fungible-tokens/andromeda-cw721/src/testing/mod.rs @@ -3,10 +3,11 @@ use andromeda_non_fungible_tokens::cw721::{ ExecuteMsg, InstantiateMsg, IsArchivedResponse, MintMsg, QueryMsg, TokenExtension, TransferAgreement, }; -use andromeda_std::error::ContractError; -use andromeda_std::testing::mock_querier::FAKE_VFS_PATH; -use andromeda_std::testing::mock_querier::{mock_dependencies_custom, MOCK_KERNEL_CONTRACT}; -use andromeda_std::{ado_contract::ADOContract, amp::addresses::AndrAddr}; +use andromeda_std::{ + amp::addresses::AndrAddr, + error::ContractError, + testing::mock_querier::{mock_dependencies_custom, FAKE_VFS_PATH, MOCK_KERNEL_CONTRACT}, +}; use cosmwasm_std::{ attr, coin, from_json, testing::{mock_env, mock_info}, @@ -289,23 +290,12 @@ fn test_burn() { let info = mock_info(creator.as_str(), &[]); let res = execute(deps.as_mut(), env, info.clone(), msg).unwrap(); - let fee_message = ADOContract::default() - .pay_fee( - deps.as_ref().storage, - &deps.as_ref().querier, - "Burn".to_string(), - Addr::unchecked("creator".to_string()), - ) - .unwrap(); - assert_eq!( - Response::default() - .add_submessage(fee_message) - .add_attributes(vec![ - attr("action", "burn"), - attr("token_id", &token_id), - attr("sender", info.sender.to_string()), - ]), + Response::default().add_attributes(vec![ + attr("action", "burn"), + attr("token_id", &token_id), + attr("sender", info.sender.to_string()), + ]), res ); diff --git a/contracts/non-fungible-tokens/andromeda-marketplace/src/testing/tests.rs b/contracts/non-fungible-tokens/andromeda-marketplace/src/testing/tests.rs index 377976c85..f931b614b 100644 --- a/contracts/non-fungible-tokens/andromeda-marketplace/src/testing/tests.rs +++ b/contracts/non-fungible-tokens/andromeda-marketplace/src/testing/tests.rs @@ -14,18 +14,15 @@ use andromeda_std::{ }, encode_binary, expiration::{expiration_from_milliseconds, Expiry, MILLISECONDS_TO_NANOSECONDS_RATIO}, - reply::ReplyId, Milliseconds, }, error::ContractError, - os::economics::ExecuteMsg as EconomicsExecuteMsg, testing::mock_querier::MOCK_CW20_CONTRACT, }; use cosmwasm_std::{ attr, coin, coins, from_json, testing::{mock_env, mock_info}, - to_json_binary, Addr, BankMsg, CosmosMsg, Decimal, Deps, DepsMut, Env, Response, SubMsg, - Uint128, WasmMsg, + BankMsg, CosmosMsg, Decimal, Deps, DepsMut, Env, Response, SubMsg, Uint128, WasmMsg, }; use cw20::Cw20ReceiveMsg; use cw721::{Cw721ExecuteMsg, Cw721ReceiveMsg}; @@ -962,18 +959,6 @@ fn test_execute_buy_with_tax_and_royalty_works() { to_address: "owner".to_string(), amount: vec![coin(100, "uusd")], })), - SubMsg::reply_on_error( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "economics_contract".to_string(), - msg: to_json_binary(&EconomicsExecuteMsg::PayFee { - payee: Addr::unchecked("someone"), - action: "Buy".to_string(), - }) - .unwrap(), - funds: vec![], - }), - ReplyId::PayFee.repr(), - ), ]; assert_eq!(res.messages, expected) } From 56810d09ea9ec8c7fef6480b9eb1fe3ba0dfb6ed Mon Sep 17 00:00:00 2001 From: Joe Monem Date: Tue, 14 Jan 2025 12:26:43 +0200 Subject: [PATCH 4/9] fix: made claim in vesting payable again, removed andr macros from validator staking --- .../src/contract.rs | 45 ++++++++++++++++--- .../src/validator_staking.rs | 11 ++--- packages/andromeda-finance/src/vesting.rs | 2 +- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/contracts/finance/andromeda-validator-staking/src/contract.rs b/contracts/finance/andromeda-validator-staking/src/contract.rs index 0374b9574..187ff338e 100644 --- a/contracts/finance/andromeda-validator-staking/src/contract.rs +++ b/contracts/finance/andromeda-validator-staking/src/contract.rs @@ -17,7 +17,6 @@ use andromeda_std::{ ado_base::{InstantiateMsg as BaseInstantiateMsg, MigrateMsg}, ado_contract::ADOContract, amp::AndrAddr, - andr_execute_fn, common::{context::ExecuteContext, distribution::MsgWithdrawDelegatorReward, encode_binary}, error::ContractError, os::aos_querier::AOSQuerier, @@ -64,8 +63,24 @@ pub fn instantiate( Ok(inst_resp) } -#[andr_execute_fn] -pub fn execute(ctx: ExecuteContext, msg: ExecuteMsg) -> Result { +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn execute( + deps: DepsMut, + env: Env, + info: MessageInfo, + msg: ExecuteMsg, +) -> Result { + let ctx = ExecuteContext::new(deps, info, env); + + match msg { + ExecuteMsg::AMPReceive(pkt) => { + ADOContract::default().execute_amp_receive(ctx, pkt, handle_execute) + } + _ => handle_execute(ctx, msg), + } +} + +pub fn handle_execute(ctx: ExecuteContext, msg: ExecuteMsg) -> Result { match msg { ExecuteMsg::Stake { validator } => execute_stake(ctx, validator), ExecuteMsg::Unstake { validator, amount } => execute_unstake(ctx, validator, amount), @@ -85,7 +100,6 @@ pub fn execute(ctx: ExecuteContext, msg: ExecuteMsg) -> Result ADOContract::default().execute(ctx, msg), } } - #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { ADOContract::default().migrate(deps, CONTRACT_NAME, CONTRACT_VERSION) @@ -145,7 +159,15 @@ fn execute_redelegate( dst_validator: Addr, amount: Option, ) -> Result { - let ExecuteContext { deps, env, .. } = ctx; + let ExecuteContext { + deps, env, info, .. + } = ctx; + + // Ensure sender is the contract owner + ensure!( + ADOContract::default().is_contract_owner(deps.storage, info.sender.as_str())?, + ContractError::Unauthorized {} + ); let src_validator = match src_validator { Some(addr) => { @@ -357,6 +379,12 @@ fn execute_withdraw_fund( deps, info, env, .. } = ctx; + // Ensure sender is the contract owner + ensure!( + ADOContract::default().is_contract_owner(deps.storage, info.sender.as_str())?, + ContractError::Unauthorized {} + ); + let recipient = recipient.map_or(Ok(info.sender), |r| r.get_raw_address(&deps.as_ref()))?; let funds = denom.map_or( deps.querier @@ -397,7 +425,12 @@ fn execute_update_default_validator( ctx: ExecuteContext, validator: Addr, ) -> Result { - let ExecuteContext { deps, .. } = ctx; + let ExecuteContext { deps, info, .. } = ctx; + + ensure!( + ADOContract::default().is_contract_owner(deps.storage, info.sender.as_str())?, + ContractError::Unauthorized {} + ); // Check if the validator is valid before setting to default validator is_validator(&deps, &validator)?; diff --git a/packages/andromeda-finance/src/validator_staking.rs b/packages/andromeda-finance/src/validator_staking.rs index 23dc2b1ee..dbd79c2b9 100644 --- a/packages/andromeda-finance/src/validator_staking.rs +++ b/packages/andromeda-finance/src/validator_staking.rs @@ -17,12 +17,13 @@ pub struct InstantiateMsg { #[cfg_attr(not(target_arch = "wasm32"), derive(cw_orch::ExecuteFns))] pub enum ExecuteMsg { #[cfg_attr(not(target_arch = "wasm32"), cw_orch(payable))] - Stake { validator: Option }, + Stake { + validator: Option, + }, Unstake { validator: Option, amount: Option, }, - #[attrs(restricted)] Redelegate { src_validator: Option, dst_validator: Addr, @@ -33,13 +34,13 @@ pub enum ExecuteMsg { /// Defaults to false restake: Option, }, - #[attrs(restricted)] WithdrawFunds { denom: Option, recipient: Option, }, - #[attrs(restricted)] - UpdateDefaultValidator { validator: Addr }, + UpdateDefaultValidator { + validator: Addr, + }, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] diff --git a/packages/andromeda-finance/src/vesting.rs b/packages/andromeda-finance/src/vesting.rs index a7a603b0b..72c8dad1e 100644 --- a/packages/andromeda-finance/src/vesting.rs +++ b/packages/andromeda-finance/src/vesting.rs @@ -21,7 +21,7 @@ pub struct InstantiateMsg { pub enum ExecuteMsg { /// Claim the number of batches specified starting from the beginning. If not /// specified then the max will be claimed. - #[attrs(restricted, nonpayable)] + #[attrs(restricted)] Claim { number_of_claims: Option, batch_id: u64, From 1e4f03230a0979f515172257d1855aee9bfc47b4 Mon Sep 17 00:00:00 2001 From: Joe Monem Date: Wed, 15 Jan 2025 10:08:19 +0200 Subject: [PATCH 5/9] test: test_execute_send_ado_recipient for conditional splitter --- .../src/testing/tests.rs | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/contracts/finance/andromeda-conditional-splitter/src/testing/tests.rs b/contracts/finance/andromeda-conditional-splitter/src/testing/tests.rs index 5abaa444d..3daef5c55 100644 --- a/contracts/finance/andromeda-conditional-splitter/src/testing/tests.rs +++ b/contracts/finance/andromeda-conditional-splitter/src/testing/tests.rs @@ -572,6 +572,81 @@ fn test_execute_send_threshold_not_found() { } ); } +#[test] +fn test_execute_send_ado_recipient() { + let mut deps = mock_dependencies_custom(&[]); + let env = mock_env(); + let _res: Response = init(deps.as_mut()); + + let sender_funds_amount = 10000u128; + let info = mock_info(OWNER, &[Coin::new(sender_funds_amount, "uluna")]); + + let recip_address1 = "address1".to_string(); + let recip_address2 = "address2".to_string(); + + let recip1 = Recipient::from_string(recip_address1); + let recip2 = Recipient::from_string(recip_address2); + + let msg = ExecuteMsg::Send {}; + + let amp_msg_1 = recip1 + .generate_amp_msg(&deps.as_ref(), Some(vec![Coin::new(1000, "uluna")])) + .unwrap(); + let amp_msg_2 = recip2 + .generate_amp_msg(&deps.as_ref(), Some(vec![Coin::new(2000, "uluna")])) + .unwrap(); + let amp_pkt = AMPPkt::new( + MOCK_CONTRACT_ADDR.to_string(), + MOCK_CONTRACT_ADDR.to_string(), + vec![amp_msg_1, amp_msg_2], + ); + let amp_msg = amp_pkt + .to_sub_msg( + MOCK_KERNEL_CONTRACT, + Some(vec![Coin::new(1000, "uluna"), Coin::new(2000, "uluna")]), + 1, + ) + .unwrap(); + + let splitter = ConditionalSplitter { + thresholds: vec![Threshold::new( + Uint128::zero(), + vec![ + AddressPercent::new( + recip1.clone(), // 10% + Decimal::from_ratio(Uint128::one(), Uint128::new(10)), + ), + AddressPercent::new( + recip2.clone(), // 20% + Decimal::from_ratio(Uint128::one(), Uint128::new(5)), + ), + ], + )], + lock_time: Milliseconds::default(), + }; + + CONDITIONAL_SPLITTER + .save(deps.as_mut().storage, &splitter) + .unwrap(); + + let res = execute(deps.as_mut(), env, info.clone(), msg).unwrap(); + + let expected_res = Response::new() + .add_submessages(vec![ + SubMsg::new( + // refunds remainder to sender + CosmosMsg::Bank(BankMsg::Send { + to_address: info.sender.to_string(), + amount: vec![Coin::new(7000, "uluna")], // 10000 * 0.7 remainder + }), + ), + amp_msg, + ]) + .add_attribute("action", "send") + .add_attribute("sender", "creator"); + + assert_eq!(res, expected_res); +} #[test] fn test_handle_packet_exit_with_error_true() { From 39b3d4b34dc4d0defec2a7ac29dac5b3ac45b730 Mon Sep 17 00:00:00 2001 From: Joe Monem Date: Wed, 15 Jan 2025 10:16:15 +0200 Subject: [PATCH 6/9] fix: make Claim nonpayable in vesting --- .../andromeda-vesting/src/testing/tests.rs | 43 +++++++++++++------ packages/andromeda-finance/src/vesting.rs | 2 +- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/contracts/finance/andromeda-vesting/src/testing/tests.rs b/contracts/finance/andromeda-vesting/src/testing/tests.rs index 8bc2aed2f..7691f6f63 100644 --- a/contracts/finance/andromeda-vesting/src/testing/tests.rs +++ b/contracts/finance/andromeda-vesting/src/testing/tests.rs @@ -348,7 +348,7 @@ fn test_claim_batch_still_locked() { batch_id: 1, }; - let res = execute(deps.as_mut(), mock_env(), info, msg); + let res = execute(deps.as_mut(), mock_env(), mock_info("owner", &[]), msg); assert_eq!(ContractError::FundsAreLocked {}, res.unwrap_err()); } @@ -374,7 +374,7 @@ fn test_claim_batch_no_funds_available() { batch_id: 1, }; - let res = execute(deps.as_mut(), mock_env(), info, msg); + let res = execute(deps.as_mut(), mock_env(), mock_info("owner", &[]), msg); // This is because, the first payment becomes available after 10 seconds. assert_eq!(ContractError::WithdrawalIsEmpty {}, res.unwrap_err()); @@ -432,7 +432,7 @@ fn test_claim_batch_single_claim() { batch_id: 1, }; - let res = execute(deps.as_mut(), env, info, msg).unwrap(); + let res = execute(deps.as_mut(), env, mock_info("owner", &[]), msg).unwrap(); assert_eq!( Response::new() @@ -493,7 +493,7 @@ fn test_claim_batch_not_nice_numbers_single_release() { batch_id: 1, }; - let res = execute(deps.as_mut(), env, info, msg).unwrap(); + let res = execute(deps.as_mut(), env, mock_info("owner", &[]), msg).unwrap(); assert_eq!( Response::new() @@ -557,7 +557,13 @@ fn test_claim_batch_not_nice_numbers_multiple_releases() { batch_id: 1, }; - let res = execute(deps.as_mut(), env.clone(), info.clone(), msg.clone()).unwrap(); + let res = execute( + deps.as_mut(), + env.clone(), + mock_info("owner", &[]), + msg.clone(), + ) + .unwrap(); assert_eq!( Response::new() @@ -587,7 +593,7 @@ fn test_claim_batch_not_nice_numbers_multiple_releases() { env.block.time = env.block.time.plus_seconds(duration); - let res = execute(deps.as_mut(), env, info, msg).unwrap(); + let res = execute(deps.as_mut(), env, mock_info("owner", &[]), msg).unwrap(); assert_eq!( Response::new() .add_message(BankMsg::Send { @@ -645,13 +651,18 @@ fn test_claim_batch_middle_of_interval() { // Only halfway to first release. env.block.time = env.block.time.plus_seconds(release_duration.seconds() / 2); - let res = execute(deps.as_mut(), env.clone(), info.clone(), msg.clone()); + let res = execute( + deps.as_mut(), + env.clone(), + mock_info("owner", &[]), + msg.clone(), + ); assert_eq!(ContractError::WithdrawalIsEmpty {}, res.unwrap_err()); // First release available and halfway to second -> result is rounding down. env.block.time = env.block.time.plus_seconds(release_duration.seconds()); - let res = execute(deps.as_mut(), env, info, msg).unwrap(); + let res = execute(deps.as_mut(), env, mock_info("owner", &[]), msg).unwrap(); assert_eq!( Response::new() @@ -711,7 +722,7 @@ fn test_claim_batch_multiple_claims() { number_of_claims: Some(1), batch_id: 1, }; - let res = execute(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); + let res = execute(deps.as_mut(), env.clone(), mock_info("owner", &[]), msg).unwrap(); assert_eq!( Response::new() @@ -744,7 +755,7 @@ fn test_claim_batch_multiple_claims() { number_of_claims: None, batch_id: 1, }; - let res = execute(deps.as_mut(), env, info, msg).unwrap(); + let res = execute(deps.as_mut(), env, mock_info("owner", &[]), msg).unwrap(); assert_eq!( Response::new() @@ -805,7 +816,13 @@ fn test_claim_batch_all_releases() { number_of_claims: None, batch_id: 1, }; - let res = execute(deps.as_mut(), env.clone(), info.clone(), msg.clone()).unwrap(); + let res = execute( + deps.as_mut(), + env.clone(), + mock_info("owner", &[]), + msg.clone(), + ) + .unwrap(); assert_eq!( Response::new() @@ -834,7 +851,7 @@ fn test_claim_batch_all_releases() { ); // Try to claim again. - let res = execute(deps.as_mut(), env, info, msg); + let res = execute(deps.as_mut(), env, mock_info("owner", &[]), msg); assert_eq!(ContractError::WithdrawalIsEmpty {}, res.unwrap_err()); } @@ -870,7 +887,7 @@ fn test_claim_batch_too_high_of_claim() { batch_id: 1, }; - let res = execute(deps.as_mut(), env, info, msg).unwrap(); + let res = execute(deps.as_mut(), env, mock_info("owner", &[]), msg).unwrap(); assert_eq!( Response::new() diff --git a/packages/andromeda-finance/src/vesting.rs b/packages/andromeda-finance/src/vesting.rs index 72c8dad1e..a7a603b0b 100644 --- a/packages/andromeda-finance/src/vesting.rs +++ b/packages/andromeda-finance/src/vesting.rs @@ -21,7 +21,7 @@ pub struct InstantiateMsg { pub enum ExecuteMsg { /// Claim the number of batches specified starting from the beginning. If not /// specified then the max will be claimed. - #[attrs(restricted)] + #[attrs(restricted, nonpayable)] Claim { number_of_claims: Option, batch_id: u64, From 485a793132ba9bb843cba52c15d4da2a6dcb4f97 Mon Sep 17 00:00:00 2001 From: Joe Monem Date: Wed, 15 Jan 2025 10:37:53 +0200 Subject: [PATCH 7/9] ref: implement andr macros to validator staking --- .../src/contract.rs | 51 ++-------- .../src/testing/mock_querier.rs | 94 +++++++++++++++++-- .../src/testing/tests.rs | 12 +-- .../src/validator_staking.rs | 12 +-- 4 files changed, 105 insertions(+), 64 deletions(-) diff --git a/contracts/finance/andromeda-validator-staking/src/contract.rs b/contracts/finance/andromeda-validator-staking/src/contract.rs index 187ff338e..ce29a6d63 100644 --- a/contracts/finance/andromeda-validator-staking/src/contract.rs +++ b/contracts/finance/andromeda-validator-staking/src/contract.rs @@ -17,6 +17,7 @@ use andromeda_std::{ ado_base::{InstantiateMsg as BaseInstantiateMsg, MigrateMsg}, ado_contract::ADOContract, amp::AndrAddr, + andr_execute_fn, common::{context::ExecuteContext, distribution::MsgWithdrawDelegatorReward, encode_binary}, error::ContractError, os::aos_querier::AOSQuerier, @@ -63,24 +64,8 @@ pub fn instantiate( Ok(inst_resp) } -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn execute( - deps: DepsMut, - env: Env, - info: MessageInfo, - msg: ExecuteMsg, -) -> Result { - let ctx = ExecuteContext::new(deps, info, env); - - match msg { - ExecuteMsg::AMPReceive(pkt) => { - ADOContract::default().execute_amp_receive(ctx, pkt, handle_execute) - } - _ => handle_execute(ctx, msg), - } -} - -pub fn handle_execute(ctx: ExecuteContext, msg: ExecuteMsg) -> Result { +#[andr_execute_fn] +pub fn execute(ctx: ExecuteContext, msg: ExecuteMsg) -> Result { match msg { ExecuteMsg::Stake { validator } => execute_stake(ctx, validator), ExecuteMsg::Unstake { validator, amount } => execute_unstake(ctx, validator, amount), @@ -100,6 +85,7 @@ pub fn handle_execute(ctx: ExecuteContext, msg: ExecuteMsg) -> Result ADOContract::default().execute(ctx, msg), } } + #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { ADOContract::default().migrate(deps, CONTRACT_NAME, CONTRACT_VERSION) @@ -159,15 +145,7 @@ fn execute_redelegate( dst_validator: Addr, amount: Option, ) -> Result { - let ExecuteContext { - deps, env, info, .. - } = ctx; - - // Ensure sender is the contract owner - ensure!( - ADOContract::default().is_contract_owner(deps.storage, info.sender.as_str())?, - ContractError::Unauthorized {} - ); + let ExecuteContext { deps, env, .. } = ctx; let src_validator = match src_validator { Some(addr) => { @@ -230,12 +208,6 @@ fn execute_unstake( } = ctx; let delegator = env.contract.address; - // Ensure sender is the contract owner - ensure!( - ADOContract::default().is_contract_owner(deps.storage, info.sender.as_str())?, - ContractError::Unauthorized {} - ); - let default_validator = DEFAULT_VALIDATOR.load(deps.storage)?; let validator = validator.unwrap_or(default_validator); @@ -379,12 +351,6 @@ fn execute_withdraw_fund( deps, info, env, .. } = ctx; - // Ensure sender is the contract owner - ensure!( - ADOContract::default().is_contract_owner(deps.storage, info.sender.as_str())?, - ContractError::Unauthorized {} - ); - let recipient = recipient.map_or(Ok(info.sender), |r| r.get_raw_address(&deps.as_ref()))?; let funds = denom.map_or( deps.querier @@ -425,12 +391,7 @@ fn execute_update_default_validator( ctx: ExecuteContext, validator: Addr, ) -> Result { - let ExecuteContext { deps, info, .. } = ctx; - - ensure!( - ADOContract::default().is_contract_owner(deps.storage, info.sender.as_str())?, - ContractError::Unauthorized {} - ); + let ExecuteContext { deps, .. } = ctx; // Check if the validator is valid before setting to default validator is_validator(&deps, &validator)?; diff --git a/contracts/finance/andromeda-validator-staking/src/testing/mock_querier.rs b/contracts/finance/andromeda-validator-staking/src/testing/mock_querier.rs index bed3c0084..7ace652dd 100644 --- a/contracts/finance/andromeda-validator-staking/src/testing/mock_querier.rs +++ b/contracts/finance/andromeda-validator-staking/src/testing/mock_querier.rs @@ -1,10 +1,24 @@ -use cosmwasm_std::testing::{MockApi, MockQuerier, MockStorage}; -use cosmwasm_std::{Decimal, OwnedDeps, Validator}; +use cosmwasm_std::{Decimal, Validator}; + +use andromeda_std::ado_base::InstantiateMsg; +use andromeda_std::ado_contract::ADOContract; +use andromeda_std::testing::mock_querier::MockAndromedaQuerier; +use cosmwasm_std::testing::mock_info; +use cosmwasm_std::QuerierWrapper; +use cosmwasm_std::{ + from_json, + testing::{mock_env, MockApi, MockQuerier, MockStorage, MOCK_CONTRACT_ADDR}, + Coin, OwnedDeps, Querier, QuerierResult, QueryRequest, SystemError, SystemResult, WasmQuery, +}; + +pub use andromeda_std::testing::mock_querier::MOCK_KERNEL_CONTRACT; pub const DEFAULT_VALIDATOR: &str = "default_validator"; pub const VALID_VALIDATOR: &str = "valid_validator"; -pub fn mock_dependencies_custom() -> OwnedDeps { +pub fn mock_dependencies_custom( + contract_balance: &[Coin], +) -> OwnedDeps { let default_validator = Validator { address: String::from(DEFAULT_VALIDATOR), commission: Decimal::percent(1), @@ -18,14 +32,80 @@ pub fn mock_dependencies_custom() -> OwnedDeps QuerierResult { + // MockQuerier doesn't support Custom, so we ignore it completely here + let request: QueryRequest = match from_json(bin_request) { + Ok(v) => v, + Err(e) => { + return SystemResult::Err(SystemError::InvalidRequest { + error: format!("Parsing query request: {e}"), + request: bin_request.into(), + }) + } + }; + self.handle_query(&request) + } +} + +impl WasmMockQuerier { + pub fn handle_query(&self, request: &QueryRequest) -> QuerierResult { + match &request { + QueryRequest::Wasm(WasmQuery::Smart { + contract_addr, + msg: _, + }) => { + let _ = contract_addr.as_str(); + MockAndromedaQuerier::default().handle_query(&self.base, request) + } + _ => MockAndromedaQuerier::default().handle_query(&self.base, request), + } + } + + pub fn new(base: MockQuerier) -> Self { + WasmMockQuerier { + base, + contract_address: mock_env().contract.address.to_string(), + tokens_left_to_burn: 2, + } } } diff --git a/contracts/finance/andromeda-validator-staking/src/testing/tests.rs b/contracts/finance/andromeda-validator-staking/src/testing/tests.rs index 3af016064..d48b59178 100644 --- a/contracts/finance/andromeda-validator-staking/src/testing/tests.rs +++ b/contracts/finance/andromeda-validator-staking/src/testing/tests.rs @@ -27,7 +27,7 @@ fn init(deps: DepsMut, default_validator: Addr) -> Result, - }, + Stake { validator: Option }, + #[attrs(restricted)] Unstake { validator: Option, amount: Option, }, + #[attrs(restricted)] Redelegate { src_validator: Option, dst_validator: Addr, @@ -34,13 +34,13 @@ pub enum ExecuteMsg { /// Defaults to false restake: Option, }, + #[attrs(restricted)] WithdrawFunds { denom: Option, recipient: Option, }, - UpdateDefaultValidator { - validator: Addr, - }, + #[attrs(restricted)] + UpdateDefaultValidator { validator: Addr }, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] From 30ef075057ea915f8501d1e59a447ea1e6580b1a Mon Sep 17 00:00:00 2001 From: Joe Monem Date: Wed, 15 Jan 2025 17:09:03 +0200 Subject: [PATCH 8/9] wip test: call msg with action fee --- e2e-tests/tests/conditional_splitter.rs | 42 +++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/e2e-tests/tests/conditional_splitter.rs b/e2e-tests/tests/conditional_splitter.rs index a4e0557ef..d29449ed6 100644 --- a/e2e-tests/tests/conditional_splitter.rs +++ b/e2e-tests/tests/conditional_splitter.rs @@ -3,7 +3,10 @@ use andromeda_app_contract::mock::{mock_andromeda_app, MockAppContract}; use andromeda_testing::{mock::mock_app, mock_builder::MockAndromedaBuilder, MockContract}; -use andromeda_std::amp::Recipient; +use andromeda_std::{ + amp::{AndrAddr, Recipient}, + os::adodb::ActionFee, +}; use cosmwasm_std::{coin, Decimal, Uint128}; use andromeda_conditional_splitter::mock::{ @@ -23,6 +26,7 @@ fn test_conditional_splitter() { ("recipient1", vec![]), ("recipient2", vec![]), ("recipient3", vec![]), + ("recipient4", vec![coin(100000000, "uandr")]), ]) .with_contracts(vec![ ("app-contract", mock_andromeda_app()), @@ -36,6 +40,7 @@ fn test_conditional_splitter() { let recipient_1 = andr.get_wallet("recipient1"); let recipient_2 = andr.get_wallet("recipient2"); let recipient_3 = andr.get_wallet("recipient3"); + let recipient_4 = andr.get_wallet("recipient4"); let app_code_id = andr.get_code_id(&mut router, "app-contract"); @@ -124,7 +129,7 @@ fn test_conditional_splitter() { // Third batch let token2 = coin(50_000, "uandr"); splitter - .execute_send(&mut router, owner.clone(), &[token2]) + .execute_send(&mut router, owner.clone(), &[token2.clone()]) .unwrap(); let balance_1 = router.wrap().query_balance(recipient_1, "uandr").unwrap(); @@ -173,4 +178,37 @@ fn test_conditional_splitter() { assert_eq!(uusd_balance_1.amount, Uint128::from(20u128)); assert_eq!(uusd_balance_2.amount, Uint128::from(80u128)); + + // Economics Msg + andr.adodb + .execute( + &mut router, + &andromeda_std::os::adodb::ExecuteMsg::UpdateActionFees { + ado_type: "conditional-splitter".to_string(), + action_fees: vec![ActionFee { + action: "Send".to_string(), + asset: "native:uandr".to_string(), + amount: Uint128::from(1u128), + receiver: None, + }], + }, + andr.get_wallet("admin").clone(), + &[], + ) + .unwrap(); + + andr.economics + .execute( + &mut router, + &andromeda_std::os::economics::ExecuteMsg::Deposit { + address: Some(AndrAddr::from_string(recipient_4.to_string())), + }, + owner.clone(), + &[coin(500, "uandr")], + ) + .unwrap(); + + splitter + .execute_send(&mut router, owner.clone(), &[coin(50, "uandr")]) + .unwrap(); } From 08bf4f7ed28a338a2e939f7505371818378ea5f3 Mon Sep 17 00:00:00 2001 From: Joe Monem Date: Fri, 17 Jan 2025 16:26:47 +0200 Subject: [PATCH 9/9] test: economics msg in conditional splitter test --- e2e-tests/tests/conditional_splitter.rs | 45 +++++++++++++++++-------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/e2e-tests/tests/conditional_splitter.rs b/e2e-tests/tests/conditional_splitter.rs index d29449ed6..946968c0a 100644 --- a/e2e-tests/tests/conditional_splitter.rs +++ b/e2e-tests/tests/conditional_splitter.rs @@ -3,11 +3,8 @@ use andromeda_app_contract::mock::{mock_andromeda_app, MockAppContract}; use andromeda_testing::{mock::mock_app, mock_builder::MockAndromedaBuilder, MockContract}; -use andromeda_std::{ - amp::{AndrAddr, Recipient}, - os::adodb::ActionFee, -}; -use cosmwasm_std::{coin, Decimal, Uint128}; +use andromeda_std::{amp::Recipient, os::adodb::ActionFee}; +use cosmwasm_std::{attr, coin, Decimal, Uint128}; use andromeda_conditional_splitter::mock::{ mock_andromeda_conditional_splitter, mock_conditional_splitter_instantiate_msg, @@ -40,7 +37,6 @@ fn test_conditional_splitter() { let recipient_1 = andr.get_wallet("recipient1"); let recipient_2 = andr.get_wallet("recipient2"); let recipient_3 = andr.get_wallet("recipient3"); - let recipient_4 = andr.get_wallet("recipient4"); let app_code_id = andr.get_code_id(&mut router, "app-contract"); @@ -186,10 +182,10 @@ fn test_conditional_splitter() { &andromeda_std::os::adodb::ExecuteMsg::UpdateActionFees { ado_type: "conditional-splitter".to_string(), action_fees: vec![ActionFee { - action: "Send".to_string(), + action: "UpdateThresholds".to_string(), asset: "native:uandr".to_string(), - amount: Uint128::from(1u128), - receiver: None, + amount: Uint128::from(10u128), + receiver: Some(owner.clone()), }], }, andr.get_wallet("admin").clone(), @@ -200,15 +196,36 @@ fn test_conditional_splitter() { andr.economics .execute( &mut router, - &andromeda_std::os::economics::ExecuteMsg::Deposit { - address: Some(AndrAddr::from_string(recipient_4.to_string())), - }, + &andromeda_std::os::economics::ExecuteMsg::Deposit { address: None }, owner.clone(), &[coin(500, "uandr")], ) .unwrap(); - splitter - .execute_send(&mut router, owner.clone(), &[coin(50, "uandr")]) + let res = splitter + .execute( + &mut router, + &andromeda_finance::conditional_splitter::ExecuteMsg::UpdateThresholds { + thresholds: vec![Threshold::new( + Uint128::new(20), + vec![ + AddressPercent::new( + Recipient::from_string(recipient_2.to_string()), // 20% + Decimal::from_ratio(Uint128::one(), Uint128::new(5)), + ), + AddressPercent::new( + Recipient::from_string(recipient_3.to_string()), // 10% + Decimal::from_ratio(Uint128::one(), Uint128::new(10)), + ), + ], + )], + }, + owner.clone(), + &[], + ) .unwrap(); + assert!(res + .events + .iter() + .any(|e| e.attributes.contains(&attr("paid_fee", "10native:uandr")))); }