Skip to content

Commit

Permalink
set some world event fields as event keys
Browse files Browse the repository at this point in the history
  • Loading branch information
remybar committed Aug 9, 2024
1 parent 4bf4715 commit cf09955
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
16 changes: 11 additions & 5 deletions crates/dojo-core/src/tests/world.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,20 @@ fn test_register_namespace() {
let namespace = "namespace";
let hash = bytearray_hash(@namespace);

world.register_namespace(namespace);
world.register_namespace(namespace.clone());

assert(world.is_owner(hash, caller), 'namespace not registered');

assert_eq!(
starknet::testing::pop_log(world.contract_address),
Option::Some(NamespaceRegistered { namespace: "namespace", hash })
);
// I don't know why but starknet::testing::pop_log does not return the event if
// at least one field is defined as an event key.
let (mut keys, data) = starknet::testing::pop_log_raw(world.contract_address).unwrap();

// do not check keys length as it contains a ByteArray stored on several felts
assert_eq!(data.len(), 1);

let _ = keys.pop_front();
assert_eq!(Serde::<ByteArray>::deserialize(ref keys).unwrap(), namespace);
assert_eq!(data.at(0), @hash);
}

#[test]
Expand Down
22 changes: 22 additions & 0 deletions crates/dojo-core/src/world/world_contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ pub mod world {
#[derive(Drop, starknet::Event)]
pub struct WorldSpawned {
pub address: ContractAddress,
#[key]
pub creator: ContractAddress
}

Expand All @@ -172,33 +173,41 @@ pub mod world {
#[derive(Drop, starknet::Event)]
pub struct ContractDeployed {
pub salt: felt252,
#[key]
pub class_hash: ClassHash,
pub address: ContractAddress,
#[key]
pub namespace: ByteArray,
#[key]
pub name: ByteArray
}

#[derive(Drop, starknet::Event)]
pub struct ContractUpgraded {
#[key]
pub class_hash: ClassHash,
pub address: ContractAddress,
}

#[derive(Drop, starknet::Event)]
pub struct MetadataUpdate {
#[key]
pub resource: felt252,
pub uri: ByteArray
}

#[derive(Drop, starknet::Event, Debug, PartialEq)]
pub struct NamespaceRegistered {
#[key]
pub namespace: ByteArray,
pub hash: felt252
}

#[derive(Drop, starknet::Event)]
pub struct ModelRegistered {
#[key]
pub name: ByteArray,
#[key]
pub namespace: ByteArray,
pub class_hash: ClassHash,
pub prev_class_hash: ClassHash,
Expand All @@ -208,42 +217,55 @@ pub mod world {

#[derive(Drop, starknet::Event)]
pub struct StoreSetRecord {
#[key]
pub table: felt252,
#[key]
pub keys: Span<felt252>,
pub values: Span<felt252>,
}

#[derive(Drop, starknet::Event)]
pub struct StoreUpdateRecord {
#[key]
pub table: felt252,
#[key]
pub entity_id: felt252,
pub values: Span<felt252>,
}

#[derive(Drop, starknet::Event)]
pub struct StoreUpdateMember {
#[key]
pub table: felt252,
#[key]
pub entity_id: felt252,
#[key]
pub member_selector: felt252,
pub values: Span<felt252>,
}

#[derive(Drop, starknet::Event)]
pub struct StoreDelRecord {
#[key]
pub table: felt252,
#[key]
pub entity_id: felt252,
}

#[derive(Drop, starknet::Event)]
pub struct WriterUpdated {
#[key]
pub resource: felt252,
#[key]
pub contract: ContractAddress,
pub value: bool
}

#[derive(Drop, starknet::Event)]
pub struct OwnerUpdated {
#[key]
pub address: ContractAddress,
#[key]
pub resource: felt252,
pub value: bool,
}
Expand Down

0 comments on commit cf09955

Please sign in to comment.