@@ -992,5 +992,153 @@ describe('Formatters', () => {
992992 expect ( formatRequestIdMessage ( '' ) ) . to . eq ( '' ) ;
993993 expect ( formatRequestIdMessage ( null as any ) ) . to . eq ( '' ) ;
994994 } ) ;
995+
996+ it ( 'should test hashNumber function indirectly through various number inputs' , ( ) => {
997+ // Test hashNumber with different types of numbers to ensure full coverage
998+ expect ( numberTo0x ( BigInt ( '18446744073709551615' ) ) ) . to . equal ( '0xffffffffffffffff' ) ; // Max 64-bit
999+ expect ( numberTo0x ( 1 ) ) . to . equal ( '0x1' ) ;
1000+ expect ( numberTo0x ( 256 ) ) . to . equal ( '0x100' ) ;
1001+ } ) ;
1002+
1003+ it ( 'should test weibarHexToTinyBarInt with empty hex value' , ( ) => {
1004+ // This should hit the specific condition: if (value === '0x') return 0;
1005+ expect ( weibarHexToTinyBarInt ( '0x' ) ) . to . eq ( 0 ) ;
1006+ } ) ;
1007+
1008+ it ( 'should test weibarHexToTinyBarInt with fractional weibar that rounds to 1' , ( ) => {
1009+ // Test the condition: if (tinybarValue === BigInt(0) && weiBigInt > BigInt(0)) return 1;
1010+ expect ( weibarHexToTinyBarInt ( '0x5' ) ) . to . eq ( 1 ) ; // 5 weibar should round to 1 tinybar
1011+ expect ( weibarHexToTinyBarInt ( '0x9' ) ) . to . eq ( 1 ) ; // 9 weibar should round to 1 tinybar
1012+ } ) ;
1013+
1014+ it ( 'should test mapKeysAndValues with no mapping functions' , ( ) => {
1015+ // Test when mapFn.key and mapFn.value are undefined
1016+ const target = { a : '1' , b : '2' } ;
1017+ const result = mapKeysAndValues ( target , { } as any ) ;
1018+ expect ( result ) . to . deep . equal ( { a : '1' , b : '2' } ) ;
1019+ } ) ;
1020+
1021+ it ( 'should test mapKeysAndValues with only key mapping' , ( ) => {
1022+ // Test when mapFn.value is undefined
1023+ const target = { a : '1' , b : '2' } ;
1024+ const result = mapKeysAndValues ( target , { key : ( k ) => k . toUpperCase ( ) } as any ) ;
1025+ expect ( result ) . to . deep . equal ( { A : '1' , B : '2' } ) ;
1026+ } ) ;
1027+
1028+ it ( 'should test mapKeysAndValues with only value mapping' , ( ) => {
1029+ // Test when mapFn.key is undefined
1030+ const target = { a : '1' , b : '2' } ;
1031+ const result = mapKeysAndValues ( target , { value : ( v ) => parseInt ( v ) } as any ) ;
1032+ expect ( result ) . to . deep . equal ( { a : 1 , b : 2 } ) ;
1033+ } ) ;
1034+
1035+ it ( 'should test nullableNumberTo0x with null input' , ( ) => {
1036+ // Test the specific condition: return input == null ? null : numberTo0x(input);
1037+ expect ( nullableNumberTo0x ( null ) ) . to . equal ( null ) ;
1038+ expect ( nullableNumberTo0x ( undefined as any ) ) . to . equal ( null ) ;
1039+ } ) ;
1040+
1041+ it ( 'should test toNullableBigNumber with string input' , ( ) => {
1042+ // Test the specific condition: if (typeof value === 'string') { return new BN(value).toString(); }
1043+ expect ( toNullableBigNumber ( '0x1a' ) ) . to . equal ( '26' ) ;
1044+ expect ( toNullableBigNumber ( '100' ) ) . to . equal ( '100' ) ;
1045+ } ) ;
1046+
1047+ it ( 'should test toNullableBigNumber with non-string input' , ( ) => {
1048+ // Test the fallback condition: return null;
1049+ expect ( toNullableBigNumber ( 123 as any ) ) . to . equal ( null ) ;
1050+ expect ( toNullableBigNumber ( true as any ) ) . to . equal ( null ) ;
1051+ expect ( toNullableBigNumber ( [ ] as any ) ) . to . equal ( null ) ;
1052+ } ) ;
1053+
1054+ it ( 'should test toNullIfEmptyHex with empty hex' , ( ) => {
1055+ // Test the specific condition: return value === EMPTY_HEX ? null : value;
1056+ expect ( toNullIfEmptyHex ( '0x' ) ) . to . equal ( null ) ;
1057+ } ) ;
1058+
1059+ it ( 'should test toNullIfEmptyHex with non-empty value' , ( ) => {
1060+ // Test the else condition
1061+ expect ( toNullIfEmptyHex ( '0x123' ) ) . to . equal ( '0x123' ) ;
1062+ expect ( toNullIfEmptyHex ( 'test' ) ) . to . equal ( 'test' ) ;
1063+ } ) ;
1064+
1065+ it ( 'should test toHexString with various byte arrays' , ( ) => {
1066+ // Test the Buffer.from conversion
1067+ expect ( toHexString ( new Uint8Array ( [ 0x01 , 0x02 , 0x03 ] ) ) ) . to . eq ( '010203' ) ;
1068+ expect ( toHexString ( new Uint8Array ( [ 0x00 ] ) ) ) . to . eq ( '00' ) ;
1069+ expect ( toHexString ( new Uint8Array ( [ 0xaa , 0xbb , 0xcc ] ) ) ) . to . eq ( 'aabbcc' ) ;
1070+ } ) ;
1071+
1072+ it ( 'should test isValidEthereumAddress with various edge cases' , ( ) => {
1073+ // Test specific return false conditions
1074+ expect ( isValidEthereumAddress ( '' ) ) . to . equal ( false ) ;
1075+ expect ( isValidEthereumAddress ( '0x' ) ) . to . equal ( false ) ;
1076+ expect ( isValidEthereumAddress ( '0x123' ) ) . to . equal ( false ) ; // too short
1077+ expect ( isValidEthereumAddress ( '0x123456789012345678901234567890123456789g' ) ) . to . equal ( false ) ; // invalid char
1078+ } ) ;
1079+
1080+ it ( 'should test getFunctionSelector with various inputs' , ( ) => {
1081+ // Test the remove0x and remove0 functions
1082+ expect ( getFunctionSelector ( '0x1234567890' ) ) . to . eq ( '12345678' ) ;
1083+ expect ( getFunctionSelector ( '1234567890' ) ) . to . eq ( '12345678' ) ;
1084+ expect ( getFunctionSelector ( '0x12345678' ) ) . to . eq ( '12345678' ) ;
1085+ expect ( getFunctionSelector ( '12345678' ) ) . to . eq ( '12345678' ) ;
1086+ expect ( getFunctionSelector ( '0x123' ) ) . to . eq ( '123' ) ;
1087+ expect ( getFunctionSelector ( '123' ) ) . to . eq ( '123' ) ;
1088+ } ) ;
1089+
1090+ it ( 'should test tinybarsToWeibars with negative values and allowNegativeValues true' , ( ) => {
1091+ // Test the condition: if (allowNegativeValues) return value;
1092+ expect ( tinybarsToWeibars ( - 5 , true ) ) . to . equal ( - 5 ) ;
1093+ expect ( tinybarsToWeibars ( - 100 , true ) ) . to . equal ( - 100 ) ;
1094+ } ) ;
1095+
1096+ it ( 'should test tinybarsToWeibars with excessive values' , ( ) => {
1097+ // Test the condition: if (value && value > constants.TOTAL_SUPPLY_TINYBARS)
1098+ const excessiveValue = constants . TOTAL_SUPPLY_TINYBARS + 1000000000 ;
1099+ expect ( ( ) => tinybarsToWeibars ( excessiveValue , false ) ) . to . throw (
1100+ Error ,
1101+ 'Value cannot be more than the total supply of tinybars in the blockchain' ,
1102+ ) ;
1103+ expect ( ( ) => tinybarsToWeibars ( excessiveValue , true ) ) . to . throw (
1104+ Error ,
1105+ 'Value cannot be more than the total supply of tinybars in the blockchain' ,
1106+ ) ;
1107+ } ) ;
1108+
1109+ it ( 'should test tinybarsToWeibars with null and undefined' , ( ) => {
1110+ // Test the condition: return value == null ? null : value * constants.TINYBAR_TO_WEIBAR_COEF;
1111+ expect ( tinybarsToWeibars ( null , false ) ) . to . equal ( null ) ;
1112+ expect ( tinybarsToWeibars ( undefined as any , false ) ) . to . equal ( null ) ;
1113+ } ) ;
1114+
1115+ it ( 'should test parseNumericEnvVar with specific constant fallback' , ( ) => {
1116+ // Test the specific condition where constants[fallbackConstantKey] is accessed
1117+ expect ( ( ) => parseNumericEnvVar ( 'NONEXISTENT_VAR' , 'TOTALLY_INVALID_CONSTANT' ) ) . to . throw (
1118+ Error ,
1119+ "Unable to parse numeric env var: 'NONEXISTENT_VAR', constant: 'TOTALLY_INVALID_CONSTANT'" ,
1120+ ) ;
1121+ } ) ;
1122+
1123+ it ( 'should test formatTransactionId with edge cases' , ( ) => {
1124+ // Test the specific TRANSACTION_ID_REGEX condition
1125+ expect ( formatTransactionId ( '0.0.2@' ) ) . to . eq ( null ) ;
1126+ expect ( formatTransactionId ( '0.0.2' ) ) . to . eq ( null ) ;
1127+ expect ( formatTransactionId ( '@1234567890.123456789' ) ) . to . eq ( null ) ;
1128+ expect ( formatTransactionId ( 'invalid' ) ) . to . eq ( null ) ;
1129+ } ) ;
1130+
1131+ it ( 'should test formatTransactionIdWithoutQueryParams with null formatTransactionId' , ( ) => {
1132+ // Test the condition: if (!formattedTransactionIdWithQueryParams) { return null; }
1133+ expect ( formatTransactionIdWithoutQueryParams ( 'invalid?nonce=1' ) ) . to . eq ( null ) ;
1134+ expect ( formatTransactionIdWithoutQueryParams ( '@invalid?nonce=1' ) ) . to . eq ( null ) ;
1135+ } ) ;
1136+
1137+ it ( 'should test decodeErrorMessage with various edge cases' , ( ) => {
1138+ // Test non-hex messages
1139+ expect ( decodeErrorMessage ( 'not hex' ) ) . to . equal ( 'not hex' ) ;
1140+ expect ( decodeErrorMessage ( '0xmalformed' ) ) . to . equal ( '' ) ;
1141+ expect ( decodeErrorMessage ( '0x123' ) ) . to . equal ( '' ) ;
1142+ } ) ;
9951143 } ) ;
9961144} ) ;
0 commit comments