Skip to content

Commit

Permalink
fungible conformance tests: Inspect and Mutate (paritytech#13852)
Browse files Browse the repository at this point in the history
* typo

* - create test files for each fungile trait
- begin implementing tests for the Inspect trait

* wrap inspect tests in a macro

* first run of mutate tests

* move test implementation out of ballances

* make tests more generic

* transfer tests

* combine inspect and mutate tests

* set balance failing tests

* can_deposit tests

* can_withdraw tests

* test reducible_balance

* remove balanced stub

* revert set_balance return val fix

* typo

* macro and dust trap tests

* disable test when it doesn't make sense

* remove debug comment

* reduce macro boilerplate

* improved var naming

* improve variable naming

* remove redundant comment

* remove placeholder tests

* remove placeholder tests

* simplify macro

* Update frame/balances/src/tests/fungible_conformance_tests.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* use Balance from T

* fix copyright

* add test doc comments

* improve test naming

* clippy

* fix rustdoc errors

* fix rustdoc

* improve macro

* improve variable naming

* remove redundant comment

* use path

---------

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
  • Loading branch information
2 people authored and nathanwhit committed Jul 19, 2023
1 parent 393d57f commit ccbe9aa
Show file tree
Hide file tree
Showing 8 changed files with 1,069 additions and 1 deletion.
1 change: 1 addition & 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 frame/balances/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ sp-std = { version = "5.0.0", default-features = false, path = "../../primitives
pallet-transaction-payment = { version = "4.0.0-dev", path = "../transaction-payment" }
sp-core = { version = "7.0.0", path = "../../primitives/core" }
sp-io = { version = "7.0.0", path = "../../primitives/io" }
paste = "1.0.12"

[features]
default = ["std"]
Expand Down
88 changes: 88 additions & 0 deletions frame/balances/src/tests/fungible_conformance_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// 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 super::*;
use frame_support::traits::fungible::{conformance_tests, Inspect, Mutate};
use paste::paste;

macro_rules! run_tests {
($path:path, $ext_deposit:expr, $($name:ident),*) => {
$(
paste! {
#[test]
fn [< $name _existential_deposit_ $ext_deposit _dust_trap_on >]() {
let trap_account = <Test as frame_system::Config>::AccountId::from(65174286u64);
let builder = ExtBuilder::default().existential_deposit($ext_deposit).dust_trap(trap_account);
builder.build_and_execute_with(|| {
Balances::set_balance(&trap_account, Balances::minimum_balance());
$path::$name::<
Balances,
<Test as frame_system::Config>::AccountId,
>(Some(trap_account));
});
}

#[test]
fn [< $name _existential_deposit_ $ext_deposit _dust_trap_off >]() {
let builder = ExtBuilder::default().existential_deposit($ext_deposit);
builder.build_and_execute_with(|| {
$path::$name::<
Balances,
<Test as frame_system::Config>::AccountId,
>(None);
});
}
}
)*
};
($path:path, $ext_deposit:expr) => {
run_tests!(
$path,
$ext_deposit,
mint_into_success,
mint_into_overflow,
mint_into_below_minimum,
burn_from_exact_success,
burn_from_best_effort_success,
burn_from_exact_insufficient_funds,
restore_success,
restore_overflow,
restore_below_minimum,
shelve_success,
shelve_insufficient_funds,
transfer_success,
transfer_expendable_all,
transfer_expendable_dust,
transfer_protect_preserve,
set_balance_mint_success,
set_balance_burn_success,
can_deposit_success,
can_deposit_below_minimum,
can_deposit_overflow,
can_withdraw_success,
can_withdraw_reduced_to_zero,
can_withdraw_balance_low,
reducible_balance_expendable,
reducible_balance_protect_preserve
);
};
}

run_tests!(conformance_tests::inspect_mutate, 1);
run_tests!(conformance_tests::inspect_mutate, 2);
run_tests!(conformance_tests::inspect_mutate, 5);
run_tests!(conformance_tests::inspect_mutate, 1000);
1 change: 1 addition & 0 deletions frame/balances/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use sp_runtime::{

mod currency_tests;
mod dispatchable_tests;
mod fungible_conformance_tests;
mod fungible_tests;
mod reentrancy_tests;

Expand Down
Loading

0 comments on commit ccbe9aa

Please sign in to comment.