From 6da085670d5d17c80b18e680eee0b5a576475430 Mon Sep 17 00:00:00 2001 From: Max Andreev Date: Wed, 07 Dec 2022 17:26:53 +0000 Subject: [PATCH] Skip rft tests --- --- a/tests/src/eth/collectionLimits.test.ts +++ b/tests/src/eth/collectionLimits.test.ts @@ -1,4 +1,5 @@ import {IKeyringPair} from '@polkadot/types/types'; +import {Pallets} from '../util'; import {expect, itEth, usingEthPlaygrounds} from './util'; @@ -13,10 +14,10 @@ [ {case: 'nft' as const, method: 'createNFTCollection' as const}, - {case: 'rft' as const, method: 'createRFTCollection' as const}, + {case: 'rft' as const, method: 'createRFTCollection' as const, requiredPallets: [Pallets.ReFungible]}, {case: 'ft' as const, method: 'createFTCollection' as const}, ].map(testCase => - itEth(`for ${testCase.case}`, async ({helper}) => { + itEth.ifWithPallets(`for ${testCase.case}`, testCase.requiredPallets || [], async ({helper}) => { const owner = await helper.eth.createAccountWithBalance(donor); const {collectionId, collectionAddress} = await helper.eth.createCollecion(testCase.method, owner, 'Limits', 'absolutely anything', 'FLO', 18); const limits = { @@ -71,10 +72,10 @@ [ {case: 'nft' as const, method: 'createNFTCollection' as const}, - {case: 'rft' as const, method: 'createRFTCollection' as const}, + {case: 'rft' as const, method: 'createRFTCollection' as const, requiredPallets: [Pallets.ReFungible]}, {case: 'ft' as const, method: 'createFTCollection' as const}, ].map(testCase => - itEth(`for ${testCase.case}`, async ({helper}) => { + itEth.ifWithPallets(`for ${testCase.case}`, testCase.requiredPallets || [], async ({helper}) => { const invalidLimits = { accountTokenOwnershipLimit: BigInt(Number.MAX_SAFE_INTEGER), transfersEnabled: 3, --- 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); + } + })); }); -- gitstuff