From cf09955fcf6055cd74936a1126406b02c1bb8a94 Mon Sep 17 00:00:00 2001 From: "remy.baranx@gmail.com" Date: Fri, 9 Aug 2024 16:11:14 +0200 Subject: [PATCH] set some world event fields as event keys --- crates/dojo-core/src/tests/world.cairo | 16 +++++++++----- .../dojo-core/src/world/world_contract.cairo | 22 +++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/crates/dojo-core/src/tests/world.cairo b/crates/dojo-core/src/tests/world.cairo index be4dcb6ff5..35172ea83f 100644 --- a/crates/dojo-core/src/tests/world.cairo +++ b/crates/dojo-core/src/tests/world.cairo @@ -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::::deserialize(ref keys).unwrap(), namespace); + assert_eq!(data.at(0), @hash); } #[test] diff --git a/crates/dojo-core/src/world/world_contract.cairo b/crates/dojo-core/src/world/world_contract.cairo index a84d4e7754..0a65553fce 100644 --- a/crates/dojo-core/src/world/world_contract.cairo +++ b/crates/dojo-core/src/world/world_contract.cairo @@ -161,6 +161,7 @@ pub mod world { #[derive(Drop, starknet::Event)] pub struct WorldSpawned { pub address: ContractAddress, + #[key] pub creator: ContractAddress } @@ -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, @@ -208,42 +217,55 @@ pub mod world { #[derive(Drop, starknet::Event)] pub struct StoreSetRecord { + #[key] pub table: felt252, + #[key] pub keys: Span, pub values: Span, } #[derive(Drop, starknet::Event)] pub struct StoreUpdateRecord { + #[key] pub table: felt252, + #[key] pub entity_id: felt252, pub values: Span, } #[derive(Drop, starknet::Event)] pub struct StoreUpdateMember { + #[key] pub table: felt252, + #[key] pub entity_id: felt252, + #[key] pub member_selector: felt252, pub values: Span, } #[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, }