From fc2984152b1ff0563ef171519e24837400514996 Mon Sep 17 00:00:00 2001 From: Incede <33103370+Incede@users.noreply.github.com> Date: Mon, 18 Sep 2023 21:56:27 +0200 Subject: [PATCH] Remove validation in verify hook --- .../modules/nft/cc_commands/cc_transfer.ts | 1 - .../src/modules/nft/commands/transfer.ts | 3 - .../nft/commands/transfer_cross_chain.ts | 3 - .../nft/cc_comands/cc_transfer.spec.ts | 34 -------- .../modules/nft/commands/transfer.spec.ts | 40 --------- .../nft/commands/transfer_cross_chain.spec.ts | 86 ------------------- 6 files changed, 167 deletions(-) diff --git a/framework/src/modules/nft/cc_commands/cc_transfer.ts b/framework/src/modules/nft/cc_commands/cc_transfer.ts index c8f9000446a..74c06e9efbd 100644 --- a/framework/src/modules/nft/cc_commands/cc_transfer.ts +++ b/framework/src/modules/nft/cc_commands/cc_transfer.ts @@ -53,7 +53,6 @@ export class CrossChainTransferCommand extends BaseCCCommand { crossChainNFTTransferMessageParamsSchema, ccm.params, ); - validator.validate(crossChainNFTTransferMessageParamsSchema, params); if (ccm.status > MAX_RESERVED_ERROR_STATUS) { throw new Error('Invalid CCM error code'); diff --git a/framework/src/modules/nft/commands/transfer.ts b/framework/src/modules/nft/commands/transfer.ts index 85a984c00a2..3da6043b42f 100644 --- a/framework/src/modules/nft/commands/transfer.ts +++ b/framework/src/modules/nft/commands/transfer.ts @@ -12,7 +12,6 @@ * Removal or modification of this copyright notice is prohibited. */ -import { validator } from '@liskhq/lisk-validator'; import { CommandExecuteContext, CommandVerifyContext, @@ -45,8 +44,6 @@ export class TransferCommand extends BaseCommand { public async verify(context: CommandVerifyContext): Promise { const { params } = context; - validator.validate(this.schema, params); - const nftStore = this.stores.get(NFTStore); const nftExists = await nftStore.has(context, params.nftID); diff --git a/framework/src/modules/nft/commands/transfer_cross_chain.ts b/framework/src/modules/nft/commands/transfer_cross_chain.ts index daf3c4f472f..9fa0cd4f20d 100644 --- a/framework/src/modules/nft/commands/transfer_cross_chain.ts +++ b/framework/src/modules/nft/commands/transfer_cross_chain.ts @@ -12,7 +12,6 @@ * Removal or modification of this copyright notice is prohibited. */ -import { validator } from '@liskhq/lisk-validator'; import { crossChainTransferParamsSchema } from '../schemas'; import { NFTStore } from '../stores/nft'; import { NFTMethod } from '../method'; @@ -59,8 +58,6 @@ export class TransferCrossChainCommand extends BaseCommand { public async verify(context: CommandVerifyContext): Promise { const { params } = context; - validator.validate(this.schema, params); - const nftStore = this.stores.get(NFTStore); const nftExists = await nftStore.has(context.getMethodContext(), params.nftID); diff --git a/framework/test/unit/modules/nft/cc_comands/cc_transfer.spec.ts b/framework/test/unit/modules/nft/cc_comands/cc_transfer.spec.ts index c2fadce28a4..a8b20e3144d 100644 --- a/framework/test/unit/modules/nft/cc_comands/cc_transfer.spec.ts +++ b/framework/test/unit/modules/nft/cc_comands/cc_transfer.spec.ts @@ -183,40 +183,6 @@ describe('CrossChain Transfer Command', () => { await expect(command.verify(context)).resolves.toBeUndefined(); }); - it('throw for if validation fails', async () => { - params = codec.encode(crossChainNFTTransferMessageParamsSchema, { - nftID: Buffer.alloc(LENGTH_NFT_ID + 1, 1), - senderAddress, - recipientAddress, - attributesArray, - data: '', - }); - ccm = { - crossChainCommand: CROSS_CHAIN_COMMAND_NAME_TRANSFER, - module: module.name, - nonce: BigInt(1), - sendingChainID, - receivingChainID, - fee: BigInt(30000), - status: CCM_STATUS_OK, - params, - }; - context = { - ccm, - transaction: defaultTransaction, - header: defaultHeader, - stateStore, - contextStore, - getMethodContext, - eventQueue, - getStore, - logger: fakeLogger, - chainID, - }; - - await expect(command.verify(context)).rejects.toThrow(`Property '.nftID' maxLength exceeded`); - }); - it('throw for invalid ccm status', async () => { ccm = { crossChainCommand: CROSS_CHAIN_COMMAND_NAME_TRANSFER, diff --git a/framework/test/unit/modules/nft/commands/transfer.spec.ts b/framework/test/unit/modules/nft/commands/transfer.spec.ts index a4cae3f8054..b9889fa9f06 100644 --- a/framework/test/unit/modules/nft/commands/transfer.spec.ts +++ b/framework/test/unit/modules/nft/commands/transfer.spec.ts @@ -99,46 +99,6 @@ describe('Transfer command', () => { }); describe('verify', () => { - it('should fail if nftID does not have valid length', async () => { - const nftMinLengthContext = createTransactionContextWithOverridingParams({ - nftID: Buffer.alloc(LENGTH_NFT_ID - 1, 1), - }); - - const nftMaxLengthContext = createTransactionContextWithOverridingParams({ - nftID: Buffer.alloc(LENGTH_NFT_ID + 1, 1), - }); - - await expect( - command.verify(nftMinLengthContext.createCommandVerifyContext(transferParamsSchema)), - ).rejects.toThrow("'.nftID' minLength not satisfied"); - - await expect( - command.verify(nftMaxLengthContext.createCommandExecuteContext(transferParamsSchema)), - ).rejects.toThrow("'.nftID' maxLength exceeded"); - }); - - it('should fail if recipientAddress is not 20 bytes', async () => { - const recipientAddressIncorrectLengthContext = createTransactionContextWithOverridingParams({ - recipientAddress: utils.getRandomBytes(22), - }); - - await expect( - command.verify( - recipientAddressIncorrectLengthContext.createCommandVerifyContext(transferParamsSchema), - ), - ).rejects.toThrow("'.recipientAddress' address length invalid"); - }); - - it('should fail if data exceeds 64 characters', async () => { - const dataIncorrectLengthContext = createTransactionContextWithOverridingParams({ - data: '1'.repeat(65), - }); - - await expect( - command.verify(dataIncorrectLengthContext.createCommandVerifyContext(transferParamsSchema)), - ).rejects.toThrow("'.data' must NOT have more than 64 characters"); - }); - it('should fail if nftID does not exist', async () => { const nftIDNotExistingContext = createTransactionContextWithOverridingParams({ nftID: Buffer.alloc(LENGTH_NFT_ID, 0), diff --git a/framework/test/unit/modules/nft/commands/transfer_cross_chain.spec.ts b/framework/test/unit/modules/nft/commands/transfer_cross_chain.spec.ts index d7c2d9e0d59..83eeb065f67 100644 --- a/framework/test/unit/modules/nft/commands/transfer_cross_chain.spec.ts +++ b/framework/test/unit/modules/nft/commands/transfer_cross_chain.spec.ts @@ -215,92 +215,6 @@ describe('TransferCrossChainComand', () => { ).rejects.toThrow('Receiving chain cannot be the sending chain'); }); - it('should fail if NFT does not have valid length', async () => { - const nftMinLengthContext = createTransactionContextWithOverridingParams({ - nftID: utils.getRandomBytes(LENGTH_NFT_ID - 1), - }); - - const nftMaxLengthContext = createTransactionContextWithOverridingParams({ - nftID: utils.getRandomBytes(LENGTH_NFT_ID + 1), - }); - - await expect( - command.verify( - nftMinLengthContext.createCommandVerifyContext(crossChainTransferParamsSchema), - ), - ).rejects.toThrow("'.nftID' minLength not satisfied"); - - await expect( - command.verify( - nftMaxLengthContext.createCommandExecuteContext(crossChainTransferParamsSchema), - ), - ).rejects.toThrow("'.nftID' maxLength exceeded"); - }); - - it('should fail if receivingChainID does not have valid length', async () => { - const receivingChainIDMinLengthContext = createTransactionContextWithOverridingParams({ - receivingChainID: utils.getRandomBytes(LENGTH_CHAIN_ID - 1), - }); - - const receivingChainIDMaxLengthContext = createTransactionContextWithOverridingParams({ - receivingChainID: utils.getRandomBytes(LENGTH_CHAIN_ID + 1), - }); - - await expect( - command.verify( - receivingChainIDMinLengthContext.createCommandVerifyContext( - crossChainTransferParamsSchema, - ), - ), - ).rejects.toThrow("'.receivingChainID' minLength not satisfied"); - - await expect( - command.verify( - receivingChainIDMaxLengthContext.createCommandVerifyContext( - crossChainTransferParamsSchema, - ), - ), - ).rejects.toThrow("'.receivingChainID' maxLength exceeded"); - }); - - it('should fail if recipientAddress does not have valid length', async () => { - const recipientAddressMinLengthContext = createTransactionContextWithOverridingParams({ - recipientAddress: utils.getRandomBytes(LENGTH_ADDRESS - 1), - }); - - const recipientAddressMaxLenghtContext = createTransactionContextWithOverridingParams({ - recipientAddress: utils.getRandomBytes(LENGTH_ADDRESS + 1), - }); - - await expect( - command.verify( - recipientAddressMinLengthContext.createCommandVerifyContext( - crossChainTransferParamsSchema, - ), - ), - ).rejects.toThrow("'.recipientAddress' address length invalid"); - - await expect( - command.verify( - recipientAddressMaxLenghtContext.createCommandVerifyContext( - crossChainTransferParamsSchema, - ), - ), - ).rejects.toThrow("'.recipientAddress' address length invalid"); - }); - - it('should fail if data has more than 64 characters', async () => { - const dataMaxLengthContext = createTransactionContextWithOverridingParams({ - data: '1'.repeat(65), - }); - - await expect( - command.verify( - dataMaxLengthContext.createCommandVerifyContext(crossChainTransferParamsSchema), - ), - ).rejects.toThrow("'.data' must NOT have more than 64 characters"); - }); - it('should fail if NFT does not exist', async () => { const context = createTransactionContextWithOverridingParams({ nftID: utils.getRandomBytes(LENGTH_NFT_ID),