Skip to content

Commit

Permalink
feat(log_data_indexes): Checkpoint; units break
Browse files Browse the repository at this point in the history
  • Loading branch information
akhercha committed Oct 25, 2023
1 parent 15daea3 commit 5e72d6c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
24 changes: 3 additions & 21 deletions src/event/event_utils_sandbox.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ use satoru::utils::i128::i128;
use traits::Default;
use satoru::utils::traits::ContractAddressDefault;

use satoru::utils::serializable_dict::{
SerializableFelt252Dict, SerializableFelt252DictTrait, SerializableFelt252DictSerde
};
use satoru::utils::serializable_dict::{SerializableFelt252Dict, SerializableFelt252DictTrait};

//
// NEEDED IMPLEMENTATIONS...
//
/// TODO: move those somewhere else?

impl Felt252IntoBool of Into<felt252, bool> {
#[inline(always)]
Expand Down Expand Up @@ -80,23 +79,6 @@ struct LogData {
string_items: SerializableFelt252Dict<felt252>
}

// generic ...
fn set_item<T, T, impl TDefault: Felt252DictValue<T>, impl TDrop: Drop<T>, impl TCopy: Copy<T>>(
mut dict: SerializableFelt252Dict<T>, key: felt252, value: T
) -> SerializableFelt252Dict<T> {
dict.add_single(key, value);
dict
}

fn set_array_item<
T, T, impl TDefault: Felt252DictValue<T>, impl TDrop: Drop<T>, impl TCopy: Copy<T>
>(
mut dict: SerializableFelt252Dict<T>, key: felt252, values: Array<T>
) -> SerializableFelt252Dict<T> {
dict.add_array(key, values);
dict
}

// uint
fn set_item_uint_items(
mut dict: SerializableFelt252Dict<u128>, key: felt252, value: u128
Expand Down Expand Up @@ -165,7 +147,7 @@ fn set_item_array_Felt252_items(
fn set_item_string_items(
mut dict: SerializableFelt252Dict<felt252>, key: felt252, value: felt252
) -> SerializableFelt252Dict<felt252> {
dict.add_single(key, value); // trigger CI
dict.add_single(key, value);
dict
}

Expand Down
26 changes: 24 additions & 2 deletions tests/utils/test_serializable_dict.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ use array::ArrayTrait;
use traits::Default;

// Local imports.
use satoru::utils::i128::{I128Serde, I128Default};
use satoru::utils::traits::ContractAddressDefault;
use satoru::utils::serializable_dict::{
Item, ItemTrait, SerializableFelt252Dict, SerializableFelt252DictTrait,
SerializableFelt252DictSerde
SerializableFelt252DictTraitImpl
};

// *********************************************************************************************
Expand Down Expand Up @@ -45,6 +44,29 @@ fn test_item_multiple() {
assert(item.is_single() == false, 'item shouldnt be single');
assert(item.len() == expected_len, 'incorrect len');
}

// SerializableDict tests

#[test]
fn test_serializable_dict_add_single() {
let mut dict: SerializableFelt252Dict<felt252> = SerializableFelt252Dict {
keys: array![], values: Default::default()
};

let key: felt252 = 'starknet';
let expected_value: felt252 = 'cairo';

dict.add_single(key, expected_value);

let retrieved_item: Item<felt252> = match dict.get(key) {
Option::Some(i) => i,
Option::None => panic_with_felt252('err while searching key')
};

let out_value: felt252 = match retrieved_item {
Item::Single(v) => v,
Item::Array(_) => panic_with_felt252('should not be array')
};

assert(out_value == expected_value, 'wrong value');
}

0 comments on commit 5e72d6c

Please sign in to comment.