@@ -548,6 +548,11 @@ describe('Formatters', () => {
548548 const value = '0x7FFFFFFFFFFFFFFF' ;
549549 expect ( weibarHexToTinyBarInt ( value ) ) . to . eq ( 922337203 ) ;
550550 } ) ;
551+
552+ it ( 'should round up fractional weibar values to 1 tinybar' , ( ) => {
553+ const value = '0x1' ;
554+ expect ( weibarHexToTinyBarInt ( value ) ) . to . eq ( 1 ) ;
555+ } ) ;
551556 } ) ;
552557
553558 describe ( 'valid ethereum address' , ( ) => {
@@ -742,6 +747,16 @@ describe('Formatters', () => {
742747 const malformedHex = '0x08c379a0000000000000000000000000000000000000000000000000000000000000002' ;
743748 expect ( decodeErrorMessage ( malformedHex ) ) . to . equal ( '' ) ;
744749 } ) ;
750+
751+ it ( 'should handle non-hex message by returning as-is' , ( ) => {
752+ const nonHexMessage = 'Simple error message without hex' ;
753+ expect ( decodeErrorMessage ( nonHexMessage ) ) . to . equal ( nonHexMessage ) ;
754+ } ) ;
755+
756+ it ( 'should handle message that starts with 0x but is malformed' , ( ) => {
757+ const malformedMessage = '0xinvalid' ;
758+ expect ( decodeErrorMessage ( malformedMessage ) ) . to . equal ( '' ) ;
759+ } ) ;
745760 } ) ;
746761 } ) ;
747762
@@ -895,7 +910,7 @@ describe('Formatters', () => {
895910 } ) ;
896911 } ) ;
897912
898- describe ( 'Additional Edge Cases' , ( ) => {
913+ describe ( 'Additional Edge Cases - Targeted Coverage ' , ( ) => {
899914 it ( 'should handle getFunctionSelector with short input' , ( ) => {
900915 expect ( getFunctionSelector ( '0x123' ) ) . to . eq ( '123' ) ;
901916 expect ( getFunctionSelector ( 'abc' ) ) . to . eq ( 'abc' ) ;
@@ -920,22 +935,62 @@ describe('Formatters', () => {
920935 expect ( toNullableBigNumber ( 123 as any ) ) . to . equal ( null ) ;
921936 } ) ;
922937
923- it ( 'should handle formatTransactionId regex validation' , ( ) => {
938+ it ( 'should handle formatTransactionId regex validation - precise failing cases' , ( ) => {
939+ // These should specifically fail the TRANSACTION_ID_REGEX: /\d{1}\.\d{1}\.\d{1,10}\@\d{1,10}\.\d{1,9}/
924940 expect ( formatTransactionId ( 'invalid-format' ) ) . to . eq ( null ) ;
925941 expect ( formatTransactionId ( '0.0.2@' ) ) . to . eq ( null ) ;
926942 expect ( formatTransactionId ( '@1234567890.123456789' ) ) . to . eq ( null ) ;
943+ expect ( formatTransactionId ( '' ) ) . to . eq ( null ) ;
944+ expect ( formatTransactionId ( '0.0.2-1234567890.123456789' ) ) . to . eq ( null ) ; // missing @
927945 } ) ;
928946
929- it ( 'should handle formatTransactionIdWithoutQueryParams with empty result' , ( ) => {
947+ it ( 'should handle formatTransactionIdWithoutQueryParams with null formatTransactionId result' , ( ) => {
948+ // These should cause formatTransactionId to return null, which should make formatTransactionIdWithoutQueryParams return null
930949 expect ( formatTransactionIdWithoutQueryParams ( 'invalid?nonce=1' ) ) . to . eq ( null ) ;
931950 expect ( formatTransactionIdWithoutQueryParams ( '?nonce=1' ) ) . to . eq ( null ) ;
951+ expect ( formatTransactionIdWithoutQueryParams ( '' ) ) . to . eq ( null ) ;
932952 } ) ;
933953
934- it ( 'should handle parseNumericEnvVar error throwing scenarios ' , ( ) => {
954+ it ( 'should handle parseNumericEnvVar with completely invalid constant ' , ( ) => {
935955 expect ( ( ) => parseNumericEnvVar ( 'NONEXISTENT_VAR' , 'NONEXISTENT_CONSTANT' ) ) . to . throw (
936956 Error ,
937957 "Unable to parse numeric env var: 'NONEXISTENT_VAR', constant: 'NONEXISTENT_CONSTANT'" ,
938958 ) ;
939959 } ) ;
960+
961+ it ( 'should handle tinybarsToWeibars negative value error when allowNegativeValues is false' , ( ) => {
962+ expect ( ( ) => tinybarsToWeibars ( - 1 , false ) ) . to . throw ( Error , 'Invalid value - cannot pass negative number' ) ;
963+ } ) ;
964+
965+ it ( 'should handle tinybarsToWeibars excessive value error' , ( ) => {
966+ const excessiveValue = constants . TOTAL_SUPPLY_TINYBARS + 1 ;
967+ expect ( ( ) => tinybarsToWeibars ( excessiveValue , false ) ) . to . throw (
968+ Error ,
969+ 'Value cannot be more than the total supply of tinybars in the blockchain' ,
970+ ) ;
971+ } ) ;
972+
973+ it ( 'should test hashNumber function indirectly through numberTo0x' , ( ) => {
974+ // The hashNumber function is used internally by numberTo0x
975+ expect ( numberTo0x ( 255 ) ) . to . equal ( '0xff' ) ;
976+ expect ( numberTo0x ( 0 ) ) . to . equal ( '0x0' ) ;
977+ expect ( numberTo0x ( 16 ) ) . to . equal ( '0x10' ) ;
978+ } ) ;
979+
980+ it ( 'should test formatRequestIdMessage with pre-formatted request ID' , ( ) => {
981+ const preFormattedId = '[Request ID: test-id]' ;
982+ expect ( formatRequestIdMessage ( preFormattedId ) ) . to . eq ( preFormattedId ) ;
983+ } ) ;
984+
985+ it ( 'should test formatRequestIdMessage with unformatted request ID' , ( ) => {
986+ const unformattedId = 'simple-id' ;
987+ expect ( formatRequestIdMessage ( unformattedId ) ) . to . eq ( '[Request ID: simple-id]' ) ;
988+ } ) ;
989+
990+ it ( 'should test various falsy inputs for formatRequestIdMessage' , ( ) => {
991+ expect ( formatRequestIdMessage ( undefined ) ) . to . eq ( '' ) ;
992+ expect ( formatRequestIdMessage ( '' ) ) . to . eq ( '' ) ;
993+ expect ( formatRequestIdMessage ( null as any ) ) . to . eq ( '' ) ;
994+ } ) ;
940995 } ) ;
941996} ) ;
0 commit comments