difftreelog
CORE-300 Add tests
in: master
3 files changed
pallets/unique/src/tests.rsdiffbeforeafterboth18use super::*;18use super::*;19use crate::mock::*;19use crate::mock::*;20use crate::{AccessMode, CollectionMode};20use crate::{AccessMode, CollectionMode};21use sp_runtime::AccountId32;21use up_data_structs::{22use up_data_structs::{22 COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData,23 COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData,23 CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, MetaUpdatePermission,24 CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, MetaUpdatePermission,2855 });2856 });2856}2857}285728582859#[test]2860fn collection_sponsoring() {2861 new_test_ext().execute_with(|| {2862 // default_limits();2863 let user1 = 1_u64;2864 let user2 = 777_u64;2865 let origin1 = Origin::signed(user1);2866 let origin2 = Origin::signed(user2);2867 let account2 = account(user2);2868 2869 let collection_id =2870 create_test_collection_for_owner(&CollectionMode::NFT, user1, CollectionId(1));2871 assert_ok!(TemplateModule::set_collection_sponsor(origin1.clone(), collection_id, user1));2872 assert_ok!(TemplateModule::confirm_sponsorship(origin1.clone(), collection_id));28732874 // Expect error while have no permissions2875 assert!(TemplateModule::create_item(origin2.clone(), collection_id, account2.clone(), default_nft_data().into()).is_err());28762877 assert_ok!(TemplateModule::set_public_access_mode(origin1.clone(), collection_id, AccessMode::AllowList));2878 assert_ok!(TemplateModule::add_to_allow_list(origin1.clone(), collection_id, account2.clone()));2879 assert_ok!(TemplateModule::set_mint_permission(origin1.clone(), collection_id, true));28802881 assert_eq!(<pallet_balances::Pallet<Test>>::free_balance(user2), 0);2882 let balance_before = <pallet_balances::Pallet<Test>>::free_balance(user1);2883 2884 assert_ok!(TemplateModule::create_item(origin2, collection_id, account2, default_nft_data().into()));2885 let balance_after = <pallet_balances::Pallet<Test>>::free_balance(user1);2886 assert_ne!(balance_before, balance_after);2887 });2888}tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/contractSponsoring.test.ts
+++ b/tests/src/eth/contractSponsoring.test.ts
@@ -24,7 +24,22 @@
itWeb3,
SponsoringMode,
createEthAccount,
+ collectionIdToAddress,
+ GAS_ARGS,
+ normalizeEvents,
} from './util/helpers';
+import {
+ createCollectionExpectSuccess,
+ createItemExpectSuccess,
+ getCreateCollectionResult,
+ normalizeAccountId,
+ toSubstrateAddress,
+} from '../util/helpers';
+import nonFungibleAbi from './nonFungibleAbi.json';
+import {
+ submitTransactionAsync,
+} from '../substrate/substrate-api';
+import { evmToAddress } from '@polkadot/util-crypto';
describe('Sponsoring EVM contracts', () => {
itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3}) => {
@@ -199,4 +214,104 @@
const helpers = contractHelpers(web3, owner);
expect(await helpers.methods.getSponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');
});
+
+
+
+
+
+
+
+
+ itWeb3.only('Sponsoring evm address from substrate collection', async ({api, web3}) => {
+ const owner = privateKey('//Alice');
+ const userEth = createEthAccount(web3);
+ const userSub = evmToAddress(userEth);
+ const collectionId = await createCollectionExpectSuccess();
+
+ {
+ const tx = api.tx.unique.setCollectionSponsor(collectionId, owner.address);
+ const events = await submitTransactionAsync(owner, tx);
+ const result = getCreateCollectionResult(events);
+ expect(result.success).to.be.true;
+ }
+ {
+ const tx = api.tx.unique.confirmSponsorship(collectionId);
+ const events = await submitTransactionAsync(owner, tx);
+ const result = getCreateCollectionResult(events);
+ expect(result.success).to.be.true;
+ }
+
+ const address = collectionIdToAddress(collectionId);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: userEth, ...GAS_ARGS});
+ const receiver = createEthAccount(web3);
+
+ {
+ const nextTokenId = await contract.methods.nextTokenId().call();
+ expect(nextTokenId).to.be.equal('1');
+ // const result = await contract.methods.mintWithTokenURI(
+ // receiver,
+ // nextTokenId,
+ // 'Test URI',
+ // ).send({from: userEth});
+ // const events = normalizeEvents(result.events);
+
+ // expect(events).to.be.deep.equal([
+ // {
+ // address,
+ // event: 'Transfer',
+ // args: {
+ // from: '0x0000000000000000000000000000000000000000',
+ // to: receiver,
+ // tokenId: nextTokenId,
+ // },
+ // },
+ // ]);
+
+ // expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
+ }
+
+ {
+ const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');
+ const events = await submitTransactionAsync(owner, tx);
+ const result = getCreateCollectionResult(events);
+ expect(result.success).to.be.true;
+ }
+ {
+ const tx = api.tx.unique.addToAllowList(collectionId, {Ethereum: userEth});
+ const events = await submitTransactionAsync(owner, tx);
+ const result = getCreateCollectionResult(events);
+ expect(result.success).to.be.true;
+ }
+ {
+ const tx = api.tx.unique.setMintPermission(collectionId, true);
+ const events = await submitTransactionAsync(owner, tx);
+ const result = getCreateCollectionResult(events);
+ expect(result.success).to.be.true;
+ }
+ {
+ const nextTokenId = await contract.methods.nextTokenId().call();
+ expect(nextTokenId).to.be.equal('1');
+ // const result = await contract.methods.mintWithTokenURI(
+ // receiver,
+ // nextTokenId,
+ // 'Test URI',
+ // ).send({from: userEth});
+ // const events = normalizeEvents(result.events);
+
+ // expect(events).to.be.deep.equal([
+ // {
+ // address,
+ // event: 'Transfer',
+ // args: {
+ // from: '0x0000000000000000000000000000000000000000',
+ // to: receiver,
+ // tokenId: nextTokenId,
+ // },
+ // },
+ // ]);
+
+ // expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
+ }
+
+ });
});
tests/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});
}