Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"bignumber.js": "^9.1.2",
"dotenv": "^16.4.7",
"hardhat-ethers": "^1.0.1",
"dockerode": "^4.0.4",
"prettier-plugin-solidity": "^1.4.1",
"proper-lockfile": "^4.1.2",
"vitest": "^3.0.1",
Expand Down
48 changes: 46 additions & 2 deletions test/setupAfterEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import { Client } from '../src/thor-client'
import 'dotenv/config'
import { testEnv } from '../src/test-env'
import { test, it } from 'vitest'
import Docker from 'dockerode'

it.e2eTest = (title, tags, testFunc) => {
const docker = new Docker({ socketPath: '/var/run/docker.sock' })
const panicRegex = /panic.*/
const errorRegex = /ERROR\[\d{2}-\d{2}\|\d{2}:\d{2}:\d{2}\.\d{3}\].*"/

it.e2eTest = async (title, tags, testFunc) => {
if (tags === 'all' || tags.includes(testEnv.type)) {
// eslint-disable-next-line vitest/valid-title,vitest/expect-expect
test(title, testFunc)
test(title, executeFunctionAndValidateNodeLogs(testFunc, title))
} else {
// eslint-disable-next-line vitest/valid-title
test.skip(title, testFunc)
Expand All @@ -17,3 +22,42 @@ afterAll(async () => {
Client.raw.closeAllSubscriptions()
Client.sdk.destroy()
})

function executeFunctionAndValidateNodeLogs(fn, title) {
return async () => {
await fn()
await parseThorLogs()
}
}

async function parseThorLogs() {
const containers = await docker.listContainers()
const filteredContainers = containers.filter((container) => {
const names = container.Names.join(',')
return names.includes('public-node') || names.includes('authority-node')
})
await Promise.all(
filteredContainers.map(async (container) => {
const runningContainer = docker.getContainer(container.Id)
const logs = await runningContainer.logs({
follow: false,
stdout: true,
stderr: true,
tail: 1000,
timestamps: true,
})
if (logs) {
const errors = logs
.toString()
.split('\n')
.filter((row) => {
return panicRegex.test(row) || errorRegex.test(row)
})
if (errors.length > 0) {
console.log(errors.join('\n'))
}
expect(errors.length, 'Errors found in thor node logs').toBe(0)
}
}),
)
}
Loading