Skip to content

Commit

Permalink
chore(cleanup):
Browse files Browse the repository at this point in the history
- test cleanup
- added new eslint rules and upped to latest
  • Loading branch information
leszek-vechain committed Dec 11, 2024
1 parent 4d52675 commit 58d2c5b
Show file tree
Hide file tree
Showing 28 changed files with 542 additions and 187 deletions.
23 changes: 0 additions & 23 deletions .eslintrc.js

This file was deleted.

44 changes: 44 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import pluginJest from "eslint-plugin-jest";
import eslintConfigPrettier from "eslint-config-prettier";
import jestExtended from 'eslint-plugin-jest-extended';
// import js from "@eslint/js";


export default [
// js.configs.recommended,
jestExtended.configs['flat/all'],
{
plugins: { jest: pluginJest },
languageOptions: {
globals: pluginJest.environments.globals.globals,
parserOptions: {
sourceType: "module",
ecmaVersion: 2024
}
},
files: ["**/*.spec.js", "**/*.test.js"],
ignores: [
".yarn/*",
"*config.js",
"**/node_modules/",
".git/*",
"artifacts/",
"cache/",
"typechain-types/",
"jest-html-reporters-attach/",
"coverage/"
],
rules: {
"indent": ["error", 2],
'jest/prefer-expect-assertions': 'warn',
"jest/no-disabled-tests": "warn",
"jest/no-focused-tests": "error",
"jest/no-identical-title": "error",
"jest/prefer-to-have-length": "warn",
"jest/valid-expect": ["error", { minArgs: 1, maxArgs: 2 }],
"jest-extended/prefer-to-be-true": "warn",
"jest-extended/prefer-to-be-false": "error"
}
},
eslintConfigPrettier
];
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"devDependencies": {
"@babel/preset-env": "^7.23.8",
"@babel/preset-typescript": "^7.23.3",
"@eslint/js": "^9.16.0",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/babel__core": "^7",
Expand All @@ -29,8 +30,10 @@
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"eslint": "^8.56.0",
"eslint": "^9.16.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^28.9.0",
"eslint-plugin-jest-extended": "^2.4.0",
"eslint-plugin-prettier": "^5.1.3",
"ethers": "^6.4.0",
"hardhat": "^2.14.0",
Expand Down Expand Up @@ -64,9 +67,9 @@
"@openzeppelin/contracts": "^5.0.2",
"@types/chai": "^4.3.16",
"@types/proper-lockfile": "^4.1.4",
"@vechain/sdk-core": "1.0.0-rc.4",
"@vechain/sdk-logging": "1.0.0-rc.4",
"@vechain/sdk-network": "1.0.0-rc.4",
"@vechain/sdk-core": "1.0.0-rc.5",
"@vechain/sdk-logging": "1.0.0-rc.5",
"@vechain/sdk-network": "1.0.0-rc.5",
"async-mutex": "^0.4.0",
"axios": "^1.6.5",
"bignumber.js": "^9.1.2",
Expand Down
5 changes: 1 addition & 4 deletions src/logs/write-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ const writeTransfers = async () => {

await pollReceipt(txId)

const receipt =
await Client.sdk.transactions.waitForTransaction(txId)

return receipt
return await Client.sdk.transactions.waitForTransaction(txId)
}),
)

Expand Down
48 changes: 0 additions & 48 deletions src/thor-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,47 +281,6 @@ class ThorClient {
)
}

/**
* A utility function to debug a particular clause in a reverted transaction
*/
async debugRevertedClause(txId, clauseIndex) {
const targetPrefix = await this.getDebugTargetPrefix(txId)

if (!targetPrefix) {
return
}

return this.traceClause({
target: `${targetPrefix}/${clauseIndex}`,
name: 'call',
config: {
OnlyTopCall: true,
},
})
}

/**
* A utility function to get the index of a transaction in a block
* @param txId
*/
async getDebugTargetPrefix(txId) {
const tx = await this.getTransaction(txId)

if (!tx.success || !tx.body?.meta?.blockID) {
return undefined
}

const block = await this.getBlock(tx.body.meta.blockID, false)

if (!block.success || !block.body) {
return undefined
}

const txIndex = block.body.transactions.indexOf(txId)

return `${block.body.id}/${txIndex}`
}

