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

Commit

Permalink
Fix: transactionObjectValidator to ignore nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
rdig committed Dec 27, 2023
1 parent eccdfb7 commit d1c5eee
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ describe('`Core` Module', () => {
'chainId',
TRANSACTION.CHAIN_ID,
);
expect(validatedTransactionObject).toHaveProperty(
'nonce',
TRANSACTION.NONCE,
);
expect(validatedTransactionObject.value.toString()).toEqual(
TRANSACTION.VALUE,
);
Expand Down Expand Up @@ -164,5 +160,39 @@ describe('`Core` Module', () => {
expect(addressValidator).not.toHaveBeenCalled();
expect(addressValidator).not.toHaveBeenCalledWith(to);
});
test('Validates nonce, only if one was provided', async () => {
transactionObjectValidator({
gasPrice,
gasLimit,
chainId,
value,
inputData,
});
/*
* Validates gas price and gas limit
*/
expect(bigNumberValidator).toHaveBeenCalled();
expect(bigNumberValidator).toHaveBeenCalledWith(gasPrice);
expect(bigNumberValidator).toHaveBeenCalledWith(gasLimit);
/*
* Validates the chain Id
*/
expect(safeIntegerValidator).toHaveBeenCalled();
expect(safeIntegerValidator).toHaveBeenCalledWith(chainId);
/*
* Validates the transaction value
*/
expect(bigNumberValidator).toHaveBeenCalled();
expect(bigNumberValidator).toHaveBeenCalledWith(value);
/*
* Validates the transaction input data
*/
expect(hexSequenceValidator).toHaveBeenCalled();
expect(hexSequenceValidator).toHaveBeenCalledWith(inputData);
/*
* Doesn't validates the nonce, since it wasn't provided
*/
expect(safeIntegerValidator).not.toHaveBeenCalledWith(nonce);
});
});
});
1 change: 0 additions & 1 deletion packages/@purser/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export const TRANSACTION = {
CHAIN_ID: 1,
GAS_PRICE: '9000000000', // 9 Gwei
GAS_LIMIT: '21000',
NONCE: 0,
VALUE: '0',
INPUT_DATA: '',
};
Expand Down
13 changes: 8 additions & 5 deletions packages/@purser/core/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export const transactionObjectValidator = ({
chainId = TRANSACTION.CHAIN_ID,
gasPrice = bigNumber(TRANSACTION.GAS_PRICE),
gasLimit = bigNumber(TRANSACTION.GAS_LIMIT),
nonce = TRANSACTION.NONCE,
nonce,
to,
value = bigNumber(TRANSACTION.VALUE),
inputData = TRANSACTION.INPUT_DATA,
Expand All @@ -228,10 +228,13 @@ export const transactionObjectValidator = ({
* Check if the chain id value is valid (a positive, safe integer)
*/
safeIntegerValidator(chainId);
/*
* Check if the nonce value is valid (a positive, safe integer)
*/
safeIntegerValidator(nonce);
if (nonce) {
/*
* Only check if the nonce value is valid (a positive, safe integer),
* if one was provided in the initial transaction object
*/
safeIntegerValidator(nonce);
}
/*
* Only check if the address (`to` prop) is in the correct
* format, if one was provided in the initial transaction object
Expand Down
2 changes: 1 addition & 1 deletion packages/@purser/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface TransactionObjectType {
chainId: number;
gasPrice: ExtendedBN;
gasLimit: ExtendedBN;
nonce: number;
nonce?: number;
value: ExtendedBN;
inputData: string;
}
Expand Down

0 comments on commit d1c5eee

Please sign in to comment.