Skip to content

Commit

Permalink
fix(tx-builder): drop nonce validator to avoid false positive
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Feb 28, 2023
1 parent 2b528b7 commit a669aae
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/tx/builder/field-types/nonce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 extends string>(senderKey: SenderKey): {
serialize: (value: number) => Buffer;
Expand All @@ -10,7 +11,7 @@ export default function genNonceField<SenderKey extends string>(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<number>;
deserialize: (value: Buffer) => number;
senderKey: string;
Expand Down
18 changes: 1 addition & 17 deletions src/tx/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions test/integration/txVerification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit a669aae

Please sign in to comment.