Skip to content

Commit

Permalink
refactor: allow to send code when init context
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieuauger committed Nov 29, 2022
1 parent 8927be7 commit d58331b
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 50 deletions.
44 changes: 33 additions & 11 deletions tests/cairo_files/instructions/test_arithmetic_operations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ func test__exec_add__should_add_0_and_1{
}() {
// Given
alloc_locals;
let (bytecode) = alloc();
let stack: model.Stack* = Stack.init();

let stack: model.Stack* = Stack.push(stack, Uint256(1, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(2, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(3, 0));
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(stack);
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(0, bytecode, stack);

// When
let result = ArithmeticOperations.exec_add(ctx);
Expand All @@ -47,11 +49,13 @@ func test__exec_mul__should_mul_0_and_1{
}() {
// Given
alloc_locals;
let (bytecode) = alloc();
let stack: model.Stack* = Stack.init();

let stack: model.Stack* = Stack.push(stack, Uint256(1, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(2, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(3, 0));
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(stack);
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(0, bytecode, stack);

// When
let result = ArithmeticOperations.exec_mul(ctx);
Expand All @@ -73,11 +77,13 @@ func test__exec_sub__should_sub_0_and_1{
}() {
// Given
alloc_locals;
let (bytecode) = alloc();
let stack: model.Stack* = Stack.init();

let stack: model.Stack* = Stack.push(stack, Uint256(1, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(2, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(3, 0));
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(stack);
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(0, bytecode, stack);

// When
let result = ArithmeticOperations.exec_sub(ctx);
Expand All @@ -99,11 +105,13 @@ func test__exec_div__should_div_0_and_1{
}() {
// Given
alloc_locals;
let (bytecode) = alloc();
let stack: model.Stack* = Stack.init();

let stack: model.Stack* = Stack.push(stack, Uint256(1, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(2, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(3, 0));
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(stack);
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(0, bytecode, stack);

// When
let result = ArithmeticOperations.exec_div(ctx);
Expand All @@ -125,11 +133,13 @@ func test__exec_sdiv__should_signed_div_0_and_1{
}() {
// Given
alloc_locals;
let (bytecode) = alloc();
let stack: model.Stack* = Stack.init();

let stack: model.Stack* = Stack.push(stack, Uint256(1, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(2, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(3, 0));
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(stack);
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(0, bytecode, stack);

// When
let result = ArithmeticOperations.exec_sdiv(ctx);
Expand All @@ -151,11 +161,13 @@ func test__exec_mod__should_mod_0_and_1{
}() {
// Given
alloc_locals;
let (bytecode) = alloc();
let stack: model.Stack* = Stack.init();

let stack: model.Stack* = Stack.push(stack, Uint256(1, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(2, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(3, 0));
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(stack);
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(0, bytecode, stack);

// When
let result = ArithmeticOperations.exec_mod(ctx);
Expand All @@ -177,11 +189,13 @@ func test__exec_smod__should_smod_0_and_1{
}() {
// Given
alloc_locals;
let (bytecode) = alloc();
let stack: model.Stack* = Stack.init();

let stack: model.Stack* = Stack.push(stack, Uint256(1, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(2, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(3, 0));
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(stack);
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(0, bytecode, stack);

// When
let result = ArithmeticOperations.exec_smod(ctx);
Expand All @@ -203,11 +217,13 @@ func test__exec_addmod__should_add_0_and_1_and_div_rem_by_2{
}() {
// Given
alloc_locals;
let (bytecode) = alloc();
let stack: model.Stack* = Stack.init();

let stack: model.Stack* = Stack.push(stack, Uint256(2, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(2, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(3, 0));
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(stack);
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(0, bytecode, stack);

// When
let result = ArithmeticOperations.exec_addmod(ctx);
Expand All @@ -227,11 +243,13 @@ func test__exec_mulmod__should_mul_0_and_1_and_div_rem_by_2{
}() {
// Given
alloc_locals;
let (bytecode) = alloc();
let stack: model.Stack* = Stack.init();

let stack: model.Stack* = Stack.push(stack, Uint256(2, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(2, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(3, 0));
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(stack);
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(0, bytecode, stack);

// When
let result = ArithmeticOperations.exec_mulmod(ctx);
Expand All @@ -251,11 +269,13 @@ func test__exec_exp__should_exp_0_and_1{
}() {
// Given
alloc_locals;
let (bytecode) = alloc();
let stack: model.Stack* = Stack.init();

let stack: model.Stack* = Stack.push(stack, Uint256(1, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(2, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(3, 0));
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(stack);
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(0, bytecode, stack);

// When
let result = ArithmeticOperations.exec_exp(ctx);
Expand All @@ -277,11 +297,13 @@ func test__exec_signextend__should_signextend_0_and_1{
}() {
// Given
alloc_locals;
let (bytecode) = alloc();
let stack: model.Stack* = Stack.init();

let stack: model.Stack* = Stack.push(stack, Uint256(1, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(2, 0));
let stack: model.Stack* = Stack.push(stack, Uint256(3, 0));
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(stack);
let ctx: model.ExecutionContext* = TestHelpers.init_context_with_stack(0, bytecode, stack);

// When
let result = ArithmeticOperations.exec_signextend(ctx);
Expand Down
21 changes: 14 additions & 7 deletions tests/cairo_files/instructions/test_block_information.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ func test__chainId__should_push_chain_id_to_stack{
}() {
// Given
alloc_locals;
let ctx: model.ExecutionContext* = TestHelpers.init_context();
let (bytecode) = alloc();
let ctx: model.ExecutionContext* = TestHelpers.init_context(0, bytecode);

// When
let result = BlockInformation.exec_chainid(ctx);
Expand All @@ -43,7 +44,8 @@ func test__coinbase_should_push_coinbase_address_to_stack{
}() {
// Given
alloc_locals;
let ctx: model.ExecutionContext* = TestHelpers.init_context();
let (bytecode) = alloc();
let ctx: model.ExecutionContext* = TestHelpers.init_context(0, bytecode);

// When
let result = BlockInformation.exec_coinbase(ctx);
Expand All @@ -64,7 +66,8 @@ func test__timestamp_should_push_block_timestamp_to_stack{
}() {
// Given
alloc_locals;
let ctx: model.ExecutionContext* = TestHelpers.init_context();
let (bytecode) = alloc();
let ctx: model.ExecutionContext* = TestHelpers.init_context(0, bytecode);

// When
let result = BlockInformation.exec_timestamp(ctx);
Expand All @@ -86,7 +89,8 @@ func test__number_should_push_block_number_to_stack{
}() {
// Given
alloc_locals;
let ctx: model.ExecutionContext* = TestHelpers.init_context();
let (bytecode) = alloc();
let ctx: model.ExecutionContext* = TestHelpers.init_context(0, bytecode);

// When
let result = BlockInformation.exec_number(ctx);
Expand All @@ -108,7 +112,8 @@ func test__gaslimit_should_push_gaslimit_to_stack{
}() {
// Given
alloc_locals;
let ctx: model.ExecutionContext* = TestHelpers.init_context();
let (bytecode) = alloc();
let ctx: model.ExecutionContext* = TestHelpers.init_context(0, bytecode);

// When
let result = BlockInformation.exec_gaslimit(ctx);
Expand All @@ -129,7 +134,8 @@ func test__difficulty_should_push_difficulty_to_stack{
}() {
// Given
alloc_locals;
let ctx: model.ExecutionContext* = TestHelpers.init_context();
let (bytecode) = alloc();
let ctx: model.ExecutionContext* = TestHelpers.init_context(0, bytecode);

// When
let result = BlockInformation.exec_difficulty(ctx);
Expand All @@ -150,7 +156,8 @@ func test__basefee_should_push_basefee_to_stack{
}() {
// Given
alloc_locals;
let ctx: model.ExecutionContext* = TestHelpers.init_context();
let (bytecode) = alloc();
let ctx: model.ExecutionContext* = TestHelpers.init_context(0, bytecode);

// When
let result = BlockInformation.exec_basefee(ctx);
Expand Down
Loading

0 comments on commit d58331b

Please sign in to comment.