difftreelog
fix tests cleanup
in: master
10 files changed
tests/src/eth/collectionLimits.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionLimits.test.ts
+++ b/tests/src/eth/collectionLimits.test.ts
@@ -97,7 +97,7 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(owner, new CreateCollectionData('Limits', 'absolutely anything', 'ISNI', testCase.case, 18)).send();
- const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, testCase.case, owner);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, testCase.case, owner);
// Cannot set non-existing limit
await expect(collectionEvm.methods
tests/src/eth/createCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createCollection.test.ts
+++ b/tests/src/eth/createCollection.test.ts
@@ -23,12 +23,13 @@
const DECIMALS = 18;
const CREATE_COLLECTION_DATA_DEFAULTS_ARRAY = [
- [],
- [],
- [],
- [false, false, []],
- [],
- [0],
+ [], // properties
+ [], // tokenPropertyPermissions
+ [], // adminList
+ [false, false, []], // nestingSettings
+ [], // limits
+ emptyAddress, // pendingSponsor
+ [0], // flags
];
type ElementOf<A> = A extends readonly (infer T)[] ? T : never;
@@ -64,7 +65,7 @@
itEth('Collection address exist', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';
- const collectionHelpers = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
expect(await collectionHelpers
.methods.isCollectionExist(collectionAddressForNonexistentCollection).call())
@@ -76,7 +77,7 @@
.to.be.true;
// check collectionOwner:
- const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner, true);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', owner, true);
const collectionOwner = await collectionEvm.methods.collectionOwner().call();
expect(helper.address.restoreCrossAccountFromBigInt(BigInt(collectionOwner.sub))).to.eq(helper.address.ethToSubstrate(owner, true));
});
@@ -84,7 +85,7 @@
itEth('destroyCollection', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress, collectionId} = await helper.eth.createCollection(owner, new CreateCollectionData('Exister', 'absolutely anything', 'WIWT', 'ft', DECIMALS)).send();
- const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const result = await collectionHelper.methods
.destroyCollection(collectionAddress)
@@ -110,7 +111,7 @@
itEth('(!negative test!) Create collection (bad lengths)', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
{
const MAX_NAME_LENGTH = 64;
const collectionName = 'A'.repeat(MAX_NAME_LENGTH + 1);
@@ -119,7 +120,6 @@
await expect(collectionHelper.methods
.createCollection([
- emptyAddress,
collectionName,
description,
tokenPrefix,
@@ -136,7 +136,6 @@
const tokenPrefix = 'A';
await expect(collectionHelper.methods
.createCollection([
- emptyAddress,
collectionName,
description,
tokenPrefix,
@@ -153,7 +152,6 @@
const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);
await expect(collectionHelper.methods
.createCollection([
- emptyAddress,
collectionName,
description,
tokenPrefix,
@@ -167,11 +165,10 @@
itEth('(!negative test!) cannot create collection if value !== 2', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const expects = [0n, 1n, 30n].map(async value => {
await expect(collectionHelper.methods
.createCollection([
- emptyAddress,
'Peasantry',
'absolutely anything',
'TWIW',
@@ -238,7 +235,7 @@
const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;
const expectedCollectionAddress = helper.ethAddress.fromCollectionId(expectedCollectionId);
- const collectionHelpers = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
expect(await collectionHelpers.methods
.isCollectionExist(expectedCollectionAddress)
@@ -246,7 +243,6 @@
await collectionHelpers.methods
.createCollection([
- emptyAddress,
'A',
'A',
'A',
@@ -331,7 +327,7 @@
const ss58Format = helper.chain.getChainProperties().ss58Format;
const {collectionId, collectionAddress} = await helper.eth.createCollection(owner, new CreateCollectionData('Sponsor', 'absolutely anything', 'ENVY', 'rft')).send();
- const collection = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);
await collection.methods.setCollectionSponsorCross(sponsorCross).send();
@@ -340,7 +336,7 @@
await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('ConfirmSponsorshipFail');
- const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);
+ const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);
await sponsorCollection.methods.confirmCollectionSponsorship().send();
data = (await helper.rft.getData(collectionId))!;
@@ -350,7 +346,7 @@
itEth('Collection address exist', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';
- const collectionHelpers = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
expect(await collectionHelpers
.methods.isCollectionExist(collectionAddressForNonexistentCollection).call())
@@ -362,7 +358,7 @@
.to.be.true;
// check collectionOwner:
- const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner, true);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', owner, true);
const collectionOwner = await collectionEvm.methods.collectionOwner().call();
expect(helper.address.restoreCrossAccountFromBigInt(BigInt(collectionOwner.sub))).to.eq(helper.address.ethToSubstrate(owner, true));
});
@@ -370,7 +366,7 @@
itEth('destroyCollection', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress, collectionId} = await helper.eth.createCollection(owner, new CreateCollectionData('Limits', 'absolutely anything', 'OLF', 'rft')).send();
- const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
await expect(collectionHelper.methods
.destroyCollection(collectionAddress)
@@ -384,7 +380,7 @@
itEth('(!negative test!) Create collection (bad lengths)', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
{
const MAX_NAME_LENGTH = 64;
const collectionName = 'A'.repeat(MAX_NAME_LENGTH + 1);
@@ -393,7 +389,6 @@
await expect(collectionHelper.methods
.createCollection([
- emptyAddress,
collectionName,
description,
tokenPrefix,
@@ -410,7 +405,6 @@
const tokenPrefix = 'A';
await expect(collectionHelper.methods
.createCollection([
- emptyAddress,
collectionName,
description,
tokenPrefix,
@@ -427,7 +421,6 @@
const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);
await expect(collectionHelper.methods
.createCollection([
- emptyAddress,
collectionName,
description,
tokenPrefix,
@@ -441,10 +434,9 @@
itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
await expect(collectionHelper.methods
.createCollection([
- emptyAddress,
'Peasantry',
'absolutely anything',
'TWIW',
@@ -473,7 +465,7 @@
pendingSponsor: sponsorCross,
},
).send();
- const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.true;
@@ -657,7 +649,7 @@
'',
);
const collectionSub = helper.nft.getCollectionObject(collectionId);
- const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
// Set and confirm sponsor:
await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsorEth});
@@ -695,7 +687,7 @@
'',
);
const receiver = await helper.eth.createAccountWithBalance(donor);
- const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});
@@ -764,7 +756,7 @@
adminList: [adminCrossSub, adminCrossEth],
},
).send();
- const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner, true);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner, true);
// 1. Expect api.rpc.unique.adminlist returns admins:
const adminListRpc = await helper.collection.getAdmins(collectionId);
@@ -801,7 +793,7 @@
},
'uri',
);
- const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);
// admin (sub and eth) can mint token:
await collectionEvm.methods.mint(owner).send({from: adminEth});
@@ -852,7 +844,7 @@
},
).send();
- const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
{
const adminList = await helper.collection.getAdmins(collectionId);
@@ -1062,7 +1054,7 @@
},
).send();
- const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, caller);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, testCase.mode, caller);
await collectionEvm.methods.deleteCollectionProperties(['testKey1', 'testKey2']).send({from: caller});
@@ -1162,7 +1154,7 @@
],
},
).send();
- const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
expect(await helper[testCase.mode].getPropertyPermissions(collectionId)).to.be.deep.equal([{
key: 'testKey',
@@ -1287,7 +1279,7 @@
},
).send();
- const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, caller);
+ const collection = helper.ethNativeContract.collection(collectionAddress, testCase.mode, caller);
const tokenId = (await collection.methods.mintCross(receiver, [{key: 'testKey', value: Buffer.from('testValue')}, {key: 'testKey_1', value: Buffer.from('testValue_1')}]).send()).events.Transfer.returnValues.tokenId;
expect(await collection.methods.properties(tokenId, ['testKey', 'testKey_1']).call()).to.has.length(2);
@@ -1311,7 +1303,7 @@
},
).send();
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
// Create a token to be nested to
const mintingTargetNFTTokenIdResult = await contract.methods.mint(owner).send({from: owner});
@@ -1342,7 +1334,7 @@
new CreateCollectionData('A', 'B', 'C', 'nft'),
).send();
- const unnestedContract = await helper.ethNativeContract.collection(unnestedCollectionAddress, 'nft', owner);
+ const unnestedContract = helper.ethNativeContract.collection(unnestedCollectionAddress, 'nft', owner);
expect(await unnestedContract.methods.collectionNesting().call({from: owner})).to.be.like([false, false, []]);
const {collectionAddress} = await helper.eth.createCollection(
@@ -1357,7 +1349,7 @@
},
).send();
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
expect(await contract.methods.collectionNesting().call({from: owner})).to.be.like([true, false, [unnestedCollectionAddress.toString()]]);
await contract.methods.setCollectionNesting([false, false, []]).send({from: owner});
expect(await contract.methods.collectionNesting().call({from: owner})).to.be.like([false, false, []]);
@@ -1378,7 +1370,7 @@
},
).send();
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
// Create a token to nest into
const mintingTargetTokenIdResult = await contract.methods.mint(owner).send({from: owner});
@@ -1419,17 +1411,15 @@
}
});
- itEth('NFT: foreign flag number is ignored', async ({helper}) => {
+ itEth('NFT: can\'t set foreign flag number', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
{
- const {collectionId} = await helper.eth.createCollection(owner, {...createCollectionData, flags: 128}).send();
- expect((await helper.nft.getData(collectionId))?.raw.flags).to.be.deep.equal({foreign: false, erc721metadata: false});
+ await expect(helper.eth.createCollection(owner, {...createCollectionData, flags: 128}).call({from: owner})).to.be.rejectedWith(/internal flags were used/);
}
{
- const {collectionId} = await helper.eth.createCollection(owner, {...createCollectionData, flags: 192}).send();
- expect((await helper.nft.getData(collectionId))?.raw.flags).to.be.deep.equal({foreign: false, erc721metadata: true});
+ await expect(helper.eth.createCollection(owner, {...createCollectionData, flags: 192}).call({from: owner})).to.be.rejectedWith(/internal flags were used/);
}
});
@@ -1446,13 +1436,11 @@
const owner = await helper.eth.createAccountWithBalance(donor);
{
- const {collectionId} = await helper.eth.createCollection(owner, {...createCollectionData, flags: [CollectionFlag.Foreign]}).send();
- expect((await helper.nft.getData(collectionId))?.raw.flags).to.be.deep.equal({foreign: false, erc721metadata: false});
+ await expect(helper.eth.createCollection(owner, {...createCollectionData, flags: [CollectionFlag.Foreign]}).call({from: owner})).to.be.rejectedWith(/internal flags were used/);
}
{
- const {collectionId} = await helper.eth.createCollection(owner, {...createCollectionData, flags: [CollectionFlag.Erc721metadata | CollectionFlag.Foreign]}).send();
- expect((await helper.nft.getData(collectionId))?.raw.flags).to.be.deep.equal({foreign: false, erc721metadata: true});
+ await expect(helper.eth.createCollection(owner, {...createCollectionData, flags: [CollectionFlag.Erc721metadata | CollectionFlag.Foreign]}).call({from: owner})).to.be.rejectedWith(/internal flags were used/);
}
});
});
tests/src/eth/createFTCollection.seqtest.tsdiffbeforeafterboth--- a/tests/src/eth/createFTCollection.seqtest.ts
+++ b/tests/src/eth/createFTCollection.seqtest.ts
@@ -59,7 +59,7 @@
const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;
const expectedCollectionAddress = helper.ethAddress.fromCollectionId(expectedCollectionId);
- const collectionHelpers = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
expect(await collectionHelpers.methods
.isCollectionExist(expectedCollectionAddress)
tests/src/eth/createFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createFTCollection.test.ts
+++ b/tests/src/eth/createFTCollection.test.ts
@@ -50,7 +50,7 @@
await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('ConfirmSponsorshipFail');
- const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor, true);
+ const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor, true);
await sponsorCollection.methods.confirmCollectionSponsorship().send();
data = (await helper.rft.getData(collectionId))!;
@@ -64,7 +64,7 @@
const description = 'absolutely anything';
const {collectionId, collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Sponsor', DECIMALS, description, 'ENVY');
- const collection = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);
await collection.methods.setCollectionSponsorCross(sponsorCross).send();
@@ -73,7 +73,7 @@
await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('ConfirmSponsorshipFail');
- const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);
+ const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);
await sponsorCollection.methods.confirmCollectionSponsorship().send();
data = (await helper.rft.getData(collectionId))!;
@@ -84,7 +84,7 @@
itEth('Collection address exist', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';
- const collectionHelpers = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
expect(await collectionHelpers
.methods.isCollectionExist(collectionAddressForNonexistentCollection).call())
@@ -96,7 +96,7 @@
.to.be.true;
// check collectionOwner:
- const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner, true);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', owner, true);
const collectionOwner = await collectionEvm.methods.collectionOwner().call();
expect(helper.address.restoreCrossAccountFromBigInt(BigInt(collectionOwner.sub))).to.eq(helper.address.ethToSubstrate(owner, true));
});
@@ -104,7 +104,7 @@
itEth('destroyCollection', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress, collectionId} = await helper.eth.createFungibleCollection(owner, 'Exister', DECIMALS, 'absolutely anything', 'WIWT');
- const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const result = await collectionHelper.methods
.destroyCollection(collectionAddress)
@@ -143,7 +143,7 @@
itEth('(!negative test!) Create collection (bad lengths)', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
{
const MAX_NAME_LENGTH = 64;
const collectionName = 'A'.repeat(MAX_NAME_LENGTH + 1);
@@ -176,7 +176,7 @@
itEth('(!negative test!) cannot create collection if value !== 2', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const expects = [0n, 1n, 30n].map(async value => {
await expect(collectionHelper.methods
.createFTCollection('Peasantry', DECIMALS, 'absolutely anything', 'TWIW')
@@ -190,7 +190,7 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const peasant = helper.eth.createAccount();
const {collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Transgressed', DECIMALS, 'absolutely anything', 'YVNE');
- const peasantCollection = await helper.ethNativeContract.collection(collectionAddress, 'ft', peasant, true);
+ const peasantCollection = helper.ethNativeContract.collection(collectionAddress, 'ft', peasant, true);
const EXPECTED_ERROR = 'NoPermission';
{
const sponsor = await helper.eth.createAccountWithBalance(donor);
@@ -198,7 +198,7 @@
.setCollectionSponsor(sponsor)
.call()).to.be.rejectedWith(EXPECTED_ERROR);
- const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'ft', sponsor, true);
+ const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'ft', sponsor, true);
await expect(sponsorCollection.methods
.confirmCollectionSponsorship()
.call()).to.be.rejectedWith('ConfirmSponsorshipFail');
@@ -214,7 +214,7 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const peasant = helper.eth.createAccount();
const {collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Transgressed', DECIMALS, 'absolutely anything', 'YVNE');
- const peasantCollection = await helper.ethNativeContract.collection(collectionAddress, 'ft', peasant);
+ const peasantCollection = helper.ethNativeContract.collection(collectionAddress, 'ft', peasant);
const EXPECTED_ERROR = 'NoPermission';
{
const sponsor = await helper.eth.createAccountWithBalance(donor);
@@ -223,7 +223,7 @@
.setCollectionSponsorCross(sponsorCross)
.call()).to.be.rejectedWith(EXPECTED_ERROR);
- const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'ft', sponsor);
+ const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'ft', sponsor);
await expect(sponsorCollection.methods
.confirmCollectionSponsorship()
.call()).to.be.rejectedWith('ConfirmSponsorshipFail');
tests/src/eth/createNFTCollection.seqtest.tsdiffbeforeafterboth--- a/tests/src/eth/createNFTCollection.seqtest.ts
+++ b/tests/src/eth/createNFTCollection.seqtest.ts
@@ -72,7 +72,7 @@
const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;
const expectedCollectionAddress = helper.ethAddress.fromCollectionId(expectedCollectionId);
- const collectionHelpers = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
expect(await collectionHelpers.methods
.isCollectionExist(expectedCollectionAddress)
tests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createNFTCollection.test.ts
+++ b/tests/src/eth/createNFTCollection.test.ts
@@ -39,7 +39,7 @@
const baseUri = 'BaseURI';
const {collectionId, collectionAddress, events} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, name, description, prefix, baseUri);
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');
expect(events).to.be.deep.equal([
{
@@ -82,7 +82,7 @@
const ss58Format = helper.chain.getChainProperties().ss58Format;
const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC');
- const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);
+ const collection = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);
await collection.methods.setCollectionSponsor(sponsor).send();
let data = (await helper.nft.getData(collectionId))!;
@@ -90,7 +90,7 @@
await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('ConfirmSponsorshipFail');
- const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor, true);
+ const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor, true);
await sponsorCollection.methods.confirmCollectionSponsorship().send();
data = (await helper.nft.getData(collectionId))!;
@@ -104,7 +104,7 @@
const description = 'absolutely anything';
const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(owner, 'Sponsor', description, 'ROC');
- const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);
await collection.methods.setCollectionSponsorCross(sponsorCross).send();
@@ -125,7 +125,7 @@
itEth('Collection address exist', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';
- const collectionHelpers = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
expect(await collectionHelpers
.methods.isCollectionExist(collectionAddressForNonexistentCollection).call())
@@ -137,7 +137,7 @@
.to.be.true;
// check collectionOwner:
- const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner, true);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', owner, true);
const collectionOwner = await collectionEvm.methods.collectionOwner().call();
expect(helper.address.restoreCrossAccountFromBigInt(BigInt(collectionOwner.sub))).to.eq(helper.address.ethToSubstrate(owner, true));
});
@@ -156,7 +156,7 @@
itEth('(!negative test!) Create collection (bad lengths)', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
{
const MAX_NAME_LENGTH = 64;
const collectionName = 'A'.repeat(MAX_NAME_LENGTH + 1);
@@ -190,7 +190,7 @@
itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
await expect(collectionHelper.methods
.createNFTCollection('Peasantry', 'absolutely anything', 'CVE')
.call({value: Number(1n * nominal)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');
@@ -209,7 +209,7 @@
.setCollectionSponsor(sponsor)
.call()).to.be.rejectedWith(EXPECTED_ERROR);
- const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor, true);
+ const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor, true);
await expect(sponsorCollection.methods
.confirmCollectionSponsorship()
.call()).to.be.rejectedWith('ConfirmSponsorshipFail');
@@ -225,7 +225,7 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const malfeasant = helper.eth.createAccount();
const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Transgressed', 'absolutely anything', 'COR');
- const malfeasantCollection = await helper.ethNativeContract.collection(collectionAddress, 'nft', malfeasant);
+ const malfeasantCollection = helper.ethNativeContract.collection(collectionAddress, 'nft', malfeasant);
const EXPECTED_ERROR = 'NoPermission';
{
const sponsor = await helper.eth.createAccountWithBalance(donor);
@@ -234,7 +234,7 @@
.setCollectionSponsorCross(sponsorCross)
.call()).to.be.rejectedWith(EXPECTED_ERROR);
- const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor);
+ const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor);
await expect(sponsorCollection.methods
.confirmCollectionSponsorship()
.call()).to.be.rejectedWith('ConfirmSponsorshipFail');
@@ -249,7 +249,7 @@
itEth('destroyCollection', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
- const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const result = await collectionHelper.methods
tests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createRFTCollection.test.ts
+++ b/tests/src/eth/createRFTCollection.test.ts
@@ -95,7 +95,7 @@
const ss58Format = helper.chain.getChainProperties().ss58Format;
const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(owner, 'Sponsor', 'absolutely anything', 'ENVY');
- const collection = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner, true);
+ const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner, true);
await collection.methods.setCollectionSponsor(sponsor).send();
let data = (await helper.rft.getData(collectionId))!;
@@ -103,7 +103,7 @@
await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('ConfirmSponsorshipFail');
- const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor, true);
+ const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor, true);
await sponsorCollection.methods.confirmCollectionSponsorship().send();
data = (await helper.rft.getData(collectionId))!;
@@ -116,7 +116,7 @@
const ss58Format = helper.chain.getChainProperties().ss58Format;
const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(owner, 'Sponsor', 'absolutely anything', 'ENVY');
- const collection = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);
await collection.methods.setCollectionSponsorCross(sponsorCross).send();
@@ -125,7 +125,7 @@
await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('ConfirmSponsorshipFail');
- const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);
+ const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);
await sponsorCollection.methods.confirmCollectionSponsorship().send();
data = (await helper.rft.getData(collectionId))!;
@@ -135,7 +135,7 @@
itEth('Collection address exist', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';
- const collectionHelpers = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
expect(await collectionHelpers
.methods.isCollectionExist(collectionAddressForNonexistentCollection).call())
@@ -147,7 +147,7 @@
.to.be.true;
// check collectionOwner:
- const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner, true);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', owner, true);
const collectionOwner = await collectionEvm.methods.collectionOwner().call();
expect(helper.address.restoreCrossAccountFromBigInt(BigInt(collectionOwner.sub))).to.eq(helper.address.ethToSubstrate(owner, true));
});
@@ -167,7 +167,7 @@
itEth('(!negative test!) Create collection (bad lengths)', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
{
const MAX_NAME_LENGTH = 64;
const collectionName = 'A'.repeat(MAX_NAME_LENGTH + 1);
@@ -200,7 +200,7 @@
itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
await expect(collectionHelper.methods
.createRFTCollection('Peasantry', 'absolutely anything', 'TWIW')
.call({value: Number(1n * nominal)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');
@@ -211,7 +211,7 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const peasant = helper.eth.createAccount();
const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Transgressed', 'absolutely anything', 'YVNE');
- const peasantCollection = await helper.ethNativeContract.collection(collectionAddress, 'rft', peasant, true);
+ const peasantCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', peasant, true);
const EXPECTED_ERROR = 'NoPermission';
{
const sponsor = await helper.eth.createAccountWithBalance(donor);
@@ -219,7 +219,7 @@
.setCollectionSponsor(sponsor)
.call()).to.be.rejectedWith(EXPECTED_ERROR);
- const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor, true);
+ const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor, true);
await expect(sponsorCollection.methods
.confirmCollectionSponsorship()
.call()).to.be.rejectedWith('ConfirmSponsorshipFail');
@@ -235,7 +235,7 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const peasant = helper.eth.createAccount();
const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Transgressed', 'absolutely anything', 'YVNE');
- const peasantCollection = await helper.ethNativeContract.collection(collectionAddress, 'rft', peasant);
+ const peasantCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', peasant);
const EXPECTED_ERROR = 'NoPermission';
{
const sponsor = await helper.eth.createAccountWithBalance(donor);
@@ -244,7 +244,7 @@
.setCollectionSponsorCross(sponsorCross)
.call()).to.be.rejectedWith(EXPECTED_ERROR);
- const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);
+ const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);
await expect(sponsorCollection.methods
.confirmCollectionSponsorship()
.call()).to.be.rejectedWith('ConfirmSponsorshipFail');
@@ -259,7 +259,7 @@
itEth('destroyCollection', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress, collectionId} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
- const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
await expect(collectionHelper.methods
.destroyCollection(collectionAddress)
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -207,7 +207,7 @@
}
private async createTransaction() {
- const collectionHelper = await this.helper.ethNativeContract.collectionHelpers(this.signer);
+ const collectionHelper = this.helper.ethNativeContract.collectionHelpers(this.signer);
let collectionMode;
switch (this.data.collectionMode) {
case 'nft': collectionMode = CollectionMode.Nonfungible; break;
tests/src/util/index.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import * as path from 'path';5import * as crypto from 'crypto';6import {IKeyringPair} from '@polkadot/types/types/interfaces';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import chaiSubset from 'chai-subset';10import {Context} from 'mocha';11import config from '../config';12import {ChainHelperBase} from './playgrounds/unique';13import {ILogger} from './playgrounds/types';14import {DevUniqueHelper, SilentLogger, SilentConsole, DevMoonbeamHelper, DevMoonriverHelper, DevAcalaHelper, DevKaruraHelper, DevRelayHelper, DevWestmintHelper, DevStatemineHelper, DevStatemintHelper, DevAstarHelper, DevShidenHelper} from './playgrounds/unique.dev';15import {dirname} from 'path';16import {fileURLToPath} from 'url';1718chai.use(chaiAsPromised);19chai.use(chaiSubset);20export const expect = chai.expect;2122const getTestHash = (filename: string) => crypto.createHash('md5').update(filename).digest('hex');2324export const getTestSeed = (filename: string) => `//Alice+${getTestHash(filename)}`;2526async function usingPlaygroundsGeneral<T extends ChainHelperBase, R = void>(27 helperType: new (logger: ILogger) => T,28 url: string,29 code: (helper: T, privateKey: (seed: string | { filename?: string, url?: string, ignoreFundsPresence?: boolean }) => Promise<IKeyringPair>) => Promise<R>,30): Promise<R> {31 const silentConsole = new SilentConsole();32 silentConsole.enable();3334 const helper = new helperType(new SilentLogger());35 let result;36 try {37 await helper.connect(url);38 const ss58Format = helper.chain.getChainProperties().ss58Format;39 const privateKey = async (seed: string | {filename?: string, url?: string, ignoreFundsPresence?: boolean}) => {40 if(typeof seed === 'string') {41 return helper.util.fromSeed(seed, ss58Format);42 }43 if(seed.url) {44 const {filename} = makeNames(seed.url);45 seed.filename = filename;46 } else if(seed.filename) {47 // Pass48 } else {49 throw new Error('no url nor filename set');50 }51 const actualSeed = getTestSeed(seed.filename);52 let account = helper.util.fromSeed(actualSeed, ss58Format);53 // here's to hoping that no54 if(!seed.ignoreFundsPresence && ((helper as any)['balance'] == undefined || await (helper as any).balance.getSubstrate(account.address) < MINIMUM_DONOR_FUND)) {55 console.warn(`${path.basename(seed.filename)}: Not enough funds present on the filename account. Using the default one as the donor instead.`);56 account = helper.util.fromSeed('//Alice', ss58Format);57 }58 return account;59 };60 result = await code(helper, privateKey);61 }62 finally {63 await helper.disconnect();64 silentConsole.disable();65 }66 return result as any as R;67}6869export const usingPlaygrounds = <R = void>(code: (helper: DevUniqueHelper, privateKey: (seed: string | {filename?: string, url?: string, ignoreFundsPresence?: boolean}) => Promise<IKeyringPair>) => Promise<R>, url: string = config.substrateUrl) => usingPlaygroundsGeneral<DevUniqueHelper, R>(DevUniqueHelper, url, code);7071export const usingWestmintPlaygrounds = (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevWestmintHelper>(DevWestmintHelper, url, code);7273export const usingStateminePlaygrounds = (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevStatemineHelper>(DevWestmintHelper, url, code);7475export const usingStatemintPlaygrounds = (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevStatemintHelper>(DevWestmintHelper, url, code);7677export const usingRelayPlaygrounds = (url: string, code: (helper: DevRelayHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevRelayHelper>(DevRelayHelper, url, code);7879export const usingAcalaPlaygrounds = (url: string, code: (helper: DevAcalaHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevAcalaHelper>(DevAcalaHelper, url, code);8081export const usingKaruraPlaygrounds = (url: string, code: (helper: DevKaruraHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevKaruraHelper>(DevAcalaHelper, url, code);8283export const usingMoonbeamPlaygrounds = (url: string, code: (helper: DevMoonbeamHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevMoonbeamHelper>(DevMoonbeamHelper, url, code);8485export const usingMoonriverPlaygrounds = (url: string, code: (helper: DevMoonbeamHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevMoonriverHelper>(DevMoonriverHelper, url, code);8687export const usingAstarPlaygrounds = (url: string, code: (helper: DevAstarHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevAstarHelper>(DevAstarHelper, url, code);8889export const usingShidenPlaygrounds = (url: string, code: (helper: DevShidenHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevShidenHelper>(DevShidenHelper, url, code);9091export const MINIMUM_DONOR_FUND = 4_000_000n;92export const DONOR_FUNDING = 4_000_000n;9394// App-promotion periods:95export const LOCKING_PERIOD = 12n; // 12 blocks of relay96export const UNLOCKING_PERIOD = 6n; // 6 blocks of parachain9798// Native contracts99export const COLLECTION_HELPER = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';100export const CONTRACT_HELPER = '0x842899ECF380553E8a4de75bF534cdf6fBF64049';101102export enum Pallets {103 Inflation = 'inflation',104 ReFungible = 'refungible',105 Fungible = 'fungible',106 NFT = 'nonfungible',107 Scheduler = 'scheduler',108 UniqueScheduler = 'uniqueScheduler',109 AppPromotion = 'apppromotion',110 CollatorSelection = 'collatorselection',111 Session = 'session',112 Identity = 'identity',113 Democracy = 'democracy',114 Council = 'council',115 //CouncilMembership = 'councilmembership',116 TechnicalCommittee = 'technicalcommittee',117 Fellowship = 'fellowshipcollective',118 Preimage = 'preimage',119 Maintenance = 'maintenance',120 TestUtils = 'testutils',121}122123export function requirePalletsOrSkip(test: Context, helper: DevUniqueHelper, requiredPallets: readonly string[]) {124 const missingPallets = helper.fetchMissingPalletNames(requiredPallets);125126 if(missingPallets.length > 0) {127 const skipMsg = `\tSkipping test '${test.test?.title}'.\n\tThe following pallets are missing:\n\t- ${missingPallets.join('\n\t- ')}`;128 console.warn('\x1b[38:5:208m%s\x1b[0m', skipMsg);129 test.skip();130 }131}132133export function itSub(name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: readonly string[] } = {}) {134 (opts.only ? it.only :135 opts.skip ? it.skip : it)(name, async function () {136 await usingPlaygrounds(async (helper, privateKey) => {137 if(opts.requiredPallets) {138 requirePalletsOrSkip(this, helper, opts.requiredPallets);139 }140141 await cb({helper, privateKey});142 });143 });144}145export function itSubIfWithPallet(name: string, required: readonly string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: readonly string[] } = {}) {146 return itSub(name, cb, {requiredPallets: required, ...opts});147}148itSub.only = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSub(name, cb, {only: true});149itSub.skip = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSub(name, cb, {skip: true});150151itSubIfWithPallet.only = (name: string, required: readonly string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSubIfWithPallet(name, required, cb, {only: true});152itSubIfWithPallet.skip = (name: string, required: readonly string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSubIfWithPallet(name, required, cb, {skip: true});153itSub.ifWithPallets = itSubIfWithPallet;154155export type SchedKind = 'anon' | 'named';156157export function itSched(158 name: string,159 cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any,160 opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {},161) {162 itSub(name + ' (anonymous scheduling)', (apis) => cb('anon', apis), opts);163 itSub(name + ' (named scheduling)', (apis) => cb('named', apis), opts);164}165itSched.only = (name: string, cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSched(name, cb, {only: true});166itSched.skip = (name: string, cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSched(name, cb, {skip: true});167itSched.ifWithPallets = itSchedIfWithPallets;168169function itSchedIfWithPallets(name: string, required: string[], cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {170 return itSched(name, cb, {requiredPallets: required, ...opts});171}172173export function describeXCM(title: string, fn: (this: Mocha.Suite) => void, opts: {skip?: boolean} = {}) {174 (process.env.RUN_XCM_TESTS && !opts.skip175 ? describe176 : describe.skip)(title, fn);177}178179describeXCM.skip = (name: string, fn: (this: Mocha.Suite) => void) => describeXCM(name, fn, {skip: true});180181export function describeGov(title: string, fn: (this: Mocha.Suite) => void, opts: {skip?: boolean} = {}) {182 (process.env.RUN_GOV_TESTS && !opts.skip183 ? describe184 : describe.skip)(title, fn);185}186187describeGov.skip = (name: string, fn: (this: Mocha.Suite) => void) => describeGov(name, fn, {skip: true});188189export function sizeOfInt(i: number) {190 if(i < 0 || i > 0xffffffff) throw new Error('out of range');191 if(i < 0b11_1111) {192 return 1;193 } else if(i < 0b11_1111_1111_1111) {194 return 2;195 } else if(i < 0b11_1111_1111_1111_1111_1111_1111_1111) {196 return 4;197 } else {198 return 5;199 }200}201202const UTF8_ENCODER = new TextEncoder();203export function sizeOfEncodedStr(v: string) {204 const encoded = UTF8_ENCODER.encode(v);205 return sizeOfInt(encoded.length) + encoded.length;206}207208export function sizeOfProperty(prop: {key: string, value: string}) {209 return sizeOfEncodedStr(prop.key) + sizeOfEncodedStr(prop.value);210}211212export function makeNames(url: string) {213 const filename = fileURLToPath(url);214 return {215 filename,216 dirname: dirname(filename),217 };218}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import * as path from 'path';5import * as crypto from 'crypto';6import {IKeyringPair} from '@polkadot/types/types/interfaces';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import chaiSubset from 'chai-subset';10import {Context} from 'mocha';11import config from '../config';12import {ChainHelperBase} from './playgrounds/unique';13import {ILogger} from './playgrounds/types';14import {DevUniqueHelper, SilentLogger, SilentConsole, DevMoonbeamHelper, DevMoonriverHelper, DevAcalaHelper, DevKaruraHelper, DevRelayHelper, DevWestmintHelper, DevStatemineHelper, DevStatemintHelper, DevAstarHelper, DevShidenHelper} from './playgrounds/unique.dev';15import {dirname} from 'path';16import {fileURLToPath} from 'url';1718chai.config.truncateThreshold = 0;19chai.use(chaiAsPromised);20chai.use(chaiSubset);21export const expect = chai.expect;2223const getTestHash = (filename: string) => crypto.createHash('md5').update(filename).digest('hex');2425export const getTestSeed = (filename: string) => `//Alice+${getTestHash(filename)}`;2627async function usingPlaygroundsGeneral<T extends ChainHelperBase, R = void>(28 helperType: new (logger: ILogger) => T,29 url: string,30 code: (helper: T, privateKey: (seed: string | { filename?: string, url?: string, ignoreFundsPresence?: boolean }) => Promise<IKeyringPair>) => Promise<R>,31): Promise<R> {32 const silentConsole = new SilentConsole();33 silentConsole.enable();3435 const helper = new helperType(new SilentLogger());36 let result;37 try {38 await helper.connect(url);39 const ss58Format = helper.chain.getChainProperties().ss58Format;40 const privateKey = async (seed: string | {filename?: string, url?: string, ignoreFundsPresence?: boolean}) => {41 if(typeof seed === 'string') {42 return helper.util.fromSeed(seed, ss58Format);43 }44 if(seed.url) {45 const {filename} = makeNames(seed.url);46 seed.filename = filename;47 } else if(seed.filename) {48 // Pass49 } else {50 throw new Error('no url nor filename set');51 }52 const actualSeed = getTestSeed(seed.filename);53 let account = helper.util.fromSeed(actualSeed, ss58Format);54 // here's to hoping that no55 if(!seed.ignoreFundsPresence && ((helper as any)['balance'] == undefined || await (helper as any).balance.getSubstrate(account.address) < MINIMUM_DONOR_FUND)) {56 console.warn(`${path.basename(seed.filename)}: Not enough funds present on the filename account. Using the default one as the donor instead.`);57 account = helper.util.fromSeed('//Alice', ss58Format);58 }59 return account;60 };61 result = await code(helper, privateKey);62 }63 finally {64 await helper.disconnect();65 silentConsole.disable();66 }67 return result as any as R;68}6970export const usingPlaygrounds = <R = void>(code: (helper: DevUniqueHelper, privateKey: (seed: string | {filename?: string, url?: string, ignoreFundsPresence?: boolean}) => Promise<IKeyringPair>) => Promise<R>, url: string = config.substrateUrl) => usingPlaygroundsGeneral<DevUniqueHelper, R>(DevUniqueHelper, url, code);7172export const usingWestmintPlaygrounds = (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevWestmintHelper>(DevWestmintHelper, url, code);7374export const usingStateminePlaygrounds = (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevStatemineHelper>(DevWestmintHelper, url, code);7576export const usingStatemintPlaygrounds = (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevStatemintHelper>(DevWestmintHelper, url, code);7778export const usingRelayPlaygrounds = (url: string, code: (helper: DevRelayHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevRelayHelper>(DevRelayHelper, url, code);7980export const usingAcalaPlaygrounds = (url: string, code: (helper: DevAcalaHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevAcalaHelper>(DevAcalaHelper, url, code);8182export const usingKaruraPlaygrounds = (url: string, code: (helper: DevKaruraHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevKaruraHelper>(DevAcalaHelper, url, code);8384export const usingMoonbeamPlaygrounds = (url: string, code: (helper: DevMoonbeamHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevMoonbeamHelper>(DevMoonbeamHelper, url, code);8586export const usingMoonriverPlaygrounds = (url: string, code: (helper: DevMoonbeamHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevMoonriverHelper>(DevMoonriverHelper, url, code);8788export const usingAstarPlaygrounds = (url: string, code: (helper: DevAstarHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevAstarHelper>(DevAstarHelper, url, code);8990export const usingShidenPlaygrounds = (url: string, code: (helper: DevShidenHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevShidenHelper>(DevShidenHelper, url, code);9192export const MINIMUM_DONOR_FUND = 4_000_000n;93export const DONOR_FUNDING = 4_000_000n;9495// App-promotion periods:96export const LOCKING_PERIOD = 12n; // 12 blocks of relay97export const UNLOCKING_PERIOD = 6n; // 6 blocks of parachain9899// Native contracts100export const COLLECTION_HELPER = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';101export const CONTRACT_HELPER = '0x842899ECF380553E8a4de75bF534cdf6fBF64049';102103export enum Pallets {104 Inflation = 'inflation',105 ReFungible = 'refungible',106 Fungible = 'fungible',107 NFT = 'nonfungible',108 Scheduler = 'scheduler',109 UniqueScheduler = 'uniqueScheduler',110 AppPromotion = 'apppromotion',111 CollatorSelection = 'collatorselection',112 Session = 'session',113 Identity = 'identity',114 Democracy = 'democracy',115 Council = 'council',116 //CouncilMembership = 'councilmembership',117 TechnicalCommittee = 'technicalcommittee',118 Fellowship = 'fellowshipcollective',119 Preimage = 'preimage',120 Maintenance = 'maintenance',121 TestUtils = 'testutils',122}123124export function requirePalletsOrSkip(test: Context, helper: DevUniqueHelper, requiredPallets: readonly string[]) {125 const missingPallets = helper.fetchMissingPalletNames(requiredPallets);126127 if(missingPallets.length > 0) {128 const skipMsg = `\tSkipping test '${test.test?.title}'.\n\tThe following pallets are missing:\n\t- ${missingPallets.join('\n\t- ')}`;129 console.warn('\x1b[38:5:208m%s\x1b[0m', skipMsg);130 test.skip();131 }132}133134export function itSub(name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: readonly string[] } = {}) {135 (opts.only ? it.only :136 opts.skip ? it.skip : it)(name, async function () {137 await usingPlaygrounds(async (helper, privateKey) => {138 if(opts.requiredPallets) {139 requirePalletsOrSkip(this, helper, opts.requiredPallets);140 }141142 await cb({helper, privateKey});143 });144 });145}146export function itSubIfWithPallet(name: string, required: readonly string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: readonly string[] } = {}) {147 return itSub(name, cb, {requiredPallets: required, ...opts});148}149itSub.only = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSub(name, cb, {only: true});150itSub.skip = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSub(name, cb, {skip: true});151152itSubIfWithPallet.only = (name: string, required: readonly string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSubIfWithPallet(name, required, cb, {only: true});153itSubIfWithPallet.skip = (name: string, required: readonly string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSubIfWithPallet(name, required, cb, {skip: true});154itSub.ifWithPallets = itSubIfWithPallet;155156export type SchedKind = 'anon' | 'named';157158export function itSched(159 name: string,160 cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any,161 opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {},162) {163 itSub(name + ' (anonymous scheduling)', (apis) => cb('anon', apis), opts);164 itSub(name + ' (named scheduling)', (apis) => cb('named', apis), opts);165}166itSched.only = (name: string, cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSched(name, cb, {only: true});167itSched.skip = (name: string, cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSched(name, cb, {skip: true});168itSched.ifWithPallets = itSchedIfWithPallets;169170function itSchedIfWithPallets(name: string, required: string[], cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {171 return itSched(name, cb, {requiredPallets: required, ...opts});172}173174export function describeXCM(title: string, fn: (this: Mocha.Suite) => void, opts: {skip?: boolean} = {}) {175 (process.env.RUN_XCM_TESTS && !opts.skip176 ? describe177 : describe.skip)(title, fn);178}179180describeXCM.skip = (name: string, fn: (this: Mocha.Suite) => void) => describeXCM(name, fn, {skip: true});181182export function describeGov(title: string, fn: (this: Mocha.Suite) => void, opts: {skip?: boolean} = {}) {183 (process.env.RUN_GOV_TESTS && !opts.skip184 ? describe185 : describe.skip)(title, fn);186}187188describeGov.skip = (name: string, fn: (this: Mocha.Suite) => void) => describeGov(name, fn, {skip: true});189190export function sizeOfInt(i: number) {191 if(i < 0 || i > 0xffffffff) throw new Error('out of range');192 if(i < 0b11_1111) {193 return 1;194 } else if(i < 0b11_1111_1111_1111) {195 return 2;196 } else if(i < 0b11_1111_1111_1111_1111_1111_1111_1111) {197 return 4;198 } else {199 return 5;200 }201}202203const UTF8_ENCODER = new TextEncoder();204export function sizeOfEncodedStr(v: string) {205 const encoded = UTF8_ENCODER.encode(v);206 return sizeOfInt(encoded.length) + encoded.length;207}208209export function sizeOfProperty(prop: {key: string, value: string}) {210 return sizeOfEncodedStr(prop.key) + sizeOfEncodedStr(prop.value);211}212213export function makeNames(url: string) {214 const filename = fileURLToPath(url);215 return {216 filename,217 dirname: dirname(filename),218 };219}tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -41,7 +41,9 @@
for(const arg of args) {
if(typeof arg !== 'string')
continue;
- if(arg.includes('1000:: Normal connection closure') || arg.includes('Not decorating unknown runtime apis:') || arg.includes('RPC methods not decorated:') || arg === 'Normal connection closure')
+ const skippedWarnings = ['1000:: Normal connection closure', 'Not decorating unknown runtime apis:', 'RPC methods not decorated:', 'Not decorating runtime apis'];
+ const needToSkip = skippedWarnings.reduce((a, b) => a || arg.includes(b), false);
+ if(needToSkip || arg === 'Normal connection closure')
return;
}
printer(...args);