From ff9c4d42fd9cf9d9ed78b0cb84710ba4f4457593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orkun=20K=C3=BCl=C3=A7e?= Date: Tue, 19 Nov 2024 13:36:18 +0300 Subject: [PATCH] Implement CreateMsgBuilder (#94) --- tests/src/helpers/mock_messages.rs | 87 ++++++++-- .../controller_tests/controller_freeze.rs | 25 ++- .../tests/streamswap_tests/cancel_stream.rs | 34 ++-- .../tests/streamswap_tests/create_stream.rs | 148 +++++++----------- .../src/tests/streamswap_tests/exit_cancel.rs | 22 ++- .../tests/streamswap_tests/finalize_stream.rs | 33 ++-- tests/src/tests/streamswap_tests/pool.rs | 61 ++++---- .../streamswap_tests/rounding_leftover.rs | 15 +- tests/src/tests/streamswap_tests/subscribe.rs | 42 ++--- .../tests/streamswap_tests/sync_position.rs | 15 +- .../src/tests/streamswap_tests/sync_stream.rs | 33 ++-- tests/src/tests/streamswap_tests/threshold.rs | 39 ++--- tests/src/tests/streamswap_tests/vesting.rs | 12 +- tests/src/tests/streamswap_tests/withdraw.rs | 40 ++--- 14 files changed, 268 insertions(+), 338 deletions(-) diff --git a/tests/src/helpers/mock_messages.rs b/tests/src/helpers/mock_messages.rs index 245c68d..95e8393 100644 --- a/tests/src/helpers/mock_messages.rs +++ b/tests/src/helpers/mock_messages.rs @@ -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, url: Option, - 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, pool_config: Option, vesting: Option, -) -> 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( + 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, + }), + } } } diff --git a/tests/src/tests/controller_tests/controller_freeze.rs b/tests/src/tests/controller_tests/controller_freeze.rs index e011058..cbdd04a 100644 --- a/tests/src/tests/controller_tests/controller_freeze.rs +++ b/tests/src/tests/controller_tests/controller_freeze.rs @@ -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; @@ -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(), @@ -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(), diff --git a/tests/src/tests/streamswap_tests/cancel_stream.rs b/tests/src/tests/streamswap_tests/cancel_stream.rs index b99e1f7..4abd8e8 100644 --- a/tests/src/tests/streamswap_tests/cancel_stream.rs +++ b/tests/src/tests/streamswap_tests/cancel_stream.rs @@ -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}, }; @@ -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( @@ -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(), @@ -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( diff --git a/tests/src/tests/streamswap_tests/create_stream.rs b/tests/src/tests/streamswap_tests/create_stream.rs index afe21cb..df93c70 100644 --- a/tests/src/tests/streamswap_tests/create_stream.rs +++ b/tests/src/tests/streamswap_tests/create_stream.rs @@ -1,11 +1,9 @@ #[cfg(test)] mod create_stream_tests { + use crate::helpers::mock_messages::CreateStreamMsgBuilder; use crate::helpers::suite::SuiteBuilder; use crate::helpers::utils::get_wasm_attribute_with_key; - 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, Uint256}; use cw_multi_test::Executor; use streamswap_controller::error::ContractError as ControllerError; @@ -41,19 +39,16 @@ mod create_stream_tests { .unwrap(); // Failed name checks // Name too short - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "s", - None, test_accounts.creator_1.as_ref(), coin(100, "out_denom"), "in_denom", bootstrapping_start_time, start_time, end_time, - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract( @@ -69,19 +64,16 @@ mod create_stream_tests { assert_eq!(*error, StreamSwapError::StreamNameTooShort {}); // Name too long let long_name = "a".repeat(65); - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( &long_name, - None, test_accounts.creator_1.as_ref(), coin(100, "out_denom"), "in_denom", bootstrapping_start_time, app.block_info().time.plus_seconds(100), app.block_info().time.plus_seconds(200), - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract( @@ -97,19 +89,16 @@ mod create_stream_tests { assert_eq!(*error, StreamSwapError::StreamNameTooLong {}); // Invalid name - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "abc~ß", - None, test_accounts.creator_1.as_ref(), coin(100, "out_denom"), "in_denom", bootstrapping_start_time, app.block_info().time.plus_seconds(100), app.block_info().time.plus_seconds(200), - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract( @@ -126,19 +115,17 @@ mod create_stream_tests { // Failed url checks // URL too short - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "stream", - Some("a".to_string()), test_accounts.creator_1.as_ref(), coin(100, "out_denom"), "in_denom", bootstrapping_start_time, app.block_info().time.plus_seconds(100), app.block_info().time.plus_seconds(200), - None, - None, - None, - ); + ) + .url("a".to_string()) + .build(); let res = app .execute_contract( @@ -156,19 +143,18 @@ mod create_stream_tests { // URL too long let long_url = "a".repeat(256); - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "stream", - Some(long_url), test_accounts.creator_1.as_ref(), coin(100, "out_denom"), "in_denom", bootstrapping_start_time, app.block_info().time.plus_seconds(100), app.block_info().time.plus_seconds(200), - Some(Uint256::from(100u128)), - None, - None, - ); + ) + .url(long_url) + .threshold(Uint256::from(100u128)) + .build(); let res = app .execute_contract( @@ -211,19 +197,17 @@ mod create_stream_tests { .unwrap(); // Non permissioned in denom - 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"), "invalid_in_denom", bootstrapping_start_time, start_time, end_time, - None, - None, - None, - ); + ) + .build(); + let res = app .execute_contract( test_accounts.creator_1.clone(), @@ -237,19 +221,16 @@ mod create_stream_tests { assert_eq!(*error, ControllerError::InDenomIsNotAccepted {}); // Same in and out denom - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "stream", - None, test_accounts.creator_1.as_ref(), coin(100, "in_denom"), "in_denom", bootstrapping_start_time, 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(), @@ -264,19 +245,17 @@ mod create_stream_tests { assert_eq!(*error, StreamSwapError::SameDenomOnEachSide {}); // Zero out supply - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "stream", - None, test_accounts.creator_1.as_ref(), coin(0, "out_denom"), "in_denom", bootstrapping_start_time, app.block_info().time.plus_seconds(100), app.block_info().time.plus_seconds(200), - Some(Uint256::from(100u128)), - None, - None, - ); + ) + .threshold(Uint256::from(100u128)) + .build(); let res = app .execute_contract( @@ -291,19 +270,16 @@ mod create_stream_tests { assert_eq!(*error, ControllerError::ZeroOutSupply {}); // No funds sent - 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, app.block_info().time.plus_seconds(100), app.block_info().time.plus_seconds(200), - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract( @@ -325,19 +301,16 @@ mod create_stream_tests { ); // Insufficient fee - 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, app.block_info().time.plus_seconds(100), app.block_info().time.plus_seconds(200), - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract( @@ -359,19 +332,16 @@ mod create_stream_tests { ); // Extra funds sent - 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, app.block_info().time.plus_seconds(100), app.block_info().time.plus_seconds(200), - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract( @@ -402,19 +372,17 @@ mod create_stream_tests { ); // Threshold zero - 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, app.block_info().time.plus_seconds(100), app.block_info().time.plus_seconds(200), - Some(Uint256::from(0u128)), - None, - None, - ); + ) + .threshold(Uint256::from(0u128)) + .build(); let res = app .execute_contract( @@ -469,19 +437,16 @@ mod create_stream_tests { let start_time = app.block_info().time.plus_seconds(100); let end_time = app.block_info().time.plus_seconds(200); - 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", bootstart_time, start_time, end_time, - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract( test_accounts.creator_1.clone(), @@ -499,19 +464,16 @@ mod create_stream_tests { let start_time = app.block_info().time.plus_seconds(100); let end_time = app.block_info().time.plus_seconds(101); - 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", bootstart_time, start_time, end_time, - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract( @@ -552,19 +514,17 @@ mod create_stream_tests { ) .unwrap(); - 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( diff --git a/tests/src/tests/streamswap_tests/exit_cancel.rs b/tests/src/tests/streamswap_tests/exit_cancel.rs index 43e0f8f..930b069 100644 --- a/tests/src/tests/streamswap_tests/exit_cancel.rs +++ b/tests/src/tests/streamswap_tests/exit_cancel.rs @@ -1,9 +1,10 @@ #[cfg(test)] mod exit_cancel { + use crate::helpers::mock_messages::CreateStreamMsgBuilder; use crate::helpers::suite::SuiteBuilder; use crate::helpers::utils::get_wasm_attribute_with_key; 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}, }; @@ -38,19 +39,16 @@ mod exit_cancel { 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, - None, - None, - None, - ); + ) + .build(); let _res = app .execute_contract( @@ -122,19 +120,17 @@ mod exit_cancel { 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( diff --git a/tests/src/tests/streamswap_tests/finalize_stream.rs b/tests/src/tests/streamswap_tests/finalize_stream.rs index e0295c9..2d95f32 100644 --- a/tests/src/tests/streamswap_tests/finalize_stream.rs +++ b/tests/src/tests/streamswap_tests/finalize_stream.rs @@ -1,11 +1,9 @@ #[cfg(test)] mod finalize_stream_tests { + use crate::helpers::mock_messages::CreateStreamMsgBuilder; use crate::helpers::suite::SuiteBuilder; use crate::helpers::utils::{get_contract_address_from_res, get_funds_from_res}; - 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, Addr, BlockInfo, Coin, Uint128}; use cw_multi_test::Executor; use streamswap_types::stream::{ @@ -35,19 +33,16 @@ mod finalize_stream_tests { None, ) .unwrap(); - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "Stream Swap tests", - None, test_accounts.creator_1.as_ref(), coin(1_000_000, "out_denom"), "in_denom", bootstrapping_start_time, start_time, end_time, - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract( test_accounts.creator_1.clone(), @@ -152,19 +147,16 @@ mod finalize_stream_tests { None, ) .unwrap(); - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "Stream Swap tests", - None, test_accounts.creator_1.as_ref(), coin(1_000_000, "out_denom"), "in_denom", bootstrapping_start_time, start_time, end_time, - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract( test_accounts.creator_1.clone(), @@ -271,19 +263,16 @@ mod finalize_stream_tests { None, ) .unwrap(); - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "Stream Swap tests", - None, test_accounts.creator_1.as_ref(), coin(1_000_000, "out_denom"), "in_denom", bootstrapping_start_time, start_time, end_time, - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract( test_accounts.creator_1.clone(), diff --git a/tests/src/tests/streamswap_tests/pool.rs b/tests/src/tests/streamswap_tests/pool.rs index 1988a20..509d95c 100644 --- a/tests/src/tests/streamswap_tests/pool.rs +++ b/tests/src/tests/streamswap_tests/pool.rs @@ -1,6 +1,6 @@ #[cfg(test)] mod pool { - use crate::helpers::mock_messages::{get_controller_inst_msg, get_create_stream_msg}; + use crate::helpers::mock_messages::{get_controller_inst_msg, CreateStreamMsgBuilder}; use crate::helpers::suite::{Suite, SuiteBuilder}; use crate::helpers::utils::{ get_contract_address_from_res, get_funds_from_res, get_wasm_attribute_with_key, @@ -50,21 +50,19 @@ mod pool { None, ) .unwrap(); - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "Stream Swap tests", - None, test_accounts.creator_1.as_ref(), coin(out_supply, out_denom), in_denom, bootstrapping_start_time, start_time, end_time, - None, - Some(PoolConfig::ConcentratedLiquidity { - out_amount_clp: out_clp_amount.into(), - }), - None, - ); + ) + .pool_config(PoolConfig::ConcentratedLiquidity { + out_amount_clp: out_clp_amount.into(), + }) + .build(); let res = app .execute_contract( test_accounts.creator_1.clone(), @@ -177,21 +175,20 @@ mod pool { let stream_creation_fee = coin(100, "fee_denom"); let in_denom = "in_denom"; - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "stream", - None, test_accounts.creator_1.as_ref(), out_coin.clone(), in_denom, bootstrapping_start_time, start_time, end_time, - Some(Uint256::from(100u128)), - Some(PoolConfig::ConcentratedLiquidity { - out_amount_clp: out_clp_amount.into(), - }), - None, - ); + ) + .threshold(Uint256::from(100u128)) + .pool_config(PoolConfig::ConcentratedLiquidity { + out_amount_clp: out_clp_amount.into(), + }) + .build(); let _res = app .execute_contract( @@ -290,21 +287,20 @@ mod pool { let stream_creation_fee = coin(100, "fee_denom"); let in_denom = "in_denom"; - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "stream", - None, test_accounts.creator_1.as_ref(), out_coin.clone(), in_denom, bootstrapping_start_time, start_time, end_time, - Some(Uint256::from(100u128)), - Some(PoolConfig::ConcentratedLiquidity { - out_amount_clp: out_clp_amount.into(), - }), - None, - ); + ) + .threshold(Uint256::from(100u128)) + .pool_config(PoolConfig::ConcentratedLiquidity { + out_amount_clp: out_clp_amount.into(), + }) + .build(); let _res = app .execute_contract( @@ -416,21 +412,20 @@ mod pool { let stream_creation_fee = coin(100, "fee_denom"); let in_denom = "in_denom"; - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "stream", - None, test_accounts.creator_1.as_ref(), out_coin.clone(), in_denom, bootstrapping_start_time, start_time, end_time, - Some(Uint256::from(100u128)), - Some(PoolConfig::ConcentratedLiquidity { - out_amount_clp: out_clp_amount.into(), - }), - None, - ); + ) + .threshold(Uint256::from(100u128)) + .pool_config(PoolConfig::ConcentratedLiquidity { + out_amount_clp: out_clp_amount.into(), + }) + .build(); let res = app .execute_contract( diff --git a/tests/src/tests/streamswap_tests/rounding_leftover.rs b/tests/src/tests/streamswap_tests/rounding_leftover.rs index a4000e1..12b9a1c 100644 --- a/tests/src/tests/streamswap_tests/rounding_leftover.rs +++ b/tests/src/tests/streamswap_tests/rounding_leftover.rs @@ -3,12 +3,10 @@ mod rounding_leftover { use std::str::FromStr; + use crate::helpers::mock_messages::CreateStreamMsgBuilder; use crate::helpers::suite::SuiteBuilder; use crate::helpers::utils::get_contract_address_from_res; - 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::Uint256; use cosmwasm_std::{coin, Addr, BlockInfo, Decimal256, Timestamp}; use cw_multi_test::Executor; @@ -44,19 +42,16 @@ mod rounding_leftover { ) .unwrap(); - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "Stream Swap tests", - Some("https://sample.url".to_string()), test_accounts.creator_1.as_ref(), coin(1_000_000_000_000, "out_denom"), "in_denom", bootstrapping_start_time, start_time, end_time, - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract( diff --git a/tests/src/tests/streamswap_tests/subscribe.rs b/tests/src/tests/streamswap_tests/subscribe.rs index 1027f73..2e16696 100644 --- a/tests/src/tests/streamswap_tests/subscribe.rs +++ b/tests/src/tests/streamswap_tests/subscribe.rs @@ -3,13 +3,11 @@ mod subscribe { use std::str::FromStr; + use crate::helpers::mock_messages::CreateStreamMsgBuilder; use crate::helpers::suite::SuiteBuilder; use crate::helpers::utils::get_contract_address_from_res; #[cfg(test)] - 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, Addr, BlockInfo, Decimal256, Uint256}; use cw_multi_test::Executor; use cw_utils::PaymentError; @@ -45,19 +43,16 @@ mod subscribe { ) .unwrap(); - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "Stream Swap tests", - None, test_accounts.creator_1.as_ref(), coin(1_000_000, "out_denom"), "in_denom", bootstrapping_start_time, start_time, end_time, - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract( @@ -198,19 +193,16 @@ mod subscribe { ) .unwrap(); - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "Stream Swap tests", - None, test_accounts.creator_1.as_ref(), coin(1_000_000, "out_denom"), "in_denom", bootstrapping_start_time, start_time, end_time, - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract( @@ -371,19 +363,16 @@ mod subscribe { ) .unwrap(); - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "Stream Swap tests", - None, test_accounts.creator_1.as_ref(), coin(1_000_000, "out_denom"), "in_denom", bootstrapping_start_time, start_time, end_time, - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract( @@ -656,19 +645,16 @@ mod subscribe { ) .unwrap(); - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "Stream Swap tests", - None, test_accounts.creator_1.as_ref(), coin(1_000_000, "out_denom"), "in_denom", bootstrapping_start_time, start_time, end_time, - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract( diff --git a/tests/src/tests/streamswap_tests/sync_position.rs b/tests/src/tests/streamswap_tests/sync_position.rs index 6bd92d6..168de65 100644 --- a/tests/src/tests/streamswap_tests/sync_position.rs +++ b/tests/src/tests/streamswap_tests/sync_position.rs @@ -3,13 +3,11 @@ mod sync_position { use std::str::FromStr; + use crate::helpers::mock_messages::CreateStreamMsgBuilder; use crate::helpers::suite::SuiteBuilder; use crate::helpers::utils::get_contract_address_from_res; #[cfg(test)] - 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, Addr, BlockInfo, Decimal256, Uint256}; use cw_multi_test::Executor; use streamswap_types::stream::{ @@ -41,19 +39,16 @@ mod sync_position { ) .unwrap(); - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "Stream Swap tests", - None, test_accounts.creator_1.as_ref(), coin(1_000_000, "out_denom"), "in_denom", bootstrapping_start_time, start_time, end_time, - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract( diff --git a/tests/src/tests/streamswap_tests/sync_stream.rs b/tests/src/tests/streamswap_tests/sync_stream.rs index fb5c197..916517b 100644 --- a/tests/src/tests/streamswap_tests/sync_stream.rs +++ b/tests/src/tests/streamswap_tests/sync_stream.rs @@ -5,11 +5,10 @@ mod sync_stream { use crate::helpers::suite::SuiteBuilder; use crate::helpers::{ - mock_messages::{get_controller_inst_msg, get_create_stream_msg}, - suite::Suite, - utils::get_contract_address_from_res, + mock_messages::get_controller_inst_msg, suite::Suite, utils::get_contract_address_from_res, }; + use crate::helpers::mock_messages::CreateStreamMsgBuilder; use cosmwasm_std::{coin, Addr, BlockInfo, Decimal256, Uint256}; use cw_multi_test::Executor; use streamswap_types::stream::{ @@ -41,20 +40,16 @@ mod sync_stream { let start_time = app.block_info().time.plus_seconds(100); 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, - None, - None, - None, - ); + ) + .build(); let _res = app .execute_contract( @@ -274,19 +269,16 @@ mod sync_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, - None, - None, - None, - ); + ) + .build(); let _res = app .execute_contract( @@ -400,19 +392,16 @@ mod sync_stream { ) .unwrap(); - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "Stream Swap tests", - None, test_accounts.creator_1.as_ref(), coin(1_000, "out_denom"), "in_denom", bootstrapping_start_time, start_time, end_time, - None, - None, - None, - ); + ) + .build(); // Create Stream let res = app .execute_contract( diff --git a/tests/src/tests/streamswap_tests/threshold.rs b/tests/src/tests/streamswap_tests/threshold.rs index 343921c..144eb6d 100644 --- a/tests/src/tests/streamswap_tests/threshold.rs +++ b/tests/src/tests/streamswap_tests/threshold.rs @@ -1,12 +1,10 @@ #[cfg(test)] mod threshold { + use crate::helpers::mock_messages::CreateStreamMsgBuilder; use crate::helpers::suite::SuiteBuilder; use crate::helpers::utils::{get_contract_address_from_res, get_funds_from_res}; - 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::testing::MockStorage; use cosmwasm_std::{coin, Addr, BlockInfo, Coin, Timestamp, Uint128, Uint256}; use cw_multi_test::Executor; @@ -77,19 +75,18 @@ mod threshold { ) .unwrap(); - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "Stream Swap tests", - Some("https://sample.url".to_string()), test_accounts.creator_1.as_ref(), coin(500, "out_denom"), "in_denom", bootstrapping_start_time, start_time, end_time, - Some(threshold), - None, - None, - ); + ) + .url("https://sample.url".to_string()) + .threshold(threshold) + .build(); let res = app .execute_contract( @@ -202,19 +199,18 @@ mod threshold { ) .unwrap(); - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "Stream Swap tests", - Some("https://sample.url".to_string()), test_accounts.creator_1.as_ref(), coin(500, "out_denom"), "in_denom", bootstrapping_start_time, start_time, end_time, - Some(threshold), - None, - None, - ); + ) + .url("https://sample.url".to_string()) + .threshold(threshold) + .build(); let res = app .execute_contract( @@ -430,19 +426,18 @@ mod threshold { ) .unwrap(); - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "Stream Swap tests", - Some("https://sample.url".to_string()), test_accounts.creator_1.as_ref(), coin(500, "out_denom"), "in_denom", bootstrapping_start_time, start_time, end_time, - Some(threshold), - None, - None, - ); + ) + .url("https://sample.url".to_string()) + .threshold(threshold) + .build(); let res = app .execute_contract( diff --git a/tests/src/tests/streamswap_tests/vesting.rs b/tests/src/tests/streamswap_tests/vesting.rs index 2f6864f..370c617 100644 --- a/tests/src/tests/streamswap_tests/vesting.rs +++ b/tests/src/tests/streamswap_tests/vesting.rs @@ -1,6 +1,6 @@ #[cfg(test)] mod vesting { - use crate::helpers::mock_messages::{get_controller_inst_msg, get_create_stream_msg}; + use crate::helpers::mock_messages::{get_controller_inst_msg, CreateStreamMsgBuilder}; use crate::helpers::suite::{Suite, SuiteBuilder}; use crate::helpers::utils::{ get_contract_address_from_res, get_funds_from_res, get_wasm_attribute_with_key, @@ -43,19 +43,17 @@ mod vesting { vesting_duration_seconds: 150, unbonding_duration_seconds: 0, }; - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "Stream Swap tests", - None, test_accounts.creator_1.as_ref(), coin(1_000_000, "out_denom"), "in_denom", bootstrapping_start_time, start_time, end_time, - None, - None, - Some(vesting_msg), - ); + ) + .vesting(vesting_msg) + .build(); let res = app .execute_contract( test_accounts.creator_1.clone(), diff --git a/tests/src/tests/streamswap_tests/withdraw.rs b/tests/src/tests/streamswap_tests/withdraw.rs index 663d2c3..c9b4797 100644 --- a/tests/src/tests/streamswap_tests/withdraw.rs +++ b/tests/src/tests/streamswap_tests/withdraw.rs @@ -2,7 +2,8 @@ mod withdraw { #[cfg(test)] - use crate::helpers::mock_messages::{get_controller_inst_msg, get_create_stream_msg}; + use crate::helpers::mock_messages::get_controller_inst_msg; + use crate::helpers::mock_messages::CreateStreamMsgBuilder; use crate::helpers::suite::SuiteBuilder; use crate::helpers::utils::get_contract_address_from_res; use cosmwasm_std::{coin, Addr, BlockInfo, Decimal256, Uint128, Uint256}; @@ -38,19 +39,16 @@ mod withdraw { 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 Swap tests", - None, test_accounts.creator_1.as_ref(), coin(1_000_000, "out_denom"), "in_denom", bootstrapping_start_time, start_time, end_time, - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract( @@ -236,19 +234,17 @@ mod withdraw { let end_time = app.block_info().time.plus_seconds(5000); let bootstrapping_start_time = app.block_info().time.plus_seconds(500); - let create_stream_msg = get_create_stream_msg( + let create_stream_msg = CreateStreamMsgBuilder::new( "Stream Swap test", - Some("https://sample.url".to_string()), test_accounts.creator_1.as_ref(), coin(1_000_000_000_000, "out_denom"), "in_denom", bootstrapping_start_time, start_time, end_time, - None, - None, - None, - ); + ) + .url("https://sample.url".to_string()) + .build(); let res = app .execute_contract( @@ -385,19 +381,16 @@ mod withdraw { 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 Swap tests", - None, test_accounts.creator_1.as_ref(), coin(1_000_000, "out_denom"), "in_denom", bootstrapping_start_time, start_time, end_time, - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract( @@ -541,19 +534,16 @@ mod withdraw { 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 Swap tests", - None, test_accounts.creator_1.as_ref(), coin(1_000_000, "out_denom"), "in_denom", bootstrapping_start_time, start_time, end_time, - None, - None, - None, - ); + ) + .build(); let res = app .execute_contract(