Skip to content

Commit

Permalink
feat: support cairo1 execute calldata
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkelawala committed Mar 31, 2023
1 parent 78b1f81 commit 1f7f001
Show file tree
Hide file tree
Showing 9 changed files with 6,702 additions and 1,653 deletions.
73 changes: 73 additions & 0 deletions __tests__/utils/transaction.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Call, CallStruct } from '../../src/types';
import {
fromCallsToExecuteCalldata_cairo1,
transformCallsToMulticallArrays_cairo1,
} from '../../src/utils/transaction';

describe('transformCallsToMulticallArrays_cairo1', () => {
it('should return an empty array when given an empty input', () => {
expect(transformCallsToMulticallArrays_cairo1([])).toEqual([]);
});

it('should transform a list of calls into an array of call structs', () => {
const calls: Call[] = [
{
contractAddress: '0x123',
entrypoint: 'transfer',
calldata: [10],
},
{
contractAddress: '0x456',
entrypoint: 'mint',
calldata: ['0x2000', BigInt(10000000)],
},
];
const expected: CallStruct[] = [
{
to: '291',
selector: '232670485425082704932579856502088130646006032362877466777181098476241604910',
calldata: ['10'],
},
{
to: '1110',
selector: '1329909728320632088402217562277154056711815095720684343816173432540100887380',
calldata: ['8192', '10000000'],
},
];
expect(transformCallsToMulticallArrays_cairo1(calls)).toEqual(expected);
});
});

describe('fromCallsToExecuteCalldata_cairo1', () => {
it('should return an array with a length of one when given an empty input', () => {
expect(fromCallsToExecuteCalldata_cairo1([])).toEqual(['0']);
});

it('should transform a list of calls into the full flattened calldata', () => {
const calls: Call[] = [
{
contractAddress: '0x123',
entrypoint: 'transfer',
calldata: [10],
},
{
contractAddress: '0x456',
entrypoint: 'mint',
calldata: ['0x2000', BigInt(10000000)],
},
];
const expected = [
'2', // Call size
'291', // First call
'232670485425082704932579856502088130646006032362877466777181098476241604910',
'1',
'10',
'1110', // Second call
'1329909728320632088402217562277154056711815095720684343816173432540100887380',
'2',
'8192',
'10000000',
];
expect(fromCallsToExecuteCalldata_cairo1(calls)).toEqual(expected);
});
});
Loading

0 comments on commit 1f7f001

Please sign in to comment.