Skip to content

Commit

Permalink
const values & cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Feb 5, 2025
1 parent 8702bbd commit 1801e25
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 28 deletions.
8 changes: 3 additions & 5 deletions examples/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
mod example {
use hdp_cairo::{
HDP, evm::block_receipt::{BlockReceiptTrait, BlockReceiptKey, BlockReceiptImpl},
evm::block_tx::{BlockTxTrait, BlockTxKey, BlockTxImpl}
evm::block_tx::{BlockTxTrait, BlockTxKey, BlockTxImpl},
};

use hdp_cairo::debug::{print, print_array};
use core::fmt::{Display, Formatter, Error};
use hdp_cairo::debug::print;

#[storage]
struct Storage {}
Expand Down Expand Up @@ -37,4 +35,4 @@ mod example {

print(2);
}
}
}
2 changes: 1 addition & 1 deletion hdp_cairo/src/debug.cairo
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mod printer;
pub use printer::{print, print_array};
pub use printer::{print, print_array};
8 changes: 2 additions & 6 deletions hdp_cairo/src/debug/printer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ pub fn print<T, +Display<T>, +Drop<T>>(value: T) {
}

pub fn print_array(array: Array<felt252>) {
call_contract_syscall(
DEBUG_CONTRACT_ADDRESS.try_into().unwrap(),
PRINT_ARRAY,
array.span()
)
call_contract_syscall(DEBUG_CONTRACT_ADDRESS.try_into().unwrap(), PRINT_ARRAY, array.span())
.unwrap_syscall();
}
}
4 changes: 3 additions & 1 deletion hdp_cairo/src/evm/block_receipt.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const BLOCK_RECEIPT_GET_CUMULATIVE_GAS_USED: felt252 = 1;
const BLOCK_RECEIPT_GET_BLOOM: felt252 = 2;
const BLOCK_RECEIPT_GET_LOGS: felt252 = 3;

const BLOCK_RECEIPT_LABEL: felt252 = 'block_receipt';

#[derive(Serde, Drop)]
pub struct BlockReceiptKey {
pub chain_id: felt252,
Expand Down Expand Up @@ -39,7 +41,7 @@ pub impl BlockReceiptImpl of BlockReceiptTrait {
*self.dict.segment_index,
*self.dict.offset,
key.chain_id,
'block_receipt',
BLOCK_RECEIPT_LABEL,
key.block_number,
key.transaction_index,
]
Expand Down
4 changes: 3 additions & 1 deletion hdp_cairo/src/evm/block_tx.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const BLOCK_TX_GET_TX_TYPE: felt252 = 15;
const BLOCK_TX_GET_SENDER: felt252 = 16;
const BLOCK_TX_GET_HASH: felt252 = 17;

const BLOCK_TX_LABEL: felt252 = 'block_tx';

#[derive(Serde, Drop)]
pub struct BlockTxKey {
pub chain_id: felt252,
Expand Down Expand Up @@ -109,7 +111,7 @@ pub impl BlockTxImpl of BlockTxTrait {
*self.dict.segment_index,
*self.dict.offset,
key.chain_id,
'block_tx',
BLOCK_TX_LABEL,
key.block_number,
key.transaction_index,
]
Expand Down
12 changes: 7 additions & 5 deletions src/memorizers/evm/memorizer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace EvmPackParams {
return (params=params, params_len=5);
}

const BLOCK_TX_LABEL = 'block_tx';
const BLOCK_TX_PARAMS_LEN = 4;
func block_tx(chain_id: felt, block_number: felt, index: felt) -> (
params: felt*, params_len: felt
Expand All @@ -56,22 +57,23 @@ namespace EvmPackParams {
local params: felt* = nondet %{ segments.add() %};
assert params[0] = chain_id;
assert params[1] = 'block_tx';
assert params[1] = BLOCK_TX_LABEL;
assert params[2] = block_number;
assert params[3] = index;

return (params=params, params_len=4);
}

const BLOCK_RECEIPT_LABEL = 'block_receipt';
const BLOCK_RECEIPT_PARAMS_LEN = 4;
func block_receipt(
chain_id: felt, block_number: felt, index: felt
) -> (params: felt*, params_len: felt) {
func block_receipt(chain_id: felt, block_number: felt, index: felt) -> (
params: felt*, params_len: felt
) {
alloc_locals;
local params: felt* = nondet %{ segments.add() %};
assert params[0] = chain_id;
assert params[1] = 'block_receipt';
assert params[1] = BLOCK_RECEIPT_LABEL;
assert params[2] = block_number;
assert params[3] = index;

Expand Down
4 changes: 2 additions & 2 deletions tests/src/evm/receipt_modules.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ mod receipts_get_status {
}

#[starknet::contract]
mod receipts_get_cumulative_gas_used {
mod receipts_get_and_tx_get {
use hdp_cairo::{
HDP, evm::block_receipt::{BlockReceiptTrait, BlockReceiptKey, BlockReceiptImpl},
evm::block_tx::{BlockTxTrait, BlockTxKey, BlockTxImpl}
evm::block_tx::{BlockTxTrait, BlockTxKey, BlockTxImpl},
};

#[storage]
Expand Down
2 changes: 1 addition & 1 deletion tests/src/evm/receipt_modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn test_modules_receipt_get_status() {
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_modules_receipt_get_cumulative_gas_used() {
run(serde_json::from_slice(include_bytes!(
"../../../target/dev/modules_receipts_get_cumulative_gas_used.compiled_contract_class.json"
"../../../target/dev/modules_receipts_get_and_tx_get.compiled_contract_class.json"
))
.unwrap())
.await
Expand Down
2 changes: 1 addition & 1 deletion tests/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod evm;
pub mod starknet;
pub mod utils;
pub mod utils;
2 changes: 1 addition & 1 deletion tests/src/utils.cairo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod debug;
pub mod debug;
10 changes: 6 additions & 4 deletions tests/src/utils/debug.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ mod test_debug_print {

impl PointDisplay of Display<Point> {
fn fmt(self: @Point, ref f: Formatter) -> Result<(), Error> {
let str: ByteArray = format!("PointThatIAmMakingQuiteABitLongerToEnsureWeHaveMoreFelts ({}, {})", *self.x, *self.y);
let str: ByteArray = format!(
"PointThatIAmMakingQuiteABitLongerToEnsureWeHaveMoreFelts ({}, {})",
*self.x,
*self.y,
);
f.buffer.append(@str);
Result::Ok(())
}
Expand All @@ -24,11 +28,9 @@ mod test_debug_print {
#[external(v0)]
pub fn main(ref self: ContractState, hdp: HDP) {
let p = Point { x: 1, y: 3 };

print(p);
print(1);
print_array(array![1, 2, 3]);


}
}

0 comments on commit 1801e25

Please sign in to comment.