Skip to content

fix(dojo-lang): ensure the dns returns the actual ClassHash. #2935

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

Merged
merged 2 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading