Impl integrity test for runtime (#6356)

* impl integrity test for runtime

* Update frame/support/src/traits.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update frame/support/procedural/src/construct_runtime/mod.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* use thread local

* update doc

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Gavin Wood <gavin@parity.io>
This commit is contained in:
Guillaume Thiolliere
2020-06-16 13:10:10 +02:00
committed by GitHub
parent 34f496eb3d
commit 622dff9ca7
6 changed files with 175 additions and 5 deletions
@@ -15,16 +15,24 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! General tests for construct_runtime macro, test for:
//! * error declareed with decl_error works
//! * integrity test is generated
#![recursion_limit="128"]
use sp_runtime::{generic, traits::{BlakeTwo256, Block as _, Verify}, DispatchError};
use sp_core::{H256, sr25519};
use sp_std::cell::RefCell;
mod system;
pub trait Currency {}
thread_local! {
pub static INTEGRITY_TEST_EXEC: RefCell<u32> = RefCell::new(0);
}
mod module1 {
use super::*;
@@ -65,6 +73,10 @@ mod module2 {
pub fn fail(_origin) -> frame_support::dispatch::DispatchResult {
Err(Error::<T>::Something.into())
}
fn integrity_test() {
INTEGRITY_TEST_EXEC.with(|i| *i.borrow_mut() += 1);
}
}
}
@@ -139,3 +151,9 @@ fn check_module2_error_type() {
Err(DispatchError::Module { index: 2, error: 0, message: Some("Something") }),
);
}
#[test]
fn integrity_test_works() {
__construct_runtime_integrity_test::runtime_integrity_tests();
assert_eq!(INTEGRITY_TEST_EXEC.with(|i| *i.borrow()), 1);
}