-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
61 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
mod components; | ||
mod models; | ||
mod systems; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 42 additions & 30 deletions
72
crates/torii/graphql/src/tests/types-test/src/systems.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,55 @@ | ||
#[system] | ||
mod spawn { | ||
use array::ArrayTrait; | ||
use box::BoxTrait; | ||
use option::OptionTrait; | ||
use traits::{Into, TryInto}; | ||
use starknet::class_hash::{Felt252TryIntoClassHash}; | ||
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; | ||
use starknet::{ContractAddress, ClassHash}; | ||
use types_test::models::{Record, Nested, NestedMore}; | ||
|
||
#[starknet::interface] | ||
trait IRecords<TContractState> { | ||
fn create(self: @TContractState, world: IWorldDispatcher, num_records: u8); | ||
} | ||
|
||
use dojo::world::Context; | ||
use types_test::components::Record; | ||
#[system] | ||
mod records { | ||
use types_test::models::{Record, Nested, NestedMore}; | ||
use super::IRecords; | ||
|
||
fn execute(ctx: Context, num_records: u8) { | ||
let mut curr_record = 0; | ||
loop { | ||
if curr_record == num_records { | ||
break(); | ||
} | ||
curr_record = curr_record + 1; | ||
#[external(v0)] | ||
impl RecordsImpl of IRecords<ContractState> { | ||
fn create(self: @ContractState, world: IWorldDispatcher, num_records: u8) { | ||
let mut curr_record = 0; | ||
loop { | ||
if curr_record == num_records { | ||
break (); | ||
} | ||
curr_record = curr_record + 1; | ||
|
||
let record_id = ctx.world.uuid(); | ||
let curr_felt: felt252 = curr_record.into(); | ||
set !( | ||
ctx.world, | ||
( | ||
Record { | ||
let record_id = world.uuid(); | ||
let curr_felt: felt252 = curr_record.into(); | ||
set!( | ||
world, | ||
(Record { | ||
record_id, | ||
type_u8: curr_record.into(), | ||
type_u16: curr_record.into(), | ||
type_u32: curr_record.into(), | ||
type_u64: curr_record.into(), | ||
type_u128: curr_record.into(), | ||
type_u256: curr_record.into(), | ||
type_bool: if curr_record % 2 == 0 { true } else { false }, | ||
//type_u256: curr_record.into(), | ||
type_bool: if curr_record % 2 == 0 { | ||
true | ||
} else { | ||
false | ||
}, | ||
type_felt: curr_felt, | ||
type_class_hash: curr_felt.try_into().unwrap(), | ||
type_contract_address: curr_felt.try_into().unwrap(), | ||
} | ||
) | ||
); | ||
}; | ||
return (); | ||
type_nested: Nested { | ||
record_id | ||
//type_more_nested: NestedMore { record_id } | ||
} | ||
}) | ||
); | ||
}; | ||
return (); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters