diff --git a/framework/src/modules/nft/method.ts b/framework/src/modules/nft/method.ts index 859fd0ac57c..a807e9ad674 100644 --- a/framework/src/modules/nft/method.ts +++ b/framework/src/modules/nft/method.ts @@ -102,47 +102,47 @@ export class NFTMethod extends BaseMethod { const owner = await this.getNFTOwner(methodContext, nftID); - if (!owner.equals(address)) { + if (owner.length === LENGTH_CHAIN_ID) { this.events.get(DestroyEvent).log( methodContext, { address, nftID, }, - NftEventResult.RESULT_INITIATED_BY_NONOWNER, + NftEventResult.RESULT_NFT_ESCROWED, ); - throw new Error('Not initiated by the NFT owner'); + throw new Error('NFT is escrowed to another chain'); } - const userStore = this.stores.get(UserStore); - const userKey = userStore.getKey(owner, nftID); - const { lockingModule } = await userStore.get(methodContext, userKey); - - if (lockingModule !== NFT_NOT_LOCKED) { + if (!owner.equals(address)) { this.events.get(DestroyEvent).log( methodContext, { address, nftID, }, - NftEventResult.RESULT_NFT_LOCKED, + NftEventResult.RESULT_INITIATED_BY_NONOWNER, ); - throw new Error('Locked NFTs cannot be destroyed'); + throw new Error('Not initiated by the NFT owner'); } - if (owner.length === LENGTH_CHAIN_ID) { + const userStore = this.stores.get(UserStore); + const userKey = userStore.getKey(owner, nftID); + const { lockingModule } = await userStore.get(methodContext, userKey); + + if (lockingModule !== NFT_NOT_LOCKED) { this.events.get(DestroyEvent).log( methodContext, { address, nftID, }, - NftEventResult.RESULT_NFT_ESCROWED, + NftEventResult.RESULT_NFT_LOCKED, ); - throw new Error('NFT is escrowed to another chain'); + throw new Error('Locked NFTs cannot be destroyed'); } await nftStore.del(methodContext, nftID); diff --git a/framework/test/unit/modules/nft/method.spec.ts b/framework/test/unit/modules/nft/method.spec.ts index 7e204f73010..8225174ba30 100644 --- a/framework/test/unit/modules/nft/method.spec.ts +++ b/framework/test/unit/modules/nft/method.spec.ts @@ -161,7 +161,7 @@ describe('NFTMethod', () => { nftID: utils.getRandomBytes(LENGTH_NFT_ID), }; - await module.stores.get(NFTStore).save(methodContext, existingNFT.nftID, { + await nftStore.save(methodContext, existingNFT.nftID, { owner: existingNFT.owner, attributesArray: [], }); @@ -170,7 +170,7 @@ describe('NFTMethod', () => { lockingModule: NFT_NOT_LOCKED, }); - await module.stores.get(NFTStore).save(methodContext, lockedExistingNFT.nftID, { + await nftStore.save(methodContext, lockedExistingNFT.nftID, { owner: lockedExistingNFT.owner, attributesArray: [], }); @@ -183,7 +183,7 @@ describe('NFTMethod', () => { }, ); - await module.stores.get(NFTStore).save(methodContext, escrowedNFT.nftID, { + await nftStore.save(methodContext, escrowedNFT.nftID, { owner: escrowedNFT.owner, attributesArray: [], }); @@ -233,10 +233,10 @@ describe('NFTMethod', () => { ); }); - it('should fail and emit Destroy event if NFT is locked', async () => { + it('should fail and emit Destroy event if NFT is escrowed', async () => { await expect( - method.destroy(methodContext, lockedExistingNFT.owner, lockedExistingNFT.nftID), - ).rejects.toThrow('Locked NFTs cannot be destroyed'); + method.destroy(methodContext, escrowedNFT.owner, escrowedNFT.nftID), + ).rejects.toThrow('NFT is escrowed to another chain'); checkEventResult( methodContext.eventQueue, @@ -244,17 +244,17 @@ describe('NFTMethod', () => { DestroyEvent, 0, { - address: lockedExistingNFT.owner, - nftID: lockedExistingNFT.nftID, + address: escrowedNFT.owner, + nftID: escrowedNFT.nftID, }, - NftEventResult.RESULT_NFT_LOCKED, + NftEventResult.RESULT_NFT_ESCROWED, ); }); - it('should fail and emit Destroy event if NFT is escrowed', async () => { + it('should fail and emit Destroy event if NFT is locked', async () => { await expect( - method.destroy(methodContext, escrowedNFT.owner, escrowedNFT.nftID), - ).rejects.toThrow(); + method.destroy(methodContext, lockedExistingNFT.owner, lockedExistingNFT.nftID), + ).rejects.toThrow('Locked NFTs cannot be destroyed'); checkEventResult( methodContext.eventQueue, @@ -262,10 +262,10 @@ describe('NFTMethod', () => { DestroyEvent, 0, { - address: escrowedNFT.owner, - nftID: escrowedNFT.nftID, + address: lockedExistingNFT.owner, + nftID: lockedExistingNFT.nftID, }, - NftEventResult.RESULT_NFT_ESCROWED, + NftEventResult.RESULT_NFT_LOCKED, ); }); @@ -274,13 +274,9 @@ describe('NFTMethod', () => { method.destroy(methodContext, existingNFT.owner, existingNFT.nftID), ).resolves.toBeUndefined(); + await expect(nftStore.has(methodContext, existingNFT.nftID)).resolves.toBeFalse(); await expect( - module.stores.get(NFTStore).has(methodContext, existingNFT.nftID), - ).resolves.toBeFalse(); - await expect( - module.stores - .get(UserStore) - .has(methodContext, Buffer.concat([existingNFT.owner, escrowedNFT.nftID])), + userStore.has(methodContext, Buffer.concat([existingNFT.owner, escrowedNFT.nftID])), ).resolves.toBeFalse(); checkEventResult(methodContext.eventQueue, 1, DestroyEvent, 0, {