import * as chai from 'chai' ; import { BigNumber } from 'bignumber.js' ; import ChaiSetup from './chaiSetup' ; ChaiSetup . configure ( ) ; const { expect } = chai ; export async function expectRevertError ( asyncTxn ) { try { await asyncTxn ; throw new Error ( 'Did not throw' ) ; } catch ( e ) { assertCertainError ( e , 'revert' ) ; } } export async function expectNoRevertError ( asyncTxn ) { try { await asyncTxn ; expect ( true ) . to . be . true ; } catch ( e ) { throw new Error ( 'Error thrown' ) ; } } export async function expectInvalidOpcodeError ( asyncTxn ) { try { await asyncTxn ; throw new Error ( 'Did not throw' ) ; } catch ( e ) { assertCertainError ( e , 'invalid opcode' ) ; } } function assertCertainError ( error , expected_error_msg ) { const message = error . message ; const matchedIndex = message . search ( expected_error_msg ) ; let matchedString = message ; if ( matchedIndex >= 0 ) { matchedString = message . substring ( matchedIndex , matchedIndex + expected_error_msg . length ) ; } expect ( matchedString ) . to . equal ( expected_error_msg ) ; }