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

Commit

Permalink
Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Incede committed Jun 7, 2023
2 parents eff844a + 0ae50b1 commit 9036286
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 34 deletions.
26 changes: 13 additions & 13 deletions framework/src/modules/nft/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
38 changes: 17 additions & 21 deletions framework/test/unit/modules/nft/method.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
});
Expand All @@ -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: [],
});
Expand All @@ -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: [],
});
Expand Down Expand Up @@ -233,39 +233,39 @@ 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<DestroyEventData>(
methodContext.eventQueue,
1,
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<DestroyEventData>(
methodContext.eventQueue,
1,
DestroyEvent,
0,
{
address: escrowedNFT.owner,
nftID: escrowedNFT.nftID,
address: lockedExistingNFT.owner,
nftID: lockedExistingNFT.nftID,
},
NftEventResult.RESULT_NFT_ESCROWED,
NftEventResult.RESULT_NFT_LOCKED,
);
});

Expand All @@ -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<DestroyEventData>(methodContext.eventQueue, 1, DestroyEvent, 0, {
Expand Down

0 comments on commit 9036286

Please sign in to comment.