Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
3fee053
feat: add CairoTypeOption class
PhilippeR26 Sep 3, 2025
ef228c0
fix: correct decompose of arrays and tuple
PhilippeR26 Sep 4, 2025
61cd1cd
fix: solve problems of recursive encoding
PhilippeR26 Sep 5, 2025
ec63010
fix: recursive encoding of CairoType
PhilippeR26 Sep 9, 2025
7a4146f
test: add CairoTypeOption tests and correct several problems in other…
PhilippeR26 Sep 10, 2025
2b5656f
feat: created CairoTypeResult
PhilippeR26 Sep 15, 2025
551783e
feat: cairoStruct
PhilippeR26 Sep 17, 2025
4b562f5
test: tests for CairoFix. strategy is splitted in 2 objects (standard…
PhilippeR26 Sep 23, 2025
3e9a1f2
test: tests for CairoStruct. strategy is splitted in 2 objects (stand…
PhilippeR26 Sep 23, 2025
7746e78
Merge branch 'new-CairoOption' of https://github.com/PhilippeR26/star…
PhilippeR26 Sep 23, 2025
8e0d256
feat: add CairoTypeCustomEnum
PhilippeR26 Sep 26, 2025
24386d4
test: add tests including customEnum. solve struct non ordered items …
PhilippeR26 Oct 1, 2025
b25fabe
feat: add ethAddress, bool, classHash, contractAddress. toApiRequest …
PhilippeR26 Oct 3, 2025
f467a89
build: nonZero, contractAddress, classHash
PhilippeR26 Oct 8, 2025
0bc90ee
Merge branch 'cairotypes/all' into new-CairoOption
PhilippeR26 Oct 8, 2025
bc82c99
chore: correct problems in u96, array. Remove request and responsePar…
PhilippeR26 Oct 13, 2025
b2ce744
chore: remove validateFields
PhilippeR26 Oct 13, 2025
3f40f3e
fix: byteArray toDecimalString
PhilippeR26 Oct 15, 2025
b232a3b
fix: problems of cairo0 decoding
PhilippeR26 Oct 29, 2025
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
13,873 changes: 13,873 additions & 0 deletions __mocks__/cairo/cairo2120/enums_test_enums.casm

Large diffs are not rendered by default.

6,810 changes: 6,810 additions & 0 deletions __mocks__/cairo/cairo2120/enums_test_enums.sierra.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions __tests__/cairo1v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,21 +696,21 @@ describe('Cairo 1', () => {
{ address: 1193046n, is_claimed: true },
{ address: 624485n, is_claimed: false },
]);
const res4 = c1v2CallData.decodeParameters('core::integer::u8', ['0x123456']);
expect(res4).toBe(1193046n);
const res4 = c1v2CallData.decodeParameters('core::integer::u8', ['0x12']);
expect(res4).toBe(18n);
const res5 = c1v2CallData.decodeParameters('core::bool', ['0x1']);
expect(res5).toBe(true);
const res6 = c1v2CallData.decodeParameters('core::felt252', ['0x123456']);
expect(res6).toBe(1193046n);
const res7 = c1v2CallData.decodeParameters('core::integer::u256', ['0x123456', '0x789']);
expect(num.toHex(res7.toString())).toBe('0x78900000000000000000000000000123456');
const res8 = c1v2CallData.decodeParameters('core::array::Array::<core::integer::u16>', [
const res8 = c1v2CallData.decodeParameters('core::array::Array::<core::integer::u32>', [
'2',
'0x123456',
'0x789',
]);
expect(res8).toEqual([1193046n, 1929n]);
const res9 = c1v2CallData.decodeParameters('core::array::Span::<core::integer::u16>', [
const res9 = c1v2CallData.decodeParameters('core::array::Span::<core::integer::u32>', [
'2',
'0x123456',
'0x789',
Expand Down
14 changes: 7 additions & 7 deletions __tests__/cairo1v2_typed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -964,13 +964,13 @@ describe('Cairo 1', () => {
expect(callD2).toEqual([hexToDecimalString(encodeShortString(str))]);
const myCallData = new CallData(contracts.C240.sierra.abi);
const myCalldata1 = myCallData.compile('proceed_bytes31', [str]);
expect(myCalldata1).toEqual([encodeShortString(str)]);
expect(myCalldata1).toEqual([hexToDecimalString(encodeShortString(str))]);
const myCalldata2 = myCallData.compile('proceed_bytes31', { str });
expect(myCalldata2).toEqual([encodeShortString(str)]);
expect(myCalldata2).toEqual([hexToDecimalString(encodeShortString(str))]);
const myCall1 = stringContract.populate('proceed_bytes31', [str]);
expect(myCall1.calldata).toEqual([encodeShortString(str)]);
expect(myCall1.calldata).toEqual([hexToDecimalString(encodeShortString(str))]);
const myCall2 = stringContract.populate('proceed_bytes31', { str });
expect(myCall2.calldata).toEqual([encodeShortString(str)]);
expect(myCall2.calldata).toEqual([hexToDecimalString(encodeShortString(str))]);
});

test('bytes31 too long', async () => {
Expand All @@ -980,7 +980,7 @@ describe('Cairo 1', () => {

test('ByteArray', async () => {
const message = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ12345AAADEFGHIJKLMNOPQRSTUVWXYZ12345A';
const callD = CallData.compile([message]);
const callD = CallData.compile([new CairoByteArray(message).toObject()]);
const expectedResult = [
'2',
hexToDecimalString('0x4142434445464748494a4b4c4d4e4f505152535455565758595a3132333435'),
Expand All @@ -989,9 +989,9 @@ describe('Cairo 1', () => {
'1',
];
expect(callD).toEqual(expectedResult);
const callD2 = CallData.compile({ mess: message });
const callD2 = CallData.compile({ mess: new CairoByteArray(message).toObject() });
expect(callD2).toEqual(expectedResult);
const callD3 = CallData.compile({ mess: new CairoByteArray('Take care.') });
const callD3 = CallData.compile({ mess: new CairoByteArray('Take care.').toObject() });
expect(callD3).toEqual(['0', '398475857363345939260718', '10']);
const str1 = await stringContract.get_string();
expect(str1).toBe(
Expand Down
16 changes: 8 additions & 8 deletions __tests__/cairov24onward.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ describe('Cairo v2.4 onwards', () => {

const myCallData = new CallData(contracts.C240.sierra.abi);
const myCalldata1 = myCallData.compile('proceed_bytes31', [str]);
expect(myCalldata1).toEqual([encodeShortString(str)]);
expect(myCalldata1).toEqual([hexToDecimalString(encodeShortString(str))]);

const myCalldata2 = myCallData.compile('proceed_bytes31', { str });
expect(myCalldata2).toEqual([encodeShortString(str)]);
expect(myCalldata2).toEqual([hexToDecimalString(encodeShortString(str))]);
const myCall1 = stringContract.populate('proceed_bytes31', [str]);
expect(myCall1.calldata).toEqual([encodeShortString(str)]);
expect(myCall1.calldata).toEqual([hexToDecimalString(encodeShortString(str))]);
const myCall2 = stringContract.populate('proceed_bytes31', { str });
expect(myCall2.calldata).toEqual([encodeShortString(str)]);
expect(myCall2.calldata).toEqual([hexToDecimalString(encodeShortString(str))]);
});

test('bytes31 too long', async () => {
Expand All @@ -76,7 +76,7 @@ describe('Cairo v2.4 onwards', () => {

test('ByteArray', async () => {
const message = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ12345AAADEFGHIJKLMNOPQRSTUVWXYZ12345A';
const callD = CallData.compile([message]);
const callD = CallData.compile([cairo.byteArray(message)]);
const expectedResult = [
'2',
hexToDecimalString('0x4142434445464748494a4b4c4d4e4f505152535455565758595a3132333435'),
Expand All @@ -85,9 +85,9 @@ describe('Cairo v2.4 onwards', () => {
'1',
];
expect(callD).toEqual(expectedResult);
const callD2 = CallData.compile({ mess: message });
const callD2 = CallData.compile({ mess: cairo.byteArray(message) });
expect(callD2).toEqual(expectedResult);
const callD3 = CallData.compile({ mess: new CairoByteArray('Take care.') });
const callD3 = CallData.compile({ mess: new CairoByteArray('Take care.').toObject() });
expect(callD3).toEqual(['0', '398475857363345939260718', '10']);
const str1 = await stringContract.get_string();
expect(str1).toBe(
Expand Down Expand Up @@ -439,7 +439,7 @@ describe('Cairo v2.4 onwards', () => {
describe('Cairo v2.9.2 fixed-array', () => {
const myArray: number[] = [1, 2, 3, 4, 5, 6, 7, 8];
const myWrongArray = [...myArray, 9];
const expectedCalldata = myArray.map((val) => `0x${val.toString(16)}`);
const expectedCalldata = myArray.map((val) => val.toString(10));
let fixedArrayContract: Contract;

beforeAll(async () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/config/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const compiledContracts = {
deployer: 'cairo2100/deployer',
CairoByteArray: 'byteArray/target/dev/test_ByteArrayStorage',
IntegerTypes: 'integerTypes/target/dev/test_IntegerTypesStorage',
TestCairoType: 'cairo2120/enums_test_enums',
};
export const contracts = mapContractSets(compiledContracts);

Expand Down
18 changes: 6 additions & 12 deletions __tests__/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ describe('Complex interaction', () => {
classHash,
account,
constructorCalldata: CallData.compile({
name: new CairoByteArray('Token'),
symbol: new CairoByteArray('ERC20'),
name: new CairoByteArray('Token').toObject(),
symbol: new CairoByteArray('ERC20').toObject(),
amount: cairo.uint256('1000000000'),
recipient: account.address,
owner: '0x823d5a0c0eefdc9a6a1cb0e064079a6284f3b26566b677a32c71bbe7bf9f8c',
Expand Down Expand Up @@ -930,21 +930,15 @@ describe('Complex interaction', () => {
const res0 = myCallData.decodeParameters('core::felt252', ['474107654995566025798705']);
expect(res0).toBe(474107654995566025798705n);
const res1 = myCallData.decodeParameters('echo::StructY', [
'474107654995566025798705',
'1844674407370955',
'3534634645645',
]);
expect(res1).toEqual({ y1: 474107654995566025798705n, y2: 3534634645645n });
expect(res1).toEqual({ y1: 1844674407370955n, y2: 3534634645645n });

const res2 = myCallData.decodeParameters('core::integer::u256', ['47410765', '35346645']);
expect(res2).toBe(12027840023314154934885372750905072692667575885n);
const res3 = myCallData.decodeParameters('echo::Struct32', [
'47410765',
'35346645',
'1',
'2',
'3',
]);
expect(res3).toEqual({ b: 47410765n, c: { '0': 35346645n, '1': 1n, '2': 2n, '3': 3n } });
const res3 = myCallData.decodeParameters('echo::Struct32', ['47410765', '45', '1', '2', '3']);
expect(res3).toEqual({ b: 47410765n, c: { '0': 45n, '1': 1n, '2': 2n, '3': 3n } });

const res4 = myCallData.decodeParameters(
'(core::felt252, core::felt252, core::felt252, core::felt252)',
Expand Down
34 changes: 13 additions & 21 deletions __tests__/utils/cairoDataTypes/CairoArray.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,41 +63,32 @@ describe('CairoArray Integration Tests', () => {

test('should work with AbiParser2 request parsing', () => {
const parser = new AbiParser2(mockAbi, hdParsingStrategy);
const requestParser = parser.getRequestParser('core::array::Array::<core::integer::u8>');

const result = requestParser([1, 2, 3], 'core::array::Array::<core::integer::u8>');
expect(result).toEqual(['3', '0x1', '0x2', '0x3']);
const result = parser.parseRequestField([1, 2, 3], 'core::array::Array::<core::integer::u8>');
expect(result).toEqual(['3', '1', '2', '3']);
});

test('should work with AbiParser2 response parsing', () => {
const parser = new AbiParser2(mockAbi, hdParsingStrategy);
const responseParser = parser.getResponseParser('core::array::Array::<core::integer::u8>');

const mockResponse = ['0x2', '0xa', '0xb']; // length=2, elements=[10, 11]
const iterator = mockResponse[Symbol.iterator]();
const result = responseParser(iterator, 'core::array::Array::<core::integer::u8>');
const result = parser.parseResponse(iterator, 'core::array::Array::<core::integer::u8>');

expect(result).toEqual([10n, 11n]);
});

test('should handle nested arrays in AbiParser2', () => {
const parser = new AbiParser2(mockAbi, hdParsingStrategy);
const requestParser = parser.getRequestParser(
'core::array::Array::<core::array::Array::<core::integer::u8>>'
);

const result = requestParser(
const result = parser.parseRequestField(
[[1, 2], [3]],
'core::array::Array::<core::array::Array::<core::integer::u8>>'
);
expect(result).toEqual(['2', '2', '0x1', '0x2', '1', '0x3']);
expect(result).toEqual(['2', '2', '1', '2', '1', '3']);
});

test('should handle empty arrays in AbiParser2', () => {
const parser = new AbiParser2(mockAbi, hdParsingStrategy);
const requestParser = parser.getRequestParser('core::array::Array::<core::integer::u8>');

const result = requestParser([], 'core::array::Array::<core::integer::u8>');
const result = parser.parseRequestField([], 'core::array::Array::<core::integer::u8>');
expect(result).toEqual(['0']);
});
});
Expand Down Expand Up @@ -170,13 +161,14 @@ describe('CairoArray Integration Tests', () => {
const originalData = [100, 200, 300];

// Request parsing (serialize)
const requestParser = parser.getRequestParser('core::array::Array::<core::integer::u32>');
const serialized = requestParser(originalData, 'core::array::Array::<core::integer::u32>');
const serialized = parser.parseRequestField(
originalData,
'core::array::Array::<core::integer::u32>'
);

// Response parsing (deserialize)
const responseParser = parser.getResponseParser('core::array::Array::<core::integer::u32>');
const iterator = serialized[Symbol.iterator]();
const result = responseParser(iterator, 'core::array::Array::<core::integer::u32>');
const result = parser.parseResponse(iterator, 'core::array::Array::<core::integer::u32>');

expect(result).toEqual([100n, 200n, 300n]);
});
Expand Down Expand Up @@ -223,7 +215,7 @@ describe('CairoArray Integration Tests', () => {
});

test('should handle mixed input types with parsing strategy', () => {
const mixedData = [1, '2', 3n, 0x4];
const mixedData = [1, '2', 3n, '0x4'];
const array = new CairoArray(
mixedData,
'core::array::Array::<core::felt252>',
Expand Down Expand Up @@ -254,7 +246,7 @@ describe('CairoArray Integration Tests', () => {

// Both should serialize the same way
expect(arraySerialized).toEqual(spanSerialized);
expect(arraySerialized).toEqual(['3', '0x1', '0x2', '0x3']);
expect(arraySerialized).toEqual(['3', '1', '2', '3']);
});
});

Expand Down
Loading