difftreelog
Merge pull request #242 from UniqueNetwork/feature/fix_unit_tests
in: master
Fix unit tests
13 files changed
Cargo.lockdiffbeforeafterboth4938 "winapi 0.3.9",4938 "winapi 0.3.9",4939]4939]49404941[[package]]4942name = "nft"4943version = "0.9.12"4944dependencies = [4945 "cumulus-client-cli",4946 "cumulus-client-collator",4947 "cumulus-client-consensus-aura",4948 "cumulus-client-consensus-common",4949 "cumulus-client-network",4950 "cumulus-client-service",4951 "cumulus-primitives-core",4952 "cumulus-primitives-parachain-inherent",4953 "fc-consensus",4954 "fc-db",4955 "fc-mapping-sync",4956 "fc-rpc",4957 "fc-rpc-core",4958 "flexi_logger",4959 "fp-rpc",4960 "frame-benchmarking",4961 "frame-benchmarking-cli",4962 "futures 0.3.17",4963 "jsonrpc-core",4964 "jsonrpc-pubsub",4965 "log",4966 "nft-data-structs",4967 "nft-rpc",4968 "nft-runtime",4969 "pallet-ethereum",4970 "pallet-transaction-payment-rpc",4971 "parity-scale-codec",4972 "parking_lot 0.11.2",4973 "polkadot-cli",4974 "polkadot-parachain",4975 "polkadot-primitives",4976 "polkadot-service",4977 "polkadot-test-service",4978 "sc-basic-authorship",4979 "sc-chain-spec",4980 "sc-cli",4981 "sc-client-api",4982 "sc-consensus",4983 "sc-consensus-aura",4984 "sc-executor",4985 "sc-finality-grandpa",4986 "sc-keystore",4987 "sc-network",4988 "sc-rpc",4989 "sc-rpc-api",4990 "sc-service",4991 "sc-telemetry",4992 "sc-tracing",4993 "sc-transaction-pool",4994 "serde",4995 "serde_json",4996 "sp-api",4997 "sp-block-builder",4998 "sp-blockchain",4999 "sp-consensus",5000 "sp-consensus-aura",5001 "sp-core",5002 "sp-finality-grandpa",5003 "sp-inherents",5004 "sp-keystore",5005 "sp-offchain",5006 "sp-runtime",5007 "sp-session",5008 "sp-timestamp",5009 "sp-transaction-pool",5010 "sp-trie",5011 "structopt",5012 "substrate-build-script-utils",5013 "substrate-frame-rpc-system",5014 "substrate-prometheus-endpoint",5015]50165017[[package]]5018name = "nft-data-structs"5019version = "0.9.0"5020dependencies = [5021 "derivative",5022 "frame-support",5023 "frame-system",5024 "parity-scale-codec",5025 "scale-info",5026 "serde",5027 "sp-core",5028 "sp-runtime",5029 "sp-std",5030]50315032[[package]]5033name = "nft-rpc"5034version = "3.3.1"5035dependencies = [5036 "fc-db",5037 "fc-mapping-sync",5038 "fc-rpc",5039 "fc-rpc-core",5040 "fp-rpc",5041 "futures 0.3.17",5042 "jsonrpc-core",5043 "jsonrpc-pubsub",5044 "nft-runtime",5045 "pallet-ethereum",5046 "pallet-nft",5047 "pallet-transaction-payment-rpc",5048 "pallet-transaction-payment-rpc-runtime-api",5049 "sc-client-api",5050 "sc-consensus-aura",5051 "sc-consensus-epochs",5052 "sc-finality-grandpa",5053 "sc-finality-grandpa-rpc",5054 "sc-keystore",5055 "sc-network",5056 "sc-rpc",5057 "sc-rpc-api",5058 "sc-service",5059 "sc-transaction-pool",5060 "sp-api",5061 "sp-block-builder",5062 "sp-blockchain",5063 "sp-consensus",5064 "sp-consensus-aura",5065 "sp-core",5066 "sp-offchain",5067 "sp-runtime",5068 "sp-session",5069 "sp-storage",5070 "sp-transaction-pool",5071 "substrate-frame-rpc-system",5072 "tokio 0.2.25",5073 "uc-rpc",5074 "up-rpc",5075]50765077[[package]]5078name = "nft-runtime"5079version = "0.9.12"5080dependencies = [5081 "cumulus-pallet-aura-ext",5082 "cumulus-pallet-dmp-queue",5083 "cumulus-pallet-parachain-system",5084 "cumulus-pallet-xcm",5085 "cumulus-pallet-xcmp-queue",5086 "cumulus-primitives-core",5087 "cumulus-primitives-timestamp",5088 "cumulus-primitives-utility",5089 "derivative",5090 "fp-rpc",5091 "fp-self-contained",5092 "frame-benchmarking",5093 "frame-executive",5094 "frame-support",5095 "frame-system",5096 "frame-system-benchmarking",5097 "frame-system-rpc-runtime-api",5098 "hex-literal",5099 "nft-data-structs",5100 "orml-vesting",5101 "pallet-aura",5102 "pallet-balances",5103 "pallet-common",5104 "pallet-ethereum",5105 "pallet-evm",5106 "pallet-evm-coder-substrate",5107 "pallet-evm-contract-helpers",5108 "pallet-evm-migration",5109 "pallet-evm-transaction-payment",5110 "pallet-fungible",5111 "pallet-inflation",5112 "pallet-nft",5113 "pallet-nonfungible",5114 "pallet-randomness-collective-flip",5115 "pallet-refungible",5116 "pallet-sudo",5117 "pallet-template-transaction-payment",5118 "pallet-timestamp",5119 "pallet-transaction-payment",5120 "pallet-transaction-payment-rpc-runtime-api",5121 "pallet-treasury",5122 "pallet-unq-scheduler",5123 "pallet-xcm",5124 "parachain-info",5125 "parity-scale-codec",5126 "polkadot-parachain",5127 "scale-info",5128 "serde",5129 "smallvec",5130 "sp-api",5131 "sp-arithmetic",5132 "sp-block-builder",5133 "sp-consensus-aura",5134 "sp-core",5135 "sp-inherents",5136 "sp-io",5137 "sp-offchain",5138 "sp-runtime",5139 "sp-session",5140 "sp-std",5141 "sp-transaction-pool",5142 "sp-version",5143 "substrate-wasm-builder",5144 "up-evm-mapping",5145 "up-rpc",5146 "xcm",5147 "xcm-builder",5148 "xcm-executor",5149]515049405151[[package]]4941[[package]]5152name = "nodrop"4942name = "nodrop"5581 "evm-coder",5371 "evm-coder",5582 "frame-support",5372 "frame-support",5583 "frame-system",5373 "frame-system",5584 "nft-data-structs",5585 "pallet-evm",5374 "pallet-evm",5586 "pallet-evm-coder-substrate",5375 "pallet-evm-coder-substrate",5587 "parity-scale-codec",5376 "parity-scale-codec",5590 "sp-core",5379 "sp-core",5591 "sp-runtime",5380 "sp-runtime",5592 "sp-std",5381 "sp-std",5382 "up-data-structs",5593 "up-evm-mapping",5383 "up-evm-mapping",5594]5384]559553855853 "frame-benchmarking",5643 "frame-benchmarking",5854 "frame-support",5644 "frame-support",5855 "frame-system",5645 "frame-system",5856 "nft-data-structs",5857 "pallet-common",5646 "pallet-common",5858 "pallet-evm-coder-substrate",5647 "pallet-evm-coder-substrate",5859 "parity-scale-codec",5648 "parity-scale-codec",5860 "scale-info",5649 "scale-info",5861 "sp-core",5650 "sp-core",5862 "sp-runtime",5651 "sp-runtime",5863 "sp-std",5652 "sp-std",5653 "up-data-structs",5864]5654]586556555866[[package]]5656[[package]]595657465957[[package]]5747[[package]]5958name = "pallet-inflation"5748name = "pallet-inflation"5959version = "3.0.0"5749version = "0.1.0"5960dependencies = [5750dependencies = [5961 "frame-benchmarking",5751 "frame-benchmarking",5962 "frame-support",5752 "frame-support",6056 "sp-std",5846 "sp-std",6057]5847]60586059[[package]]6060name = "pallet-nft"6061version = "3.0.0"6062dependencies = [6063 "ethereum 0.9.0 (git+https://github.com/purestake/ethereum?branch=joshy-scale-info)",6064 "evm-coder",6065 "fp-evm",6066 "frame-benchmarking",6067 "frame-support",6068 "frame-system",6069 "hex-literal",6070 "nft-data-structs",6071 "pallet-balances",6072 "pallet-common",6073 "pallet-ethereum",6074 "pallet-evm",6075 "pallet-evm-coder-substrate",6076 "pallet-fungible",6077 "pallet-nonfungible",6078 "pallet-randomness-collective-flip",6079 "pallet-refungible",6080 "pallet-timestamp",6081 "pallet-transaction-payment",6082 "parity-scale-codec",6083 "primitive-types 0.10.1",6084 "rlp",6085 "scale-info",6086 "serde",6087 "sp-api",6088 "sp-core",6089 "sp-io",6090 "sp-runtime",6091 "sp-std",6092 "up-evm-mapping",6093 "up-sponsorship",6094]609558486096[[package]]5849[[package]]6097name = "pallet-nicks"5850name = "pallet-nicks"6116 "frame-benchmarking",5869 "frame-benchmarking",6117 "frame-support",5870 "frame-support",6118 "frame-system",5871 "frame-system",6119 "nft-data-structs",6120 "pallet-common",5872 "pallet-common",6121 "pallet-evm-coder-substrate",5873 "pallet-evm-coder-substrate",6122 "parity-scale-codec",5874 "parity-scale-codec",6123 "scale-info",5875 "scale-info",6124 "sp-core",5876 "sp-core",6125 "sp-runtime",5877 "sp-runtime",6126 "sp-std",5878 "sp-std",5879 "up-data-structs",6127]5880]612858816129[[package]]5882[[package]]6216 "frame-benchmarking",5969 "frame-benchmarking",6217 "frame-support",5970 "frame-support",6218 "frame-system",5971 "frame-system",6219 "nft-data-structs",6220 "pallet-common",5972 "pallet-common",6221 "parity-scale-codec",5973 "parity-scale-codec",6222 "scale-info",5974 "scale-info",6223 "sp-core",5975 "sp-core",6224 "sp-runtime",5976 "sp-runtime",6225 "sp-std",5977 "sp-std",5978 "up-data-structs",6226]5979]622759806228[[package]]5981[[package]]6468 "sp-std",6221 "sp-std",6469]6222]62236224[[package]]6225name = "pallet-unique"6226version = "0.1.0"6227dependencies = [6228 "ethereum 0.9.0 (git+https://github.com/purestake/ethereum?branch=joshy-scale-info)",6229 "evm-coder",6230 "fp-evm",6231 "frame-benchmarking",6232 "frame-support",6233 "frame-system",6234 "hex-literal",6235 "pallet-balances",6236 "pallet-common",6237 "pallet-ethereum",6238 "pallet-evm",6239 "pallet-evm-coder-substrate",6240 "pallet-fungible",6241 "pallet-nonfungible",6242 "pallet-randomness-collective-flip",6243 "pallet-refungible",6244 "pallet-timestamp",6245 "pallet-transaction-payment",6246 "parity-scale-codec",6247 "primitive-types 0.10.1",6248 "rlp",6249 "scale-info",6250 "serde",6251 "sp-api",6252 "sp-core",6253 "sp-io",6254 "sp-runtime",6255 "sp-std",6256 "up-data-structs",6257 "up-evm-mapping",6258 "up-sponsorship",6259]647062606471[[package]]6261[[package]]6472name = "pallet-unq-scheduler"6262name = "pallet-unq-scheduler"6473version = "3.0.0"6263version = "0.1.0"6474dependencies = [6264dependencies = [6475 "frame-benchmarking",6265 "frame-benchmarking",6476 "frame-support",6266 "frame-support",11714 "jsonrpc-core",11504 "jsonrpc-core",11715 "jsonrpc-core-client",11505 "jsonrpc-core-client",11716 "jsonrpc-derive",11506 "jsonrpc-derive",11717 "nft-data-structs",11718 "pallet-common",11507 "pallet-common",11719 "parity-scale-codec",11508 "parity-scale-codec",11720 "sp-api",11509 "sp-api",11721 "sp-blockchain",11510 "sp-blockchain",11722 "sp-core",11511 "sp-core",11723 "sp-rpc",11512 "sp-rpc",11724 "sp-runtime",11513 "sp-runtime",11514 "up-data-structs",11725 "up-rpc",11515 "up-rpc",11726]11516]117271151711785source = "registry+https://github.com/rust-lang/crates.io-index"11575source = "registry+https://github.com/rust-lang/crates.io-index"11786checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"11576checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"1157711578[[package]]11579name = "unique-node"11580version = "0.9.12"11581dependencies = [11582 "cumulus-client-cli",11583 "cumulus-client-collator",11584 "cumulus-client-consensus-aura",11585 "cumulus-client-consensus-common",11586 "cumulus-client-network",11587 "cumulus-client-service",11588 "cumulus-primitives-core",11589 "cumulus-primitives-parachain-inherent",11590 "fc-consensus",11591 "fc-db",11592 "fc-mapping-sync",11593 "fc-rpc",11594 "fc-rpc-core",11595 "flexi_logger",11596 "fp-rpc",11597 "frame-benchmarking",11598 "frame-benchmarking-cli",11599 "futures 0.3.17",11600 "jsonrpc-core",11601 "jsonrpc-pubsub",11602 "log",11603 "pallet-ethereum",11604 "pallet-transaction-payment-rpc",11605 "parity-scale-codec",11606 "parking_lot 0.11.2",11607 "polkadot-cli",11608 "polkadot-parachain",11609 "polkadot-primitives",11610 "polkadot-service",11611 "polkadot-test-service",11612 "sc-basic-authorship",11613 "sc-chain-spec",11614 "sc-cli",11615 "sc-client-api",11616 "sc-consensus",11617 "sc-consensus-aura",11618 "sc-executor",11619 "sc-finality-grandpa",11620 "sc-keystore",11621 "sc-network",11622 "sc-rpc",11623 "sc-rpc-api",11624 "sc-service",11625 "sc-telemetry",11626 "sc-tracing",11627 "sc-transaction-pool",11628 "serde",11629 "serde_json",11630 "sp-api",11631 "sp-block-builder",11632 "sp-blockchain",11633 "sp-consensus",11634 "sp-consensus-aura",11635 "sp-core",11636 "sp-finality-grandpa",11637 "sp-inherents",11638 "sp-keystore",11639 "sp-offchain",11640 "sp-runtime",11641 "sp-session",11642 "sp-timestamp",11643 "sp-transaction-pool",11644 "sp-trie",11645 "structopt",11646 "substrate-build-script-utils",11647 "substrate-frame-rpc-system",11648 "substrate-prometheus-endpoint",11649 "unique-rpc",11650 "unique-runtime",11651 "up-data-structs",11652]1165311654[[package]]11655name = "unique-rpc"11656version = "0.1.0"11657dependencies = [11658 "fc-db",11659 "fc-mapping-sync",11660 "fc-rpc",11661 "fc-rpc-core",11662 "fp-rpc",11663 "futures 0.3.17",11664 "jsonrpc-core",11665 "jsonrpc-pubsub",11666 "pallet-ethereum",11667 "pallet-transaction-payment-rpc",11668 "pallet-transaction-payment-rpc-runtime-api",11669 "pallet-unique",11670 "sc-client-api",11671 "sc-consensus-aura",11672 "sc-consensus-epochs",11673 "sc-finality-grandpa",11674 "sc-finality-grandpa-rpc",11675 "sc-keystore",11676 "sc-network",11677 "sc-rpc",11678 "sc-rpc-api",11679 "sc-service",11680 "sc-transaction-pool",11681 "sp-api",11682 "sp-block-builder",11683 "sp-blockchain",11684 "sp-consensus",11685 "sp-consensus-aura",11686 "sp-core",11687 "sp-offchain",11688 "sp-runtime",11689 "sp-session",11690 "sp-storage",11691 "sp-transaction-pool",11692 "substrate-frame-rpc-system",11693 "tokio 0.2.25",11694 "uc-rpc",11695 "unique-runtime",11696 "up-rpc",11697]1169811699[[package]]11700name = "unique-runtime"11701version = "0.9.12"11702dependencies = [11703 "cumulus-pallet-aura-ext",11704 "cumulus-pallet-dmp-queue",11705 "cumulus-pallet-parachain-system",11706 "cumulus-pallet-xcm",11707 "cumulus-pallet-xcmp-queue",11708 "cumulus-primitives-core",11709 "cumulus-primitives-timestamp",11710 "cumulus-primitives-utility",11711 "derivative",11712 "fp-rpc",11713 "fp-self-contained",11714 "frame-benchmarking",11715 "frame-executive",11716 "frame-support",11717 "frame-system",11718 "frame-system-benchmarking",11719 "frame-system-rpc-runtime-api",11720 "hex-literal",11721 "orml-vesting",11722 "pallet-aura",11723 "pallet-balances",11724 "pallet-common",11725 "pallet-ethereum",11726 "pallet-evm",11727 "pallet-evm-coder-substrate",11728 "pallet-evm-contract-helpers",11729 "pallet-evm-migration",11730 "pallet-evm-transaction-payment",11731 "pallet-fungible",11732 "pallet-inflation",11733 "pallet-nonfungible",11734 "pallet-randomness-collective-flip",11735 "pallet-refungible",11736 "pallet-sudo",11737 "pallet-template-transaction-payment",11738 "pallet-timestamp",11739 "pallet-transaction-payment",11740 "pallet-transaction-payment-rpc-runtime-api",11741 "pallet-treasury",11742 "pallet-unique",11743 "pallet-unq-scheduler",11744 "pallet-xcm",11745 "parachain-info",11746 "parity-scale-codec",11747 "polkadot-parachain",11748 "scale-info",11749 "serde",11750 "smallvec",11751 "sp-api",11752 "sp-arithmetic",11753 "sp-block-builder",11754 "sp-consensus-aura",11755 "sp-core",11756 "sp-inherents",11757 "sp-io",11758 "sp-offchain",11759 "sp-runtime",11760 "sp-session",11761 "sp-std",11762 "sp-transaction-pool",11763 "sp-version",11764 "substrate-wasm-builder",11765 "up-data-structs",11766 "up-evm-mapping",11767 "up-rpc",11768 "xcm",11769 "xcm-builder",11770 "xcm-executor",11771]117871177211788[[package]]11773[[package]]11789name = "universal-hash"11774name = "universal-hash"11831source = "registry+https://github.com/rust-lang/crates.io-index"11816source = "registry+https://github.com/rust-lang/crates.io-index"11832checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"11817checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"1181811819[[package]]11820name = "up-data-structs"11821version = "0.1.0"11822dependencies = [11823 "derivative",11824 "frame-support",11825 "frame-system",11826 "parity-scale-codec",11827 "scale-info",11828 "serde",11829 "sp-core",11830 "sp-runtime",11831 "sp-std",11832]118331183311834[[package]]11834[[package]]11835name = "up-evm-mapping"11835name = "up-evm-mapping"11843name = "up-rpc"11843name = "up-rpc"11844version = "0.1.0"11844version = "0.1.0"11845dependencies = [11845dependencies = [11846 "nft-data-structs",11847 "pallet-common",11846 "pallet-common",11848 "parity-scale-codec",11847 "parity-scale-codec",11849 "sp-api",11848 "sp-api",11850 "sp-core",11849 "sp-core",11851 "sp-runtime",11850 "sp-runtime",11852 "sp-std",11851 "sp-std",11852 "up-data-structs",11853]11853]118541185411855[[package]]11855[[package]]pallets/common/src/account.rsdiffbeforeafterboth--- a/pallets/common/src/account.rs
+++ b/pallets/common/src/account.rs
@@ -7,7 +7,7 @@
use pallet_evm::AddressMapping;
use sp_std::vec::Vec;
use sp_std::clone::Clone;
-use up_evm_mapping::EvmBackwardsAddressMapping;
+pub use up_evm_mapping::EvmBackwardsAddressMapping;
pub trait CrossAccountId<AccountId>:
Encode + EncodeLike + Decode + TypeInfo + Clone + PartialEq + Ord + core::fmt::Debug + Default
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -273,8 +273,8 @@
TotalCollectionsLimitExceeded,
/// variable_data exceeded data limit.
TokenVariableDataLimitExceeded,
- /// Exceeded max admin amount
- CollectionAdminAmountExceeded,
+ /// Exceeded max admin count
+ CollectionAdminCountExceeded,
/// Collection settings not allowing items transferring
TransferNotAllowed,
@@ -506,10 +506,10 @@
if admin {
let amount = amount
.checked_add(1)
- .ok_or(<Error<T>>::CollectionAdminAmountExceeded)?;
+ .ok_or(<Error<T>>::CollectionAdminCountExceeded)?;
ensure!(
amount <= Self::collection_admins_limit(),
- <Error<T>>::CollectionAdminAmountExceeded,
+ <Error<T>>::CollectionAdminCountExceeded,
);
// =========
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -182,7 +182,7 @@
_token: TokenId,
_data: Vec<u8>,
) -> DispatchResultWithPostInfo {
- fail!(<Error<T>>::FungibleItemsHaveData)
+ fail!(<Error<T>>::FungibleItemsDontHaveData)
}
fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -35,7 +35,7 @@
/// Not default id passed as TokenId argument
FungibleItemsHaveNoId,
/// Tried to set data for fungible item
- FungibleItemsHaveData,
+ FungibleItemsDontHaveData,
}
#[pallet::config]
@@ -48,7 +48,7 @@
pub struct Pallet<T>(_);
#[pallet::storage]
- pub(super) type TotalSupply<T: Config> =
+ pub type TotalSupply<T: Config> =
StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u128, QueryKind = ValueQuery>;
#[pallet::storage]
@@ -62,7 +62,7 @@
>;
#[pallet::storage]
- pub(super) type Allowance<T: Config> = StorageNMap<
+ pub type Allowance<T: Config> = StorageNMap<
Key = (
Key<Twox64Concat, CollectionId>,
Key<Blake2_128, T::CrossAccountId>,
pallets/inflation/src/lib.rsdiffbeforeafterboth--- a/pallets/inflation/src/lib.rs
+++ b/pallets/inflation/src/lib.rs
@@ -46,7 +46,8 @@
pub type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
-pub const YEAR: u32 = 5_259_600;
+// pub const YEAR: u32 = 5_259_600; // 6-second block
+pub const YEAR: u32 = 2_629_800; // 12-second block
pub const TOTAL_YEARS_UNTIL_FLAT: u32 = 9;
pub const START_INFLATION_PERCENT: u32 = 10;
pub const END_INFLATION_PERCENT: u32 = 4;
pallets/inflation/src/tests.rsdiffbeforeafterboth--- a/pallets/inflation/src/tests.rs
+++ b/pallets/inflation/src/tests.rs
@@ -18,7 +18,7 @@
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
-const YEAR: u64 = 5_259_600;
+const YEAR: u64 = 2_629_800;
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
@@ -112,8 +112,8 @@
// first inflation deposit should be equal to BlockInflation
Inflation::on_initialize(1);
- // SBP M2 review: Verify expected block inflation for year 1
- assert_eq!(Inflation::block_inflation(), 1901);
+ // Expected 100-block inflation for year 1 is 100 * 100_000_000 / YEAR = 3803
+ assert_eq!(Inflation::block_inflation(), 3803);
assert_eq!(
Balances::free_balance(1234) - initial_issuance,
Inflation::block_inflation()
@@ -158,26 +158,21 @@
let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
assert_eq!(Balances::free_balance(1234), initial_issuance);
Inflation::on_initialize(1);
- let block_inflation_year_0 = Inflation::block_inflation();
- // SBP M2 review: go through all the block inflations for year 1,
+ // Go through all the block inflations for year 1,
// total issuance will be updated accordingly
for block in (100..YEAR).step_by(100) {
Inflation::on_initialize(block);
}
assert_eq!(
- initial_issuance + (1901 * (YEAR / 100)),
+ initial_issuance + (3803 * (YEAR / 100)),
<Balances as Currency<_>>::total_issuance()
);
Inflation::on_initialize(YEAR);
let block_inflation_year_1 = Inflation::block_inflation();
- // SBP M2 review: Verify expected block inflation for year 2
- assert_eq!(block_inflation_year_1, 1952);
-
- // SBP M2 review: this is actually not true
- // Assert that year 1 inflation is less than year 0
- // assert!(block_inflation_year_0 > block_inflation_year_1);
+ // Expected 100-block inflation for year 2: 100 * 9.33% * initial issuance * 110% / YEAR = 3904
+ assert_eq!(block_inflation_year_1, 3904);
});
}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -58,7 +58,7 @@
}
#[pallet::pallet]
- #[pallet::generate_store(pub trait Store)]
+ #[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);
#[pallet::storage]
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -54,7 +54,7 @@
}
#[pallet::pallet]
- #[pallet::generate_store(pub trait Store)]
+ #[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);
#[pallet::storage]
pallets/scheduler/src/lib.rsdiffbeforeafterboth--- a/pallets/scheduler/src/lib.rs
+++ b/pallets/scheduler/src/lib.rs
@@ -738,9 +738,7 @@
use super::*;
use frame_support::{
- Hashable, assert_err, assert_noop, assert_ok, ord_parameter_types, parameter_types,
- traits::{Contains, OnFinalize, OnInitialize},
- weights::constants::RocksDbWeight,
+ ord_parameter_types, parameter_types, traits::Contains, weights::constants::RocksDbWeight,
};
use sp_core::H256;
use sp_runtime::{
@@ -749,7 +747,6 @@
traits::{BlakeTwo256, IdentityLookup},
};
use frame_system::{EnsureOneOf, EnsureRoot, EnsureSignedBy};
- use substrate_test_utils::assert_eq_uvec;
use crate as scheduler;
mod logger {
@@ -758,9 +755,6 @@
thread_local! {
static LOG: RefCell<Vec<(OriginCaller, u32)>> = RefCell::new(Vec::new());
- }
- pub fn log() -> Vec<(OriginCaller, u32)> {
- LOG.with(|log| log.borrow().clone())
}
pub trait Config: system::Config {
type Event: From<Event> + Into<<Self as system::Config>::Event>;
@@ -871,24 +865,5 @@
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = ();
type SponsorshipHandler = ();
- }
-
- pub fn new_test_ext() -> sp_io::TestExternalities {
- let t = system::GenesisConfig::default()
- .build_storage::<Test>()
- .unwrap();
- t.into()
- }
-
- fn run_to_block(n: u64) {
- while System::block_number() < n {
- Scheduler::on_finalize(System::block_number());
- System::set_block_number(System::block_number() + 1);
- Scheduler::on_initialize(System::block_number());
- }
- }
-
- fn root() -> OriginCaller {
- system::RawOrigin::Root.into()
}
}
pallets/unique/src/mock.rsdiffbeforeafterboth--- a/pallets/unique/src/mock.rs
+++ b/pallets/unique/src/mock.rs
@@ -10,7 +10,7 @@
use pallet_transaction_payment::{CurrencyAdapter};
use frame_system as system;
use pallet_evm::AddressMapping;
-use crate::{EvmBackwardsAddressMapping, CrossAccountId};
+use pallet_common::account::{EvmBackwardsAddressMapping, CrossAccountId};
use codec::{Encode, Decode};
use scale_info::TypeInfo;
@@ -27,6 +27,10 @@
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
TemplateModule: pallet_template::{Pallet, Call, Storage},
Balances: pallet_balances::{Pallet, Call, Storage},
+ Common: pallet_common::{Pallet, Storage, Event<T>},
+ Fungible: pallet_fungible::{Pallet, Storage},
+ Refungible: pallet_refungible::{Pallet, Storage},
+ Nonfungible: pallet_nonfungible::{Pallet, Storage},
}
);
@@ -124,13 +128,16 @@
#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo)]
pub struct TestCrossAccountId(u64, sp_core::H160);
impl CrossAccountId<u64> for TestCrossAccountId {
+ fn as_sub(&self) -> &u64 {
+ &self.0
+ }
+ fn as_eth(&self) -> &sp_core::H160 {
+ &self.1
+ }
fn from_sub(sub: u64) -> Self {
let mut eth = [0; 20];
eth[12..20].copy_from_slice(&sub.to_be_bytes());
Self(sub, sp_core::H160(eth))
- }
- fn as_sub(&self) -> &u64 {
- &self.0
}
fn from_eth(eth: sp_core::H160) -> Self {
let mut sub_raw = [0; 8];
@@ -138,11 +145,17 @@
let sub = u64::from_be_bytes(sub_raw);
Self(sub, eth)
}
- fn as_eth(&self) -> &sp_core::H160 {
- &self.1
+ fn conv_eq(&self, other: &Self) -> bool {
+ self.as_sub() == other.as_sub()
}
}
+impl Default for TestCrossAccountId {
+ fn default() -> Self {
+ Self::from_sub(0)
+ }
+}
+
pub struct TestEtheremTransactionSender;
impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {
fn submit_logs_transaction(
@@ -157,15 +170,29 @@
type EthereumTransactionSender = TestEtheremTransactionSender;
}
-impl pallet_template::Config for Test {
+impl pallet_common::Config for Test {
type Event = ();
- type WeightInfo = ();
- type CollectionCreationPrice = CollectionCreationPrice;
- type Currency = pallet_balances::Pallet<Test>;
- type TreasuryAccountId = TreasuryAccountId;
- type EvmAddressMapping = TestEvmAddressMapping;
type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;
+ type EvmAddressMapping = TestEvmAddressMapping;
type CrossAccountId = TestCrossAccountId;
+
+ type Currency = Balances;
+ type CollectionCreationPrice = CollectionCreationPrice;
+ type TreasuryAccountId = TreasuryAccountId;
+}
+
+impl pallet_fungible::Config for Test {
+ type WeightInfo = ();
+}
+impl pallet_refungible::Config for Test {
+ type WeightInfo = ();
+}
+impl pallet_nonfungible::Config for Test {
+ type WeightInfo = ();
+}
+
+impl pallet_template::Config for Test {
+ type WeightInfo = ();
}
// Build genesis storage according to the mock runtime.
pallets/unique/src/tests.rsdiffbeforeafterboth--- a/pallets/unique/src/tests.rs
+++ b/pallets/unique/src/tests.rs
@@ -1,10 +1,11 @@
// Tests to be written here
use super::*;
use crate::mock::*;
-use crate::{AccessMode, CollectionMode, Ownership, CreateItemData};
+use crate::{AccessMode, CollectionMode};
use up_data_structs::{
- CreateNftData, CreateFungibleData, CreateReFungibleData, CollectionId, TokenId,
- MAX_DECIMAL_POINTS,
+ COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData,
+ CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, MetaUpdatePermission,
+ TokenId,
};
use frame_support::{assert_noop, assert_ok};
use sp_std::convert::TryInto;
@@ -49,18 +50,30 @@
let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();
- assert_eq!(TemplateModule::collection_id(id).unwrap().owner, owner);
assert_eq!(
- TemplateModule::collection_id(id).unwrap().name,
+ <pallet_common::CollectionById<Test>>::get(id)
+ .unwrap()
+ .owner,
+ owner
+ );
+ assert_eq!(
+ <pallet_common::CollectionById<Test>>::get(id).unwrap().name,
saved_col_name
);
- assert_eq!(TemplateModule::collection_id(id).unwrap().mode, *mode);
assert_eq!(
- TemplateModule::collection_id(id).unwrap().description,
+ <pallet_common::CollectionById<Test>>::get(id).unwrap().mode,
+ *mode
+ );
+ assert_eq!(
+ <pallet_common::CollectionById<Test>>::get(id)
+ .unwrap()
+ .description,
saved_description
);
assert_eq!(
- TemplateModule::collection_id(id).unwrap().token_prefix,
+ <pallet_common::CollectionById<Test>>::get(id)
+ .unwrap()
+ .token_prefix,
saved_prefix
);
id
@@ -91,7 +104,7 @@
fn set_version_schema() {
new_test_ext().execute_with(|| {
let origin1 = Origin::signed(1);
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
assert_ok!(TemplateModule::set_schema_version(
origin1,
@@ -99,7 +112,7 @@
SchemaVersion::Unique
));
assert_eq!(
- TemplateModule::collection_id(collection_id)
+ <pallet_common::CollectionById<Test>>::get(collection_id)
.unwrap()
.schema_version,
SchemaVersion::Unique
@@ -131,11 +144,12 @@
#[test]
fn create_nft_item() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let data = default_nft_data();
create_test_item(collection_id, &data.clone().into());
- let item = TemplateModule::nft_item_id(collection_id, 1).unwrap();
+
+ let item = <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1)).unwrap();
assert_eq!(item.const_data, data.const_data.into_inner());
assert_eq!(item.variable_data, data.variable_data.into_inner());
});
@@ -146,7 +160,7 @@
#[test]
fn create_nft_multiple_items() {
new_test_ext().execute_with(|| {
- create_test_collection(&CollectionMode::NFT, 1);
+ create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -154,7 +168,7 @@
assert_ok!(TemplateModule::create_multiple_items(
origin1,
- 1,
+ CollectionId(1),
account(1),
items_data
.clone()
@@ -163,7 +177,11 @@
.collect()
));
for (index, data) in items_data.into_iter().enumerate() {
- let item = TemplateModule::nft_item_id(1, (index + 1) as TokenId).unwrap();
+ let item = <pallet_nonfungible::TokenData<Test>>::get((
+ CollectionId(1),
+ TokenId((index + 1) as u32),
+ ))
+ .unwrap();
assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());
assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());
}
@@ -173,27 +191,23 @@
#[test]
fn create_refungible_item() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);
+ let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
let data = default_re_fungible_data();
create_test_item(collection_id, &data.clone().into());
- let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();
+ let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));
+ let balance =
+ <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));
assert_eq!(item.const_data, data.const_data.into_inner());
assert_eq!(item.variable_data, data.variable_data.into_inner());
- assert_eq!(
- item.owner[0],
- Ownership {
- owner: account(1),
- fraction: 1023
- }
- );
+ assert_eq!(balance, 1023);
});
}
#[test]
fn create_multiple_refungible_items() {
new_test_ext().execute_with(|| {
- create_test_collection(&CollectionMode::ReFungible, 1);
+ create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -205,7 +219,7 @@
assert_ok!(TemplateModule::create_multiple_items(
origin1,
- 1,
+ CollectionId(1),
account(1),
items_data
.clone()
@@ -214,16 +228,15 @@
.collect()
));
for (index, data) in items_data.into_iter().enumerate() {
- let item = TemplateModule::refungible_item_id(1, (index + 1) as TokenId).unwrap();
+ let item = <pallet_refungible::TokenData<Test>>::get((
+ CollectionId(1),
+ TokenId((index + 1) as u32),
+ ));
+ let balance =
+ <pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));
assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());
assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());
- assert_eq!(
- item.owner[0],
- Ownership {
- owner: account(1),
- fraction: 1023
- }
- );
+ assert_eq!(balance, 1023);
}
});
}
@@ -231,12 +244,15 @@
#[test]
fn create_fungible_item() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);
+ let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
let data = default_fungible_data();
create_test_item(collection_id, &data.into());
- assert_eq!(TemplateModule::fungible_item_id(collection_id, 1).value, 5);
+ assert_eq!(
+ <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),
+ 5
+ );
});
}
@@ -245,7 +261,7 @@
// new_test_ext().execute_with(|| {
// default_limits();
-// create_test_collection(&CollectionMode::Fungible(3), 1);
+// create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
// let origin1 = Origin::signed(1);
@@ -269,7 +285,7 @@
#[test]
fn transfer_fungible_item() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);
+ let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -277,155 +293,287 @@
let data = default_fungible_data();
create_test_item(collection_id, &data.into());
- assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 5);
- assert_eq!(TemplateModule::balance_count(1, 1), 5);
+ assert_eq!(
+ <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),
+ 5
+ );
// change owner scenario
- assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 5));
- assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 0);
- assert_eq!(TemplateModule::balance_count(1, 1), 0);
- assert_eq!(TemplateModule::balance_count(1, 2), 5);
+ assert_ok!(TemplateModule::transfer(
+ origin1,
+ account(2),
+ CollectionId(1),
+ TokenId(0),
+ 5
+ ));
+ assert_eq!(
+ <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),
+ 0
+ );
// split item scenario
assert_ok!(TemplateModule::transfer(
origin2.clone(),
account(3),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(0),
3
));
- assert_eq!(TemplateModule::balance_count(1, 2), 2);
- assert_eq!(TemplateModule::balance_count(1, 3), 3);
// split item and new owner has account scenario
- assert_ok!(TemplateModule::transfer(origin2, account(3), 1, 1, 1));
- assert_eq!(TemplateModule::fungible_item_id(1, 2).value, 1);
- assert_eq!(TemplateModule::fungible_item_id(1, 3).value, 4);
- assert_eq!(TemplateModule::balance_count(1, 2), 1);
- assert_eq!(TemplateModule::balance_count(1, 3), 4);
+ assert_ok!(TemplateModule::transfer(
+ origin2,
+ account(3),
+ CollectionId(1),
+ TokenId(0),
+ 1
+ ));
+ assert_eq!(
+ <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))),
+ 1
+ );
+ assert_eq!(
+ <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))),
+ 4
+ );
});
}
#[test]
fn transfer_refungible_item() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);
+ let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
+ // Create RFT 1 in 1023 pieces for account 1
let data = default_re_fungible_data();
create_test_item(collection_id, &data.clone().into());
+ let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));
+ assert_eq!(item.const_data, data.const_data.into_inner());
+ assert_eq!(item.variable_data, data.variable_data.into_inner());
+ assert_eq!(
+ <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 1
+ );
+ assert_eq!(
+ <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),
+ 1023
+ );
+ assert_eq!(
+ <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
+ true
+ );
+ // Account 1 transfers all 1023 pieces of RFT 1 to account 2
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
- {
- let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();
- assert_eq!(item.const_data, data.const_data.into_inner());
- assert_eq!(item.variable_data, data.variable_data.into_inner());
- assert_eq!(
- item.owner[0],
- Ownership {
- owner: account(1),
- fraction: 1023
- }
- );
- }
- assert_eq!(TemplateModule::balance_count(1, 1), 1023);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
-
- // change owner scenario
- assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1023));
+ assert_ok!(TemplateModule::transfer(
+ origin1,
+ account(2),
+ CollectionId(1),
+ TokenId(1),
+ 1023
+ ));
assert_eq!(
- TemplateModule::refungible_item_id(1, 1).unwrap().owner[0],
- Ownership {
- owner: account(2),
- fraction: 1023
- }
+ <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),
+ 1023
+ );
+ assert_eq!(
+ <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 0
+ );
+ assert_eq!(
+ <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),
+ 1
+ );
+ assert_eq!(
+ <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
+ false
+ );
+ assert_eq!(
+ <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),
+ true
);
- assert_eq!(TemplateModule::balance_count(1, 1), 0);
- assert_eq!(TemplateModule::balance_count(1, 2), 1023);
- // assert_eq!(TemplateModule::address_tokens(1, 1), []);
- assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
- // split item scenario
+ // Account 2 transfers 500 pieces of RFT 1 to account 3
assert_ok!(TemplateModule::transfer(
origin2.clone(),
account(3),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(1),
500
));
- {
- let item = TemplateModule::refungible_item_id(1, 1).unwrap();
- assert_eq!(
- item.owner[0],
- Ownership {
- owner: account(2),
- fraction: 523
- }
- );
- assert_eq!(
- item.owner[1],
- Ownership {
- owner: account(3),
- fraction: 500
- }
- );
- }
- assert_eq!(TemplateModule::balance_count(1, 2), 523);
- assert_eq!(TemplateModule::balance_count(1, 3), 500);
- assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
- assert_eq!(TemplateModule::address_tokens(1, 3), [1]);
+ assert_eq!(
+ <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),
+ 523
+ );
+ assert_eq!(
+ <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),
+ 500
+ );
+ assert_eq!(
+ <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),
+ 1
+ );
+ assert_eq!(
+ <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),
+ 1
+ );
+ assert_eq!(
+ <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),
+ true
+ );
+ assert_eq!(
+ <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),
+ true
+ );
- // split item and new owner has account scenario
- assert_ok!(TemplateModule::transfer(origin2, account(3), 1, 1, 200));
- {
- let item = TemplateModule::refungible_item_id(1, 1).unwrap();
- assert_eq!(
- item.owner[0],
- Ownership {
- owner: account(2),
- fraction: 323
- }
- );
- assert_eq!(
- item.owner[1],
- Ownership {
- owner: account(3),
- fraction: 700
- }
- );
- }
- assert_eq!(TemplateModule::balance_count(1, 2), 323);
- assert_eq!(TemplateModule::balance_count(1, 3), 700);
- assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
- assert_eq!(TemplateModule::address_tokens(1, 3), [1]);
+ // Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance
+ assert_ok!(TemplateModule::transfer(
+ origin2,
+ account(3),
+ CollectionId(1),
+ TokenId(1),
+ 200
+ ));
+ assert_eq!(
+ <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),
+ 323
+ );
+ assert_eq!(
+ <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),
+ 700
+ );
+ assert_eq!(
+ <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),
+ 1
+ );
+ assert_eq!(
+ <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),
+ 1
+ );
+ assert_eq!(
+ <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),
+ true
+ );
+ assert_eq!(
+ <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),
+ true
+ );
});
}
#[test]
fn transfer_nft_item() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let data = default_nft_data();
create_test_item(collection_id, &data.into());
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 1
+ );
+ assert_eq!(
+ <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
+ true
+ );
let origin1 = Origin::signed(1);
// default scenario
- assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));
- assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));
- assert_eq!(TemplateModule::balance_count(1, 1), 0);
- assert_eq!(TemplateModule::balance_count(1, 2), 1);
- // assert_eq!(TemplateModule::address_tokens(1, 1), []);
- assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
+ assert_ok!(TemplateModule::transfer(
+ origin1,
+ account(2),
+ CollectionId(1),
+ TokenId(1),
+ 1
+ ));
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 0
+ );
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),
+ 1
+ );
+ assert_eq!(
+ <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
+ false
+ );
+ assert_eq!(
+ <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),
+ true
+ );
+ });
+}
+
+#[test]
+fn transfer_nft_item_wrong_value() {
+ new_test_ext().execute_with(|| {
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
+
+ let data = default_nft_data();
+ create_test_item(collection_id, &data.into());
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 1
+ );
+ assert_eq!(
+ <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
+ true
+ );
+
+ let origin1 = Origin::signed(1);
+
+ assert_noop!(
+ TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2)
+ .map_err(|e| e.error),
+ <pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount
+ );
});
}
#[test]
+fn transfer_nft_item_zero_value() {
+ new_test_ext().execute_with(|| {
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
+
+ let data = default_nft_data();
+ create_test_item(collection_id, &data.into());
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 1
+ );
+ assert_eq!(
+ <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
+ true
+ );
+
+ let origin1 = Origin::signed(1);
+
+ // Transferring 0 amount works on NFT...
+ assert_ok!(TemplateModule::transfer(
+ origin1,
+ account(2),
+ CollectionId(1),
+ TokenId(1),
+ 0
+ ));
+ // ... and results in no transfer
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 1
+ );
+ assert_eq!(
+ <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
+ true
+ );
+ });
+}
+
+#[test]
fn nft_approve_and_transfer_from() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let data = default_nft_data();
create_test_item(collection_id, &data.into());
@@ -433,197 +581,286 @@
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 1
+ );
+ assert_eq!(
+ <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
+ true
+ );
- // neg transfer
+ // neg transfer_from
assert_noop!(
- TemplateModule::transfer_from(origin2.clone(), account(1), account(2), 1, 1, 1),
- Error::<Test>::NoPermission
+ TemplateModule::transfer_from(
+ origin2.clone(),
+ account(1),
+ account(2),
+ CollectionId(1),
+ TokenId(1),
+ 1
+ )
+ .map_err(|e| e.error),
+ CommonError::<Test>::TokenValueNotEnough
);
// do approve
- assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 5));
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
+ assert_ok!(TemplateModule::approve(
+ origin1,
+ account(2),
+ CollectionId(1),
+ TokenId(1),
+ 1
+ ));
+ assert_eq!(
+ <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
+ account(2)
+ );
assert_ok!(TemplateModule::transfer_from(
origin2,
account(1),
account(3),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(1),
1
));
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);
+ assert!(
+ <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()
+ );
});
}
#[test]
fn nft_approve_and_transfer_from_allow_list() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
+ // Create NFT 1 for account 1
let data = default_nft_data();
create_test_item(collection_id, &data.clone().into());
-
assert_eq!(
- &TemplateModule::nft_item_id(1, 1).unwrap().const_data,
+ &<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))
+ .unwrap()
+ .const_data,
&data.const_data.into_inner()
);
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 1
+ );
+ assert_eq!(
+ <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
+ true
+ );
+ // Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list
assert_ok!(TemplateModule::set_mint_permission(
origin1.clone(),
- 1,
+ CollectionId(1),
true
));
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
- 1,
+ CollectionId(1),
AccessMode::AllowList
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(1)
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(2)
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(3)
));
- // do approve
+ // Account 1 approves account 2 for NFT 1
assert_ok!(TemplateModule::approve(
origin1.clone(),
account(2),
- 1,
- 1,
- 5
+ CollectionId(1),
+ TokenId(1),
+ 1
));
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
- assert_ok!(TemplateModule::approve(origin1, account(3), 1, 1, 5));
- assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);
+ assert_eq!(
+ <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
+ account(2)
+ );
+ // Account 2 transfers NFT 1 from account 1 to account 3
assert_ok!(TemplateModule::transfer_from(
origin2,
account(1),
account(3),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(1),
1
));
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);
+ assert!(
+ <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()
+ );
});
}
#[test]
fn refungible_approve_and_transfer_from() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);
+ let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
+ // Create RFT 1 in 1023 pieces for account 1
let data = default_re_fungible_data();
create_test_item(collection_id, &data.into());
- assert_eq!(TemplateModule::balance_count(1, 1), 1023);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ assert_eq!(
+ <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 1
+ );
+ assert_eq!(
+ <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),
+ 1023
+ );
+ assert_eq!(
+ <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
+ true
+ );
+ // Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list
assert_ok!(TemplateModule::set_mint_permission(
origin1.clone(),
- 1,
+ CollectionId(1),
true
));
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
- 1,
+ CollectionId(1),
AccessMode::AllowList
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(1)
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(2)
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(3)
));
- // do approve
- assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 1023));
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1023);
+ // Account 1 approves account 2 for 1023 pieces of RFT 1
+ assert_ok!(TemplateModule::approve(
+ origin1,
+ account(2),
+ CollectionId(1),
+ TokenId(1),
+ 1023
+ ));
+ assert_eq!(
+ <pallet_refungible::Allowance<Test>>::get((
+ CollectionId(1),
+ TokenId(1),
+ account(1),
+ account(2)
+ )),
+ 1023
+ );
+ // Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3
assert_ok!(TemplateModule::transfer_from(
origin2,
account(1),
account(3),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(1),
100
));
- assert_eq!(TemplateModule::balance_count(1, 1), 923);
- assert_eq!(TemplateModule::balance_count(1, 3), 100);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
- assert_eq!(TemplateModule::address_tokens(1, 3), [1]);
-
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 923);
+ assert_eq!(
+ <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 1
+ );
+ assert_eq!(
+ <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),
+ 1
+ );
+ assert_eq!(
+ <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),
+ 923
+ );
+ assert_eq!(
+ <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),
+ 100
+ );
+ assert_eq!(
+ <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
+ true
+ );
+ assert_eq!(
+ <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
+ true
+ );
+ assert_eq!(
+ <pallet_refungible::Allowance<Test>>::get((
+ CollectionId(1),
+ TokenId(1),
+ account(1),
+ account(2)
+ )),
+ 923
+ );
});
}
#[test]
fn fungible_approve_and_transfer_from() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);
+ let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
let data = default_fungible_data();
create_test_item(collection_id, &data.into());
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
-
- assert_eq!(TemplateModule::balance_count(1, 1), 5);
assert_ok!(TemplateModule::set_mint_permission(
origin1.clone(),
- 1,
+ CollectionId(1),
true
));
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
- 1,
+ CollectionId(1),
AccessMode::AllowList
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(1)
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(2)
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(3)
));
@@ -631,31 +868,55 @@
assert_ok!(TemplateModule::approve(
origin1.clone(),
account(2),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(0),
5
));
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
- assert_ok!(TemplateModule::approve(origin1, account(3), 1, 1, 5));
- assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
+ assert_eq!(
+ <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),
+ 5
+ );
+ assert_ok!(TemplateModule::approve(
+ origin1,
+ account(3),
+ CollectionId(1),
+ TokenId(0),
+ 5
+ ));
+ assert_eq!(
+ <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),
+ 5
+ );
+ assert_eq!(
+ <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))),
+ 5
+ );
assert_ok!(TemplateModule::transfer_from(
origin2.clone(),
account(1),
account(3),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(0),
4
));
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::balance_count(1, 3), 4);
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);
+ assert_eq!(
+ <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),
+ 1
+ );
assert_noop!(
- TemplateModule::transfer_from(origin2, account(1), account(3), 1, 1, 4),
- Error::<Test>::NoPermission
+ TemplateModule::transfer_from(
+ origin2,
+ account(1),
+ account(3),
+ CollectionId(1),
+ TokenId(0),
+ 4
+ )
+ .map_err(|e| e.error),
+ CommonError::<Test>::TokenValueNotEnough
);
});
}
@@ -663,7 +924,7 @@
#[test]
fn change_collection_owner() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::change_collection_owner(
@@ -672,7 +933,9 @@
2
));
assert_eq!(
- TemplateModule::collection_id(collection_id).unwrap().owner,
+ <pallet_common::CollectionById<Test>>::get(collection_id)
+ .unwrap()
+ .owner,
2
);
});
@@ -681,7 +944,7 @@
#[test]
fn destroy_collection() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));
@@ -691,41 +954,74 @@
#[test]
fn burn_nft_item() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
- assert_ok!(TemplateModule::add_collection_admin(
+
+ let data = default_nft_data();
+ create_test_item(collection_id, &data.into());
+
+ // check balance (collection with id = 1, user id = 1)
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 1
+ );
+
+ // burn item
+ assert_ok!(TemplateModule::burn_item(
origin1.clone(),
collection_id,
- account(2)
+ TokenId(1),
+ 1
));
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 0
+ );
+ });
+}
+
+#[test]
+fn burn_same_nft_item_twice() {
+ new_test_ext().execute_with(|| {
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
+
+ let origin1 = Origin::signed(1);
let data = default_nft_data();
create_test_item(collection_id, &data.into());
// check balance (collection with id = 1, user id = 1)
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 1
+ );
// burn item
assert_ok!(TemplateModule::burn_item(
origin1.clone(),
collection_id,
- 1,
+ TokenId(1),
1
));
+
+ // burn item again
assert_noop!(
- TemplateModule::burn_item(origin1, collection_id, 1, 1),
- Error::<Test>::TokenNotFound
+ TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),
+ CommonError::<Test>::TokenNotFound
);
- assert_eq!(TemplateModule::balance_count(1, 1), 0);
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 0
+ );
});
}
#[test]
fn burn_fungible_item() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);
+ let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::add_collection_admin(
@@ -738,23 +1034,62 @@
create_test_item(collection_id, &data.into());
// check balance (collection with id = 1, user id = 1)
- assert_eq!(TemplateModule::balance_count(1, 1), 5);
+ assert_eq!(
+ <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),
+ 5
+ );
// burn item
- assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));
+ assert_ok!(TemplateModule::burn_item(
+ origin1.clone(),
+ CollectionId(1),
+ TokenId(0),
+ 5
+ ));
assert_noop!(
- TemplateModule::burn_item(origin1, 1, 1, 5),
- Error::<Test>::TokenValueNotEnough
+ TemplateModule::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),
+ CommonError::<Test>::TokenValueTooLow
);
- assert_eq!(TemplateModule::balance_count(1, 1), 0);
+ assert_eq!(
+ <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),
+ 0
+ );
});
}
#[test]
+fn burn_fungible_item_with_token_id() {
+ new_test_ext().execute_with(|| {
+ let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
+
+ let origin1 = Origin::signed(1);
+ assert_ok!(TemplateModule::add_collection_admin(
+ origin1.clone(),
+ collection_id,
+ account(2)
+ ));
+
+ let data = default_fungible_data();
+ create_test_item(collection_id, &data.into());
+
+ // check balance (collection with id = 1, user id = 1)
+ assert_eq!(
+ <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),
+ 5
+ );
+
+ // Try to burn item using Token ID
+ assert_noop!(
+ TemplateModule::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),
+ <pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId
+ );
+ });
+}
+#[test]
fn burn_refungible_item() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);
+ let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::set_mint_permission(
@@ -769,13 +1104,13 @@
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ collection_id,
account(1)
));
assert_ok!(TemplateModule::add_collection_admin(
origin1.clone(),
- 1,
+ collection_id,
account(2)
));
@@ -783,29 +1118,43 @@
create_test_item(collection_id, &data.into());
// check balance (collection with id = 1, user id = 2)
- assert_eq!(TemplateModule::balance_count(1, 1), 1023);
+ assert_eq!(
+ <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 1
+ );
+ assert_eq!(
+ <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),
+ 1023
+ );
// burn item
- assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 1023));
+ assert_ok!(TemplateModule::burn_item(
+ origin1.clone(),
+ collection_id,
+ TokenId(1),
+ 1023
+ ));
assert_noop!(
- TemplateModule::burn_item(origin1, 1, 1, 1023),
- Error::<Test>::TokenNotFound
+ TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023)
+ .map_err(|e| e.error),
+ CommonError::<Test>::TokenValueTooLow
);
- assert_eq!(TemplateModule::balance_count(1, 1), 0);
+ assert_eq!(
+ <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),
+ 0
+ );
});
}
#[test]
fn add_collection_admin() {
new_test_ext().execute_with(|| {
- let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);
- create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);
- create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);
-
+ let collection1_id =
+ create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
let origin1 = Origin::signed(1);
- // collection admin
+ // Add collection admins
assert_ok!(TemplateModule::add_collection_admin(
origin1.clone(),
collection1_id,
@@ -817,22 +1166,31 @@
account(3)
));
- assert!(TemplateModule::admin_list_collection(collection1_id).contains(&account(2)),);
- assert!(TemplateModule::admin_list_collection(collection1_id).contains(&account(3)),);
+ // Owner is not an admin by default
+ assert_eq!(
+ <pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))),
+ false
+ );
+ assert!(<pallet_common::IsAdmin<Test>>::get((
+ CollectionId(1),
+ account(2)
+ )));
+ assert!(<pallet_common::IsAdmin<Test>>::get((
+ CollectionId(1),
+ account(3)
+ )));
});
}
#[test]
fn remove_collection_admin() {
new_test_ext().execute_with(|| {
- let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);
- create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);
- create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);
-
+ let collection1_id =
+ create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
- // collection admin
+ // Add collection admins 2 and 3
assert_ok!(TemplateModule::add_collection_admin(
origin1.clone(),
collection1_id,
@@ -844,31 +1202,54 @@
account(3)
));
- assert!(TemplateModule::admin_list_collection(1).contains(&account(2)),);
- assert!(TemplateModule::admin_list_collection(1).contains(&account(3)),);
+ assert!(<pallet_common::IsAdmin<Test>>::get((
+ CollectionId(1),
+ account(2)
+ )));
+ assert!(<pallet_common::IsAdmin<Test>>::get((
+ CollectionId(1),
+ account(3)
+ )));
- // remove admin
+ // remove admin 3
assert_ok!(TemplateModule::remove_collection_admin(
origin2,
- 1,
+ CollectionId(1),
account(3)
));
- assert!(!TemplateModule::admin_list_collection(1).contains(&account(3)),);
+
+ // 2 is still admin, 3 is not an admin anymore
+ assert!(<pallet_common::IsAdmin<Test>>::get((
+ CollectionId(1),
+ account(2)
+ )));
+ assert_eq!(
+ <pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))),
+ false
+ );
});
}
#[test]
fn balance_of() {
new_test_ext().execute_with(|| {
- let nft_collection_id = create_test_collection(&CollectionMode::NFT, 1);
- let fungible_collection_id = create_test_collection(&CollectionMode::Fungible(3), 2);
- let re_fungible_collection_id = create_test_collection(&CollectionMode::ReFungible, 3);
+ let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
+ let fungible_collection_id =
+ create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));
+ let re_fungible_collection_id =
+ create_test_collection(&CollectionMode::ReFungible, CollectionId(3));
// check balance before
- assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 0);
- assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 0);
assert_eq!(
- TemplateModule::balance_count(re_fungible_collection_id, 1),
+ <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),
+ 0
+ );
+ assert_eq!(
+ <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),
+ 0
+ );
+ assert_eq!(
+ <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),
0
);
@@ -882,28 +1263,30 @@
create_test_item(re_fungible_collection_id, &re_fungible_data.into());
// check balance (collection with id = 1, user id = 1)
- assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 1);
- assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 5);
assert_eq!(
- TemplateModule::balance_count(re_fungible_collection_id, 1),
- 1023
+ <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),
+ 1
);
assert_eq!(
- TemplateModule::nft_item_id(nft_collection_id, 1)
- .unwrap()
- .owner,
- account(1)
+ <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),
+ 5
);
assert_eq!(
- TemplateModule::fungible_item_id(fungible_collection_id, 1).value,
- 5
+ <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),
+ 1
);
+
assert_eq!(
- TemplateModule::refungible_item_id(re_fungible_collection_id, 1)
- .unwrap()
- .owner[0]
- .owner,
- account(1)
+ <pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))),
+ true
+ );
+ assert_eq!(
+ <pallet_refungible::Owned<Test>>::get((
+ re_fungible_collection_id,
+ account(1),
+ TokenId(1)
+ )),
+ true
);
});
}
@@ -911,7 +1294,7 @@
#[test]
fn approve() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let data = default_nft_data();
create_test_item(collection_id, &data.into());
@@ -919,15 +1302,24 @@
let origin1 = Origin::signed(1);
// approve
- assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 1));
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);
+ assert_ok!(TemplateModule::approve(
+ origin1,
+ account(2),
+ CollectionId(1),
+ TokenId(1),
+ 1
+ ));
+ assert_eq!(
+ <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
+ account(2)
+ );
});
}
#[test]
fn transfer_from() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -938,46 +1330,59 @@
assert_ok!(TemplateModule::approve(
origin1.clone(),
account(2),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(1),
1
));
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);
+ assert_eq!(
+ <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
+ account(2)
+ );
assert_ok!(TemplateModule::set_mint_permission(
origin1.clone(),
- 1,
+ CollectionId(1),
true
));
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
- 1,
+ CollectionId(1),
AccessMode::AllowList
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(1)
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(2)
));
- assert_ok!(TemplateModule::add_to_allow_list(origin1, 1, account(3)));
+ assert_ok!(TemplateModule::add_to_allow_list(
+ origin1,
+ CollectionId(1),
+ account(3)
+ ));
assert_ok!(TemplateModule::transfer_from(
origin2,
account(1),
account(2),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(1),
1
));
// after transfer
- assert_eq!(TemplateModule::balance_count(1, 1), 0);
- assert_eq!(TemplateModule::balance_count(1, 2), 1);
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))),
+ 0
+ );
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))),
+ 1
+ );
});
}
@@ -989,7 +1394,7 @@
#[test]
fn owner_can_add_address_to_allow_list() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::add_to_allow_list(
@@ -997,14 +1402,17 @@
collection_id,
account(2)
));
- assert!(TemplateModule::allow_list(collection_id, 2));
+ assert!(<pallet_common::Allowlist<Test>>::get((
+ collection_id,
+ account(2)
+ )));
});
}
#[test]
fn admin_can_add_address_to_allow_list() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1018,19 +1426,22 @@
collection_id,
account(3)
));
- assert!(TemplateModule::allow_list(collection_id, 3));
+ assert!(<pallet_common::Allowlist<Test>>::get((
+ collection_id,
+ account(3)
+ )));
});
}
#[test]
fn nonprivileged_user_cannot_add_address_to_allow_list() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin2 = Origin::signed(2);
assert_noop!(
TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),
- Error::<Test>::NoPermission
+ CommonError::<Test>::NoPermission
);
});
}
@@ -1041,8 +1452,8 @@
let origin1 = Origin::signed(1);
assert_noop!(
- TemplateModule::add_to_allow_list(origin1, 1, account(2)),
- Error::<Test>::CollectionNotFound
+ TemplateModule::add_to_allow_list(origin1, CollectionId(1), account(2)),
+ CommonError::<Test>::CollectionNotFound
);
});
}
@@ -1050,7 +1461,7 @@
#[test]
fn nobody_can_add_address_to_allow_list_of_deleted_collection() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::destroy_collection(
@@ -1059,7 +1470,7 @@
));
assert_noop!(
TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),
- Error::<Test>::CollectionNotFound
+ CommonError::<Test>::CollectionNotFound
);
});
}
@@ -1068,7 +1479,7 @@
#[test]
fn address_is_already_added_to_allow_list() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::add_to_allow_list(
@@ -1081,14 +1492,17 @@
collection_id,
account(2)
));
- assert!(TemplateModule::allow_list(collection_id, 2));
+ assert!(<pallet_common::Allowlist<Test>>::get((
+ collection_id,
+ account(2)
+ )));
});
}
#[test]
fn owner_can_remove_address_from_allow_list() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::add_to_allow_list(
@@ -1101,41 +1515,51 @@
collection_id,
account(2)
));
- assert!(!TemplateModule::allow_list(collection_id, 2));
+ assert_eq!(
+ <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),
+ false
+ );
});
}
#[test]
fn admin_can_remove_address_from_allow_list() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
+ // Owner adds admin
assert_ok!(TemplateModule::add_collection_admin(
origin1.clone(),
collection_id,
account(2)
));
+ // Owner adds address 3 to allow list
assert_ok!(TemplateModule::add_to_allow_list(
origin1,
collection_id,
account(3)
));
+
+ // Admin removes address 3 from allow list
assert_ok!(TemplateModule::remove_from_allow_list(
origin2,
collection_id,
account(3)
));
- assert!(!TemplateModule::allow_list(collection_id, 3));
+ assert_eq!(
+ <pallet_common::Allowlist<Test>>::get((collection_id, account(3))),
+ false
+ );
});
}
#[test]
fn nonprivileged_user_cannot_remove_address_from_allow_list() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1146,9 +1570,12 @@
));
assert_noop!(
TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),
- Error::<Test>::NoPermission
+ CommonError::<Test>::NoPermission
);
- assert!(TemplateModule::allow_list(collection_id, 2));
+ assert!(<pallet_common::Allowlist<Test>>::get((
+ collection_id,
+ account(2)
+ )));
});
}
@@ -1158,8 +1585,8 @@
let origin1 = Origin::signed(1);
assert_noop!(
- TemplateModule::remove_from_allow_list(origin1, 1, account(2)),
- Error::<Test>::CollectionNotFound
+ TemplateModule::remove_from_allow_list(origin1, CollectionId(1), account(2)),
+ CommonError::<Test>::CollectionNotFound
);
});
}
@@ -1167,21 +1594,37 @@
#[test]
fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
+ // Add account 2 to allow list
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
collection_id,
account(2)
));
+
+ // Account 2 is in collection allow-list
+ assert!(<pallet_common::Allowlist<Test>>::get((
+ collection_id,
+ account(2)
+ )));
+
+ // Destroy collection
assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));
+
+ // Attempt to remove account 2 from collection allow-list => error
assert_noop!(
TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),
- Error::<Test>::CollectionNotFound
+ CommonError::<Test>::CollectionNotFound
+ );
+
+ // Account 2 is not found in collection allow-list anyway
+ assert_eq!(
+ <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),
+ false
);
- assert!(!TemplateModule::allow_list(collection_id, 2));
});
}
@@ -1189,7 +1632,7 @@
#[test]
fn address_is_already_removed_from_allow_list() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::add_to_allow_list(
@@ -1202,12 +1645,19 @@
collection_id,
account(2)
));
+ assert_eq!(
+ <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),
+ false
+ );
assert_ok!(TemplateModule::remove_from_allow_list(
origin1,
collection_id,
account(2)
));
- assert!(!TemplateModule::allow_list(collection_id, 2));
+ assert_eq!(
+ <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),
+ false
+ );
});
}
@@ -1215,7 +1665,7 @@
#[test]
fn allow_list_test_1() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -1234,8 +1684,9 @@
));
assert_noop!(
- TemplateModule::transfer(origin1, account(3), 1, 1, 1),
- Error::<Test>::AddresNotInAllowList
+ TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1)
+ .map_err(|e| e.error),
+ CommonError::<Test>::AddressNotInAllowlist
);
});
}
@@ -1243,7 +1694,7 @@
#[test]
fn allow_list_test_2() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let data = default_nft_data();
@@ -1256,12 +1707,12 @@
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ collection_id,
account(1)
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ collection_id,
account(2)
));
@@ -1269,21 +1720,32 @@
assert_ok!(TemplateModule::approve(
origin1.clone(),
account(1),
- 1,
- 1,
+ collection_id,
+ TokenId(1),
1
));
- assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);
+ assert_eq!(
+ <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
+ account(1)
+ );
assert_ok!(TemplateModule::remove_from_allow_list(
origin1.clone(),
- 1,
+ collection_id,
account(1)
));
assert_noop!(
- TemplateModule::transfer_from(origin1, account(1), account(3), 1, 1, 1),
- Error::<Test>::AddresNotInAllowList
+ TemplateModule::transfer_from(
+ origin1,
+ account(1),
+ account(3),
+ CollectionId(1),
+ TokenId(1),
+ 1
+ )
+ .map_err(|e| e.error),
+ CommonError::<Test>::AddressNotInAllowlist
);
});
}
@@ -1292,7 +1754,7 @@
#[test]
fn allow_list_test_3() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -1306,13 +1768,14 @@
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ collection_id,
account(1)
));
assert_noop!(
- TemplateModule::transfer(origin1, account(3), 1, 1, 1),
- Error::<Test>::AddresNotInAllowList
+ TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1)
+ .map_err(|e| e.error),
+ CommonError::<Test>::AddressNotInAllowlist
);
});
}
@@ -1320,7 +1783,7 @@
#[test]
fn allow_list_test_4() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -1347,11 +1810,14 @@
assert_ok!(TemplateModule::approve(
origin1.clone(),
account(1),
- 1,
- 1,
+ collection_id,
+ TokenId(1),
1
));
- assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);
+ assert_eq!(
+ <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
+ account(1)
+ );
assert_ok!(TemplateModule::remove_from_allow_list(
origin1.clone(),
@@ -1360,8 +1826,16 @@
));
assert_noop!(
- TemplateModule::transfer_from(origin1, account(1), account(3), 1, 1, 1),
- Error::<Test>::AddresNotInAllowList
+ TemplateModule::transfer_from(
+ origin1,
+ account(1),
+ account(3),
+ collection_id,
+ TokenId(1),
+ 1
+ )
+ .map_err(|e| e.error),
+ CommonError::<Test>::AddressNotInAllowlist
);
});
}
@@ -1370,7 +1844,7 @@
#[test]
fn allow_list_test_5() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -1383,8 +1857,9 @@
AccessMode::AllowList
));
assert_noop!(
- TemplateModule::burn_item(origin1.clone(), 1, 1, 5),
- Error::<Test>::AddresNotInAllowList
+ TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1)
+ .map_err(|e| e.error),
+ CommonError::<Test>::AddressNotInAllowlist
);
});
}
@@ -1393,7 +1868,7 @@
#[test]
fn allow_list_test_6() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -1408,8 +1883,9 @@
// do approve
assert_noop!(
- TemplateModule::approve(origin1, account(1), 1, 1, 5),
- Error::<Test>::AddresNotInAllowList
+ TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 1)
+ .map_err(|e| e.error),
+ CommonError::<Test>::AddressNotInAllowlist
);
});
}
@@ -1419,7 +1895,7 @@
#[test]
fn allow_list_test_7() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let data = default_nft_data();
create_test_item(collection_id, &data.into());
@@ -1442,20 +1918,28 @@
account(2)
));
- assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1));
+ assert_ok!(TemplateModule::transfer(
+ origin1,
+ account(2),
+ CollectionId(1),
+ TokenId(1),
+ 1
+ ));
});
}
#[test]
fn allow_list_test_8() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
+ // Create NFT for account 1
let data = default_nft_data();
create_test_item(collection_id, &data.into());
let origin1 = Origin::signed(1);
+ // Toggle Allow List mode and add accounts 1 and 2
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
collection_id,
@@ -1472,22 +1956,26 @@
account(2)
));
- // do approve
+ // Sself-approve account 1 for NFT 1
assert_ok!(TemplateModule::approve(
origin1.clone(),
account(1),
- 1,
- 1,
- 5
+ CollectionId(1),
+ TokenId(1),
+ 1
));
- assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 5);
+ assert_eq!(
+ <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
+ account(1)
+ );
+ // Transfer from 1 to 2
assert_ok!(TemplateModule::transfer_from(
origin1,
account(1),
account(2),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(1),
1
));
});
@@ -1497,7 +1985,7 @@
#[test]
fn allow_list_test_9() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::set_public_access_mode(
@@ -1520,7 +2008,7 @@
#[test]
fn allow_list_test_10() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1555,7 +2043,7 @@
#[test]
fn allow_list_test_11() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1577,8 +2065,14 @@
));
assert_noop!(
- TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),
- Error::<Test>::PublicMintingNotAllowed
+ TemplateModule::create_item(
+ origin2,
+ CollectionId(1),
+ account(2),
+ default_nft_data().into()
+ )
+ .map_err(|e| e.error),
+ CommonError::<Test>::PublicMintingNotAllowed
);
});
}
@@ -1587,7 +2081,7 @@
#[test]
fn allow_list_test_12() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1604,8 +2098,14 @@
));
assert_noop!(
- TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),
- Error::<Test>::PublicMintingNotAllowed
+ TemplateModule::create_item(
+ origin2,
+ CollectionId(1),
+ account(2),
+ default_nft_data().into()
+ )
+ .map_err(|e| e.error),
+ CommonError::<Test>::PublicMintingNotAllowed
);
});
}
@@ -1614,7 +2114,7 @@
#[test]
fn allow_list_test_13() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -1638,7 +2138,7 @@
#[test]
fn allow_list_test_14() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1662,7 +2162,7 @@
assert_ok!(TemplateModule::create_item(
origin2,
- 1,
+ collection_id,
account(2),
default_nft_data().into()
));
@@ -1673,7 +2173,7 @@
#[test]
fn allow_list_test_15() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1690,8 +2190,14 @@
));
assert_noop!(
- TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),
- Error::<Test>::AddresNotInAllowList
+ TemplateModule::create_item(
+ origin2,
+ collection_id,
+ account(2),
+ default_nft_data().into()
+ )
+ .map_err(|e| e.error),
+ CommonError::<Test>::AddressNotInAllowlist
);
});
}
@@ -1700,7 +2206,7 @@
#[test]
fn allow_list_test_16() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1723,7 +2229,7 @@
assert_ok!(TemplateModule::create_item(
origin2,
- 1,
+ collection_id,
account(2),
default_nft_data().into()
));
@@ -1734,18 +2240,27 @@
#[test]
fn total_number_collections_bound() {
new_test_ext().execute_with(|| {
- create_test_collection(&CollectionMode::NFT, 1);
+ create_test_collection(&CollectionMode::NFT, CollectionId(1));
});
}
-// Total number of collections. Negotive test
#[test]
+fn create_max_collections() {
+ new_test_ext().execute_with(|| {
+ for i in 1..=COLLECTION_NUMBER_LIMIT {
+ create_test_collection(&CollectionMode::NFT, CollectionId(i));
+ }
+ });
+}
+
+// Total number of collections. Negative test
+#[test]
fn total_number_collections_bound_neg() {
new_test_ext().execute_with(|| {
let origin1 = Origin::signed(1);
- for i in 0..COLLECTION_NUMBER_LIMIT {
- create_test_collection(&CollectionMode::NFT, i + 1);
+ for i in 1..=COLLECTION_NUMBER_LIMIT {
+ create_test_collection(&CollectionMode::NFT, CollectionId(i));
}
let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
@@ -1761,7 +2276,7 @@
token_prefix1,
CollectionMode::NFT
),
- Error::<Test>::TotalCollectionsLimitExceeded
+ CommonError::<Test>::TotalCollectionsLimitExceeded
);
});
}
@@ -1770,7 +2285,7 @@
#[test]
fn owned_tokens_bound() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let data = default_nft_data();
create_test_item(collection_id, &data.clone().into());
@@ -1782,19 +2297,20 @@
#[test]
fn owned_tokens_bound_neg() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
- for _ in 0..ACCOUNT_TOKEN_OWNERSHIP_LIMIT {
+ for _ in 1..=MAX_TOKEN_OWNERSHIP {
let data = default_nft_data();
create_test_item(collection_id, &data.clone().into());
}
let data = default_nft_data();
assert_noop!(
- TemplateModule::create_item(origin1, 1, account(1), data.into()),
- Error::<Test>::AccountTokenLimitExceeded
+ TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into())
+ .map_err(|e| e.error),
+ CommonError::<Test>::AccountTokenLimitExceeded
);
});
}
@@ -1803,7 +2319,7 @@
#[test]
fn collection_admins_bound() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -1824,7 +2340,7 @@
#[test]
fn collection_admins_bound_neg() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -1832,16 +2348,16 @@
assert_ok!(TemplateModule::add_collection_admin(
origin1.clone(),
collection_id,
- account(2 + i)
+ account((2 + i).into())
));
}
assert_noop!(
TemplateModule::add_collection_admin(
origin1,
collection_id,
- account(3 + COLLECTION_ADMINS_LIMIT)
+ account((3 + COLLECTION_ADMINS_LIMIT).into())
),
- Error::<Test>::CollectionAdminsLimitExceeded
+ CommonError::<Test>::CollectionAdminCountExceeded
);
});
}
@@ -1850,7 +2366,7 @@
#[test]
fn set_const_on_chain_schema() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::set_const_on_chain_schema(
@@ -1860,13 +2376,13 @@
));
assert_eq!(
- TemplateModule::collection_id(collection_id)
+ <pallet_common::CollectionById<Test>>::get(collection_id)
.unwrap()
.const_on_chain_schema,
b"test const on chain schema".to_vec()
);
assert_eq!(
- TemplateModule::collection_id(collection_id)
+ <pallet_common::CollectionById<Test>>::get(collection_id)
.unwrap()
.variable_on_chain_schema,
b"".to_vec()
@@ -1877,7 +2393,7 @@
#[test]
fn set_variable_on_chain_schema() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::set_variable_on_chain_schema(
@@ -1887,13 +2403,13 @@
));
assert_eq!(
- TemplateModule::collection_id(collection_id)
+ <pallet_common::CollectionById<Test>>::get(collection_id)
.unwrap()
.const_on_chain_schema,
b"".to_vec()
);
assert_eq!(
- TemplateModule::collection_id(collection_id)
+ <pallet_common::CollectionById<Test>>::get(collection_id)
.unwrap()
.variable_on_chain_schema,
b"test variable on chain schema".to_vec()
@@ -1904,23 +2420,23 @@
#[test]
fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let data = default_nft_data();
- create_test_item(1, &data.into());
+ create_test_item(CollectionId(1), &data.into());
let variable_data = b"test data".to_vec();
assert_ok!(TemplateModule::set_variable_meta_data(
origin1,
collection_id,
- 1,
+ TokenId(1),
variable_data.clone()
));
assert_eq!(
- TemplateModule::nft_item_id(collection_id, 1)
+ <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))
.unwrap()
.variable_data,
variable_data
@@ -1931,25 +2447,23 @@
#[test]
fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);
+ let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
let origin1 = Origin::signed(1);
let data = default_re_fungible_data();
- create_test_item(1, &data.into());
+ create_test_item(collection_id, &data.into());
let variable_data = b"test data".to_vec();
assert_ok!(TemplateModule::set_variable_meta_data(
origin1,
collection_id,
- 1,
+ TokenId(1),
variable_data.clone()
));
assert_eq!(
- TemplateModule::refungible_item_id(collection_id, 1)
- .unwrap()
- .variable_data,
+ <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1))).variable_data,
variable_data
);
});
@@ -1958,17 +2472,23 @@
#[test]
fn set_variable_meta_data_on_fungible_token_fails() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);
+ let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
let origin1 = Origin::signed(1);
let data = default_fungible_data();
- create_test_item(1, &data.into());
+ create_test_item(collection_id, &data.into());
let variable_data = b"test data".to_vec();
assert_noop!(
- TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),
- Error::<Test>::CantStoreMetadataInFungibleTokens
+ TemplateModule::set_variable_meta_data(
+ origin1,
+ collection_id,
+ TokenId(0),
+ variable_data
+ )
+ .map_err(|e| e.error),
+ <pallet_fungible::Error<Test>>::FungibleItemsDontHaveData
);
});
}
@@ -1976,17 +2496,23 @@
#[test]
fn set_variable_meta_data_on_nft_token_fails_for_big_data() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let data = default_nft_data();
- create_test_item(1, &data.into());
+ create_test_item(collection_id, &data.into());
let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();
assert_noop!(
- TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),
- Error::<Test>::TokenVariableDataLimitExceeded
+ TemplateModule::set_variable_meta_data(
+ origin1,
+ collection_id,
+ TokenId(1),
+ variable_data
+ )
+ .map_err(|e| e.error),
+ CommonError::<Test>::TokenVariableDataLimitExceeded
);
});
}
@@ -1994,17 +2520,23 @@
#[test]
fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);
+ let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
let origin1 = Origin::signed(1);
let data = default_re_fungible_data();
- create_test_item(1, &data.into());
+ create_test_item(collection_id, &data.into());
let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();
assert_noop!(
- TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),
- Error::<Test>::TokenVariableDataLimitExceeded
+ TemplateModule::set_variable_meta_data(
+ origin1,
+ collection_id,
+ TokenId(1),
+ variable_data
+ )
+ .map_err(|e| e.error),
+ CommonError::<Test>::TokenVariableDataLimitExceeded
);
});
}
@@ -2014,12 +2546,12 @@
new_test_ext().execute_with(|| {
//default_limits();
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let data = default_nft_data();
- create_test_item(1, &data.into());
+ create_test_item(collection_id, &data.into());
assert_ok!(TemplateModule::set_meta_update_permission_flag(
origin1.clone(),
@@ -2031,12 +2563,12 @@
assert_ok!(TemplateModule::set_variable_meta_data(
origin1,
collection_id,
- 1,
+ TokenId(1),
variable_data.clone()
));
assert_eq!(
- TemplateModule::nft_item_id(collection_id, 1)
+ <pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))
.unwrap()
.variable_data,
variable_data
@@ -2047,7 +2579,8 @@
#[test]
fn set_variable_meta_data_on_nft_with_item_owner_permission_flag_neg() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);
+ let collection_id =
+ create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -2063,7 +2596,7 @@
));
let data = default_nft_data();
- create_test_item(1, &data.into());
+ create_test_item(collection_id, &data.into());
assert_ok!(TemplateModule::set_meta_update_permission_flag(
origin1.clone(),
@@ -2076,10 +2609,11 @@
TemplateModule::set_variable_meta_data(
origin1,
collection_id,
- 1,
+ TokenId(1),
variable_data.clone()
- ),
- Error::<Test>::TokenVariableDataLimitExceeded
+ )
+ .map_err(|e| e.error),
+ CommonError::<Test>::TokenVariableDataLimitExceeded
);
})
}
@@ -2089,23 +2623,50 @@
new_test_ext().execute_with(|| {
let origin1 = Origin::signed(1);
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
- assert_ok!(TemplateModule::set_transfers_enabled_flag(origin1, 1, true));
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
+ assert_ok!(TemplateModule::set_transfers_enabled_flag(
+ origin1,
+ collection_id,
+ true
+ ));
let data = default_nft_data();
create_test_item(collection_id, &data.into());
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 1
+ );
+ assert_eq!(
+ <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
+ true
+ );
let origin1 = Origin::signed(1);
// default scenario
- assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));
- assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));
- assert_eq!(TemplateModule::balance_count(1, 1), 0);
- assert_eq!(TemplateModule::balance_count(1, 2), 1);
-
- assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
+ assert_ok!(TemplateModule::transfer(
+ origin1,
+ account(2),
+ collection_id,
+ TokenId(1),
+ 1
+ ));
+ assert_eq!(
+ <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
+ false
+ );
+ assert_eq!(
+ <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),
+ true
+ );
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 0
+ );
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),
+ 1
+ );
});
}
@@ -2114,7 +2675,8 @@
new_test_ext().execute_with(|| {
// default_limits();
- let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);
+ let collection_id =
+ create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -2137,7 +2699,7 @@
));
let data = default_nft_data();
- create_test_item(1, &data.into());
+ create_test_item(collection_id, &data.into());
assert_ok!(TemplateModule::set_meta_update_permission_flag(
origin2.clone(),
@@ -2149,12 +2711,12 @@
assert_ok!(TemplateModule::set_variable_meta_data(
origin1,
collection_id,
- 1,
+ TokenId(1),
variable_data.clone()
));
assert_eq!(
- TemplateModule::nft_item_id(collection_id, 1)
+ <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))
.unwrap()
.variable_data,
variable_data
@@ -2167,7 +2729,8 @@
new_test_ext().execute_with(|| {
// default_limits();
- let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);
+ let collection_id =
+ create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -2184,7 +2747,7 @@
));
let data = default_nft_data();
- create_test_item(1, &data.into());
+ create_test_item(collection_id, &data.into());
assert_ok!(TemplateModule::set_meta_update_permission_flag(
origin2.clone(),
@@ -2197,10 +2760,11 @@
TemplateModule::set_variable_meta_data(
origin1,
collection_id,
- 1,
+ TokenId(1),
variable_data.clone()
- ),
- Error::<Test>::NoPermission
+ )
+ .map_err(|e| e.error),
+ CommonError::<Test>::NoPermission
);
});
}
@@ -2210,7 +2774,8 @@
new_test_ext().execute_with(|| {
// default_limits();
- let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);
+ let collection_id =
+ create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));
let origin2 = Origin::signed(2);
@@ -2225,7 +2790,7 @@
collection_id,
MetaUpdatePermission::Admin
),
- Error::<Test>::MetadataFlagFrozen
+ CommonError::<Test>::MetadataFlagFrozen
);
});
}
@@ -2235,11 +2800,12 @@
new_test_ext().execute_with(|| {
// default_limits();
- let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);
+ let collection_id =
+ create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
let origin1 = Origin::signed(1);
let data = default_nft_data();
- create_test_item(1, &data.into());
+ create_test_item(collection_id, &data.into());
assert_ok!(TemplateModule::set_meta_update_permission_flag(
origin1.clone(),
@@ -2252,10 +2818,11 @@
TemplateModule::set_variable_meta_data(
origin1.clone(),
collection_id,
- 1,
+ TokenId(1),
variable_data.clone()
- ),
- Error::<Test>::MetadataUpdateDenied
+ )
+ .map_err(|e| e.error),
+ CommonError::<Test>::NoPermission
);
});
}
@@ -2265,27 +2832,47 @@
new_test_ext().execute_with(|| {
let origin1 = Origin::signed(1);
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
assert_ok!(TemplateModule::set_transfers_enabled_flag(
- origin1, 1, false
+ origin1,
+ collection_id,
+ false
));
let data = default_nft_data();
create_test_item(collection_id, &data.into());
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 1
+ );
+ assert_eq!(
+ <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
+ true
+ );
let origin1 = Origin::signed(1);
// default scenario
assert_noop!(
- TemplateModule::transfer(origin1, account(2), 1, 1, 1000),
- Error::<Test>::TransferNotAllowed
+ TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)
+ .map_err(|e| e.error),
+ CommonError::<Test>::TransferNotAllowed
+ );
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
+ 1
);
- assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(1));
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::balance_count(1, 2), 0);
-
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ assert_eq!(
+ <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),
+ 0
+ );
+ assert_eq!(
+ <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
+ true
+ );
+ assert_eq!(
+ <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),
+ false
+ );
});
}
primitives/data-structs/src/lib.rsdiffbeforeafterboth--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -29,10 +29,14 @@
pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;
pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;
pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;
-pub const MAX_TOKEN_OWNERSHIP: u32 = 10_000_000;
+pub const MAX_TOKEN_OWNERSHIP: u32 = if cfg!(not(feature = "limit-testing")) {
+ 10_000_000
+} else {
+ 10
+};
pub const COLLECTION_NUMBER_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {
- 100000
+ 100_000
} else {
10
};
@@ -44,7 +48,7 @@
pub const COLLECTION_ADMINS_LIMIT: u32 = 5;
pub const COLLECTION_TOKEN_LIMIT: u32 = u32::MAX;
pub const ACCOUNT_TOKEN_OWNERSHIP_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {
- 1000000
+ 1_000_000
} else {
10
};