Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

Commit

Permalink
🎨 Remove duplicated test code
Browse files Browse the repository at this point in the history
  • Loading branch information
0xlny authored and AbdelStark committed Oct 17, 2022
1 parent 15705ec commit 9a34d8c
Showing 1 changed file with 25 additions and 43 deletions.
68 changes: 25 additions & 43 deletions tests/units/kakarot/test_basic.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -47,59 +47,41 @@ func test_arithmetic_operations{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*,
return ();
}

@external
func test_comparison_operations{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() {
alloc_locals;

print_banner();

// Prepare Kakarot instance
let (local context) = prepare();

// Load test case for LT
let (evm_test_case: EVMTestCase) = test_utils.load_evm_test_case_from_file(
'./tests/cases/003_lt.json'
);

// Run EVM execution
let ctx: model.ExecutionContext* = Kakarot.execute(evm_test_case.code, evm_test_case.calldata);

// Assert value on the top of the stack
test_utils.assert_top_stack(ctx, 0);

// Load test case for GT
let (evm_test_case: EVMTestCase) = test_utils.load_evm_test_case_from_file(
'./tests/cases/003_gt.json'
);
func _assert_comparison_operation{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
filename: felt, assert_result: felt
) {
// Load test case
let (evm_test_case: EVMTestCase) = test_utils.load_evm_test_case_from_file(filename);

// Run EVM execution
let ctx: model.ExecutionContext* = Kakarot.execute(evm_test_case.code, evm_test_case.calldata);

// Assert value on the top of the stack
test_utils.assert_top_stack(ctx, 1);
test_utils.assert_top_stack(ctx, assert_result);

// Load test case for SLT
let (evm_test_case: EVMTestCase) = test_utils.load_evm_test_case_from_file(
'./tests/cases/003_slt.json'
);

// Run EVM execution
let ctx: model.ExecutionContext* = Kakarot.execute(evm_test_case.code, evm_test_case.calldata);

// Assert value on the top of the stack
test_utils.assert_top_stack(ctx, 1);
return ();
}

// Load test case for SGT
let (evm_test_case: EVMTestCase) = test_utils.load_evm_test_case_from_file(
'./tests/cases/003_sgt.json'
);
@external
func test_comparison_operations{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() {
alloc_locals;

// Run EVM execution
let ctx: model.ExecutionContext* = Kakarot.execute(evm_test_case.code, evm_test_case.calldata);
print_banner();

// Assert value on the top of the stack
test_utils.assert_top_stack(ctx, 0);
// Prepare Kakarot instance
let (local context) = prepare();

// Test for LT
_assert_comparison_operation('./tests/cases/003_lt.json', 0);

// Test for GT
_assert_comparison_operation('./tests/cases/003_gt.json', 1);

// Test for SLT
_assert_comparison_operation('./tests/cases/003_slt.json', 1);

// Test for SGT
_assert_comparison_operation('./tests/cases/003_sgt.json', 0);

return ();
}
Expand Down

0 comments on commit 9a34d8c

Please sign in to comment.