-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e683e16
commit 360bb2a
Showing
12 changed files
with
263 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[package] | ||
name = "pallet-fungibles" | ||
authors = ["Anonymous"] | ||
description = "Frame Pallet" | ||
version = "0.1.0" | ||
license = "Unlicense" | ||
edition = "2021" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
codec.workspace = true | ||
scale-info.workspace = true | ||
|
||
# Substrate | ||
frame-benchmarking.workspace = true | ||
frame-support.workspace = true | ||
frame-system.workspace = true | ||
pallet-assets.workspace = true | ||
sp-runtime.workspace = true | ||
|
||
[dev-dependencies] | ||
sp-core.workspace = true | ||
sp-io.workspace = true | ||
|
||
[features] | ||
default = ["std"] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking/runtime-benchmarks", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
"sp-runtime/runtime-benchmarks", | ||
] | ||
std = [ | ||
"codec/std", | ||
"frame-benchmarking/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"pallet-assets/std", | ||
"scale-info/std", | ||
"sp-core/std", | ||
"sp-io/std", | ||
"sp-runtime/std", | ||
] | ||
try-runtime = [ | ||
"frame-support/try-runtime", | ||
"frame-system/try-runtime", | ||
"sp-runtime/try-runtime", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//! Benchmarking setup for pallet-parachain-template | ||
// https://docs.substrate.io/test/benchmark/ | ||
|
||
use super::*; | ||
|
||
#[allow(unused)] | ||
use crate::Pallet as Template; | ||
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller}; | ||
use frame_system::RawOrigin; | ||
|
||
benchmarks! { | ||
do_something { | ||
let s in 0 .. 100; | ||
let caller: T::AccountId = whitelisted_caller(); | ||
}: _(RawOrigin::Signed(caller), s) | ||
verify { | ||
assert_eq!(Something::<T>::get(), Some(s)); | ||
Check failure on line 18 in pallets/fungibles/src/benchmarking.rs GitHub Actions / clippyfailed to resolve: use of undeclared type `Something`
|
||
} | ||
} | ||
|
||
impl_benchmark_test_suite!(Template, crate::mock::new_test_ext(), crate::mock::Test,); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
pub use pallet::*; | ||
|
||
#[cfg(test)] | ||
mod mock; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
#[cfg(feature = "runtime-benchmarks")] | ||
mod benchmarking; | ||
|
||
#[frame_support::pallet] | ||
pub mod pallet { | ||
use frame_support::{pallet_prelude::*, traits::fungibles::Inspect}; | ||
use frame_system::pallet_prelude::*; | ||
use sp_runtime::traits::StaticLookup; | ||
|
||
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source; | ||
type AssetIdOf<T> = <pallet_assets::Pallet<T, TrustBackedAssetsInstance> as Inspect< | ||
<T as frame_system::Config>::AccountId, | ||
>>::AssetId; | ||
type AssetIdParameterOf<T> = | ||
<T as pallet_assets::Config<TrustBackedAssetsInstance>>::AssetIdParameter; | ||
type BalanceOf<T> = <pallet_assets::Pallet<T, TrustBackedAssetsInstance> as Inspect< | ||
<T as frame_system::Config>::AccountId, | ||
>>::Balance; | ||
// Should be defined in primitives. | ||
type TrustBackedAssetsInstance = pallet_assets::Instance1; | ||
|
||
#[pallet::config] | ||
pub trait Config: | ||
frame_system::Config + pallet_assets::Config<TrustBackedAssetsInstance> | ||
{ | ||
} | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T>(_); | ||
|
||
use pallet_assets::WeightInfo; | ||
|
||
#[pallet::call] | ||
impl<T: Config> Pallet<T> { | ||
#[pallet::call_index(0)] | ||
#[pallet::weight(<T as pallet_assets::Config<TrustBackedAssetsInstance>>::WeightInfo::transfer_keep_alive())] | ||
pub fn transfer( | ||
origin: OriginFor<T>, | ||
id: AssetIdParameterOf<T>, | ||
target: AccountIdLookupOf<T>, | ||
amount: BalanceOf<T>, | ||
) -> DispatchResult { | ||
pallet_assets::Pallet::<T, TrustBackedAssetsInstance>::transfer_keep_alive( | ||
origin, id, target, amount, | ||
) | ||
} | ||
} | ||
|
||
impl<T: Config> Pallet<T> { | ||
pub fn total_supply(id: AssetIdOf<T>) -> BalanceOf<T> { | ||
pallet_assets::Pallet::<T, TrustBackedAssetsInstance>::total_supply(id) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use frame_support::{parameter_types, traits::Everything}; | ||
use frame_system as system; | ||
use sp_core::H256; | ||
use sp_runtime::{ | ||
traits::{BlakeTwo256, IdentityLookup}, | ||
BuildStorage, | ||
}; | ||
|
||
type Block = frame_system::mocking::MockBlock<Test>; | ||
|
||
// Configure a mock runtime to test the pallet. | ||
frame_support::construct_runtime!( | ||
pub enum Test | ||
{ | ||
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>}, | ||
fungibles: crate::{Pallet, Call, Storage, Event<T>}, | ||
} | ||
); | ||
|
||
parameter_types! { | ||
pub const BlockHashCount: u64 = 250; | ||
pub const SS58Prefix: u8 = 42; | ||
} | ||
|
||
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] | ||
impl system::Config for Test { | ||
type BaseCallFilter = Everything; | ||
type BlockWeights = (); | ||
type BlockLength = (); | ||
type DbWeight = (); | ||
type RuntimeOrigin = RuntimeOrigin; | ||
type RuntimeCall = RuntimeCall; | ||
type Nonce = u64; | ||
type Hash = H256; | ||
type Hashing = BlakeTwo256; | ||
type AccountId = u64; | ||
type Lookup = IdentityLookup<Self::AccountId>; | ||
type Block = Block; | ||
type RuntimeEvent = RuntimeEvent; | ||
type BlockHashCount = BlockHashCount; | ||
type Version = (); | ||
type PalletInfo = PalletInfo; | ||
type AccountData = (); | ||
type OnNewAccount = (); | ||
type OnKilledAccount = (); | ||
type SystemWeightInfo = (); | ||
type SS58Prefix = SS58Prefix; | ||
type OnSetCode = (); | ||
type MaxConsumers = frame_support::traits::ConstU32<16>; | ||
} | ||
|
||
impl crate::Config for Test { | ||
type RuntimeEvent = RuntimeEvent; | ||
type WeightInfo = (); | ||
} | ||
|
||
// Build genesis storage according to the mock runtime. | ||
pub fn new_test_ext() -> sp_io::TestExternalities { | ||
system::GenesisConfig::<Test>::default().build_storage().unwrap().into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use crate::{mock::*, Error}; | ||
use frame_support::{assert_noop, assert_ok}; | ||
|
||
// https://docs.substrate.io/test/ | ||
|
||
#[test] | ||
fn it_works_for_default_value() { | ||
new_test_ext().execute_with(|| { | ||
// Dispatch a signed extrinsic. | ||
assert_ok!(fungibles::do_something(RuntimeOrigin::signed(1), 42)); | ||
// Read pallet storage and assert an expected result. | ||
assert_eq!(fungibles::something(), Some(42)); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn correct_error_for_none_value() { | ||
new_test_ext().execute_with(|| { | ||
// Ensure the expected error is thrown when no value is present. | ||
assert_noop!(fungibles::cause_error(RuntimeOrigin::signed(1)), Error::<Test>::NoneValue); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters