git.delta.rocks / unique-network / refs/commits / 6c1cc7ee4bff

difftreelog

Merge pull request #242 from UniqueNetwork/feature/fix_unit_tests

kozyrevdev2021-11-25parents: #3def18a #5c2c651.patch.diff
in: master
Fix unit tests

13 files changed

modifiedCargo.lockdiffbeforeafterboth
4938 "winapi 0.3.9",4938 "winapi 0.3.9",
4939]4939]
4940
4941[[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]
5016
5017[[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]
5031
5032[[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]
5076
5077[[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]
51504940
5151[[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]
55955385
5853 "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]
58655655
5866[[package]]5656[[package]]
59565746
5957[[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]
6058
6059[[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]
60955848
6096[[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]
61285881
6129[[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]
62275980
6228[[package]]5981[[package]]
6468 "sp-std",6221 "sp-std",
6469]6222]
6223
6224[[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]
64706260
6471[[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]
1172711517
11785source = "registry+https://github.com/rust-lang/crates.io-index"11575source = "registry+https://github.com/rust-lang/crates.io-index"
11786checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"11576checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
11577
11578[[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]
11653
11654[[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]
11698
11699[[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]
1178711772
11788[[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"
11818
11819[[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]
1183311833
11834[[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]
1185411854
11855[[package]]11855[[package]]
modifiedpallets/common/src/account.rsdiffbeforeafterboth
7use pallet_evm::AddressMapping;7use pallet_evm::AddressMapping;
8use sp_std::vec::Vec;8use sp_std::vec::Vec;
9use sp_std::clone::Clone;9use sp_std::clone::Clone;
10use up_evm_mapping::EvmBackwardsAddressMapping;10pub use up_evm_mapping::EvmBackwardsAddressMapping;
1111
12pub trait CrossAccountId<AccountId>:12pub trait CrossAccountId<AccountId>:
13 Encode + EncodeLike + Decode + TypeInfo + Clone + PartialEq + Ord + core::fmt::Debug + Default13 Encode + EncodeLike + Decode + TypeInfo + Clone + PartialEq + Ord + core::fmt::Debug + Default
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
273 TotalCollectionsLimitExceeded,273 TotalCollectionsLimitExceeded,
274 /// variable_data exceeded data limit.274 /// variable_data exceeded data limit.
275 TokenVariableDataLimitExceeded,275 TokenVariableDataLimitExceeded,
276 /// Exceeded max admin amount276 /// Exceeded max admin count
277 CollectionAdminAmountExceeded,277 CollectionAdminCountExceeded,
278278
279 /// Collection settings not allowing items transferring279 /// Collection settings not allowing items transferring
280 TransferNotAllowed,280 TransferNotAllowed,
506 if admin {506 if admin {
507 let amount = amount507 let amount = amount
508 .checked_add(1)508 .checked_add(1)
509 .ok_or(<Error<T>>::CollectionAdminAmountExceeded)?;509 .ok_or(<Error<T>>::CollectionAdminCountExceeded)?;
510 ensure!(510 ensure!(
511 amount <= Self::collection_admins_limit(),511 amount <= Self::collection_admins_limit(),
512 <Error<T>>::CollectionAdminAmountExceeded,512 <Error<T>>::CollectionAdminCountExceeded,
513 );513 );
514514
515 // =========515 // =========
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
182 _token: TokenId,182 _token: TokenId,
183 _data: Vec<u8>,183 _data: Vec<u8>,
184 ) -> DispatchResultWithPostInfo {184 ) -> DispatchResultWithPostInfo {
185 fail!(<Error<T>>::FungibleItemsHaveData)185 fail!(<Error<T>>::FungibleItemsDontHaveData)
186 }186 }
187187
188 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {188 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
35 /// Not default id passed as TokenId argument35 /// Not default id passed as TokenId argument
36 FungibleItemsHaveNoId,36 FungibleItemsHaveNoId,
37 /// Tried to set data for fungible item37 /// Tried to set data for fungible item
38 FungibleItemsHaveData,38 FungibleItemsDontHaveData,
39 }39 }
4040
41 #[pallet::config]41 #[pallet::config]
48 pub struct Pallet<T>(_);48 pub struct Pallet<T>(_);
4949
50 #[pallet::storage]50 #[pallet::storage]
51 pub(super) type TotalSupply<T: Config> =51 pub type TotalSupply<T: Config> =
52 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u128, QueryKind = ValueQuery>;52 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u128, QueryKind = ValueQuery>;
5353
54 #[pallet::storage]54 #[pallet::storage]
62 >;62 >;
6363
64 #[pallet::storage]64 #[pallet::storage]
65 pub(super) type Allowance<T: Config> = StorageNMap<65 pub type Allowance<T: Config> = StorageNMap<
66 Key = (66 Key = (
67 Key<Twox64Concat, CollectionId>,67 Key<Twox64Concat, CollectionId>,
68 Key<Blake2_128, T::CrossAccountId>,68 Key<Blake2_128, T::CrossAccountId>,
modifiedpallets/inflation/src/lib.rsdiffbeforeafterboth
46pub type BalanceOf<T> =46pub type BalanceOf<T> =
47 <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;47 <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
4848
49// pub const YEAR: u32 = 5_259_600; // 6-second block
49pub const YEAR: u32 = 5_259_600;50pub const YEAR: u32 = 2_629_800; // 12-second block
50pub const TOTAL_YEARS_UNTIL_FLAT: u32 = 9;51pub const TOTAL_YEARS_UNTIL_FLAT: u32 = 9;
51pub const START_INFLATION_PERCENT: u32 = 10;52pub const START_INFLATION_PERCENT: u32 = 10;
52pub const END_INFLATION_PERCENT: u32 = 4;53pub const END_INFLATION_PERCENT: u32 = 4;
modifiedpallets/inflation/src/tests.rsdiffbeforeafterboth
18type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;18type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
19type Block = frame_system::mocking::MockBlock<Test>;19type Block = frame_system::mocking::MockBlock<Test>;
2020
21const YEAR: u64 = 5_259_600;21const YEAR: u64 = 2_629_800;
2222
23parameter_types! {23parameter_types! {
24 pub const ExistentialDeposit: u64 = 1;24 pub const ExistentialDeposit: u64 = 1;
112 // first inflation deposit should be equal to BlockInflation112 // first inflation deposit should be equal to BlockInflation
113 Inflation::on_initialize(1);113 Inflation::on_initialize(1);
114114
115 // SBP M2 review: Verify expected block inflation for year 1115 // Expected 100-block inflation for year 1 is 100 * 100_000_000 / YEAR = 3803
116 assert_eq!(Inflation::block_inflation(), 1901);116 assert_eq!(Inflation::block_inflation(), 3803);
117 assert_eq!(117 assert_eq!(
118 Balances::free_balance(1234) - initial_issuance,118 Balances::free_balance(1234) - initial_issuance,
119 Inflation::block_inflation()119 Inflation::block_inflation()
158 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);158 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
159 assert_eq!(Balances::free_balance(1234), initial_issuance);159 assert_eq!(Balances::free_balance(1234), initial_issuance);
160 Inflation::on_initialize(1);160 Inflation::on_initialize(1);
161 let block_inflation_year_0 = Inflation::block_inflation();
162161
163 // SBP M2 review: go through all the block inflations for year 1,162 // Go through all the block inflations for year 1,
164 // total issuance will be updated accordingly163 // total issuance will be updated accordingly
165 for block in (100..YEAR).step_by(100) {164 for block in (100..YEAR).step_by(100) {
166 Inflation::on_initialize(block);165 Inflation::on_initialize(block);
167 }166 }
168 assert_eq!(167 assert_eq!(
169 initial_issuance + (1901 * (YEAR / 100)),168 initial_issuance + (3803 * (YEAR / 100)),
170 <Balances as Currency<_>>::total_issuance()169 <Balances as Currency<_>>::total_issuance()
171 );170 );
172171
173 Inflation::on_initialize(YEAR);172 Inflation::on_initialize(YEAR);
174 let block_inflation_year_1 = Inflation::block_inflation();173 let block_inflation_year_1 = Inflation::block_inflation();
175 // SBP M2 review: Verify expected block inflation for year 2174 // Expected 100-block inflation for year 2: 100 * 9.33% * initial issuance * 110% / YEAR = 3904
176 assert_eq!(block_inflation_year_1, 1952);175 assert_eq!(block_inflation_year_1, 3904);
177
178 // SBP M2 review: this is actually not true
179 // Assert that year 1 inflation is less than year 0
180 // assert!(block_inflation_year_0 > block_inflation_year_1);
181 });176 });
182}177}
183178
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
58 }58 }
5959
60 #[pallet::pallet]60 #[pallet::pallet]
61 #[pallet::generate_store(pub trait Store)]61 #[pallet::generate_store(pub(super) trait Store)]
62 pub struct Pallet<T>(_);62 pub struct Pallet<T>(_);
6363
64 #[pallet::storage]64 #[pallet::storage]
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
54 }54 }
5555
56 #[pallet::pallet]56 #[pallet::pallet]
57 #[pallet::generate_store(pub trait Store)]57 #[pallet::generate_store(pub(super) trait Store)]
58 pub struct Pallet<T>(_);58 pub struct Pallet<T>(_);
5959
60 #[pallet::storage]60 #[pallet::storage]
modifiedpallets/scheduler/src/lib.rsdiffbeforeafterboth
738 use super::*;738 use super::*;
739739
740 use frame_support::{740 use frame_support::{
741 Hashable, assert_err, assert_noop, assert_ok, ord_parameter_types, parameter_types,741 ord_parameter_types, parameter_types, traits::Contains, weights::constants::RocksDbWeight,
742 traits::{Contains, OnFinalize, OnInitialize},
743 weights::constants::RocksDbWeight,
744 };742 };
745 use sp_core::H256;743 use sp_core::H256;
749 traits::{BlakeTwo256, IdentityLookup},747 traits::{BlakeTwo256, IdentityLookup},
750 };748 };
751 use frame_system::{EnsureOneOf, EnsureRoot, EnsureSignedBy};749 use frame_system::{EnsureOneOf, EnsureRoot, EnsureSignedBy};
752 use substrate_test_utils::assert_eq_uvec;
753 use crate as scheduler;750 use crate as scheduler;
754751
755 mod logger {752 mod logger {
759 thread_local! {756 thread_local! {
760 static LOG: RefCell<Vec<(OriginCaller, u32)>> = RefCell::new(Vec::new());757 static LOG: RefCell<Vec<(OriginCaller, u32)>> = RefCell::new(Vec::new());
761 }758 }
762 pub fn log() -> Vec<(OriginCaller, u32)> {
763 LOG.with(|log| log.borrow().clone())
764 }
765 pub trait Config: system::Config {759 pub trait Config: system::Config {
766 type Event: From<Event> + Into<<Self as system::Config>::Event>;760 type Event: From<Event> + Into<<Self as system::Config>::Event>;
767 }761 }
873 type SponsorshipHandler = ();867 type SponsorshipHandler = ();
874 }868 }
875
876 pub fn new_test_ext() -> sp_io::TestExternalities {
877 let t = system::GenesisConfig::default()
878 .build_storage::<Test>()
879 .unwrap();
880 t.into()
881 }
882
883 fn run_to_block(n: u64) {
884 while System::block_number() < n {
885 Scheduler::on_finalize(System::block_number());
886 System::set_block_number(System::block_number() + 1);
887 Scheduler::on_initialize(System::block_number());
888 }
889 }
890
891 fn root() -> OriginCaller {
892 system::RawOrigin::Root.into()
893 }
894}869}
895870
modifiedpallets/unique/src/mock.rsdiffbeforeafterboth
10use pallet_transaction_payment::{CurrencyAdapter};10use pallet_transaction_payment::{CurrencyAdapter};
11use frame_system as system;11use frame_system as system;
12use pallet_evm::AddressMapping;12use pallet_evm::AddressMapping;
13use crate::{EvmBackwardsAddressMapping, CrossAccountId};13use pallet_common::account::{EvmBackwardsAddressMapping, CrossAccountId};
14use codec::{Encode, Decode};14use codec::{Encode, Decode};
15use scale_info::TypeInfo;15use scale_info::TypeInfo;
1616
27 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},27 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
28 TemplateModule: pallet_template::{Pallet, Call, Storage},28 TemplateModule: pallet_template::{Pallet, Call, Storage},
29 Balances: pallet_balances::{Pallet, Call, Storage},29 Balances: pallet_balances::{Pallet, Call, Storage},
30 Common: pallet_common::{Pallet, Storage, Event<T>},
31 Fungible: pallet_fungible::{Pallet, Storage},
32 Refungible: pallet_refungible::{Pallet, Storage},
33 Nonfungible: pallet_nonfungible::{Pallet, Storage},
30 }34 }
31);35);
3236
124#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo)]128#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo)]
125pub struct TestCrossAccountId(u64, sp_core::H160);129pub struct TestCrossAccountId(u64, sp_core::H160);
126impl CrossAccountId<u64> for TestCrossAccountId {130impl CrossAccountId<u64> for TestCrossAccountId {
131 fn as_sub(&self) -> &u64 {
132 &self.0
133 }
134 fn as_eth(&self) -> &sp_core::H160 {
135 &self.1
136 }
127 fn from_sub(sub: u64) -> Self {137 fn from_sub(sub: u64) -> Self {
128 let mut eth = [0; 20];138 let mut eth = [0; 20];
129 eth[12..20].copy_from_slice(&sub.to_be_bytes());139 eth[12..20].copy_from_slice(&sub.to_be_bytes());
130 Self(sub, sp_core::H160(eth))140 Self(sub, sp_core::H160(eth))
131 }141 }
132 fn as_sub(&self) -> &u64 {
133 &self.0
134 }
135 fn from_eth(eth: sp_core::H160) -> Self {142 fn from_eth(eth: sp_core::H160) -> Self {
136 let mut sub_raw = [0; 8];143 let mut sub_raw = [0; 8];
137 sub_raw.copy_from_slice(&eth.0[0..8]);144 sub_raw.copy_from_slice(&eth.0[0..8]);
138 let sub = u64::from_be_bytes(sub_raw);145 let sub = u64::from_be_bytes(sub_raw);
139 Self(sub, eth)146 Self(sub, eth)
140 }147 }
141 fn as_eth(&self) -> &sp_core::H160 {148 fn conv_eq(&self, other: &Self) -> bool {
142 &self.1149 self.as_sub() == other.as_sub()
143 }150 }
144}151}
152
153impl Default for TestCrossAccountId {
154 fn default() -> Self {
155 Self::from_sub(0)
156 }
157}
145158
146pub struct TestEtheremTransactionSender;159pub struct TestEtheremTransactionSender;
147impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {160impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {
157 type EthereumTransactionSender = TestEtheremTransactionSender;170 type EthereumTransactionSender = TestEtheremTransactionSender;
158}171}
159172
160impl pallet_template::Config for Test {173impl pallet_common::Config for Test {
161 type Event = ();174 type Event = ();
162 type WeightInfo = ();175 type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;
163 type CollectionCreationPrice = CollectionCreationPrice;176 type EvmAddressMapping = TestEvmAddressMapping;
164 type Currency = pallet_balances::Pallet<Test>;177 type CrossAccountId = TestCrossAccountId;
178
165 type TreasuryAccountId = TreasuryAccountId;179 type Currency = Balances;
166 type EvmAddressMapping = TestEvmAddressMapping;180 type CollectionCreationPrice = CollectionCreationPrice;
167 type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;181 type TreasuryAccountId = TreasuryAccountId;
168 type CrossAccountId = TestCrossAccountId;
169}182}
183
184impl pallet_fungible::Config for Test {
185 type WeightInfo = ();
186}
187impl pallet_refungible::Config for Test {
188 type WeightInfo = ();
189}
190impl pallet_nonfungible::Config for Test {
191 type WeightInfo = ();
192}
193
194impl pallet_template::Config for Test {
195 type WeightInfo = ();
196}
170197
171// Build genesis storage according to the mock runtime.198// Build genesis storage according to the mock runtime.
172pub fn new_test_ext() -> sp_io::TestExternalities {199pub fn new_test_ext() -> sp_io::TestExternalities {
modifiedpallets/unique/src/tests.rsdiffbeforeafterboth
1// Tests to be written here1// Tests to be written here
2use super::*;2use super::*;
3use crate::mock::*;3use crate::mock::*;
4use crate::{AccessMode, CollectionMode, Ownership, CreateItemData};4use crate::{AccessMode, CollectionMode};
5use up_data_structs::{5use up_data_structs::{
6 CreateNftData, CreateFungibleData, CreateReFungibleData, CollectionId, TokenId,6 COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData,
7 CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, MetaUpdatePermission,
7 MAX_DECIMAL_POINTS,8 TokenId,
8};9};
9use frame_support::{assert_noop, assert_ok};10use frame_support::{assert_noop, assert_ok};
10use sp_std::convert::TryInto;11use sp_std::convert::TryInto;
49 let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();50 let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
50 let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();51 let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
51 let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();52 let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();
52 assert_eq!(TemplateModule::collection_id(id).unwrap().owner, owner);
53 assert_eq!(53 assert_eq!(
54 TemplateModule::collection_id(id).unwrap().name,54 <pallet_common::CollectionById<Test>>::get(id)
55 .unwrap()
56 .owner,
57 owner
58 );
59 assert_eq!(
60 <pallet_common::CollectionById<Test>>::get(id).unwrap().name,
55 saved_col_name61 saved_col_name
56 );62 );
57 assert_eq!(TemplateModule::collection_id(id).unwrap().mode, *mode);
58 assert_eq!(63 assert_eq!(
59 TemplateModule::collection_id(id).unwrap().description,64 <pallet_common::CollectionById<Test>>::get(id).unwrap().mode,
65 *mode
66 );
67 assert_eq!(
68 <pallet_common::CollectionById<Test>>::get(id)
69 .unwrap()
70 .description,
60 saved_description71 saved_description
61 );72 );
62 assert_eq!(73 assert_eq!(
63 TemplateModule::collection_id(id).unwrap().token_prefix,74 <pallet_common::CollectionById<Test>>::get(id)
75 .unwrap()
76 .token_prefix,
64 saved_prefix77 saved_prefix
65 );78 );
66 id79 id
91fn set_version_schema() {104fn set_version_schema() {
92 new_test_ext().execute_with(|| {105 new_test_ext().execute_with(|| {
93 let origin1 = Origin::signed(1);106 let origin1 = Origin::signed(1);
94 let collection_id = create_test_collection(&CollectionMode::NFT, 1);107 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
95108
96 assert_ok!(TemplateModule::set_schema_version(109 assert_ok!(TemplateModule::set_schema_version(
97 origin1,110 origin1,
98 collection_id,111 collection_id,
99 SchemaVersion::Unique112 SchemaVersion::Unique
100 ));113 ));
101 assert_eq!(114 assert_eq!(
102 TemplateModule::collection_id(collection_id)115 <pallet_common::CollectionById<Test>>::get(collection_id)
103 .unwrap()116 .unwrap()
104 .schema_version,117 .schema_version,
105 SchemaVersion::Unique118 SchemaVersion::Unique
131#[test]144#[test]
132fn create_nft_item() {145fn create_nft_item() {
133 new_test_ext().execute_with(|| {146 new_test_ext().execute_with(|| {
134 let collection_id = create_test_collection(&CollectionMode::NFT, 1);147 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
135148
136 let data = default_nft_data();149 let data = default_nft_data();
137 create_test_item(collection_id, &data.clone().into());150 create_test_item(collection_id, &data.clone().into());
151
138 let item = TemplateModule::nft_item_id(collection_id, 1).unwrap();152 let item = <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1)).unwrap();
139 assert_eq!(item.const_data, data.const_data.into_inner());153 assert_eq!(item.const_data, data.const_data.into_inner());
140 assert_eq!(item.variable_data, data.variable_data.into_inner());154 assert_eq!(item.variable_data, data.variable_data.into_inner());
141 });155 });
146#[test]160#[test]
147fn create_nft_multiple_items() {161fn create_nft_multiple_items() {
148 new_test_ext().execute_with(|| {162 new_test_ext().execute_with(|| {
149 create_test_collection(&CollectionMode::NFT, 1);163 create_test_collection(&CollectionMode::NFT, CollectionId(1));
150164
151 let origin1 = Origin::signed(1);165 let origin1 = Origin::signed(1);
152166
153 let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];167 let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];
154168
155 assert_ok!(TemplateModule::create_multiple_items(169 assert_ok!(TemplateModule::create_multiple_items(
156 origin1,170 origin1,
157 1,171 CollectionId(1),
158 account(1),172 account(1),
159 items_data173 items_data
160 .clone()174 .clone()
163 .collect()177 .collect()
164 ));178 ));
165 for (index, data) in items_data.into_iter().enumerate() {179 for (index, data) in items_data.into_iter().enumerate() {
166 let item = TemplateModule::nft_item_id(1, (index + 1) as TokenId).unwrap();180 let item = <pallet_nonfungible::TokenData<Test>>::get((
181 CollectionId(1),
182 TokenId((index + 1) as u32),
183 ))
184 .unwrap();
167 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());185 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());
168 assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());186 assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());
169 }187 }
173#[test]191#[test]
174fn create_refungible_item() {192fn create_refungible_item() {
175 new_test_ext().execute_with(|| {193 new_test_ext().execute_with(|| {
176 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);194 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
177195
178 let data = default_re_fungible_data();196 let data = default_re_fungible_data();
179 create_test_item(collection_id, &data.clone().into());197 create_test_item(collection_id, &data.clone().into());
180 let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();198 let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));
199 let balance =
200 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));
181 assert_eq!(item.const_data, data.const_data.into_inner());201 assert_eq!(item.const_data, data.const_data.into_inner());
182 assert_eq!(item.variable_data, data.variable_data.into_inner());202 assert_eq!(item.variable_data, data.variable_data.into_inner());
183 assert_eq!(203 assert_eq!(balance, 1023);
184 item.owner[0],
185 Ownership {
186 owner: account(1),
187 fraction: 1023
188 }
189 );
190 });204 });
191}205}
192206
193#[test]207#[test]
194fn create_multiple_refungible_items() {208fn create_multiple_refungible_items() {
195 new_test_ext().execute_with(|| {209 new_test_ext().execute_with(|| {
196 create_test_collection(&CollectionMode::ReFungible, 1);210 create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
197211
198 let origin1 = Origin::signed(1);212 let origin1 = Origin::signed(1);
199213
205219
206 assert_ok!(TemplateModule::create_multiple_items(220 assert_ok!(TemplateModule::create_multiple_items(
207 origin1,221 origin1,
208 1,222 CollectionId(1),
209 account(1),223 account(1),
210 items_data224 items_data
211 .clone()225 .clone()
214 .collect()228 .collect()
215 ));229 ));
216 for (index, data) in items_data.into_iter().enumerate() {230 for (index, data) in items_data.into_iter().enumerate() {
217 let item = TemplateModule::refungible_item_id(1, (index + 1) as TokenId).unwrap();231 let item = <pallet_refungible::TokenData<Test>>::get((
232 CollectionId(1),
233 TokenId((index + 1) as u32),
234 ));
235 let balance =
236 <pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));
218 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());237 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());
219 assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());238 assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());
220 assert_eq!(239 assert_eq!(balance, 1023);
221 item.owner[0],
222 Ownership {
223 owner: account(1),
224 fraction: 1023
225 }
226 );
227 }240 }
228 });241 });
229}242}
230243
231#[test]244#[test]
232fn create_fungible_item() {245fn create_fungible_item() {
233 new_test_ext().execute_with(|| {246 new_test_ext().execute_with(|| {
234 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);247 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
235248
236 let data = default_fungible_data();249 let data = default_fungible_data();
237 create_test_item(collection_id, &data.into());250 create_test_item(collection_id, &data.into());
238251
239 assert_eq!(TemplateModule::fungible_item_id(collection_id, 1).value, 5);252 assert_eq!(
253 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),
254 5
255 );
240 });256 });
241}257}
242258
245// new_test_ext().execute_with(|| {261// new_test_ext().execute_with(|| {
246// default_limits();262// default_limits();
247263
248// create_test_collection(&CollectionMode::Fungible(3), 1);264// create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
249265
250// let origin1 = Origin::signed(1);266// let origin1 = Origin::signed(1);
251267
269#[test]285#[test]
270fn transfer_fungible_item() {286fn transfer_fungible_item() {
271 new_test_ext().execute_with(|| {287 new_test_ext().execute_with(|| {
272 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);288 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
273289
274 let origin1 = Origin::signed(1);290 let origin1 = Origin::signed(1);
275 let origin2 = Origin::signed(2);291 let origin2 = Origin::signed(2);
276292
277 let data = default_fungible_data();293 let data = default_fungible_data();
278 create_test_item(collection_id, &data.into());294 create_test_item(collection_id, &data.into());
279295
280 assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 5);296 assert_eq!(
281 assert_eq!(TemplateModule::balance_count(1, 1), 5);297 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),
298 5
299 );
282300
283 // change owner scenario301 // change owner scenario
284 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 5));302 assert_ok!(TemplateModule::transfer(
303 origin1,
304 account(2),
305 CollectionId(1),
306 TokenId(0),
307 5
308 ));
285 assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 0);309 assert_eq!(
310 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),
286 assert_eq!(TemplateModule::balance_count(1, 1), 0);311 0
287 assert_eq!(TemplateModule::balance_count(1, 2), 5);312 );
288313
289 // split item scenario314 // split item scenario
290 assert_ok!(TemplateModule::transfer(315 assert_ok!(TemplateModule::transfer(
291 origin2.clone(),316 origin2.clone(),
292 account(3),317 account(3),
293 1,318 CollectionId(1),
294 1,319 TokenId(0),
295 3320 3
296 ));321 ));
297 assert_eq!(TemplateModule::balance_count(1, 2), 2);
298 assert_eq!(TemplateModule::balance_count(1, 3), 3);
299322
300 // split item and new owner has account scenario323 // split item and new owner has account scenario
301 assert_ok!(TemplateModule::transfer(origin2, account(3), 1, 1, 1));324 assert_ok!(TemplateModule::transfer(
325 origin2,
326 account(3),
302 assert_eq!(TemplateModule::fungible_item_id(1, 2).value, 1);327 CollectionId(1),
303 assert_eq!(TemplateModule::fungible_item_id(1, 3).value, 4);328 TokenId(0),
329 1
330 ));
304 assert_eq!(TemplateModule::balance_count(1, 2), 1);331 assert_eq!(
332 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))),
333 1
334 );
305 assert_eq!(TemplateModule::balance_count(1, 3), 4);335 assert_eq!(
336 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))),
337 4
338 );
306 });339 });
307}340}
308341
309#[test]342#[test]
310fn transfer_refungible_item() {343fn transfer_refungible_item() {
311 new_test_ext().execute_with(|| {344 new_test_ext().execute_with(|| {
312 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);345 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
313346
347 // Create RFT 1 in 1023 pieces for account 1
314 let data = default_re_fungible_data();348 let data = default_re_fungible_data();
315 create_test_item(collection_id, &data.clone().into());349 create_test_item(collection_id, &data.clone().into());
350 let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));
351 assert_eq!(item.const_data, data.const_data.into_inner());
352 assert_eq!(item.variable_data, data.variable_data.into_inner());
353 assert_eq!(
354 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),
355 1
356 );
357 assert_eq!(
358 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),
359 1023
360 );
361 assert_eq!(
362 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
363 true
364 );
316365
366 // Account 1 transfers all 1023 pieces of RFT 1 to account 2
317 let origin1 = Origin::signed(1);367 let origin1 = Origin::signed(1);
318 let origin2 = Origin::signed(2);368 let origin2 = Origin::signed(2);
319 {369 assert_ok!(TemplateModule::transfer(
320 let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();
321 assert_eq!(item.const_data, data.const_data.into_inner());370 origin1,
322 assert_eq!(item.variable_data, data.variable_data.into_inner());371 account(2),
323 assert_eq!(
324 item.owner[0],
325 Ownership {372 CollectionId(1),
326 owner: account(1),
327 fraction: 1023373 TokenId(1),
328 }
329 );
330 }
331 assert_eq!(TemplateModule::balance_count(1, 1), 1023);
332 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);374 1023
333
334 // change owner scenario
335 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1023));375 ));
336 assert_eq!(376 assert_eq!(
337 TemplateModule::refungible_item_id(1, 1).unwrap().owner[0],377 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),
338 Ownership {
339 owner: account(2),
340 fraction: 1023378 1023
341 }
342 );379 );
343 assert_eq!(TemplateModule::balance_count(1, 1), 0);380 assert_eq!(
381 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),
382 0
383 );
344 assert_eq!(TemplateModule::balance_count(1, 2), 1023);384 assert_eq!(
385 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),
386 1
387 );
345 // assert_eq!(TemplateModule::address_tokens(1, 1), []);388 assert_eq!(
389 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
390 false
391 );
346 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);392 assert_eq!(
393 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),
394 true
395 );
347396
348 // split item scenario397 // Account 2 transfers 500 pieces of RFT 1 to account 3
349 assert_ok!(TemplateModule::transfer(398 assert_ok!(TemplateModule::transfer(
350 origin2.clone(),399 origin2.clone(),
351 account(3),400 account(3),
352 1,401 CollectionId(1),
353 1,402 TokenId(1),
354 500403 500
355 ));404 ));
356 {405 assert_eq!(
357 let item = TemplateModule::refungible_item_id(1, 1).unwrap();406 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),
358 assert_eq!(
359 item.owner[0],
360 Ownership {
361 owner: account(2),
362 fraction: 523407 523
363 }408 );
364 );
365 assert_eq!(409 assert_eq!(
366 item.owner[1],410 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),
367 Ownership {
368 owner: account(3),
369 fraction: 500411 500
370 }412 );
371 );
372 }413 assert_eq!(
373 assert_eq!(TemplateModule::balance_count(1, 2), 523);414 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),
415 1
416 );
374 assert_eq!(TemplateModule::balance_count(1, 3), 500);417 assert_eq!(
418 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),
419 1
420 );
375 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);421 assert_eq!(
422 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),
423 true
424 );
376 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);425 assert_eq!(
426 <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),
427 true
428 );
377429
378 // split item and new owner has account scenario430 // Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance
379 assert_ok!(TemplateModule::transfer(origin2, account(3), 1, 1, 200));431 assert_ok!(TemplateModule::transfer(
432 origin2,
433 account(3),
380 {434 CollectionId(1),
381 let item = TemplateModule::refungible_item_id(1, 1).unwrap();
382 assert_eq!(435 TokenId(1),
383 item.owner[0],436 200
384 Ownership {437 ));
438 assert_eq!(
385 owner: account(2),439 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),
386 fraction: 323440 323
387 }441 );
388 );
389 assert_eq!(442 assert_eq!(
390 item.owner[1],443 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),
391 Ownership {
392 owner: account(3),
393 fraction: 700444 700
394 }445 );
395 );
396 }446 assert_eq!(
397 assert_eq!(TemplateModule::balance_count(1, 2), 323);447 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),
448 1
449 );
398 assert_eq!(TemplateModule::balance_count(1, 3), 700);450 assert_eq!(
451 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),
452 1
453 );
399 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);454 assert_eq!(
455 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),
456 true
457 );
400 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);458 assert_eq!(
459 <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),
460 true
461 );
401 });462 });
402}463}
403464
404#[test]465#[test]
405fn transfer_nft_item() {466fn transfer_nft_item() {
406 new_test_ext().execute_with(|| {467 new_test_ext().execute_with(|| {
407 let collection_id = create_test_collection(&CollectionMode::NFT, 1);468 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
408469
409 let data = default_nft_data();470 let data = default_nft_data();
410 create_test_item(collection_id, &data.into());471 create_test_item(collection_id, &data.into());
411 assert_eq!(TemplateModule::balance_count(1, 1), 1);472 assert_eq!(
473 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
474 1
475 );
412 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);476 assert_eq!(
477 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
478 true
479 );
413480
414 let origin1 = Origin::signed(1);481 let origin1 = Origin::signed(1);
415 // default scenario482 // default scenario
416 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));483 assert_ok!(TemplateModule::transfer(
484 origin1,
485 account(2),
486 CollectionId(1),
487 TokenId(1),
488 1
489 ));
417 assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));490 assert_eq!(
491 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
418 assert_eq!(TemplateModule::balance_count(1, 1), 0);492 0
493 );
419 assert_eq!(TemplateModule::balance_count(1, 2), 1);494 assert_eq!(
495 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),
496 1
497 );
420 // assert_eq!(TemplateModule::address_tokens(1, 1), []);498 assert_eq!(
499 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
500 false
501 );
421 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);502 assert_eq!(
503 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),
504 true
505 );
422 });506 });
423}507}
424508
425#[test]509#[test]
510fn transfer_nft_item_wrong_value() {
511 new_test_ext().execute_with(|| {
512 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
513
514 let data = default_nft_data();
515 create_test_item(collection_id, &data.into());
516 assert_eq!(
517 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
518 1
519 );
520 assert_eq!(
521 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
522 true
523 );
524
525 let origin1 = Origin::signed(1);
526
527 assert_noop!(
528 TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2)
529 .map_err(|e| e.error),
530 <pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount
531 );
532 });
533}
534
535#[test]
536fn transfer_nft_item_zero_value() {
537 new_test_ext().execute_with(|| {
538 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
539
540 let data = default_nft_data();
541 create_test_item(collection_id, &data.into());
542 assert_eq!(
543 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
544 1
545 );
546 assert_eq!(
547 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
548 true
549 );
550
551 let origin1 = Origin::signed(1);
552
553 // Transferring 0 amount works on NFT...
554 assert_ok!(TemplateModule::transfer(
555 origin1,
556 account(2),
557 CollectionId(1),
558 TokenId(1),
559 0
560 ));
561 // ... and results in no transfer
562 assert_eq!(
563 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
564 1
565 );
566 assert_eq!(
567 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
568 true
569 );
570 });
571}
572
573#[test]
426fn nft_approve_and_transfer_from() {574fn nft_approve_and_transfer_from() {
427 new_test_ext().execute_with(|| {575 new_test_ext().execute_with(|| {
428 let collection_id = create_test_collection(&CollectionMode::NFT, 1);576 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
429577
430 let data = default_nft_data();578 let data = default_nft_data();
431 create_test_item(collection_id, &data.into());579 create_test_item(collection_id, &data.into());
432580
433 let origin1 = Origin::signed(1);581 let origin1 = Origin::signed(1);
434 let origin2 = Origin::signed(2);582 let origin2 = Origin::signed(2);
435583
436 assert_eq!(TemplateModule::balance_count(1, 1), 1);584 assert_eq!(
585 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
586 1
587 );
437 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);588 assert_eq!(
589 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
590 true
591 );
438592
439 // neg transfer593 // neg transfer_from
440 assert_noop!(594 assert_noop!(
441 TemplateModule::transfer_from(origin2.clone(), account(1), account(2), 1, 1, 1),595 TemplateModule::transfer_from(
596 origin2.clone(),
597 account(1),
598 account(2),
599 CollectionId(1),
600 TokenId(1),
601 1
602 )
603 .map_err(|e| e.error),
442 Error::<Test>::NoPermission604 CommonError::<Test>::TokenValueNotEnough
443 );605 );
444606
445 // do approve607 // do approve
446 assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 5));608 assert_ok!(TemplateModule::approve(
609 origin1,
610 account(2),
611 CollectionId(1),
612 TokenId(1),
613 1
614 ));
447 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);615 assert_eq!(
616 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
448 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);617 account(2)
618 );
449619
450 assert_ok!(TemplateModule::transfer_from(620 assert_ok!(TemplateModule::transfer_from(
451 origin2,621 origin2,
452 account(1),622 account(1),
453 account(3),623 account(3),
454 1,624 CollectionId(1),
455 1,625 TokenId(1),
456 1626 1
457 ));627 ));
458 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);628 assert!(
629 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()
630 );
459 });631 });
460}632}
461633
462#[test]634#[test]
463fn nft_approve_and_transfer_from_allow_list() {635fn nft_approve_and_transfer_from_allow_list() {
464 new_test_ext().execute_with(|| {636 new_test_ext().execute_with(|| {
465 let collection_id = create_test_collection(&CollectionMode::NFT, 1);637 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
466638
467 let origin1 = Origin::signed(1);639 let origin1 = Origin::signed(1);
468 let origin2 = Origin::signed(2);640 let origin2 = Origin::signed(2);
469641
642 // Create NFT 1 for account 1
470 let data = default_nft_data();643 let data = default_nft_data();
471 create_test_item(collection_id, &data.clone().into());644 create_test_item(collection_id, &data.clone().into());
472
473 assert_eq!(645 assert_eq!(
474 &TemplateModule::nft_item_id(1, 1).unwrap().const_data,646 &<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))
647 .unwrap()
648 .const_data,
475 &data.const_data.into_inner()649 &data.const_data.into_inner()
476 );650 );
477 assert_eq!(TemplateModule::balance_count(1, 1), 1);651 assert_eq!(
652 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
653 1
654 );
478 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);655 assert_eq!(
656 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
657 true
658 );
479659
660 // Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list
480 assert_ok!(TemplateModule::set_mint_permission(661 assert_ok!(TemplateModule::set_mint_permission(
481 origin1.clone(),662 origin1.clone(),
482 1,663 CollectionId(1),
483 true664 true
484 ));665 ));
485 assert_ok!(TemplateModule::set_public_access_mode(666 assert_ok!(TemplateModule::set_public_access_mode(
486 origin1.clone(),667 origin1.clone(),
487 1,668 CollectionId(1),
488 AccessMode::AllowList669 AccessMode::AllowList
489 ));670 ));
490 assert_ok!(TemplateModule::add_to_allow_list(671 assert_ok!(TemplateModule::add_to_allow_list(
491 origin1.clone(),672 origin1.clone(),
492 1,673 CollectionId(1),
493 account(1)674 account(1)
494 ));675 ));
495 assert_ok!(TemplateModule::add_to_allow_list(676 assert_ok!(TemplateModule::add_to_allow_list(
496 origin1.clone(),677 origin1.clone(),
497 1,678 CollectionId(1),
498 account(2)679 account(2)
499 ));680 ));
500 assert_ok!(TemplateModule::add_to_allow_list(681 assert_ok!(TemplateModule::add_to_allow_list(
501 origin1.clone(),682 origin1.clone(),
502 1,683 CollectionId(1),
503 account(3)684 account(3)
504 ));685 ));
505686
506 // do approve687 // Account 1 approves account 2 for NFT 1
507 assert_ok!(TemplateModule::approve(688 assert_ok!(TemplateModule::approve(
508 origin1.clone(),689 origin1.clone(),
509 account(2),690 account(2),
510 1,691 CollectionId(1),
511 1,692 TokenId(1),
512 5693 1
513 ));694 ));
514 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);695 assert_eq!(
696 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
515 assert_ok!(TemplateModule::approve(origin1, account(3), 1, 1, 5));697 account(2)
516 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);698 );
517699
700 // Account 2 transfers NFT 1 from account 1 to account 3
518 assert_ok!(TemplateModule::transfer_from(701 assert_ok!(TemplateModule::transfer_from(
519 origin2,702 origin2,
520 account(1),703 account(1),
521 account(3),704 account(3),
522 1,705 CollectionId(1),
523 1,706 TokenId(1),
524 1707 1
525 ));708 ));
526 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);709 assert!(
710 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()
711 );
527 });712 });
528}713}
529714
530#[test]715#[test]
531fn refungible_approve_and_transfer_from() {716fn refungible_approve_and_transfer_from() {
532 new_test_ext().execute_with(|| {717 new_test_ext().execute_with(|| {
533 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);718 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
534719
535 let origin1 = Origin::signed(1);720 let origin1 = Origin::signed(1);
536 let origin2 = Origin::signed(2);721 let origin2 = Origin::signed(2);
537722
723 // Create RFT 1 in 1023 pieces for account 1
538 let data = default_re_fungible_data();724 let data = default_re_fungible_data();
539 create_test_item(collection_id, &data.into());725 create_test_item(collection_id, &data.into());
540726
541 assert_eq!(TemplateModule::balance_count(1, 1), 1023);727 assert_eq!(
728 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),
729 1
730 );
731 assert_eq!(
732 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),
733 1023
734 );
542 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);735 assert_eq!(
736 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
737 true
738 );
543739
740 // Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list
544 assert_ok!(TemplateModule::set_mint_permission(741 assert_ok!(TemplateModule::set_mint_permission(
545 origin1.clone(),742 origin1.clone(),
546 1,743 CollectionId(1),
547 true744 true
548 ));745 ));
549 assert_ok!(TemplateModule::set_public_access_mode(746 assert_ok!(TemplateModule::set_public_access_mode(
550 origin1.clone(),747 origin1.clone(),
551 1,748 CollectionId(1),
552 AccessMode::AllowList749 AccessMode::AllowList
553 ));750 ));
554 assert_ok!(TemplateModule::add_to_allow_list(751 assert_ok!(TemplateModule::add_to_allow_list(
555 origin1.clone(),752 origin1.clone(),
556 1,753 CollectionId(1),
557 account(1)754 account(1)
558 ));755 ));
559 assert_ok!(TemplateModule::add_to_allow_list(756 assert_ok!(TemplateModule::add_to_allow_list(
560 origin1.clone(),757 origin1.clone(),
561 1,758 CollectionId(1),
562 account(2)759 account(2)
563 ));760 ));
564 assert_ok!(TemplateModule::add_to_allow_list(761 assert_ok!(TemplateModule::add_to_allow_list(
565 origin1.clone(),762 origin1.clone(),
566 1,763 CollectionId(1),
567 account(3)764 account(3)
568 ));765 ));
569766
570 // do approve767 // Account 1 approves account 2 for 1023 pieces of RFT 1
571 assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 1023));768 assert_ok!(TemplateModule::approve(
769 origin1,
770 account(2),
771 CollectionId(1),
772 TokenId(1),
773 1023
774 ));
572 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1023);775 assert_eq!(
776 <pallet_refungible::Allowance<Test>>::get((
777 CollectionId(1),
778 TokenId(1),
779 account(1),
780 account(2)
781 )),
782 1023
783 );
573784
785 // Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3
574 assert_ok!(TemplateModule::transfer_from(786 assert_ok!(TemplateModule::transfer_from(
575 origin2,787 origin2,
576 account(1),788 account(1),
577 account(3),789 account(3),
578 1,790 CollectionId(1),
579 1,791 TokenId(1),
580 100792 100
581 ));793 ));
582 assert_eq!(TemplateModule::balance_count(1, 1), 923);794 assert_eq!(
795 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),
796 1
797 );
798 assert_eq!(
799 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),
800 1
801 );
802 assert_eq!(
803 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),
804 923
805 );
583 assert_eq!(TemplateModule::balance_count(1, 3), 100);806 assert_eq!(
807 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),
808 100
809 );
584 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);810 assert_eq!(
811 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
812 true
813 );
585 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);814 assert_eq!(
586815 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
816 true
587 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 923);817 );
818 assert_eq!(
819 <pallet_refungible::Allowance<Test>>::get((
820 CollectionId(1),
821 TokenId(1),
822 account(1),
823 account(2)
824 )),
825 923
826 );
588 });827 });
589}828}
590829
591#[test]830#[test]
592fn fungible_approve_and_transfer_from() {831fn fungible_approve_and_transfer_from() {
593 new_test_ext().execute_with(|| {832 new_test_ext().execute_with(|| {
594 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);833 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
595834
596 let data = default_fungible_data();835 let data = default_fungible_data();
597 create_test_item(collection_id, &data.into());836 create_test_item(collection_id, &data.into());
598837
599 let origin1 = Origin::signed(1);838 let origin1 = Origin::signed(1);
600 let origin2 = Origin::signed(2);839 let origin2 = Origin::signed(2);
601840
602 assert_eq!(TemplateModule::balance_count(1, 1), 5);
603
604 assert_ok!(TemplateModule::set_mint_permission(841 assert_ok!(TemplateModule::set_mint_permission(
605 origin1.clone(),842 origin1.clone(),
606 1,843 CollectionId(1),
607 true844 true
608 ));845 ));
609 assert_ok!(TemplateModule::set_public_access_mode(846 assert_ok!(TemplateModule::set_public_access_mode(
610 origin1.clone(),847 origin1.clone(),
611 1,848 CollectionId(1),
612 AccessMode::AllowList849 AccessMode::AllowList
613 ));850 ));
614 assert_ok!(TemplateModule::add_to_allow_list(851 assert_ok!(TemplateModule::add_to_allow_list(
615 origin1.clone(),852 origin1.clone(),
616 1,853 CollectionId(1),
617 account(1)854 account(1)
618 ));855 ));
619 assert_ok!(TemplateModule::add_to_allow_list(856 assert_ok!(TemplateModule::add_to_allow_list(
620 origin1.clone(),857 origin1.clone(),
621 1,858 CollectionId(1),
622 account(2)859 account(2)
623 ));860 ));
624 assert_ok!(TemplateModule::add_to_allow_list(861 assert_ok!(TemplateModule::add_to_allow_list(
625 origin1.clone(),862 origin1.clone(),
626 1,863 CollectionId(1),
627 account(3)864 account(3)
628 ));865 ));
629866
630 // do approve867 // do approve
631 assert_ok!(TemplateModule::approve(868 assert_ok!(TemplateModule::approve(
632 origin1.clone(),869 origin1.clone(),
633 account(2),870 account(2),
634 1,871 CollectionId(1),
635 1,872 TokenId(0),
636 5873 5
637 ));874 ));
638 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);875 assert_eq!(
876 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),
877 5
878 );
639 assert_ok!(TemplateModule::approve(origin1, account(3), 1, 1, 5));879 assert_ok!(TemplateModule::approve(
880 origin1,
881 account(3),
882 CollectionId(1),
883 TokenId(0),
884 5
885 ));
640 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);886 assert_eq!(
887 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),
888 5
889 );
641 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);890 assert_eq!(
891 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))),
892 5
893 );
642894
643 assert_ok!(TemplateModule::transfer_from(895 assert_ok!(TemplateModule::transfer_from(
644 origin2.clone(),896 origin2.clone(),
645 account(1),897 account(1),
646 account(3),898 account(3),
647 1,899 CollectionId(1),
648 1,900 TokenId(0),
649 4901 4
650 ));902 ));
651 assert_eq!(TemplateModule::balance_count(1, 1), 1);
652 assert_eq!(TemplateModule::balance_count(1, 3), 4);
653903
654 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);904 assert_eq!(
905 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),
906 1
907 );
655908
656 assert_noop!(909 assert_noop!(
657 TemplateModule::transfer_from(origin2, account(1), account(3), 1, 1, 4),910 TemplateModule::transfer_from(
911 origin2,
912 account(1),
913 account(3),
914 CollectionId(1),
915 TokenId(0),
916 4
917 )
918 .map_err(|e| e.error),
658 Error::<Test>::NoPermission919 CommonError::<Test>::TokenValueNotEnough
659 );920 );
660 });921 });
661}922}
662923
663#[test]924#[test]
664fn change_collection_owner() {925fn change_collection_owner() {
665 new_test_ext().execute_with(|| {926 new_test_ext().execute_with(|| {
666 let collection_id = create_test_collection(&CollectionMode::NFT, 1);927 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
667928
668 let origin1 = Origin::signed(1);929 let origin1 = Origin::signed(1);
669 assert_ok!(TemplateModule::change_collection_owner(930 assert_ok!(TemplateModule::change_collection_owner(
672 2933 2
673 ));934 ));
674 assert_eq!(935 assert_eq!(
675 TemplateModule::collection_id(collection_id).unwrap().owner,936 <pallet_common::CollectionById<Test>>::get(collection_id)
937 .unwrap()
938 .owner,
676 2939 2
677 );940 );
678 });941 });
681#[test]944#[test]
682fn destroy_collection() {945fn destroy_collection() {
683 new_test_ext().execute_with(|| {946 new_test_ext().execute_with(|| {
684 let collection_id = create_test_collection(&CollectionMode::NFT, 1);947 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
685948
686 let origin1 = Origin::signed(1);949 let origin1 = Origin::signed(1);
687 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));950 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));
691#[test]954#[test]
692fn burn_nft_item() {955fn burn_nft_item() {
693 new_test_ext().execute_with(|| {956 new_test_ext().execute_with(|| {
694 let collection_id = create_test_collection(&CollectionMode::NFT, 1);957 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
695958
696 let origin1 = Origin::signed(1);959 let origin1 = Origin::signed(1);
960
961 let data = default_nft_data();
962 create_test_item(collection_id, &data.into());
963
964 // check balance (collection with id = 1, user id = 1)
965 assert_eq!(
966 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
967 1
968 );
969
970 // burn item
697 assert_ok!(TemplateModule::add_collection_admin(971 assert_ok!(TemplateModule::burn_item(
698 origin1.clone(),972 origin1.clone(),
699 collection_id,973 collection_id,
700 account(2)974 TokenId(1),
975 1
701 ));976 ));
977 assert_eq!(
978 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
979 0
980 );
981 });
982}
702983
984#[test]
985fn burn_same_nft_item_twice() {
986 new_test_ext().execute_with(|| {
987 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
988
989 let origin1 = Origin::signed(1);
990
703 let data = default_nft_data();991 let data = default_nft_data();
704 create_test_item(collection_id, &data.into());992 create_test_item(collection_id, &data.into());
705993
706 // check balance (collection with id = 1, user id = 1)994 // check balance (collection with id = 1, user id = 1)
707 assert_eq!(TemplateModule::balance_count(1, 1), 1);995 assert_eq!(
996 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
997 1
998 );
708999
709 // burn item1000 // burn item
710 assert_ok!(TemplateModule::burn_item(1001 assert_ok!(TemplateModule::burn_item(
711 origin1.clone(),1002 origin1.clone(),
712 collection_id,1003 collection_id,
713 1,1004 TokenId(1),
714 11005 1
715 ));1006 ));
1007
1008 // burn item again
716 assert_noop!(1009 assert_noop!(
717 TemplateModule::burn_item(origin1, collection_id, 1, 1),1010 TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),
718 Error::<Test>::TokenNotFound1011 CommonError::<Test>::TokenNotFound
719 );1012 );
7201013
721 assert_eq!(TemplateModule::balance_count(1, 1), 0);1014 assert_eq!(
1015 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
1016 0
1017 );
722 });1018 });
723}1019}
7241020
725#[test]1021#[test]
726fn burn_fungible_item() {1022fn burn_fungible_item() {
727 new_test_ext().execute_with(|| {1023 new_test_ext().execute_with(|| {
728 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);1024 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
7291025
730 let origin1 = Origin::signed(1);1026 let origin1 = Origin::signed(1);
731 assert_ok!(TemplateModule::add_collection_admin(1027 assert_ok!(TemplateModule::add_collection_admin(
738 create_test_item(collection_id, &data.into());1034 create_test_item(collection_id, &data.into());
7391035
740 // check balance (collection with id = 1, user id = 1)1036 // check balance (collection with id = 1, user id = 1)
741 assert_eq!(TemplateModule::balance_count(1, 1), 5);1037 assert_eq!(
1038 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),
1039 5
1040 );
7421041
743 // burn item1042 // burn item
744 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));1043 assert_ok!(TemplateModule::burn_item(
1044 origin1.clone(),
1045 CollectionId(1),
1046 TokenId(0),
1047 5
1048 ));
745 assert_noop!(1049 assert_noop!(
746 TemplateModule::burn_item(origin1, 1, 1, 5),1050 TemplateModule::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),
747 Error::<Test>::TokenValueNotEnough1051 CommonError::<Test>::TokenValueTooLow
748 );1052 );
7491053
750 assert_eq!(TemplateModule::balance_count(1, 1), 0);1054 assert_eq!(
1055 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),
1056 0
1057 );
751 });1058 });
752}1059}
7531060
754#[test]1061#[test]
1062fn burn_fungible_item_with_token_id() {
1063 new_test_ext().execute_with(|| {
1064 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
1065
1066 let origin1 = Origin::signed(1);
1067 assert_ok!(TemplateModule::add_collection_admin(
1068 origin1.clone(),
1069 collection_id,
1070 account(2)
1071 ));
1072
1073 let data = default_fungible_data();
1074 create_test_item(collection_id, &data.into());
1075
1076 // check balance (collection with id = 1, user id = 1)
1077 assert_eq!(
1078 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),
1079 5
1080 );
1081
1082 // Try to burn item using Token ID
1083 assert_noop!(
1084 TemplateModule::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),
1085 <pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId
1086 );
1087 });
1088}
1089#[test]
755fn burn_refungible_item() {1090fn burn_refungible_item() {
756 new_test_ext().execute_with(|| {1091 new_test_ext().execute_with(|| {
757 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);1092 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
758 let origin1 = Origin::signed(1);1093 let origin1 = Origin::signed(1);
7591094
760 assert_ok!(TemplateModule::set_mint_permission(1095 assert_ok!(TemplateModule::set_mint_permission(
769 ));1104 ));
770 assert_ok!(TemplateModule::add_to_allow_list(1105 assert_ok!(TemplateModule::add_to_allow_list(
771 origin1.clone(),1106 origin1.clone(),
772 1,1107 collection_id,
773 account(1)1108 account(1)
774 ));1109 ));
7751110
776 assert_ok!(TemplateModule::add_collection_admin(1111 assert_ok!(TemplateModule::add_collection_admin(
777 origin1.clone(),1112 origin1.clone(),
778 1,1113 collection_id,
779 account(2)1114 account(2)
780 ));1115 ));
7811116
782 let data = default_re_fungible_data();1117 let data = default_re_fungible_data();
783 create_test_item(collection_id, &data.into());1118 create_test_item(collection_id, &data.into());
7841119
785 // check balance (collection with id = 1, user id = 2)1120 // check balance (collection with id = 1, user id = 2)
786 assert_eq!(TemplateModule::balance_count(1, 1), 1023);1121 assert_eq!(
1122 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),
1123 1
1124 );
1125 assert_eq!(
1126 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),
1127 1023
1128 );
7871129
788 // burn item1130 // burn item
789 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 1023));1131 assert_ok!(TemplateModule::burn_item(
1132 origin1.clone(),
1133 collection_id,
1134 TokenId(1),
1135 1023
1136 ));
790 assert_noop!(1137 assert_noop!(
791 TemplateModule::burn_item(origin1, 1, 1, 1023),1138 TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023)
1139 .map_err(|e| e.error),
792 Error::<Test>::TokenNotFound1140 CommonError::<Test>::TokenValueTooLow
793 );1141 );
7941142
795 assert_eq!(TemplateModule::balance_count(1, 1), 0);1143 assert_eq!(
1144 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),
1145 0
1146 );
796 });1147 });
797}1148}
7981149
799#[test]1150#[test]
800fn add_collection_admin() {1151fn add_collection_admin() {
801 new_test_ext().execute_with(|| {1152 new_test_ext().execute_with(|| {
802 let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);1153 let collection1_id =
803 create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);1154 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
804 create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);
805
806 let origin1 = Origin::signed(1);1155 let origin1 = Origin::signed(1);
8071156
808 // collection admin1157 // Add collection admins
809 assert_ok!(TemplateModule::add_collection_admin(1158 assert_ok!(TemplateModule::add_collection_admin(
810 origin1.clone(),1159 origin1.clone(),
811 collection1_id,1160 collection1_id,
817 account(3)1166 account(3)
818 ));1167 ));
8191168
820 assert!(TemplateModule::admin_list_collection(collection1_id).contains(&account(2)),);1169 // Owner is not an admin by default
1170 assert_eq!(
1171 <pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))),
1172 false
1173 );
1174 assert!(<pallet_common::IsAdmin<Test>>::get((
1175 CollectionId(1),
1176 account(2)
1177 )));
821 assert!(TemplateModule::admin_list_collection(collection1_id).contains(&account(3)),);1178 assert!(<pallet_common::IsAdmin<Test>>::get((
1179 CollectionId(1),
1180 account(3)
1181 )));
822 });1182 });
823}1183}
8241184
825#[test]1185#[test]
826fn remove_collection_admin() {1186fn remove_collection_admin() {
827 new_test_ext().execute_with(|| {1187 new_test_ext().execute_with(|| {
828 let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);1188 let collection1_id =
829 create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);1189 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
830 create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);
831
832 let origin1 = Origin::signed(1);1190 let origin1 = Origin::signed(1);
833 let origin2 = Origin::signed(2);1191 let origin2 = Origin::signed(2);
8341192
835 // collection admin1193 // Add collection admins 2 and 3
836 assert_ok!(TemplateModule::add_collection_admin(1194 assert_ok!(TemplateModule::add_collection_admin(
837 origin1.clone(),1195 origin1.clone(),
838 collection1_id,1196 collection1_id,
844 account(3)1202 account(3)
845 ));1203 ));
8461204
847 assert!(TemplateModule::admin_list_collection(1).contains(&account(2)),);1205 assert!(<pallet_common::IsAdmin<Test>>::get((
1206 CollectionId(1),
1207 account(2)
1208 )));
848 assert!(TemplateModule::admin_list_collection(1).contains(&account(3)),);1209 assert!(<pallet_common::IsAdmin<Test>>::get((
1210 CollectionId(1),
1211 account(3)
1212 )));
8491213
850 // remove admin1214 // remove admin 3
851 assert_ok!(TemplateModule::remove_collection_admin(1215 assert_ok!(TemplateModule::remove_collection_admin(
852 origin2,1216 origin2,
853 1,1217 CollectionId(1),
854 account(3)1218 account(3)
855 ));1219 ));
1220
856 assert!(!TemplateModule::admin_list_collection(1).contains(&account(3)),);1221 // 2 is still admin, 3 is not an admin anymore
1222 assert!(<pallet_common::IsAdmin<Test>>::get((
1223 CollectionId(1),
1224 account(2)
1225 )));
1226 assert_eq!(
1227 <pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))),
1228 false
1229 );
857 });1230 });
858}1231}
8591232
860#[test]1233#[test]
861fn balance_of() {1234fn balance_of() {
862 new_test_ext().execute_with(|| {1235 new_test_ext().execute_with(|| {
863 let nft_collection_id = create_test_collection(&CollectionMode::NFT, 1);1236 let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
864 let fungible_collection_id = create_test_collection(&CollectionMode::Fungible(3), 2);1237 let fungible_collection_id =
1238 create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));
865 let re_fungible_collection_id = create_test_collection(&CollectionMode::ReFungible, 3);1239 let re_fungible_collection_id =
1240 create_test_collection(&CollectionMode::ReFungible, CollectionId(3));
8661241
867 // check balance before1242 // check balance before
868 assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 0);
869 assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 0);
870 assert_eq!(1243 assert_eq!(
871 TemplateModule::balance_count(re_fungible_collection_id, 1),1244 <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),
872 01245 0
873 );1246 );
1247 assert_eq!(
1248 <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),
1249 0
1250 );
1251 assert_eq!(
1252 <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),
1253 0
1254 );
8741255
875 let nft_data = default_nft_data();1256 let nft_data = default_nft_data();
876 create_test_item(nft_collection_id, &nft_data.into());1257 create_test_item(nft_collection_id, &nft_data.into());
882 create_test_item(re_fungible_collection_id, &re_fungible_data.into());1263 create_test_item(re_fungible_collection_id, &re_fungible_data.into());
8831264
884 // check balance (collection with id = 1, user id = 1)1265 // check balance (collection with id = 1, user id = 1)
885 assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 1);
886 assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 5);
887 assert_eq!(1266 assert_eq!(
888 TemplateModule::balance_count(re_fungible_collection_id, 1),1267 <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),
889 10231268 1
890 );1269 );
891 assert_eq!(1270 assert_eq!(
892 TemplateModule::nft_item_id(nft_collection_id, 1)1271 <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),
893 .unwrap()
894 .owner,
895 account(1)1272 5
896 );1273 );
897 assert_eq!(1274 assert_eq!(
898 TemplateModule::fungible_item_id(fungible_collection_id, 1).value,1275 <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),
899 51276 1
900 );1277 );
1278
901 assert_eq!(1279 assert_eq!(
902 TemplateModule::refungible_item_id(re_fungible_collection_id, 1)1280 <pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))),
903 .unwrap()
904 .owner[0]
905 .owner,
906 account(1)1281 true
907 );1282 );
1283 assert_eq!(
1284 <pallet_refungible::Owned<Test>>::get((
1285 re_fungible_collection_id,
1286 account(1),
1287 TokenId(1)
1288 )),
1289 true
1290 );
908 });1291 });
909}1292}
9101293
911#[test]1294#[test]
912fn approve() {1295fn approve() {
913 new_test_ext().execute_with(|| {1296 new_test_ext().execute_with(|| {
914 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1297 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
9151298
916 let data = default_nft_data();1299 let data = default_nft_data();
917 create_test_item(collection_id, &data.into());1300 create_test_item(collection_id, &data.into());
9181301
919 let origin1 = Origin::signed(1);1302 let origin1 = Origin::signed(1);
9201303
921 // approve1304 // approve
922 assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 1));1305 assert_ok!(TemplateModule::approve(
1306 origin1,
1307 account(2),
1308 CollectionId(1),
1309 TokenId(1),
1310 1
1311 ));
923 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);1312 assert_eq!(
1313 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
1314 account(2)
1315 );
924 });1316 });
925}1317}
9261318
927#[test]1319#[test]
928fn transfer_from() {1320fn transfer_from() {
929 new_test_ext().execute_with(|| {1321 new_test_ext().execute_with(|| {
930 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1322 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
931 let origin1 = Origin::signed(1);1323 let origin1 = Origin::signed(1);
932 let origin2 = Origin::signed(2);1324 let origin2 = Origin::signed(2);
9331325
938 assert_ok!(TemplateModule::approve(1330 assert_ok!(TemplateModule::approve(
939 origin1.clone(),1331 origin1.clone(),
940 account(2),1332 account(2),
941 1,1333 CollectionId(1),
942 1,1334 TokenId(1),
943 11335 1
944 ));1336 ));
945 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);1337 assert_eq!(
1338 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
1339 account(2)
1340 );
9461341
947 assert_ok!(TemplateModule::set_mint_permission(1342 assert_ok!(TemplateModule::set_mint_permission(
948 origin1.clone(),1343 origin1.clone(),
949 1,1344 CollectionId(1),
950 true1345 true
951 ));1346 ));
952 assert_ok!(TemplateModule::set_public_access_mode(1347 assert_ok!(TemplateModule::set_public_access_mode(
953 origin1.clone(),1348 origin1.clone(),
954 1,1349 CollectionId(1),
955 AccessMode::AllowList1350 AccessMode::AllowList
956 ));1351 ));
957 assert_ok!(TemplateModule::add_to_allow_list(1352 assert_ok!(TemplateModule::add_to_allow_list(
958 origin1.clone(),1353 origin1.clone(),
959 1,1354 CollectionId(1),
960 account(1)1355 account(1)
961 ));1356 ));
962 assert_ok!(TemplateModule::add_to_allow_list(1357 assert_ok!(TemplateModule::add_to_allow_list(
963 origin1.clone(),1358 origin1.clone(),
964 1,1359 CollectionId(1),
965 account(2)1360 account(2)
966 ));1361 ));
967 assert_ok!(TemplateModule::add_to_allow_list(origin1, 1, account(3)));1362 assert_ok!(TemplateModule::add_to_allow_list(
1363 origin1,
1364 CollectionId(1),
1365 account(3)
1366 ));
9681367
969 assert_ok!(TemplateModule::transfer_from(1368 assert_ok!(TemplateModule::transfer_from(
970 origin2,1369 origin2,
971 account(1),1370 account(1),
972 account(2),1371 account(2),
973 1,1372 CollectionId(1),
974 1,1373 TokenId(1),
975 11374 1
976 ));1375 ));
9771376
978 // after transfer1377 // after transfer
979 assert_eq!(TemplateModule::balance_count(1, 1), 0);1378 assert_eq!(
1379 <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))),
1380 0
1381 );
980 assert_eq!(TemplateModule::balance_count(1, 2), 1);1382 assert_eq!(
1383 <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))),
1384 1
1385 );
981 });1386 });
982}1387}
9831388
989#[test]1394#[test]
990fn owner_can_add_address_to_allow_list() {1395fn owner_can_add_address_to_allow_list() {
991 new_test_ext().execute_with(|| {1396 new_test_ext().execute_with(|| {
992 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1397 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
9931398
994 let origin1 = Origin::signed(1);1399 let origin1 = Origin::signed(1);
995 assert_ok!(TemplateModule::add_to_allow_list(1400 assert_ok!(TemplateModule::add_to_allow_list(
996 origin1,1401 origin1,
997 collection_id,1402 collection_id,
998 account(2)1403 account(2)
999 ));1404 ));
1000 assert!(TemplateModule::allow_list(collection_id, 2));1405 assert!(<pallet_common::Allowlist<Test>>::get((
1406 collection_id,
1407 account(2)
1408 )));
1001 });1409 });
1002}1410}
10031411
1004#[test]1412#[test]
1005fn admin_can_add_address_to_allow_list() {1413fn admin_can_add_address_to_allow_list() {
1006 new_test_ext().execute_with(|| {1414 new_test_ext().execute_with(|| {
1007 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1415 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
1008 let origin1 = Origin::signed(1);1416 let origin1 = Origin::signed(1);
1009 let origin2 = Origin::signed(2);1417 let origin2 = Origin::signed(2);
10101418
1018 collection_id,1426 collection_id,
1019 account(3)1427 account(3)
1020 ));1428 ));
1021 assert!(TemplateModule::allow_list(collection_id, 3));1429 assert!(<pallet_common::Allowlist<Test>>::get((
1430 collection_id,
1431 account(3)
1432 )));
1022 });1433 });
1023}1434}
10241435
1025#[test]1436#[test]
1026fn nonprivileged_user_cannot_add_address_to_allow_list() {1437fn nonprivileged_user_cannot_add_address_to_allow_list() {
1027 new_test_ext().execute_with(|| {1438 new_test_ext().execute_with(|| {
1028 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1439 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
10291440
1030 let origin2 = Origin::signed(2);1441 let origin2 = Origin::signed(2);
1031 assert_noop!(1442 assert_noop!(
1032 TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),1443 TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),
1033 Error::<Test>::NoPermission1444 CommonError::<Test>::NoPermission
1034 );1445 );
1035 });1446 });
1036}1447}
1041 let origin1 = Origin::signed(1);1452 let origin1 = Origin::signed(1);
10421453
1043 assert_noop!(1454 assert_noop!(
1044 TemplateModule::add_to_allow_list(origin1, 1, account(2)),1455 TemplateModule::add_to_allow_list(origin1, CollectionId(1), account(2)),
1045 Error::<Test>::CollectionNotFound1456 CommonError::<Test>::CollectionNotFound
1046 );1457 );
1047 });1458 });
1048}1459}
10491460
1050#[test]1461#[test]
1051fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1462fn nobody_can_add_address_to_allow_list_of_deleted_collection() {
1052 new_test_ext().execute_with(|| {1463 new_test_ext().execute_with(|| {
1053 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1464 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
10541465
1055 let origin1 = Origin::signed(1);1466 let origin1 = Origin::signed(1);
1056 assert_ok!(TemplateModule::destroy_collection(1467 assert_ok!(TemplateModule::destroy_collection(
1059 ));1470 ));
1060 assert_noop!(1471 assert_noop!(
1061 TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),1472 TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),
1062 Error::<Test>::CollectionNotFound1473 CommonError::<Test>::CollectionNotFound
1063 );1474 );
1064 });1475 });
1065}1476}
1068#[test]1479#[test]
1069fn address_is_already_added_to_allow_list() {1480fn address_is_already_added_to_allow_list() {
1070 new_test_ext().execute_with(|| {1481 new_test_ext().execute_with(|| {
1071 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1482 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
1072 let origin1 = Origin::signed(1);1483 let origin1 = Origin::signed(1);
10731484
1074 assert_ok!(TemplateModule::add_to_allow_list(1485 assert_ok!(TemplateModule::add_to_allow_list(
1081 collection_id,1492 collection_id,
1082 account(2)1493 account(2)
1083 ));1494 ));
1084 assert!(TemplateModule::allow_list(collection_id, 2));1495 assert!(<pallet_common::Allowlist<Test>>::get((
1496 collection_id,
1497 account(2)
1498 )));
1085 });1499 });
1086}1500}
10871501
1088#[test]1502#[test]
1089fn owner_can_remove_address_from_allow_list() {1503fn owner_can_remove_address_from_allow_list() {
1090 new_test_ext().execute_with(|| {1504 new_test_ext().execute_with(|| {
1091 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1505 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
10921506
1093 let origin1 = Origin::signed(1);1507 let origin1 = Origin::signed(1);
1094 assert_ok!(TemplateModule::add_to_allow_list(1508 assert_ok!(TemplateModule::add_to_allow_list(
1101 collection_id,1515 collection_id,
1102 account(2)1516 account(2)
1103 ));1517 ));
1104 assert!(!TemplateModule::allow_list(collection_id, 2));1518 assert_eq!(
1519 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),
1520 false
1521 );
1105 });1522 });
1106}1523}
11071524
1108#[test]1525#[test]
1109fn admin_can_remove_address_from_allow_list() {1526fn admin_can_remove_address_from_allow_list() {
1110 new_test_ext().execute_with(|| {1527 new_test_ext().execute_with(|| {
1111 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1528 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
1112 let origin1 = Origin::signed(1);1529 let origin1 = Origin::signed(1);
1113 let origin2 = Origin::signed(2);1530 let origin2 = Origin::signed(2);
11141531
1532 // Owner adds admin
1115 assert_ok!(TemplateModule::add_collection_admin(1533 assert_ok!(TemplateModule::add_collection_admin(
1116 origin1.clone(),1534 origin1.clone(),
1117 collection_id,1535 collection_id,
1118 account(2)1536 account(2)
1119 ));1537 ));
11201538
1539 // Owner adds address 3 to allow list
1121 assert_ok!(TemplateModule::add_to_allow_list(1540 assert_ok!(TemplateModule::add_to_allow_list(
1122 origin1,1541 origin1,
1123 collection_id,1542 collection_id,
1124 account(3)1543 account(3)
1125 ));1544 ));
1545
1546 // Admin removes address 3 from allow list
1126 assert_ok!(TemplateModule::remove_from_allow_list(1547 assert_ok!(TemplateModule::remove_from_allow_list(
1127 origin2,1548 origin2,
1128 collection_id,1549 collection_id,
1129 account(3)1550 account(3)
1130 ));1551 ));
1131 assert!(!TemplateModule::allow_list(collection_id, 3));1552 assert_eq!(
1553 <pallet_common::Allowlist<Test>>::get((collection_id, account(3))),
1554 false
1555 );
1132 });1556 });
1133}1557}
11341558
1135#[test]1559#[test]
1136fn nonprivileged_user_cannot_remove_address_from_allow_list() {1560fn nonprivileged_user_cannot_remove_address_from_allow_list() {
1137 new_test_ext().execute_with(|| {1561 new_test_ext().execute_with(|| {
1138 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1562 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
1139 let origin1 = Origin::signed(1);1563 let origin1 = Origin::signed(1);
1140 let origin2 = Origin::signed(2);1564 let origin2 = Origin::signed(2);
11411565
1146 ));1570 ));
1147 assert_noop!(1571 assert_noop!(
1148 TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1572 TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),
1149 Error::<Test>::NoPermission1573 CommonError::<Test>::NoPermission
1150 );1574 );
1151 assert!(TemplateModule::allow_list(collection_id, 2));1575 assert!(<pallet_common::Allowlist<Test>>::get((
1576 collection_id,
1577 account(2)
1578 )));
1152 });1579 });
1153}1580}
11541581
1158 let origin1 = Origin::signed(1);1585 let origin1 = Origin::signed(1);
11591586
1160 assert_noop!(1587 assert_noop!(
1161 TemplateModule::remove_from_allow_list(origin1, 1, account(2)),1588 TemplateModule::remove_from_allow_list(origin1, CollectionId(1), account(2)),
1162 Error::<Test>::CollectionNotFound1589 CommonError::<Test>::CollectionNotFound
1163 );1590 );
1164 });1591 });
1165}1592}
11661593
1167#[test]1594#[test]
1168fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1595fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {
1169 new_test_ext().execute_with(|| {1596 new_test_ext().execute_with(|| {
1170 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1597 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
1171 let origin1 = Origin::signed(1);1598 let origin1 = Origin::signed(1);
1172 let origin2 = Origin::signed(2);1599 let origin2 = Origin::signed(2);
11731600
1601 // Add account 2 to allow list
1174 assert_ok!(TemplateModule::add_to_allow_list(1602 assert_ok!(TemplateModule::add_to_allow_list(
1175 origin1.clone(),1603 origin1.clone(),
1176 collection_id,1604 collection_id,
1177 account(2)1605 account(2)
1178 ));1606 ));
1607
1608 // Account 2 is in collection allow-list
1609 assert!(<pallet_common::Allowlist<Test>>::get((
1610 collection_id,
1611 account(2)
1612 )));
1613
1614 // Destroy collection
1179 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));1615 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));
1616
1617 // Attempt to remove account 2 from collection allow-list => error
1180 assert_noop!(1618 assert_noop!(
1181 TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1619 TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),
1182 Error::<Test>::CollectionNotFound1620 CommonError::<Test>::CollectionNotFound
1183 );1621 );
1622
1184 assert!(!TemplateModule::allow_list(collection_id, 2));1623 // Account 2 is not found in collection allow-list anyway
1624 assert_eq!(
1625 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),
1626 false
1627 );
1185 });1628 });
1186}1629}
11871630
1188// If address is already removed from allow list, nothing happens1631// If address is already removed from allow list, nothing happens
1189#[test]1632#[test]
1190fn address_is_already_removed_from_allow_list() {1633fn address_is_already_removed_from_allow_list() {
1191 new_test_ext().execute_with(|| {1634 new_test_ext().execute_with(|| {
1192 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1635 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
1193 let origin1 = Origin::signed(1);1636 let origin1 = Origin::signed(1);
11941637
1195 assert_ok!(TemplateModule::add_to_allow_list(1638 assert_ok!(TemplateModule::add_to_allow_list(
1202 collection_id,1645 collection_id,
1203 account(2)1646 account(2)
1204 ));1647 ));
1648 assert_eq!(
1649 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),
1650 false
1651 );
1205 assert_ok!(TemplateModule::remove_from_allow_list(1652 assert_ok!(TemplateModule::remove_from_allow_list(
1206 origin1,1653 origin1,
1207 collection_id,1654 collection_id,
1208 account(2)1655 account(2)
1209 ));1656 ));
1210 assert!(!TemplateModule::allow_list(collection_id, 2));1657 assert_eq!(
1658 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),
1659 false
1660 );
1211 });1661 });
1212}1662}
12131663
1214// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1664// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)
1215#[test]1665#[test]
1216fn allow_list_test_1() {1666fn allow_list_test_1() {
1217 new_test_ext().execute_with(|| {1667 new_test_ext().execute_with(|| {
1218 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1668 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
12191669
1220 let origin1 = Origin::signed(1);1670 let origin1 = Origin::signed(1);
12211671
1234 ));1684 ));
12351685
1236 assert_noop!(1686 assert_noop!(
1237 TemplateModule::transfer(origin1, account(3), 1, 1, 1),1687 TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1)
1688 .map_err(|e| e.error),
1238 Error::<Test>::AddresNotInAllowList1689 CommonError::<Test>::AddressNotInAllowlist
1239 );1690 );
1240 });1691 });
1241}1692}
12421693
1243#[test]1694#[test]
1244fn allow_list_test_2() {1695fn allow_list_test_2() {
1245 new_test_ext().execute_with(|| {1696 new_test_ext().execute_with(|| {
1246 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1697 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
1247 let origin1 = Origin::signed(1);1698 let origin1 = Origin::signed(1);
12481699
1249 let data = default_nft_data();1700 let data = default_nft_data();
1256 ));1707 ));
1257 assert_ok!(TemplateModule::add_to_allow_list(1708 assert_ok!(TemplateModule::add_to_allow_list(
1258 origin1.clone(),1709 origin1.clone(),
1259 1,1710 collection_id,
1260 account(1)1711 account(1)
1261 ));1712 ));
1262 assert_ok!(TemplateModule::add_to_allow_list(1713 assert_ok!(TemplateModule::add_to_allow_list(
1263 origin1.clone(),1714 origin1.clone(),
1264 1,1715 collection_id,
1265 account(2)1716 account(2)
1266 ));1717 ));
12671718
1268 // do approve1719 // do approve
1269 assert_ok!(TemplateModule::approve(1720 assert_ok!(TemplateModule::approve(
1270 origin1.clone(),1721 origin1.clone(),
1271 account(1),1722 account(1),
1272 1,1723 collection_id,
1273 1,1724 TokenId(1),
1274 11725 1
1275 ));1726 ));
1276 assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);1727 assert_eq!(
1728 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
1729 account(1)
1730 );
12771731
1278 assert_ok!(TemplateModule::remove_from_allow_list(1732 assert_ok!(TemplateModule::remove_from_allow_list(
1279 origin1.clone(),1733 origin1.clone(),
1280 1,1734 collection_id,
1281 account(1)1735 account(1)
1282 ));1736 ));
12831737
1284 assert_noop!(1738 assert_noop!(
1285 TemplateModule::transfer_from(origin1, account(1), account(3), 1, 1, 1),1739 TemplateModule::transfer_from(
1740 origin1,
1741 account(1),
1742 account(3),
1743 CollectionId(1),
1744 TokenId(1),
1745 1
1746 )
1747 .map_err(|e| e.error),
1286 Error::<Test>::AddresNotInAllowList1748 CommonError::<Test>::AddressNotInAllowlist
1287 );1749 );
1288 });1750 });
1289}1751}
1292#[test]1754#[test]
1293fn allow_list_test_3() {1755fn allow_list_test_3() {
1294 new_test_ext().execute_with(|| {1756 new_test_ext().execute_with(|| {
1295 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1757 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
12961758
1297 let origin1 = Origin::signed(1);1759 let origin1 = Origin::signed(1);
12981760
1306 ));1768 ));
1307 assert_ok!(TemplateModule::add_to_allow_list(1769 assert_ok!(TemplateModule::add_to_allow_list(
1308 origin1.clone(),1770 origin1.clone(),
1309 1,1771 collection_id,
1310 account(1)1772 account(1)
1311 ));1773 ));
13121774
1313 assert_noop!(1775 assert_noop!(
1314 TemplateModule::transfer(origin1, account(3), 1, 1, 1),1776 TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1)
1777 .map_err(|e| e.error),
1315 Error::<Test>::AddresNotInAllowList1778 CommonError::<Test>::AddressNotInAllowlist
1316 );1779 );
1317 });1780 });
1318}1781}
13191782
1320#[test]1783#[test]
1321fn allow_list_test_4() {1784fn allow_list_test_4() {
1322 new_test_ext().execute_with(|| {1785 new_test_ext().execute_with(|| {
1323 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1786 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
13241787
1325 let origin1 = Origin::signed(1);1788 let origin1 = Origin::signed(1);
13261789
1347 assert_ok!(TemplateModule::approve(1810 assert_ok!(TemplateModule::approve(
1348 origin1.clone(),1811 origin1.clone(),
1349 account(1),1812 account(1),
1350 1,1813 collection_id,
1351 1,1814 TokenId(1),
1352 11815 1
1353 ));1816 ));
1354 assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);1817 assert_eq!(
1818 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
1819 account(1)
1820 );
13551821
1356 assert_ok!(TemplateModule::remove_from_allow_list(1822 assert_ok!(TemplateModule::remove_from_allow_list(
1357 origin1.clone(),1823 origin1.clone(),
1360 ));1826 ));
13611827
1362 assert_noop!(1828 assert_noop!(
1363 TemplateModule::transfer_from(origin1, account(1), account(3), 1, 1, 1),1829 TemplateModule::transfer_from(
1830 origin1,
1831 account(1),
1832 account(3),
1833 collection_id,
1834 TokenId(1),
1835 1
1836 )
1837 .map_err(|e| e.error),
1364 Error::<Test>::AddresNotInAllowList1838 CommonError::<Test>::AddressNotInAllowlist
1365 );1839 );
1366 });1840 });
1367}1841}
1370#[test]1844#[test]
1371fn allow_list_test_5() {1845fn allow_list_test_5() {
1372 new_test_ext().execute_with(|| {1846 new_test_ext().execute_with(|| {
1373 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1847 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
13741848
1375 let origin1 = Origin::signed(1);1849 let origin1 = Origin::signed(1);
13761850
1383 AccessMode::AllowList1857 AccessMode::AllowList
1384 ));1858 ));
1385 assert_noop!(1859 assert_noop!(
1386 TemplateModule::burn_item(origin1.clone(), 1, 1, 5),1860 TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1)
1861 .map_err(|e| e.error),
1387 Error::<Test>::AddresNotInAllowList1862 CommonError::<Test>::AddressNotInAllowlist
1388 );1863 );
1389 });1864 });
1390}1865}
1393#[test]1868#[test]
1394fn allow_list_test_6() {1869fn allow_list_test_6() {
1395 new_test_ext().execute_with(|| {1870 new_test_ext().execute_with(|| {
1396 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1871 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
13971872
1398 let origin1 = Origin::signed(1);1873 let origin1 = Origin::signed(1);
13991874
14081883
1409 // do approve1884 // do approve
1410 assert_noop!(1885 assert_noop!(
1411 TemplateModule::approve(origin1, account(1), 1, 1, 5),1886 TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 1)
1887 .map_err(|e| e.error),
1412 Error::<Test>::AddresNotInAllowList1888 CommonError::<Test>::AddressNotInAllowlist
1413 );1889 );
1414 });1890 });
1415}1891}
1419#[test]1895#[test]
1420fn allow_list_test_7() {1896fn allow_list_test_7() {
1421 new_test_ext().execute_with(|| {1897 new_test_ext().execute_with(|| {
1422 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1898 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
14231899
1424 let data = default_nft_data();1900 let data = default_nft_data();
1425 create_test_item(collection_id, &data.into());1901 create_test_item(collection_id, &data.into());
1442 account(2)1918 account(2)
1443 ));1919 ));
14441920
1445 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1));1921 assert_ok!(TemplateModule::transfer(
1922 origin1,
1923 account(2),
1924 CollectionId(1),
1925 TokenId(1),
1926 1
1927 ));
1446 });1928 });
1447}1929}
14481930
1449#[test]1931#[test]
1450fn allow_list_test_8() {1932fn allow_list_test_8() {
1451 new_test_ext().execute_with(|| {1933 new_test_ext().execute_with(|| {
1452 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1934 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
14531935
1936 // Create NFT for account 1
1454 let data = default_nft_data();1937 let data = default_nft_data();
1455 create_test_item(collection_id, &data.into());1938 create_test_item(collection_id, &data.into());
14561939
1457 let origin1 = Origin::signed(1);1940 let origin1 = Origin::signed(1);
14581941
1942 // Toggle Allow List mode and add accounts 1 and 2
1459 assert_ok!(TemplateModule::set_public_access_mode(1943 assert_ok!(TemplateModule::set_public_access_mode(
1460 origin1.clone(),1944 origin1.clone(),
1461 collection_id,1945 collection_id,
1472 account(2)1956 account(2)
1473 ));1957 ));
14741958
1475 // do approve1959 // Sself-approve account 1 for NFT 1
1476 assert_ok!(TemplateModule::approve(1960 assert_ok!(TemplateModule::approve(
1477 origin1.clone(),1961 origin1.clone(),
1478 account(1),1962 account(1),
1479 1,1963 CollectionId(1),
1480 1,1964 TokenId(1),
1481 51965 1
1482 ));1966 ));
1483 assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 5);1967 assert_eq!(
1968 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),
1969 account(1)
1970 );
14841971
1972 // Transfer from 1 to 2
1485 assert_ok!(TemplateModule::transfer_from(1973 assert_ok!(TemplateModule::transfer_from(
1486 origin1,1974 origin1,
1487 account(1),1975 account(1),
1488 account(2),1976 account(2),
1489 1,1977 CollectionId(1),
1490 1,1978 TokenId(1),
1491 11979 1
1492 ));1980 ));
1493 });1981 });
1497#[test]1985#[test]
1498fn allow_list_test_9() {1986fn allow_list_test_9() {
1499 new_test_ext().execute_with(|| {1987 new_test_ext().execute_with(|| {
1500 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1988 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
1501 let origin1 = Origin::signed(1);1989 let origin1 = Origin::signed(1);
15021990
1503 assert_ok!(TemplateModule::set_public_access_mode(1991 assert_ok!(TemplateModule::set_public_access_mode(
1520#[test]2008#[test]
1521fn allow_list_test_10() {2009fn allow_list_test_10() {
1522 new_test_ext().execute_with(|| {2010 new_test_ext().execute_with(|| {
1523 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2011 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
15242012
1525 let origin1 = Origin::signed(1);2013 let origin1 = Origin::signed(1);
1526 let origin2 = Origin::signed(2);2014 let origin2 = Origin::signed(2);
1555#[test]2043#[test]
1556fn allow_list_test_11() {2044fn allow_list_test_11() {
1557 new_test_ext().execute_with(|| {2045 new_test_ext().execute_with(|| {
1558 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2046 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
15592047
1560 let origin1 = Origin::signed(1);2048 let origin1 = Origin::signed(1);
1561 let origin2 = Origin::signed(2);2049 let origin2 = Origin::signed(2);
1577 ));2065 ));
15782066
1579 assert_noop!(2067 assert_noop!(
1580 TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),2068 TemplateModule::create_item(
2069 origin2,
2070 CollectionId(1),
2071 account(2),
2072 default_nft_data().into()
2073 )
2074 .map_err(|e| e.error),
1581 Error::<Test>::PublicMintingNotAllowed2075 CommonError::<Test>::PublicMintingNotAllowed
1582 );2076 );
1583 });2077 });
1584}2078}
1587#[test]2081#[test]
1588fn allow_list_test_12() {2082fn allow_list_test_12() {
1589 new_test_ext().execute_with(|| {2083 new_test_ext().execute_with(|| {
1590 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2084 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
15912085
1592 let origin1 = Origin::signed(1);2086 let origin1 = Origin::signed(1);
1593 let origin2 = Origin::signed(2);2087 let origin2 = Origin::signed(2);
1604 ));2098 ));
16052099
1606 assert_noop!(2100 assert_noop!(
1607 TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),2101 TemplateModule::create_item(
2102 origin2,
2103 CollectionId(1),
2104 account(2),
2105 default_nft_data().into()
2106 )
2107 .map_err(|e| e.error),
1608 Error::<Test>::PublicMintingNotAllowed2108 CommonError::<Test>::PublicMintingNotAllowed
1609 );2109 );
1610 });2110 });
1611}2111}
1614#[test]2114#[test]
1615fn allow_list_test_13() {2115fn allow_list_test_13() {
1616 new_test_ext().execute_with(|| {2116 new_test_ext().execute_with(|| {
1617 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2117 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
16182118
1619 let origin1 = Origin::signed(1);2119 let origin1 = Origin::signed(1);
16202120
1638#[test]2138#[test]
1639fn allow_list_test_14() {2139fn allow_list_test_14() {
1640 new_test_ext().execute_with(|| {2140 new_test_ext().execute_with(|| {
1641 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2141 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
16422142
1643 let origin1 = Origin::signed(1);2143 let origin1 = Origin::signed(1);
1644 let origin2 = Origin::signed(2);2144 let origin2 = Origin::signed(2);
16622162
1663 assert_ok!(TemplateModule::create_item(2163 assert_ok!(TemplateModule::create_item(
1664 origin2,2164 origin2,
1665 1,2165 collection_id,
1666 account(2),2166 account(2),
1667 default_nft_data().into()2167 default_nft_data().into()
1668 ));2168 ));
1673#[test]2173#[test]
1674fn allow_list_test_15() {2174fn allow_list_test_15() {
1675 new_test_ext().execute_with(|| {2175 new_test_ext().execute_with(|| {
1676 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2176 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
16772177
1678 let origin1 = Origin::signed(1);2178 let origin1 = Origin::signed(1);
1679 let origin2 = Origin::signed(2);2179 let origin2 = Origin::signed(2);
1690 ));2190 ));
16912191
1692 assert_noop!(2192 assert_noop!(
1693 TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),2193 TemplateModule::create_item(
2194 origin2,
2195 collection_id,
2196 account(2),
2197 default_nft_data().into()
2198 )
2199 .map_err(|e| e.error),
1694 Error::<Test>::AddresNotInAllowList2200 CommonError::<Test>::AddressNotInAllowlist
1695 );2201 );
1696 });2202 });
1697}2203}
1700#[test]2206#[test]
1701fn allow_list_test_16() {2207fn allow_list_test_16() {
1702 new_test_ext().execute_with(|| {2208 new_test_ext().execute_with(|| {
1703 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2209 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
17042210
1705 let origin1 = Origin::signed(1);2211 let origin1 = Origin::signed(1);
1706 let origin2 = Origin::signed(2);2212 let origin2 = Origin::signed(2);
17232229
1724 assert_ok!(TemplateModule::create_item(2230 assert_ok!(TemplateModule::create_item(
1725 origin2,2231 origin2,
1726 1,2232 collection_id,
1727 account(2),2233 account(2),
1728 default_nft_data().into()2234 default_nft_data().into()
1729 ));2235 ));
1734#[test]2240#[test]
1735fn total_number_collections_bound() {2241fn total_number_collections_bound() {
1736 new_test_ext().execute_with(|| {2242 new_test_ext().execute_with(|| {
1737 create_test_collection(&CollectionMode::NFT, 1);2243 create_test_collection(&CollectionMode::NFT, CollectionId(1));
1738 });2244 });
1739}2245}
17402246
1741// Total number of collections. Negotive test
1742#[test]2247#[test]
2248fn create_max_collections() {
2249 new_test_ext().execute_with(|| {
2250 for i in 1..=COLLECTION_NUMBER_LIMIT {
2251 create_test_collection(&CollectionMode::NFT, CollectionId(i));
2252 }
2253 });
2254}
2255
2256// Total number of collections. Negative test
2257#[test]
1743fn total_number_collections_bound_neg() {2258fn total_number_collections_bound_neg() {
1744 new_test_ext().execute_with(|| {2259 new_test_ext().execute_with(|| {
1745 let origin1 = Origin::signed(1);2260 let origin1 = Origin::signed(1);
17462261
1747 for i in 0..COLLECTION_NUMBER_LIMIT {2262 for i in 1..=COLLECTION_NUMBER_LIMIT {
1748 create_test_collection(&CollectionMode::NFT, i + 1);2263 create_test_collection(&CollectionMode::NFT, CollectionId(i));
1749 }2264 }
17502265
1751 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();2266 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
1761 token_prefix1,2276 token_prefix1,
1762 CollectionMode::NFT2277 CollectionMode::NFT
1763 ),2278 ),
1764 Error::<Test>::TotalCollectionsLimitExceeded2279 CommonError::<Test>::TotalCollectionsLimitExceeded
1765 );2280 );
1766 });2281 });
1767}2282}
1770#[test]2285#[test]
1771fn owned_tokens_bound() {2286fn owned_tokens_bound() {
1772 new_test_ext().execute_with(|| {2287 new_test_ext().execute_with(|| {
1773 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2288 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
17742289
1775 let data = default_nft_data();2290 let data = default_nft_data();
1776 create_test_item(collection_id, &data.clone().into());2291 create_test_item(collection_id, &data.clone().into());
1782#[test]2297#[test]
1783fn owned_tokens_bound_neg() {2298fn owned_tokens_bound_neg() {
1784 new_test_ext().execute_with(|| {2299 new_test_ext().execute_with(|| {
1785 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2300 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
17862301
1787 let origin1 = Origin::signed(1);2302 let origin1 = Origin::signed(1);
17882303
1789 for _ in 0..ACCOUNT_TOKEN_OWNERSHIP_LIMIT {2304 for _ in 1..=MAX_TOKEN_OWNERSHIP {
1790 let data = default_nft_data();2305 let data = default_nft_data();
1791 create_test_item(collection_id, &data.clone().into());2306 create_test_item(collection_id, &data.clone().into());
1792 }2307 }
17932308
1794 let data = default_nft_data();2309 let data = default_nft_data();
1795 assert_noop!(2310 assert_noop!(
1796 TemplateModule::create_item(origin1, 1, account(1), data.into()),2311 TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into())
2312 .map_err(|e| e.error),
1797 Error::<Test>::AccountTokenLimitExceeded2313 CommonError::<Test>::AccountTokenLimitExceeded
1798 );2314 );
1799 });2315 });
1800}2316}
1803#[test]2319#[test]
1804fn collection_admins_bound() {2320fn collection_admins_bound() {
1805 new_test_ext().execute_with(|| {2321 new_test_ext().execute_with(|| {
1806 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2322 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
18072323
1808 let origin1 = Origin::signed(1);2324 let origin1 = Origin::signed(1);
18092325
1824#[test]2340#[test]
1825fn collection_admins_bound_neg() {2341fn collection_admins_bound_neg() {
1826 new_test_ext().execute_with(|| {2342 new_test_ext().execute_with(|| {
1827 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2343 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
18282344
1829 let origin1 = Origin::signed(1);2345 let origin1 = Origin::signed(1);
18302346
1831 for i in 0..COLLECTION_ADMINS_LIMIT {2347 for i in 0..COLLECTION_ADMINS_LIMIT {
1832 assert_ok!(TemplateModule::add_collection_admin(2348 assert_ok!(TemplateModule::add_collection_admin(
1833 origin1.clone(),2349 origin1.clone(),
1834 collection_id,2350 collection_id,
1835 account(2 + i)2351 account((2 + i).into())
1836 ));2352 ));
1837 }2353 }
1838 assert_noop!(2354 assert_noop!(
1839 TemplateModule::add_collection_admin(2355 TemplateModule::add_collection_admin(
1840 origin1,2356 origin1,
1841 collection_id,2357 collection_id,
1842 account(3 + COLLECTION_ADMINS_LIMIT)2358 account((3 + COLLECTION_ADMINS_LIMIT).into())
1843 ),2359 ),
1844 Error::<Test>::CollectionAdminsLimitExceeded2360 CommonError::<Test>::CollectionAdminCountExceeded
1845 );2361 );
1846 });2362 });
1847}2363}
1850#[test]2366#[test]
1851fn set_const_on_chain_schema() {2367fn set_const_on_chain_schema() {
1852 new_test_ext().execute_with(|| {2368 new_test_ext().execute_with(|| {
1853 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2369 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
18542370
1855 let origin1 = Origin::signed(1);2371 let origin1 = Origin::signed(1);
1856 assert_ok!(TemplateModule::set_const_on_chain_schema(2372 assert_ok!(TemplateModule::set_const_on_chain_schema(
1860 ));2376 ));
18612377
1862 assert_eq!(2378 assert_eq!(
1863 TemplateModule::collection_id(collection_id)2379 <pallet_common::CollectionById<Test>>::get(collection_id)
1864 .unwrap()2380 .unwrap()
1865 .const_on_chain_schema,2381 .const_on_chain_schema,
1866 b"test const on chain schema".to_vec()2382 b"test const on chain schema".to_vec()
1867 );2383 );
1868 assert_eq!(2384 assert_eq!(
1869 TemplateModule::collection_id(collection_id)2385 <pallet_common::CollectionById<Test>>::get(collection_id)
1870 .unwrap()2386 .unwrap()
1871 .variable_on_chain_schema,2387 .variable_on_chain_schema,
1872 b"".to_vec()2388 b"".to_vec()
1877#[test]2393#[test]
1878fn set_variable_on_chain_schema() {2394fn set_variable_on_chain_schema() {
1879 new_test_ext().execute_with(|| {2395 new_test_ext().execute_with(|| {
1880 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2396 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
18812397
1882 let origin1 = Origin::signed(1);2398 let origin1 = Origin::signed(1);
1883 assert_ok!(TemplateModule::set_variable_on_chain_schema(2399 assert_ok!(TemplateModule::set_variable_on_chain_schema(
1887 ));2403 ));
18882404
1889 assert_eq!(2405 assert_eq!(
1890 TemplateModule::collection_id(collection_id)2406 <pallet_common::CollectionById<Test>>::get(collection_id)
1891 .unwrap()2407 .unwrap()
1892 .const_on_chain_schema,2408 .const_on_chain_schema,
1893 b"".to_vec()2409 b"".to_vec()
1894 );2410 );
1895 assert_eq!(2411 assert_eq!(
1896 TemplateModule::collection_id(collection_id)2412 <pallet_common::CollectionById<Test>>::get(collection_id)
1897 .unwrap()2413 .unwrap()
1898 .variable_on_chain_schema,2414 .variable_on_chain_schema,
1899 b"test variable on chain schema".to_vec()2415 b"test variable on chain schema".to_vec()
1904#[test]2420#[test]
1905fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {2421fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {
1906 new_test_ext().execute_with(|| {2422 new_test_ext().execute_with(|| {
1907 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2423 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
19082424
1909 let origin1 = Origin::signed(1);2425 let origin1 = Origin::signed(1);
19102426
1911 let data = default_nft_data();2427 let data = default_nft_data();
1912 create_test_item(1, &data.into());2428 create_test_item(CollectionId(1), &data.into());
19132429
1914 let variable_data = b"test data".to_vec();2430 let variable_data = b"test data".to_vec();
1915 assert_ok!(TemplateModule::set_variable_meta_data(2431 assert_ok!(TemplateModule::set_variable_meta_data(
1916 origin1,2432 origin1,
1917 collection_id,2433 collection_id,
1918 1,2434 TokenId(1),
1919 variable_data.clone()2435 variable_data.clone()
1920 ));2436 ));
19212437
1922 assert_eq!(2438 assert_eq!(
1923 TemplateModule::nft_item_id(collection_id, 1)2439 <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))
1924 .unwrap()2440 .unwrap()
1925 .variable_data,2441 .variable_data,
1926 variable_data2442 variable_data
1931#[test]2447#[test]
1932fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {2448fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {
1933 new_test_ext().execute_with(|| {2449 new_test_ext().execute_with(|| {
1934 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);2450 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
19352451
1936 let origin1 = Origin::signed(1);2452 let origin1 = Origin::signed(1);
19372453
1938 let data = default_re_fungible_data();2454 let data = default_re_fungible_data();
1939 create_test_item(1, &data.into());2455 create_test_item(collection_id, &data.into());
19402456
1941 let variable_data = b"test data".to_vec();2457 let variable_data = b"test data".to_vec();
1942 assert_ok!(TemplateModule::set_variable_meta_data(2458 assert_ok!(TemplateModule::set_variable_meta_data(
1943 origin1,2459 origin1,
1944 collection_id,2460 collection_id,
1945 1,2461 TokenId(1),
1946 variable_data.clone()2462 variable_data.clone()
1947 ));2463 ));
19482464
1949 assert_eq!(2465 assert_eq!(
1950 TemplateModule::refungible_item_id(collection_id, 1)2466 <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1))).variable_data,
1951 .unwrap()
1952 .variable_data,
1953 variable_data2467 variable_data
1954 );2468 );
1955 });2469 });
1958#[test]2472#[test]
1959fn set_variable_meta_data_on_fungible_token_fails() {2473fn set_variable_meta_data_on_fungible_token_fails() {
1960 new_test_ext().execute_with(|| {2474 new_test_ext().execute_with(|| {
1961 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);2475 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
19622476
1963 let origin1 = Origin::signed(1);2477 let origin1 = Origin::signed(1);
19642478
1965 let data = default_fungible_data();2479 let data = default_fungible_data();
1966 create_test_item(1, &data.into());2480 create_test_item(collection_id, &data.into());
19672481
1968 let variable_data = b"test data".to_vec();2482 let variable_data = b"test data".to_vec();
1969 assert_noop!(2483 assert_noop!(
1970 TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),2484 TemplateModule::set_variable_meta_data(
2485 origin1,
2486 collection_id,
2487 TokenId(0),
2488 variable_data
2489 )
2490 .map_err(|e| e.error),
1971 Error::<Test>::CantStoreMetadataInFungibleTokens2491 <pallet_fungible::Error<Test>>::FungibleItemsDontHaveData
1972 );2492 );
1973 });2493 });
1974}2494}
19752495
1976#[test]2496#[test]
1977fn set_variable_meta_data_on_nft_token_fails_for_big_data() {2497fn set_variable_meta_data_on_nft_token_fails_for_big_data() {
1978 new_test_ext().execute_with(|| {2498 new_test_ext().execute_with(|| {
1979 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2499 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
19802500
1981 let origin1 = Origin::signed(1);2501 let origin1 = Origin::signed(1);
19822502
1983 let data = default_nft_data();2503 let data = default_nft_data();
1984 create_test_item(1, &data.into());2504 create_test_item(collection_id, &data.into());
19852505
1986 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();2506 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();
1987 assert_noop!(2507 assert_noop!(
1988 TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),2508 TemplateModule::set_variable_meta_data(
2509 origin1,
2510 collection_id,
2511 TokenId(1),
2512 variable_data
2513 )
2514 .map_err(|e| e.error),
1989 Error::<Test>::TokenVariableDataLimitExceeded2515 CommonError::<Test>::TokenVariableDataLimitExceeded
1990 );2516 );
1991 });2517 });
1992}2518}
19932519
1994#[test]2520#[test]
1995fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {2521fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {
1996 new_test_ext().execute_with(|| {2522 new_test_ext().execute_with(|| {
1997 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);2523 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
19982524
1999 let origin1 = Origin::signed(1);2525 let origin1 = Origin::signed(1);
20002526
2001 let data = default_re_fungible_data();2527 let data = default_re_fungible_data();
2002 create_test_item(1, &data.into());2528 create_test_item(collection_id, &data.into());
20032529
2004 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();2530 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();
2005 assert_noop!(2531 assert_noop!(
2006 TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),2532 TemplateModule::set_variable_meta_data(
2533 origin1,
2534 collection_id,
2535 TokenId(1),
2536 variable_data
2537 )
2538 .map_err(|e| e.error),
2007 Error::<Test>::TokenVariableDataLimitExceeded2539 CommonError::<Test>::TokenVariableDataLimitExceeded
2008 );2540 );
2009 });2541 });
2010}2542}
2014 new_test_ext().execute_with(|| {2546 new_test_ext().execute_with(|| {
2015 //default_limits();2547 //default_limits();
20162548
2017 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2549 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
20182550
2019 let origin1 = Origin::signed(1);2551 let origin1 = Origin::signed(1);
20202552
2021 let data = default_nft_data();2553 let data = default_nft_data();
2022 create_test_item(1, &data.into());2554 create_test_item(collection_id, &data.into());
20232555
2024 assert_ok!(TemplateModule::set_meta_update_permission_flag(2556 assert_ok!(TemplateModule::set_meta_update_permission_flag(
2025 origin1.clone(),2557 origin1.clone(),
2031 assert_ok!(TemplateModule::set_variable_meta_data(2563 assert_ok!(TemplateModule::set_variable_meta_data(
2032 origin1,2564 origin1,
2033 collection_id,2565 collection_id,
2034 1,2566 TokenId(1),
2035 variable_data.clone()2567 variable_data.clone()
2036 ));2568 ));
20372569
2038 assert_eq!(2570 assert_eq!(
2039 TemplateModule::nft_item_id(collection_id, 1)2571 <pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))
2040 .unwrap()2572 .unwrap()
2041 .variable_data,2573 .variable_data,
2042 variable_data2574 variable_data
2047#[test]2579#[test]
2048fn set_variable_meta_data_on_nft_with_item_owner_permission_flag_neg() {2580fn set_variable_meta_data_on_nft_with_item_owner_permission_flag_neg() {
2049 new_test_ext().execute_with(|| {2581 new_test_ext().execute_with(|| {
2050 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);2582 let collection_id =
2583 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
20512584
2052 let origin1 = Origin::signed(1);2585 let origin1 = Origin::signed(1);
20532586
2063 ));2596 ));
20642597
2065 let data = default_nft_data();2598 let data = default_nft_data();
2066 create_test_item(1, &data.into());2599 create_test_item(collection_id, &data.into());
20672600
2068 assert_ok!(TemplateModule::set_meta_update_permission_flag(2601 assert_ok!(TemplateModule::set_meta_update_permission_flag(
2069 origin1.clone(),2602 origin1.clone(),
2076 TemplateModule::set_variable_meta_data(2609 TemplateModule::set_variable_meta_data(
2077 origin1,2610 origin1,
2078 collection_id,2611 collection_id,
2079 1,2612 TokenId(1),
2080 variable_data.clone()2613 variable_data.clone()
2081 ),2614 )
2615 .map_err(|e| e.error),
2082 Error::<Test>::TokenVariableDataLimitExceeded2616 CommonError::<Test>::TokenVariableDataLimitExceeded
2083 );2617 );
2084 })2618 })
2085}2619}
2089 new_test_ext().execute_with(|| {2623 new_test_ext().execute_with(|| {
2090 let origin1 = Origin::signed(1);2624 let origin1 = Origin::signed(1);
20912625
2092 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2626 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
2093 assert_ok!(TemplateModule::set_transfers_enabled_flag(origin1, 1, true));2627 assert_ok!(TemplateModule::set_transfers_enabled_flag(
2628 origin1,
2629 collection_id,
2630 true
2631 ));
20942632
2095 let data = default_nft_data();2633 let data = default_nft_data();
2096 create_test_item(collection_id, &data.into());2634 create_test_item(collection_id, &data.into());
2097 assert_eq!(TemplateModule::balance_count(1, 1), 1);2635 assert_eq!(
2636 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
2637 1
2638 );
2098 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);2639 assert_eq!(
2640 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
2641 true
2642 );
20992643
2100 let origin1 = Origin::signed(1);2644 let origin1 = Origin::signed(1);
21012645
2102 // default scenario2646 // default scenario
2103 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));2647 assert_ok!(TemplateModule::transfer(
2648 origin1,
2649 account(2),
2650 collection_id,
2651 TokenId(1),
2652 1
2653 ));
2104 assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));2654 assert_eq!(
2655 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
2656 false
2657 );
2105 assert_eq!(TemplateModule::balance_count(1, 1), 0);2658 assert_eq!(
2659 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),
2660 true
2661 );
2106 assert_eq!(TemplateModule::balance_count(1, 2), 1);2662 assert_eq!(
21072663 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
2664 0
2665 );
2108 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);2666 assert_eq!(
2667 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),
2668 1
2669 );
2109 });2670 });
2110}2671}
21112672
2114 new_test_ext().execute_with(|| {2675 new_test_ext().execute_with(|| {
2115 // default_limits();2676 // default_limits();
21162677
2117 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);2678 let collection_id =
2679 create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));
21182680
2119 let origin1 = Origin::signed(1);2681 let origin1 = Origin::signed(1);
2120 let origin2 = Origin::signed(2);2682 let origin2 = Origin::signed(2);
2137 ));2699 ));
21382700
2139 let data = default_nft_data();2701 let data = default_nft_data();
2140 create_test_item(1, &data.into());2702 create_test_item(collection_id, &data.into());
21412703
2142 assert_ok!(TemplateModule::set_meta_update_permission_flag(2704 assert_ok!(TemplateModule::set_meta_update_permission_flag(
2143 origin2.clone(),2705 origin2.clone(),
2149 assert_ok!(TemplateModule::set_variable_meta_data(2711 assert_ok!(TemplateModule::set_variable_meta_data(
2150 origin1,2712 origin1,
2151 collection_id,2713 collection_id,
2152 1,2714 TokenId(1),
2153 variable_data.clone()2715 variable_data.clone()
2154 ));2716 ));
21552717
2156 assert_eq!(2718 assert_eq!(
2157 TemplateModule::nft_item_id(collection_id, 1)2719 <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))
2158 .unwrap()2720 .unwrap()
2159 .variable_data,2721 .variable_data,
2160 variable_data2722 variable_data
2167 new_test_ext().execute_with(|| {2729 new_test_ext().execute_with(|| {
2168 // default_limits();2730 // default_limits();
21692731
2170 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);2732 let collection_id =
2733 create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));
21712734
2172 let origin1 = Origin::signed(1);2735 let origin1 = Origin::signed(1);
2173 let origin2 = Origin::signed(2);2736 let origin2 = Origin::signed(2);
2184 ));2747 ));
21852748
2186 let data = default_nft_data();2749 let data = default_nft_data();
2187 create_test_item(1, &data.into());2750 create_test_item(collection_id, &data.into());
21882751
2189 assert_ok!(TemplateModule::set_meta_update_permission_flag(2752 assert_ok!(TemplateModule::set_meta_update_permission_flag(
2190 origin2.clone(),2753 origin2.clone(),
2197 TemplateModule::set_variable_meta_data(2760 TemplateModule::set_variable_meta_data(
2198 origin1,2761 origin1,
2199 collection_id,2762 collection_id,
2200 1,2763 TokenId(1),
2201 variable_data.clone()2764 variable_data.clone()
2202 ),2765 )
2766 .map_err(|e| e.error),
2203 Error::<Test>::NoPermission2767 CommonError::<Test>::NoPermission
2204 );2768 );
2205 });2769 });
2206}2770}
2210 new_test_ext().execute_with(|| {2774 new_test_ext().execute_with(|| {
2211 // default_limits();2775 // default_limits();
22122776
2213 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);2777 let collection_id =
2778 create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));
22142779
2215 let origin2 = Origin::signed(2);2780 let origin2 = Origin::signed(2);
22162781
2225 collection_id,2790 collection_id,
2226 MetaUpdatePermission::Admin2791 MetaUpdatePermission::Admin
2227 ),2792 ),
2228 Error::<Test>::MetadataFlagFrozen2793 CommonError::<Test>::MetadataFlagFrozen
2229 );2794 );
2230 });2795 });
2231}2796}
2235 new_test_ext().execute_with(|| {2800 new_test_ext().execute_with(|| {
2236 // default_limits();2801 // default_limits();
22372802
2238 let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);2803 let collection_id =
2804 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
2239 let origin1 = Origin::signed(1);2805 let origin1 = Origin::signed(1);
22402806
2241 let data = default_nft_data();2807 let data = default_nft_data();
2242 create_test_item(1, &data.into());2808 create_test_item(collection_id, &data.into());
22432809
2244 assert_ok!(TemplateModule::set_meta_update_permission_flag(2810 assert_ok!(TemplateModule::set_meta_update_permission_flag(
2245 origin1.clone(),2811 origin1.clone(),
2252 TemplateModule::set_variable_meta_data(2818 TemplateModule::set_variable_meta_data(
2253 origin1.clone(),2819 origin1.clone(),
2254 collection_id,2820 collection_id,
2255 1,2821 TokenId(1),
2256 variable_data.clone()2822 variable_data.clone()
2257 ),2823 )
2824 .map_err(|e| e.error),
2258 Error::<Test>::MetadataUpdateDenied2825 CommonError::<Test>::NoPermission
2259 );2826 );
2260 });2827 });
2261}2828}
2265 new_test_ext().execute_with(|| {2832 new_test_ext().execute_with(|| {
2266 let origin1 = Origin::signed(1);2833 let origin1 = Origin::signed(1);
22672834
2268 let collection_id = create_test_collection(&CollectionMode::NFT, 1);2835 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
2269 assert_ok!(TemplateModule::set_transfers_enabled_flag(2836 assert_ok!(TemplateModule::set_transfers_enabled_flag(
2270 origin1, 1, false2837 origin1,
2838 collection_id,
2839 false
2271 ));2840 ));
22722841
2273 let data = default_nft_data();2842 let data = default_nft_data();
2274 create_test_item(collection_id, &data.into());2843 create_test_item(collection_id, &data.into());
2275 assert_eq!(TemplateModule::balance_count(1, 1), 1);2844 assert_eq!(
2845 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
2846 1
2847 );
2276 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);2848 assert_eq!(
2849 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
2850 true
2851 );
22772852
2278 let origin1 = Origin::signed(1);2853 let origin1 = Origin::signed(1);
22792854
2280 // default scenario2855 // default scenario
2281 assert_noop!(2856 assert_noop!(
2282 TemplateModule::transfer(origin1, account(2), 1, 1, 1000),2857 TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)
2858 .map_err(|e| e.error),
2283 Error::<Test>::TransferNotAllowed2859 CommonError::<Test>::TransferNotAllowed
2284 );2860 );
2285 assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(1));2861 assert_eq!(
2862 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),
2863 1
2864 );
2286 assert_eq!(TemplateModule::balance_count(1, 1), 1);2865 assert_eq!(
2866 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),
2867 0
2868 );
2287 assert_eq!(TemplateModule::balance_count(1, 2), 0);2869 assert_eq!(
22882870 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),
2871 true
2289 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);2872 );
2873 assert_eq!(
2874 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),
2875 false
2876 );
2290 });2877 });
2291}2878}
22922879
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
30pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;30pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;
31pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;31pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;
32
32pub const MAX_TOKEN_OWNERSHIP: u32 = 10_000_000;33pub const MAX_TOKEN_OWNERSHIP: u32 = if cfg!(not(feature = "limit-testing")) {
3334 10_000_000
35} else {
36 10
37};
34pub const COLLECTION_NUMBER_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {38pub const COLLECTION_NUMBER_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {
35 10000039 100_000
36} else {40} else {
37 1041 10
38};42};
44pub const COLLECTION_ADMINS_LIMIT: u32 = 5;48pub const COLLECTION_ADMINS_LIMIT: u32 = 5;
45pub const COLLECTION_TOKEN_LIMIT: u32 = u32::MAX;49pub const COLLECTION_TOKEN_LIMIT: u32 = u32::MAX;
46pub const ACCOUNT_TOKEN_OWNERSHIP_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {50pub const ACCOUNT_TOKEN_OWNERSHIP_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {
47 100000051 1_000_000
48} else {52} else {
49 1053 10
50};54};