difftreelog
Merge branch 'develop' into fix/tests
in: master
49 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5114,7 +5114,7 @@
"pallet-randomness-collective-flip",
"pallet-refungible",
"pallet-sudo",
- "pallet-template-charge-transaction",
+ "pallet-template-transaction-payment",
"pallet-timestamp",
"pallet-transaction-payment",
"pallet-transaction-payment-rpc-runtime-api",
@@ -6350,9 +6350,9 @@
]
[[package]]
-name = "pallet-template-charge-transaction"
+name = "pallet-template-transaction-payment"
version = "3.0.0"
-source = "git+https://github.com/UniqueNetwork/pallet-sponsoring#e5d3354ab68face1b2ef709dc7f629803f56598d"
+source = "git+https://github.com/UniqueNetwork/pallet-sponsoring#ab8b91e9350a31133f3a3e4f52a84c6de4108e95"
dependencies = [
"frame-benchmarking",
"frame-support",
@@ -11696,7 +11696,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f559b464de2e2bdabcac6a210d12e9b5a5973c251e102c44c585c71d51bd78e"
dependencies = [
- "cfg-if 0.1.10",
+ "cfg-if 1.0.0",
"rand 0.8.4",
"static_assertions",
]
@@ -11847,7 +11847,7 @@
[[package]]
name = "up-sponsorship"
version = "0.1.0"
-source = "git+https://github.com/UniqueNetwork/pallet-sponsoring#e5d3354ab68face1b2ef709dc7f629803f56598d"
+source = "git+https://github.com/UniqueNetwork/pallet-sponsoring#ab8b91e9350a31133f3a3e4f52a84c6de4108e95"
dependencies = [
"impl-trait-for-tuples 0.2.1",
]
README.mddiffbeforeafterboth--- a/README.md
+++ b/README.md
@@ -41,7 +41,7 @@
- Re-Fungible Token Mode
- Off-Chain Schema to store token image URLs
- Alternative economic model
- - White Lists and Public Mint Permission
+ - Allow Lists and Public Mint Permission
- Use example: [SubstraPunks Game](https://github.com/usetech-llc/substrapunks), fully hosted on IPFS and NFT Testnet
Blockchain.
doc/builders_walk_through.mddiffbeforeafterboth--- a/doc/builders_walk_through.md
+++ b/doc/builders_walk_through.md
@@ -173,11 +173,11 @@
6. Now select your "ZERO BALANCE" address in the drop-down list and repeat searching and adding the collection for this address.
7. Transfer token back to your main address. Observe that despite the zero balance, the transfer is successful.
-### White Lists and Public Mint Permission
+### Allow Lists and Public Mint Permission
-We did not complete these features in time by Hackusama deadline, but because they are important for security of the network, we completed them after the deadline anyway. They can be seen in branch [feature/white_list](https://github.com/usetech-llc/nft_parachain/tree/feature/white_list). Here are the permalinks to essential functions:
+We did not complete these features in time by Hackusama deadline, but because they are important for security of the network, we completed them after the deadline anyway. They can be seen in branch [feature/allow_list](https://github.com/usetech-llc/nft_parachain/tree/feature/allow_list). Here are the permalinks to essential functions:
-[white_lists](https://github.com/usetech-llc/nft_parachain/blob/b7c59f0085ed2bc1922e937adf68ef4174a8ba36/pallets/nft/src/lib.rs#L659)
+[allow_lists](https://github.com/usetech-llc/nft_parachain/blob/b7c59f0085ed2bc1922e937adf68ef4174a8ba36/pallets/nft/src/lib.rs#L659)
[mint_permission](https://github.com/usetech-llc/nft_parachain/blob/b7c59f0085ed2bc1922e937adf68ef4174a8ba36/pallets/nft/src/lib.rs#L373)
doc/economic_model.mddiffbeforeafterboth--- a/doc/economic_model.md
+++ b/doc/economic_model.md
@@ -40,7 +40,7 @@
Set the collection sponsor address. The sponsorship needs to be confirmed by sending a ConfirmSponsorship transaction
from that address. Also, the protection measures need to be in place so that sponsor account cannot be depleted by
-malicious users. White listing is one of the measured. It can be enabled with SetPublicAccessMode method.
+malicious users. Allow listing is one of the measured. It can be enabled with SetPublicAccessMode method.
##### List of transactions
@@ -67,7 +67,7 @@
Further, the logic is similar to limiting by token as above. If only one of the limits (by token or by address)
indicates that fee should be paid by the user, the fee is paid by the user.
- A pallet method (SetCollectionRateLimits) will be added to set these parameters and enable rate limiting.
-- One idea to consider is deposits that must be made by an address in order to become white listed (instead of admin
+- One idea to consider is deposits that must be made by an address in order to become allow listed (instead of admin
review).
#### Permissions
@@ -173,12 +173,12 @@
#### Description
-Toggle between normal and white list access for the methods with access for “Anyone”. If White List mode is enabled,
-AddToWhiteList and RemoveFromWhiteList methods can be called to add to and remove addresses from the white list.
+Toggle between normal and allow list access for the methods with access for “Anyone”. If Allow List mode is enabled,
+AddToAllowList and RemoveFromAllowList methods can be called to add to and remove addresses from the allow list.
-White list mode is the property of collection. If it is turned on, all public operations such as token transfers, for
-example, which normally have “Anyone” permission, become white listed, i.e. are only available to collection owner,
-admins, and addresses from the white list. White lists can be helpful for rate limiting of transfers when collection
+Allow list mode is the property of collection. If it is turned on, all public operations such as token transfers, for
+example, which normally have “Anyone” permission, become allow listed, i.e. are only available to collection owner,
+admins, and addresses from the allow list. Allow lists can be helpful for rate limiting of transfers when collection
sponsoring is enabled.
#### Permissions
@@ -190,13 +190,13 @@
- CollectionID: ID of the Collection to set access mode for
- Mode
- 0 = Normal
- - 1 = White list
+ - 1 = Allow list
-### AddToWhiteList
+### AddToAllowList
#### Description
-Add an address to white list.
+Add an address to allow list.
#### Permissions
@@ -208,11 +208,11 @@
- CollectionID: ID of the Collection
- Address
-### RemoveFromWhiteList
+### RemoveFromAllowList
#### Description
-Remove an address from white list.
+Remove an address from allow list.
#### Permissions
doc/hackusama_walk_through.mddiffbeforeafterboth--- a/doc/hackusama_walk_through.md
+++ b/doc/hackusama_walk_through.md
@@ -187,14 +187,14 @@
address.
7. Transfer token back to your main address. Observe that despite the zero balance, the transfer is successful.
-### White Lists and Public Mint Permission
+### Allow Lists and Public Mint Permission
We did not complete these features in time by Hackusama deadline, but because they are important for security of the
network, we completed them after the deadline anyway. They can be seen in branch
-[feature/white_list](https://github.com/usetech-llc/nft_parachain/tree/feature/white_list). Here are the permalinks to
+[feature/allow_list](https://github.com/usetech-llc/nft_parachain/tree/feature/allow_list). Here are the permalinks to
essential functions:
-[white_lists](https://github.com/usetech-llc/nft_parachain/blob/b7c59f0085ed2bc1922e937adf68ef4174a8ba36/pallets/nft/src/lib.rs#L659)
+[allow_lists](https://github.com/usetech-llc/nft_parachain/blob/b7c59f0085ed2bc1922e937adf68ef4174a8ba36/pallets/nft/src/lib.rs#L659)
[mint_permission](https://github.com/usetech-llc/nft_parachain/blob/b7c59f0085ed2bc1922e937adf68ef4174a8ba36/pallets/nft/src/lib.rs#L373)
doc/milestone_1.mddiffbeforeafterboth--- a/doc/milestone_1.md
+++ b/doc/milestone_1.md
@@ -1,38 +1,38 @@
## Milestone 1
-**User Paid Fees and Sponsored. Finish/Debug white listing and spam/DOS protection**
+**User Paid Fees and Sponsored. Finish/Debug allow listing and spam/DOS protection**
Implementation of two models
If collection sponsor is set and confirmed for collection instance that means Sponsored Economic Model has chosen. Otherwise default economic model User Paid Fees is set.
-For Sponsored Economic Model exists timeouts for token transactions. For every NFT type timeouts defined separately. Timeouts and white list limits together prevented spam and malicious actions.
+For Sponsored Economic Model exists timeouts for token transactions. For every NFT type timeouts defined separately. Timeouts and allow list limits together prevented spam and malicious actions.
Set sponsor
`nft`.`set_collection_sponsor`
Confirm sponsor
`nft`.`confirm_sponsorship`
-A white list mode presented by collection property `access` and can be enabled with `set_public_access_mode`. Rules provide spam/DOS protection
-While collection in the white list mode rules below are active:
-Owner can add address to white list
-Admin can add address to white list
-Non-privileged user cannot add address to white list
-Owner can remove address from white list
-Admin can remove address from white list
-Non-privileged user cannot remove address from white list
-If Public Access mode is set to WhiteList, tokens can’t be transferred from a non-whitelisted address with transfer or transferFrom
-If Public Access mode is set to WhiteList, tokens can’t be transferred to a non-whitelisted address with transfer or transferFrom
-If Public Access mode is set to WhiteList, tokens can’t be destroyed by a non-whitelisted address (even if it owned them before enabling WhiteList mode)
-If Public Access mode is set to WhiteList, token transfers can’t be Approved by a non-whitelisted address (see Approve method).
-If Public Access mode is set to WhiteList, tokens can be transferred to a whitelisted address with transfer or transferFrom
-If Public Access mode is set to WhiteList, tokens can be transferred from a whitelisted address with transfer or transferFrom
-If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by owner.
-If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by admin.
-If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens cannot be created by non-privileged and white listed address.
-If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-white listed address.
-If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by owner.
-If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by admin.
-If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-white listed address.
-If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by non-privileged and white listed address.
+A allow list mode presented by collection property `access` and can be enabled with `set_public_access_mode`. Rules provide spam/DOS protection
+While collection in the allow list mode rules below are active:
+Owner can add address to allow list
+Admin can add address to allow list
+Non-privileged user cannot add address to allow list
+Owner can remove address from allow list
+Admin can remove address from allow list
+Non-privileged user cannot remove address from allow list
+If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom
+If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom
+If Public Access mode is set to AllowList, tokens can’t be destroyed by a non-allowlisted address (even if it owned them before enabling AllowList mode)
+If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method).
+If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer or transferFrom
+If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer or transferFrom
+If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner.
+If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin.
+If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and allow listed address.
+If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-allow listed address.
+If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner.
+If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin.
+If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-allow listed address.
+If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by non-privileged and allow listed address.
**Add missing custom types (CollectionMode, FungibleItemType, ReFungibleItemType)**
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -260,7 +260,7 @@
NoPermission,
/// Collection is not in mint mode.
PublicMintingNotAllowed,
- /// Address is not in white list.
+ /// Address is not in allow list.
AddressNotInAllowlist,
/// Collection name can not be longer than 63 char.
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -123,7 +123,7 @@
.checked_sub(amount)
.ok_or(<CommonError<T>>::TokenValueTooLow)?;
- if collection.access == AccessMode::WhiteList {
+ if collection.access == AccessMode::AllowList {
collection.check_allowlist(owner)?;
}
@@ -161,7 +161,7 @@
<CommonError<T>>::TransferNotAllowed,
);
- if collection.access == AccessMode::WhiteList {
+ if collection.access == AccessMode::AllowList {
collection.check_allowlist(from)?;
collection.check_allowlist(to)?;
}
@@ -307,7 +307,7 @@
spender: &T::CrossAccountId,
amount: u128,
) -> DispatchResult {
- if collection.access == AccessMode::WhiteList {
+ if collection.access == AccessMode::AllowList {
collection.check_allowlist(&owner)?;
collection.check_allowlist(&spender)?;
}
@@ -335,7 +335,7 @@
if spender.conv_eq(from) {
return Self::transfer(collection, from, to, amount);
}
- if collection.access == AccessMode::WhiteList {
+ if collection.access == AccessMode::AllowList {
// `from`, `to` checked in [`transfer`]
collection.check_allowlist(spender)?;
}
@@ -366,7 +366,7 @@
if spender.conv_eq(from) {
return Self::burn(collection, from, amount);
}
- if collection.access == AccessMode::WhiteList {
+ if collection.access == AccessMode::AllowList {
// `from` checked in [`burn`]
collection.check_allowlist(spender)?;
}
pallets/nft/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/nft/src/benchmarking.rs
+++ b/pallets/nft/src/benchmarking.rs
@@ -55,23 +55,23 @@
let collection = create_nft_collection::<T>(caller.clone())?;
}: _(RawOrigin::Signed(caller.clone()), collection)
- add_to_white_list {
+ add_to_allow_list {
let caller: T::AccountId = account("caller", 0, SEED);
- let whitelist_account: T::AccountId = account("admin", 0, SEED);
+ let allowlist_account: T::AccountId = account("admin", 0, SEED);
let collection = create_nft_collection::<T>(caller.clone())?;
- }: _(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(whitelist_account))
+ }: _(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(allowlist_account))
- remove_from_white_list {
+ remove_from_allow_list {
let caller: T::AccountId = account("caller", 0, SEED);
- let whitelist_account: T::AccountId = account("admin", 0, SEED);
+ let allowlist_account: T::AccountId = account("admin", 0, SEED);
let collection = create_nft_collection::<T>(caller.clone())?;
- <Pallet<T>>::add_to_white_list(RawOrigin::Signed(caller.clone()).into(), collection, T::CrossAccountId::from_sub(whitelist_account.clone()))?;
- }: _(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(whitelist_account))
+ <Pallet<T>>::add_to_allow_list(RawOrigin::Signed(caller.clone()).into(), collection, T::CrossAccountId::from_sub(allowlist_account.clone()))?;
+ }: _(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(allowlist_account))
set_public_access_mode {
let caller: T::AccountId = account("caller", 0, SEED);
let collection = create_nft_collection::<T>(caller.clone())?;
- }: _(RawOrigin::Signed(caller.clone()), collection, AccessMode::WhiteList)
+ }: _(RawOrigin::Signed(caller.clone()), collection, AccessMode::AllowList)
set_mint_permission {
let caller: T::AccountId = account("caller", 0, SEED);
pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -256,7 +256,7 @@
Ok(())
}
- /// Add an address to white list.
+ /// Add an address to allow list.
///
/// # Permissions
///
@@ -268,9 +268,9 @@
/// * collection_id.
///
/// * address.
- #[weight = <SelfWeightOf<T>>::add_to_white_list()]
+ #[weight = <SelfWeightOf<T>>::add_to_allow_list()]
#[transactional]
- pub fn add_to_white_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{
+ pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
let collection = <CollectionHandle<T>>::try_get(collection_id)?;
@@ -285,7 +285,7 @@
Ok(())
}
- /// Remove an address from white list.
+ /// Remove an address from allow list.
///
/// # Permissions
///
@@ -297,9 +297,9 @@
/// * collection_id.
///
/// * address.
- #[weight = <SelfWeightOf<T>>::remove_from_white_list()]
+ #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]
#[transactional]
- pub fn remove_from_white_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{
+ pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
let collection = <CollectionHandle<T>>::try_get(collection_id)?;
@@ -314,7 +314,7 @@
Ok(())
}
- /// Toggle between normal and white list access for the methods with access for `Anyone`.
+ /// Toggle between normal and allow list access for the methods with access for `Anyone`.
///
/// # Permissions
///
@@ -339,8 +339,8 @@
}
/// Allows Anyone to create tokens if:
- /// * White List is enabled, and
- /// * Address is added to white list, and
+ /// * Allow List is enabled, and
+ /// * Address is added to allow list, and
/// * This method was called with True parameter
///
/// # Permissions
@@ -502,8 +502,8 @@
/// * Collection Owner.
/// * Collection Admin.
/// * Anyone if
- /// * White List is enabled, and
- /// * Address is added to white list, and
+ /// * Allow List is enabled, and
+ /// * Address is added to allow list, and
/// * MintPermission is enabled (see SetMintPermission method)
///
/// # Arguments
@@ -528,8 +528,8 @@
/// * Collection Owner.
/// * Collection Admin.
/// * Anyone if
- /// * White List is enabled, and
- /// * Address is added to white list, and
+ /// * Allow List is enabled, and
+ /// * Address is added to allow list, and
/// * MintPermission is enabled (see SetMintPermission method)
///
/// # Arguments
pallets/nft/src/tests.rsdiffbeforeafterboth--- a/pallets/nft/src/tests.rs
+++ b/pallets/nft/src/tests.rs
@@ -460,7 +460,7 @@
}
#[test]
-fn nft_approve_and_transfer_from_white_list() {
+fn nft_approve_and_transfer_from_allow_list() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
@@ -485,19 +485,19 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
1,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
1,
account(1)
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
1,
account(2)
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
1,
account(3)
@@ -549,19 +549,19 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
1,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
1,
account(1)
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
1,
account(2)
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
1,
account(3)
@@ -609,19 +609,19 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
1,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
1,
account(1)
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
1,
account(2)
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
1,
account(3)
@@ -765,9 +765,9 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
collection_id,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
1,
account(1)
@@ -952,19 +952,19 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
1,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
1,
account(1)
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
1,
account(2)
));
- assert_ok!(TemplateModule::add_to_white_list(origin1, 1, account(3)));
+ assert_ok!(TemplateModule::add_to_allow_list(origin1, 1, account(3)));
assert_ok!(TemplateModule::transfer_from(
origin2,
@@ -987,22 +987,22 @@
// #region
#[test]
-fn owner_can_add_address_to_white_list() {
+fn owner_can_add_address_to_allow_list() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1,
collection_id,
account(2)
));
- assert!(TemplateModule::white_list(collection_id, 2));
+ assert!(TemplateModule::allow_list(collection_id, 2));
});
}
#[test]
-fn admin_can_add_address_to_white_list() {
+fn admin_can_add_address_to_allow_list() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1013,42 +1013,42 @@
collection_id,
account(2)
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin2,
collection_id,
account(3)
));
- assert!(TemplateModule::white_list(collection_id, 3));
+ assert!(TemplateModule::allow_list(collection_id, 3));
});
}
#[test]
-fn nonprivileged_user_cannot_add_address_to_white_list() {
+fn nonprivileged_user_cannot_add_address_to_allow_list() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin2 = Origin::signed(2);
assert_noop!(
- TemplateModule::add_to_white_list(origin2, collection_id, account(3)),
+ TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),
Error::<Test>::NoPermission
);
});
}
#[test]
-fn nobody_can_add_address_to_white_list_of_nonexisting_collection() {
+fn nobody_can_add_address_to_allow_list_of_nonexisting_collection() {
new_test_ext().execute_with(|| {
let origin1 = Origin::signed(1);
assert_noop!(
- TemplateModule::add_to_white_list(origin1, 1, account(2)),
+ TemplateModule::add_to_allow_list(origin1, 1, account(2)),
Error::<Test>::CollectionNotFound
);
});
}
#[test]
-fn nobody_can_add_address_to_white_list_of_deleted_collection() {
+fn nobody_can_add_address_to_allow_list_of_deleted_collection() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
@@ -1058,55 +1058,55 @@
collection_id
));
assert_noop!(
- TemplateModule::add_to_white_list(origin1, collection_id, account(2)),
+ TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),
Error::<Test>::CollectionNotFound
);
});
}
-// If address is already added to white list, nothing happens
+// If address is already added to allow list, nothing happens
#[test]
-fn address_is_already_added_to_white_list() {
+fn address_is_already_added_to_allow_list() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
collection_id,
account(2)
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1,
collection_id,
account(2)
));
- assert!(TemplateModule::white_list(collection_id, 2));
+ assert!(TemplateModule::allow_list(collection_id, 2));
});
}
#[test]
-fn owner_can_remove_address_from_white_list() {
+fn owner_can_remove_address_from_allow_list() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
collection_id,
account(2)
));
- assert_ok!(TemplateModule::remove_from_white_list(
+ assert_ok!(TemplateModule::remove_from_allow_list(
origin1,
collection_id,
account(2)
));
- assert!(!TemplateModule::white_list(collection_id, 2));
+ assert!(!TemplateModule::allow_list(collection_id, 2));
});
}
#[test]
-fn admin_can_remove_address_from_white_list() {
+fn admin_can_remove_address_from_allow_list() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1118,102 +1118,102 @@
account(2)
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1,
collection_id,
account(3)
));
- assert_ok!(TemplateModule::remove_from_white_list(
+ assert_ok!(TemplateModule::remove_from_allow_list(
origin2,
collection_id,
account(3)
));
- assert!(!TemplateModule::white_list(collection_id, 3));
+ assert!(!TemplateModule::allow_list(collection_id, 3));
});
}
#[test]
-fn nonprivileged_user_cannot_remove_address_from_white_list() {
+fn nonprivileged_user_cannot_remove_address_from_allow_list() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1,
collection_id,
account(2)
));
assert_noop!(
- TemplateModule::remove_from_white_list(origin2, collection_id, account(2)),
+ TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),
Error::<Test>::NoPermission
);
- assert!(TemplateModule::white_list(collection_id, 2));
+ assert!(TemplateModule::allow_list(collection_id, 2));
});
}
#[test]
-fn nobody_can_remove_address_from_white_list_of_nonexisting_collection() {
+fn nobody_can_remove_address_from_allow_list_of_nonexisting_collection() {
new_test_ext().execute_with(|| {
let origin1 = Origin::signed(1);
assert_noop!(
- TemplateModule::remove_from_white_list(origin1, 1, account(2)),
+ TemplateModule::remove_from_allow_list(origin1, 1, account(2)),
Error::<Test>::CollectionNotFound
);
});
}
#[test]
-fn nobody_can_remove_address_from_white_list_of_deleted_collection() {
+fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
collection_id,
account(2)
));
assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));
assert_noop!(
- TemplateModule::remove_from_white_list(origin2, collection_id, account(2)),
+ TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),
Error::<Test>::CollectionNotFound
);
- assert!(!TemplateModule::white_list(collection_id, 2));
+ assert!(!TemplateModule::allow_list(collection_id, 2));
});
}
-// If address is already removed from white list, nothing happens
+// If address is already removed from allow list, nothing happens
#[test]
-fn address_is_already_removed_from_white_list() {
+fn address_is_already_removed_from_allow_list() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
collection_id,
account(2)
));
- assert_ok!(TemplateModule::remove_from_white_list(
+ assert_ok!(TemplateModule::remove_from_allow_list(
origin1.clone(),
collection_id,
account(2)
));
- assert_ok!(TemplateModule::remove_from_white_list(
+ assert_ok!(TemplateModule::remove_from_allow_list(
origin1,
collection_id,
account(2)
));
- assert!(!TemplateModule::white_list(collection_id, 2));
+ assert!(!TemplateModule::allow_list(collection_id, 2));
});
}
-// If Public Access mode is set to WhiteList, tokens can’t be transferred from a non-whitelisted address with transfer or transferFrom (2 tests)
+// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)
#[test]
-fn white_list_test_1() {
+fn allow_list_test_1() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
@@ -1225,9 +1225,9 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
collection_id,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
collection_id,
account(2)
@@ -1235,13 +1235,13 @@
assert_noop!(
TemplateModule::transfer(origin1, account(3), 1, 1, 1),
- Error::<Test>::AddresNotInWhiteList
+ Error::<Test>::AddresNotInAllowList
);
});
}
#[test]
-fn white_list_test_2() {
+fn allow_list_test_2() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1252,14 +1252,14 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
collection_id,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
1,
account(1)
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
1,
account(2)
@@ -1275,7 +1275,7 @@
));
assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);
- assert_ok!(TemplateModule::remove_from_white_list(
+ assert_ok!(TemplateModule::remove_from_allow_list(
origin1.clone(),
1,
account(1)
@@ -1283,14 +1283,14 @@
assert_noop!(
TemplateModule::transfer_from(origin1, account(1), account(3), 1, 1, 1),
- Error::<Test>::AddresNotInWhiteList
+ Error::<Test>::AddresNotInAllowList
);
});
}
-// If Public Access mode is set to WhiteList, tokens can’t be transferred to a non-whitelisted address with transfer or transferFrom (2 tests)
+// If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom (2 tests)
#[test]
-fn white_list_test_3() {
+fn allow_list_test_3() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
@@ -1302,9 +1302,9 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
collection_id,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
1,
account(1)
@@ -1312,13 +1312,13 @@
assert_noop!(
TemplateModule::transfer(origin1, account(3), 1, 1, 1),
- Error::<Test>::AddresNotInWhiteList
+ Error::<Test>::AddresNotInAllowList
);
});
}
#[test]
-fn white_list_test_4() {
+fn allow_list_test_4() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
@@ -1330,14 +1330,14 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
collection_id,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
collection_id,
account(1)
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
collection_id,
account(2)
@@ -1353,7 +1353,7 @@
));
assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);
- assert_ok!(TemplateModule::remove_from_white_list(
+ assert_ok!(TemplateModule::remove_from_allow_list(
origin1.clone(),
collection_id,
account(2)
@@ -1361,14 +1361,14 @@
assert_noop!(
TemplateModule::transfer_from(origin1, account(1), account(3), 1, 1, 1),
- Error::<Test>::AddresNotInWhiteList
+ Error::<Test>::AddresNotInAllowList
);
});
}
-// If Public Access mode is set to WhiteList, tokens can’t be destroyed by a non-whitelisted address (even if it owned them before enabling WhiteList mode)
+// If Public Access mode is set to AllowList, tokens can’t be destroyed by a non-allowlisted address (even if it owned them before enabling AllowList mode)
#[test]
-fn white_list_test_5() {
+fn allow_list_test_5() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
@@ -1380,18 +1380,18 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
collection_id,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
assert_noop!(
TemplateModule::burn_item(origin1.clone(), 1, 1, 5),
- Error::<Test>::AddresNotInWhiteList
+ Error::<Test>::AddresNotInAllowList
);
});
}
-// If Public Access mode is set to WhiteList, token transfers can’t be Approved by a non-whitelisted address (see Approve method).
+// If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method).
#[test]
-fn white_list_test_6() {
+fn allow_list_test_6() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
@@ -1403,21 +1403,21 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
collection_id,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
// do approve
assert_noop!(
TemplateModule::approve(origin1, account(1), 1, 1, 5),
- Error::<Test>::AddresNotInWhiteList
+ Error::<Test>::AddresNotInAllowList
);
});
}
-// If Public Access mode is set to WhiteList, tokens can be transferred from a whitelisted address with transfer or transferFrom (2 tests) and
-// tokens can be transferred from a whitelisted address with transfer or transferFrom (2 tests)
+// If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests) and
+// tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests)
#[test]
-fn white_list_test_7() {
+fn allow_list_test_7() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
@@ -1429,14 +1429,14 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
collection_id,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
collection_id,
account(1)
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
collection_id,
account(2)
@@ -1447,7 +1447,7 @@
}
#[test]
-fn white_list_test_8() {
+fn allow_list_test_8() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
@@ -1459,14 +1459,14 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
collection_id,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
collection_id,
account(1)
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
collection_id,
account(2)
@@ -1493,9 +1493,9 @@
});
}
-// If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by owner.
+// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner.
#[test]
-fn white_list_test_9() {
+fn allow_list_test_9() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1503,7 +1503,7 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
collection_id,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
assert_ok!(TemplateModule::set_mint_permission(
origin1,
@@ -1516,9 +1516,9 @@
});
}
-// If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by admin.
+// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin.
#[test]
-fn white_list_test_10() {
+fn allow_list_test_10() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
@@ -1528,7 +1528,7 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
collection_id,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
assert_ok!(TemplateModule::set_mint_permission(
origin1.clone(),
@@ -1551,9 +1551,9 @@
});
}
-// If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens cannot be created by non-privileged and white listed address.
+// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and allow listed address.
#[test]
-fn white_list_test_11() {
+fn allow_list_test_11() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
@@ -1563,14 +1563,14 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
collection_id,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
assert_ok!(TemplateModule::set_mint_permission(
origin1.clone(),
collection_id,
false
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1,
collection_id,
account(2)
@@ -1583,9 +1583,9 @@
});
}
-// If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-white listed address.
+// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-allow listed address.
#[test]
-fn white_list_test_12() {
+fn allow_list_test_12() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
@@ -1595,7 +1595,7 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
collection_id,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
assert_ok!(TemplateModule::set_mint_permission(
origin1,
@@ -1610,9 +1610,9 @@
});
}
-// If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by owner.
+// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner.
#[test]
-fn white_list_test_13() {
+fn allow_list_test_13() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
@@ -1621,7 +1621,7 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
collection_id,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
assert_ok!(TemplateModule::set_mint_permission(
origin1,
@@ -1634,9 +1634,9 @@
});
}
-// If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by admin.
+// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin.
#[test]
-fn white_list_test_14() {
+fn allow_list_test_14() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
@@ -1646,7 +1646,7 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
collection_id,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
assert_ok!(TemplateModule::set_mint_permission(
origin1.clone(),
@@ -1669,9 +1669,9 @@
});
}
-// If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-white listed address.
+// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-allow listed address.
#[test]
-fn white_list_test_15() {
+fn allow_list_test_15() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
@@ -1681,7 +1681,7 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
collection_id,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
assert_ok!(TemplateModule::set_mint_permission(
origin1,
@@ -1691,14 +1691,14 @@
assert_noop!(
TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),
- Error::<Test>::AddresNotInWhiteList
+ Error::<Test>::AddresNotInAllowList
);
});
}
-// If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by non-privileged and white listed address.
+// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by non-privileged and allow listed address.
#[test]
-fn white_list_test_16() {
+fn allow_list_test_16() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
@@ -1708,14 +1708,14 @@
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
collection_id,
- AccessMode::WhiteList
+ AccessMode::AllowList
));
assert_ok!(TemplateModule::set_mint_permission(
origin1.clone(),
collection_id,
true
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1,
collection_id,
account(2)
@@ -2056,7 +2056,7 @@
collection_id,
true
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
collection_id,
account(1)
@@ -2124,7 +2124,7 @@
collection_id,
true
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin2.clone(),
collection_id,
account(1)
@@ -2177,7 +2177,7 @@
collection_id,
true
));
- assert_ok!(TemplateModule::add_to_white_list(
+ assert_ok!(TemplateModule::add_to_allow_list(
origin2.clone(),
collection_id,
account(1)
pallets/nft/src/weights.rsdiffbeforeafterboth--- a/pallets/nft/src/weights.rs
+++ b/pallets/nft/src/weights.rs
@@ -33,8 +33,8 @@
pub trait WeightInfo {
fn create_collection() -> Weight;
fn destroy_collection() -> Weight;
- fn add_to_white_list() -> Weight;
- fn remove_from_white_list() -> Weight;
+ fn add_to_allow_list() -> Weight;
+ fn remove_from_allow_list() -> Weight;
fn set_public_access_mode() -> Weight;
fn set_mint_permission() -> Weight;
fn change_collection_owner() -> Weight;
@@ -75,14 +75,14 @@
}
// Storage: Common CollectionById (r:1 w:0)
// Storage: Common Allowlist (r:0 w:1)
- fn add_to_white_list() -> Weight {
+ fn add_to_allow_list() -> Weight {
(6_629_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Common CollectionById (r:1 w:0)
// Storage: Common Allowlist (r:0 w:1)
- fn remove_from_white_list() -> Weight {
+ fn remove_from_allow_list() -> Weight {
(6_596_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
@@ -205,14 +205,14 @@
}
// Storage: Common CollectionById (r:1 w:0)
// Storage: Common Allowlist (r:0 w:1)
- fn add_to_white_list() -> Weight {
+ fn add_to_allow_list() -> Weight {
(6_629_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: Common CollectionById (r:1 w:0)
// Storage: Common Allowlist (r:0 w:1)
- fn remove_from_white_list() -> Weight {
+ fn remove_from_allow_list() -> Weight {
(6_596_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -169,7 +169,7 @@
<CommonError<T>>::NoPermission
);
- if collection.access == AccessMode::WhiteList {
+ if collection.access == AccessMode::AllowList {
collection.check_allowlist(sender)?;
}
@@ -228,7 +228,7 @@
<CommonError<T>>::NoPermission
);
- if collection.access == AccessMode::WhiteList {
+ if collection.access == AccessMode::AllowList {
collection.check_allowlist(from)?;
collection.check_allowlist(to)?;
}
@@ -449,7 +449,7 @@
token: TokenId,
spender: Option<&T::CrossAccountId>,
) -> DispatchResult {
- if collection.access == AccessMode::WhiteList {
+ if collection.access == AccessMode::AllowList {
collection.check_allowlist(&sender)?;
if let Some(spender) = spender {
collection.check_allowlist(&spender)?;
@@ -484,7 +484,7 @@
if spender.conv_eq(from) {
return Self::transfer(collection, from, to, token);
}
- if collection.access == AccessMode::WhiteList {
+ if collection.access == AccessMode::AllowList {
// `from`, `to` checked in [`transfer`]
collection.check_allowlist(spender)?;
}
@@ -512,7 +512,7 @@
if spender.conv_eq(from) {
return Self::burn(collection, from, token);
}
- if collection.access == AccessMode::WhiteList {
+ if collection.access == AccessMode::AllowList {
// `from` checked in [`burn`]
collection.check_allowlist(spender)?;
}
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -272,7 +272,7 @@
<CommonError<T>>::TransferNotAllowed
);
- if collection.access == AccessMode::WhiteList {
+ if collection.access == AccessMode::AllowList {
collection.check_allowlist(from)?;
collection.check_allowlist(to)?;
}
@@ -483,7 +483,7 @@
token: TokenId,
amount: u128,
) -> DispatchResult {
- if collection.access == AccessMode::WhiteList {
+ if collection.access == AccessMode::AllowList {
collection.check_allowlist(&sender)?;
collection.check_allowlist(&spender)?;
}
@@ -514,7 +514,7 @@
if spender.conv_eq(from) {
return Self::transfer(collection, from, to, token, amount);
}
- if collection.access == AccessMode::WhiteList {
+ if collection.access == AccessMode::AllowList {
// `from`, `to` checked in [`transfer`]
collection.check_allowlist(spender)?;
}
@@ -547,7 +547,7 @@
if spender.conv_eq(from) {
return Self::burn(collection, from, token, amount);
}
- if collection.access == AccessMode::WhiteList {
+ if collection.access == AccessMode::AllowList {
// `from` checked in [`burn`]
collection.check_allowlist(spender)?;
}
primitives/nft/src/lib.rsdiffbeforeafterboth--- a/primitives/nft/src/lib.rs
+++ b/primitives/nft/src/lib.rs
@@ -142,7 +142,7 @@
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
pub enum AccessMode {
Normal,
- WhiteList,
+ AllowList,
}
impl Default for AccessMode {
fn default() -> Self {
runtime/src/chain_extension.rsdiffbeforeafterboth--- a/runtime/src/chain_extension.rs
+++ b/runtime/src/chain_extension.rs
@@ -75,10 +75,10 @@
}
#[derive(Debug, PartialEq, Encode, Decode, MaxEncodedLen)]
-pub struct NFTExtToggleWhiteList<AccountId> {
+pub struct NFTExtToggleAllowList<AccountId> {
pub collection_id: u32,
pub address: AccountId,
- pub whitelisted: bool,
+ pub allowlisted: bool,
}
/// The chain Extension of NFT pallet
@@ -211,18 +211,18 @@
Ok(RetVal::Converging(0))
}
6 => {
- // Toggle whitelist
+ // Toggle allowlist
let mut env = env.buf_in_buf_out();
- let input: NFTExtToggleWhiteList<AccountIdOf<C>> = env.read_as()?;
- env.charge_weight(NftWeightInfoOf::<C>::add_to_white_list())?;
+ let input: NFTExtToggleAllowList<AccountIdOf<C>> = env.read_as()?;
+ env.charge_weight(NftWeightInfoOf::<C>::add_to_allow_list())?;
let collection = pallet_nft::Module::<C>::get_collection(input.collection_id)?;
- pallet_nft::Module::<C>::toggle_white_list_internal(
+ pallet_nft::Module::<C>::toggle_allow_list_internal(
&C::CrossAccountId::from_sub(env.ext().address().clone()),
&collection,
&C::CrossAccountId::from_sub(input.address),
- input.whitelisted,
+ input.allowlisted,
)?;
collection.submit_logs()?;
runtime/src/lib.rsdiffbeforeafterboth--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -1340,7 +1340,7 @@
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
- let whitelist: Vec<TrackedStorageKey> = vec![
+ let allowlist: Vec<TrackedStorageKey> = vec![
// Block Number
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
// Total Issuance
@@ -1354,7 +1354,7 @@
];
let mut batches = Vec::<BenchmarkBatch>::new();
- let params = (&config, &whitelist);
+ let params = (&config, &allowlist);
add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);
add_benchmark!(params, batches, pallet_nft, Nft);
smart_contracs/transfer/lib.rsdiffbeforeafterboth--- a/smart_contracs/transfer/lib.rs
+++ b/smart_contracs/transfer/lib.rs
@@ -75,7 +75,7 @@
#[ink(extension = 5, returns_result = false)]
fn set_variable_meta_data(collection_id: u32, item_id: u32, data: Vec<u8>);
#[ink(extension = 6, returns_result = false)]
- fn toggle_white_list(collection_id: u32, address: DefaultAccountId, whitelisted: bool);
+ fn toggle_allow_list(collection_id: u32, address: DefaultAccountId, allowlisted: bool);
}
#[ink::contract(env = crate::NftEnvironment, dynamic_storage_allocator = true)]
@@ -135,10 +135,10 @@
.set_variable_meta_data(collection_id, item_id, data);
}
#[ink(message)]
- pub fn toggle_white_list(&mut self, collection_id: u32, address: AccountId, whitelisted: bool) {
+ pub fn toggle_allow_list(&mut self, collection_id: u32, address: AccountId, allowlisted: bool) {
let _ = self.env()
.extension()
- .toggle_white_list(collection_id, address, whitelisted);
+ .toggle_allow_list(collection_id, address, allowlisted);
}
}
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -42,7 +42,7 @@
"testConfirmSponsorship": "mocha --timeout 9999999 -r ts-node/register ./**/confirmSponsorship.test.ts",
"testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",
"testRemoveCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionSponsor.test.ts",
- "testRemoveFromWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromWhiteList.test.ts",
+ "testRemoveFromAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromAllowList.test.ts",
"testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",
"testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",
"testContracts": "mocha --timeout 9999999 -r ts-node/register ./**/contracts.test.ts",
@@ -51,14 +51,14 @@
"testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",
"testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",
"testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",
- "testToggleContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractWhiteList.test.ts",
- "testAddToContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractWhiteList.test.ts",
+ "testToggleContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractAllowList.test.ts",
+ "testAddToContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractAllowList.test.ts",
"testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",
"testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",
"testSetMintPermission": "mocha --timeout 9999999 -r ts-node/register ./**/setMintPermission.test.ts",
"testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",
"testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",
- "testRemoveFromContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromContractWhiteList.test.ts",
+ "testRemoveFromContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromContractAllowList.test.ts",
"testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",
"testSetOffchainSchema": "mocha --timeout 9999999 -r ts-node/register ./**/setOffchainSchema.test.ts",
"testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts",
tests/src/addToAllowList.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/addToAllowList.test.ts
@@ -0,0 +1,124 @@
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
+import {IKeyringPair} from '@polkadot/types/types';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import privateKey from './substrate/privateKey';
+import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';
+import {
+ addToAllowListExpectSuccess,
+ createCollectionExpectSuccess,
+ createItemExpectSuccess,
+ destroyCollectionExpectSuccess,
+ enablePublicMintingExpectSuccess,
+ enableAllowListExpectSuccess,
+ normalizeAccountId,
+ addCollectionAdminExpectSuccess,
+ addToAllowListExpectFail,
+} from './util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+let alice: IKeyringPair;
+let bob: IKeyringPair;
+let charlie: IKeyringPair;
+
+describe('Integration Test ext. addToAllowList()', () => {
+
+ before(async () => {
+ await usingApi(async () => {
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ });
+ });
+
+ it('Execute the extrinsic with parameters: Collection ID and address to add to the allow list', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addToAllowListExpectSuccess(alice, collectionId, bob.address);
+ });
+
+ it('Allowlisted minting: list restrictions', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addToAllowListExpectSuccess(alice, collectionId, bob.address);
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await enablePublicMintingExpectSuccess(alice, collectionId);
+ await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
+ });
+});
+
+describe('Negative Integration Test ext. addToAllowList()', () => {
+
+ it('Allow list an address in the collection that does not exist', async () => {
+ await usingApi(async (api) => {
+ // tslint:disable-next-line: no-bitwise
+ const collectionId = ((await api.query.common.createdCollectionCount()).toNumber()) + 1;
+ const bob = privateKey('//Bob');
+
+ const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(bob.address));
+ await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
+ });
+ });
+
+ it('Allow list an address in the collection that was destroyed', async () => {
+ await usingApi(async (api) => {
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
+ // tslint:disable-next-line: no-bitwise
+ const collectionId = await createCollectionExpectSuccess();
+ await destroyCollectionExpectSuccess(collectionId);
+ const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(bob.address));
+ await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
+ });
+ });
+
+ it('Allow list an address in the collection that does not have allow list access enabled', async () => {
+ await usingApi(async (api) => {
+ const alice = privateKey('//Alice');
+ const ferdie = privateKey('//Ferdie');
+ const collectionId = await createCollectionExpectSuccess();
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await enablePublicMintingExpectSuccess(alice, collectionId);
+ const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(ferdie.address), 'NFT');
+ await expect(submitTransactionExpectFailAsync(ferdie, tx)).to.be.rejected;
+ });
+ });
+
+});
+
+describe('Integration Test ext. addToAllowList() with collection admin permissions:', () => {
+
+ before(async () => {
+ await usingApi(async () => {
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ charlie = privateKey('//Charlie');
+ });
+ });
+
+ it('Negative. Add to the allow list by regular user', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addToAllowListExpectFail(bob, collectionId, charlie.address);
+ });
+
+ it('Execute the extrinsic with parameters: Collection ID and address to add to the allow list', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ await addToAllowListExpectSuccess(bob, collectionId, charlie.address);
+ });
+
+ it('Allowlisted minting: list restrictions', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ await addToAllowListExpectSuccess(bob, collectionId, charlie.address);
+
+ // allowed only for collection owner
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await enablePublicMintingExpectSuccess(alice, collectionId);
+
+ await createItemExpectSuccess(charlie, collectionId, 'NFT', charlie.address);
+ });
+});
tests/src/addToContractAllowList.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/addToContractAllowList.test.ts
@@ -0,0 +1,92 @@
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
+import privateKey from './substrate/privateKey';
+import {
+ deployFlipper,
+} from './util/contracthelpers';
+import {
+ getGenericResult,
+} from './util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+describe.skip('Integration Test addToContractAllowList', () => {
+
+ it('Add an address to a contract allow list', async () => {
+ await usingApi(async api => {
+ const bob = privateKey('//Bob');
+ const [contract, deployer] = await deployFlipper(api);
+
+ const allowListedBefore = (await api.query.nft.contractAllowList(contract.address, bob.address)).toJSON();
+ const addTx = api.tx.nft.addToContractAllowList(contract.address, bob.address);
+ const addEvents = await submitTransactionAsync(deployer, addTx);
+ const allowListedAfter = (await api.query.nft.contractAllowList(contract.address, bob.address)).toJSON();
+
+ expect(getGenericResult(addEvents).success).to.be.true;
+ expect(allowListedBefore).to.be.false;
+ expect(allowListedAfter).to.be.true;
+ });
+ });
+
+ it('Adding same address to allow list repeatedly should not produce errors', async () => {
+ await usingApi(async api => {
+ const bob = privateKey('//Bob');
+ const [contract, deployer] = await deployFlipper(api);
+
+ const allowListedBefore = (await api.query.nft.contractAllowList(contract.address, bob.address)).toJSON();
+ const addTx = api.tx.nft.addToContractAllowList(contract.address, bob.address);
+ const addEvents = await submitTransactionAsync(deployer, addTx);
+ const allowListedAfter = (await api.query.nft.contractAllowList(contract.address, bob.address)).toJSON();
+ const addAgainEvents = await submitTransactionAsync(deployer, addTx);
+ const allowListedAgainAfter = (await api.query.nft.contractAllowList(contract.address, bob.address)).toJSON();
+
+ expect(getGenericResult(addEvents).success).to.be.true;
+ expect(allowListedBefore).to.be.false;
+ expect(allowListedAfter).to.be.true;
+ expect(getGenericResult(addAgainEvents).success).to.be.true;
+ expect(allowListedAgainAfter).to.be.true;
+ });
+ });
+});
+
+describe.skip('Negative Integration Test addToContractAllowList', () => {
+
+ it('Add an address to a allow list of a non-contract', async () => {
+ await usingApi(async api => {
+ const alice = privateKey('//Bob');
+ const bob = privateKey('//Bob');
+ const charlieGuineaPig = privateKey('//Charlie');
+
+ const allowListedBefore = (await api.query.nft.contractAllowList(charlieGuineaPig.address, bob.address)).toJSON();
+ const addTx = api.tx.nft.addToContractAllowList(charlieGuineaPig.address, bob.address);
+ await expect(submitTransactionExpectFailAsync(alice, addTx)).to.be.rejected;
+ const allowListedAfter = (await api.query.nft.contractAllowList(charlieGuineaPig.address, bob.address)).toJSON();
+
+ expect(allowListedBefore).to.be.false;
+ expect(allowListedAfter).to.be.false;
+ });
+ });
+
+ it('Add to a contract allow list using a non-owner address', async () => {
+ await usingApi(async api => {
+ const bob = privateKey('//Bob');
+ const [contract] = await deployFlipper(api);
+
+ const allowListedBefore = (await api.query.nft.contractAllowList(contract.address, bob.address)).toJSON();
+ const addTx = api.tx.nft.addToContractAllowList(contract.address, bob.address);
+ await expect(submitTransactionExpectFailAsync(bob, addTx)).to.be.rejected;
+ const allowListedAfter = (await api.query.nft.contractAllowList(contract.address, bob.address)).toJSON();
+
+ expect(allowListedBefore).to.be.false;
+ expect(allowListedAfter).to.be.false;
+ });
+ });
+
+});
tests/src/addToContractWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/addToContractWhiteList.test.ts
+++ /dev/null
@@ -1,92 +0,0 @@
-//
-// This file is subject to the terms and conditions defined in
-// file 'LICENSE', which is part of this source code package.
-//
-
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
-import privateKey from './substrate/privateKey';
-import {
- deployFlipper,
-} from './util/contracthelpers';
-import {
- getGenericResult,
-} from './util/helpers';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-
-describe.skip('Integration Test addToContractWhiteList', () => {
-
- it('Add an address to a contract white list', async () => {
- await usingApi(async api => {
- const bob = privateKey('//Bob');
- const [contract, deployer] = await deployFlipper(api);
-
- const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();
- const addTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);
- const addEvents = await submitTransactionAsync(deployer, addTx);
- const whiteListedAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();
-
- expect(getGenericResult(addEvents).success).to.be.true;
- expect(whiteListedBefore).to.be.false;
- expect(whiteListedAfter).to.be.true;
- });
- });
-
- it('Adding same address to white list repeatedly should not produce errors', async () => {
- await usingApi(async api => {
- const bob = privateKey('//Bob');
- const [contract, deployer] = await deployFlipper(api);
-
- const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();
- const addTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);
- const addEvents = await submitTransactionAsync(deployer, addTx);
- const whiteListedAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();
- const addAgainEvents = await submitTransactionAsync(deployer, addTx);
- const whiteListedAgainAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();
-
- expect(getGenericResult(addEvents).success).to.be.true;
- expect(whiteListedBefore).to.be.false;
- expect(whiteListedAfter).to.be.true;
- expect(getGenericResult(addAgainEvents).success).to.be.true;
- expect(whiteListedAgainAfter).to.be.true;
- });
- });
-});
-
-describe.skip('Negative Integration Test addToContractWhiteList', () => {
-
- it('Add an address to a white list of a non-contract', async () => {
- await usingApi(async api => {
- const alice = privateKey('//Bob');
- const bob = privateKey('//Bob');
- const charlieGuineaPig = privateKey('//Charlie');
-
- const whiteListedBefore = (await api.query.nft.contractWhiteList(charlieGuineaPig.address, bob.address)).toJSON();
- const addTx = api.tx.nft.addToContractWhiteList(charlieGuineaPig.address, bob.address);
- await expect(submitTransactionExpectFailAsync(alice, addTx)).to.be.rejected;
- const whiteListedAfter = (await api.query.nft.contractWhiteList(charlieGuineaPig.address, bob.address)).toJSON();
-
- expect(whiteListedBefore).to.be.false;
- expect(whiteListedAfter).to.be.false;
- });
- });
-
- it('Add to a contract white list using a non-owner address', async () => {
- await usingApi(async api => {
- const bob = privateKey('//Bob');
- const [contract] = await deployFlipper(api);
-
- const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();
- const addTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);
- await expect(submitTransactionExpectFailAsync(bob, addTx)).to.be.rejected;
- const whiteListedAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();
-
- expect(whiteListedBefore).to.be.false;
- expect(whiteListedAfter).to.be.false;
- });
- });
-
-});
tests/src/addToWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/addToWhiteList.test.ts
+++ /dev/null
@@ -1,124 +0,0 @@
-//
-// This file is subject to the terms and conditions defined in
-// file 'LICENSE', which is part of this source code package.
-//
-
-import {IKeyringPair} from '@polkadot/types/types';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
-import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';
-import {
- addToWhiteListExpectSuccess,
- createCollectionExpectSuccess,
- createItemExpectSuccess,
- destroyCollectionExpectSuccess,
- enablePublicMintingExpectSuccess,
- enableWhiteListExpectSuccess,
- normalizeAccountId,
- addCollectionAdminExpectSuccess,
- addToWhiteListExpectFail,
-} from './util/helpers';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-
-let alice: IKeyringPair;
-let bob: IKeyringPair;
-let charlie: IKeyringPair;
-
-describe('Integration Test ext. addToWhiteList()', () => {
-
- before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- });
- });
-
- it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
- });
-
- it('Whitelisted minting: list restrictions', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
- await enableWhiteListExpectSuccess(alice, collectionId);
- await enablePublicMintingExpectSuccess(alice, collectionId);
- await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
- });
-});
-
-describe('Negative Integration Test ext. addToWhiteList()', () => {
-
- it('White list an address in the collection that does not exist', async () => {
- await usingApi(async (api) => {
- // tslint:disable-next-line: no-bitwise
- const collectionId = ((await api.query.common.createdCollectionCount()).toNumber()) + 1;
- const bob = privateKey('//Bob');
-
- const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(bob.address));
- await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
- });
- });
-
- it('White list an address in the collection that was destroyed', async () => {
- await usingApi(async (api) => {
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- // tslint:disable-next-line: no-bitwise
- const collectionId = await createCollectionExpectSuccess();
- await destroyCollectionExpectSuccess(collectionId);
- const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(bob.address));
- await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
- });
- });
-
- it('White list an address in the collection that does not have white list access enabled', async () => {
- await usingApi(async (api) => {
- const alice = privateKey('//Alice');
- const ferdie = privateKey('//Ferdie');
- const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(alice, collectionId);
- await enablePublicMintingExpectSuccess(alice, collectionId);
- const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(ferdie.address), 'NFT');
- await expect(submitTransactionExpectFailAsync(ferdie, tx)).to.be.rejected;
- });
- });
-
-});
-
-describe('Integration Test ext. addToWhiteList() with collection admin permissions:', () => {
-
- before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
- });
- });
-
- it('Negative. Add to the white list by regular user', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectFail(bob, collectionId, charlie.address);
- });
-
- it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- await addToWhiteListExpectSuccess(bob, collectionId, charlie.address);
- });
-
- it('Whitelisted minting: list restrictions', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- await addToWhiteListExpectSuccess(bob, collectionId, charlie.address);
-
- // allowed only for collection owner
- await enableWhiteListExpectSuccess(alice, collectionId);
- await enablePublicMintingExpectSuccess(alice, collectionId);
-
- await createItemExpectSuccess(charlie, collectionId, 'NFT', charlie.address);
- });
-});
tests/src/allowLists.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/allowLists.test.ts
@@ -0,0 +1,304 @@
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
+import {IKeyringPair} from '@polkadot/types/types';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import privateKey from './substrate/privateKey';
+import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';
+import {
+ addToAllowListExpectSuccess,
+ createCollectionExpectSuccess,
+ createItemExpectSuccess,
+ destroyCollectionExpectSuccess,
+ enableAllowListExpectSuccess,
+ normalizeAccountId,
+ addCollectionAdminExpectSuccess,
+ addToAllowListExpectFail,
+ removeFromAllowListExpectSuccess,
+ removeFromAllowListExpectFailure,
+ addToAllowListAgainExpectSuccess,
+ transferExpectFailure,
+ approveExpectSuccess,
+ approveExpectFail,
+ transferExpectSuccess,
+ transferFromExpectSuccess,
+ setMintPermissionExpectSuccess,
+ createItemExpectFailure,
+} from './util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+let alice: IKeyringPair;
+let bob: IKeyringPair;
+let charlie: IKeyringPair;
+
+describe('Integration Test ext. Allow list tests', () => {
+
+ before(async () => {
+ await usingApi(async () => {
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ charlie = privateKey('//Charlie');
+ });
+ });
+
+ it('Owner can add address to allow list', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addToAllowListExpectSuccess(alice, collectionId, bob.address);
+ });
+
+ it('Admin can add address to allow list', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ await addToAllowListExpectSuccess(bob, collectionId, charlie.address);
+ });
+
+ it('Non-privileged user cannot add address to allow list', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addToAllowListExpectFail(bob, collectionId, charlie.address);
+ });
+
+ it('Nobody can add address to allow list of non-existing collection', async () => {
+ const collectionId = (1<<32) - 1;
+ await addToAllowListExpectFail(alice, collectionId, bob.address);
+ });
+
+ it('Nobody can add address to allow list of destroyed collection', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await destroyCollectionExpectSuccess(collectionId, '//Alice');
+ await addToAllowListExpectFail(alice, collectionId, bob.address);
+ });
+
+ it('If address is already added to allow list, nothing happens', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addToAllowListExpectSuccess(alice, collectionId, bob.address);
+ await addToAllowListAgainExpectSuccess(alice, collectionId, bob.address);
+ });
+
+ it('Owner can remove address from allow list', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addToAllowListExpectSuccess(alice, collectionId, bob.address);
+ await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(bob));
+ });
+
+ it('Admin can remove address from allow list', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
+ await removeFromAllowListExpectSuccess(bob, collectionId, normalizeAccountId(charlie));
+ });
+
+ it('Non-privileged user cannot remove address from allow list', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
+ await removeFromAllowListExpectFailure(bob, collectionId, normalizeAccountId(charlie));
+ });
+
+ it('Nobody can remove address from allow list of non-existing collection', async () => {
+ const collectionId = (1<<32) - 1;
+ await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie));
+ });
+
+ it('Nobody can remove address from allow list of deleted collection', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
+ await destroyCollectionExpectSuccess(collectionId, '//Alice');
+ await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie));
+ });
+
+ it('If address is already removed from allow list, nothing happens', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
+ await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));
+ await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));
+ });
+
+ it('If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom. Test1', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
+
+ await transferExpectFailure(
+ collectionId,
+ itemId,
+ alice,
+ charlie,
+ 1,
+ );
+ });
+
+ it('If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom. Test2', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await addToAllowListExpectSuccess(alice, collectionId, alice.address);
+ await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
+ await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
+ await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice));
+
+ await transferExpectFailure(
+ collectionId,
+ itemId,
+ alice,
+ charlie,
+ 1,
+ );
+ });
+
+ it('If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom. Test1', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await addToAllowListExpectSuccess(alice, collectionId, alice.address);
+
+ await transferExpectFailure(
+ collectionId,
+ itemId,
+ alice,
+ charlie,
+ 1,
+ );
+ });
+
+ it('If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom. Test2', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await addToAllowListExpectSuccess(alice, collectionId, alice.address);
+ await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
+ await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
+ await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice));
+
+ await transferExpectFailure(
+ collectionId,
+ itemId,
+ alice,
+ charlie,
+ 1,
+ );
+ });
+
+ it('If Public Access mode is set to AllowList, tokens can’t be destroyed by a non-allowlisted address (even if it owned them before enabling AllowList mode)', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableAllowListExpectSuccess(alice, collectionId);
+
+ await usingApi(async (api) => {
+ const tx = api.tx.nft.burnItem(collectionId, itemId, /*normalizeAccountId(Alice.address),*/ 11);
+ const badTransaction = async function () {
+ await submitTransactionExpectFailAsync(alice, tx);
+ };
+ await expect(badTransaction()).to.be.rejected;
+ });
+ });
+
+ it('If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method)', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await approveExpectFail(collectionId, itemId, alice, bob);
+ });
+
+ it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await addToAllowListExpectSuccess(alice, collectionId, alice.address);
+ await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
+ await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');
+ });
+
+ it('If Public Access mode is set to AllowList, tokens can be transferred to a alowlisted address with transferFrom.', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await addToAllowListExpectSuccess(alice, collectionId, alice.address);
+ await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
+ await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
+ await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');
+ });
+
+ it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await addToAllowListExpectSuccess(alice, collectionId, alice.address);
+ await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
+ await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');
+ });
+
+ it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await addToAllowListExpectSuccess(alice, collectionId, alice.address);
+ await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
+ await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
+ await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');
+ });
+
+ it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await setMintPermissionExpectSuccess(alice, collectionId, false);
+ await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ });
+
+ it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await setMintPermissionExpectSuccess(alice, collectionId, false);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
+ });
+
+ it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and allow-listed address', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await setMintPermissionExpectSuccess(alice, collectionId, false);
+ await addToAllowListExpectSuccess(alice, collectionId, bob.address);
+ await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);
+ });
+
+ it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-allow listed address', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await setMintPermissionExpectSuccess(alice, collectionId, false);
+ await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);
+ });
+
+ it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await setMintPermissionExpectSuccess(alice, collectionId, true);
+ await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ });
+
+ it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await setMintPermissionExpectSuccess(alice, collectionId, true);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
+ });
+
+ it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-allow listed address', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await setMintPermissionExpectSuccess(alice, collectionId, true);
+ await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);
+ });
+
+ it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by non-privileged and allow listed address', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await setMintPermissionExpectSuccess(alice, collectionId, true);
+ await addToAllowListExpectSuccess(alice, collectionId, bob.address);
+ await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
+ });
+});
tests/src/change-collection-owner.test.tsdiffbeforeafterboth--- a/tests/src/change-collection-owner.test.ts
+++ b/tests/src/change-collection-owner.test.ts
@@ -12,13 +12,13 @@
setCollectionSponsorExpectSuccess,
confirmSponsorshipExpectSuccess,
removeCollectionSponsorExpectSuccess,
- enableWhiteListExpectSuccess,
+ enableAllowListExpectSuccess,
setMintPermissionExpectSuccess,
destroyCollectionExpectSuccess,
setCollectionSponsorExpectFailure,
confirmSponsorshipExpectFailure,
removeCollectionSponsorExpectFailure,
- enableWhiteListExpectFail,
+ enableAllowListExpectFail,
setMintPermissionExpectFailure,
destroyCollectionExpectFailure,
setPublicAccessModeExpectSuccess,
@@ -104,8 +104,8 @@
);
await submitTransactionAsync(bob, tx1);
- await setPublicAccessModeExpectSuccess(bob, collectionId, 'WhiteList');
- await enableWhiteListExpectSuccess(bob, collectionId);
+ await setPublicAccessModeExpectSuccess(bob, collectionId, 'AllowList');
+ await enableAllowListExpectSuccess(bob, collectionId);
await setMintPermissionExpectSuccess(bob, collectionId, true);
await destroyCollectionExpectSuccess(collectionId, '//Bob');
});
@@ -225,7 +225,7 @@
);
await expect(submitTransactionExpectFailAsync(alice, tx1)).to.be.rejected;
- await enableWhiteListExpectFail(alice, collectionId);
+ await enableAllowListExpectFail(alice, collectionId);
await setMintPermissionExpectFailure(alice, collectionId, true);
await destroyCollectionExpectFailure(collectionId, '//Alice');
});
tests/src/collision-tests/adminDestroyCollection.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/adminDestroyCollection.test.ts
+++ b/tests/src/collision-tests/adminDestroyCollection.test.ts
@@ -27,26 +27,26 @@
});
});
-describe('Deleting a collection while add address to whitelist: ', () => {
+describe('Deleting a collection while add address to allowlist: ', () => {
// tslint:disable-next-line: max-line-length
- it('Adding an address to the collection whitelist in a block by the admin, and deleting the collection by the owner ', async () => {
+ it('Adding an address to the collection allowlist in a block by the admin, and deleting the collection by the owner ', async () => {
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
await submitTransactionAsync(Alice, changeAdminTx);
await waitNewBlocks(1);
//
- const addWhitelistAdm = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Ferdie.address));
+ const addAllowlistAdm = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(Ferdie.address));
const destroyCollection = api.tx.nft.destroyCollection(collectionId);
await Promise.all([
- addWhitelistAdm.signAndSend(Bob),
+ addAllowlistAdm.signAndSend(Bob),
destroyCollection.signAndSend(Alice),
]);
await waitNewBlocks(1);
- let whiteList = false;
- whiteList = (await api.query.nft.whiteList(collectionId, Ferdie.address)).toJSON() as boolean;
+ let allowList = false;
+ allowList = (await api.query.nft.allowList(collectionId, Ferdie.address)).toJSON() as boolean;
// tslint:disable-next-line: no-unused-expression
- expect(whiteList).to.be.false;
+ expect(allowList).to.be.false;
await waitNewBlocks(2);
});
});
tests/src/collision-tests/tokenLimitsOff.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/tokenLimitsOff.test.ts
+++ b/tests/src/collision-tests/tokenLimitsOff.test.ts
@@ -9,7 +9,7 @@
import privateKey from '../substrate/privateKey';
import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';
import {
- addToWhiteListExpectSuccess,
+ addToAllowListExpectSuccess,
createCollectionExpectSuccess,
getCreateItemResult,
setMintPermissionExpectSuccess,
@@ -44,8 +44,8 @@
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
await setMintPermissionExpectSuccess(Alice, collectionId, true);
- await addToWhiteListExpectSuccess(Alice, collectionId, Ferdie.address);
- await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
+ await addToAllowListExpectSuccess(Alice, collectionId, Ferdie.address);
+ await addToAllowListExpectSuccess(Alice, collectionId, Bob.address);
const setCollectionLim = api.tx.nft.setCollectionLimits(
collectionId,
{
tests/src/collision-tests/turnsOffMinting.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/turnsOffMinting.test.ts
+++ b/tests/src/collision-tests/turnsOffMinting.test.ts
@@ -8,7 +8,7 @@
import privateKey from '../substrate/privateKey';
import usingApi from '../substrate/substrate-api';
import {
- addToWhiteListExpectSuccess,
+ addToAllowListExpectSuccess,
createCollectionExpectSuccess,
setMintPermissionExpectSuccess,
normalizeAccountId,
@@ -33,7 +33,7 @@
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
await setMintPermissionExpectSuccess(Alice, collectionId, true);
- await addToWhiteListExpectSuccess(Alice, collectionId, Ferdie.address);
+ await addToAllowListExpectSuccess(Alice, collectionId, Ferdie.address);
const mintItem = api.tx.nft.createItem(collectionId, normalizeAccountId(Ferdie.address), 'NFT');
const offMinting = api.tx.nft.setMintPermission(collectionId, false);
tests/src/confirmSponsorship.test.tsdiffbeforeafterboth--- a/tests/src/confirmSponsorship.test.ts
+++ b/tests/src/confirmSponsorship.test.ts
@@ -15,9 +15,9 @@
createItemExpectSuccess,
findUnusedAddress,
getGenericResult,
- enableWhiteListExpectSuccess,
+ enableAllowListExpectSuccess,
enablePublicMintingExpectSuccess,
- addToWhiteListExpectSuccess,
+ addToAllowListExpectSuccess,
normalizeAccountId,
addCollectionAdminExpectSuccess,
} from './util/helpers';
@@ -144,8 +144,8 @@
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
- // Enable collection white list
- await enableWhiteListExpectSuccess(alice, collectionId);
+ // Enable collection allow list
+ await enableAllowListExpectSuccess(alice, collectionId);
// Enable public minting
await enablePublicMintingExpectSuccess(alice, collectionId);
@@ -157,8 +157,8 @@
// Find unused address
const zeroBalance = await findUnusedAddress(api);
- // Add zeroBalance address to white list
- await addToWhiteListExpectSuccess(alice, collectionId, zeroBalance.address);
+ // Add zeroBalance address to allow list
+ await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);
// Mint token using unused address as signer
await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);
@@ -285,8 +285,8 @@
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
- // Enable collection white list
- await enableWhiteListExpectSuccess(alice, collectionId);
+ // Enable collection allow list
+ await enableAllowListExpectSuccess(alice, collectionId);
// Enable public minting
await enablePublicMintingExpectSuccess(alice, collectionId);
@@ -295,8 +295,8 @@
// Find unused address
const zeroBalance = await findUnusedAddress(api);
- // Add zeroBalance address to white list
- await addToWhiteListExpectSuccess(alice, collectionId, zeroBalance.address);
+ // Add zeroBalance address to allow list
+ await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);
// Mint token using unused address as signer - gets sponsored
await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);
tests/src/contracts.test.tsdiffbeforeafterboth--- a/tests/src/contracts.test.ts
+++ b/tests/src/contracts.test.ts
@@ -16,15 +16,15 @@
} from './util/contracthelpers';
import {
- addToWhiteListExpectSuccess,
+ addToAllowListExpectSuccess,
approveExpectSuccess,
createCollectionExpectSuccess,
createItemExpectSuccess,
enablePublicMintingExpectSuccess,
- enableWhiteListExpectSuccess,
+ enableAllowListExpectSuccess,
getGenericResult,
normalizeAccountId,
- isWhitelisted,
+ isAllowlisted,
transferFromExpectSuccess,
getTokenOwner,
} from './util/helpers';
@@ -96,9 +96,9 @@
const collectionId = await createCollectionExpectSuccess();
const [contract] = await deployTransferContract(api);
await enablePublicMintingExpectSuccess(alice, collectionId);
- await enableWhiteListExpectSuccess(alice, collectionId);
- await addToWhiteListExpectSuccess(alice, collectionId, contract.address);
- await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await addToAllowListExpectSuccess(alice, collectionId, contract.address);
+ await addToAllowListExpectSuccess(alice, collectionId, bob.address);
const transferTx = contract.tx.createItem(value, gasLimit, bob.address, collectionId, {Nft: {const_data: '0x010203', variable_data: '0x020304'}});
const events = await submitTransactionAsync(alice, transferTx);
@@ -124,9 +124,9 @@
const collectionId = await createCollectionExpectSuccess();
const [contract] = await deployTransferContract(api);
await enablePublicMintingExpectSuccess(alice, collectionId);
- await enableWhiteListExpectSuccess(alice, collectionId);
- await addToWhiteListExpectSuccess(alice, collectionId, contract.address);
- await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await addToAllowListExpectSuccess(alice, collectionId, contract.address);
+ await addToAllowListExpectSuccess(alice, collectionId, bob.address);
const transferTx = contract.tx.createMultipleItems(value, gasLimit, bob.address, collectionId, [
{Nft: {const_data: '0x010203', variable_data: '0x020304'}},
@@ -218,7 +218,7 @@
});
});
- it('ToggleWhiteList CE', async () => {
+ it('ToggleAllowList CE', async () => {
await usingApi(async api => {
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
@@ -228,23 +228,23 @@
const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, contract.address);
await submitTransactionAsync(alice, changeAdminTx);
- expect(await isWhitelisted(collectionId, bob.address)).to.be.false;
+ expect(await isAllowlisted(collectionId, bob.address)).to.be.false;
{
- const transferTx = contract.tx.toggleWhiteList(value, gasLimit, collectionId, bob.address, true);
+ const transferTx = contract.tx.toggleAllowList(value, gasLimit, collectionId, bob.address, true);
const events = await submitTransactionAsync(alice, transferTx);
const result = getGenericResult(events);
expect(result.success).to.be.true;
- expect(await isWhitelisted(collectionId, bob.address)).to.be.true;
+ expect(await isAllowlisted(collectionId, bob.address)).to.be.true;
}
{
- const transferTx = contract.tx.toggleWhiteList(value, gasLimit, collectionId, bob.address, false);
+ const transferTx = contract.tx.toggleAllowList(value, gasLimit, collectionId, bob.address, false);
const events = await submitTransactionAsync(alice, transferTx);
const result = getGenericResult(events);
expect(result.success).to.be.true;
- expect(await isWhitelisted(collectionId, bob.address)).to.be.false;
+ expect(await isAllowlisted(collectionId, bob.address)).to.be.false;
}
});
});
tests/src/eth/allowlist.test.tsdiffbeforeafterboth--- a/tests/src/eth/allowlist.test.ts
+++ b/tests/src/eth/allowlist.test.ts
@@ -24,7 +24,7 @@
expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.true;
});
- itWeb3('Non-whitelisted user can\'t call contract with allowlist enabled', async ({api, web3}) => {
+ itWeb3('Non-allowlisted user can\'t call contract with allowlist enabled', async ({api, web3}) => {
const owner = await createEthAccountWithBalance(api, web3);
const flipper = await deployFlipper(web3, owner);
const caller = await createEthAccountWithBalance(api, web3);
@@ -35,7 +35,7 @@
await flipper.methods.flip().send({from: caller});
expect(await flipper.methods.getValue().call()).to.be.true;
- // Tx will be reverted if user is not in whitelist
+ // Tx will be reverted if user is not in allowlist
await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
await expect(flipper.methods.flip().send({from: caller})).to.rejected;
expect(await flipper.methods.getValue().call()).to.be.true;
tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/contractSponsoring.test.ts
+++ b/tests/src/eth/contractSponsoring.test.ts
@@ -32,7 +32,7 @@
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
});
- itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should decrease (whitelisted)', async ({api, web3}) => {
+ itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should decrease (allowlisted)', async ({api, web3}) => {
const alice = privateKey('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
@@ -62,7 +62,7 @@
expect(+balanceAfter).to.be.lessThan(+originalFlipperBalance);
});
- itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should not decrease (non-whitelisted)', async ({api, web3}) => {
+ itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should not decrease (non-allowlisted)', async ({api, web3}) => {
const alice = privateKey('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
@@ -158,7 +158,7 @@
expect(await helpers.methods.getSponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');
});
- itWeb3('If whitelist mode is off and sponsorship is on, sponsorship does not work', async ({api, web3}) => {
+ itWeb3('If allowlist mode is off and sponsorship is on, sponsorship does not work', async ({api, web3}) => {
const alice = privateKey('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
tests/src/interfaces/augment-api-errors.tsdiffbeforeafterboth--- a/tests/src/interfaces/augment-api-errors.ts
+++ b/tests/src/interfaces/augment-api-errors.ts
@@ -53,7 +53,7 @@
**/
AddressIsZero: AugmentedError<ApiType>;
/**
- * Address is not in white list.
+ * Address is not in allow list.
**/
AddressNotInAllowlist: AugmentedError<ApiType>;
/**
tests/src/interfaces/augment-api-tx.tsdiffbeforeafterboth--- a/tests/src/interfaces/augment-api-tx.ts
+++ b/tests/src/interfaces/augment-api-tx.ts
@@ -219,7 +219,7 @@
**/
addCollectionAdmin: AugmentedSubmittable<(collectionId: u32 | AnyNumber | Uint8Array, newAdminId: PalletCommonAccountBasicCrossAccountIdRepr | { Substrate: any } | { Ethereum: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [u32, PalletCommonAccountBasicCrossAccountIdRepr]>;
/**
- * Add an address to white list.
+ * Add an address to allow list.
*
* # Permissions
*
@@ -232,7 +232,7 @@
*
* * address.
**/
- addToWhiteList: AugmentedSubmittable<(collectionId: u32 | AnyNumber | Uint8Array, address: PalletCommonAccountBasicCrossAccountIdRepr | { Substrate: any } | { Ethereum: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [u32, PalletCommonAccountBasicCrossAccountIdRepr]>;
+ addToAllowList: AugmentedSubmittable<(collectionId: u32 | AnyNumber | Uint8Array, address: PalletCommonAccountBasicCrossAccountIdRepr | { Substrate: any } | { Ethereum: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [u32, PalletCommonAccountBasicCrossAccountIdRepr]>;
/**
* Set, change, or remove approved address to transfer the ownership of the NFT.
*
@@ -336,8 +336,8 @@
* * Collection Owner.
* * Collection Admin.
* * Anyone if
- * * White List is enabled, and
- * * Address is added to white list, and
+ * * Allow List is enabled, and
+ * * Address is added to allow list, and
* * MintPermission is enabled (see SetMintPermission method)
*
* # Arguments
@@ -357,8 +357,8 @@
* * Collection Owner.
* * Collection Admin.
* * Anyone if
- * * White List is enabled, and
- * * Address is added to white list, and
+ * * Allow List is enabled, and
+ * * Address is added to allow list, and
* * MintPermission is enabled (see SetMintPermission method)
*
* # Arguments
@@ -410,7 +410,7 @@
**/
removeCollectionSponsor: AugmentedSubmittable<(collectionId: u32 | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [u32]>;
/**
- * Remove an address from white list.
+ * Remove an address from allow list.
*
* # Permissions
*
@@ -423,7 +423,7 @@
*
* * address.
**/
- removeFromWhiteList: AugmentedSubmittable<(collectionId: u32 | AnyNumber | Uint8Array, address: PalletCommonAccountBasicCrossAccountIdRepr | { Substrate: any } | { Ethereum: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [u32, PalletCommonAccountBasicCrossAccountIdRepr]>;
+ removeFromAllowList: AugmentedSubmittable<(collectionId: u32 | AnyNumber | Uint8Array, address: PalletCommonAccountBasicCrossAccountIdRepr | { Substrate: any } | { Ethereum: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [u32, PalletCommonAccountBasicCrossAccountIdRepr]>;
setCollectionLimits: AugmentedSubmittable<(collectionId: u32 | AnyNumber | Uint8Array, newLimit: NftDataStructsCollectionLimits | { accountTokenOwnershipLimit?: any; sponsoredDataSize?: any; sponsoredDataRateLimit?: any; tokenLimit?: any; sponsorTransferTimeout?: any; ownerCanTransfer?: any; ownerCanDestroy?: any; transfersEnabled?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [u32, NftDataStructsCollectionLimits]>;
/**
* # Permissions
@@ -468,8 +468,8 @@
setMetaUpdatePermissionFlag: AugmentedSubmittable<(collectionId: u32 | AnyNumber | Uint8Array, value: NftDataStructsMetaUpdatePermission | 'ItemOwner' | 'Admin' | 'None' | number | Uint8Array) => SubmittableExtrinsic<ApiType>, [u32, NftDataStructsMetaUpdatePermission]>;
/**
* Allows Anyone to create tokens if:
- * * White List is enabled, and
- * * Address is added to white list, and
+ * * Allow List is enabled, and
+ * * Address is added to allow list, and
* * This method was called with True parameter
*
* # Permissions
@@ -498,7 +498,7 @@
**/
setOffchainSchema: AugmentedSubmittable<(collectionId: u32 | AnyNumber | Uint8Array, schema: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [u32, Bytes]>;
/**
- * Toggle between normal and white list access for the methods with access for `Anyone`.
+ * Toggle between normal and allow list access for the methods with access for `Anyone`.
*
* # Permissions
*
@@ -510,7 +510,7 @@
*
* * mode: [AccessMode]
**/
- setPublicAccessMode: AugmentedSubmittable<(collectionId: u32 | AnyNumber | Uint8Array, mode: NftDataStructsAccessMode | 'Normal' | 'WhiteList' | number | Uint8Array) => SubmittableExtrinsic<ApiType>, [u32, NftDataStructsAccessMode]>;
+ setPublicAccessMode: AugmentedSubmittable<(collectionId: u32 | AnyNumber | Uint8Array, mode: NftDataStructsAccessMode | 'Normal' | 'AllowList' | number | Uint8Array) => SubmittableExtrinsic<ApiType>, [u32, NftDataStructsAccessMode]>;
/**
* Set schema standard
* ImageURL
tests/src/interfaces/nft/definitions.tsdiffbeforeafterboth--- a/tests/src/interfaces/nft/definitions.ts
+++ b/tests/src/interfaces/nft/definitions.ts
@@ -91,7 +91,7 @@
},
},
NftDataStructsAccessMode: {
- _enum: ['Normal', 'WhiteList'],
+ _enum: ['Normal', 'AllowList'],
},
NftDataStructsSchemaVersion: mkDummy('SchemaVersion'),
tests/src/interfaces/nft/types.tsdiffbeforeafterboth--- a/tests/src/interfaces/nft/types.ts
+++ b/tests/src/interfaces/nft/types.ts
@@ -7,7 +7,7 @@
/** @name NftDataStructsAccessMode */
export interface NftDataStructsAccessMode extends Enum {
readonly isNormal: boolean;
- readonly isWhiteList: boolean;
+ readonly isAllowList: boolean;
}
/** @name NftDataStructsCollection */
tests/src/metadataUpdate.test.tsdiffbeforeafterboth--- a/tests/src/metadataUpdate.test.ts
+++ b/tests/src/metadataUpdate.test.ts
@@ -12,11 +12,11 @@
createItemExpectSuccess,
createCollectionExpectSuccess,
enablePublicMintingExpectSuccess,
- enableWhiteListExpectSuccess,
+ enableAllowListExpectSuccess,
setMetadataUpdatePermissionFlagExpectSuccess,
setVariableMetaDataExpectSuccess,
setMintPermissionExpectSuccess,
- addToWhiteListExpectSuccess,
+ addToAllowListExpectSuccess,
addCollectionAdminExpectSuccess,
setVariableMetaDataExpectFailure,
setMetadataUpdatePermissionFlagExpectFailure,
@@ -53,7 +53,7 @@
await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'ItemOwner');
await setMintPermissionExpectSuccess(alice, nftCollectionId, true);
- await addToWhiteListExpectSuccess(alice, nftCollectionId, bob.address);
+ await addToAllowListExpectSuccess(alice, nftCollectionId, bob.address);
await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);
await setVariableMetaDataExpectFailure(bob, nftCollectionId, newNftTokenId, data);
@@ -92,7 +92,7 @@
await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'Admin');
await setMintPermissionExpectSuccess(alice, nftCollectionId, true);
- await addToWhiteListExpectSuccess(alice, nftCollectionId, bob.address);
+ await addToAllowListExpectSuccess(alice, nftCollectionId, bob.address);
await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);
await setVariableMetaDataExpectSuccess(bob, nftCollectionId, newNftTokenId, data);
@@ -112,7 +112,7 @@
await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'Admin');
await setMintPermissionExpectSuccess(alice, nftCollectionId, true);
- await addToWhiteListExpectSuccess(alice, nftCollectionId, bob.address);
+ await addToAllowListExpectSuccess(alice, nftCollectionId, bob.address);
await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);
await setVariableMetaDataExpectSuccess(bob, nftCollectionId, newNftTokenId, data);
@@ -129,8 +129,8 @@
// nft
const nftCollectionId = await createCollectionExpectSuccess();
await enablePublicMintingExpectSuccess(alice, nftCollectionId);
- await addToWhiteListExpectSuccess(alice, nftCollectionId, bob.address);
- await enableWhiteListExpectSuccess(alice, nftCollectionId);
+ await addToAllowListExpectSuccess(alice, nftCollectionId, bob.address);
+ await enableAllowListExpectSuccess(alice, nftCollectionId);
const newNftTokenId = await createItemExpectSuccess(bob, nftCollectionId, 'NFT');
await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'Admin');
@@ -169,7 +169,7 @@
await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'None');
await setMintPermissionExpectSuccess(alice, nftCollectionId, true);
- await addToWhiteListExpectSuccess(alice, nftCollectionId, bob.address);
+ await addToAllowListExpectSuccess(alice, nftCollectionId, bob.address);
await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);
await setVariableMetaDataExpectFailure(bob, nftCollectionId, newNftTokenId, data);
tests/src/mintModes.test.tsdiffbeforeafterboth--- a/tests/src/mintModes.test.ts
+++ b/tests/src/mintModes.test.ts
@@ -7,14 +7,14 @@
import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
import {
- addToWhiteListExpectSuccess,
+ addToAllowListExpectSuccess,
createCollectionExpectSuccess,
createItemExpectFailure,
createItemExpectSuccess,
- enableWhiteListExpectSuccess,
+ enableAllowListExpectSuccess,
setMintPermissionExpectSuccess,
addCollectionAdminExpectSuccess,
- disableWhiteListExpectSuccess,
+ disableAllowListExpectSuccess,
} from './util/helpers';
describe('Integration Test public minting', () => {
@@ -28,40 +28,40 @@
});
});
- it('If the AllowList mode is enabled, then the address added to the whitelist and not the owner or administrator can create tokens', async () => {
+ it('If the AllowList mode is enabled, then the address added to the allowlist and not the owner or administrator can create tokens', async () => {
await usingApi(async () => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await enableWhiteListExpectSuccess(alice, collectionId);
+ await enableAllowListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, true);
- await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
+ await addToAllowListExpectSuccess(alice, collectionId, bob.address);
await createItemExpectSuccess(bob, collectionId, 'NFT');
});
});
- it('If the AllowList mode is enabled, address not included in whitelist that is regular user cannot create tokens', async () => {
+ it('If the AllowList mode is enabled, address not included in allowlist that is regular user cannot create tokens', async () => {
await usingApi(async () => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await enableWhiteListExpectSuccess(alice, collectionId);
+ await enableAllowListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, true);
await createItemExpectFailure(bob, collectionId, 'NFT');
});
});
- it('If the AllowList mode is enabled, address not included in whitelist that is admin can create tokens', async () => {
+ it('If the AllowList mode is enabled, address not included in allowlist that is admin can create tokens', async () => {
await usingApi(async () => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await enableWhiteListExpectSuccess(alice, collectionId);
+ await enableAllowListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, true);
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
await createItemExpectSuccess(bob, collectionId, 'NFT');
});
});
- it('If the AllowList mode is enabled, address not included in whitelist that is owner can create tokens', async () => {
+ it('If the AllowList mode is enabled, address not included in allowlist that is owner can create tokens', async () => {
await usingApi(async () => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await enableWhiteListExpectSuccess(alice, collectionId);
+ await enableAllowListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, true);
await createItemExpectSuccess(alice, collectionId, 'NFT');
});
@@ -70,7 +70,7 @@
it('If the AllowList mode is disabled, owner can create tokens', async () => {
await usingApi(async () => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await disableWhiteListExpectSuccess(alice, collectionId);
+ await disableAllowListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, true);
await createItemExpectSuccess(alice, collectionId, 'NFT');
});
@@ -79,7 +79,7 @@
it('If the AllowList mode is disabled, collection admin can create tokens', async () => {
await usingApi(async () => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await disableWhiteListExpectSuccess(alice, collectionId);
+ await disableAllowListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, true);
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
await createItemExpectSuccess(bob, collectionId, 'NFT');
@@ -89,7 +89,7 @@
it('If the AllowList mode is disabled, regular user can`t create tokens', async () => {
await usingApi(async () => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await disableWhiteListExpectSuccess(alice, collectionId);
+ await disableAllowListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, true);
await createItemExpectFailure(bob, collectionId, 'NFT');
});
@@ -110,9 +110,9 @@
it('Address that is the not owner or not admin cannot create tokens', async () => {
await usingApi(async () => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await enableWhiteListExpectSuccess(alice, collectionId);
+ await enableAllowListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, false);
- await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
+ await addToAllowListExpectSuccess(alice, collectionId, bob.address);
await createItemExpectFailure(bob, collectionId, 'NFT');
});
});
@@ -120,7 +120,7 @@
it('Address that is collection owner can create tokens', async () => {
await usingApi(async () => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await disableWhiteListExpectSuccess(alice, collectionId);
+ await disableAllowListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, false);
await createItemExpectSuccess(alice, collectionId, 'NFT');
});
@@ -129,7 +129,7 @@
it('Address that is admin can create tokens', async () => {
await usingApi(async () => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await disableWhiteListExpectSuccess(alice, collectionId);
+ await disableAllowListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, false);
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
await createItemExpectSuccess(bob, collectionId, 'NFT');
tests/src/removeFromAllowList.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/removeFromAllowList.test.ts
@@ -0,0 +1,136 @@
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import {default as usingApi} from './substrate/substrate-api';
+import {
+ createCollectionExpectSuccess,
+ destroyCollectionExpectSuccess,
+ enableAllowListExpectSuccess,
+ addToAllowListExpectSuccess,
+ removeFromAllowListExpectSuccess,
+ isAllowlisted,
+ findNotExistingCollection,
+ removeFromAllowListExpectFailure,
+ disableAllowListExpectSuccess,
+ normalizeAccountId,
+ addCollectionAdminExpectSuccess,
+} from './util/helpers';
+import {IKeyringPair} from '@polkadot/types/types';
+import privateKey from './substrate/privateKey';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+describe('Integration Test removeFromAllowList', () => {
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+
+ before(async () => {
+ await usingApi(async () => {
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ });
+ });
+
+ it('ensure bob is not in allowlist after removal', async () => {
+ await usingApi(async () => {
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await addToAllowListExpectSuccess(alice, collectionId, bob.address);
+
+ await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(bob.address));
+ expect(await isAllowlisted(collectionId, bob.address)).to.be.false;
+ });
+ });
+
+ it('allows removal from collection with unset allowlist status', async () => {
+ await usingApi(async () => {
+ const collectionWithoutAllowlistId = await createCollectionExpectSuccess();
+ await enableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);
+ await addToAllowListExpectSuccess(alice, collectionWithoutAllowlistId, bob.address);
+ await disableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);
+
+ await removeFromAllowListExpectSuccess(alice, collectionWithoutAllowlistId, normalizeAccountId(bob.address));
+ });
+ });
+});
+
+describe('Negative Integration Test removeFromAllowList', () => {
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+
+ before(async () => {
+ await usingApi(async () => {
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ });
+ });
+
+ it('fails on removal from not existing collection', async () => {
+ await usingApi(async (api) => {
+ const collectionId = await findNotExistingCollection(api);
+
+ await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));
+ });
+ });
+
+ it('fails on removal from removed collection', async () => {
+ await usingApi(async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await addToAllowListExpectSuccess(alice, collectionId, bob.address);
+ await destroyCollectionExpectSuccess(collectionId);
+
+ await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));
+ });
+ });
+});
+
+describe('Integration Test removeFromAllowList with collection admin permissions', () => {
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
+
+ before(async () => {
+ await usingApi(async () => {
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ charlie = privateKey('//Charlie');
+ });
+ });
+
+ it('ensure address is not in allowlist after removal', async () => {
+ await usingApi(async () => {
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
+ await removeFromAllowListExpectSuccess(bob, collectionId, normalizeAccountId(charlie.address));
+ expect(await isAllowlisted(collectionId, charlie.address)).to.be.false;
+ });
+ });
+
+ it('Collection admin allowed to remove from allowlist with unset allowlist status', async () => {
+ await usingApi(async () => {
+ const collectionWithoutAllowlistId = await createCollectionExpectSuccess();
+ await enableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);
+ await addCollectionAdminExpectSuccess(alice, collectionWithoutAllowlistId, bob.address);
+ await addToAllowListExpectSuccess(alice, collectionWithoutAllowlistId, charlie.address);
+ await disableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);
+ await removeFromAllowListExpectSuccess(bob, collectionWithoutAllowlistId, normalizeAccountId(charlie.address));
+ });
+ });
+
+ it('Regular user can`t remove from allowlist', async () => {
+ await usingApi(async () => {
+ const collectionWithoutAllowlistId = await createCollectionExpectSuccess();
+ await enableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);
+ await addToAllowListExpectSuccess(alice, collectionWithoutAllowlistId, charlie.address);
+ await removeFromAllowListExpectFailure(bob, collectionWithoutAllowlistId, normalizeAccountId(charlie.address));
+ });
+ });
+});
tests/src/removeFromContractAllowList.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/removeFromContractAllowList.test.ts
@@ -0,0 +1,81 @@
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
+import privateKey from './substrate/privateKey';
+import usingApi from './substrate/substrate-api';
+import {deployFlipper, toggleFlipValueExpectFailure, toggleFlipValueExpectSuccess} from './util/contracthelpers';
+import {addToContractAllowListExpectSuccess, isAllowlistedInContract, removeFromContractAllowListExpectFailure, removeFromContractAllowListExpectSuccess, toggleContractAllowlistExpectSuccess} from './util/helpers';
+import {IKeyringPair} from '@polkadot/types/types';
+import {expect} from 'chai';
+
+describe.skip('Integration Test removeFromContractAllowList', () => {
+ let bob: IKeyringPair;
+
+ before(async () => {
+ await usingApi(async () => {
+ bob = privateKey('//Bob');
+ });
+ });
+
+ it('user is no longer allowlisted after removal', async () => {
+ await usingApi(async (api) => {
+ const [flipper, deployer] = await deployFlipper(api);
+
+ await addToContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);
+ await removeFromContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);
+
+ expect(await isAllowlistedInContract(flipper.address, bob.address)).to.be.false;
+ });
+ });
+
+ it('user can\'t execute contract after removal', async () => {
+ await usingApi(async (api) => {
+ const [flipper, deployer] = await deployFlipper(api);
+ await toggleContractAllowlistExpectSuccess(deployer, flipper.address.toString(), true);
+
+ await addToContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);
+ await toggleFlipValueExpectSuccess(bob, flipper);
+
+ await removeFromContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);
+ await toggleFlipValueExpectFailure(bob, flipper);
+ });
+ });
+
+ it('can be called twice', async () => {
+ await usingApi(async (api) => {
+ const [flipper, deployer] = await deployFlipper(api);
+
+ await addToContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);
+ await removeFromContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);
+ await removeFromContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);
+ });
+ });
+});
+
+describe.skip('Negative Integration Test removeFromContractAllowList', () => {
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+
+ before(async () => {
+ await usingApi(async () => {
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ });
+ });
+
+ it('fails when called with non-contract address', async () => {
+ await usingApi(async () => {
+ await removeFromContractAllowListExpectFailure(alice, alice.address, bob.address);
+ });
+ });
+
+ it('fails when executed by non owner', async () => {
+ await usingApi(async (api) => {
+ const [flipper] = await deployFlipper(api);
+
+ await removeFromContractAllowListExpectFailure(alice, flipper.address.toString(), bob.address);
+ });
+ });
+});
tests/src/removeFromContractWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/removeFromContractWhiteList.test.ts
+++ /dev/null
@@ -1,81 +0,0 @@
-//
-// This file is subject to the terms and conditions defined in
-// file 'LICENSE', which is part of this source code package.
-//
-
-import privateKey from './substrate/privateKey';
-import usingApi from './substrate/substrate-api';
-import {deployFlipper, toggleFlipValueExpectFailure, toggleFlipValueExpectSuccess} from './util/contracthelpers';
-import {addToContractWhiteListExpectSuccess, isWhitelistedInContract, removeFromContractWhiteListExpectFailure, removeFromContractWhiteListExpectSuccess, toggleContractWhitelistExpectSuccess} from './util/helpers';
-import {IKeyringPair} from '@polkadot/types/types';
-import {expect} from 'chai';
-
-describe.skip('Integration Test removeFromContractWhiteList', () => {
- let bob: IKeyringPair;
-
- before(async () => {
- await usingApi(async () => {
- bob = privateKey('//Bob');
- });
- });
-
- it('user is no longer whitelisted after removal', async () => {
- await usingApi(async (api) => {
- const [flipper, deployer] = await deployFlipper(api);
-
- await addToContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
- await removeFromContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
-
- expect(await isWhitelistedInContract(flipper.address, bob.address)).to.be.false;
- });
- });
-
- it('user can\'t execute contract after removal', async () => {
- await usingApi(async (api) => {
- const [flipper, deployer] = await deployFlipper(api);
- await toggleContractWhitelistExpectSuccess(deployer, flipper.address.toString(), true);
-
- await addToContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
- await toggleFlipValueExpectSuccess(bob, flipper);
-
- await removeFromContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
- await toggleFlipValueExpectFailure(bob, flipper);
- });
- });
-
- it('can be called twice', async () => {
- await usingApi(async (api) => {
- const [flipper, deployer] = await deployFlipper(api);
-
- await addToContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
- await removeFromContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
- await removeFromContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
- });
- });
-});
-
-describe.skip('Negative Integration Test removeFromContractWhiteList', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
-
- before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- });
- });
-
- it('fails when called with non-contract address', async () => {
- await usingApi(async () => {
- await removeFromContractWhiteListExpectFailure(alice, alice.address, bob.address);
- });
- });
-
- it('fails when executed by non owner', async () => {
- await usingApi(async (api) => {
- const [flipper] = await deployFlipper(api);
-
- await removeFromContractWhiteListExpectFailure(alice, flipper.address.toString(), bob.address);
- });
- });
-});
tests/src/removeFromWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/removeFromWhiteList.test.ts
+++ /dev/null
@@ -1,136 +0,0 @@
-//
-// This file is subject to the terms and conditions defined in
-// file 'LICENSE', which is part of this source code package.
-//
-
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import {default as usingApi} from './substrate/substrate-api';
-import {
- createCollectionExpectSuccess,
- destroyCollectionExpectSuccess,
- enableWhiteListExpectSuccess,
- addToWhiteListExpectSuccess,
- removeFromWhiteListExpectSuccess,
- isWhitelisted,
- findNotExistingCollection,
- removeFromWhiteListExpectFailure,
- disableWhiteListExpectSuccess,
- normalizeAccountId,
- addCollectionAdminExpectSuccess,
-} from './util/helpers';
-import {IKeyringPair} from '@polkadot/types/types';
-import privateKey from './substrate/privateKey';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-
-describe('Integration Test removeFromWhiteList', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
-
- before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- });
- });
-
- it('ensure bob is not in whitelist after removal', async () => {
- await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await enableWhiteListExpectSuccess(alice, collectionId);
- await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
-
- await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(bob.address));
- expect(await isWhitelisted(collectionId, bob.address)).to.be.false;
- });
- });
-
- it('allows removal from collection with unset whitelist status', async () => {
- await usingApi(async () => {
- const collectionWithoutWhitelistId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);
- await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, bob.address);
- await disableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);
-
- await removeFromWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, normalizeAccountId(bob.address));
- });
- });
-});
-
-describe('Negative Integration Test removeFromWhiteList', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
-
- before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- });
- });
-
- it('fails on removal from not existing collection', async () => {
- await usingApi(async (api) => {
- const collectionId = await findNotExistingCollection(api);
-
- await removeFromWhiteListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));
- });
- });
-
- it('fails on removal from removed collection', async () => {
- await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(alice, collectionId);
- await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
- await destroyCollectionExpectSuccess(collectionId);
-
- await removeFromWhiteListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));
- });
- });
-});
-
-describe('Integration Test removeFromWhiteList with collection admin permissions', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
- let charlie: IKeyringPair;
-
- before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
- });
- });
-
- it('ensure address is not in whitelist after removal', async () => {
- await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await enableWhiteListExpectSuccess(alice, collectionId);
- await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
- await removeFromWhiteListExpectSuccess(bob, collectionId, normalizeAccountId(charlie.address));
- expect(await isWhitelisted(collectionId, charlie.address)).to.be.false;
- });
- });
-
- it('Collection admin allowed to remove from whitelist with unset whitelist status', async () => {
- await usingApi(async () => {
- const collectionWithoutWhitelistId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);
- await addCollectionAdminExpectSuccess(alice, collectionWithoutWhitelistId, bob.address);
- await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, charlie.address);
- await disableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);
- await removeFromWhiteListExpectSuccess(bob, collectionWithoutWhitelistId, normalizeAccountId(charlie.address));
- });
- });
-
- it('Regular user can`t remove from whitelist', async () => {
- await usingApi(async () => {
- const collectionWithoutWhitelistId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);
- await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, charlie.address);
- await removeFromWhiteListExpectFailure(bob, collectionWithoutWhitelistId, normalizeAccountId(charlie.address));
- });
- });
-});
tests/src/setMintPermission.test.tsdiffbeforeafterboth--- a/tests/src/setMintPermission.test.ts
+++ b/tests/src/setMintPermission.test.ts
@@ -7,12 +7,12 @@
import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
import {
- addToWhiteListExpectSuccess,
+ addToAllowListExpectSuccess,
createCollectionExpectSuccess,
createItemExpectFailure,
createItemExpectSuccess,
destroyCollectionExpectSuccess,
- enableWhiteListExpectSuccess,
+ enableAllowListExpectSuccess,
findNotExistingCollection,
setMintPermissionExpectFailure,
setMintPermissionExpectSuccess,
@@ -30,12 +30,12 @@
});
});
- it('ensure white-listed non-privileged address can mint tokens', async () => {
+ it('ensure allow-listed non-privileged address can mint tokens', async () => {
await usingApi(async () => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await enableWhiteListExpectSuccess(alice, collectionId);
+ await enableAllowListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, true);
- await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
+ await addToAllowListExpectSuccess(alice, collectionId, bob.address);
await createItemExpectSuccess(bob, collectionId, 'NFT');
});
@@ -88,7 +88,7 @@
it('fails when not collection owner tries to set mint status', async () => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await enableWhiteListExpectSuccess(alice, collectionId);
+ await enableAllowListExpectSuccess(alice, collectionId);
await setMintPermissionExpectFailure(bob, collectionId, true);
});
@@ -100,10 +100,10 @@
});
});
- it('ensure non-white-listed non-privileged address can\'t mint tokens', async () => {
+ it('ensure non-allow-listed non-privileged address can\'t mint tokens', async () => {
await usingApi(async () => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await enableWhiteListExpectSuccess(alice, collectionId);
+ await enableAllowListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, true);
await createItemExpectFailure(bob, collectionId, 'NFT');
tests/src/setPublicAccessMode.test.tsdiffbeforeafterboth--- a/tests/src/setPublicAccessMode.test.ts
+++ b/tests/src/setPublicAccessMode.test.ts
@@ -11,12 +11,12 @@
import privateKey from './substrate/privateKey';
import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';
import {
- addToWhiteListExpectSuccess,
+ addToAllowListExpectSuccess,
createCollectionExpectSuccess,
createItemExpectSuccess,
destroyCollectionExpectSuccess,
enablePublicMintingExpectSuccess,
- enableWhiteListExpectSuccess,
+ enableAllowListExpectSuccess,
normalizeAccountId,
addCollectionAdminExpectSuccess,
} from './util/helpers';
@@ -35,20 +35,20 @@
});
});
- it('Run extrinsic with collection id parameters, set the whitelist mode for the collection', async () => {
+ it('Run extrinsic with collection id parameters, set the allowlist mode for the collection', async () => {
await usingApi(async () => {
const collectionId: number = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(alice, collectionId);
+ await enableAllowListExpectSuccess(alice, collectionId);
await enablePublicMintingExpectSuccess(alice, collectionId);
- await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
+ await addToAllowListExpectSuccess(alice, collectionId, bob.address);
await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
});
});
- it('Whitelisted collection limits', async () => {
+ it('Allowlisted collection limits', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(alice, collectionId);
+ await enableAllowListExpectSuccess(alice, collectionId);
await enablePublicMintingExpectSuccess(alice, collectionId);
const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(bob.address), 'NFT');
await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
@@ -61,7 +61,7 @@
await usingApi(async (api: ApiPromise) => {
// tslint:disable-next-line: radix
const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
- const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
+ const tx = api.tx.nft.setPublicAccessMode(collectionId, 'AllowList');
await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
});
});
@@ -71,7 +71,7 @@
// tslint:disable-next-line: no-bitwise
const collectionId = await createCollectionExpectSuccess();
await destroyCollectionExpectSuccess(collectionId);
- const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
+ const tx = api.tx.nft.setPublicAccessMode(collectionId, 'AllowList');
await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
});
});
@@ -79,8 +79,8 @@
it('Re-set the list mode already set in quantity', async () => {
await usingApi(async () => {
const collectionId: number = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(alice, collectionId);
- await enableWhiteListExpectSuccess(alice, collectionId);
+ await enableAllowListExpectSuccess(alice, collectionId);
+ await enableAllowListExpectSuccess(alice, collectionId);
});
});
@@ -88,7 +88,7 @@
await usingApi(async (api: ApiPromise) => {
// tslint:disable-next-line: no-bitwise
const collectionId = await createCollectionExpectSuccess();
- const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
+ const tx = api.tx.nft.setPublicAccessMode(collectionId, 'AllowList');
await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
});
});
@@ -106,7 +106,7 @@
// tslint:disable-next-line: no-bitwise
const collectionId = await createCollectionExpectSuccess();
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
+ const tx = api.tx.nft.setPublicAccessMode(collectionId, 'AllowList');
await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
});
});
tests/src/toggleContractAllowList.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/toggleContractAllowList.test.ts
@@ -0,0 +1,156 @@
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
+import privateKey from './substrate/privateKey';
+import {
+ deployFlipper,
+ getFlipValue,
+} from './util/contracthelpers';
+import {
+ getGenericResult,
+} from './util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+const value = 0;
+const gasLimit = 3000n * 1000000n;
+
+describe.skip('Integration Test toggleContractAllowList', () => {
+
+ it('Enable allow list contract mode', async () => {
+ await usingApi(async api => {
+ const [contract, deployer] = await deployFlipper(api);
+
+ const enabledBefore = (await api.query.nft.contractAllowListEnabled(contract.address)).toJSON();
+ const enableAllowListTx = api.tx.nft.toggleContractAllowList(contract.address, true);
+ const enableEvents = await submitTransactionAsync(deployer, enableAllowListTx);
+ const enabled = (await api.query.nft.contractAllowListEnabled(contract.address)).toJSON();
+
+ expect(getGenericResult(enableEvents).success).to.be.true;
+ expect(enabledBefore).to.be.false;
+ expect(enabled).to.be.true;
+ });
+ });
+
+ it('Only allowlisted account can call contract', async () => {
+ await usingApi(async api => {
+ const bob = privateKey('//Bob');
+
+ const [contract, deployer] = await deployFlipper(api);
+
+ let flipValueBefore = await getFlipValue(contract, deployer);
+ const flip = contract.tx.flip(value, gasLimit);
+ await submitTransactionAsync(bob, flip);
+ const flipValueAfter = await getFlipValue(contract,deployer);
+ expect(flipValueAfter).to.be.eq(!flipValueBefore, 'Anyone can call new contract.');
+
+ const deployerCanFlip = async () => {
+ const flipValueBefore = await getFlipValue(contract, deployer);
+ const deployerFlip = contract.tx.flip(value, gasLimit);
+ await submitTransactionAsync(deployer, deployerFlip);
+ const aliceFlip1Response = await getFlipValue(contract, deployer);
+ expect(aliceFlip1Response).to.be.eq(!flipValueBefore, 'Deployer always can flip.');
+ };
+ await deployerCanFlip();
+
+ flipValueBefore = await getFlipValue(contract, deployer);
+ const enableAllowListTx = api.tx.nft.toggleContractAllowList(contract.address, true);
+ await submitTransactionAsync(deployer, enableAllowListTx);
+ const flipWithEnabledAllowList = contract.tx.flip(value, gasLimit);
+ await expect(submitTransactionExpectFailAsync(bob, flipWithEnabledAllowList)).to.be.rejected;
+ const flipValueAfterEnableAllowList = await getFlipValue(contract, deployer);
+ expect(flipValueAfterEnableAllowList).to.be.eq(flipValueBefore, 'Enabling allowlist doesn\'t make it possible to call contract for everyone.');
+
+ await deployerCanFlip();
+
+ flipValueBefore = await getFlipValue(contract, deployer);
+ const addBobToAllowListTx = api.tx.nft.addToContractAllowList(contract.address, bob.address);
+ await submitTransactionAsync(deployer, addBobToAllowListTx);
+ const flipWithAllowlistedBob = contract.tx.flip(value, gasLimit);
+ await submitTransactionAsync(bob, flipWithAllowlistedBob);
+ const flipAfterAllowListed = await getFlipValue(contract,deployer);
+ expect(flipAfterAllowListed).to.be.eq(!flipValueBefore, 'Bob was allowlisted, now he can flip.');
+
+ await deployerCanFlip();
+
+ flipValueBefore = await getFlipValue(contract, deployer);
+ const removeBobFromAllowListTx = api.tx.nft.removeFromContractAllowList(contract.address, bob.address);
+ await submitTransactionAsync(deployer, removeBobFromAllowListTx);
+ const bobRemoved = contract.tx.flip(value, gasLimit);
+ await expect(submitTransactionExpectFailAsync(bob, bobRemoved)).to.be.rejected;
+ const afterBobRemoved = await getFlipValue(contract, deployer);
+ expect(afterBobRemoved).to.be.eq(flipValueBefore, 'Bob can\'t call contract, now when he is removeed from allow list.');
+
+ await deployerCanFlip();
+
+ flipValueBefore = await getFlipValue(contract, deployer);
+ const disableAllowListTx = api.tx.nft.toggleContractAllowList(contract.address, false);
+ await submitTransactionAsync(deployer, disableAllowListTx);
+ const allowListDisabledFlip = contract.tx.flip(value, gasLimit);
+ await submitTransactionAsync(bob, allowListDisabledFlip);
+ const afterAllowListDisabled = await getFlipValue(contract,deployer);
+ expect(afterAllowListDisabled).to.be.eq(!flipValueBefore, 'Anyone can call contract with disabled allowlist.');
+
+ });
+ });
+
+ it('Enabling allow list repeatedly should not produce errors', async () => {
+ await usingApi(async api => {
+ const [contract, deployer] = await deployFlipper(api);
+
+ const enabledBefore = (await api.query.nft.contractAllowListEnabled(contract.address)).toJSON();
+ const enableAllowListTx = api.tx.nft.toggleContractAllowList(contract.address, true);
+ const enableEvents = await submitTransactionAsync(deployer, enableAllowListTx);
+ const enabled = (await api.query.nft.contractAllowListEnabled(contract.address)).toJSON();
+ const enableAgainEvents = await submitTransactionAsync(deployer, enableAllowListTx);
+ const enabledAgain = (await api.query.nft.contractAllowListEnabled(contract.address)).toJSON();
+
+ expect(getGenericResult(enableEvents).success).to.be.true;
+ expect(enabledBefore).to.be.false;
+ expect(enabled).to.be.true;
+ expect(getGenericResult(enableAgainEvents).success).to.be.true;
+ expect(enabledAgain).to.be.true;
+ });
+ });
+
+});
+
+describe.skip('Negative Integration Test toggleContractAllowList', () => {
+
+ it('Enable allow list for a non-contract', async () => {
+ await usingApi(async api => {
+ const alice = privateKey('//Alice');
+ const bobGuineaPig = privateKey('//Bob');
+
+ const enabledBefore = (await api.query.nft.contractAllowListEnabled(bobGuineaPig.address)).toJSON();
+ const enableAllowListTx = api.tx.nft.toggleContractAllowList(bobGuineaPig.address, true);
+ await expect(submitTransactionExpectFailAsync(alice, enableAllowListTx)).to.be.rejected;
+ const enabled = (await api.query.nft.contractAllowListEnabled(bobGuineaPig.address)).toJSON();
+
+ expect(enabledBefore).to.be.false;
+ expect(enabled).to.be.false;
+ });
+ });
+
+ it('Enable allow list using a non-owner address', async () => {
+ await usingApi(async api => {
+ const bob = privateKey('//Bob');
+ const [contract] = await deployFlipper(api);
+
+ const enabledBefore = (await api.query.nft.contractAllowListEnabled(contract.address)).toJSON();
+ const enableAllowListTx = api.tx.nft.toggleContractAllowList(contract.address, true);
+ await expect(submitTransactionExpectFailAsync(bob, enableAllowListTx)).to.be.rejected;
+ const enabled = (await api.query.nft.contractAllowListEnabled(contract.address)).toJSON();
+
+ expect(enabledBefore).to.be.false;
+ expect(enabled).to.be.false;
+ });
+ });
+
+});
tests/src/toggleContractWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/toggleContractWhiteList.test.ts
+++ /dev/null
@@ -1,156 +0,0 @@
-//
-// This file is subject to the terms and conditions defined in
-// file 'LICENSE', which is part of this source code package.
-//
-
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
-import privateKey from './substrate/privateKey';
-import {
- deployFlipper,
- getFlipValue,
-} from './util/contracthelpers';
-import {
- getGenericResult,
-} from './util/helpers';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-
-const value = 0;
-const gasLimit = 3000n * 1000000n;
-
-describe.skip('Integration Test toggleContractWhiteList', () => {
-
- it('Enable white list contract mode', async () => {
- await usingApi(async api => {
- const [contract, deployer] = await deployFlipper(api);
-
- const enabledBefore = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();
- const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, true);
- const enableEvents = await submitTransactionAsync(deployer, enableWhiteListTx);
- const enabled = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();
-
- expect(getGenericResult(enableEvents).success).to.be.true;
- expect(enabledBefore).to.be.false;
- expect(enabled).to.be.true;
- });
- });
-
- it('Only whitelisted account can call contract', async () => {
- await usingApi(async api => {
- const bob = privateKey('//Bob');
-
- const [contract, deployer] = await deployFlipper(api);
-
- let flipValueBefore = await getFlipValue(contract, deployer);
- const flip = contract.tx.flip(value, gasLimit);
- await submitTransactionAsync(bob, flip);
- const flipValueAfter = await getFlipValue(contract,deployer);
- expect(flipValueAfter).to.be.eq(!flipValueBefore, 'Anyone can call new contract.');
-
- const deployerCanFlip = async () => {
- const flipValueBefore = await getFlipValue(contract, deployer);
- const deployerFlip = contract.tx.flip(value, gasLimit);
- await submitTransactionAsync(deployer, deployerFlip);
- const aliceFlip1Response = await getFlipValue(contract, deployer);
- expect(aliceFlip1Response).to.be.eq(!flipValueBefore, 'Deployer always can flip.');
- };
- await deployerCanFlip();
-
- flipValueBefore = await getFlipValue(contract, deployer);
- const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, true);
- await submitTransactionAsync(deployer, enableWhiteListTx);
- const flipWithEnabledWhiteList = contract.tx.flip(value, gasLimit);
- await expect(submitTransactionExpectFailAsync(bob, flipWithEnabledWhiteList)).to.be.rejected;
- const flipValueAfterEnableWhiteList = await getFlipValue(contract, deployer);
- expect(flipValueAfterEnableWhiteList).to.be.eq(flipValueBefore, 'Enabling whitelist doesn\'t make it possible to call contract for everyone.');
-
- await deployerCanFlip();
-
- flipValueBefore = await getFlipValue(contract, deployer);
- const addBobToWhiteListTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);
- await submitTransactionAsync(deployer, addBobToWhiteListTx);
- const flipWithWhitelistedBob = contract.tx.flip(value, gasLimit);
- await submitTransactionAsync(bob, flipWithWhitelistedBob);
- const flipAfterWhiteListed = await getFlipValue(contract,deployer);
- expect(flipAfterWhiteListed).to.be.eq(!flipValueBefore, 'Bob was whitelisted, now he can flip.');
-
- await deployerCanFlip();
-
- flipValueBefore = await getFlipValue(contract, deployer);
- const removeBobFromWhiteListTx = api.tx.nft.removeFromContractWhiteList(contract.address, bob.address);
- await submitTransactionAsync(deployer, removeBobFromWhiteListTx);
- const bobRemoved = contract.tx.flip(value, gasLimit);
- await expect(submitTransactionExpectFailAsync(bob, bobRemoved)).to.be.rejected;
- const afterBobRemoved = await getFlipValue(contract, deployer);
- expect(afterBobRemoved).to.be.eq(flipValueBefore, 'Bob can\'t call contract, now when he is removeed from white list.');
-
- await deployerCanFlip();
-
- flipValueBefore = await getFlipValue(contract, deployer);
- const disableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, false);
- await submitTransactionAsync(deployer, disableWhiteListTx);
- const whiteListDisabledFlip = contract.tx.flip(value, gasLimit);
- await submitTransactionAsync(bob, whiteListDisabledFlip);
- const afterWhiteListDisabled = await getFlipValue(contract,deployer);
- expect(afterWhiteListDisabled).to.be.eq(!flipValueBefore, 'Anyone can call contract with disabled whitelist.');
-
- });
- });
-
- it('Enabling white list repeatedly should not produce errors', async () => {
- await usingApi(async api => {
- const [contract, deployer] = await deployFlipper(api);
-
- const enabledBefore = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();
- const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, true);
- const enableEvents = await submitTransactionAsync(deployer, enableWhiteListTx);
- const enabled = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();
- const enableAgainEvents = await submitTransactionAsync(deployer, enableWhiteListTx);
- const enabledAgain = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();
-
- expect(getGenericResult(enableEvents).success).to.be.true;
- expect(enabledBefore).to.be.false;
- expect(enabled).to.be.true;
- expect(getGenericResult(enableAgainEvents).success).to.be.true;
- expect(enabledAgain).to.be.true;
- });
- });
-
-});
-
-describe.skip('Negative Integration Test toggleContractWhiteList', () => {
-
- it('Enable white list for a non-contract', async () => {
- await usingApi(async api => {
- const alice = privateKey('//Alice');
- const bobGuineaPig = privateKey('//Bob');
-
- const enabledBefore = (await api.query.nft.contractWhiteListEnabled(bobGuineaPig.address)).toJSON();
- const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(bobGuineaPig.address, true);
- await expect(submitTransactionExpectFailAsync(alice, enableWhiteListTx)).to.be.rejected;
- const enabled = (await api.query.nft.contractWhiteListEnabled(bobGuineaPig.address)).toJSON();
-
- expect(enabledBefore).to.be.false;
- expect(enabled).to.be.false;
- });
- });
-
- it('Enable white list using a non-owner address', async () => {
- await usingApi(async api => {
- const bob = privateKey('//Bob');
- const [contract] = await deployFlipper(api);
-
- const enabledBefore = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();
- const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, true);
- await expect(submitTransactionExpectFailAsync(bob, enableWhiteListTx)).to.be.rejected;
- const enabled = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();
-
- expect(enabledBefore).to.be.false;
- expect(enabled).to.be.false;
- });
- });
-
-});
tests/src/transfer_contract/metadata.jsondiffbeforeafterboth--- a/tests/src/transfer_contract/metadata.json
+++ b/tests/src/transfer_contract/metadata.json
@@ -323,7 +323,7 @@
}
},
{
- "name": "whitelisted",
+ "name": "allowlisted",
"type": {
"displayName": [
"bool"
@@ -335,7 +335,7 @@
"docs": [],
"mutates": true,
"name": [
- "toggle_white_list"
+ "toggle_allow_list"
],
"payable": false,
"returnType": null,
tests/src/util/helpers.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import {ApiPromise, Keyring} from '@polkadot/api';7import type {AccountId, EventRecord} from '@polkadot/types/interfaces';8import {IKeyringPair} from '@polkadot/types/types';9import {evmToAddress} from '@polkadot/util-crypto';10import BN from 'bn.js';11import chai from 'chai';12import chaiAsPromised from 'chai-as-promised';13import {alicesPublicKey} from '../accounts';14import {NftDataStructsCollection} from '../interfaces';15import privateKey from '../substrate/privateKey';16import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';17import {hexToStr, strToUTF16, utf16ToStr} from './util';1819chai.use(chaiAsPromised);20const expect = chai.expect;2122export type CrossAccountId = {23 Substrate: string,24} | {25 Ethereum: string,26};27export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {28 if (typeof input === 'string') {29 if (input.length === 48 || input.length === 47) {30 return {Substrate: input};31 } else if (input.length === 42 && input.startsWith('0x')) {32 return {Ethereum: input.toLowerCase()};33 } else if (input.length === 40 && !input.startsWith('0x')) {34 return {Ethereum: '0x' + input.toLowerCase()};35 } else {36 throw new Error(`Unknown address format: "${input}"`);37 }38 }39 if ('address' in input) {40 return {Substrate: input.address};41 }42 if ('Ethereum' in input) {43 return {44 Ethereum: input.Ethereum.toLowerCase(),45 };46 } else if ('ethereum' in input) {47 return {48 Ethereum: (input as any).ethereum.toLowerCase(),49 };50 } else if ('Substrate' in input) {51 return input;52 }else if ('substrate' in input) {53 return {54 Substrate: (input as any).substrate,55 };56 }5758 // AccountId59 return {Substrate: input.toString()};60}61export function toSubstrateAddress(input: string | CrossAccountId | IKeyringPair): string {62 input = normalizeAccountId(input);63 if ('Substrate' in input) {64 return input.Substrate;65 } else {66 return evmToAddress(input.Ethereum);67 }68}6970export const U128_MAX = (1n << 128n) - 1n;7172const MICROUNIQUE = 1_000_000_000n;73const MILLIUNIQUE = 1_000n * MICROUNIQUE;74const CENTIUNIQUE = 10n * MILLIUNIQUE;75export const UNIQUE = 100n * CENTIUNIQUE;7677type GenericResult = {78 success: boolean,79};8081interface CreateCollectionResult {82 success: boolean;83 collectionId: number;84}8586interface CreateItemResult {87 success: boolean;88 collectionId: number;89 itemId: number;90 recipient?: CrossAccountId;91}9293interface TransferResult {94 success: boolean;95 collectionId: number;96 itemId: number;97 sender?: CrossAccountId;98 recipient?: CrossAccountId;99 value: bigint;100}101102interface IReFungibleOwner {103 fraction: BN;104 owner: number[];105}106107interface IGetMessage {108 checkMsgNftMethod: string;109 checkMsgTrsMethod: string;110 checkMsgSysMethod: string;111}112113export interface IFungibleTokenDataType {114 value: number;115}116117export interface IChainLimits {118 collectionNumbersLimit: number;119 accountTokenOwnershipLimit: number;120 collectionsAdminsLimit: number;121 customDataLimit: number;122 nftSponsorTransferTimeout: number;123 fungibleSponsorTransferTimeout: number;124 refungibleSponsorTransferTimeout: number;125 offchainSchemaLimit: number;126 variableOnChainSchemaLimit: number;127 constOnChainSchemaLimit: number;128}129130export interface IReFungibleTokenDataType {131 owner: IReFungibleOwner[];132 constData: number[];133 variableData: number[];134}135136export function nftEventMessage(events: EventRecord[]): IGetMessage {137 let checkMsgNftMethod = '';138 let checkMsgTrsMethod = '';139 let checkMsgSysMethod = '';140 events.forEach(({event: {method, section}}) => {141 if (section === 'common') {142 checkMsgNftMethod = method;143 } else if (section === 'treasury') {144 checkMsgTrsMethod = method;145 } else if (section === 'system') {146 checkMsgSysMethod = method;147 } else { return null; }148 });149 const result: IGetMessage = {150 checkMsgNftMethod,151 checkMsgTrsMethod,152 checkMsgSysMethod,153 };154 return result;155}156157export function getGenericResult(events: EventRecord[]): GenericResult {158 const result: GenericResult = {159 success: false,160 };161 events.forEach(({event: {method}}) => {162 // console.log(` ${phase}: ${section}.${method}:: ${data}`);163 if (method === 'ExtrinsicSuccess') {164 result.success = true;165 }166 });167 return result;168}169170171172export function getCreateCollectionResult(events: EventRecord[]): CreateCollectionResult {173 let success = false;174 let collectionId = 0;175 events.forEach(({event: {data, method, section}}) => {176 // console.log(` ${phase}: ${section}.${method}:: ${data}`);177 if (method == 'ExtrinsicSuccess') {178 success = true;179 } else if ((section == 'common') && (method == 'CollectionCreated')) {180 collectionId = parseInt(data[0].toString(), 10);181 }182 });183 const result: CreateCollectionResult = {184 success,185 collectionId,186 };187 return result;188}189190export function getCreateItemResult(events: EventRecord[]): CreateItemResult {191 let success = false;192 let collectionId = 0;193 let itemId = 0;194 let recipient;195 events.forEach(({event: {data, method, section}}) => {196 // console.log(` ${phase}: ${section}.${method}:: ${data}`);197 if (method == 'ExtrinsicSuccess') {198 success = true;199 } else if ((section == 'common') && (method == 'ItemCreated')) {200 collectionId = parseInt(data[0].toString(), 10);201 itemId = parseInt(data[1].toString(), 10);202 recipient = normalizeAccountId(data[2].toJSON() as any);203 }204 });205 const result: CreateItemResult = {206 success,207 collectionId,208 itemId,209 recipient,210 };211 return result;212}213214export function getTransferResult(events: EventRecord[]): TransferResult {215 const result: TransferResult = {216 success: false,217 collectionId: 0,218 itemId: 0,219 value: 0n,220 };221222 events.forEach(({event: {data, method, section}}) => {223 if (method === 'ExtrinsicSuccess') {224 result.success = true;225 } else if (section === 'common' && method === 'Transfer') {226 result.collectionId = +data[0].toString();227 result.itemId = +data[1].toString();228 result.sender = normalizeAccountId(data[2].toJSON() as any);229 result.recipient = normalizeAccountId(data[3].toJSON() as any);230 result.value = BigInt(data[4].toString());231 }232 });233234 return result;235}236237interface Nft {238 type: 'NFT';239}240241interface Fungible {242 type: 'Fungible';243 decimalPoints: number;244}245246interface ReFungible {247 type: 'ReFungible';248}249250type CollectionMode = Nft | Fungible | ReFungible;251252export type CreateCollectionParams = {253 mode: CollectionMode,254 name: string,255 description: string,256 tokenPrefix: string,257};258259const defaultCreateCollectionParams: CreateCollectionParams = {260 description: 'description',261 mode: {type: 'NFT'},262 name: 'name',263 tokenPrefix: 'prefix',264};265266export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {267 const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};268269 let collectionId = 0;270 await usingApi(async (api) => {271 // Get number of collections before the transaction272 const collectionCountBefore = (await api.query.common.createdCollectionCount()).toNumber();273274 // Run the CreateCollection transaction275 const alicePrivateKey = privateKey('//Alice');276277 let modeprm = {};278 if (mode.type === 'NFT') {279 modeprm = {nft: null};280 } else if (mode.type === 'Fungible') {281 modeprm = {fungible: mode.decimalPoints};282 } else if (mode.type === 'ReFungible') {283 modeprm = {refungible: null};284 }285286 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm as any);287 const events = await submitTransactionAsync(alicePrivateKey, tx);288 const result = getCreateCollectionResult(events);289290 // Get number of collections after the transaction291 const collectionCountAfter = (await api.query.common.createdCollectionCount()).toNumber();292293 // Get the collection294 const collection = (await api.query.common.collectionById(result.collectionId)).unwrap();295296 // What to expect297 // tslint:disable-next-line:no-unused-expression298 expect(result.success).to.be.true;299 expect(result.collectionId).to.be.equal(collectionCountAfter);300 // tslint:disable-next-line:no-unused-expression301 expect(collection).to.be.not.null;302 expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');303 expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicesPublicKey));304 expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);305 expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);306 expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);307308 collectionId = result.collectionId;309 });310311 return collectionId;312}313314export async function createCollectionExpectFailure(params: Partial<CreateCollectionParams> = {}) {315 const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};316317 let modeprm = {};318 if (mode.type === 'NFT') {319 modeprm = {nft: null};320 } else if (mode.type === 'Fungible') {321 modeprm = {fungible: mode.decimalPoints};322 } else if (mode.type === 'ReFungible') {323 modeprm = {refungible: null};324 }325326 await usingApi(async (api) => {327 // Get number of collections before the transaction328 const collectionCountBefore = (await api.query.common.createdCollectionCount()).toNumber();329330 // Run the CreateCollection transaction331 const alicePrivateKey = privateKey('//Alice');332 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm as any);333 const events = await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;334 const result = getCreateCollectionResult(events);335336 // Get number of collections after the transaction337 const collectionCountAfter = (await api.query.common.createdCollectionCount()).toNumber();338339 // What to expect340 // tslint:disable-next-line:no-unused-expression341 expect(result.success).to.be.false;342 expect(collectionCountAfter).to.be.equal(collectionCountBefore, 'Error: Collection with incorrect data created.');343 });344}345346export async function findUnusedAddress(api: ApiPromise, seedAddition = ''): Promise<IKeyringPair> {347 let bal = 0n;348 let unused;349 do {350 const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000)) + seedAddition;351 const keyring = new Keyring({type: 'sr25519'});352 unused = keyring.addFromUri(`//${randomSeed}`);353 bal = (await api.query.system.account(unused.address)).data.free.toBigInt();354 } while (bal !== 0n);355 return unused;356}357358export async function getAllowance(api: ApiPromise, collectionId: number, owner: CrossAccountId | string, approved: CrossAccountId | string, tokenId: number) {359 return (await api.rpc.nft.allowance(collectionId, normalizeAccountId(owner), normalizeAccountId(approved), tokenId)).toBigInt();360}361362export function findUnusedAddresses(api: ApiPromise, amount: number): Promise<IKeyringPair[]> {363 return Promise.all(new Array(amount).fill(null).map(() => findUnusedAddress(api, '_' + Date.now())));364}365366export async function findNotExistingCollection(api: ApiPromise): Promise<number> {367 const totalNumber = (await api.query.common.createdCollectionCount()).toNumber();368 const newCollection: number = totalNumber + 1;369 return newCollection;370}371372function getDestroyResult(events: EventRecord[]): boolean {373 let success = false;374 events.forEach(({event: {method}}) => {375 if (method == 'ExtrinsicSuccess') {376 success = true;377 }378 });379 return success;380}381382export async function destroyCollectionExpectFailure(collectionId: number, senderSeed = '//Alice') {383 await usingApi(async (api) => {384 // Run the DestroyCollection transaction385 const alicePrivateKey = privateKey(senderSeed);386 const tx = api.tx.nft.destroyCollection(collectionId);387 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;388 });389}390391export async function destroyCollectionExpectSuccess(collectionId: number, senderSeed = '//Alice') {392 await usingApi(async (api) => {393 // Run the DestroyCollection transaction394 const alicePrivateKey = privateKey(senderSeed);395 const tx = api.tx.nft.destroyCollection(collectionId);396 const events = await submitTransactionAsync(alicePrivateKey, tx);397 const result = getDestroyResult(events);398 expect(result).to.be.true;399400 // What to expect401 expect((await api.query.common.collectionById(collectionId)).isNone).to.be.true;402 });403}404405export async function setCollectionLimitsExpectSuccess(sender: IKeyringPair, collectionId: number, limits: any) {406 await usingApi(async (api) => {407 const tx = api.tx.nft.setCollectionLimits(collectionId, limits);408 const events = await submitTransactionAsync(sender, tx);409 const result = getGenericResult(events);410411 expect(result.success).to.be.true;412 });413}414415export async function setCollectionLimitsExpectFailure(sender: IKeyringPair, collectionId: number, limits: any) {416 await usingApi(async (api) => {417 const tx = api.tx.nft.setCollectionLimits(collectionId, limits);418 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;419 const result = getGenericResult(events);420421 expect(result.success).to.be.false;422 });423}424425export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string, sender = '//Alice') {426 await usingApi(async (api) => {427428 // Run the transaction429 const senderPrivateKey = privateKey(sender);430 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);431 const events = await submitTransactionAsync(senderPrivateKey, tx);432 const result = getGenericResult(events);433434 // Get the collection435 const collection = (await api.query.common.collectionById(collectionId)).unwrap();436437 // What to expect438 expect(result.success).to.be.true;439 expect(collection.sponsorship.toJSON()).to.deep.equal({440 unconfirmed: sponsor,441 });442 });443}444445export async function removeCollectionSponsorExpectSuccess(collectionId: number, sender = '//Alice') {446 await usingApi(async (api) => {447448 // Run the transaction449 const alicePrivateKey = privateKey(sender);450 const tx = api.tx.nft.removeCollectionSponsor(collectionId);451 const events = await submitTransactionAsync(alicePrivateKey, tx);452 const result = getGenericResult(events);453454 // Get the collection455 const collection = (await api.query.common.collectionById(collectionId)).unwrap();456457 // What to expect458 expect(result.success).to.be.true;459 expect(collection.sponsorship.toJSON()).to.be.deep.equal({disabled: null});460 });461}462463export async function removeCollectionSponsorExpectFailure(collectionId: number, senderSeed = '//Alice') {464 await usingApi(async (api) => {465466 // Run the transaction467 const alicePrivateKey = privateKey(senderSeed);468 const tx = api.tx.nft.removeCollectionSponsor(collectionId);469 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;470 });471}472473export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string, senderSeed = '//Alice') {474 await usingApi(async (api) => {475476 // Run the transaction477 const alicePrivateKey = privateKey(senderSeed);478 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);479 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;480 });481}482483export async function confirmSponsorshipExpectSuccess(collectionId: number, senderSeed = '//Alice') {484 await usingApi(async (api) => {485486 // Run the transaction487 const sender = privateKey(senderSeed);488 const tx = api.tx.nft.confirmSponsorship(collectionId);489 const events = await submitTransactionAsync(sender, tx);490 const result = getGenericResult(events);491492 // Get the collection493 const collection = (await api.query.common.collectionById(collectionId)).unwrap();494495 // What to expect496 expect(result.success).to.be.true;497 expect(collection.sponsorship.toJSON()).to.be.deep.equal({498 confirmed: sender.address,499 });500 });501}502503504export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed = '//Alice') {505 await usingApi(async (api) => {506507 // Run the transaction508 const sender = privateKey(senderSeed);509 const tx = api.tx.nft.confirmSponsorship(collectionId);510 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;511 });512}513514export async function setMetadataUpdatePermissionFlagExpectSuccess(sender: IKeyringPair, collectionId: number, flag: string) {515516 await usingApi(async (api) => {517 const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag as any);518 const events = await submitTransactionAsync(sender, tx);519 const result = getGenericResult(events);520521 expect(result.success).to.be.true;522 });523}524525export async function setMetadataUpdatePermissionFlagExpectFailure(sender: IKeyringPair, collectionId: number, flag: string) {526527 await usingApi(async (api) => {528 const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag as any);529 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;530 const result = getGenericResult(events);531532 expect(result.success).to.be.false;533 });534}535536export async function enableContractSponsoringExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, enable: boolean) {537 await usingApi(async (api) => {538 const tx = api.tx.nft.enableContractSponsoring(contractAddress, enable);539 const events = await submitTransactionAsync(sender, tx);540 const result = getGenericResult(events);541542 expect(result.success).to.be.true;543 });544}545546export async function enableContractSponsoringExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, enable: boolean) {547 await usingApi(async (api) => {548 const tx = api.tx.nft.enableContractSponsoring(contractAddress, enable);549 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;550 const result = getGenericResult(events);551552 expect(result.success).to.be.false;553 });554}555556export async function setTransferFlagExpectSuccess(sender: IKeyringPair, collectionId: number, enabled: boolean) {557558 await usingApi(async (api) => {559560 const tx = api.tx.nft.setTransfersEnabledFlag (collectionId, enabled);561 const events = await submitTransactionAsync(sender, tx);562 const result = getGenericResult(events);563564 expect(result.success).to.be.true;565 });566}567568export async function setTransferFlagExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {569570 await usingApi(async (api) => {571572 const tx = api.tx.nft.setTransfersEnabledFlag (collectionId, enabled);573 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;574 const result = getGenericResult(events);575576 expect(result.success).to.be.false;577 });578}579580export async function setContractSponsoringRateLimitExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) {581 await usingApi(async (api) => {582 const tx = api.tx.nft.setContractSponsoringRateLimit(contractAddress, rateLimit);583 const events = await submitTransactionAsync(sender, tx);584 const result = getGenericResult(events);585586 expect(result.success).to.be.true;587 });588}589590export async function setContractSponsoringRateLimitExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) {591 await usingApi(async (api) => {592 const tx = api.tx.nft.setContractSponsoringRateLimit(contractAddress, rateLimit);593 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;594 const result = getGenericResult(events);595596 expect(result.success).to.be.false;597 });598}599600export async function toggleContractWhitelistExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, value = true) {601 await usingApi(async (api) => {602 const tx = api.tx.nft.toggleContractWhiteList(contractAddress, value);603 const events = await submitTransactionAsync(sender, tx);604 const result = getGenericResult(events);605606 expect(result.success).to.be.true;607 });608}609610export async function isWhitelistedInContract(contractAddress: AccountId | string, user: string) {611 let whitelisted = false;612 await usingApi(async (api) => {613 whitelisted = (await api.query.nft.contractWhiteList(contractAddress, user)).toJSON() as boolean;614 });615 return whitelisted;616}617618export async function addToContractWhiteListExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, user: AccountId | string) {619 await usingApi(async (api) => {620 const tx = api.tx.nft.addToContractWhiteList(contractAddress.toString(), user.toString());621 const events = await submitTransactionAsync(sender, tx);622 const result = getGenericResult(events);623624 expect(result.success).to.be.true;625 });626}627628export async function removeFromContractWhiteListExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, user: AccountId | string) {629 await usingApi(async (api) => {630 const tx = api.tx.nft.removeFromContractWhiteList(contractAddress.toString(), user.toString());631 const events = await submitTransactionAsync(sender, tx);632 const result = getGenericResult(events);633634 expect(result.success).to.be.true;635 });636}637638export async function removeFromContractWhiteListExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, user: AccountId | string) {639 await usingApi(async (api) => {640 const tx = api.tx.nft.removeFromContractWhiteList(contractAddress.toString(), user.toString());641 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;642 const result = getGenericResult(events);643644 expect(result.success).to.be.false;645 });646}647648export async function setVariableMetaDataExpectSuccess(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) {649 await usingApi(async (api) => {650 const tx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(data).toString('hex'));651 const events = await submitTransactionAsync(sender, tx);652 const result = getGenericResult(events);653654 expect(result.success).to.be.true;655 });656}657658export async function setVariableMetaDataExpectFailure(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) {659 await usingApi(async (api) => {660 const tx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(data).toString('hex'));661 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;662 });663}664665export async function setOffchainSchemaExpectSuccess(sender: IKeyringPair, collectionId: number, data: number[]) {666 await usingApi(async (api) => {667 const tx = api.tx.nft.setOffchainSchema(collectionId, '0x' + Buffer.from(data).toString('hex'));668 const events = await submitTransactionAsync(sender, tx);669 const result = getGenericResult(events);670671 expect(result.success).to.be.true;672 });673}674675export async function setOffchainSchemaExpectFailure(sender: IKeyringPair, collectionId: number, data: number[]) {676 await usingApi(async (api) => {677 const tx = api.tx.nft.setOffchainSchema(collectionId, '0x' + Buffer.from(data).toString('hex'));678 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;679 });680}681682export interface CreateFungibleData {683 readonly Value: bigint;684}685686export interface CreateReFungibleData { }687export interface CreateNftData { }688689export type CreateItemData = {690 NFT: CreateNftData;691} | {692 Fungible: CreateFungibleData;693} | {694 ReFungible: CreateReFungibleData;695};696697export async function burnItemExpectSuccess(sender: IKeyringPair, collectionId: number, tokenId: number, value = 1) {698 await usingApi(async (api) => {699 const balanceBefore = await getBalance(api, collectionId, normalizeAccountId(sender), tokenId);700 // if burning token by admin - use adminButnItemExpectSuccess701 expect(balanceBefore >= BigInt(value)).to.be.true;702703 const tx = api.tx.nft.burnItem(collectionId, tokenId, value);704 const events = await submitTransactionAsync(sender, tx);705 const result = getGenericResult(events);706 expect(result.success).to.be.true;707708 const balanceAfter = await getBalance(api, collectionId, normalizeAccountId(sender), tokenId);709 expect(balanceAfter + BigInt(value)).to.be.equal(balanceBefore);710 });711}712713export async function714approveExpectSuccess(715 collectionId: number,716 tokenId: number, owner: IKeyringPair, approved: CrossAccountId | string, amount: number | bigint = 1,717) {718 await usingApi(async (api: ApiPromise) => {719 const approveNftTx = api.tx.nft.approve(normalizeAccountId(approved), collectionId, tokenId, amount);720 const events = await submitTransactionAsync(owner, approveNftTx);721 const result = getGenericResult(events);722 expect(result.success).to.be.true;723724 expect(await getAllowance(api, collectionId, owner.address, approved, tokenId)).to.be.equal(BigInt(amount));725 });726}727728export async function adminApproveFromExpectSuccess(729 collectionId: number,730 tokenId: number, admin: IKeyringPair, owner: CrossAccountId | string, approved: CrossAccountId | string, amount: number | bigint = 1,731) {732 await usingApi(async (api: ApiPromise) => {733 const approveNftTx = api.tx.nft.approve(normalizeAccountId(approved), collectionId, tokenId, amount);734 const events = await submitTransactionAsync(admin, approveNftTx);735 const result = getGenericResult(events);736 expect(result.success).to.be.true;737738 expect(await getAllowance(api, collectionId, owner, approved, tokenId)).to.be.equal(BigInt(amount));739 });740}741742export async function743transferFromExpectSuccess(744 collectionId: number,745 tokenId: number,746 accountApproved: IKeyringPair,747 accountFrom: IKeyringPair | CrossAccountId,748 accountTo: IKeyringPair | CrossAccountId,749 value: number | bigint = 1,750 type = 'NFT',751) {752 await usingApi(async (api: ApiPromise) => {753 const to = normalizeAccountId(accountTo);754 let balanceBefore = 0n;755 if (type === 'Fungible') {756 balanceBefore = await getBalance(api, collectionId, to, tokenId);757 }758 const transferFromTx = api.tx.nft.transferFrom(normalizeAccountId(accountFrom), to, collectionId, tokenId, value);759 const events = await submitTransactionAsync(accountApproved, transferFromTx);760 const result = getCreateItemResult(events);761 // tslint:disable-next-line:no-unused-expression762 expect(result.success).to.be.true;763 if (type === 'NFT') {764 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(to);765 }766 if (type === 'Fungible') {767 const balanceAfter = await getBalance(api, collectionId, to, tokenId);768 expect(balanceAfter - balanceBefore).to.be.equal(BigInt(value));769 }770 if (type === 'ReFungible') {771 expect(await getBalance(api, collectionId, to, tokenId)).to.be.equal(BigInt(value));772 }773 });774}775776export async function777transferFromExpectFail(778 collectionId: number,779 tokenId: number,780 accountApproved: IKeyringPair,781 accountFrom: IKeyringPair,782 accountTo: IKeyringPair,783 value: number | bigint = 1,784) {785 await usingApi(async (api: ApiPromise) => {786 const transferFromTx = api.tx.nft.transferFrom(normalizeAccountId(accountFrom.address), normalizeAccountId(accountTo.address), collectionId, tokenId, value);787 const events = await expect(submitTransactionExpectFailAsync(accountApproved, transferFromTx)).to.be.rejected;788 const result = getCreateCollectionResult(events);789 // tslint:disable-next-line:no-unused-expression790 expect(result.success).to.be.false;791 });792}793794/* eslint no-async-promise-executor: "off" */795async function getBlockNumber(api: ApiPromise): Promise<number> {796 return new Promise<number>(async (resolve) => {797 const unsubscribe = await api.rpc.chain.subscribeNewHeads((head) => {798 unsubscribe();799 resolve(head.number.toNumber());800 });801 });802}803804export async function addCollectionAdminExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | CrossAccountId) {805 await usingApi(async (api) => {806 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(address));807 const events = await submitTransactionAsync(sender, changeAdminTx);808 const result = getCreateCollectionResult(events);809 expect(result.success).to.be.true;810 });811}812813export async function814getFreeBalance(account: IKeyringPair) : Promise<bigint>815{816 let balance = 0n;817 await usingApi(async (api) => {818 balance = BigInt((await api.query.system.account(account.address)).data.free.toString());819 });820821 return balance;822}823824export async function825scheduleTransferExpectSuccess(826 collectionId: number,827 tokenId: number,828 sender: IKeyringPair,829 recipient: IKeyringPair,830 value: number | bigint = 1,831 blockSchedule: number,832) {833 await usingApi(async (api: ApiPromise) => {834 const blockNumber: number | undefined = await getBlockNumber(api);835 const expectedBlockNumber = blockNumber + blockSchedule;836837 expect(blockNumber).to.be.greaterThan(0);838 const transferTx = api.tx.nft.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);839 const scheduleTx = api.tx.scheduler.schedule(expectedBlockNumber, null, 0, transferTx as any);840841 await submitTransactionAsync(sender, scheduleTx);842843 const recipientBalanceBefore = (await api.query.system.account(recipient.address)).data.free.toBigInt();844845 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(normalizeAccountId(sender.address));846847 // sleep for 4 blocks848 await waitNewBlocks(blockSchedule + 1);849850 const recipientBalanceAfter = (await api.query.system.account(recipient.address)).data.free.toBigInt();851852 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(normalizeAccountId(recipient.address));853 expect(recipientBalanceAfter).to.be.equal(recipientBalanceBefore);854 });855}856857858export async function859transferExpectSuccess(860 collectionId: number,861 tokenId: number,862 sender: IKeyringPair,863 recipient: IKeyringPair | CrossAccountId,864 value: number | bigint = 1,865 type = 'NFT',866) {867 await usingApi(async (api: ApiPromise) => {868 const to = normalizeAccountId(recipient);869870 let balanceBefore = 0n;871 if (type === 'Fungible') {872 balanceBefore = await getBalance(api, collectionId, to, tokenId);873 }874 const transferTx = api.tx.nft.transfer(to, collectionId, tokenId, value);875 const events = await submitTransactionAsync(sender, transferTx);876 const result = getTransferResult(events);877 // tslint:disable-next-line:no-unused-expression878 expect(result.success).to.be.true;879 expect(result.collectionId).to.be.equal(collectionId);880 expect(result.itemId).to.be.equal(tokenId);881 expect(result.sender).to.be.deep.equal(normalizeAccountId(sender.address));882 expect(result.recipient).to.be.deep.equal(to);883 expect(result.value).to.be.equal(BigInt(value));884 if (type === 'NFT') {885 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(to);886 }887 if (type === 'Fungible') {888 const balanceAfter = await getBalance(api, collectionId, to, tokenId);889 expect(balanceAfter - balanceBefore).to.be.equal(BigInt(value));890 }891 if (type === 'ReFungible') {892 expect(await getBalance(api, collectionId, to, tokenId) >= value).to.be.true;893 }894 });895}896897export async function898transferExpectFailure(899 collectionId: number,900 tokenId: number,901 sender: IKeyringPair,902 recipient: IKeyringPair,903 value: number | bigint = 1,904) {905 await usingApi(async (api: ApiPromise) => {906 const transferTx = api.tx.nft.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);907 const events = await expect(submitTransactionExpectFailAsync(sender, transferTx)).to.be.rejected;908 const result = getGenericResult(events);909 // if (events && Array.isArray(events)) {910 // const result = getCreateCollectionResult(events);911 // tslint:disable-next-line:no-unused-expression912 expect(result.success).to.be.false;913 //}914 });915}916917export async function918approveExpectFail(919 collectionId: number,920 tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number | bigint = 1,921) {922 await usingApi(async (api: ApiPromise) => {923 const approveNftTx = api.tx.nft.approve(normalizeAccountId(approved.address), collectionId, tokenId, amount);924 const events = await expect(submitTransactionExpectFailAsync(owner, approveNftTx)).to.be.rejected;925 const result = getCreateCollectionResult(events);926 // tslint:disable-next-line:no-unused-expression927 expect(result.success).to.be.false;928 });929}930931export async function getBalance(932 api: ApiPromise,933 collectionId: number,934 owner: string | CrossAccountId,935 token: number,936): Promise<bigint> {937 return (await api.rpc.nft.balance(collectionId, normalizeAccountId(owner), token)).toBigInt();938}939export async function getTokenOwner(940 api: ApiPromise,941 collectionId: number,942 token: number,943): Promise<CrossAccountId> {944 return normalizeAccountId((await api.rpc.nft.tokenOwner(collectionId, token)).toJSON() as any);945}946export async function isTokenExists(947 api: ApiPromise,948 collectionId: number,949 token: number,950): Promise<boolean> {951 return (await api.rpc.nft.tokenExists(collectionId, token)).toJSON();952}953export async function getLastTokenId(954 api: ApiPromise,955 collectionId: number,956): Promise<number> {957 return (await api.rpc.nft.lastTokenId(collectionId)).toJSON();958}959export async function getAdminList(960 api: ApiPromise,961 collectionId: number,962): Promise<string[]> {963 return (await api.rpc.nft.adminlist(collectionId)).toHuman() as any;964}965export async function getVariableMetadata(966 api: ApiPromise,967 collectionId: number,968 tokenId: number,969): Promise<number[]> {970 return [...(await api.rpc.nft.variableMetadata(collectionId, tokenId))];971}972export async function getConstMetadata(973 api: ApiPromise,974 collectionId: number,975 tokenId: number,976): Promise<number[]> {977 return [...(await api.rpc.nft.constMetadata(collectionId, tokenId))];978}979980export async function createFungibleItemExpectSuccess(981 sender: IKeyringPair,982 collectionId: number,983 data: CreateFungibleData,984 owner: CrossAccountId | string = sender.address,985) {986 return await usingApi(async (api) => {987 const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(owner), {Fungible: data});988989 const events = await submitTransactionAsync(sender, tx);990 const result = getCreateItemResult(events);991992 expect(result.success).to.be.true;993 return result.itemId;994 });995}996997export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: CrossAccountId | string = sender.address) {998 let newItemId = 0;999 await usingApi(async (api) => {1000 const to = normalizeAccountId(owner);1001 const itemCountBefore = await getLastTokenId(api, collectionId);1002 const itemBalanceBefore = await getBalance(api, collectionId, to, newItemId);10031004 let tx;1005 if (createMode === 'Fungible') {1006 const createData = {fungible: {value: 10}};1007 tx = api.tx.nft.createItem(collectionId, to, createData as any);1008 } else if (createMode === 'ReFungible') {1009 const createData = {refungible: {const_data: [], variable_data: [], pieces: 100}};1010 tx = api.tx.nft.createItem(collectionId, to, createData as any);1011 } else {1012 const createData = {nft: {const_data: [], variable_data: []}};1013 tx = api.tx.nft.createItem(collectionId, to, createData as any);1014 }10151016 const events = await submitTransactionAsync(sender, tx);1017 const result = getCreateItemResult(events);10181019 const itemCountAfter = await getLastTokenId(api, collectionId);1020 const itemBalanceAfter = await getBalance(api, collectionId, to, newItemId);10211022 // What to expect1023 // tslint:disable-next-line:no-unused-expression1024 expect(result.success).to.be.true;1025 if (createMode === 'Fungible') {1026 expect(itemBalanceAfter - itemBalanceBefore).to.be.equal(10n);1027 } else {1028 expect(itemCountAfter).to.be.equal(itemCountBefore + 1);1029 }1030 expect(collectionId).to.be.equal(result.collectionId);1031 expect(itemCountAfter.toString()).to.be.equal(result.itemId.toString());1032 expect(to).to.be.deep.equal(result.recipient);1033 newItemId = result.itemId;1034 });1035 return newItemId;1036}10371038export async function createItemExpectFailure(sender: IKeyringPair, collectionId: number, createMode: string, owner: string = sender.address) {1039 await usingApi(async (api) => {1040 const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(owner), createMode);10411042 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1043 const result = getCreateItemResult(events);10441045 expect(result.success).to.be.false;1046 });1047}10481049export async function setPublicAccessModeExpectSuccess(1050 sender: IKeyringPair, collectionId: number,1051 accessMode: 'Normal' | 'WhiteList',1052) {1053 await usingApi(async (api) => {10541055 // Run the transaction1056 const tx = api.tx.nft.setPublicAccessMode(collectionId, accessMode);1057 const events = await submitTransactionAsync(sender, tx);1058 const result = getGenericResult(events);10591060 // Get the collection1061 const collection = (await api.query.common.collectionById(collectionId)).unwrap();10621063 // What to expect1064 // tslint:disable-next-line:no-unused-expression1065 expect(result.success).to.be.true;1066 expect(collection.access.toHuman()).to.be.equal(accessMode);1067 });1068}10691070export async function setPublicAccessModeExpectFail(1071 sender: IKeyringPair, collectionId: number,1072 accessMode: 'Normal' | 'WhiteList',1073) {1074 await usingApi(async (api) => {10751076 // Run the transaction1077 const tx = api.tx.nft.setPublicAccessMode(collectionId, accessMode);1078 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1079 const result = getGenericResult(events);10801081 // What to expect1082 // tslint:disable-next-line:no-unused-expression1083 expect(result.success).to.be.false;1084 });1085}10861087export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {1088 await setPublicAccessModeExpectSuccess(sender, collectionId, 'WhiteList');1089}10901091export async function enableWhiteListExpectFail(sender: IKeyringPair, collectionId: number) {1092 await setPublicAccessModeExpectFail(sender, collectionId, 'WhiteList');1093}10941095export async function disableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {1096 await setPublicAccessModeExpectSuccess(sender, collectionId, 'Normal');1097}10981099export async function setMintPermissionExpectSuccess(sender: IKeyringPair, collectionId: number, enabled: boolean) {1100 await usingApi(async (api) => {11011102 // Run the transaction1103 const tx = api.tx.nft.setMintPermission(collectionId, enabled);1104 const events = await submitTransactionAsync(sender, tx);1105 const result = getGenericResult(events);1106 expect(result.success).to.be.true;11071108 // Get the collection1109 const collection = (await api.query.common.collectionById(collectionId)).unwrap();11101111 expect(collection.mintMode.toHuman()).to.be.equal(enabled);1112 });1113}11141115export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {1116 await setMintPermissionExpectSuccess(sender, collectionId, true);1117}11181119export async function setMintPermissionExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {1120 await usingApi(async (api) => {1121 // Run the transaction1122 const tx = api.tx.nft.setMintPermission(collectionId, enabled);1123 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1124 const result = getCreateCollectionResult(events);1125 // tslint:disable-next-line:no-unused-expression1126 expect(result.success).to.be.false;1127 });1128}11291130export async function setChainLimitsExpectFailure(sender: IKeyringPair, limits: IChainLimits) {1131 await usingApi(async (api) => {1132 // Run the transaction1133 const tx = api.tx.nft.setChainLimits(limits);1134 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1135 const result = getCreateCollectionResult(events);1136 // tslint:disable-next-line:no-unused-expression1137 expect(result.success).to.be.false;1138 });1139}11401141export async function isWhitelisted(collectionId: number, address: string | CrossAccountId) {1142 return await usingApi(async (api) => {1143 return (await api.query.common.allowlist(collectionId, normalizeAccountId(address))).toJSON();1144 });1145}11461147export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId | CrossAccountId) {1148 await usingApi(async (api) => {1149 expect(await isWhitelisted(collectionId, normalizeAccountId(address))).to.be.false;11501151 // Run the transaction1152 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(address));1153 const events = await submitTransactionAsync(sender, tx);1154 const result = getGenericResult(events);1155 expect(result.success).to.be.true;11561157 expect(await isWhitelisted(collectionId, normalizeAccountId(address))).to.be.true;1158 });1159}11601161export async function addToWhiteListAgainExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId) {1162 await usingApi(async (api) => {11631164 expect(await isWhitelisted(collectionId, normalizeAccountId(address))).to.be.true;11651166 // Run the transaction1167 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(address));1168 const events = await submitTransactionAsync(sender, tx);1169 const result = getGenericResult(events);1170 expect(result.success).to.be.true;11711172 expect(await isWhitelisted(collectionId, normalizeAccountId(address))).to.be.true;1173 });1174}11751176export async function addToWhiteListExpectFail(sender: IKeyringPair, collectionId: number, address: string | AccountId) {1177 await usingApi(async (api) => {11781179 // Run the transaction1180 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(address));1181 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1182 const result = getGenericResult(events);11831184 // What to expect1185 // tslint:disable-next-line:no-unused-expression1186 expect(result.success).to.be.false;1187 });1188}11891190export async function removeFromWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: CrossAccountId) {1191 await usingApi(async (api) => {1192 // Run the transaction1193 const tx = api.tx.nft.removeFromWhiteList(collectionId, normalizeAccountId(address));1194 const events = await submitTransactionAsync(sender, tx);1195 const result = getGenericResult(events);11961197 // What to expect1198 // tslint:disable-next-line:no-unused-expression1199 expect(result.success).to.be.true;1200 });1201}12021203export async function removeFromWhiteListExpectFailure(sender: IKeyringPair, collectionId: number, address: CrossAccountId) {1204 await usingApi(async (api) => {1205 // Run the transaction1206 const tx = api.tx.nft.removeFromWhiteList(collectionId, normalizeAccountId(address));1207 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1208 const result = getGenericResult(events);12091210 // What to expect1211 // tslint:disable-next-line:no-unused-expression1212 expect(result.success).to.be.false;1213 });1214}12151216export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)1217 : Promise<NftDataStructsCollection | null> => {1218 return (await api.query.common.collectionById(collectionId)).unwrapOr(null);1219};12201221export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {1222 // set global object - collectionsCount1223 return (await api.query.common.createdCollectionCount()).toNumber();1224};12251226export async function queryCollectionExpectSuccess(api: ApiPromise, collectionId: number): Promise<NftDataStructsCollection> {1227 return (await api.query.common.collectionById(collectionId)).unwrap();1228}12291230export async function waitNewBlocks(blocksCount = 1): Promise<void> {1231 await usingApi(async (api) => {1232 const promise = new Promise<void>(async (resolve) => {1233 const unsubscribe = await api.rpc.chain.subscribeNewHeads(() => {1234 if (blocksCount > 0) {1235 blocksCount--;1236 } else {1237 unsubscribe();1238 resolve();1239 }1240 });1241 });1242 return promise;1243 });1244}1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import {ApiPromise, Keyring} from '@polkadot/api';7import type {AccountId, EventRecord} from '@polkadot/types/interfaces';8import {IKeyringPair} from '@polkadot/types/types';9import {evmToAddress} from '@polkadot/util-crypto';10import BN from 'bn.js';11import chai from 'chai';12import chaiAsPromised from 'chai-as-promised';13import {alicesPublicKey} from '../accounts';14import {NftDataStructsCollection} from '../interfaces';15import privateKey from '../substrate/privateKey';16import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';17import {hexToStr, strToUTF16, utf16ToStr} from './util';1819chai.use(chaiAsPromised);20const expect = chai.expect;2122export type CrossAccountId = {23 Substrate: string,24} | {25 Ethereum: string,26};27export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {28 if (typeof input === 'string') {29 if (input.length === 48 || input.length === 47) {30 return {Substrate: input};31 } else if (input.length === 42 && input.startsWith('0x')) {32 return {Ethereum: input.toLowerCase()};33 } else if (input.length === 40 && !input.startsWith('0x')) {34 return {Ethereum: '0x' + input.toLowerCase()};35 } else {36 throw new Error(`Unknown address format: "${input}"`);37 }38 }39 if ('address' in input) {40 return {Substrate: input.address};41 }42 if ('Ethereum' in input) {43 return {44 Ethereum: input.Ethereum.toLowerCase(),45 };46 } else if ('ethereum' in input) {47 return {48 Ethereum: (input as any).ethereum.toLowerCase(),49 };50 } else if ('Substrate' in input) {51 return input;52 }else if ('substrate' in input) {53 return {54 Substrate: (input as any).substrate,55 };56 }5758 // AccountId59 return {Substrate: input.toString()};60}61export function toSubstrateAddress(input: string | CrossAccountId | IKeyringPair): string {62 input = normalizeAccountId(input);63 if ('Substrate' in input) {64 return input.Substrate;65 } else {66 return evmToAddress(input.Ethereum);67 }68}6970export const U128_MAX = (1n << 128n) - 1n;7172const MICROUNIQUE = 1_000_000_000n;73const MILLIUNIQUE = 1_000n * MICROUNIQUE;74const CENTIUNIQUE = 10n * MILLIUNIQUE;75export const UNIQUE = 100n * CENTIUNIQUE;7677type GenericResult = {78 success: boolean,79};8081interface CreateCollectionResult {82 success: boolean;83 collectionId: number;84}8586interface CreateItemResult {87 success: boolean;88 collectionId: number;89 itemId: number;90 recipient?: CrossAccountId;91}9293interface TransferResult {94 success: boolean;95 collectionId: number;96 itemId: number;97 sender?: CrossAccountId;98 recipient?: CrossAccountId;99 value: bigint;100}101102interface IReFungibleOwner {103 fraction: BN;104 owner: number[];105}106107interface IGetMessage {108 checkMsgNftMethod: string;109 checkMsgTrsMethod: string;110 checkMsgSysMethod: string;111}112113export interface IFungibleTokenDataType {114 value: number;115}116117export interface IChainLimits {118 collectionNumbersLimit: number;119 accountTokenOwnershipLimit: number;120 collectionsAdminsLimit: number;121 customDataLimit: number;122 nftSponsorTransferTimeout: number;123 fungibleSponsorTransferTimeout: number;124 refungibleSponsorTransferTimeout: number;125 offchainSchemaLimit: number;126 variableOnChainSchemaLimit: number;127 constOnChainSchemaLimit: number;128}129130export interface IReFungibleTokenDataType {131 owner: IReFungibleOwner[];132 constData: number[];133 variableData: number[];134}135136export function nftEventMessage(events: EventRecord[]): IGetMessage {137 let checkMsgNftMethod = '';138 let checkMsgTrsMethod = '';139 let checkMsgSysMethod = '';140 events.forEach(({event: {method, section}}) => {141 if (section === 'common') {142 checkMsgNftMethod = method;143 } else if (section === 'treasury') {144 checkMsgTrsMethod = method;145 } else if (section === 'system') {146 checkMsgSysMethod = method;147 } else { return null; }148 });149 const result: IGetMessage = {150 checkMsgNftMethod,151 checkMsgTrsMethod,152 checkMsgSysMethod,153 };154 return result;155}156157export function getGenericResult(events: EventRecord[]): GenericResult {158 const result: GenericResult = {159 success: false,160 };161 events.forEach(({event: {method}}) => {162 // console.log(` ${phase}: ${section}.${method}:: ${data}`);163 if (method === 'ExtrinsicSuccess') {164 result.success = true;165 }166 });167 return result;168}169170171172export function getCreateCollectionResult(events: EventRecord[]): CreateCollectionResult {173 let success = false;174 let collectionId = 0;175 events.forEach(({event: {data, method, section}}) => {176 // console.log(` ${phase}: ${section}.${method}:: ${data}`);177 if (method == 'ExtrinsicSuccess') {178 success = true;179 } else if ((section == 'common') && (method == 'CollectionCreated')) {180 collectionId = parseInt(data[0].toString(), 10);181 }182 });183 const result: CreateCollectionResult = {184 success,185 collectionId,186 };187 return result;188}189190export function getCreateItemResult(events: EventRecord[]): CreateItemResult {191 let success = false;192 let collectionId = 0;193 let itemId = 0;194 let recipient;195 events.forEach(({event: {data, method, section}}) => {196 // console.log(` ${phase}: ${section}.${method}:: ${data}`);197 if (method == 'ExtrinsicSuccess') {198 success = true;199 } else if ((section == 'common') && (method == 'ItemCreated')) {200 collectionId = parseInt(data[0].toString(), 10);201 itemId = parseInt(data[1].toString(), 10);202 recipient = normalizeAccountId(data[2].toJSON() as any);203 }204 });205 const result: CreateItemResult = {206 success,207 collectionId,208 itemId,209 recipient,210 };211 return result;212}213214export function getTransferResult(events: EventRecord[]): TransferResult {215 const result: TransferResult = {216 success: false,217 collectionId: 0,218 itemId: 0,219 value: 0n,220 };221222 events.forEach(({event: {data, method, section}}) => {223 if (method === 'ExtrinsicSuccess') {224 result.success = true;225 } else if (section === 'common' && method === 'Transfer') {226 result.collectionId = +data[0].toString();227 result.itemId = +data[1].toString();228 result.sender = normalizeAccountId(data[2].toJSON() as any);229 result.recipient = normalizeAccountId(data[3].toJSON() as any);230 result.value = BigInt(data[4].toString());231 }232 });233234 return result;235}236237interface Nft {238 type: 'NFT';239}240241interface Fungible {242 type: 'Fungible';243 decimalPoints: number;244}245246interface ReFungible {247 type: 'ReFungible';248}249250type CollectionMode = Nft | Fungible | ReFungible;251252export type CreateCollectionParams = {253 mode: CollectionMode,254 name: string,255 description: string,256 tokenPrefix: string,257};258259const defaultCreateCollectionParams: CreateCollectionParams = {260 description: 'description',261 mode: {type: 'NFT'},262 name: 'name',263 tokenPrefix: 'prefix',264};265266export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {267 const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};268269 let collectionId = 0;270 await usingApi(async (api) => {271 // Get number of collections before the transaction272 const collectionCountBefore = (await api.query.common.createdCollectionCount()).toNumber();273274 // Run the CreateCollection transaction275 const alicePrivateKey = privateKey('//Alice');276277 let modeprm = {};278 if (mode.type === 'NFT') {279 modeprm = {nft: null};280 } else if (mode.type === 'Fungible') {281 modeprm = {fungible: mode.decimalPoints};282 } else if (mode.type === 'ReFungible') {283 modeprm = {refungible: null};284 }285286 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm as any);287 const events = await submitTransactionAsync(alicePrivateKey, tx);288 const result = getCreateCollectionResult(events);289290 // Get number of collections after the transaction291 const collectionCountAfter = (await api.query.common.createdCollectionCount()).toNumber();292293 // Get the collection294 const collection = (await api.query.common.collectionById(result.collectionId)).unwrap();295296 // What to expect297 // tslint:disable-next-line:no-unused-expression298 expect(result.success).to.be.true;299 expect(result.collectionId).to.be.equal(collectionCountAfter);300 // tslint:disable-next-line:no-unused-expression301 expect(collection).to.be.not.null;302 expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');303 expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicesPublicKey));304 expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);305 expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);306 expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);307308 collectionId = result.collectionId;309 });310311 return collectionId;312}313314export async function createCollectionExpectFailure(params: Partial<CreateCollectionParams> = {}) {315 const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};316317 let modeprm = {};318 if (mode.type === 'NFT') {319 modeprm = {nft: null};320 } else if (mode.type === 'Fungible') {321 modeprm = {fungible: mode.decimalPoints};322 } else if (mode.type === 'ReFungible') {323 modeprm = {refungible: null};324 }325326 await usingApi(async (api) => {327 // Get number of collections before the transaction328 const collectionCountBefore = (await api.query.common.createdCollectionCount()).toNumber();329330 // Run the CreateCollection transaction331 const alicePrivateKey = privateKey('//Alice');332 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm as any);333 const events = await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;334 const result = getCreateCollectionResult(events);335336 // Get number of collections after the transaction337 const collectionCountAfter = (await api.query.common.createdCollectionCount()).toNumber();338339 // What to expect340 // tslint:disable-next-line:no-unused-expression341 expect(result.success).to.be.false;342 expect(collectionCountAfter).to.be.equal(collectionCountBefore, 'Error: Collection with incorrect data created.');343 });344}345346export async function findUnusedAddress(api: ApiPromise, seedAddition = ''): Promise<IKeyringPair> {347 let bal = 0n;348 let unused;349 do {350 const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000)) + seedAddition;351 const keyring = new Keyring({type: 'sr25519'});352 unused = keyring.addFromUri(`//${randomSeed}`);353 bal = (await api.query.system.account(unused.address)).data.free.toBigInt();354 } while (bal !== 0n);355 return unused;356}357358export async function getAllowance(api: ApiPromise, collectionId: number, owner: CrossAccountId | string, approved: CrossAccountId | string, tokenId: number) {359 return (await api.rpc.nft.allowance(collectionId, normalizeAccountId(owner), normalizeAccountId(approved), tokenId)).toBigInt();360}361362export function findUnusedAddresses(api: ApiPromise, amount: number): Promise<IKeyringPair[]> {363 return Promise.all(new Array(amount).fill(null).map(() => findUnusedAddress(api, '_' + Date.now())));364}365366export async function findNotExistingCollection(api: ApiPromise): Promise<number> {367 const totalNumber = (await api.query.common.createdCollectionCount()).toNumber();368 const newCollection: number = totalNumber + 1;369 return newCollection;370}371372function getDestroyResult(events: EventRecord[]): boolean {373 let success = false;374 events.forEach(({event: {method}}) => {375 if (method == 'ExtrinsicSuccess') {376 success = true;377 }378 });379 return success;380}381382export async function destroyCollectionExpectFailure(collectionId: number, senderSeed = '//Alice') {383 await usingApi(async (api) => {384 // Run the DestroyCollection transaction385 const alicePrivateKey = privateKey(senderSeed);386 const tx = api.tx.nft.destroyCollection(collectionId);387 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;388 });389}390391export async function destroyCollectionExpectSuccess(collectionId: number, senderSeed = '//Alice') {392 await usingApi(async (api) => {393 // Run the DestroyCollection transaction394 const alicePrivateKey = privateKey(senderSeed);395 const tx = api.tx.nft.destroyCollection(collectionId);396 const events = await submitTransactionAsync(alicePrivateKey, tx);397 const result = getDestroyResult(events);398 expect(result).to.be.true;399400 // What to expect401 expect((await api.query.common.collectionById(collectionId)).isNone).to.be.true;402 });403}404405export async function setCollectionLimitsExpectSuccess(sender: IKeyringPair, collectionId: number, limits: any) {406 await usingApi(async (api) => {407 const tx = api.tx.nft.setCollectionLimits(collectionId, limits);408 const events = await submitTransactionAsync(sender, tx);409 const result = getGenericResult(events);410411 expect(result.success).to.be.true;412 });413}414415export async function setCollectionLimitsExpectFailure(sender: IKeyringPair, collectionId: number, limits: any) {416 await usingApi(async (api) => {417 const tx = api.tx.nft.setCollectionLimits(collectionId, limits);418 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;419 const result = getGenericResult(events);420421 expect(result.success).to.be.false;422 });423}424425export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string, sender = '//Alice') {426 await usingApi(async (api) => {427428 // Run the transaction429 const senderPrivateKey = privateKey(sender);430 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);431 const events = await submitTransactionAsync(senderPrivateKey, tx);432 const result = getGenericResult(events);433434 // Get the collection435 const collection = (await api.query.common.collectionById(collectionId)).unwrap();436437 // What to expect438 expect(result.success).to.be.true;439 expect(collection.sponsorship.toJSON()).to.deep.equal({440 unconfirmed: sponsor,441 });442 });443}444445export async function removeCollectionSponsorExpectSuccess(collectionId: number, sender = '//Alice') {446 await usingApi(async (api) => {447448 // Run the transaction449 const alicePrivateKey = privateKey(sender);450 const tx = api.tx.nft.removeCollectionSponsor(collectionId);451 const events = await submitTransactionAsync(alicePrivateKey, tx);452 const result = getGenericResult(events);453454 // Get the collection455 const collection = (await api.query.common.collectionById(collectionId)).unwrap();456457 // What to expect458 expect(result.success).to.be.true;459 expect(collection.sponsorship.toJSON()).to.be.deep.equal({disabled: null});460 });461}462463export async function removeCollectionSponsorExpectFailure(collectionId: number, senderSeed = '//Alice') {464 await usingApi(async (api) => {465466 // Run the transaction467 const alicePrivateKey = privateKey(senderSeed);468 const tx = api.tx.nft.removeCollectionSponsor(collectionId);469 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;470 });471}472473export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string, senderSeed = '//Alice') {474 await usingApi(async (api) => {475476 // Run the transaction477 const alicePrivateKey = privateKey(senderSeed);478 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);479 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;480 });481}482483export async function confirmSponsorshipExpectSuccess(collectionId: number, senderSeed = '//Alice') {484 await usingApi(async (api) => {485486 // Run the transaction487 const sender = privateKey(senderSeed);488 const tx = api.tx.nft.confirmSponsorship(collectionId);489 const events = await submitTransactionAsync(sender, tx);490 const result = getGenericResult(events);491492 // Get the collection493 const collection = (await api.query.common.collectionById(collectionId)).unwrap();494495 // What to expect496 expect(result.success).to.be.true;497 expect(collection.sponsorship.toJSON()).to.be.deep.equal({498 confirmed: sender.address,499 });500 });501}502503504export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed = '//Alice') {505 await usingApi(async (api) => {506507 // Run the transaction508 const sender = privateKey(senderSeed);509 const tx = api.tx.nft.confirmSponsorship(collectionId);510 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;511 });512}513514export async function setMetadataUpdatePermissionFlagExpectSuccess(sender: IKeyringPair, collectionId: number, flag: string) {515516 await usingApi(async (api) => {517 const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag as any);518 const events = await submitTransactionAsync(sender, tx);519 const result = getGenericResult(events);520521 expect(result.success).to.be.true;522 });523}524525export async function setMetadataUpdatePermissionFlagExpectFailure(sender: IKeyringPair, collectionId: number, flag: string) {526527 await usingApi(async (api) => {528 const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag as any);529 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;530 const result = getGenericResult(events);531532 expect(result.success).to.be.false;533 });534}535536export async function enableContractSponsoringExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, enable: boolean) {537 await usingApi(async (api) => {538 const tx = api.tx.nft.enableContractSponsoring(contractAddress, enable);539 const events = await submitTransactionAsync(sender, tx);540 const result = getGenericResult(events);541542 expect(result.success).to.be.true;543 });544}545546export async function enableContractSponsoringExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, enable: boolean) {547 await usingApi(async (api) => {548 const tx = api.tx.nft.enableContractSponsoring(contractAddress, enable);549 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;550 const result = getGenericResult(events);551552 expect(result.success).to.be.false;553 });554}555556export async function setTransferFlagExpectSuccess(sender: IKeyringPair, collectionId: number, enabled: boolean) {557558 await usingApi(async (api) => {559560 const tx = api.tx.nft.setTransfersEnabledFlag (collectionId, enabled);561 const events = await submitTransactionAsync(sender, tx);562 const result = getGenericResult(events);563564 expect(result.success).to.be.true;565 });566}567568export async function setTransferFlagExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {569570 await usingApi(async (api) => {571572 const tx = api.tx.nft.setTransfersEnabledFlag (collectionId, enabled);573 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;574 const result = getGenericResult(events);575576 expect(result.success).to.be.false;577 });578}579580export async function setContractSponsoringRateLimitExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) {581 await usingApi(async (api) => {582 const tx = api.tx.nft.setContractSponsoringRateLimit(contractAddress, rateLimit);583 const events = await submitTransactionAsync(sender, tx);584 const result = getGenericResult(events);585586 expect(result.success).to.be.true;587 });588}589590export async function setContractSponsoringRateLimitExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) {591 await usingApi(async (api) => {592 const tx = api.tx.nft.setContractSponsoringRateLimit(contractAddress, rateLimit);593 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;594 const result = getGenericResult(events);595596 expect(result.success).to.be.false;597 });598}599600export async function toggleContractAllowlistExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, value = true) {601 await usingApi(async (api) => {602 const tx = api.tx.nft.toggleContractAllowList(contractAddress, value);603 const events = await submitTransactionAsync(sender, tx);604 const result = getGenericResult(events);605606 expect(result.success).to.be.true;607 });608}609610export async function isAllowlistedInContract(contractAddress: AccountId | string, user: string) {611 let allowlisted = false;612 await usingApi(async (api) => {613 allowlisted = (await api.query.nft.contractAllowList(contractAddress, user)).toJSON() as boolean;614 });615 return allowlisted;616}617618export async function addToContractAllowListExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, user: AccountId | string) {619 await usingApi(async (api) => {620 const tx = api.tx.nft.addToContractAllowList(contractAddress.toString(), user.toString());621 const events = await submitTransactionAsync(sender, tx);622 const result = getGenericResult(events);623624 expect(result.success).to.be.true;625 });626}627628export async function removeFromContractAllowListExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, user: AccountId | string) {629 await usingApi(async (api) => {630 const tx = api.tx.nft.removeFromContractAllowList(contractAddress.toString(), user.toString());631 const events = await submitTransactionAsync(sender, tx);632 const result = getGenericResult(events);633634 expect(result.success).to.be.true;635 });636}637638export async function removeFromContractAllowListExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, user: AccountId | string) {639 await usingApi(async (api) => {640 const tx = api.tx.nft.removeFromContractAllowList(contractAddress.toString(), user.toString());641 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;642 const result = getGenericResult(events);643644 expect(result.success).to.be.false;645 });646}647648export async function setVariableMetaDataExpectSuccess(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) {649 await usingApi(async (api) => {650 const tx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(data).toString('hex'));651 const events = await submitTransactionAsync(sender, tx);652 const result = getGenericResult(events);653654 expect(result.success).to.be.true;655 });656}657658export async function setVariableMetaDataExpectFailure(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) {659 await usingApi(async (api) => {660 const tx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(data).toString('hex'));661 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;662 });663}664665export async function setOffchainSchemaExpectSuccess(sender: IKeyringPair, collectionId: number, data: number[]) {666 await usingApi(async (api) => {667 const tx = api.tx.nft.setOffchainSchema(collectionId, '0x' + Buffer.from(data).toString('hex'));668 const events = await submitTransactionAsync(sender, tx);669 const result = getGenericResult(events);670671 expect(result.success).to.be.true;672 });673}674675export async function setOffchainSchemaExpectFailure(sender: IKeyringPair, collectionId: number, data: number[]) {676 await usingApi(async (api) => {677 const tx = api.tx.nft.setOffchainSchema(collectionId, '0x' + Buffer.from(data).toString('hex'));678 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;679 });680}681682export interface CreateFungibleData {683 readonly Value: bigint;684}685686export interface CreateReFungibleData { }687export interface CreateNftData { }688689export type CreateItemData = {690 NFT: CreateNftData;691} | {692 Fungible: CreateFungibleData;693} | {694 ReFungible: CreateReFungibleData;695};696697export async function burnItemExpectSuccess(sender: IKeyringPair, collectionId: number, tokenId: number, value = 1) {698 await usingApi(async (api) => {699 const balanceBefore = await getBalance(api, collectionId, normalizeAccountId(sender), tokenId);700 // if burning token by admin - use adminButnItemExpectSuccess701 expect(balanceBefore >= BigInt(value)).to.be.true;702703 const tx = api.tx.nft.burnItem(collectionId, tokenId, value);704 const events = await submitTransactionAsync(sender, tx);705 const result = getGenericResult(events);706 expect(result.success).to.be.true;707708 const balanceAfter = await getBalance(api, collectionId, normalizeAccountId(sender), tokenId);709 expect(balanceAfter + BigInt(value)).to.be.equal(balanceBefore);710 });711}712713export async function714approveExpectSuccess(715 collectionId: number,716 tokenId: number, owner: IKeyringPair, approved: CrossAccountId | string, amount: number | bigint = 1,717) {718 await usingApi(async (api: ApiPromise) => {719 const approveNftTx = api.tx.nft.approve(normalizeAccountId(approved), collectionId, tokenId, amount);720 const events = await submitTransactionAsync(owner, approveNftTx);721 const result = getGenericResult(events);722 expect(result.success).to.be.true;723724 expect(await getAllowance(api, collectionId, owner.address, approved, tokenId)).to.be.equal(BigInt(amount));725 });726}727728export async function adminApproveFromExpectSuccess(729 collectionId: number,730 tokenId: number, admin: IKeyringPair, owner: CrossAccountId | string, approved: CrossAccountId | string, amount: number | bigint = 1,731) {732 await usingApi(async (api: ApiPromise) => {733 const approveNftTx = api.tx.nft.approve(normalizeAccountId(approved), collectionId, tokenId, amount);734 const events = await submitTransactionAsync(admin, approveNftTx);735 const result = getGenericResult(events);736 expect(result.success).to.be.true;737738 expect(await getAllowance(api, collectionId, owner, approved, tokenId)).to.be.equal(BigInt(amount));739 });740}741742export async function743transferFromExpectSuccess(744 collectionId: number,745 tokenId: number,746 accountApproved: IKeyringPair,747 accountFrom: IKeyringPair | CrossAccountId,748 accountTo: IKeyringPair | CrossAccountId,749 value: number | bigint = 1,750 type = 'NFT',751) {752 await usingApi(async (api: ApiPromise) => {753 const to = normalizeAccountId(accountTo);754 let balanceBefore = 0n;755 if (type === 'Fungible') {756 balanceBefore = await getBalance(api, collectionId, to, tokenId);757 }758 const transferFromTx = api.tx.nft.transferFrom(normalizeAccountId(accountFrom), to, collectionId, tokenId, value);759 const events = await submitTransactionAsync(accountApproved, transferFromTx);760 const result = getCreateItemResult(events);761 // tslint:disable-next-line:no-unused-expression762 expect(result.success).to.be.true;763 if (type === 'NFT') {764 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(to);765 }766 if (type === 'Fungible') {767 const balanceAfter = await getBalance(api, collectionId, to, tokenId);768 expect(balanceAfter - balanceBefore).to.be.equal(BigInt(value));769 }770 if (type === 'ReFungible') {771 expect(await getBalance(api, collectionId, to, tokenId)).to.be.equal(BigInt(value));772 }773 });774}775776export async function777transferFromExpectFail(778 collectionId: number,779 tokenId: number,780 accountApproved: IKeyringPair,781 accountFrom: IKeyringPair,782 accountTo: IKeyringPair,783 value: number | bigint = 1,784) {785 await usingApi(async (api: ApiPromise) => {786 const transferFromTx = api.tx.nft.transferFrom(normalizeAccountId(accountFrom.address), normalizeAccountId(accountTo.address), collectionId, tokenId, value);787 const events = await expect(submitTransactionExpectFailAsync(accountApproved, transferFromTx)).to.be.rejected;788 const result = getCreateCollectionResult(events);789 // tslint:disable-next-line:no-unused-expression790 expect(result.success).to.be.false;791 });792}793794/* eslint no-async-promise-executor: "off" */795async function getBlockNumber(api: ApiPromise): Promise<number> {796 return new Promise<number>(async (resolve) => {797 const unsubscribe = await api.rpc.chain.subscribeNewHeads((head) => {798 unsubscribe();799 resolve(head.number.toNumber());800 });801 });802}803804export async function addCollectionAdminExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | CrossAccountId) {805 await usingApi(async (api) => {806 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(address));807 const events = await submitTransactionAsync(sender, changeAdminTx);808 const result = getCreateCollectionResult(events);809 expect(result.success).to.be.true;810 });811}812813export async function814getFreeBalance(account: IKeyringPair) : Promise<bigint>815{816 let balance = 0n;817 await usingApi(async (api) => {818 balance = BigInt((await api.query.system.account(account.address)).data.free.toString());819 });820821 return balance;822}823824export async function825scheduleTransferExpectSuccess(826 collectionId: number,827 tokenId: number,828 sender: IKeyringPair,829 recipient: IKeyringPair,830 value: number | bigint = 1,831 blockSchedule: number,832) {833 await usingApi(async (api: ApiPromise) => {834 const blockNumber: number | undefined = await getBlockNumber(api);835 const expectedBlockNumber = blockNumber + blockSchedule;836837 expect(blockNumber).to.be.greaterThan(0);838 const transferTx = api.tx.nft.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);839 const scheduleTx = api.tx.scheduler.schedule(expectedBlockNumber, null, 0, transferTx as any);840841 await submitTransactionAsync(sender, scheduleTx);842843 const recipientBalanceBefore = (await api.query.system.account(recipient.address)).data.free.toBigInt();844845 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(normalizeAccountId(sender.address));846847 // sleep for 4 blocks848 await waitNewBlocks(blockSchedule + 1);849850 const recipientBalanceAfter = (await api.query.system.account(recipient.address)).data.free.toBigInt();851852 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(normalizeAccountId(recipient.address));853 expect(recipientBalanceAfter).to.be.equal(recipientBalanceBefore);854 });855}856857858export async function859transferExpectSuccess(860 collectionId: number,861 tokenId: number,862 sender: IKeyringPair,863 recipient: IKeyringPair | CrossAccountId,864 value: number | bigint = 1,865 type = 'NFT',866) {867 await usingApi(async (api: ApiPromise) => {868 const to = normalizeAccountId(recipient);869870 let balanceBefore = 0n;871 if (type === 'Fungible') {872 balanceBefore = await getBalance(api, collectionId, to, tokenId);873 }874 const transferTx = api.tx.nft.transfer(to, collectionId, tokenId, value);875 const events = await submitTransactionAsync(sender, transferTx);876 const result = getTransferResult(events);877 // tslint:disable-next-line:no-unused-expression878 expect(result.success).to.be.true;879 expect(result.collectionId).to.be.equal(collectionId);880 expect(result.itemId).to.be.equal(tokenId);881 expect(result.sender).to.be.deep.equal(normalizeAccountId(sender.address));882 expect(result.recipient).to.be.deep.equal(to);883 expect(result.value).to.be.equal(BigInt(value));884 if (type === 'NFT') {885 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(to);886 }887 if (type === 'Fungible') {888 const balanceAfter = await getBalance(api, collectionId, to, tokenId);889 expect(balanceAfter - balanceBefore).to.be.equal(BigInt(value));890 }891 if (type === 'ReFungible') {892 expect(await getBalance(api, collectionId, to, tokenId) >= value).to.be.true;893 }894 });895}896897export async function898transferExpectFailure(899 collectionId: number,900 tokenId: number,901 sender: IKeyringPair,902 recipient: IKeyringPair,903 value: number | bigint = 1,904) {905 await usingApi(async (api: ApiPromise) => {906 const transferTx = api.tx.nft.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);907 const events = await expect(submitTransactionExpectFailAsync(sender, transferTx)).to.be.rejected;908 const result = getGenericResult(events);909 // if (events && Array.isArray(events)) {910 // const result = getCreateCollectionResult(events);911 // tslint:disable-next-line:no-unused-expression912 expect(result.success).to.be.false;913 //}914 });915}916917export async function918approveExpectFail(919 collectionId: number,920 tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number | bigint = 1,921) {922 await usingApi(async (api: ApiPromise) => {923 const approveNftTx = api.tx.nft.approve(normalizeAccountId(approved.address), collectionId, tokenId, amount);924 const events = await expect(submitTransactionExpectFailAsync(owner, approveNftTx)).to.be.rejected;925 const result = getCreateCollectionResult(events);926 // tslint:disable-next-line:no-unused-expression927 expect(result.success).to.be.false;928 });929}930931export async function getBalance(932 api: ApiPromise,933 collectionId: number,934 owner: string | CrossAccountId,935 token: number,936): Promise<bigint> {937 return (await api.rpc.nft.balance(collectionId, normalizeAccountId(owner), token)).toBigInt();938}939export async function getTokenOwner(940 api: ApiPromise,941 collectionId: number,942 token: number,943): Promise<CrossAccountId> {944 return normalizeAccountId((await api.rpc.nft.tokenOwner(collectionId, token)).toJSON() as any);945}946export async function isTokenExists(947 api: ApiPromise,948 collectionId: number,949 token: number,950): Promise<boolean> {951 return (await api.rpc.nft.tokenExists(collectionId, token)).toJSON();952}953export async function getLastTokenId(954 api: ApiPromise,955 collectionId: number,956): Promise<number> {957 return (await api.rpc.nft.lastTokenId(collectionId)).toJSON();958}959export async function getAdminList(960 api: ApiPromise,961 collectionId: number,962): Promise<string[]> {963 return (await api.rpc.nft.adminlist(collectionId)).toHuman() as any;964}965export async function getVariableMetadata(966 api: ApiPromise,967 collectionId: number,968 tokenId: number,969): Promise<number[]> {970 return [...(await api.rpc.nft.variableMetadata(collectionId, tokenId))];971}972export async function getConstMetadata(973 api: ApiPromise,974 collectionId: number,975 tokenId: number,976): Promise<number[]> {977 return [...(await api.rpc.nft.constMetadata(collectionId, tokenId))];978}979980export async function createFungibleItemExpectSuccess(981 sender: IKeyringPair,982 collectionId: number,983 data: CreateFungibleData,984 owner: CrossAccountId | string = sender.address,985) {986 return await usingApi(async (api) => {987 const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(owner), {Fungible: data});988989 const events = await submitTransactionAsync(sender, tx);990 const result = getCreateItemResult(events);991992 expect(result.success).to.be.true;993 return result.itemId;994 });995}996997export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: CrossAccountId | string = sender.address) {998 let newItemId = 0;999 await usingApi(async (api) => {1000 const to = normalizeAccountId(owner);1001 const itemCountBefore = await getLastTokenId(api, collectionId);1002 const itemBalanceBefore = await getBalance(api, collectionId, to, newItemId);10031004 let tx;1005 if (createMode === 'Fungible') {1006 const createData = {fungible: {value: 10}};1007 tx = api.tx.nft.createItem(collectionId, to, createData as any);1008 } else if (createMode === 'ReFungible') {1009 const createData = {refungible: {const_data: [], variable_data: [], pieces: 100}};1010 tx = api.tx.nft.createItem(collectionId, to, createData as any);1011 } else {1012 const createData = {nft: {const_data: [], variable_data: []}};1013 tx = api.tx.nft.createItem(collectionId, to, createData as any);1014 }10151016 const events = await submitTransactionAsync(sender, tx);1017 const result = getCreateItemResult(events);10181019 const itemCountAfter = await getLastTokenId(api, collectionId);1020 const itemBalanceAfter = await getBalance(api, collectionId, to, newItemId);10211022 // What to expect1023 // tslint:disable-next-line:no-unused-expression1024 expect(result.success).to.be.true;1025 if (createMode === 'Fungible') {1026 expect(itemBalanceAfter - itemBalanceBefore).to.be.equal(10n);1027 } else {1028 expect(itemCountAfter).to.be.equal(itemCountBefore + 1);1029 }1030 expect(collectionId).to.be.equal(result.collectionId);1031 expect(itemCountAfter.toString()).to.be.equal(result.itemId.toString());1032 expect(to).to.be.deep.equal(result.recipient);1033 newItemId = result.itemId;1034 });1035 return newItemId;1036}10371038export async function createItemExpectFailure(sender: IKeyringPair, collectionId: number, createMode: string, owner: string = sender.address) {1039 await usingApi(async (api) => {1040 const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(owner), createMode);10411042 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1043 const result = getCreateItemResult(events);10441045 expect(result.success).to.be.false;1046 });1047}10481049export async function setPublicAccessModeExpectSuccess(1050 sender: IKeyringPair, collectionId: number,1051 accessMode: 'Normal' | 'AllowList',1052) {1053 await usingApi(async (api) => {10541055 // Run the transaction1056 const tx = api.tx.nft.setPublicAccessMode(collectionId, accessMode);1057 const events = await submitTransactionAsync(sender, tx);1058 const result = getGenericResult(events);10591060 // Get the collection1061 const collection = (await api.query.common.collectionById(collectionId)).unwrap();10621063 // What to expect1064 // tslint:disable-next-line:no-unused-expression1065 expect(result.success).to.be.true;1066 expect(collection.access.toHuman()).to.be.equal(accessMode);1067 });1068}10691070export async function setPublicAccessModeExpectFail(1071 sender: IKeyringPair, collectionId: number,1072 accessMode: 'Normal' | 'AllowList',1073) {1074 await usingApi(async (api) => {10751076 // Run the transaction1077 const tx = api.tx.nft.setPublicAccessMode(collectionId, accessMode);1078 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1079 const result = getGenericResult(events);10801081 // What to expect1082 // tslint:disable-next-line:no-unused-expression1083 expect(result.success).to.be.false;1084 });1085}10861087export async function enableAllowListExpectSuccess(sender: IKeyringPair, collectionId: number) {1088 await setPublicAccessModeExpectSuccess(sender, collectionId, 'AllowList');1089}10901091export async function enableAllowListExpectFail(sender: IKeyringPair, collectionId: number) {1092 await setPublicAccessModeExpectFail(sender, collectionId, 'AllowList');1093}10941095export async function disableAllowListExpectSuccess(sender: IKeyringPair, collectionId: number) {1096 await setPublicAccessModeExpectSuccess(sender, collectionId, 'Normal');1097}10981099export async function setMintPermissionExpectSuccess(sender: IKeyringPair, collectionId: number, enabled: boolean) {1100 await usingApi(async (api) => {11011102 // Run the transaction1103 const tx = api.tx.nft.setMintPermission(collectionId, enabled);1104 const events = await submitTransactionAsync(sender, tx);1105 const result = getGenericResult(events);1106 expect(result.success).to.be.true;11071108 // Get the collection1109 const collection = (await api.query.common.collectionById(collectionId)).unwrap();11101111 expect(collection.mintMode.toHuman()).to.be.equal(enabled);1112 });1113}11141115export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {1116 await setMintPermissionExpectSuccess(sender, collectionId, true);1117}11181119export async function setMintPermissionExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {1120 await usingApi(async (api) => {1121 // Run the transaction1122 const tx = api.tx.nft.setMintPermission(collectionId, enabled);1123 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1124 const result = getCreateCollectionResult(events);1125 // tslint:disable-next-line:no-unused-expression1126 expect(result.success).to.be.false;1127 });1128}11291130export async function setChainLimitsExpectFailure(sender: IKeyringPair, limits: IChainLimits) {1131 await usingApi(async (api) => {1132 // Run the transaction1133 const tx = api.tx.nft.setChainLimits(limits);1134 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1135 const result = getCreateCollectionResult(events);1136 // tslint:disable-next-line:no-unused-expression1137 expect(result.success).to.be.false;1138 });1139}11401141export async function isAllowlisted(collectionId: number, address: string | CrossAccountId) {1142 return await usingApi(async (api) => {1143 return (await api.query.common.allowlist(collectionId, normalizeAccountId(address))).toJSON();1144 });1145}11461147export async function addToAllowListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId | CrossAccountId) {1148 await usingApi(async (api) => {1149 expect(await isAllowlisted(collectionId, normalizeAccountId(address))).to.be.false;11501151 // Run the transaction1152 const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(address));1153 const events = await submitTransactionAsync(sender, tx);1154 const result = getGenericResult(events);1155 expect(result.success).to.be.true;11561157 expect(await isAllowlisted(collectionId, normalizeAccountId(address))).to.be.true;1158 });1159}11601161export async function addToAllowListAgainExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId) {1162 await usingApi(async (api) => {11631164 expect(await isAllowlisted(collectionId, normalizeAccountId(address))).to.be.true;11651166 // Run the transaction1167 const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(address));1168 const events = await submitTransactionAsync(sender, tx);1169 const result = getGenericResult(events);1170 expect(result.success).to.be.true;11711172 expect(await isAllowlisted(collectionId, normalizeAccountId(address))).to.be.true;1173 });1174}11751176export async function addToAllowListExpectFail(sender: IKeyringPair, collectionId: number, address: string | AccountId) {1177 await usingApi(async (api) => {11781179 // Run the transaction1180 const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(address));1181 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1182 const result = getGenericResult(events);11831184 // What to expect1185 // tslint:disable-next-line:no-unused-expression1186 expect(result.success).to.be.false;1187 });1188}11891190export async function removeFromAllowListExpectSuccess(sender: IKeyringPair, collectionId: number, address: CrossAccountId) {1191 await usingApi(async (api) => {1192 // Run the transaction1193 const tx = api.tx.nft.removeFromAllowList(collectionId, normalizeAccountId(address));1194 const events = await submitTransactionAsync(sender, tx);1195 const result = getGenericResult(events);11961197 // What to expect1198 // tslint:disable-next-line:no-unused-expression1199 expect(result.success).to.be.true;1200 });1201}12021203export async function removeFromAllowListExpectFailure(sender: IKeyringPair, collectionId: number, address: CrossAccountId) {1204 await usingApi(async (api) => {1205 // Run the transaction1206 const tx = api.tx.nft.removeFromAllowList(collectionId, normalizeAccountId(address));1207 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1208 const result = getGenericResult(events);12091210 // What to expect1211 // tslint:disable-next-line:no-unused-expression1212 expect(result.success).to.be.false;1213 });1214}12151216export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)1217 : Promise<NftDataStructsCollection | null> => {1218 return (await api.query.common.collectionById(collectionId)).unwrapOr(null);1219};12201221export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {1222 // set global object - collectionsCount1223 return (await api.query.common.createdCollectionCount()).toNumber();1224};12251226export async function queryCollectionExpectSuccess(api: ApiPromise, collectionId: number): Promise<NftDataStructsCollection> {1227 return (await api.query.common.collectionById(collectionId)).unwrap();1228}12291230export async function waitNewBlocks(blocksCount = 1): Promise<void> {1231 await usingApi(async (api) => {1232 const promise = new Promise<void>(async (resolve) => {1233 const unsubscribe = await api.rpc.chain.subscribeNewHeads(() => {1234 if (blocksCount > 0) {1235 blocksCount--;1236 } else {1237 unsubscribe();1238 resolve();1239 }1240 });1241 });1242 return promise;1243 });1244}tests/src/whiteLists.test.tsdiffbeforeafterboth--- a/tests/src/whiteLists.test.ts
+++ /dev/null
@@ -1,304 +0,0 @@
-//
-// This file is subject to the terms and conditions defined in
-// file 'LICENSE', which is part of this source code package.
-//
-
-import {IKeyringPair} from '@polkadot/types/types';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
-import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';
-import {
- addToWhiteListExpectSuccess,
- createCollectionExpectSuccess,
- createItemExpectSuccess,
- destroyCollectionExpectSuccess,
- enableWhiteListExpectSuccess,
- normalizeAccountId,
- addCollectionAdminExpectSuccess,
- addToWhiteListExpectFail,
- removeFromWhiteListExpectSuccess,
- removeFromWhiteListExpectFailure,
- addToWhiteListAgainExpectSuccess,
- transferExpectFailure,
- approveExpectSuccess,
- approveExpectFail,
- transferExpectSuccess,
- transferFromExpectSuccess,
- setMintPermissionExpectSuccess,
- createItemExpectFailure,
-} from './util/helpers';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-
-let alice: IKeyringPair;
-let bob: IKeyringPair;
-let charlie: IKeyringPair;
-
-describe('Integration Test ext. White list tests', () => {
-
- before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
- });
- });
-
- it('Owner can add address to white list', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
- });
-
- it('Admin can add address to white list', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- await addToWhiteListExpectSuccess(bob, collectionId, charlie.address);
- });
-
- it('Non-privileged user cannot add address to white list', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectFail(bob, collectionId, charlie.address);
- });
-
- it('Nobody can add address to white list of non-existing collection', async () => {
- const collectionId = (1<<32) - 1;
- await addToWhiteListExpectFail(alice, collectionId, bob.address);
- });
-
- it('Nobody can add address to white list of destroyed collection', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await destroyCollectionExpectSuccess(collectionId, '//Alice');
- await addToWhiteListExpectFail(alice, collectionId, bob.address);
- });
-
- it('If address is already added to white list, nothing happens', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
- await addToWhiteListAgainExpectSuccess(alice, collectionId, bob.address);
- });
-
- it('Owner can remove address from white list', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
- await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(bob));
- });
-
- it('Admin can remove address from white list', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
- await removeFromWhiteListExpectSuccess(bob, collectionId, normalizeAccountId(charlie));
- });
-
- it('Non-privileged user cannot remove address from white list', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
- await removeFromWhiteListExpectFailure(bob, collectionId, normalizeAccountId(charlie));
- });
-
- it('Nobody can remove address from white list of non-existing collection', async () => {
- const collectionId = (1<<32) - 1;
- await removeFromWhiteListExpectFailure(alice, collectionId, normalizeAccountId(charlie));
- });
-
- it('Nobody can remove address from white list of deleted collection', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
- await destroyCollectionExpectSuccess(collectionId, '//Alice');
- await removeFromWhiteListExpectFailure(alice, collectionId, normalizeAccountId(charlie));
- });
-
- it('If address is already removed from white list, nothing happens', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
- await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));
- await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));
- });
-
- it('If Public Access mode is set to WhiteList, tokens can’t be transferred from a non-whitelisted address with transfer or transferFrom. Test1', async () => {
- const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
- await enableWhiteListExpectSuccess(alice, collectionId);
- await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
-
- await transferExpectFailure(
- collectionId,
- itemId,
- alice,
- charlie,
- 1,
- );
- });
-
- it('If Public Access mode is set to WhiteList, tokens can’t be transferred from a non-whitelisted address with transfer or transferFrom. Test2', async () => {
- const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
- await enableWhiteListExpectSuccess(alice, collectionId);
- await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
- await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
- await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
- await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(alice));
-
- await transferExpectFailure(
- collectionId,
- itemId,
- alice,
- charlie,
- 1,
- );
- });
-
- it('If Public Access mode is set to WhiteList, tokens can’t be transferred to a non-whitelisted address with transfer or transferFrom. Test1', async () => {
- const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
- await enableWhiteListExpectSuccess(alice, collectionId);
- await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
-
- await transferExpectFailure(
- collectionId,
- itemId,
- alice,
- charlie,
- 1,
- );
- });
-
- it('If Public Access mode is set to WhiteList, tokens can’t be transferred to a non-whitelisted address with transfer or transferFrom. Test2', async () => {
- const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
- await enableWhiteListExpectSuccess(alice, collectionId);
- await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
- await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
- await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
- await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(alice));
-
- await transferExpectFailure(
- collectionId,
- itemId,
- alice,
- charlie,
- 1,
- );
- });
-
- it('If Public Access mode is set to WhiteList, tokens can’t be destroyed by a non-whitelisted address (even if it owned them before enabling WhiteList mode)', async () => {
- const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
- await enableWhiteListExpectSuccess(alice, collectionId);
-
- await usingApi(async (api) => {
- const tx = api.tx.nft.burnItem(collectionId, itemId, /*normalizeAccountId(Alice.address),*/ 11);
- const badTransaction = async function () {
- await submitTransactionExpectFailAsync(alice, tx);
- };
- await expect(badTransaction()).to.be.rejected;
- });
- });
-
- it('If Public Access mode is set to WhiteList, token transfers can’t be Approved by a non-whitelisted address (see Approve method)', async () => {
- const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
- await enableWhiteListExpectSuccess(alice, collectionId);
- await approveExpectFail(collectionId, itemId, alice, bob);
- });
-
- it('If Public Access mode is set to WhiteList, tokens can be transferred to a whitelisted address with transfer.', async () => {
- const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
- await enableWhiteListExpectSuccess(alice, collectionId);
- await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
- await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
- await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');
- });
-
- it('If Public Access mode is set to WhiteList, tokens can be transferred to a whitelisted address with transferFrom.', async () => {
- const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
- await enableWhiteListExpectSuccess(alice, collectionId);
- await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
- await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
- await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
- await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');
- });
-
- it('If Public Access mode is set to WhiteList, tokens can be transferred from a whitelisted address with transfer', async () => {
- const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
- await enableWhiteListExpectSuccess(alice, collectionId);
- await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
- await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
- await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');
- });
-
- it('If Public Access mode is set to WhiteList, tokens can be transferred from a whitelisted address with transferFrom', async () => {
- const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
- await enableWhiteListExpectSuccess(alice, collectionId);
- await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
- await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
- await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
- await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');
- });
-
- it('If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by owner', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(alice, collectionId);
- await setMintPermissionExpectSuccess(alice, collectionId, false);
- await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
- });
-
- it('If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by admin', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(alice, collectionId);
- await setMintPermissionExpectSuccess(alice, collectionId, false);
- await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
- });
-
- it('If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens cannot be created by non-privileged and white-listed address', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(alice, collectionId);
- await setMintPermissionExpectSuccess(alice, collectionId, false);
- await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
- await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);
- });
-
- it('If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-white listed address', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(alice, collectionId);
- await setMintPermissionExpectSuccess(alice, collectionId, false);
- await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);
- });
-
- it('If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by owner', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(alice, collectionId);
- await setMintPermissionExpectSuccess(alice, collectionId, true);
- await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
- });
-
- it('If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by admin', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(alice, collectionId);
- await setMintPermissionExpectSuccess(alice, collectionId, true);
- await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
- });
-
- it('If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-white listed address', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(alice, collectionId);
- await setMintPermissionExpectSuccess(alice, collectionId, true);
- await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);
- });
-
- it('If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by non-privileged and white listed address', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(alice, collectionId);
- await setMintPermissionExpectSuccess(alice, collectionId, true);
- await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
- await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
- });
-});