Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/cairo1v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ describe('Cairo 1', () => {
const callD2 = CallData.compile({ mess: message });
expect(callD2).toEqual(expectedResult);
const callD3 = CallData.compile({ mess: byteArray.byteArrayFromString('Take care.') });
expect(callD3).toEqual(['1', '0', '398475857363345939260718', '10']);
expect(callD3).toEqual(['0', '398475857363345939260718', '10']);
const str1 = await stringContract.get_string();
expect(str1).toBe(
"Cairo has become the most popular language for developers + charizards !@#$%^&*_+|:'<>?~`"
Expand Down
2 changes: 1 addition & 1 deletion __tests__/cairo1v2_typed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ describe('Cairo 1', () => {
const callD2 = CallData.compile({ mess: message });
expect(callD2).toEqual(expectedResult);
const callD3 = CallData.compile({ mess: byteArray.byteArrayFromString('Take care.') });
expect(callD3).toEqual(['1', '0', '398475857363345939260718', '10']);
expect(callD3).toEqual(['0', '398475857363345939260718', '10']);
const str1 = await stringContract.get_string();
expect(str1).toBe(
"Cairo has become the most popular language for developers + charizards !@#$%^&*_+|:'<>?~`"
Expand Down
8 changes: 4 additions & 4 deletions __tests__/utils/shortString.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ describe('shortString', () => {
pending_word_len: 0,
});
expect(byteArray.byteArrayFromString('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234')).toEqual({
data: ['0x00'],
data: [],
pending_word: '0x4142434445464748494a4b4c4d4e4f505152535455565758595a31323334',
pending_word_len: 30,
});
expect(byteArray.byteArrayFromString('')).toEqual({
data: ['0x00'],
data: [],
pending_word: '0x00',
pending_word_len: 0,
});
Expand All @@ -90,14 +90,14 @@ describe('shortString', () => {
});
expect(
byteArray.stringFromByteArray({
data: ['0x00'],
data: [],
pending_word: '0x4142434445464748494a4b4c4d4e4f505152535455565758595a31323334',
pending_word_len: 30,
})
).toBe('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234');
expect(
byteArray.stringFromByteArray({
data: ['0x00'],
data: [],
pending_word: '0x00',
pending_word_len: 0,
})
Expand Down
8 changes: 4 additions & 4 deletions src/utils/calldata/byteArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { decodeShortString, encodeShortString, splitLongString } from '../shortS
* @example
* ```typescript
* const myByteArray = {
* data: [ '0x00' ],
* data: [],
* pending_word: '0x414243444546474849',
* pending_word_len: 9
* }
Expand Down Expand Up @@ -40,15 +40,15 @@ export function stringFromByteArray(myByteArray: ByteArray): string {
* ```
* Result is :
* {
* data: [ '0x00' ],
* data: [],
* pending_word: '0x414243444546474849',
* pending_word_len: 9
* }
*/
export function byteArrayFromString(myString: string): ByteArray {
if (myString.length === 0) {
return {
data: ['0x00'],
data: [],
pending_word: '0x00',
pending_word_len: 0,
} as ByteArray;
Expand All @@ -67,7 +67,7 @@ export function byteArrayFromString(myString: string): ByteArray {
}
const pendingEncodedWord: BigNumberish = myShortStringsEncoded.pop()!;
return {
data: myShortStringsEncoded.length === 0 ? ['0x00'] : myShortStringsEncoded,
data: myShortStringsEncoded.length === 0 ? [] : myShortStringsEncoded,
pending_word: pendingEncodedWord,
pending_word_len: remains.length,
} as ByteArray;
Expand Down