Skip to content

Commit

Permalink
fix(dojo-lang): ensure the dns returns the actual ClassHash. (#2935)
Browse files Browse the repository at this point in the history
* fix: ensure the DNS returns the actual class hash

* tests: regenerate test db
  • Loading branch information
glihm authored Jan 20, 2025
1 parent 0e6e207 commit fbb972b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
20 changes: 19 additions & 1 deletion crates/dojo/core-cairo-test/src/tests/world/world.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use dojo::model::ModelStorage;
use dojo::event::{Event, EventStorage};

use crate::tests::helpers::{
IbarDispatcherTrait, drop_all_events, deploy_world_and_bar, Foo, m_Foo, test_contract,
bar, IbarDispatcherTrait, drop_all_events, deploy_world_and_bar, Foo, m_Foo, test_contract,
test_contract_with_dojo_init_args, SimpleEvent, e_SimpleEvent, deploy_world,
};
use crate::{spawn_test_world, ContractDefTrait, NamespaceDef, TestResource, WorldStorageTestTrait};
Expand Down Expand Up @@ -311,3 +311,21 @@ fn test_can_call_init_only_world_args() {
},
}
}

#[test]
pub fn dns_valid_class_hash() {
let namespace_def = NamespaceDef {
namespace: "dojo",
resources: [
TestResource::Model(m_Foo::TEST_CLASS_HASH),
TestResource::Contract(bar::TEST_CLASS_HASH),
]
.span(),
};

let mut world = spawn_test_world([namespace_def].span());
world.sync_perms_and_inits([].span());

let (_, class_hash) = world.dns(@"bar").unwrap();
assert!(class_hash == bar::TEST_CLASS_HASH.try_into().unwrap());
}
8 changes: 6 additions & 2 deletions crates/dojo/core/src/world/storage.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ pub impl WorldStorageInternalImpl of WorldStorageTrait {
dojo::utils::selector_from_namespace_and_name(*self.namespace_hash, contract_name),
) {
Resource::Contract((
contract_address, class_hash,
)) => Option::Some((contract_address, class_hash.try_into().unwrap())),
contract_address, _,
)) => {
let class_hash = starknet::syscalls::get_class_hash_at_syscall(contract_address)
.expect('Failed to get class hash');
Option::Some((contract_address, class_hash))
},
_ => Option::None,
}
}
Expand Down
Binary file modified spawn-and-move-db.tar.gz
Binary file not shown.
Binary file modified types-test-db.tar.gz
Binary file not shown.

0 comments on commit fbb972b

Please sign in to comment.