1
1
import async from 'async'
2
2
import * as changeCase from 'change-case'
3
- import { Web3 } from 'web3 '
3
+ import { keccak256 , AbiCoder } from 'ethers '
4
4
import assertionEvents from './assertionEvents'
5
5
import {
6
6
RunListInterface , TestCbInterface , TestResultInterface , ResultCbInterface ,
@@ -218,8 +218,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
218
218
const isJSONInterfaceAvailable = testObject && testObject . options && testObject . options . jsonInterface
219
219
if ( ! isJSONInterfaceAvailable ) { return resultsCallback ( new Error ( 'Contract interface not available' ) , { passingNum, failureNum, timePassed } ) }
220
220
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
223
222
const accts : TestResultInterface = {
224
223
type : 'accountList' ,
225
224
value : opts . accounts
@@ -250,12 +249,12 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
250
249
if ( func . constant ) {
251
250
sendParams = { }
252
251
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 )
254
253
method . call ( sendParams ) . then ( async ( result ) => {
255
254
const time = ( Date . now ( ) - startTime ) / 1000.0
256
255
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 )
259
258
debugTxHash = tagTxHash
260
259
if ( result ) {
261
260
const resp : TestResultInterface = {
@@ -264,7 +263,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
264
263
filename : testObject . filename ,
265
264
time : time ,
266
265
context : testName ,
267
- web3 ,
266
+ provider ,
268
267
debugTxHash
269
268
}
270
269
if ( hhLogs && hhLogs . length ) resp . hhLogs = hhLogs
@@ -279,7 +278,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
279
278
time : time ,
280
279
errMsg : 'function returned false' ,
281
280
context : testName ,
282
- web3 ,
281
+ provider ,
283
282
debugTxHash
284
283
}
285
284
if ( hhLogs && hhLogs . length ) resp . hhLogs = hhLogs
@@ -302,17 +301,17 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
302
301
method . send ( sendParams ) . on ( 'receipt' , async ( receipt ) => {
303
302
try {
304
303
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 )
306
305
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 ( ) + ')' ) )
308
307
let testPassed = false
309
308
for ( const i in receipt . logs ) {
310
309
let events = receipt . logs [ i ]
311
310
if ( ! Array . isArray ( events ) ) events = [ events ]
312
311
for ( const event of events ) {
313
312
const eIndex = assertionEventHashes . indexOf ( event . topics [ 0 ] ) // event name topic will always be at index 0
314
313
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 )
316
315
if ( ! testEvent [ 0 ] ) {
317
316
const assertMethod = testEvent [ 2 ]
318
317
if ( assertMethod === 'ok' ) { // for 'Assert.ok' method
@@ -331,7 +330,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
331
330
returned : testEvent [ 3 ] ,
332
331
expected : testEvent [ 4 ] ,
333
332
location,
334
- web3 ,
333
+ provider ,
335
334
debugTxHash
336
335
}
337
336
if ( hhLogs && hhLogs . length ) resp . hhLogs = hhLogs
@@ -352,7 +351,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
352
351
filename : testObject . filename ,
353
352
time : time ,
354
353
context : testName ,
355
- web3 ,
354
+ provider ,
356
355
debugTxHash
357
356
}
358
357
if ( hhLogs && hhLogs . length ) resp . hhLogs = hhLogs
@@ -391,13 +390,13 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
391
390
time : time ,
392
391
errMsg,
393
392
context : testName ,
394
- web3
393
+ provider
395
394
}
396
395
if ( err . receipt ) txHash = err . receipt . transactionHash
397
396
else if ( err . message . includes ( 'Transaction has been reverted by the EVM' ) ) {
398
397
txHash = JSON . parse ( err . message . replace ( 'Transaction has been reverted by the EVM:' , '' ) ) . transactionHash
399
398
}
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 )
401
400
if ( hhLogs && hhLogs . length ) resp . hhLogs = hhLogs
402
401
resp . debugTxHash = txHash
403
402
testCallback ( undefined , resp )
0 commit comments