diff --git a/__mocks__/cairo/testReject/test_reject.cairo b/__mocks__/cairo/testReject/test_reject.cairo new file mode 100644 index 000000000..f9018c43e --- /dev/null +++ b/__mocks__/cairo/testReject/test_reject.cairo @@ -0,0 +1,33 @@ +//Cairo 2.3.1 + +#[starknet::interface] +trait ITestReject { + fn test_fail(ref self: TContractState, p1: u8) ; + fn get_counter(self: @TContractState) -> u8 ; + fn init_count(ref self: TContractState, p1: u8); +} + +#[starknet::contract] +mod MyTestReject { + #[storage] + struct Storage { + counter: u8 + } + + #[external(v0)] + impl TestReject of super::ITestReject { + fn test_fail(ref self: ContractState, p1: u8) { + assert(p1 == 100, 'Fatal'); + self.counter.write(p1); + } + + fn get_counter(self: @ContractState) -> u8 { + self.counter.read() + } + + fn init_count(ref self: ContractState, p1: u8) { + self.counter.write(p1); + } + + } +} diff --git a/__mocks__/cairo/testReject/test_reject.casm b/__mocks__/cairo/testReject/test_reject.casm new file mode 100644 index 000000000..920ea449a --- /dev/null +++ b/__mocks__/cairo/testReject/test_reject.casm @@ -0,0 +1,1189 @@ +{ + "prime": "0x800000000000011000000000000000000000000000000000000000000000001", + "compiler_version": "2.3.1", + "bytecode": [ + "0xa0680017fff8000", + "0x7", + "0x482680017ffa8000", + "0xffffffffffffffffffffffffffffd7f6", + "0x400280007ff97fff", + "0x10780017fff7fff", + "0x88", + "0x4825800180007ffa", + "0x280a", + "0x400280007ff97fff", + "0x482680017ff98000", + "0x1", + "0x48297ffc80007ffd", + "0x20680017fff7fff", + "0x4", + "0x10780017fff7fff", + "0xa", + "0x482680017ffc8000", + "0x1", + "0x480a7ffd7fff8000", + "0x480680017fff8000", + "0x0", + "0x480a7ffc7fff8000", + "0x10780017fff7fff", + "0x8", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x480680017fff8000", + "0x1", + "0x480680017fff8000", + "0x0", + "0x20680017fff7ffe", + "0x5d", + "0x48127ffa7fff8000", + "0x480080007ffe8000", + "0x1104800180018000", + "0x181", + "0x20680017fff7ffe", + "0x54", + "0x48127fee7fff8000", + "0x48127fee7fff8000", + "0x48307ffe80007fff", + "0x4824800180007fff", + "0x0", + "0x20680017fff7fff", + "0x4", + "0x10780017fff7fff", + "0x10", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473", + "0x400080007ffe7fff", + "0x48127ff77fff8000", + "0x48127fe47fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x1104800180018000", + "0x29f", + "0x482480017fff8000", + "0x29e", + "0x480080007fff8000", + "0xa0680017fff8000", + "0x9", + "0x4824800180007fe2", + "0x0", + "0x482480017fff8000", + "0x100000000000000000000000000000000", + "0x400080007ff27fff", + "0x10780017fff7fff", + "0x20", + "0x4824800180007fe2", + "0x0", + "0x400080007ff37fff", + "0x48127fff7fff8000", + "0x480a7ffb7fff8000", + "0x48127ff37fff8000", + "0x1104800180018000", + "0x178", + "0x482480017fd08000", + "0x1", + "0x20680017fff7ffc", + "0xc", + "0x40780017fff7fff", + "0x1", + "0x48127ffe7fff8000", + "0x48127ff87fff8000", + "0x48127ff87fff8000", + "0x480680017fff8000", + "0x0", + "0x48127ffb7fff8000", + "0x48127ffa7fff8000", + "0x208b7fff7fff7ffe", + "0x48127fff7fff8000", + "0x48127ff97fff8000", + "0x48127ff97fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ff97fff8000", + "0x48127ff97fff8000", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482480017ff08000", + "0x1", + "0x48127fdd7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x48127ffd7fff8000", + "0x10780017fff7fff", + "0x5", + "0x40780017fff7fff", + "0xe", + "0x48127fec7fff8000", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4661696c656420746f20646573657269616c697a6520706172616d202331", + "0x400080007ffe7fff", + "0x48127ffd7fff8000", + "0x48127fe77fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482680017ff98000", + "0x1", + "0x480a7ffa7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0xa0680017fff8000", + "0x7", + "0x482680017ffa8000", + "0xffffffffffffffffffffffffffffd6ca", + "0x400280007ff97fff", + "0x10780017fff7fff", + "0x58", + "0x4825800180007ffa", + "0x2936", + "0x400280007ff97fff", + "0x48297ffc80007ffd", + "0x482680017ff98000", + "0x1", + "0x4824800180007ffe", + "0x0", + "0x20680017fff7fff", + "0x4", + "0x10780017fff7fff", + "0x10", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473", + "0x400080007ffe7fff", + "0x48127ffc7fff8000", + "0x48127ff97fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x1104800180018000", + "0x220", + "0x482480017fff8000", + "0x21f", + "0x480080007fff8000", + "0xa0680017fff8000", + "0x9", + "0x4824800180007ff7", + "0x0", + "0x482480017fff8000", + "0x100000000000000000000000000000000", + "0x400080007ff77fff", + "0x10780017fff7fff", + "0x21", + "0x4824800180007ff7", + "0x0", + "0x400080007ff87fff", + "0x482480017ff88000", + "0x1", + "0x48127ffe7fff8000", + "0x480a7ffb7fff8000", + "0x1104800180018000", + "0x124", + "0x20680017fff7ffd", + "0xe", + "0x40780017fff7fff", + "0x1", + "0x400080007fff7ffe", + "0x48127ff97fff8000", + "0x48127ff97fff8000", + "0x48127ff97fff8000", + "0x480680017fff8000", + "0x0", + "0x48127ffb7fff8000", + "0x482480017ffa8000", + "0x1", + "0x208b7fff7fff7ffe", + "0x48127ffa7fff8000", + "0x48127ffa7fff8000", + "0x48127ffa7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x48127ffa7fff8000", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482480017ff58000", + "0x1", + "0x48127ff27fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482680017ff98000", + "0x1", + "0x480a7ffa7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0xa0680017fff8000", + "0x7", + "0x482680017ffa8000", + "0xffffffffffffffffffffffffffffd922", + "0x400280007ff97fff", + "0x10780017fff7fff", + "0x88", + "0x4825800180007ffa", + "0x26de", + "0x400280007ff97fff", + "0x482680017ff98000", + "0x1", + "0x48297ffc80007ffd", + "0x20680017fff7fff", + "0x4", + "0x10780017fff7fff", + "0xa", + "0x482680017ffc8000", + "0x1", + "0x480a7ffd7fff8000", + "0x480680017fff8000", + "0x0", + "0x480a7ffc7fff8000", + "0x10780017fff7fff", + "0x8", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x480680017fff8000", + "0x1", + "0x480680017fff8000", + "0x0", + "0x20680017fff7ffe", + "0x5d", + "0x48127ffa7fff8000", + "0x480080007ffe8000", + "0x1104800180018000", + "0x79", + "0x20680017fff7ffe", + "0x54", + "0x48127fee7fff8000", + "0x48127fee7fff8000", + "0x48307ffe80007fff", + "0x4824800180007fff", + "0x0", + "0x20680017fff7fff", + "0x4", + "0x10780017fff7fff", + "0x10", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473", + "0x400080007ffe7fff", + "0x48127ff77fff8000", + "0x48127fe47fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x1104800180018000", + "0x197", + "0x482480017fff8000", + "0x196", + "0x480080007fff8000", + "0xa0680017fff8000", + "0x9", + "0x4824800180007fe2", + "0x0", + "0x482480017fff8000", + "0x100000000000000000000000000000000", + "0x400080007ff27fff", + "0x10780017fff7fff", + "0x20", + "0x4824800180007fe2", + "0x0", + "0x400080007ff37fff", + "0x48127fff7fff8000", + "0x480a7ffb7fff8000", + "0x48127ff37fff8000", + "0x1104800180018000", + "0xb4", + "0x482480017fd18000", + "0x1", + "0x20680017fff7ffc", + "0xc", + "0x40780017fff7fff", + "0x1", + "0x48127ffe7fff8000", + "0x48127ff87fff8000", + "0x48127ff87fff8000", + "0x480680017fff8000", + "0x0", + "0x48127ffb7fff8000", + "0x48127ffa7fff8000", + "0x208b7fff7fff7ffe", + "0x48127fff7fff8000", + "0x48127ff97fff8000", + "0x48127ff97fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ff97fff8000", + "0x48127ff97fff8000", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482480017ff08000", + "0x1", + "0x48127fdd7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x48127ffd7fff8000", + "0x10780017fff7fff", + "0x5", + "0x40780017fff7fff", + "0xe", + "0x48127fec7fff8000", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4661696c656420746f20646573657269616c697a6520706172616d202331", + "0x400080007ffe7fff", + "0x48127ffd7fff8000", + "0x48127fe77fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482680017ff98000", + "0x1", + "0x480a7ffa7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0xa0680017fff8000", + "0x12", + "0x4825800180007ffd", + "0x100", + "0x4844800180008002", + "0x8000000000000110000000000000000", + "0x4830800080017ffe", + "0x480280007ffc7fff", + "0x482480017ffe8000", + "0xefffffffffffffde00000000000000ff", + "0x480280017ffc7fff", + "0x400280027ffc7ffb", + "0x402480017fff7ffb", + "0xffffffffffffffffffffffffffffffff", + "0x20680017fff7fff", + "0x11", + "0x402780017fff7fff", + "0x1", + "0x400380007ffc7ffd", + "0x482680017ffd8000", + "0xffffffffffffffffffffffffffffff00", + "0x400280017ffc7fff", + "0x40780017fff7fff", + "0x5", + "0x482680017ffc8000", + "0x2", + "0x480680017fff8000", + "0x0", + "0x480a7ffd7fff8000", + "0x10780017fff7fff", + "0x8", + "0x482680017ffc8000", + "0x3", + "0x480680017fff8000", + "0x1", + "0x480680017fff8000", + "0x0", + "0x208b7fff7fff7ffe", + "0x4825800180007ffd", + "0x64", + "0x20680017fff7fff", + "0x4", + "0x10780017fff7fff", + "0x11", + "0x40780017fff7fff", + "0x16", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x466174616c", + "0x400080007ffe7fff", + "0x480a7ffb7fff8000", + "0x480a7ffc7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffb7fff8000", + "0x482480017ffa8000", + "0x1", + "0x208b7fff7fff7ffe", + "0x480a7ffb7fff8000", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x1104800180018000", + "0x43", + "0x20680017fff7ffd", + "0xb", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x208b7fff7fff7ffe", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x208b7fff7fff7ffe", + "0x480a7ffb7fff8000", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x1104800180018000", + "0x60", + "0x20680017fff7ffd", + "0xb", + "0x48127ffa7fff8000", + "0x48127ffa7fff8000", + "0x48127ffa7fff8000", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x48127ffa7fff8000", + "0x208b7fff7fff7ffe", + "0x48127ffa7fff8000", + "0x48127ffa7fff8000", + "0x48127ffa7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x48127ffa7fff8000", + "0x208b7fff7fff7ffe", + "0x480a7ffb7fff8000", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x1104800180018000", + "0x14", + "0x20680017fff7ffd", + "0xb", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x208b7fff7fff7ffe", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x208b7fff7fff7ffe", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x7ebcc807b5c7e19f245995a55aed6f46f5f582f476a886b91b834b0ddf5854", + "0x480680017fff8000", + "0x53746f726167655772697465", + "0x400280007ffc7fff", + "0x400380017ffc7ffb", + "0x400280027ffc7ffd", + "0x400280037ffc7ffe", + "0x400380047ffc7ffd", + "0x480280067ffc8000", + "0x20680017fff7fff", + "0xd", + "0x480280057ffc8000", + "0x482680017ffc8000", + "0x7", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x10780017fff7fff", + "0x9", + "0x480280057ffc8000", + "0x482680017ffc8000", + "0x9", + "0x480680017fff8000", + "0x1", + "0x480280077ffc8000", + "0x480280087ffc8000", + "0x1104800180018000", + "0x41", + "0x20680017fff7ffd", + "0xb", + "0x48127ff67fff8000", + "0x48127ff67fff8000", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x208b7fff7fff7ffe", + "0x48127ff67fff8000", + "0x48127ff67fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x208b7fff7fff7ffe", + "0x480a7ffb7fff8000", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x7ebcc807b5c7e19f245995a55aed6f46f5f582f476a886b91b834b0ddf5854", + "0x1104800180018000", + "0x34", + "0x20680017fff7ffc", + "0x1a", + "0x48127ffd7fff8000", + "0x48127ffd7fff8000", + "0x48127ffd7fff8000", + "0x1104800180018000", + "0x69", + "0x20680017fff7ffd", + "0xb", + "0x48127ff17fff8000", + "0x48127ff17fff8000", + "0x48127ff17fff8000", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x48127ffa7fff8000", + "0x208b7fff7fff7ffe", + "0x48127ff17fff8000", + "0x48127ff17fff8000", + "0x48127ff17fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x48127ffa7fff8000", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x8", + "0x48127ff17fff8000", + "0x48127ff17fff8000", + "0x48127ff17fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ff27fff8000", + "0x48127ff27fff8000", + "0x208b7fff7fff7ffe", + "0x20780017fff7ffb", + "0x9", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x208b7fff7fff7ffe", + "0x480680017fff8000", + "0x1", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x208b7fff7fff7ffe", + "0x480680017fff8000", + "0x53746f7261676552656164", + "0x400280007ffb7fff", + "0x400380017ffb7ffa", + "0x400380027ffb7ffc", + "0x400380037ffb7ffd", + "0x480280057ffb8000", + "0x20680017fff7fff", + "0x28", + "0x480a7ff97fff8000", + "0x480280067ffb8000", + "0x1104800180018000", + "0x800000000000010ffffffffffffffffffffffffffffffffffffffffffffff06", + "0x480280047ffb8000", + "0x482680017ffb8000", + "0x7", + "0x20680017fff7ffc", + "0xf", + "0x40780017fff7fff", + "0x2", + "0x48127ff97fff8000", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x48127ff57fff8000", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x53746f72655538202d206e6f6e207538", + "0x400080007ffe7fff", + "0x48127ff97fff8000", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x480680017fff8000", + "0x0", + "0x48127ff97fff8000", + "0x482480017ff88000", + "0x1", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x12", + "0x480a7ff97fff8000", + "0x480280047ffb8000", + "0x482680017ffb8000", + "0x8", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x1", + "0x480280067ffb8000", + "0x480280077ffb8000", + "0x208b7fff7fff7ffe", + "0x20780017fff7ffb", + "0x8", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x480a7ffd7fff8000", + "0x208b7fff7fff7ffe", + "0x480680017fff8000", + "0x1", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x208b7fff7fff7ffe" + ], + "hints": [ + [ + 0, + [ + { + "TestLessThanOrEqual": { + "lhs": { + "Immediate": "0x280a" + }, + "rhs": { + "Deref": { + "register": "FP", + "offset": -6 + } + }, + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 48, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 67, + [ + { + "TestLessThanOrEqual": { + "lhs": { + "Immediate": "0x0" + }, + "rhs": { + "Deref": { + "register": "AP", + "offset": -29 + } + }, + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 88, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 106, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 127, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 141, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 156, + [ + { + "TestLessThanOrEqual": { + "lhs": { + "Immediate": "0x2936" + }, + "rhs": { + "Deref": { + "register": "FP", + "offset": -6 + } + }, + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 175, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 194, + [ + { + "TestLessThanOrEqual": { + "lhs": { + "Immediate": "0x0" + }, + "rhs": { + "Deref": { + "register": "AP", + "offset": -8 + } + }, + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 214, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 234, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 249, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 264, + [ + { + "TestLessThanOrEqual": { + "lhs": { + "Immediate": "0x26de" + }, + "rhs": { + "Deref": { + "register": "FP", + "offset": -6 + } + }, + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 312, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 331, + [ + { + "TestLessThanOrEqual": { + "lhs": { + "Immediate": "0x0" + }, + "rhs": { + "Deref": { + "register": "AP", + "offset": -29 + } + }, + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 352, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 370, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 391, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 405, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 420, + [ + { + "TestLessThan": { + "lhs": { + "Deref": { + "register": "FP", + "offset": -3 + } + }, + "rhs": { + "Immediate": "0x100" + }, + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 424, + [ + { + "LinearSplit": { + "value": { + "Deref": { + "register": "AP", + "offset": -1 + } + }, + "scalar": { + "Immediate": "0x8000000000000110000000000000000" + }, + "max_x": { + "Immediate": "0xfffffffffffffffffffffffffffffffe" + }, + "x": { + "register": "AP", + "offset": 0 + }, + "y": { + "register": "AP", + "offset": 1 + } + } + } + ] + ], + [ + 466, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 560, + [ + { + "SystemCall": { + "system": { + "Deref": { + "register": "FP", + "offset": -4 + } + } + } + } + ] + ], + [ + 666, + [ + { + "SystemCall": { + "system": { + "Deref": { + "register": "FP", + "offset": -5 + } + } + } + } + ] + ], + [ + 691, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ] + ], + "entry_points_by_type": { + "EXTERNAL": [ + { + "selector": "0x3147e009aa1d3b7827f0cf9ce80b10dd02b119d549eb0a2627600662354eba", + "offset": 264, + "builtins": [ + "range_check" + ] + }, + { + "selector": "0x10b7e63d3ca05c9baffd985d3e1c3858d4dbf0759f066be0eaddc5d71c2cab5", + "offset": 0, + "builtins": [ + "range_check" + ] + }, + { + "selector": "0x3370263ab53343580e77063a719a5865004caff7f367ec136a6cdd34b6786ca", + "offset": 156, + "builtins": [ + "range_check" + ] + } + ], + "L1_HANDLER": [], + "CONSTRUCTOR": [] + } +} \ No newline at end of file diff --git a/__mocks__/cairo/testReject/test_reject.sierra.json b/__mocks__/cairo/testReject/test_reject.sierra.json new file mode 100644 index 000000000..0a660d8f2 --- /dev/null +++ b/__mocks__/cairo/testReject/test_reject.sierra.json @@ -0,0 +1,522 @@ +{ + "sierra_program": [ + "0x1", + "0x3", + "0x0", + "0x2", + "0x3", + "0x1", + "0xf7", + "0x9", + "0x22", + "0x52616e6765436865636b", + "0x800000000000000100000000000000000000000000000000", + "0x7538", + "0x800000000000000700000000000000000000000000000000", + "0x4172726179", + "0x800000000000000300000000000000000000000000000001", + "0x1", + "0x1e", + "0x456e756d", + "0x800000000000000300000000000000000000000000000003", + "0x0", + "0x3baae81d8b68311d843a3db861802028fc5b88bca4c37f5b121cabb0dfa12ac", + "0x2", + "0x537472756374", + "0x800000000000000300000000000000000000000000000002", + "0x2ee1e2b1b89f8c495f200e4956278a4d47395fe262f27b52e5865c9524c08c3", + "0x3", + "0x800000000000000f00000000000000000000000000000001", + "0x16a4c8d7c05909052238a862d8cc3e7975bf05a07b3a69c6b28951083a6d672", + "0x5", + "0xe82f28be99fa1cbe00b18388da8bfdec908ee3097fda05d02792092433ad35", + "0x4", + "0x6", + "0x800000000000000f00000000000000000000000000000002", + "0x8", + "0xcc5e86243f861d2d64b08c35db21013e773ac5cf10097946fe0011304886d5", + "0x9", + "0x101dc0399934cc08fa0d6f6f2daead4e4a38cabeea1c743e1fc28d2d6e58e99", + "0x53746f7261676541646472657373", + "0x53746f726167654261736541646472657373", + "0x184009a5fcc292e1ed4484e514bbc14dc406991056b6c8655cca301862f4945", + "0x800000000000000f00000000000000000000000000000003", + "0xe", + "0x2224364ac687efc6304ee71e22221e921eecedca58983b65abdbf8bbc94a463", + "0xf", + "0x800000000000000700000000000000000000000000000002", + "0x2360086d8de14207bc705f7c51c3fc6bb6de6b826f1a4576e4db739d8b5edaf", + "0x11", + "0x536e617073686f74", + "0x800000000000000700000000000000000000000000000001", + "0x1baeba72e79e9db2587cf44fedb2f3700b2075a5e8e39a562584862c4b71f62", + "0x13", + "0x14", + "0x318d35396a9bff14fc14d962a8b7bc49a3583773cded0b4b1b4e6b711f80f05", + "0x16", + "0x310bef514f21b308fcb4a1f62947660dca3336ac34dce277613300e1d6715cb", + "0x17", + "0x4275696c74696e436f737473", + "0x53797374656d", + "0x9931c641b913035ae674b400b61a51476d506bbe8bba2ff8a6272790aba9e6", + "0x15", + "0x753332", + "0x800000000000000700000000000000000000000000000003", + "0x3b9ddf97bd58cc7301a2107c3eabad82196f38221c880cd3645d07c3aac1422", + "0x66656c74323532", + "0x426f78", + "0x29d7d57c04a880978e7b3689f6218e507f3be17588744b58dc17762447ad0e7", + "0x1f", + "0x4761734275696c74696e", + "0x7e", + "0x7265766f6b655f61705f747261636b696e67", + "0x77697468647261775f676173", + "0x6272616e63685f616c69676e", + "0x7374727563745f6465636f6e737472756374", + "0x656e61626c655f61705f747261636b696e67", + "0x73746f72655f74656d70", + "0x61727261795f736e617073686f745f706f705f66726f6e74", + "0x656e756d5f696e6974", + "0x20", + "0x6a756d70", + "0x7374727563745f636f6e737472756374", + "0x656e756d5f6d61746368", + "0x756e626f78", + "0x72656e616d65", + "0x66756e6374696f6e5f63616c6c", + "0x1d", + "0x61727261795f6c656e", + "0x736e617073686f745f74616b65", + "0x1c", + "0x64726f70", + "0x7533325f636f6e7374", + "0x7533325f6571", + "0x64697361626c655f61705f747261636b696e67", + "0x61727261795f6e6577", + "0x66656c743235325f636f6e7374", + "0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473", + "0x61727261795f617070656e64", + "0x1b", + "0x21", + "0x1a", + "0x6765745f6275696c74696e5f636f737473", + "0x19", + "0x77697468647261775f6761735f616c6c", + "0x18", + "0x4f7574206f6620676173", + "0x4661696c656420746f20646573657269616c697a6520706172616d202331", + "0x12", + "0x75385f746f5f66656c74323532", + "0x75385f7472795f66726f6d5f66656c74323532", + "0x75385f636f6e7374", + "0x64", + "0x75385f6571", + "0x466174616c", + "0x7", + "0x10", + "0x73746f726167655f626173655f616464726573735f636f6e7374", + "0x7ebcc807b5c7e19f245995a55aed6f46f5f582f476a886b91b834b0ddf5854", + "0x73746f726167655f616464726573735f66726f6d5f62617365", + "0xc", + "0x73746f726167655f77726974655f73797363616c6c", + "0xb", + "0xa", + "0xd", + "0x73746f726167655f726561645f73797363616c6c", + "0x53746f72655538202d206e6f6e207538", + "0x26e", + "0xffffffffffffffff", + "0x7d", + "0x6c", + "0x67", + "0x23", + "0x24", + "0x36", + "0x25", + "0x26", + "0x27", + "0x28", + "0x29", + "0x2a", + "0x2b", + "0x2c", + "0x2d", + "0x2e", + "0x2f", + "0x30", + "0x31", + "0x59", + "0x32", + "0x33", + "0x34", + "0x35", + "0x39", + "0x3a", + "0x3b", + "0x3c", + "0x37", + "0x38", + "0x3d", + "0x52", + "0x3e", + "0x3f", + "0x40", + "0x41", + "0x42", + "0x43", + "0x44", + "0x45", + "0x46", + "0x47", + "0x48", + "0x49", + "0x4a", + "0x4b", + "0x4c", + "0x4d", + "0x4e", + "0x4f", + "0x50", + "0x51", + "0x53", + "0x54", + "0x55", + "0x56", + "0x57", + "0x58", + "0x70", + "0x5a", + "0x5b", + "0x5c", + "0x5d", + "0x5e", + "0x5f", + "0x60", + "0x61", + "0x62", + "0x63", + "0x65", + "0x66", + "0x68", + "0x69", + "0x6a", + "0x6b", + "0xdc", + "0xa7", + "0xcf", + "0xc8", + "0x167", + "0xf6", + "0xfb", + "0x156", + "0x151", + "0x120", + "0x143", + "0x13c", + "0x15a", + "0x17b", + "0x180", + "0x198", + "0x1ab", + "0x1c1", + "0x1da", + "0x1f0", + "0x1f5", + "0x200", + "0x226", + "0x6d", + "0x6e", + "0x6f", + "0x21f", + "0x233", + "0x71", + "0x72", + "0x73", + "0x74", + "0x75", + "0x259", + "0x24b", + "0x76", + "0x77", + "0x78", + "0x79", + "0x7a", + "0x7b", + "0x7c", + "0x268", + "0x8b", + "0xea", + "0x175", + "0x183", + "0x1b1", + "0x1c8", + "0x1e0", + "0x207", + "0x22d", + "0x239", + "0x262", + "0x1642", + "0x100b0a0e130b120e1107100b0f0e0d0707070c0b0a09080706050403020100", + "0x917071b071a0b0a091907100b180e100b120e17071607150b0a090d071407", + "0x17072307220b0a0919072107100b200e1f0b120e041e041d0d0719071c0b0a", + "0xe2b07100b240e2a07290b240e0d07282717072607250b0a090707100b240e", + "0x3307320b0a090231043017072f072e0b0a0919072d07100b200e21072c0b18", + "0xb3d3c023b19073a07390b350908072838043719070707360b350904341707", + "0x707422a0707420b0d45070d44080707430b0707420b412b0707400b3f0b3e", + "0x74b080707420807074a0807074945070748070d45070d44190707470b4645", + "0x424f07074a0b0d07514f0707504f07074e0807074d2b0707474c0707481111", + "0x170707471407074708070757560d075508070754070707500b530b524f0707", + "0x47210707470b5d5c0707420b5b580707425a07074259070742070d58070d44", + "0xd0707500d07074e2f0707505e0707481611074b070707422d0707422d0707", + "0x4e2b070750600d07552a070750190707505f0d07550b0d58070d4433070747", + "0x74b0b620707074a0707074e26070740610707481411074b2d0707502d0707", + "0xd07644c07074a0b07074a070d4c070d444c0707420b0d4c070d440b631711", + "0x7486811074b210707422d0707405e070742070d5e070d44670d07550b6665", + "0x420b0d61070d44260707471911074b0b0d5e070d442f070747230707406907", + "0xd440b6e6d070742210707502107074e0b6c6b0d076a070d61070d44610707", + "0x471b070740700707481b11074b6f07074a070d6f070d446f0707420b0d6f07", + "0x680707487011074b71070742070d69070d44690707420b0d69070d44230707", + "0x44700707420b0d70070d441b0707476f0707486f11074b1107074216070740", + "0x730d0755680707420b0d68070d44160707470b0d11070d440b72070d70070d", + "0xd750d070b0d070b0b75070b0b0b7411070748070d11070d44070d68070d44", + "0x71607140b0b75070b160b190775071107110b0b75070b0d0b68170d761416", + "0x190b6d0775077007680b0b75070b0d0b6f076d701b0d750d1907170b160775", + "0x75070b6f0b0b75070b0d0b0b26070b700b210775076d071b0b710775071b07", + "0xd2107710b2107750769071b0b710775076f07190b6907750723076d0b2307", + "0x7140b2b0775072a07230b2a0775072607210b0b75070b0d0b610777260775", + "0x5c07750d2d07610b2d330d75075e2f0d260b5e0775072b07690b2f07750716", + "0x75074f07190b4f0775075807110b5807750771072a0b0b75070b0d0b5a0778", + "0x75070b2f0b0b750708072d0b3a080d75074c07330b4c0775074f072b0b4f07", + "0x700075e0b790775073a075e0b0b750759072d0b00590d75074507330b4507", + "0x70b580b0b75070b0d0b0b7b0b750d7a790d5a0b7907750779075c0b7a0775", + "0x7d0775077d07690b7d0775070b080b7c0775070b4c0b0b75075c074f0b0b75", + "0x75078007000b800775077e7f0d590b7f0775070b450b7e0775077d7c0d3a0b", + "0x781077c0b840775070d077a0b830775071407790b820775073307140b8107", + "0x77e0b860775070b7d0b0b75070b580b0b75070b0d0b858483821607850775", + "0x75070b800b0b75070b0d0b8b8a0d8988870d750d861433117f0b8607750786", + "0x78d07820b8f0775070d077a0b8e0775078807790b8d0775078c07810b8c07", + "0x775078707140b93927b11750791908f8e16840b910775075c07830b900775", + "0x775070b4c0b0b75079407860b0b75070b0d0b9607959407750d9307850b87", + "0x75079a078a0b9a07750799072a0b0b75079807880b99980d75079707870b97", + "0x792077a0b9e0775077b07790b9d0775078707140b9c0775079b078b0b9b07", + "0xa10775079607000b0b75070b0d0ba09f9e9d1607a00775079c077c0b9f0775", + "0x77507a1077c0ba407750792077a0ba30775077b07790ba20775078707140b", + "0x70b8c0ba60775070b4c0b0b75075c074f0b0b75070b0d0ba5a4a3a21607a5", + "0xa90d590ba90775070b450ba8077507a7a60d3a0ba7077507a707690ba70775", + "0x7a0bac0775078b07790bab0775078a07140baa0775079507000b95077507a8", + "0x75a078d0b0b75070b0d0baeadacab1607ae077507aa077c0bad0775070d07", + "0x8d0b0b75070b0d0b0bb0070b700baf0775073307140b0b750771077b0b0b75", + "0x75070b4c0b0b75070b580baf0775071607140b0b750771077b0b0b75076107", + "0x75070b450bb2077507b1890d3a0bb1077507b107690bb10775070b920b8907", + "0x1407790bb6077507af07140bb5077507b407000bb4077507b2b30d590bb307", + "0x75070b0d0bb9b8b7b61607b9077507b5077c0bb80775070d077a0bb7077507", + "0xb650775076507690b650775070b8c0bba0775070b4c0b0b75071107930b0b", + "0x775077807000b78077507bbbc0d590bbc0775070b450bbb07750765ba0d3a", + "0x7507bd077c0bc00775070d077a0bbf0775076807790bbe0775071707140bbd", + "0xb0d0b68170dc114160d750d070b0d070b0b75070b0b0b77c0bfbe16077707", + "0x72d0b6f700d75071b07330b1b07750719072b0b190775071107110b0b7507", + "0x6f075e0b0b750771072d0b21710d75076d07330b6d0775070b2f0b0b750770", + "0xd5a0b160775071607140b2307750723075c0b6907750721075e0b23077507", + "0x6107690b610775070b080b260775070b4c0b0b75070b0d0b0bc20b750d6923", + "0xb330775072a2b0d590b2b0775070b450b2a07750761260d3a0b61077507", + "0xb5c0775070d077a0b5e0775071407790b2f0775071607140b2d0775073307", + "0x758077e0b580775070b7d0b0b75070b0d0b5a5c5e2f16075a0775072d077c", + "0x450775070b800b0b75070b0d0b3a080dc34c4f0d750d581416117f0b580775", + "0x775074f07140b0b750700078f0b79000d750759078e0b590775074507810b", + "0x81807f16900b820775077907820b810775070d077a0b800775074c07790b7f", + "0x775070b4c0b0b75070b0d0b8407c48307750d7e07910b7e7d7c7a16750782", + "0x75078807970b0b750787074f0b88870d75078607960b860775078307940b85", + "0x7880b7b8d0d75078c07870b8c0775078b850d3a0b8b0775078a07980b8a07", + "0x7140b8e07750793078b0b9307750792078a0b920775077b072a0b0b75078d", + "0x1607940775078e077c0b910775077d077a0b900775077c07790b8f0775077a", + "0x77c07790b970775077a07140b960775078407000b0b75070b0d0b9491908f", + "0xb75070b0d0b9a99989716079a07750796077c0b990775077d077a0b980775", + "0x9d0775079c9b0d3a0b9c0775079c07690b9c0775070b8c0b9b0775070b4c0b", + "0x775070807140ba00775079f07000b9f0775079d9e0d590b9e0775070b450b", + "0xa4a3a2a11607a4077507a0077c0ba30775070d077a0ba20775073a07790ba1", + "0xa607690ba60775070b8c0ba50775070b4c0b0b75071107930b0b75070b0d0b", + "0xba9077507a7a80d590ba80775070b450ba7077507a6a50d3a0ba6077507", + "0xbac0775070d077a0bab0775076807790baa0775071707140b95077507a907", + "0xdc514160d750d070b0d070b0b75070b0b0badacabaa1607ad07750795077c", + "0xb160775071607140b0b75070b160b190775071107110b0b75070b0d0b6817", + "0x75071b07190b6d0775077007680b0b75070b0d0b6f07c6701b0d750d190717", + "0x6d0b230775070b6f0b0b75070b0d0b0bc7070b700b210775076d071b0b7107", + "0xc82607750d2107710b2107750769071b0b710775076f07190b690775072307", + "0x775071607140b2b0775072a07230b2a0775072607210b0b75070b0d0b6107", + "0xb5a07c95c07750d2d07610b2d330d75075e2f0d260b5e0775072b07690b2f", + "0x2b0b4f0775074f07190b4f0775075807110b5807750771072a0b0b75070b0d", + "0x330b450775070b2f0b0b750708072d0b3a080d75074c07330b4c0775074f07", + "0xb7a07750700075e0b790775073a075e0b0b750759072d0b00590d75074507", + "0x4f0b0b75070b580b0b75070b0d0b0bca0b750d7a790d5a0b7907750779075c", + "0x7c0d3a0b7d0775077d07690b7d0775070b080b7c0775070b4c0b0b75075c07", + "0x140b810775078007000b800775077e7f0d590b7f0775070b450b7e0775077d", + "0x78507750781077c0b840775070d077a0b830775071407790b820775073307", + "0x7750786077e0b860775070b7d0b0b75070b580b0b75070b0d0b8584838216", + "0x810b8c0775070b800b0b75070b0d0b8b8a0dcb88870d750d861433117f0b86", + "0xb900775078d07820b8f0775070d077a0b8e0775078807790b8d0775078c07", + "0x7850b870775078707140b93927b11750791908f8e16990b910775075c0783", + "0x7870b970775070b4c0b0b75079407860b0b75070b0d0b9607cc9407750d93", + "0x8b0b9b0775079a078a0b9a07750799072a0b0b75079807880b99980d750797", + "0xb9f07750792077a0b9e0775077b07790b9d0775078707140b9c0775079b07", + "0x8707140ba10775079607000b0b75070b0d0ba09f9e9d1607a00775079c077c", + "0xa21607a5077507a1077c0ba407750792077a0ba30775077b07790ba2077507", + "0xba70775070b8c0ba60775070b4c0b0b75075c074f0b0b75070b0d0ba5a4a3", + "0x77507a8a90d590ba90775070b450ba8077507a7a60d3a0ba7077507a70769", + "0x75070d077a0bac0775078b07790bab0775078a07140baa0775079507000b95", + "0x7b0b0b75075a078d0b0b75070b0d0baeadacab1607ae077507aa077c0bad07", + "0x750761078d0b0b75070b0d0b0bcd070b700baf0775073307140b0b75077107", + "0x920b890775070b4c0b0b75070b580baf0775071607140b0b750771077b0b0b", + "0x590bb30775070b450bb2077507b1890d3a0bb1077507b107690bb10775070b", + "0xb70775071407790bb6077507af07140bb5077507b407000bb4077507b2b30d", + "0x7930b0b75070b0d0bb9b8b7b61607b9077507b5077c0bb80775070d077a0b", + "0x65ba0d3a0b650775076507690b650775070b8c0bba0775070b4c0b0b750711", + "0x7140bbd0775077807000b78077507bbbc0d590bbc0775070b450bbb077507", + "0x160777077507bd077c0bc00775070d077a0bbf0775076807790bbe07750717", + "0x1407750711079b0b0b75070b0d0b1607ce110d0d750d070b0d9a0b77c0bfbe", + "0xb6f0b0b75070b0d0b0bcf070b700b6807750714079c0b170775070d07140b", + "0x79e0b680775071b079c0b170775071607140b1b07750719079d0b19077507", + "0x75070ba00b14160d75071107960b6f700d076f07750768079f0b7007750717", + "0x71907970b1b0775071407970b0b750768074f0b19680d75071707960b1707", + "0x70d078f0b0b750716074f0b0b75070b0d0b0bd00b750d701b0da10b700775", + "0x75076d6f0d3a0b6d0775076d07690b6d0775070ba20b6f0775070b4c0b0b75", + "0x70b07790b690775072307a30b2307750771210d590b210775070b450b7107", + "0xb0b75070b0d0b2a612611072a0775076907a40b6107750707077a0b260775", + "0x5a0775072b07a60b5c07750707077a0b5e0775070b07790b2b0775070d07a5", + "0x7d14f07750d2f07a80b2f2d33117507585a5c5e16a70b580775071607830b", + "0xb450775070b6f0b0b75073a078d0b3a080d75074f07a90b0b75070b0d0b4c", + "0x775073307790b790775070007aa0b0007750745590d950b59077507080781", + "0x7a30b0b75070b0d0b7d7c7a11077d0775077907a40b7c0775072d077a0b7a", + "0x1107810775077e07a40b800775072d077a0b7f0775073307790b7e0775074c", + "0xd077a0b700775070707790b1b0775070b07140b160775071107a50b81807f", + "0xd1907910b196817141675076d6f701b16ab0b6d0775071607a60b6f077507", + "0x7ad0b690775072307ac0b230775077107940b0b75070b0d0b2107d2710775", + "0xae0b2b07750768077a0b2a0775071707790b610775071407140b2607750769", + "0x71407140b2d0775072107af0b0b75070b0d0b332b2a611607330775072607", + "0x5e2f16075a0775072d07ae0b5c07750768077a0b5e0775071707790b2f0775", + "0x71607a60b1b07750707077a0b190775070b07790b160775070d07a50b5a5c", + "0x7750d6807a80b6817141175076f701b1916a70b6f0775071107830b700775", + "0x75070b6f0b0b750723078d0b23210d75076d07a90b0b75070b0d0b7107d36d", + "0x1407790b2a0775076107aa0b6107750769260d950b260775072107810b6907", + "0xb75070b0d0b2d332b11072d0775072a07a40b3307750717077a0b2b077507", + "0x775072f07a40b5c07750717077a0b5e0775071407790b2f0775077107a30b", + "0x2f0b170775071607b10b140775071107980b160775070b890b5a5c5e11075a", + "0xb40b6807750768075c0b0b75071b07b30b1b190d75070d07b20b680775070b", + "0xb0b75070b0d0b21716d11d46f700d750d141768070b14b50b170775071707", + "0xb610775076f077a0b260775077007790b690775072307b60b230775070b6f", + "0x6d07790b2b0775072107b80b0b75070b0d0b0bd5070b700b2a0775076907b7", + "0x7ba0b2d0775072a07b90b2a0775072b07b70b6107750771077a0b26077507", + "0xb5c0775072f07bb0b0b75070b0d0b5e07d62f07750d3307650b330775072d", + "0x7750761077a0b4f0775072607790b580775075a07780b5a0775075c190dbc", + "0x5e07be0b0b75071907b30b0b75070b0d0b084c4f1107080775075807bd0b4c", + "0x451107000775073a07bd0b5907750761077a0b450775072607790b3a077507", + "0x700775070b07140b140775070b2f0b160775070b890b0b75071107b30b0059", + "0x775071607bf0b7107750714075c0b6d0775070d077a0b6f0775070707790b", + "0x70b0d0b6907d72307750d1b07770b1b19681716750721716d6f7014c00b21", + "0xd6107910b610775072a07da0b2a0775072607d90b260775072307d80b0b75", + "0x7ad0b2f0775072d07ac0b2d0775072b07940b0b75070b0d0b3307db2b0775", + "0xae0b5807750719077a0b5a0775076807790b5c0775071707140b5e0775072f", + "0x71707140b4c0775073307af0b0b75070b0d0b4f585a5c16074f0775075e07", + "0x3a081607590775074c07ae0b4507750719077a0b3a0775076807790b080775", + "0x775076807790b790775071707140b000775076907af0b0b75070b0d0b5945", + "0x707750d0b07b00b7d7c7a7916077d0775070007ae0b7c07750719077a0b7a", + "0x75071607df0b160775071107de0b110775070707dd0b0b75070b0d0b0d07dc", + "0x6807e00b680775070d170d590b170775070b450b0b75070b0d0b1407071407", + "0xd14110d0716e10b140775071607b10b1b07071b0775071907df0b19077507", + "0x775071907690b210775070b07140b0b75070b0d0b6f701b11e21968171175", + "0x7107610b6807750768077a0b170775071707790b716d0d750723210d260b23", + "0xe60b2a0775076107e50b610775076907e40b0b75070b0d0b2607e36907750d", + "0xb2f07750768077a0b2d0775071707790b330775076d07140b2b0775072a07", + "0x75070b4c0b0b750726078d0b0b75070b0d0b5e2f2d3316075e0775072b07e7", + "0x75070b450b580775075a5c0d3a0b5a0775075a07690b5a0775070be80b5c07", + "0x1707790b3a0775076d07140b080775074c07e90b4c077507584f0d590b4f07", + "0x75070b0d0b0059453a1607000775070807e70b5907750768077a0b45077507", + "0x75070b07140b7c0775077a07e60b7a0775077907e50b790775076f07ea0b0b", + "0x7f7e7d1607800775077c07e70b7f07750770077a0b7e0775071b07790b7d07", + "0x71107ad0b110775070707ac0b0b75070b0d0b0d07eb0707750d0b07760b80", + "0x170d590b170775070b450b0b75070b0d0b140707140775071607ae0b160775", + "0x162b5a590b166d1b07071b0775071907ae0b190775076807af0b680775070d", + "0xb162b5a590b16ec110d070b585a590b162b5a590b160b110d070b585a590b", + "0xef110d070b5e5a5911072d5a5916ee070b4c0b0d080b0ded110d070b585a59", + "0x5916f1110d070b5e5a5911072d5a5916f0110d070b615a590b162d5a590b16", + "0x70076f07f3110d070b615a590b16215a590b16f2110d070b695a591107215a", + "0xf60b61071107f516110d070b685a590b16714f5a590b14f40b" + ], + "sierra_program_debug_info": { + "type_names": [], + "libfunc_names": [], + "user_func_names": [] + }, + "contract_class_version": "0.1.0", + "entry_points_by_type": { + "EXTERNAL": [ + { + "selector": "0x3147e009aa1d3b7827f0cf9ce80b10dd02b119d549eb0a2627600662354eba", + "function_idx": 2 + }, + { + "selector": "0x10b7e63d3ca05c9baffd985d3e1c3858d4dbf0759f066be0eaddc5d71c2cab5", + "function_idx": 0 + }, + { + "selector": "0x3370263ab53343580e77063a719a5865004caff7f367ec136a6cdd34b6786ca", + "function_idx": 1 + } + ], + "L1_HANDLER": [], + "CONSTRUCTOR": [] + }, + "abi": [ + { + "type": "impl", + "name": "TestReject", + "interface_name": "reject::reject::ITestReject" + }, + { + "type": "interface", + "name": "reject::reject::ITestReject", + "items": [ + { + "type": "function", + "name": "test_fail", + "inputs": [ + { + "name": "p1", + "type": "core::integer::u8" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "get_counter", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u8" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "init_count", + "inputs": [ + { + "name": "p1", + "type": "core::integer::u8" + } + ], + "outputs": [], + "state_mutability": "external" + } + ] + }, + { + "type": "event", + "name": "reject::reject::MyTestReject::Event", + "kind": "enum", + "variants": [] + } + ] +} diff --git a/__tests__/config/fixtures.ts b/__tests__/config/fixtures.ts index 65bfd68f6..050879b5d 100644 --- a/__tests__/config/fixtures.ts +++ b/__tests__/config/fixtures.ts @@ -57,6 +57,8 @@ export const compiledNaming = readContractSierra('starknetId/naming/naming.sierr export const compiledNamingCasm = readContractSierraCasm('starknetId/naming/naming'); export const compiledPricing = readContractSierra('starknetId/pricing/pricing.sierra'); export const compiledPricingCasm = readContractSierraCasm('starknetId/pricing/pricing'); +export const compiledTestRejectSierra = readContractSierra('cairo/testReject/test_reject.sierra'); +export const compiledTestRejectCasm = readContractSierraCasm('cairo/testReject/test_reject'); export const compiledSidMulticall = readContractSierra('starknetId/multicall/multicall.sierra'); export const compiledSidMulticallCasm = readContractSierraCasm('starknetId/multicall/multicall'); diff --git a/__tests__/contract.test.ts b/__tests__/contract.test.ts index 19eb64348..d72db6f22 100644 --- a/__tests__/contract.test.ts +++ b/__tests__/contract.test.ts @@ -2,12 +2,12 @@ import { BigNumberish, Contract, ContractFactory, - GetTransactionReceiptResponse, ParsedEvents, RawArgs, json, shortString, stark, + SuccessfulTransactionReceiptResponse, } from '../src'; import { CallData } from '../src/utils/calldata'; import { felt, isCairo1Abi, tuple, uint256 } from '../src/utils/calldata/cairo'; @@ -795,7 +795,7 @@ describe('Complex interaction', () => { test('invoke compiled data', async () => { const result = await erc20Echo20Contract.iecho(CallData.compile(request)); const transaction = await provider.waitForTransaction(result.transaction_hash); - expect((transaction as GetTransactionReceiptResponse).execution_status).toBeDefined(); + expect((transaction as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined(); }); // skip on live for performance @@ -805,19 +805,19 @@ describe('Complex interaction', () => { const result = await erc20Echo20Contract.iecho(calldata); const transaction = await provider.waitForTransaction(result.transaction_hash); - expect((transaction as GetTransactionReceiptResponse).execution_status).toBeDefined(); + expect((transaction as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined(); const result1 = await erc20Echo20Contract.iecho(...args); const transaction1 = await provider.waitForTransaction(result1.transaction_hash); - expect((transaction1 as GetTransactionReceiptResponse).execution_status).toBeDefined(); + expect((transaction1 as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined(); const result2 = await erc20Echo20Contract.invoke('iecho', calldata); const transaction2 = await provider.waitForTransaction(result2.transaction_hash); - expect((transaction2 as GetTransactionReceiptResponse).execution_status).toBeDefined(); + expect((transaction2 as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined(); const result3 = await erc20Echo20Contract.invoke('iecho', args); const transaction3 = await provider.waitForTransaction(result3.transaction_hash); - expect((transaction3 as GetTransactionReceiptResponse).execution_status).toBeDefined(); + expect((transaction3 as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined(); }); describe('speedup live tests', () => { @@ -871,7 +871,9 @@ describe('Complex interaction', () => { { formatResponse } ); const transaction = await provider.waitForTransaction(result.transaction_hash); - expect((transaction as GetTransactionReceiptResponse).execution_status).toBeDefined(); + expect( + (transaction as SuccessfulTransactionReceiptResponse).execution_status + ).toBeDefined(); }); }); diff --git a/__tests__/rpcProvider.test.ts b/__tests__/rpcProvider.test.ts index cb8024c51..a10bdcabf 100644 --- a/__tests__/rpcProvider.test.ts +++ b/__tests__/rpcProvider.test.ts @@ -8,6 +8,7 @@ import { FeeEstimate, RPC, RPC06, + ReceiptTx, RpcProvider, TransactionExecutionStatus, stark, @@ -166,12 +167,12 @@ describeIfRpc('RPCProvider', () => { test('successful - default', async () => { transactionStatusSpy.mockResolvedValueOnce(response.successful); - await expect(rpcProvider.waitForTransaction(0)).resolves.toBe(receipt); + await expect(rpcProvider.waitForTransaction(0)).resolves.toBeInstanceOf(ReceiptTx); }); test('reverted - default', async () => { transactionStatusSpy.mockResolvedValueOnce(response.reverted); - await expect(rpcProvider.waitForTransaction(0)).resolves.toBe(receipt); + await expect(rpcProvider.waitForTransaction(0)).resolves.toBeInstanceOf(ReceiptTx); }); test('rejected - default', async () => { diff --git a/__tests__/transactionReceipt.test.ts b/__tests__/transactionReceipt.test.ts new file mode 100644 index 000000000..98572cfc1 --- /dev/null +++ b/__tests__/transactionReceipt.test.ts @@ -0,0 +1,104 @@ +import { + Call, + Contract, + DeclareDeployUDCResponse, + RevertedTransactionReceiptResponse, + SuccessfulTransactionReceiptResponse, + TransactionExecutionStatus, +} from '../src'; +import { + compiledTestRejectCasm, + compiledTestRejectSierra, + getTestAccount, + getTestProvider, +} from './config/fixtures'; + +describe('Transaction receipt utility', () => { + const provider = getTestProvider(); + const account = getTestAccount(provider); + + let dd: DeclareDeployUDCResponse; + let contract: Contract; + + beforeAll(async () => { + dd = await account.declareAndDeploy({ + contract: compiledTestRejectSierra, + casm: compiledTestRejectCasm, + }); + await provider.waitForTransaction(dd.deploy.transaction_hash); + contract = new Contract(compiledTestRejectSierra.abi, dd.deploy.contract_address, account); + contract.connect(account); + }); + + test('test for Success variant', async () => { + const myCall: Call = contract.populate('test_fail', { p1: 100 }); + const res = await account.execute(myCall, undefined, { maxFee: 1 * 10 ** 15 }); // maxFee needed to not throw error in getEstimateFee + const txR = await provider.waitForTransaction(res.transaction_hash); + expect(txR.value).toHaveProperty('execution_status', TransactionExecutionStatus.SUCCEEDED); + expect(txR.statusReceipt).toBe('success'); + expect(txR.isSuccess()).toBe(true); + expect(txR.isRejected()).toBe(false); + expect(txR.isReverted()).toBe(false); + expect(txR.isError()).toBe(false); + let isSuccess: boolean = false; + txR.match({ + success: () => { + isSuccess = true; + }, + _: () => { + isSuccess = false; + }, + }); + expect(isSuccess).toBe(true); + }); + + test('test for Reverted variant', async () => { + const myCall: Call = contract.populate('test_fail', { p1: 10 }); // reverted if not 100 + const res = await account.execute(myCall, undefined, { maxFee: 1 * 10 ** 15 }); // maxFee needed to not throw error in getEstimateFee + const txR = await provider.waitForTransaction(res.transaction_hash); + expect(txR.value).toHaveProperty('execution_status', TransactionExecutionStatus.REVERTED); + expect(txR.statusReceipt).toBe('reverted'); + expect(txR.isSuccess()).toBe(false); + expect(txR.isRejected()).toBe(false); + expect(txR.isReverted()).toBe(true); + expect(txR.isError()).toBe(false); + let isReverted: boolean = false; + txR.match({ + reverted: (_resp: RevertedTransactionReceiptResponse) => { + isReverted = true; + }, + _: () => { + isReverted = false; + }, + }); + expect(isReverted).toBe(true); + }); + + test('test for deploy Success variant', async () => { + const res = await account.deployContract( + { classHash: dd.declare.class_hash }, + { maxFee: 1 * 10 ** 15 } + ); // maxFee needed to not throw error in getEstimateFee + const txR = await provider.waitForTransaction(res.transaction_hash); + expect(txR.value).toHaveProperty('execution_status', TransactionExecutionStatus.SUCCEEDED); + expect(txR.statusReceipt).toBe('success'); + expect(txR.isSuccess()).toBe(true); + expect(txR.isRejected()).toBe(false); + expect(txR.isReverted()).toBe(false); + expect(txR.isError()).toBe(false); + let isSuccess: boolean = false; + txR.match({ + success: (_resp: SuccessfulTransactionReceiptResponse) => { + isSuccess = true; + }, + _: () => { + isSuccess = false; + }, + }); + expect(isSuccess).toBe(true); + }); + + // NOTE: + // no rejected test, impossible to trigger 'rejected' from a node/devnet. + // no declare test due to slow process (result is very similar to Invoke) +}); diff --git a/src/contract/default.ts b/src/contract/default.ts index b18139df8..1cac159d8 100644 --- a/src/contract/default.ts +++ b/src/contract/default.ts @@ -15,7 +15,6 @@ import { ContractOptions, EstimateFeeResponse, FunctionAbi, - GetTransactionReceiptResponse, InvokeFunctionResponse, InvokeOptions, InvokeTransactionReceiptResponse, @@ -31,6 +30,7 @@ import { createAbiParser } from '../utils/calldata/parser'; import { getAbiEvents, parseEvents as parseRawEvents } from '../utils/events/index'; import { cleanHex } from '../utils/num'; import { ContractInterface } from './interface'; +import type { GetTransactionReceiptResponse } from '../utils/transactionReceipt'; export type TypedContractV2 = AbiWanTypedContract & Contract; diff --git a/src/contract/interface.ts b/src/contract/interface.ts index 1b3a56fb7..bab526be3 100644 --- a/src/contract/interface.ts +++ b/src/contract/interface.ts @@ -13,7 +13,6 @@ import { ContractFunction, ContractVersion, EstimateFeeResponse, - GetTransactionReceiptResponse, Invocation, InvokeFunctionResponse, InvokeOptions, @@ -25,6 +24,7 @@ import { import { CairoCustomEnum } from '../utils/calldata/enum/CairoCustomEnum'; import { CairoOption } from '../utils/calldata/enum/CairoOption'; import { CairoResult } from '../utils/calldata/enum/CairoResult'; +import type { GetTransactionReceiptResponse } from '../utils/transactionReceipt'; declare module 'abi-wan-kanabi' { export interface Config { diff --git a/src/index.ts b/src/index.ts index 3a2c4576e..42c728697 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,6 +40,7 @@ export * from './utils/calldata'; export * from './utils/calldata/enum'; export * from './utils/contract'; export * from './utils/events'; +export * from './utils/transactionReceipt'; /** * Deprecated diff --git a/src/provider/interface.ts b/src/provider/interface.ts index b9026ab91..4875211bf 100644 --- a/src/provider/interface.ts +++ b/src/provider/interface.ts @@ -17,7 +17,6 @@ import type { EstimateFeeResponse, EstimateFeeResponseBulk, GetBlockResponse, - GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, @@ -32,6 +31,7 @@ import type { getSimulateTransactionOptions, waitForTransactionOptions, } from '../types'; +import type { GetTransactionReceiptResponse } from '../utils/transactionReceipt'; export abstract class ProviderInterface { public abstract channel: RPC07.RpcChannel | RPC06.RpcChannel; diff --git a/src/provider/rpc.ts b/src/provider/rpc.ts index 0e3fa6970..5abb32a46 100644 --- a/src/provider/rpc.ts +++ b/src/provider/rpc.ts @@ -25,10 +25,12 @@ import { getEstimateFeeBulkOptions, getSimulateTransactionOptions, waitForTransactionOptions, + GetTxReceiptResponseWithoutHelper, } from '../types'; import { getAbiContractVersion } from '../utils/calldata/cairo'; import { isSierra } from '../utils/contract'; import { RPCResponseParser } from '../utils/responseParser/rpc'; +import { ReceiptTx, GetTransactionReceiptResponse } from '../utils/transactionReceipt'; export class RpcProvider implements ProviderInterface { private responseParser: RPCResponseParser; @@ -147,10 +149,11 @@ export class RpcProvider implements ProviderInterface { return this.channel.getTransactionByBlockIdAndIndex(blockIdentifier, index); } - public async getTransactionReceipt(txHash: BigNumberish) { - return this.channel - .getTransactionReceipt(txHash) - .then(this.responseParser.parseTransactionReceipt); + public async getTransactionReceipt(txHash: BigNumberish): Promise { + const txReceiptWoHelper = await this.channel.getTransactionReceipt(txHash); + const txReceiptWoHelperModified: GetTxReceiptResponseWithoutHelper = + this.responseParser.parseTransactionReceipt(txReceiptWoHelper); + return new ReceiptTx(txReceiptWoHelperModified) as GetTransactionReceiptResponse; } public async getTransactionTrace(txHash: BigNumberish) { @@ -181,8 +184,15 @@ export class RpcProvider implements ProviderInterface { .then((r) => this.responseParser.parseSimulateTransactionResponse(r)); } - public async waitForTransaction(txHash: BigNumberish, options?: waitForTransactionOptions) { - return this.channel.waitForTransaction(txHash, options); + public async waitForTransaction( + txHash: BigNumberish, + options?: waitForTransactionOptions + ): Promise { + const receiptWoHelper = (await this.channel.waitForTransaction( + txHash, + options + )) as GetTxReceiptResponseWithoutHelper; + return new ReceiptTx(receiptWoHelper) as GetTransactionReceiptResponse; } public async getStorageAt( diff --git a/src/types/index.ts b/src/types/index.ts index a096ffccc..37c03d8f9 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -6,5 +6,6 @@ export * from './provider'; export * from './signer'; export * from './typedData'; export * from './cairoEnum'; +export * from './transactionReceipt'; export * as RPC from './api'; diff --git a/src/types/provider/response.ts b/src/types/provider/response.ts index 6be225614..2dbdae650 100644 --- a/src/types/provider/response.ts +++ b/src/types/provider/response.ts @@ -3,7 +3,15 @@ * Intersection (sequencer response ∩ (∪ rpc responses)) */ -import { CompiledSierra, LegacyContractClass } from '../lib'; +import { + CompiledSierra, + LegacyContractClass, + TransactionExecutionStatus, + TransactionFinalityStatus, + TransactionType, + TransactionStatus, + BlockNumber, +} from '../lib'; import { BLOCK_HASH, BLOCK_NUMBER, @@ -24,8 +32,6 @@ import { TXN_HASH, DeclaredTransaction, InvokedTransaction, - PendingReceipt, - Receipt, ResourceBounds, SimulateTransaction, TransactionWithHash, @@ -58,9 +64,45 @@ export type Block = { transactions: TXN_HASH[]; }; -export type GetTransactionResponse = TransactionWithHash; +export interface MessageToL1 { + to_address: string; + payload: Array; +} + +export type RevertedTransactionReceiptResponse = { + type?: TransactionType | any; // RPC only // any due to RPC Spec issue + execution_status: TransactionExecutionStatus.REVERTED | any; // any due to RPC Spec issue + finality_status: TransactionFinalityStatus | any; + status?: TransactionStatus; // SEQ only + actual_fee: string; + block_hash?: string; // ?~ optional due to RPC spec issue + block_number?: BlockNumber; // ?~ optional due to RCP spec issue + transaction_hash: string; + transaction_index?: number; // SEQ only + messages_sent: Array; // SEQ Casted l2_to_l1_messages + events: any[]; + revert_reason?: string; // SEQ Casted revert_error // ?~ optional due to RCP spec issue +}; -export type GetTransactionReceiptResponse = Receipt | PendingReceipt; +export type RejectedTransactionReceiptResponse = { + status: `${TransactionStatus.REJECTED}`; + transaction_failure_reason: { + code: string; + error_message: string; + }; +}; + +export type GetTxReceiptResponseWithoutHelper = + | SuccessfulTransactionReceiptResponse + | RevertedTransactionReceiptResponse + | RejectedTransactionReceiptResponse; + +export type SuccessfulTransactionReceiptResponse = + | InvokeTransactionReceiptResponse + | DeployTransactionReceiptResponse + | DeclareTransactionReceiptResponse; + +export type GetTransactionResponse = TransactionWithHash; // Spread individual types for usage convenience export type InvokeTransactionReceiptResponse = INVOKE_TXN_RECEIPT | PENDING_INVOKE_TXN_RECEIPT; export type DeclareTransactionReceiptResponse = DECLARE_TXN_RECEIPT | PENDING_DECLARE_TXN_RECEIPT; diff --git a/src/types/provider/spec.ts b/src/types/provider/spec.ts index 8f676a3d8..3a51a7604 100644 --- a/src/types/provider/spec.ts +++ b/src/types/provider/spec.ts @@ -33,7 +33,7 @@ type MergeProperties, T2 extends Record> = // type c = Merge; // { w: (bigint | number)[] x: bigint | number; y?: string; z?: string; } // // NOTE: handling for ambiguous overlaps, such as a shared property being an array or object, -// is simplified to resolve to only one type since there shouldn't be such occurences in the +// is simplified to resolve to only one type since there shouldn't be such occurrences in the // currently supported RPC specifications type Merge = Simplify< T1 extends Array diff --git a/src/types/transactionReceipt.ts b/src/types/transactionReceipt.ts new file mode 100644 index 000000000..84d96b06d --- /dev/null +++ b/src/types/transactionReceipt.ts @@ -0,0 +1,32 @@ +import { + RejectedTransactionReceiptResponse, + RevertedTransactionReceiptResponse, + SuccessfulTransactionReceiptResponse, +} from './provider'; + +export type TransactionStatusReceiptSets = { + success: SuccessfulTransactionReceiptResponse; + reverted: RevertedTransactionReceiptResponse; + rejected: RejectedTransactionReceiptResponse; + error: Error; +}; +export type TransactionReceiptStatus = keyof TransactionStatusReceiptSets; +export type TransactionReceiptValue = TransactionStatusReceiptSets[TransactionReceiptStatus]; + +export type TransactionReceiptCallbacksDefined = { + [key in TransactionReceiptStatus]: (response: TransactionStatusReceiptSets[key]) => void; +}; +export type TransactionReceiptCallbacksDefault = Partial & { + _: () => void; +}; +export type TransactionReceiptCallbacks = + | TransactionReceiptCallbacksDefined + | TransactionReceiptCallbacksDefault; + +export type TransactionReceiptUtilityInterface = { + readonly statusReceipt: TransactionReceiptStatus; + readonly value: TransactionReceiptValue; + match(callbacks: TransactionReceiptCallbacks): void; +} & { + [key in `is${Capitalize}`]: () => boolean; +}; diff --git a/src/utils/provider.ts b/src/utils/provider.ts index 59983e23d..6f10ac51d 100644 --- a/src/utils/provider.ts +++ b/src/utils/provider.ts @@ -7,12 +7,10 @@ import { CompiledSierra, ContractClass, GetBlockResponse, - GetTransactionReceiptResponse, InvocationsDetailsWithNonce, LegacyContractClass, PendingBlock, PendingStateUpdate, - RPC, SierraContractClass, StateUpdateResponse, V3TransactionDetails, @@ -23,6 +21,7 @@ import { formatSpaces } from './hash'; import { parse, stringify } from './json'; import { isBigInt, isHex, isNumber, toHex } from './num'; import { compressProgram } from './stark'; +import type { GetTransactionReceiptResponse } from './transactionReceipt'; import { isString } from './shortString'; /** @@ -193,9 +192,7 @@ export function isPendingBlock(response: GetBlockResponse): response is PendingB /** * Guard Pending Transaction */ -export function isPendingTransaction( - response: GetTransactionReceiptResponse -): response is RPC.PendingReceipt { +export function isPendingTransaction(response: GetTransactionReceiptResponse): boolean { return !('block_hash' in response); } diff --git a/src/utils/responseParser/index.ts b/src/utils/responseParser/index.ts index fe3014bb4..9161fc124 100644 --- a/src/utils/responseParser/index.ts +++ b/src/utils/responseParser/index.ts @@ -4,11 +4,11 @@ import { DeployContractResponse, EstimateFeeResponse, GetBlockResponse, - GetTransactionReceiptResponse, GetTransactionResponse, InvokeFunctionResponse, SimulateTransactionResponse, } from '../../types'; +import type { GetTransactionReceiptResponse } from '../transactionReceipt'; export abstract class ResponseParser { abstract parseGetBlockResponse(res: any): GetBlockResponse; diff --git a/src/utils/responseParser/rpc.ts b/src/utils/responseParser/rpc.ts index 9ae3ce45d..a30dba2c9 100644 --- a/src/utils/responseParser/rpc.ts +++ b/src/utils/responseParser/rpc.ts @@ -10,11 +10,11 @@ import { EstimateFeeResponse, EstimateFeeResponseBulk, GetBlockResponse, - GetTransactionReceiptResponse, FeeEstimate, SimulateTransactionResponse, SimulatedTransaction, RpcProviderOptions, + GetTxReceiptResponseWithoutHelper, } from '../../types/provider'; import { toBigInt } from '../num'; import { estimateFeeToBounds, estimatedFeeToMaxFee } from '../stark'; @@ -55,20 +55,20 @@ export class RPCResponseParser return { status: 'PENDING', ...res } as GetBlockResponse; } - public parseTransactionReceipt(res: TransactionReceipt): GetTransactionReceiptResponse { + public parseTransactionReceipt(res: TransactionReceipt): GetTxReceiptResponseWithoutHelper { // HOTFIX RPC 0.5 to align with RPC 0.6 // This case is RPC 0.5. It can be only v2 thx with FRI units if ('actual_fee' in res && isString(res.actual_fee)) { return { - ...(res as GetTransactionReceiptResponse), + ...(res as GetTxReceiptResponseWithoutHelper), actual_fee: { amount: res.actual_fee, unit: 'FRI', }, - }; + } as GetTxReceiptResponseWithoutHelper; } - return res as GetTransactionReceiptResponse; + return res as GetTxReceiptResponseWithoutHelper; } public parseFeeEstimateResponse(res: FeeEstimate[]): EstimateFeeResponse { diff --git a/src/utils/transactionReceipt.ts b/src/utils/transactionReceipt.ts new file mode 100644 index 000000000..ffc353985 --- /dev/null +++ b/src/utils/transactionReceipt.ts @@ -0,0 +1,114 @@ +/* eslint-disable no-nested-ternary */ +import { + GetTxReceiptResponseWithoutHelper, + RejectedTransactionReceiptResponse, + RevertedTransactionReceiptResponse, + SuccessfulTransactionReceiptResponse, + TransactionExecutionStatus, +} from '../types'; +import type { + TransactionReceiptCallbacks, + TransactionReceiptCallbacksDefault, + TransactionReceiptStatus, + TransactionReceiptUtilityInterface, + TransactionReceiptValue, +} from '../types/transactionReceipt'; + +/** + * Utility that analyses transaction receipt response and provides helpers to process it + * @example + * ```typescript + * const responseTx = new ReceiptTx(receipt); + * responseTx.match({ + * success: (txR: SuccessfulTransactionReceiptResponse) => { }, + * rejected: (txR: RejectedTransactionReceiptResponse) => { }, + * reverted: (txR: RevertedTransactionReceiptResponse) => { }, + * error: (err: Error) => { }, + * }); + * responseTx.match({ + * success: (txR: SuccessfulTransactionReceiptResponse) => { }, + * _: () => { }, + * } + * ``` + */ +export class ReceiptTx implements TransactionReceiptUtilityInterface { + public readonly statusReceipt: TransactionReceiptStatus; + + public readonly value: TransactionReceiptValue; + + constructor(receipt: GetTxReceiptResponseWithoutHelper) { + [this.statusReceipt, this.value] = ReceiptTx.isSuccess(receipt) + ? ['success', receipt] + : ReceiptTx.isReverted(receipt) + ? ['reverted', receipt] + : ReceiptTx.isRejected(receipt) + ? ['rejected', receipt] + : ['error', new Error('Unknown response type')]; + // eslint-disable-next-line no-restricted-syntax + for (const [key] of Object.entries(this)) { + Object.defineProperty(this, key, { + enumerable: false, + }); + } + // eslint-disable-next-line no-restricted-syntax + for (const [key, value] of Object.entries(receipt)) { + Object.defineProperty(this, key, { + enumerable: true, + writable: false, + value, + }); + } + } + + match(callbacks: TransactionReceiptCallbacks) { + if (this.statusReceipt in callbacks) { + return callbacks[this.statusReceipt]!(this.value as any); + } + return (callbacks as TransactionReceiptCallbacksDefault)._(); + } + + isSuccess() { + return this.statusReceipt === 'success'; + } + + isReverted() { + return this.statusReceipt === 'reverted'; + } + + isRejected() { + return this.statusReceipt === 'rejected'; + } + + isError() { + return this.statusReceipt === 'error'; + } + + static isSuccess( + transactionReceipt: GetTxReceiptResponseWithoutHelper + ): transactionReceipt is SuccessfulTransactionReceiptResponse { + return ( + (transactionReceipt as SuccessfulTransactionReceiptResponse).execution_status === + TransactionExecutionStatus.SUCCEEDED + ); + } + + static isReverted( + transactionReceipt: GetTxReceiptResponseWithoutHelper + ): transactionReceipt is RevertedTransactionReceiptResponse { + return ( + (transactionReceipt as RevertedTransactionReceiptResponse).execution_status === + TransactionExecutionStatus.REVERTED + ); + } + + static isRejected( + transactionReceipt: GetTxReceiptResponseWithoutHelper + ): transactionReceipt is RejectedTransactionReceiptResponse { + return ( + (transactionReceipt as RejectedTransactionReceiptResponse).status === + TransactionExecutionStatus.REJECTED + ); + } +} + +export type GetTransactionReceiptResponse = GetTxReceiptResponseWithoutHelper & ReceiptTx; diff --git a/www/docs/guides/interact.md b/www/docs/guides/interact.md index 11fdc02cc..691513e71 100644 --- a/www/docs/guides/interact.md +++ b/www/docs/guides/interact.md @@ -239,3 +239,39 @@ const getResponse = await myAccount.call('get_bal', specialParameters, { parseRe ``` You provide the low-level numbers expected by Starknet, without any parsing or checking. See more details [here](define_call_message.md#parse-configuration). + +## Transaction receipt response + +You can interpret the transaction receipt response to check whether it succeeded or not. + +```typescript +const result = await account.execute(myCall); +const txR = await provider.waitForTransaction(result.transaction_hash); + +console.log(txR.statusReceipt, txR.value); +console.log(txR.isSuccess(), txR.isRejected(), txR.isReverted(), txR.isError()); + +txR.match({ + success: () => { + console.log('Success'); + }, + _: () => { + console.log('Unsuccess'); + }, +}); + +txR.match({ + success: (txR: SuccessfulTransactionReceiptResponse) => { + console.log('Success =', txR); + }, + rejected: (txR: RejectedTransactionReceiptResponse) => { + console.log('Rejected =', txR); + }, + reverted: (txR: RevertedTransactionReceiptResponse) => { + console.log('Reverted =', txR); + }, + error: (err: Error) => { + console.log('An error occured =', err); + }, +}); +```