|
| 1 | +import { Call, CallStruct } from '../../src/types'; |
| 2 | +import { |
| 3 | + fromCallsToExecuteCalldata_cairo1, |
| 4 | + transformCallsToMulticallArrays_cairo1, |
| 5 | +} from '../../src/utils/transaction'; |
| 6 | + |
| 7 | +describe('transformCallsToMulticallArrays_cairo1', () => { |
| 8 | + it('should return an empty array when given an empty input', () => { |
| 9 | + expect(transformCallsToMulticallArrays_cairo1([])).toEqual([]); |
| 10 | + }); |
| 11 | + |
| 12 | + it('should transform a list of calls into an array of call structs', () => { |
| 13 | + const calls: Call[] = [ |
| 14 | + { |
| 15 | + contractAddress: '0x123', |
| 16 | + entrypoint: 'transfer', |
| 17 | + calldata: [10], |
| 18 | + }, |
| 19 | + { |
| 20 | + contractAddress: '0x456', |
| 21 | + entrypoint: 'mint', |
| 22 | + calldata: ['0x2000', BigInt(10000000)], |
| 23 | + }, |
| 24 | + ]; |
| 25 | + const expected: CallStruct[] = [ |
| 26 | + { |
| 27 | + to: '291', |
| 28 | + selector: '232670485425082704932579856502088130646006032362877466777181098476241604910', |
| 29 | + calldata: ['10'], |
| 30 | + }, |
| 31 | + { |
| 32 | + to: '1110', |
| 33 | + selector: '1329909728320632088402217562277154056711815095720684343816173432540100887380', |
| 34 | + calldata: ['8192', '10000000'], |
| 35 | + }, |
| 36 | + ]; |
| 37 | + expect(transformCallsToMulticallArrays_cairo1(calls)).toEqual(expected); |
| 38 | + }); |
| 39 | +}); |
| 40 | + |
| 41 | +describe('fromCallsToExecuteCalldata_cairo1', () => { |
| 42 | + it('should return an array with a length of one when given an empty input', () => { |
| 43 | + expect(fromCallsToExecuteCalldata_cairo1([])).toEqual(['0']); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should transform a list of calls into the full flattened calldata', () => { |
| 47 | + const calls: Call[] = [ |
| 48 | + { |
| 49 | + contractAddress: '0x123', |
| 50 | + entrypoint: 'transfer', |
| 51 | + calldata: [10], |
| 52 | + }, |
| 53 | + { |
| 54 | + contractAddress: '0x456', |
| 55 | + entrypoint: 'mint', |
| 56 | + calldata: ['0x2000', BigInt(10000000)], |
| 57 | + }, |
| 58 | + ]; |
| 59 | + const expected = [ |
| 60 | + '2', // Call size |
| 61 | + '291', // First call |
| 62 | + '232670485425082704932579856502088130646006032362877466777181098476241604910', |
| 63 | + '1', |
| 64 | + '10', |
| 65 | + '1110', // Second call |
| 66 | + '1329909728320632088402217562277154056711815095720684343816173432540100887380', |
| 67 | + '2', |
| 68 | + '8192', |
| 69 | + '10000000', |
| 70 | + ]; |
| 71 | + expect(fromCallsToExecuteCalldata_cairo1(calls)).toEqual(expected); |
| 72 | + }); |
| 73 | +}); |
0 commit comments