From 474823e1ad59905975c21f41fecee2f1e8598ea8 Mon Sep 17 00:00:00 2001 From: Benjamin DENEUX Date: Tue, 4 Jun 2024 10:42:21 +0200 Subject: [PATCH] feat(law-stone): do not allow funds on instantiate --- contracts/axone-law-stone/src/contract.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/contracts/axone-law-stone/src/contract.rs b/contracts/axone-law-stone/src/contract.rs index e9b15041..42c4dcfb 100644 --- a/contracts/axone-law-stone/src/contract.rs +++ b/contracts/axone-law-stone/src/contract.rs @@ -26,9 +26,10 @@ const STORE_PROGRAM_REPLY_ID: u64 = 1; pub fn instantiate( deps: DepsMut<'_, LogicCustomQuery>, _env: Env, - _info: MessageInfo, + info: MessageInfo, msg: InstantiateMsg, ) -> Result { + nonpayable(&info)?; set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; let store_msg = StorageMsg::StoreObject { @@ -294,6 +295,7 @@ mod tests { }; use cw_utils::ParseReplyError::SubMsgFailure; use cw_utils::PaymentError; + use cw_utils::PaymentError::NonPayable; use std::collections::VecDeque; use std::marker::PhantomData; @@ -387,6 +389,24 @@ mod tests { ); } + #[test] + fn instantiate_fail_with_funds() { + let mut deps = + mock_dependencies_with_logic_handler(|_| SystemResult::Err(SystemError::Unknown {})); + let env = mock_env(); + let info = mock_info("sender", &coins(10, "uaxone")); + + let msg = InstantiateMsg { + program: to_json_binary("foo(_) :- true.").unwrap(), + storage_address: "axone1ffzp0xmjhwkltuxcvccl0z9tyfuu7txp5ke0tpkcjpzuq9fcj3pq85yqlv" + .to_string(), + }; + + let result = instantiate(deps.as_mut(), env, info, msg); + assert!(result.is_err()); + assert_eq!(result.unwrap_err(), ContractError::Payment(NonPayable {})); + } + #[test] fn program() { let mut deps =