Skip to content

Commit

Permalink
merge main and overwrite open edition minter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
humanalgorithm committed Aug 27, 2023
2 parents 44fed17 + 13e288d commit 1d68e29
Show file tree
Hide file tree
Showing 31 changed files with 1,140 additions and 79 deletions.
2 changes: 1 addition & 1 deletion contracts/collections/sg721-metadata-onchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ mod tests {
Ok(v) => v,
Err(e) => {
return SystemResult::Err(SystemError::InvalidRequest {
error: format!("Parsing query request: {}", e),
error: format!("Parsing query request: {e}"),
request: bin_request.into(),
})
}
Expand Down
3 changes: 1 addition & 2 deletions contracts/collections/sg721-updatable/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ pub fn execute_enable_updatable(
return Err(ContractError::AlreadyEnableUpdatable {});
}

// TODO add check if sender is contract admin
// Check if sender is creator
let collection_info: CollectionInfoResponse =
Sg721UpdatableContract::default().query_collection_info(deps.as_ref())?;
Expand Down Expand Up @@ -265,7 +264,7 @@ mod tests {
Ok(v) => v,
Err(e) => {
return SystemResult::Err(SystemError::InvalidRequest {
error: format!("Parsing query request: {}", e),
error: format!("Parsing query request: {e}"),
request: bin_request.into(),
})
}
Expand Down
32 changes: 30 additions & 2 deletions contracts/factories/open-edition-factory/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, StdResult, WasmMsg};
use cosmwasm_std::{
ensure, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, StdResult, WasmMsg,
};
use cw2::set_contract_version;
use sg_std::{Response, NATIVE_DENOM};

Expand Down Expand Up @@ -31,8 +33,19 @@ pub fn instantiate(
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
let params = msg.params;

ensure!(
params.extension.airdrop_mint_price.denom == params.clone().min_mint_price.denom()?,
BaseContractError::InvalidDenom {}
);

SUDO_PARAMS.save(deps.storage, &msg.params)?;
ensure!(
params.creation_fee.denom == NATIVE_DENOM,
BaseContractError::InvalidDenom {}
);

SUDO_PARAMS.save(deps.storage, &params)?;

Ok(Response::new())
}
Expand Down Expand Up @@ -73,6 +86,7 @@ pub fn execute_create_minter(
&params,
)?;

// <<<<<<< HEAD
if NATIVE_DENOM != msg.init_msg.mint_price.denom {
return Err(ContractError::BaseError(BaseContractError::InvalidDenom {}));
}
Expand All @@ -83,6 +97,20 @@ pub fn execute_create_minter(
got: msg.init_msg.mint_price.amount.into(),
});
}
// =======
// ensure!(
// params.min_mint_price.denom == msg.init_msg.mint_price.denom,
// BaseContractError::InvalidDenom {}
// );

// ensure!(
// params.min_mint_price.amount <= msg.init_msg.mint_price.amount,
// ContractError::InsufficientMintPrice {
// expected: params.min_mint_price.amount.u128(),
// >>>>>>> main
// got: msg.init_msg.mint_price.amount.into(),
// }
// );

