Skip to content

Commit

Permalink
feat(tx-builder): reject used accounts in GaAttachTx in Ceres
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Jan 22, 2024
1 parent d925d29 commit 88b1d5d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/tx/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,15 @@ validators.push(
}];
}
},
// TODO: move to fee field of tx builder after dropping Iris
(tx, { consensusProtocolVersion }) => ((
Tag.GaAttachTx === tx.tag
&& ConsensusProtocolVersion.Ceres === consensusProtocolVersion
&& tx.nonce !== 1
) ? [{
message: `Account ${tx.ownerId} can't become generalized because it is already used`,
key: 'AccountUsed',
checkedKeys: ['nonce'],
}]
: []),
);
13 changes: 13 additions & 0 deletions test/integration/txVerification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect } from 'chai';
import { getSdk } from '.';
import {
AeSdk, Node, InvalidTxError, ArgumentError, Tag, MemoryAccount, verifyTransaction,
ConsensusProtocolVersion,
} from '../../src';

describe('Verify Transaction', () => {
Expand Down Expand Up @@ -85,4 +86,16 @@ describe('Verify Transaction', () => {
const errors = await verifyTransaction(contractCall, node);
expect(errors.map(({ key }) => key)).to.include('ContractNotFound');
});

it('verifies nonce of gaAttach transaction', async () => {
const gaAttach = 'tx_+QEWUAGhAUfN4Ejc4KynKrM1XI1D2AWlqBrTeCVywu9B6hV4rnriAri0+LJGA6BFoqzc6YC/ewZLk3eumqCWL/K7O2Wqy+x14Zbcx4rB0MC4hbhV/kTWRB8ANwA3ABoOgq+CAAEAPwEDP/5s8lcLADcBBxd3AoJ3AAg8AgT7A01Ob3QgaW4gQXV0aCBjb250ZXh0AQP//qsVVmEANwCHAjcANwGXQAECgqovAxFE1kQfEWluaXQRbPJXCyVhdXRob3JpemURqxVWYSVnZXRUeEhhc2iCLwCFOC4wLjAAoGzyVwsKFZm3CCkeUKo9rxPQx/JIS8M33a0kE6N/1KAJgwgAA4ZJUs52OAAAa4Q7msoAhysRRNZEHz/z50Zp';
const errors = await verifyTransaction(gaAttach, node);
const isIris = (await aeSdk.api.getNodeInfo())
.consensusProtocolVersion === ConsensusProtocolVersion.Iris;
expect(errors.find((e) => e.key === 'AccountUsed')).to.eql(isIris ? undefined : {
message: 'Account ak_Yd9EiaBy8GNXWLkMuH53H9hiCyEuL3RKxN4wYKhN8xDnjKRpb can\'t become generalized because it is already used',
key: 'AccountUsed',
checkedKeys: ['nonce'],
});
});
});

0 comments on commit 88b1d5d

Please sign in to comment.