From 012b227bf9e47d7f926e115df08d0df0aa5e84ed Mon Sep 17 00:00:00 2001 From: str-mv Date: Fri, 12 Nov 2021 12:52:32 +0000 Subject: [PATCH] CORE-168 --- --- a/tests/src/approve.test.ts +++ b/tests/src/approve.test.ts @@ -18,76 +18,393 @@ transferExpectSuccess, addCollectionAdminExpectSuccess, adminApproveFromExpectSuccess, + transferFromExpectSuccess, + transferFromExpectFail, } from './util/helpers'; chai.use(chaiAsPromised); +const expect = chai.expect; describe('Integration Test approve(spender, collection_id, item_id, amount):', () => { - let alice: IKeyringPair; - let bob: IKeyringPair; - let charlie: IKeyringPair; + let Alice: IKeyringPair; + let Bob: IKeyringPair; + let Charlie: IKeyringPair; before(async () => { await usingApi(async () => { - alice = privateKey('//Alice'); - bob = privateKey('//Bob'); - charlie = privateKey('//Charlie'); + Alice = privateKey('//Alice'); + Bob = privateKey('//Bob'); + Charlie = privateKey('//Charlie'); }); }); it('Execute the extrinsic and check approvedList', async () => { const nftCollectionId = await createCollectionExpectSuccess(); // nft - const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT'); - await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address); + const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT'); + await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob.address); // fungible const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}}); - const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible'); - await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address); + const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible'); + await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob.address); // reFungible const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}}); - const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible'); - await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address); + const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible'); + await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob.address); }); it('Remove approval by using 0 amount', async () => { const nftCollectionId = await createCollectionExpectSuccess(); // nft - const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT'); - await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address, 1); - await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address, 0); + const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT'); + await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob.address, 1); + await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob.address, 0); // fungible const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}}); - const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible'); - await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 1); - await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 0); + const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible'); + await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob.address, 1); + await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob.address, 0); // reFungible const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}}); - const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible'); - await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 1); - await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 0); + const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible'); + await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob.address, 1); + await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob.address, 0); }); it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => { const collectionId = await createCollectionExpectSuccess(); - const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address); + + await adminApproveFromExpectSuccess(collectionId, itemId, Alice, Bob.address, Charlie.address); + }); +}); + +describe('Normal user can approve other users to transfer:', () => { + let Alice: IKeyringPair; + let Bob: IKeyringPair; + let Charlie: IKeyringPair; + + before(async () => { + await usingApi(async () => { + Alice = privateKey('//Alice'); + Bob = privateKey('//Bob'); + Charlie = privateKey('//Charlie'); + }); + }); + + it('NFT', async () => { + const collectionId = await createCollectionExpectSuccess(); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address); + await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address); + }); + + it('Fungible up to an approved amount', async () => { + const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }}); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'Fungible', Bob.address); + await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address); + }); + + it('ReFungible up to an approved amount', async () => { + const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } }); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible', Bob.address); + await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address); + }); +}); + +describe('Approved users can transferFrom up to approved amount:', () => { + let Alice: IKeyringPair; + let Bob: IKeyringPair; + let Charlie: IKeyringPair; + + before(async () => { + await usingApi(async () => { + Alice = privateKey('//Alice'); + Bob = privateKey('//Bob'); + Charlie = privateKey('//Charlie'); + }); + }); + + it('NFT', async () => { + const collectionId = await createCollectionExpectSuccess(); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address); + await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address); + await transferFromExpectSuccess(collectionId, itemId, Charlie, Bob, Alice, 1, 'NFT'); + }); + + it('Fungible up to an approved amount', async () => { + const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }}); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'Fungible', Bob.address); + await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address); + await transferFromExpectSuccess(collectionId, itemId, Charlie, Bob, Alice, 1, 'Fungible'); + }); + + it('ReFungible up to an approved amount', async () => { + const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } }); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible', Bob.address); + await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address); + await transferFromExpectSuccess(collectionId, itemId, Charlie, Bob, Alice, 1, 'ReFungible'); + }); +}); + +describe('Approved users cannot use transferFrom to repeat transfers if approved amount was already transferred:', () => { + let Alice: IKeyringPair; + let Bob: IKeyringPair; + let Charlie: IKeyringPair; + + before(async () => { + await usingApi(async () => { + Alice = privateKey('//Alice'); + Bob = privateKey('//Bob'); + Charlie = privateKey('//Charlie'); + }); + }); + + it('NFT', async () => { + const collectionId = await createCollectionExpectSuccess(); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address); + await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address); + await transferFromExpectSuccess(collectionId, itemId, Charlie, Bob, Alice, 1, 'NFT'); + await transferFromExpectFail(collectionId, itemId, Charlie, Bob, Alice, 1); + }); + + it('Fungible up to an approved amount', async () => { + const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }}); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'Fungible', Bob.address); + await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address); + await transferFromExpectSuccess(collectionId, itemId, Charlie, Bob, Alice, 1, 'Fungible'); + await transferFromExpectFail(collectionId, itemId, Charlie, Bob, Alice, 1); + }); + + it('ReFungible up to an approved amount', async () => { + const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } }); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible', Bob.address); + await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address); + await transferFromExpectSuccess(collectionId, itemId, Charlie, Bob, Alice, 1, 'ReFungible'); + await transferFromExpectFail(collectionId, itemId, Charlie, Bob, Alice, 1); + }); +}); + +describe('Approved amount decreases by the transferred amount.:', () => { + let Alice: IKeyringPair; + let Bob: IKeyringPair; + let Charlie: IKeyringPair; + let Dave: IKeyringPair; + + before(async () => { + await usingApi(async () => { + Alice = privateKey('//Alice'); + Bob = privateKey('//Bob'); + Charlie = privateKey('//Charlie'); + Dave = privateKey('//Dave'); + }); + }); + + it('If a user B is approved to transfer 10 Fungible tokens from user A, they can transfer 2 tokens to user C, which will result in decreasing approval from 10 to 8. Then user B can transfer 8 tokens to user D.', async () => { + const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }}); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'Fungible', Alice.address); + await approveExpectSuccess(collectionId, itemId, Alice, Bob.address, 10); + await transferFromExpectSuccess(collectionId, itemId, Bob, Alice, Charlie, 2, 'Fungible'); + await transferFromExpectSuccess(collectionId, itemId, Bob, Alice, Dave, 8, 'Fungible'); + }); +}); + +describe('User may clear the approvals to approving for 0 amount:', () => { + let Alice: IKeyringPair; + let Bob: IKeyringPair; + let Charlie: IKeyringPair; + + before(async () => { + await usingApi(async () => { + Alice = privateKey('//Alice'); + Bob = privateKey('//Bob'); + Charlie = privateKey('//Charlie'); + }); + }); + + it('NFT', async () => { + const collectionId = await createCollectionExpectSuccess(); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT'); + await approveExpectSuccess(collectionId, itemId, Alice, Bob.address, 1); + await approveExpectSuccess(collectionId, itemId, Alice, Bob.address, 0); + await transferFromExpectFail(collectionId, itemId, Bob, Bob, Charlie, 1); + }); + + it('Fungible', async () => { + const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}}); + const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible'); + await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob.address, 1); + await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob.address, 0); + await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Bob, Charlie, 1); + }); - await adminApproveFromExpectSuccess(collectionId, itemId, alice, bob.address, charlie.address); + it('ReFungible', async () => { + const reFungibleCollectionId = + await createCollectionExpectSuccess({mode: {type: 'ReFungible'}}); + const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible'); + await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob.address, 1); + await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob.address, 0); + await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Bob, Charlie, 1); }); }); +describe('User cannot approve for the amount greater than they own:', () => { + let Alice: IKeyringPair; + let Bob: IKeyringPair; + let Charlie: IKeyringPair; + + before(async () => { + await usingApi(async () => { + Alice = privateKey('//Alice'); + Bob = privateKey('//Bob'); + Charlie = privateKey('//Charlie'); + }); + }); + + it('1 for NFT', async () => { + const collectionId = await createCollectionExpectSuccess(); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address); + await approveExpectFail(collectionId, itemId, Bob, Charlie, 2); + }); + + it('Fungible', async () => { + const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}}); + const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible'); + await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Charlie, 11); + }); + + it('ReFungible', async () => { + const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}}); + const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible'); + await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Charlie, 101); + }); +}); + +describe('Administrator and collection owner do not need approval in order to execute TransferFrom:', () => { + let Alice: IKeyringPair; + let Bob: IKeyringPair; + let Charlie: IKeyringPair; + let Dave: IKeyringPair; + + before(async () => { + await usingApi(async () => { + Alice = privateKey('//Alice'); + Bob = privateKey('//Bob'); + Charlie = privateKey('//Charlie'); + Dave = privateKey('//Dave'); + }); + }); + + it('NFT', async () => { + const collectionId = await createCollectionExpectSuccess(); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Charlie.address); + await transferFromExpectSuccess(collectionId, itemId, Alice, Charlie, Dave, 1, 'NFT'); + await addCollectionAdminExpectSuccess(Alice, collectionId, Bob.address); + await transferFromExpectSuccess(collectionId, itemId, Bob, Dave, Alice, 1, 'NFT'); + }); + + it('Fungible up to an approved amount', async () => { + const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }}); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'Fungible', Charlie.address); + await transferFromExpectSuccess(collectionId, itemId, Alice, Charlie, Dave, 1, 'Fungible'); + await addCollectionAdminExpectSuccess(Alice, collectionId, Bob.address); + await transferFromExpectSuccess(collectionId, itemId, Bob, Dave, Alice, 1, 'Fungible'); + }); + + it('ReFungible up to an approved amount', async () => { + const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } }); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible', Charlie.address); + await transferFromExpectSuccess(collectionId, itemId, Alice, Charlie, Dave, 1, 'ReFungible'); + await addCollectionAdminExpectSuccess(Alice, collectionId, Bob.address); + await transferFromExpectSuccess(collectionId, itemId, Bob, Dave, Alice, 1, 'ReFungible'); + }); +}); + +describe('Repeated approvals add up', () => { + let Alice: IKeyringPair; + let Bob: IKeyringPair; + let Charlie: IKeyringPair; + let Dave: IKeyringPair; + + before(async () => { + await usingApi(async () => { + Alice = privateKey('//Alice'); + Bob = privateKey('//Bob'); + Charlie = privateKey('//Charlie'); + Dave = privateKey('//Dave'); + }); + }); + + it.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. Fungible', async () => { + const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }}); + await createItemExpectSuccess(Alice, collectionId, 'Fungible', Alice.address); + await approveExpectSuccess(collectionId, 0, Alice, Bob.address, 1); + await approveExpectSuccess(collectionId, 0, Alice, Charlie.address, 1); + // const allowances1 = await getAllowance(collectionId, 0, Alice.address, Bob.address); + // const allowances2 = await getAllowance(collectionId, 0, Alice.address, Charlie.address); + // expect(allowances1 + allowances2).to.be.eq(BigInt(2)); + }); + + it.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. ReFungible', async () => { + const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } }); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible', Alice.address); + await approveExpectSuccess(collectionId, itemId, Alice, Bob.address, 1); + await approveExpectSuccess(collectionId, itemId, Alice, Charlie.address, 1); + // const allowances1 = await getAllowance(collectionId, itemId, Alice.address, Bob.address); + // const allowances2 = await getAllowance(collectionId, itemId, Alice.address, Charlie.address); + // expect(allowances1 + allowances2).to.be.eq(BigInt(2)); + }); + + // Canceled by changing approve logic + it.skip('Cannot approve for more than total user`s amount (owned: 10, approval 1: 5 - should succeed, approval 2: 6 - should fail). Fungible', async () => { + const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }}); + await createItemExpectSuccess(Alice, collectionId, 'Fungible', Dave.address); + await approveExpectSuccess(collectionId, 0, Dave, Bob.address, 5); + await approveExpectFail(collectionId, 0, Dave, Charlie, 6); + }); + + // Canceled by changing approve logic + it.skip('Cannot approve for more than total users amount (owned: 100, approval 1: 50 - should succeed, approval 2: 51 - should fail). ReFungible', async () => { + const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } }); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible', Dave.address); + await approveExpectSuccess(collectionId, itemId, Dave, Bob.address, 50); + await approveExpectFail(collectionId, itemId, Dave, Charlie, 51); + }); +}); + +describe('Integration Test approve(spender, collection_id, item_id, amount) with collection admin permissions:', () => { + let Alice: IKeyringPair; + let Bob: IKeyringPair; + let Charlie: IKeyringPair; + + before(async () => { + await usingApi(async () => { + Alice = privateKey('//Alice'); + Bob = privateKey('//Bob'); + Charlie = privateKey('//Charlie'); + }); + }); + + it('can be called by collection admin on non-owned item', async () => { + const collectionId = await createCollectionExpectSuccess(); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address); + + await addCollectionAdminExpectSuccess(Alice, collectionId, Bob.address); + await adminApproveFromExpectSuccess(collectionId, itemId, Bob, Alice.address, Charlie.address); + }); +}); + describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => { - let alice: IKeyringPair; - let bob: IKeyringPair; - let charlie: IKeyringPair; + let Alice: IKeyringPair; + let Bob: IKeyringPair; + let Charlie: IKeyringPair; before(async () => { await usingApi(async () => { - alice = privateKey('//Alice'); - bob = privateKey('//Bob'); - charlie = privateKey('//Charlie'); + Alice = privateKey('//Alice'); + Bob = privateKey('//Bob'); + Charlie = privateKey('//Charlie'); }); }); @@ -95,13 +412,13 @@ await usingApi(async (api: ApiPromise) => { // nft const nftCollectionCount = (await api.query.common.createdCollectionCount()).toNumber(); - await approveExpectFail(nftCollectionCount + 1, 1, alice, bob); + await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob); // fungible const fungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber(); - await approveExpectFail(fungibleCollectionCount + 1, 0, alice, bob); + await approveExpectFail(fungibleCollectionCount + 1, 0, Alice, Bob); // reFungible const reFungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber(); - await approveExpectFail(reFungibleCollectionCount + 1, 1, alice, bob); + await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob); }); }); @@ -109,87 +426,65 @@ // nft const nftCollectionId = await createCollectionExpectSuccess(); await destroyCollectionExpectSuccess(nftCollectionId); - await approveExpectFail(nftCollectionId, 1, alice, bob); + await approveExpectFail(nftCollectionId, 1, Alice, Bob); // fungible const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}}); await destroyCollectionExpectSuccess(fungibleCollectionId); - await approveExpectFail(fungibleCollectionId, 0, alice, bob); + await approveExpectFail(fungibleCollectionId, 0, Alice, Bob); // reFungible const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}}); await destroyCollectionExpectSuccess(reFungibleCollectionId); - await approveExpectFail(reFungibleCollectionId, 1, alice, bob); + await approveExpectFail(reFungibleCollectionId, 1, Alice, Bob); }); it('Approve transfer of a token that does not exist', async () => { // nft const nftCollectionId = await createCollectionExpectSuccess(); - await approveExpectFail(nftCollectionId, 2, alice, bob); + await approveExpectFail(nftCollectionId, 2, Alice, Bob); // reFungible const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}}); - await approveExpectFail(reFungibleCollectionId, 2, alice, bob); + await approveExpectFail(reFungibleCollectionId, 2, Alice, Bob); }); it('Approve using the address that does not own the approved token', async () => { const nftCollectionId = await createCollectionExpectSuccess(); // nft - const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT'); - await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice); + const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT'); + await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice); // fungible const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}}); - const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible'); - await approveExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice); + const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible'); + await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice); // reFungible const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}}); - const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible'); - await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, alice); + const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible'); + await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice); }); it('should fail if approved more ReFungibles than owned', async () => { const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}}); - const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'ReFungible'); - await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 100, 'ReFungible'); - await approveExpectSuccess(nftCollectionId, newNftTokenId, bob, alice.address, 100); - await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice, 101); + const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'ReFungible'); + await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 100, 'ReFungible'); + await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice.address, 100); + await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, 101); }); it('should fail if approved more Fungibles than owned', async () => { const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}}); - const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'Fungible'); - await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 10, 'Fungible'); - await approveExpectSuccess(nftCollectionId, newNftTokenId, bob, alice.address, 10); - await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice, 11); + const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'Fungible'); + await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 10, 'Fungible'); + await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice.address, 10); + await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, 11); }); it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => { const collectionId = await createCollectionExpectSuccess(); - const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address); - await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: false}); - - await approveExpectFail(collectionId, itemId, alice, charlie); - }); -}); - -describe('Integration Test approve(spender, collection_id, item_id, amount) with collection admin permissions:', () => { - let alice: IKeyringPair; - let bob: IKeyringPair; - let charlie: IKeyringPair; - - before(async () => { - await usingApi(async () => { - alice = privateKey('//Alice'); - bob = privateKey('//Bob'); - charlie = privateKey('//Charlie'); - }); - }); - - it('can be called by collection admin on non-owned item', async () => { - const collectionId = await createCollectionExpectSuccess(); - const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address); + const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address); + await setCollectionLimitsExpectSuccess(Alice, collectionId, {ownerCanTransfer: false}); - await addCollectionAdminExpectSuccess(alice, collectionId, bob.address); - await adminApproveFromExpectSuccess(collectionId, itemId, bob, alice.address, charlie.address); + await approveExpectFail(collectionId, itemId, Alice, Charlie); }); }); -- gitstuff