mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 02:21:14 +00:00
Add execute_with to TestExternalities (#3793)
This function executes the given closure in a context where the test externalities are set. This makes the srml tests easier to write, as the test externalities need to be created anyway.
This commit is contained in:
@@ -173,10 +173,10 @@ macro_rules! assert_err {
|
||||
#[macro_export]
|
||||
#[cfg(feature = "std")]
|
||||
macro_rules! assert_ok {
|
||||
( $x:expr ) => {
|
||||
( $x:expr $(,)? ) => {
|
||||
assert_eq!($x, Ok(()));
|
||||
};
|
||||
( $x:expr, $y:expr ) => {
|
||||
( $x:expr, $y:expr $(,)? ) => {
|
||||
assert_eq!($x, Ok($y));
|
||||
}
|
||||
}
|
||||
@@ -236,7 +236,6 @@ pub use serde::{Serialize, Deserialize};
|
||||
mod tests {
|
||||
use super::*;
|
||||
use codec::{Codec, EncodeLike};
|
||||
use sr_primitives::set_and_run_with_externalities;
|
||||
use srml_metadata::{
|
||||
DecodeDifferent, StorageEntryMetadata, StorageMetadata, StorageEntryType,
|
||||
StorageEntryModifier, DefaultByteGetter, StorageHasher,
|
||||
@@ -288,7 +287,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn linked_map_issue_3318() {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
new_test_ext().execute_with(|| {
|
||||
OptionLinkedMap::insert(1, 1);
|
||||
assert_eq!(OptionLinkedMap::get(1), Some(1));
|
||||
OptionLinkedMap::insert(1, 2);
|
||||
@@ -298,7 +297,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn linked_map_swap_works() {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
new_test_ext().execute_with(|| {
|
||||
OptionLinkedMap::insert(0, 0);
|
||||
OptionLinkedMap::insert(1, 1);
|
||||
OptionLinkedMap::insert(2, 2);
|
||||
@@ -327,7 +326,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn linked_map_basic_insert_remove_should_work() {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
new_test_ext().execute_with(|| {
|
||||
// initialized during genesis
|
||||
assert_eq!(Map::get(&15u32), 42u64);
|
||||
|
||||
@@ -353,7 +352,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn linked_map_enumeration_and_head_should_work() {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_eq!(Map::head(), Some(15));
|
||||
assert_eq!(Map::enumerate().collect::<Vec<_>>(), vec![(15, 42)]);
|
||||
// insert / remove
|
||||
@@ -405,7 +404,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn double_map_basic_insert_remove_remove_prefix_should_work() {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
new_test_ext().execute_with(|| {
|
||||
type DoubleMap = DataDM;
|
||||
// initialized during genesis
|
||||
assert_eq!(DoubleMap::get(&15u32, &16u32), 42u64);
|
||||
@@ -445,7 +444,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn double_map_append_should_work() {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
new_test_ext().execute_with(|| {
|
||||
type DoubleMap = AppendableDM<Test>;
|
||||
|
||||
let key1 = 17u32;
|
||||
|
||||
@@ -759,7 +759,6 @@ mod test3 {
|
||||
#[allow(dead_code)]
|
||||
mod test_append_and_len {
|
||||
use runtime_io::TestExternalities;
|
||||
use sr_primitives::set_and_run_with_externalities;
|
||||
use codec::{Encode, Decode};
|
||||
|
||||
pub trait Trait {
|
||||
@@ -801,7 +800,7 @@ mod test_append_and_len {
|
||||
|
||||
#[test]
|
||||
fn default_for_option() {
|
||||
set_and_run_with_externalities(&mut TestExternalities::default(), || {
|
||||
TestExternalities::default().execute_with(|| {
|
||||
assert_eq!(OptionVec::get(), None);
|
||||
assert_eq!(JustVec::get(), vec![]);
|
||||
});
|
||||
@@ -809,7 +808,7 @@ mod test_append_and_len {
|
||||
|
||||
#[test]
|
||||
fn append_works() {
|
||||
set_and_run_with_externalities(&mut TestExternalities::default(), || {
|
||||
TestExternalities::default().execute_with(|| {
|
||||
let _ = MapVec::append(1, [1, 2, 3].iter());
|
||||
let _ = MapVec::append(1, [4, 5].iter());
|
||||
assert_eq!(MapVec::get(1), vec![1, 2, 3, 4, 5]);
|
||||
@@ -822,7 +821,7 @@ mod test_append_and_len {
|
||||
|
||||
#[test]
|
||||
fn append_works_for_default() {
|
||||
set_and_run_with_externalities(&mut TestExternalities::default(), || {
|
||||
TestExternalities::default().execute_with(|| {
|
||||
assert_eq!(JustVecWithDefault::get(), vec![6, 9]);
|
||||
let _ = JustVecWithDefault::append([1].iter());
|
||||
assert_eq!(JustVecWithDefault::get(), vec![6, 9, 1]);
|
||||
@@ -839,7 +838,7 @@ mod test_append_and_len {
|
||||
|
||||
#[test]
|
||||
fn append_or_put_works() {
|
||||
set_and_run_with_externalities(&mut TestExternalities::default(), || {
|
||||
TestExternalities::default().execute_with(|| {
|
||||
let _ = MapVec::append_or_insert(1, &[1, 2, 3][..]);
|
||||
let _ = MapVec::append_or_insert(1, &[4, 5][..]);
|
||||
assert_eq!(MapVec::get(1), vec![1, 2, 3, 4, 5]);
|
||||
@@ -856,7 +855,7 @@ mod test_append_and_len {
|
||||
|
||||
#[test]
|
||||
fn len_works() {
|
||||
set_and_run_with_externalities(&mut TestExternalities::default(), || {
|
||||
TestExternalities::default().execute_with(|| {
|
||||
JustVec::put(&vec![1, 2, 3, 4]);
|
||||
OptionVec::put(&vec![1, 2, 3, 4, 5]);
|
||||
MapVec::insert(1, &vec![1, 2, 3, 4, 5, 6]);
|
||||
@@ -871,7 +870,7 @@ mod test_append_and_len {
|
||||
|
||||
#[test]
|
||||
fn len_works_for_default() {
|
||||
set_and_run_with_externalities(&mut TestExternalities::default(), || {
|
||||
TestExternalities::default().execute_with(|| {
|
||||
// vec
|
||||
assert_eq!(JustVec::get(), vec![]);
|
||||
assert_eq!(JustVec::decode_len(), Ok(0));
|
||||
|
||||
Reference in New Issue
Block a user