File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 7
7
getComponentNameFromEvent ,
8
8
getSelectorFromTag ,
9
9
splitEventTag ,
10
+ asciiToHex ,
10
11
} from "../../utils/index" ;
11
12
12
13
describe ( "utils" , ( ) => {
@@ -126,4 +127,14 @@ describe("utils", () => {
126
127
"/dns4/api.cartridge.gg/tcp/443/x-parity-wss/%2Fx%2Fwordle-game%2Ftorii%2Fwss"
127
128
) ;
128
129
} ) ;
130
+
131
+ it ( "should convert ASCII strings to hex" , ( ) => {
132
+ const f = ( input : string , expected : string ) => {
133
+ expect ( asciiToHex ( input ) ) . toBe ( expected ) ;
134
+ } ;
135
+
136
+ f ( "Hello" , "0x48656c6c6f" ) ;
137
+ f ( "A" , "0x41" ) ;
138
+ f ( "123" , "0x313233" ) ;
139
+ } ) ;
129
140
} ) ;
Original file line number Diff line number Diff line change @@ -190,6 +190,18 @@ export function hexToAscii(hex: string): string {
190
190
return str ;
191
191
}
192
192
193
+ /**
194
+ * Converts an ASCII string to a hexadecimal string.
195
+ * With a 0x prefix, matching the original function's format
196
+ */
197
+ export function asciiToHex ( str : string ) : string {
198
+ let hex = "0x" ;
199
+ for ( let i = 0 ; i < str . length ; i ++ ) {
200
+ hex += str . charCodeAt ( i ) . toString ( 16 ) . padStart ( 2 , "0" ) ;
201
+ }
202
+ return hex ;
203
+ }
204
+
193
205
/**
194
206
* Get the component name from felt event name
195
207
*/
You can’t perform that action at this time.
0 commit comments