difftreelog
Skip rft tests
in: master
2 files changed
tests/src/eth/collectionLimits.test.tsdiffbeforeafterboth1import {IKeyringPair} from '@polkadot/types/types';2import {expect, itEth, usingEthPlaygrounds} from './util';345describe('Can set collection limits', () => {6 let donor: IKeyringPair;78 before(async () => {9 await usingEthPlaygrounds(async (_helper, privateKey) => {10 donor = await privateKey({filename: __filename});11 });12 });1314 [15 {case: 'nft' as const, method: 'createNFTCollection' as const},16 {case: 'rft' as const, method: 'createRFTCollection' as const},17 {case: 'ft' as const, method: 'createFTCollection' as const},18 ].map(testCase =>19 itEth(`for ${testCase.case}`, async ({helper}) => {20 const owner = await helper.eth.createAccountWithBalance(donor);21 const {collectionId, collectionAddress} = await helper.eth.createCollecion(testCase.method, owner, 'Limits', 'absolutely anything', 'FLO', 18);22 const limits = {23 accountTokenOwnershipLimit: 1000,24 sponsoredDataSize: 1024,25 sponsoredDataRateLimit: 30,26 tokenLimit: 1000000,27 sponsorTransferTimeout: 6,28 sponsorApproveTimeout: 6,29 ownerCanTransfer: 1,30 ownerCanDestroy: 0,31 transfersEnabled: 0,32 };33 34 const expectedLimits = {35 accountTokenOwnershipLimit: 1000,36 sponsoredDataSize: 1024,37 sponsoredDataRateLimit: {blocks: 30},38 tokenLimit: 1000000,39 sponsorTransferTimeout: 6,40 sponsorApproveTimeout: 6,41 ownerCanTransfer: true,42 ownerCanDestroy: false,43 transfersEnabled: false,44 };45 46 const collection = helper.ethNativeContract.collection(collectionAddress, testCase.case, owner);47 await collection.methods.setCollectionLimit('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();48 await collection.methods.setCollectionLimit('sponsoredDataSize', limits.sponsoredDataSize).send();49 await collection.methods.setCollectionLimit('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();50 await collection.methods.setCollectionLimit('tokenLimit', limits.tokenLimit).send();51 await collection.methods.setCollectionLimit('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();52 await collection.methods.setCollectionLimit('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();53 await collection.methods.setCollectionLimit('ownerCanTransfer', limits.ownerCanTransfer).send();54 await collection.methods.setCollectionLimit('ownerCanDestroy', limits.ownerCanDestroy).send();55 await collection.methods.setCollectionLimit('transfersEnabled', limits.transfersEnabled).send();56 57 const data = (await helper.rft.getData(collectionId))!;58 expect(data.raw.limits).to.deep.eq(expectedLimits);59 expect(await helper.collection.getEffectiveLimits(collectionId)).to.deep.eq(expectedLimits);60 }));61});6263describe('Cannot set invalid collection limits', () => {64 let donor: IKeyringPair;6566 before(async () => {67 await usingEthPlaygrounds(async (_helper, privateKey) => {68 donor = await privateKey({filename: __filename});69 });70 });7172 [73 {case: 'nft' as const, method: 'createNFTCollection' as const},74 {case: 'rft' as const, method: 'createRFTCollection' as const},75 {case: 'ft' as const, method: 'createFTCollection' as const},76 ].map(testCase =>77 itEth(`for ${testCase.case}`, async ({helper}) => {78 const invalidLimits = {79 accountTokenOwnershipLimit: BigInt(Number.MAX_SAFE_INTEGER),80 transfersEnabled: 3,81 };8283 const owner = await helper.eth.createAccountWithBalance(donor);84 const {collectionAddress} = await helper.eth.createCollecion(testCase.method, owner, 'Limits', 'absolutely anything', 'ISNI', 18);85 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, testCase.case, owner);86 await expect(collectionEvm.methods87 .setCollectionLimit('badLimit', '1')88 .call()).to.be.rejectedWith('unknown limit "badLimit"');89 90 await expect(collectionEvm.methods91 .setCollectionLimit(Object.keys(invalidLimits)[0], invalidLimits.accountTokenOwnershipLimit)92 .call()).to.be.rejectedWith(`can't convert value to u32 "${invalidLimits.accountTokenOwnershipLimit}"`);93 94 await expect(collectionEvm.methods95 .setCollectionLimit(Object.keys(invalidLimits)[1], invalidLimits.transfersEnabled)96 .call()).to.be.rejectedWith(`can't convert value to boolean "${invalidLimits.transfersEnabled}"`);97 }));98});99 tests/src/eth/collectionProperties.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionProperties.test.ts
+++ b/tests/src/eth/collectionProperties.test.ts
@@ -18,7 +18,6 @@
import {Pallets} from '../util';
import {IProperty, ITokenPropertyPermission} from '../util/playgrounds/types';
import {IKeyringPair} from '@polkadot/types/types';
-import {TCollectionMode} from '../util/playgrounds/types';
describe('EVM collection properties', () => {
let donor: IKeyringPair;
@@ -133,86 +132,82 @@
donor = await privateKey({filename: __filename});
});
});
-
- const checkERC721Metadata = async (helper: EthUniqueHelper, mode: 'nft' | 'rft') => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const bruh = await helper.eth.createAccountWithBalance(donor);
-
- const BASE_URI = 'base/';
- const SUFFIX = 'suffix1';
- const URI = 'uri1';
-
- const collectionHelpers = helper.ethNativeContract.collectionHelpers(caller);
- const creatorMethod = mode === 'rft' ? 'createRFTCollection' : 'createNFTCollection';
-
- const {collectionId, collectionAddress} = await helper.eth[creatorMethod](caller, 'n', 'd', 'p');
- const bruhCross = helper.ethCrossAccount.fromAddress(bruh);
-
- const contract = helper.ethNativeContract.collectionById(collectionId, mode, caller);
- await contract.methods.addCollectionAdminCross(bruhCross).send(); // to check that admin will work too
- const collection1 = helper.nft.getCollectionObject(collectionId);
- const data1 = await collection1.getData();
- expect(data1?.raw.flags.erc721metadata).to.be.false;
- expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.false;
-
- await collectionHelpers.methods.makeCollectionERC721MetadataCompatible(collectionAddress, BASE_URI)
- .send({from: bruh});
-
- expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.true;
-
- const collection2 = helper.nft.getCollectionObject(collectionId);
- const data2 = await collection2.getData();
- expect(data2?.raw.flags.erc721metadata).to.be.true;
-
- const propertyPermissions = data2?.raw.tokenPropertyPermissions;
- expect(propertyPermissions?.length).to.equal(2);
-
- expect(propertyPermissions.find((tpp: ITokenPropertyPermission) => {
- return tpp.key === 'URI' && tpp.permission.mutable && tpp.permission.collectionAdmin && !tpp.permission.tokenOwner;
- })).to.be.not.null;
-
- expect(propertyPermissions.find((tpp: ITokenPropertyPermission) => {
- return tpp.key === 'URISuffix' && tpp.permission.mutable && tpp.permission.collectionAdmin && !tpp.permission.tokenOwner;
- })).to.be.not.null;
-
- expect(data2?.raw.properties?.find((property: IProperty) => {
- return property.key === 'baseURI' && property.value === BASE_URI;
- })).to.be.not.null;
-
- const token1Result = await contract.methods.mint(bruh).send();
- const tokenId1 = token1Result.events.Transfer.returnValues.tokenId;
-
- expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI);
-
- await contract.methods.setProperties(tokenId1, [{key: 'URISuffix', value: Buffer.from(SUFFIX)}]).send();
- expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI + SUFFIX);
-
- await contract.methods.setProperties(tokenId1, [{key: 'URI', value: Buffer.from(URI)}]).send();
- expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(URI);
-
- await contract.methods.deleteProperties(tokenId1, ['URI']).send();
- expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI + SUFFIX);
-
- const token2Result = await contract.methods.mintWithTokenURI(bruh, URI).send();
- const tokenId2 = token2Result.events.Transfer.returnValues.tokenId;
-
- expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(URI);
-
- await contract.methods.deleteProperties(tokenId2, ['URI']).send();
- expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(BASE_URI);
-
- await contract.methods.setProperties(tokenId2, [{key: 'URISuffix', value: Buffer.from(SUFFIX)}]).send();
- expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(BASE_URI + SUFFIX);
- };
-
- itEth('ERC721Metadata property can be set for NFT collection', async({helper}) => {
- await checkERC721Metadata(helper, 'nft');
- });
-
- itEth.ifWithPallets('ERC721Metadata property can be set for RFT collection', [Pallets.ReFungible], async({helper}) => {
- await checkERC721Metadata(helper, 'rft');
- });
+ [
+ {case: 'nft' as const},
+ {case: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ ].map(testCase =>
+ itEth.ifWithPallets(`ERC721Metadata property can be set for ${testCase.case} collection`, testCase.requiredPallets || [], async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const bruh = await helper.eth.createAccountWithBalance(donor);
+
+ const BASE_URI = 'base/';
+ const SUFFIX = 'suffix1';
+ const URI = 'uri1';
+
+ const collectionHelpers = helper.ethNativeContract.collectionHelpers(caller);
+ const creatorMethod = testCase.case === 'rft' ? 'createRFTCollection' : 'createNFTCollection';
+
+ const {collectionId, collectionAddress} = await helper.eth[creatorMethod](caller, 'n', 'd', 'p');
+ const bruhCross = helper.ethCrossAccount.fromAddress(bruh);
+
+ const contract = helper.ethNativeContract.collectionById(collectionId, testCase.case, caller);
+ await contract.methods.addCollectionAdminCross(bruhCross).send(); // to check that admin will work too
+
+ const collection1 = helper.nft.getCollectionObject(collectionId);
+ const data1 = await collection1.getData();
+ expect(data1?.raw.flags.erc721metadata).to.be.false;
+ expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.false;
+
+ await collectionHelpers.methods.makeCollectionERC721MetadataCompatible(collectionAddress, BASE_URI)
+ .send({from: bruh});
+
+ expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.true;
+
+ const collection2 = helper.nft.getCollectionObject(collectionId);
+ const data2 = await collection2.getData();
+ expect(data2?.raw.flags.erc721metadata).to.be.true;
+
+ const propertyPermissions = data2?.raw.tokenPropertyPermissions;
+ expect(propertyPermissions?.length).to.equal(2);
+
+ expect(propertyPermissions.find((tpp: ITokenPropertyPermission) => {
+ return tpp.key === 'URI' && tpp.permission.mutable && tpp.permission.collectionAdmin && !tpp.permission.tokenOwner;
+ })).to.be.not.null;
+
+ expect(propertyPermissions.find((tpp: ITokenPropertyPermission) => {
+ return tpp.key === 'URISuffix' && tpp.permission.mutable && tpp.permission.collectionAdmin && !tpp.permission.tokenOwner;
+ })).to.be.not.null;
+
+ expect(data2?.raw.properties?.find((property: IProperty) => {
+ return property.key === 'baseURI' && property.value === BASE_URI;
+ })).to.be.not.null;
+
+ const token1Result = await contract.methods.mint(bruh).send();
+ const tokenId1 = token1Result.events.Transfer.returnValues.tokenId;
+
+ expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI);
+
+ await contract.methods.setProperties(tokenId1, [{key: 'URISuffix', value: Buffer.from(SUFFIX)}]).send();
+ expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI + SUFFIX);
+
+ await contract.methods.setProperties(tokenId1, [{key: 'URI', value: Buffer.from(URI)}]).send();
+ expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(URI);
+
+ await contract.methods.deleteProperties(tokenId1, ['URI']).send();
+ expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI + SUFFIX);
+
+ const token2Result = await contract.methods.mintWithTokenURI(bruh, URI).send();
+ const tokenId2 = token2Result.events.Transfer.returnValues.tokenId;
+
+ expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(URI);
+
+ await contract.methods.deleteProperties(tokenId2, ['URI']).send();
+ expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(BASE_URI);
+
+ await contract.methods.setProperties(tokenId2, [{key: 'URISuffix', value: Buffer.from(SUFFIX)}]).send();
+ expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(BASE_URI + SUFFIX);
+ }));
});
describe('EVM collection property', () => {
@@ -224,81 +219,70 @@
});
});
- async function testSetReadProperties(helper: EthUniqueHelper, mode: TCollectionMode) {
- const collection = await helper[mode].mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});
-
- const sender = await helper.eth.createAccountWithBalance(donor, 100n);
- await collection.addAdmin(donor, {Ethereum: sender});
+ [
+ {case: 'nft' as const},
+ {case: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {case: 'ft' as const},
+ ].map(testCase =>
+ itEth.ifWithPallets(`can set/read properties ${testCase.case}`, testCase.requiredPallets || [], async ({helper}) => {
+ const collection = await helper[testCase.case].mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});
- const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, mode, sender);
-
- const keys = ['key0', 'key1'];
-
- const writeProperties = [
- helper.ethProperty.property(keys[0], 'value0'),
- helper.ethProperty.property(keys[1], 'value1'),
- ];
-
- await contract.methods.setCollectionProperties(writeProperties).send();
- const readProperties = await contract.methods.collectionProperties([keys[0], keys[1]]).call();
- expect(readProperties).to.be.like(writeProperties);
- }
-
- itEth('Set/read properties ft', async ({helper}) => {
- await testSetReadProperties(helper, 'ft');
- });
- itEth.ifWithPallets('Set/read properties rft', [Pallets.ReFungible], async ({helper}) => {
- await testSetReadProperties(helper, 'rft');
- });
- itEth('Set/read properties nft', async ({helper}) => {
- await testSetReadProperties(helper, 'nft');
- });
-
- async function testDeleteProperties(helper: EthUniqueHelper, mode: TCollectionMode) {
- const collection = await helper[mode].mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});
-
- const sender = await helper.eth.createAccountWithBalance(donor, 100n);
- await collection.addAdmin(donor, {Ethereum: sender});
-
- const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, mode, sender);
-
- const keys = ['key0', 'key1', 'key2', 'key3'];
-
- {
+ const sender = await helper.eth.createAccountWithBalance(donor, 100n);
+ await collection.addAdmin(donor, {Ethereum: sender});
+
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, testCase.case, sender);
+
+ const keys = ['key0', 'key1'];
+
const writeProperties = [
helper.ethProperty.property(keys[0], 'value0'),
helper.ethProperty.property(keys[1], 'value1'),
- helper.ethProperty.property(keys[2], 'value2'),
- helper.ethProperty.property(keys[3], 'value3'),
];
-
+
await contract.methods.setCollectionProperties(writeProperties).send();
- const readProperties = await contract.methods.collectionProperties([keys[0], keys[1], keys[2], keys[3]]).call();
+ const readProperties = await contract.methods.collectionProperties([keys[0], keys[1]]).call();
expect(readProperties).to.be.like(writeProperties);
- }
+ }));
- {
- const expectProperties = [
- helper.ethProperty.property(keys[0], 'value0'),
- helper.ethProperty.property(keys[1], 'value1'),
- ];
+ [
+ {case: 'nft' as const},
+ {case: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {case: 'ft' as const},
+ ].map(testCase =>
+ itEth.ifWithPallets(`can delete properties ${testCase.case}`, testCase.requiredPallets || [], async ({helper}) => {
+ const collection = await helper[testCase.case].mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});
- await contract.methods.deleteCollectionProperties([keys[2], keys[3]]).send();
- const readProperties = await contract.methods.collectionProperties([]).call();
- expect(readProperties).to.be.like(expectProperties);
- }
- }
+ const sender = await helper.eth.createAccountWithBalance(donor, 100n);
+ await collection.addAdmin(donor, {Ethereum: sender});
- itEth('Delete properties ft', async ({helper}) => {
- await testDeleteProperties(helper, 'ft');
- });
- itEth.ifWithPallets('Delete properties rft', [Pallets.ReFungible], async ({helper}) => {
- await testDeleteProperties(helper, 'rft');
- });
- itEth('Delete properties nft', async ({helper}) => {
- await testDeleteProperties(helper, 'nft');
- });
-
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, testCase.case, sender);
+
+ const keys = ['key0', 'key1', 'key2', 'key3'];
+
+ {
+ const writeProperties = [
+ helper.ethProperty.property(keys[0], 'value0'),
+ helper.ethProperty.property(keys[1], 'value1'),
+ helper.ethProperty.property(keys[2], 'value2'),
+ helper.ethProperty.property(keys[3], 'value3'),
+ ];
+
+ await contract.methods.setCollectionProperties(writeProperties).send();
+ const readProperties = await contract.methods.collectionProperties([keys[0], keys[1], keys[2], keys[3]]).call();
+ expect(readProperties).to.be.like(writeProperties);
+ }
+
+ {
+ const expectProperties = [
+ helper.ethProperty.property(keys[0], 'value0'),
+ helper.ethProperty.property(keys[1], 'value1'),
+ ];
+
+ await contract.methods.deleteCollectionProperties([keys[2], keys[3]]).send();
+ const readProperties = await contract.methods.collectionProperties([]).call();
+ expect(readProperties).to.be.like(expectProperties);
+ }
+ }));
});