diff --git a/pallets/streaming/src/benchmarking.rs b/pallets/streaming/src/benchmarking.rs index 72749c18b..d95fa0196 100644 --- a/pallets/streaming/src/benchmarking.rs +++ b/pallets/streaming/src/benchmarking.rs @@ -52,6 +52,8 @@ benchmarks! { create { let caller: T::AccountId = whitelisted_caller(); transfer_initial_balance::(caller.clone()); + assert_ok!(Streaming::::set_minimum_deposit(SystemOrigin::Root.into(), KSM, 0)); + let recipient: T::AccountId = account("Streaming", 101, SEED); let deposit_amount: u128 = dollar(5); let start_time: u64 = 6; @@ -64,6 +66,7 @@ benchmarks! { cancel { let caller: T::AccountId = whitelisted_caller(); transfer_initial_balance::(caller.clone()); + assert_ok!(Streaming::::set_minimum_deposit(SystemOrigin::Root.into(), KSM, 0)); let recipient: T::AccountId = account("Streaming", 101, SEED); let deposit_amount: u128 = dollar(5); let start_time: u64 = 6; @@ -78,6 +81,8 @@ benchmarks! { withdraw { let caller: T::AccountId = whitelisted_caller(); transfer_initial_balance::(caller.clone()); + assert_ok!(Streaming::::set_minimum_deposit(SystemOrigin::Root.into(), KSM, 0)); + let recipient: T::AccountId = account("Streaming", 101, SEED); let deposit_amount: u128 = dollar(5); diff --git a/pallets/streaming/src/lib.rs b/pallets/streaming/src/lib.rs index 5ff94a4c5..cd4b0afd5 100644 --- a/pallets/streaming/src/lib.rs +++ b/pallets/streaming/src/lib.rs @@ -97,6 +97,8 @@ pub mod pallet { pub enum Error { /// Sender as specified themselves as the recipient RecipientIsAlsoSender, + /// Asset is not supported to create stream + InvalidAssetId, /// Insufficient deposit size DepositLowerThanMinimum, /// Start time is before current block time @@ -219,9 +221,10 @@ pub mod pallet { let sender = ensure_signed(origin)?; ensure!(sender != recipient, Error::::RecipientIsAlsoSender); - let minimum_deposit = MinimumDeposits::::get(asset_id); + let minimum_deposit = + Self::minimum_deposit(asset_id).ok_or(Error::::InvalidAssetId)?; ensure!( - deposit >= minimum_deposit.unwrap_or(1u128), + deposit >= minimum_deposit, Error::::DepositLowerThanMinimum ); @@ -348,12 +351,12 @@ pub mod pallet { stream.try_deduct(amount)?; stream.try_complete()?; + Streams::::insert(stream_id, stream.clone()); if stream.has_finished() { Self::try_push_stream_library(&stream.sender, stream_id, StreamKind::Finish)?; Self::try_push_stream_library(&recipient, stream_id, StreamKind::Finish)?; Self::update_finished_stream_library(&stream.sender, &recipient)?; } - Streams::::insert(stream_id, stream.clone()); // Withdraw deposit from stream T::Assets::transfer( diff --git a/pallets/streaming/src/mock.rs b/pallets/streaming/src/mock.rs index 0de9cba57..5bb6ff48c 100644 --- a/pallets/streaming/src/mock.rs +++ b/pallets/streaming/src/mock.rs @@ -185,6 +185,9 @@ pub(crate) fn new_test_ext() -> sp_io::TestExternalities { // Set block number and time System::set_block_number(0); TimestampPallet::set_timestamp(6000); + + // Set minimum deposit for DOT + Streaming::set_minimum_deposit(Origin::root(), DOT, dollar(0)).unwrap(); }); ext } diff --git a/pallets/streaming/src/tests.rs b/pallets/streaming/src/tests.rs index 1aaccb733..1edd6ebc1 100644 --- a/pallets/streaming/src/tests.rs +++ b/pallets/streaming/src/tests.rs @@ -69,7 +69,7 @@ fn cancel_works_without_withdrawal() { true, )); // rate_per_secs: 101 / (19-6) = 7769230769230 - let stream = >::get(stream_id_0).unwrap(); + let stream = Streams::::get(stream_id_0).unwrap(); assert_eq!( stream, Stream::new(dollar(101), DOT, 7769230769230, ALICE, BOB, 6, 19, true,) @@ -194,7 +194,7 @@ fn withdraw_with_slower_rate_works() { true, )); // rate_per_secs: 101 / (19-6) = 7769230769230 - let stream = >::get(stream_id_0).unwrap(); + let stream = Streams::::get(stream_id_0).unwrap(); assert_eq!( stream, Stream::new(dollar(101), DOT, 7769230769230, ALICE, BOB, 6, 19, true,) @@ -277,7 +277,7 @@ fn cancel_works_with_withdrawal() { true, )); // rate_per_secs: 101 / (19-6) = 7769230769230 - let stream = >::get(stream_id_0).unwrap(); + let stream = Streams::::get(stream_id_0).unwrap(); assert_eq!( stream, Stream::new(dollar(101), DOT, 7769230769230, ALICE, BOB, 6, 19, true,) @@ -649,10 +649,12 @@ fn create_with_minimum_deposit_works() { Error::::DepositLowerThanMinimum ); - // Check with default option + // Asset is not supported to create stream + Assets::force_create(Origin::root(), USDT, ALICE, true, 1).unwrap(); + Assets::mint(Origin::signed(ALICE), USDT, ALICE, dollar(10000)).unwrap(); assert_err!( - Streaming::create(Origin::signed(ALICE), BOB, 0, KSM, 6, 10, true), - Error::::DepositLowerThanMinimum + Streaming::create(Origin::signed(ALICE), BOB, dollar(99), USDT, 6, 10, true), + Error::::InvalidAssetId ); }) }