Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
🐛 Fixes NFTMethod.unlock to not log event if NFT is escrowed
Browse files Browse the repository at this point in the history
  • Loading branch information
has5aan committed Jun 9, 2023
1 parent 5c1565f commit de66f9e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
15 changes: 3 additions & 12 deletions framework/src/modules/nft/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,23 +375,14 @@ export class NFTMethod extends BaseMethod {
throw new Error('NFT substore entry does not exist');
}

const owner = await this.getNFTOwner(methodContext, nftID);

if (owner.length === LENGTH_CHAIN_ID) {
this.events.get(LockEvent).error(
methodContext,
{
module,
nftID,
},
NftEventResult.RESULT_NFT_ESCROWED,
);
const nftData = await nftStore.get(methodContext, nftID);

if (nftData.owner.length === LENGTH_CHAIN_ID) {
throw new Error('NFT is escrowed to another chain');
}

const userStore = this.stores.get(UserStore);
const userKey = userStore.getKey(owner, nftID);
const userKey = userStore.getKey(nftData.owner, nftID);
const userData = await userStore.get(methodContext, userKey);

if (userData.lockingModule === NFT_NOT_LOCKED) {
Expand Down
14 changes: 1 addition & 13 deletions framework/test/unit/modules/nft/method.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,22 +693,10 @@ describe('NFTMethod', () => {
);
});

it('should throw and log LockEvent if NFT is escrowed', async () => {
it('should throw if NFT is escrowed', async () => {
await expect(method.unlock(methodContext, module.name, escrowedNFT.nftID)).rejects.toThrow(
'NFT is escrowed to another chain',
);

checkEventResult<LockEventData>(
methodContext.eventQueue,
1,
LockEvent,
0,
{
module: module.name,
nftID: escrowedNFT.nftID,
},
NftEventResult.RESULT_NFT_ESCROWED,
);
});

it('should throw and log LockEvent if NFT is not locked', async () => {
Expand Down

0 comments on commit de66f9e

Please sign in to comment.