import BN from 'bn.js' ; export function supportBn ( Assertion , utils ) { Assertion . overwriteMethod ( 'above' , override ( 'gt' , 'above' , utils ) ) ; Assertion . overwriteMethod ( 'gt' , override ( 'gt' , 'greater than' , utils ) ) ; Assertion . overwriteMethod ( 'below' , override ( 'lt' , 'below' , utils ) ) ; Assertion . overwriteMethod ( 'lt' , override ( 'lt' , 'less than' , utils ) ) ; Assertion . overwriteMethod ( 'least' , override ( 'gte' , 'at least' , utils ) ) ; Assertion . overwriteMethod ( 'gte' , override ( 'gte' , 'greater than or equal' , utils ) ) ; Assertion . overwriteMethod ( 'most' , override ( 'lte' , 'at most' , utils ) ) ; Assertion . overwriteMethod ( 'lte' , override ( 'lte' , 'less than or equal' , utils ) ) ; } type Methods = 'eq' | 'gt' | 'lt' | 'gte' | 'lte' ; function override ( method , name , utils ) { return ( _super ) => overwriteBigNumberFunction ( method , name , _super , utils ) ; } function overwriteBigNumberFunction ( functionName , readableName , _super , chaiUtils ) { return function ( this , ... args ) { const [ actual ] = args ; const expected = chaiUtils . flag ( this , 'object' ) ; if ( BN . isBN ( expected ) || BN . isBN ( actual ) ) { this . assert ( new BN ( expected ) [ functionName ] ( actual ) , `Expected "${ expected }" to be ${ readableName } ${ actual }` , `Expected "${ expected }" NOT to be ${ readableName } ${ actual }` , expected , actual ) ; } else { _super . apply ( this , args ) ; } } ; }