show logs from contract

pull/2716/head^2
Aniket-Engg 2 years ago committed by Aniket
parent 865af85203
commit 582fa7029f
  1. 4
      libs/remix-tests/src/run.ts
  2. 22
      libs/remix-tests/src/runTestFiles.ts
  3. 2
      libs/remix-tests/tests/examples_0/assert_ok_test.sol

@ -4,7 +4,7 @@ import path from 'path'
import axios, { AxiosResponse } from 'axios'
import { runTestFiles } from './runTestFiles'
import fs from './fileSystem'
import { Provider } from '@remix-project/remix-simulator'
import { Provider, extend } from '@remix-project/remix-simulator'
import { CompilerConfiguration } from './types'
import Log from './logger'
import colors from 'colors'
@ -115,7 +115,7 @@ commander
const provider: any = new Provider()
await provider.init()
web3.setProvider(provider)
extend(web3)
runTestFiles(path.resolve(testsPath), isDirectory, web3, compilerConfig)
})

@ -4,7 +4,7 @@ import { runTest } from './testRunner'
import { TestResultInterface, ResultsInterface, CompilerConfiguration, compilationInterface, ASTInterface, Options, AstNode } from './types'
import colors from 'colors'
import Web3 from 'web3'
import { format } from 'util'
import { compileFileOrFiles } from './compiler'
import { deployAll } from './deployer'
@ -22,6 +22,15 @@ export function runTestFiles (filepath: string, isDirectory: boolean, web3: Web3
opts = opts || {}
compilerConfig = compilerConfig || {} as CompilerConfiguration
const sourceASTs: any = {}
const printLog = (log: string[]) => {
let formattedLog
if (typeof log[0] === 'string' && (log[0].includes('%s') || log[0].includes('%d'))) {
formattedLog = format(log[0], ...log.slice(1))
} else {
formattedLog = log.join(' ')
}
signale.log(formattedLog)
}
const { Signale } = require('signale') // eslint-disable-line
// signale configuration
const options = {
@ -36,6 +45,11 @@ export function runTestFiles (filepath: string, isDirectory: boolean, web3: Web3
label: '',
color: 'white'
},
log: {
badge: '\t',
label: '',
color: 'white'
},
error: {
badge: '\t✘',
label: '',
@ -111,8 +125,10 @@ export function runTestFiles (filepath: string, isDirectory: boolean, web3: Web3
if (result.type === 'contract') {
signale.name(result.value.white)
} else if (result.type === 'testPass') {
signale.result(result.value)
if (result?.hhLogs?.length) result.hhLogs.forEach(printLog)
signale.result(result.value.green)
} else if (result.type === 'testFailure') {
if (result?.hhLogs?.length) result.hhLogs.forEach(printLog)
signale.error(result.value.red)
errors.push(result)
}
@ -127,7 +143,7 @@ export function runTestFiles (filepath: string, isDirectory: boolean, web3: Web3
async.eachOfLimit(contractsToTest, 1, (contractName: string, index, cb) => {
try {
const fileAST: AstNode = sourceASTs[contracts[contractName]['filename']]
runTest(contractName, contracts[contractName], contractsToTestDetails[index], fileAST, { accounts }, _testCallback, (err, result) => {
runTest(contractName, contracts[contractName], contractsToTestDetails[index], fileAST, { accounts, web3 }, _testCallback, (err, result) => {
if (err) {
console.log(err)
return cb(err)

@ -1,6 +1,4 @@
import "remix_tests.sol"; // this import is automatically injected by Remix.
import "hardhat/console.sol";
contract AssertOkTest {

Loading…
Cancel
Save