Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(torii): types test proj #818

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions crates/torii/graphql/src/tests/types-test/Scarb.toml
Original file line number Diff line number Diff line change
@@ -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 = "0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973"
private_key = "0x1800000000300000180000000000030000000000003006001800006600"
# world_address = "0x789c94ef39aeebc7f8c4c4633030faefb8bee454e358ae53d06ced36136d7d6"
# keystore_password = "password"
# keystore_path = "../keystore.json"
2 changes: 2 additions & 0 deletions crates/torii/graphql/src/tests/types-test/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod models;
mod systems;
30 changes: 30 additions & 0 deletions crates/torii/graphql/src/tests/types-test/src/models.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use array::ArrayTrait;
use starknet::{ContractAddress, ClassHash};

#[derive(Model, Copy, Drop, Serde)]
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,
type_nested: Nested,
}

#[derive(Copy, Drop, Serde, Introspect)]
struct Nested {
record_id: u32,
//type_more_nested: Option<NestedMore>,
}

#[derive(Copy, Drop, Serde, Introspect)]
struct NestedMore {
record_id: u32,
}
55 changes: 55 additions & 0 deletions crates/torii/graphql/src/tests/types-test/src/systems.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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);
}

#[system]
mod records {
use types_test::models::{Record, Nested, NestedMore};
use super::IRecords;

#[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 = 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_felt: curr_felt,
type_class_hash: curr_felt.try_into().unwrap(),
type_contract_address: curr_felt.try_into().unwrap(),
type_nested: Nested {
record_id
//type_more_nested: NestedMore { record_id }
}
})
);
};
return ();
}
}
}
2 changes: 1 addition & 1 deletion crates/torii/migrations/20230316154230_setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ CREATE TABLE model_members(
type TEXT NOT NULL,
key BOOLEAN NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id, model_idx) FOREIGN KEY (model_id) REFERENCES models(id) UNIQUE (id, member_idx)
PRIMARY KEY (id, member_idx) FOREIGN KEY (model_id) REFERENCES models(id)
);

CREATE INDEX idx_model_members_model_id ON model_members (model_id);
Expand Down