11import async from 'async'
22import * as changeCase from 'change-case'
3- import { Web3 } from 'web3 '
3+ import { keccak256 , AbiCoder } from 'ethers '
44import assertionEvents from './assertionEvents'
55import {
66 RunListInterface , TestCbInterface , TestResultInterface , ResultCbInterface ,
@@ -218,8 +218,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
218218 const isJSONInterfaceAvailable = testObject && testObject . options && testObject . options . jsonInterface
219219 if ( ! isJSONInterfaceAvailable ) { return resultsCallback ( new Error ( 'Contract interface not available' ) , { passingNum, failureNum, timePassed } ) }
220220 const runList : RunListInterface [ ] = createRunList ( testObject . options . jsonInterface , fileAST , testName )
221- const web3 = opts . web3 || new Web3 ( )
222- web3 . eth . handleRevert = true // enables returning error reason on revert
221+ const provider = opts . provider
223222 const accts : TestResultInterface = {
224223 type : 'accountList' ,
225224 value : opts . accounts
@@ -250,12 +249,12 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
250249 if ( func . constant ) {
251250 sendParams = { }
252251 const tagTimestamp = 'remix_tests_tag' + Date . now ( )
253- if ( web3 . remix && web3 . remix . registerCallId ) web3 . remix . registerCallId ( tagTimestamp )
252+ if ( provider . remix && provider . remix . registerCallId ) provider . remix . registerCallId ( tagTimestamp )
254253 method . call ( sendParams ) . then ( async ( result ) => {
255254 const time = ( Date . now ( ) - startTime ) / 1000.0
256255 let tagTxHash
257- if ( web3 . remix && web3 . remix . getHashFromTagBySimulator ) tagTxHash = await web3 . remix . getHashFromTagBySimulator ( tagTimestamp )
258- if ( web3 . remix && web3 . remix . getHHLogsForTx ) hhLogs = await web3 . remix . getHHLogsForTx ( tagTxHash )
256+ if ( provider . remix && provider . remix . getHashFromTagBySimulator ) tagTxHash = await provider . remix . getHashFromTagBySimulator ( tagTimestamp )
257+ if ( provider . remix && provider . remix . getHHLogsForTx ) hhLogs = await provider . remix . getHHLogsForTx ( tagTxHash )
259258 debugTxHash = tagTxHash
260259 if ( result ) {
261260 const resp : TestResultInterface = {
@@ -264,7 +263,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
264263 filename : testObject . filename ,
265264 time : time ,
266265 context : testName ,
267- web3 ,
266+ provider ,
268267 debugTxHash
269268 }
270269 if ( hhLogs && hhLogs . length ) resp . hhLogs = hhLogs
@@ -279,7 +278,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
279278 time : time ,
280279 errMsg : 'function returned false' ,
281280 context : testName ,
282- web3 ,
281+ provider ,
283282 debugTxHash
284283 }
285284 if ( hhLogs && hhLogs . length ) resp . hhLogs = hhLogs
@@ -302,17 +301,17 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
302301 method . send ( sendParams ) . on ( 'receipt' , async ( receipt ) => {
303302 try {
304303 debugTxHash = receipt . transactionHash
305- if ( web3 . remix && web3 . remix . getHHLogsForTx ) hhLogs = await web3 . remix . getHHLogsForTx ( receipt . transactionHash )
304+ if ( provider . remix && provider . remix . getHHLogsForTx ) hhLogs = await provider . remix . getHHLogsForTx ( receipt . transactionHash )
306305 const time : number = ( Date . now ( ) - startTime ) / 1000.0
307- const assertionEventHashes = assertionEvents . map ( e => Web3 . utils . sha3 ( e . name + '(' + e . params . join ( ) + ')' ) )
306+ const assertionEventHashes = assertionEvents . map ( e => keccak256 ( e . name + '(' + e . params . join ( ) + ')' ) )
308307 let testPassed = false
309308 for ( const i in receipt . logs ) {
310309 let events = receipt . logs [ i ]
311310 if ( ! Array . isArray ( events ) ) events = [ events ]
312311 for ( const event of events ) {
313312 const eIndex = assertionEventHashes . indexOf ( event . topics [ 0 ] ) // event name topic will always be at index 0
314313 if ( eIndex >= 0 ) {
315- const testEvent = web3 . eth . abi . decodeParameters ( assertionEvents [ eIndex ] . params , event . data )
314+ const testEvent = AbiCoder . defaultAbiCoder ( ) . decode ( assertionEvents [ eIndex ] . params , event . data )
316315 if ( ! testEvent [ 0 ] ) {
317316 const assertMethod = testEvent [ 2 ]
318317 if ( assertMethod === 'ok' ) { // for 'Assert.ok' method
@@ -331,7 +330,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
331330 returned : testEvent [ 3 ] ,
332331 expected : testEvent [ 4 ] ,
333332 location,
334- web3 ,
333+ provider ,
335334 debugTxHash
336335 }
337336 if ( hhLogs && hhLogs . length ) resp . hhLogs = hhLogs
@@ -352,7 +351,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
352351 filename : testObject . filename ,
353352 time : time ,
354353 context : testName ,
355- web3 ,
354+ provider ,
356355 debugTxHash
357356 }
358357 if ( hhLogs && hhLogs . length ) resp . hhLogs = hhLogs
@@ -391,13 +390,13 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
391390 time : time ,
392391 errMsg,
393392 context : testName ,
394- web3
393+ provider
395394 }
396395 if ( err . receipt ) txHash = err . receipt . transactionHash
397396 else if ( err . message . includes ( 'Transaction has been reverted by the EVM' ) ) {
398397 txHash = JSON . parse ( err . message . replace ( 'Transaction has been reverted by the EVM:' , '' ) ) . transactionHash
399398 }
400- if ( web3 . remix && web3 . remix . getHHLogsForTx && txHash ) hhLogs = await web3 . remix . getHHLogsForTx ( txHash )
399+ if ( provider . remix && provider . remix . getHHLogsForTx && txHash ) hhLogs = await provider . remix . getHHLogsForTx ( txHash )
401400 if ( hhLogs && hhLogs . length ) resp . hhLogs = hhLogs
402401 resp . debugTxHash = txHash
403402 testCallback ( undefined , resp )
0 commit comments