Skip to content

Commit

Permalink
minor example reorder
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Oct 11, 2023
1 parent ce6b634 commit abd0c89
Showing 1 changed file with 44 additions and 43 deletions.
87 changes: 44 additions & 43 deletions runtime/integration-tests/src/generic/cases/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ fn transfer_balance<T: Runtime>() {
)
.unwrap();

// Pass blocks to evolve the system
env.pass(Blocks::ByNumber(1));

// Check for an even occurred in this block
env.check_event(pallet_balances::Event::Transfer {
from: Keyring::Alice.to_account_id(),
Expand All @@ -50,9 +53,6 @@ fn transfer_balance<T: Runtime>() {
})
.unwrap();

// Pass blocks to evolve the system
env.pass(Blocks::ByNumber(1));

// Check the state
env.state(|| {
assert_eq!(
Expand All @@ -62,43 +62,7 @@ fn transfer_balance<T: Runtime>() {
});
}

fn call_api<T: Runtime>() {
let env = RuntimeEnv::<T>::from_storage(Default::default());

env.state(|| {
// Call to Core::version() API.
// It's automatically implemented by the runtime T, so you can easily do:
// T::version()
assert_eq!(T::version(), <T as frame_system::Config>::Version::get());
})
}

fn check_fee<T: Runtime>() {
let mut env = RuntimeEnv::<T>::from_storage(
Genesis::default()
.add(pallet_balances::GenesisConfig::<T> {
balances: vec![(Keyring::Alice.to_account_id(), 1 * CFG)],
})
.storage(),
);

env.submit(
Keyring::Alice,
frame_system::Call::remark { remark: vec![] },
)
.unwrap();

// Get the fee of the last submitted extrinsic
let fee = env.last_fee();

env.state(|| {
assert_eq!(
pallet_balances::Pallet::<T>::free_balance(Keyring::Alice.to_account_id()),
1 * CFG - fee
);
});
}

// Identical to `transfer_balance()` test but using fudge.
fn fudge_transfer_balance<T: Runtime + FudgeSupport>() {
const TRANSFER: Balance = 1000 * CFG;
const FOR_FEES: Balance = 1 * CFG;
Expand Down Expand Up @@ -142,6 +106,17 @@ fn fudge_transfer_balance<T: Runtime + FudgeSupport>() {
.unwrap();
}

fn call_api<T: Runtime>() {
let env = RuntimeEnv::<T>::from_storage(Default::default());

env.state(|| {
// Call to Core::version() API.
// It's automatically implemented by the runtime T, so you can easily do:
// T::version()
assert_eq!(T::version(), <T as frame_system::Config>::Version::get());
})
}

fn fudge_call_api<T: Runtime + FudgeSupport>() {
let env = FudgeEnv::<T>::from_storage(Default::default());

Expand All @@ -151,11 +126,37 @@ fn fudge_call_api<T: Runtime + FudgeSupport>() {
// We include the API we want to use
use sp_api::Core;

let result = api.version(&latest).unwrap();

assert_eq!(result, T::version());
assert_eq!(result, <T as frame_system::Config>::Version::get());
})
}

fn check_fee<T: Runtime>() {
let mut env = RuntimeEnv::<T>::from_storage(
Genesis::default()
.add(pallet_balances::GenesisConfig::<T> {
balances: vec![(Keyring::Alice.to_account_id(), 1 * CFG)],
})
.storage(),
);

env.submit(
Keyring::Alice,
frame_system::Call::remark { remark: vec![] },
)
.unwrap();

// Get the fee of the last submitted extrinsic
let fee = env.last_fee();

env.state(|| {
assert_eq!(
api.version(&latest).unwrap(),
<T as frame_system::Config>::Version::get()
pallet_balances::Pallet::<T>::free_balance(Keyring::Alice.to_account_id()),
1 * CFG - fee
);
})
});
}

crate::test_for_runtimes!([development, altair, centrifuge], transfer_balance);
Expand Down

0 comments on commit abd0c89

Please sign in to comment.