-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// This file is part of HydraDX-node. | ||
|
||
// Copyright (C) 2020-2022 Intergalactic, Limited (GIB). | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use hydradx_traits::router::{Filler, TradeOperation}; | ||
use crate::tests::mock::*; | ||
use crate::Event; | ||
|
||
#[test] | ||
fn event_id_should_be_incremented() { | ||
ExtBuilder::default().build().execute_with(|| { | ||
|
||
assert_eq!(AmmSupport::incremental_id(), 0); | ||
assert_eq!(AmmSupport::next_incremental_id(), 0); | ||
|
||
assert_eq!(AmmSupport::incremental_id(), 1); | ||
assert_eq!(AmmSupport::next_incremental_id(), 1); | ||
|
||
assert_eq!(AmmSupport::incremental_id(), 2); | ||
assert_eq!(AmmSupport::next_incremental_id(), 2); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn event_should_be_deposited() { | ||
ExtBuilder::default().build().execute_with(|| { | ||
AmmSupport::deposit_trade_event( | ||
ALICE, | ||
BOB, | ||
Filler::Omnipool, | ||
TradeOperation::Sell, | ||
HDX, | ||
DOT, | ||
1_000_000, | ||
2_000_000, | ||
vec![(HDX, 1_000, ALICE), (DOT, 2_000, BOB)], | ||
Some(7), | ||
); | ||
|
||
expect_events(vec![Event::Swapped { | ||
swapper: ALICE, | ||
filler: BOB, | ||
filler_type: Filler::Omnipool, | ||
operation: TradeOperation::Sell, | ||
asset_in: HDX, | ||
asset_out: DOT, | ||
amount_in: 1_000_000, | ||
amount_out: 2_000_000, | ||
fees: vec![(HDX, 1_000, ALICE), (DOT, 2_000, BOB)], | ||
event_id: Some(7), | ||
} | ||
.into()]); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// This file is part of HydraDX. | ||
|
||
// Copyright (C) 2020-2022 Intergalactic, Limited (GIB). | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use crate as pallet_amm_support; | ||
|
||
use frame_support::{ | ||
construct_runtime, | ||
sp_runtime::{ | ||
traits::{BlakeTwo256, IdentityLookup}, | ||
BuildStorage, | ||
}, | ||
traits::{ConstU32, ConstU64, Everything}, | ||
}; | ||
use sp_core::H256; | ||
|
||
type Block = frame_system::mocking::MockBlock<Test>; | ||
|
||
pub type AccountId = u64; | ||
pub type AssetId = u32; | ||
|
||
pub const HDX: AssetId = 0; | ||
pub const DOT: AssetId = 1; | ||
|
||
pub const ALICE: AccountId = 1; | ||
pub const BOB: AccountId = 2; | ||
|
||
construct_runtime!( | ||
pub enum Test | ||
{ | ||
System: frame_system, | ||
AmmSupport: pallet_amm_support, | ||
} | ||
); | ||
|
||
impl crate::Config for Test { | ||
type RuntimeEvent = RuntimeEvent; | ||
} | ||
|
||
impl frame_system::Config for Test { | ||
type BaseCallFilter = Everything; | ||
type BlockWeights = (); | ||
type BlockLength = (); | ||
type RuntimeOrigin = RuntimeOrigin; | ||
type RuntimeCall = RuntimeCall; | ||
type RuntimeTask = RuntimeTask; | ||
type Nonce = u64; | ||
type Block = Block; | ||
type Hash = H256; | ||
type Hashing = BlakeTwo256; | ||
type AccountId = AccountId; | ||
type Lookup = IdentityLookup<Self::AccountId>; | ||
type RuntimeEvent = RuntimeEvent; | ||
type BlockHashCount = ConstU64<250>; | ||
type DbWeight = (); | ||
type Version = (); | ||
type PalletInfo = PalletInfo; | ||
type AccountData = (); | ||
type OnNewAccount = (); | ||
type OnKilledAccount = (); | ||
type SystemWeightInfo = (); | ||
type SS58Prefix = (); | ||
type OnSetCode = (); | ||
type MaxConsumers = ConstU32<16>; | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct ExtBuilder { | ||
} | ||
|
||
impl ExtBuilder { | ||
pub fn build(self) -> sp_io::TestExternalities { | ||
let t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap(); | ||
|
||
let mut r: sp_io::TestExternalities = t.into(); | ||
|
||
r.execute_with(|| { | ||
System::set_block_number(1); | ||
}); | ||
|
||
r | ||
} | ||
} | ||
|
||
pub fn expect_events(e: Vec<RuntimeEvent>) { | ||
e.into_iter().for_each(frame_system::Pallet::<Test>::assert_has_event); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod mock; | ||
mod incremental_id; |