Skip to content

Commit

Permalink
List Stream Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
orkunkl committed Dec 8, 2024
1 parent 397b7af commit 627fb0e
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
1 change: 1 addition & 0 deletions contracts/stream/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ pub fn query_stream(deps: Deps, _env: Env) -> StdResult<StreamResponse> {
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,
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/stream/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
99 changes: 99 additions & 0 deletions tests/src/tests/controller_tests/list_streams.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
use crate::helpers::mock_messages::{get_controller_inst_msg, CreateStreamMsgBuilder};

Check failure on line 1 in tests/src/tests/controller_tests/list_streams.rs

View workflow job for this annotation

GitHub Actions / Lints

unused imports: `CreateStreamMsgBuilder`, `get_controller_inst_msg`

Check failure on line 1 in tests/src/tests/controller_tests/list_streams.rs

View workflow job for this annotation

GitHub Actions / Lints

unused imports: `CreateStreamMsgBuilder`, `get_controller_inst_msg`
use crate::helpers::suite::{Suite, SuiteBuilder};

Check failure on line 2 in tests/src/tests/controller_tests/list_streams.rs

View workflow job for this annotation

GitHub Actions / Lints

unused imports: `SuiteBuilder`, `Suite`

Check failure on line 2 in tests/src/tests/controller_tests/list_streams.rs

View workflow job for this annotation

GitHub Actions / Lints

unused imports: `SuiteBuilder`, `Suite`
use crate::helpers::utils::get_wasm_attribute_with_key;

Check failure on line 3 in tests/src/tests/controller_tests/list_streams.rs

View workflow job for this annotation

GitHub Actions / Lints

unresolved import `crate::helpers::utils::get_wasm_attribute_with_key`

Check failure on line 3 in tests/src/tests/controller_tests/list_streams.rs

View workflow job for this annotation

GitHub Actions / Lints

unresolved import `crate::helpers::utils::get_wasm_attribute_with_key`
#[cfg(test)]
use cosmwasm_std::coin;
use cosmwasm_std::Binary;

Check failure on line 6 in tests/src/tests/controller_tests/list_streams.rs

View workflow job for this annotation

GitHub Actions / Lints

unused import: `cosmwasm_std::Binary`

Check failure on line 6 in tests/src/tests/controller_tests/list_streams.rs

View workflow job for this annotation

GitHub Actions / Lints

unused import: `cosmwasm_std::Binary`
use cw_multi_test::Executor;

Check failure on line 7 in tests/src/tests/controller_tests/list_streams.rs

View workflow job for this annotation

GitHub Actions / Lints

unused import: `cw_multi_test::Executor`

Check failure on line 7 in tests/src/tests/controller_tests/list_streams.rs

View workflow job for this annotation

GitHub Actions / Lints

unused import: `cw_multi_test::Executor`
use streamswap_types::controller::{QueryMsg, StreamsResponse};

Check failure on line 8 in tests/src/tests/controller_tests/list_streams.rs

View workflow job for this annotation

GitHub Actions / Lints

unused imports: `QueryMsg`, `StreamsResponse`

Check failure on line 8 in tests/src/tests/controller_tests/list_streams.rs

View workflow job for this annotation

GitHub Actions / Lints

unused imports: `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);
}
1 change: 1 addition & 0 deletions tests/src/tests/controller_tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod controller_freeze;
mod instantiate;
mod list_streams;
mod params_update;

0 comments on commit 627fb0e

Please sign in to comment.