Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(lang): update convention for keys and values naming #2660

Merged
merged 9 commits into from
Nov 8, 2024
18 changes: 9 additions & 9 deletions crates/dojo/core-cairo-test/src/tests/model/model.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ fn test_values() {
let mvalues = FooValue { v1: 3, v2: 4 };
let expected_values = [3, 4].span();

let values = mvalues.values();
let values = mvalues.serialized_values();
assert!(expected_values == values);
}

#[test]
fn test_from_values() {
let mut values = [3, 4].span();

let model_values: Option<FooValue> = ModelValue::<FooValue>::from_values(1, ref values);
let model_values: Option<FooValue> = ModelValue::<FooValue>::from_serialized(1, ref values);
assert!(model_values.is_some());
let model_values = model_values.unwrap();
assert!(model_values.v1 == 3 && model_values.v2 == 4);
Expand All @@ -71,7 +71,7 @@ fn test_from_values() {
#[test]
fn test_from_values_bad_data() {
let mut values = [3].span();
let res: Option<FooValue> = ModelValue::<FooValue>::from_values(1, ref values);
let res: Option<FooValue> = ModelValue::<FooValue>::from_serialized(1, ref values);
assert!(res.is_none());
}

Expand All @@ -83,7 +83,7 @@ fn test_read_and_update_model_value() {
world.write_model(@foo);

let entity_id = foo.entity_id();
let mut model_value: FooValue = world.read_value(foo.key());
let mut model_value: FooValue = world.read_value(foo.keys());
assert_eq!(model_value.v1, foo.v1);
assert_eq!(model_value.v2, foo.v2);

Expand All @@ -92,7 +92,7 @@ fn test_read_and_update_model_value() {

world.write_value_from_id(entity_id, @model_value);

let read_values: FooValue = world.read_value(foo.key());
let read_values: FooValue = world.read_value(foo.keys());
assert!(read_values.v1 == model_value.v1 && read_values.v2 == model_value.v2);
}

Expand Down Expand Up @@ -153,20 +153,20 @@ fn test_delete_from_model() {
}

#[test]
fn test_model_ptr_from_key() {
fn test_model_ptr_from_keys() {
let mut world = spawn_foo_world();
let foo = Foo { k1: 1, k2: 2, v1: 3, v2: 4 };
let ptr = Model::<Foo>::ptr_from_key(foo.key());
let ptr = Model::<Foo>::ptr_from_keys(foo.keys());
world.write_model(@foo);
let v1 = world.read_member(ptr, selector!("v1"));
assert!(foo.v1 == v1);
}

#[test]
fn test_model_ptr_from_keys() {
fn test_model_ptr_from_serialized_keys() {
let mut world = spawn_foo_world();
let foo = Foo { k1: 1, k2: 2, v1: 3, v2: 4 };
let ptr = Model::<Foo>::ptr_from_keys(foo.keys());
let ptr = Model::<Foo>::ptr_from_serialized_keys(foo.serialized_keys());
world.write_model(@foo);
let v1 = world.read_member(ptr, selector!("v1"));
assert!(foo.v1 == v1);
Expand Down
7 changes: 5 additions & 2 deletions crates/dojo/core-cairo-test/src/tests/utils/key.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use dojo::utils::{entity_id_from_keys, combine_key};
use dojo::utils::{entity_id_from_serialized_keys, combine_key};

#[test]
fn test_entity_id_from_keys() {
let keys = [1, 2, 3].span();
assert(entity_id_from_keys(keys) == core::poseidon::poseidon_hash_span(keys), 'bad entity ID');
assert(
entity_id_from_serialized_keys(keys) == core::poseidon::poseidon_hash_span(keys),
'bad entity ID'
);
}

#[test]
Expand Down
Loading
Loading