mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 19:51:05 +00:00
Move Externalities into its own crate (#3775)
* Move `Externalities` into `substrate-externalities` - `Externalities` now support generic extensions - Split of `primtives-storage` for storage primitive types * Move the externalities scoping into `substrate-externalities` * Fix compilation * Review feedback * Adds macro for declaring extensions * Fix benchmarks * Introduce `ExtensionStore` trait * Last review comments * Implement it for `ExtensionStore`
This commit is contained in:
@@ -240,12 +240,14 @@ impl<T: Trait> Module<T> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use runtime_io::with_externalities;
|
||||
use support::{impl_outer_origin, assert_ok, assert_noop, parameter_types};
|
||||
use primitives::{H256, Blake2Hasher};
|
||||
use primitives::H256;
|
||||
// The testing primitives are very useful for avoiding having to work with signatures
|
||||
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required.
|
||||
use sr_primitives::{Perbill, traits::{BlakeTwo256, IdentityLookup}, testing::Header};
|
||||
use sr_primitives::{
|
||||
Perbill, traits::{BlakeTwo256, IdentityLookup}, testing::Header,
|
||||
set_and_run_with_externalities,
|
||||
};
|
||||
|
||||
impl_outer_origin! {
|
||||
pub enum Origin for Test {}
|
||||
@@ -289,13 +291,13 @@ mod tests {
|
||||
|
||||
// This function basically just builds a genesis storage key/value store according to
|
||||
// our desired mockup.
|
||||
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
fn new_test_ext() -> runtime_io::TestExternalities {
|
||||
system::GenesisConfig::default().build_storage::<Test>().unwrap().into()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issuing_asset_units_to_issuer_should_work() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
assert_ok!(Assets::issue(Origin::signed(1), 100));
|
||||
assert_eq!(Assets::balance(0, 1), 100);
|
||||
});
|
||||
@@ -303,7 +305,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn querying_total_supply_should_work() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
assert_ok!(Assets::issue(Origin::signed(1), 100));
|
||||
assert_eq!(Assets::balance(0, 1), 100);
|
||||
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 50));
|
||||
@@ -320,7 +322,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn transferring_amount_above_available_balance_should_work() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
assert_ok!(Assets::issue(Origin::signed(1), 100));
|
||||
assert_eq!(Assets::balance(0, 1), 100);
|
||||
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 50));
|
||||
@@ -331,7 +333,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn transferring_amount_less_than_available_balance_should_not_work() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
assert_ok!(Assets::issue(Origin::signed(1), 100));
|
||||
assert_eq!(Assets::balance(0, 1), 100);
|
||||
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 50));
|
||||
@@ -345,7 +347,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn transferring_less_than_one_unit_should_not_work() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
assert_ok!(Assets::issue(Origin::signed(1), 100));
|
||||
assert_eq!(Assets::balance(0, 1), 100);
|
||||
assert_noop!(Assets::transfer(Origin::signed(1), 0, 2, 0), "transfer amount should be non-zero");
|
||||
@@ -354,7 +356,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn transferring_more_units_than_total_supply_should_not_work() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
assert_ok!(Assets::issue(Origin::signed(1), 100));
|
||||
assert_eq!(Assets::balance(0, 1), 100);
|
||||
assert_noop!(Assets::transfer(Origin::signed(1), 0, 2, 101), "origin account balance must be greater than or equal to the transfer amount");
|
||||
@@ -363,7 +365,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn destroying_asset_balance_with_positive_balance_should_work() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
assert_ok!(Assets::issue(Origin::signed(1), 100));
|
||||
assert_eq!(Assets::balance(0, 1), 100);
|
||||
assert_ok!(Assets::destroy(Origin::signed(1), 0));
|
||||
@@ -372,7 +374,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn destroying_asset_balance_with_zero_balance_should_not_work() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
assert_ok!(Assets::issue(Origin::signed(1), 100));
|
||||
assert_eq!(Assets::balance(0, 2), 0);
|
||||
assert_noop!(Assets::destroy(Origin::signed(2), 0), "origin balance should be non-zero");
|
||||
|
||||
Reference in New Issue
Block a user