Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avkos committed Oct 12, 2023
1 parent 0fd2602 commit 6c16bea
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/web3-eth-accounts/src/tx/transactionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class TransactionFactory {
case 2:
return FeeMarketEIP1559Transaction.fromSerializedTx(data, txOptions);
default: {
const ExtraTransaction = extraTxTypes.get(data[0]);
const ExtraTransaction = extraTxTypes.get(Number(data[0]));
if (ExtraTransaction?.fromSerializedTx) {
return ExtraTransaction.fromSerializedTx(
data,
Expand Down
51 changes: 51 additions & 0 deletions packages/web3-eth-accounts/test/unit/tx/registerNewTx.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
This file is part of web3.js.
web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import { TransactionFactory } from '../../../src/tx/transactionFactory';
import { BaseTransaction } from '../../../src/tx/baseTransaction';
import { TxData, TxOptions } from '../../../src/tx';

describe('Register new TX', () => {
it('validateCannotExceedMaxInteger()', () => {
const TYPE = 20;
// @ts-ignore
class SomeNewTxType extends BaseTransaction<any> {
constructor(txData: TxData, opts: TxOptions = {}) {
super(txData, opts);
// @ts-ignore
this._type = 20;
}
public static fromTxData() {
return 'new fromTxData';
}
public static fromSerializedTx() {
return 'new fromSerializedData';
}
}
TransactionFactory.registerTransactionType(TYPE, SomeNewTxType);
const txData = {
from: '0x',
to: '0x',
value: '0x1',
type: TYPE,
};
expect(TransactionFactory.fromTxData(txData)).toBe('new fromTxData');
expect(TransactionFactory.fromSerializedData(new Uint8Array([TYPE, 10]))).toBe(
'new fromSerializedData',
);
});
});

0 comments on commit 6c16bea

Please sign in to comment.