Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unit tests done #327

Merged
merged 3 commits into from
Oct 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ members = [
"pallets/vtoken-mint",
"pallets/vtoken-mint/rpc",
"pallets/token-issuer",
"pallets/lightening-redeem",
"runtime/asgard",
"runtime/bifrost",
"utils/subkey",
Expand Down
6 changes: 6 additions & 0 deletions node/service/src/chain_spec/asgard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ fn local_config_genesis(id: ParaId) -> GenesisConfig {
(x.clone(), CurrencyId::Stable(TokenSymbol::KUSD), ENDOWMENT * 4_000_000),
(x.clone(), CurrencyId::Token(TokenSymbol::KSM), ENDOWMENT * 4_000_000),
(x.clone(), CurrencyId::Native(TokenSymbol::ASG), ENDOWMENT * 4_000_000),
(x.clone(), CurrencyId::VSToken(TokenSymbol::KSM), ENDOWMENT * 4_000_000),
(
x.clone(),
CurrencyId::VSBond(TokenSymbol::BNC, 2001, 13, 20),
ENDOWMENT * 4_000_000,
),
]
})
.collect();
Expand Down
47 changes: 47 additions & 0 deletions pallets/lightening-redeem/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[package]
name = "bifrost-lightening-redeem"
version = "0.8.0"
authors = ["Herry Ho <herry.heyi@gmail.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.124", optional = true }
orml-traits = { version = "0.4.1-dev", default-features = false }
orml-tokens = { version = "0.4.1-dev", default-features = false }
node-primitives = { path = "../../node/primitives", default-features = false }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.10", default-features = false, optional = true }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.10", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.10", default-features = false }
sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.10", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.10", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.10", default-features = false }
pallet-collective = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.10", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.10", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.10", default-features = false }

[features]
default = ["std"]
std = [
"codec/std",
"frame-system/std",
"frame-support/std",
"sp-runtime/std",
"sp-arithmetic/std",
"serde/std",
"orml-traits/std",
"orml-tokens/std",
"node-primitives/std",
"sp-core/std",
"sp-io/std",
"sp-std/std",
"pallet-collective/std",
]

runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
83 changes: 83 additions & 0 deletions pallets/lightening-redeem/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// This file is part of Bifrost.

// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#![cfg(feature = "runtime-benchmarks")]

use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_support::{dispatch::UnfilteredDispatchable, sp_runtime::traits::UniqueSaturatedFrom};
use frame_system::RawOrigin;

use super::*;
#[allow(unused_imports)]
use crate::Pallet as LighteningRedeem;
use crate::{PoolAmount, StartEndReleaseBlock};

benchmarks! {
add_ksm_to_pool {
let caller: T::AccountId = whitelisted_caller();
let token_amount = BalanceOf::<T>::unique_saturated_from(1000u32 as u128);
}: _(RawOrigin::Signed(caller), token_amount)

exchange_for_ksm {
let caller: T::AccountId = whitelisted_caller();
// add 1000 ksm to the pool
let amount = BalanceOf::<T>::unique_saturated_from(1_000u128);
LighteningRedeem::<T>::add_ksm_to_pool(RawOrigin::Signed(caller.clone()).into(), BalanceOf::<T>::unique_saturated_from(amount))?;

PoolAmount::<T>::mutate(|amt| *amt += amount);

let exchange_amount: u128 = 900;
let token_amount = BalanceOf::<T>::unique_saturated_from(exchange_amount);
}: _(RawOrigin::Signed(caller), token_amount)

edit_exchange_price {
let origin = T::ControlOrigin::successful_origin();
let price = BalanceOf::<T>::unique_saturated_from(50u128);
let call = Call::<T>::edit_exchange_price(price);
}: {call.dispatch_bypass_filter(origin)?}

edit_release_per_day {
let origin = T::ControlOrigin::successful_origin();
let amount_per_day = BalanceOf::<T>::unique_saturated_from(50u128);
let call = Call::<T>::edit_release_per_day(amount_per_day);
}: {call.dispatch_bypass_filter(origin)?}

edit_release_start_and_end_block {
let origin = T::ControlOrigin::successful_origin();
let start = BlockNumberFor::<T>::from(50u32);
let end = BlockNumberFor::<T>::from(100u32);
let call = Call::<T>::edit_release_start_and_end_block(start, end);
}: {call.dispatch_bypass_filter(origin)?}

on_initialize {
let caller: T::AccountId = whitelisted_caller();
let amount: u128 = 1_000;
LighteningRedeem::<T>::add_ksm_to_pool(RawOrigin::Signed(caller.clone()).into(), BalanceOf::<T>::unique_saturated_from(amount))?;
StartEndReleaseBlock::<T>::mutate(|interval| *interval = (T::BlockNumber::from(0u32), T::BlockNumber::from(100u32)));

let block_num = T::BlockNumber::from(10u32);
}:{LighteningRedeem::<T>::on_initialize(block_num);}
}

impl_benchmark_test_suite!(
LighteningRedeem,
crate::mock::ExtBuilder::default()
.one_hundred_precision_for_each_currency_type_for_whitelist_account()
.build(),
crate::mock::Test
);
Loading