Skip to content

Commit

Permalink
use real life class data for testig salt
Browse files Browse the repository at this point in the history
  • Loading branch information
taitruong committed Nov 14, 2023
1 parent 4010f53 commit 9db0c66
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 42 deletions.
82 changes: 60 additions & 22 deletions contracts/sg-ics721/src/testing/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
// owner, aka "minter"
const COLLECTION_OWNER_TARGET_CHAIN: &str = "collection-minter-target-chain";
const COLLECTION_OWNER_SOURCE_CHAIN: &str = "collection-minter-source-chain";
const COLLECTION_CONTRACT_SOURCE_CHAIN: &str = "collection-contract-source-chain";
const CHANNEL_TARGET_CHAIN: &str = "channel-1";
const BECH32_PREFIX_HRP: &str = "stars";
const NFT_OWNER_TARGET_CHAIN: &str = "nft-owner-target-chain";
const ICS721_ADMIN_AND_PAUSER: &str = "ics721-pauser";
Expand Down Expand Up @@ -535,6 +537,12 @@ fn test_instantiate() {
#[test]
fn test_do_instantiate_and_mint_weird_data() {
let mut test = Test::new(false, None, sg721_base_contract());
let collection_contract_source_chain =
ClassId::new(test.app.api().addr_make(COLLECTION_CONTRACT_SOURCE_CHAIN));
let class_id = format!(
"wasm.{}/{}/{}",
test.ics721, CHANNEL_TARGET_CHAIN, collection_contract_source_chain
);
test.app
.execute_contract(
test.ics721.clone(),
Expand All @@ -543,7 +551,7 @@ fn test_do_instantiate_and_mint_weird_data() {
receiver: test.app.api().addr_make(NFT_OWNER_TARGET_CHAIN).to_string(),
create: VoucherCreation {
class: Class {
id: ClassId::new("some/class/id"),
id: ClassId::new(class_id),
uri: None,
data: Some(
// data comes from source chain, so it can't be SgCollectionData
Expand Down Expand Up @@ -581,6 +589,12 @@ fn test_do_instantiate_and_mint() {
// test case: instantiate cw721 with no ClassData (without owner, name, and symbol)
{
let mut test = Test::new(false, None, sg721_base_contract());
let collection_contract_source_chain =
ClassId::new(test.app.api().addr_make(COLLECTION_CONTRACT_SOURCE_CHAIN));
let class_id = format!(
"wasm.{}/{}/{}",
test.ics721, CHANNEL_TARGET_CHAIN, collection_contract_source_chain
);
test.app
.execute_contract(
test.ics721.clone(),
Expand All @@ -589,7 +603,7 @@ fn test_do_instantiate_and_mint() {
receiver: test.app.api().addr_make(NFT_OWNER_TARGET_CHAIN).to_string(),
create: VoucherCreation {
class: Class {
id: ClassId::new("some/class/id"),
id: ClassId::new(class_id.clone()),
uri: Some("https://moonphase.is".to_string()),
data: None, // no class data
},
Expand All @@ -613,15 +627,15 @@ fn test_do_instantiate_and_mint() {
// Check entry added in CLASS_ID_TO_NFT_CONTRACT
let nft_contracts = test.query_nft_contracts();
assert_eq!(nft_contracts.len(), 1);
assert_eq!(nft_contracts[0].0, "some/class/id");
assert_eq!(nft_contracts[0].0, class_id.to_string());
// Get the address of the instantiated NFT.
let nft_contract: Addr = test
.app
.wrap()
.query_wasm_smart(
test.ics721.clone(),
&QueryMsg::NftContract {
class_id: "some/class/id".to_string(),
class_id: class_id.to_string(),
},
)
.unwrap();
Expand All @@ -638,8 +652,8 @@ fn test_do_instantiate_and_mint() {
assert_eq!(
contract_info,
cw721::ContractInfoResponse {
name: "some/class/id".to_string(), // name is set to class_id
symbol: "some/class/id".to_string() // symbol is set to class_id
name: class_id.to_string(), // name is set to class_id
symbol: class_id.to_string() // symbol is set to class_id
}
);

Expand Down Expand Up @@ -712,7 +726,7 @@ fn test_do_instantiate_and_mint() {
test.ics721,
&QueryMsg::Owner {
token_id: "1".to_string(),
class_id: "some/class/id".to_string(),
class_id: class_id.to_string(),
},
)
.unwrap();
Expand All @@ -735,6 +749,12 @@ fn test_do_instantiate_and_mint() {
// test case: instantiate cw721 with ClassData containing owner, name, and symbol
{
let mut test = Test::new(false, None, sg721_base_contract());
let collection_contract_source_chain =
ClassId::new(test.app.api().addr_make(COLLECTION_CONTRACT_SOURCE_CHAIN));
let class_id = format!(
"wasm.{}/{}/{}",
test.ics721, CHANNEL_TARGET_CHAIN, collection_contract_source_chain
);
test.app
.execute_contract(
test.ics721.clone(),
Expand All @@ -743,7 +763,7 @@ fn test_do_instantiate_and_mint() {
receiver: test.app.api().addr_make(NFT_OWNER_TARGET_CHAIN).to_string(),
create: VoucherCreation {
class: Class {
id: ClassId::new("some/class/id"),
id: ClassId::new(class_id.clone()),
uri: Some("https://moonphase.is".to_string()),
data: Some(
// data comes from source chain, so it can't be SgCollectionData
Expand Down Expand Up @@ -783,15 +803,15 @@ fn test_do_instantiate_and_mint() {
// Check entry added in CLASS_ID_TO_NFT_CONTRACT
let nft_contracts = test.query_nft_contracts();
assert_eq!(nft_contracts.len(), 1);
assert_eq!(nft_contracts[0].0, "some/class/id");
assert_eq!(nft_contracts[0].0, class_id.to_string());
// Get the address of the instantiated NFT.
let nft_contract: Addr = test
.app
.wrap()
.query_wasm_smart(
test.ics721.clone(),
&QueryMsg::NftContract {
class_id: "some/class/id".to_string(),
class_id: class_id.to_string(),
},
)
.unwrap();
Expand Down Expand Up @@ -890,7 +910,7 @@ fn test_do_instantiate_and_mint() {
test.ics721,
&QueryMsg::Owner {
token_id: "1".to_string(),
class_id: "some/class/id".to_string(),
class_id: class_id.to_string(),
},
)
.unwrap();
Expand All @@ -913,6 +933,12 @@ fn test_do_instantiate_and_mint() {
// test case: instantiate cw721 with CustomClassData (without owner, name, and symbol)
{
let mut test = Test::new(false, None, sg721_base_contract());
let collection_contract_source_chain =
ClassId::new(test.app.api().addr_make(COLLECTION_CONTRACT_SOURCE_CHAIN));
let class_id = format!(
"wasm.{}/{}/{}",
test.ics721, CHANNEL_TARGET_CHAIN, collection_contract_source_chain
);
test.app
.execute_contract(
test.ics721.clone(),
Expand All @@ -921,7 +947,7 @@ fn test_do_instantiate_and_mint() {
receiver: test.app.api().addr_make(NFT_OWNER_TARGET_CHAIN).to_string(),
create: VoucherCreation {
class: Class {
id: ClassId::new("some/class/id"),
id: ClassId::new(class_id.clone()),
uri: Some("https://moonphase.is".to_string()),
data: Some(
// CustomClassData doesn't apply to CollectionData type and won't be considered
Expand Down Expand Up @@ -958,15 +984,15 @@ fn test_do_instantiate_and_mint() {
// Check entry added in CLASS_ID_TO_NFT_CONTRACT
let nft_contracts = test.query_nft_contracts();
assert_eq!(nft_contracts.len(), 1);
assert_eq!(nft_contracts[0].0, "some/class/id");
assert_eq!(nft_contracts[0].0, class_id.to_string());
// Get the address of the instantiated NFT.
let nft_contract: Addr = test
.app
.wrap()
.query_wasm_smart(
test.ics721.clone(),
&QueryMsg::NftContract {
class_id: "some/class/id".to_string(),
class_id: class_id.to_string(),
},
)
.unwrap();
Expand All @@ -983,8 +1009,8 @@ fn test_do_instantiate_and_mint() {
assert_eq!(
contract_info,
cw721::ContractInfoResponse {
name: "some/class/id".to_string(),
symbol: "some/class/id".to_string()
name: class_id.to_string(),
symbol: class_id.to_string()
}
);

Expand Down Expand Up @@ -1057,7 +1083,7 @@ fn test_do_instantiate_and_mint() {
test.ics721,
&QueryMsg::Owner {
token_id: "1".to_string(),
class_id: "some/class/id".to_string(),
class_id: class_id.to_string(),
},
)
.unwrap();
Expand All @@ -1083,6 +1109,12 @@ fn test_do_instantiate_and_mint() {
#[test]
fn test_do_instantiate_and_mint_no_instantiate() {
let mut test = Test::new(false, None, sg721_base_contract());
let collection_contract_source_chain =
ClassId::new(test.app.api().addr_make(COLLECTION_CONTRACT_SOURCE_CHAIN));
let class_id = format!(
"wasm.{}/{}/{}",
test.ics721, CHANNEL_TARGET_CHAIN, collection_contract_source_chain
);
// Check calling CreateVouchers twice with same class id
// on 2nd call it will not instantiate a new contract,
// instead it will just mint the token on existing contract
Expand All @@ -1094,7 +1126,7 @@ fn test_do_instantiate_and_mint_no_instantiate() {
receiver: test.app.api().addr_make(NFT_OWNER_TARGET_CHAIN).to_string(),
create: VoucherCreation {
class: Class {
id: ClassId::new("some/class/id"),
id: ClassId::new(class_id.clone()),
uri: Some("https://moonphase.is".to_string()),
data: Some(
// data comes from source chain, so it can't be SgCollectionData
Expand Down Expand Up @@ -1129,7 +1161,7 @@ fn test_do_instantiate_and_mint_no_instantiate() {
// Check entry added in CLASS_ID_TO_NFT_CONTRACT
let class_id_to_nft_contract = test.query_nft_contracts();
assert_eq!(class_id_to_nft_contract.len(), 1);
assert_eq!(class_id_to_nft_contract[0].0, "some/class/id");
assert_eq!(class_id_to_nft_contract[0].0, class_id.to_string());

// 2nd call will only do a mint as the contract for the class ID has
// already been instantiated.
Expand All @@ -1141,7 +1173,7 @@ fn test_do_instantiate_and_mint_no_instantiate() {
receiver: test.app.api().addr_make(NFT_OWNER_TARGET_CHAIN).to_string(),
create: VoucherCreation {
class: Class {
id: ClassId::new("some/class/id"),
id: ClassId::new(class_id.clone()),
uri: Some("https://moonphase.is".to_string()),
// unlike above in 1st transfer, here on 2nd transfer no classdata is provided!
// this won't affect collection since it's already instantiated
Expand Down Expand Up @@ -1169,7 +1201,7 @@ fn test_do_instantiate_and_mint_no_instantiate() {
.query_wasm_smart(
test.ics721,
&QueryMsg::NftContract {
class_id: "some/class/id".to_string(),
class_id: class_id.to_string(),
},
)
.unwrap();
Expand Down Expand Up @@ -1221,6 +1253,12 @@ fn test_do_instantiate_and_mint_no_instantiate() {
#[test]
fn test_do_instantiate_and_mint_permissions() {
let mut test = Test::new(false, None, sg721_base_contract());
let collection_contract_source_chain =
ClassId::new(test.app.api().addr_make(COLLECTION_CONTRACT_SOURCE_CHAIN));
let class_id = format!(
"wasm.{}/{}/{}",
test.ics721, CHANNEL_TARGET_CHAIN, collection_contract_source_chain
);
// Method is only callable by the contract itself.
let err: ContractError = test
.app
Expand All @@ -1231,7 +1269,7 @@ fn test_do_instantiate_and_mint_permissions() {
receiver: test.app.api().addr_make(NFT_OWNER_TARGET_CHAIN).to_string(),
create: VoucherCreation {
class: Class {
id: ClassId::new("some/class/id"),
id: ClassId::new(class_id),
uri: Some("https://moonphase.is".to_string()),
data: Some(
to_json_binary(&CollectionData {
Expand Down
2 changes: 1 addition & 1 deletion packages/ics721/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{StdError, Instantiate2AddressError};
use cosmwasm_std::{Instantiate2AddressError, StdError};
use cw_pause_once::PauseError;
use cw_utils::ParseReplyError;
use thiserror::Error;
Expand Down
2 changes: 1 addition & 1 deletion packages/ics721/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::Debug;

use cosmwasm_std::{
from_json, instantiate2_address, to_json_binary, Addr, Binary, CodeInfoResponse, Deps, DepsMut,
Empty, Env, IbcMsg, MessageInfo, Response, StdError, StdResult, SubMsg, WasmMsg,
Empty, Env, IbcMsg, MessageInfo, Response, StdResult, SubMsg, WasmMsg,
};
use serde::{de::DeserializeOwned, Serialize};
use sha2::{Digest, Sha256};
Expand Down
Loading

0 comments on commit 9db0c66

Please sign in to comment.