Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
tests: add test with dojo init flow
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Oct 11, 2024
1 parent 9c2f8ba commit cdd9540
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion examples/dojo_simple/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub mod models {

pub mod events {
use starknet::ContractAddress;

#[derive(Drop, Serde)]
#[dojo::event]
pub struct PositionUpdated {
Expand Down Expand Up @@ -57,6 +57,11 @@ pub mod actions {
pub a: u8,
}

fn dojo_init(world: @IWorldDispatcher, id: u32, a: u8) {
let m = ModelInContract { id, a };
m.set(world);
}

#[abi(embed_v0)]
impl ActionsImpl of IActions<ContractState> {
fn spawn(ref world: IWorldDispatcher) {
Expand All @@ -78,8 +83,25 @@ pub mod sn_actions {

#[cfg(test)]
mod tests {
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
#[test]
fn test_spawn_world_full() {
let _world = spawn_test_world!();
}

#[test]
fn test_dojo_init_flow() {
let world = spawn_test_world!();

let actions_addr = world
.register_contract('salt1', super::actions::TEST_CLASS_HASH.try_into().unwrap());

world.grant_writer(dojo::utils::bytearray_hash(@"ds"), actions_addr);

world.init_contract(selector_from_tag!("ds-actions"), [10, 20].span());

let model = super::actions::ModelInContractStore::get(world, 10);
assert_eq!(model.a, 20);
}
}

0 comments on commit cdd9540

Please sign in to comment.