Skip to content

Commit

Permalink
apply pr suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Nov 14, 2024
1 parent fd298a1 commit fe28e81
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cairo-zero-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: kkrt-labs/ef-tests
ref: feat/update-base-fee-state
- name: Checkout local skip file
uses: actions/checkout@v4
with:
Expand Down
16 changes: 6 additions & 10 deletions cairo_zero/backend/starknet.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,15 @@ namespace Starknet {
let (block_number) = get_block_number();
let is_next_fee_ready = is_le(next_start_block_number, block_number);

let (res_current_block) = Kakarot_base_fee.read('current_block');
let current_base_fee = res_current_block[0];
let current_start_block_number = res_current_block[1];
let is_already_updated = Helpers.is_zero(
current_start_block_number - next_start_block_number
);

if (is_already_updated == FALSE and is_next_fee_ready != FALSE) {
Kakarot_base_fee.write('current_block', (next_base_fee, next_start_block_number));
if (next_start_block_number != 0 and is_next_fee_ready != FALSE) {
// update current_block storage and return next_block value
Kakarot_base_fee.write('current_block', (next_base_fee, block_number));
Kakarot_base_fee.write('next_block', (0, 0));
return (next_base_fee,);
}

return (current_base_fee,);
let (res_current_block) = Kakarot_base_fee.read('current_block');
return (res_current_block[0],);
}
}

Expand Down
16 changes: 8 additions & 8 deletions cairo_zero/tests/src/kakarot/test_kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,34 +276,34 @@ def test_get_base_fee_should_return_next_block_fee_if_applicable_and_update_curr
base_fee = cairo_run("test__get_base_fee")
assert base_fee == 2

# Should read the value from next_block
# Should update current block base fee
SyscallHandler.mock_storage.assert_any_call(
address=get_storage_var_address(
"Kakarot_base_fee", int.from_bytes(b"next_block", "big")
"Kakarot_base_fee", int.from_bytes(b"current_block", "big")
),
value=base_fee,
)
SyscallHandler.mock_storage.assert_any_call(
address=get_storage_var_address(
"Kakarot_base_fee", int.from_bytes(b"next_block", "big")
"Kakarot_base_fee", int.from_bytes(b"current_block", "big")
)
+ 1,
value=0x101,
)

# Should update current block base fee
# Should nullify the value from next_block
SyscallHandler.mock_storage.assert_any_call(
address=get_storage_var_address(
"Kakarot_base_fee", int.from_bytes(b"current_block", "big")
"Kakarot_base_fee", int.from_bytes(b"next_block", "big")
),
value=base_fee,
value=0,
)
SyscallHandler.mock_storage.assert_any_call(
address=get_storage_var_address(
"Kakarot_base_fee", int.from_bytes(b"current_block", "big")
"Kakarot_base_fee", int.from_bytes(b"next_block", "big")
)
+ 1,
value=0x101,
value=0,
)

class TestCoinbase:
Expand Down

0 comments on commit fe28e81

Please sign in to comment.