diff --git a/contracts/sg-ics721/src/testing/integration_tests.rs b/contracts/sg-ics721/src/testing/integration_tests.rs index e06fa9b1..3c2fb4fb 100644 --- a/contracts/sg-ics721/src/testing/integration_tests.rs +++ b/contracts/sg-ics721/src/testing/integration_tests.rs @@ -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"; @@ -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(), @@ -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 @@ -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(), @@ -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 }, @@ -613,7 +627,7 @@ 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 @@ -621,7 +635,7 @@ fn test_do_instantiate_and_mint() { .query_wasm_smart( test.ics721.clone(), &QueryMsg::NftContract { - class_id: "some/class/id".to_string(), + class_id: class_id.to_string(), }, ) .unwrap(); @@ -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 } ); @@ -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(); @@ -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(), @@ -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 @@ -783,7 +803,7 @@ 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 @@ -791,7 +811,7 @@ fn test_do_instantiate_and_mint() { .query_wasm_smart( test.ics721.clone(), &QueryMsg::NftContract { - class_id: "some/class/id".to_string(), + class_id: class_id.to_string(), }, ) .unwrap(); @@ -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(); @@ -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(), @@ -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 @@ -958,7 +984,7 @@ 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 @@ -966,7 +992,7 @@ fn test_do_instantiate_and_mint() { .query_wasm_smart( test.ics721.clone(), &QueryMsg::NftContract { - class_id: "some/class/id".to_string(), + class_id: class_id.to_string(), }, ) .unwrap(); @@ -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() } ); @@ -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(); @@ -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 @@ -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 @@ -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. @@ -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 @@ -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(); @@ -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 @@ -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 { diff --git a/packages/ics721/src/error.rs b/packages/ics721/src/error.rs index a75f7c76..7dbb11fa 100644 --- a/packages/ics721/src/error.rs +++ b/packages/ics721/src/error.rs @@ -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; diff --git a/packages/ics721/src/execute.rs b/packages/ics721/src/execute.rs index f34581df..93495bbe 100644 --- a/packages/ics721/src/execute.rs +++ b/packages/ics721/src/execute.rs @@ -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}; diff --git a/packages/ics721/src/testing/integration_tests.rs b/packages/ics721/src/testing/integration_tests.rs index d8de2ca5..564e116e 100644 --- a/packages/ics721/src/testing/integration_tests.rs +++ b/packages/ics721/src/testing/integration_tests.rs @@ -518,6 +518,12 @@ fn test_instantiate() { #[test] fn test_do_instantiate_and_mint_weird_data() { let mut test = Test::new(false, None, cw721_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(), @@ -526,7 +532,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( to_json_binary(&CollectionData { @@ -563,8 +569,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, cw721_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); + 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(), @@ -698,6 +708,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, cw721_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(), @@ -706,7 +722,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( to_json_binary(&CollectionData { @@ -745,7 +761,7 @@ 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 @@ -753,7 +769,7 @@ fn test_do_instantiate_and_mint() { .query_wasm_smart( test.ics721.clone(), &QueryMsg::NftContract { - class_id: "some/class/id".to_string(), + class_id: class_id.to_string(), }, ) .unwrap(); @@ -823,7 +839,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(); @@ -846,6 +862,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, cw721_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(), @@ -854,7 +876,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 @@ -891,7 +913,7 @@ 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 @@ -899,7 +921,7 @@ fn test_do_instantiate_and_mint() { .query_wasm_smart( test.ics721.clone(), &QueryMsg::NftContract { - class_id: "some/class/id".to_string(), + class_id: class_id.to_string(), }, ) .unwrap(); @@ -916,8 +938,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() } ); @@ -969,7 +991,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(); @@ -995,6 +1017,12 @@ fn test_do_instantiate_and_mint() { #[test] fn test_do_instantiate_and_mint_no_instantiate() { let mut test = Test::new(false, None, cw721_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 @@ -1006,7 +1034,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( to_json_binary(&CollectionData { @@ -1039,7 +1067,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. @@ -1051,7 +1079,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 @@ -1079,7 +1107,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(); @@ -1102,6 +1130,12 @@ fn test_do_instantiate_and_mint_no_instantiate() { #[test] fn test_do_instantiate_and_mint_permissions() { let mut test = Test::new(false, None, cw721_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 @@ -1112,7 +1146,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 {