diff --git a/Cargo.lock b/Cargo.lock index b68586c..233c227 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4168,6 +4168,7 @@ dependencies = [ "frame", "frame-support", "frame-system", + "pallet-assets", "pallet-balances", "pallet-minimal-template", "pallet-sudo", @@ -4180,6 +4181,7 @@ dependencies = [ "sp-genesis-builder", "sp-io", "sp-runtime", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.9.0)", "substrate-wasm-builder", ] @@ -4620,6 +4622,22 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" +[[package]] +name = "pallet-assets" +version = "29.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.9.0#3c3d6fceb82372a3019b37117aa453d564b212de" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-runtime", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.9.0)", +] + [[package]] name = "pallet-balances" version = "28.0.0" @@ -4717,7 +4735,7 @@ checksum = "4e69bf016dc406eff7d53a7d3f7cf1c2e72c82b9088aac1118591e36dd2cd3e9" dependencies = [ "bitcoin_hashes", "rand", - "rand_core 0.5.1", + "rand_core 0.6.4", "serde", "unicode-normalization", ] @@ -7596,7 +7614,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/paritytech/polkadot-sdk#0711729d251efebf3486db602119ecfa67d98366" +source = "git+https://github.com/paritytech/polkadot-sdk#d6f68bb9062167537211cc05286809771fc8861a" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -7658,7 +7676,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#0711729d251efebf3486db602119ecfa67d98366" +source = "git+https://github.com/paritytech/polkadot-sdk#d6f68bb9062167537211cc05286809771fc8861a" dependencies = [ "proc-macro2", "quote", @@ -7679,7 +7697,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/paritytech/polkadot-sdk#0711729d251efebf3486db602119ecfa67d98366" +source = "git+https://github.com/paritytech/polkadot-sdk#d6f68bb9062167537211cc05286809771fc8861a" dependencies = [ "environmental", "parity-scale-codec", @@ -7866,7 +7884,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#0711729d251efebf3486db602119ecfa67d98366" +source = "git+https://github.com/paritytech/polkadot-sdk#d6f68bb9062167537211cc05286809771fc8861a" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -7898,7 +7916,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#0711729d251efebf3486db602119ecfa67d98366" +source = "git+https://github.com/paritytech/polkadot-sdk#d6f68bb9062167537211cc05286809771fc8861a" dependencies = [ "Inflector", "expander", @@ -7991,7 +8009,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#0711729d251efebf3486db602119ecfa67d98366" +source = "git+https://github.com/paritytech/polkadot-sdk#d6f68bb9062167537211cc05286809771fc8861a" [[package]] name = "sp-storage" @@ -8009,7 +8027,7 @@ dependencies = [ [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#0711729d251efebf3486db602119ecfa67d98366" +source = "git+https://github.com/paritytech/polkadot-sdk#d6f68bb9062167537211cc05286809771fc8861a" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8046,7 +8064,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#0711729d251efebf3486db602119ecfa67d98366" +source = "git+https://github.com/paritytech/polkadot-sdk#d6f68bb9062167537211cc05286809771fc8861a" dependencies = [ "parity-scale-codec", "tracing", @@ -8146,7 +8164,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#0711729d251efebf3486db602119ecfa67d98366" +source = "git+https://github.com/paritytech/polkadot-sdk#d6f68bb9062167537211cc05286809771fc8861a" dependencies = [ "anyhow", "impl-trait-for-tuples", diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 1973b5a..f95e405 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -28,6 +28,7 @@ frame-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "r sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" , default-features = false } sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" , default-features = false } sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false } +sp-std = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false } # pallets that we want to use pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" , default-features = false } @@ -35,6 +36,7 @@ pallet-sudo = { git = "https://github.com/paritytech/polkadot-sdk", branch = "re pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false } pallet-transaction-payment = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false } pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false } +pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false } # genesis builder that allows us to interacto with runtime genesis config sp-genesis-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false } @@ -59,12 +61,14 @@ std = [ "sp-core/std", "sp-runtime/std", + "sp-io/std", "pallet-balances/std", "pallet-sudo/std", "pallet-timestamp/std", "pallet-transaction-payment-rpc-runtime-api/std", "pallet-transaction-payment/std", + "pallet-assets/std", "pallet-minimal-template/std", diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index d612275..b38540d 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -37,7 +37,8 @@ use frame::{ }, }; -use frame_support::weights::{constants::WEIGHT_REF_TIME_PER_MILLIS, IdentityFee, Weight}; +use frame_support::weights::{constants::WEIGHT_REF_TIME_PER_MILLIS, Weight}; +use frame_support::traits::AsEnsureOriginWithArg; // Substrate FRAME #[cfg(feature = "with-paritydb-weights")] @@ -45,7 +46,7 @@ use frame_support::weights::constants::ParityDbWeight as RuntimeDbWeight; #[cfg(feature = "with-rocksdb-weights")] use frame_support::weights::constants::RocksDbWeight as RuntimeDbWeight; -use sp_runtime::{generic, traits::BlakeTwo256, Perbill}; +use sp_runtime::{generic, traits::BlakeTwo256, Perbill, AccountId32}; /// Type of block number. pub type BlockNumber = u32; @@ -100,6 +101,7 @@ construct_runtime!( Balances: pallet_balances, Sudo: pallet_sudo, TransactionPayment: pallet_transaction_payment, + Assets: pallet_assets, // our local pallet Template: pallet_minimal_template, @@ -122,6 +124,8 @@ parameter_types! { pub const SS58Prefix: u8 = 42; } +type AccountId = AccountId32; + impl frame_system::Config for Runtime { /// The default type for storing how many extrinsics an account has signed. type Nonce = u32; @@ -135,7 +139,7 @@ impl frame_system::Config for Runtime { type Hashing = sp_runtime::traits::BlakeTwo256; /// The default identifier used to distinguish between accounts. - type AccountId = sp_runtime::AccountId32; + type AccountId = AccountId; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = sp_runtime::traits::AccountIdLookup; @@ -201,6 +205,16 @@ impl frame_system::Config for Runtime { type PostTransactions = (); } + +#[derive_impl(pallet_assets::config_preludes::TestDefaultConfig)] +impl pallet_assets::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type CreateOrigin = AsEnsureOriginWithArg>; + type ForceOrigin = frame_system::EnsureRoot; + type Freezer = (); +} + #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)] impl pallet_balances::Config for Runtime { type AccountStore = System; @@ -349,7 +363,6 @@ impl_runtime_apis! { // https://github.com/paritytech/substrate/issues/10579#issuecomment-1600537558 pub mod interface { use super::Runtime; - use frame::deps::frame_system; pub type Block = super::Block; pub use frame::runtime::types_common::OpaqueBlock; @@ -362,7 +375,8 @@ pub mod interface { #[cfg(test)] mod tests { - use super::{interface, Balances, Runtime, RuntimeOrigin, System}; + use super::{interface, Balances, Runtime, RuntimeOrigin, System, Assets}; + use frame_support::assert_ok; use sp_io; use sp_runtime::BuildStorage; @@ -420,4 +434,25 @@ mod tests { assert_eq!(Balances::usable_balance(BOB.clone()), 1010); }) } + + #[test] + fn test_assets() { + let ALICE: AccountId32 = get_account_id(&"Alice"); + let BOB: AccountId32 = get_account_id(&"Bob"); + let asset1 = 0; + new_test_ext().execute_with(|| { + assert_ok!(Assets::create(RuntimeOrigin::signed(ALICE.clone()), asset1, Id(ALICE.clone()), 1)); + assert_eq!(Assets::total_supply(asset1), 0); + + assert_ok!(Assets::mint(RuntimeOrigin::signed(ALICE.clone()), asset1, Id(ALICE.clone()), 10000)); + assert_eq!(Assets::total_supply(asset1), 10000); + assert_eq!(Assets::balance(asset1, ALICE.clone()), 10000); + + assert_eq!(Assets::balance(asset1, BOB.clone()), 0); + assert_ok!(Assets::transfer(RuntimeOrigin::signed(ALICE.clone()), asset1, Id(BOB.clone()), 1000)); + assert_eq!(Assets::balance(asset1, BOB.clone()), 1000); + assert_eq!(Assets::balance(asset1, ALICE.clone()), 9000); + + }) + } }