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

Commit

Permalink
Add use for sp_io::storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinonard committed Oct 20, 2022
1 parent 8ad9cf5 commit 53385e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
5 changes: 3 additions & 2 deletions frame/assets/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use frame_support::{
traits::{ConstU32, ConstU64, GenesisBuild},
};
use sp_core::H256;
use sp_io::storage;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
Expand Down Expand Up @@ -91,11 +92,11 @@ impl pallet_balances::Config for Test {
pub struct AssetsCallbackHandle;
impl AssetsCallback<AssetId, AccountId> for AssetsCallbackHandle {
fn created(_id: &AssetId, _owner: &AccountId) {
sp_io::storage::set(b"asset_created", &true.encode());
storage::set(b"asset_created", &true.encode());
}

fn destroyed(_id: &AssetId) {
sp_io::storage::set(b"asset_destroyed", &true.encode());
storage::set(b"asset_destroyed", &true.encode());
}
}

Expand Down
17 changes: 9 additions & 8 deletions frame/assets/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use super::*;
use crate::{mock::*, Error};
use frame_support::{assert_noop, assert_ok, traits::Currency};
use pallet_balances::Error as BalancesError;
use sp_io::storage;
use sp_runtime::{traits::ConvertInto, TokenError};

#[test]
Expand Down Expand Up @@ -1003,26 +1004,26 @@ fn querying_roles_should_work() {
#[test]
fn normal_asset_create_and_destroy_callbacks_should_work() {
new_test_ext().execute_with(|| {
assert!(sp_io::storage::get(b"asset_created").is_none());
assert!(sp_io::storage::get(b"asset_destroyed").is_none());
assert!(storage::get(b"asset_created").is_none());
assert!(storage::get(b"asset_destroyed").is_none());

Balances::make_free_balance_be(&1, 100);
assert_ok!(Assets::create(Origin::signed(1), 0, 1, 1));
assert!(sp_io::storage::get(b"asset_created").is_some());
assert!(sp_io::storage::get(b"asset_destroyed").is_none());
assert!(storage::get(b"asset_created").is_some());
assert!(storage::get(b"asset_destroyed").is_none());

let w = Asset::<Test>::get(0).unwrap().destroy_witness();
assert_ok!(Assets::destroy(Origin::signed(1), 0, w));
assert!(sp_io::storage::get(b"asset_destroyed").is_some());
assert!(storage::get(b"asset_destroyed").is_some());
});
}

#[test]
fn root_asset_create_should_work() {
new_test_ext().execute_with(|| {
assert!(sp_io::storage::get(b"asset_created").is_none());
assert!(storage::get(b"asset_created").is_none());
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
assert!(sp_io::storage::get(b"asset_created").is_some());
assert!(sp_io::storage::get(b"asset_destroyed").is_none());
assert!(storage::get(b"asset_created").is_some());
assert!(storage::get(b"asset_destroyed").is_none());
});
}

0 comments on commit 53385e6

Please sign in to comment.