difftreelog
CORE-300 Add tests
in: master
3 files changed
pallets/unique/src/tests.rsdiffbeforeafterboth--- a/pallets/unique/src/tests.rs
+++ b/pallets/unique/src/tests.rs
@@ -18,6 +18,7 @@
use super::*;
use crate::mock::*;
use crate::{AccessMode, CollectionMode};
+use sp_runtime::AccountId32;
use up_data_structs::{
COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData,
CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, MetaUpdatePermission,
@@ -2854,3 +2855,34 @@
);
});
}
+
+#[test]
+fn collection_sponsoring() {
+ new_test_ext().execute_with(|| {
+ // default_limits();
+ let user1 = 1_u64;
+ let user2 = 777_u64;
+ let origin1 = Origin::signed(user1);
+ let origin2 = Origin::signed(user2);
+ let account2 = account(user2);
+
+ let collection_id =
+ create_test_collection_for_owner(&CollectionMode::NFT, user1, CollectionId(1));
+ assert_ok!(TemplateModule::set_collection_sponsor(origin1.clone(), collection_id, user1));
+ assert_ok!(TemplateModule::confirm_sponsorship(origin1.clone(), collection_id));
+
+ // Expect error while have no permissions
+ assert!(TemplateModule::create_item(origin2.clone(), collection_id, account2.clone(), default_nft_data().into()).is_err());
+
+ assert_ok!(TemplateModule::set_public_access_mode(origin1.clone(), collection_id, AccessMode::AllowList));
+ assert_ok!(TemplateModule::add_to_allow_list(origin1.clone(), collection_id, account2.clone()));
+ assert_ok!(TemplateModule::set_mint_permission(origin1.clone(), collection_id, true));
+
+ assert_eq!(<pallet_balances::Pallet<Test>>::free_balance(user2), 0);
+ let balance_before = <pallet_balances::Pallet<Test>>::free_balance(user1);
+
+ assert_ok!(TemplateModule::create_item(origin2, collection_id, account2, default_nft_data().into()));
+ let balance_after = <pallet_balances::Pallet<Test>>::free_balance(user1);
+ assert_ne!(balance_before, balance_after);
+ });
+}
\ No newline at end of file
tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth24 itWeb3,24 itWeb3,25 SponsoringMode,25 SponsoringMode,26 createEthAccount,26 createEthAccount,27 collectionIdToAddress,28 GAS_ARGS,29 normalizeEvents,27} from './util/helpers';30} from './util/helpers';31import {32 createCollectionExpectSuccess,33 createItemExpectSuccess,34 getCreateCollectionResult,35 normalizeAccountId,36 toSubstrateAddress,37} from '../util/helpers';38import nonFungibleAbi from './nonFungibleAbi.json';39import {40 submitTransactionAsync,41} from '../substrate/substrate-api';42import { evmToAddress } from '@polkadot/util-crypto';284329describe('Sponsoring EVM contracts', () => {44describe('Sponsoring EVM contracts', () => {30 itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3}) => {45 itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3}) => {222223224 225 itWeb3.only('Sponsoring evm address from substrate collection', async ({api, web3}) => {226 const owner = privateKey('//Alice');227 const userEth = createEthAccount(web3);228 const userSub = evmToAddress(userEth);229 const collectionId = await createCollectionExpectSuccess();230231 {232 const tx = api.tx.unique.setCollectionSponsor(collectionId, owner.address);233 const events = await submitTransactionAsync(owner, tx);234 const result = getCreateCollectionResult(events);235 expect(result.success).to.be.true;236 }237 {238 const tx = api.tx.unique.confirmSponsorship(collectionId);239 const events = await submitTransactionAsync(owner, tx);240 const result = getCreateCollectionResult(events);241 expect(result.success).to.be.true;242 }243244 const address = collectionIdToAddress(collectionId);245 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: userEth, ...GAS_ARGS});246 const receiver = createEthAccount(web3);247248 {249 const nextTokenId = await contract.methods.nextTokenId().call();250 expect(nextTokenId).to.be.equal('1');251 // const result = await contract.methods.mintWithTokenURI(252 // receiver,253 // nextTokenId,254 // 'Test URI',255 // ).send({from: userEth});256 // const events = normalizeEvents(result.events);257258 // expect(events).to.be.deep.equal([259 // {260 // address,261 // event: 'Transfer',262 // args: {263 // from: '0x0000000000000000000000000000000000000000',264 // to: receiver,265 // tokenId: nextTokenId,266 // },267 // },268 // ]);269270 // expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');271 }272273 {274 const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');275 const events = await submitTransactionAsync(owner, tx);276 const result = getCreateCollectionResult(events);277 expect(result.success).to.be.true;278 }279 {280 const tx = api.tx.unique.addToAllowList(collectionId, {Ethereum: userEth});281 const events = await submitTransactionAsync(owner, tx);282 const result = getCreateCollectionResult(events);283 expect(result.success).to.be.true;284 }285 {286 const tx = api.tx.unique.setMintPermission(collectionId, true);287 const events = await submitTransactionAsync(owner, tx);288 const result = getCreateCollectionResult(events);289 expect(result.success).to.be.true;290 }291 {292 const nextTokenId = await contract.methods.nextTokenId().call();293 expect(nextTokenId).to.be.equal('1');294 // const result = await contract.methods.mintWithTokenURI(295 // receiver,296 // nextTokenId,297 // 'Test URI',298 // ).send({from: userEth});299 // const events = normalizeEvents(result.events);300301 // expect(events).to.be.deep.equal([302 // {303 // address,304 // event: 'Transfer',305 // args: {306 // from: '0x0000000000000000000000000000000000000000',307 // to: receiver,308 // tokenId: nextTokenId,309 // },310 // },311 // ]);312313 // expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');314 }315316 });202});317});203318tests/src/eth/util/helpers.tsdiffbeforeafterboth--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -241,6 +241,12 @@
return collector;
}
+/**
+ * pallet evm_contract_helpers
+ * @param web3
+ * @param caller - eth address
+ * @returns
+ */
export function contractHelpers(web3: Web3, caller: string) {
return new web3.eth.Contract(contractHelpersAbi as any, '0x842899ECF380553E8a4de75bF534cdf6fBF64049', {from: caller, ...GAS_ARGS});
}