Skip to content

Commit

Permalink
feat(dataverse): do not allow funds on instantiate
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Jun 4, 2024
1 parent 035e8a6 commit 952e727
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion contracts/axone-cognitarium/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,12 @@ mod tests {
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::{coins, from_json, Addr, Attribute, Order, Uint128};
use cw_utils::PaymentError;
use cw_utils::PaymentError::NonPayable;
use std::collections::BTreeMap;
use std::fs::File;
use std::io::Read;
use std::path::Path;
use std::{env, u128};
use cw_utils::PaymentError::NonPayable;

#[test]
fn proper_initialization() {
Expand Down
29 changes: 26 additions & 3 deletions contracts/axone-dataverse/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
pub fn instantiate(
deps: DepsMut<'_>,
env: Env,
_info: MessageInfo,
info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
nonpayable(&info)?;
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

let creator = deps.api.addr_canonicalize(env.contract.address.as_str())?;
Expand Down Expand Up @@ -149,7 +150,7 @@ mod tests {
coins, from_json, Addr, Attribute, ContractResult, CosmosMsg, HexBinary, SubMsg,
SystemError, SystemResult, Uint128, Uint64, WasmQuery,
};
use cw_utils::PaymentError;
use cw_utils::PaymentError::NonPayable;
use std::collections::BTreeMap;

#[test]
Expand Down Expand Up @@ -213,6 +214,28 @@ mod tests {
)
}

#[test]
fn instantiate_fail_with_funds() {
let mut deps = mock_dependencies();
let env = mock_env();
let info = mock_info("sender", &coins(10, "uaxone"));

let msg = InstantiateMsg {
name: "my-dataverse".to_string(),
triplestore_config: TripleStoreConfig {
code_id: Uint64::from(17u64),
limits: TripleStoreLimitsInput::default(),
},
};

let result = instantiate(deps.as_mut(), env, info, msg);
assert!(result.is_err());
assert!(matches!(
result.unwrap_err(),
ContractError::Payment(NonPayable {})
));
}

#[test]
fn proper_dataverse() {
let mut deps = mock_dependencies();
Expand Down Expand Up @@ -255,7 +278,7 @@ mod tests {
assert!(result.is_err());
assert!(matches!(
result.unwrap_err(),
ContractError::Payment(PaymentError::NonPayable {})
ContractError::Payment(NonPayable {})
));
}

Expand Down

0 comments on commit 952e727

Please sign in to comment.