Skip to content

Commit

Permalink
tx: apply strict-boolean-expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrocheleau committed Jul 8, 2022
1 parent dddcc97 commit 502f85e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/tx/src/baseTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ export abstract class BaseTransaction<TransactionObject> {
*/
protected _getCommon(common?: Common, chainId?: BigIntLike) {
// Chain ID provided
if (chainId) {
if (typeof chainId !== 'undefined') {
const chainIdBigInt = bufferToBigInt(toBuffer(chainId))
if (common) {
if (common.chainId() !== chainIdBigInt) {
Expand Down
2 changes: 1 addition & 1 deletion packages/tx/src/eip1559Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export default class FeeMarketEIP1559Transaction extends BaseTransaction<FeeMark
this.common = this._getCommon(opts.common, chainId)
this.chainId = this.common.chainId()

if (!this.common.isActivatedEIP(1559)) {
if (this.common.isActivatedEIP(1559) === false) {
throw new Error('EIP-1559 not enabled on Common')
}
this.activeCapabilities = this.activeCapabilities.concat([1559, 2718, 2930])
Expand Down
2 changes: 1 addition & 1 deletion packages/tx/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class AccessLists {
public static getAccessListData(accessList: AccessListBuffer | AccessList) {
let AccessListJSON
let bufferAccessList
if (accessList && isAccessList(accessList)) {
if (isAccessList(accessList)) {
AccessListJSON = accessList
const newAccessList: AccessListBuffer = []

Expand Down
10 changes: 5 additions & 5 deletions packages/tx/test/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ tape('[BaseTransaction]', function (t) {
for (const txType of txTypes) {
txType.txs.forEach(function (tx: any, i: number) {
const { privateKey } = txType.fixtures[i]
if (privateKey) {
if (typeof privateKey !== 'undefined') {
st.ok(tx.sign(Buffer.from(privateKey, 'hex')), `${txType.name}: should sign tx`)
}

Expand Down Expand Up @@ -316,7 +316,7 @@ tape('[BaseTransaction]', function (t) {
for (const txType of txTypes) {
txType.txs.forEach(function (tx: any, i: number) {
const { privateKey, sendersAddress } = txType.fixtures[i]
if (privateKey) {
if (typeof privateKey !== 'undefined') {
const signedTx = tx.sign(Buffer.from(privateKey, 'hex'))
st.equal(
signedTx.getSenderAddress().toString(),
Expand All @@ -333,7 +333,7 @@ tape('[BaseTransaction]', function (t) {
for (const txType of txTypes) {
txType.txs.forEach(function (tx: any, i: number) {
const { privateKey } = txType.fixtures[i]
if (privateKey) {
if (typeof privateKey !== 'undefined') {
const signedTx = tx.sign(Buffer.from(privateKey, 'hex'))
const txPubKey = signedTx.getSenderPublicKey()
const pubKeyFromPriv = privateToPublic(Buffer.from(privateKey, 'hex'))
Expand All @@ -355,7 +355,7 @@ tape('[BaseTransaction]', function (t) {
for (const txType of txTypes) {
txType.txs.forEach(function (tx: any, i: number) {
const { privateKey } = txType.fixtures[i]
if (privateKey) {
if (typeof privateKey !== 'undefined') {
let signedTx = tx.sign(Buffer.from(privateKey, 'hex'))
signedTx = JSON.parse(JSON.stringify(signedTx)) // deep clone
;(signedTx as any).s = SECP256K1_ORDER + BigInt(1)
Expand All @@ -373,7 +373,7 @@ tape('[BaseTransaction]', function (t) {
for (const txType of txTypes) {
txType.txs.forEach(function (tx: any, i: number) {
const { privateKey } = txType.fixtures[i]
if (privateKey) {
if (typeof privateKey !== 'undefined') {
const signedTx = tx.sign(Buffer.from(privateKey, 'hex'))
st.ok(signedTx.verifySignature(), `${txType.name}: should verify signing it`)
}
Expand Down
12 changes: 6 additions & 6 deletions packages/tx/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import * as minimist from 'minimist'

const argv = minimist(process.argv.slice(2))

if (argv.b) {
if (argv.b === true) {
require('./base.spec')
} else if (argv.l) {
} else if (argv.l === true) {
require('./legacy.spec')
} else if (argv.e) {
} else if (argv.e === true) {
require('./typedTxsAndEIP2930.spec')
require('./eip1559.spec')
} else if (argv.t) {
} else if (argv.t === true) {
require('./transactionRunner')
} else if (argv.f) {
} else if (argv.f === true) {
require('./transactionFactory.spec')
} else if (argv.a) {
} else if (argv.a === true) {
// All manual API tests
require('./base.spec')
require('./legacy.spec')
Expand Down
2 changes: 1 addition & 1 deletion packages/tx/test/testLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export async function getTests(
const testsByName = JSON.parse(content)
const testNames = Object.keys(testsByName)
for (const testName of testNames) {
if (!skipPredicate(testName, testsByName[testName])) {
if (skipPredicate(testName, testsByName[testName]) === false) {
await onFile(parsedFileName, subDir, testName, testsByName[testName])
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/tx/test/transactionRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const EIPs: any = {
}

tape('TransactionTests', async (t) => {
const fileFilterRegex = file ? new RegExp(file + '[^\\w]') : undefined
const fileFilterRegex = typeof file !== 'undefined' ? new RegExp(file + '[^\\w]') : undefined
await getTests(
(
_filename: string,
Expand All @@ -56,14 +56,14 @@ tape('TransactionTests', async (t) => {
continue
}
const forkTestData = testData.result[forkName]
const shouldBeInvalid = !!forkTestData.exception
const shouldBeInvalid = typeof forkTestData.exception !== 'undefined'

try {
const rawTx = toBuffer(testData.txbytes)
const hardfork = forkNameMap[forkName]
const common = new Common({ chain: 1, hardfork })
const activateEIPs = EIPs[forkName]
if (activateEIPs) {
if (typeof activateEIPs !== undefined) {
common.setEIPs(activateEIPs)
}
const tx = TransactionFactory.fromSerializedData(rawTx, { common })
Expand All @@ -73,7 +73,7 @@ tape('TransactionTests', async (t) => {
const senderIsCorrect = forkTestData.sender === sender
const hashIsCorrect = forkTestData.hash?.slice(2) === hash

const hashAndSenderAreCorrect = forkTestData && senderIsCorrect && hashIsCorrect
const hashAndSenderAreCorrect = senderIsCorrect && hashIsCorrect
if (shouldBeInvalid) {
st.assert(!txIsValid, `Transaction should be invalid on ${forkName}`)
} else {
Expand Down

0 comments on commit 502f85e

Please sign in to comment.