difftreelog
fix PR
in: master
2 files changed
tests/src/eth/events.test.tsdiffbeforeafterboth--- a/tests/src/eth/events.test.ts
+++ b/tests/src/eth/events.test.ts
@@ -17,8 +17,9 @@
import {expect} from 'chai';
import {IKeyringPair} from '@polkadot/types/types';
import {EthUniqueHelper, itEth, usingEthPlaygrounds} from './util';
-import {TCollectionMode} from '../util/playgrounds/types';
+import {IEvent, TCollectionMode} from '../util/playgrounds/types';
import {Pallets, requirePalletsOrSkip} from '../util';
+import {NormalizedEvent} from './util/playgrounds/types';
let donor: IKeyringPair;
@@ -28,6 +29,11 @@
});
});
+function clearEvents(ethEvents: NormalizedEvent[], subEvents: IEvent[]) {
+ ethEvents.splice(0);
+ subEvents.splice(0);
+}
+
async function testCollectionCreatedAndDestroy(helper: EthUniqueHelper, mode: TCollectionMode) {
const owner = await helper.eth.createAccountWithBalance(donor);
const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionCreated', 'CollectionDestroyed']}]);
@@ -44,8 +50,7 @@
},
]);
expect(subEvents).to.be.like([{method: 'CollectionCreated'}]);
- ethEvents.pop();
- subEvents.pop();
+ clearEvents(ethEvents, subEvents);
}
{
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
@@ -69,12 +74,12 @@
const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
+ const ethEvents: any = [];
+ collectionHelper.events.allEvents((_: any, event: any) => {
+ ethEvents.push(event);
+ });
const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionPropertySet', 'CollectionPropertyDeleted']}]);
{
- const ethEvents: any = [];
- collectionHelper.events.allEvents((_: any, event: any) => {
- ethEvents.push(event);
- });
await collection.methods.setCollectionProperties([{key: 'A', value: [0,1,2,3]}]).send({from:owner});
await helper.wait.newBlocks(1);
expect(ethEvents).to.be.like([
@@ -86,13 +91,9 @@
},
]);
expect(subEvents).to.be.like([{method: 'CollectionPropertySet'}]);
- subEvents.pop();
+ clearEvents(ethEvents, subEvents);
}
{
- const ethEvents: any = [];
- collectionHelper.events.allEvents((_: any, event: any) => {
- ethEvents.push(event);
- });
await collection.methods.deleteCollectionProperties(['A']).send({from:owner});
await helper.wait.newBlocks(1);
expect(ethEvents).to.be.like([
@@ -113,14 +114,14 @@
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
- const eethEvents: any = [];
+ const ethEvents: any = [];
collectionHelper.events.allEvents((_: any, event: any) => {
- eethEvents.push(event);
+ ethEvents.push(event);
});
const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['PropertyPermissionSet']}]);
await collection.methods.setTokenPropertyPermission('testKey', true, true, true).send({from: owner});
await helper.wait.newBlocks(1);
- expect(eethEvents).to.be.like([
+ expect(ethEvents).to.be.like([
{
event: 'CollectionChanged',
returnValues: {
@@ -156,8 +157,7 @@
},
]);
expect(subEvents).to.be.like([{method: 'AllowListAddressAdded'}]);
- ethEvents.pop();
- subEvents.pop();
+ clearEvents(ethEvents, subEvents);
}
{
await collection.methods.removeFromCollectionAllowListCross(user).send({from: owner});
@@ -176,7 +176,7 @@
unsubscribe();
}
-async function testCollectionAdminAddedAndCollectionAdminRemoved(helper: EthUniqueHelper, mode: TCollectionMode) {
+async function testCollectionAdminAddedAndRemoved(helper: EthUniqueHelper, mode: TCollectionMode) {
const owner = await helper.eth.createAccountWithBalance(donor);
const user = helper.ethCrossAccount.createAccount();
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
@@ -199,8 +199,7 @@
},
]);
expect(subEvents).to.be.like([{method: 'CollectionAdminAdded'}]);
- ethEvents.pop();
- subEvents.pop();
+ clearEvents(ethEvents, subEvents);
}
{
await collection.methods.removeCollectionAdminCross(user).send({from: owner});
@@ -293,8 +292,7 @@
},
]);
expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);
- ethEvents.pop();
- subEvents.pop();
+ clearEvents(ethEvents, subEvents);
}
{
await collection.methods.setCollectionAccess(1).send({from: owner});
@@ -312,7 +310,7 @@
unsubscribe();
}
-async function testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper: EthUniqueHelper, mode: TCollectionMode) {
+async function testCollectionSponsorSetAndConfirmedAndThenRemoved(helper: EthUniqueHelper, mode: TCollectionMode) {
const owner = await helper.eth.createAccountWithBalance(donor);
const sponsor = await helper.ethCrossAccount.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
@@ -337,8 +335,7 @@
},
]);
expect(subEvents).to.be.like([{method: 'CollectionSponsorSet'}]);
- ethEvents.pop();
- subEvents.pop();
+ clearEvents(ethEvents, subEvents);
}
{
await collection.methods.confirmCollectionSponsorship().send({from: sponsor.eth});
@@ -352,8 +349,7 @@
},
]);
expect(subEvents).to.be.like([{method: 'SponsorshipConfirmed'}]);
- ethEvents.pop();
- subEvents.pop();
+ clearEvents(ethEvents, subEvents);
}
{
await collection.methods.removeCollectionSponsor().send({from: owner});
@@ -371,7 +367,7 @@
unsubscribe();
}
-async function testTokenPropertySetAndTokenPropertyDeleted(helper: EthUniqueHelper, mode: TCollectionMode) {
+async function testTokenPropertySetAndDeleted(helper: EthUniqueHelper, mode: TCollectionMode) {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
@@ -398,8 +394,7 @@
},
]);
expect(subEvents).to.be.like([{method: 'TokenPropertySet'}]);
- ethEvents.pop();
- subEvents.pop();
+ clearEvents(ethEvents, subEvents);
}
{
await collection.methods.deleteProperties(tokenId, ['A']).send({from: owner});
@@ -417,7 +412,7 @@
unsubscribe();
}
-describe('[FT] Sync sub & eth events', () => {
+describe.only('[FT] Sync sub & eth events', () => {
const mode: TCollectionMode = 'ft';
itEth('CollectionCreated and CollectionDestroyed events', async ({helper}) => {
@@ -433,7 +428,7 @@
});
itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => {
- await testCollectionAdminAddedAndCollectionAdminRemoved(helper, mode);
+ await testCollectionAdminAddedAndRemoved(helper, mode);
});
itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => {
@@ -449,11 +444,11 @@
});
itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {
- await testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper, mode);
+ await testCollectionSponsorSetAndConfirmedAndThenRemoved(helper, mode);
});
});
-describe('[NFT] Sync sub & eth events', () => {
+describe.only('[NFT] Sync sub & eth events', () => {
const mode: TCollectionMode = 'nft';
itEth('CollectionCreated and CollectionDestroyed events', async ({helper}) => {
@@ -473,7 +468,7 @@
});
itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => {
- await testCollectionAdminAddedAndCollectionAdminRemoved(helper, mode);
+ await testCollectionAdminAddedAndRemoved(helper, mode);
});
itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => {
@@ -489,15 +484,15 @@
});
itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {
- await testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper, mode);
+ await testCollectionSponsorSetAndConfirmedAndThenRemoved(helper, mode);
});
itEth('CollectionChanged event for TokenPropertySet, TokenPropertyDeleted', async ({helper}) => {
- await testTokenPropertySetAndTokenPropertyDeleted(helper, mode);
+ await testTokenPropertySetAndDeleted(helper, mode);
});
});
-describe('[RFT] Sync sub & eth events', () => {
+describe.only('[RFT] Sync sub & eth events', () => {
const mode: TCollectionMode = 'rft';
before(async function() {
@@ -524,7 +519,7 @@
});
itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => {
- await testCollectionAdminAddedAndCollectionAdminRemoved(helper, mode);
+ await testCollectionAdminAddedAndRemoved(helper, mode);
});
itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => {
@@ -540,10 +535,10 @@
});
itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {
- await testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper, mode);
+ await testCollectionSponsorSetAndConfirmedAndThenRemoved(helper, mode);
});
itEth('CollectionChanged event for TokenPropertySet, TokenPropertyDeleted', async ({helper}) => {
- await testTokenPropertySetAndTokenPropertyDeleted(helper, mode);
+ await testTokenPropertySetAndDeleted(helper, mode);
});
});
tests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util';1920describe('integration test: ext. removeCollectionSponsor():', () => {21 let donor: IKeyringPair;22 let alice: IKeyringPair;23 let bob: IKeyringPair;24 let charlie: IKeyringPair;2526 before(async () => {27 await usingPlaygrounds(async (helper, privateKey) => {28 donor = await privateKey({filename: __filename});29 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);30 });31 });3233 itSub('Removing NFT collection sponsor stops sponsorship', async ({helper}) => {34 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-1', tokenPrefix: 'RCS'});35 await collection.setSponsor(alice, bob.address);36 await collection.confirmSponsorship(bob);37 await collection.removeSponsor(alice);3839 // Find unused address40 const [zeroBalance] = await helper.arrange.createAccounts([0n], donor);4142 // Mint token for unused address43 const token = await collection.mintToken(alice, {Substrate: zeroBalance.address});4445 // Transfer this tokens from unused address to Alice - should fail46 const sponsorBalanceBefore = await helper.balance.getSubstrate(bob.address);47 await expect(token.transfer(zeroBalance, {Substrate: alice.address}))48 .to.be.rejectedWith('Inability to pay some fees');49 const sponsorBalanceAfter = await helper.balance.getSubstrate(bob.address);5051 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);52 });5354 itSub('Remove a sponsor after it was already removed', async ({helper}) => {55 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-2', tokenPrefix: 'RCS'});56 await collection.setSponsor(alice, bob.address);57 await collection.confirmSponsorship(bob);58 await expect(collection.removeSponsor(alice)).to.not.be.rejected;59 await expect(collection.removeSponsor(alice)).to.not.be.rejected;60 });6162 itSub('Remove sponsor in a collection that never had the sponsor set', async ({helper}) => {63 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-3', tokenPrefix: 'RCS'});64 await expect(collection.removeSponsor(alice)).to.not.be.rejected;65 });6667 itSub('Remove sponsor for a collection that had the sponsor set, but not confirmed', async ({helper}) => {68 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-4', tokenPrefix: 'RCS'});69 await collection.setSponsor(alice, bob.address);70 await expect(collection.removeSponsor(alice)).to.not.be.rejected;71 });7273 itSub('Remove sponsor for a collection with collection admin permissions', async ({helper}) => {74 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-1', tokenPrefix: 'RCS'});75 await collection.setSponsor(alice, bob.address);76 await collection.addAdmin(alice, {Substrate: charlie.address});77 await expect(collection.removeSponsor(charlie)).not.to.be.rejected;78 });79});8081describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {82 let alice: IKeyringPair;83 let bob: IKeyringPair;84 let charlie: IKeyringPair;8586 before(async () => {87 await usingPlaygrounds(async (helper, privateKey) => {88 const donor = await privateKey({filename: __filename});89 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);90 });91 });9293 itSub('(!negative test!) Remove sponsor for a collection that never existed', async ({helper}) => {94 const collectionId = (1 << 32) - 1;95 await expect(helper.collection.removeSponsor(alice, collectionId)).to.be.rejectedWith(/common\.CollectionNotFound/);96 });9798 itSub('(!negative test!) Remove sponsor for a collection by regular user', async ({helper}) => {99 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-2', tokenPrefix: 'RCS'});100 await collection.setSponsor(alice, bob.address);101 await expect(collection.removeSponsor(charlie)).to.be.rejectedWith(/common\.NoPermission/);102 });103104 itSub('(!negative test!) Remove sponsor in a destroyed collection', async ({helper}) => {105 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-3', tokenPrefix: 'RCS'});106 await collection.setSponsor(alice, bob.address);107 await collection.burn(alice);108 await expect(collection.removeSponsor(alice)).to.be.rejectedWith(/common\.CollectionNotFound/);109 });110111 itSub('Set - remove - confirm: fails', async ({helper}) => {112 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-4', tokenPrefix: 'RCS'});113 await collection.setSponsor(alice, bob.address);114 await collection.removeSponsor(alice);115 await expect(collection.confirmSponsorship(bob)).to.be.rejectedWith(/common\.ConfirmSponsorshipFail/);116 });117118 itSub('Set - confirm - remove - confirm: Sponsor cannot come back', async ({helper}) => {119 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-5', tokenPrefix: 'RCS'});120 await collection.setSponsor(alice, bob.address);121 await collection.confirmSponsorship(bob);122 await collection.removeSponsor(alice);123 await expect(collection.confirmSponsorship(bob)).to.be.rejectedWith(/common\.ConfirmSponsorshipFail/);124 });125});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util';1920describe('integration test: ext. removeCollectionSponsor():', () => {21 let donor: IKeyringPair;22 let alice: IKeyringPair;23 let bob: IKeyringPair;24 let charlie: IKeyringPair;2526 before(async () => {27 await usingPlaygrounds(async (helper, privateKey) => {28 donor = await privateKey({filename: __filename});29 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);30 });31 });3233 itSub('Removing NFT collection sponsor stops sponsorship', async ({helper}) => {34 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-1', tokenPrefix: 'RCS'});35 await collection.setSponsor(alice, bob.address);36 await collection.confirmSponsorship(bob);37 await collection.removeSponsor(alice);3839 // Find unused address40 const [zeroBalance] = await helper.arrange.createAccounts([0n], donor);4142 // Mint token for unused address43 const token = await collection.mintToken(alice, {Substrate: zeroBalance.address});4445 // Transfer this tokens from unused address to Alice - should fail46 const sponsorBalanceBefore = await helper.balance.getSubstrate(bob.address);47 await expect(token.transfer(zeroBalance, {Substrate: alice.address}))48 .to.be.rejectedWith('Inability to pay some fees');49 const sponsorBalanceAfter = await helper.balance.getSubstrate(bob.address);5051 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);52 });5354 itSub('Remove a sponsor after it was already removed', async ({helper}) => {55 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-2', tokenPrefix: 'RCS'});56 await collection.setSponsor(alice, bob.address);57 await collection.confirmSponsorship(bob);58 await expect(collection.removeSponsor(alice)).to.not.be.rejected;59 await expect(collection.removeSponsor(alice)).to.not.be.rejected;60 });6162 itSub('Remove sponsor in a collection that never had the sponsor set', async ({helper}) => {63 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-3', tokenPrefix: 'RCS'});64 await expect(collection.removeSponsor(alice)).to.not.be.rejected;65 });6667 itSub('Remove sponsor for a collection that had the sponsor set, but not confirmed', async ({helper}) => {68 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-4', tokenPrefix: 'RCS'});69 await collection.setSponsor(alice, bob.address);70 await expect(collection.removeSponsor(alice)).to.not.be.rejected;71 });7273 itSub('Remove a sponsor from a collection with collection admin permissions', async ({helper}) => {74 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-1', tokenPrefix: 'RCS'});75 await collection.setSponsor(alice, bob.address);76 await collection.addAdmin(alice, {Substrate: charlie.address});77 await expect(collection.removeSponsor(charlie)).not.to.be.rejected;78 });79});8081describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {82 let alice: IKeyringPair;83 let bob: IKeyringPair;84 let charlie: IKeyringPair;8586 before(async () => {87 await usingPlaygrounds(async (helper, privateKey) => {88 const donor = await privateKey({filename: __filename});89 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);90 });91 });9293 itSub('(!negative test!) Remove sponsor for a collection that never existed', async ({helper}) => {94 const collectionId = (1 << 32) - 1;95 await expect(helper.collection.removeSponsor(alice, collectionId)).to.be.rejectedWith(/common\.CollectionNotFound/);96 });9798 itSub('(!negative test!) Remove sponsor for a collection by regular user', async ({helper}) => {99 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-2', tokenPrefix: 'RCS'});100 await collection.setSponsor(alice, bob.address);101 await expect(collection.removeSponsor(charlie)).to.be.rejectedWith(/common\.NoPermission/);102 });103104 itSub('(!negative test!) Remove sponsor in a destroyed collection', async ({helper}) => {105 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-3', tokenPrefix: 'RCS'});106 await collection.setSponsor(alice, bob.address);107 await collection.burn(alice);108 await expect(collection.removeSponsor(alice)).to.be.rejectedWith(/common\.CollectionNotFound/);109 });110111 itSub('Set - remove - confirm: fails', async ({helper}) => {112 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-4', tokenPrefix: 'RCS'});113 await collection.setSponsor(alice, bob.address);114 await collection.removeSponsor(alice);115 await expect(collection.confirmSponsorship(bob)).to.be.rejectedWith(/common\.ConfirmSponsorshipFail/);116 });117118 itSub('Set - confirm - remove - confirm: Sponsor cannot come back', async ({helper}) => {119 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-5', tokenPrefix: 'RCS'});120 await collection.setSponsor(alice, bob.address);121 await collection.confirmSponsorship(bob);122 await collection.removeSponsor(alice);123 await expect(collection.confirmSponsorship(bob)).to.be.rejectedWith(/common\.ConfirmSponsorshipFail/);124 });125});