let wasm_msg = WasmMsg::Instantiate {
admin: Some(info.sender.to_string()),
Expand Down
38 changes: 26 additions & 12 deletions contracts/minters/open-edition-minter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use cw721::Cw721ReceiveMsg;
use cw_utils::{may_pay, maybe_addr, nonpayable, parse_reply_instantiate_data};
use semver::Version;
use sg_std::math::U64Ext;
use sg_std::StargazeMsgWrapper;
use sg_std::{StargazeMsgWrapper, NATIVE_DENOM};
use url::Url;

use open_edition_factory::msg::{OpenEditionMinterCreateMsg, ParamsResponse};
use open_edition_factory::types::NftMetadataType;
use sg1::checked_fair_burn;
use sg1::{checked_fair_burn, ibc_denom_fair_burn};
use sg2::query::Sg2QueryMsg;
use sg2::{MinterParams, Token};
use sg4::{Status, StatusResponse, SudoMsg};
Expand Down Expand Up @@ -290,16 +290,30 @@ fn pay_fairburn(
) -> Result<(Response, Uint128), ContractError> {
let mut res = Response::new();
let network_fee = mint_price_with_discounts.amount * mint_fee;
// This is for the network fee msg
checked_fair_burn(
&info,
network_fee.u128(),
Some(
deps.api
.addr_validate(&factory_params.extension.dev_fee_address)?,
),
&mut res,
)?;
if mint_price_with_discounts.denom != NATIVE_DENOM {
// only send non-zero amounts
// send portion to dev addr
if !network_fee.is_zero() {

Check warning on line 296 in contracts/minters/open-edition-minter/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/minters/open-edition-minter/src/contract.rs#L296

Added line #L296 was not covered by tests
ibc_denom_fair_burn(
coin(network_fee.u128(), mint_price_with_discounts.denom),
Some(
deps.api
.addr_validate(&factory_params.extension.dev_fee_address)?,

Check warning on line 301 in contracts/minters/open-edition-minter/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/minters/open-edition-minter/src/contract.rs#L298-L301

Added lines #L298 - L301 were not covered by tests
),
&mut res,
)?;
}
} else if !network_fee.is_zero() {
checked_fair_burn(
&info,
network_fee.u128(),
Some(
deps.api
.addr_validate(&factory_params.extension.dev_fee_address)?,
),
&mut res,
)?;
}
Ok((res, network_fee))
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/sg-eth-airdrop/src/claim_airdrop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ mod validation {
verify_ethereum_text(deps.as_ref(), &plaintext_msg, &eth_sig_hex, &eth_address)
}
Err(_) => Err(StdError::InvalidHex {
msg: format!("Could not decode {}", eth_sig),
msg: format!("Could not decode {eth_sig}"),
}),
}
}
Expand Down
25 changes: 19 additions & 6 deletions e2e/src/helpers/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,14 @@ pub fn create_minter_msg(

// gen_users will create `num_users` random SigningKeys
// and then transfer `init_balance` of funds to each of them.
pub fn gen_users(chain: &mut Chain, num_users: u32, init_balance: u128) -> Vec<SigningKey> {
pub fn gen_users(
chain: &mut Chain,
num_users: u32,
init_balance: u128,
denom: Option<&String>,
) -> Vec<SigningKey> {
let prefix = &chain.cfg.orc_cfg.chain_cfg.prefix;
let denom = &chain.cfg.orc_cfg.chain_cfg.denom;
let base_denom = &chain.cfg.orc_cfg.chain_cfg.denom;
let from_user = &chain.cfg.users[1];

let mut users = vec![];
Expand All @@ -126,13 +131,21 @@ pub fn gen_users(chain: &mut Chain, num_users: u32, init_balance: u128) -> Vec<S

let mut reqs = vec![];
for user in &users {
let mut amounts = vec![OrcCoin {
amount: init_balance,
denom: base_denom.parse().unwrap(),
}];
// add extra denom if specified
if let Some(denom) = denom {
amounts.push(OrcCoin {
amount: init_balance,
denom: denom.parse().unwrap(),
});
}
reqs.push(SendRequest {
from: from_user.account.address.parse().unwrap(),
to: user.to_addr(prefix).unwrap(),
amounts: vec![OrcCoin {
amount: init_balance,
denom: denom.parse().unwrap(),
}],
amounts,
});
}

Expand Down
117 changes: 117 additions & 0 deletions e2e/src/helpers/open_edition_ibc_minter_helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
use super::chain::Chain;
use cosm_orc::orchestrator::error::ProcessError;
use cosm_orc::orchestrator::{InstantiateResponse, SigningKey};
use cosmwasm_std::{Coin, Timestamp, Uint128};
use open_edition_factory::types::NftData;
use open_edition_factory::{
msg::{InstantiateMsg, OpenEditionMinterInitMsgExtension},
state::ParamsExtension,
};
use sg2::{
msg::{CollectionParams, CreateMinterMsg},
MinterParams,
};
use sg721::CollectionInfo;

// contract names used by cosm-orc to register stored code ids / instantiated addresses:
#[allow(dead_code)]
pub const SG721_NAME: &str = "sg721_base";
#[allow(dead_code)]
pub const FACTORY_NAME: &str = "open_edition_factory";
#[allow(dead_code)]
pub const MINTER_NAME: &str = "open_edition_minter";
#[allow(dead_code)]
pub const MAX_TOKENS: u32 = 10;
#[allow(dead_code)]
pub const CREATION_FEE: u128 = 1_000_000_000;
#[allow(dead_code)]
pub const MINT_PRICE: u128 = 100_000_000;
#[allow(dead_code)]
pub const MINT_DENOM: &str = "ibc/frenz";

#[allow(dead_code)]
pub fn instantiate_factory(
chain: &mut Chain,
creator_addr: String,
dev_addr: String,
key: &SigningKey,
) -> Result<InstantiateResponse, ProcessError> {
let denom = &chain.cfg.orc_cfg.chain_cfg.denom;

chain.orc.instantiate(
FACTORY_NAME,
"factory_inst",
&InstantiateMsg {
params: MinterParams {
code_id: chain.orc.contract_map.code_id(MINTER_NAME).unwrap(),
allowed_sg721_code_ids: vec![chain.orc.contract_map.code_id(SG721_NAME).unwrap()],
frozen: false,
creation_fee: Coin {
amount: Uint128::new(CREATION_FEE),
denom: denom.to_string(),
},
min_mint_price: Coin {
amount: Uint128::new(50),
denom: MINT_DENOM.to_string(),
},
mint_fee_bps: 1000, // 10%
max_trading_offset_secs: (60 * 60) * 24,
extension: ParamsExtension {
max_per_address_limit: 50,
airdrop_mint_fee_bps: 0,
airdrop_mint_price: Coin {
amount: Uint128::new(0),
denom: denom.to_string(),
},
dev_fee_address: dev_addr,
},
},
},
key,
Some(creator_addr.parse().unwrap()),
vec![],
)
}

#[allow(dead_code)]
#[allow(clippy::too_many_arguments)]
pub fn create_minter_msg(
chain: &mut Chain,
code_id: Option<u64>,
creator_addr: String,
limit: u32,
start_time: Timestamp,
end_time: Timestamp,
start_trading_time: Option<Timestamp>,
nft_data: NftData,
) -> CreateMinterMsg<OpenEditionMinterInitMsgExtension> {
let denom = &chain.cfg.orc_cfg.chain_cfg.denom;

CreateMinterMsg {
init_msg: OpenEditionMinterInitMsgExtension {
nft_data,
start_time,
payment_address: Some(creator_addr.clone()),
mint_price: Coin {
amount: Uint128::new(MINT_PRICE),
denom: MINT_DENOM.to_string(),
},
per_address_limit: limit,
end_time,
},
collection_params: CollectionParams {
code_id: code_id.unwrap_or_else(|| chain.orc.contract_map.code_id(SG721_NAME).unwrap()),
name: "Collection".to_string(),
symbol: "SYM".to_string(),
info: CollectionInfo {
creator: creator_addr,
description: "Description".to_string(),
image: "https://example.com/image.png".to_string(),
start_trading_time,
external_link: None,
explicit_content: None,
royalty_info: None,
},
},
}
}
4 changes: 2 additions & 2 deletions e2e/src/tests/factory_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn test_create_minter(chain: &mut Chain) {
assert!(!sg721_addr.trim().is_empty());

// generate 200 user keys and send them all enough money to each mint 50 tokens + gas
let users = gen_users(chain, 200, MINT_PRICE * 52);
let users = gen_users(chain, 200, MINT_PRICE * 52, None);

let init_balance = tokio_block(
chain
Expand Down Expand Up @@ -271,7 +271,7 @@ fn test_start_trading_time(chain: &mut Chain) {
let amount = fair_burn_fees[0].value.split(&denom).collect::<Vec<&str>>()[0];
total_fairburn_fees += amount.parse::<u128>().unwrap();

let users = gen_users(chain, 20, MINT_PRICE * 12);
let users = gen_users(chain, 20, MINT_PRICE * 12, None);
let num_users = users.len() as u32;

chain
Expand Down
4 changes: 2 additions & 2 deletions e2e/src/tests/open_edition_factory_and_mint_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ fn test_create_minter(chain: &mut Chain) {
assert!(!sg721_addr.trim().is_empty());

// generate 10 user keys and send them all enough money to each mint 10 tokens (max)
let users = gen_users(chain, 10, MINT_PRICE * MAX_TOKENS as u128 * 2u128);
let users = gen_users(chain, 10, MINT_PRICE * MAX_TOKENS as u128 * 2u128, None);

let init_balance = tokio_block(
chain
Expand Down Expand Up @@ -433,7 +433,7 @@ fn test_start_trading_time(chain: &mut Chain) {
let amount = fair_burn_fees[0].value.split(&denom).collect::<Vec<&str>>()[0];
total_fairburn_fees += amount.parse::<u128>().unwrap();

let users = gen_users(chain, 20, MINT_PRICE * 12);
let users = gen_users(chain, 20, MINT_PRICE * 12, None);

chain
.orc
Expand Down
Loading

0 comments on commit 1d68e29

Please sign in to comment.