From 57c317e392d75644e1eb97692fa718f847aaa97b Mon Sep 17 00:00:00 2001 From: mr-t Date: Fri, 17 Nov 2023 11:04:33 +0100 Subject: [PATCH 1/3] cargo clippy --tests --- .../src/testing/integration_tests.rs | 64 +++++++++---------- packages/ics721/src/state.rs | 2 +- packages/ics721/src/testing/contract.rs | 7 +- packages/ics721/src/testing/ibc_tests.rs | 1 - .../ics721/src/testing/integration_tests.rs | 60 +++++++++-------- 5 files changed, 62 insertions(+), 72 deletions(-) diff --git a/contracts/sg-ics721/src/testing/integration_tests.rs b/contracts/sg-ics721/src/testing/integration_tests.rs index 376261d9..2ad1c791 100644 --- a/contracts/sg-ics721/src/testing/integration_tests.rs +++ b/contracts/sg-ics721/src/testing/integration_tests.rs @@ -41,6 +41,27 @@ const BECH32_PREFIX_HRP: &str = "stars"; const NFT_OWNER_TARGET_CHAIN: &str = "nft-owner-target-chain"; const ICS721_ADMIN_AND_PAUSER: &str = "ics721-pauser"; +type MockRouter = Router< + BankKeeper, + FailingModule, + WasmKeeper, + StakeKeeper, + DistributionKeeper, + IbcAcceptingModule, + FailingModule, +>; + +type MockApp = App< + BankKeeper, + MockApiBech32, + MemoryStorage, + FailingModule, + WasmKeeper, + StakeKeeper, + DistributionKeeper, + IbcAcceptingModule, +>; + // copy of cosmwasm_std::ContractInfoResponse (marked as non-exhaustive) #[cw_serde] pub struct ContractInfoResponse { @@ -82,20 +103,7 @@ fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> Result, - WasmKeeper, - StakeKeeper, - DistributionKeeper, - IbcAcceptingModule, - FailingModule, - >, - _api: &dyn Api, - _storage: &mut dyn Storage, -) { -} +fn no_init(_router: &mut MockRouter, _api: &dyn Api, _storage: &mut dyn Storage) {} #[derive(Default)] pub struct MockAddressGenerator; @@ -136,13 +144,12 @@ impl MockAddressGenerator { key.extend_from_slice(&code_id.to_be_bytes()); key.extend_from_slice(&instance_id.to_be_bytes()); let module = Sha256::digest("module".as_bytes()); - let result = Sha256::new() + Sha256::new() .chain(module) .chain(key) .finalize() .to_vec() - .into(); - return result; + .into() } } pub struct MockApiBech32 { @@ -250,16 +257,7 @@ pub struct CustomClassData { } struct Test { - app: App< - BankKeeper, - MockApiBech32, - MemoryStorage, - FailingModule, - WasmKeeper, - StakeKeeper, - DistributionKeeper, - IbcAcceptingModule, - >, + app: MockApp, // origin cw721 contract on source chain for interchain transfers to other target chains source_cw721_owner: Addr, source_cw721_id: u64, @@ -313,13 +311,13 @@ impl Test { proxy: proxy.clone(), pauser: admin_and_pauser .clone() - .and_then(|p| Some(app.api().addr_make(&p).to_string())), + .map(|p| app.api().addr_make(&p).to_string()), }, &[], "sg-ics721", admin_and_pauser .clone() - .and_then(|p| Some(app.api().addr_make(&p).to_string())), + .map(|p| app.api().addr_make(&p).to_string()), ) .unwrap(); @@ -480,8 +478,7 @@ fn sg721_base_contract() -> Box> { info: MessageInfo, msg: sg721::ExecuteMsg, Empty>, ) -> Result { - sg721_base::entry::execute(deps, env, info, msg) - .and_then(|_| Ok::(Response::default())) + sg721_base::entry::execute(deps, env, info, msg).map(|_| Response::default()) } fn instantiate_fn( deps: DepsMut, @@ -489,8 +486,7 @@ fn sg721_base_contract() -> Box> { info: MessageInfo, msg: sg721::InstantiateMsg, ) -> Result { - sg721_base::entry::instantiate(deps, env, info, msg) - .and_then(|_| Ok::(Response::default())) + sg721_base::entry::instantiate(deps, env, info, msg).map(|_| Response::default()) } let contract = ContractWrapper::new(exececute_fn, instantiate_fn, sg721_base::entry::query); Box::new(contract) @@ -1773,7 +1769,7 @@ fn test_receive_nft() { let expected_contract_info: cosmwasm_std::ContractInfoResponse = // workaround using from_json/to_json_binary since ContractInfoResponse is non-exhaustive, can't be created directly from_json( - &to_json_binary(&ContractInfoResponse { + to_json_binary(&ContractInfoResponse { code_id: test.source_cw721_id, creator: test.source_cw721_owner.to_string(), admin: None, diff --git a/packages/ics721/src/state.rs b/packages/ics721/src/state.rs index beae865e..3c5feab9 100644 --- a/packages/ics721/src/state.rs +++ b/packages/ics721/src/state.rs @@ -89,7 +89,7 @@ mod tests { }, }; let start = to_json_binary(&start).unwrap(); - let end: UniversalAllNftInfoResponse = from_json(&start).unwrap(); + let end: UniversalAllNftInfoResponse = from_json(start).unwrap(); assert_eq!(end.access.owner, "foo".to_string()); assert_eq!(end.access.approvals, vec![]); assert_eq!(end.info.token_uri, None); diff --git a/packages/ics721/src/testing/contract.rs b/packages/ics721/src/testing/contract.rs index 766bd25e..bdc4158a 100644 --- a/packages/ics721/src/testing/contract.rs +++ b/packages/ics721/src/testing/contract.rs @@ -179,7 +179,7 @@ fn mock_querier_v016(query: &WasmQuery) -> QuerierResult { fn test_receive_nft() { // test case: receive nft from cw721-base let expected_contract_info: cosmwasm_std::ContractInfoResponse = from_json( - &to_json_binary(&ContractInfoResponse { + to_json_binary(&ContractInfoResponse { code_id: 0, creator: "creator".to_string(), admin: None, @@ -253,7 +253,6 @@ fn test_receive_nft() { // check outgoing classID and tokenID let keys = OUTGOING_CLASS_TOKEN_TO_CHANNEL .keys(deps.as_mut().storage, None, None, Order::Ascending) - .into_iter() .collect::>>() .unwrap(); assert_eq!(keys, [(NFT_ADDR.to_string(), token_id.to_string())]); @@ -335,7 +334,6 @@ fn test_receive_nft() { // check outgoing classID and tokenID let keys = OUTGOING_CLASS_TOKEN_TO_CHANNEL .keys(deps.as_mut().storage, None, None, Order::Ascending) - .into_iter() .collect::>>() .unwrap(); assert_eq!(keys, [(NFT_ADDR.to_string(), token_id.to_string())]); @@ -408,7 +406,6 @@ fn test_receive_nft() { // check outgoing classID and tokenID let keys = OUTGOING_CLASS_TOKEN_TO_CHANNEL .keys(deps.as_mut().storage, None, None, Order::Ascending) - .into_iter() .collect::>>() .unwrap(); assert_eq!(keys, [(NFT_ADDR.to_string(), token_id.to_string())]); @@ -456,7 +453,7 @@ fn test_receive_sets_uri() { .unwrap(); assert_eq!(class.uri, None); let expected_contract_info: cosmwasm_std::ContractInfoResponse = from_json( - &to_json_binary(&ContractInfoResponse { + to_json_binary(&ContractInfoResponse { code_id: 0, creator: "creator".to_string(), admin: None, diff --git a/packages/ics721/src/testing/ibc_tests.rs b/packages/ics721/src/testing/ibc_tests.rs index 3448c7a3..364b9756 100644 --- a/packages/ics721/src/testing/ibc_tests.rs +++ b/packages/ics721/src/testing/ibc_tests.rs @@ -450,7 +450,6 @@ fn test_ibc_packet_receive() { // check incoming classID and tokenID let keys = INCOMING_CLASS_TOKEN_TO_CHANNEL .keys(deps.as_mut().storage, None, None, Order::Ascending) - .into_iter() .collect::>>() .unwrap(); let class_id = format!( diff --git a/packages/ics721/src/testing/integration_tests.rs b/packages/ics721/src/testing/integration_tests.rs index 2a4d75f1..29d09ef5 100644 --- a/packages/ics721/src/testing/integration_tests.rs +++ b/packages/ics721/src/testing/integration_tests.rs @@ -41,6 +41,27 @@ const BECH32_PREFIX_HRP: &str = "stars"; const NFT_OWNER_TARGET_CHAIN: &str = "nft-owner-target-chain"; const ICS721_ADMIN_AND_PAUSER: &str = "ics721-pauser"; +type MockRouter = Router< + BankKeeper, + FailingModule, + WasmKeeper, + StakeKeeper, + DistributionKeeper, + IbcAcceptingModule, + FailingModule, +>; + +type MockApp = App< + BankKeeper, + MockApiBech32, + MemoryStorage, + FailingModule, + WasmKeeper, + StakeKeeper, + DistributionKeeper, + IbcAcceptingModule, +>; + // copy of cosmwasm_std::ContractInfoResponse (marked as non-exhaustive) #[cw_serde] pub struct ContractInfoResponse { @@ -82,20 +103,7 @@ fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> Result, - WasmKeeper, - StakeKeeper, - DistributionKeeper, - IbcAcceptingModule, - FailingModule, - >, - _api: &dyn Api, - _storage: &mut dyn Storage, -) { -} +fn no_init(_router: &mut MockRouter, _api: &dyn Api, _storage: &mut dyn Storage) {} #[derive(Default)] pub struct MockAddressGenerator; @@ -136,13 +144,12 @@ impl MockAddressGenerator { key.extend_from_slice(&code_id.to_be_bytes()); key.extend_from_slice(&instance_id.to_be_bytes()); let module = Sha256::digest("module".as_bytes()); - let result = Sha256::new() + Sha256::new() .chain(module) .chain(key) .finalize() .to_vec() - .into(); - return result; + .into() } } pub struct MockApiBech32 { @@ -250,16 +257,7 @@ pub struct CustomClassData { } struct Test { - app: App< - BankKeeper, - MockApiBech32, - MemoryStorage, - FailingModule, - WasmKeeper, - StakeKeeper, - DistributionKeeper, - IbcAcceptingModule, - >, + app: MockApp, // origin cw721 contract on source chain for interchain transfers to other target chains source_cw721_owner: Addr, source_cw721_id: u64, @@ -313,13 +311,13 @@ impl Test { proxy: proxy.clone(), pauser: admin_and_pauser .clone() - .and_then(|p| Some(app.api().addr_make(&p).to_string())), + .map(|p| app.api().addr_make(&p).to_string()), }, &[], "ics721-base", admin_and_pauser .clone() - .and_then(|p| Some(app.api().addr_make(&p).to_string())), + .map(|p| app.api().addr_make(&p).to_string()), ) .unwrap(); @@ -1599,7 +1597,7 @@ fn test_receive_nft() { let expected_contract_info: cosmwasm_std::ContractInfoResponse = // workaround using from_json/to_json_binary since ContractInfoResponse is non-exhaustive, can't be created directly from_json( - &to_json_binary(&ContractInfoResponse { + to_json_binary(&ContractInfoResponse { code_id: test.source_cw721_id, creator: test.source_cw721_owner.to_string(), admin: None, @@ -1667,7 +1665,7 @@ fn test_receive_nft() { let expected_contract_info: cosmwasm_std::ContractInfoResponse = // workaround using from_json/to_json_binary since ContractInfoResponse is non-exhaustive, can't be created directly from_json( - &to_json_binary(&ContractInfoResponse { + to_json_binary(&ContractInfoResponse { code_id: test.source_cw721_id, creator: test.source_cw721_owner.to_string(), admin: None, From a1665e4e7d27347e476ba52ac1be06af2fca4398 Mon Sep 17 00:00:00 2001 From: mr-t Date: Fri, 17 Nov 2023 11:25:12 +0100 Subject: [PATCH 2/3] update README with a quick getting started --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 0099044d..d28a7982 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,26 @@ This implementation rate limiting of outgoing NFTs; 4. is well tested. +To enable ICS721 contracts to function correctly, the app chain needs to have at least `wasmd v0.31.0` installed, with the `cosmwasm_1_2` feature enabled. This requirement arises from the fact that the ICS721 contract uses `instantiate2` for creating predicted cw721 addresses. For more detailed information, please refer to the [CHANGELOG.md](https://github.com/CosmWasm/wasmd/blob/main/CHANGELOG.md#v0310-2023-03-13) `wasmd` repository. + +## Getting Started + +Follow these steps to set up contracts and channels: + +1. Clone the [`cw-ics721`](https://github.com/public-awesome/cw-ics721) repository. +2. Build the contracts using the [`ts-relayer-tests/build.sh`](https://github.com/public-awesome/cw-ics721/blob/main/ts-relayer-tests/build.sh) script. +3. Upload and instantiate the `ics721-base` contract (refer to the [CosmWasm book](https://book.cosmwasm.com/) for details) on at least 2 CosmWasm-based app chains. +4. Set up relayers, such as [Cosmos/IBC Go](https://github.com/cosmos/relayer/) or [Hermes](https://hermes.informal.systems/). + +To gain a better understanding of how ICS721 (interchain) workflows function, consider running the integration tests. You can find more information in the [ts-relayer-tests/README.md](./ts-relayer-tests/README.md) file. The integration tests perform the following actions: + +- Set up 2 local chains. +- Upload interchain contracts. +- Create an IBC channel between both contracts. +- Create a collection contract (cw721). +- Mint an NFT. +- Transfer the NFT from one chain to another. + ## From a thousand feet up This contract deals in debt-vouchers. From 0822c4b96285fb0765ce9cd8b12b3caea8464ba0 Mon Sep 17 00:00:00 2001 From: mr-t Date: Fri, 17 Nov 2023 11:28:43 +0100 Subject: [PATCH 3/3] cleanup --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d28a7982..c4ed2b6b 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ This implementation rate limiting of outgoing NFTs; 4. is well tested. -To enable ICS721 contracts to function correctly, the app chain needs to have at least `wasmd v0.31.0` installed, with the `cosmwasm_1_2` feature enabled. This requirement arises from the fact that the ICS721 contract uses `instantiate2` for creating predicted cw721 addresses. For more detailed information, please refer to the [CHANGELOG.md](https://github.com/CosmWasm/wasmd/blob/main/CHANGELOG.md#v0310-2023-03-13) `wasmd` repository. +To enable ICS721 contracts to function correctly, the app chain needs to have at least `wasmd v0.31.0` installed, with the `cosmwasm_1_2` feature enabled. This requirement arises from the fact that the ICS721 contract uses `instantiate2` for creating predicted cw721 addresses. For more detailed information, please refer to the [CHANGELOG.md](https://github.com/CosmWasm/wasmd/blob/main/CHANGELOG.md#v0310-2023-03-13) in the `wasmd` repository. ## Getting Started