diff --git a/crates/torii/graphql/src/tests/types-test/Scarb.toml b/crates/torii/graphql/src/tests/types-test/Scarb.toml new file mode 100644 index 0000000000..d4873655b4 --- /dev/null +++ b/crates/torii/graphql/src/tests/types-test/Scarb.toml @@ -0,0 +1,24 @@ +[package] +cairo-version = "2.1.1" +name = "types_test" +version = "0.1.0" + +[cairo] +sierra-replace-ids = true + +[dependencies] +dojo = { path = "../../../../../dojo-core" } + +[[target.dojo]] + +[tool.dojo] +initializer_class_hash = "0xbeef" + +[tool.dojo.env] +rpc_url = "http://localhost:5050/" +# Default account for katana with seed = 0 +account_address = "0x3ee9e18edc71a6df30ac3aca2e0b02a198fbce19b7480a63a0d71cbd76652e0" +private_key = "0x300001800000000300000180000000000030000000000003006001800006600" +# world_address = "0x789c94ef39aeebc7f8c4c4633030faefb8bee454e358ae53d06ced36136d7d6" +# keystore_password = "password" +# keystore_path = "../keystore.json" diff --git a/crates/torii/graphql/src/tests/types-test/src/components.cairo b/crates/torii/graphql/src/tests/types-test/src/components.cairo new file mode 100644 index 0000000000..48f4467a97 --- /dev/null +++ b/crates/torii/graphql/src/tests/types-test/src/components.cairo @@ -0,0 +1,18 @@ +use array::ArrayTrait; +use starknet::{ContractAddress, ClassHash}; + +#[derive(Component, Copy, Drop, Serde, SerdeLen)] +struct Record { + #[key] + record_id: u32, + type_u8: u8, + type_u16: u16, + type_u32: u32, + type_u64: u64, + type_u128: u128, + type_u256: u256, + type_bool: bool, + type_felt: felt252, + type_class_hash: ClassHash, + type_contract_address: ContractAddress, +} \ No newline at end of file diff --git a/crates/torii/graphql/src/tests/types-test/src/lib.cairo b/crates/torii/graphql/src/tests/types-test/src/lib.cairo new file mode 100644 index 0000000000..98d784c920 --- /dev/null +++ b/crates/torii/graphql/src/tests/types-test/src/lib.cairo @@ -0,0 +1,2 @@ +mod components; +mod systems; diff --git a/crates/torii/graphql/src/tests/types-test/src/systems.cairo b/crates/torii/graphql/src/tests/types-test/src/systems.cairo new file mode 100644 index 0000000000..3cd48ce4c2 --- /dev/null +++ b/crates/torii/graphql/src/tests/types-test/src/systems.cairo @@ -0,0 +1,43 @@ +#[system] +mod spawn { + use array::ArrayTrait; + use box::BoxTrait; + use option::OptionTrait; + use traits::{Into, TryInto}; + use starknet::class_hash::{Felt252TryIntoClassHash}; + + use dojo::world::Context; + use types_test::components::Record; + + fn execute(ctx: Context, 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 { + 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_felt: curr_felt, + type_class_hash: curr_felt.try_into().unwrap(), + type_contract_address: curr_felt.try_into().unwrap(), + } + ) + ); + }; + return (); + } +} \ No newline at end of file