diff --git a/pallets/xyk/src/lib.rs b/pallets/xyk/src/lib.rs index 415e4aa234918..7ac4d692fd47c 100644 --- a/pallets/xyk/src/lib.rs +++ b/pallets/xyk/src/lib.rs @@ -1392,7 +1392,7 @@ impl XykFunctionsTrait for Module { second_asset_id, second_asset_amount, liquidity_asset_id, - second_asset_amount, + liquidity_assets_minted, )); Ok(()) @@ -1555,7 +1555,7 @@ impl XykFunctionsTrait for Module { second_asset_id, second_asset_amount, liquidity_asset_id, - second_asset_amount, + liquidity_asset_amount, )); Ok(()) diff --git a/pallets/xyk/src/mock.rs b/pallets/xyk/src/mock.rs index 4a1f10db4b274..4968e5e8222c5 100644 --- a/pallets/xyk/src/mock.rs +++ b/pallets/xyk/src/mock.rs @@ -9,18 +9,28 @@ use sp_runtime::{ Perbill, }; -use frame_support::{impl_outer_origin, parameter_types, weights::Weight}; +use frame_support::{impl_outer_origin, impl_outer_event, parameter_types, weights::Weight}; use frame_system as system; use mangata_primitives::{Amount, Balance, TokenId}; use orml_tokens::{MultiTokenCurrency, MultiTokenCurrencyAdapter, MultiTokenCurrencyExtended}; use pallet_assets_info as assets_info; pub const NATIVE_CURRENCY_ID: u32 = 0; +mod xyk { + pub use crate::Event; +} impl_outer_origin! { pub enum Origin for Test {} } +impl_outer_event! { + pub enum TestEvent for Test { + frame_system, + xyk, + orml_tokens, + } +} // For testing the pallet, we construct most of a mock runtime. This means // first constructing a configuration type (`Test`) which `impl`s each of the // configuration traits of pallets we want to use. @@ -43,7 +53,7 @@ impl system::Trait for Test { type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; - type Event = (); + type Event = TestEvent; type BlockHashCount = BlockHashCount; type MaximumBlockWeight = MaximumBlockWeight; type DbWeight = (); @@ -61,7 +71,7 @@ impl system::Trait for Test { } impl orml_tokens::Trait for Test { - type Event = (); + type Event = TestEvent; type Balance = Balance; type Amount = Amount; type CurrencyId = TokenId; @@ -96,12 +106,13 @@ parameter_types! { } impl Trait for Test { - type Event = (); + type Event = TestEvent; type Currency = MultiTokenCurrencyAdapter; type NativeCurrencyId = NativeCurrencyId; } pub type XykStorage = Module; +pub type System = system::Module; impl Module { pub fn balance(id: TokenId, who: T::AccountId) -> Balance { diff --git a/pallets/xyk/src/tests.rs b/pallets/xyk/src/tests.rs index 1660dee697e00..47ecdc867be44 100644 --- a/pallets/xyk/src/tests.rs +++ b/pallets/xyk/src/tests.rs @@ -2,7 +2,6 @@ #![allow(non_snake_case)] use super::*; -use crate::mock::Test; use crate::mock::*; use frame_support::assert_err; @@ -60,6 +59,7 @@ use frame_support::assert_err; fn initialize() { // creating asset with assetId 0 and minting to accountId 2 + System::set_block_number(1); let acc_id: u64 = 2; let amount: u128 = 1000000000000000000000; XykStorage::create_new_token(&acc_id, amount); @@ -73,6 +73,10 @@ fn initialize() { 60000000000000000000, ) .unwrap(); + + let pool_created_event = TestEvent::xyk(Event::::PoolCreated(acc_id, 0, 40000000000000000000, 1, 60000000000000000000)); + + assert!(System::events().iter().any(|record| record.event == pool_created_event)); } fn initialize_buy_and_burn() { @@ -438,6 +442,7 @@ fn create_pool_W() { XykStorage::balance(1, XykStorage::account_id()), 60000000000000000000 ); // amount of asset 1 in vault acc after creating pool + }); } @@ -534,6 +539,7 @@ fn create_pool_N_zero_second_amount() { #[test] fn sell_W() { new_test_ext().execute_with(|| { + System::set_block_number(1); initialize(); XykStorage::sell_asset(Origin::signed(2), 0, 1, 20000000000000000000, 0).unwrap(); // selling 20000000000000000000 assetId 0 of pool 0 1 @@ -551,6 +557,10 @@ fn sell_W() { XykStorage::balance(1, XykStorage::account_id()), 40040040040040040041 ); // amount of asset 1 in vault acc after creating pool + + let assets_swapped_event = TestEvent::xyk(Event::::AssetsSwapped(2, 0, 20000000000000000000, 1, 19959959959959959959)); + + assert!(System::events().iter().any(|record| record.event == assets_swapped_event)); }); } @@ -627,6 +637,7 @@ fn sell_N_zero_amount() { #[test] fn buy_W() { new_test_ext().execute_with(|| { + System::set_block_number(1); initialize(); // buying 30000000000000000000 assetId 1 of pool 0 1 XykStorage::buy_asset( @@ -651,6 +662,10 @@ fn buy_W() { XykStorage::balance(1, XykStorage::account_id()), 30000000000000000000 ); // amount of asset 1 in vault acc after creating pool + + let assets_swapped_event = TestEvent::xyk(Event::::AssetsSwapped(2, 0, 40120361083249749248, 1, 30000000000000000000)); + + assert!(System::events().iter().any(|record| record.event == assets_swapped_event)); }); } @@ -787,6 +802,9 @@ fn mint_W() { XykStorage::balance(1, XykStorage::account_id()), 90000000000000000001 ); // amount of asset 1 in vault acc after creating pool + let liquidity_minted_event = TestEvent::xyk(Event::::LiquidityMinted(2, 0, 20000000000000000000, 1, 30000000000000000001, 2, 50000000000000000000 )); + + assert!(System::events().iter().any(|record| record.event == liquidity_minted_event)); }); } @@ -908,6 +926,10 @@ fn burn_W() { XykStorage::balance(1, XykStorage::account_id()), 30000000000000000000 ); // amount of asset 1 in vault acc after creating pool + + let liquidity_burned = TestEvent::xyk(Event::::LiquidityBurned(2, 0, 20000000000000000000, 1, 30000000000000000000, 2, 50000000000000000000)); + + assert!(System::events().iter().any(|record| record.event == liquidity_burned)); }); }