difftreelog
refactor reorganize imports
in: master
119 files changed
.rustfmt.tomldiffbeforeafterboth--- a/.rustfmt.toml
+++ b/.rustfmt.toml
@@ -1,2 +1,3 @@
+group_imports = "stdexternalcrate"
hard_tabs = true
-reorder_imports = false
+imports_granularity = "crate"
client/rpc/src/lib.rsdiffbeforeafterboth--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -17,23 +17,19 @@
// Original License
use std::sync::Arc;
-use codec::Decode;
-use jsonrpsee::{
- core::{RpcResult as Result},
- proc_macros::rpc,
-};
use anyhow::anyhow;
+use app_promotion_rpc::AppPromotionApi as AppPromotionRuntimeApi;
+pub use app_promotion_unique_rpc::AppPromotionApiServer;
+use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc};
+use parity_scale_codec::Decode;
+use sp_api::{ApiExt, BlockT, ProvideRuntimeApi};
+use sp_blockchain::HeaderBackend;
use sp_runtime::traits::{AtLeast32BitUnsigned, Member};
use up_data_structs::{
- RpcCollection, CollectionId, CollectionStats, CollectionLimits, TokenId, Property,
- PropertyKeyPermission, TokenData, TokenChild,
+ CollectionId, CollectionLimits, CollectionStats, Property, PropertyKeyPermission,
+ RpcCollection, TokenChild, TokenData, TokenId,
};
-use sp_api::{BlockT, ProvideRuntimeApi, ApiExt};
-use sp_blockchain::HeaderBackend;
use up_rpc::UniqueApi as UniqueRuntimeApi;
-use app_promotion_rpc::AppPromotionApi as AppPromotionRuntimeApi;
-
-pub use app_promotion_unique_rpc::AppPromotionApiServer;
#[cfg(feature = "pov-estimate")]
pub mod pov_estimate;
@@ -549,16 +545,16 @@
keys.map(|keys| keys.into_iter().map(|key| key.into_bytes()).collect())
}
-fn decode_collection_from_bytes<T: codec::Decode>(
+fn decode_collection_from_bytes<T: parity_scale_codec::Decode>(
bytes: &[u8],
-) -> core::result::Result<T, codec::Error> {
- let mut reader = codec::IoReader(bytes);
+) -> core::result::Result<T, parity_scale_codec::Error> {
+ let mut reader = parity_scale_codec::IoReader(bytes);
T::decode(&mut reader)
}
fn detect_type_and_decode_collection<AccountId: Decode>(
bytes: &[u8],
-) -> core::result::Result<RpcCollection<AccountId>, codec::Error> {
+) -> core::result::Result<RpcCollection<AccountId>, parity_scale_codec::Error> {
use up_data_structs::{CollectionVersion1, RpcCollectionVersion1};
decode_collection_from_bytes::<RpcCollection<AccountId>>(bytes)
@@ -574,11 +570,12 @@
#[cfg(test)]
mod tests {
- use super::*;
- use codec::IoReader;
use hex_literal::hex;
+ use parity_scale_codec::IoReader;
use up_data_structs::{CollectionVersion1, RawEncoded};
+ use super::*;
+
const ENCODED_COLLECTION_V1: [u8; 180] = hex!("aab94a1ee784bc17f68d76d4d48d736916ca6ff6315b8c1fa1175726c8345a390000285000720069006d00610020004c00690076006500d04500730065006d00700069006f00200064006900200063007200650061007a0069006f006e006500200064006900200075006e00610020006e0075006f0076006100200063006f006c006c0065007a0069006f006e00650020006400690020004e004600540021000c464e5400000000000000000000000000000000");
const ENCODED_RPC_COLLECTION_V2: [u8; 618] = hex!("d00dcc24bf66750d3809aa26884b930ec8a3094d6f6f19fdc62020b2fbec013400604d0069006e007400460065007300740020002d002000460075006e006e007900200061006e0069006d0061006c0073008c430072006f00730073006f0076006500720020006200650074007700650065006e00200061006e0069006d0061006c00730020002d00200066006f0072002000660075006e00104d46464100000000000000000000010001000100000004385f6f6c645f636f6e7374446174610001000c5c5f6f6c645f636f6e73744f6e436861696e536368656d6139047b226e6573746564223a7b226f6e436861696e4d65746144617461223a7b226e6573746564223a7b224e46544d657461223a7b226669656c6473223a7b22697066734a736f6e223a7b226964223a312c2272756c65223a227265717569726564222c2274797065223a22737472696e67227d2c2248656164223a7b226964223a322c2272756c65223a227265717569726564222c2274797065223a22737472696e67227d2c22426f6479223a7b226964223a332c2272756c65223a227265717569726564222c2274797065223a22737472696e67227d2c225461696c223a7b226964223a342c2272756c65223a227265717569726564222c2274797065223a22737472696e67227d7d7d7d7d7d7d485f6f6c645f736368656d6156657273696f6e18556e69717565685f6f6c645f7661726961626c654f6e436861696e536368656d6111017b22636f6c6c656374696f6e436f766572223a22516d53557a7139354c357a556777795a584d3731576a3762786b36557048515468633162536965347766706e5435227d000000");
client/rpc/src/pov_estimate.rsdiffbeforeafterboth--- a/client/rpc/src/pov_estimate.rs
+++ b/client/rpc/src/pov_estimate.rs
@@ -16,39 +16,31 @@
use std::sync::Arc;
-use codec::{Encode, Decode};
-use sp_externalities::Extensions;
-
-use up_pov_estimate_rpc::{PovEstimateApi as PovEstimateRuntimeApi};
-use up_common::types::opaque::RuntimeId;
-
-use sc_service::{NativeExecutionDispatch, config::ExecutionStrategy};
-use sp_state_machine::{StateMachine, TrieBackendBuilder};
-use trie_db::{Trie, TrieDBBuilder};
-
+use anyhow::anyhow;
use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc};
-use anyhow::anyhow;
-
+use parity_scale_codec::{Decode, Encode};
use sc_client_api::backend::Backend;
+use sc_executor::NativeElseWasmExecutor;
+use sc_rpc_api::DenyUnsafe;
+use sc_service::{config::ExecutionStrategy, NativeExecutionDispatch};
+use sp_api::{AsTrieBackend, BlockId, BlockT, ProvideRuntimeApi};
use sp_blockchain::HeaderBackend;
use sp_core::{
- Bytes,
offchain::{
testing::{TestOffchainExt, TestTransactionPoolExt},
OffchainDbExt, OffchainWorkerExt, TransactionPoolExt,
},
testing::TaskExecutor,
traits::TaskExecutorExt,
+ Bytes,
};
+use sp_externalities::Extensions;
use sp_keystore::{testing::KeyStore, KeystoreExt};
-use sp_api::{AsTrieBackend, BlockId, BlockT, ProvideRuntimeApi};
-
-use sc_executor::NativeElseWasmExecutor;
-use sc_rpc_api::DenyUnsafe;
-
use sp_runtime::traits::Header;
-
-use up_pov_estimate_rpc::{PovInfo, TrieKeyValue};
+use sp_state_machine::{StateMachine, TrieBackendBuilder};
+use trie_db::{Trie, TrieDBBuilder};
+use up_common::types::opaque::RuntimeId;
+use up_pov_estimate_rpc::{PovEstimateApi as PovEstimateRuntimeApi, PovInfo, TrieKeyValue};
use crate::define_struct_for_server_api;
crates/struct-versioning/src/lib.rsdiffbeforeafterboth--- a/crates/struct-versioning/src/lib.rs
+++ b/crates/struct-versioning/src/lib.rs
@@ -17,13 +17,12 @@
#![doc = include_str!("../README.md")]
use proc_macro::TokenStream;
-use quote::format_ident;
+use quote::{format_ident, quote};
use syn::{
- parse::{Parse, ParseStream},
- Token, LitInt, parse_macro_input, ItemStruct, Error, Fields, Result, Field, Expr,
parenthesized,
+ parse::{Parse, ParseStream},
+ parse_macro_input, Error, Expr, Field, Fields, ItemStruct, LitInt, Result, Token,
};
-use quote::quote;
mod kw {
syn::custom_keyword!(version);
node/cli/src/chain_spec.rsdiffbeforeafterboth--- a/node/cli/src/chain_spec.rs
+++ b/node/cli/src/chain_spec.rs
@@ -14,36 +14,35 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+use std::collections::BTreeMap;
+
+#[cfg(all(not(feature = "unique-runtime"), not(feature = "quartz-runtime")))]
+pub use opal_runtime as default_runtime;
+#[cfg(all(not(feature = "unique-runtime"), feature = "quartz-runtime"))]
+pub use quartz_runtime as default_runtime;
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
+use serde::{Deserialize, Serialize};
+use serde_json::map::Map;
use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};
-use std::collections::BTreeMap;
-
-use serde::{Deserialize, Serialize};
-use serde_json::map::Map;
-
-use up_common::types::opaque::*;
-
#[cfg(feature = "unique-runtime")]
pub use unique_runtime as default_runtime;
-
-#[cfg(all(not(feature = "unique-runtime"), feature = "quartz-runtime"))]
-pub use quartz_runtime as default_runtime;
-
-#[cfg(all(not(feature = "unique-runtime"), not(feature = "quartz-runtime")))]
-pub use opal_runtime as default_runtime;
+use up_common::types::opaque::*;
/// The `ChainSpec` parameterized for the unique runtime.
#[cfg(feature = "unique-runtime")]
-pub type UniqueChainSpec = sc_service::GenericChainSpec<unique_runtime::GenesisConfig, Extensions>;
+pub type UniqueChainSpec =
+ sc_service::GenericChainSpec<unique_runtime::RuntimeGenesisConfig, Extensions>;
/// The `ChainSpec` parameterized for the quartz runtime.
#[cfg(feature = "quartz-runtime")]
-pub type QuartzChainSpec = sc_service::GenericChainSpec<quartz_runtime::GenesisConfig, Extensions>;
+pub type QuartzChainSpec =
+ sc_service::GenericChainSpec<quartz_runtime::RuntimeGenesisConfig, Extensions>;
/// The `ChainSpec` parameterized for the opal runtime.
-pub type OpalChainSpec = sc_service::GenericChainSpec<opal_runtime::GenesisConfig, Extensions>;
+pub type OpalChainSpec =
+ sc_service::GenericChainSpec<opal_runtime::RuntimeGenesisConfig, Extensions>;
#[cfg(feature = "unique-runtime")]
pub type DefaultChainSpec = UniqueChainSpec;
node/cli/src/cli.rsdiffbeforeafterboth--- a/node/cli/src/cli.rs
+++ b/node/cli/src/cli.rs
@@ -14,10 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use crate::chain_spec;
use std::path::PathBuf;
+
use clap::Parser;
+use crate::chain_spec;
+
/// Sub-commands supported by the collator.
#[derive(Debug, Parser)]
pub enum Subcommand {
node/cli/src/command.rsdiffbeforeafterboth--- a/node/cli/src/command.rs
+++ b/node/cli/src/command.rs
@@ -32,28 +32,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-use crate::{
- chain_spec::{self, RuntimeIdentification, ServiceId, ServiceIdentification},
- cli::{Cli, RelayChainCli, Subcommand},
- service::{new_partial, start_node, start_dev_node},
-};
-#[cfg(feature = "runtime-benchmarks")]
-use crate::chain_spec::default_runtime;
-
-#[cfg(feature = "unique-runtime")]
-use crate::service::UniqueRuntimeExecutor;
-
-#[cfg(feature = "quartz-runtime")]
-use crate::service::QuartzRuntimeExecutor;
-
-use crate::service::OpalRuntimeExecutor;
-
-#[cfg(feature = "runtime-benchmarks")]
-use crate::service::DefaultRuntimeExecutor;
+use std::time::Duration;
use codec::Encode;
-use cumulus_primitives_core::ParaId;
use cumulus_client_cli::generate_genesis_block;
+use cumulus_primitives_core::ParaId;
use log::{debug, info};
use sc_cli::{
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,
@@ -62,8 +45,21 @@
use sc_service::config::{BasePath, PrometheusConfig};
use sp_core::hexdisplay::HexDisplay;
use sp_runtime::traits::{AccountIdConversion, Block as BlockT};
+use up_common::types::opaque::{Block, RuntimeId};
-use up_common::types::opaque::{Block, RuntimeId};
+#[cfg(feature = "runtime-benchmarks")]
+use crate::chain_spec::default_runtime;
+#[cfg(feature = "runtime-benchmarks")]
+use crate::service::DefaultRuntimeExecutor;
+#[cfg(feature = "quartz-runtime")]
+use crate::service::QuartzRuntimeExecutor;
+#[cfg(feature = "unique-runtime")]
+use crate::service::UniqueRuntimeExecutor;
+use crate::{
+ chain_spec::{self, RuntimeIdentification, ServiceId, ServiceIdentification},
+ cli::{Cli, RelayChainCli, Subcommand},
+ service::{new_partial, start_dev_node, start_node, OpalRuntimeExecutor},
+};
macro_rules! no_runtime_err {
($runtime_id:expr) => {
node/cli/src/lib.rsdiffbeforeafterboth--- a/node/cli/src/lib.rs
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-pub mod chain_spec;
-pub mod service;
node/cli/src/main.rsdiffbeforeafterboth--- a/node/cli/src/main.rs
+++ b/node/cli/src/main.rs
@@ -19,6 +19,7 @@
mod service;
mod cli;
mod command;
+mod rpc;
fn main() -> sc_cli::Result<()> {
command::run()
node/cli/src/service.rsdiffbeforeafterboth--- a/node/cli/src/service.rs
+++ b/node/cli/src/service.rs
@@ -15,73 +15,72 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
// std
-use std::sync::Arc;
-use std::sync::Mutex;
-use std::collections::BTreeMap;
-use std::time::Duration;
-use std::pin::Pin;
-use fc_mapping_sync::EthereumBlockNotificationSinks;
-use fc_rpc::EthBlockDataCacheTask;
-use fc_rpc::EthTask;
-use fc_rpc_core::types::FeeHistoryCache;
-use futures::{
- Stream, StreamExt,
- stream::select,
- task::{Context, Poll},
+use std::{
+ collections::BTreeMap,
+ marker::PhantomData,
+ pin::Pin,
+ sync::{Arc, Mutex},
+ time::Duration,
};
-use sc_rpc::SubscriptionTaskExecutor;
-use sp_keystore::KeystorePtr;
-use tokio::time::Interval;
-use jsonrpsee::RpcModule;
-
-use serde::{Serialize, Deserialize};
-// Cumulus Imports
-use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion};
-use cumulus_client_consensus_common::{
- ParachainConsensus, ParachainBlockImport as TParachainBlockImport,
+use cumulus_client_cli::CollatorOptions;
+use cumulus_client_collator::service::CollatorService;
+#[cfg(not(feature = "lookahead"))]
+use cumulus_client_consensus_aura::collators::basic::{
+ run as run_aura, Params as BuildAuraConsensusParams,
};
+#[cfg(feature = "lookahead")]
+use cumulus_client_consensus_aura::collators::lookahead::{
+ run as run_aura, Params as BuildAuraConsensusParams,
+};
+use cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImport;
+use cumulus_client_consensus_proposer::Proposer;
+use cumulus_client_network::RequireSecondedInBlockAnnounce;
use cumulus_client_service::{
- prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,
+ build_relay_chain_interface, prepare_node_config, start_relay_chain_tasks, DARecoveryProfile,
+ StartRelayChainTasksParams,
};
-use cumulus_client_cli::CollatorOptions;
-use cumulus_client_network::BlockAnnounceValidator;
use cumulus_primitives_core::ParaId;
-use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain;
-use cumulus_relay_chain_interface::{RelayChainInterface, RelayChainResult};
-use cumulus_relay_chain_minimal_node::build_minimal_relay_chain_node;
-
-// Substrate Imports
-use sp_api::{BlockT, HeaderT, ProvideRuntimeApi, StateBackend};
-use sc_executor::NativeElseWasmExecutor;
-use sc_executor::NativeExecutionDispatch;
+use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface};
+use fc_mapping_sync::{kv::MappingSyncWorker, EthereumBlockNotificationSinks, SyncStrategy};
+use fc_rpc::{
+ frontier_backend_client::SystemAccountId32StorageOverride, EthBlockDataCacheTask, EthConfig,
+ EthTask, OverrideHandle, RuntimeApiStorageOverride, SchemaV1Override, SchemaV2Override,
+ SchemaV3Override, StorageOverride,
+};
+use fc_rpc_core::types::{FeeHistoryCache, FilterPool};
+use fp_rpc::EthereumRuntimeRPCApi;
+use fp_storage::EthereumStorageSchema;
+use futures::{
+ stream::select,
+ task::{Context, Poll},
+ Stream, StreamExt,
+};
+use jsonrpsee::RpcModule;
+use polkadot_service::CollatorPair;
+use sc_client_api::{AuxStore, Backend, BlockOf, BlockchainEvents, StorageProvider};
+use sc_consensus::ImportQueue;
+use sc_executor::{NativeElseWasmExecutor, NativeExecutionDispatch};
use sc_network::NetworkBlock;
use sc_network_sync::SyncingService;
+use sc_rpc::SubscriptionTaskExecutor;
use sc_service::{Configuration, PartialComponents, TaskManager};
use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};
+use serde::{Deserialize, Serialize};
+use sp_api::{ProvideRuntimeApi, StateBackend};
+use sp_block_builder::BlockBuilder;
+use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
+use sp_consensus_aura::sr25519::AuthorityPair as AuraAuthorityPair;
+use sp_keystore::KeystorePtr;
use sp_runtime::traits::BlakeTwo256;
use substrate_prometheus_endpoint::Registry;
-use sc_client_api::{BlockchainEvents, BlockOf, Backend, AuxStore, StorageProvider};
-use sp_blockchain::{HeaderBackend, HeaderMetadata, Error as BlockChainError};
-use sc_consensus::ImportQueue;
-use sp_core::H256;
-use sp_block_builder::BlockBuilder;
+use tokio::time::Interval;
+use up_common::types::{opaque::*, Nonce};
-use polkadot_service::CollatorPair;
-
-// Frontier Imports
-use fc_rpc_core::types::FilterPool;
-use fc_mapping_sync::{kv::MappingSyncWorker, SyncStrategy};
-use fc_rpc::{
- StorageOverride, OverrideHandle, SchemaV1Override, SchemaV2Override, SchemaV3Override,
- RuntimeApiStorageOverride,
+use crate::{
+ chain_spec::RuntimeIdentification,
+ rpc::{create_eth, create_full, EthDeps, FullDeps},
};
-use fp_rpc::EthereumRuntimeRPCApi;
-use fp_storage::EthereumStorageSchema;
-
-use up_common::types::opaque::*;
-
-use crate::chain_spec::RuntimeIdentification;
/// Unique native executor instance.
#[cfg(feature = "unique-runtime")]
pallets/app-promotion/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/app-promotion/src/benchmarking.rs
+++ b/pallets/app-promotion/src/benchmarking.rs
@@ -16,16 +16,15 @@
#![cfg(feature = "runtime-benchmarks")]
-use super::*;
-use crate::Pallet as PromototionPallet;
-use frame_support::traits::fungible::Unbalanced;
-use sp_runtime::traits::Bounded;
-
-use frame_benchmarking::{benchmarks, account};
-use frame_support::traits::OnInitialize;
+use frame_benchmarking::{account, benchmarks};
+use frame_support::traits::{fungible::Unbalanced, OnInitialize};
use frame_system::RawOrigin;
+use pallet_evm_migration::Pallet as EvmMigrationPallet;
use pallet_unique::benchmarking::create_nft_collection;
-use pallet_evm_migration::Pallet as EvmMigrationPallet;
+use sp_runtime::traits::Bounded;
+
+use super::*;
+use crate::Pallet as PromototionPallet;
const SEED: u32 = 0;
pallets/app-promotion/src/lib.rsdiffbeforeafterboth--- a/pallets/app-promotion/src/lib.rs
+++ b/pallets/app-promotion/src/lib.rs
@@ -53,32 +53,32 @@
pub mod types;
pub mod weights;
-use sp_std::{vec::Vec, vec, iter::Sum, borrow::ToOwned, cell::RefCell};
-use sp_core::H160;
-use codec::EncodeLike;
-pub use types::*;
-
-use up_data_structs::CollectionId;
-
use frame_support::{
- dispatch::{DispatchResult},
+ dispatch::DispatchResult,
+ ensure,
+ pallet_prelude::*,
+ storage::Key,
traits::{
- Get,
+ fungible::{Inspect, InspectFreeze, Mutate, MutateFreeze},
tokens::Balance,
- fungible::{Inspect, InspectFreeze, Mutate, MutateFreeze},
+ Get,
},
- ensure, BoundedVec,
+ weights::Weight,
+ Blake2_128Concat, BoundedVec, PalletId, Twox64Concat,
};
-
-use weights::WeightInfo;
-
+use frame_system::pallet_prelude::*;
pub use pallet::*;
use pallet_evm::account::CrossAccountId;
+use parity_scale_codec::EncodeLike;
+use sp_core::H160;
use sp_runtime::{
- Perbill,
- traits::{BlockNumberProvider, CheckedAdd, CheckedSub, AccountIdConversion, Zero},
- ArithmeticError, DispatchError,
+ traits::{AccountIdConversion, BlockNumberProvider, CheckedAdd, CheckedSub, Zero},
+ ArithmeticError, DispatchError, Perbill,
};
+use sp_std::{borrow::ToOwned, cell::RefCell, iter::Sum, vec, vec::Vec};
+pub use types::*;
+use up_data_structs::CollectionId;
+use weights::WeightInfo;
const PENDING_LIMIT_PER_BLOCK: u32 = 3;
@@ -87,12 +87,8 @@
#[frame_support::pallet]
pub mod pallet {
+
use super::*;
- use frame_support::{
- Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key, PalletId, weights::Weight,
- };
- use frame_system::pallet_prelude::*;
- use sp_runtime::DispatchError;
#[pallet::config]
pub trait Config:
pallets/app-promotion/src/types.rsdiffbeforeafterboth--- a/pallets/app-promotion/src/types.rs
+++ b/pallets/app-promotion/src/types.rs
@@ -1,13 +1,12 @@
-use frame_support::{dispatch::DispatchResult};
-
+use frame_support::dispatch::DispatchResult;
+use frame_system::pallet_prelude::*;
use pallet_common::CollectionHandle;
-
+use pallet_configuration::AppPromomotionConfigurationOverride;
+use pallet_evm_contract_helpers::{Config as EvmHelpersConfig, Pallet as EvmHelpersPallet};
+use sp_core::Get;
use sp_runtime::{DispatchError, Perbill};
-use up_data_structs::{CollectionId};
use sp_std::borrow::ToOwned;
-use pallet_evm_contract_helpers::{Pallet as EvmHelpersPallet, Config as EvmHelpersConfig};
-use pallet_configuration::{AppPromomotionConfigurationOverride};
-use sp_core::Get;
+use up_data_structs::CollectionId;
const MAX_NUMBER_PAYOUTS: u8 = 100;
pub(crate) const DEFAULT_NUMBER_PAYOUTS: u8 = 20;
pallets/balances-adapter/src/common.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/common.rs
+++ b/pallets/balances-adapter/src/common.rs
@@ -1,11 +1,13 @@
use alloc::{vec, vec::Vec};
use core::marker::PhantomData;
-use crate::{Config, NativeFungibleHandle, Pallet};
+
use frame_support::{fail, weights::Weight};
use pallet_balances::{weights::SubstrateWeight as BalancesWeight, WeightInfo};
use pallet_common::{CommonCollectionOperations, CommonWeightInfo};
use up_data_structs::TokenId;
+use crate::{Config, NativeFungibleHandle, Pallet};
+
pub struct CommonWeights<T: Config>(PhantomData<T>);
// All implementations with `Weight::default` used in methods that return error `UnsupportedOperation`.
pallets/balances-adapter/src/erc.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/erc.rs
+++ b/pallets/balances-adapter/src/erc.rs
@@ -1,4 +1,3 @@
-use crate::{Config, NativeFungibleHandle, Pallet, SelfWeightOf};
use evm_coder::{abi::AbiType, generate_stubgen, solidity_interface, types::*};
use pallet_balances::WeightInfo;
use pallet_common::{
@@ -10,8 +9,10 @@
execution::{PreDispatch, Result},
frontier_contract, WithRecorder,
};
-use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};
-use sp_core::{U256, Get};
+use pallet_structure::{weights::WeightInfo as _, SelfWeightOf as StructureWeight};
+use sp_core::{Get, U256};
+
+use crate::{Config, NativeFungibleHandle, Pallet, SelfWeightOf};
frontier_contract! {
macro_rules! NativeFungibleHandle_result {...}
pallets/balances-adapter/src/lib.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/lib.rs
+++ b/pallets/balances-adapter/src/lib.rs
@@ -4,8 +4,8 @@
use core::ops::Deref;
use frame_support::sp_runtime::DispatchResult;
-use pallet_evm_coder_substrate::{WithRecorder, SubstrateRecorder};
pub use pallet::*;
+use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
pub mod common;
pub mod erc;
@@ -55,16 +55,16 @@
}
#[frame_support::pallet]
pub mod pallet {
- use super::*;
use alloc::string::String;
+
use frame_support::{
dispatch::PostDispatchInfo,
ensure,
- pallet_prelude::{DispatchResultWithPostInfo, Pays},
+ pallet_prelude::*,
traits::{
- Get,
fungible::{Inspect, Mutate},
tokens::Preservation,
+ Get,
},
};
use pallet_balances::WeightInfo;
@@ -74,6 +74,8 @@
use sp_runtime::DispatchError;
use up_data_structs::{budget::Budget, mapping::TokenAddressMapping};
+ use super::*;
+
#[pallet::config]
pub trait Config:
frame_system::Config
pallets/collator-selection/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/collator-selection/src/benchmarking.rs
+++ b/pallets/collator-selection/src/benchmarking.rs
@@ -32,18 +32,13 @@
//! Benchmarking setup for pallet-collator-selection
-use super::*;
-
-#[allow(unused)]
-use crate::{Pallet as CollatorSelection, BalanceOf};
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_support::{
assert_ok,
- codec::Decode,
+ parity_scale_codec::Decode,
traits::{
- EnsureOrigin,
fungible::{Inspect, Mutate},
- Get,
+ EnsureOrigin, Get,
},
};
use frame_system::{EventRecord, RawOrigin};
pallets/collator-selection/src/lib.rsdiffbeforeafterboth--- a/pallets/collator-selection/src/lib.rs
+++ b/pallets/collator-selection/src/lib.rs
@@ -96,26 +96,27 @@
<<T as Config>::Currency as Inspect<<T as frame_system::Config>::AccountId>>::Balance;
#[frame_support::pallet]
pub mod pallet {
- use super::*;
- pub use crate::weights::WeightInfo;
use core::ops::Div;
+
use frame_support::{
dispatch::{DispatchClass, DispatchResultWithPostInfo},
- inherent::Vec,
pallet_prelude::*,
sp_runtime::traits::{AccountIdConversion, CheckedSub, Saturating, Zero},
traits::{
- EnsureOrigin,
- fungible::{Balanced, BalancedHold, Inspect, InspectHold, Mutate, MutateHold},
- ValidatorRegistration,
+ fungible::{Balanced, BalancedHold, Inspect, Mutate, MutateHold},
tokens::{Precision, Preservation},
+ EnsureOrigin, ValidatorRegistration,
},
BoundedVec, PalletId,
};
use frame_system::pallet_prelude::*;
use pallet_session::SessionManager;
- use sp_runtime::{Perbill, traits::Convert};
+ use sp_runtime::{traits::Convert, Perbill};
use sp_staking::SessionIndex;
+ use sp_std::vec::Vec;
+
+ use super::*;
+ pub use crate::weights::WeightInfo;
/// A convertor from collators id. Since this pallet does not have stash/controller, this is
/// just identity.
pallets/collator-selection/src/mock.rsdiffbeforeafterboth--- a/pallets/collator-selection/src/mock.rs
+++ b/pallets/collator-selection/src/mock.rs
@@ -30,8 +30,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-use super::*;
-use crate as collator_selection;
use frame_support::{
ord_parameter_types, parameter_types,
traits::{FindAuthor, GenesisBuild, ValidatorRegistration},
@@ -46,6 +44,9 @@
Perbill, RuntimeAppPublic,
};
+use super::*;
+use crate as collator_selection;
+
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
pallets/collator-selection/src/tests.rsdiffbeforeafterboth--- a/pallets/collator-selection/src/tests.rs
+++ b/pallets/collator-selection/src/tests.rs
@@ -30,15 +30,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-use crate::{self as collator_selection, Config};
-use crate::{mock::*, Error};
use frame_support::{
assert_noop, assert_ok,
traits::{fungible, GenesisBuild, OnInitialize},
};
+use scale_info::prelude::*;
use sp_runtime::{traits::BadOrigin, TokenError};
-use scale_info::prelude::*;
+use crate::{self as collator_selection, mock::*, Config, Error};
+
fn get_license_and_onboard(account_id: <Test as frame_system::Config>::AccountId) {
assert_ok!(CollatorSelection::get_license(RuntimeOrigin::signed(
account_id
pallets/common/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/common/src/benchmarking.rs
+++ b/pallets/common/src/benchmarking.rs
@@ -16,23 +16,25 @@
#![allow(missing_docs)]
-use sp_std::vec::Vec;
-use crate::{Config, CollectionHandle, Pallet};
-use pallet_evm::account::CrossAccountId;
-use frame_benchmarking::{benchmarks, account};
-use up_data_structs::{
- CollectionMode, CreateCollectionData, CollectionId, Property, PropertyKey, PropertyValue,
- CollectionPermissions, NestingPermissions, AccessMode, PropertiesPermissionMap,
- MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
- MAX_PROPERTIES_PER_ITEM,
-};
+use core::convert::TryInto;
+
+use frame_benchmarking::{account, benchmarks};
use frame_support::{
- traits::{Get, fungible::Balanced, Imbalance, tokens::Precision},
pallet_prelude::ConstU32,
+ traits::{fungible::Balanced, tokens::Precision, Get, Imbalance},
BoundedVec,
};
-use core::convert::TryInto;
-use sp_runtime::{DispatchError, traits::Zero};
+use pallet_evm::account::CrossAccountId;
+use sp_runtime::{traits::Zero, DispatchError};
+use sp_std::vec::Vec;
+use up_data_structs::{
+ AccessMode, CollectionId, CollectionMode, CollectionPermissions, CreateCollectionData,
+ NestingPermissions, PropertiesPermissionMap, Property, PropertyKey, PropertyValue,
+ MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_COLLECTION_NAME_LENGTH, MAX_PROPERTIES_PER_ITEM,
+ MAX_TOKEN_PREFIX_LENGTH,
+};
+
+use crate::{CollectionHandle, Config, Pallet};
const SEED: u32 = 1;
pallets/common/src/dispatch.rsdiffbeforeafterboth--- a/pallets/common/src/dispatch.rs
+++ b/pallets/common/src/dispatch.rs
@@ -2,13 +2,13 @@
use frame_support::{
dispatch::{
- DispatchResultWithPostInfo, PostDispatchInfo, Weight, DispatchErrorWithPostInfo,
- DispatchResult,
+ DispatchErrorWithPostInfo, DispatchResult, DispatchResultWithPostInfo, Pays,
+ PostDispatchInfo,
},
- dispatch::Pays,
traits::Get,
};
use sp_runtime::DispatchError;
+use sp_weights::Weight;
use up_data_structs::{CollectionId, CreateCollectionData};
use crate::{pallet::Config, CommonCollectionOperations};
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -16,15 +16,17 @@
//! This module contains the implementation of pallet methods for evm.
-pub use pallet_evm::{PrecompileOutput, PrecompileResult, PrecompileHandle, account::CrossAccountId};
+pub use pallet_evm::{
+ account::CrossAccountId, PrecompileHandle, PrecompileOutput, PrecompileResult,
+};
use pallet_evm_coder_substrate::{
abi::AbiType,
- solidity_interface, ToLog,
+ dispatch_to_evm,
+ execution::{Error, PreDispatch, Result},
+ frontier_contract, solidity_interface,
types::*,
- execution::{Result, Error, PreDispatch},
- frontier_contract,
+ ToLog,
};
-use pallet_evm_coder_substrate::dispatch_to_evm;
use sp_std::{vec, vec::Vec};
use up_data_structs::{
CollectionMode, CollectionPermissions, OwnerRestrictedSet, Property, SponsoringRateLimit,
@@ -32,7 +34,7 @@
};
use crate::{
- Pallet, CollectionHandle, Config, CollectionProperties, eth, SelfWeightOf, weights::WeightInfo,
+ eth, weights::WeightInfo, CollectionHandle, CollectionProperties, Config, Pallet, SelfWeightOf,
};
frontier_contract! {
@@ -727,11 +729,10 @@
/// Contains static property keys and values.
pub mod static_property {
- use pallet_evm_coder_substrate::{
- execution::{Result, Error},
- };
use alloc::format;
+ use pallet_evm_coder_substrate::execution::{Error, Result};
+
const EXPECT_CONVERT_ERROR: &str = "length < limit";
/// Keys.
pallets/common/src/eth.rsdiffbeforeafterboth--- a/pallets/common/src/eth.rs
+++ b/pallets/common/src/eth.rs
@@ -17,15 +17,16 @@
//! The module contains a number of functions for converting and checking ethereum identifiers.
use alloc::format;
-use sp_std::{vec, vec::Vec};
+
use evm_coder::{
+ types::{Address, String},
AbiCoder,
- types::{Address, String},
};
-pub use pallet_evm::{Config, account::CrossAccountId};
-use sp_core::{H160, U256};
-use up_data_structs::{CollectionId, CollectionFlags};
+pub use pallet_evm::{account::CrossAccountId, Config};
use pallet_evm_coder_substrate::execution::Error;
+use sp_core::{H160, U256};
+use sp_std::{vec, vec::Vec};
+use up_data_structs::{CollectionFlags, CollectionId};
// 0x17c4e6453Cc49AAAaEACA894e6D9683e00000001 - collection 1
// TODO: Unhardcode prefix
pallets/common/src/helpers.rsdiffbeforeafterboth--- a/pallets/common/src/helpers.rs
+++ b/pallets/common/src/helpers.rs
@@ -3,9 +3,9 @@
//! The module contains helpers.
//!
use frame_support::{
+ dispatch::{DispatchErrorWithPostInfo, PostDispatchInfo},
pallet_prelude::DispatchResultWithPostInfo,
weights::Weight,
- dispatch::{DispatchErrorWithPostInfo, PostDispatchInfo},
};
/// Add weight for a `DispatchResultWithPostInfo`
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -58,37 +58,37 @@
slice::from_ref,
marker::PhantomData,
};
-use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
-use sp_std::vec::Vec;
-use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
+
use evm_coder::ToLog;
use frame_support::{
- dispatch::{DispatchErrorWithPostInfo, DispatchResultWithPostInfo, Weight, PostDispatchInfo},
- ensure,
+ dispatch::{DispatchErrorWithPostInfo, DispatchResultWithPostInfo, Pays, PostDispatchInfo},
+ ensure, fail,
traits::{
- Get,
fungible::{Balanced, Debt, Inspect},
tokens::{Imbalance, Precision, Preservation},
+ Get,
},
- dispatch::Pays,
- transactional, fail,
+ transactional,
};
+pub use pallet::*;
+use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
+use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
+use sp_core::H160;
+use sp_runtime::{traits::Zero, ArithmeticError, DispatchError, DispatchResult};
+use sp_std::vec::Vec;
+use sp_weights::Weight;
use up_data_structs::{
- AccessMode, COLLECTION_NUMBER_LIMIT, Collection, RpcCollection, RpcCollectionFlags,
- CollectionId, CreateItemData, MAX_TOKEN_PREFIX_LENGTH, COLLECTION_ADMINS_LIMIT, TokenId,
- TokenChild, CollectionStats, MAX_TOKEN_OWNERSHIP, CollectionMode, NFT_SPONSOR_TRANSFER_TIMEOUT,
- FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, MAX_SPONSOR_TIMEOUT,
- CUSTOM_DATA_LIMIT, CollectionLimits, CreateCollectionData, SponsorshipState, CreateItemExData,
- SponsoringRateLimit, budget::Budget, PhantomType, Property,
- CollectionProperties as CollectionPropertiesT, TokenProperties, PropertiesPermissionMap,
- PropertyKey, PropertyValue, PropertyPermission, PropertiesError, TokenOwnerError,
- PropertyKeyPermission, TokenData, TrySetProperty, PropertyScope, CollectionPermissions,
+ budget::Budget, AccessMode, Collection, CollectionId, CollectionLimits, CollectionMode,
+ CollectionPermissions, CollectionProperties as CollectionPropertiesT, CollectionStats,
+ CreateCollectionData, CreateItemData, CreateItemExData, PhantomType, PropertiesError,
+ PropertiesPermissionMap, Property, PropertyKey, PropertyKeyPermission, PropertyPermission,
+ PropertyScope, PropertyValue, RpcCollection, RpcCollectionFlags, SponsoringRateLimit,
+ SponsorshipState, TokenChild, TokenData, TokenId, TokenOwnerError, TokenProperties,
+ TrySetProperty, COLLECTION_ADMINS_LIMIT, COLLECTION_NUMBER_LIMIT, CUSTOM_DATA_LIMIT,
+ FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, MAX_SPONSOR_TIMEOUT, MAX_TOKEN_OWNERSHIP,
+ MAX_TOKEN_PREFIX_LENGTH, NFT_SPONSOR_TRANSFER_TIMEOUT, REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
};
use up_pov_estimate_rpc::PovInfo;
-
-pub use pallet::*;
-use sp_core::H160;
-use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, traits::Zero};
#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
@@ -401,13 +401,16 @@
#[frame_support::pallet]
pub mod pallet {
- use super::*;
use dispatch::CollectionDispatch;
- use frame_support::{Blake2_128Concat, pallet_prelude::*, storage::Key, traits::StorageVersion};
- use up_data_structs::{TokenId, mapping::TokenAddressMapping};
+ use frame_support::{
+ pallet_prelude::*, storage::Key, traits::StorageVersion, Blake2_128Concat,
+ };
use scale_info::TypeInfo;
+ use up_data_structs::{mapping::TokenAddressMapping, TokenId};
use weights::WeightInfo;
+ use super::*;
+
#[pallet::config]
pub trait Config:
frame_system::Config + pallet_evm_coder_substrate::Config + pallet_evm::Config + TypeInfo
@@ -2720,7 +2723,7 @@
#[cfg(any(feature = "tests", test))]
#[allow(missing_docs)]
pub mod tests {
- use crate::{DispatchResult, DispatchError, LazyValue, Config};
+ use crate::{Config, DispatchError, DispatchResult, LazyValue};
const fn to_bool(u: u8) -> bool {
u != 0
pallets/configuration/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/configuration/src/benchmarking.rs
+++ b/pallets/configuration/src/benchmarking.rs
@@ -16,10 +16,11 @@
//! Benchmarking setup for pallet-configuration
-use super::*;
use frame_benchmarking::benchmarks;
-use frame_system::{EventRecord, RawOrigin};
use frame_support::assert_ok;
+use frame_system::{EventRecord, RawOrigin};
+
+use super::*;
fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
let events = frame_system::Pallet::<T>::events();
pallets/configuration/src/lib.rsdiffbeforeafterboth--- a/pallets/configuration/src/lib.rs
+++ b/pallets/configuration/src/lib.rs
@@ -20,19 +20,17 @@
use frame_support::{
pallet,
- weights::{WeightToFeePolynomial, WeightToFeeCoefficients, WeightToFeeCoefficient, Weight},
traits::Get,
- Parameter,
+ weights::{Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial},
};
-use codec::{Decode, Encode, MaxEncodedLen};
+pub use pallet::*;
+use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
+use smallvec::smallvec;
use sp_arithmetic::{
- per_things::{Perbill, PerThing},
+ per_things::{PerThing, Perbill},
traits::{BaseArithmetic, Unsigned},
};
-use smallvec::smallvec;
-
-pub use pallet::*;
use sp_core::U256;
#[cfg(feature = "runtime-benchmarks")]
@@ -41,15 +39,14 @@
#[pallet]
mod pallet {
+ use core::fmt::Debug;
+
+ use frame_support::{pallet_prelude::*, traits::Get};
+ use frame_system::{ensure_root, pallet_prelude::*};
+ use parity_scale_codec::Codec;
+ use sp_arithmetic::{traits::AtLeast32BitUnsigned, FixedPointOperand, Permill};
+
use super::*;
- use frame_support::{
- traits::Get,
- pallet_prelude::*,
- log,
- dispatch::{Codec, fmt::Debug},
- };
- use frame_system::{pallet_prelude::OriginFor, ensure_root, pallet_prelude::*};
- use sp_arithmetic::{FixedPointOperand, traits::AtLeast32BitUnsigned, Permill};
pub use crate::weights::WeightInfo;
#[pallet::config]
pallets/evm-coder-substrate/procedural/src/lib.rsdiffbeforeafterboth--- a/pallets/evm-coder-substrate/procedural/src/lib.rs
+++ b/pallets/evm-coder-substrate/procedural/src/lib.rs
@@ -1,12 +1,12 @@
use std::result;
-use proc_macro2::{TokenStream, Ident};
+use proc_macro2::{Ident, TokenStream};
use quote::quote;
use syn::{
- Error, DeriveInput, Data, Attribute,
+ parenthesized,
parse::{Parse, ParseBuffer},
spanned::Spanned,
- Expr, parenthesized,
+ Attribute, Data, DeriveInput, Error, Expr,
};
type Result<T = TokenStream, E = syn::Error> = result::Result<T, E>;
pallets/evm-coder-substrate/src/execution.rsdiffbeforeafterboth--- a/pallets/evm-coder-substrate/src/execution.rs
+++ b/pallets/evm-coder-substrate/src/execution.rs
@@ -22,10 +22,9 @@
use std::string::{String, ToString};
use evm_coder::ERC165Call;
+pub use evm_coder_substrate_procedural::PreDispatch;
use evm_core::{ExitError, ExitFatal};
-
pub use frame_support::weights::Weight;
-pub use evm_coder_substrate_procedural::PreDispatch;
/// Execution error, should be convertible between EVM and Substrate.
#[derive(Debug, Clone)]
pallets/evm-coder-substrate/src/lib.rsdiffbeforeafterboth--- a/pallets/evm-coder-substrate/src/lib.rs
+++ b/pallets/evm-coder-substrate/src/lib.rs
@@ -22,42 +22,39 @@
extern crate alloc;
#[cfg(not(feature = "std"))]
use alloc::format;
-use execution::PreDispatch;
-use frame_support::dispatch::Weight;
-
use core::marker::PhantomData;
-use sp_std::{cell::RefCell, vec::Vec};
-use codec::Decode;
-use frame_support::pallet_prelude::DispatchError;
-use frame_support::traits::PalletInfo;
-use frame_support::{ensure, sp_runtime::ModuleError};
-use up_data_structs::budget;
+use execution::PreDispatch;
+use frame_support::{
+ ensure, pallet_prelude::DispatchError, sp_runtime::ModuleError, traits::PalletInfo,
+};
use pallet_evm::{
- ExitError, ExitRevert, ExitSucceed, GasWeightMapping, PrecompileFailure, PrecompileOutput,
- PrecompileResult, PrecompileHandle,
+ ExitError, ExitRevert, ExitSucceed, GasWeightMapping, PrecompileFailure, PrecompileHandle,
+ PrecompileOutput, PrecompileResult,
};
+use parity_scale_codec::Decode;
use sp_core::{Get, H160};
+use sp_std::{cell::RefCell, vec::Vec};
+use sp_weights::Weight;
+use up_data_structs::budget;
// #[cfg(feature = "runtime-benchmarks")]
// pub mod benchmarking;
pub mod execution;
-#[doc(hidden)]
-pub use spez::spez;
-
+pub use evm_coder::{abi, solidity_interface, types, Contract, ResultWithPostInfoOf, ToLog};
use evm_coder::{
types::{Msg, Value},
AbiEncode,
};
-
pub use pallet::*;
-pub use evm_coder::{ResultWithPostInfoOf, Contract, abi, solidity_interface, ToLog, types};
+#[doc(hidden)]
+pub use spez::spez;
#[frame_support::pallet]
pub mod pallet {
+ pub use frame_support::dispatch::DispatchResult;
+
use super::*;
-
- pub use frame_support::dispatch::DispatchResult;
/// DispatchError is opaque, but we need to somehow extract correct error in case of OutOfGas failure
/// So we have this pallet, which defines OutOfGas error, and knews its own id to check if DispatchError
pallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -18,32 +18,35 @@
extern crate alloc;
use core::marker::PhantomData;
+
use evm_coder::{
- abi::{AbiType, AbiEncode},
+ abi::{AbiEncode, AbiType},
generate_stubgen, solidity_interface,
types::*,
ToLog,
};
+use frame_support::traits::Get;
+use frame_system::pallet_prelude::*;
use pallet_common::eth;
use pallet_evm::{
- ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure, PrecompileHandle,
- account::CrossAccountId,
+ account::CrossAccountId, ExitRevert, OnCreate, OnMethodCall, PrecompileFailure,
+ PrecompileHandle, PrecompileResult,
};
use pallet_evm_coder_substrate::{
- SubstrateRecorder, WithRecorder, dispatch_to_evm,
- execution::{Result, PreDispatch},
- frontier_contract,
+ dispatch_to_evm,
+ execution::{PreDispatch, Result},
+ frontier_contract, SubstrateRecorder, WithRecorder,
};
use pallet_evm_transaction_payment::CallContext;
use sp_core::{H160, U256};
+use sp_std::vec::Vec;
use up_data_structs::SponsorshipState;
+use up_sponsorship::SponsorshipHandler;
+
use crate::{
- AllowlistEnabled, Config, Owner, Pallet, SponsorBasket, SponsoringFeeLimit,
- SponsoringRateLimit, SponsoringModeT, Sponsoring,
+ AllowlistEnabled, Config, Owner, Pallet, SponsorBasket, Sponsoring, SponsoringFeeLimit,
+ SponsoringModeT, SponsoringRateLimit,
};
-use frame_support::traits::Get;
-use up_sponsorship::SponsorshipHandler;
-use sp_std::vec::Vec;
frontier_contract! {
macro_rules! ContractHelpers_result {...}
pallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/lib.rs
+++ b/pallets/evm-contract-helpers/src/lib.rs
@@ -18,12 +18,12 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs)]
-use codec::{Decode, Encode, MaxEncodedLen};
+pub use eth::*;
use evm_coder::AbiCoder;
+use frame_support::storage::bounded_btree_map::BoundedBTreeMap;
pub use pallet::*;
-pub use eth::*;
+use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
-use frame_support::storage::bounded_btree_map::BoundedBTreeMap;
pub mod eth;
/// Maximum number of methods per contract that could have fee limit
@@ -31,15 +31,16 @@
#[frame_support::pallet]
pub mod pallet {
- pub use super::*;
+ use evm_coder::ToLog;
use frame_support::{pallet_prelude::*, sp_runtime::DispatchResult};
- use frame_system::{pallet_prelude::OriginFor, ensure_root};
+ use frame_system::{ensure_root, pallet_prelude::*};
+ use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
use sp_core::{H160, U256};
use sp_std::vec::Vec;
- use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
use up_data_structs::SponsorshipState;
- use evm_coder::ToLog;
+ pub use super::*;
+
#[pallet::config]
pub trait Config:
frame_system::Config + pallet_evm_coder_substrate::Config + pallet_evm::Config
pallets/evm-migration/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/evm-migration/src/benchmarking.rs
+++ b/pallets/evm-migration/src/benchmarking.rs
@@ -16,11 +16,12 @@
#![allow(missing_docs)]
-use super::{Call, Config, Pallet};
use frame_benchmarking::benchmarks;
use frame_system::RawOrigin;
use sp_core::{H160, H256};
-use sp_std::{vec::Vec, vec};
+use sp_std::{vec, vec::Vec};
+
+use super::{Call, Config, Pallet};
benchmarks! {
where_clause { where <T as Config>::RuntimeEvent: parity_scale_codec::Encode }
pallets/evm-migration/src/lib.rsdiffbeforeafterboth--- a/pallets/evm-migration/src/lib.rs
+++ b/pallets/evm-migration/src/lib.rs
@@ -26,15 +26,13 @@
#[frame_support::pallet]
pub mod pallet {
- use frame_support::{
- pallet_prelude::{*, DispatchResult},
- traits::IsType,
- };
- use frame_system::pallet_prelude::{*, OriginFor};
+ use frame_support::{pallet_prelude::*, traits::IsType};
+ use frame_system::pallet_prelude::*;
+ use pallet_evm::{Pallet as PalletEvm, PrecompileHandle};
use sp_core::{H160, H256};
use sp_std::vec::Vec;
+
use super::weights::WeightInfo;
- use pallet_evm::{PrecompileHandle, Pallet as PalletEvm};
#[pallet::config]
pub trait Config: frame_system::Config + pallet_evm::Config {
pallets/evm-transaction-payment/src/lib.rsdiffbeforeafterboth--- a/pallets/evm-transaction-payment/src/lib.rs
+++ b/pallets/evm-transaction-payment/src/lib.rs
@@ -19,19 +19,26 @@
#![deny(missing_docs)]
use core::marker::PhantomData;
-use fp_evm::WithdrawReason;
-use frame_support::traits::IsSubType;
+
+use fp_evm::{CheckEvmTransaction, FeeCalculator, TransactionValidationError, WithdrawReason};
+use frame_support::{
+ storage::with_transaction,
+ traits::{Currency, Imbalance, IsSubType, OnUnbalanced},
+};
pub use pallet::*;
-use pallet_evm::{account::CrossAccountId, EnsureAddressOrigin};
+use pallet_evm::{
+ account::CrossAccountId, EnsureAddressOrigin, NegativeImbalanceOf, OnChargeEVMTransaction,
+ OnCheckEvmTransaction,
+};
use sp_core::{H160, U256};
-use sp_runtime::{TransactionOutcome, DispatchError};
+use sp_runtime::{traits::UniqueSaturatedInto, DispatchError, TransactionOutcome};
use up_sponsorship::SponsorshipHandler;
#[frame_support::pallet]
pub mod pallet {
+ use sp_std::vec::Vec;
+
use super::*;
-
- use sp_std::vec::Vec;
/// Contains call data
pub struct CallContext {
pallets/foreign-assets/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/foreign-assets/src/benchmarking.rs
+++ b/pallets/foreign-assets/src/benchmarking.rs
@@ -16,15 +16,14 @@
#![allow(missing_docs)]
-use super::{Config, Pallet, Call};
-use frame_benchmarking::{benchmarks, account};
+use frame_benchmarking::{account, benchmarks};
+use frame_support::traits::Currency;
use frame_system::RawOrigin;
+use sp_std::{boxed::Box, vec::Vec};
+use staging_xcm::{opaque::latest::Junction::Parachain, v3::Junctions::X1, VersionedMultiLocation};
+
+use super::{Call, Config, Pallet};
use crate::AssetMetadata;
-use xcm::opaque::latest::Junction::Parachain;
-use xcm::VersionedMultiLocation;
-use xcm::v3::Junctions::X1;
-use frame_support::traits::Currency;
-use sp_std::{vec::Vec, boxed::Box};
fn bounded<T: TryFrom<Vec<u8>>>(slice: &[u8]) -> T {
T::try_from(slice.to_vec())
pallets/foreign-assets/src/impl_fungibles.rsdiffbeforeafterboth--- a/pallets/foreign-assets/src/impl_fungibles.rs
+++ b/pallets/foreign-assets/src/impl_fungibles.rs
@@ -16,18 +16,17 @@
//! Implementations for fungibles trait.
-use super::*;
-use frame_system::Config as SystemConfig;
-
use frame_support::traits::tokens::{
- DepositConsequence, WithdrawConsequence, Preservation, Fortitude, Provenance, Precision,
+ DepositConsequence, Fortitude, Precision, Preservation, Provenance, WithdrawConsequence,
};
-use pallet_common::CollectionHandle;
+use frame_system::Config as SystemConfig;
+use pallet_common::{CollectionHandle, CommonCollectionOperations};
use pallet_fungible::FungibleHandle;
-use pallet_common::CommonCollectionOperations;
+use sp_runtime::traits::{CheckedAdd, CheckedSub};
use up_data_structs::budget::Value;
-use sp_runtime::traits::{CheckedAdd, CheckedSub};
+use super::*;
+
impl<T: Config> fungibles::Inspect<<T as SystemConfig>::AccountId> for Pallet<T>
where
T: orml_tokens::Config<CurrencyId = AssetId>,
pallets/foreign-assets/src/lib.rsdiffbeforeafterboth--- a/pallets/foreign-assets/src/lib.rs
+++ b/pallets/foreign-assets/src/lib.rs
@@ -39,29 +39,26 @@
ensure,
pallet_prelude::*,
traits::{fungible, fungibles, Currency, EnsureOrigin},
- RuntimeDebug,
};
use frame_system::pallet_prelude::*;
-use up_data_structs::CollectionMode;
+use pallet_common::erc::CrossAccountId;
use pallet_fungible::Pallet as PalletFungible;
use scale_info::TypeInfo;
+use serde::{Deserialize, Serialize};
use sp_runtime::{
traits::{One, Zero},
ArithmeticError,
};
use sp_std::{boxed::Box, vec::Vec};
-use up_data_structs::{CollectionId, TokenId, CreateCollectionData};
-
+use staging_xcm::{latest::MultiLocation, VersionedMultiLocation};
// NOTE: MultiLocation is used in storages, we will need to do migration if upgrade the
// MultiLocation to the XCM v3.
-use xcm::opaque::latest::{prelude::XcmError, Weight};
-use xcm::{latest::MultiLocation, VersionedMultiLocation};
-use xcm_executor::{traits::WeightTrader, Assets};
-
-use pallet_common::erc::CrossAccountId;
-
-#[cfg(feature = "std")]
-use serde::{Deserialize, Serialize};
+use staging_xcm::{
+ opaque::latest::{prelude::XcmError, Weight},
+ v3::XcmContext,
+};
+use staging_xcm_executor::{traits::WeightTrader, Assets};
+use up_data_structs::{CollectionId, CollectionMode, CreateCollectionData, TokenId};
// TODO: Move to primitives
// Id of native currency.
pallets/fungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/fungible/src/benchmarking.rs
+++ b/pallets/fungible/src/benchmarking.rs
@@ -14,14 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use super::*;
-use crate::{Pallet, Config, FungibleHandle};
-
+use frame_benchmarking::{account, benchmarks};
+use pallet_common::{bench_init, benchmarking::create_collection_raw};
use sp_std::prelude::*;
-use pallet_common::benchmarking::create_collection_raw;
-use frame_benchmarking::{benchmarks, account};
-use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH, budget::Unlimited};
-use pallet_common::bench_init;
+use up_data_structs::{budget::Unlimited, CollectionMode, MAX_ITEMS_PER_BATCH};
+
+use super::*;
+use crate::{Config, FungibleHandle, Pallet};
const SEED: u32 = 1;
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -16,22 +16,24 @@
use core::marker::PhantomData;
-use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, traits::Get};
-use up_data_structs::{
- TokenId, CollectionId, CreateItemExData, budget::Budget, CreateItemData, TokenOwnerError,
+use frame_support::{
+ dispatch::DispatchResultWithPostInfo, ensure, fail, traits::Get, weights::Weight,
};
use pallet_common::{
- CommonCollectionOperations, CommonWeightInfo, RefungibleExtensions, with_weight,
- weights::WeightInfo as _, SelfWeightOf as PalletCommonWeightOf,
+ weights::WeightInfo as _, with_weight, CommonCollectionOperations, CommonWeightInfo,
+ RefungibleExtensions, SelfWeightOf as PalletCommonWeightOf,
};
use pallet_structure::Error as StructureError;
use sp_runtime::{ArithmeticError, DispatchError};
-use sp_std::{vec::Vec, vec};
-use up_data_structs::{Property, PropertyKey, PropertyValue, PropertyKeyPermission};
+use sp_std::{vec, vec::Vec};
+use up_data_structs::{
+ budget::Budget, CollectionId, CreateItemData, CreateItemExData, Property, PropertyKey,
+ PropertyKeyPermission, PropertyValue, TokenId, TokenOwnerError,
+};
use crate::{
- Allowance, TotalSupply, Balance, Config, Error, FungibleHandle, Pallet, SelfWeightOf,
- weights::WeightInfo,
+ weights::WeightInfo, Allowance, Balance, Config, Error, FungibleHandle, Pallet, SelfWeightOf,
+ TotalSupply,
};
pub struct CommonWeights<T: Config>(PhantomData<T>);
pallets/fungible/src/erc.rsdiffbeforeafterboth--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -17,30 +17,31 @@
//! ERC-20 standart support implementation.
extern crate alloc;
-use core::char::{REPLACEMENT_CHARACTER, decode_utf16};
-use core::convert::TryInto;
-use evm_coder::AbiCoder;
-use evm_coder::{abi::AbiType, ToLog, generate_stubgen, solidity_interface, types::*};
-use up_data_structs::CollectionMode;
+use core::{
+ char::{decode_utf16, REPLACEMENT_CHARACTER},
+ convert::TryInto,
+};
+
+use evm_coder::{abi::AbiType, generate_stubgen, solidity_interface, types::*, AbiCoder, ToLog};
use pallet_common::{
- CollectionHandle,
- erc::{CommonEvmHandler, PrecompileResult, CollectionCall},
+ erc::{CollectionCall, CommonEvmHandler, PrecompileResult},
eth::CrossAddress,
- CommonWeightInfo as _,
+ CollectionHandle, CommonWeightInfo as _,
};
-use sp_std::vec::Vec;
use pallet_evm::{account::CrossAccountId, PrecompileHandle};
use pallet_evm_coder_substrate::{
call, dispatch_to_evm,
execution::{PreDispatch, Result},
frontier_contract,
};
-use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};
-use sp_core::{U256, Get};
+use pallet_structure::{weights::WeightInfo as _, SelfWeightOf as StructureWeight};
+use sp_core::{Get, U256};
+use sp_std::vec::Vec;
+use up_data_structs::CollectionMode;
use crate::{
- Allowance, Balance, Config, FungibleHandle, Pallet, TotalSupply, SelfWeightOf,
- weights::WeightInfo, common::CommonWeights,
+ common::CommonWeights, weights::WeightInfo, Allowance, Balance, Config, FungibleHandle, Pallet,
+ SelfWeightOf, TotalSupply,
};
frontier_contract! {
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -79,30 +79,26 @@
#![cfg_attr(not(feature = "std"), no_std)]
use core::ops::Deref;
+
use evm_coder::ToLog;
-use frame_support::{
- ensure,
- pallet_prelude::{DispatchResultWithPostInfo, Pays},
- dispatch::PostDispatchInfo,
-};
-use pallet_evm::account::CrossAccountId;
-use up_data_structs::{
- AccessMode, CollectionId, TokenId, CreateCollectionData, mapping::TokenAddressMapping,
- budget::Budget, PropertyKey, Property,
-};
+use frame_support::{dispatch::PostDispatchInfo, ensure, pallet_prelude::*};
+pub use pallet::*;
use pallet_common::{
- Error as CommonError, Event as CommonEvent, Pallet as PalletCommon,
- eth::collection_id_to_address, SelfWeightOf as PalletCommonWeightOf,
- weights::WeightInfo as CommonWeightInfo, helpers::add_weight_to_post_info,
+ eth::collection_id_to_address, helpers::add_weight_to_post_info,
+ weights::WeightInfo as CommonWeightInfo, Error as CommonError, Event as CommonEvent,
+ Pallet as PalletCommon, SelfWeightOf as PalletCommonWeightOf,
};
-use pallet_evm::Pallet as PalletEvm;
+use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
+use pallet_evm_coder_substrate::WithRecorder;
use pallet_structure::Pallet as PalletStructure;
-use pallet_evm_coder_substrate::WithRecorder;
use sp_core::H160;
use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};
use sp_std::{collections::btree_map::BTreeMap, vec::Vec};
+use up_data_structs::{
+ budget::Budget, mapping::TokenAddressMapping, AccessMode, CollectionId, CreateCollectionData,
+ Property, PropertyKey, TokenId,
+};
use weights::WeightInfo;
-pub use pallet::*;
use crate::erc::ERC20Events;
#[cfg(feature = "runtime-benchmarks")]
@@ -116,8 +112,11 @@
#[frame_support::pallet]
pub mod pallet {
- use frame_support::{Blake2_128, Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key};
+ use frame_support::{
+ pallet_prelude::*, storage::Key, Blake2_128, Blake2_128Concat, Twox64Concat,
+ };
use up_data_structs::CollectionId;
+
use super::weights::WeightInfo;
#[pallet::error]
pallets/gov-origins/src/lib.rsdiffbeforeafterboth--- a/pallets/gov-origins/src/lib.rs
+++ b/pallets/gov-origins/src/lib.rs
@@ -17,7 +17,6 @@
#![cfg_attr(not(feature = "std"), no_std)]
use frame_support::pallet_prelude::*;
-
pub use pallet::*;
#[frame_support::pallet]
pallets/identity/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/identity/src/benchmarking.rs
+++ b/pallets/identity/src/benchmarking.rs
@@ -37,17 +37,17 @@
#![cfg(feature = "runtime-benchmarks")]
#![allow(clippy::no_effect)]
-use super::*;
-
-use crate::Pallet as Identity;
use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_support::{
- ensure, assert_ok,
+ assert_ok, ensure,
traits::{EnsureOrigin, Get},
};
use frame_system::RawOrigin;
use sp_runtime::traits::Bounded;
+use super::*;
+use crate::Pallet as Identity;
+
const SEED: u32 = 0;
fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
pallets/identity/src/lib.rsdiffbeforeafterboth--- a/pallets/identity/src/lib.rs
+++ b/pallets/identity/src/lib.rs
@@ -95,21 +95,18 @@
mod types;
pub mod weights;
-use frame_support::{
- traits::{BalanceStatus, Currency, OnUnbalanced, ReservableCurrency},
-};
+use frame_support::traits::{BalanceStatus, Currency, OnUnbalanced, ReservableCurrency};
+pub use pallet::*;
use sp_runtime::{
- BoundedVec,
traits::{AppendZerosInput, Hash, Saturating, StaticLookup, Zero},
+ BoundedVec,
};
use sp_std::prelude::*;
-pub use weights::WeightInfo;
-
-pub use pallet::*;
pub use types::{
Data, IdentityField, IdentityFields, IdentityInfo, Judgement, RegistrarIndex, RegistrarInfo,
Registration,
};
+pub use weights::WeightInfo;
pub type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
@@ -132,10 +129,11 @@
#[frame_support::pallet]
pub mod pallet {
- use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
+ use super::*;
+
#[pallet::config]
pub trait Config: frame_system::Config {
/// The overarching event type.
pallets/identity/src/tests.rsdiffbeforeafterboth--- a/pallets/identity/src/tests.rs
+++ b/pallets/identity/src/tests.rs
@@ -34,22 +34,23 @@
// Tests for Identity Pallet
-use super::*;
-use crate as pallet_identity;
-
-use codec::{Decode, Encode};
use frame_support::{
assert_noop, assert_ok, ord_parameter_types, parameter_types,
traits::{ConstU32, ConstU64, EitherOfDiverse},
BoundedVec,
};
use frame_system::{EnsureRoot, EnsureSignedBy};
+use parity_scale_codec::{Decode, Encode};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BadOrigin, BlakeTwo256, IdentityLookup},
+ BuildStorage,
};
+use super::*;
+use crate as pallet_identity;
+
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
pallets/identity/src/types.rsdiffbeforeafterboth--- a/pallets/identity/src/types.rs
+++ b/pallets/identity/src/types.rs
@@ -32,13 +32,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-use super::*;
-use codec::{Decode, Encode, MaxEncodedLen};
use enumflags2::{bitflags, BitFlags};
use frame_support::{
traits::{ConstU32, Get},
BoundedVec, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound,
};
+use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::{
build::{Fields, Variants},
meta_type, Path, Type, TypeInfo, TypeParameter,
@@ -46,6 +45,8 @@
use sp_runtime::{traits::Zero, RuntimeDebug};
use sp_std::{fmt::Debug, iter::once, ops::Add, prelude::*};
+use super::*;
+
/// Either underlying data blob if it is at most 32 bytes, or a hash of it. If the data is greater
/// than 32-bytes then it will be truncated when encoding.
///
pallets/inflation/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/inflation/src/benchmarking.rs
+++ b/pallets/inflation/src/benchmarking.rs
@@ -16,11 +16,11 @@
#![cfg(feature = "runtime-benchmarks")]
+use frame_benchmarking::benchmarks;
+use frame_support::traits::OnInitialize;
+
use super::*;
use crate::Pallet as Inflation;
-
-use frame_benchmarking::{benchmarks};
-use frame_support::traits::OnInitialize;
benchmarks! {
pallets/inflation/src/lib.rsdiffbeforeafterboth--- a/pallets/inflation/src/lib.rs
+++ b/pallets/inflation/src/lib.rs
@@ -37,17 +37,14 @@
#[cfg(test)]
mod tests;
-use frame_support::{
- dispatch::{DispatchResult},
- traits::{
- fungible::{Balanced, Inspect, Mutate},
- Get,
- tokens::Precision,
- },
+use frame_support::traits::{
+ fungible::{Balanced, Inspect, Mutate},
+ tokens::Precision,
+ Get,
};
+use frame_system::pallet_prelude::BlockNumberFor;
pub use pallet::*;
-use sp_runtime::{Perbill, traits::BlockNumberProvider};
-
+use sp_runtime::{traits::BlockNumberProvider, Perbill};
use sp_std::convert::TryInto;
type BalanceOf<T> =
@@ -61,10 +58,11 @@
#[frame_support::pallet]
pub mod pallet {
- use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
+ use super::*;
+
#[pallet::config]
pub trait Config: frame_system::Config {
type Currency: Balanced<Self::AccountId>
pallets/inflation/src/tests.rsdiffbeforeafterboth--- a/pallets/inflation/src/tests.rs
+++ b/pallets/inflation/src/tests.rs
@@ -16,14 +16,12 @@
#![cfg(test)]
#![allow(clippy::from_over_into)]
-use crate as pallet_inflation;
-
use frame_support::{
assert_ok, parameter_types,
traits::{
fungible::{Balanced, Inspect},
- OnInitialize, Everything, ConstU32,
tokens::Precision,
+ ConstU32, Everything, OnInitialize,
},
weights::Weight,
};
@@ -31,9 +29,11 @@
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, BlockNumberProvider, IdentityLookup},
- testing::Header,
+ BuildStorage,
};
+use crate as pallet_inflation;
+
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
pallets/maintenance/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/maintenance/src/benchmarking.rs
+++ b/pallets/maintenance/src/benchmarking.rs
@@ -14,13 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use super::*;
-use crate::{Pallet as Maintenance, Config};
-
-use codec::Encode;
use frame_benchmarking::benchmarks;
+use frame_support::{ensure, pallet_prelude::Weight, traits::StorePreimage};
use frame_system::RawOrigin;
-use frame_support::{ensure, pallet_prelude::Weight, traits::StorePreimage};
+use parity_scale_codec::Encode;
+
+use super::*;
+use crate::{Config, Pallet as Maintenance};
benchmarks! {
enable {
pallets/maintenance/src/lib.rsdiffbeforeafterboth--- a/pallets/maintenance/src/lib.rs
+++ b/pallets/maintenance/src/lib.rs
@@ -26,10 +26,14 @@
#[frame_support::pallet]
pub mod pallet {
- use frame_support::{dispatch::*, pallet_prelude::*};
- use frame_support::traits::{QueryPreimage, StorePreimage, EnsureOrigin};
+ use frame_support::{
+ dispatch::*,
+ pallet_prelude::*,
+ traits::{EnsureOrigin, QueryPreimage, StorePreimage},
+ };
use frame_system::pallet_prelude::*;
use sp_core::H256;
+ use sp_runtime::traits::Dispatchable;
use crate::weights::WeightInfo;
@@ -111,7 +115,7 @@
hash: H256,
weight_bound: Weight,
) -> DispatchResultWithPostInfo {
- use codec::Decode;
+ use parity_scale_codec::Decode;
T::PreimageOrigin::ensure_origin(origin.clone())?;
pallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -14,10 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use super::*;
-use crate::{Pallet, Config, NonfungibleHandle};
-
-use frame_benchmarking::{benchmarks, account};
+use frame_benchmarking::{account, benchmarks};
use pallet_common::{
bench_init,
benchmarking::{
@@ -27,10 +24,13 @@
};
use sp_std::prelude::*;
use up_data_structs::{
- CollectionMode, MAX_ITEMS_PER_BATCH, MAX_PROPERTIES_PER_ITEM, budget::Unlimited,
- PropertyPermission,
+ budget::Unlimited, CollectionMode, PropertyPermission, MAX_ITEMS_PER_BATCH,
+ MAX_PROPERTIES_PER_ITEM,
};
+use super::*;
+use crate::{Config, NonfungibleHandle, Pallet};
+
const SEED: u32 = 1;
fn create_max_item_data<T: Config>(owner: T::CrossAccountId) -> CreateItemData<T> {
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -17,21 +17,21 @@
use core::marker::PhantomData;
use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight};
-use up_data_structs::{
- TokenId, CreateItemExData, CollectionId, budget::Budget, Property, PropertyKey,
- PropertyKeyPermission, PropertyValue, TokenOwnerError,
-};
use pallet_common::{
- CommonCollectionOperations, CommonWeightInfo, RefungibleExtensions, with_weight,
- weights::WeightInfo as _, SelfWeightOf as PalletCommonWeightOf, init_token_properties_delta,
+ init_token_properties_delta, weights::WeightInfo as _, with_weight, CommonCollectionOperations,
+ CommonWeightInfo, RefungibleExtensions, SelfWeightOf as PalletCommonWeightOf,
};
use pallet_structure::Pallet as PalletStructure;
use sp_runtime::DispatchError;
-use sp_std::{vec::Vec, vec};
+use sp_std::{vec, vec::Vec};
+use up_data_structs::{
+ budget::Budget, CollectionId, CreateItemExData, Property, PropertyKey, PropertyKeyPermission,
+ PropertyValue, TokenId, TokenOwnerError,
+};
use crate::{
- AccountBalance, Allowance, Config, CreateItemData, Error, NonfungibleHandle, Owned, Pallet,
- SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted, TokenProperties,
+ weights::WeightInfo, AccountBalance, Allowance, Config, CreateItemData, Error,
+ NonfungibleHandle, Owned, Pallet, SelfWeightOf, TokenData, TokenProperties, TokensMinted,
};
pub struct CommonWeights<T: Config>(PhantomData<T>);
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -23,34 +23,34 @@
use alloc::string::ToString;
use core::{
- char::{REPLACEMENT_CHARACTER, decode_utf16},
+ char::{decode_utf16, REPLACEMENT_CHARACTER},
convert::TryInto,
};
-use evm_coder::{abi::AbiType, AbiCoder, ToLog, generate_stubgen, solidity_interface, types::*};
+
+use evm_coder::{abi::AbiType, generate_stubgen, solidity_interface, types::*, AbiCoder, ToLog};
use frame_support::BoundedVec;
-use up_data_structs::{
- TokenId, PropertyPermission, PropertyKeyPermission, Property, CollectionId, PropertyKey,
- CollectionPropertiesVec,
+use pallet_common::{
+ erc::{static_property::key, CollectionCall, CommonEvmHandler, PrecompileResult},
+ eth::{self, TokenUri},
+ CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations, CommonWeightInfo,
};
+use pallet_evm::{account::CrossAccountId, PrecompileHandle};
use pallet_evm_coder_substrate::{
- dispatch_to_evm, frontier_contract,
- execution::{Result, PreDispatch, Error},
+ call, dispatch_to_evm,
+ execution::{Error, PreDispatch, Result},
+ frontier_contract,
};
-use sp_std::{vec::Vec, vec};
-use pallet_common::{
- CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,
- erc::{CommonEvmHandler, PrecompileResult, CollectionCall, static_property::key},
- eth::{self, TokenUri},
- CommonWeightInfo,
+use pallet_structure::{weights::WeightInfo as _, SelfWeightOf as StructureWeight};
+use sp_core::{Get, U256};
+use sp_std::{vec, vec::Vec};
+use up_data_structs::{
+ CollectionId, CollectionPropertiesVec, Property, PropertyKey, PropertyKeyPermission,
+ PropertyPermission, TokenId,
};
-use pallet_evm::{account::CrossAccountId, PrecompileHandle};
-use pallet_evm_coder_substrate::call;
-use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};
-use sp_core::{U256, Get};
use crate::{
- AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,
- TokenProperties, SelfWeightOf, weights::WeightInfo, common::CommonWeights,
+ common::CommonWeights, weights::WeightInfo, AccountBalance, Config, CreateItemData,
+ NonfungibleHandle, Pallet, SelfWeightOf, TokenData, TokenProperties, TokensMinted,
};
/// Nft events.
pallets/refungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/refungible/src/benchmarking.rs
+++ b/pallets/refungible/src/benchmarking.rs
@@ -14,12 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use super::*;
-use crate::{Pallet, Config, RefungibleHandle};
+use core::{convert::TryInto, iter::IntoIterator};
-use core::convert::TryInto;
-use core::iter::IntoIterator;
-use frame_benchmarking::{benchmarks, account};
+use frame_benchmarking::{account, benchmarks};
use pallet_common::{
bench_init,
benchmarking::{
@@ -28,10 +25,13 @@
};
use sp_std::prelude::*;
use up_data_structs::{
- CollectionMode, MAX_ITEMS_PER_BATCH, MAX_PROPERTIES_PER_ITEM, budget::Unlimited,
- PropertyPermission,
+ budget::Unlimited, CollectionMode, PropertyPermission, MAX_ITEMS_PER_BATCH,
+ MAX_PROPERTIES_PER_ITEM,
};
+use super::*;
+use crate::{Config, Pallet, RefungibleHandle};
+
const SEED: u32 = 1;
fn create_max_item_data<T: Config>(
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -16,24 +16,25 @@
use core::marker::PhantomData;
-use sp_std::collections::btree_map::BTreeMap;
-use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, traits::Get};
-use up_data_structs::{
- CollectionId, TokenId, CreateItemExData, budget::Budget, Property, PropertyKey, PropertyValue,
- PropertyKeyPermission, CreateRefungibleExMultipleOwners, CreateRefungibleExSingleOwner,
- TokenOwnerError,
+use frame_support::{
+ dispatch::DispatchResultWithPostInfo, ensure, fail, traits::Get, weights::Weight,
};
use pallet_common::{
- CommonCollectionOperations, CommonWeightInfo, RefungibleExtensions, with_weight,
- weights::WeightInfo as _, init_token_properties_delta,
+ init_token_properties_delta, weights::WeightInfo as _, with_weight, CommonCollectionOperations,
+ CommonWeightInfo, RefungibleExtensions,
};
-use pallet_structure::{Pallet as PalletStructure, Error as StructureError};
-use sp_runtime::{DispatchError};
-use sp_std::{vec::Vec, vec};
+use pallet_structure::{Error as StructureError, Pallet as PalletStructure};
+use sp_runtime::DispatchError;
+use sp_std::{collections::btree_map::BTreeMap, vec, vec::Vec};
+use up_data_structs::{
+ budget::Budget, CollectionId, CreateItemExData, CreateRefungibleExMultipleOwners,
+ CreateRefungibleExSingleOwner, Property, PropertyKey, PropertyKeyPermission, PropertyValue,
+ TokenId, TokenOwnerError,
+};
use crate::{
- AccountBalance, Allowance, Balance, Config, Error, Owned, Pallet, RefungibleHandle,
- SelfWeightOf, weights::WeightInfo, TokensMinted, TotalSupply, CreateItemData, TokenProperties,
+ weights::WeightInfo, AccountBalance, Allowance, Balance, Config, CreateItemData, Error, Owned,
+ Pallet, RefungibleHandle, SelfWeightOf, TokenProperties, TokensMinted, TotalSupply,
};
macro_rules! max_weight_of {
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -23,34 +23,35 @@
use alloc::string::ToString;
use core::{
- char::{REPLACEMENT_CHARACTER, decode_utf16},
+ char::{decode_utf16, REPLACEMENT_CHARACTER},
convert::TryInto,
};
-use evm_coder::{abi::AbiType, AbiCoder, ToLog, generate_stubgen, solidity_interface, types::*};
+
+use evm_coder::{abi::AbiType, generate_stubgen, solidity_interface, types::*, AbiCoder, ToLog};
use frame_support::{BoundedBTreeMap, BoundedVec};
use pallet_common::{
+ erc::{static_property::key, CollectionCall, CommonEvmHandler},
+ eth::{self, TokenUri},
CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,
Error as CommonError,
- erc::{CommonEvmHandler, CollectionCall, static_property::key},
- eth::{self, TokenUri},
};
use pallet_evm::{account::CrossAccountId, PrecompileHandle};
use pallet_evm_coder_substrate::{
call, dispatch_to_evm,
- execution::{PreDispatch, Result, Error},
+ execution::{Error, PreDispatch, Result},
frontier_contract,
};
-use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};
-use sp_core::{H160, U256, Get};
-use sp_std::{collections::btree_map::BTreeMap, vec::Vec, vec};
+use pallet_structure::{weights::WeightInfo as _, SelfWeightOf as StructureWeight};
+use sp_core::{Get, H160, U256};
+use sp_std::{collections::btree_map::BTreeMap, vec, vec::Vec};
use up_data_structs::{
- CollectionId, CollectionPropertiesVec, mapping::TokenAddressMapping, Property, PropertyKey,
+ mapping::TokenAddressMapping, CollectionId, CollectionPropertiesVec, Property, PropertyKey,
PropertyKeyPermission, PropertyPermission, TokenId, TokenOwnerError,
};
use crate::{
- AccountBalance, Balance, Config, CreateItemData, Pallet, RefungibleHandle, TokenProperties,
- TokensMinted, TotalSupply, SelfWeightOf, weights::WeightInfo,
+ weights::WeightInfo, AccountBalance, Balance, Config, CreateItemData, Pallet, RefungibleHandle,
+ SelfWeightOf, TokenProperties, TokensMinted, TotalSupply,
};
frontier_contract! {
pallets/refungible/src/erc_token.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc_token.rs
+++ b/pallets/refungible/src/erc_token.rs
@@ -20,11 +20,12 @@
//! Method implementations are mostly doing parameter conversion and calling Nonfungible Pallet methods.
use core::{
- char::{REPLACEMENT_CHARACTER, decode_utf16},
+ char::{decode_utf16, REPLACEMENT_CHARACTER},
convert::TryInto,
ops::Deref,
};
-use evm_coder::{abi::AbiType, ToLog, generate_stubgen, solidity_interface, types::*};
+
+use evm_coder::{abi::AbiType, generate_stubgen, solidity_interface, types::*, ToLog};
use pallet_common::{
erc::{CommonEvmHandler, PrecompileResult},
eth::{collection_id_to_address, CrossAddress},
@@ -32,17 +33,18 @@
};
use pallet_evm::{account::CrossAccountId, PrecompileHandle};
use pallet_evm_coder_substrate::{
- call, dispatch_to_evm, WithRecorder, frontier_contract,
- execution::{Result, PreDispatch},
+ call, dispatch_to_evm,
+ execution::{PreDispatch, Result},
+ frontier_contract, WithRecorder,
};
-use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};
-use sp_std::vec::Vec;
+use pallet_structure::{weights::WeightInfo as _, SelfWeightOf as StructureWeight};
use sp_core::U256;
+use sp_std::vec::Vec;
use up_data_structs::TokenId;
use crate::{
- Allowance, Balance, Config, Pallet, RefungibleHandle, TotalSupply, common::CommonWeights,
- SelfWeightOf, weights::WeightInfo,
+ common::CommonWeights, weights::WeightInfo, Allowance, Balance, Config, Pallet,
+ RefungibleHandle, SelfWeightOf, TotalSupply,
};
/// Refungible token handle contains information about token's collection and id
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -87,30 +87,29 @@
#![cfg_attr(not(feature = "std"), no_std)]
-use crate::erc_token::ERC20Events;
-use crate::erc::ERC721Events;
+use core::{cmp::Ordering, ops::Deref};
-use core::{ops::Deref, cmp::Ordering};
use evm_coder::ToLog;
use frame_support::{ensure, storage::with_transaction, transactional};
-use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
-use pallet_evm_coder_substrate::WithRecorder;
+pub use pallet::*;
use pallet_common::{
- Error as CommonError, eth::collection_id_to_address, Event as CommonEvent,
+ eth::collection_id_to_address, Error as CommonError, Event as CommonEvent,
Pallet as PalletCommon,
};
+use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
+use pallet_evm_coder_substrate::WithRecorder;
use pallet_structure::Pallet as PalletStructure;
use sp_core::{Get, H160};
use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};
-use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};
+use sp_std::{collections::btree_map::BTreeMap, vec, vec::Vec};
use up_data_structs::{
- AccessMode, budget::Budget, CollectionId, CreateCollectionData, mapping::TokenAddressMapping,
- MAX_REFUNGIBLE_PIECES, Property, PropertyKey, PropertyKeyPermission, PropertyScope,
- PropertyValue, TokenId, PropertiesPermissionMap, CreateRefungibleExMultipleOwners,
- TokenOwnerError, TokenProperties as TokenPropertiesT,
+ budget::Budget, mapping::TokenAddressMapping, AccessMode, CollectionId, CreateCollectionData,
+ CreateRefungibleExMultipleOwners, PropertiesPermissionMap, Property, PropertyKey,
+ PropertyKeyPermission, PropertyScope, PropertyValue, TokenId, TokenOwnerError,
+ TokenProperties as TokenPropertiesT, TrySetProperty, MAX_REFUNGIBLE_PIECES,
};
-pub use pallet::*;
+use crate::{erc::ERC721Events, erc_token::ERC20Events};
#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
pub mod common;
@@ -124,14 +123,14 @@
#[frame_support::pallet]
pub mod pallet {
- use super::*;
use frame_support::{
- Blake2_128, Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key,
- traits::StorageVersion,
+ pallet_prelude::*, storage::Key, traits::StorageVersion, Blake2_128, Blake2_128Concat,
+ Twox64Concat,
};
use up_data_structs::{CollectionId, TokenId};
- use super::weights::WeightInfo;
+ use super::{weights::WeightInfo, *};
+
#[pallet::error]
pub enum Error<T> {
/// Not Refungible item data used to mint in Refungible collection.
pallets/structure/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/structure/src/benchmarking.rs
+++ b/pallets/structure/src/benchmarking.rs
@@ -14,16 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use super::*;
-
-use frame_benchmarking::{benchmarks, account};
-use frame_support::traits::{fungible::Balanced, Get, tokens::Precision};
+use frame_benchmarking::{account, benchmarks};
+use frame_support::traits::{fungible::Balanced, tokens::Precision, Get};
+use pallet_common::Config as CommonConfig;
+use pallet_evm::account::CrossAccountId;
use up_data_structs::{
- CreateCollectionData, CollectionMode, CreateItemData, CreateNftData, budget::Unlimited,
+ budget::Unlimited, CollectionMode, CreateCollectionData, CreateItemData, CreateNftData,
};
-use pallet_common::Config as CommonConfig;
-use pallet_evm::account::CrossAccountId;
+use super::*;
+
const SEED: u32 = 1;
benchmarks! {
pallets/structure/src/lib.rsdiffbeforeafterboth--- a/pallets/structure/src/lib.rs
+++ b/pallets/structure/src/lib.rs
@@ -53,29 +53,31 @@
#![cfg_attr(not(feature = "std"), no_std)]
-use pallet_common::CommonCollectionOperations;
-use pallet_common::{erc::CrossAccountId, eth::is_collection};
+use frame_support::{
+ dispatch::{DispatchResult, DispatchResultWithPostInfo},
+ fail,
+ pallet_prelude::*,
+};
+use pallet_common::{
+ dispatch::CollectionDispatch, erc::CrossAccountId, eth::is_collection,
+ CommonCollectionOperations,
+};
use sp_std::collections::btree_set::BTreeSet;
-
-use frame_support::dispatch::{DispatchError, DispatchResult, DispatchResultWithPostInfo};
-use frame_support::fail;
-pub use pallet::*;
-use pallet_common::{dispatch::CollectionDispatch};
use up_data_structs::{
- CollectionId, TokenId, mapping::TokenAddressMapping, budget::Budget, TokenOwnerError,
+ budget::Budget, mapping::TokenAddressMapping, CollectionId, TokenId, TokenOwnerError,
};
#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
pub mod weights;
+pub use pallet::*;
+
pub type SelfWeightOf<T> = <T as crate::Config>::WeightInfo;
#[frame_support::pallet]
pub mod pallet {
- use frame_support::Parameter;
- use frame_support::dispatch::{GetDispatchInfo, UnfilteredDispatchable};
- use frame_support::pallet_prelude::*;
+ use frame_support::{dispatch::GetDispatchInfo, traits::UnfilteredDispatchable, Parameter};
use super::*;
pallets/unique/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/unique/src/benchmarking.rs
+++ b/pallets/unique/src/benchmarking.rs
@@ -16,22 +16,23 @@
#![cfg(feature = "runtime-benchmarks")]
-use super::*;
-use crate::Pallet;
+use frame_benchmarking::{account, benchmarks};
+use frame_support::traits::{fungible::Balanced, tokens::Precision, Get};
use frame_system::RawOrigin;
-use frame_support::traits::{fungible::Balanced, Get, tokens::Precision};
-use frame_benchmarking::{benchmarks, account};
-use sp_runtime::DispatchError;
use pallet_common::{
- Config as CommonConfig,
benchmarking::{create_data, create_u16_data},
+ erc::CrossAccountId,
+ Config as CommonConfig,
};
+use sp_runtime::DispatchError;
use up_data_structs::{
- CollectionId, CollectionMode, MAX_COLLECTION_NAME_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
- MAX_COLLECTION_DESCRIPTION_LENGTH, CollectionLimits,
+ CollectionId, CollectionLimits, CollectionMode, MAX_COLLECTION_DESCRIPTION_LENGTH,
+ MAX_COLLECTION_NAME_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
};
-use pallet_common::erc::CrossAccountId;
+use super::*;
+use crate::Pallet;
+
const SEED: u32 = 1;
fn create_collection_helper<T: Config>(
pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -16,32 +16,31 @@
//! Implementation of CollectionHelpers contract.
//!
+use alloc::{collections::BTreeSet, format};
use core::marker::PhantomData;
+
use ethereum as _;
use evm_coder::{abi::AbiType, generate_stubgen, solidity_interface, types::*};
-use frame_support::{BoundedVec, traits::Get};
+use frame_support::{traits::Get, BoundedVec};
use pallet_common::{
- CollectionById,
dispatch::CollectionDispatch,
- erc::{CollectionHelpersEvents, static_property::key},
- eth::{self, map_eth_to_id, collection_id_to_address},
- Pallet as PalletCommon, CollectionHandle,
+ erc::{static_property::key, CollectionHelpersEvents},
+ eth::{self, collection_id_to_address, map_eth_to_id},
+ CollectionById, CollectionHandle, Pallet as PalletCommon,
};
use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};
use pallet_evm_coder_substrate::{
- dispatch_to_evm, SubstrateRecorder, WithRecorder,
- execution::{PreDispatch, Result, Error},
- frontier_contract,
+ dispatch_to_evm,
+ execution::{Error, PreDispatch, Result},
+ frontier_contract, SubstrateRecorder, WithRecorder,
};
+use sp_std::vec::Vec;
use up_data_structs::{
CollectionDescription, CollectionMode, CollectionName, CollectionPermissions,
CollectionTokenPrefix, CreateCollectionData, NestingPermissions,
};
use crate::{weights::WeightInfo, Config, Pallet, SelfWeightOf};
-
-use alloc::{format, collections::BTreeSet};
-use sp_std::vec::Vec;
frontier_contract! {
macro_rules! EvmCollectionHelpers_result {...}
pallets/unique/src/lib.rsdiffbeforeafterboth--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -73,9 +73,9 @@
extern crate alloc;
-pub use pallet::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
+pub use pallet::*;
pub mod eth;
#[cfg(feature = "runtime-benchmarks")]
@@ -84,27 +84,27 @@
#[frame_support::pallet]
pub mod pallet {
- use super::*;
-
- use frame_support::{dispatch::DispatchResult, ensure, fail, BoundedVec, storage::Key};
+ use frame_support::{dispatch::DispatchResult, ensure, fail, storage::Key, BoundedVec};
+ use frame_system::{ensure_root, ensure_signed};
+ use pallet_common::{
+ dispatch::{dispatch_tx, CollectionDispatch},
+ CollectionHandle, CommonWeightInfo, Pallet as PalletCommon, RefungibleExtensionsWeightInfo,
+ };
+ use pallet_evm::account::CrossAccountId;
use scale_info::TypeInfo;
- use frame_system::{ensure_signed, ensure_root};
use sp_std::{vec, vec::Vec};
use up_data_structs::{
- MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
- MAX_PROPERTIES_PER_ITEM, MAX_PROPERTY_KEY_LENGTH, MAX_PROPERTY_VALUE_LENGTH,
- MAX_COLLECTION_PROPERTIES_SIZE, COLLECTION_ADMINS_LIMIT, MAX_TOKEN_PROPERTIES_SIZE,
- CreateItemData, CollectionLimits, CollectionPermissions, CollectionId, CollectionMode,
- TokenId, CreateCollectionData, CreateItemExData, budget, Property, PropertyKey,
- PropertyKeyPermission,
- };
- use pallet_evm::account::CrossAccountId;
- use pallet_common::{
- CollectionHandle, Pallet as PalletCommon, CommonWeightInfo, dispatch::dispatch_tx,
- dispatch::CollectionDispatch, RefungibleExtensionsWeightInfo,
+ budget, CollectionId, CollectionLimits, CollectionMode, CollectionPermissions,
+ CreateCollectionData, CreateItemData, CreateItemExData, Property, PropertyKey,
+ PropertyKeyPermission, TokenId, COLLECTION_ADMINS_LIMIT, MAX_COLLECTION_DESCRIPTION_LENGTH,
+ MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_PROPERTIES_SIZE, MAX_PROPERTIES_PER_ITEM,
+ MAX_PROPERTY_KEY_LENGTH, MAX_PROPERTY_VALUE_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
+ MAX_TOKEN_PROPERTIES_SIZE,
};
use weights::WeightInfo;
+ use super::*;
+
/// A maximum number of levels of depth in the token nesting tree.
pub const NESTING_BUDGET: u32 = 5;
primitives/app_promotion_rpc/src/lib.rsdiffbeforeafterboth--- a/primitives/app_promotion_rpc/src/lib.rs
+++ b/primitives/app_promotion_rpc/src/lib.rs
@@ -16,12 +16,12 @@
#![cfg_attr(not(feature = "std"), no_std)]
-use sp_std::vec::Vec;
-use codec::Decode;
+use parity_scale_codec::Decode;
use sp_runtime::{
+ traits::{AtLeast32BitUnsigned, Member},
DispatchError,
- traits::{AtLeast32BitUnsigned, Member},
};
+use sp_std::vec::Vec;
type Result<T> = core::result::Result<T, DispatchError>;
primitives/common/src/constants.rsdiffbeforeafterboth--- a/primitives/common/src/constants.rs
+++ b/primitives/common/src/constants.rs
@@ -14,13 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use sp_runtime::Perbill;
+use cumulus_primitives_core::relay_chain::MAX_POV_SIZE;
use frame_support::{
parameter_types,
- weights::{Weight, constants::WEIGHT_REF_TIME_PER_SECOND},
+ weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
};
-use cumulus_primitives_core::relay_chain::MAX_POV_SIZE;
-use crate::types::{BlockNumber, Balance};
+use sp_runtime::Perbill;
+
+use crate::types::{Balance, BlockNumber};
pub const MILLISECS_PER_BLOCK: u64 = 12000;
pub const MILLISECS_PER_RELAY_BLOCK: u64 = 6000;
primitives/common/src/types.rsdiffbeforeafterboth--- a/primitives/common/src/types.rs
+++ b/primitives/common/src/types.rs
@@ -16,7 +16,7 @@
use sp_runtime::{
generic,
- traits::{Verify, IdentifyAccount},
+ traits::{IdentifyAccount, Verify},
MultiSignature,
};
@@ -27,7 +27,7 @@
pub mod opaque {
pub use sp_runtime::{generic, traits::BlakeTwo256, OpaqueExtrinsic as UncheckedExtrinsic};
- pub use super::{BlockNumber, Signature, AccountId, Balance, Index, Hash, AuraId};
+ pub use super::{AccountId, AuraId, Balance, BlockNumber, Hash, Signature};
#[derive(Debug, Clone)]
pub enum RuntimeId {
primitives/data-structs/src/bounded.rsdiffbeforeafterboth--- a/primitives/data-structs/src/bounded.rs
+++ b/primitives/data-structs/src/bounded.rs
@@ -17,13 +17,15 @@
//! This module contins implementations for support bounded structures ([`BoundedVec`], [`BoundedBTreeMap`], [`BoundedBTreeSet`]) in [`serde`].
use core::fmt;
-use sp_std::collections::{btree_map::BTreeMap, btree_set::BTreeSet};
-use sp_std::vec::Vec;
use frame_support::{
+ storage::{bounded_btree_map::BoundedBTreeMap, bounded_btree_set::BoundedBTreeSet},
BoundedVec,
- storage::{bounded_btree_map::BoundedBTreeMap, bounded_btree_set::BoundedBTreeSet},
};
+use sp_std::{
+ collections::{btree_map::BTreeMap, btree_set::BTreeSet},
+ vec::Vec,
+};
/// [`serde`] implementations for [`BoundedVec`].
pub mod vec_serde {
primitives/data-structs/src/lib.rsdiffbeforeafterboth--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -25,20 +25,21 @@
fmt,
ops::Deref,
};
-use frame_support::storage::{bounded_btree_map::BoundedBTreeMap, bounded_btree_set::BoundedBTreeSet};
-#[cfg(feature = "serde")]
-use serde::{Serialize, Deserialize};
-
-use sp_core::U256;
-use sp_runtime::{ArithmeticError, sp_std::prelude::Vec};
-use sp_std::collections::btree_set::BTreeSet;
-use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};
-use frame_support::{BoundedVec, traits::ConstU32};
+use bondrewd::Bitfields;
use derivative::Derivative;
-use scale_info::TypeInfo;
use evm_coder::AbiCoderFlags;
-use bondrewd::Bitfields;
+use frame_support::{
+ storage::{bounded_btree_map::BoundedBTreeMap, bounded_btree_set::BoundedBTreeSet},
+ traits::ConstU32,
+ BoundedVec,
+};
+use parity_scale_codec::{Decode, Encode, EncodeLike, MaxEncodedLen};
+use scale_info::TypeInfo;
+use serde::{Deserialize, Serialize};
+use sp_core::U256;
+use sp_runtime::{sp_std::prelude::Vec, ArithmeticError};
+use sp_std::collections::btree_set::BTreeSet;
mod bondrewd_codec;
mod bounded;
primitives/data-structs/src/mapping.rsdiffbeforeafterboth--- a/primitives/data-structs/src/mapping.rs
+++ b/primitives/data-structs/src/mapping.rs
@@ -18,10 +18,10 @@
use core::marker::PhantomData;
+use pallet_evm::account::CrossAccountId;
use sp_core::H160;
use crate::{CollectionId, TokenId};
-use pallet_evm::account::CrossAccountId;
/// Trait for mapping between token id and some `Address`.
pub trait TokenAddressMapping<Address> {
primitives/data-structs/src/migration.rsdiffbeforeafterboth--- a/primitives/data-structs/src/migration.rs
+++ b/primitives/data-structs/src/migration.rs
@@ -17,8 +17,9 @@
/// Storage migration is not required for this change, as SponsoringRateLimit has same encoding as Option<u32>
#[test]
fn sponsoring_rate_limit_has_same_encoding_as_option_u32() {
+ use parity_scale_codec::Encode;
+
use crate::SponsoringRateLimit;
- use codec::Encode;
fn limit_to_option(limit: SponsoringRateLimit) -> Option<u32> {
match limit {
@@ -41,8 +42,9 @@
#[test]
fn collection_flags_have_same_encoding_as_bool() {
+ use parity_scale_codec::Encode;
+
use crate::CollectionFlags;
- use codec::Encode;
assert_eq!(
true.encode(),
primitives/pov-estimate-rpc/src/lib.rsdiffbeforeafterboth--- a/primitives/pov-estimate-rpc/src/lib.rs
+++ b/primitives/pov-estimate-rpc/src/lib.rs
@@ -17,12 +17,10 @@
#![cfg_attr(not(feature = "std"), no_std)]
use scale_info::TypeInfo;
-use sp_std::vec::Vec;
-
#[cfg(feature = "std")]
use serde::Serialize;
-
use sp_runtime::ApplyExtrinsicResult;
+use sp_std::vec::Vec;
#[cfg_attr(feature = "std", derive(Serialize))]
#[derive(Debug, TypeInfo)]
primitives/rpc/src/lib.rsdiffbeforeafterboth--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -18,14 +18,13 @@
extern crate alloc;
+use parity_scale_codec::Decode;
+use sp_runtime::DispatchError;
+use sp_std::vec::Vec;
use up_data_structs::{
- CollectionId, TokenId, RawEncoded, RpcCollection, CollectionStats, CollectionLimits, Property,
- PropertyKeyPermission, TokenData, TokenChild, TokenDataVersion1,
+ CollectionId, CollectionLimits, CollectionStats, Property, PropertyKeyPermission,
+ RpcCollection, TokenChild, TokenData, TokenId,
};
-
-use sp_std::vec::Vec;
-use codec::Decode;
-use sp_runtime::DispatchError;
type Result<T> = core::result::Result<T, DispatchError>;
runtime/common/config/ethereum.rsdiffbeforeafterboth--- a/runtime/common/config/ethereum.rs
+++ b/runtime/common/config/ethereum.rs
@@ -1,22 +1,24 @@
-use sp_core::{U256, H160};
use frame_support::{
- weights::{Weight, constants::WEIGHT_REF_TIME_PER_SECOND},
- traits::{FindAuthor},
- parameter_types, ConsensusEngineId,
+ parameter_types,
+ traits::FindAuthor,
+ weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
+ ConsensusEngineId,
};
-use sp_runtime::{RuntimeAppPublic, Perbill, traits::ConstU32};
+use pallet_ethereum::PostLogContent;
+use pallet_evm::{EnsureAddressTruncated, HashedAddressMapping};
+use sp_core::{H160, U256};
+use sp_runtime::{traits::ConstU32, Perbill, RuntimeAppPublic};
+use up_common::constants::*;
+
use crate::{
runtime_common::{
config::sponsoring::DefaultSponsoringRateLimit,
- DealWithFees,
dispatch::CollectionDispatchT,
ethereum::{precompiles::UniquePrecompiles, sponsoring::EvmSponsorshipHandler},
+ DealWithFees,
},
- Runtime, Aura, Balances, RuntimeEvent, ChainId,
+ Aura, Balances, ChainId, Runtime, RuntimeEvent,
};
-use pallet_evm::{EnsureAddressTruncated, HashedAddressMapping};
-use pallet_ethereum::PostLogContent;
-use up_common::constants::*;
pub type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Runtime>;
runtime/common/config/governance/fellowship.rsdiffbeforeafterboth--- a/runtime/common/config/governance/fellowship.rs
+++ b/runtime/common/config/governance/fellowship.rs
@@ -1,8 +1,11 @@
-use crate::{Preimage, Treasury, RuntimeCall, RuntimeEvent, Scheduler, FellowshipReferenda, Runtime};
-use super::*;
use pallet_gov_origins::Origin as GovOrigins;
use pallet_ranked_collective::{Config as RankedConfig, Rank, TallyOf};
+use super::*;
+use crate::{
+ FellowshipReferenda, Preimage, Runtime, RuntimeCall, RuntimeEvent, Scheduler, Treasury,
+};
+
pub const FELLOWSHIP_MODULE_ID: PalletId = PalletId(*b"flowship");
pub const DEMOCRACY_TRACK_ID: u16 = 10;
runtime/common/config/governance/mod.rsdiffbeforeafterboth--- a/runtime/common/config/governance/mod.rs
+++ b/runtime/common/config/governance/mod.rs
@@ -15,29 +15,31 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use frame_support::{
- PalletId, parameter_types,
+ pallet_prelude::*,
+ parameter_types,
traits::{
- EnsureOrigin, EqualPrivilegeOnly, EitherOfDiverse, EitherOf, MapSuccess, ConstU16, Polling,
+ ConstU16, EitherOf, EitherOfDiverse, EnsureOrigin, EqualPrivilegeOnly, MapSuccess, Polling,
},
weights::Weight,
- pallet_prelude::*,
+ PalletId,
};
-use frame_system::{EnsureRoot, EnsureNever};
+use frame_system::{EnsureNever, EnsureRoot};
+use pallet_collective::EnsureProportionAtLeast;
use sp_runtime::{
+ morph_types,
+ traits::{AccountIdConversion, CheckedSub, ConstU32, Convert, Replace},
Perbill,
- traits::{AccountIdConversion, ConstU32, Replace, CheckedSub, Convert},
- morph_types,
};
-use crate::{
- Runtime, RuntimeOrigin, RuntimeEvent, RuntimeCall, OriginCaller, Preimage, Balances, Treasury,
- Scheduler, Council, TechnicalCommittee,
-};
pub use up_common::{
- constants::{UNIQUE, DAYS, HOURS, MINUTES, CENTIUNIQUE},
+ constants::{CENTIUNIQUE, DAYS, HOURS, MINUTES, UNIQUE},
types::{AccountId, Balance, BlockNumber},
};
-use pallet_collective::EnsureProportionAtLeast;
+use crate::{
+ Balances, Council, OriginCaller, Preimage, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin,
+ Scheduler, TechnicalCommittee, Treasury,
+};
+
pub mod council;
pub use council::*;
runtime/common/config/orml.rsdiffbeforeafterboth--- a/runtime/common/config/orml.rs
+++ b/runtime/common/config/orml.rs
@@ -20,26 +20,26 @@
};
use frame_system::EnsureSigned;
use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key};
+use pallet_foreign_assets::{CurrencyId, NativeCurrency};
use sp_runtime::traits::Convert;
-use xcm::latest::{Weight, Junction::*, Junctions::*, MultiLocation};
-use xcm_executor::XcmExecutor;
use sp_std::{vec, vec::Vec};
-use pallet_foreign_assets::{CurrencyId, NativeCurrency};
+use staging_xcm::latest::{Junction::*, Junctions::*, MultiLocation, Weight};
+use staging_xcm_executor::XcmExecutor;
+use up_common::{
+ constants::*,
+ types::{AccountId, Balance},
+};
+
use crate::{
- Runtime, RuntimeEvent, RelayChainBlockNumberProvider,
runtime_common::config::{
+ pallets::TreasuryAccountId,
+ substrate::{MaxLocks, MaxReserves},
xcm::{
- SelfLocation, Weigher, XcmExecutorConfig, UniversalLocation,
- xcm_assets::{CurrencyIdConvert},
+ xcm_assets::CurrencyIdConvert, SelfLocation, UniversalLocation, Weigher,
+ XcmExecutorConfig,
},
- pallets::TreasuryAccountId,
- substrate::{MaxLocks, MaxReserves},
},
-};
-
-use up_common::{
- types::{AccountId, Balance},
- constants::*,
+ RelayChainBlockNumberProvider, Runtime, RuntimeEvent,
};
// Signed version of balance
runtime/common/config/pallets/app_promotion.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/app_promotion.rs
+++ b/runtime/common/config/pallets/app_promotion.rs
@@ -14,18 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use crate::{
- runtime_common::config::pallets::{TreasuryAccountId, RelayChainBlockNumberProvider},
- Runtime, Balances, BlockNumber, Unique, RuntimeEvent, EvmContractHelpers, Maintenance,
-};
-
use frame_support::{parameter_types, PalletId};
use sp_arithmetic::Perbill;
use up_common::{
- constants::{UNIQUE, DAYS, RELAY_DAYS},
+ constants::{DAYS, RELAY_DAYS, UNIQUE},
types::Balance,
};
+use crate::{
+ runtime_common::config::pallets::{RelayChainBlockNumberProvider, TreasuryAccountId},
+ Balances, BlockNumber, EvmContractHelpers, Maintenance, Runtime, RuntimeEvent, Unique,
+};
+
parameter_types! {
pub const AppPromotionId: PalletId = PalletId(*b"appstake");
pub const RecalculationInterval: BlockNumber = RELAY_DAYS;
runtime/common/config/pallets/collator_selection.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/collator_selection.rs
+++ b/runtime/common/config/pallets/collator_selection.rs
@@ -15,23 +15,21 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use frame_support::{parameter_types, PalletId};
-use crate::{
- Balance, Balances, BlockNumber, Runtime, RuntimeEvent, Aura, Session, SessionKeys,
- CollatorSelection, Treasury,
- config::pallets::{MaxCollators, SessionPeriod, TreasuryAccountId},
+#[cfg(not(feature = "governance"))]
+use frame_system::EnsureRoot;
+use pallet_configuration::{
+ CollatorSelectionDesiredCollatorsOverride, CollatorSelectionKickThresholdOverride,
+ CollatorSelectionLicenseBondOverride,
};
+use sp_runtime::Perbill;
+use up_common::constants::{MILLIUNIQUE, UNIQUE};
#[cfg(feature = "governance")]
use crate::config::governance;
-
-#[cfg(not(feature = "governance"))]
-use frame_system::EnsureRoot;
-
-use sp_runtime::Perbill;
-use up_common::constants::{UNIQUE, MILLIUNIQUE};
-use pallet_configuration::{
- CollatorSelectionKickThresholdOverride, CollatorSelectionLicenseBondOverride,
- CollatorSelectionDesiredCollatorsOverride,
+use crate::{
+ config::pallets::{MaxCollators, SessionPeriod, TreasuryAccountId},
+ Aura, Balance, Balances, BlockNumber, CollatorSelection, Runtime, RuntimeEvent,
+ RuntimeHoldReason, Session, SessionKeys, Treasury,
};
parameter_types! {
pub const SessionOffset: BlockNumber = 0;
runtime/common/config/pallets/foreign_asset.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/foreign_asset.rs
+++ b/runtime/common/config/pallets/foreign_asset.rs
@@ -1,6 +1,7 @@
-use crate::{Runtime, RuntimeEvent, Balances};
use up_common::types::AccountId;
+use crate::{Balances, Runtime, RuntimeEvent};
+
impl pallet_foreign_assets::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
runtime/common/config/pallets/mod.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -15,29 +15,30 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use alloc::string::{String, ToString};
-use frame_support::parameter_types;
+
+use frame_support::{
+ parameter_types,
+ traits::{ConstU32, ConstU64, Currency},
+};
+use sp_arithmetic::Perbill;
use sp_runtime::traits::AccountIdConversion;
+use up_common::{
+ constants::*,
+ types::{AccountId, Balance, BlockNumber},
+};
+use up_data_structs::mapping::{CrossTokenAddressMapping, EvmTokenAddressMapping};
+
+#[cfg(feature = "governance")]
+use crate::runtime_common::config::governance;
use crate::{
runtime_common::{
+ config::{ethereum::EvmCollectionHelpersAddress, substrate::TreasuryModuleId},
dispatch::CollectionDispatchT,
- config::{substrate::TreasuryModuleId, ethereum::EvmCollectionHelpersAddress},
weights::CommonWeights,
RelayChainBlockNumberProvider,
},
- Runtime, RuntimeEvent, RuntimeCall, VERSION, TOKEN_SYMBOL, DECIMALS, Balances,
-};
-use frame_support::traits::{ConstU32, ConstU64, Currency};
-use up_common::{
- types::{AccountId, Balance, BlockNumber},
- constants::*,
-};
-use up_data_structs::{
- mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping},
+ Balances, Runtime, RuntimeCall, RuntimeEvent, DECIMALS, TOKEN_SYMBOL, VERSION,
};
-use sp_arithmetic::Perbill;
-
-#[cfg(feature = "governance")]
-use crate::runtime_common::config::governance;
#[cfg(feature = "unique-scheduler")]
pub mod scheduler;
runtime/common/config/pallets/preimage.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/preimage.rs
+++ b/runtime/common/config/pallets/preimage.rs
@@ -16,9 +16,10 @@
use frame_support::parameter_types;
use frame_system::EnsureRoot;
-use crate::{AccountId, Balance, Balances, Runtime, RuntimeEvent};
use up_common::constants::*;
+use crate::{AccountId, Balance, Balances, Runtime, RuntimeEvent};
+
parameter_types! {
pub PreimageBaseDeposit: Balance = 1000 * UNIQUE;
}
runtime/common/config/pallets/scheduler.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/scheduler.rs
+++ b/runtime/common/config/pallets/scheduler.rs
@@ -14,21 +14,23 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+use core::cmp::Ordering;
+
use frame_support::{
- traits::{PrivilegeCmp, EnsureOrigin},
- weights::Weight,
parameter_types,
+ traits::{EnsureOrigin, PrivilegeCmp},
+ weights::Weight,
};
use frame_system::{EnsureRoot, RawOrigin};
+use pallet_unique_scheduler_v2::ScheduledEnsureOriginSuccess;
+use parity_scale_codec::Decode;
use sp_runtime::Perbill;
-use core::cmp::Ordering;
-use codec::Decode;
+use up_common::types::AccountId;
+
use crate::{
- runtime_common::{scheduler::SchedulerPaymentExecutor, config::substrate::RuntimeBlockWeights},
- Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, OriginCaller,
+ runtime_common::{config::substrate::RuntimeBlockWeights, scheduler::SchedulerPaymentExecutor},
+ OriginCaller, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin,
};
-use pallet_unique_scheduler_v2::ScheduledEnsureOriginSuccess;
-use up_common::types::AccountId;
parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(50) *
runtime/common/config/parachain.rsdiffbeforeafterboth--- a/runtime/common/config/parachain.rs
+++ b/runtime/common/config/parachain.rs
@@ -14,10 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use frame_support::{weights::Weight, parameter_types};
-use crate::{Runtime, RuntimeEvent, XcmpQueue, DmpQueue};
+use frame_support::{parameter_types, weights::Weight};
use up_common::constants::*;
+use crate::{DmpQueue, Runtime, RuntimeEvent, XcmpQueue};
+
parameter_types! {
pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
runtime/common/config/sponsoring.rsdiffbeforeafterboth--- a/runtime/common/config/sponsoring.rs
+++ b/runtime/common/config/sponsoring.rs
@@ -14,14 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use crate::{
- runtime_common::{sponsoring::UniqueSponsorshipHandler},
- Runtime,
-};
use frame_support::parameter_types;
use sp_core::U256;
use up_common::{constants::*, types::BlockNumber};
+use crate::{runtime_common::sponsoring::UniqueSponsorshipHandler, Runtime};
+
parameter_types! {
pub const DefaultSponsoringRateLimit: BlockNumber = 1 * DAYS;
pub const DefaultSponsoringFeeLimit: U256 = U256::MAX;
runtime/common/config/substrate.rsdiffbeforeafterboth--- a/runtime/common/config/substrate.rs
+++ b/runtime/common/config/substrate.rs
@@ -15,31 +15,32 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use frame_support::{
- traits::{Everything, ConstU32, NeverEnsureOrigin},
+ dispatch::DispatchClass,
+ ord_parameter_types, parameter_types,
+ traits::{ConstBool, ConstU32, Everything, NeverEnsureOrigin},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight},
ConstantMultiplier,
},
- dispatch::DispatchClass,
- parameter_types, ord_parameter_types, PalletId,
-};
-use sp_runtime::{
- generic,
- traits::{BlakeTwo256, AccountIdLookup},
- Perbill, Permill, Percent,
+ PalletId,
};
-use sp_arithmetic::traits::One;
use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot, EnsureSignedBy,
};
-use pallet_transaction_payment::{Multiplier, ConstFeeMultiplier};
-use crate::{
- runtime_common::DealWithFees, Runtime, RuntimeEvent, RuntimeCall, RuntimeOrigin, OriginCaller,
- PalletInfo, System, Balances, SS58Prefix, Version,
+use pallet_transaction_payment::{ConstFeeMultiplier, Multiplier};
+use sp_arithmetic::traits::One;
+use sp_runtime::{
+ traits::{AccountIdLookup, BlakeTwo256},
+ Perbill, Percent, Permill,
};
-use up_common::{types::*, constants::*};
use sp_std::vec;
+use up_common::{constants::*, types::*};
+
+use crate::{
+ runtime_common::DealWithFees, Balances, Block, OriginCaller, PalletInfo, Runtime, RuntimeCall,
+ RuntimeEvent, RuntimeHoldReason, RuntimeOrigin, SS58Prefix, System, Version,
+};
parameter_types! {
pub const BlockHashCount: BlockNumber = 2400;
runtime/common/config/test_pallets.rsdiffbeforeafterboth--- a/runtime/common/config/test_pallets.rs
+++ b/runtime/common/config/test_pallets.rs
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use crate::{Runtime, RuntimeEvent, RuntimeCall};
+use crate::{Runtime, RuntimeCall, RuntimeEvent};
impl pallet_test_utils::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
runtime/common/config/xcm/foreignassets.rsdiffbeforeafterboth--- a/runtime/common/config/xcm/foreignassets.rs
+++ b/runtime/common/config/xcm/foreignassets.rs
@@ -14,23 +14,22 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use frame_support::{traits::Get, parameter_types};
-use sp_runtime::traits::Convert;
-use xcm::latest::{prelude::*, MultiAsset, MultiLocation};
-use xcm_builder::{FungiblesAdapter, NoChecking, ConvertedConcreteId};
-use xcm_executor::traits::{TransactAsset, Convert as ConvertXcm, JustTry};
-use pallet_foreign_assets::{
- AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, NativeCurrency, FreeForAll, TryAsForeign,
- ForeignAssetId, CurrencyId,
-};
-use sp_std::{borrow::Borrow, marker::PhantomData};
+use frame_support::{parameter_types, traits::Get};
use orml_traits::location::AbsoluteReserveProvider;
use orml_xcm_support::MultiNativeAsset;
-use crate::{Runtime, Balances, ParachainInfo, PolkadotXcm, ForeignAssets};
+use pallet_foreign_assets::{
+ AssetId, AssetIdMapping, CurrencyId, ForeignAssetId, FreeForAll, NativeCurrency, TryAsForeign,
+ XcmForeignAssetIdMapping,
+};
+use sp_runtime::traits::{Convert, MaybeEquivalence};
+use sp_std::marker::PhantomData;
+use staging_xcm::latest::{prelude::*, MultiAsset, MultiLocation};
+use staging_xcm_builder::{ConvertedConcreteId, FungiblesAdapter, NoChecking};
+use staging_xcm_executor::traits::{JustTry, TransactAsset};
+use up_common::types::{AccountId, Balance};
use super::{LocationToAccountId, RelayLocation};
-
-use up_common::types::{AccountId, Balance};
+use crate::{Balances, ForeignAssets, ParachainInfo, PolkadotXcm, Runtime};
parameter_types! {
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
runtime/common/config/xcm/mod.rsdiffbeforeafterboth--- a/runtime/common/config/xcm/mod.rs
+++ b/runtime/common/config/xcm/mod.rs
@@ -15,28 +15,33 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use frame_support::{
- traits::{Everything, Nothing, Get, ConstU32, ProcessMessageError, Contains},
parameter_types,
+ traits::{ConstU32, Contains, Everything, Get, Nothing, ProcessMessageError},
};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
-use polkadot_parachain::primitives::Sibling;
-use xcm::latest::{prelude::*, Weight, MultiLocation};
-use xcm::v3::Instruction;
-use xcm_builder::{
- AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, ParentAsSuperuser, RelayChainAsNative,
- SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
- SignedToAccountId32, SovereignSignedViaLocation, ParentIsPreset,
-};
-use xcm_executor::{XcmExecutor, traits::ShouldExecute};
+use polkadot_parachain_primitives::primitives::Sibling;
use sp_std::marker::PhantomData;
-use crate::{
- Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, ParachainInfo, ParachainSystem, PolkadotXcm,
- XcmpQueue, xcm_barrier::Barrier, RelayNetwork, AllPalletsWithSystem, Balances,
+use staging_xcm::{
+ latest::{prelude::*, MultiLocation, Weight},
+ v3::Instruction,
+};
+use staging_xcm_builder::{
+ AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, ParentAsSuperuser, ParentIsPreset,
+ RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
+ SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
+};
+use staging_xcm_executor::{
+ traits::{Properties, ShouldExecute},
+ XcmExecutor,
};
-
use up_common::types::AccountId;
+use crate::{
+ xcm_barrier::Barrier, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem,
+ PolkadotXcm, RelayNetwork, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, XcmpQueue,
+};
+
#[cfg(feature = "foreign-assets")]
pub mod foreignassets;
@@ -45,14 +50,12 @@
#[cfg(feature = "foreign-assets")]
pub use foreignassets as xcm_assets;
-
#[cfg(not(feature = "foreign-assets"))]
pub use nativeassets as xcm_assets;
+use xcm_assets::{AssetTransactor, IsReserve, Trader};
#[cfg(feature = "governance")]
use crate::runtime_common::config::governance;
-
-use xcm_assets::{AssetTransactor, IsReserve, Trader};
parameter_types! {
pub const RelayLocation: MultiLocation = MultiLocation::parent();
runtime/common/config/xcm/nativeassets.rsdiffbeforeafterboth--- a/runtime/common/config/xcm/nativeassets.rs
+++ b/runtime/common/config/xcm/nativeassets.rs
@@ -14,31 +14,28 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+use cumulus_primitives_core::XcmContext;
use frame_support::{
- traits::{tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Get},
+ traits::{tokens::currency::Currency as CurrencyT, Get, OnUnbalanced as OnUnbalancedT},
weights::WeightToFeePolynomial,
};
-use sp_runtime::traits::{CheckedConversion, Zero, Convert};
-use xcm::latest::{
- AssetId::{Concrete},
- Fungibility::Fungible as XcmFungible,
- MultiAsset, Error as XcmError, Weight,
- Junction::*,
- MultiLocation,
- Junctions::*,
+use pallet_foreign_assets::{AssetIds, NativeCurrency};
+use sp_runtime::traits::{CheckedConversion, Convert, Zero};
+use sp_std::marker::PhantomData;
+use staging_xcm::latest::{
+ AssetId::Concrete, Error as XcmError, Fungibility::Fungible as XcmFungible, Junction::*,
+ Junctions::*, MultiAsset, MultiLocation, Weight,
};
-use xcm_builder::{CurrencyAdapter, NativeAsset};
-use xcm_executor::{
+use staging_xcm_builder::{CurrencyAdapter, NativeAsset};
+use staging_xcm_executor::{
+ traits::{MatchesFungible, WeightTrader},
Assets,
- traits::{MatchesFungible, WeightTrader},
};
-use pallet_foreign_assets::{AssetIds, NativeCurrency};
-use sp_std::marker::PhantomData;
-use crate::{Balances, ParachainInfo};
-use super::{LocationToAccountId, RelayLocation};
-
use up_common::types::{AccountId, Balance};
+use super::{LocationToAccountId, RelayLocation};
+use crate::{Balances, ParachainInfo};
+
pub struct OnlySelfCurrency;
impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {
fn matches_fungible(a: &MultiAsset) -> Option<B> {
runtime/common/dispatch.rsdiffbeforeafterboth--- a/runtime/common/dispatch.rs
+++ b/runtime/common/dispatch.rs
@@ -15,28 +15,27 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use frame_support::{dispatch::DispatchResult, ensure, fail};
-use pallet_evm::{PrecompileHandle, PrecompileResult};
-use sp_core::H160;
-use sp_runtime::DispatchError;
-use sp_std::{borrow::ToOwned, vec::Vec};
+use pallet_balances_adapter::NativeFungibleHandle;
+pub use pallet_common::dispatch::CollectionDispatch;
+#[cfg(not(feature = "refungible"))]
+use pallet_common::unsupported;
use pallet_common::{
- CollectionById, CollectionHandle, CommonCollectionOperations, erc::CommonEvmHandler,
- eth::map_eth_to_id,
+ erc::CommonEvmHandler, eth::map_eth_to_id, CollectionById, CollectionHandle,
+ CommonCollectionOperations,
};
-pub use pallet_common::dispatch::CollectionDispatch;
-use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};
-use pallet_balances_adapter::NativeFungibleHandle;
-use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};
+use pallet_evm::{PrecompileHandle, PrecompileResult};
+use pallet_fungible::{FungibleHandle, Pallet as PalletFungible};
+use pallet_nonfungible::{NonfungibleHandle, Pallet as PalletNonfungible};
use pallet_refungible::{
- Pallet as PalletRefungible, RefungibleHandle, erc_token::RefungibleTokenHandle,
+ erc_token::RefungibleTokenHandle, Pallet as PalletRefungible, RefungibleHandle,
};
+use sp_core::H160;
+use sp_runtime::DispatchError;
+use sp_std::{borrow::ToOwned, vec::Vec};
use up_data_structs::{
- CollectionMode, CreateCollectionData, MAX_DECIMAL_POINTS, mapping::TokenAddressMapping,
- CollectionId,
+ mapping::TokenAddressMapping, CollectionId, CollectionMode, CreateCollectionData,
+ MAX_DECIMAL_POINTS,
};
-
-#[cfg(not(feature = "refungible"))]
-use pallet_common::unsupported;
pub enum CollectionDispatchT<T>
where
runtime/common/ethereum/precompiles/mod.rsdiffbeforeafterboth--- a/runtime/common/ethereum/precompiles/mod.rs
+++ b/runtime/common/ethereum/precompiles/mod.rs
@@ -14,11 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use pallet_evm::{Precompile, PrecompileHandle, PrecompileResult, PrecompileSet, IsPrecompileResult};
+use pallet_evm::{
+ IsPrecompileResult, Precompile, PrecompileHandle, PrecompileResult, PrecompileSet,
+};
+use pallet_evm_precompile_simple::ECRecover;
use sp_core::H160;
use sp_std::marker::PhantomData;
-
-use pallet_evm_precompile_simple::{ECRecover};
use sr25519::Sr25519Precompile;
mod sr25519;
runtime/common/ethereum/precompiles/sr25519.rsdiffbeforeafterboth--- a/runtime/common/ethereum/precompiles/sr25519.rs
+++ b/runtime/common/ethereum/precompiles/sr25519.rs
@@ -17,8 +17,7 @@
use fp_evm::{Context, ExitSucceed, PrecompileHandle, PrecompileOutput};
use pallet_evm::Precompile;
use sp_core::{crypto::UncheckedFrom, sr25519, H256};
-use sp_std::marker::PhantomData;
-use sp_std::prelude::*;
+use sp_std::{marker::PhantomData, prelude::*};
use super::utils::{Bytes, EvmDataReader, EvmDataWriter, EvmResult, FunctionModifier, Gasometer};
runtime/common/ethereum/precompiles/utils/data.rsdiffbeforeafterboth--- a/runtime/common/ethereum/precompiles/utils/data.rs
+++ b/runtime/common/ethereum/precompiles/utils/data.rs
@@ -16,12 +16,12 @@
// You should have received a copy of the GNU General Public License
// along with Utils. If not, see <http://www.gnu.org/licenses/>.
-use super::{EvmResult, Gasometer};
+use core::{any::type_name, ops::Range};
-use sp_std::borrow::ToOwned;
-use core::{any::type_name, ops::Range};
use sp_core::{H160, H256, U256};
-use sp_std::{convert::TryInto, vec, vec::Vec};
+use sp_std::{borrow::ToOwned, convert::TryInto, vec, vec::Vec};
+
+use super::{EvmResult, Gasometer};
/// The `address` type of Solidity.
/// H160 could represent 2 types of data (bytes20 and address) that are not encoded the same way.
runtime/common/ethereum/precompiles/utils/macro/src/lib.rsdiffbeforeafterboth--- a/runtime/common/ethereum/precompiles/utils/macro/src/lib.rs
+++ b/runtime/common/ethereum/precompiles/utils/macro/src/lib.rs
@@ -19,11 +19,12 @@
#![crate_type = "proc-macro"]
extern crate proc_macro;
+use std::convert::TryInto;
+
use proc_macro::TokenStream;
use proc_macro2::Literal;
use quote::{quote, quote_spanned};
use sha3::{Digest, Keccak256};
-use std::convert::TryInto;
use syn::{parse_macro_input, spanned::Spanned, Expr, ExprLit, Ident, ItemEnum, Lit};
/// This macro allows to associate to each variant of an enumeration a discriminant (of type u32
runtime/common/ethereum/precompiles/utils/mod.rsdiffbeforeafterboth--- a/runtime/common/ethereum/precompiles/utils/mod.rs
+++ b/runtime/common/ethereum/precompiles/utils/mod.rs
@@ -16,10 +16,9 @@
// You should have received a copy of the GNU General Public License
// along with Utils. If not, see <http://www.gnu.org/licenses/>.
-use sp_std::borrow::ToOwned;
use fp_evm::{Context, ExitRevert, PrecompileFailure};
use sp_core::U256;
-use sp_std::marker::PhantomData;
+use sp_std::{borrow::ToOwned, marker::PhantomData};
mod data;
runtime/common/ethereum/self_contained_call.rsdiffbeforeafterboth--- a/runtime/common/ethereum/self_contained_call.rs
+++ b/runtime/common/ethereum/self_contained_call.rs
@@ -16,11 +16,12 @@
use sp_core::H160;
use sp_runtime::{
- traits::{Dispatchable, DispatchInfoOf, PostDispatchInfoOf},
- transaction_validity::{TransactionValidityError, TransactionValidity, InvalidTransaction},
+ traits::{DispatchInfoOf, Dispatchable, PostDispatchInfoOf},
+ transaction_validity::{InvalidTransaction, TransactionValidity, TransactionValidityError},
};
-use crate::{RuntimeOrigin, RuntimeCall, Maintenance};
+use crate::{Maintenance, RuntimeCall, RuntimeOrigin};
+
impl fp_self_contained::SelfContainedCall for RuntimeCall {
type SignedInfo = H160;
runtime/common/ethereum/sponsoring.rsdiffbeforeafterboth--- a/runtime/common/ethereum/sponsoring.rs
+++ b/runtime/common/ethereum/sponsoring.rs
@@ -17,35 +17,36 @@
//! Implements EVM sponsoring logic via TransactionValidityHack
use core::{convert::TryInto, marker::PhantomData};
-use evm_coder::{Call};
-use pallet_common::{CollectionHandle, eth::map_eth_to_id};
+
+use evm_coder::Call;
+use pallet_common::{eth::map_eth_to_id, CollectionHandle};
use pallet_evm::account::CrossAccountId;
use pallet_evm_transaction_payment::CallContext;
+use pallet_fungible::{
+ erc::{ERC20Call, UniqueFungibleCall},
+ Config as FungibleConfig,
+};
use pallet_nonfungible::{
- Config as NonfungibleConfig, Pallet as NonfungiblePallet, NonfungibleHandle,
erc::{
- UniqueNFTCall, ERC721UniqueExtensionsCall, ERC721UniqueMintableCall, ERC721Call,
- TokenPropertiesCall,
+ ERC721Call, ERC721UniqueExtensionsCall, ERC721UniqueMintableCall, TokenPropertiesCall,
+ UniqueNFTCall,
},
-};
-use pallet_fungible::{
- Config as FungibleConfig,
- erc::{UniqueFungibleCall, ERC20Call},
+ Config as NonfungibleConfig, NonfungibleHandle, Pallet as NonfungiblePallet,
};
use pallet_refungible::{
- Config as RefungibleConfig,
erc::UniqueRefungibleCall,
erc_token::{RefungibleTokenHandle, UniqueRefungibleTokenCall},
- RefungibleHandle,
+ Config as RefungibleConfig, RefungibleHandle,
};
use pallet_unique::Config as UniqueConfig;
use sp_std::prelude::*;
use up_data_structs::{
- CollectionMode, CreateItemData, CreateNftData, mapping::TokenAddressMapping, TokenId,
+ mapping::TokenAddressMapping, CollectionMode, CreateItemData, CreateNftData, TokenId,
};
use up_sponsorship::SponsorshipHandler;
-use crate::{Runtime, runtime_common::sponsoring::*};
+use crate::{runtime_common::sponsoring::*, Runtime};
+
mod refungible;
pub type EvmSponsorshipHandler = (
@@ -206,9 +207,9 @@
}
mod common {
- use super::*;
+ use pallet_common::erc::CollectionCall;
- use pallet_common::erc::{CollectionCall};
+ use super::*;
pub fn collection_call_sponsor<T>(
call: CollectionCall<T>,
runtime/common/ethereum/sponsoring/refungible.rsdiffbeforeafterboth--- a/runtime/common/ethereum/sponsoring/refungible.rs
+++ b/runtime/common/ethereum/sponsoring/refungible.rs
@@ -19,14 +19,7 @@
use pallet_common::CollectionHandle;
use pallet_evm::account::CrossAccountId;
use pallet_fungible::Config as FungibleConfig;
-use pallet_refungible::Config as RefungibleConfig;
use pallet_nonfungible::Config as NonfungibleConfig;
-use pallet_unique::Config as UniqueConfig;
-use up_data_structs::{CreateItemData, CreateNftData, TokenId};
-
-use super::common;
-use crate::runtime_common::sponsoring::*;
-
use pallet_refungible::{
erc::{
ERC721BurnableCall, ERC721Call, ERC721EnumerableCall, ERC721MetadataCall,
@@ -37,7 +30,13 @@
ERC1633Call, ERC20Call, ERC20UniqueExtensionsCall, RefungibleTokenHandle,
UniqueRefungibleTokenCall,
},
+ Config as RefungibleConfig,
};
+use pallet_unique::Config as UniqueConfig;
+use up_data_structs::{CreateItemData, CreateNftData, TokenId};
+
+use super::common;
+use crate::runtime_common::sponsoring::*;
pub fn call_sponsor<T>(
call: UniqueRefungibleCall<T>,
runtime/common/identity.rsdiffbeforeafterboth--- a/runtime/common/identity.rs
+++ b/runtime/common/identity.rs
@@ -14,18 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
-use codec::{Encode, Decode};
-use up_common::types::AccountId;
-use crate::RuntimeCall;
-
+#[cfg(feature = "collator-selection")]
+use sp_runtime::transaction_validity::InvalidTransaction;
use sp_runtime::{
traits::{DispatchInfoOf, SignedExtension},
- transaction_validity::{TransactionValidity, ValidTransaction, TransactionValidityError},
+ transaction_validity::{TransactionValidity, TransactionValidityError, ValidTransaction},
};
+use up_common::types::AccountId;
-#[cfg(feature = "collator-selection")]
-use sp_runtime::transaction_validity::InvalidTransaction;
+use crate::RuntimeCall;
#[derive(Debug, Encode, Decode, PartialEq, Eq, Clone, TypeInfo)]
pub struct DisableIdentityCalls;
runtime/common/instance.rsdiffbeforeafterboth--- a/runtime/common/instance.rs
+++ b/runtime/common/instance.rs
@@ -1,9 +1,7 @@
-use crate::{
- runtime_common::{config::ethereum::CrossAccountId},
- Runtime,
-};
use up_common::types::opaque::RuntimeInstance;
+use crate::{runtime_common::config::ethereum::CrossAccountId, Runtime};
+
impl RuntimeInstance for Runtime {
type CrossAccountId = CrossAccountId;
}
runtime/common/maintenance.rsdiffbeforeafterboth--- a/runtime/common/maintenance.rs
+++ b/runtime/common/maintenance.rs
@@ -14,17 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
-use codec::{Encode, Decode};
-use up_common::types::AccountId;
-use crate::{RuntimeCall, Maintenance};
-
use sp_runtime::{
traits::{DispatchInfoOf, SignedExtension},
transaction_validity::{
- TransactionValidity, ValidTransaction, InvalidTransaction, TransactionValidityError,
+ InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransaction,
},
};
+use up_common::types::AccountId;
+
+use crate::{Maintenance, RuntimeCall};
#[derive(Debug, Encode, Decode, PartialEq, Eq, Clone, TypeInfo)]
pub struct CheckMaintenance;
runtime/common/mod.rsdiffbeforeafterboth--- a/runtime/common/mod.rs
+++ b/runtime/common/mod.rs
@@ -33,26 +33,23 @@
#[cfg(test)]
pub mod tests;
-use sp_core::H160;
use frame_support::{
- traits::{Currency, OnUnbalanced, Imbalance},
+ traits::{Currency, Imbalance, OnUnbalanced},
weights::Weight,
};
use sp_runtime::{
- generic,
+ generic, impl_opaque_keys,
traits::{BlakeTwo256, BlockNumberProvider},
- impl_opaque_keys,
};
use sp_std::vec::Vec;
-
#[cfg(feature = "std")]
use sp_version::NativeVersion;
+use up_common::types::{AccountId, BlockNumber};
use crate::{
- Runtime, RuntimeCall, Balances, Treasury, Aura, Signature, AllPalletsWithSystem,
- InherentDataExt,
+ AllPalletsWithSystem, Aura, Balances, InherentDataExt, Runtime, RuntimeCall, Signature,
+ Treasury,
};
-use up_common::types::{AccountId, BlockNumber};
#[macro_export]
macro_rules! unsupported {
@@ -175,7 +172,7 @@
}
}
-#[derive(codec::Encode, codec::Decode)]
+#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode)]
pub enum XCMPMessage<XAccountId, XBalance> {
/// Transfer tokens to the given account from the Parachain account.
TransferToken(XAccountId, XBalance),
@@ -186,9 +183,10 @@
fn on_runtime_upgrade() -> Weight {
#[cfg(feature = "collator-selection")]
{
- use frame_support::{BoundedVec, storage::migration};
- use sp_runtime::{traits::OpaqueKeys, RuntimeAppPublic};
+ use frame_support::{storage::migration, BoundedVec};
use pallet_session::SessionManager;
+ use sp_runtime::{traits::OpaqueKeys, RuntimeAppPublic};
+
use crate::config::pallets::MaxCollators;
let mut weight = <Runtime as frame_system::Config>::DbWeight::get().reads(1);
runtime/common/scheduler.rsdiffbeforeafterboth--- a/runtime/common/scheduler.rs
+++ b/runtime/common/scheduler.rs
@@ -14,21 +14,20 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use frame_support::{
- dispatch::{GetDispatchInfo, PostDispatchInfo, DispatchInfo},
-};
+use fp_self_contained::SelfContainedCall;
+use frame_support::dispatch::{DispatchInfo, GetDispatchInfo, PostDispatchInfo};
+use pallet_transaction_payment::ChargeTransactionPayment;
+use pallet_unique_scheduler_v2::DispatchCall;
+use parity_scale_codec::Encode;
use sp_runtime::{
- traits::{Dispatchable, Applyable, Member},
+ traits::{Applyable, Dispatchable, Member},
transaction_validity::TransactionValidityError,
DispatchErrorWithPostInfo,
};
-use codec::Encode;
-use crate::{Runtime, RuntimeCall, RuntimeOrigin, maintenance};
use up_common::types::AccountId;
-use fp_self_contained::SelfContainedCall;
-use pallet_unique_scheduler_v2::DispatchCall;
-use pallet_transaction_payment::ChargeTransactionPayment;
+use crate::{maintenance, Runtime, RuntimeCall, RuntimeOrigin};
+
/// The SignedExtension to the basic transaction logic.
pub type SignedExtraScheduler = (
frame_system::CheckWeight<Runtime>,
runtime/common/sponsoring.rsdiffbeforeafterboth--- a/runtime/common/sponsoring.rs
+++ b/runtime/common/sponsoring.rs
@@ -15,25 +15,25 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use core::marker::PhantomData;
-use up_sponsorship::SponsorshipHandler;
-use frame_support::{
- traits::{IsSubType},
-};
-use up_data_structs::{
- CollectionId, FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, NFT_SPONSOR_TRANSFER_TIMEOUT,
- REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, TokenId, CollectionMode, CreateItemData,
-};
-use sp_runtime::traits::Saturating;
-use pallet_common::{CollectionHandle};
+
+use frame_support::traits::IsSubType;
+use frame_system::pallet_prelude::*;
+use pallet_common::CollectionHandle;
use pallet_evm::account::CrossAccountId;
-use pallet_unique::{
- Call as UniqueCall, Config as UniqueConfig, FungibleApproveBasket, RefungibleApproveBasket,
- NftApproveBasket, CreateItemBasket, ReFungibleTransferBasket, FungibleTransferBasket,
- NftTransferBasket, TokenPropertyBasket,
-};
use pallet_fungible::Config as FungibleConfig;
use pallet_nonfungible::Config as NonfungibleConfig;
use pallet_refungible::Config as RefungibleConfig;
+use pallet_unique::{
+ Call as UniqueCall, Config as UniqueConfig, CreateItemBasket, FungibleApproveBasket,
+ FungibleTransferBasket, NftApproveBasket, NftTransferBasket, ReFungibleTransferBasket,
+ RefungibleApproveBasket, TokenPropertyBasket,
+};
+use sp_runtime::traits::Saturating;
+use up_data_structs::{
+ CollectionId, CollectionMode, CreateItemData, TokenId, FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
+ NFT_SPONSOR_TRANSFER_TIMEOUT, REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
+};
+use up_sponsorship::SponsorshipHandler;
pub trait Config: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig {}
impl<T> Config for T where T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig {}
runtime/common/tests/mod.rsdiffbeforeafterboth--- a/runtime/common/tests/mod.rs
+++ b/runtime/common/tests/mod.rs
@@ -14,12 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+use sp_core::{Pair, Public};
+pub use sp_runtime::AccountId32 as AccountId;
use sp_runtime::{BuildStorage, Storage};
-use sp_core::{Public, Pair};
use up_common::types::AuraId;
-use crate::{Runtime, GenesisConfig, ParachainInfoConfig, RuntimeEvent, System};
-pub use sp_runtime::AccountId32 as AccountId;
+use crate::{BuildGenesisConfig, ParachainInfoConfig, Runtime, RuntimeEvent, System};
pub type Balance = u128;
pub mod xcm;
@@ -62,10 +62,11 @@
#[cfg(feature = "collator-selection")]
fn make_basic_storage() -> Storage {
- use sp_core::{sr25519};
+ use sp_core::sr25519;
use sp_runtime::traits::{IdentifyAccount, Verify};
- use crate::{AccountId, Signature, SessionKeys, CollatorSelectionConfig, SessionConfig};
+ use crate::{AccountId, CollatorSelectionConfig, SessionConfig, SessionKeys, Signature};
+
type AccountPublic = <Signature as Verify>::Signer;
fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
runtime/common/tests/xcm.rsdiffbeforeafterboth--- a/runtime/common/tests/xcm.rs
+++ b/runtime/common/tests/xcm.rs
@@ -14,15 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use xcm::{
- VersionedXcm,
+use frame_support::pallet_prelude::Weight;
+use parity_scale_codec::Encode;
+use staging_xcm::{
latest::{prelude::*, Error},
+ VersionedXcm,
};
-use codec::Encode;
-use crate::{Runtime, RuntimeCall, RuntimeOrigin, RuntimeEvent, PolkadotXcm};
-use super::{new_test_ext, last_events, AccountId};
-use frame_support::{pallet_prelude::Weight};
+use super::{last_events, new_test_ext, AccountId};
+use crate::{PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin};
+
const ALICE: AccountId = AccountId::new([0u8; 32]);
const BOB: AccountId = AccountId::new([1u8; 32]);
runtime/common/weights/mod.rsdiffbeforeafterboth--- a/runtime/common/weights/mod.rs
+++ b/runtime/common/weights/mod.rs
@@ -15,20 +15,21 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use core::marker::PhantomData;
-use frame_support::{weights::Weight};
-use pallet_common::{CommonWeightInfo, dispatch::dispatch_weight, RefungibleExtensionsWeightInfo};
+use frame_support::weights::Weight;
use pallet_balances_adapter::{
- Config as NativeFungibleConfig, common::CommonWeights as NativeFungibleWeights,
+ common::CommonWeights as NativeFungibleWeights, Config as NativeFungibleConfig,
};
-use pallet_fungible::{Config as FungibleConfig, common::CommonWeights as FungibleWeights};
-use pallet_nonfungible::{Config as NonfungibleConfig, common::CommonWeights as NonfungibleWeights};
-
+use pallet_common::{dispatch::dispatch_weight, CommonWeightInfo, RefungibleExtensionsWeightInfo};
+use pallet_fungible::{common::CommonWeights as FungibleWeights, Config as FungibleConfig};
+use pallet_nonfungible::{
+ common::CommonWeights as NonfungibleWeights, Config as NonfungibleConfig,
+};
#[cfg(feature = "refungible")]
use pallet_refungible::{
- Config as RefungibleConfig, weights::WeightInfo, common::CommonWeights as RefungibleWeights,
+ common::CommonWeights as RefungibleWeights, weights::WeightInfo, Config as RefungibleConfig,
};
-use up_data_structs::{CreateItemExData, CreateItemData};
+use up_data_structs::{CreateItemData, CreateItemExData};
pub mod xcm;
runtime/opal/src/lib.rsdiffbeforeafterboth--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -27,14 +27,11 @@
extern crate alloc;
+use ::staging_xcm::latest::NetworkId;
use frame_support::parameter_types;
-
-use sp_version::RuntimeVersion;
use sp_runtime::create_runtime_str;
-
+use sp_version::RuntimeVersion;
use up_common::types::*;
-
-use ::xcm::latest::NetworkId;
mod runtime_common;
runtime/opal/src/xcm_barrier.rsdiffbeforeafterboth--- a/runtime/opal/src/xcm_barrier.rs
+++ b/runtime/opal/src/xcm_barrier.rs
@@ -16,7 +16,7 @@
use frame_support::{match_types, traits::Everything};
use xcm::latest::{Junctions::*, MultiLocation};
-use xcm_builder::{AllowTopLevelPaidExecutionFrom, TakeWeightCredit, AllowExplicitUnpaidExecutionFrom};
+use staging_xcm_builder::{AllowTopLevelPaidExecutionFrom, TakeWeightCredit, AllowExplicitUnpaidExecutionFrom};
match_types! {
pub type ParentOnly: impl Contains<MultiLocation> = {
runtime/quartz/src/lib.rsdiffbeforeafterboth--- a/runtime/quartz/src/lib.rs
+++ b/runtime/quartz/src/lib.rs
@@ -27,14 +27,11 @@
extern crate alloc;
+use ::staging_xcm::latest::NetworkId;
use frame_support::parameter_types;
-
-use sp_version::RuntimeVersion;
use sp_runtime::create_runtime_str;
-
+use sp_version::RuntimeVersion;
use up_common::types::*;
-
-use ::xcm::latest::NetworkId;
mod runtime_common;
runtime/quartz/src/xcm_barrier.rsdiffbeforeafterboth--- a/runtime/quartz/src/xcm_barrier.rs
+++ b/runtime/quartz/src/xcm_barrier.rs
@@ -15,8 +15,8 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use frame_support::{match_types, traits::Everything};
-use xcm::latest::{Junctions::*, MultiLocation};
-use xcm_builder::{
+use staging_xcm::latest::{Junctions::*, MultiLocation};
+use staging_xcm_builder::{
AllowKnownQueryResponses, AllowSubscriptionsFrom, TakeWeightCredit,
AllowTopLevelPaidExecutionFrom, AllowExplicitUnpaidExecutionFrom,
};
runtime/tests/src/lib.rsdiffbeforeafterboth--- a/runtime/tests/src/lib.rs
+++ b/runtime/tests/src/lib.rs
@@ -16,27 +16,26 @@
#![allow(clippy::from_over_into)]
-use sp_core::{H160, H256, U256};
use frame_support::{
+ pallet_prelude::Weight,
parameter_types,
- traits::{Everything, ConstU32, ConstU64, fungible::Inspect},
+ traits::{fungible::Inspect, ConstU32, ConstU64, Everything},
weights::IdentityFee,
- pallet_prelude::Weight,
};
-use sp_runtime::{
- traits::{BlakeTwo256, IdentityLookup},
- testing::Header,
-};
-use pallet_transaction_payment::CurrencyAdapter;
use frame_system as system;
+use pallet_ethereum::PostLogContent;
use pallet_evm::{
- AddressMapping, account::CrossAccountId, EnsureAddressNever, SubstrateBlockHashMapping,
- BackwardsAddressMapping,
+ account::CrossAccountId, AddressMapping, BackwardsAddressMapping, EnsureAddressNever,
+ SubstrateBlockHashMapping,
};
-use pallet_ethereum::PostLogContent;
-use codec::{Encode, Decode, MaxEncodedLen};
+use pallet_transaction_payment::CurrencyAdapter;
+use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
-
+use sp_core::{H160, H256, U256};
+use sp_runtime::{
+ testing::Header,
+ traits::{BlakeTwo256, IdentityLookup},
+};
use up_data_structs::mapping::{CrossTokenAddressMapping, EvmTokenAddressMapping};
#[path = "../../common/dispatch.rs"]
runtime/tests/src/tests.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Tests to be written here18use crate::{Test, TestCrossAccountId, CollectionCreationPrice, RuntimeOrigin, Unique, new_test_ext};19use up_data_structs::{20 COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData,21 CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, TokenId,22 MAX_TOKEN_OWNERSHIP, CreateCollectionData, CollectionMode, AccessMode, CollectionPermissions,23 PropertyKeyPermission, PropertyPermission, Property, CollectionPropertiesVec,24 CollectionPropertiesPermissionsVec,25};26use frame_support::{assert_noop, assert_ok, assert_err};27use sp_std::convert::TryInto;28use pallet_evm::account::CrossAccountId;29use pallet_common::Error as CommonError;30use pallet_unique::Error as UniqueError;3132fn add_balance(user: u64, value: u64) {33 const DONOR_USER: u64 = 999;34 assert_ok!(<pallet_balances::Pallet<Test>>::force_set_balance(35 RuntimeOrigin::root(),36 DONOR_USER,37 value,38 ));39 assert_ok!(<pallet_balances::Pallet<Test>>::force_transfer(40 RuntimeOrigin::root(),41 DONOR_USER,42 user,43 value44 ));45}4647fn default_nft_data() -> CreateNftData {48 CreateNftData {49 properties: vec![Property {50 key: b"test-prop".to_vec().try_into().unwrap(),51 value: b"test-nft-prop".to_vec().try_into().unwrap(),52 }]53 .try_into()54 .unwrap(),55 }56}5758fn default_fungible_data() -> CreateFungibleData {59 CreateFungibleData { value: 5 }60}6162fn default_re_fungible_data() -> CreateReFungibleData {63 CreateReFungibleData {64 pieces: 1023,65 properties: vec![Property {66 key: b"test-prop".to_vec().try_into().unwrap(),67 value: b"test-nft-prop".to_vec().try_into().unwrap(),68 }]69 .try_into()70 .unwrap(),71 }72}7374fn create_test_collection_for_owner(75 mode: &CollectionMode,76 owner: u64,77 id: CollectionId,78) -> CollectionId {79 add_balance(owner, CollectionCreationPrice::get() as u64 + 1);8081 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();82 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();83 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();84 let token_property_permissions: CollectionPropertiesPermissionsVec =85 vec![PropertyKeyPermission {86 key: b"test-prop".to_vec().try_into().unwrap(),87 permission: PropertyPermission {88 mutable: true,89 collection_admin: false,90 token_owner: true,91 },92 }]93 .try_into()94 .unwrap();95 let properties: CollectionPropertiesVec = vec![Property {96 key: b"test-collection-prop".to_vec().try_into().unwrap(),97 value: b"test-collection-value".to_vec().try_into().unwrap(),98 }]99 .try_into()100 .unwrap();101102 let data = CreateCollectionData {103 name: col_name1.try_into().unwrap(),104 description: col_desc1.try_into().unwrap(),105 token_prefix: token_prefix1.try_into().unwrap(),106 mode: mode.clone(),107 token_property_permissions: token_property_permissions.clone(),108 properties: properties.clone(),109 ..Default::default()110 };111112 let origin1 = RuntimeOrigin::signed(owner);113 assert_ok!(Unique::create_collection_ex(origin1, data));114115 let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();116 let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();117 let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();118 assert_eq!(119 <pallet_common::CollectionById<Test>>::get(id)120 .unwrap()121 .owner,122 owner123 );124 assert_eq!(125 <pallet_common::CollectionById<Test>>::get(id).unwrap().name,126 saved_col_name127 );128 assert_eq!(129 <pallet_common::CollectionById<Test>>::get(id).unwrap().mode,130 *mode131 );132 assert_eq!(133 <pallet_common::CollectionById<Test>>::get(id)134 .unwrap()135 .description,136 saved_description137 );138 assert_eq!(139 <pallet_common::CollectionById<Test>>::get(id)140 .unwrap()141 .token_prefix,142 saved_prefix143 );144 assert_eq!(145 get_collection_property_permissions(id).as_slice(),146 token_property_permissions.as_slice()147 );148 assert_eq!(149 get_collection_properties(id).as_slice(),150 properties.as_slice()151 );152 id153}154155fn get_collection_property_permissions(collection_id: CollectionId) -> Vec<PropertyKeyPermission> {156 <pallet_common::Pallet<Test>>::property_permissions(collection_id)157 .into_iter()158 .map(|(key, permission)| PropertyKeyPermission { key, permission })159 .collect()160}161162fn get_collection_properties(collection_id: CollectionId) -> Vec<Property> {163 <pallet_common::Pallet<Test>>::collection_properties(collection_id)164 .into_iter()165 .map(|(key, value)| Property { key, value })166 .collect()167}168169fn get_token_properties(collection_id: CollectionId, token_id: TokenId) -> Vec<Property> {170 <pallet_nonfungible::Pallet<Test>>::token_properties((collection_id, token_id))171 .unwrap_or_default()172 .into_iter()173 .map(|(key, value)| Property { key, value })174 .collect()175}176177fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {178 create_test_collection_for_owner(&mode, 1, id)179}180181fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {182 let origin1 = RuntimeOrigin::signed(1);183 assert_ok!(Unique::create_item(184 origin1,185 collection_id,186 account(1),187 data.clone()188 ));189}190191fn account(sub: u64) -> TestCrossAccountId {192 TestCrossAccountId::from_sub(sub)193}194195// Use cases tests region196// #region197198#[test]199fn check_not_sufficient_founds() {200 new_test_ext().execute_with(|| {201 let acc: u64 = 1;202 <pallet_balances::Pallet<Test>>::force_set_balance(RuntimeOrigin::root(), acc, 0).unwrap();203204 let name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();205 let description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();206 let token_prefix: Vec<u8> = b"token_prefix1\0".to_vec();207208 let data = CreateCollectionData {209 name: name.try_into().unwrap(),210 description: description.try_into().unwrap(),211 token_prefix: token_prefix.try_into().unwrap(),212 mode: CollectionMode::NFT,213 ..Default::default()214 };215216 let result = Unique::create_collection_ex(RuntimeOrigin::signed(acc), data);217 assert_err!(result, <CommonError<Test>>::NotSufficientFounds);218 });219}220221#[test]222fn create_fungible_collection_fails_with_large_decimal_numbers() {223 new_test_ext().execute_with(|| {224 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();225 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();226 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();227228 let data = CreateCollectionData {229 name: col_name1.try_into().unwrap(),230 description: col_desc1.try_into().unwrap(),231 token_prefix: token_prefix1.try_into().unwrap(),232 mode: CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1),233 ..Default::default()234 };235236 let origin1 = RuntimeOrigin::signed(1);237 assert_noop!(238 Unique::create_collection_ex(origin1, data),239 UniqueError::<Test>::CollectionDecimalPointLimitExceeded240 );241 });242}243244#[test]245fn create_nft_item() {246 new_test_ext().execute_with(|| {247 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));248249 let data = default_nft_data();250 create_test_item(collection_id, &data.clone().into());251252 assert_eq!(253 get_token_properties(collection_id, TokenId(1)).as_slice(),254 data.properties.as_slice(),255 );256 });257}258259// Use cases tests region260// #region261#[test]262fn create_nft_multiple_items() {263 new_test_ext().execute_with(|| {264 create_test_collection(&CollectionMode::NFT, CollectionId(1));265266 let origin1 = RuntimeOrigin::signed(1);267268 let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];269270 assert_ok!(Unique::create_multiple_items(271 origin1,272 CollectionId(1),273 account(1),274 items_data275 .clone()276 .into_iter()277 .map(|d| { d.into() })278 .collect()279 ));280 for (index, data) in items_data.into_iter().enumerate() {281 assert_eq!(282 get_token_properties(CollectionId(1), TokenId(index as u32 + 1)).as_slice(),283 data.properties.as_slice()284 );285 }286 });287}288289#[test]290fn create_refungible_item() {291 new_test_ext().execute_with(|| {292 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));293294 let data = default_re_fungible_data();295 create_test_item(collection_id, &data.clone().into());296 let balance =297 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));298 assert_eq!(balance, 1023);299 });300}301302#[test]303fn create_multiple_refungible_items() {304 new_test_ext().execute_with(|| {305 create_test_collection(&CollectionMode::ReFungible, CollectionId(1));306307 let origin1 = RuntimeOrigin::signed(1);308309 let items_data = vec![310 default_re_fungible_data(),311 default_re_fungible_data(),312 default_re_fungible_data(),313 ];314315 assert_ok!(Unique::create_multiple_items(316 origin1,317 CollectionId(1),318 account(1),319 items_data320 .clone()321 .into_iter()322 .map(|d| { d.into() })323 .collect()324 ));325 for (index, _data) in items_data.into_iter().enumerate() {326 let balance = <pallet_refungible::Balance<Test>>::get((327 CollectionId(1),328 TokenId((index + 1) as u32),329 account(1),330 ));331 assert_eq!(balance, 1023);332 }333 });334}335336#[test]337fn create_fungible_item() {338 new_test_ext().execute_with(|| {339 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));340341 let data = default_fungible_data();342 create_test_item(collection_id, &data.into());343344 assert_eq!(345 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),346 5347 );348 });349}350351//#[test]352// fn create_multiple_fungible_items() {353// new_test_ext().execute_with(|| {354// default_limits();355356// create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));357358// let origin1 = RuntimeOrigin::signed(1);359360// let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];361362// assert_ok!(Unique::create_multiple_items(363// origin1.clone(),364// 1,365// 1,366// items_data.clone().into_iter().map(|d| { d.into() }).collect()367// ));368369// for (index, _) in items_data.iter().enumerate() {370// assert_eq!(Unique::fungible_item_id(1, (index + 1) as TokenId).value, 5);371// }372// assert_eq!(Unique::balance_count(1, 1), 3000);373// assert_eq!(Unique::address_tokens(1, 1), [1, 2, 3]);374// });375// }376377#[test]378fn transfer_fungible_item() {379 new_test_ext().execute_with(|| {380 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));381382 let origin1 = RuntimeOrigin::signed(1);383 let origin2 = RuntimeOrigin::signed(2);384385 let data = default_fungible_data();386 create_test_item(collection_id, &data.into());387388 assert_eq!(389 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),390 5391 );392393 // change owner scenario394 assert_ok!(Unique::transfer(395 origin1,396 account(2),397 CollectionId(1),398 TokenId(0),399 5400 ));401 assert_eq!(402 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),403 0404 );405406 // split item scenario407 assert_ok!(Unique::transfer(408 origin2.clone(),409 account(3),410 CollectionId(1),411 TokenId(0),412 3413 ));414415 // split item and new owner has account scenario416 assert_ok!(Unique::transfer(417 origin2,418 account(3),419 CollectionId(1),420 TokenId(0),421 1422 ));423 assert_eq!(424 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))),425 1426 );427 assert_eq!(428 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))),429 4430 );431 });432}433434#[test]435fn transfer_refungible_item() {436 new_test_ext().execute_with(|| {437 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));438439 // Create RFT 1 in 1023 pieces for account 1440 let data = default_re_fungible_data();441 create_test_item(collection_id, &data.clone().into());442 assert_eq!(443 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),444 1445 );446 assert_eq!(447 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),448 1023449 );450 assert_eq!(451 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),452 true453 );454455 // Account 1 transfers all 1023 pieces of RFT 1 to account 2456 let origin1 = RuntimeOrigin::signed(1);457 let origin2 = RuntimeOrigin::signed(2);458 assert_ok!(Unique::transfer(459 origin1,460 account(2),461 CollectionId(1),462 TokenId(1),463 1023464 ));465 assert_eq!(466 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),467 1023468 );469 assert_eq!(470 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),471 0472 );473 assert_eq!(474 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),475 1476 );477 assert_eq!(478 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),479 false480 );481 assert_eq!(482 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),483 true484 );485486 // Account 2 transfers 500 pieces of RFT 1 to account 3487 assert_ok!(Unique::transfer(488 origin2.clone(),489 account(3),490 CollectionId(1),491 TokenId(1),492 500493 ));494 assert_eq!(495 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),496 523497 );498 assert_eq!(499 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),500 500501 );502 assert_eq!(503 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),504 1505 );506 assert_eq!(507 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),508 1509 );510 assert_eq!(511 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),512 true513 );514 assert_eq!(515 <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),516 true517 );518519 // Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance520 assert_ok!(Unique::transfer(521 origin2,522 account(3),523 CollectionId(1),524 TokenId(1),525 200526 ));527 assert_eq!(528 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),529 323530 );531 assert_eq!(532 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),533 700534 );535 assert_eq!(536 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),537 1538 );539 assert_eq!(540 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),541 1542 );543 assert_eq!(544 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),545 true546 );547 assert_eq!(548 <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),549 true550 );551 });552}553554#[test]555fn transfer_nft_item() {556 new_test_ext().execute_with(|| {557 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));558559 let data = default_nft_data();560 create_test_item(collection_id, &data.into());561 assert_eq!(562 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),563 1564 );565 assert_eq!(566 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),567 true568 );569570 let origin1 = RuntimeOrigin::signed(1);571 // default scenario572 assert_ok!(Unique::transfer(573 origin1,574 account(2),575 CollectionId(1),576 TokenId(1),577 1578 ));579 assert_eq!(580 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),581 0582 );583 assert_eq!(584 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),585 1586 );587 assert_eq!(588 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),589 false590 );591 assert_eq!(592 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),593 true594 );595 });596}597598#[test]599fn transfer_nft_item_wrong_value() {600 new_test_ext().execute_with(|| {601 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));602603 let data = default_nft_data();604 create_test_item(collection_id, &data.into());605 assert_eq!(606 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),607 1608 );609 assert_eq!(610 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),611 true612 );613614 let origin1 = RuntimeOrigin::signed(1);615616 assert_noop!(617 Unique::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2)618 .map_err(|e| e.error),619 <pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount620 );621 });622}623624#[test]625fn transfer_nft_item_zero_value() {626 new_test_ext().execute_with(|| {627 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));628629 let data = default_nft_data();630 create_test_item(collection_id, &data.into());631 assert_eq!(632 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),633 1634 );635 assert_eq!(636 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),637 true638 );639640 let origin1 = RuntimeOrigin::signed(1);641642 // Transferring 0 amount works on NFT...643 assert_ok!(Unique::transfer(644 origin1,645 account(2),646 CollectionId(1),647 TokenId(1),648 0649 ));650 // ... and results in no transfer651 assert_eq!(652 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),653 1654 );655 assert_eq!(656 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),657 true658 );659 });660}661662#[test]663fn nft_approve_and_transfer_from() {664 new_test_ext().execute_with(|| {665 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));666667 let data = default_nft_data();668 create_test_item(collection_id, &data.into());669670 let origin1 = RuntimeOrigin::signed(1);671 let origin2 = RuntimeOrigin::signed(2);672673 assert_eq!(674 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),675 1676 );677 assert_eq!(678 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),679 true680 );681682 // neg transfer_from683 assert_noop!(684 Unique::transfer_from(685 origin2.clone(),686 account(1),687 account(2),688 CollectionId(1),689 TokenId(1),690 1691 )692 .map_err(|e| e.error),693 CommonError::<Test>::ApprovedValueTooLow694 );695696 // do approve697 assert_ok!(Unique::approve(698 origin1,699 account(2),700 CollectionId(1),701 TokenId(1),702 1703 ));704 assert_eq!(705 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),706 account(2)707 );708709 assert_ok!(Unique::transfer_from(710 origin2,711 account(1),712 account(3),713 CollectionId(1),714 TokenId(1),715 1716 ));717 assert!(718 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()719 );720 });721}722723#[test]724fn nft_approve_and_transfer_from_allow_list() {725 new_test_ext().execute_with(|| {726 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));727728 let origin1 = RuntimeOrigin::signed(1);729 let origin2 = RuntimeOrigin::signed(2);730731 // Create NFT 1 for account 1732 let data = default_nft_data();733 create_test_item(collection_id, &data.clone().into());734 assert_eq!(735 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),736 1737 );738 assert_eq!(739 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),740 true741 );742743 // Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list744 assert_ok!(Unique::set_collection_permissions(745 origin1.clone(),746 CollectionId(1),747 CollectionPermissions {748 mint_mode: Some(true),749 access: Some(AccessMode::AllowList),750 nesting: None,751 }752 ));753 assert_ok!(Unique::add_to_allow_list(754 origin1.clone(),755 CollectionId(1),756 account(1)757 ));758 assert_ok!(Unique::add_to_allow_list(759 origin1.clone(),760 CollectionId(1),761 account(2)762 ));763 assert_ok!(Unique::add_to_allow_list(764 origin1.clone(),765 CollectionId(1),766 account(3)767 ));768769 // Account 1 approves account 2 for NFT 1770 assert_ok!(Unique::approve(771 origin1.clone(),772 account(2),773 CollectionId(1),774 TokenId(1),775 1776 ));777 assert_eq!(778 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),779 account(2)780 );781782 // Account 2 transfers NFT 1 from account 1 to account 3783 assert_ok!(Unique::transfer_from(784 origin2,785 account(1),786 account(3),787 CollectionId(1),788 TokenId(1),789 1790 ));791 assert!(792 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()793 );794 });795}796797#[test]798fn refungible_approve_and_transfer_from() {799 new_test_ext().execute_with(|| {800 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));801802 let origin1 = RuntimeOrigin::signed(1);803 let origin2 = RuntimeOrigin::signed(2);804805 // Create RFT 1 in 1023 pieces for account 1806 let data = default_re_fungible_data();807 create_test_item(collection_id, &data.into());808809 assert_eq!(810 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),811 1812 );813 assert_eq!(814 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),815 1023816 );817 assert_eq!(818 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),819 true820 );821822 // Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list823 assert_ok!(Unique::set_collection_permissions(824 origin1.clone(),825 CollectionId(1),826 CollectionPermissions {827 mint_mode: Some(true),828 access: Some(AccessMode::AllowList),829 nesting: None,830 }831 ));832 assert_ok!(Unique::add_to_allow_list(833 origin1.clone(),834 CollectionId(1),835 account(1)836 ));837 assert_ok!(Unique::add_to_allow_list(838 origin1.clone(),839 CollectionId(1),840 account(2)841 ));842 assert_ok!(Unique::add_to_allow_list(843 origin1.clone(),844 CollectionId(1),845 account(3)846 ));847848 // Account 1 approves account 2 for 1023 pieces of RFT 1849 assert_ok!(Unique::approve(850 origin1,851 account(2),852 CollectionId(1),853 TokenId(1),854 1023855 ));856 assert_eq!(857 <pallet_refungible::Allowance<Test>>::get((858 CollectionId(1),859 TokenId(1),860 account(1),861 account(2)862 )),863 1023864 );865866 // Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3867 assert_ok!(Unique::transfer_from(868 origin2,869 account(1),870 account(3),871 CollectionId(1),872 TokenId(1),873 100874 ));875 assert_eq!(876 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),877 1878 );879 assert_eq!(880 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),881 1882 );883 assert_eq!(884 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),885 923886 );887 assert_eq!(888 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),889 100890 );891 assert_eq!(892 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),893 true894 );895 assert_eq!(896 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),897 true898 );899 assert_eq!(900 <pallet_refungible::Allowance<Test>>::get((901 CollectionId(1),902 TokenId(1),903 account(1),904 account(2)905 )),906 923907 );908 });909}910911#[test]912fn fungible_approve_and_transfer_from() {913 new_test_ext().execute_with(|| {914 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));915916 let data = default_fungible_data();917 create_test_item(collection_id, &data.into());918919 let origin1 = RuntimeOrigin::signed(1);920 let origin2 = RuntimeOrigin::signed(2);921922 assert_ok!(Unique::set_collection_permissions(923 origin1.clone(),924 CollectionId(1),925 CollectionPermissions {926 mint_mode: Some(true),927 access: Some(AccessMode::AllowList),928 nesting: None,929 }930 ));931 assert_ok!(Unique::add_to_allow_list(932 origin1.clone(),933 CollectionId(1),934 account(1)935 ));936 assert_ok!(Unique::add_to_allow_list(937 origin1.clone(),938 CollectionId(1),939 account(2)940 ));941 assert_ok!(Unique::add_to_allow_list(942 origin1.clone(),943 CollectionId(1),944 account(3)945 ));946947 // do approve948 assert_ok!(Unique::approve(949 origin1.clone(),950 account(2),951 CollectionId(1),952 TokenId(0),953 5954 ));955 assert_eq!(956 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),957 5958 );959 assert_ok!(Unique::approve(960 origin1,961 account(3),962 CollectionId(1),963 TokenId(0),964 5965 ));966 assert_eq!(967 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),968 5969 );970 assert_eq!(971 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))),972 5973 );974975 assert_ok!(Unique::transfer_from(976 origin2.clone(),977 account(1),978 account(3),979 CollectionId(1),980 TokenId(0),981 4982 ));983984 assert_eq!(985 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),986 1987 );988989 assert_noop!(990 Unique::transfer_from(991 origin2,992 account(1),993 account(3),994 CollectionId(1),995 TokenId(0),996 4997 )998 .map_err(|e| e.error),999 CommonError::<Test>::ApprovedValueTooLow1000 );1001 });1002}10031004#[test]1005fn change_collection_owner() {1006 new_test_ext().execute_with(|| {1007 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10081009 let origin1 = RuntimeOrigin::signed(1);1010 assert_ok!(Unique::change_collection_owner(origin1, collection_id, 2));1011 assert_eq!(1012 <pallet_common::CollectionById<Test>>::get(collection_id)1013 .unwrap()1014 .owner,1015 21016 );1017 });1018}10191020#[test]1021fn destroy_collection() {1022 new_test_ext().execute_with(|| {1023 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10241025 let origin1 = RuntimeOrigin::signed(1);1026 assert_ok!(Unique::destroy_collection(origin1, collection_id));1027 });1028}10291030#[test]1031fn burn_nft_item() {1032 new_test_ext().execute_with(|| {1033 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10341035 let origin1 = RuntimeOrigin::signed(1);10361037 let data = default_nft_data();1038 create_test_item(collection_id, &data.into());10391040 // check balance (collection with id = 1, user id = 1)1041 assert_eq!(1042 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1043 11044 );10451046 // burn item1047 assert_ok!(Unique::burn_item(1048 origin1.clone(),1049 collection_id,1050 TokenId(1),1051 11052 ));1053 assert_eq!(1054 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1055 01056 );1057 });1058}10591060#[test]1061fn burn_same_nft_item_twice() {1062 new_test_ext().execute_with(|| {1063 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10641065 let origin1 = RuntimeOrigin::signed(1);10661067 let data = default_nft_data();1068 create_test_item(collection_id, &data.into());10691070 // check balance (collection with id = 1, user id = 1)1071 assert_eq!(1072 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1073 11074 );10751076 // burn item1077 assert_ok!(Unique::burn_item(1078 origin1.clone(),1079 collection_id,1080 TokenId(1),1081 11082 ));10831084 // burn item again1085 assert_noop!(1086 Unique::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),1087 CommonError::<Test>::TokenNotFound1088 );10891090 assert_eq!(1091 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1092 01093 );1094 });1095}10961097#[test]1098fn burn_fungible_item() {1099 new_test_ext().execute_with(|| {1100 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));11011102 let origin1 = RuntimeOrigin::signed(1);1103 assert_ok!(Unique::add_collection_admin(1104 origin1.clone(),1105 collection_id,1106 account(2)1107 ));11081109 let data = default_fungible_data();1110 create_test_item(collection_id, &data.into());11111112 // check balance (collection with id = 1, user id = 1)1113 assert_eq!(1114 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1115 51116 );11171118 // burn item1119 assert_ok!(Unique::burn_item(1120 origin1.clone(),1121 CollectionId(1),1122 TokenId(0),1123 51124 ));1125 assert_noop!(1126 Unique::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),1127 CommonError::<Test>::TokenValueTooLow1128 );11291130 assert_eq!(1131 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1132 01133 );1134 });1135}11361137#[test]1138fn burn_fungible_item_with_token_id() {1139 new_test_ext().execute_with(|| {1140 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));11411142 let origin1 = RuntimeOrigin::signed(1);1143 assert_ok!(Unique::add_collection_admin(1144 origin1.clone(),1145 collection_id,1146 account(2)1147 ));11481149 let data = default_fungible_data();1150 create_test_item(collection_id, &data.into());11511152 // check balance (collection with id = 1, user id = 1)1153 assert_eq!(1154 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1155 51156 );11571158 // Try to burn item using Token ID1159 assert_noop!(1160 Unique::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),1161 <pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId1162 );1163 });1164}1165#[test]1166fn burn_refungible_item() {1167 new_test_ext().execute_with(|| {1168 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));1169 let origin1 = RuntimeOrigin::signed(1);11701171 assert_ok!(Unique::set_collection_permissions(1172 origin1.clone(),1173 collection_id,1174 CollectionPermissions {1175 mint_mode: Some(true),1176 access: Some(AccessMode::AllowList),1177 nesting: None,1178 }1179 ));1180 assert_ok!(Unique::add_to_allow_list(1181 origin1.clone(),1182 collection_id,1183 account(1)1184 ));11851186 assert_ok!(Unique::add_collection_admin(1187 origin1.clone(),1188 collection_id,1189 account(2)1190 ));11911192 let data = default_re_fungible_data();1193 create_test_item(collection_id, &data.into());11941195 // check balance (collection with id = 1, user id = 2)1196 assert_eq!(1197 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),1198 11199 );1200 assert_eq!(1201 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1202 10231203 );12041205 // burn item1206 assert_ok!(Unique::burn_item(1207 origin1.clone(),1208 collection_id,1209 TokenId(1),1210 10231211 ));1212 assert_noop!(1213 Unique::burn_item(origin1, collection_id, TokenId(1), 1023).map_err(|e| e.error),1214 CommonError::<Test>::TokenValueTooLow1215 );12161217 assert_eq!(1218 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1219 01220 );1221 });1222}12231224#[test]1225fn add_collection_admin() {1226 new_test_ext().execute_with(|| {1227 let collection1_id =1228 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1229 let origin1 = RuntimeOrigin::signed(1);12301231 // Add collection admins1232 assert_ok!(Unique::add_collection_admin(1233 origin1.clone(),1234 collection1_id,1235 account(2)1236 ));1237 assert_ok!(Unique::add_collection_admin(1238 origin1,1239 collection1_id,1240 account(3)1241 ));12421243 // Owner is not an admin by default1244 assert_eq!(1245 <pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))),1246 false1247 );1248 assert!(<pallet_common::IsAdmin<Test>>::get((1249 CollectionId(1),1250 account(2)1251 )));1252 assert!(<pallet_common::IsAdmin<Test>>::get((1253 CollectionId(1),1254 account(3)1255 )));1256 });1257}12581259#[test]1260fn remove_collection_admin() {1261 new_test_ext().execute_with(|| {1262 let collection1_id =1263 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1264 let origin1 = RuntimeOrigin::signed(1);12651266 // Add collection admins 2 and 31267 assert_ok!(Unique::add_collection_admin(1268 origin1.clone(),1269 collection1_id,1270 account(2)1271 ));1272 assert_ok!(Unique::add_collection_admin(1273 origin1.clone(),1274 collection1_id,1275 account(3)1276 ));12771278 assert!(<pallet_common::IsAdmin<Test>>::get((1279 CollectionId(1),1280 account(2)1281 )));1282 assert!(<pallet_common::IsAdmin<Test>>::get((1283 CollectionId(1),1284 account(3)1285 )));12861287 // remove admin 31288 assert_ok!(Unique::remove_collection_admin(1289 origin1,1290 CollectionId(1),1291 account(3)1292 ));12931294 // 2 is still admin, 3 is not an admin anymore1295 assert!(<pallet_common::IsAdmin<Test>>::get((1296 CollectionId(1),1297 account(2)1298 )));1299 assert_eq!(1300 <pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))),1301 false1302 );1303 });1304}13051306#[test]1307fn balance_of() {1308 new_test_ext().execute_with(|| {1309 let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1310 let fungible_collection_id =1311 create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));1312 let re_fungible_collection_id =1313 create_test_collection(&CollectionMode::ReFungible, CollectionId(3));13141315 // check balance before1316 assert_eq!(1317 <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1318 01319 );1320 assert_eq!(1321 <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1322 01323 );1324 assert_eq!(1325 <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1326 01327 );13281329 let nft_data = default_nft_data();1330 create_test_item(nft_collection_id, &nft_data.into());13311332 let fungible_data = default_fungible_data();1333 create_test_item(fungible_collection_id, &fungible_data.into());13341335 let re_fungible_data = default_re_fungible_data();1336 create_test_item(re_fungible_collection_id, &re_fungible_data.into());13371338 // check balance (collection with id = 1, user id = 1)1339 assert_eq!(1340 <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1341 11342 );1343 assert_eq!(1344 <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1345 51346 );1347 assert_eq!(1348 <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1349 11350 );13511352 assert_eq!(1353 <pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))),1354 true1355 );1356 assert_eq!(1357 <pallet_refungible::Owned<Test>>::get((1358 re_fungible_collection_id,1359 account(1),1360 TokenId(1)1361 )),1362 true1363 );1364 });1365}13661367#[test]1368fn approve() {1369 new_test_ext().execute_with(|| {1370 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));13711372 let data = default_nft_data();1373 create_test_item(collection_id, &data.into());13741375 let origin1 = RuntimeOrigin::signed(1);13761377 // approve1378 assert_ok!(Unique::approve(1379 origin1,1380 account(2),1381 CollectionId(1),1382 TokenId(1),1383 11384 ));1385 assert_eq!(1386 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1387 account(2)1388 );1389 });1390}13911392#[test]1393fn transfer_from() {1394 new_test_ext().execute_with(|| {1395 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1396 let origin1 = RuntimeOrigin::signed(1);1397 let origin2 = RuntimeOrigin::signed(2);13981399 let data = default_nft_data();1400 create_test_item(collection_id, &data.into());14011402 // approve1403 assert_ok!(Unique::approve(1404 origin1.clone(),1405 account(2),1406 CollectionId(1),1407 TokenId(1),1408 11409 ));1410 assert_eq!(1411 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1412 account(2)1413 );14141415 assert_ok!(Unique::set_collection_permissions(1416 origin1.clone(),1417 CollectionId(1),1418 CollectionPermissions {1419 mint_mode: Some(true),1420 access: Some(AccessMode::AllowList),1421 nesting: None,1422 }1423 ));1424 assert_ok!(Unique::add_to_allow_list(1425 origin1.clone(),1426 CollectionId(1),1427 account(1)1428 ));1429 assert_ok!(Unique::add_to_allow_list(1430 origin1.clone(),1431 CollectionId(1),1432 account(2)1433 ));1434 assert_ok!(Unique::add_to_allow_list(1435 origin1,1436 CollectionId(1),1437 account(3)1438 ));14391440 assert_ok!(Unique::transfer_from(1441 origin2,1442 account(1),1443 account(2),1444 CollectionId(1),1445 TokenId(1),1446 11447 ));14481449 // after transfer1450 assert_eq!(1451 <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))),1452 01453 );1454 assert_eq!(1455 <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))),1456 11457 );1458 });1459}14601461// #endregion14621463// Coverage tests region1464// #region14651466#[test]1467fn owner_can_add_address_to_allow_list() {1468 new_test_ext().execute_with(|| {1469 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14701471 let origin1 = RuntimeOrigin::signed(1);1472 assert_ok!(Unique::add_to_allow_list(1473 origin1,1474 collection_id,1475 account(2)1476 ));1477 assert!(<pallet_common::Allowlist<Test>>::get((1478 collection_id,1479 account(2)1480 )));1481 });1482}14831484#[test]1485fn admin_can_add_address_to_allow_list() {1486 new_test_ext().execute_with(|| {1487 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1488 let origin1 = RuntimeOrigin::signed(1);1489 let origin2 = RuntimeOrigin::signed(2);14901491 assert_ok!(Unique::add_collection_admin(1492 origin1,1493 collection_id,1494 account(2)1495 ));1496 assert_ok!(Unique::add_to_allow_list(1497 origin2,1498 collection_id,1499 account(3)1500 ));1501 assert!(<pallet_common::Allowlist<Test>>::get((1502 collection_id,1503 account(3)1504 )));1505 });1506}15071508#[test]1509fn nonprivileged_user_cannot_add_address_to_allow_list() {1510 new_test_ext().execute_with(|| {1511 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15121513 let origin2 = RuntimeOrigin::signed(2);1514 assert_noop!(1515 Unique::add_to_allow_list(origin2, collection_id, account(3)),1516 CommonError::<Test>::NoPermission1517 );1518 });1519}15201521#[test]1522fn nobody_can_add_address_to_allow_list_of_nonexisting_collection() {1523 new_test_ext().execute_with(|| {1524 let origin1 = RuntimeOrigin::signed(1);15251526 assert_noop!(1527 Unique::add_to_allow_list(origin1, CollectionId(1), account(2)),1528 CommonError::<Test>::CollectionNotFound1529 );1530 });1531}15321533#[test]1534fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1535 new_test_ext().execute_with(|| {1536 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15371538 let origin1 = RuntimeOrigin::signed(1);1539 assert_ok!(Unique::destroy_collection(origin1.clone(), collection_id));1540 assert_noop!(1541 Unique::add_to_allow_list(origin1, collection_id, account(2)),1542 CommonError::<Test>::CollectionNotFound1543 );1544 });1545}15461547// If address is already added to allow list, nothing happens1548#[test]1549fn address_is_already_added_to_allow_list() {1550 new_test_ext().execute_with(|| {1551 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1552 let origin1 = RuntimeOrigin::signed(1);15531554 assert_ok!(Unique::add_to_allow_list(1555 origin1.clone(),1556 collection_id,1557 account(2)1558 ));1559 assert_ok!(Unique::add_to_allow_list(1560 origin1,1561 collection_id,1562 account(2)1563 ));1564 assert!(<pallet_common::Allowlist<Test>>::get((1565 collection_id,1566 account(2)1567 )));1568 });1569}15701571#[test]1572fn owner_can_remove_address_from_allow_list() {1573 new_test_ext().execute_with(|| {1574 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15751576 let origin1 = RuntimeOrigin::signed(1);1577 assert_ok!(Unique::add_to_allow_list(1578 origin1.clone(),1579 collection_id,1580 account(2)1581 ));1582 assert_ok!(Unique::remove_from_allow_list(1583 origin1,1584 collection_id,1585 account(2)1586 ));1587 assert_eq!(1588 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1589 false1590 );1591 });1592}15931594#[test]1595fn admin_can_remove_address_from_allow_list() {1596 new_test_ext().execute_with(|| {1597 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1598 let origin1 = RuntimeOrigin::signed(1);1599 let origin2 = RuntimeOrigin::signed(2);16001601 // Owner adds admin1602 assert_ok!(Unique::add_collection_admin(1603 origin1.clone(),1604 collection_id,1605 account(2)1606 ));16071608 // Owner adds address 3 to allow list1609 assert_ok!(Unique::add_to_allow_list(1610 origin1,1611 collection_id,1612 account(3)1613 ));16141615 // Admin removes address 3 from allow list1616 assert_ok!(Unique::remove_from_allow_list(1617 origin2,1618 collection_id,1619 account(3)1620 ));1621 assert_eq!(1622 <pallet_common::Allowlist<Test>>::get((collection_id, account(3))),1623 false1624 );1625 });1626}16271628#[test]1629fn nonprivileged_user_cannot_remove_address_from_allow_list() {1630 new_test_ext().execute_with(|| {1631 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1632 let origin1 = RuntimeOrigin::signed(1);1633 let origin2 = RuntimeOrigin::signed(2);16341635 assert_ok!(Unique::add_to_allow_list(1636 origin1,1637 collection_id,1638 account(2)1639 ));1640 assert_noop!(1641 Unique::remove_from_allow_list(origin2, collection_id, account(2)),1642 CommonError::<Test>::NoPermission1643 );1644 assert!(<pallet_common::Allowlist<Test>>::get((1645 collection_id,1646 account(2)1647 )));1648 });1649}16501651#[test]1652fn nobody_can_remove_address_from_allow_list_of_nonexisting_collection() {1653 new_test_ext().execute_with(|| {1654 let origin1 = RuntimeOrigin::signed(1);16551656 assert_noop!(1657 Unique::remove_from_allow_list(origin1, CollectionId(1), account(2)),1658 CommonError::<Test>::CollectionNotFound1659 );1660 });1661}16621663#[test]1664fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1665 new_test_ext().execute_with(|| {1666 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1667 let origin1 = RuntimeOrigin::signed(1);1668 let origin2 = RuntimeOrigin::signed(2);16691670 // Add account 2 to allow list1671 assert_ok!(Unique::add_to_allow_list(1672 origin1.clone(),1673 collection_id,1674 account(2)1675 ));16761677 // Account 2 is in collection allow-list1678 assert!(<pallet_common::Allowlist<Test>>::get((1679 collection_id,1680 account(2)1681 )));16821683 // Destroy collection1684 assert_ok!(Unique::destroy_collection(origin1, collection_id));16851686 // Attempt to remove account 2 from collection allow-list => error1687 assert_noop!(1688 Unique::remove_from_allow_list(origin2, collection_id, account(2)),1689 CommonError::<Test>::CollectionNotFound1690 );16911692 // Account 2 is not found in collection allow-list anyway1693 assert_eq!(1694 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1695 false1696 );1697 });1698}16991700// If address is already removed from allow list, nothing happens1701#[test]1702fn address_is_already_removed_from_allow_list() {1703 new_test_ext().execute_with(|| {1704 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1705 let origin1 = RuntimeOrigin::signed(1);17061707 assert_ok!(Unique::add_to_allow_list(1708 origin1.clone(),1709 collection_id,1710 account(2)1711 ));1712 assert_ok!(Unique::remove_from_allow_list(1713 origin1.clone(),1714 collection_id,1715 account(2)1716 ));1717 assert_eq!(1718 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1719 false1720 );1721 assert_ok!(Unique::remove_from_allow_list(1722 origin1,1723 collection_id,1724 account(2)1725 ));1726 assert_eq!(1727 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1728 false1729 );1730 });1731}17321733// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1734#[test]1735fn allow_list_test_1() {1736 new_test_ext().execute_with(|| {1737 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17381739 let origin1 = RuntimeOrigin::signed(1);1740 assert_ok!(Unique::add_collection_admin(1741 origin1.clone(),1742 collection_id,1743 account(1)1744 ));17451746 let data = default_nft_data();1747 create_test_item(collection_id, &data.into());17481749 assert_ok!(Unique::set_collection_permissions(1750 origin1.clone(),1751 collection_id,1752 CollectionPermissions {1753 mint_mode: None,1754 access: Some(AccessMode::AllowList),1755 nesting: None,1756 }1757 ));1758 assert_ok!(Unique::add_to_allow_list(1759 origin1.clone(),1760 collection_id,1761 account(2)1762 ));17631764 assert_noop!(1765 Unique::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1)1766 .map_err(|e| e.error),1767 CommonError::<Test>::AddressNotInAllowlist1768 );1769 });1770}17711772#[test]1773fn allow_list_test_2() {1774 new_test_ext().execute_with(|| {1775 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1776 let origin1 = RuntimeOrigin::signed(1);17771778 let data = default_nft_data();1779 create_test_item(collection_id, &data.into());17801781 assert_ok!(Unique::set_collection_permissions(1782 origin1.clone(),1783 collection_id,1784 CollectionPermissions {1785 mint_mode: None,1786 access: Some(AccessMode::AllowList),1787 nesting: None,1788 }1789 ));1790 assert_ok!(Unique::add_to_allow_list(1791 origin1.clone(),1792 collection_id,1793 account(1)1794 ));1795 assert_ok!(Unique::add_to_allow_list(1796 origin1.clone(),1797 collection_id,1798 account(2)1799 ));18001801 // do approve1802 assert_ok!(Unique::approve(1803 origin1.clone(),1804 account(1),1805 collection_id,1806 TokenId(1),1807 11808 ));1809 assert_eq!(1810 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1811 account(1)1812 );18131814 assert_ok!(Unique::remove_from_allow_list(1815 origin1.clone(),1816 collection_id,1817 account(1)1818 ));18191820 assert_noop!(1821 Unique::transfer_from(1822 origin1,1823 account(1),1824 account(3),1825 CollectionId(1),1826 TokenId(1),1827 11828 )1829 .map_err(|e| e.error),1830 CommonError::<Test>::AddressNotInAllowlist1831 );1832 });1833}18341835// If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom (2 tests)1836#[test]1837fn allow_list_test_3() {1838 new_test_ext().execute_with(|| {1839 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18401841 let origin1 = RuntimeOrigin::signed(1);18421843 let data = default_nft_data();1844 create_test_item(collection_id, &data.into());18451846 assert_ok!(Unique::set_collection_permissions(1847 origin1.clone(),1848 collection_id,1849 CollectionPermissions {1850 mint_mode: None,1851 access: Some(AccessMode::AllowList),1852 nesting: None,1853 }1854 ));1855 assert_ok!(Unique::add_to_allow_list(1856 origin1.clone(),1857 collection_id,1858 account(1)1859 ));18601861 assert_noop!(1862 Unique::transfer(origin1, account(3), collection_id, TokenId(1), 1)1863 .map_err(|e| e.error),1864 CommonError::<Test>::AddressNotInAllowlist1865 );1866 });1867}18681869#[test]1870fn allow_list_test_4() {1871 new_test_ext().execute_with(|| {1872 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18731874 let origin1 = RuntimeOrigin::signed(1);18751876 let data = default_nft_data();1877 create_test_item(collection_id, &data.into());18781879 assert_ok!(Unique::set_collection_permissions(1880 origin1.clone(),1881 collection_id,1882 CollectionPermissions {1883 mint_mode: None,1884 access: Some(AccessMode::AllowList),1885 nesting: None,1886 }1887 ));1888 assert_ok!(Unique::add_to_allow_list(1889 origin1.clone(),1890 collection_id,1891 account(1)1892 ));1893 assert_ok!(Unique::add_to_allow_list(1894 origin1.clone(),1895 collection_id,1896 account(2)1897 ));18981899 // do approve1900 assert_ok!(Unique::approve(1901 origin1.clone(),1902 account(1),1903 collection_id,1904 TokenId(1),1905 11906 ));1907 assert_eq!(1908 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1909 account(1)1910 );19111912 assert_ok!(Unique::remove_from_allow_list(1913 origin1.clone(),1914 collection_id,1915 account(2)1916 ));19171918 assert_noop!(1919 Unique::transfer_from(1920 origin1,1921 account(1),1922 account(3),1923 collection_id,1924 TokenId(1),1925 11926 )1927 .map_err(|e| e.error),1928 CommonError::<Test>::AddressNotInAllowlist1929 );1930 });1931}19321933// If Public Access mode is set to AllowList, tokens can’t be destroyed by a non-allowlisted address (even if it owned them before enabling AllowList mode)1934#[test]1935fn allow_list_test_5() {1936 new_test_ext().execute_with(|| {1937 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19381939 let origin1 = RuntimeOrigin::signed(1);19401941 let data = default_nft_data();1942 create_test_item(collection_id, &data.into());19431944 assert_ok!(Unique::set_collection_permissions(1945 origin1.clone(),1946 collection_id,1947 CollectionPermissions {1948 mint_mode: None,1949 access: Some(AccessMode::AllowList),1950 nesting: None,1951 }1952 ));1953 assert_noop!(1954 Unique::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1).map_err(|e| e.error),1955 CommonError::<Test>::AddressNotInAllowlist1956 );1957 });1958}19591960// If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method).1961#[test]1962fn allow_list_test_6() {1963 new_test_ext().execute_with(|| {1964 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19651966 let origin1 = RuntimeOrigin::signed(1);19671968 let data = default_nft_data();1969 create_test_item(collection_id, &data.into());19701971 assert_ok!(Unique::set_collection_permissions(1972 origin1.clone(),1973 collection_id,1974 CollectionPermissions {1975 mint_mode: None,1976 access: Some(AccessMode::AllowList),1977 nesting: None,1978 }1979 ));19801981 // do approve1982 assert_noop!(1983 Unique::approve(origin1, account(1), CollectionId(1), TokenId(1), 1)1984 .map_err(|e| e.error),1985 CommonError::<Test>::AddressNotInAllowlist1986 );1987 });1988}19891990// If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests) and1991// tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests)1992#[test]1993fn allow_list_test_7() {1994 new_test_ext().execute_with(|| {1995 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19961997 let data = default_nft_data();1998 create_test_item(collection_id, &data.into());19992000 let origin1 = RuntimeOrigin::signed(1);20012002 assert_ok!(Unique::set_collection_permissions(2003 origin1.clone(),2004 collection_id,2005 CollectionPermissions {2006 mint_mode: None,2007 access: Some(AccessMode::AllowList),2008 nesting: None,2009 }2010 ));2011 assert_ok!(Unique::add_to_allow_list(2012 origin1.clone(),2013 collection_id,2014 account(1)2015 ));2016 assert_ok!(Unique::add_to_allow_list(2017 origin1.clone(),2018 collection_id,2019 account(2)2020 ));20212022 assert_ok!(Unique::transfer(2023 origin1,2024 account(2),2025 CollectionId(1),2026 TokenId(1),2027 12028 ));2029 });2030}20312032#[test]2033fn allow_list_test_8() {2034 new_test_ext().execute_with(|| {2035 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20362037 // Create NFT for account 12038 let data = default_nft_data();2039 create_test_item(collection_id, &data.into());20402041 let origin1 = RuntimeOrigin::signed(1);20422043 // Toggle Allow List mode and add accounts 1 and 22044 assert_ok!(Unique::set_collection_permissions(2045 origin1.clone(),2046 collection_id,2047 CollectionPermissions {2048 mint_mode: None,2049 access: Some(AccessMode::AllowList),2050 nesting: None,2051 }2052 ));2053 assert_ok!(Unique::add_to_allow_list(2054 origin1.clone(),2055 collection_id,2056 account(1)2057 ));2058 assert_ok!(Unique::add_to_allow_list(2059 origin1.clone(),2060 collection_id,2061 account(2)2062 ));20632064 // Sself-approve account 1 for NFT 12065 assert_ok!(Unique::approve(2066 origin1.clone(),2067 account(1),2068 CollectionId(1),2069 TokenId(1),2070 12071 ));2072 assert_eq!(2073 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),2074 account(1)2075 );20762077 // Transfer from 1 to 22078 assert_ok!(Unique::transfer_from(2079 origin1,2080 account(1),2081 account(2),2082 CollectionId(1),2083 TokenId(1),2084 12085 ));2086 });2087}20882089// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner.2090#[test]2091fn allow_list_test_9() {2092 new_test_ext().execute_with(|| {2093 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2094 let origin1 = RuntimeOrigin::signed(1);20952096 assert_ok!(Unique::set_collection_permissions(2097 origin1.clone(),2098 collection_id,2099 CollectionPermissions {2100 mint_mode: Some(false),2101 access: Some(AccessMode::AllowList),2102 nesting: None,2103 }2104 ));21052106 let data = default_nft_data();2107 create_test_item(collection_id, &data.into());2108 });2109}21102111// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin.2112#[test]2113fn allow_list_test_10() {2114 new_test_ext().execute_with(|| {2115 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21162117 let origin1 = RuntimeOrigin::signed(1);2118 let origin2 = RuntimeOrigin::signed(2);21192120 assert_ok!(Unique::set_collection_permissions(2121 origin1.clone(),2122 collection_id,2123 CollectionPermissions {2124 mint_mode: Some(false),2125 access: Some(AccessMode::AllowList),2126 nesting: None,2127 }2128 ));21292130 assert_ok!(Unique::add_collection_admin(2131 origin1,2132 collection_id,2133 account(2)2134 ));21352136 assert_ok!(Unique::create_item(2137 origin2,2138 collection_id,2139 account(2),2140 default_nft_data().into()2141 ));2142 });2143}21442145// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and allow listed address.2146#[test]2147fn allow_list_test_11() {2148 new_test_ext().execute_with(|| {2149 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21502151 let origin1 = RuntimeOrigin::signed(1);2152 let origin2 = RuntimeOrigin::signed(2);21532154 assert_ok!(Unique::set_collection_permissions(2155 origin1.clone(),2156 collection_id,2157 CollectionPermissions {2158 mint_mode: Some(false),2159 access: Some(AccessMode::AllowList),2160 nesting: None,2161 }2162 ));2163 assert_ok!(Unique::add_to_allow_list(2164 origin1,2165 collection_id,2166 account(2)2167 ));21682169 assert_noop!(2170 Unique::create_item(2171 origin2,2172 CollectionId(1),2173 account(2),2174 default_nft_data().into()2175 )2176 .map_err(|e| e.error),2177 CommonError::<Test>::PublicMintingNotAllowed2178 );2179 });2180}21812182// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-allow listed address.2183#[test]2184fn allow_list_test_12() {2185 new_test_ext().execute_with(|| {2186 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21872188 let origin1 = RuntimeOrigin::signed(1);2189 let origin2 = RuntimeOrigin::signed(2);21902191 assert_ok!(Unique::set_collection_permissions(2192 origin1.clone(),2193 collection_id,2194 CollectionPermissions {2195 mint_mode: Some(false),2196 access: Some(AccessMode::AllowList),2197 nesting: None,2198 }2199 ));22002201 assert_noop!(2202 Unique::create_item(2203 origin2,2204 CollectionId(1),2205 account(2),2206 default_nft_data().into()2207 )2208 .map_err(|e| e.error),2209 CommonError::<Test>::PublicMintingNotAllowed2210 );2211 });2212}22132214// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner.2215#[test]2216fn allow_list_test_13() {2217 new_test_ext().execute_with(|| {2218 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22192220 let origin1 = RuntimeOrigin::signed(1);22212222 assert_ok!(Unique::set_collection_permissions(2223 origin1.clone(),2224 collection_id,2225 CollectionPermissions {2226 mint_mode: Some(true),2227 access: Some(AccessMode::AllowList),2228 nesting: None,2229 }2230 ));22312232 let data = default_nft_data();2233 create_test_item(collection_id, &data.into());2234 });2235}22362237// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin.2238#[test]2239fn allow_list_test_14() {2240 new_test_ext().execute_with(|| {2241 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22422243 let origin1 = RuntimeOrigin::signed(1);2244 let origin2 = RuntimeOrigin::signed(2);22452246 assert_ok!(Unique::set_collection_permissions(2247 origin1.clone(),2248 collection_id,2249 CollectionPermissions {2250 mint_mode: Some(true),2251 access: Some(AccessMode::AllowList),2252 nesting: None,2253 }2254 ));22552256 assert_ok!(Unique::add_collection_admin(2257 origin1,2258 collection_id,2259 account(2)2260 ));22612262 assert_ok!(Unique::create_item(2263 origin2,2264 collection_id,2265 account(2),2266 default_nft_data().into()2267 ));2268 });2269}22702271// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-allow listed address.2272#[test]2273fn allow_list_test_15() {2274 new_test_ext().execute_with(|| {2275 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22762277 let origin1 = RuntimeOrigin::signed(1);2278 let origin2 = RuntimeOrigin::signed(2);22792280 assert_ok!(Unique::set_collection_permissions(2281 origin1.clone(),2282 collection_id,2283 CollectionPermissions {2284 mint_mode: Some(true),2285 access: Some(AccessMode::AllowList),2286 nesting: None,2287 }2288 ));22892290 assert_noop!(2291 Unique::create_item(2292 origin2,2293 collection_id,2294 account(2),2295 default_nft_data().into()2296 )2297 .map_err(|e| e.error),2298 CommonError::<Test>::AddressNotInAllowlist2299 );2300 });2301}23022303// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by non-privileged and allow listed address.2304#[test]2305fn allow_list_test_16() {2306 new_test_ext().execute_with(|| {2307 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23082309 let origin1 = RuntimeOrigin::signed(1);2310 let origin2 = RuntimeOrigin::signed(2);23112312 assert_ok!(Unique::set_collection_permissions(2313 origin1.clone(),2314 collection_id,2315 CollectionPermissions {2316 mint_mode: Some(true),2317 access: Some(AccessMode::AllowList),2318 nesting: None,2319 }2320 ));2321 assert_ok!(Unique::add_to_allow_list(2322 origin1,2323 collection_id,2324 account(2)2325 ));23262327 assert_ok!(Unique::create_item(2328 origin2,2329 collection_id,2330 account(2),2331 default_nft_data().into()2332 ));2333 });2334}23352336// Total number of collections. Positive test2337#[test]2338fn total_number_collections_bound() {2339 new_test_ext().execute_with(|| {2340 create_test_collection(&CollectionMode::NFT, CollectionId(1));2341 });2342}23432344#[test]2345fn create_max_collections() {2346 new_test_ext().execute_with(|| {2347 for i in 1..COLLECTION_NUMBER_LIMIT {2348 create_test_collection(&CollectionMode::NFT, CollectionId(i));2349 }2350 });2351}23522353// Total number of collections. Negative test2354#[test]2355fn total_number_collections_bound_neg() {2356 new_test_ext().execute_with(|| {2357 let origin1 = RuntimeOrigin::signed(1);23582359 for i in 1..=COLLECTION_NUMBER_LIMIT {2360 create_test_collection(&CollectionMode::NFT, CollectionId(i));2361 }23622363 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();2364 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();2365 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();23662367 let data = CreateCollectionData {2368 name: col_name1.try_into().unwrap(),2369 description: col_desc1.try_into().unwrap(),2370 token_prefix: token_prefix1.try_into().unwrap(),2371 mode: CollectionMode::NFT,2372 ..Default::default()2373 };23742375 // 11-th collection in chain. Expects error2376 assert_noop!(2377 Unique::create_collection_ex(origin1, data),2378 CommonError::<Test>::TotalCollectionsLimitExceeded2379 );2380 });2381}23822383// Owned tokens by a single address. Positive test2384#[test]2385fn owned_tokens_bound() {2386 new_test_ext().execute_with(|| {2387 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23882389 let data = default_nft_data();2390 create_test_item(collection_id, &data.clone().into());2391 create_test_item(collection_id, &data.into());2392 });2393}23942395// Owned tokens by a single address. Negotive test2396#[test]2397fn owned_tokens_bound_neg() {2398 new_test_ext().execute_with(|| {2399 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24002401 let origin1 = RuntimeOrigin::signed(1);24022403 for _ in 1..=MAX_TOKEN_OWNERSHIP {2404 let data = default_nft_data();2405 create_test_item(collection_id, &data.clone().into());2406 }24072408 let data = default_nft_data();2409 assert_noop!(2410 Unique::create_item(origin1, CollectionId(1), account(1), data.into())2411 .map_err(|e| e.error),2412 CommonError::<Test>::AccountTokenLimitExceeded2413 );2414 });2415}24162417// Number of collection admins. Positive test2418#[test]2419fn collection_admins_bound() {2420 new_test_ext().execute_with(|| {2421 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24222423 let origin1 = RuntimeOrigin::signed(1);24242425 assert_ok!(Unique::add_collection_admin(2426 origin1.clone(),2427 collection_id,2428 account(2)2429 ));2430 assert_ok!(Unique::add_collection_admin(2431 origin1,2432 collection_id,2433 account(3)2434 ));2435 });2436}24372438// Number of collection admins. Negotive test2439#[test]2440fn collection_admins_bound_neg() {2441 new_test_ext().execute_with(|| {2442 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24432444 let origin1 = RuntimeOrigin::signed(1);24452446 for i in 0..COLLECTION_ADMINS_LIMIT {2447 assert_ok!(Unique::add_collection_admin(2448 origin1.clone(),2449 collection_id,2450 account((2 + i).into())2451 ));2452 }2453 assert_noop!(2454 Unique::add_collection_admin(2455 origin1,2456 collection_id,2457 account((3 + COLLECTION_ADMINS_LIMIT).into())2458 ),2459 CommonError::<Test>::CollectionAdminCountExceeded2460 );2461 });2462}2463// #endregion24642465#[test]2466fn collection_transfer_flag_works() {2467 new_test_ext().execute_with(|| {2468 let origin1 = RuntimeOrigin::signed(1);24692470 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2471 assert_ok!(Unique::set_transfers_enabled_flag(2472 origin1,2473 collection_id,2474 true2475 ));24762477 let data = default_nft_data();2478 create_test_item(collection_id, &data.into());2479 assert_eq!(2480 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2481 12482 );2483 assert_eq!(2484 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2485 true2486 );24872488 let origin1 = RuntimeOrigin::signed(1);24892490 // default scenario2491 assert_ok!(Unique::transfer(2492 origin1,2493 account(2),2494 collection_id,2495 TokenId(1),2496 12497 ));2498 assert_eq!(2499 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2500 false2501 );2502 assert_eq!(2503 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2504 true2505 );2506 assert_eq!(2507 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2508 02509 );2510 assert_eq!(2511 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2512 12513 );2514 });2515}25162517#[test]2518fn collection_transfer_flag_works_neg() {2519 new_test_ext().execute_with(|| {2520 let origin1 = RuntimeOrigin::signed(1);25212522 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2523 assert_ok!(Unique::set_transfers_enabled_flag(2524 origin1,2525 collection_id,2526 false2527 ));25282529 let data = default_nft_data();2530 create_test_item(collection_id, &data.into());2531 assert_eq!(2532 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2533 12534 );2535 assert_eq!(2536 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2537 true2538 );25392540 let origin1 = RuntimeOrigin::signed(1);25412542 // default scenario2543 assert_noop!(2544 Unique::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)2545 .map_err(|e| e.error),2546 CommonError::<Test>::TransferNotAllowed2547 );2548 assert_eq!(2549 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2550 12551 );2552 assert_eq!(2553 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2554 02555 );2556 assert_eq!(2557 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2558 true2559 );2560 assert_eq!(2561 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2562 false2563 );2564 });2565}25662567#[test]2568fn collection_sponsoring() {2569 new_test_ext().execute_with(|| {2570 // default_limits();2571 let user1 = 1_u64;2572 let user2 = 777_u64;2573 let origin1 = RuntimeOrigin::signed(user1);2574 let origin2 = RuntimeOrigin::signed(user2);2575 let account2 = account(user2);25762577 let collection_id =2578 create_test_collection_for_owner(&CollectionMode::NFT, user1, CollectionId(1));2579 assert_ok!(Unique::set_collection_sponsor(2580 origin1.clone(),2581 collection_id,2582 user12583 ));2584 assert_ok!(Unique::confirm_sponsorship(origin1.clone(), collection_id));25852586 // Expect error while have no permissions2587 assert!(Unique::create_item(2588 origin2.clone(),2589 collection_id,2590 account2.clone(),2591 default_nft_data().into()2592 )2593 .is_err());25942595 assert_ok!(Unique::set_collection_permissions(2596 origin1.clone(),2597 collection_id,2598 CollectionPermissions {2599 mint_mode: Some(true),2600 access: Some(AccessMode::AllowList),2601 nesting: None,2602 }2603 ));2604 assert_ok!(Unique::add_to_allow_list(2605 origin1.clone(),2606 collection_id,2607 account2.clone()2608 ));26092610 assert_ok!(Unique::create_item(2611 origin2,2612 collection_id,2613 account2,2614 default_nft_data().into()2615 ));2616 });2617}26182619mod check_token_permissions {2620 use super::*;2621 use pallet_common::LazyValue;26222623 fn test<FTE: FnOnce() -> bool>(2624 i: usize,2625 test_case: &pallet_common::tests::TestCase,2626 check_token_existence: &mut LazyValue<bool, FTE>,2627 ) {2628 let collection_admin = test_case.collection_admin;2629 let mut is_collection_admin = LazyValue::new(|| test_case.is_collection_admin);2630 let token_owner = test_case.token_owner;2631 let mut is_token_owner = LazyValue::new(|| Ok(test_case.is_token_owner));2632 let is_no_permission = test_case.no_permission;26332634 let result = pallet_common::tests::check_token_permissions::<Test, _, _, FTE>(2635 collection_admin,2636 token_owner,2637 &mut is_collection_admin,2638 &mut is_token_owner,2639 check_token_existence,2640 );26412642 if is_no_permission {2643 assert!(2644 result.is_err(),2645 "{i}: {test_case:?}, token_exist: {}",2646 check_token_existence.value()2647 );2648 assert_err!(result, pallet_common::Error::<Test>::NoPermission,);2649 } else if check_token_existence.has_value() && !check_token_existence.value() {2650 assert!(2651 result.is_err(),2652 "{i}: {test_case:?}, token_exist: {}",2653 check_token_existence.value()2654 );2655 assert_err!(result, pallet_common::Error::<Test>::TokenNotFound,);2656 }2657 }26582659 #[test]2660 fn no_permission_only() {2661 new_test_ext().execute_with(|| {2662 let mut check_token_existence = LazyValue::new(|| true);2663 for (i, row) in pallet_common::tests::TABLE.iter().enumerate() {2664 test(i, row, &mut check_token_existence);2665 }2666 });2667 }26682669 #[test]2670 fn no_permission_and_token_not_found() {2671 new_test_ext().execute_with(|| {2672 for (i, row) in pallet_common::tests::TABLE.iter().enumerate() {2673 // This is inside the loop to keep track of whether the lambda was called2674 let mut check_token_existence = LazyValue::new(|| false);2675 test(i, row, &mut check_token_existence);2676 }2677 });2678 }2679}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Tests to be written here18use frame_support::{assert_err, assert_noop, assert_ok};19use pallet_common::Error as CommonError;20use pallet_evm::account::CrossAccountId;21use pallet_unique::Error as UniqueError;22use sp_std::convert::TryInto;23use up_data_structs::{24 AccessMode, CollectionId, CollectionMode, CollectionPermissions,25 CollectionPropertiesPermissionsVec, CollectionPropertiesVec, CreateCollectionData,26 CreateFungibleData, CreateItemData, CreateNftData, CreateReFungibleData, Property,27 PropertyKeyPermission, PropertyPermission, TokenId, COLLECTION_ADMINS_LIMIT,28 COLLECTION_NUMBER_LIMIT, MAX_DECIMAL_POINTS, MAX_TOKEN_OWNERSHIP,29};3031use crate::{32 new_test_ext, CollectionCreationPrice, RuntimeOrigin, Test, TestCrossAccountId, Unique,33};3435fn add_balance(user: u64, value: u64) {36 const DONOR_USER: u64 = 999;37 assert_ok!(<pallet_balances::Pallet<Test>>::force_set_balance(38 RuntimeOrigin::root(),39 DONOR_USER,40 value,41 ));42 assert_ok!(<pallet_balances::Pallet<Test>>::force_transfer(43 RuntimeOrigin::root(),44 DONOR_USER,45 user,46 value47 ));48}4950fn default_nft_data() -> CreateNftData {51 CreateNftData {52 properties: vec![Property {53 key: b"test-prop".to_vec().try_into().unwrap(),54 value: b"test-nft-prop".to_vec().try_into().unwrap(),55 }]56 .try_into()57 .unwrap(),58 }59}6061fn default_fungible_data() -> CreateFungibleData {62 CreateFungibleData { value: 5 }63}6465fn default_re_fungible_data() -> CreateReFungibleData {66 CreateReFungibleData {67 pieces: 1023,68 properties: vec![Property {69 key: b"test-prop".to_vec().try_into().unwrap(),70 value: b"test-nft-prop".to_vec().try_into().unwrap(),71 }]72 .try_into()73 .unwrap(),74 }75}7677fn create_test_collection_for_owner(78 mode: &CollectionMode,79 owner: u64,80 id: CollectionId,81) -> CollectionId {82 add_balance(owner, CollectionCreationPrice::get() as u64 + 1);8384 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();85 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();86 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();87 let token_property_permissions: CollectionPropertiesPermissionsVec =88 vec![PropertyKeyPermission {89 key: b"test-prop".to_vec().try_into().unwrap(),90 permission: PropertyPermission {91 mutable: true,92 collection_admin: false,93 token_owner: true,94 },95 }]96 .try_into()97 .unwrap();98 let properties: CollectionPropertiesVec = vec![Property {99 key: b"test-collection-prop".to_vec().try_into().unwrap(),100 value: b"test-collection-value".to_vec().try_into().unwrap(),101 }]102 .try_into()103 .unwrap();104105 let data = CreateCollectionData {106 name: col_name1.try_into().unwrap(),107 description: col_desc1.try_into().unwrap(),108 token_prefix: token_prefix1.try_into().unwrap(),109 mode: mode.clone(),110 token_property_permissions: token_property_permissions.clone(),111 properties: properties.clone(),112 ..Default::default()113 };114115 let origin1 = RuntimeOrigin::signed(owner);116 assert_ok!(Unique::create_collection_ex(origin1, data));117118 let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();119 let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();120 let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();121 assert_eq!(122 <pallet_common::CollectionById<Test>>::get(id)123 .unwrap()124 .owner,125 owner126 );127 assert_eq!(128 <pallet_common::CollectionById<Test>>::get(id).unwrap().name,129 saved_col_name130 );131 assert_eq!(132 <pallet_common::CollectionById<Test>>::get(id).unwrap().mode,133 *mode134 );135 assert_eq!(136 <pallet_common::CollectionById<Test>>::get(id)137 .unwrap()138 .description,139 saved_description140 );141 assert_eq!(142 <pallet_common::CollectionById<Test>>::get(id)143 .unwrap()144 .token_prefix,145 saved_prefix146 );147 assert_eq!(148 get_collection_property_permissions(id).as_slice(),149 token_property_permissions.as_slice()150 );151 assert_eq!(152 get_collection_properties(id).as_slice(),153 properties.as_slice()154 );155 id156}157158fn get_collection_property_permissions(collection_id: CollectionId) -> Vec<PropertyKeyPermission> {159 <pallet_common::Pallet<Test>>::property_permissions(collection_id)160 .into_iter()161 .map(|(key, permission)| PropertyKeyPermission { key, permission })162 .collect()163}164165fn get_collection_properties(collection_id: CollectionId) -> Vec<Property> {166 <pallet_common::Pallet<Test>>::collection_properties(collection_id)167 .into_iter()168 .map(|(key, value)| Property { key, value })169 .collect()170}171172fn get_token_properties(collection_id: CollectionId, token_id: TokenId) -> Vec<Property> {173 <pallet_nonfungible::Pallet<Test>>::token_properties((collection_id, token_id))174 .unwrap_or_default()175 .into_iter()176 .map(|(key, value)| Property { key, value })177 .collect()178}179180fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {181 create_test_collection_for_owner(&mode, 1, id)182}183184fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {185 let origin1 = RuntimeOrigin::signed(1);186 assert_ok!(Unique::create_item(187 origin1,188 collection_id,189 account(1),190 data.clone()191 ));192}193194fn account(sub: u64) -> TestCrossAccountId {195 TestCrossAccountId::from_sub(sub)196}197198// Use cases tests region199// #region200201#[test]202fn check_not_sufficient_founds() {203 new_test_ext().execute_with(|| {204 let acc: u64 = 1;205 <pallet_balances::Pallet<Test>>::force_set_balance(RuntimeOrigin::root(), acc, 0).unwrap();206207 let name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();208 let description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();209 let token_prefix: Vec<u8> = b"token_prefix1\0".to_vec();210211 let data = CreateCollectionData {212 name: name.try_into().unwrap(),213 description: description.try_into().unwrap(),214 token_prefix: token_prefix.try_into().unwrap(),215 mode: CollectionMode::NFT,216 ..Default::default()217 };218219 let result = Unique::create_collection_ex(RuntimeOrigin::signed(acc), data);220 assert_err!(result, <CommonError<Test>>::NotSufficientFounds);221 });222}223224#[test]225fn create_fungible_collection_fails_with_large_decimal_numbers() {226 new_test_ext().execute_with(|| {227 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();228 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();229 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();230231 let data = CreateCollectionData {232 name: col_name1.try_into().unwrap(),233 description: col_desc1.try_into().unwrap(),234 token_prefix: token_prefix1.try_into().unwrap(),235 mode: CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1),236 ..Default::default()237 };238239 let origin1 = RuntimeOrigin::signed(1);240 assert_noop!(241 Unique::create_collection_ex(origin1, data),242 UniqueError::<Test>::CollectionDecimalPointLimitExceeded243 );244 });245}246247#[test]248fn create_nft_item() {249 new_test_ext().execute_with(|| {250 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));251252 let data = default_nft_data();253 create_test_item(collection_id, &data.clone().into());254255 assert_eq!(256 get_token_properties(collection_id, TokenId(1)).as_slice(),257 data.properties.as_slice(),258 );259 });260}261262// Use cases tests region263// #region264#[test]265fn create_nft_multiple_items() {266 new_test_ext().execute_with(|| {267 create_test_collection(&CollectionMode::NFT, CollectionId(1));268269 let origin1 = RuntimeOrigin::signed(1);270271 let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];272273 assert_ok!(Unique::create_multiple_items(274 origin1,275 CollectionId(1),276 account(1),277 items_data278 .clone()279 .into_iter()280 .map(|d| { d.into() })281 .collect()282 ));283 for (index, data) in items_data.into_iter().enumerate() {284 assert_eq!(285 get_token_properties(CollectionId(1), TokenId(index as u32 + 1)).as_slice(),286 data.properties.as_slice()287 );288 }289 });290}291292#[test]293fn create_refungible_item() {294 new_test_ext().execute_with(|| {295 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));296297 let data = default_re_fungible_data();298 create_test_item(collection_id, &data.clone().into());299 let balance =300 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));301 assert_eq!(balance, 1023);302 });303}304305#[test]306fn create_multiple_refungible_items() {307 new_test_ext().execute_with(|| {308 create_test_collection(&CollectionMode::ReFungible, CollectionId(1));309310 let origin1 = RuntimeOrigin::signed(1);311312 let items_data = vec![313 default_re_fungible_data(),314 default_re_fungible_data(),315 default_re_fungible_data(),316 ];317318 assert_ok!(Unique::create_multiple_items(319 origin1,320 CollectionId(1),321 account(1),322 items_data323 .clone()324 .into_iter()325 .map(|d| { d.into() })326 .collect()327 ));328 for (index, _data) in items_data.into_iter().enumerate() {329 let balance = <pallet_refungible::Balance<Test>>::get((330 CollectionId(1),331 TokenId((index + 1) as u32),332 account(1),333 ));334 assert_eq!(balance, 1023);335 }336 });337}338339#[test]340fn create_fungible_item() {341 new_test_ext().execute_with(|| {342 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));343344 let data = default_fungible_data();345 create_test_item(collection_id, &data.into());346347 assert_eq!(348 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),349 5350 );351 });352}353354//#[test]355// fn create_multiple_fungible_items() {356// new_test_ext().execute_with(|| {357// default_limits();358359// create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));360361// let origin1 = RuntimeOrigin::signed(1);362363// let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];364365// assert_ok!(Unique::create_multiple_items(366// origin1.clone(),367// 1,368// 1,369// items_data.clone().into_iter().map(|d| { d.into() }).collect()370// ));371372// for (index, _) in items_data.iter().enumerate() {373// assert_eq!(Unique::fungible_item_id(1, (index + 1) as TokenId).value, 5);374// }375// assert_eq!(Unique::balance_count(1, 1), 3000);376// assert_eq!(Unique::address_tokens(1, 1), [1, 2, 3]);377// });378// }379380#[test]381fn transfer_fungible_item() {382 new_test_ext().execute_with(|| {383 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));384385 let origin1 = RuntimeOrigin::signed(1);386 let origin2 = RuntimeOrigin::signed(2);387388 let data = default_fungible_data();389 create_test_item(collection_id, &data.into());390391 assert_eq!(392 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),393 5394 );395396 // change owner scenario397 assert_ok!(Unique::transfer(398 origin1,399 account(2),400 CollectionId(1),401 TokenId(0),402 5403 ));404 assert_eq!(405 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),406 0407 );408409 // split item scenario410 assert_ok!(Unique::transfer(411 origin2.clone(),412 account(3),413 CollectionId(1),414 TokenId(0),415 3416 ));417418 // split item and new owner has account scenario419 assert_ok!(Unique::transfer(420 origin2,421 account(3),422 CollectionId(1),423 TokenId(0),424 1425 ));426 assert_eq!(427 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))),428 1429 );430 assert_eq!(431 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))),432 4433 );434 });435}436437#[test]438fn transfer_refungible_item() {439 new_test_ext().execute_with(|| {440 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));441442 // Create RFT 1 in 1023 pieces for account 1443 let data = default_re_fungible_data();444 create_test_item(collection_id, &data.clone().into());445 assert_eq!(446 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),447 1448 );449 assert_eq!(450 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),451 1023452 );453 assert_eq!(454 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),455 true456 );457458 // Account 1 transfers all 1023 pieces of RFT 1 to account 2459 let origin1 = RuntimeOrigin::signed(1);460 let origin2 = RuntimeOrigin::signed(2);461 assert_ok!(Unique::transfer(462 origin1,463 account(2),464 CollectionId(1),465 TokenId(1),466 1023467 ));468 assert_eq!(469 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),470 1023471 );472 assert_eq!(473 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),474 0475 );476 assert_eq!(477 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),478 1479 );480 assert_eq!(481 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),482 false483 );484 assert_eq!(485 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),486 true487 );488489 // Account 2 transfers 500 pieces of RFT 1 to account 3490 assert_ok!(Unique::transfer(491 origin2.clone(),492 account(3),493 CollectionId(1),494 TokenId(1),495 500496 ));497 assert_eq!(498 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),499 523500 );501 assert_eq!(502 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),503 500504 );505 assert_eq!(506 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),507 1508 );509 assert_eq!(510 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),511 1512 );513 assert_eq!(514 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),515 true516 );517 assert_eq!(518 <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),519 true520 );521522 // Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance523 assert_ok!(Unique::transfer(524 origin2,525 account(3),526 CollectionId(1),527 TokenId(1),528 200529 ));530 assert_eq!(531 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),532 323533 );534 assert_eq!(535 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),536 700537 );538 assert_eq!(539 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),540 1541 );542 assert_eq!(543 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),544 1545 );546 assert_eq!(547 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),548 true549 );550 assert_eq!(551 <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),552 true553 );554 });555}556557#[test]558fn transfer_nft_item() {559 new_test_ext().execute_with(|| {560 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));561562 let data = default_nft_data();563 create_test_item(collection_id, &data.into());564 assert_eq!(565 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),566 1567 );568 assert_eq!(569 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),570 true571 );572573 let origin1 = RuntimeOrigin::signed(1);574 // default scenario575 assert_ok!(Unique::transfer(576 origin1,577 account(2),578 CollectionId(1),579 TokenId(1),580 1581 ));582 assert_eq!(583 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),584 0585 );586 assert_eq!(587 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),588 1589 );590 assert_eq!(591 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),592 false593 );594 assert_eq!(595 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),596 true597 );598 });599}600601#[test]602fn transfer_nft_item_wrong_value() {603 new_test_ext().execute_with(|| {604 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));605606 let data = default_nft_data();607 create_test_item(collection_id, &data.into());608 assert_eq!(609 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),610 1611 );612 assert_eq!(613 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),614 true615 );616617 let origin1 = RuntimeOrigin::signed(1);618619 assert_noop!(620 Unique::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2)621 .map_err(|e| e.error),622 <pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount623 );624 });625}626627#[test]628fn transfer_nft_item_zero_value() {629 new_test_ext().execute_with(|| {630 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));631632 let data = default_nft_data();633 create_test_item(collection_id, &data.into());634 assert_eq!(635 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),636 1637 );638 assert_eq!(639 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),640 true641 );642643 let origin1 = RuntimeOrigin::signed(1);644645 // Transferring 0 amount works on NFT...646 assert_ok!(Unique::transfer(647 origin1,648 account(2),649 CollectionId(1),650 TokenId(1),651 0652 ));653 // ... and results in no transfer654 assert_eq!(655 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),656 1657 );658 assert_eq!(659 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),660 true661 );662 });663}664665#[test]666fn nft_approve_and_transfer_from() {667 new_test_ext().execute_with(|| {668 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));669670 let data = default_nft_data();671 create_test_item(collection_id, &data.into());672673 let origin1 = RuntimeOrigin::signed(1);674 let origin2 = RuntimeOrigin::signed(2);675676 assert_eq!(677 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),678 1679 );680 assert_eq!(681 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),682 true683 );684685 // neg transfer_from686 assert_noop!(687 Unique::transfer_from(688 origin2.clone(),689 account(1),690 account(2),691 CollectionId(1),692 TokenId(1),693 1694 )695 .map_err(|e| e.error),696 CommonError::<Test>::ApprovedValueTooLow697 );698699 // do approve700 assert_ok!(Unique::approve(701 origin1,702 account(2),703 CollectionId(1),704 TokenId(1),705 1706 ));707 assert_eq!(708 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),709 account(2)710 );711712 assert_ok!(Unique::transfer_from(713 origin2,714 account(1),715 account(3),716 CollectionId(1),717 TokenId(1),718 1719 ));720 assert!(721 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()722 );723 });724}725726#[test]727fn nft_approve_and_transfer_from_allow_list() {728 new_test_ext().execute_with(|| {729 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));730731 let origin1 = RuntimeOrigin::signed(1);732 let origin2 = RuntimeOrigin::signed(2);733734 // Create NFT 1 for account 1735 let data = default_nft_data();736 create_test_item(collection_id, &data.clone().into());737 assert_eq!(738 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),739 1740 );741 assert_eq!(742 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),743 true744 );745746 // Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list747 assert_ok!(Unique::set_collection_permissions(748 origin1.clone(),749 CollectionId(1),750 CollectionPermissions {751 mint_mode: Some(true),752 access: Some(AccessMode::AllowList),753 nesting: None,754 }755 ));756 assert_ok!(Unique::add_to_allow_list(757 origin1.clone(),758 CollectionId(1),759 account(1)760 ));761 assert_ok!(Unique::add_to_allow_list(762 origin1.clone(),763 CollectionId(1),764 account(2)765 ));766 assert_ok!(Unique::add_to_allow_list(767 origin1.clone(),768 CollectionId(1),769 account(3)770 ));771772 // Account 1 approves account 2 for NFT 1773 assert_ok!(Unique::approve(774 origin1.clone(),775 account(2),776 CollectionId(1),777 TokenId(1),778 1779 ));780 assert_eq!(781 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),782 account(2)783 );784785 // Account 2 transfers NFT 1 from account 1 to account 3786 assert_ok!(Unique::transfer_from(787 origin2,788 account(1),789 account(3),790 CollectionId(1),791 TokenId(1),792 1793 ));794 assert!(795 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()796 );797 });798}799800#[test]801fn refungible_approve_and_transfer_from() {802 new_test_ext().execute_with(|| {803 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));804805 let origin1 = RuntimeOrigin::signed(1);806 let origin2 = RuntimeOrigin::signed(2);807808 // Create RFT 1 in 1023 pieces for account 1809 let data = default_re_fungible_data();810 create_test_item(collection_id, &data.into());811812 assert_eq!(813 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),814 1815 );816 assert_eq!(817 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),818 1023819 );820 assert_eq!(821 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),822 true823 );824825 // Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list826 assert_ok!(Unique::set_collection_permissions(827 origin1.clone(),828 CollectionId(1),829 CollectionPermissions {830 mint_mode: Some(true),831 access: Some(AccessMode::AllowList),832 nesting: None,833 }834 ));835 assert_ok!(Unique::add_to_allow_list(836 origin1.clone(),837 CollectionId(1),838 account(1)839 ));840 assert_ok!(Unique::add_to_allow_list(841 origin1.clone(),842 CollectionId(1),843 account(2)844 ));845 assert_ok!(Unique::add_to_allow_list(846 origin1.clone(),847 CollectionId(1),848 account(3)849 ));850851 // Account 1 approves account 2 for 1023 pieces of RFT 1852 assert_ok!(Unique::approve(853 origin1,854 account(2),855 CollectionId(1),856 TokenId(1),857 1023858 ));859 assert_eq!(860 <pallet_refungible::Allowance<Test>>::get((861 CollectionId(1),862 TokenId(1),863 account(1),864 account(2)865 )),866 1023867 );868869 // Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3870 assert_ok!(Unique::transfer_from(871 origin2,872 account(1),873 account(3),874 CollectionId(1),875 TokenId(1),876 100877 ));878 assert_eq!(879 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),880 1881 );882 assert_eq!(883 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),884 1885 );886 assert_eq!(887 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),888 923889 );890 assert_eq!(891 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),892 100893 );894 assert_eq!(895 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),896 true897 );898 assert_eq!(899 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),900 true901 );902 assert_eq!(903 <pallet_refungible::Allowance<Test>>::get((904 CollectionId(1),905 TokenId(1),906 account(1),907 account(2)908 )),909 923910 );911 });912}913914#[test]915fn fungible_approve_and_transfer_from() {916 new_test_ext().execute_with(|| {917 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));918919 let data = default_fungible_data();920 create_test_item(collection_id, &data.into());921922 let origin1 = RuntimeOrigin::signed(1);923 let origin2 = RuntimeOrigin::signed(2);924925 assert_ok!(Unique::set_collection_permissions(926 origin1.clone(),927 CollectionId(1),928 CollectionPermissions {929 mint_mode: Some(true),930 access: Some(AccessMode::AllowList),931 nesting: None,932 }933 ));934 assert_ok!(Unique::add_to_allow_list(935 origin1.clone(),936 CollectionId(1),937 account(1)938 ));939 assert_ok!(Unique::add_to_allow_list(940 origin1.clone(),941 CollectionId(1),942 account(2)943 ));944 assert_ok!(Unique::add_to_allow_list(945 origin1.clone(),946 CollectionId(1),947 account(3)948 ));949950 // do approve951 assert_ok!(Unique::approve(952 origin1.clone(),953 account(2),954 CollectionId(1),955 TokenId(0),956 5957 ));958 assert_eq!(959 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),960 5961 );962 assert_ok!(Unique::approve(963 origin1,964 account(3),965 CollectionId(1),966 TokenId(0),967 5968 ));969 assert_eq!(970 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),971 5972 );973 assert_eq!(974 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))),975 5976 );977978 assert_ok!(Unique::transfer_from(979 origin2.clone(),980 account(1),981 account(3),982 CollectionId(1),983 TokenId(0),984 4985 ));986987 assert_eq!(988 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),989 1990 );991992 assert_noop!(993 Unique::transfer_from(994 origin2,995 account(1),996 account(3),997 CollectionId(1),998 TokenId(0),999 41000 )1001 .map_err(|e| e.error),1002 CommonError::<Test>::ApprovedValueTooLow1003 );1004 });1005}10061007#[test]1008fn change_collection_owner() {1009 new_test_ext().execute_with(|| {1010 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10111012 let origin1 = RuntimeOrigin::signed(1);1013 assert_ok!(Unique::change_collection_owner(origin1, collection_id, 2));1014 assert_eq!(1015 <pallet_common::CollectionById<Test>>::get(collection_id)1016 .unwrap()1017 .owner,1018 21019 );1020 });1021}10221023#[test]1024fn destroy_collection() {1025 new_test_ext().execute_with(|| {1026 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10271028 let origin1 = RuntimeOrigin::signed(1);1029 assert_ok!(Unique::destroy_collection(origin1, collection_id));1030 });1031}10321033#[test]1034fn burn_nft_item() {1035 new_test_ext().execute_with(|| {1036 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10371038 let origin1 = RuntimeOrigin::signed(1);10391040 let data = default_nft_data();1041 create_test_item(collection_id, &data.into());10421043 // check balance (collection with id = 1, user id = 1)1044 assert_eq!(1045 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1046 11047 );10481049 // burn item1050 assert_ok!(Unique::burn_item(1051 origin1.clone(),1052 collection_id,1053 TokenId(1),1054 11055 ));1056 assert_eq!(1057 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1058 01059 );1060 });1061}10621063#[test]1064fn burn_same_nft_item_twice() {1065 new_test_ext().execute_with(|| {1066 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10671068 let origin1 = RuntimeOrigin::signed(1);10691070 let data = default_nft_data();1071 create_test_item(collection_id, &data.into());10721073 // check balance (collection with id = 1, user id = 1)1074 assert_eq!(1075 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1076 11077 );10781079 // burn item1080 assert_ok!(Unique::burn_item(1081 origin1.clone(),1082 collection_id,1083 TokenId(1),1084 11085 ));10861087 // burn item again1088 assert_noop!(1089 Unique::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),1090 CommonError::<Test>::TokenNotFound1091 );10921093 assert_eq!(1094 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1095 01096 );1097 });1098}10991100#[test]1101fn burn_fungible_item() {1102 new_test_ext().execute_with(|| {1103 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));11041105 let origin1 = RuntimeOrigin::signed(1);1106 assert_ok!(Unique::add_collection_admin(1107 origin1.clone(),1108 collection_id,1109 account(2)1110 ));11111112 let data = default_fungible_data();1113 create_test_item(collection_id, &data.into());11141115 // check balance (collection with id = 1, user id = 1)1116 assert_eq!(1117 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1118 51119 );11201121 // burn item1122 assert_ok!(Unique::burn_item(1123 origin1.clone(),1124 CollectionId(1),1125 TokenId(0),1126 51127 ));1128 assert_noop!(1129 Unique::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),1130 CommonError::<Test>::TokenValueTooLow1131 );11321133 assert_eq!(1134 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1135 01136 );1137 });1138}11391140#[test]1141fn burn_fungible_item_with_token_id() {1142 new_test_ext().execute_with(|| {1143 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));11441145 let origin1 = RuntimeOrigin::signed(1);1146 assert_ok!(Unique::add_collection_admin(1147 origin1.clone(),1148 collection_id,1149 account(2)1150 ));11511152 let data = default_fungible_data();1153 create_test_item(collection_id, &data.into());11541155 // check balance (collection with id = 1, user id = 1)1156 assert_eq!(1157 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1158 51159 );11601161 // Try to burn item using Token ID1162 assert_noop!(1163 Unique::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),1164 <pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId1165 );1166 });1167}1168#[test]1169fn burn_refungible_item() {1170 new_test_ext().execute_with(|| {1171 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));1172 let origin1 = RuntimeOrigin::signed(1);11731174 assert_ok!(Unique::set_collection_permissions(1175 origin1.clone(),1176 collection_id,1177 CollectionPermissions {1178 mint_mode: Some(true),1179 access: Some(AccessMode::AllowList),1180 nesting: None,1181 }1182 ));1183 assert_ok!(Unique::add_to_allow_list(1184 origin1.clone(),1185 collection_id,1186 account(1)1187 ));11881189 assert_ok!(Unique::add_collection_admin(1190 origin1.clone(),1191 collection_id,1192 account(2)1193 ));11941195 let data = default_re_fungible_data();1196 create_test_item(collection_id, &data.into());11971198 // check balance (collection with id = 1, user id = 2)1199 assert_eq!(1200 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),1201 11202 );1203 assert_eq!(1204 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1205 10231206 );12071208 // burn item1209 assert_ok!(Unique::burn_item(1210 origin1.clone(),1211 collection_id,1212 TokenId(1),1213 10231214 ));1215 assert_noop!(1216 Unique::burn_item(origin1, collection_id, TokenId(1), 1023).map_err(|e| e.error),1217 CommonError::<Test>::TokenValueTooLow1218 );12191220 assert_eq!(1221 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1222 01223 );1224 });1225}12261227#[test]1228fn add_collection_admin() {1229 new_test_ext().execute_with(|| {1230 let collection1_id =1231 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1232 let origin1 = RuntimeOrigin::signed(1);12331234 // Add collection admins1235 assert_ok!(Unique::add_collection_admin(1236 origin1.clone(),1237 collection1_id,1238 account(2)1239 ));1240 assert_ok!(Unique::add_collection_admin(1241 origin1,1242 collection1_id,1243 account(3)1244 ));12451246 // Owner is not an admin by default1247 assert_eq!(1248 <pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))),1249 false1250 );1251 assert!(<pallet_common::IsAdmin<Test>>::get((1252 CollectionId(1),1253 account(2)1254 )));1255 assert!(<pallet_common::IsAdmin<Test>>::get((1256 CollectionId(1),1257 account(3)1258 )));1259 });1260}12611262#[test]1263fn remove_collection_admin() {1264 new_test_ext().execute_with(|| {1265 let collection1_id =1266 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1267 let origin1 = RuntimeOrigin::signed(1);12681269 // Add collection admins 2 and 31270 assert_ok!(Unique::add_collection_admin(1271 origin1.clone(),1272 collection1_id,1273 account(2)1274 ));1275 assert_ok!(Unique::add_collection_admin(1276 origin1.clone(),1277 collection1_id,1278 account(3)1279 ));12801281 assert!(<pallet_common::IsAdmin<Test>>::get((1282 CollectionId(1),1283 account(2)1284 )));1285 assert!(<pallet_common::IsAdmin<Test>>::get((1286 CollectionId(1),1287 account(3)1288 )));12891290 // remove admin 31291 assert_ok!(Unique::remove_collection_admin(1292 origin1,1293 CollectionId(1),1294 account(3)1295 ));12961297 // 2 is still admin, 3 is not an admin anymore1298 assert!(<pallet_common::IsAdmin<Test>>::get((1299 CollectionId(1),1300 account(2)1301 )));1302 assert_eq!(1303 <pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))),1304 false1305 );1306 });1307}13081309#[test]1310fn balance_of() {1311 new_test_ext().execute_with(|| {1312 let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1313 let fungible_collection_id =1314 create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));1315 let re_fungible_collection_id =1316 create_test_collection(&CollectionMode::ReFungible, CollectionId(3));13171318 // check balance before1319 assert_eq!(1320 <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1321 01322 );1323 assert_eq!(1324 <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1325 01326 );1327 assert_eq!(1328 <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1329 01330 );13311332 let nft_data = default_nft_data();1333 create_test_item(nft_collection_id, &nft_data.into());13341335 let fungible_data = default_fungible_data();1336 create_test_item(fungible_collection_id, &fungible_data.into());13371338 let re_fungible_data = default_re_fungible_data();1339 create_test_item(re_fungible_collection_id, &re_fungible_data.into());13401341 // check balance (collection with id = 1, user id = 1)1342 assert_eq!(1343 <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1344 11345 );1346 assert_eq!(1347 <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1348 51349 );1350 assert_eq!(1351 <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1352 11353 );13541355 assert_eq!(1356 <pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))),1357 true1358 );1359 assert_eq!(1360 <pallet_refungible::Owned<Test>>::get((1361 re_fungible_collection_id,1362 account(1),1363 TokenId(1)1364 )),1365 true1366 );1367 });1368}13691370#[test]1371fn approve() {1372 new_test_ext().execute_with(|| {1373 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));13741375 let data = default_nft_data();1376 create_test_item(collection_id, &data.into());13771378 let origin1 = RuntimeOrigin::signed(1);13791380 // approve1381 assert_ok!(Unique::approve(1382 origin1,1383 account(2),1384 CollectionId(1),1385 TokenId(1),1386 11387 ));1388 assert_eq!(1389 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1390 account(2)1391 );1392 });1393}13941395#[test]1396fn transfer_from() {1397 new_test_ext().execute_with(|| {1398 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1399 let origin1 = RuntimeOrigin::signed(1);1400 let origin2 = RuntimeOrigin::signed(2);14011402 let data = default_nft_data();1403 create_test_item(collection_id, &data.into());14041405 // approve1406 assert_ok!(Unique::approve(1407 origin1.clone(),1408 account(2),1409 CollectionId(1),1410 TokenId(1),1411 11412 ));1413 assert_eq!(1414 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1415 account(2)1416 );14171418 assert_ok!(Unique::set_collection_permissions(1419 origin1.clone(),1420 CollectionId(1),1421 CollectionPermissions {1422 mint_mode: Some(true),1423 access: Some(AccessMode::AllowList),1424 nesting: None,1425 }1426 ));1427 assert_ok!(Unique::add_to_allow_list(1428 origin1.clone(),1429 CollectionId(1),1430 account(1)1431 ));1432 assert_ok!(Unique::add_to_allow_list(1433 origin1.clone(),1434 CollectionId(1),1435 account(2)1436 ));1437 assert_ok!(Unique::add_to_allow_list(1438 origin1,1439 CollectionId(1),1440 account(3)1441 ));14421443 assert_ok!(Unique::transfer_from(1444 origin2,1445 account(1),1446 account(2),1447 CollectionId(1),1448 TokenId(1),1449 11450 ));14511452 // after transfer1453 assert_eq!(1454 <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))),1455 01456 );1457 assert_eq!(1458 <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))),1459 11460 );1461 });1462}14631464// #endregion14651466// Coverage tests region1467// #region14681469#[test]1470fn owner_can_add_address_to_allow_list() {1471 new_test_ext().execute_with(|| {1472 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14731474 let origin1 = RuntimeOrigin::signed(1);1475 assert_ok!(Unique::add_to_allow_list(1476 origin1,1477 collection_id,1478 account(2)1479 ));1480 assert!(<pallet_common::Allowlist<Test>>::get((1481 collection_id,1482 account(2)1483 )));1484 });1485}14861487#[test]1488fn admin_can_add_address_to_allow_list() {1489 new_test_ext().execute_with(|| {1490 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1491 let origin1 = RuntimeOrigin::signed(1);1492 let origin2 = RuntimeOrigin::signed(2);14931494 assert_ok!(Unique::add_collection_admin(1495 origin1,1496 collection_id,1497 account(2)1498 ));1499 assert_ok!(Unique::add_to_allow_list(1500 origin2,1501 collection_id,1502 account(3)1503 ));1504 assert!(<pallet_common::Allowlist<Test>>::get((1505 collection_id,1506 account(3)1507 )));1508 });1509}15101511#[test]1512fn nonprivileged_user_cannot_add_address_to_allow_list() {1513 new_test_ext().execute_with(|| {1514 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15151516 let origin2 = RuntimeOrigin::signed(2);1517 assert_noop!(1518 Unique::add_to_allow_list(origin2, collection_id, account(3)),1519 CommonError::<Test>::NoPermission1520 );1521 });1522}15231524#[test]1525fn nobody_can_add_address_to_allow_list_of_nonexisting_collection() {1526 new_test_ext().execute_with(|| {1527 let origin1 = RuntimeOrigin::signed(1);15281529 assert_noop!(1530 Unique::add_to_allow_list(origin1, CollectionId(1), account(2)),1531 CommonError::<Test>::CollectionNotFound1532 );1533 });1534}15351536#[test]1537fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1538 new_test_ext().execute_with(|| {1539 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15401541 let origin1 = RuntimeOrigin::signed(1);1542 assert_ok!(Unique::destroy_collection(origin1.clone(), collection_id));1543 assert_noop!(1544 Unique::add_to_allow_list(origin1, collection_id, account(2)),1545 CommonError::<Test>::CollectionNotFound1546 );1547 });1548}15491550// If address is already added to allow list, nothing happens1551#[test]1552fn address_is_already_added_to_allow_list() {1553 new_test_ext().execute_with(|| {1554 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1555 let origin1 = RuntimeOrigin::signed(1);15561557 assert_ok!(Unique::add_to_allow_list(1558 origin1.clone(),1559 collection_id,1560 account(2)1561 ));1562 assert_ok!(Unique::add_to_allow_list(1563 origin1,1564 collection_id,1565 account(2)1566 ));1567 assert!(<pallet_common::Allowlist<Test>>::get((1568 collection_id,1569 account(2)1570 )));1571 });1572}15731574#[test]1575fn owner_can_remove_address_from_allow_list() {1576 new_test_ext().execute_with(|| {1577 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15781579 let origin1 = RuntimeOrigin::signed(1);1580 assert_ok!(Unique::add_to_allow_list(1581 origin1.clone(),1582 collection_id,1583 account(2)1584 ));1585 assert_ok!(Unique::remove_from_allow_list(1586 origin1,1587 collection_id,1588 account(2)1589 ));1590 assert_eq!(1591 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1592 false1593 );1594 });1595}15961597#[test]1598fn admin_can_remove_address_from_allow_list() {1599 new_test_ext().execute_with(|| {1600 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1601 let origin1 = RuntimeOrigin::signed(1);1602 let origin2 = RuntimeOrigin::signed(2);16031604 // Owner adds admin1605 assert_ok!(Unique::add_collection_admin(1606 origin1.clone(),1607 collection_id,1608 account(2)1609 ));16101611 // Owner adds address 3 to allow list1612 assert_ok!(Unique::add_to_allow_list(1613 origin1,1614 collection_id,1615 account(3)1616 ));16171618 // Admin removes address 3 from allow list1619 assert_ok!(Unique::remove_from_allow_list(1620 origin2,1621 collection_id,1622 account(3)1623 ));1624 assert_eq!(1625 <pallet_common::Allowlist<Test>>::get((collection_id, account(3))),1626 false1627 );1628 });1629}16301631#[test]1632fn nonprivileged_user_cannot_remove_address_from_allow_list() {1633 new_test_ext().execute_with(|| {1634 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1635 let origin1 = RuntimeOrigin::signed(1);1636 let origin2 = RuntimeOrigin::signed(2);16371638 assert_ok!(Unique::add_to_allow_list(1639 origin1,1640 collection_id,1641 account(2)1642 ));1643 assert_noop!(1644 Unique::remove_from_allow_list(origin2, collection_id, account(2)),1645 CommonError::<Test>::NoPermission1646 );1647 assert!(<pallet_common::Allowlist<Test>>::get((1648 collection_id,1649 account(2)1650 )));1651 });1652}16531654#[test]1655fn nobody_can_remove_address_from_allow_list_of_nonexisting_collection() {1656 new_test_ext().execute_with(|| {1657 let origin1 = RuntimeOrigin::signed(1);16581659 assert_noop!(1660 Unique::remove_from_allow_list(origin1, CollectionId(1), account(2)),1661 CommonError::<Test>::CollectionNotFound1662 );1663 });1664}16651666#[test]1667fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1668 new_test_ext().execute_with(|| {1669 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1670 let origin1 = RuntimeOrigin::signed(1);1671 let origin2 = RuntimeOrigin::signed(2);16721673 // Add account 2 to allow list1674 assert_ok!(Unique::add_to_allow_list(1675 origin1.clone(),1676 collection_id,1677 account(2)1678 ));16791680 // Account 2 is in collection allow-list1681 assert!(<pallet_common::Allowlist<Test>>::get((1682 collection_id,1683 account(2)1684 )));16851686 // Destroy collection1687 assert_ok!(Unique::destroy_collection(origin1, collection_id));16881689 // Attempt to remove account 2 from collection allow-list => error1690 assert_noop!(1691 Unique::remove_from_allow_list(origin2, collection_id, account(2)),1692 CommonError::<Test>::CollectionNotFound1693 );16941695 // Account 2 is not found in collection allow-list anyway1696 assert_eq!(1697 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1698 false1699 );1700 });1701}17021703// If address is already removed from allow list, nothing happens1704#[test]1705fn address_is_already_removed_from_allow_list() {1706 new_test_ext().execute_with(|| {1707 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1708 let origin1 = RuntimeOrigin::signed(1);17091710 assert_ok!(Unique::add_to_allow_list(1711 origin1.clone(),1712 collection_id,1713 account(2)1714 ));1715 assert_ok!(Unique::remove_from_allow_list(1716 origin1.clone(),1717 collection_id,1718 account(2)1719 ));1720 assert_eq!(1721 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1722 false1723 );1724 assert_ok!(Unique::remove_from_allow_list(1725 origin1,1726 collection_id,1727 account(2)1728 ));1729 assert_eq!(1730 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1731 false1732 );1733 });1734}17351736// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1737#[test]1738fn allow_list_test_1() {1739 new_test_ext().execute_with(|| {1740 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17411742 let origin1 = RuntimeOrigin::signed(1);1743 assert_ok!(Unique::add_collection_admin(1744 origin1.clone(),1745 collection_id,1746 account(1)1747 ));17481749 let data = default_nft_data();1750 create_test_item(collection_id, &data.into());17511752 assert_ok!(Unique::set_collection_permissions(1753 origin1.clone(),1754 collection_id,1755 CollectionPermissions {1756 mint_mode: None,1757 access: Some(AccessMode::AllowList),1758 nesting: None,1759 }1760 ));1761 assert_ok!(Unique::add_to_allow_list(1762 origin1.clone(),1763 collection_id,1764 account(2)1765 ));17661767 assert_noop!(1768 Unique::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1)1769 .map_err(|e| e.error),1770 CommonError::<Test>::AddressNotInAllowlist1771 );1772 });1773}17741775#[test]1776fn allow_list_test_2() {1777 new_test_ext().execute_with(|| {1778 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1779 let origin1 = RuntimeOrigin::signed(1);17801781 let data = default_nft_data();1782 create_test_item(collection_id, &data.into());17831784 assert_ok!(Unique::set_collection_permissions(1785 origin1.clone(),1786 collection_id,1787 CollectionPermissions {1788 mint_mode: None,1789 access: Some(AccessMode::AllowList),1790 nesting: None,1791 }1792 ));1793 assert_ok!(Unique::add_to_allow_list(1794 origin1.clone(),1795 collection_id,1796 account(1)1797 ));1798 assert_ok!(Unique::add_to_allow_list(1799 origin1.clone(),1800 collection_id,1801 account(2)1802 ));18031804 // do approve1805 assert_ok!(Unique::approve(1806 origin1.clone(),1807 account(1),1808 collection_id,1809 TokenId(1),1810 11811 ));1812 assert_eq!(1813 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1814 account(1)1815 );18161817 assert_ok!(Unique::remove_from_allow_list(1818 origin1.clone(),1819 collection_id,1820 account(1)1821 ));18221823 assert_noop!(1824 Unique::transfer_from(1825 origin1,1826 account(1),1827 account(3),1828 CollectionId(1),1829 TokenId(1),1830 11831 )1832 .map_err(|e| e.error),1833 CommonError::<Test>::AddressNotInAllowlist1834 );1835 });1836}18371838// If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom (2 tests)1839#[test]1840fn allow_list_test_3() {1841 new_test_ext().execute_with(|| {1842 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18431844 let origin1 = RuntimeOrigin::signed(1);18451846 let data = default_nft_data();1847 create_test_item(collection_id, &data.into());18481849 assert_ok!(Unique::set_collection_permissions(1850 origin1.clone(),1851 collection_id,1852 CollectionPermissions {1853 mint_mode: None,1854 access: Some(AccessMode::AllowList),1855 nesting: None,1856 }1857 ));1858 assert_ok!(Unique::add_to_allow_list(1859 origin1.clone(),1860 collection_id,1861 account(1)1862 ));18631864 assert_noop!(1865 Unique::transfer(origin1, account(3), collection_id, TokenId(1), 1)1866 .map_err(|e| e.error),1867 CommonError::<Test>::AddressNotInAllowlist1868 );1869 });1870}18711872#[test]1873fn allow_list_test_4() {1874 new_test_ext().execute_with(|| {1875 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18761877 let origin1 = RuntimeOrigin::signed(1);18781879 let data = default_nft_data();1880 create_test_item(collection_id, &data.into());18811882 assert_ok!(Unique::set_collection_permissions(1883 origin1.clone(),1884 collection_id,1885 CollectionPermissions {1886 mint_mode: None,1887 access: Some(AccessMode::AllowList),1888 nesting: None,1889 }1890 ));1891 assert_ok!(Unique::add_to_allow_list(1892 origin1.clone(),1893 collection_id,1894 account(1)1895 ));1896 assert_ok!(Unique::add_to_allow_list(1897 origin1.clone(),1898 collection_id,1899 account(2)1900 ));19011902 // do approve1903 assert_ok!(Unique::approve(1904 origin1.clone(),1905 account(1),1906 collection_id,1907 TokenId(1),1908 11909 ));1910 assert_eq!(1911 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1912 account(1)1913 );19141915 assert_ok!(Unique::remove_from_allow_list(1916 origin1.clone(),1917 collection_id,1918 account(2)1919 ));19201921 assert_noop!(1922 Unique::transfer_from(1923 origin1,1924 account(1),1925 account(3),1926 collection_id,1927 TokenId(1),1928 11929 )1930 .map_err(|e| e.error),1931 CommonError::<Test>::AddressNotInAllowlist1932 );1933 });1934}19351936// If Public Access mode is set to AllowList, tokens can’t be destroyed by a non-allowlisted address (even if it owned them before enabling AllowList mode)1937#[test]1938fn allow_list_test_5() {1939 new_test_ext().execute_with(|| {1940 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19411942 let origin1 = RuntimeOrigin::signed(1);19431944 let data = default_nft_data();1945 create_test_item(collection_id, &data.into());19461947 assert_ok!(Unique::set_collection_permissions(1948 origin1.clone(),1949 collection_id,1950 CollectionPermissions {1951 mint_mode: None,1952 access: Some(AccessMode::AllowList),1953 nesting: None,1954 }1955 ));1956 assert_noop!(1957 Unique::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1).map_err(|e| e.error),1958 CommonError::<Test>::AddressNotInAllowlist1959 );1960 });1961}19621963// If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method).1964#[test]1965fn allow_list_test_6() {1966 new_test_ext().execute_with(|| {1967 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19681969 let origin1 = RuntimeOrigin::signed(1);19701971 let data = default_nft_data();1972 create_test_item(collection_id, &data.into());19731974 assert_ok!(Unique::set_collection_permissions(1975 origin1.clone(),1976 collection_id,1977 CollectionPermissions {1978 mint_mode: None,1979 access: Some(AccessMode::AllowList),1980 nesting: None,1981 }1982 ));19831984 // do approve1985 assert_noop!(1986 Unique::approve(origin1, account(1), CollectionId(1), TokenId(1), 1)1987 .map_err(|e| e.error),1988 CommonError::<Test>::AddressNotInAllowlist1989 );1990 });1991}19921993// If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests) and1994// tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests)1995#[test]1996fn allow_list_test_7() {1997 new_test_ext().execute_with(|| {1998 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19992000 let data = default_nft_data();2001 create_test_item(collection_id, &data.into());20022003 let origin1 = RuntimeOrigin::signed(1);20042005 assert_ok!(Unique::set_collection_permissions(2006 origin1.clone(),2007 collection_id,2008 CollectionPermissions {2009 mint_mode: None,2010 access: Some(AccessMode::AllowList),2011 nesting: None,2012 }2013 ));2014 assert_ok!(Unique::add_to_allow_list(2015 origin1.clone(),2016 collection_id,2017 account(1)2018 ));2019 assert_ok!(Unique::add_to_allow_list(2020 origin1.clone(),2021 collection_id,2022 account(2)2023 ));20242025 assert_ok!(Unique::transfer(2026 origin1,2027 account(2),2028 CollectionId(1),2029 TokenId(1),2030 12031 ));2032 });2033}20342035#[test]2036fn allow_list_test_8() {2037 new_test_ext().execute_with(|| {2038 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20392040 // Create NFT for account 12041 let data = default_nft_data();2042 create_test_item(collection_id, &data.into());20432044 let origin1 = RuntimeOrigin::signed(1);20452046 // Toggle Allow List mode and add accounts 1 and 22047 assert_ok!(Unique::set_collection_permissions(2048 origin1.clone(),2049 collection_id,2050 CollectionPermissions {2051 mint_mode: None,2052 access: Some(AccessMode::AllowList),2053 nesting: None,2054 }2055 ));2056 assert_ok!(Unique::add_to_allow_list(2057 origin1.clone(),2058 collection_id,2059 account(1)2060 ));2061 assert_ok!(Unique::add_to_allow_list(2062 origin1.clone(),2063 collection_id,2064 account(2)2065 ));20662067 // Sself-approve account 1 for NFT 12068 assert_ok!(Unique::approve(2069 origin1.clone(),2070 account(1),2071 CollectionId(1),2072 TokenId(1),2073 12074 ));2075 assert_eq!(2076 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),2077 account(1)2078 );20792080 // Transfer from 1 to 22081 assert_ok!(Unique::transfer_from(2082 origin1,2083 account(1),2084 account(2),2085 CollectionId(1),2086 TokenId(1),2087 12088 ));2089 });2090}20912092// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner.2093#[test]2094fn allow_list_test_9() {2095 new_test_ext().execute_with(|| {2096 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2097 let origin1 = RuntimeOrigin::signed(1);20982099 assert_ok!(Unique::set_collection_permissions(2100 origin1.clone(),2101 collection_id,2102 CollectionPermissions {2103 mint_mode: Some(false),2104 access: Some(AccessMode::AllowList),2105 nesting: None,2106 }2107 ));21082109 let data = default_nft_data();2110 create_test_item(collection_id, &data.into());2111 });2112}21132114// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin.2115#[test]2116fn allow_list_test_10() {2117 new_test_ext().execute_with(|| {2118 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21192120 let origin1 = RuntimeOrigin::signed(1);2121 let origin2 = RuntimeOrigin::signed(2);21222123 assert_ok!(Unique::set_collection_permissions(2124 origin1.clone(),2125 collection_id,2126 CollectionPermissions {2127 mint_mode: Some(false),2128 access: Some(AccessMode::AllowList),2129 nesting: None,2130 }2131 ));21322133 assert_ok!(Unique::add_collection_admin(2134 origin1,2135 collection_id,2136 account(2)2137 ));21382139 assert_ok!(Unique::create_item(2140 origin2,2141 collection_id,2142 account(2),2143 default_nft_data().into()2144 ));2145 });2146}21472148// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and allow listed address.2149#[test]2150fn allow_list_test_11() {2151 new_test_ext().execute_with(|| {2152 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21532154 let origin1 = RuntimeOrigin::signed(1);2155 let origin2 = RuntimeOrigin::signed(2);21562157 assert_ok!(Unique::set_collection_permissions(2158 origin1.clone(),2159 collection_id,2160 CollectionPermissions {2161 mint_mode: Some(false),2162 access: Some(AccessMode::AllowList),2163 nesting: None,2164 }2165 ));2166 assert_ok!(Unique::add_to_allow_list(2167 origin1,2168 collection_id,2169 account(2)2170 ));21712172 assert_noop!(2173 Unique::create_item(2174 origin2,2175 CollectionId(1),2176 account(2),2177 default_nft_data().into()2178 )2179 .map_err(|e| e.error),2180 CommonError::<Test>::PublicMintingNotAllowed2181 );2182 });2183}21842185// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-allow listed address.2186#[test]2187fn allow_list_test_12() {2188 new_test_ext().execute_with(|| {2189 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21902191 let origin1 = RuntimeOrigin::signed(1);2192 let origin2 = RuntimeOrigin::signed(2);21932194 assert_ok!(Unique::set_collection_permissions(2195 origin1.clone(),2196 collection_id,2197 CollectionPermissions {2198 mint_mode: Some(false),2199 access: Some(AccessMode::AllowList),2200 nesting: None,2201 }2202 ));22032204 assert_noop!(2205 Unique::create_item(2206 origin2,2207 CollectionId(1),2208 account(2),2209 default_nft_data().into()2210 )2211 .map_err(|e| e.error),2212 CommonError::<Test>::PublicMintingNotAllowed2213 );2214 });2215}22162217// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner.2218#[test]2219fn allow_list_test_13() {2220 new_test_ext().execute_with(|| {2221 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22222223 let origin1 = RuntimeOrigin::signed(1);22242225 assert_ok!(Unique::set_collection_permissions(2226 origin1.clone(),2227 collection_id,2228 CollectionPermissions {2229 mint_mode: Some(true),2230 access: Some(AccessMode::AllowList),2231 nesting: None,2232 }2233 ));22342235 let data = default_nft_data();2236 create_test_item(collection_id, &data.into());2237 });2238}22392240// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin.2241#[test]2242fn allow_list_test_14() {2243 new_test_ext().execute_with(|| {2244 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22452246 let origin1 = RuntimeOrigin::signed(1);2247 let origin2 = RuntimeOrigin::signed(2);22482249 assert_ok!(Unique::set_collection_permissions(2250 origin1.clone(),2251 collection_id,2252 CollectionPermissions {2253 mint_mode: Some(true),2254 access: Some(AccessMode::AllowList),2255 nesting: None,2256 }2257 ));22582259 assert_ok!(Unique::add_collection_admin(2260 origin1,2261 collection_id,2262 account(2)2263 ));22642265 assert_ok!(Unique::create_item(2266 origin2,2267 collection_id,2268 account(2),2269 default_nft_data().into()2270 ));2271 });2272}22732274// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-allow listed address.2275#[test]2276fn allow_list_test_15() {2277 new_test_ext().execute_with(|| {2278 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22792280 let origin1 = RuntimeOrigin::signed(1);2281 let origin2 = RuntimeOrigin::signed(2);22822283 assert_ok!(Unique::set_collection_permissions(2284 origin1.clone(),2285 collection_id,2286 CollectionPermissions {2287 mint_mode: Some(true),2288 access: Some(AccessMode::AllowList),2289 nesting: None,2290 }2291 ));22922293 assert_noop!(2294 Unique::create_item(2295 origin2,2296 collection_id,2297 account(2),2298 default_nft_data().into()2299 )2300 .map_err(|e| e.error),2301 CommonError::<Test>::AddressNotInAllowlist2302 );2303 });2304}23052306// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by non-privileged and allow listed address.2307#[test]2308fn allow_list_test_16() {2309 new_test_ext().execute_with(|| {2310 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23112312 let origin1 = RuntimeOrigin::signed(1);2313 let origin2 = RuntimeOrigin::signed(2);23142315 assert_ok!(Unique::set_collection_permissions(2316 origin1.clone(),2317 collection_id,2318 CollectionPermissions {2319 mint_mode: Some(true),2320 access: Some(AccessMode::AllowList),2321 nesting: None,2322 }2323 ));2324 assert_ok!(Unique::add_to_allow_list(2325 origin1,2326 collection_id,2327 account(2)2328 ));23292330 assert_ok!(Unique::create_item(2331 origin2,2332 collection_id,2333 account(2),2334 default_nft_data().into()2335 ));2336 });2337}23382339// Total number of collections. Positive test2340#[test]2341fn total_number_collections_bound() {2342 new_test_ext().execute_with(|| {2343 create_test_collection(&CollectionMode::NFT, CollectionId(1));2344 });2345}23462347#[test]2348fn create_max_collections() {2349 new_test_ext().execute_with(|| {2350 for i in 1..COLLECTION_NUMBER_LIMIT {2351 create_test_collection(&CollectionMode::NFT, CollectionId(i));2352 }2353 });2354}23552356// Total number of collections. Negative test2357#[test]2358fn total_number_collections_bound_neg() {2359 new_test_ext().execute_with(|| {2360 let origin1 = RuntimeOrigin::signed(1);23612362 for i in 1..=COLLECTION_NUMBER_LIMIT {2363 create_test_collection(&CollectionMode::NFT, CollectionId(i));2364 }23652366 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();2367 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();2368 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();23692370 let data = CreateCollectionData {2371 name: col_name1.try_into().unwrap(),2372 description: col_desc1.try_into().unwrap(),2373 token_prefix: token_prefix1.try_into().unwrap(),2374 mode: CollectionMode::NFT,2375 ..Default::default()2376 };23772378 // 11-th collection in chain. Expects error2379 assert_noop!(2380 Unique::create_collection_ex(origin1, data),2381 CommonError::<Test>::TotalCollectionsLimitExceeded2382 );2383 });2384}23852386// Owned tokens by a single address. Positive test2387#[test]2388fn owned_tokens_bound() {2389 new_test_ext().execute_with(|| {2390 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23912392 let data = default_nft_data();2393 create_test_item(collection_id, &data.clone().into());2394 create_test_item(collection_id, &data.into());2395 });2396}23972398// Owned tokens by a single address. Negotive test2399#[test]2400fn owned_tokens_bound_neg() {2401 new_test_ext().execute_with(|| {2402 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24032404 let origin1 = RuntimeOrigin::signed(1);24052406 for _ in 1..=MAX_TOKEN_OWNERSHIP {2407 let data = default_nft_data();2408 create_test_item(collection_id, &data.clone().into());2409 }24102411 let data = default_nft_data();2412 assert_noop!(2413 Unique::create_item(origin1, CollectionId(1), account(1), data.into())2414 .map_err(|e| e.error),2415 CommonError::<Test>::AccountTokenLimitExceeded2416 );2417 });2418}24192420// Number of collection admins. Positive test2421#[test]2422fn collection_admins_bound() {2423 new_test_ext().execute_with(|| {2424 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24252426 let origin1 = RuntimeOrigin::signed(1);24272428 assert_ok!(Unique::add_collection_admin(2429 origin1.clone(),2430 collection_id,2431 account(2)2432 ));2433 assert_ok!(Unique::add_collection_admin(2434 origin1,2435 collection_id,2436 account(3)2437 ));2438 });2439}24402441// Number of collection admins. Negotive test2442#[test]2443fn collection_admins_bound_neg() {2444 new_test_ext().execute_with(|| {2445 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24462447 let origin1 = RuntimeOrigin::signed(1);24482449 for i in 0..COLLECTION_ADMINS_LIMIT {2450 assert_ok!(Unique::add_collection_admin(2451 origin1.clone(),2452 collection_id,2453 account((2 + i).into())2454 ));2455 }2456 assert_noop!(2457 Unique::add_collection_admin(2458 origin1,2459 collection_id,2460 account((3 + COLLECTION_ADMINS_LIMIT).into())2461 ),2462 CommonError::<Test>::CollectionAdminCountExceeded2463 );2464 });2465}2466// #endregion24672468#[test]2469fn collection_transfer_flag_works() {2470 new_test_ext().execute_with(|| {2471 let origin1 = RuntimeOrigin::signed(1);24722473 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2474 assert_ok!(Unique::set_transfers_enabled_flag(2475 origin1,2476 collection_id,2477 true2478 ));24792480 let data = default_nft_data();2481 create_test_item(collection_id, &data.into());2482 assert_eq!(2483 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2484 12485 );2486 assert_eq!(2487 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2488 true2489 );24902491 let origin1 = RuntimeOrigin::signed(1);24922493 // default scenario2494 assert_ok!(Unique::transfer(2495 origin1,2496 account(2),2497 collection_id,2498 TokenId(1),2499 12500 ));2501 assert_eq!(2502 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2503 false2504 );2505 assert_eq!(2506 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2507 true2508 );2509 assert_eq!(2510 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2511 02512 );2513 assert_eq!(2514 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2515 12516 );2517 });2518}25192520#[test]2521fn collection_transfer_flag_works_neg() {2522 new_test_ext().execute_with(|| {2523 let origin1 = RuntimeOrigin::signed(1);25242525 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2526 assert_ok!(Unique::set_transfers_enabled_flag(2527 origin1,2528 collection_id,2529 false2530 ));25312532 let data = default_nft_data();2533 create_test_item(collection_id, &data.into());2534 assert_eq!(2535 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2536 12537 );2538 assert_eq!(2539 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2540 true2541 );25422543 let origin1 = RuntimeOrigin::signed(1);25442545 // default scenario2546 assert_noop!(2547 Unique::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)2548 .map_err(|e| e.error),2549 CommonError::<Test>::TransferNotAllowed2550 );2551 assert_eq!(2552 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2553 12554 );2555 assert_eq!(2556 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2557 02558 );2559 assert_eq!(2560 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2561 true2562 );2563 assert_eq!(2564 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2565 false2566 );2567 });2568}25692570#[test]2571fn collection_sponsoring() {2572 new_test_ext().execute_with(|| {2573 // default_limits();2574 let user1 = 1_u64;2575 let user2 = 777_u64;2576 let origin1 = RuntimeOrigin::signed(user1);2577 let origin2 = RuntimeOrigin::signed(user2);2578 let account2 = account(user2);25792580 let collection_id =2581 create_test_collection_for_owner(&CollectionMode::NFT, user1, CollectionId(1));2582 assert_ok!(Unique::set_collection_sponsor(2583 origin1.clone(),2584 collection_id,2585 user12586 ));2587 assert_ok!(Unique::confirm_sponsorship(origin1.clone(), collection_id));25882589 // Expect error while have no permissions2590 assert!(Unique::create_item(2591 origin2.clone(),2592 collection_id,2593 account2.clone(),2594 default_nft_data().into()2595 )2596 .is_err());25972598 assert_ok!(Unique::set_collection_permissions(2599 origin1.clone(),2600 collection_id,2601 CollectionPermissions {2602 mint_mode: Some(true),2603 access: Some(AccessMode::AllowList),2604 nesting: None,2605 }2606 ));2607 assert_ok!(Unique::add_to_allow_list(2608 origin1.clone(),2609 collection_id,2610 account2.clone()2611 ));26122613 assert_ok!(Unique::create_item(2614 origin2,2615 collection_id,2616 account2,2617 default_nft_data().into()2618 ));2619 });2620}26212622mod check_token_permissions {2623 use pallet_common::LazyValue;26242625 use super::*;26262627 fn test<FTE: FnOnce() -> bool>(2628 i: usize,2629 test_case: &pallet_common::tests::TestCase,2630 check_token_existence: &mut LazyValue<bool, FTE>,2631 ) {2632 let collection_admin = test_case.collection_admin;2633 let mut is_collection_admin = LazyValue::new(|| test_case.is_collection_admin);2634 let token_owner = test_case.token_owner;2635 let mut is_token_owner = LazyValue::new(|| Ok(test_case.is_token_owner));2636 let is_no_permission = test_case.no_permission;26372638 let result = pallet_common::tests::check_token_permissions::<Test, _, _, FTE>(2639 collection_admin,2640 token_owner,2641 &mut is_collection_admin,2642 &mut is_token_owner,2643 check_token_existence,2644 );26452646 if is_no_permission {2647 assert!(2648 result.is_err(),2649 "{i}: {test_case:?}, token_exist: {}",2650 check_token_existence.value()2651 );2652 assert_err!(result, pallet_common::Error::<Test>::NoPermission,);2653 } else if check_token_existence.has_value() && !check_token_existence.value() {2654 assert!(2655 result.is_err(),2656 "{i}: {test_case:?}, token_exist: {}",2657 check_token_existence.value()2658 );2659 assert_err!(result, pallet_common::Error::<Test>::TokenNotFound,);2660 }2661 }26622663 #[test]2664 fn no_permission_only() {2665 new_test_ext().execute_with(|| {2666 let mut check_token_existence = LazyValue::new(|| true);2667 for (i, row) in pallet_common::tests::TABLE.iter().enumerate() {2668 test(i, row, &mut check_token_existence);2669 }2670 });2671 }26722673 #[test]2674 fn no_permission_and_token_not_found() {2675 new_test_ext().execute_with(|| {2676 for (i, row) in pallet_common::tests::TABLE.iter().enumerate() {2677 // This is inside the loop to keep track of whether the lambda was called2678 let mut check_token_existence = LazyValue::new(|| false);2679 test(i, row, &mut check_token_existence);2680 }2681 });2682 }2683}runtime/unique/src/lib.rsdiffbeforeafterboth--- a/runtime/unique/src/lib.rs
+++ b/runtime/unique/src/lib.rs
@@ -27,14 +27,11 @@
extern crate alloc;
+use ::staging_xcm::latest::NetworkId;
use frame_support::parameter_types;
-
-use sp_version::RuntimeVersion;
use sp_runtime::create_runtime_str;
-
+use sp_version::RuntimeVersion;
use up_common::types::*;
-
-use ::xcm::latest::NetworkId;
mod runtime_common;
runtime/unique/src/xcm_barrier.rsdiffbeforeafterboth--- a/runtime/unique/src/xcm_barrier.rs
+++ b/runtime/unique/src/xcm_barrier.rs
@@ -15,8 +15,8 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use frame_support::{match_types, traits::Everything};
-use xcm::latest::{Junctions::*, MultiLocation};
-use xcm_builder::{
+use staging_xcm::latest::{Junctions::*, MultiLocation};
+use staging_xcm_builder::{
AllowKnownQueryResponses, AllowSubscriptionsFrom, TakeWeightCredit,
AllowTopLevelPaidExecutionFrom, AllowExplicitUnpaidExecutionFrom,
};
test-pallets/utils/src/lib.rsdiffbeforeafterboth--- a/test-pallets/utils/src/lib.rs
+++ b/test-pallets/utils/src/lib.rs
@@ -16,18 +16,19 @@
#![cfg_attr(not(feature = "std"), no_std)]
-pub use pallet::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
+pub use pallet::*;
#[frame_support::pallet(dev_mode)]
pub mod pallet {
use frame_support::{
+ dispatch::{GetDispatchInfo, PostDispatchInfo},
pallet_prelude::*,
- dispatch::{Dispatchable, GetDispatchInfo, PostDispatchInfo},
- traits::{UnfilteredDispatchable, IsSubType, OriginTrait},
+ traits::{IsSubType, OriginTrait, UnfilteredDispatchable},
};
use frame_system::pallet_prelude::*;
+ use sp_runtime::traits::Dispatchable;
use sp_std::vec::Vec;
#[pallet::config]