From 6149eae5324edd08d5aa8dd04aeb77be4dcdba69 Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Thu, 2 Nov 2023 16:30:52 +0800 Subject: [PATCH 01/16] build(deps): bump desmos into v6.2.0 --- .github/workflows/chain-interaction.yml | 2 +- packages/bindings/src/proto/DESMOS_COMMIT | 2 +- packages/proto-build/src/lib.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/chain-interaction.yml b/.github/workflows/chain-interaction.yml index 441d1bb2..112a38ac 100644 --- a/.github/workflows/chain-interaction.yml +++ b/.github/workflows/chain-interaction.yml @@ -50,7 +50,7 @@ jobs: uses: actions/checkout@v3 with: repository: desmos-labs/desmos - ref: v6.1.0 + ref: v6.2.0 path: ./desmos-src - name: Build desmos chain ⚙ diff --git a/packages/bindings/src/proto/DESMOS_COMMIT b/packages/bindings/src/proto/DESMOS_COMMIT index 9f925ba2..f4c0c050 100644 --- a/packages/bindings/src/proto/DESMOS_COMMIT +++ b/packages/bindings/src/proto/DESMOS_COMMIT @@ -1 +1 @@ -v6.0.0 \ No newline at end of file +v6.2.0 \ No newline at end of file diff --git a/packages/proto-build/src/lib.rs b/packages/proto-build/src/lib.rs index cc5def74..8802e315 100644 --- a/packages/proto-build/src/lib.rs +++ b/packages/proto-build/src/lib.rs @@ -10,7 +10,7 @@ mod transform; mod transformers; /// The desmos commit or tag to be cloned and used to build the proto files -const DESMOS_REV: &str = "v6.0.0"; +const DESMOS_REV: &str = "v6.2.0"; /// Directory where the desmos submodule is located const DESMOS_DIR: &str = "../../dependencies/desmos/"; @@ -22,7 +22,7 @@ const DESMOS_REPO_URL: &str = "https://github.com/desmos-labs/desmos.git"; const COSMOS_SDK_DIR: &str = "../../dependencies/cosmos-sdk/"; /// The Cosmos SDK commit or tag to be cloned and used to build the proto files -const COSMOS_SDK_REV: &str = "v0.47.4-desmos"; +const COSMOS_SDK_REV: &str = "v0.47.5-desmos"; /// URL where the Cosmos SDK repository is located const COSMOS_SDK_REPO_URL: &str = "https://github.com/desmos-labs/cosmos-sdk.git"; @@ -31,7 +31,7 @@ const COSMOS_SDK_REPO_URL: &str = "https://github.com/desmos-labs/cosmos-sdk.git const IBC_DIR: &str = "../../dependencies/ibc/"; /// The IBC commit or tag to be cloned and used to build the proto files -const IBC_REV: &str = "v7.2.0"; +const IBC_REV: &str = "v7.3.1"; /// URL where the IBC repository is located const IBC_REPO_URL: &str = "https://github.com/cosmos/ibc-go.git"; From 1a05b6e4a45318b5eb6cbe575d0fbfdb8be4a829 Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Wed, 23 Aug 2023 18:50:21 +0800 Subject: [PATCH 02/16] feat: add new posts msgs to constructor --- packages/bindings/src/posts/msg.rs | 170 +++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) diff --git a/packages/bindings/src/posts/msg.rs b/packages/bindings/src/posts/msg.rs index 24c4ac33..bd6a3af2 100644 --- a/packages/bindings/src/posts/msg.rs +++ b/packages/bindings/src/posts/msg.rs @@ -148,6 +148,95 @@ impl PostsMsg { signer: signer.into(), } } + + /// Creates an instance of [`MsgMovePost`]. + /// * `subspace_id` - Id of the subspace where the post is currently located. + /// * `post_id` - Id of the post to be moved. + /// * `target_subspace_id` - Id of the target subspace to which the post will be moved. + /// * `target_section_id` - Id of the target section to which the post will be moved. + /// * `owner` - Address of the post owner. + pub fn move_post( + subspace_id: u64, + post_id: u64, + target_subspace_id: u64, + target_section_id: u32, + owner: Addr, + ) -> MsgMovePost { + MsgMovePost { + subspace_id, + post_id, + target_subspace_id, + target_section_id, + owner: owner.into(), + } + } + + /// Creates an instance of [`MsgRequestPostOwnerTransfer`]. + /// * `subspace_id` - Id of the subspace that holds the post which ownership should be transferred. + /// * `post_id` - Id of the post which will be transferred. + /// * `receiver` - Address of the post ownership receiver. + /// * `sender` - Address of the sender who is creating a transfer request. + pub fn request_post_owner_transfer( + subspace_id: u64, + post_id: u64, + receiver: Addr, + sender: Addr, + ) -> MsgRequestPostOwnerTransfer { + MsgRequestPostOwnerTransfer { + subspace_id, + post_id, + receiver: receiver.into(), + sender: sender.into(), + } + } + + /// Creates an instance of [`MsgCancelPostOwnerTransferRequest`]. + /// * `subspace_id` - Id of the subspace that holds the post for which the request should be canceled. + /// * `post_id` - Id of the post for which the request will be cancelled. + /// * `sender` - Address of the transfer request sender. + pub fn cancel_post_owner_transfer_request( + subspace_id: u64, + post_id: u64, + sender: Addr, + ) -> MsgCancelPostOwnerTransferRequest { + MsgCancelPostOwnerTransferRequest { + subspace_id, + post_id, + sender: sender.into(), + } + } + + /// Creates an instance of [`MsgAcceptPostOwnerTransferRequest`]. + /// * `subspace_id` - Id of the subspace holding the post for which the request will be accepted. + /// * `post_id` - Id of the post for which the request will be accepted. + /// * `receiver` - Address of the request receiver. + pub fn accept_post_owner_transfer_request( + subspace_id: u64, + post_id: u64, + receiver: Addr, + ) -> MsgAcceptPostOwnerTransferRequest { + MsgAcceptPostOwnerTransferRequest { + subspace_id, + post_id, + receiver: receiver.into(), + } + } + + /// Creates an instance of [`MsgRefusePostOwnerTransferRequest`]. + /// * `subspace_id` - Id of the subspace holding the post for which the request will be refused. + /// * `post_id` - Id of the post for which the request will be refused. + /// * `receiver` - Address of the request receiver. + pub fn refuse_post_owner_transfer_request( + subspace_id: u64, + post_id: u64, + receiver: Addr, + ) -> MsgRefusePostOwnerTransferRequest { + MsgRefusePostOwnerTransferRequest { + subspace_id, + post_id, + receiver: receiver.into(), + } + } } #[cfg(test)] @@ -335,4 +424,85 @@ mod tests { assert_eq!(expected, msg) } + + #[test] + fn test_move_post() { + let msg = PostsMsg::move_post(1, 1, 2, 0, Addr::unchecked("user")); + + let expected = MsgMovePost { + subspace_id: 1, + post_id: 1, + target_subspace_id: 2, + target_section_id: 0, + owner: "user".into(), + }; + + assert_eq!(expected, msg) + } + + #[test] + fn test_request_post_owner_transfer() { + let msg = PostsMsg::request_post_owner_transfer( + 1, + 1, + Addr::unchecked("receiver"), + Addr::unchecked("sender"), + ); + + let expected = MsgRequestPostOwnerTransfer { + subspace_id: 1, + post_id: 1, + receiver: "receiver".into(), + sender: "sender".into(), + }; + + assert_eq!(expected, msg) + } + + #[test] + fn test_cancel_post_owner_transfer_request() { + let msg = PostsMsg::cancel_post_owner_transfer_request(1, 1, Addr::unchecked("sender")); + + let expected = MsgCancelPostOwnerTransferRequest { + subspace_id: 1, + post_id: 1, + sender: "sender".into(), + }; + + assert_eq!(expected, msg) + } + + #[test] + fn test_accept_post_owner_transfer_request() { + let msg = PostsMsg::accept_post_owner_transfer_request( + 1, + 1, + Addr::unchecked("receiver"), + ); + + let expected = MsgAcceptPostOwnerTransferRequest { + subspace_id: 1, + post_id: 1, + receiver: "receiver".into(), + }; + + assert_eq!(expected, msg) + } + + #[test] + fn test_refuse_post_owner_transfer_request() { + let msg = PostsMsg::refuse_post_owner_transfer_request( + 1, + 1, + Addr::unchecked("receiver"), + ); + + let expected = MsgRefusePostOwnerTransferRequest { + subspace_id: 1, + post_id: 1, + receiver: "receiver".into(), + }; + + assert_eq!(expected, msg) + } } From 3fcb8327986db00e1670571d7102f4cea2063895 Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Wed, 23 Aug 2023 19:53:26 +0800 Subject: [PATCH 03/16] feat: support new posts features --- packages/bindings/src/mocks/mock_queriers.rs | 7 +- packages/bindings/src/posts/mocks.rs | 15 +++- packages/bindings/src/posts/querier.rs | 80 ++++++++++++++++++++ 3 files changed, 100 insertions(+), 2 deletions(-) diff --git a/packages/bindings/src/mocks/mock_queriers.rs b/packages/bindings/src/mocks/mock_queriers.rs index cb1dc3f9..50135d93 100644 --- a/packages/bindings/src/mocks/mock_queriers.rs +++ b/packages/bindings/src/mocks/mock_queriers.rs @@ -102,7 +102,7 @@ fn register_default_mock_queries(querier: &mut MockDesmosQuerier) { use crate::posts::mocks::MockPostsQueries; use crate::posts::types::{ QueryPollAnswersRequest, QueryPostAttachmentsRequest, QueryPostRequest, - QuerySectionPostsRequest, QuerySubspacePostsRequest, + QuerySectionPostsRequest, QuerySubspacePostsRequest, QueryIncomingPostOwnerTransferRequestsRequest, }; QuerySubspacePostsRequest::mock_response( @@ -125,6 +125,11 @@ fn register_default_mock_queries(querier: &mut MockDesmosQuerier) { querier, MockPostsQueries::get_mocked_poll_answers_response(), ); + + QueryIncomingPostOwnerTransferRequestsRequest::mock_response( + querier, + MockPostsQueries::get_mocked_incoming_post_transfer_requests_response(), + ); } #[cfg(feature = "profiles")] { diff --git a/packages/bindings/src/posts/mocks.rs b/packages/bindings/src/posts/mocks.rs index ef9fe776..cc98edfc 100644 --- a/packages/bindings/src/posts/mocks.rs +++ b/packages/bindings/src/posts/mocks.rs @@ -5,7 +5,7 @@ use crate::posts::types::AttachmentContent; use crate::posts::types::{ Attachment, Media, Post, QueryPollAnswersResponse, QueryPostAttachmentsResponse, QueryPostResponse, QuerySectionPostsResponse, QuerySubspacePostsResponse, ReplySetting, - UserAnswer, + UserAnswer, QueryIncomingPostOwnerTransferRequestsResponse, PostOwnerTransferRequest, }; use chrono::DateTime; @@ -140,4 +140,17 @@ impl MockPostsQueries { pagination: None, } } + + /// Function that mocks a [`QueryIncomingPostOwnerTransferRequestsResponse`]. + pub fn get_mocked_incoming_post_transfer_requests_response() -> QueryIncomingPostOwnerTransferRequestsResponse { + QueryIncomingPostOwnerTransferRequestsResponse { + requests: vec![PostOwnerTransferRequest{ + subspace_id: 1, + post_id: 1, + sender: "sender".into(), + receiver: "receiver".into() + }], + pagination: None, + } + } } diff --git a/packages/bindings/src/posts/querier.rs b/packages/bindings/src/posts/querier.rs index 8fd20975..0b887481 100644 --- a/packages/bindings/src/posts/querier.rs +++ b/packages/bindings/src/posts/querier.rs @@ -252,6 +252,60 @@ impl<'a> PostsQuerier<'a> { page_size, ) } + + /// Queries the incoming post transfer requests having the given `subspace_id`. + /// + /// * `subspace_id` - Id of the subspace where the requests are stored. + /// * `receiver` - Optional the address of the user to which query the incoming requests for. + /// * `pagination` - Optional pagination for the request. + pub fn query_incoming_post_transfer_requests( + &self, + subspace_id: u64, + receiver: Option, + pagination: Option, + ) -> StdResult { + self.querier.incoming_post_owner_transfer_requests( + subspace_id, + receiver.unwrap_or_else(|| Addr::unchecked("")).into(), + pagination.map(Into::into), + ) + } + + /// Gives an iterator to scan over the incoming post transfer requests having the given `subspace_id`. + /// + /// * `subspace_id` - Id of the subspace where the requests are stored. + /// * `receiver` - Optional the address of the user to which query the incoming requests for. + /// * `page_size` - Size of the page requested to the chain. + #[cfg(feature = "iterators")] + pub fn iterate_incoming_post_transfer_requests( + &self, + subspace_id: u64, + receiver: Option, + page_size: u64, + ) -> PageIterator { + PageIterator::new( + Box::new(move |key, limit| { + self.query_incoming_post_transfer_requests( + subspace_id, + receiver.clone(), + Some(PageRequest { + key: key.unwrap_or_default().to_vec(), + limit: limit.into(), + reverse: false, + count_total: false, + offset: 0, + }), + ) + .map(|response| Page { + items: response.requests, + next_page_key: response.pagination.and_then(|response| { + (!response.next_key.is_empty()).then_some(Binary::from(response.next_key)) + }), + }) + }), + page_size, + ) + } } #[cfg(test)] @@ -378,4 +432,30 @@ mod tests { assert_eq!(expected.answers[0], iterator.next().unwrap().unwrap()); assert!(iterator.next().is_none()) } + + #[test] + fn test_query_incoming_post_transfer_requests() { + let owned_deps = mock_desmos_dependencies(); + let deps = owned_deps.as_ref(); + let querier = PostsQuerier::new(&deps.querier); + + let result = querier.query_incoming_post_transfer_requests(1, None, None); + let response = result.unwrap(); + let expected = MockPostsQueries::get_mocked_incoming_post_transfer_requests_response(); + + assert_eq!(expected, response) + } + + #[test] + fn test_iterate_incoming_post_transfer_requests() { + let owned_deps = mock_desmos_dependencies(); + let deps = owned_deps.as_ref(); + let querier = PostsQuerier::new(&deps.querier); + + let mut iterator = querier.iterate_incoming_post_transfer_requests(1, None, 32); + let expected = MockPostsQueries::get_mocked_incoming_post_transfer_requests_response(); + + assert_eq!(expected.requests[0], iterator.next().unwrap().unwrap()); + assert!(iterator.next().is_none()) + } } From e6246fcfed1dd06ee9d905b995bf5d079179e862 Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Wed, 23 Aug 2023 19:53:51 +0800 Subject: [PATCH 04/16] chore: run lint --- packages/bindings/src/mocks/mock_queriers.rs | 5 +++-- packages/bindings/src/posts/mocks.rs | 14 ++++++++------ packages/bindings/src/posts/msg.rs | 12 ++---------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/packages/bindings/src/mocks/mock_queriers.rs b/packages/bindings/src/mocks/mock_queriers.rs index 50135d93..2050d6c7 100644 --- a/packages/bindings/src/mocks/mock_queriers.rs +++ b/packages/bindings/src/mocks/mock_queriers.rs @@ -101,8 +101,9 @@ fn register_default_mock_queries(querier: &mut MockDesmosQuerier) { { use crate::posts::mocks::MockPostsQueries; use crate::posts::types::{ - QueryPollAnswersRequest, QueryPostAttachmentsRequest, QueryPostRequest, - QuerySectionPostsRequest, QuerySubspacePostsRequest, QueryIncomingPostOwnerTransferRequestsRequest, + QueryIncomingPostOwnerTransferRequestsRequest, QueryPollAnswersRequest, + QueryPostAttachmentsRequest, QueryPostRequest, QuerySectionPostsRequest, + QuerySubspacePostsRequest, }; QuerySubspacePostsRequest::mock_response( diff --git a/packages/bindings/src/posts/mocks.rs b/packages/bindings/src/posts/mocks.rs index cc98edfc..111e5490 100644 --- a/packages/bindings/src/posts/mocks.rs +++ b/packages/bindings/src/posts/mocks.rs @@ -3,9 +3,10 @@ use crate::cosmos_types::Timestamp; use crate::posts::types::AttachmentContent; use crate::posts::types::{ - Attachment, Media, Post, QueryPollAnswersResponse, QueryPostAttachmentsResponse, - QueryPostResponse, QuerySectionPostsResponse, QuerySubspacePostsResponse, ReplySetting, - UserAnswer, QueryIncomingPostOwnerTransferRequestsResponse, PostOwnerTransferRequest, + Attachment, Media, Post, PostOwnerTransferRequest, + QueryIncomingPostOwnerTransferRequestsResponse, QueryPollAnswersResponse, + QueryPostAttachmentsResponse, QueryPostResponse, QuerySectionPostsResponse, + QuerySubspacePostsResponse, ReplySetting, UserAnswer, }; use chrono::DateTime; @@ -142,13 +143,14 @@ impl MockPostsQueries { } /// Function that mocks a [`QueryIncomingPostOwnerTransferRequestsResponse`]. - pub fn get_mocked_incoming_post_transfer_requests_response() -> QueryIncomingPostOwnerTransferRequestsResponse { + pub fn get_mocked_incoming_post_transfer_requests_response( + ) -> QueryIncomingPostOwnerTransferRequestsResponse { QueryIncomingPostOwnerTransferRequestsResponse { - requests: vec![PostOwnerTransferRequest{ + requests: vec![PostOwnerTransferRequest { subspace_id: 1, post_id: 1, sender: "sender".into(), - receiver: "receiver".into() + receiver: "receiver".into(), }], pagination: None, } diff --git a/packages/bindings/src/posts/msg.rs b/packages/bindings/src/posts/msg.rs index bd6a3af2..31319bf0 100644 --- a/packages/bindings/src/posts/msg.rs +++ b/packages/bindings/src/posts/msg.rs @@ -474,11 +474,7 @@ mod tests { #[test] fn test_accept_post_owner_transfer_request() { - let msg = PostsMsg::accept_post_owner_transfer_request( - 1, - 1, - Addr::unchecked("receiver"), - ); + let msg = PostsMsg::accept_post_owner_transfer_request(1, 1, Addr::unchecked("receiver")); let expected = MsgAcceptPostOwnerTransferRequest { subspace_id: 1, @@ -491,11 +487,7 @@ mod tests { #[test] fn test_refuse_post_owner_transfer_request() { - let msg = PostsMsg::refuse_post_owner_transfer_request( - 1, - 1, - Addr::unchecked("receiver"), - ); + let msg = PostsMsg::refuse_post_owner_transfer_request(1, 1, Addr::unchecked("receiver")); let expected = MsgRefusePostOwnerTransferRequest { subspace_id: 1, From 271fb3e55def78e20104403416cecd8c7aa3fbca Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Thu, 24 Aug 2023 16:52:28 +0800 Subject: [PATCH 05/16] test: add move post interaction test --- packages/bindings-test/src/consts.rs | 6 +++ packages/bindings-test/src/posts/mod.rs | 58 +++++++++++++++++++++++++ packages/bindings-test/src/posts/msg.rs | 38 ++++++++++++++++ 3 files changed, 102 insertions(+) diff --git a/packages/bindings-test/src/consts.rs b/packages/bindings-test/src/consts.rs index bf78cfa3..847c6489 100644 --- a/packages/bindings-test/src/consts.rs +++ b/packages/bindings-test/src/consts.rs @@ -8,17 +8,23 @@ pub const USER1_ADDRESS: &str = "desmos1jnpfa06xhflyjh6klwlrq8mk55s53czh6ncdm3"; pub const USER2_KEY: &str = "user2"; pub const USER2_ADDRESS: &str = "desmos1ptvq7l4jt7n9sc3fky22mfvc6waf2jd8nuc0jv"; +// x/subspaces pub const TEST_SUBSPACE: u64 = 1; pub const TEST_SUBSPACE_USER_GROUP: u32 = 1; + +// x/posts pub const TEST_SUBSPACE_EDITABLE_POST_ID: u64 = 1; pub const TEST_SUBSPACE_DELETABLE_POST_ID: u64 = 2; pub const TEST_DELETABLE_ATTACHMENT_ID: u32 = 2; pub const TEST_POLL_ID: u32 = 1; + +// x/reports pub const TEST_REASON_ID: u32 = 1; pub const TEST_DELETABLE_REASON_ID: u32 = 2; pub const TEST_REPORT_ID_WITH_USER_TARGET: u64 = 1; pub const TEST_DELETABLE_REPORT_ID: u64 = 3; +// x/reactions pub const TEST_EDITABLE_REGISTERED_REACTION_ID: u32 = 1; pub const TEST_DELETABLE_REGISTERED_REACTION_ID: u32 = 2; pub const TEST_REACTIONS_POST_ID: u64 = 3; diff --git a/packages/bindings-test/src/posts/mod.rs b/packages/bindings-test/src/posts/mod.rs index 3cb8faed..47578fab 100644 --- a/packages/bindings-test/src/posts/mod.rs +++ b/packages/bindings-test/src/posts/mod.rs @@ -1,2 +1,60 @@ mod msg; mod query; + +use crate::chain_communication::DesmosCli; +use cosmwasm_std::Addr; + +use desmos_bindings::cosmos_types::PageRequest; +use desmos_bindings::posts::msg::PostsMsg; +use desmos_bindings::posts::types::Post; + +pub fn create_sample_post(subspace_id: u64, contract_address: &str) -> &Post { + let desmos_cli = DesmosCli::default(); + + // Create a post + desmos_cli + .execute_contract(contract, PostsMsg::create_post( + subspace_id, + 0, + None, + "Sample post", + Some(Entities { + urls: vec![Url { + start: 0, + end: 1, + url: "https://ipfs.infura.io/ipfs/QmT3AenKHkhCeesTUdnarqUVu91mmBk1cxQknxnUd79gY7" + .into(), + display_url: "IPFS".into(), + }], + hashtags: vec![], + mentions: vec![], + }), + vec![], + vec![], + Addr::unchecked(contract_address), + None, + ReplySetting::Everyone, + vec![], + )) + .assert_success(); + + // query the created post + let result: QuerySubspacePostsResponse = desmos_cli.wasm_query( + contract_address, + DesmosChain { + request: QuerySubspacePostsRequest { + subspace_id, + pagination: Some(PageRequest { + key: vec![], + limit: 1, + offset: 0, + count_total: false, + reverse: true, + }), + } + .into(), + }, + ); + + result.posts.first().unwrap() +} diff --git a/packages/bindings-test/src/posts/msg.rs b/packages/bindings-test/src/posts/msg.rs index 9f969fcc..e1e8dd0c 100644 --- a/packages/bindings-test/src/posts/msg.rs +++ b/packages/bindings-test/src/posts/msg.rs @@ -5,6 +5,8 @@ mod test { TEST_DELETABLE_ATTACHMENT_ID, TEST_POLL_ID, TEST_SUBSPACE, TEST_SUBSPACE_DELETABLE_POST_ID, TEST_SUBSPACE_EDITABLE_POST_ID, }; + use crate::posts::create_sample_post; + use chrono::DateTime; use cosmwasm_std::Addr; use desmos_bindings::posts::msg::PostsMsg; @@ -12,6 +14,7 @@ mod test { poll::ProvidedAnswer, AttachmentContent, Entities, Media, Poll, PostReference, PostReferenceType, ReplySetting, Url, }; + use desmos_bindings::subspaces::msg::SubspacesMsg; use test_contract::msg::ExecuteMsg; #[test] @@ -200,4 +203,39 @@ mod test { ) .assert_success(); } + + #[test] + fn test_move_post() { + let desmos_cli = DesmosCli::default(); + let contract_address = desmos_cli.get_contract_by_code(1); + + // Create target subspace for moving post + desmos_cli + .execute_contract( + &contract_address, + vec![SubspacesMsg::create_subspace( + "Test target subspace", + "", + Addr::unchecked(&contract), + Addr::unchecked(&contract), + )], + ) + .assert_success(); + + // Get target subspace and post + let target_subspace = desmos_cli.query_subspaces(None).subspaces.last().unwrap(); + let post = create_sample_post(TEST_SUBSPACE, &contract_address); + + let move_post_msg = PostsMsg::move_post( + TEST_SUBSPACE, + post.id, + target_subspace.id, + 0, + contract_address, + ); + + desmos_cli + .execute_contract(&contract_address, [move_post_msg]) + .assert_success() + } } From b4ab9ef190dc551b69fd5163d538c00ea87d6a92 Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Thu, 24 Aug 2023 16:52:59 +0800 Subject: [PATCH 06/16] test: add second contract for post transfer owner testing --- .../bindings-test/src/chain_communication.rs | 5 +- packages/bindings-test/src/posts/mod.rs | 48 +++++++++++-------- packages/bindings-test/src/posts/msg.rs | 27 ++++++----- packages/bindings-test/src/posts/query.rs | 10 ++-- packages/bindings-test/src/profiles/msg.rs | 14 +++--- packages/bindings-test/src/profiles/query.rs | 14 +++--- packages/bindings-test/src/reactions/msg.rs | 12 ++--- packages/bindings-test/src/reactions/query.rs | 12 ++--- .../bindings-test/src/relationships/msg.rs | 4 +- .../bindings-test/src/relationships/query.rs | 12 ++--- packages/bindings-test/src/reports/msg.rs | 10 ++-- packages/bindings-test/src/reports/query.rs | 8 ++-- packages/bindings-test/src/setup.rs | 2 +- packages/bindings-test/src/subspaces/msg.rs | 22 ++++----- packages/bindings-test/src/subspaces/query.rs | 16 +++---- scripts/deploy_contract.sh | 6 +++ 16 files changed, 120 insertions(+), 102 deletions(-) diff --git a/packages/bindings-test/src/chain_communication.rs b/packages/bindings-test/src/chain_communication.rs index 8b5ca4ad..48d919b5 100644 --- a/packages/bindings-test/src/chain_communication.rs +++ b/packages/bindings-test/src/chain_communication.rs @@ -130,7 +130,8 @@ impl DesmosCli { /// Gets a contract address by it's id. /// /// * `id` - ID of the contract of interest. - pub fn get_contract_by_code(&self, id: u64) -> String { + /// * `offset` - Offset of the target contract. + pub fn get_contract_by_code(&self, id: u64, offset: usize) -> String { let mut cmd = self.desmos(); cmd.arg("query") @@ -144,7 +145,7 @@ impl DesmosCli { result .contracts - .get(0) + .get(offset) .expect(&format!("can't find smart contract with id {}", id)) .to_string() } diff --git a/packages/bindings-test/src/posts/mod.rs b/packages/bindings-test/src/posts/mod.rs index 47578fab..72cb6cb0 100644 --- a/packages/bindings-test/src/posts/mod.rs +++ b/packages/bindings-test/src/posts/mod.rs @@ -4,16 +4,20 @@ mod query; use crate::chain_communication::DesmosCli; use cosmwasm_std::Addr; +use test_contract::msg::QueryMsg::DesmosChain; + use desmos_bindings::cosmos_types::PageRequest; use desmos_bindings::posts::msg::PostsMsg; -use desmos_bindings::posts::types::Post; +use desmos_bindings::posts::types::{ + Entities, Post, QuerySubspacePostsRequest, QuerySubspacePostsResponse, ReplySetting, Url, +}; -pub fn create_sample_post(subspace_id: u64, contract_address: &str) -> &Post { +pub fn create_sample_post(subspace_id: u64, contract_address: &str) -> Post { let desmos_cli = DesmosCli::default(); // Create a post desmos_cli - .execute_contract(contract, PostsMsg::create_post( + .execute_contract(contract_address, vec![PostsMsg::create_post( subspace_id, 0, None, @@ -35,26 +39,28 @@ pub fn create_sample_post(subspace_id: u64, contract_address: &str) -> &Post { None, ReplySetting::Everyone, vec![], - )) + )]) .assert_success(); // query the created post - let result: QuerySubspacePostsResponse = desmos_cli.wasm_query( - contract_address, - DesmosChain { - request: QuerySubspacePostsRequest { - subspace_id, - pagination: Some(PageRequest { - key: vec![], - limit: 1, - offset: 0, - count_total: false, - reverse: true, - }), - } - .into(), - }, - ); + let result: QuerySubspacePostsResponse = desmos_cli + .wasm_query( + contract_address, + &DesmosChain { + request: QuerySubspacePostsRequest { + subspace_id, + pagination: Some(PageRequest { + key: vec![], + limit: 1, + offset: 0, + count_total: false, + reverse: true, + }), + } + .into(), + }, + ) + .to_object(); - result.posts.first().unwrap() + result.posts.first().unwrap().clone() } diff --git a/packages/bindings-test/src/posts/msg.rs b/packages/bindings-test/src/posts/msg.rs index e1e8dd0c..26359486 100644 --- a/packages/bindings-test/src/posts/msg.rs +++ b/packages/bindings-test/src/posts/msg.rs @@ -20,7 +20,7 @@ mod test { #[test] fn test_create_post() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let msg = PostsMsg::create_post( TEST_SUBSPACE, @@ -53,7 +53,7 @@ mod test { #[test] fn test_edit_post() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let msg = PostsMsg::edit_post( TEST_SUBSPACE, @@ -88,7 +88,7 @@ mod test { #[test] fn test_delete_post() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let msg = PostsMsg::delete_post( TEST_SUBSPACE, @@ -109,7 +109,7 @@ mod test { #[test] fn test_add_media_post_attachment() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let msg_add_media = PostsMsg::add_post_attachment( TEST_SUBSPACE, @@ -162,7 +162,7 @@ mod test { #[test] fn test_remove_post_attachment() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let msg = PostsMsg::remove_post_attachment( TEST_SUBSPACE, @@ -184,7 +184,7 @@ mod test { #[test] fn test_answer_poll() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let msg = PostsMsg::answer_poll( TEST_SUBSPACE, @@ -207,7 +207,7 @@ mod test { #[test] fn test_move_post() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); // Create target subspace for moving post desmos_cli @@ -216,14 +216,19 @@ mod test { vec![SubspacesMsg::create_subspace( "Test target subspace", "", - Addr::unchecked(&contract), - Addr::unchecked(&contract), + Addr::unchecked(&contract_address), + Addr::unchecked(&contract_address), )], ) .assert_success(); // Get target subspace and post - let target_subspace = desmos_cli.query_subspaces(None).subspaces.last().unwrap(); + let target_subspace = desmos_cli + .query_subspaces(None) + .subspaces + .last() + .unwrap() + .clone(); let post = create_sample_post(TEST_SUBSPACE, &contract_address); let move_post_msg = PostsMsg::move_post( @@ -231,7 +236,7 @@ mod test { post.id, target_subspace.id, 0, - contract_address, + Addr::unchecked(&contract_address), ); desmos_cli diff --git a/packages/bindings-test/src/posts/query.rs b/packages/bindings-test/src/posts/query.rs index e6eace3b..2ee4c388 100644 --- a/packages/bindings-test/src/posts/query.rs +++ b/packages/bindings-test/src/posts/query.rs @@ -80,7 +80,7 @@ mod test { .into(), }; - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let result: QuerySubspacePostsResponse = desmos_cli .wasm_query(&contract_address, &query_msg) @@ -103,7 +103,7 @@ mod test { .into(), }; - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let result: QuerySectionPostsResponse = desmos_cli .wasm_query(&contract_address, &query_msg) @@ -125,7 +125,7 @@ mod test { .into(), }; - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let result: QueryPostResponse = desmos_cli .wasm_query(&contract_address, &query_msg) @@ -151,7 +151,7 @@ mod test { .into(), }; - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let result: QueryPostAttachmentsResponse = desmos_cli .wasm_query(&contract_address, &query_msg) @@ -194,7 +194,7 @@ mod test { #[test] fn test_query_poll_answers() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let msg = MsgAnswerPoll { subspace_id: TEST_SUBSPACE, diff --git a/packages/bindings-test/src/profiles/msg.rs b/packages/bindings-test/src/profiles/msg.rs index e543dade..f800a440 100644 --- a/packages/bindings-test/src/profiles/msg.rs +++ b/packages/bindings-test/src/profiles/msg.rs @@ -27,7 +27,7 @@ mod tests { #[test] fn test_create_profile() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let save_profile_msg = build_save_profile_msg(&contract_address); @@ -39,7 +39,7 @@ mod tests { #[test] fn test_delete_profile() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let save_profile_msg = build_save_profile_msg(&contract_address); @@ -61,7 +61,7 @@ mod tests { #[test] pub fn test_request_dtag_transfer() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let dtag_transfer_request = ProfilesMsg::request_dtag_transfer( Addr::unchecked(&contract_address), @@ -93,7 +93,7 @@ mod tests { #[test] fn test_accept_dtag_transfer() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); // Create a profile for the smart contract let save_profile = ProfilesMsg::save_profile( @@ -144,7 +144,7 @@ mod tests { #[test] fn test_refuse_dtag_transfer_request() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); // Create a profile for the smart contract let save_profile = ProfilesMsg::save_profile( @@ -194,7 +194,7 @@ mod tests { #[test] fn test_link_unlink_chain_account() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); // Create a profile for the smart contract let save_profile = ProfilesMsg::save_profile( @@ -249,7 +249,7 @@ mod tests { #[test] fn test_set_default_external_address() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); // Create a profile for the smart contract let save_profile = ProfilesMsg::save_profile( diff --git a/packages/bindings-test/src/profiles/query.rs b/packages/bindings-test/src/profiles/query.rs index d7c7b672..64ee6889 100644 --- a/packages/bindings-test/src/profiles/query.rs +++ b/packages/bindings-test/src/profiles/query.rs @@ -25,7 +25,7 @@ mod tests { .into(), }; - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let result: QueryProfileResponse = desmos_cli .wasm_query(&contract_address, &query_msg) @@ -56,7 +56,7 @@ mod tests { .into(), }; - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let result: QueryIncomingDTagTransferRequestsResponse = desmos_cli .wasm_query(&contract_address, &query_msg) .to_object(); @@ -81,7 +81,7 @@ mod tests { .into(), }; - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let result: QueryChainLinksResponse = desmos_cli .wasm_query(&contract_address, &query_msg) .to_object(); @@ -122,7 +122,7 @@ mod tests { .into(), }; - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let result: QueryChainLinksResponse = desmos_cli .wasm_query(&contract_address, &query_msg) .to_object(); @@ -152,7 +152,7 @@ mod tests { .into(), }; - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let result: QueryChainLinksResponse = desmos_cli .wasm_query(&contract_address, &query_msg) .to_object(); @@ -181,7 +181,7 @@ mod tests { .into(), }; - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let result: QueryChainLinkOwnersResponse = desmos_cli .wasm_query(&contract_address, &query_msg) .to_object(); @@ -206,7 +206,7 @@ mod tests { } .into(), }; - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let result: QueryDefaultExternalAddressesResponse = desmos_cli .wasm_query(&contract_address, &query_msg) .to_object(); diff --git a/packages/bindings-test/src/reactions/msg.rs b/packages/bindings-test/src/reactions/msg.rs index 9ff3b924..ee7bdde6 100644 --- a/packages/bindings-test/src/reactions/msg.rs +++ b/packages/bindings-test/src/reactions/msg.rs @@ -15,7 +15,7 @@ mod tests { #[test] fn test_add_reaction() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let msg = ReactionsMsg::add_reaction( TEST_SUBSPACE, @@ -39,7 +39,7 @@ mod tests { #[test] fn test_remove_reaction() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let msg = ReactionsMsg::remove_reaction( TEST_SUBSPACE, @@ -61,7 +61,7 @@ mod tests { #[test] fn test_add_registered_reaction() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let msg = ReactionsMsg::add_registered_reaction( TEST_SUBSPACE, @@ -83,7 +83,7 @@ mod tests { #[test] fn test_edit_registered_reaction() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let msg = ReactionsMsg::edit_registered_reaction( TEST_SUBSPACE, @@ -106,7 +106,7 @@ mod tests { #[test] fn test_remove_registered_reaction() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let msg = ReactionsMsg::remove_registered_reaction( TEST_SUBSPACE, @@ -127,7 +127,7 @@ mod tests { #[test] fn test_set_reactions_params() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let msg = ReactionsMsg::set_reactions_params( TEST_SUBSPACE, diff --git a/packages/bindings-test/src/reactions/query.rs b/packages/bindings-test/src/reactions/query.rs index f09a79e3..78afc0d8 100644 --- a/packages/bindings-test/src/reactions/query.rs +++ b/packages/bindings-test/src/reactions/query.rs @@ -31,7 +31,7 @@ mod tests { .into(), }; - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let result: QueryReactionsResponse = desmos_cli .wasm_query(&contract_address, &query_msg) @@ -66,7 +66,7 @@ mod tests { .into(), }; - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let result: QueryReactionResponse = desmos_cli .wasm_query(&contract_address, &query_msg) @@ -100,7 +100,7 @@ mod tests { .into(), }; - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let result: QueryReactionResponse = desmos_cli .wasm_query(&contract_address, &query_msg) @@ -133,7 +133,7 @@ mod tests { .into(), }; - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let result: QueryRegisteredReactionsResponse = desmos_cli .wasm_query(&contract_address, &query_msg) @@ -161,7 +161,7 @@ mod tests { .into(), }; - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let result: QueryRegisteredReactionResponse = desmos_cli .wasm_query(&contract_address, &query_msg) @@ -187,7 +187,7 @@ mod tests { .into(), }; - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let result: QueryReactionsParamsResponse = desmos_cli .wasm_query(&contract_address, &query_msg) diff --git a/packages/bindings-test/src/relationships/msg.rs b/packages/bindings-test/src/relationships/msg.rs index c363fbd7..8ab58c65 100644 --- a/packages/bindings-test/src/relationships/msg.rs +++ b/packages/bindings-test/src/relationships/msg.rs @@ -9,7 +9,7 @@ mod tests { #[test] fn test_create_delete_relationship() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let create_relationship = RelationshipsMsg::create_relationship( Addr::unchecked(&contract_address), @@ -43,7 +43,7 @@ mod tests { #[test] fn test_block_unblock_user() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let block_user = RelationshipsMsg::block_user( Addr::unchecked(&contract_address), diff --git a/packages/bindings-test/src/relationships/query.rs b/packages/bindings-test/src/relationships/query.rs index 00ce7e30..a3b09950 100644 --- a/packages/bindings-test/src/relationships/query.rs +++ b/packages/bindings-test/src/relationships/query.rs @@ -11,7 +11,7 @@ mod tests { #[test] fn test_query_all_relationships() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let query = DesmosChain { request: QueryRelationshipsRequest { @@ -33,7 +33,7 @@ mod tests { #[test] fn test_query_user1_relationships() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let query = DesmosChain { request: QueryRelationshipsRequest { @@ -61,7 +61,7 @@ mod tests { #[test] fn test_query_user1_user2_relationship() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let query = DesmosChain { request: QueryRelationshipsRequest { @@ -89,7 +89,7 @@ mod tests { #[test] fn test_query_all_blocks() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let query = DesmosChain { request: QueryBlocksRequest { @@ -111,7 +111,7 @@ mod tests { #[test] fn test_query_user2_blocks() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let query = DesmosChain { request: QueryBlocksRequest { @@ -139,7 +139,7 @@ mod tests { #[test] fn test_query_user2_user1_block() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let query = DesmosChain { request: QueryBlocksRequest { diff --git a/packages/bindings-test/src/reports/msg.rs b/packages/bindings-test/src/reports/msg.rs index a329b633..60a801c7 100644 --- a/packages/bindings-test/src/reports/msg.rs +++ b/packages/bindings-test/src/reports/msg.rs @@ -12,7 +12,7 @@ mod tests { #[test] fn test_create_report() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let create_report = ReportsMsg::create_report( TEST_SUBSPACE, @@ -36,7 +36,7 @@ mod tests { #[test] fn test_delete_report() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let delete_report = ReportsMsg::delete_report( TEST_SUBSPACE, @@ -56,7 +56,7 @@ mod tests { #[test] fn test_support_standard_reason() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let delete_report = ReportsMsg::support_standard_reason( TEST_SUBSPACE, @@ -76,7 +76,7 @@ mod tests { #[test] fn test_add_reason() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let add_reason = ReportsMsg::add_reason( TEST_SUBSPACE, @@ -97,7 +97,7 @@ mod tests { #[test] fn test_remove_reason() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let remove_reason = ReportsMsg::remove_reason( TEST_SUBSPACE, diff --git a/packages/bindings-test/src/reports/query.rs b/packages/bindings-test/src/reports/query.rs index 90f7882e..0ff5adf1 100644 --- a/packages/bindings-test/src/reports/query.rs +++ b/packages/bindings-test/src/reports/query.rs @@ -16,7 +16,7 @@ mod tests { #[test] fn test_query_reports() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); // Query all let query = DesmosChain { @@ -91,7 +91,7 @@ mod tests { #[test] fn test_query_report() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); // Query all let query = DesmosChain { @@ -117,7 +117,7 @@ mod tests { #[test] fn test_query_reasons() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); // Query all let query = DesmosChain { @@ -143,7 +143,7 @@ mod tests { #[test] fn test_query_reason() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); // Query all let query = DesmosChain { diff --git a/packages/bindings-test/src/setup.rs b/packages/bindings-test/src/setup.rs index be711d84..c3034813 100644 --- a/packages/bindings-test/src/setup.rs +++ b/packages/bindings-test/src/setup.rs @@ -27,7 +27,7 @@ use desmos_bindings::subspaces::{ pub fn setup() { let cli = DesmosCli::default(); - let contract = cli.get_contract_by_code(1); + let contract = cli.get_contract_by_code(1, 0); // Create a profile for the smart contract to allow the creation of posts cli.execute_contract( diff --git a/packages/bindings-test/src/subspaces/msg.rs b/packages/bindings-test/src/subspaces/msg.rs index 0829d615..0a3db575 100644 --- a/packages/bindings-test/src/subspaces/msg.rs +++ b/packages/bindings-test/src/subspaces/msg.rs @@ -27,7 +27,7 @@ mod tests { #[test] fn test_create_subspace() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let create_subspace_msg = build_create_subspace_msg(&contract_address); @@ -39,7 +39,7 @@ mod tests { #[test] fn test_edit_subspace() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let subspace_id = TEST_SUBSPACE; let new_subspace_name = "Test subspace"; @@ -66,7 +66,7 @@ mod tests { #[test] fn test_delete_subspace() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let create_subspace_msg = build_create_subspace_msg(&contract_address); @@ -109,7 +109,7 @@ mod tests { #[test] pub fn test_create_user_group() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let create_user_group_msg = build_create_user_group_msg(TEST_SUBSPACE, &contract_address); @@ -121,7 +121,7 @@ mod tests { #[test] pub fn test_delete_user_group() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let subspace_id = TEST_SUBSPACE; // Create the user group to delete. @@ -154,7 +154,7 @@ mod tests { #[test] pub fn test_edit_user_group() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let subspace_id = TEST_SUBSPACE; let group_id = TEST_SUBSPACE_USER_GROUP; let new_user_group_name = "Test user group"; @@ -186,7 +186,7 @@ mod tests { #[test] pub fn test_set_user_group_permissions() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let subspace_id = TEST_SUBSPACE; let group_id = TEST_SUBSPACE_USER_GROUP; let new_permissions = vec![Permission::EditSubspace]; @@ -210,7 +210,7 @@ mod tests { #[test] pub fn test_add_remove_user_from_user_group() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let subspace_id = TEST_SUBSPACE; let group_id = TEST_SUBSPACE_USER_GROUP; @@ -252,7 +252,7 @@ mod tests { #[test] pub fn test_set_user_permissions() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let subspace_id = TEST_SUBSPACE; let new_permissions = vec![ Permission::EditSubspace, @@ -284,7 +284,7 @@ mod tests { #[test] pub fn test_grant_revoke_treasury_authorization() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let subspace_id = TEST_SUBSPACE; let grant_treasury_authorization = SubspacesMsg::grant_treasury_authorization( @@ -329,7 +329,7 @@ mod tests { #[test] pub fn test_grant_revoke_allowance() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let subspace_id = TEST_SUBSPACE; let grant_allowance = SubspacesMsg::grant_allowance( diff --git a/packages/bindings-test/src/subspaces/query.rs b/packages/bindings-test/src/subspaces/query.rs index 8962b6c8..6235de0b 100644 --- a/packages/bindings-test/src/subspaces/query.rs +++ b/packages/bindings-test/src/subspaces/query.rs @@ -20,7 +20,7 @@ mod tests { #[test] fn test_query_all_subspaces() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let query = DesmosChain { request: QuerySubspacesRequest { pagination: None }.into(), @@ -39,7 +39,7 @@ mod tests { #[test] fn test_query_subspace() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let query = DesmosChain { request: QuerySubspaceRequest { @@ -61,7 +61,7 @@ mod tests { #[test] fn test_query_user_groups() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let query = DesmosChain { request: QueryUserGroupsRequest { @@ -91,7 +91,7 @@ mod tests { #[test] fn test_query_user_group() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let query = DesmosChain { request: QueryUserGroupRequest { @@ -120,7 +120,7 @@ mod tests { #[test] fn test_query_user_group_members() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let query = DesmosChain { request: QueryUserGroupMembersRequest { @@ -144,7 +144,7 @@ mod tests { #[test] fn test_query_user_permissions() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let query = DesmosChain { request: QueryUserPermissionsRequest { @@ -207,7 +207,7 @@ mod tests { #[test] fn test_query_user_allowances() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let query = DesmosChain { request: QueryUserAllowancesRequest { @@ -245,7 +245,7 @@ mod tests { #[test] fn test_query_group_allowances() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let query = DesmosChain { request: QueryGroupAllowancesRequest { diff --git a/scripts/deploy_contract.sh b/scripts/deploy_contract.sh index 56a0da83..3f0bc32d 100755 --- a/scripts/deploy_contract.sh +++ b/scripts/deploy_contract.sh @@ -30,6 +30,12 @@ echo $KEYRING_PASS | desmos --keyring-backend=file tx wasm instantiate 1 "{}" \ --from $USER1 --label "test-contract" --admin $USER1_ADDRESS --chain-id=testchain -b=sync -y echo "Contract initialized" +# Initialize the second contract +echo "Initializing second contract..." +echo $KEYRING_PASS | desmos --keyring-backend=file tx wasm instantiate 1 "{}" \ + --from $USER1 --label "test-contract" --admin $USER1_ADDRESS --chain-id=testchain -b=sync -y +echo "Second contract initialized" + # Print contract address CONTRACT=$(desmos query wasm list-contract-by-code 1 --output json | jq -r '.contracts[-1]') echo "Contract address $CONTRACT" From 08dfc339473428b1baae8d4116a8be5a1a0c24bc Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Thu, 24 Aug 2023 18:15:00 +0800 Subject: [PATCH 07/16] test: add post owner request interation tests --- packages/bindings-test/src/posts/mod.rs | 47 ++++++------ packages/bindings-test/src/posts/msg.rs | 98 ++++++++++++++++++++++++- 2 files changed, 120 insertions(+), 25 deletions(-) diff --git a/packages/bindings-test/src/posts/mod.rs b/packages/bindings-test/src/posts/mod.rs index 72cb6cb0..0fe147f7 100644 --- a/packages/bindings-test/src/posts/mod.rs +++ b/packages/bindings-test/src/posts/mod.rs @@ -16,30 +16,31 @@ pub fn create_sample_post(subspace_id: u64, contract_address: &str) -> Post { let desmos_cli = DesmosCli::default(); // Create a post + let create_post_msg = PostsMsg::create_post( + subspace_id, + 0, + None, + "Sample post", + Some(Entities { + urls: vec![Url { + start: 0, + end: 1, + url: "https://ipfs.infura.io/ipfs/QmT3AenKHkhCeesTUdnarqUVu91mmBk1cxQknxnUd79gY7" + .into(), + display_url: "IPFS".into(), + }], + hashtags: vec![], + mentions: vec![], + }), + vec![], + vec![], + Addr::unchecked(contract_address), + None, + ReplySetting::Everyone, + vec![], + ); desmos_cli - .execute_contract(contract_address, vec![PostsMsg::create_post( - subspace_id, - 0, - None, - "Sample post", - Some(Entities { - urls: vec![Url { - start: 0, - end: 1, - url: "https://ipfs.infura.io/ipfs/QmT3AenKHkhCeesTUdnarqUVu91mmBk1cxQknxnUd79gY7" - .into(), - display_url: "IPFS".into(), - }], - hashtags: vec![], - mentions: vec![], - }), - vec![], - vec![], - Addr::unchecked(contract_address), - None, - ReplySetting::Everyone, - vec![], - )]) + .execute_contract(contract_address, vec![create_post_msg.into()]) .assert_success(); // query the created post diff --git a/packages/bindings-test/src/posts/msg.rs b/packages/bindings-test/src/posts/msg.rs index 26359486..ea6f6b49 100644 --- a/packages/bindings-test/src/posts/msg.rs +++ b/packages/bindings-test/src/posts/msg.rs @@ -218,7 +218,8 @@ mod test { "", Addr::unchecked(&contract_address), Addr::unchecked(&contract_address), - )], + ) + .into()], ) .assert_success(); @@ -240,7 +241,100 @@ mod test { ); desmos_cli - .execute_contract(&contract_address, [move_post_msg]) + .execute_contract(&contract_address, [move_post_msg.into()]) + .assert_success() + } + + #[test] + fn test_request_then_cancel_post_owner_transfer() { + let desmos_cli = DesmosCli::default(); + let contract_address = desmos_cli.get_contract_by_code(1, 0); + let receiver_contract_address = desmos_cli.get_contract_by_code(1, 1); + + let post = create_sample_post(TEST_SUBSPACE, &contract_address); + let request_post_owner_transfer_msg = PostsMsg::request_post_owner_transfer( + TEST_SUBSPACE, + post.id, + Addr::unchecked(&receiver_contract_address), + Addr::unchecked(&contract_address), + ); + + let cancel_post_owner_transfer_request_msg = PostsMsg::cancel_post_owner_transfer_request( + TEST_SUBSPACE, + post.id, + Addr::unchecked(&contract_address), + ); + + desmos_cli + .execute_contract( + &contract_address, + [ + request_post_owner_transfer_msg.into(), + cancel_post_owner_transfer_request_msg.into(), + ], + ) + .assert_success() + } + + #[test] + fn test_request_then_accept_post_owner_transfer() { + let desmos_cli = DesmosCli::default(); + let contract_address = desmos_cli.get_contract_by_code(1, 0); + let receiver_contract_address = desmos_cli.get_contract_by_code(1, 1); + + let post = create_sample_post(TEST_SUBSPACE, &contract_address); + let request_post_owner_transfer_msg = PostsMsg::request_post_owner_transfer( + TEST_SUBSPACE, + post.id, + Addr::unchecked(&receiver_contract_address), + Addr::unchecked(&contract_address), + ); + + let accept_post_owner_transfer_request_msg = PostsMsg::accept_post_owner_transfer_request( + TEST_SUBSPACE, + post.id, + Addr::unchecked(&receiver_contract_address), + ); + + desmos_cli + .execute_contract( + &contract_address, + [ + request_post_owner_transfer_msg.into(), + accept_post_owner_transfer_request_msg.into(), + ], + ) + .assert_success() + } + + #[test] + fn test_request_then_refuse_post_owner_transfer() { + let desmos_cli = DesmosCli::default(); + let contract_address = desmos_cli.get_contract_by_code(1, 0); + let receiver_contract_address = desmos_cli.get_contract_by_code(1, 1); + + let post = create_sample_post(TEST_SUBSPACE, &contract_address); + let request_post_owner_transfer_msg = PostsMsg::request_post_owner_transfer( + TEST_SUBSPACE, + post.id, + Addr::unchecked(&receiver_contract_address), + Addr::unchecked(&contract_address), + ); + + let refuse_post_owner_transfer_request_msg = PostsMsg::refuse_post_owner_transfer_request( + TEST_SUBSPACE, + post.id, + Addr::unchecked(&receiver_contract_address), + ); + + desmos_cli + .execute_contract( + &contract_address, + [ + request_post_owner_transfer_msg.into(), + refuse_post_owner_transfer_request_msg.into(), + ], + ) .assert_success() } } From e2f7f2237a126e7baeb93098c78951a19147cc95 Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Thu, 24 Aug 2023 20:12:19 +0800 Subject: [PATCH 08/16] test: add query post owner transfer request interation test --- .../bindings-test/src/chain_communication.rs | 4 +- packages/bindings-test/src/posts/query.rs | 51 +++++++++++++++++-- packages/bindings-test/src/setup.rs | 16 ++++++ scripts/deploy_contract.sh | 41 --------------- scripts/upload_test_contract.sh | 6 +++ 5 files changed, 73 insertions(+), 45 deletions(-) delete mode 100755 scripts/deploy_contract.sh diff --git a/packages/bindings-test/src/chain_communication.rs b/packages/bindings-test/src/chain_communication.rs index 48d919b5..8d866163 100644 --- a/packages/bindings-test/src/chain_communication.rs +++ b/packages/bindings-test/src/chain_communication.rs @@ -138,6 +138,8 @@ impl DesmosCli { .arg("wasm") .arg("list-contract-by-code") .arg(id.to_string()) + .arg(format!("--offset={}", offset)) + .arg(format!("--limit=1")) .arg("--output=json"); let output = DesmosCli::run_command(&mut cmd); @@ -145,7 +147,7 @@ impl DesmosCli { result .contracts - .get(offset) + .get(0) .expect(&format!("can't find smart contract with id {}", id)) .to_string() } diff --git a/packages/bindings-test/src/posts/query.rs b/packages/bindings-test/src/posts/query.rs index 2ee4c388..ca87b918 100644 --- a/packages/bindings-test/src/posts/query.rs +++ b/packages/bindings-test/src/posts/query.rs @@ -2,15 +2,18 @@ mod test { use crate::chain_communication::DesmosCli; use crate::consts::{TEST_POLL_ID, TEST_SUBSPACE, TEST_SUBSPACE_EDITABLE_POST_ID}; + use crate::posts::create_sample_post; use chrono::DateTime; use cosmwasm_std::Addr; + use desmos_bindings::posts::msg::PostsMsg; use desmos_bindings::posts::types::{ poll::ProvidedAnswer, Entities, Poll, Post, ReplySetting, Url, }; use desmos_bindings::posts::types::{ - MsgAnswerPoll, QueryPollAnswersRequest, QueryPollAnswersResponse, - QueryPostAttachmentsRequest, QueryPostAttachmentsResponse, QueryPostRequest, - QueryPostResponse, QuerySectionPostsRequest, QuerySectionPostsResponse, + MsgAnswerPoll, PostOwnerTransferRequest, QueryIncomingPostOwnerTransferRequestsRequest, + QueryIncomingPostOwnerTransferRequestsResponse, QueryPollAnswersRequest, + QueryPollAnswersResponse, QueryPostAttachmentsRequest, QueryPostAttachmentsResponse, + QueryPostRequest, QueryPostResponse, QuerySectionPostsRequest, QuerySectionPostsResponse, QuerySubspacePostsRequest, QuerySubspacePostsResponse, }; use test_contract::msg::ExecuteMsg; @@ -232,4 +235,46 @@ mod test { assert_eq!(Addr::unchecked(&contract_address), answer.user); assert_eq!(vec![0], answer.answers_indexes) } + + #[test] + fn test_query_incoming_post_owner_transfer_requests() { + let desmos_cli = DesmosCli::default(); + let contract_address = desmos_cli.get_contract_by_code(1, 0); + let receiver_contract_address = desmos_cli.get_contract_by_code(1, 1); + + let post = create_sample_post(TEST_SUBSPACE, &contract_address); + desmos_cli + .execute_contract( + &contract_address, + [PostsMsg::request_post_owner_transfer( + TEST_SUBSPACE, + post.id, + Addr::unchecked(&receiver_contract_address), + Addr::unchecked(&contract_address), + ) + .into()], + ) + .assert_success(); + + let query_msg = DesmosChain { + request: QueryIncomingPostOwnerTransferRequestsRequest { + subspace_id: TEST_SUBSPACE, + receiver: receiver_contract_address.clone(), + pagination: None, + } + .into(), + }; + + let result: QueryIncomingPostOwnerTransferRequestsResponse = desmos_cli + .wasm_query(&contract_address, &query_msg) + .to_object(); + + let request = result.requests.first().unwrap(); + assert_eq!(&PostOwnerTransferRequest { + subspace_id: TEST_SUBSPACE, + post_id: post.id, + sender: contract_address.clone(), + receiver: receiver_contract_address.clone(), + }, request) + } } diff --git a/packages/bindings-test/src/setup.rs b/packages/bindings-test/src/setup.rs index c3034813..4b0ae676 100644 --- a/packages/bindings-test/src/setup.rs +++ b/packages/bindings-test/src/setup.rs @@ -44,6 +44,22 @@ pub fn setup() { ) .assert_success(); + // Create a profile for target contract + let target_contract = cli.get_contract_by_code(1, 1); + cli.execute_contract( + &target_contract, + vec![ProfilesMsg::save_profile( + Some("test_profile_posts"), + Some("contract_nick"), + Some("test_bio"), + Some("https://i.imgur.com/X2aK5Bq.jpeg"), + Some("https://i.imgur.com/X2aK5Bq.jpeg"), + Addr::unchecked(&target_contract), + ) + .into()], + ) + .assert_success(); + // Create test subspace owned by the smart contract cli.execute_contract( &contract, diff --git a/scripts/deploy_contract.sh b/scripts/deploy_contract.sh deleted file mode 100755 index 3f0bc32d..00000000 --- a/scripts/deploy_contract.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash - -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -DESMOS_HOME="$SCRIPT_DIR/.desmos" -KEYRING_PASS=pass1234 -# Smart contract dir -SMART_CONTRACT="$SCRIPT_DIR/../artifacts/test_contract.wasm" -# User 1 informations -USER1=user1 -USER1_ADDRESS=desmos1jnpfa06xhflyjh6klwlrq8mk55s53czh6ncdm3 - - - -desmos() { - "$SCRIPT_DIR/desmos" --home="$DESMOS_HOME" "$@" -} - -# Force the script to exit at the first error -set -e - -# Upload the smart contract -echo "Uploading contract..." -echo $KEYRING_PASS | desmos tx wasm store "$SMART_CONTRACT" \ - --from $USER1 --chain-id=testchain --keyring-backend=file -y --gas 30000000 \ - -b=sync - -# Initialize the contract -echo "Initializing contract..." -echo $KEYRING_PASS | desmos --keyring-backend=file tx wasm instantiate 1 "{}" \ - --from $USER1 --label "test-contract" --admin $USER1_ADDRESS --chain-id=testchain -b=sync -y -echo "Contract initialized" - -# Initialize the second contract -echo "Initializing second contract..." -echo $KEYRING_PASS | desmos --keyring-backend=file tx wasm instantiate 1 "{}" \ - --from $USER1 --label "test-contract" --admin $USER1_ADDRESS --chain-id=testchain -b=sync -y -echo "Second contract initialized" - -# Print contract address -CONTRACT=$(desmos query wasm list-contract-by-code 1 --output json | jq -r '.contracts[-1]') -echo "Contract address $CONTRACT" diff --git a/scripts/upload_test_contract.sh b/scripts/upload_test_contract.sh index 3b227117..b0f16c2d 100755 --- a/scripts/upload_test_contract.sh +++ b/scripts/upload_test_contract.sh @@ -33,3 +33,9 @@ echo $KEYRING_PASS | desmos --keyring-backend=file tx wasm instantiate 1 "{}" \ --from $USER1 --label "test-contract" --admin $USER1_ADDRESS --chain-id=testchain -b=sync -y echo "Contract initialized" +# Initialize the second contract +echo "Initializing second contract..." +echo $KEYRING_PASS | desmos --keyring-backend=file tx wasm instantiate 1 "{}" \ + --from $USER1 --label "test-contract-" --admin $USER1_ADDRESS --chain-id=testchain -b=sync -y +echo "Second contract initialized" + From 1c118bab025f226808b4252ce75349911e9688f0 Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Thu, 24 Aug 2023 20:12:40 +0800 Subject: [PATCH 09/16] chore: run lint --- packages/bindings-test/src/posts/query.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/bindings-test/src/posts/query.rs b/packages/bindings-test/src/posts/query.rs index ca87b918..77753f0c 100644 --- a/packages/bindings-test/src/posts/query.rs +++ b/packages/bindings-test/src/posts/query.rs @@ -270,11 +270,14 @@ mod test { .to_object(); let request = result.requests.first().unwrap(); - assert_eq!(&PostOwnerTransferRequest { - subspace_id: TEST_SUBSPACE, - post_id: post.id, - sender: contract_address.clone(), - receiver: receiver_contract_address.clone(), - }, request) + assert_eq!( + &PostOwnerTransferRequest { + subspace_id: TEST_SUBSPACE, + post_id: post.id, + sender: contract_address.clone(), + receiver: receiver_contract_address.clone(), + }, + request + ) } } From 7edaefada5fb69379a9d50b9ee9d26fda4447b6b Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Thu, 24 Aug 2023 20:22:33 +0800 Subject: [PATCH 10/16] test: fix accept/refuse msgs --- packages/bindings-test/src/posts/msg.rs | 26 +++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/bindings-test/src/posts/msg.rs b/packages/bindings-test/src/posts/msg.rs index ea6f6b49..ebfc9e3f 100644 --- a/packages/bindings-test/src/posts/msg.rs +++ b/packages/bindings-test/src/posts/msg.rs @@ -282,6 +282,7 @@ mod test { let contract_address = desmos_cli.get_contract_by_code(1, 0); let receiver_contract_address = desmos_cli.get_contract_by_code(1, 1); + // Create a post owner transfer request to receiver let post = create_sample_post(TEST_SUBSPACE, &contract_address); let request_post_owner_transfer_msg = PostsMsg::request_post_owner_transfer( TEST_SUBSPACE, @@ -289,20 +290,20 @@ mod test { Addr::unchecked(&receiver_contract_address), Addr::unchecked(&contract_address), ); + desmos_cli + .execute_contract(&contract_address, [request_post_owner_transfer_msg.into()]) + .assert_success(); + // Receiver accepts a post owner transfer request let accept_post_owner_transfer_request_msg = PostsMsg::accept_post_owner_transfer_request( TEST_SUBSPACE, post.id, Addr::unchecked(&receiver_contract_address), ); - desmos_cli .execute_contract( - &contract_address, - [ - request_post_owner_transfer_msg.into(), - accept_post_owner_transfer_request_msg.into(), - ], + &receiver_contract_address, + [accept_post_owner_transfer_request_msg.into()], ) .assert_success() } @@ -313,6 +314,7 @@ mod test { let contract_address = desmos_cli.get_contract_by_code(1, 0); let receiver_contract_address = desmos_cli.get_contract_by_code(1, 1); + // Create a post owner transfer request to receiver let post = create_sample_post(TEST_SUBSPACE, &contract_address); let request_post_owner_transfer_msg = PostsMsg::request_post_owner_transfer( TEST_SUBSPACE, @@ -320,20 +322,20 @@ mod test { Addr::unchecked(&receiver_contract_address), Addr::unchecked(&contract_address), ); + desmos_cli + .execute_contract(&contract_address, [request_post_owner_transfer_msg.into()]) + .assert_success(); + // Receiver refuses a post owner transfer request let refuse_post_owner_transfer_request_msg = PostsMsg::refuse_post_owner_transfer_request( TEST_SUBSPACE, post.id, Addr::unchecked(&receiver_contract_address), ); - desmos_cli .execute_contract( - &contract_address, - [ - request_post_owner_transfer_msg.into(), - refuse_post_owner_transfer_request_msg.into(), - ], + &receiver_contract_address, + [refuse_post_owner_transfer_request_msg.into()], ) .assert_success() } From 33185f03d2b6180e84fa374b36993a9593a555b1 Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Thu, 24 Aug 2023 21:28:52 +0800 Subject: [PATCH 11/16] chore: improve naming --- packages/bindings-test/src/posts/mod.rs | 3 ++- packages/bindings-test/src/posts/msg.rs | 10 +++++----- packages/bindings-test/src/posts/query.rs | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/bindings-test/src/posts/mod.rs b/packages/bindings-test/src/posts/mod.rs index 0fe147f7..99e6e11d 100644 --- a/packages/bindings-test/src/posts/mod.rs +++ b/packages/bindings-test/src/posts/mod.rs @@ -12,7 +12,8 @@ use desmos_bindings::posts::types::{ Entities, Post, QuerySubspacePostsRequest, QuerySubspacePostsResponse, ReplySetting, Url, }; -pub fn create_sample_post(subspace_id: u64, contract_address: &str) -> Post { +/// Creates a post inside the given subspace for interaction testing +pub fn create_test_post(subspace_id: u64, contract_address: &str) -> Post { let desmos_cli = DesmosCli::default(); // Create a post diff --git a/packages/bindings-test/src/posts/msg.rs b/packages/bindings-test/src/posts/msg.rs index ebfc9e3f..30d5f34c 100644 --- a/packages/bindings-test/src/posts/msg.rs +++ b/packages/bindings-test/src/posts/msg.rs @@ -5,7 +5,7 @@ mod test { TEST_DELETABLE_ATTACHMENT_ID, TEST_POLL_ID, TEST_SUBSPACE, TEST_SUBSPACE_DELETABLE_POST_ID, TEST_SUBSPACE_EDITABLE_POST_ID, }; - use crate::posts::create_sample_post; + use crate::posts::create_test_post; use chrono::DateTime; use cosmwasm_std::Addr; @@ -230,7 +230,7 @@ mod test { .last() .unwrap() .clone(); - let post = create_sample_post(TEST_SUBSPACE, &contract_address); + let post = create_test_post(TEST_SUBSPACE, &contract_address); let move_post_msg = PostsMsg::move_post( TEST_SUBSPACE, @@ -251,7 +251,7 @@ mod test { let contract_address = desmos_cli.get_contract_by_code(1, 0); let receiver_contract_address = desmos_cli.get_contract_by_code(1, 1); - let post = create_sample_post(TEST_SUBSPACE, &contract_address); + let post = create_test_post(TEST_SUBSPACE, &contract_address); let request_post_owner_transfer_msg = PostsMsg::request_post_owner_transfer( TEST_SUBSPACE, post.id, @@ -283,7 +283,7 @@ mod test { let receiver_contract_address = desmos_cli.get_contract_by_code(1, 1); // Create a post owner transfer request to receiver - let post = create_sample_post(TEST_SUBSPACE, &contract_address); + let post = create_test_post(TEST_SUBSPACE, &contract_address); let request_post_owner_transfer_msg = PostsMsg::request_post_owner_transfer( TEST_SUBSPACE, post.id, @@ -315,7 +315,7 @@ mod test { let receiver_contract_address = desmos_cli.get_contract_by_code(1, 1); // Create a post owner transfer request to receiver - let post = create_sample_post(TEST_SUBSPACE, &contract_address); + let post = create_test_post(TEST_SUBSPACE, &contract_address); let request_post_owner_transfer_msg = PostsMsg::request_post_owner_transfer( TEST_SUBSPACE, post.id, diff --git a/packages/bindings-test/src/posts/query.rs b/packages/bindings-test/src/posts/query.rs index 77753f0c..80a37b25 100644 --- a/packages/bindings-test/src/posts/query.rs +++ b/packages/bindings-test/src/posts/query.rs @@ -2,7 +2,7 @@ mod test { use crate::chain_communication::DesmosCli; use crate::consts::{TEST_POLL_ID, TEST_SUBSPACE, TEST_SUBSPACE_EDITABLE_POST_ID}; - use crate::posts::create_sample_post; + use crate::posts::create_test_post; use chrono::DateTime; use cosmwasm_std::Addr; use desmos_bindings::posts::msg::PostsMsg; @@ -242,7 +242,7 @@ mod test { let contract_address = desmos_cli.get_contract_by_code(1, 0); let receiver_contract_address = desmos_cli.get_contract_by_code(1, 1); - let post = create_sample_post(TEST_SUBSPACE, &contract_address); + let post = create_test_post(TEST_SUBSPACE, &contract_address); desmos_cli .execute_contract( &contract_address, From f7e67738dfbc34fa7c5d755f73246919607e328f Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Tue, 29 Aug 2023 20:33:23 +0800 Subject: [PATCH 12/16] fix: change array into vector --- packages/bindings-test/src/posts/msg.rs | 12 ++++++------ packages/bindings-test/src/posts/query.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/bindings-test/src/posts/msg.rs b/packages/bindings-test/src/posts/msg.rs index 30d5f34c..38a534f8 100644 --- a/packages/bindings-test/src/posts/msg.rs +++ b/packages/bindings-test/src/posts/msg.rs @@ -241,7 +241,7 @@ mod test { ); desmos_cli - .execute_contract(&contract_address, [move_post_msg.into()]) + .execute_contract(&contract_address, vec![move_post_msg.into()]) .assert_success() } @@ -268,7 +268,7 @@ mod test { desmos_cli .execute_contract( &contract_address, - [ + vec![ request_post_owner_transfer_msg.into(), cancel_post_owner_transfer_request_msg.into(), ], @@ -291,7 +291,7 @@ mod test { Addr::unchecked(&contract_address), ); desmos_cli - .execute_contract(&contract_address, [request_post_owner_transfer_msg.into()]) + .execute_contract(&contract_address, vec![request_post_owner_transfer_msg.into()]) .assert_success(); // Receiver accepts a post owner transfer request @@ -303,7 +303,7 @@ mod test { desmos_cli .execute_contract( &receiver_contract_address, - [accept_post_owner_transfer_request_msg.into()], + vec![accept_post_owner_transfer_request_msg.into()], ) .assert_success() } @@ -323,7 +323,7 @@ mod test { Addr::unchecked(&contract_address), ); desmos_cli - .execute_contract(&contract_address, [request_post_owner_transfer_msg.into()]) + .execute_contract(&contract_address, vec![request_post_owner_transfer_msg.into()]) .assert_success(); // Receiver refuses a post owner transfer request @@ -335,7 +335,7 @@ mod test { desmos_cli .execute_contract( &receiver_contract_address, - [refuse_post_owner_transfer_request_msg.into()], + vec![refuse_post_owner_transfer_request_msg.into()], ) .assert_success() } diff --git a/packages/bindings-test/src/posts/query.rs b/packages/bindings-test/src/posts/query.rs index 80a37b25..936968c9 100644 --- a/packages/bindings-test/src/posts/query.rs +++ b/packages/bindings-test/src/posts/query.rs @@ -246,7 +246,7 @@ mod test { desmos_cli .execute_contract( &contract_address, - [PostsMsg::request_post_owner_transfer( + vec![PostsMsg::request_post_owner_transfer( TEST_SUBSPACE, post.id, Addr::unchecked(&receiver_contract_address), From 144cd56ec74d303d36afbd390526ca8e0a9941d2 Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Thu, 31 Aug 2023 16:30:43 +0800 Subject: [PATCH 13/16] chore: run lint --- packages/bindings-test/src/posts/msg.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/bindings-test/src/posts/msg.rs b/packages/bindings-test/src/posts/msg.rs index 38a534f8..4d1f1350 100644 --- a/packages/bindings-test/src/posts/msg.rs +++ b/packages/bindings-test/src/posts/msg.rs @@ -291,7 +291,10 @@ mod test { Addr::unchecked(&contract_address), ); desmos_cli - .execute_contract(&contract_address, vec![request_post_owner_transfer_msg.into()]) + .execute_contract( + &contract_address, + vec![request_post_owner_transfer_msg.into()], + ) .assert_success(); // Receiver accepts a post owner transfer request @@ -323,7 +326,10 @@ mod test { Addr::unchecked(&contract_address), ); desmos_cli - .execute_contract(&contract_address, vec![request_post_owner_transfer_msg.into()]) + .execute_contract( + &contract_address, + vec![request_post_owner_transfer_msg.into()], + ) .assert_success(); // Receiver refuses a post owner transfer request From 629053d63c61a20478c92bb9052106b8e60e44fe Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Fri, 3 Nov 2023 18:15:15 +0800 Subject: [PATCH 14/16] fix: remove deprecated offset --- packages/bindings-test/src/chain_communication.rs | 6 ++---- packages/bindings-test/src/tokenfactory/msg.rs | 6 +++--- packages/bindings-test/src/tokenfactory/query.rs | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/bindings-test/src/chain_communication.rs b/packages/bindings-test/src/chain_communication.rs index 8d866163..42996140 100644 --- a/packages/bindings-test/src/chain_communication.rs +++ b/packages/bindings-test/src/chain_communication.rs @@ -138,8 +138,6 @@ impl DesmosCli { .arg("wasm") .arg("list-contract-by-code") .arg(id.to_string()) - .arg(format!("--offset={}", offset)) - .arg(format!("--limit=1")) .arg("--output=json"); let output = DesmosCli::run_command(&mut cmd); @@ -147,8 +145,8 @@ impl DesmosCli { result .contracts - .get(0) - .expect(&format!("can't find smart contract with id {}", id)) + .get(offset) + .expect(&format!("can't find smart contract with id {} and offset {}", id, offset)) .to_string() } diff --git a/packages/bindings-test/src/tokenfactory/msg.rs b/packages/bindings-test/src/tokenfactory/msg.rs index 8c6efc9d..3231fe00 100644 --- a/packages/bindings-test/src/tokenfactory/msg.rs +++ b/packages/bindings-test/src/tokenfactory/msg.rs @@ -12,7 +12,7 @@ mod tests { #[test] fn test_create_denom() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); // Setup subspace and deposit creation fees let subspace = create_test_subspace(&contract_address); @@ -39,7 +39,7 @@ mod tests { #[test] fn test_mint_then_burn() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let subdenom = "test_mint_burn"; // Setup subspace and deposit creation fees @@ -83,7 +83,7 @@ mod tests { #[test] fn test_set_metadata() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let subdenom = "test_set_metadata"; // Setup subspace and deposit creation fees diff --git a/packages/bindings-test/src/tokenfactory/query.rs b/packages/bindings-test/src/tokenfactory/query.rs index 29de2b3b..2301485a 100644 --- a/packages/bindings-test/src/tokenfactory/query.rs +++ b/packages/bindings-test/src/tokenfactory/query.rs @@ -15,7 +15,7 @@ mod tests { #[test] fn test_query_subspace_denoms() { let desmos_cli = DesmosCli::default(); - let contract_address = desmos_cli.get_contract_by_code(1); + let contract_address = desmos_cli.get_contract_by_code(1, 0); let subdenom = "test_query"; // Setup a subspace and denom for testing From 678f0eebafba44177d2b984b1e84a1c495461aff Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Fri, 3 Nov 2023 18:17:36 +0800 Subject: [PATCH 15/16] chore: run fmt --- packages/bindings-test/src/chain_communication.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/bindings-test/src/chain_communication.rs b/packages/bindings-test/src/chain_communication.rs index 42996140..44a5768c 100644 --- a/packages/bindings-test/src/chain_communication.rs +++ b/packages/bindings-test/src/chain_communication.rs @@ -146,7 +146,10 @@ impl DesmosCli { result .contracts .get(offset) - .expect(&format!("can't find smart contract with id {} and offset {}", id, offset)) + .expect(&format!( + "can't find smart contract with id {} and offset {}", + id, offset + )) .to_string() } From bd48febf11fa6713cc34e6f2be04385343566118 Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Fri, 3 Nov 2023 19:05:21 +0800 Subject: [PATCH 16/16] fix: target contract profile dtag --- packages/bindings-test/src/setup.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bindings-test/src/setup.rs b/packages/bindings-test/src/setup.rs index 4b0ae676..40fe0bf4 100644 --- a/packages/bindings-test/src/setup.rs +++ b/packages/bindings-test/src/setup.rs @@ -49,7 +49,7 @@ pub fn setup() { cli.execute_contract( &target_contract, vec![ProfilesMsg::save_profile( - Some("test_profile_posts"), + Some("target_test_profile_posts"), Some("contract_nick"), Some("test_bio"), Some("https://i.imgur.com/X2aK5Bq.jpeg"),