Skip to content

Commit

Permalink
bugfix: use the '<namespace>__<name>' format for model contract names
Browse files Browse the repository at this point in the history
  • Loading branch information
remybar committed Sep 10, 2024
1 parent 6112180 commit f2a90cf
Show file tree
Hide file tree
Showing 81 changed files with 197 additions and 20,750 deletions.
4 changes: 2 additions & 2 deletions crates/dojo-core/src/tests/benchmarks.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use dojo::model::introspect::Introspect;
use dojo::storage::{database, storage};
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};

use dojo::tests::helpers::{Foo, Sword, Case, CaseStore, case, Character, Abilities, Stats, Weapon};
use dojo::tests::helpers::{Foo, Sword, Case, CaseStore, dojo__case, Character, Abilities, Stats, Weapon};
use dojo::utils::test::{spawn_test_world, GasCounterTrait};

#[derive(Drop, Serde)]
Expand Down Expand Up @@ -47,7 +47,7 @@ fn deploy_world() -> IWorldDispatcher {
spawn_test_world(
["dojo"].span(),
[
case::TEST_CLASS_HASH, case_not_packed::TEST_CLASS_HASH, complex_model::TEST_CLASS_HASH
dojo__case::TEST_CLASS_HASH, dojo__case_not_packed::TEST_CLASS_HASH, dojo__complex_model::TEST_CLASS_HASH
].span()
)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/dojo-core/src/tests/helpers.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct Foo {
}

#[derive(Copy, Drop, Serde)]
#[dojo::model(namespace: "another_namespace", nomapping: true)]
#[dojo::model(namespace: "bizz", nomapping: true)]
pub struct Buzz {
#[key]
pub caller: ContractAddress,
Expand Down Expand Up @@ -203,7 +203,7 @@ pub fn deploy_world() -> IWorldDispatcher {
pub fn deploy_world_and_bar() -> (IWorldDispatcher, IbarDispatcher) {
// Spawn empty world
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());

// System contract
let contract_address = deploy_with_world_address(bar::TEST_CLASS_HASH, world);
Expand Down
16 changes: 8 additions & 8 deletions crates/dojo-core/src/tests/model/model.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn test_from_values_bad_data() {
#[test]
fn test_get_and_update_entity() {
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());

let foo = Foo { k1: 1, k2: 2, v1: 3, v2: 4 };
foo.set(world);
Expand All @@ -69,7 +69,7 @@ fn test_get_and_update_entity() {
#[test]
fn test_delete_entity() {
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());

let foo = Foo { k1: 1, k2: 2, v1: 3, v2: 4 };
foo.set(world);
Expand All @@ -85,7 +85,7 @@ fn test_delete_entity() {
#[test]
fn test_get_and_set_member_from_entity() {
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());

let foo = Foo { k1: 1, k2: 2, v1: 3, v2: 4 };
foo.set(world);
Expand All @@ -107,7 +107,7 @@ fn test_get_and_set_member_from_entity() {
#[test]
fn test_get_and_set_field_name() {
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());

let foo = Foo { k1: 1, k2: 2, v1: 3, v2: 4 };
foo.set(world);
Expand All @@ -125,7 +125,7 @@ fn test_get_and_set_field_name() {
#[test]
fn test_get_and_set_from_model() {
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());

let foo = Foo { k1: 1, k2: 2, v1: 3, v2: 4 };
foo.set(world);
Expand All @@ -143,7 +143,7 @@ fn test_get_and_set_from_model() {
#[test]
fn test_delete_from_model() {
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());

let foo = Foo { k1: 1, k2: 2, v1: 3, v2: 4 };
foo.set(world);
Expand All @@ -161,7 +161,7 @@ fn test_delete_from_model() {
#[test]
fn test_get_and_set_member_from_model() {
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());

let foo = Foo { k1: 1, k2: 2, v1: 3, v2: 4 };
let keys = [foo.k1.into(), foo.k2.into()].span();
Expand All @@ -180,7 +180,7 @@ fn test_get_and_set_member_from_model() {
#[test]
fn test_get_and_set_field_name_from_model() {
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());

let foo = Foo { k1: 1, k2: 2, v1: 3, v2: 4 };
foo.set(world);
Expand Down
24 changes: 12 additions & 12 deletions crates/dojo-core/src/tests/world/acl.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use dojo::utils::{bytearray_hash, entity_id_from_keys};
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait, world};

use dojo::tests::helpers::{
deploy_world, Foo, foo, foo_setter, IFooSetterDispatcher, IFooSetterDispatcherTrait
deploy_world, Foo, dojo__foo, foo_setter, IFooSetterDispatcher, IFooSetterDispatcherTrait
};

#[test]
fn test_owner() {
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());
let foo_selector = Model::<Foo>::selector();

let alice = starknet::contract_address_const::<0xa11ce>();
Expand Down Expand Up @@ -52,7 +52,7 @@ fn test_grant_owner_not_registered_resource() {
)]
fn test_grant_owner_through_malicious_contract() {
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());
let foo_selector = Model::<Foo>::selector();

let alice = starknet::contract_address_const::<0xa11ce>();
Expand All @@ -76,7 +76,7 @@ fn test_grant_owner_through_malicious_contract() {
)]
fn test_grant_owner_fails_for_non_owner() {
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());
let foo_selector = Model::<Foo>::selector();

let alice = starknet::contract_address_const::<0xa11ce>();
Expand All @@ -97,7 +97,7 @@ fn test_grant_owner_fails_for_non_owner() {
)]
fn test_revoke_owner_through_malicious_contract() {
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());
let foo_selector = Model::<Foo>::selector();

let alice = starknet::contract_address_const::<0xa11ce>();
Expand All @@ -122,7 +122,7 @@ fn test_revoke_owner_through_malicious_contract() {
)]
fn test_revoke_owner_fails_for_non_owner() {
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());
let foo_selector = Model::<Foo>::selector();

let alice = starknet::contract_address_const::<0xa11ce>();
Expand All @@ -140,7 +140,7 @@ fn test_revoke_owner_fails_for_non_owner() {
#[available_gas(6000000)]
fn test_writer() {
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());
let foo_selector = Model::<Foo>::selector();

assert(!world.is_writer(foo_selector, 69.try_into().unwrap()), 'should not be writer');
Expand Down Expand Up @@ -169,7 +169,7 @@ fn test_writer_not_registered_resource() {
)]
fn test_grant_writer_through_malicious_contract() {
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());
let foo_selector = Model::<Foo>::selector();

let alice = starknet::contract_address_const::<0xa11ce>();
Expand All @@ -193,7 +193,7 @@ fn test_grant_writer_through_malicious_contract() {
)]
fn test_grant_writer_fails_for_non_owner() {
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());
let foo_selector = Model::<Foo>::selector();

let alice = starknet::contract_address_const::<0xa11ce>();
Expand All @@ -214,7 +214,7 @@ fn test_grant_writer_fails_for_non_owner() {
)]
fn test_revoke_writer_through_malicious_contract() {
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());
let foo_selector = Model::<Foo>::selector();

let alice = starknet::contract_address_const::<0xa11ce>();
Expand All @@ -239,7 +239,7 @@ fn test_revoke_writer_through_malicious_contract() {
)]
fn test_revoke_writer_fails_for_non_owner() {
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());
let foo_selector = Model::<Foo>::selector();

let alice = starknet::contract_address_const::<0xa11ce>();
Expand All @@ -263,7 +263,7 @@ fn test_revoke_writer_fails_for_non_owner() {
)]
fn test_not_writer_with_known_contract() {
let world = deploy_world();
world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap());
world.register_model(dojo__foo::TEST_CLASS_HASH.try_into().unwrap());

let account = starknet::contract_address_const::<0xb0b>();
world.grant_owner(bytearray_hash(@"dojo"), account);
Expand Down
Loading

0 comments on commit f2a90cf

Please sign in to comment.