--- /dev/null +++ b/tests/src/collision-tests/admVsOwnerChanges.test.ts @@ -0,0 +1,55 @@ +import { IKeyringPair } from '@polkadot/types/types'; +import chai from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +import { alicesPublicKey, bobsPublicKey } from '../accounts'; +import getBalance from '../substrate/get-balance'; +import privateKey from '../substrate/privateKey'; +import usingApi, { submitTransactionAsync } from '../substrate/substrate-api'; +import waitNewBlocks from '../substrate/wait-new-blocks'; +import { + createCollectionExpectSuccess, + createItemExpectSuccess, + setCollectionSponsorExpectSuccess, +} from '../util/helpers'; + +chai.use(chaiAsPromised); +const expect = chai.expect; +let Alice: IKeyringPair; +let Bob: IKeyringPair; +let Ferdie: IKeyringPair; + +before(async () => { + await usingApi(async () => { + Alice = privateKey('//Alice'); + Bob = privateKey('//Bob'); + Ferdie = privateKey('//Ferdie'); + }); +}); + +describe('Admin vs Owner changes token: ', () => { + // tslint:disable-next-line: max-line-length + it('The collection admin changes the owner of the token and in the same block the current owner transfers the token to another address ', async () => { + await usingApi(async (api) => { + const collectionId = await createCollectionExpectSuccess(); + const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, Bob.address); + await submitTransactionAsync(Alice, changeAdminTxBob); + const changeAdminTxFerdie = api.tx.nft.addCollectionAdmin(collectionId, Ferdie.address); + await submitTransactionAsync(Bob, changeAdminTxFerdie); + const itemId = await createItemExpectSuccess(Ferdie, collectionId, 'NFT'); + // + const changeOwner = api.tx.nft.transferFrom(Ferdie.address, Bob.address, collectionId, itemId, 1); + const approve = api.tx.nft.approve(Bob.address, collectionId, itemId, 1); + const sendItem = api.tx.nft.transfer(Alice.address, collectionId, itemId, 1); + await Promise.all + ([ + changeOwner.signAndSend(Alice), + approve.signAndSend(Bob), + sendItem.signAndSend(Ferdie), + ]); + const itemBefore: any = await api.query.nft.nftItemList(collectionId, itemId); + expect(itemBefore.Owner.toString()).not.to.be.eq(Bob.address); + const blockHash = await api.query.system.number(); + console.log(`blockHash: ${blockHash}`); + }); + }); +}); --- /dev/null +++ b/tests/src/collision-tests/admVsOwnerData.test.ts @@ -0,0 +1,54 @@ +import { IKeyringPair } from '@polkadot/types/types'; +import chai from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +import { alicesPublicKey, bobsPublicKey } from '../accounts'; +import getBalance from '../substrate/get-balance'; +import privateKey from '../substrate/privateKey'; +import usingApi, { submitTransactionAsync } from '../substrate/substrate-api'; +import waitNewBlocks from '../substrate/wait-new-blocks'; +import { + createCollectionExpectSuccess, + createItemExpectSuccess, + setCollectionSponsorExpectSuccess, +} from '../util/helpers'; + +chai.use(chaiAsPromised); +const expect = chai.expect; +let Alice: IKeyringPair; +let Bob: IKeyringPair; +let Ferdie: IKeyringPair; + +before(async () => { + await usingApi(async () => { + Alice = privateKey('//Alice'); + Bob = privateKey('//Bob'); + Ferdie = privateKey('//Ferdie'); + }); +}); + +describe('Admin vs Owner changes the data in the token: ', () => { + it('The collection admin changes the data in the token and in the same block the token owner also changes the data in it ', async () => { + await usingApi(async (api) => { + const AliceData = [31]; + const BobData = [32]; + const collectionId = await createCollectionExpectSuccess(); + const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address); + await submitTransactionAsync(Alice, changeAdminTx); + const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT'); + // + // tslint:disable-next-line: max-line-length + const AliceTx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(AliceData).toString('hex')); + // tslint:disable-next-line: max-line-length + const BobTx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(BobData).toString('hex')); + await Promise.all + ([ + AliceTx.signAndSend(Alice), + BobTx.signAndSend(Bob), + ]); + const item: any = await api.query.nft.nftItemList(collectionId, itemId); + expect(Array.from(item.VariableData)).to.deep.equal(Array.from([])); + const blockHash = await api.query.system.number(); + console.log(`blockHash: ${blockHash}`); + }); + }); +}); --- /dev/null +++ b/tests/src/collision-tests/admVsOwnerTake.test.ts @@ -0,0 +1,51 @@ +import { IKeyringPair } from '@polkadot/types/types'; +import chai from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +import { alicesPublicKey, bobsPublicKey } from '../accounts'; +import getBalance from '../substrate/get-balance'; +import privateKey from '../substrate/privateKey'; +import usingApi, { submitTransactionAsync } from '../substrate/substrate-api'; +import waitNewBlocks from '../substrate/wait-new-blocks'; +import { + createCollectionExpectSuccess, + createItemExpectSuccess, + setCollectionSponsorExpectSuccess, +} from '../util/helpers'; + +chai.use(chaiAsPromised); +const expect = chai.expect; +let Alice: IKeyringPair; +let Bob: IKeyringPair; +let Ferdie: IKeyringPair; + +before(async () => { + await usingApi(async () => { + Alice = privateKey('//Alice'); + Bob = privateKey('//Bob'); + Ferdie = privateKey('//Ferdie'); + }); +}); + +describe('Admin vs Owner take token: ', () => { + // tslint:disable-next-line: max-line-length + it('The collection admin burns the token and in the same block the token owner performs a transaction on it ', async () => { + await usingApi(async (api) => { + const collectionId = await createCollectionExpectSuccess(); + const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address); + await submitTransactionAsync(Alice, changeAdminTx); + const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT'); + // + const sendItem = api.tx.nft.transfer(Ferdie.address, collectionId, itemId, 1); + const burnItem = api.tx.nft.burnItem(collectionId, itemId, 1); + await Promise.all + ([ + sendItem.signAndSend(Bob), + burnItem.signAndSend(Alice), + ]); + const itemBurn: any = await api.query.nft.nftItemList(collectionId, itemId); + expect(itemBurn.Owner.toString()).to.be.eq('5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM'); + const blockHash = await api.query.system.number(); + console.log(`blockHash: ${blockHash}`); + }); + }); +}); --- /dev/null +++ b/tests/src/collision-tests/sponsorPayments.test.ts @@ -0,0 +1,58 @@ +import { IKeyringPair } from '@polkadot/types/types'; +import chai from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +import { alicesPublicKey, bobsPublicKey } from '../accounts'; +import getBalance from '../substrate/get-balance'; +import privateKey from '../substrate/privateKey'; +import usingApi, { submitTransactionAsync } from '../substrate/substrate-api'; +import waitNewBlocks from '../substrate/wait-new-blocks'; +import { + confirmSponsorshipExpectSuccess, + createCollectionExpectSuccess, + createItemExpectSuccess, + setCollectionSponsorExpectSuccess, +} from '../util/helpers'; + +chai.use(chaiAsPromised); +const expect = chai.expect; +let Alice: IKeyringPair; +let Bob: IKeyringPair; +let Ferdie: IKeyringPair; + +before(async () => { + await usingApi(async () => { + Alice = privateKey('//Alice'); + Bob = privateKey('//Bob'); + Ferdie = privateKey('//Ferdie'); + }); +}); + +describe('Payment of commission if one block: ', () => { + // tslint:disable-next-line: max-line-length + it('Payment of commission if one block contains transactions for payment from the sponsor\'s balance and his (sponsor\'s) exclusion from the collection ', async () => { + await usingApi(async (api) => { + const collectionId = await createCollectionExpectSuccess(); + const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, Bob.address); + await submitTransactionAsync(Alice, changeAdminTxBob); + const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT'); + await setCollectionSponsorExpectSuccess(collectionId, Bob.address); + await confirmSponsorshipExpectSuccess(collectionId, '//Bob'); + // + const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alicesPublicKey, bobsPublicKey]); + const sendItem = api.tx.nft.transfer(Alice.address, collectionId, itemId, 1); + const revokeSponsor = api.tx.nft.removeCollectionSponsor(collectionId); + await Promise.all + ([ + sendItem.signAndSend(Bob), + revokeSponsor.signAndSend(Alice), + ]); + const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alicesPublicKey, bobsPublicKey]); + // tslint:disable-next-line:no-unused-expression + expect(alicesBalanceAfter === alicesBalanceBefore).to.be.true; + // tslint:disable-next-line:no-unused-expression + expect(bobsBalanceAfter === bobsBalanceBefore).to.be.true; + const blockHash = await api.query.system.number(); + console.log(`blockHash: ${blockHash}`); + }); + }); +}); --- /dev/null +++ b/tests/src/collision-tests/turnsOffMinting.test.ts @@ -0,0 +1,48 @@ +import { IKeyringPair } from '@polkadot/types/types'; +import chai from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +import privateKey from '../substrate/privateKey'; +import usingApi, { submitTransactionAsync } from '../substrate/substrate-api'; +import waitNewBlocks from '../substrate/wait-new-blocks'; +import { + addToWhiteListExpectSuccess, + createCollectionExpectSuccess, + setMintPermissionExpectSuccess, +} from '../util/helpers'; + +chai.use(chaiAsPromised); +const expect = chai.expect; +let Alice: IKeyringPair; +let Bob: IKeyringPair; +let Ferdie: IKeyringPair; + +before(async () => { + await usingApi(async () => { + Alice = privateKey('//Alice'); + Bob = privateKey('//Bob'); + Ferdie = privateKey('//Ferdie'); + }); +}); + +describe('Turns off minting mode: ', () => { + // tslint:disable-next-line: max-line-length + it('The collection owner turns off minting mode and there are minting transactions in the same block ', async () => { + await usingApi(async (api) => { + const collectionId = await createCollectionExpectSuccess(); + await setMintPermissionExpectSuccess(Alice, collectionId, true); + await addToWhiteListExpectSuccess(Alice, collectionId, Ferdie.address); + // + const mintItem = api.tx.nft.createItem(collectionId, Ferdie.address, 'NFT'); + const offMinting = api.tx.nft.setMintPermission(collectionId, false); + await Promise.all + ([ + mintItem.signAndSend(Ferdie), + offMinting.signAndSend(Alice), + ]); + const itemList: any = await api.query.nft.nftItemList(collectionId, mintItem); + expect(itemList.Owner.toString()).to.be.eq('5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM'); + const blockHash = await api.query.system.number(); + console.log(`blockHash: ${blockHash}`); + }); + }); +});