Skip to content

Commit

Permalink
Merge branch '9-implementation-of-the-where-api' of github.com:dojoen…
Browse files Browse the repository at this point in the history
…gine/dojo into 9-implementation-of-the-where-api
  • Loading branch information
matzayonc committed Nov 30, 2023
2 parents 901c6d6 + b9fa2bf commit 6069856
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 48 deletions.
7 changes: 7 additions & 0 deletions crates/dojo-core/src/database.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ fn set_with_index(
index::create(0, index, key, *members.at(idx)); // create a record for each of the indexes
idx += 1;
};
}

fn del(model: felt252, key: felt252) {
index::delete(0, model, key);

let len_keys = array!['dojo_storage_keys_len', model, key].span();
let len = storage::get(0, len_keys);

let mut idx = 0; // Iterating over all members of the model...
loop {
Expand Down
46 changes: 1 addition & 45 deletions crates/dojo-core/src/world_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use debug::PrintTrait;

use dojo::benchmarks;
use dojo::executor::executor;
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait, world, IUpgradeableWorld, IUpgradeableWorldDispatcher, IUpgradeableWorldDispatcherTrait };
use dojo::database::introspect::Introspect;
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait, world};
use dojo::database::{Clause, MemberClause};
use dojo::test_utils::{spawn_test_world, deploy_with_world_address};
use dojo::benchmarks::{Character, end};
Expand Down Expand Up @@ -291,50 +291,6 @@ fn test_entities() {
// assert(*(*values.at(0)).at(0) == 0x420, 'Caller at 1 not valid');
}

#[test]
#[available_gas(60000000)]
fn test_entities() {
// Deploy world contract
let world = spawn_test_world(array![fizz::TEST_CLASS_HASH],);

let bar_contract = IbarDispatcher {
contract_address: deploy_with_world_address(bar::TEST_CLASS_HASH, world)
};

let alice = starknet::contract_address_const::<0x1337>();
starknet::testing::set_contract_address(alice);
bar_contract.set_fizz(1337, 1337);
bar_contract.set_fizz(7331, 7331);
let bob = starknet::contract_address_const::<0x420>();
starknet::testing::set_contract_address(bob);
bar_contract.set_fizz(1337, 420);

let layout = array![251].span();

// Get all in the index
let values = world.entities(Clause::All('Fizz'), 1, layout);
// assert(keys.len() == 3, 'Not all found for any!');
// assert(values.len() == 3, 'Number of values does not match');
// assert(*(*values.at(0)).at(0) == 0x1337, 'Caller at 0 not valid');
// assert(*(*values.at(1)).at(0) == 0x1337, 'Caller at 1 not valid');
// assert(*(*values.at(2)).at(0) == 0x420, 'Caller at 2 not valid');

let mut where = MemberClause { model: 'Fizz', member: 0, value: 1337, };

// Get all with a == 1337
let values = world.entities(Clause::Member(where), 1, layout);
// assert(keys.len() == 2, 'Not all keys found for 1337!');
// assert(*(*values.at(0)).at(0) == 0x1337, 'Caller at 0 not valid');
// assert(*(*values.at(1)).at(0) == 0x420, 'Caller at 1 not valid');

// Get all with b == 420
where.member = 1;
where.value = 420;
let values = world.entities(Clause::Member(where), 1, layout);
// assert(keys.len() == 1, 'Not all keys found for 420!');
// assert(*(*values.at(0)).at(0) == 0x420, 'Caller at 1 not valid');
}

#[test]
#[available_gas(60000000)]
fn test_metadata_uri() {
Expand Down
20 changes: 20 additions & 0 deletions crates/dojo-erc/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "dojo"
version = "0.3.2"
dependencies = [
"dojo_plugin",
]

[[package]]
name = "dojo_erc"
version = "0.3.2"
dependencies = [
"dojo",
]

[[package]]
name = "dojo_plugin"
version = "0.3.2"
20 changes: 20 additions & 0 deletions crates/dojo-primitives/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "dojo"
version = "0.3.2"
dependencies = [
"dojo_plugin",
]

[[package]]
name = "dojo_plugin"
version = "0.3.2"

[[package]]
name = "dojo_primitives"
version = "0.3.2"
dependencies = [
"dojo",
]
6 changes: 3 additions & 3 deletions crates/torii/graphql/src/tests/types-test/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ version = 1

[[package]]
name = "dojo"
version = "0.3.13"
version = "0.3.12"
dependencies = [
"dojo_plugin",
]

[[package]]
name = "dojo_plugin"
version = "0.3.11"
source = "git+https://github.com/dojoengine/dojo?tag=v0.3.11#1e651b5d4d3b79b14a7d8aa29a92062fcb9e6659"
version = "0.3.12"
source = "git+https://github.com/dojoengine/dojo?tag=v0.3.12#12d58f29ec53454317f1f6d265007a053d279288"

[[package]]
name = "types_test"
Expand Down

0 comments on commit 6069856

Please sign in to comment.