openWebsocket(url, callback, errorCallback) {
const ws = new WebSocket(url)
ws.onmessage = (event) => {
Expand Down Expand Up @@ -404,13 +363,6 @@ class LoadBalancedClient {
return new Proxy(this.getRandomSDKClient(), handler)
}

index(index) {
return {
sdk: this.sdkClients[index],
raw: this.clients[index],
}
}

getRandomClient() {
return this.clients[Math.floor(Math.random() * this.clients.length)]
}
Expand Down
4 changes: 2 additions & 2 deletions src/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ export const pollReceipt = async (txId, timeout = 60_000) => {
const blocks = blockIds.values()

if (
receipts.length == Client.clients.length &&
receipts.length === Client.clients.length &&
HexUtils.isValid(blocks.next().value) &&
blockIds.size == 1
blockIds.size === 1
) {
clearInterval(intervalId) // Clear the interval when the receipt is found
resolve(receipts[0].body)
Expand Down
2 changes: 0 additions & 2 deletions src/utils/legacy-bloom.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import HexUtils from './hex-utils'
* Implementation from https://github.com/vechain/thor-devkit.js/blob/master/src/bloom.ts
*/
export class LegacyBloom {
/** number of hash functions */
static MAX_K = 16
/** bits length */
static BITS_LENGTH = 2048

Expand Down
4 changes: 2 additions & 2 deletions test/evm/eth-opcodes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { pollReceipt } from '../../src/transactions'
*/

/**
* @group opcodes
* @group evm
* @group opcodes
*/
describe('EVM Opcodes', () => {
let wallet
Expand Down Expand Up @@ -54,6 +54,6 @@ describe('EVM Opcodes', () => {
await pollReceipt(id)
const tx = await wait()

expect(tx?.reverted).toBe(true)
expect(tx?.reverted).toBeTrue()
})
})
6 changes: 5 additions & 1 deletion test/evm/evm-methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { HEX_REGEX_40 } from '../../src/utils/hex-utils'
import { Hex, Keccak256, Txt } from '@vechain/sdk-core'
import { Client } from '../../src/thor-client'

/**
* @group evm
* @group methods
*/
describe('EVM methods', () => {
let evmMethods
const wallet = ThorWallet.withFunds()
Expand Down Expand Up @@ -102,7 +106,7 @@ describe('EVM methods', () => {
it.e2eTest('should be able to get "msg.value"', 'all', async () => {
const msgValue = await evmMethods.transact.getMsgValue({ value: 100 })
const receipt = await msgValue.wait(3, 15)
expect(receipt.reverted).toEqual(false)
expect(receipt.reverted).toBeFalse()
})

it.e2eTest('should be able to get "tx.gasprice"', 'all', async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/evm/individual-opcodes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const opcodesInterface = Opcodes.createInterface()
*/

/**
* @group opcodes
* @group evm
* @group opcodes
*/
describe('Individual OpCodes', () => {
let wallet
Expand Down Expand Up @@ -415,7 +415,7 @@ describe('Individual OpCodes', () => {

expect(
debugged.structLogs.some((log) => log.op === name),
).toEqual(true)
).toBeTrue()
expect(debugged.returnValue).toBe(expected)
},
)
Expand All @@ -440,7 +440,7 @@ describe('Individual OpCodes', () => {

expect(
debugged.structLogs.some((log) => log.op === 'BALANCE'),
).toEqual(true)
).toBeTrue()
expect(balance).toBeGreaterThan(0)
},
)
Expand Down Expand Up @@ -603,7 +603,7 @@ describe('Individual OpCodes', () => {

const receipt = await pollReceipt(tx.id ?? '')

expect(receipt.reverted).toBe(true)
expect(receipt.reverted).toBeTrue()

// 0x5f is the PUSH0 opcode
const simulation = await Client.raw.executeAccountBatch({
Expand Down
14 changes: 7 additions & 7 deletions test/thorest-api/accounts/contracts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('Contracts', () => {
await pollReceipt(tx.id)
const receipt = await tx.wait()
expect(receipt).toBeDefined()
expect(receipt.reverted).toBe(false)
expect(receipt.reverted).toBeFalse()

const newValue = await counter.read.getCounter()
expect(newValue[0]).toBe(startValue[0] + 3n)
Expand All @@ -114,12 +114,12 @@ describe('Contracts', () => {
const estimate = await Client.sdk.gas.estimateGas([
payClause.clause,
])
expect(estimate.reverted).toBe(true)
expect(estimate.reverted).toBeTrue()
expect(
estimate.revertReasons.some(
(reason) => reason === 'Not authorized',
),
).toBe(true)
).toBeTrue()

const authorizeClause = authorizeTransaction.clause.authorize()

Expand All @@ -132,7 +132,7 @@ describe('Contracts', () => {
await pollReceipt(tx.id)
const receipt = await tx.wait()
expect(receipt).toBeDefined()
expect(receipt.reverted).toBe(false)
expect(receipt.reverted).toBeFalse()
},
)

Expand All @@ -151,7 +151,7 @@ describe('Contracts', () => {

const receipt = await wallet.sendClauses([clause], true)
expect(receipt).toBeDefined()
expect(receipt.reverted).toBe(false)
expect(receipt.reverted).toBeFalse()
},
)

Expand All @@ -170,7 +170,7 @@ describe('Contracts', () => {

const receipt = await wallet.sendClauses([clause], true)
expect(receipt).toBeDefined()
expect(receipt.reverted).toBe(true)
expect(receipt.reverted).toBeTrue()
},
)

Expand Down Expand Up @@ -205,7 +205,7 @@ describe('Contracts', () => {

const receipt = await wallet.sendClauses([clause], true)
expect(receipt).toBeDefined()
expect(receipt.reverted).toBe(true)
expect(receipt.reverted).toBeTrue()

const currentText = await stringer.read.text()
expect(currentText[0]).toBe(priorText[0])
Expand Down
12 changes: 6 additions & 6 deletions test/thorest-api/accounts/execute-codes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe('POST /accounts/*', function () {
expect(
historicCall.body?.[0]?.reverted,
'Transaction should revert',
).toEqual(true)
).toBeTrue()

// generated wallet was funded, so this should be successful
const currentCall = await Client.raw.executeAccountBatch(
Expand All @@ -180,7 +180,7 @@ describe('POST /accounts/*', function () {
expect(
currentCall.body?.[0]?.reverted,
'Transaction should not revert',
).toEqual(false)
).toBeFalse()
},
)

Expand All @@ -198,8 +198,8 @@ describe('POST /accounts/*', function () {
'API response should be a success',
).toBeTrue()
expect(historicCall.httpCode, 'Expected HTTP Code').toEqual(200)
expect(historicCall.body?.[0]?.reverted).toEqual(false)
expect(historicCall.body?.[1]?.reverted).toEqual(false)
expect(historicCall.body?.[0]?.reverted).toBeFalse()
expect(historicCall.body?.[1]?.reverted).toBeFalse()
const balanceOf = parseInt(historicCall.body?.[0]?.data ?? '-1', 16)
const totalSupply = parseInt(
historicCall.body?.[1]?.data ?? '-1',
Expand All @@ -225,8 +225,8 @@ describe('POST /accounts/*', function () {
'API response should be a success',
).toBeTrue()
expect(res.httpCode, 'Expected HTTP Code').toEqual(200)
expect(res.body?.[0]?.reverted).toEqual(false)
expect(res.body?.[1]?.reverted).toEqual(false)
expect(res.body?.[0]?.reverted).toBeFalse()
expect(res.body?.[1]?.reverted).toBeFalse()
},
)
})
Expand Down
1 change: 1 addition & 0 deletions test/thorest-api/debug/storage-range.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('GET /debug/storage-range', () => {
},
options: { address: counter.address, maxResult: 1 },
})
/* eslint-disable jest/prefer-to-have-length */
expect(Object.keys(storage.storage).length).toBe(1)
expect(storage.nextKey).toBeNull()
},
Expand Down
3 changes: 2 additions & 1 deletion test/thorest-api/debug/tracers-call.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ describe('POST /debug/tracers/call', () => {
const body = response.body

expect(body.gas).toEqual(0)
expect(body.failed).toEqual(false)
expect(body.failed).toBeFalse()
expect(body.returnValue).toMatch(HEX_AT_LEAST_1)
/* eslint-disable jest/prefer-to-have-length */
expect(response.body.structLogs.length).toBe(23)
verifyStructLogs(response.body.structLogs)
})
Expand Down
Loading

0 comments on commit 58d2c5b

Please sign in to comment.