import { HardhatNetworkProvider } from 'hardhat/internal/hardhat-network/provider/provider' ; import { HardhatRuntimeEnvironment } from 'hardhat/types' ; import { fromHexString , toHexString } from '.' ; param hre return export const getHardhatBaseProvider = async ( runtime ) : Promise < HardhatNetworkProvider > => { const maxLoopIterations = 1024 ; let currentLoopIterations = 0 ; let provider = runtime . network . provider ; while ( provider . _wrapped !== undefined ) { provider = provider . _wrapped ; currentLoopIterations += 1 ; if ( currentLoopIterations > maxLoopIterations ) { throw new Error ( `[smock]: unable to find base hardhat provider. are you sure you're running locally?` ) ; } } if ( provider . _node === undefined ) { await provider . _init ( ) ; } return provider ; } ; param address returns export const toFancyAddress = ( address ) : Buffer => { const fancyAddress = fromHexString ( address ) ; ( fancyAddress as any ) . buf = fromHexString ( address ) ; ( fancyAddress as any ) . toString = ( encoding ? ) => { if ( encoding === undefined ) { return address . toLowerCase ( ) ; } else { return fromHexString ( address ) . toString ( encoding ) ; } } ; return fancyAddress ; } ; param fancyAddress returns export const fromFancyAddress = ( fancyAddress ) : string => { if ( fancyAddress . buf ) { return toHexString ( fancyAddress . buf ) ; } else { return toHexString ( fancyAddress ) ; } } ;