From a669aae7b9ae83414945962e57abae35b90dbcdd Mon Sep 17 00:00:00 2001 From: Denis Davidyuk Date: Tue, 28 Feb 2023 09:04:53 +0400 Subject: [PATCH] fix(tx-builder): drop nonce validator to avoid false positive --- src/tx/builder/field-types/nonce.ts | 3 ++- src/tx/validator.ts | 18 +----------------- test/integration/txVerification.ts | 8 +++----- 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/tx/builder/field-types/nonce.ts b/src/tx/builder/field-types/nonce.ts index 3892b7d46a..a5d814852f 100644 --- a/src/tx/builder/field-types/nonce.ts +++ b/src/tx/builder/field-types/nonce.ts @@ -2,6 +2,7 @@ import { isAccountNotFoundError } from '../../../utils/other'; import shortUInt from './short-u-int'; import Node from '../../../Node'; import { ArgumentError } from '../../../utils/errors'; +import { NextNonceStrategy } from '../../../apis/node'; export default function genNonceField(senderKey: SenderKey): { serialize: (value: number) => Buffer; @@ -10,7 +11,7 @@ export default function genNonceField(senderKey: Sende value: number | undefined, params: {}, // TODO: replace `string` with AddressEncodings - options: { [key in SenderKey]: string } & { strategy?: 'continuity' | 'max'; onNode?: Node }, + options: { [key in SenderKey]: string } & { strategy?: NextNonceStrategy; onNode?: Node }, ) => Promise; deserialize: (value: Buffer) => number; senderKey: string; diff --git a/src/tx/validator.ts b/src/tx/validator.ts index 2d20821f24..234f8aecd9 100644 --- a/src/tx/validator.ts +++ b/src/tx/validator.ts @@ -142,23 +142,7 @@ validators.push( if (message == null) return []; return [{ message, key: 'InvalidAccountType', checkedKeys: ['tag'] }]; }, - (tx, { account, parentTxTypes }) => { - if (!('nonce' in tx) || parentTxTypes.includes(Tag.GaMetaTx)) return []; - const validNonce = account.nonce + 1; - if (tx.nonce === validNonce) return []; - return [{ - ...tx.nonce < validNonce - ? { - message: `Nonce ${tx.nonce} is already used, valid nonce is ${validNonce}`, - key: 'NonceAlreadyUsed', - } - : { - message: `Nonce ${tx.nonce} is too high, valid nonce is ${validNonce}`, - key: 'NonceHigh', - }, - checkedKeys: ['nonce'], - }]; - }, + // TODO: revert nonce check (tx, { consensusProtocolVersion }) => { const oracleCall = Tag.Oracle === tx.tag || Tag.OracleRegisterTx === tx.tag; const contractCreate = Tag.ContractCreateTx === tx.tag || Tag.GaAttachTx === tx.tag; diff --git a/test/integration/txVerification.ts b/test/integration/txVerification.ts index 65d913bc2e..c8e7f2b7ce 100644 --- a/test/integration/txVerification.ts +++ b/test/integration/txVerification.ts @@ -34,12 +34,10 @@ describe('Verify Transaction', () => { }); const signedTx = await aeSdk.signTransaction(spendTx, { onAccount: MemoryAccount.generate() }); const errors = await verifyTransaction(signedTx, node); - expect(errors.map(({ key }) => key)).to.be.eql([ - 'InvalidSignature', 'ExpiredTTL', 'NonceAlreadyUsed', - ]); + expect(errors.map(({ key }) => key)).to.be.eql(['InvalidSignature', 'ExpiredTTL']); }); - it('returns NonceHigh error', async () => { + it.skip('returns NonceHigh error', async () => { const spendTx = await aeSdk.buildTx({ tag: Tag.SpendTx, senderId: aeSdk.address, @@ -75,7 +73,7 @@ describe('Verify Transaction', () => { it('verifies channel create tx', async () => { const channelCreate = 'tx_+IgyAqEBA36iFX3O+BMXMZJbffeT423KLpEuFsISUTsGu8Sb10eJBWvHXi1jEAAAoQGTnVZ1Jow5NGyBOg3NAf+ie3mV8qDj/wBwyKBHFNdhT4kFa8deLWMQAAAAAQCGECcSfcAAwMCgGAbROhx5lfoSkXsM5MQLw+EAWei3pcUGj/zWSO8RGkAKfIRASg=='; const errors = await verifyTransaction(channelCreate, node); - expect(errors).to.have.lengthOf(2); + expect(errors).to.have.lengthOf(1); }); it('verifies nameFee for nameClaim transaction', async () => {