From 627fb0e8da789b000f9d50f973aa912678efdb24 Mon Sep 17 00:00:00 2001 From: orkunkl Date: Sun, 8 Dec 2024 21:46:28 +0300 Subject: [PATCH 1/2] List Stream Refactor --- contracts/stream/src/contract.rs | 1 + packages/types/src/stream/msg.rs | 2 + .../tests/controller_tests/list_streams.rs | 99 +++++++++++++++++++ tests/src/tests/controller_tests/mod.rs | 1 + 4 files changed, 103 insertions(+) create mode 100644 tests/src/tests/controller_tests/list_streams.rs diff --git a/contracts/stream/src/contract.rs b/contracts/stream/src/contract.rs index 44d3a38..893ad47 100644 --- a/contracts/stream/src/contract.rs +++ b/contracts/stream/src/contract.rs @@ -872,6 +872,7 @@ pub fn query_stream(deps: Deps, _env: Env) -> StdResult { let stream = STREAM_STATE.load(deps.storage)?; let stream_info = STREAM_INFO.load(deps.storage)?; let stream = StreamResponse { + name: stream_info.name, treasury: stream_info.treasury.to_string(), in_denom: stream.in_denom, out_asset: stream.out_asset, diff --git a/packages/types/src/stream/msg.rs b/packages/types/src/stream/msg.rs index d6c4d4f..c2a2512 100644 --- a/packages/types/src/stream/msg.rs +++ b/packages/types/src/stream/msg.rs @@ -100,6 +100,8 @@ pub struct ConfigResponse { } #[cw_serde] pub struct StreamResponse { + /// Unique name of the stream. + pub name: String, /// Address of the treasury where the stream earnings will be sent. pub treasury: String, /// URL of the stream. diff --git a/tests/src/tests/controller_tests/list_streams.rs b/tests/src/tests/controller_tests/list_streams.rs new file mode 100644 index 0000000..1e96b45 --- /dev/null +++ b/tests/src/tests/controller_tests/list_streams.rs @@ -0,0 +1,99 @@ +use crate::helpers::mock_messages::{get_controller_inst_msg, CreateStreamMsgBuilder}; +use crate::helpers::suite::{Suite, SuiteBuilder}; +use crate::helpers::utils::get_wasm_attribute_with_key; +#[cfg(test)] +use cosmwasm_std::coin; +use cosmwasm_std::Binary; +use cw_multi_test::Executor; +use streamswap_types::controller::{QueryMsg, StreamsResponse}; + +#[test] +fn test_list_streams() { + let Suite { + mut app, + test_accounts, + stream_swap_code_id, + stream_swap_controller_code_id, + vesting_code_id, + } = SuiteBuilder::default().build(); + + let msg = get_controller_inst_msg(stream_swap_code_id, vesting_code_id, &test_accounts); + let controller_address = app + .instantiate_contract( + stream_swap_controller_code_id, + test_accounts.admin.clone(), + &msg, + &[], + "Controller".to_string(), + None, + ) + .unwrap(); + + let create_stream_msg = CreateStreamMsgBuilder::new( + "stream", + test_accounts.creator_1.as_ref(), + coin(100, "out_denom"), + "in_denom", + app.block_info().time.plus_seconds(50), + app.block_info().time.plus_seconds(100), + app.block_info().time.plus_seconds(200), + ) + .salt( + Binary::from_base64("dGlnaHRseXB1YmxpY2h1cnJ5Y2FyZWZ1bHJ1bGVyYm93d2FpdHZhcG9ydHJ1dGhicmk") + .unwrap(), + ) + .build(); + + let res = app + .execute_contract( + test_accounts.creator_1.clone(), + controller_address.clone(), + &create_stream_msg, + &[coin(100, "fee_denom"), coin(100, "out_denom")], + ) + .unwrap(); + let stream_addr1 = get_wasm_attribute_with_key(res, "stream_contract_addr".to_string()); + + let create_stream_msg = CreateStreamMsgBuilder::new( + "stream2", + test_accounts.creator_2.as_ref(), + coin(200, "out_denom"), + "in_denom", + app.block_info().time.plus_seconds(50), + app.block_info().time.plus_seconds(100), + app.block_info().time.plus_seconds(200), + ) + .salt( + Binary::from_base64("bmVlZHNpbnRlcmVzdGtub3dudGhlbWRyYXdlc3BlY2lhbGx5d29ubm90aWNldmFsdWU") + .unwrap(), + ) + .build(); + + let res = app + .execute_contract( + test_accounts.creator_2.clone(), + controller_address.clone(), + &create_stream_msg, + &[coin(100, "fee_denom"), coin(200, "out_denom")], + ) + .unwrap(); + let stream_addr2 = get_wasm_attribute_with_key(res, "stream_contract_addr".to_string()); + + let res: StreamsResponse = app + .wrap() + .query_wasm_smart( + controller_address.clone(), + &QueryMsg::ListStreams { + start_after: None, + limit: None, + }, + ) + .unwrap(); + + assert_eq!(res.streams.len(), 2); + assert_eq!(res.streams[0].id, 1); + assert_eq!(res.streams[0].address, stream_addr1); + + assert_eq!(res.streams[1].id, 2); + assert_eq!(res.streams[1].address, stream_addr2); +} diff --git a/tests/src/tests/controller_tests/mod.rs b/tests/src/tests/controller_tests/mod.rs index e40b2c2..dcedb8c 100644 --- a/tests/src/tests/controller_tests/mod.rs +++ b/tests/src/tests/controller_tests/mod.rs @@ -1,3 +1,4 @@ mod controller_freeze; mod instantiate; +mod list_streams; mod params_update; From a0f6f2a9bb98005879a112bdefbf310239f4280e Mon Sep 17 00:00:00 2001 From: orkunkl Date: Sun, 8 Dec 2024 22:04:16 +0300 Subject: [PATCH 2/2] Fix clippy --- tests/src/tests/controller_tests/list_streams.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/tests/controller_tests/list_streams.rs b/tests/src/tests/controller_tests/list_streams.rs index 1e96b45..001c1db 100644 --- a/tests/src/tests/controller_tests/list_streams.rs +++ b/tests/src/tests/controller_tests/list_streams.rs @@ -1,7 +1,7 @@ +#![cfg(test)] use crate::helpers::mock_messages::{get_controller_inst_msg, CreateStreamMsgBuilder}; use crate::helpers::suite::{Suite, SuiteBuilder}; use crate::helpers::utils::get_wasm_attribute_with_key; -#[cfg(test)] use cosmwasm_std::coin; use cosmwasm_std::Binary; use cw_multi_test::Executor;