Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

fungible conformance tests: Inspect and Mutate #13852

Merged
merged 47 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
577e69e
typo
liamaharon Mar 24, 2023
2d43fbc
- create test files for each fungile trait
liamaharon Mar 25, 2023
344d3a6
Merge branch 'master' of github.com:paritytech/substrate into liam-fu…
liamaharon Mar 28, 2023
9e3dc4e
wrap inspect tests in a macro
liamaharon Mar 28, 2023
c8b9e80
first run of mutate tests
liamaharon Mar 28, 2023
9f553fd
move test implementation out of ballances
liamaharon Mar 28, 2023
68db553
Merge branch 'master' of github.com:paritytech/substrate into liam-fu…
liamaharon Mar 28, 2023
6ba1a0a
Merge branch 'master' of github.com:paritytech/substrate into liam-fu…
liamaharon Apr 6, 2023
bdf0020
make tests more generic
liamaharon Apr 7, 2023
c1286cd
transfer tests
liamaharon Apr 7, 2023
b1c7b2a
combine inspect and mutate tests
liamaharon Apr 7, 2023
28ae371
set balance failing tests
liamaharon Apr 7, 2023
bfd008b
can_deposit tests
liamaharon Apr 7, 2023
7a7fab9
can_withdraw tests
liamaharon Apr 7, 2023
d305774
test reducible_balance
liamaharon Apr 7, 2023
7544e0f
remove balanced stub
liamaharon Apr 7, 2023
509f61a
revert set_balance return val fix
liamaharon Apr 7, 2023
d7bf251
typo
liamaharon Apr 7, 2023
2873dda
Merge branch 'master' of github.com:paritytech/substrate into liam-fu…
liamaharon Apr 8, 2023
6c4de8e
Merge branch 'master' of github.com:paritytech/substrate into liam-fu…
liamaharon Apr 10, 2023
3ebe6e9
macro and dust trap tests
liamaharon Apr 10, 2023
33f6a6b
disable test when it doesn't make sense
liamaharon Apr 10, 2023
13455c7
remove debug comment
liamaharon Apr 10, 2023
a948896
reduce macro boilerplate
liamaharon Apr 10, 2023
c12a327
improved var naming
liamaharon Apr 10, 2023
1685856
improve variable naming
liamaharon Apr 10, 2023
1b13509
remove redundant comment
liamaharon Apr 10, 2023
8845504
remove placeholder tests
liamaharon Apr 10, 2023
8b1b707
remove placeholder tests
liamaharon Apr 10, 2023
95286a8
simplify macro
liamaharon Apr 11, 2023
682f33f
Update frame/balances/src/tests/fungible_conformance_tests.rs
liamaharon Apr 11, 2023
090e7bb
use Balance from T
liamaharon Apr 11, 2023
bb4242d
Merge branch 'liam-fungibles-conformance-tests' of github.com:parityt…
liamaharon Apr 11, 2023
dd7ae89
fix copyright
liamaharon Apr 11, 2023
cdb4fa0
Merge branch 'master' of github.com:paritytech/substrate into liam-fu…
liamaharon Apr 11, 2023
880aeb0
add test doc comments
liamaharon Apr 11, 2023
8d8ffa9
improve test naming
liamaharon Apr 11, 2023
6764c26
Merge branch 'master' of github.com:paritytech/substrate into liam-fu…
liamaharon Apr 11, 2023
704f06e
clippy
liamaharon Apr 12, 2023
e8b1323
fix rustdoc errors
liamaharon Apr 12, 2023
f7baa52
fix rustdoc
liamaharon Apr 12, 2023
137a8dc
improve macro
liamaharon Apr 18, 2023
39c00bb
improve variable naming
liamaharon Apr 18, 2023
76c0808
Merge branch 'master' of github.com:paritytech/substrate into liam-fu…
liamaharon Apr 18, 2023
00d494b
remove redundant comment
liamaharon Apr 18, 2023
f265ff1
use path
liamaharon May 4, 2023
30b9781
Merge branch 'master' of github.com:paritytech/substrate into liam-fu…
liamaharon May 4, 2023
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
329 changes: 329 additions & 0 deletions frame/balances/src/tests/fungible_conformance_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,329 @@
// This file is part of Substrate.

// Copyright (C) 2017-2023 Parity Technologies (UK) Ltd.
liamaharon marked this conversation as resolved.
Show resolved Hide resolved
// 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;

// TODO: Add a macro to the conformance tests to generate all of these tests

#[test]
fn mint_into_success() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::mint_into_success::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}
liamaharon marked this conversation as resolved.
Show resolved Hide resolved

#[test]
fn mint_into_overflow() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::mint_into_overflow::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn mint_into_below_minimum() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::mint_into_below_minimum::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn mint_into_done_mint_into() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::mint_into_done_mint_into::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn burn_from_exact_success() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::burn_from_exact_success::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn burn_from_best_effort_success() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::burn_from_best_effort_success::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn burn_from_exact_insufficient_funds() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::burn_from_exact_insufficient_funds::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn restore_success() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::restore_success::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn restore_overflow() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::restore_overflow::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn restore_below_minimum() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::restore_below_minimum::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn restore_done_restore() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::restore_done_restore::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn shelve_success() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::shelve_success::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn shelve_insufficient_funds() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::shelve_insufficient_funds::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn shelve_done_shelve() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::shelve_done_shelve::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn transfer_success() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::transfer_success::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn transfer_expendable() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::transfer_expendable::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn transfer_protect_preserve() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::transfer_protect_preserve::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn transfer_done_transfer() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::transfer_done_transfer::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn set_balance_mint_success() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::set_balance_mint_success::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn set_balance_burn_success() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::set_balance_burn_success::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn can_deposit_success() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::can_deposit_success::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn can_deposit_below_minimum() {
ExtBuilder::default().existential_deposit(5).build_and_execute_with(|| {
conformance_tests::inspect_mutate::can_deposit_below_minimum::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn can_deposit_overflow() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::can_deposit_overflow::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn can_withdraw_success() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::can_withdraw_success::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn can_withdraw_reduced_to_zero() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::can_withdraw_reduced_to_zero::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn can_withdraw_balance_low() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::can_withdraw_balance_low::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn reducible_balance_expendable() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::reducible_balance_expendable::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}

#[test]
fn reducible_balance_protect_preserve() {
ExtBuilder::default().build_and_execute_with(|| {
conformance_tests::inspect_mutate::reducible_balance_protect_preserve::<
Balances,
<Test as frame_system::Config>::AccountId,
<Test as pallet_balances::Config>::Balance,
>();
});
}
2 changes: 2 additions & 0 deletions frame/balances/src/tests/fungible_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// limitations under the License.

//! Tests regarding the functionality of the `fungible` trait set implementations.
//!
//! TODO: Bundle these tests into the conformance tests & remove them.

use super::*;
use frame_support::traits::tokens::{
Expand Down
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