Skip to content

Commit

Permalink
fix(dojo-core): fix tests and compilation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Feb 7, 2024
1 parent 189002e commit 889831e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
12 changes: 6 additions & 6 deletions crates/dojo-core/src/benchmarks.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn bench_native_storage() {

let gas = testing::get_available_gas();
gas::withdraw_gas().unwrap();
starknet::storage_write_syscall(0, address, 42);
starknet::storage_write_syscall(0, address, 42).unwrap_syscall();
end(gas, 'native write');

let gas = testing::get_available_gas();
Expand All @@ -97,7 +97,7 @@ fn bench_native_storage_offset() {

let gas = testing::get_available_gas();
gas::withdraw_gas().unwrap();
starknet::storage_write_syscall(0, address, 42);
starknet::storage_write_syscall(0, address, 42).unwrap_syscall();
end(gas, 'native writ of');

let gas = testing::get_available_gas();
Expand Down Expand Up @@ -228,7 +228,7 @@ fn bench_database_array() {

let gas = testing::get_available_gas();
gas::withdraw_gas().unwrap();
let second_res = database::get('table', 'key', 3, 8, array![251, 251, 251, 251, 251].span());
let second_res = database::get('table', 'key', 3, 8, half_layout);
end(gas, 'db get half arr');

assert(second_res.len() == 5, 'wrong number of values');
Expand All @@ -254,7 +254,7 @@ fn bench_indexed_database_array() {

let gas = testing::get_available_gas();
gas::withdraw_gas().unwrap();
let (keys, values) = database::scan('table', Option::None(()), 2, layout);
let (_keys, _values) = database::scan('table', Option::None(()), 2, layout);
end(gas, 'dbi scan arr 1');

let gas = testing::get_available_gas();
Expand Down Expand Up @@ -410,7 +410,7 @@ fn bench_nested_struct() {
material: 'wooden',
};
end(gas, 'case init');
let gas = testing::get_available_gas();
let _gas = testing::get_available_gas();
gas::withdraw_gas().unwrap();


Expand Down Expand Up @@ -566,4 +566,4 @@ fn bench_complex_struct() {
gas::withdraw_gas().unwrap();
database::get('chars', '42', 0, char.packed_size(), char.layout());
end(gas, 'chars db get');
}
}
2 changes: 1 addition & 1 deletion crates/dojo-core/src/database/introspect_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ struct Generic<T> {
#[test]
#[available_gas(2000000)]
fn test_generic_introspect() {
let generic = Generic { value: Base { value: 123 } };
let _generic = Generic { value: Base { value: 123 } };
}
3 changes: 1 addition & 2 deletions crates/dojo-core/src/database/utils_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ fn test_find_matching() {
fn test_find_matching_wrong_arg_len() {
let mut ids1: Array<felt252> = ArrayTrait::new();
let mut ids2: Array<felt252> = ArrayTrait::new();
let mut ids3: Array<felt252> = ArrayTrait::new();

ids1.append(1);
ids1.append(3);
Expand Down Expand Up @@ -141,5 +140,5 @@ fn test_find_matching_wrong_arg_len() {
entities.append(e2.span());
entities.append(e3.span());

let matching = find_matching(ids.span(), entities.span());
let _matching = find_matching(ids.span(), entities.span());
}
11 changes: 8 additions & 3 deletions crates/dojo-core/src/executor_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ struct Foo {
b: u128,
}

#[starknet::interface]
trait IBar<T> {
fn dojo_resource(self: @T) -> felt252;
fn execute(self: @T, foo: Foo) -> Foo;
}

#[starknet::contract]
mod bar {
use super::{Foo};
use super::{Foo, IBar};

#[storage]
struct Storage {}

#[abi(embed_v0)]
#[generate_trait]
impl IbarImpl of IBar {
impl IbarImpl of IBar<ContractState> {
fn dojo_resource(self: @ContractState) -> felt252 {
'bar'
}
Expand Down
1 change: 0 additions & 1 deletion crates/dojo-core/src/packing_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ fn test_pack_unpack_types() {
let mut packing: felt252 = 0;
let mut offset = 0;

let mut i: u8 = 0;
pack_inner(@3, 8, ref packing, ref offset, ref packed);
pack_inner(@14, 16, ref packing, ref offset, ref packed);
pack_inner(@59, 32, ref packing, ref offset, ref packed);
Expand Down
11 changes: 7 additions & 4 deletions crates/dojo-core/src/test_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ fn deploy_with_world_address(class_hash: felt252, world: IWorldDispatcher) -> Co
}

fn spawn_test_world(models: Array<felt252>) -> IWorldDispatcher {
let salt = testing::get_available_gas();

// deploy executor
let constructor_calldata = array::ArrayTrait::new();
let (executor_address, _) = deploy_syscall(
executor::TEST_CLASS_HASH.try_into().unwrap(), 0, constructor_calldata.span(), false
executor::TEST_CLASS_HASH.try_into().unwrap(), salt.into(), constructor_calldata.span(), true
)
.unwrap();
// deploy world
let (world_address, _) = deploy_syscall(
world::TEST_CLASS_HASH.try_into().unwrap(),
0,
salt.into(),
array![executor_address.into(), dojo::base::base::TEST_CLASS_HASH].span(),
false
true
)
.unwrap();
let world = IWorldDispatcher { contract_address: world_address };
Expand Down Expand Up @@ -98,6 +100,7 @@ fn end(start: u128, name: felt252) {
};

let name: felt252 = (name % GAS_OFFSET.into()).try_into().unwrap();
let used_gas = (start - gas_after - 1770).into() * GAS_OFFSET;
// Q?: What's this 1070 value that needed to be adjusted?
let used_gas = (start - gas_after - 1070).into() * GAS_OFFSET;
(used_gas + name).print();
}
6 changes: 3 additions & 3 deletions crates/dojo-core/src/world_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ fn test_entities() {

let mut query_keys = ArrayTrait::new();
let layout = array![251].span();
let (keys, values) = world.entities('Foo', Option::None, query_keys.span(), 2, layout);
let (keys, _values) = world.entities('Foo', Option::None, query_keys.span(), 2, layout);
let ids = world.entity_ids('Foo');
assert(keys.len() == ids.len(), 'result differs in entity_ids');
assert(keys.len() == 0, 'found value for unindexed');
Expand Down Expand Up @@ -410,7 +410,6 @@ fn test_set_writer_fails_for_non_owner() {
world.grant_writer(42, 69.try_into().unwrap());
}


#[test]
#[available_gas(60000000)]
fn test_execute_multiple_worlds() {
Expand All @@ -436,6 +435,7 @@ fn test_execute_multiple_worlds() {

let data1 = get!(world1, alice, Foo);
let data2 = get!(world2, alice, Foo);

assert(data1.a == 1337, 'data1 not stored');
assert(data2.a == 7331, 'data2 not stored');
}
Expand Down Expand Up @@ -563,4 +563,4 @@ fn test_upgradeable_world_from_non_owner() {
contract_address: world.contract_address
};
upgradeable_world_dispatcher.upgrade(worldupgrade::TEST_CLASS_HASH.try_into().unwrap());
}
}

0 comments on commit 889831e

Please sign in to comment.