import * as assert from 'assert' ; import * as chai from 'chai' ; import * as deepEqualInAnyOrder from 'deep-equal-in-any-order' ; import { EOSManager } from './eosManager' ; import { TableRowsResult } from './contracts' ; import { ConfigManager } from './configManager' ; import * as chalk from 'chalk' ; chai . use ( deepEqualInAnyOrder ) ; note author Kevin Brown <github.com/thekevinbrown>
 *  param number export const untilBlocknumber = async ( number ) => { let { head_block_num } = await EOSManager . rpc . get_info ( ) ; while ( head_block_num < number ) { await sleep ( ( number - head_block_num ) * 500 ) ; ( { head_block_num } = await EOSManager . rpc . get_info ( ) ) ; } } ; author Kevin Brown <github.com/thekevinbrown>
 *  param delayInMs export const sleep = async ( delayInMs ) => new Promise ( ( resolve ) => setTimeout ( resolve , delayInMs ) ) ; note author Kevin Brown <github.com/thekevinbrown>
  export const nextBlock = ( ) => sleep ( 500 ) ; author Dallas Johnson <github.com/dallasjohnson>
 *  param getTableRowsResult param expected export const assertRowsContain = async < RowType > ( getTableRowsResult , expected , strict = false ) => { const result = await getTableRowsResult ; chai . expect ( result . rows ) . contain ( expected ) ; } ; author Kevin Brown <github.com/thekevinbrown>
 *  author Mitch Pierias <github.com/MitchPierias>
 *  param getTableRowsResult param expected param strict export const assertRowsEqual = async < RowType > ( getTableRowsResult , expected , strict = false ) => { if ( strict ) { assertRowsEqualStrict ( getTableRowsResult , expected ) ; return ; } const result = await getTableRowsResult ; chai . expect ( result ) . to . deep . equalInAnyOrder ( { rows : expected , more : false , } ) ; } ; author Mitch Pierias <github.com/MitchPierias>
 *  param getTableRowsResult param expected export const assertRowsEqualStrict = async < RowType > ( getTableRowsResult , expected ) => { const result = await getTableRowsResult ; assert . deepStrictEqual ( result , { rows : expected , more : false , } ) ; } ; author Kevin Brown <github.com/thekevinbrown>
 *  param getTableRowsResult param expectedRowCount export const assertRowCount = async ( getTableRowsResult , expectedRowCount ) => { const result = await getTableRowsResult ; assert . equal ( result . more , false , `There were more rows pending on the response which was not expected.` ) ; assert . equal ( result . rows . length , expectedRowCount , `Different number of rows than expected.` ) ; } ; author Dallas Johnson <github.com/dallasjohnson>
 *  author Kevin Brown <github.com/thekevinbrown>
 *  author Mitch Pierias <github.com/MitchPierias>
 *  param operation param eosErrorName param description param furtherErrorCheck returns const assertExpectedEOSError = async ( operation , eosErrorName , furtherErrorCheck ? ) : Promise < boolean > => { try { await operation ; } catch ( error ) { if ( error . json && error . json . error && error . json . error . name ) { assert ( error . json . error . name === eosErrorName , `Expected ${ eosErrorName }, got ${ error . json . error . name } instead.` ) ; if ( furtherErrorCheck ) { furtherErrorCheck ( error ) ; } } else { assert . fail ( `Expected EOS error ${ eosErrorName }, but got ${ JSON . stringify ( error , null , 4 ) } instead.` ) ; } return true ; } return false ; } ; author Kevin Brown <github.com/thekevinbrown>
 *  param operation param eosErrorName param description export const assertEOSError = async ( operation , eosErrorName , description ) => { if ( assertExpectedEOSError ( operation , eosErrorName ) ) { assert . fail ( `Expected ${ description } but operation completed successfully.` ) ; } } ; author Dallas Johnson <github.com/dallasjohnson>
 *  param operation param message export const assertEOSErrorIncludesMessage = async ( operation , message , errorName ? ) => { const eosErrorName = errorName || 'eosio_assert_message_exception' ; if ( ! ( await assertExpectedEOSError ( operation , eosErrorName , ( error ) => { let errorMessage = error . json . error . details [ 0 ] . message ; if ( ! errorMessage ) { assert . fail ( `Expected EOS error ${ eosErrorName }, but got ${ JSON . stringify ( error , null , 4 ) } instead.` ) ; } assert ( errorMessage . includes ( message ) , `Expected to include ${ message }, got ${ errorMessage } instead.` ) ; } ) ) ) { assert . fail ( `Expected ${ eosErrorName } with message to include ${ message } but operation completed successfully.` ) ; } } ; author Kevin Brown <github.com/thekevinbrown>
 *  param operation export const assertEOSException = async ( operation ) => assertEOSError ( operation , 'eosio_assert_message_exception' , 'assert' ) ; author Kevin Brown <github.com/thekevinbrown>
 *  param operation export const assertMissingAuthority = async ( operation ) => assertEOSErrorIncludesMessage ( operation , '' , 'missing_auth_exception' ) ; export async function debugPromise < T > ( promise , successMessage , errorMessage ? ) { let debugPrefix = 'DebugPromise: ' ; let successString = debugPrefix + successMessage ; let errorString = errorMessage ? debugPrefix + errorMessage + ': ' : debugPrefix + 'error - ' + successMessage + ': ' ; const promiseTimer = timer ( ) ; return promise . then ( ( value ) => { if ( ConfigManager . debugLevelVerbose || ConfigManager . debugLevelMin ) { console . log ( chalk . green ( successString ) + chalk . blue ( ' (%s)' ) , promiseTimer . ms ) ; } if ( ConfigManager . debugLevelVerbose ) { console . log ( `Promise result: ${ JSON . stringify ( value , null , 4 ) }` ) ; } return value ; } ) . catch ( ( err ) => { assert . fail ( errorString + err ) ; } ) ; } /**
 * Simple timer
 */ export function timer ( ) { let timeStart = new Date ( ) . getTime ( ) ; return { /** <integer>s e.g 2s etc. */ get seconds ( ) { const seconds = Math . ceil ( ( new Date ( ) . getTime ( ) - timeStart ) / 1000 ) + 's' ; return seconds ; } , /** Milliseconds e.g. 2000ms etc. */ get ms ( ) { const ms = new Date ( ) . getTime ( ) - timeStart + 'ms' ; return ms ; } , } ; }