WIP - Fix yarn nx run remix-tests:test

pull/3949/head
Wyatt Barnes 1 year ago
parent 855b38aca1
commit 059c998734
No known key found for this signature in database
GPG Key ID: 163BAC08AC766FF4
  1. 2
      apps/remix-ide/src/app/plugins/solidity-script.tsx
  2. 8
      apps/remix-ide/src/blockchain/blockchain.tsx
  3. 17
      libs/remix-debug/src/init.ts
  4. 4
      libs/remix-lib/src/execution/txListener.ts
  5. 62
      libs/remix-lib/src/init.ts
  6. 52
      libs/remix-simulator/src/provider.ts
  7. 4
      libs/remix-tests/src/deployer.ts
  8. 8
      libs/remix-tests/src/testRunner.ts
  9. 12
      libs/remix-tests/tests/testRunner.spec.ts

@ -80,7 +80,7 @@ export class SolidityScript extends Plugin {
}
const receiptCall = await web3.eth.sendTransaction(tx)
const hhlogs = await web3.eth.getHHLogsForTx(receiptCall.transactionHash)
const hhlogs = await web3.testPlugin.getHHLogsForTx(receiptCall.transactionHash)
if (hhlogs && hhlogs.length) {
const finalLogs = <div><div><b>console.log:</b></div>

@ -666,7 +666,7 @@ export class Blockchain extends Plugin {
if (error) return reject(error)
try {
if (this.executionContext.isVM()) {
const execResult = await this.web3().eth.getExecutionResultFromSimulator(result.transactionHash)
const execResult = await this.web3().testPlugin.getExecutionResultFromSimulator(result.transactionHash)
resolve(resultToRemixTx(result, execResult))
} else
resolve(resultToRemixTx(result))
@ -767,7 +767,7 @@ export class Blockchain extends Plugin {
const isVM = this.executionContext.isVM()
if (isVM && tx.useCall) {
try {
result.transactionHash = await this.web3().eth.getHashFromTagBySimulator(timestamp)
result.transactionHash = await this.web3().testPlugin.getHashFromTagBySimulator(timestamp)
} catch (e) {
console.log('unable to retrieve back the "call" hash', e)
}
@ -805,7 +805,7 @@ export class Blockchain extends Plugin {
let execResult
let returnValue = null
if (isVM) {
const hhlogs = await this.web3().eth.getHHLogsForTx(txResult.transactionHash)
const hhlogs = await this.web3().testPlugin.getHHLogsForTx(txResult.transactionHash)
if (hhlogs && hhlogs.length) {
const finalLogs = <div><div><b>console.log:</b></div>
@ -827,7 +827,7 @@ export class Blockchain extends Plugin {
_paq.push(['trackEvent', 'udapp', 'hardhat', 'console.log'])
this.call('terminal', 'logHtml', finalLogs)
}
execResult = await this.web3().eth.getExecutionResultFromSimulator(txResult.transactionHash)
execResult = await this.web3().testPlugin.getExecutionResultFromSimulator(txResult.transactionHash)
if (execResult) {
// if it's not the VM, we don't have return value. We only have the transaction, and it does not contain the return value.
returnValue = execResult ? toBuffer(execResult.returnValue) : toBuffer(addHexPrefix(txResult.result) || '0x0000000000000000000000000000000000000000000000000000000000000000')

@ -5,12 +5,12 @@ export function loadWeb3 (url) {
if (!url) url = 'http://localhost:8545'
const web3 = new Web3()
web3.setProvider(new Web3.providers.HttpProvider(url))
web3.registerPlugin(new Web3DebugPlugin(web3))
web3.registerPlugin(new Web3DebugPlugin())
return web3
}
export function extendWeb3 (web3) {
web3.registerPlugin(new Web3DebugPlugin(web3))
web3.registerPlugin(new Web3DebugPlugin())
}
export function setProvider (web3, url) {
@ -34,15 +34,8 @@ export function web3DebugNode (network) {
class Web3DebugPlugin extends Web3PluginBase {
public pluginNamespace = 'debug'
private _web3;
constructor(web3) {
super()
this._web3 = web3;
}
public preimage(key, cb) {
this._web3.requestManager.send({
this.requestManager.send({
method: 'debug_preimage',
params: [key]
})
@ -51,7 +44,7 @@ class Web3DebugPlugin extends Web3PluginBase {
}
public traceTransaction(txHash, options, cb) {
this._web3.requestManager.send({
this.requestManager.send({
method: 'debug_traceTransaction',
params: [txHash, options]
})
@ -60,7 +53,7 @@ class Web3DebugPlugin extends Web3PluginBase {
}
public storageRangeAt(txBlockHash, txIndex, address, start, maxSize, cb) {
this._web3.requestManager.send({
this.requestManager.send({
method: 'debug_storageRangeAt',
params: [txBlockHash, txIndex, address, start, maxSize]
})

@ -63,7 +63,7 @@ export class TxListener {
let returnValue
let execResult
if (this.executionContext.isVM()) {
execResult = await this.executionContext.web3().eth.getExecutionResultFromSimulator(txResult.transactionHash)
execResult = await this.executionContext.web3().testPlugin.getExecutionResultFromSimulator(txResult.transactionHash)
returnValue = toBuffer(execResult.returnValue)
} else {
returnValue = toBuffer(addHexPrefix(txResult.result))
@ -99,7 +99,7 @@ export class TxListener {
let execResult
if (this.executionContext.isVM()) {
execResult = await this.executionContext.web3().eth.getExecutionResultFromSimulator(txResult.transactionHash)
execResult = await this.executionContext.web3().testPlugin.getExecutionResultFromSimulator(txResult.transactionHash)
}
addExecutionCosts(txResult, tx, execResult)

@ -1,54 +1,44 @@
'use strict'
import Web3 from 'web3'
import Web3, { Web3PluginBase } from 'web3'
export function loadWeb3 (url = 'http://localhost:8545') {
const web3 = new Web3()
web3.setProvider(new Web3.providers.HttpProvider(url))
extend(web3)
web3.registerPlugin(new Web3DebugPlugin())
return web3
}
export function extendWeb3 (web3) {
extend(web3)
web3.registerPlugin(new Web3DebugPlugin())
}
export function extend (web3) {
if (!web3.extend) {
return
}
// DEBUG
const methods = []
if (!(web3.debug && web3.debug.preimage)) {
methods.push(new web3.extend.Method({
name: 'preimage',
call: 'debug_preimage',
inputFormatter: [null],
params: 1
}))
}
class Web3DebugPlugin extends Web3PluginBase {
public pluginNamespace = 'debug'
if (!(web3.debug && web3.debug.traceTransaction)) {
methods.push(new web3.extend.Method({
name: 'traceTransaction',
call: 'debug_traceTransaction',
inputFormatter: [null, null],
params: 2
}))
public preimage(key, cb) {
this.requestManager.send({
method: 'debug_preimage',
params: [key]
})
.then(result => cb(null, result))
.catch(error => cb(error))
}
if (!(web3.debug && web3.debug.storageRangeAt)) {
methods.push(new web3.extend.Method({
name: 'storageRangeAt',
call: 'debug_storageRangeAt',
inputFormatter: [null, null, null, null, null],
params: 5
}))
public traceTransaction(txHash, options, cb) {
this.requestManager.send({
method: 'debug_traceTransaction',
params: [txHash, options]
})
.then(result => cb(null, result))
.catch(error => cb(error))
}
if (methods.length > 0) {
web3.extend({
property: 'debug',
methods: methods,
properties: []
public storageRangeAt(txBlockHash, txIndex, address, start, maxSize, cb) {
this.requestManager.send({
method: 'debug_storageRangeAt',
params: [txBlockHash, txIndex, address, start, maxSize]
})
.then(result => cb(null, result))
.catch(error => cb(error))
}
}

@ -10,6 +10,7 @@ import { methods as netMethods } from './methods/net'
import { Transactions } from './methods/transactions'
import { Debug } from './methods/debug'
import { VMContext } from './vm-context'
import { Web3PluginBase } from 'web3'
export interface JSONRPCRequestPayload {
params: any[];
@ -117,43 +118,30 @@ export class Provider {
}
export function extend (web3) {
if (!web3.extend) {
return
}
// DEBUG
const methods = []
if (!(web3.eth && web3.eth.getExecutionResultFromSimulator)) {
methods.push(new web3.extend.Method({
name: 'getExecutionResultFromSimulator',
call: 'eth_getExecutionResultFromSimulator',
inputFormatter: [null],
params: 1
}))
}
web3.registerPlugin(new Web3TestPlugin())
}
if (!(web3.eth && web3.eth.getHHLogsForTx)) {
methods.push(new web3.extend.Method({
name: 'getHHLogsForTx',
call: 'eth_getHHLogsForTx',
inputFormatter: [null],
params: 1
}))
class Web3TestPlugin extends Web3PluginBase {
public pluginNamespace = 'testPlugin'
public getExecutionResultFromSimulator(transactionHash) {
return this.requestManager.send({
method: 'eth_getExecutionResultFromSimulator',
params: [transactionHash]
})
}
if (!(web3.eth && web3.eth.getHashFromTagBySimulator)) {
methods.push(new web3.extend.Method({
name: 'getHashFromTagBySimulator',
call: 'eth_getHashFromTagBySimulator',
inputFormatter: [null],
params: 1
}))
public getHHLogsForTx(transactionHash) {
return this.requestManager.send({
method: 'eth_getHHLogsForTx',
params: [transactionHash]
})
}
if (methods.length > 0) {
web3.extend({
property: 'eth',
methods: methods,
properties: []
public getHashFromTagBySimulator(timestamp) {
return this.requestManager.send({
method: 'eth_getHashFromTagBySimulator',
params: [timestamp]
})
}
}

@ -1,6 +1,6 @@
import async from 'async'
import { execution } from '@remix-project/remix-lib'
import Web3 from 'web3'
import Web3, { FMT_BYTES, FMT_NUMBER } from 'web3'
import { compilationInterface } from './types'
/**
@ -58,7 +58,7 @@ export function deployAll (compileResult: compilationInterface, web3: Web3, test
},
function deployContracts (contractsToDeploy: string[], next) {
const deployRunner = (deployObject, contractObject, contractName, filename, callback) => {
deployObject.estimateGas().then((gasValue) => {
deployObject.estimateGas(undefined, { number: FMT_NUMBER.NUMBER, bytes: FMT_BYTES.HEX }).then((gasValue) => {
const gasBase = Math.ceil(gasValue * 1.2)
const gas = withDoubleGas ? gasBase * 2 : gasBase
deployObject.send({

@ -253,8 +253,8 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
method.call(sendParams).then(async (result) => {
const time = (Date.now() - startTime) / 1000.0
let tagTxHash
if (web3.eth && web3.eth.getHashFromTagBySimulator) tagTxHash = await web3.eth.getHashFromTagBySimulator(tagTimestamp)
if (web3.eth && web3.eth.getHHLogsForTx) hhLogs = await web3.eth.getHHLogsForTx(tagTxHash)
if (web3.testPlugin && web3.testPlugin.getHashFromTagBySimulator) tagTxHash = await web3.testPlugin.getHashFromTagBySimulator(tagTimestamp)
if (web3.testPlugin && web3.testPlugin.getHHLogsForTx) hhLogs = await web3.testPlugin.getHHLogsForTx(tagTxHash)
debugTxHash = tagTxHash
if (result) {
const resp: TestResultInterface = {
@ -301,7 +301,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
method.send(sendParams).on('receipt', async (receipt) => {
try {
debugTxHash = receipt.transactionHash
if (web3.eth && web3.eth.getHHLogsForTx) hhLogs = await web3.eth.getHHLogsForTx(receipt.transactionHash)
if (web3.testPlugin && web3.testPlugin.getHHLogsForTx) hhLogs = await web3.testPlugin.getHHLogsForTx(receipt.transactionHash)
const time: number = (Date.now() - startTime) / 1000.0
const assertionEventHashes = assertionEvents.map(e => Web3.utils.sha3(e.name + '(' + e.params.join() + ')'))
let testPassed = false
@ -394,7 +394,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
else if (err.message.includes('Transaction has been reverted by the EVM')) {
txHash = JSON.parse(err.message.replace('Transaction has been reverted by the EVM:', '')).transactionHash
}
if (web3.eth && web3.eth.getHHLogsForTx && txHash) hhLogs = await web3.eth.getHHLogsForTx(txHash)
if (web3.testPlugin && web3.testPlugin.getHHLogsForTx && txHash) hhLogs = await web3.testPlugin.getHHLogsForTx(txHash)
if (hhLogs && hhLogs.length) resp.hhLogs = hhLogs
resp.debugTxHash = txHash
testCallback(undefined, resp)

@ -53,11 +53,13 @@ async function compileAndDeploy(filename: string, callback: any) {
let compilationData: any
async.waterfall([
function getAccountList(next: any): void {
web3.eth.getAccounts((_err: Error | null | undefined, _accounts: string[]) => {
accounts = _accounts
web3.eth.defaultAccount = accounts[0]
next(_err)
})
web3.eth.getAccounts()
.then(( _accounts: string[]) => {
accounts = _accounts
web3.eth.defaultAccount = accounts[0]
next(undefined)
})
.catch((_err: Error | null | undefined) => next(_err))
},
function compile(next: any): void {
compileFileOrFiles(filename, false, { accounts }, null, next)

Loading…
Cancel
Save