Skip to content

Commit

Permalink
Implement CreateMsgBuilder (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
orkunkl authored Nov 19, 2024
1 parent a3d4888 commit ff9c4d4
Show file tree
Hide file tree
Showing 14 changed files with 268 additions and 338 deletions.
87 changes: 71 additions & 16 deletions tests/src/helpers/mock_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,90 @@ pub fn get_controller_inst_msg(
}
}

#[allow(dead_code)]
pub fn get_create_stream_msg(
name: &str,
pub struct CreateStreamMsgBuilder {
name: String,

Check failure on line 32 in tests/src/helpers/mock_messages.rs

View workflow job for this annotation

GitHub Actions / Lints

multiple fields are never read
url: Option<String>,
treasury: &str,
treasury: String,
out_asset: Coin,
in_denom: &str,
in_denom: String,
bootstrapping_start_time: Timestamp,
start_time: Timestamp,
end_time: Timestamp,
threshold: Option<Uint256>,
pool_config: Option<PoolConfig>,
vesting: Option<VestingConfig>,
) -> ControllerExecuteMsg {
ControllerExecuteMsg::CreateStream {
msg: Box::new(CreateStreamMsg {
bootstraping_start_time: bootstrapping_start_time,
treasury: treasury.to_string(),
stream_admin: treasury.to_string(),
salt: Binary,
}

impl CreateStreamMsgBuilder {
pub fn new(

Check failure on line 47 in tests/src/helpers/mock_messages.rs

View workflow job for this annotation

GitHub Actions / Lints

associated items `new`, `url`, `threshold`, `pool_config`, `vesting`, and `build` are never used
name: &str,
treasury: &str,
out_asset: Coin,
in_denom: &str,
bootstrapping_start_time: Timestamp,
start_time: Timestamp,
end_time: Timestamp,
) -> Self {
Self {
name: name.to_string(),
url,
url: None,
treasury: treasury.to_string(),
out_asset,
in_denom: in_denom.to_string(),
bootstrapping_start_time,
start_time,
end_time,
threshold,
pool_config,
vesting,
threshold: None,
pool_config: None,
vesting: None,
salt: Binary::from_base64("salt").unwrap(),
}),
}
}

pub fn url(mut self, url: String) -> Self {
self.url = Some(url);
self
}

pub fn threshold(mut self, threshold: Uint256) -> Self {
self.threshold = Some(threshold);
self
}

pub fn pool_config(mut self, pool_config: PoolConfig) -> Self {
self.pool_config = Some(pool_config);
self
}

pub fn vesting(mut self, vesting: VestingConfig) -> Self {
self.vesting = Some(vesting);
self
}

#[allow(dead_code)]
pub fn salt(mut self, salt: Binary) -> Self {
self.salt = salt;
self
}

pub fn build(self) -> ControllerExecuteMsg {
ControllerExecuteMsg::CreateStream {
msg: Box::new(CreateStreamMsg {
bootstraping_start_time: self.bootstrapping_start_time,
treasury: self.treasury.clone(),
stream_admin: self.treasury,
name: self.name,
url: self.url,
out_asset: self.out_asset,
in_denom: self.in_denom,
start_time: self.start_time,
end_time: self.end_time,
threshold: self.threshold,
pool_config: self.pool_config,
vesting: self.vesting,
salt: self.salt,
}),
}
}
}
25 changes: 9 additions & 16 deletions tests/src/tests/controller_tests/controller_freeze.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#![cfg(test)]
use crate::helpers::mock_messages::CreateStreamMsgBuilder;
use crate::helpers::suite::SuiteBuilder;
use crate::helpers::{
mock_messages::{get_controller_inst_msg, get_create_stream_msg},
suite::Suite,
};
use crate::helpers::{mock_messages::get_controller_inst_msg, suite::Suite};
use cosmwasm_std::coin;
use cw_multi_test::Executor;
use streamswap_controller::error::ContractError as ControllerError;
Expand Down Expand Up @@ -31,19 +29,17 @@ fn controller_freeze() {
)
.unwrap();
// When controller is created, it is not frozen, Stream creation is allowed
let create_stream_msg = get_create_stream_msg(
let create_stream_msg = CreateStreamMsgBuilder::new(
"stream",
None,
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),
None,
None,
None,
);
)
.build();

let _create_stream_res = app
.execute_contract(
test_accounts.creator_1.clone(),
Expand Down Expand Up @@ -85,19 +81,16 @@ fn controller_freeze() {
assert!(res);

// When controller is frozen, Stream creation is not allowed
let create_stream_msg = get_create_stream_msg(
let create_stream_msg = CreateStreamMsgBuilder::new(
"stream",
None,
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),
None,
None,
None,
);
)
.build();
let res = app
.execute_contract(
test_accounts.creator_1.clone(),
Expand Down
34 changes: 14 additions & 20 deletions tests/src/tests/streamswap_tests/cancel_stream.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#[cfg(test)]
mod cancel_stream {
use crate::helpers::mock_messages::CreateStreamMsgBuilder;
use crate::helpers::suite::SuiteBuilder;
use crate::helpers::{
mock_messages::{get_controller_inst_msg, get_create_stream_msg},
mock_messages::get_controller_inst_msg,
suite::Suite,
utils::{get_contract_address_from_res, get_funds_from_res, get_wasm_attribute_with_key},
};
Expand Down Expand Up @@ -37,19 +38,17 @@ mod cancel_stream {
let end_time = app.block_info().time.plus_seconds(200);
let bootstrapping_start_time = app.block_info().time.plus_seconds(50);

let create_stream_msg = get_create_stream_msg(
let create_stream_msg = CreateStreamMsgBuilder::new(
"stream",
None,
test_accounts.creator_1.as_ref(),
coin(100, "out_denom"),
"in_denom",
bootstrapping_start_time,
start_time,
end_time,
Some(Uint256::from(100u128)),
None,
None,
);
)
.threshold(Uint256::from(100u128))
.build();

let _res = app
.execute_contract(
Expand Down Expand Up @@ -123,20 +122,17 @@ mod cancel_stream {
let bootstrapping_start_time = app.block_info().time.plus_seconds(50);
let out_amount = coin(100, "out_denom");

let create_stream_msg = get_create_stream_msg(
let create_stream_msg = CreateStreamMsgBuilder::new(
"stream",
None,
test_accounts.creator_1.as_ref(),
out_amount.clone(),
"in_denom",
bootstrapping_start_time,
start_time,
end_time,
Some(Uint256::from(100u128)),
None,
None,
);

)
.threshold(Uint256::from(100u128))
.build();
let _res = app
.execute_contract(
test_accounts.creator_1.clone(),
Expand Down Expand Up @@ -212,19 +208,17 @@ mod cancel_stream {
let end_time = app.block_info().time.plus_seconds(200);
let bootstrapping_start_time = app.block_info().time.plus_seconds(50);

let create_stream_msg = get_create_stream_msg(
let create_stream_msg = CreateStreamMsgBuilder::new(
"stream",
None,
test_accounts.creator_1.as_ref(),
coin(100, "out_denom"),
"in_denom",
bootstrapping_start_time,
start_time,
end_time,
Some(Uint256::from(100u128)),
None,
None,
);
)
.threshold(Uint256::from(100u128))
.build();

let _res = app
.execute_contract(
Expand Down
Loading

0 comments on commit ff9c4d4

Please sign in to comment.