difftreelog
Merge branch 'develop' into feature/transferfromtests
in: master
43 files changed
.devcontainer/Dockerfilediffbeforeafterbothno changes
.devcontainer/devcontainer.jsondiffbeforeafterbothno changes
Cargo.lockdiffbeforeafterboth543543544[[package]]544[[package]]545name = "bumpalo"545name = "bumpalo"546version = "3.5.0"546version = "3.6.0"547source = "registry+https://github.com/rust-lang/crates.io-index"547source = "registry+https://github.com/rust-lang/crates.io-index"548checksum = "f07aa6688c702439a1be0307b6a94dffe1168569e45b9500c1372bc580740d59"548checksum = "099e596ef14349721d9016f6b80dd3419ea1bf289ab9b44df8e4dfd3a005d5d9"549549550[[package]]550[[package]]551name = "byte-slice-cast"551name = "byte-slice-cast"985985986[[package]]986[[package]]987name = "ctor"987name = "ctor"988version = "0.1.18"988version = "0.1.19"989source = "registry+https://github.com/rust-lang/crates.io-index"989source = "registry+https://github.com/rust-lang/crates.io-index"990checksum = "10bcb9d7dcbf7002aaffbb53eac22906b64cdcc127971dcc387d8eb7c95d5560"990checksum = "e8f45d9ad417bcef4817d614a501ab55cdd96a6fdb24f49aab89a54acfd66b19"991dependencies = [991dependencies = [992 "quote",992 "quote",993 "syn",993 "syn",103210321033[[package]]1033[[package]]1034name = "data-encoding"1034name = "data-encoding"1035version = "2.3.1"1035version = "2.3.2"1036source = "registry+https://github.com/rust-lang/crates.io-index"1036source = "registry+https://github.com/rust-lang/crates.io-index"1037checksum = "993a608597367c6377b258c25d7120740f00ed23a2252b729b1932dd7866f908"1037checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57"103810381039[[package]]1039[[package]]1040name = "derive_more"1040name = "derive_more"1151 "ed25519",1151 "ed25519",1152 "rand 0.7.3",1152 "rand 0.7.3",1153 "serde",1153 "serde",1154 "sha2 0.9.2",1154 "sha2 0.9.3",1155 "zeroize",1155 "zeroize",1156]1156]11571157134213421343[[package]]1343[[package]]1344name = "flate2"1344name = "flate2"1345version = "1.0.19"1345version = "1.0.20"1346source = "registry+https://github.com/rust-lang/crates.io-index"1346source = "registry+https://github.com/rust-lang/crates.io-index"1347checksum = "7411863d55df97a419aa64cb4d2f167103ea9d767e2c54a1868b7ac3f6b47129"1347checksum = "cd3aec53de10fe96d7d8c565eb17f2c687bb5518a2ec453b5b1252964526abe0"1348dependencies = [1348dependencies = [1349 "cfg-if 1.0.0",1349 "cfg-if 1.0.0",1350 "crc32fast",1350 "crc32fast",1907 "http 0.2.3",1907 "http 0.2.3",1908 "indexmap",1908 "indexmap",1909 "slab",1909 "slab",1910 "tokio 0.2.24",1910 "tokio 0.2.25",1911 "tokio-util",1911 "tokio-util",1912 "tracing",1912 "tracing",1913 "tracing-futures",1913 "tracing-futures",206420642065[[package]]2065[[package]]2066name = "httparse"2066name = "httparse"2067version = "1.3.4"2067version = "1.3.5"2068source = "registry+https://github.com/rust-lang/crates.io-index"2068source = "registry+https://github.com/rust-lang/crates.io-index"2069checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9"2069checksum = "615caabe2c3160b313d52ccc905335f4ed5f10881dd63dc5699d47e90be85691"207020702071[[package]]2071[[package]]2072name = "httpdate"2072name = "httpdate"2129 "httparse",2129 "httparse",2130 "httpdate",2130 "httpdate",2131 "itoa",2131 "itoa",2132 "pin-project 1.0.4",2132 "pin-project 1.0.5",2133 "socket2",2133 "socket2",2134 "tokio 0.2.24",2134 "tokio 0.2.25",2135 "tower-service",2135 "tower-service",2136 "tracing",2136 "tracing",2137 "want 0.3.0",2137 "want 0.3.0",2150 "log",2150 "log",2151 "rustls 0.18.1",2151 "rustls 0.18.1",2152 "rustls-native-certs",2152 "rustls-native-certs",2153 "tokio 0.2.24",2153 "tokio 0.2.25",2154 "tokio-rustls",2154 "tokio-rustls",2155 "webpki",2155 "webpki",2156]2156]255325532554[[package]]2554[[package]]2555name = "libc"2555name = "libc"2556version = "0.2.82"2556version = "0.2.85"2557source = "registry+https://github.com/rust-lang/crates.io-index"2557source = "registry+https://github.com/rust-lang/crates.io-index"2558checksum = "89203f3fba0a3795506acaad8ebce3c80c0af93f994d5a1d7a0b1eeb23271929"2558checksum = "7ccac4b00700875e6a07c6cde370d44d32fa01c5a65cdd2fca6858c479d28bb3"255925592560[[package]]2560[[package]]2561name = "libloading"2561name = "libloading"2606 "libp2p-yamux",2606 "libp2p-yamux",2607 "parity-multiaddr",2607 "parity-multiaddr",2608 "parking_lot 0.11.1",2608 "parking_lot 0.11.1",2609 "pin-project 1.0.4",2609 "pin-project 1.0.5",2610 "smallvec 1.6.1",2610 "smallvec 1.6.1",2611 "wasm-timer",2611 "wasm-timer",2612]2612]2631 "multistream-select",2631 "multistream-select",2632 "parity-multiaddr",2632 "parity-multiaddr",2633 "parking_lot 0.11.1",2633 "parking_lot 0.11.1",2634 "pin-project 1.0.4",2634 "pin-project 1.0.5",2635 "prost",2635 "prost",2636 "prost-build",2636 "prost-build",2637 "rand 0.7.3",2637 "rand 0.7.3",2638 "ring",2638 "ring",2639 "rw-stream-sink",2639 "rw-stream-sink",2640 "sha2 0.9.2",2640 "sha2 0.9.3",2641 "smallvec 1.6.1",2641 "smallvec 1.6.1",2642 "thiserror",2642 "thiserror",2643 "unsigned-varint 0.6.0",2643 "unsigned-varint 0.6.0",2715 "prost-build",2715 "prost-build",2716 "rand 0.7.3",2716 "rand 0.7.3",2717 "regex",2717 "regex",2718 "sha2 0.9.2",2718 "sha2 0.9.3",2719 "smallvec 1.6.1",2719 "smallvec 1.6.1",2720 "unsigned-varint 0.6.0",2720 "unsigned-varint 0.6.0",2721 "wasm-timer",2721 "wasm-timer",2755 "prost",2755 "prost",2756 "prost-build",2756 "prost-build",2757 "rand 0.7.3",2757 "rand 0.7.3",2758 "sha2 0.9.2",2758 "sha2 0.9.3",2759 "smallvec 1.6.1",2759 "smallvec 1.6.1",2760 "uint",2760 "uint",2761 "unsigned-varint 0.6.0",2761 "unsigned-varint 0.6.0",2817 "prost",2817 "prost",2818 "prost-build",2818 "prost-build",2819 "rand 0.7.3",2819 "rand 0.7.3",2820 "sha2 0.9.2",2820 "sha2 0.9.3",2821 "snow",2821 "snow",2822 "static_assertions",2822 "static_assertions",2823 "x25519-dalek",2823 "x25519-dalek",2864dependencies = [2864dependencies = [2865 "futures 0.3.12",2865 "futures 0.3.12",2866 "log",2866 "log",2867 "pin-project 1.0.4",2867 "pin-project 1.0.5",2868 "rand 0.7.3",2868 "rand 0.7.3",2869 "salsa20",2869 "salsa20",2870 "sha3",2870 "sha3",289228922893[[package]]2893[[package]]2894name = "libp2p-swarm"2894name = "libp2p-swarm"2895version = "0.27.1"2895version = "0.27.2"2896source = "registry+https://github.com/rust-lang/crates.io-index"2896source = "registry+https://github.com/rust-lang/crates.io-index"2897checksum = "d4f89ebb4d8953bda12623e9871959fe728dea3bf6eae0421dc9c42dc821e488"2897checksum = "7955b973e1fd2bd61ffd43ce261c1223f61f4aacd5bae362a924993f9a25fd98"2898dependencies = [2898dependencies = [2899 "either",2899 "either",2900 "futures 0.3.12",2900 "futures 0.3.12",307430743075[[package]]3075[[package]]3076name = "lru"3076name = "lru"3077version = "0.6.3"3077version = "0.6.4"3078source = "registry+https://github.com/rust-lang/crates.io-index"3078source = "registry+https://github.com/rust-lang/crates.io-index"3079checksum = "3aae342b73d57ad0b8b364bd12584819f2c1fe9114285dfcf8b0722607671635"3079checksum = "fe2382d8ed3918ea4ba70d98d5b74e47a168e0331965f3f17cdbc748bdebc5a3"3080dependencies = [3080dependencies = [3081 "hashbrown",3081 "hashbrown",3082]3082]3310 "digest 0.9.0",3310 "digest 0.9.0",3311 "generic-array 0.14.4",3311 "generic-array 0.14.4",3312 "multihash-derive",3312 "multihash-derive",3313 "sha2 0.9.2",3313 "sha2 0.9.3",3314 "unsigned-varint 0.5.1",3314 "unsigned-varint 0.5.1",3315]3315]331633163343 "bytes 1.0.1",3343 "bytes 1.0.1",3344 "futures 0.3.12",3344 "futures 0.3.12",3345 "log",3345 "log",3346 "pin-project 1.0.4",3346 "pin-project 1.0.5",3347 "smallvec 1.6.1",3347 "smallvec 1.6.1",3348 "unsigned-varint 0.6.0",3348 "unsigned-varint 0.6.0",3349]3349]426942694270[[package]]4270[[package]]4271name = "pin-project"4271name = "pin-project"4272version = "1.0.4"4272version = "1.0.5"4273source = "registry+https://github.com/rust-lang/crates.io-index"4273source = "registry+https://github.com/rust-lang/crates.io-index"4274checksum = "95b70b68509f17aa2857863b6fa00bf21fc93674c7a8893de2f469f6aa7ca2f2"4274checksum = "96fa8ebb90271c4477f144354485b8068bd8f6b78b428b01ba892ca26caf0b63"4275dependencies = [4275dependencies = [4276 "pin-project-internal 1.0.4",4276 "pin-project-internal 1.0.5",4277]4277]427842784279[[package]]4279[[package]]428942894290[[package]]4290[[package]]4291name = "pin-project-internal"4291name = "pin-project-internal"4292version = "1.0.4"4292version = "1.0.5"4293source = "registry+https://github.com/rust-lang/crates.io-index"4293source = "registry+https://github.com/rust-lang/crates.io-index"4294checksum = "caa25a6393f22ce819b0f50e0be89287292fda8d425be38ee0ca14c4931d9e71"4294checksum = "758669ae3558c6f74bd2a18b41f7ac0b5a195aea6639d6a9b5e5d1ad5ba24c0b"4295dependencies = [4295dependencies = [4296 "proc-macro2",4296 "proc-macro2",4297 "quote",4297 "quote",486248624863[[package]]4863[[package]]4864name = "ring"4864name = "ring"4865version = "0.16.19"4865version = "0.16.20"4866source = "registry+https://github.com/rust-lang/crates.io-index"4866source = "registry+https://github.com/rust-lang/crates.io-index"4867checksum = "024a1e66fea74c66c66624ee5622a7ff0e4b73a13b4f5c326ddb50c708944226"4867checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc"4868dependencies = [4868dependencies = [4869 "cc",4869 "cc",4870 "libc",4870 "libc",5114 "structopt",5114 "structopt",5115 "thiserror",5115 "thiserror",5116 "tiny-bip39",5116 "tiny-bip39",5117 "tokio 0.2.24",5117 "tokio 0.2.25",5118]5118]511951195120[[package]]5120[[package]]603760376038[[package]]6038[[package]]6039name = "sha-1"6039name = "sha-1"6040version = "0.9.2"6040version = "0.9.3"6041source = "registry+https://github.com/rust-lang/crates.io-index"6041source = "registry+https://github.com/rust-lang/crates.io-index"6042checksum = "ce3cdf1b5e620a498ee6f2a171885ac7e22f0e12089ec4b3d22b84921792507c"6042checksum = "f4b312c3731e3fe78a185e6b9b911a7aa715b8e31cce117975219aab2acf285d"6043dependencies = [6043dependencies = [6044 "block-buffer 0.9.0",6044 "block-buffer 0.9.0",6045 "cfg-if 1.0.0",6045 "cfg-if 1.0.0",606260626063[[package]]6063[[package]]6064name = "sha2"6064name = "sha2"6065version = "0.9.2"6065version = "0.9.3"6066source = "registry+https://github.com/rust-lang/crates.io-index"6066source = "registry+https://github.com/rust-lang/crates.io-index"6067checksum = "6e7aab86fe2149bad8c507606bdb3f4ef5e7b2380eb92350f56122cca72a42a8"6067checksum = "fa827a14b29ab7f44778d14a88d3cb76e949c45083f7dbfa507d0cb699dc12de"6068dependencies = [6068dependencies = [6069 "block-buffer 0.9.0",6069 "block-buffer 0.9.0",6070 "cfg-if 1.0.0",6070 "cfg-if 1.0.0",6171 "rand_core 0.5.1",6171 "rand_core 0.5.1",6172 "ring",6172 "ring",6173 "rustc_version",6173 "rustc_version",6174 "sha2 0.9.2",6174 "sha2 0.9.3",6175 "subtle 2.4.0",6175 "subtle 2.4.0",6176 "x25519-dalek",6176 "x25519-dalek",6177]6177]6200 "httparse",6200 "httparse",6201 "log",6201 "log",6202 "rand 0.7.3",6202 "rand 0.7.3",6203 "sha-1 0.9.2",6203 "sha-1 0.9.3",6204]6204]620562056206[[package]]6206[[package]]6428 "schnorrkel",6428 "schnorrkel",6429 "secrecy",6429 "secrecy",6430 "serde",6430 "serde",6431 "sha2 0.9.2",6431 "sha2 0.9.3",6432 "sp-debug-derive",6432 "sp-debug-derive",6433 "sp-externalities",6433 "sp-externalities",6434 "sp-runtime-interface",6434 "sp-runtime-interface",6973 "hyper 0.13.9",6973 "hyper 0.13.9",6974 "log",6974 "log",6975 "prometheus",6975 "prometheus",6976 "tokio 0.2.24",6976 "tokio 0.2.25",6977]6977]697869786979[[package]]6979[[package]]708370837084[[package]]7084[[package]]7085name = "thread_local"7085name = "thread_local"7086version = "1.1.2"7086version = "1.1.3"7087source = "registry+https://github.com/rust-lang/crates.io-index"7087source = "registry+https://github.com/rust-lang/crates.io-index"7088checksum = "d8208a331e1cb318dd5bd76951d2b8fc48ca38a69f5f4e4af1b6a9f8c6236915"7088checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd"7089dependencies = [7089dependencies = [7090 "once_cell",7090 "once_cell",7091]7091]7122 "pbkdf2 0.4.0",7122 "pbkdf2 0.4.0",7123 "rand 0.7.3",7123 "rand 0.7.3",7124 "rustc-hash",7124 "rustc-hash",7125 "sha2 0.9.2",7125 "sha2 0.9.3",7126 "thiserror",7126 "thiserror",7127 "unicode-normalization",7127 "unicode-normalization",7128 "zeroize",7128 "zeroize",717871787179[[package]]7179[[package]]7180name = "tokio"7180name = "tokio"7181version = "0.2.24"7181version = "0.2.25"7182source = "registry+https://github.com/rust-lang/crates.io-index"7182source = "registry+https://github.com/rust-lang/crates.io-index"7183checksum = "099837d3464c16a808060bb3f02263b412f6fafcb5d01c533d309985fbeebe48"7183checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092"7184dependencies = [7184dependencies = [7185 "bytes 0.5.6",7185 "bytes 0.5.6",7186 "fnv",7186 "fnv",7302dependencies = [7302dependencies = [7303 "futures-core",7303 "futures-core",7304 "rustls 0.18.1",7304 "rustls 0.18.1",7305 "tokio 0.2.24",7305 "tokio 0.2.25",7306 "webpki",7306 "webpki",7307]7307]730873087412 "futures-sink",7412 "futures-sink",7413 "log",7413 "log",7414 "pin-project-lite 0.1.11",7414 "pin-project-lite 0.1.11",7415 "tokio 0.2.24",7415 "tokio 0.2.25",7416]7416]741774177418[[package]]7418[[package]]743274327433[[package]]7433[[package]]7434name = "tracing"7434name = "tracing"7435version = "0.1.22"7435version = "0.1.23"7436source = "registry+https://github.com/rust-lang/crates.io-index"7436source = "registry+https://github.com/rust-lang/crates.io-index"7437checksum = "9f47026cdc4080c07e49b37087de021820269d996f581aac150ef9e5583eefe3"7437checksum = "f7d40a22fd029e33300d8d89a5cc8ffce18bb7c587662f54629e94c9de5487f3"7438dependencies = [7438dependencies = [7439 "cfg-if 1.0.0",7439 "cfg-if 1.0.0",7440 "log",7440 "log",744574457446[[package]]7446[[package]]7447name = "tracing-attributes"7447name = "tracing-attributes"7448version = "0.1.11"7448version = "0.1.12"7449source = "registry+https://github.com/rust-lang/crates.io-index"7449source = "registry+https://github.com/rust-lang/crates.io-index"7450checksum = "80e0ccfc3378da0cce270c946b676a376943f5cd16aeba64568e7939806f4ada"7450checksum = "43f080ea7e4107844ef4766459426fa2d5c1ada2e47edba05dc7fa99d9629f47"7451dependencies = [7451dependencies = [7452 "proc-macro2",7452 "proc-macro2",7453 "quote",7453 "quote",751875187519[[package]]7519[[package]]7520name = "trie-db"7520name = "trie-db"7521version = "0.22.2"7521version = "0.22.3"7522source = "registry+https://github.com/rust-lang/crates.io-index"7522source = "registry+https://github.com/rust-lang/crates.io-index"7523checksum = "5cc176c377eb24d652c9c69c832c832019011b6106182bf84276c66b66d5c9a6"7523checksum = "ec051edf7f0fc9499a2cb0947652cab2148b9d7f61cee7605e312e9f970dacaf"7524dependencies = [7524dependencies = [7525 "hash-db",7525 "hash-db",7526 "hashbrown",7526 "hashbrown",803280328033[[package]]8033[[package]]8034name = "wast"8034name = "wast"8035version = "32.0.0"8035version = "33.0.0"8036source = "registry+https://github.com/rust-lang/crates.io-index"8036source = "registry+https://github.com/rust-lang/crates.io-index"8037checksum = "c24a3ee360d01d60ed0a0f960ab76a6acce64348cdb0bf8699c2a866fad57c7c"8037checksum = "1d04fe175c7f78214971293e7d8875673804e736092206a3a4544dbc12811c1b"8038dependencies = [8038dependencies = [8039 "leb128",8039 "leb128",8040]8040]804180418042[[package]]8042[[package]]8043name = "wat"8043name = "wat"8044version = "1.0.33"8044version = "1.0.34"8045source = "registry+https://github.com/rust-lang/crates.io-index"8045source = "registry+https://github.com/rust-lang/crates.io-index"8046checksum = "5e8f7f34773fa6318e8897283abf7941c1f250faae4e1a52f82df09c3bad7cce"8046checksum = "7ec9c6ee01ae07a26adadcdfed22c7a97e0b8cbee9c06e0e96076ece5aeb5cfe"8047dependencies = [8047dependencies = [8048 "wast",8048 "wast",8049]8049]Dockerfilediffbeforeafterboth1# ===== BUILD ======1# ===== BUILD ======223FROM phusion/baseimage:0.10.2 as builder3FROM phusion/baseimage:18.04-1.0.0 as builder4LABEL maintainer="gz@usetech.com"4LABEL maintainer="gz@usetech.com"556ENV WASM_TOOLCHAIN=nightly-2020-10-016ENV WASM_TOOLCHAIN=nightly-2021-01-27778ARG PROFILE=release8ARG PROFILE=release99373738# ===== RUN ======38# ===== RUN ======393940FROM phusion/baseimage:0.10.240FROM phusion/baseimage:18.04-1.0.041ARG PROFILE=release41ARG PROFILE=release424243COPY --from=builder /nft_parachain/target/$PROFILE/nft /usr/local/bin43COPY --from=builder /nft_parachain/target/$PROFILE/nft /usr/local/binREADME.mddiffbeforeafterboth565657```bash57```bash58rustup toolchain install 1.49.058rustup toolchain install 1.49.059rustup toolchain install nightly-2020-10-0159rustup toolchain install nightly-2020-01-2760rustup default nightly-2021-01-2760rustup default nightly-2021-01-2761```61```6262pallets/nft/src/lib.rsdiffbeforeafterboth54mod default_weights;54mod default_weights;555556pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;56pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;57pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;57pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;58pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;58pub const MAX_TOKEN_OWNERSHIP: u32 = 10_000_000;59pub const MAX_TOKEN_OWNERSHIP: u32 = 10_000_000;596071 NFT,72 NFT,72 // decimal points73 // decimal points73 Fungible(DecimalPoints),74 Fungible(DecimalPoints),74 // decimal points75 ReFungible(DecimalPoints),75 ReFungible,76}76}777778impl Default for CollectionMode {78impl Default for CollectionMode {87 CollectionMode::Invalid => 0,87 CollectionMode::Invalid => 0,88 CollectionMode::NFT => 1,88 CollectionMode::NFT => 1,89 CollectionMode::Fungible(_) => 2,89 CollectionMode::Fungible(_) => 2,90 CollectionMode::ReFungible(_) => 3,90 CollectionMode::ReFungible => 3,91 }91 }92 }92 }93}93}266pub struct CreateReFungibleData {266pub struct CreateReFungibleData {267 pub const_data: Vec<u8>,267 pub const_data: Vec<u8>,268 pub variable_data: Vec<u8>,268 pub variable_data: Vec<u8>,269 pub pieces: u128,269}270}270271271#[derive(Encode, Decode, Debug, Clone, PartialEq)]272#[derive(Encode, Decode, Debug, Clone, PartialEq)]377 /// Collection limit bounds per collection exceeded378 /// Collection limit bounds per collection exceeded378 CollectionLimitBoundsExceeded,379 CollectionLimitBoundsExceeded,379 /// Schema data size limit bound exceeded380 /// Schema data size limit bound exceeded380 SchemaDataLimitExceeded381 SchemaDataLimitExceeded,382 /// Maximum refungibility exceeded383 WrongRefungiblePieces381 }384 }382}385}383386548551549 let decimal_points = match mode {552 let decimal_points = match mode {550 CollectionMode::Fungible(points) => points,553 CollectionMode::Fungible(points) => points,551 CollectionMode::ReFungible(points) => points,552 _ => 0554 _ => 0553 };555 };554556933935934 Self::can_create_items_in_collection(collection_id, &target_collection, &sender, &owner)?;936 Self::can_create_items_in_collection(collection_id, &target_collection, &sender, &owner)?;935 Self::validate_create_item_args(&target_collection, &data)?;937 Self::validate_create_item_args(&target_collection, &data)?;936 Self::create_item_no_validation(collection_id, &target_collection, owner, data)?;938 Self::create_item_no_validation(collection_id, owner, data)?;937939938 Ok(())940 Ok(())939 }941 }973 Self::validate_create_item_args(&target_collection, data)?;975 Self::validate_create_item_args(&target_collection, data)?;974 }976 }975 for data in &items_data {977 for data in &items_data {976 Self::create_item_no_validation(collection_id, &target_collection, owner.clone(), data.clone())?;978 Self::create_item_no_validation(collection_id, owner.clone(), data.clone())?;977 }979 }978980979 Ok(())981 Ok(())1012 {1014 {1013 CollectionMode::NFT => Self::burn_nft_item(collection_id, item_id)?,1015 CollectionMode::NFT => Self::burn_nft_item(collection_id, item_id)?,1014 CollectionMode::Fungible(_) => Self::burn_fungible_item(&sender, collection_id, value)?,1016 CollectionMode::Fungible(_) => Self::burn_fungible_item(&sender, collection_id, value)?,1015 CollectionMode::ReFungible(_) => Self::burn_refungible_item(collection_id, item_id, &sender)?,1017 CollectionMode::ReFungible => Self::burn_refungible_item(collection_id, item_id, &sender)?,1016 _ => ()1018 _ => ()1017 };1019 };10181020112211241123 // Check approval1125 // Check approval1124 let mut approval: u128 = 0;1126 let mut approval: u128 = 0;1125 if <Allowances<T>>::contains_key(collection_id, (item_id, &from, &recipient)) {1127 if <Allowances<T>>::contains_key(collection_id, (item_id, &from, &sender)) {1126 approval = <Allowances<T>>::get(collection_id, (item_id, &from, &recipient));1128 approval = <Allowances<T>>::get(collection_id, (item_id, &from, &sender));1127 ensure!(approval >= value, Error::<T>::TokenValueNotEnough);1129 ensure!(approval >= value, Error::<T>::TokenValueNotEnough);1128 appoved_transfer = true;1130 appoved_transfer = true;1129 }1131 }114411461145 // Reduce approval by transferred amount or remove if remaining approval drops to 01147 // Reduce approval by transferred amount or remove if remaining approval drops to 01146 if approval.checked_sub(value).unwrap_or(0) > 0 {1148 if approval.checked_sub(value).unwrap_or(0) > 0 {1147 <Allowances<T>>::insert(collection_id, (item_id, &from, &recipient), approval - value);1149 <Allowances<T>>::insert(collection_id, (item_id, &from, &sender), approval - value);1148 }1150 }1149 else {1151 else {1150 <Allowances<T>>::remove(collection_id, (item_id, &from, &recipient));1152 <Allowances<T>>::remove(collection_id, (item_id, &from, &sender));1151 }1153 }115211541153 match target_collection.mode1155 match target_collection.mode1154 {1156 {1155 CollectionMode::NFT => Self::transfer_nft(collection_id, item_id, from, recipient)?,1157 CollectionMode::NFT => Self::transfer_nft(collection_id, item_id, from, recipient)?,1156 CollectionMode::Fungible(_) => Self::transfer_fungible(collection_id, value, &from, &recipient)?,1158 CollectionMode::Fungible(_) => Self::transfer_fungible(collection_id, value, &from, &recipient)?,1157 CollectionMode::ReFungible(_) => Self::transfer_refungible(collection_id, item_id, value, from.clone(), recipient)?,1159 CollectionMode::ReFungible => Self::transfer_refungible(collection_id, item_id, value, from.clone(), recipient)?,1158 _ => ()1160 _ => ()1159 };1161 };116011621211 match target_collection.mode1213 match target_collection.mode1212 {1214 {1213 CollectionMode::NFT => Self::set_nft_variable_data(collection_id, item_id, data)?,1215 CollectionMode::NFT => Self::set_nft_variable_data(collection_id, item_id, data)?,1214 CollectionMode::ReFungible(_) => Self::set_re_fungible_variable_data(collection_id, item_id, data)?,1216 CollectionMode::ReFungible => Self::set_re_fungible_variable_data(collection_id, item_id, data)?,1215 CollectionMode::Fungible(_) => fail!(Error::<T>::CantStoreMetadataInFungibleTokens),1217 CollectionMode::Fungible(_) => fail!(Error::<T>::CantStoreMetadataInFungibleTokens),1216 _ => fail!(Error::<T>::UnexpectedCollectionType)1218 _ => fail!(Error::<T>::UnexpectedCollectionType)1217 };1219 };1551 {1553 {1552 CollectionMode::NFT => Self::transfer_nft(collection_id, item_id, sender.clone(), recipient)?,1554 CollectionMode::NFT => Self::transfer_nft(collection_id, item_id, sender.clone(), recipient)?,1553 CollectionMode::Fungible(_) => Self::transfer_fungible(collection_id, value, &sender, &recipient)?,1555 CollectionMode::Fungible(_) => Self::transfer_fungible(collection_id, value, &sender, &recipient)?,1554 CollectionMode::ReFungible(_) => Self::transfer_refungible(collection_id, item_id, value, sender.clone(), recipient)?,1556 CollectionMode::ReFungible => Self::transfer_refungible(collection_id, item_id, value, sender.clone(), recipient)?,1555 _ => ()1557 _ => ()1556 };1558 };155715591603 fail!(Error::<T>::NotFungibleDataUsedToMintFungibleCollectionToken);1605 fail!(Error::<T>::NotFungibleDataUsedToMintFungibleCollectionToken);1604 }1606 }1605 },1607 },1606 CollectionMode::ReFungible(_) => {1608 CollectionMode::ReFungible => {1607 if let CreateItemData::ReFungible(data) = data {1609 if let CreateItemData::ReFungible(data) = data {160816101609 // check sizes1611 // check sizes1610 ensure!(ChainLimit::get().custom_data_limit >= data.const_data.len() as u32, Error::<T>::TokenConstDataLimitExceeded);1612 ensure!(ChainLimit::get().custom_data_limit >= data.const_data.len() as u32, Error::<T>::TokenConstDataLimitExceeded);1611 ensure!(ChainLimit::get().custom_data_limit >= data.variable_data.len() as u32, Error::<T>::TokenVariableDataLimitExceeded);1613 ensure!(ChainLimit::get().custom_data_limit >= data.variable_data.len() as u32, Error::<T>::TokenVariableDataLimitExceeded);16141615 // Check refungibility limits1616 ensure!(data.pieces <= MAX_REFUNGIBLE_PIECES, Error::<T>::WrongRefungiblePieces);1617 ensure!(data.pieces > 0, Error::<T>::WrongRefungiblePieces);1612 } else {1618 } else {1613 fail!(Error::<T>::NotReFungibleDataUsedToMintReFungibleCollectionToken);1619 fail!(Error::<T>::NotReFungibleDataUsedToMintReFungibleCollectionToken);1614 }1620 }1619 Ok(())1625 Ok(())1620 }1626 }162116271622 fn create_item_no_validation(collection_id: CollectionId, collection: &CollectionType<T::AccountId>, owner: T::AccountId, data: CreateItemData) -> DispatchResult {1628 fn create_item_no_validation(collection_id: CollectionId, owner: T::AccountId, data: CreateItemData) -> DispatchResult {1623 match data1629 match data1624 {1630 {1625 CreateItemData::NFT(data) => {1631 CreateItemData::NFT(data) => {1636 },1642 },1637 CreateItemData::ReFungible(data) => {1643 CreateItemData::ReFungible(data) => {1638 let mut owner_list = Vec::new();1644 let mut owner_list = Vec::new();1639 let value = (10 as u128).pow(collection.decimal_points as u32);1640 owner_list.push(Ownership {owner: owner.clone(), fraction: value});1645 owner_list.push(Ownership {owner: owner.clone(), fraction: data.pieces});164116461642 let item = ReFungibleItemType {1647 let item = ReFungibleItemType {1643 owner: owner_list,1648 owner: owner_list,1866 CollectionMode::Fungible(_) => {1871 CollectionMode::Fungible(_) => {1867 <FungibleItemList<T>>::contains_key(collection_id, &subject)1872 <FungibleItemList<T>>::contains_key(collection_id, &subject)1868 }1873 }1869 CollectionMode::ReFungible(_) => {1874 CollectionMode::ReFungible => {1870 <ReFungibleItemList<T>>::get(collection_id, item_id)1875 <ReFungibleItemList<T>>::get(collection_id, item_id)1871 .owner1876 .owner1872 .iter()1877 .iter()1895 {1900 {1896 CollectionMode::NFT => <NftItemList<T>>::contains_key(collection_id, item_id),1901 CollectionMode::NFT => <NftItemList<T>>::contains_key(collection_id, item_id),1897 CollectionMode::Fungible(_) => <FungibleItemList<T>>::contains_key(collection_id, owner),1902 CollectionMode::Fungible(_) => <FungibleItemList<T>>::contains_key(collection_id, owner),1898 CollectionMode::ReFungible(_) => <ReFungibleItemList<T>>::contains_key(collection_id, item_id),1903 CollectionMode::ReFungible => <ReFungibleItemList<T>>::contains_key(collection_id, item_id),1899 _ => false1904 _ => false1900 };1905 };19011906242124262422 sponsored2427 sponsored2423 }2428 }2424 CollectionMode::ReFungible(_) => {2429 CollectionMode::ReFungible => {2425 2430 2426 // get correct limit2431 // get correct limit2427 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {2432 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {pallets/nft/src/mock.rsdiffbeforeafterboth1// Creating mock runtime here1// Creating mock runtime here223use crate::{Module, Trait};3use crate::{Module, Config};45use pallet_contracts::{6 ContractAddressFor, TrieId, TrieIdGenerator,7};849use frame_support::{5use frame_support::{10 impl_outer_origin, parameter_types,6 impl_outer_origin, parameter_types,11 weights::{7 weights::{Weight, IdentityFee},12 // constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight},13 Weight, IdentityFee,14 },15};8};16use frame_system as system;9use frame_system as system;10use system::limits::{BlockLength, BlockWeights};17use transaction_payment;11use transaction_payment::{self, CurrencyAdapter};18use sp_core::H256;12use sp_core::H256;19use sp_runtime::{13use sp_runtime::{20 testing::Header,14 testing::Header,21 traits::{BlakeTwo256, IdentityLookup, Saturating},15 traits::{BlakeTwo256, IdentityLookup},22 Perbill,16 Perbill,23};17};18use pallet_contracts::WeightInfo;24pub use pallet_balances;19pub use pallet_balances;252026impl_outer_origin! {21impl_outer_origin! {34pub struct Test;29pub struct Test;35parameter_types! {30parameter_types! {36 pub const BlockHashCount: u64 = 250;31 pub const BlockHashCount: u64 = 250;37 pub const MaximumBlockWeight: Weight = 1024;32 pub TestBlockWeights: BlockWeights = BlockWeights::default();38 pub const MaximumBlockLength: u32 = 2 * 1024;33 pub TestBlockLength: BlockLength = BlockLength::default();39 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);40 pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()34 pub SS58Prefix: u8 = 0;41 .saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();42}35}433644impl system::Trait for Test {37impl system::Config for Test {45 type BaseCallFilter = ();38 type BaseCallFilter = ();46 type Origin = Origin;39 type Origin = Origin;47 type Call = ();40 type Call = ();54 type Header = Header;47 type Header = Header;55 type Event = ();48 type Event = ();56 type BlockHashCount = BlockHashCount;49 type BlockHashCount = BlockHashCount;57 type MaximumBlockWeight = MaximumBlockWeight;50 type BlockWeights = TestBlockWeights;58 type DbWeight = ();51 type DbWeight = ();59 type BlockExecutionWeight = ();52 type BlockLength = TestBlockLength;60 type ExtrinsicBaseWeight = ();61 type MaximumExtrinsicWeight = MaximumBlockWeight;62 type MaximumBlockLength = MaximumBlockLength;63 type AvailableBlockRatio = AvailableBlockRatio;64 type Version = ();53 type Version = ();65 type PalletInfo = ();54 type PalletInfo = ();66 type AccountData = pallet_balances::AccountData<u64>;55 type AccountData = pallet_balances::AccountData<u64>;67 type OnNewAccount = ();56 type OnNewAccount = ();68 type OnKilledAccount = ();57 type OnKilledAccount = ();58 type SS58Prefix = SS58Prefix;69 type SystemWeightInfo = ();59 type SystemWeightInfo = ();70}60}716175}65}766677type System = frame_system::Module<Test>;67type System = frame_system::Module<Test>;78impl pallet_balances::Trait for Test {68impl pallet_balances::Config for Test {79 type AccountStore = System;69 type AccountStore = System;80 type Balance = u64;70 type Balance = u64;81 type DustRemoval = ();71 type DustRemoval = ();89 pub const TransactionByteFee: u64 = 1;79 pub const TransactionByteFee: u64 = 1;90}80}8191impl transaction_payment::Trait for Test {82impl transaction_payment::Config for Test {92 type Currency = pallet_balances::Module<Test>;83 type OnChargeTransaction = CurrencyAdapter<pallet_balances::Module<Test>, ()>;93 type OnTransactionPayment = ();94 type TransactionByteFee = TransactionByteFee;84 type TransactionByteFee = TransactionByteFee;95 type WeightToFee = IdentityFee<u64>;85 type WeightToFee = IdentityFee<u64>;96 type FeeMultiplierUpdate = ();86 type FeeMultiplierUpdate = ();100parameter_types! {90parameter_types! {101 pub const MinimumPeriod: u64 = 1;91 pub const MinimumPeriod: u64 = 1;102}92}103impl pallet_timestamp::Trait for Test {93impl pallet_timestamp::Config for Test {104 type Moment = u64;94 type Moment = u64;105 type OnTimestampSet = ();95 type OnTimestampSet = ();106 type MinimumPeriod = MinimumPeriod;96 type MinimumPeriod = MinimumPeriod;110type Timestamp = pallet_timestamp::Module<Test>;100type Timestamp = pallet_timestamp::Module<Test>;111type Randomness = pallet_randomness_collective_flip::Module<Test>;101type Randomness = pallet_randomness_collective_flip::Module<Test>;112102113parameter_types! {103parameter_types! {114 pub const TombstoneDeposit: u64 = 1;104 pub const TombstoneDeposit: u64 = 1;115 pub const RentByteFee: u64 = 1;105 pub const DepositPerContract: u64 = 1;116 pub const RentDepositOffset: u64 = 1;106 pub const DepositPerStorageByte: u64 = 1;117 pub const SurchargeReward: u64 = 1;107 pub const DepositPerStorageItem: u64 = 1;118}119120pub struct DummyTrieIdGenerator;108 pub RentFraction: Perbill = Perbill::from_rational_approximation(1u32, 30 * 24 * 60 * 10);121impl TrieIdGenerator<u64> for DummyTrieIdGenerator {122 fn trie_id(account_id: &u64) -> TrieId {109 pub const SurchargeReward: u64 = 1;123 let new_seed = *account_id + 1;124 let mut res = vec![];110 pub const SignedClaimHandicap: u32 = 2;125 res.extend_from_slice(&new_seed.to_le_bytes());126 res.extend_from_slice(&account_id.to_le_bytes());127 res128 }129}130131pub struct DummyContractAddressFor;111 pub const MaxDepth: u32 = 32;132impl ContractAddressFor<H256, u64> for DummyContractAddressFor {133 fn contract_address_for(_code_hash: &H256, _data: &[u8], origin: &u64) -> u64 {112 pub const MaxValueSize: u32 = 16 * 1024;134 *origin + 1113 pub DeletionWeightLimit: Weight = Perbill::from_percent(10) *135 }114 TestBlockWeights::get().max_block;136}115 pub DeletionQueueDepth: u32 = ((DeletionWeightLimit::get() / (116 <Test as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(1) -117 <Test as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(0)118 )) / 5) as u32;119}137120138impl pallet_contracts::Trait for Test {121impl pallet_contracts::Config for Test {139 type Time = Timestamp;122 type Time = Timestamp;140 type Randomness = Randomness;123 type Randomness = Randomness;141 type Currency = pallet_balances::Module<Test>;124 type Currency = pallet_balances::Module<Test>;142 type Event = ();125 type Event = ();143 type DetermineContractAddress = DummyContractAddressFor;144 type TrieIdGenerator = DummyTrieIdGenerator;145 type RentPayment = ();126 type RentPayment = ();146 type SignedClaimHandicap = pallet_contracts::DefaultSignedClaimHandicap;127 type SignedClaimHandicap = SignedClaimHandicap;147 type TombstoneDeposit = TombstoneDeposit;128 type TombstoneDeposit = TombstoneDeposit;148 type StorageSizeOffset = pallet_contracts::DefaultStorageSizeOffset;129 type DepositPerContract = DepositPerContract;149 type RentByteFee = RentByteFee;130 type DepositPerStorageByte = DepositPerStorageByte;150 type RentDepositOffset = RentDepositOffset;131 type DepositPerStorageItem = DepositPerStorageItem;132 type RentFraction = RentFraction;151 type SurchargeReward = SurchargeReward;133 type SurchargeReward = SurchargeReward;134 type DeletionWeightLimit = DeletionWeightLimit;152 type MaxDepth = pallet_contracts::DefaultMaxDepth;135 type MaxDepth = MaxDepth;136 type DeletionQueueDepth = DeletionQueueDepth;153 type MaxValueSize = pallet_contracts::DefaultMaxValueSize;137 type MaxValueSize = MaxValueSize;138 type ChainExtension = ();154 type WeightPrice = ();139 type WeightPrice = ();140 type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;155}141}156142157impl Trait for Test {143impl Config for Test {158 type Event = ();144 type Event = ();159 type WeightInfo = ();145 type WeightInfo = ();160146pallets/nft/src/tests.rsdiffbeforeafterboth35}35}363637fn default_re_fungible_data () -> CreateReFungibleData {37fn default_re_fungible_data () -> CreateReFungibleData {38 CreateReFungibleData { const_data: vec![1, 2, 3], variable_data: vec![3, 2, 1] }38 CreateReFungibleData { const_data: vec![1, 2, 3], variable_data: vec![3, 2, 1], pieces: 1023 }39}39}404041fn create_test_collection_for_owner(mode: &CollectionMode, owner: u64, id: CollectionId) -> CollectionId {41fn create_test_collection_for_owner(mode: &CollectionMode, owner: u64, id: CollectionId) -> CollectionId {113 }); 113 }); 114}114}115116#[test]117fn create_re_fungible_collection_fails_with_large_decimal_numbers() {118 new_test_ext().execute_with(|| {119 default_limits();120121 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();122 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();123 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();124125 let origin1 = Origin::signed(1);126 assert_noop!(TemplateModule::create_collection(127 origin1,128 col_name1,129 col_desc1,130 token_prefix1,131 CollectionMode::ReFungible(MAX_DECIMAL_POINTS + 1)132 ), Error::<Test>::CollectionDecimalPointLimitExceeded);133 });134}135115136#[test]116#[test]137fn create_nft_item() {117fn create_nft_item() {176fn create_refungible_item() {156fn create_refungible_item() {177 new_test_ext().execute_with(|| {157 new_test_ext().execute_with(|| {178 default_limits();158 default_limits();179 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);159 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);180160181 let data = default_re_fungible_data();161 let data = default_re_fungible_data();182 create_test_item(collection_id, &data.clone().into());162 create_test_item(collection_id, &data.clone().into());192 TemplateModule::refungible_item_id(collection_id, 1).owner[0],172 TemplateModule::refungible_item_id(collection_id, 1).owner[0],193 Ownership {173 Ownership {194 owner: 1,174 owner: 1,195 fraction: 1000175 fraction: 1023196 }176 }197 );177 );198 });178 });203 new_test_ext().execute_with(|| {183 new_test_ext().execute_with(|| {204 default_limits();184 default_limits();205 185 206 create_test_collection(&CollectionMode::ReFungible(3), 1);186 create_test_collection(&CollectionMode::ReFungible, 1);207187208 let origin1 = Origin::signed(1);188 let origin1 = Origin::signed(1);209189224 item.owner[0],204 item.owner[0],225 Ownership {205 Ownership {226 owner: 1,206 owner: 1,227 fraction: 1000207 fraction: 1023228 }208 }229 );209 );230 }210 }312 new_test_ext().execute_with(|| {292 new_test_ext().execute_with(|| {313 default_limits();293 default_limits();314 294 315 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);295 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);316296317 let data = default_re_fungible_data();297 let data = default_re_fungible_data();318 create_test_item(collection_id, &data.clone().into());298 create_test_item(collection_id, &data.clone().into());331 TemplateModule::refungible_item_id(collection_id, 1).owner[0],311 TemplateModule::refungible_item_id(collection_id, 1).owner[0],332 Ownership {312 Ownership {333 owner: 1,313 owner: 1,334 fraction: 1000314 fraction: 1023335 }315 }336 );316 );337 assert_eq!(TemplateModule::balance_count(1, 1), 1000);317 assert_eq!(TemplateModule::balance_count(1, 1), 1023);338 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);318 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);339319340 // change owner scenario320 // change owner scenario341 assert_ok!(TemplateModule::transfer(origin1.clone(), 2, 1, 1, 1000));321 assert_ok!(TemplateModule::transfer(origin1.clone(), 2, 1, 1, 1023));342 assert_eq!(322 assert_eq!(343 TemplateModule::refungible_item_id(1, 1).owner[0],323 TemplateModule::refungible_item_id(1, 1).owner[0],344 Ownership {324 Ownership {345 owner: 2,325 owner: 2,346 fraction: 1000326 fraction: 1023347 }327 }348 );328 );349 assert_eq!(TemplateModule::balance_count(1, 1), 0);329 assert_eq!(TemplateModule::balance_count(1, 1), 0);350 assert_eq!(TemplateModule::balance_count(1, 2), 1000);330 assert_eq!(TemplateModule::balance_count(1, 2), 1023);351 // assert_eq!(TemplateModule::address_tokens(1, 1), []);331 // assert_eq!(TemplateModule::address_tokens(1, 1), []);352 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);332 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);353333357 TemplateModule::refungible_item_id(1, 1).owner[0],337 TemplateModule::refungible_item_id(1, 1).owner[0],358 Ownership {338 Ownership {359 owner: 2,339 owner: 2,360 fraction: 500340 fraction: 523361 }341 }362 );342 );363 assert_eq!(343 assert_eq!(367 fraction: 500347 fraction: 500368 }348 }369 );349 );370 assert_eq!(TemplateModule::balance_count(1, 2), 500);350 assert_eq!(TemplateModule::balance_count(1, 2), 523);371 assert_eq!(TemplateModule::balance_count(1, 3), 500);351 assert_eq!(TemplateModule::balance_count(1, 3), 500);372 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);352 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);373 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);353 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);378 TemplateModule::refungible_item_id(1, 1).owner[0],358 TemplateModule::refungible_item_id(1, 1).owner[0],379 Ownership {359 Ownership {380 owner: 2,360 owner: 2,381 fraction: 300361 fraction: 323382 }362 }383 );363 );384 assert_eq!(364 assert_eq!(388 fraction: 700368 fraction: 700389 }369 }390 );370 );391 assert_eq!(TemplateModule::balance_count(1, 2), 300);371 assert_eq!(TemplateModule::balance_count(1, 2), 323);392 assert_eq!(TemplateModule::balance_count(1, 3), 700);372 assert_eq!(TemplateModule::balance_count(1, 3), 700);393 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);373 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);394 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);374 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);454 assert_ok!(TemplateModule::transfer_from(434 assert_ok!(TemplateModule::transfer_from(455 origin2.clone(),435 origin2.clone(),456 1,436 1,457 2,437 3,458 1,438 1,459 1,439 1,460 1440 1508 1,488 1,509 1489 1510 ));490 ));511 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 4);491 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);512 });492 });513}493}514494517 new_test_ext().execute_with(|| {497 new_test_ext().execute_with(|| {518 default_limits();498 default_limits();519 499 520 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);500 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);521 501 522 let origin1 = Origin::signed(1);502 let origin1 = Origin::signed(1);523 let origin2 = Origin::signed(2);503 let origin2 = Origin::signed(2);524504525 let data = default_re_fungible_data();505 let data = default_re_fungible_data();526 create_test_item(collection_id, &data.into());506 create_test_item(collection_id, &data.into());527507528 assert_eq!(TemplateModule::balance_count(1, 1), 1000);508 assert_eq!(TemplateModule::balance_count(1, 1), 1023);529 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);509 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);530510531 assert_ok!(TemplateModule::set_mint_permission(511 assert_ok!(TemplateModule::set_mint_permission(543 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));523 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));544524545 // do approve525 // do approve546 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));526 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 1023));547 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);527 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1023);548 assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1, 1000));549 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 1000);550528551 assert_ok!(TemplateModule::transfer_from(529 assert_ok!(TemplateModule::transfer_from(552 origin2.clone(),530 origin2.clone(),556 1,534 1,557 100535 100558 ));536 ));559 assert_eq!(TemplateModule::balance_count(1, 1), 900);537 assert_eq!(TemplateModule::balance_count(1, 1), 923);560 assert_eq!(TemplateModule::balance_count(1, 3), 100);538 assert_eq!(TemplateModule::balance_count(1, 3), 100);561 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);539 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);562 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);540 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);563541564 assert_eq!(542 assert_eq!(565 TemplateModule::approved(1, (1, 1, 3)),543 TemplateModule::approved(1, (1, 1, 2)),566 900544 923567 );545 );568 });546 });569}547}618 assert_eq!(TemplateModule::balance_count(1, 1), 1);596 assert_eq!(TemplateModule::balance_count(1, 1), 1);619 assert_eq!(TemplateModule::balance_count(1, 3), 4);597 assert_eq!(TemplateModule::balance_count(1, 3), 4);620598621 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);599 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);622 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 1);600623624 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));625 assert_noop!(TemplateModule::transfer_from(601 assert_noop!(TemplateModule::transfer_from(626 origin2.clone(),602 origin2.clone(),627 1,603 1,721 new_test_ext().execute_with(|| {697 new_test_ext().execute_with(|| {722 default_limits();698 default_limits();723 699 724 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);700 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);725 let origin1 = Origin::signed(1);701 let origin1 = Origin::signed(1);726702727 assert_ok!(TemplateModule::set_mint_permission(703 assert_ok!(TemplateModule::set_mint_permission(742 create_test_item(collection_id, &data.into());718 create_test_item(collection_id, &data.into());743719744 // check balance (collection with id = 1, user id = 2)720 // check balance (collection with id = 1, user id = 2)745 assert_eq!(TemplateModule::balance_count(1, 1), 1000);721 assert_eq!(TemplateModule::balance_count(1, 1), 1023);746722747 // burn item723 // burn item748 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 1000));724 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 1023));749 assert_noop!(725 assert_noop!(750 TemplateModule::burn_item(origin1.clone(), 1, 1, 1000),726 TemplateModule::burn_item(origin1.clone(), 1, 1, 1023),751 Error::<Test>::TokenNotFound727 Error::<Test>::TokenNotFound752 );728 );753729811 787 812 let nft_collection_id = create_test_collection(&CollectionMode::NFT, 1);788 let nft_collection_id = create_test_collection(&CollectionMode::NFT, 1);813 let fungible_collection_id = create_test_collection(&CollectionMode::Fungible(3), 2);789 let fungible_collection_id = create_test_collection(&CollectionMode::Fungible(3), 2);814 let re_fungible_collection_id = create_test_collection(&CollectionMode::ReFungible(3), 3);790 let re_fungible_collection_id = create_test_collection(&CollectionMode::ReFungible, 3);815 791 816 // check balance before792 // check balance before817 assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 0);793 assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 0);830 // check balance (collection with id = 1, user id = 1)806 // check balance (collection with id = 1, user id = 1)831 assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 1);807 assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 1);832 assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 5);808 assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 5);833 assert_eq!(TemplateModule::balance_count(re_fungible_collection_id, 1), 1000);809 assert_eq!(TemplateModule::balance_count(re_fungible_collection_id, 1), 1023);834 assert_eq!(TemplateModule::nft_item_id(nft_collection_id, 1).owner, 1);810 assert_eq!(TemplateModule::nft_item_id(nft_collection_id, 1).owner, 1);835 assert_eq!(TemplateModule::fungible_item_id(fungible_collection_id, 1).value, 5);811 assert_eq!(TemplateModule::fungible_item_id(fungible_collection_id, 1).value, 5);836 assert_eq!(TemplateModule::refungible_item_id(re_fungible_collection_id, 1).owner[0].owner, 1);812 assert_eq!(TemplateModule::refungible_item_id(re_fungible_collection_id, 1).owner[0].owner, 1);1909 new_test_ext().execute_with(|| {1885 new_test_ext().execute_with(|| {1910 default_limits();1886 default_limits();191118871912 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);1888 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);191318891914 let origin1 = Origin::signed(1);1890 let origin1 = Origin::signed(1);191518911986 }));1962 }));19871963198819641989 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);1965 let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);199019661991 let origin1 = Origin::signed(1);1967 let origin1 = Origin::signed(1);19921968runtime_types.jsondiffbeforeafterboth1{1{2 "Schedule": {3 "version": "u32",4 "put_code_per_byte_cost": "Gas",5 "grow_mem_cost": "Gas",6 "regular_op_cost": "Gas",7 "return_data_per_byte_cost": "Gas",8 "event_data_per_byte_cost": "Gas",9 "event_per_topic_cost": "Gas",10 "event_base_cost": "Gas",11 "call_base_cost": "Gas",12 "instantiate_base_cost": "Gas",13 "dispatch_base_cost": "Gas",14 "sandbox_data_read_cost": "Gas",15 "sandbox_data_write_cost": "Gas",16 "transfer_cost": "Gas",17 "instantiate_cost": "Gas",18 "max_event_topics": "u32",19 "max_stack_height": "u32",20 "max_memory_pages": "u32",21 "max_table_size": "u32",22 "enable_println": "bool",23 "max_subject_len": "u32"24 },25 "AccessMode": {2 "AccessMode": {26 "_enum": [3 "_enum": [27 "Normal",4 "Normal",34 "Invalid": null,11 "Invalid": null,35 "NFT": null,12 "NFT": null,36 "Fungible": "DecimalPoints",13 "Fungible": "DecimalPoints",37 "ReFungible": "DecimalPoints"14 "ReFungible": null38 }15 }39 },16 },40 "Ownership": {17 "Ownership": {84 },61 },85 "CreateReFungibleData": {62 "CreateReFungibleData": {86 "const_data": "Vec<u8>",63 "const_data": "Vec<u8>",87 "variable_data": "Vec<u8>" 64 "variable_data": "Vec<u8>",65 "pieces": "u128"88 },66 },89 "CreateItemData": {67 "CreateItemData": {90 "_enum": {68 "_enum": {102 "CollectionId": "u32",80 "CollectionId": "u32",103 "TokenId": "u32",81 "TokenId": "u32",104 "ChainLimits": {82 "ChainLimits": {105 "collection_numbers_limit": "u32",83 "CollectionNumbersLimit": "u32",106 "account_token_ownership_limit": "u32",84 "AccountTokenOwnershipLimit": "u32",107 "collections_admins_limit": "u64",85 "CollectionAdminsLimit": "u64",108 "custom_data_limit": "u32",86 "CustomDataLimit": "u32",109 "nft_sponsor_timeout": "u32",87 "NftSponsorTimeout": "u32",110 "fungible_sponsor_timeout": "u32",88 "FungibleSponsorTimeout": "u32",111 "refungible_sponsor_timeout": "u32"89 "RefungibleSponsorTimeout": "u32",90 "OffchainSchemaLimit": "u32",91 "VariableOnChainSchemaLimit": "u32",92 "ConstOnChainSchemaLimit": "u32"112 },93 },113 "CollectionLimits": {94 "CollectionLimits": {114 "AccountTokenOwnershipLimit": "u32",95 "AccountTokenOwnershipLimit": "u32",115 "SponsoredMintSize": "u32",96 "SponsoredMintSize": "u32",116 "TokenLimit": "u32",97 "TokenLimit": "u32",117 "SponsorTimeout": "u32"98 "SponsorTimeout": "u32"118 },99 }119 "AccountInfo": "AccountInfoWithProviders",120 "AccountInfoWithProviders": {121 "nonce": "Index",122 "consumers": "RefCount",123 "providers": "RefCount",124 "data": "AccountData"125 }126127 }100}128 tests/.vscode/settings.jsondiffbeforeafterbothno changes
tests/README.mddiffbeforeafterboth223## How to run3## How to run4451. Run `npm install`.51. Run `yarn install`.62. Setup a test node. You can do it using `docker-compose up -d` in parent directory.62. Setup a test node. You can do it using `docker-compose up -d` in parent directory.73. Optional step - configure tests with env variables or by editing [configuration file](src/config.ts).73. Optional step - configure tests with env variables or by editing [configuration file](src/config.ts).84. Run `npm test`.84. Run `yarn test`.991010tests/package.jsondiffbeforeafterboth22 "load": "mocha --timeout 9999999 -r ts-node/register ./**/*.load.ts",22 "load": "mocha --timeout 9999999 -r ts-node/register ./**/*.load.ts",23 "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",23 "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",24 "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",24 "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",25 "testSetVariableMetaData": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetaData.test.ts",25 "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",26 "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",26 "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",27 "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",28 "testRemoveFromWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromWhiteList.test.ts",27 "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",29 "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",28 "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",30 "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",31 "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",29 "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",32 "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",30 "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",33 "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",31 "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",34 "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",32 "testToggleContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractWhiteList.test.ts",35 "testToggleContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractWhiteList.test.ts",33 "testAddToContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractWhiteList.test.ts",36 "testAddToContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractWhiteList.test.ts",34 "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",37 "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",35 "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",38 "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",39 "testSetMintPermission": "mocha --timeout 9999999 -r ts-node/register ./**/setMintPermission.test.ts",36 "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts"40 "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",41 "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",42 "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts"37 },43 },38 "author": "",44 "author": "",39 "license": "SEE LICENSE IN ../LICENSE",45 "license": "SEE LICENSE IN ../LICENSE",tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth1//
2// This file is subject to the terms and conditions defined in
3// file 'LICENSE', which is part of this source code package.
4//
5
1import { ApiPromise } from '@polkadot/api';
6import { ApiPromise } from '@polkadot/api';
2import BN from 'bn.js';
7import BN from 'bn.js';
98 });
103 });
99 });
104 });
100
105
101 it('Add an admin to a collection that has reached the maximum number of admins limit', async () => {
106 it.only('Add an admin to a collection that has reached the maximum number of admins limit', async () => {
102 await usingApi(async (api: ApiPromise) => {
107 await usingApi(async (api: ApiPromise) => {
103 const Alice = privateKey('//Alice');
108 const Alice = privateKey('//Alice');
104 const accounts = [
109 const accounts = [
112 ];
117 ];
113 const collectionId = await createCollectionExpectSuccess();
118 const collectionId = await createCollectionExpectSuccess();
114
119
115 const chainLimit = await api.query.nft.chainLimit() as unknown as { collections_admins_limit: BN };
120 const chainLimit = await api.query.nft.chainLimit() as unknown as { CollectionAdminsLimit: BN };
116 const chainLimitNumber = chainLimit.collections_admins_limit.toNumber();
121 const chainAdminLimit = chainLimit.CollectionAdminsLimit.toNumber();
117 expect(chainLimitNumber).to.be.equal(5);
122 expect(chainAdminLimit).to.be.equal(5);
118
123
119 for (let i = 0; i < chainLimitNumber; i++) {
124 for (let i = 0; i < chainAdminLimit; i++) {
120 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, accounts[i]);
125 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, accounts[i]);
121 await submitTransactionAsync(Alice, changeAdminTx);
126 await submitTransactionAsync(Alice, changeAdminTx);
122 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));
127 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));
123 expect(adminListAfterAddAdmin).to.be.contains(accounts[i]);
128 expect(adminListAfterAddAdmin).to.be.contains(accounts[i]);
124 }
129 }
125
130
126 const tx = api.tx.nft.addCollectionAdmin(collectionId, accounts[chainLimitNumber]);
131 const tx = api.tx.nft.addCollectionAdmin(collectionId, accounts[chainAdminLimit]);
127 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
132 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
128 });
133 });
129 });
134 });
tests/src/addToContractWhiteList.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//51import chai from "chai";6import chai from "chai";2import chaiAsPromised from 'chai-as-promised';7import chaiAsPromised from 'chai-as-promised';tests/src/addToWhiteList.test.tsdiffbeforeafterboth1//
2// This file is subject to the terms and conditions defined in
3// file 'LICENSE', which is part of this source code package.
4//
5
1import { IKeyringPair } from '@polkadot/types/types';
6import { IKeyringPair } from '@polkadot/types/types';
2import chai from 'chai';
7import chai from 'chai';
tests/src/approve.test.tsdiffbeforeafterboth34 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);34 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);35 // reFungible35 // reFungible36 const reFungibleCollectionId =36 const reFungibleCollectionId =37 await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});37 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});38 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');38 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');39 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);39 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);40 });40 });56 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 0);56 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 0);57 // reFungible57 // reFungible58 const reFungibleCollectionId =58 const reFungibleCollectionId =59 await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});59 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});60 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');60 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');61 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 1);61 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 1);62 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 0);62 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 0);95 await approveExpectFail(fungibleCollectionId, 1, Alice, Bob);95 await approveExpectFail(fungibleCollectionId, 1, Alice, Bob);96 // reFungible96 // reFungible97 const reFungibleCollectionId =97 const reFungibleCollectionId =98 await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});98 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});99 await destroyCollectionExpectSuccess(reFungibleCollectionId);99 await destroyCollectionExpectSuccess(reFungibleCollectionId);100 await approveExpectFail(reFungibleCollectionId, 1, Alice, Bob);100 await approveExpectFail(reFungibleCollectionId, 1, Alice, Bob);101 });101 });113 await approveExpectFail(fungibleCollectionId, 2, Alice, Bob);113 await approveExpectFail(fungibleCollectionId, 2, Alice, Bob);114 // reFungible114 // reFungible115 const reFungibleCollectionId =115 const reFungibleCollectionId =116 await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});116 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});117 await approveExpectFail(reFungibleCollectionId, 2, Alice, Bob);117 await approveExpectFail(reFungibleCollectionId, 2, Alice, Bob);118 });118 });119 });119 });132 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice);132 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice);133 // reFungible133 // reFungible134 const reFungibleCollectionId =134 const reFungibleCollectionId =135 await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});135 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});136 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');136 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');137 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice);137 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice);138 });138 });tests/src/burnItem.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//51import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';6import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';2import { Keyring } from "@polkadot/api";7import { Keyring } from "@polkadot/api";70 });75 });71 it('Burn item in ReFungible collection', async () => {76 it('Burn item in ReFungible collection', async () => {72 const createMode = 'ReFungible';77 const createMode = 'ReFungible';73 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 2 }});78 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});74 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);79 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);758076 await usingApi(async (api) => {81 await usingApi(async (api) => {919692 it('Burn owned portion of item in ReFungible collection', async () => {97 it('Burn owned portion of item in ReFungible collection', async () => {93 const createMode = 'ReFungible';98 const createMode = 'ReFungible';94 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 2 }});99 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});95 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);100 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);9610197 await usingApi(async (api) => {102 await usingApi(async (api) => {tests/src/change-collection-owner.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//51import chai from 'chai';6import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';7import chaiAsPromised from 'chai-as-promised';tests/src/confirmSponsorship.test.tsdiffbeforeafterboth115 });115 });116116117 it('ReFungible: Transfer fees are paid by the sponsor after confirmation', async () => {117 it('ReFungible: Transfer fees are paid by the sponsor after confirmation', async () => {118 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0 }});118 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});119 await setCollectionSponsorExpectSuccess(collectionId, bob.address);119 await setCollectionSponsorExpectSuccess(collectionId, bob.address);120 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');120 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');121121247 });247 });248248249 it('ReFungible: Sponsoring is rate limited', async () => {249 it('ReFungible: Sponsoring is rate limited', async () => {250 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0 }});250 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});251 await setCollectionSponsorExpectSuccess(collectionId, bob.address);251 await setCollectionSponsorExpectSuccess(collectionId, bob.address);252 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');252 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');253253tests/src/contracts.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//51import chai from "chai";6import chai from "chai";2import chaiAsPromised from 'chai-as-promised';7import chaiAsPromised from 'chai-as-promised';tests/src/createCollection.test.tsdiffbeforeafterboth28 await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
28 await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
29 });
29 });
30 it('Create new ReFungible collection', async () => {
30 it('Create new ReFungible collection', async () => {
31 await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
31 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
32 });
32 });
33});
33});
34
34
tests/src/createItem.test.tsdiffbeforeafterboth1//
2// This file is subject to the terms and conditions defined in
3// file 'LICENSE', which is part of this source code package.
4//
5
1import { default as usingApi } from './substrate/substrate-api';
6import { default as usingApi } from './substrate/substrate-api';
2import { Keyring } from "@polkadot/api";
7import { Keyring } from "@polkadot/api";
28 });
33 });
29 it('Create new item in ReFungible collection', async () => {
34 it('Create new item in ReFungible collection', async () => {
30 const createMode = 'ReFungible';
35 const createMode = 'ReFungible';
31 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
36 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
32 await createItemExpectSuccess(alice, newCollectionID, createMode);
37 await createItemExpectSuccess(alice, newCollectionID, createMode);
33 });
38 });
34});
39});
tests/src/createMultipleItems.test.tsdiffbeforeafterboth3// file 'LICENSE', which is part of this source code package.3// file 'LICENSE', which is part of this source code package.4//4//56import { assert } from 'chai';5import { ApiPromise } from '@polkadot/api';6import BN from 'bn.js';7import chai from 'chai';7import { alicesPublicKey } from './accounts';8import chaiAsPromised from 'chai-as-promised';8import privateKey from './substrate/privateKey';9import privateKey from './substrate/privateKey';9import usingApi from './substrate/substrate-api';10import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';10import waitNewBlocks from './substrate/wait-new-blocks';11import {1112 createCollectionExpectSuccess,13 destroyCollectionExpectSuccess,14 IReFungibleTokenDataType,15} from './util/helpers';1617chai.use(chaiAsPromised);12const idCollection = 12;18const expect = chai.expect;1920interface ITokenDataType {21 Owner: number[];22 ConstData: number[];23 VariableData: number[];24}2526describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {27 it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {28 await usingApi(async (api: ApiPromise) => {29 const collectionId = await createCollectionExpectSuccess();30 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;31 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);32 const Alice = privateKey('//Alice');33 const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];34 const createMultipleItemsTx = await api.tx.nft35 .createMultipleItems(collectionId, Alice.address, args);36 await submitTransactionAsync(Alice, createMultipleItemsTx);37 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;38 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);39 const token1Data = await api.query.nft.nftItemList(collectionId, 1) as unknown as ITokenDataType;40 const token2Data = await api.query.nft.nftItemList(collectionId, 2) as unknown as ITokenDataType;41 const token3Data = await api.query.nft.nftItemList(collectionId, 3) as unknown as ITokenDataType;4243 expect(token1Data.Owner.toString()).to.be.equal(Alice.address);44 expect(token2Data.Owner.toString()).to.be.equal(Alice.address);45 expect(token3Data.Owner.toString()).to.be.equal(Alice.address);4647 expect(token1Data.ConstData.toString()).to.be.equal('0x31');48 expect(token2Data.ConstData.toString()).to.be.equal('0x32');49 expect(token3Data.ConstData.toString()).to.be.equal('0x33');5051 expect(token1Data.VariableData.toString()).to.be.equal('0x31');52 expect(token2Data.VariableData.toString()).to.be.equal('0x32');53 expect(token3Data.VariableData.toString()).to.be.equal('0x33');54 });55 });5657 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {58 await usingApi(async (api: ApiPromise) => {59 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});60 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;61 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);62 const Alice = privateKey('//Alice');63 const args = [64 {refungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},65 {refungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},66 {refungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},67 ];68 const createMultipleItemsTx = await api.tx.nft69 .createMultipleItems(collectionId, Alice.address, args);70 await submitTransactionAsync(Alice, createMultipleItemsTx);71 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;72 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);73 const token1Data = await api.query.nft.reFungibleItemList(collectionId, 1) as unknown as IReFungibleTokenDataType;74 const token2Data = await api.query.nft.reFungibleItemList(collectionId, 2) as unknown as IReFungibleTokenDataType;75 const token3Data = await api.query.nft.reFungibleItemList(collectionId, 3) as unknown as IReFungibleTokenDataType;7677 expect(token1Data.Owner[0].Owner.toString()).to.be.equal(Alice.address);78 expect(token1Data.Owner[0].Fraction.toNumber()).to.be.equal(1);7980 expect(token2Data.Owner[0].Owner.toString()).to.be.equal(Alice.address);81 expect(token2Data.Owner[0].Fraction.toNumber()).to.be.equal(1);8283 expect(token3Data.Owner[0].Owner.toString()).to.be.equal(Alice.address);84 expect(token3Data.Owner[0].Fraction.toNumber()).to.be.equal(1);8586 expect(token1Data.ConstData.toString()).to.be.equal('0x31');87 expect(token2Data.ConstData.toString()).to.be.equal('0x32');88 expect(token3Data.ConstData.toString()).to.be.equal('0x33');8990 expect(token1Data.VariableData.toString()).to.be.equal('0x31');91 expect(token2Data.VariableData.toString()).to.be.equal('0x32');92 expect(token3Data.VariableData.toString()).to.be.equal('0x33');93 });94 });95});139614describe.skip('integration test: ext. createMultipleItems():', () => {97describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {15 it('Create two NFT tokens in active NFT collection', async () => {98 it('Create token with not existing type', async () => {16 await usingApi(async (api) => {99 await usingApi(async (api: ApiPromise) => {17 const AitemListIndex = await api.query.nft.itemListIndex(idCollection);100 const collectionId = await createCollectionExpectSuccess();18 console.log(`itemListIndex count (before): ${AitemListIndex}`);101 const Alice = privateKey('//Alice');102 try {19 const args = ['NFT', 'NFT'];103 const args = [{ invalid: null }, { invalid: null }, { invalid: null }];20 const alicePrivateKey = privateKey('//Alice');21 const createMultipleItems = await api.tx.nft104 const createMultipleItemsTx = await api.tx.nft22 .createMultipleItems(idCollection, alicesPublicKey, args)105 .createMultipleItems(collectionId, Alice.address, args);23 .signAndSend(alicePrivateKey);24 // tslint:disable-next-line: no-unused-expression25 assert.exists(createMultipleItems, 'createMultipleItems is neither `null` or `undefined`');26 console.log(`Ext. createMultipleItems submitted with hash: ${createMultipleItems}`);27 await waitNewBlocks(api);28 const BitemListIndex = await api.query.nft.itemListIndex(idCollection);106 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;29 console.log(`itemListIndex count (after): ${BitemListIndex}`);30 if (BitemListIndex === AitemListIndex) { assert.fail('Corret token not added in collection!'); }107 } catch (e) {108 // tslint:disable-next-line:no-unused-expression109 expect(e).to.be.exist;110 }31 });111 });32 });112 });11333 it('(!negative test!) Create two Fungible tokens in active NFT collection', async () => {114 it('Create token in not existing collection', async () => {34 await usingApi(async (api) => {115 await usingApi(async (api: ApiPromise) => {35 const AitemListIndex = await api.query.nft.itemListIndex(idCollection);116 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;36 console.log(`itemListIndex count (before): ${AitemListIndex}`);37 const args = ['Fungible', 'Fungible'];38 const alicePrivateKey = privateKey('//Alice');117 const Alice = privateKey('//Alice');39 const createMultipleItems = await api.tx.nft118 const createMultipleItemsTx = await api.tx.nft40 .createMultipleItems(idCollection, alicesPublicKey, args)119 .createMultipleItems(collectionId, Alice.address, ['NFT', 'NFT', 'NFT']);41 .signAndSend(alicePrivateKey);42 // tslint:disable-next-line: no-unused-expression43 assert.exists(createMultipleItems, 'createMultipleItems is neither `null` or `undefined`');44 console.log(`Ext. createMultipleItems submitted with hash: ${createMultipleItems}`);45 await waitNewBlocks(api);46 const BitemListIndex = await api.query.nft.itemListIndex(idCollection);120 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;47 console.log(`itemListIndex count (after): ${BitemListIndex}`);48 if (BitemListIndex > AitemListIndex) { assert.fail('Incorrect token added in collection!'); }49 });121 });50 });122 });12351 it('(!negative test!) Create two ReFungible tokens in active NFT collection', async () => {124 it('Create NFT and Re-fungible tokens that has reached the maximum data limit', async () => {52 await usingApi(async (api) => {125 await usingApi(async (api: ApiPromise) => {126 // NFT53 const AitemListIndex = await api.query.nft.itemListIndex(idCollection);127 const collectionId = await createCollectionExpectSuccess();54 console.log(`itemListIndex count (before): ${AitemListIndex}`);55 const args = ['ReFungible', 'ReFungible'];128 const Alice = privateKey('//Alice');56 const alicePrivateKey = privateKey('//Alice');129 const args = [130 { nft: ['A'.repeat(2049), 'A'.repeat(2049)] },131 { nft: ['B'.repeat(2049), 'B'.repeat(2049)] },132 { nft: ['C'.repeat(2049), 'C'.repeat(2049)] },133 ];57 const createMultipleItems = await api.tx.nft134 const createMultipleItemsTx = await api.tx.nft58 .createMultipleItems(idCollection, alicesPublicKey, args)135 .createMultipleItems(collectionId, Alice.address, args);59 .signAndSend(alicePrivateKey);60 // tslint:disable-next-line: no-unused-expression61 assert.exists(createMultipleItems, 'createMultipleItems is neither `null` or `undefined`');136 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;137138 // ReFungible139 const collectionIdReFungible =62 console.log(`Ext. createMultipleItems submitted with hash: ${createMultipleItems}`);140 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});141 const argsReFungible = [63 await waitNewBlocks(api);142 { ReFungible: ['1'.repeat(2049), '1'.repeat(2049)] },143 { ReFungible: ['2'.repeat(2049), '2'.repeat(2049)] },144 { ReFungible: ['3'.repeat(2049), '3'.repeat(2049)] },145 ];64 const BitemListIndex = await api.query.nft.itemListIndex(idCollection);146 const createMultipleItemsTxFungible = await api.tx.nft65 console.log(`itemListIndex count (after): ${BitemListIndex}`);147 .createMultipleItems(collectionIdReFungible, Alice.address, argsReFungible);66 if (BitemListIndex > AitemListIndex) { assert.fail('Incorrect token added in collection!'); }148 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTxFungible)).to.be.rejected;67 });149 });68 });150 });151152 it('Create tokens with different types', async () => {153 await usingApi(async (api: ApiPromise) => {154 const collectionId = await createCollectionExpectSuccess();155 const Alice = privateKey('//Alice');156 const createMultipleItemsTx = await api.tx.nft157 .createMultipleItems(collectionId, Alice.address, ['NFT', 'Fungible', 'ReFungible']);158 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;159 // garbage collection :-D160 await destroyCollectionExpectSuccess(collectionId);161 });162 });163164 it('Create tokens with different data limits <> maximum data limit', async () => {165 await usingApi(async (api: ApiPromise) => {166 const collectionId = await createCollectionExpectSuccess();167 const Alice = privateKey('//Alice');168 const args = [169 { nft: ['A', 'A'] },170 { nft: ['B', 'B'.repeat(2049)] },171 { nft: ['C'.repeat(2049), 'C'] },172 ];173 const createMultipleItemsTx = await api.tx.nft174 .createMultipleItems(collectionId, Alice.address, args);175 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;176 });177 });69});178});70179tests/src/destroyCollection.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//51import chai from 'chai';6import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';7import chaiAsPromised from 'chai-as-promised';3import { default as usingApi, submitTransactionAsync } from "./substrate/substrate-api";8import { default as usingApi } from "./substrate/substrate-api";4import { createCollectionExpectSuccess, createCollectionExpectFailure, destroyCollectionExpectSuccess, destroyCollectionExpectFailure } from "./util/helpers";9import { createCollectionExpectSuccess, destroyCollectionExpectSuccess, destroyCollectionExpectFailure } from "./util/helpers";5import type { AccountId, EventRecord } from '@polkadot/types/interfaces';6import privateKey from './substrate/privateKey';7108chai.use(chaiAsPromised);11chai.use(chaiAsPromised);9const expect = chai.expect;101211describe('integration test: ext. destroyCollection():', () => {13describe('integration test: ext. destroyCollection():', () => {12 it('NFT collection can be destroyed', async () => {14 it('NFT collection can be destroyed', async () => {18 await destroyCollectionExpectSuccess(collectionId);20 await destroyCollectionExpectSuccess(collectionId);19 });21 });20 it('ReFungible collection can be destroyed', async () => {22 it('ReFungible collection can be destroyed', async () => {21 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});23 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});22 await destroyCollectionExpectSuccess(collectionId);24 await destroyCollectionExpectSuccess(collectionId);23 });25 });24});26});tests/src/enableContractSponsoring.test.tsdiffbeforeafterbothno changes
tests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//51import { ApiPromise } from '@polkadot/api';6import { ApiPromise } from '@polkadot/api';2import BN from 'bn.js';3import chai from 'chai';7import chai from 'chai';4import chaiAsPromised from 'chai-as-promised';8import chaiAsPromised from 'chai-as-promised';5import privateKey from './substrate/privateKey';9import privateKey from './substrate/privateKey';tests/src/removeFromWhiteList.test.tsdiffbeforeafterbothno changes
tests/src/setCollectionLimits.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//51// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits6// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits2import { ApiPromise, Keyring } from '@polkadot/api';7import { ApiPromise, Keyring } from '@polkadot/api';tests/src/setCollectionSponsor.test.tsdiffbeforeafterboth9import { createCollectionExpectSuccess, setCollectionSponsorExpectSuccess, destroyCollectionExpectSuccess, setCollectionSponsorExpectFailure } from "./util/helpers";9import { createCollectionExpectSuccess, setCollectionSponsorExpectSuccess, destroyCollectionExpectSuccess, setCollectionSponsorExpectFailure } from "./util/helpers";10import { Keyring } from "@polkadot/api";10import { Keyring } from "@polkadot/api";11import { IKeyringPair } from "@polkadot/types/types";11import { IKeyringPair } from "@polkadot/types/types";12import type { AccountId } from '@polkadot/types/interfaces';131214chai.use(chaiAsPromised);13chai.use(chaiAsPromised);15const expect = chai.expect;14const expect = chai.expect;34 await setCollectionSponsorExpectSuccess(collectionId, bob.address);33 await setCollectionSponsorExpectSuccess(collectionId, bob.address);35 });34 });36 it('Set ReFungible collection sponsor', async () => {35 it('Set ReFungible collection sponsor', async () => {37 const collectionId = await createCollectionExpectSuccess({ mode: {type: 'ReFungible', decimalPoints: 0} });36 const collectionId = await createCollectionExpectSuccess({ mode: {type: 'ReFungible'} });38 await setCollectionSponsorExpectSuccess(collectionId, bob.address);37 await setCollectionSponsorExpectSuccess(collectionId, bob.address);39 });38 });4039tests/src/setConstOnChainSchema.test.tsdiffbeforeafterbothno changes
tests/src/setContractSponsoringRateLimit.test.tsdiffbeforeafterbothno changes
tests/src/setMintPermission.test.tsdiffbeforeafterbothno changes
tests/src/setPublicAccessMode.test.tsdiffbeforeafterboth1//
2// This file is subject to the terms and conditions defined in
3// file 'LICENSE', which is part of this source code package.
4//
5
1// https://unique-network.readthedocs.io/en/latest/jsapi.html#setschemaversion
6// https://unique-network.readthedocs.io/en/latest/jsapi.html#setschemaversion
2import { ApiPromise, Keyring } from '@polkadot/api';
7import { ApiPromise, Keyring } from '@polkadot/api';
tests/src/setSchemaVersion.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//51// https://unique-network.readthedocs.io/en/latest/jsapi.html#setschemaversion6// https://unique-network.readthedocs.io/en/latest/jsapi.html#setschemaversion2import { ApiPromise, Keyring } from '@polkadot/api';7import { ApiPromise, Keyring } from '@polkadot/api';3import { IKeyringPair } from '@polkadot/types/types';8import { IKeyringPair } from '@polkadot/types/types';4import BN from 'bn.js';5import chai from 'chai';9import chai from 'chai';6import chaiAsPromised from 'chai-as-promised';10import chaiAsPromised from 'chai-as-promised';7import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';11import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';9810299 it('execute setSchemaVersion with not correct schema version', async () => {103 it('execute setSchemaVersion with not correct schema version', async () => {100 await usingApi(async (api: ApiPromise) => {104 await usingApi(async (api: ApiPromise) => {105 const consoleError = console.error;106 console.error = (message: string) => {};101 try {107 try {102 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Test');108 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Test');103 await submitTransactionAsync(alice, tx);109 await submitTransactionAsync(alice, tx);104 } catch (e) {110 } catch (e) {105 // tslint:disable-next-line:no-unused-expression111 // tslint:disable-next-line:no-unused-expression106 expect(e).to.be.exist;112 expect(e).to.be.exist;107 }113 } finally {114 console.error = consoleError;115 }108 });116 });109 });117 });110118tests/src/setVariableMetaData.test.tsdiffbeforeafterbothno changes
tests/src/setVariableOnChainSchema.test.tsdiffbeforeafterbothno changes
tests/src/substrate/substrate-api.tsdiffbeforeafterboth242425 // TODO: Remove, this is temporary: Filter unneeded API output 25 // TODO: Remove, this is temporary: Filter unneeded API output 26 // (Jaco promised it will be removed in the next version)26 // (Jaco promised it will be removed in the next version)27 // const consoleLog = console.log;27 const consoleLog = console.log;28 // console.log = (message: string) => {28 console.log = (message: string) => {29 // if (!(message.includes("API/INIT: Capabilities detected") || message.includes("2021-"))) {29 if (message.includes("API/INIT: Capabilities detected") || message.includes("2021-")) {}30 // consoleLog(message);30 else if (message.includes("StorageChangeSet:: WebSocket is not connected") || message.includes("2021-")) {}31 // }31 else consoleLog(message);32 // };32 };33 const consoleErr = console.error;34 console.error = (message: string) => {35 if (message.includes("StorageChangeSet:: WebSocket is not connected") || message.includes("2021-")) {}36 else consoleErr(message);37 };333834 try {39 try {35 await promisifySubstrate(api, async () => {40 await promisifySubstrate(api, async () => {40 })();45 })();41 } finally {46 } finally {42 await api.disconnect();47 await api.disconnect();43 // console.log = consoleLog;48 console.log = consoleLog;49 console.error = consoleErr;44 }50 }45}51}4652115 await transaction.signAndSend(sender, ({ events = [], status }) => {121 await transaction.signAndSend(sender, ({ events = [], status }) => {116 const transactionStatus = getTransactionStatus(events, status);122 const transactionStatus = getTransactionStatus(events, status);117123118 console.log('transactionStatus', transactionStatus, 'events', events);124 // console.log('transactionStatus', transactionStatus, 'events', events);119125120 if (transactionStatus == TransactionStatus.Success) {126 if (transactionStatus === TransactionStatus.Success) {121 resolve(events);127 resolve(events);122 } else if (transactionStatus == TransactionStatus.Fail) {128 } else if (transactionStatus === TransactionStatus.Fail) {123 reject(events);129 reject(events);124 }130 }125 });131 });tests/src/toggleContractWhiteList.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//51import chai from "chai";6import chai from "chai";2import chaiAsPromised from 'chai-as-promised';7import chaiAsPromised from 'chai-as-promised';tests/src/transfer.test.tsdiffbeforeafterboth63 });63 });64 });64 });656566 it('Create collection, balance transfers and check balance', async () => {66 it('User can transfer owned token', async () => {67 await usingApi(async (api) => {67 await usingApi(async (api) => {68 const Alice = privateKey('//Alice');68 const Alice = privateKey('//Alice');69 const Bob = privateKey('//Bob');69 const Bob = privateKey('//Bob');77 await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');77 await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');78 // reFungible78 // reFungible79 const reFungibleCollectionId = await79 const reFungibleCollectionId = await80 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});80 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});81 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');81 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');82 await transferExpectSuccess(reFungibleCollectionId,82 await transferExpectSuccess(reFungibleCollectionId,83 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');83 newReFungibleTokenId, Alice, Bob, 100, 'ReFungible');84 });84 });85 });85 });86});86});119 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');119 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');120 // reFungible120 // reFungible121 const reFungibleCollectionId = await121 const reFungibleCollectionId = await122 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});122 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});123 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');123 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');124 await destroyCollectionExpectSuccess(reFungibleCollectionId);124 await destroyCollectionExpectSuccess(reFungibleCollectionId);125 await transferExpectFail(reFungibleCollectionId,125 await transferExpectFail(reFungibleCollectionId,134 await transferExpectFail(fungibleCollectionId, 2, Alice, Bob, 1, 'Fungible');134 await transferExpectFail(fungibleCollectionId, 2, Alice, Bob, 1, 'Fungible');135 // reFungible135 // reFungible136 const reFungibleCollectionId = await136 const reFungibleCollectionId = await137 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});137 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});138 await transferExpectFail(reFungibleCollectionId,138 await transferExpectFail(reFungibleCollectionId,139 2, Alice, Bob, 1, 'ReFungible');139 2, Alice, Bob, 1, 'ReFungible');140 });140 });151 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');151 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');152 // reFungible152 // reFungible153 const reFungibleCollectionId = await153 const reFungibleCollectionId = await154 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});154 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});155 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');155 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');156 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);156 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);157 await transferExpectFail(reFungibleCollectionId,157 await transferExpectFail(reFungibleCollectionId,168 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Charlie, Bob, 1, 'Fungible');168 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Charlie, Bob, 1, 'Fungible');169 // reFungible169 // reFungible170 const reFungibleCollectionId = await170 const reFungibleCollectionId = await171 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});171 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});172 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');172 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');173 await transferExpectFail(reFungibleCollectionId,173 await transferExpectFail(reFungibleCollectionId,174 newReFungibleTokenId, Charlie, Bob, 1, 'ReFungible');174 newReFungibleTokenId, Charlie, Bob, 1, 'ReFungible');tests/src/transferFrom.test.tsdiffbeforeafterboth41 await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1, 'Fungible');41 await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1, 'Fungible');42 // reFungible42 // reFungible43 const reFungibleCollectionId = await43 const reFungibleCollectionId = await44 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});44 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});45 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');45 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');46 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);46 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 100);47 await transferFromExpectSuccess(reFungibleCollectionId,47 await transferFromExpectSuccess(reFungibleCollectionId,48 newReFungibleTokenId, Bob, Alice, Charlie, 1, 'ReFungible');48 newReFungibleTokenId, Bob, Alice, Charlie, 100, 'ReFungible');49 });49 });50 });50 });51});51});110 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);110 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);111 // reFungible111 // reFungible112 const reFungibleCollectionId = await112 const reFungibleCollectionId = await113 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});113 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});114 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');114 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');115 await transferFromExpectFail(reFungibleCollectionId,115 await transferFromExpectFail(reFungibleCollectionId,116 newReFungibleTokenId, Bob, Alice, Charlie, 1);116 newReFungibleTokenId, Bob, Alice, Charlie, 1);136 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 2);136 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 2);137 // reFungible137 // reFungible138 const reFungibleCollectionId = await138 const reFungibleCollectionId = await139 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});139 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});140 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');140 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');141 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);141 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);142 await transferFromExpectFail(reFungibleCollectionId,142 await transferFromExpectFail(reFungibleCollectionId,149 const Alice = privateKey('//Alice');149 const Alice = privateKey('//Alice');150 const Bob = privateKey('//Bob');150 const Bob = privateKey('//Bob');151 const Charlie = privateKey('//Charlie');151 const Charlie = privateKey('//Charlie');152 const Dave = privateKey('//DAVE');152 const Dave = privateKey('//Dave');153 // nft153 // nft154 const nftCollectionId = await createCollectionExpectSuccess();154 const nftCollectionId = await createCollectionExpectSuccess();155 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');155 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');175 }175 }176 // reFungible176 // reFungible177 const reFungibleCollectionId = await177 const reFungibleCollectionId = await178 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});178 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});179 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');179 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');180 try {180 try {181 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Bob);181 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Bob);tests/src/types.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//51import BN from 'bn.js';6import BN from 'bn.js';27tests/src/util/contracthelpers.tsdiffbeforeafterboth556import chai from "chai";6import chai from "chai";7import chaiAsPromised from 'chai-as-promised';7import chaiAsPromised from 'chai-as-promised';8import { submitTransactionAsync } from "../substrate/substrate-api";8import { submitTransactionAsync, submitTransactionExpectFailAsync } from "../substrate/substrate-api";9import fs from "fs";9import fs from "fs";10import { Abi, BlueprintPromise as Blueprint, CodePromise, ContractPromise as Contract } from "@polkadot/api-contract";10import { Abi, BlueprintPromise as Blueprint, CodePromise, ContractPromise as Contract } from "@polkadot/api-contract";11import { IKeyringPair } from "@polkadot/types/types";11import { IKeyringPair } from "@polkadot/types/types";14chai.use(chaiAsPromised);14chai.use(chaiAsPromised);15const expect = chai.expect;15const expect = chai.expect;16import { BigNumber } from 'bignumber.js';16import { BigNumber } from 'bignumber.js';17import { findUnusedAddress } from '../util/helpers';17import { findUnusedAddress, getGenericResult } from '../util/helpers';181819const value = 0;19const value = 0;20const gasLimit = '200000000000';20const gasLimit = '200000000000';92 return (result.result.asOk.data[0] == 0x00) ? false : true;92 return (result.result.asOk.data[0] == 0x00) ? false : true;93}93}9495export async function toggleFlipValueExpectSuccess(sender: IKeyringPair, contract: Contract) {96 const tx = contract.tx.flip(value, gasLimit);97 const events = await submitTransactionAsync(sender, tx);98 const result = getGenericResult(events);99100 expect(result.success).to.be.true;101}102103export async function toggleFlipValueExpectFailure(sender: IKeyringPair, contract: Contract) {104 const tx = contract.tx.flip(value, gasLimit);105 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;106}9410795function instantiateTransferContract(alice: IKeyringPair, blueprint: Blueprint) : Promise<any> {108function instantiateTransferContract(alice: IKeyringPair, blueprint: Blueprint) : Promise<any> {96 return new Promise<any>(async (resolve, reject) => {109 return new Promise<any>(async (resolve, reject) => {tests/src/util/helpers.tsdiffbeforeafterboth51 Value: BN;51 Value: BN;52}52}535354interface IReFungibleTokenDataType {54export interface IReFungibleTokenDataType {55 Owner: IReFungibleOwner[];55 Owner: IReFungibleOwner[];56 ConstData: number[];56 ConstData: number[];57 VariableData: number[];57 VariableData: number[];124124125interface ReFungible {125interface ReFungible {126 type: 'ReFungible';126 type: 'ReFungible';127 decimalPoints: number;128}127}129130interface Nft {131 type: 'NFT'132}133134interface Fungible {135 type: 'Fungible',136 decimalPoints: number137}138139interface ReFungible {140 type: 'ReFungible',141 decimalPoints: number142}143128144type CollectionMode = Nft | Fungible | ReFungible | Invalid;129type CollectionMode = Nft | Fungible | ReFungible | Invalid;145130174 } else if (mode.type === 'Fungible') {159 } else if (mode.type === 'Fungible') {175 modeprm = {fungible: mode.decimalPoints};160 modeprm = {fungible: mode.decimalPoints};176 } else if (mode.type === 'ReFungible') {161 } else if (mode.type === 'ReFungible') {177 modeprm = {refungible: mode.decimalPoints};162 modeprm = {refungible: null};178 } else if (mode.type === 'Invalid') {163 } else if (mode.type === 'Invalid') {179 modeprm = {invalid: null};164 modeprm = {invalid: null};180 }165 }216 } else if (mode.type === 'Fungible') {201 } else if (mode.type === 'Fungible') {217 modeprm = {fungible: mode.decimalPoints};202 modeprm = {fungible: mode.decimalPoints};218 } else if (mode.type === 'ReFungible') {203 } else if (mode.type === 'ReFungible') {219 modeprm = {refungible: mode.decimalPoints};204 modeprm = {refungible: null};220 } else if (mode.type === 'Invalid') {205 } else if (mode.type === 'Invalid') {221 modeprm = {invalid: null};206 modeprm = {invalid: null};222 }207 }253 return unused;238 return unused;254}239}240241export async function findNotExistingCollection(api: ApiPromise): Promise<number> {242 const totalNumber = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10) as unknown as number;243 const newCollection: number = totalNumber + 1;244 return newCollection;245}255246256function getDestroyResult(events: EventRecord[]): boolean {247function getDestroyResult(events: EventRecord[]): boolean {257 let success: boolean = false;248 let success: boolean = false;379 });370 });380}371}372373export async function enableContractSponsoringExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, enable: boolean) {374 await usingApi(async (api) => {375 const tx = api.tx.nft.enableContractSponsoring(contractAddress, enable);376 const events = await submitTransactionAsync(sender, tx);377 const result = getGenericResult(events);378379 expect(result.success).to.be.true;380 });381}382383export async function enableContractSponsoringExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, enable: boolean) {384 await usingApi(async (api) => {385 const tx = api.tx.nft.enableContractSponsoring(contractAddress, enable);386 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;387 const result = getGenericResult(events);388389 expect(result.success).to.be.false;390 });391}392393export async function setContractSponsoringRateLimitExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) {394 await usingApi(async (api) => {395 const tx = api.tx.nft.setContractSponsoringRateLimit(contractAddress, rateLimit);396 const events = await submitTransactionAsync(sender, tx);397 const result = getGenericResult(events);398399 expect(result.success).to.be.true;400 });401}402403export async function setContractSponsoringRateLimitExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) {404 await usingApi(async (api) => {405 const tx = api.tx.nft.setContractSponsoringRateLimit(contractAddress, rateLimit);406 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;407 const result = getGenericResult(events);408409 expect(result.success).to.be.false;410 });411}412413export async function setVariableMetaDataExpectSuccess(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) {414 await usingApi(async (api) => {415 const tx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(data).toString('hex'));416 const events = await submitTransactionAsync(sender, tx);417 const result = getGenericResult(events);418419 expect(result.success).to.be.true;420 });421}422423export async function setVariableMetaDataExpectFailure(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) {424 await usingApi(async (api) => {425 const tx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(data).toString('hex'));426 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;427 });428}381429382export interface CreateFungibleData extends Struct {430export interface CreateFungibleData extends Struct {383 readonly value: u128;431 readonly value: u128;440 }488 }441 const transferFromTx = await api.tx.nft.transferFrom(489 const transferFromTx = await api.tx.nft.transferFrom(442 accountFrom.address, accountTo.address, collectionId, tokenId, value);490 accountFrom.address, accountTo.address, collectionId, tokenId, value);443 const events = await submitTransactionAsync(accountFrom, transferFromTx);491 const events = await submitTransactionAsync(accountApproved, transferFromTx);444 const result = getCreateItemResult(events);492 const result = getCreateItemResult(events);445 // tslint:disable-next-line:no-unused-expression493 // tslint:disable-next-line:no-unused-expression446 expect(result.success).to.be.true;494 expect(result.success).to.be.true;558 if (createMode === 'Fungible') {606 if (createMode === 'Fungible') {559 const createData = {fungible: {value: 10}};607 const createData = {fungible: {value: 10}};560 tx = api.tx.nft.createItem(collectionId, owner, createData);608 tx = api.tx.nft.createItem(collectionId, owner, createData);561 } else {609 } else if (createMode === 'ReFungible') {610 const createData = {refungible: {const_data: [], variable_data: [], pieces: 100}};611 tx = api.tx.nft.createItem(collectionId, owner, createData);612 } else {562 tx = api.tx.nft.createItem(collectionId, owner, createMode);613 tx = api.tx.nft.createItem(collectionId, owner, createMode);563 }614 }564 const events = await submitTransactionAsync(sender, tx);615 const events = await submitTransactionAsync(sender, tx);583 return newItemId;634 return newItemId;584}635}636637export async function createItemExpectFailure(638 sender: IKeyringPair, collectionId: number, createMode: string, owner: string = sender.address) {639 await usingApi(async (api) => {640 const tx = api.tx.nft.createItem(collectionId, owner, createMode);641 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;642 const result = getCreateItemResult(events);643644 expect(result.success).to.be.false;645 });646}585647586export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {648export async function setPublicAccessModeExpectSuccess(649 sender: IKeyringPair, collectionId: number,650 accessMode: 'Normal' | 'WhiteList',651) {587 await usingApi(async (api) => {652 await usingApi(async (api) => {588653589 // Run the transaction654 // Run the transaction590 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');655 const tx = api.tx.nft.setPublicAccessMode(collectionId, accessMode);591 const events = await submitTransactionAsync(sender, tx);656 const events = await submitTransactionAsync(sender, tx);592 const result = getGenericResult(events);657 const result = getGenericResult(events);593658597 // What to expect662 // What to expect598 // tslint:disable-next-line:no-unused-expression663 // tslint:disable-next-line:no-unused-expression599 expect(result.success).to.be.true;664 expect(result.success).to.be.true;600 expect(collection.Access).to.be.equal('WhiteList');665 expect(collection.Access).to.be.equal(accessMode);601 });666 });602}667}668669export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {670 await setPublicAccessModeExpectSuccess(sender, collectionId, 'WhiteList');671}672673export async function disableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {674 await setPublicAccessModeExpectSuccess(sender, collectionId, 'Normal');675}603676604export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {677export async function setMintPermissionExpectSuccess(sender: IKeyringPair, collectionId: number, enabled: boolean) {605 await usingApi(async (api) => {678 await usingApi(async (api) => {606679607 // Run the transaction680 // Run the transaction608 const tx = api.tx.nft.setMintPermission(collectionId, true);681 const tx = api.tx.nft.setMintPermission(collectionId, enabled);609 const events = await submitTransactionAsync(sender, tx);682 const events = await submitTransactionAsync(sender, tx);610 const result = getGenericResult(events);683 const result = getGenericResult(events);611684612 // Get the collection685 // Get the collection613 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();686 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();614687615 // What to expect688 // What to expect689 // tslint:disable-next-line:no-unused-expression616 expect(result.success).to.be.true;690 expect(result.success).to.be.true;617 expect(collection.MintMode).to.be.equal(true);691 expect(collection.MintMode).to.be.equal(enabled);618 });692 });619}693}694695export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {696 await setMintPermissionExpectSuccess(sender, collectionId, true);697}698699export async function setMintPermissionExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {700 await usingApi(async (api) => {701 // Run the transaction702 const tx = api.tx.nft.setMintPermission(collectionId, enabled);703 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;704 const result = getCreateCollectionResult(events);705 // tslint:disable-next-line:no-unused-expression706 expect(result.success).to.be.false;707 });708}709710export async function isWhitelisted(collectionId: number, address: string) {711 let whitelisted: boolean = false;712 await usingApi(async (api) => {713 whitelisted = (await api.query.nft.whiteList(collectionId, address)).toJSON() as unknown as boolean;714 });715 return whitelisted;716}620717621export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {718export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {622 await usingApi(async (api) => {719 await usingApi(async (api) => {640 });737 });641}738}739740export async function removeFromWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {741 await usingApi(async (api) => {742 // Run the transaction743 const tx = api.tx.nft.removeFromWhiteList(collectionId, address);744 const events = await submitTransactionAsync(sender, tx);745 const result = getGenericResult(events);746747 // What to expect748 // tslint:disable-next-line:no-unused-expression749 expect(result.success).to.be.true;750 });751}752753export async function removeFromWhiteListExpectFailure(sender: IKeyringPair, collectionId: number, address: string) {754 await usingApi(async (api) => {755 // Run the transaction756 const tx = api.tx.nft.removeFromWhiteList(collectionId, address);757 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;758 const result = getGenericResult(events);759760 // What to expect761 // tslint:disable-next-line:no-unused-expression762 expect(result.success).to.be.false;763 });764}642765643export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)766export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)644 : Promise<ICollectionInterface | null> => {767 : Promise<ICollectionInterface | null> => {