Skip to content

fix(core): introduce DojoStore trait to handle some specific storage cases #3051

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

Closed
wants to merge 1 commit 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
33 changes: 17 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ rstest = "0.18.2"
rstest_reuse = "0.6.0"
salsa = "0.16.1"

scarb = { git = "https://github.com/dojoengine/scarb", rev = "b2ce4fa03bed98ca44918c390df0e190b637894d" }
scarb-metadata = { git = "https://github.com/dojoengine/scarb", rev = "b2ce4fa03bed98ca44918c390df0e190b637894d" }
scarb-ui = { git = "https://github.com/dojoengine/scarb", rev = "b2ce4fa03bed98ca44918c390df0e190b637894d" }
scarb = { git = "https://github.com/remybar/scarb", rev = "9c08b043997a743950eda2a9bb74c867e9114c9e" }
scarb-metadata = { git = "https://github.com/remybar/scarb", rev = "9c08b043997a743950eda2a9bb74c867e9114c9e" }
scarb-ui = { git = "https://github.com/remybar/scarb", rev = "9c08b043997a743950eda2a9bb74c867e9114c9e" }

semver = "1.0.5"
serde = { version = "1.0", features = [ "derive" ] }
Expand Down
67 changes: 67 additions & 0 deletions crates/benches/contracts/src/models/character.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use starknet::{ContractAddress, get_caller_address};

// TODO import all this when complex benchmarks are merged
#[derive(Introspect, Copy, Drop)]
#[dojo::model]
struct Character {
#[key]
caller: ContractAddress,
heigth: felt252,
abilities: Abilities,
stats: Stats,
weapon: Weapon,
gold: u32,
}

#[derive(Introspect, Copy, Drop)]
struct Abilities {
strength: u8,
dexterity: u8,
constitution: u8,
intelligence: u8,
wisdom: u8,
charisma: u8,
}

#[derive(Introspect, Copy, Drop)]
struct Stats {
kills: u128,
deaths: u16,
rests: u32,
hits: u64,
blocks: u32,
walked: felt252,
runned: felt252,
finished: bool,
romances: u16,
}

#[derive(Introspect, Copy, Drop, Default)]
enum Weapon {
#[default]
DualWield: (Sword, Sword),
Fists: (Sword, Sword),
}

#[derive(Introspect, Copy, Drop, Default)]
struct Sword {
swordsmith: ContractAddress,
damage: u32,
}

#[derive(Introspect, Copy, Drop)]
#[dojo::model]
struct Case {
#[key]
owner: ContractAddress,
sword: Sword,
material: felt252,
}

#[derive(Introspect, Copy, Drop)]
#[dojo::model]
struct Alias {
#[key]
player: ContractAddress,
name: felt252,
}
2 changes: 1 addition & 1 deletion crates/dojo/core-cairo-test/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version = 1

[[package]]
name = "dojo"
version = "1.4.2"
version = "1.5.0"
dependencies = [
"dojo_plugin",
]
Expand Down
3 changes: 3 additions & 0 deletions crates/dojo/core-cairo-test/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub use world::{
mod tests {
mod meta {
mod introspect;
mod layout;
}

mod event {
Expand All @@ -29,8 +30,10 @@ mod tests {

mod storage {
mod database;
mod dojo_store;
mod packing;
mod storage;
mod layout;
}

mod contract;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,9 @@ pub mod attacker_model {
unpacked_size: Self::unpacked_size(self),
}
}

fn use_legacy_storage(self: @ContractState) -> bool {
false
}
}
}
8 changes: 5 additions & 3 deletions crates/dojo/core-cairo-test/src/tests/helpers/event.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::world::{spawn_test_world, NamespaceDef, TestResource};
/// These event contracts are used to test event upgrades in tests/event.cairo.

// This event is used as a base to create the "previous" version of an event to be upgraded.
#[derive(Introspect)]
#[derive(Introspect, Serde)]
struct FooBaseEvent {
#[key]
pub caller: ContractAddress,
Expand Down Expand Up @@ -63,8 +63,9 @@ struct FooEventMemberAdded {
pub b: u128,
}

#[derive(Introspect, Copy, Drop, Serde)]
#[derive(Introspect, Copy, Drop, Serde, Default)]
enum MyEnum {
#[default]
X: u8,
}

Expand All @@ -77,8 +78,9 @@ struct FooEventMemberChanged {
pub b: u128,
}

#[derive(Introspect, Copy, Drop, Serde)]
#[derive(Introspect, Copy, Drop, Serde, Default)]
enum AnotherEnum {
#[default]
X: u8,
}

Expand Down
13 changes: 10 additions & 3 deletions crates/dojo/core-cairo-test/src/tests/helpers/helpers.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use starknet::{ContractAddress};
use dojo::world::{IWorldDispatcher, WorldStorage, WorldStorageTrait};
use dojo::model::Model;
use dojo::event::Event;
use dojo::storage::ContractAddressDefault;

use crate::world::{
spawn_test_world, NamespaceDef, TestResource, ContractDefTrait, WorldStorageTestTrait,
Expand Down Expand Up @@ -37,9 +38,10 @@ pub struct NotCopiable {
pub b: ByteArray,
}

#[derive(Drop, Serde, Debug, PartialEq, Introspect)]
#[derive(Drop, Serde, Debug, PartialEq, Introspect, Default)]
pub enum EnumOne {
One,
#[default]
Two: u32,
Three: (felt252, u32),
}
Expand Down Expand Up @@ -97,6 +99,10 @@ pub mod foo_invalid_name {
unpacked_size: Self::unpacked_size(self),
}
}

fn use_legacy_storage(self: @ContractState) -> bool {
false
}
}
}

Expand Down Expand Up @@ -129,7 +135,7 @@ pub mod test_contract_with_dojo_init_args {
}
}

#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde, Default)]
pub struct Sword {
pub swordsmith: ContractAddress,
pub damage: u32,
Expand Down Expand Up @@ -179,8 +185,9 @@ pub struct Stats {
pub romances: u16,
}

#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde, Default)]
pub enum Weapon {
#[default]
DualWield: (Sword, Sword),
Fists: (Sword, Sword),
}
Expand Down
6 changes: 4 additions & 2 deletions crates/dojo/core-cairo-test/src/tests/helpers/model.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ struct FooModelMemberAdded {
pub b: u128,
}

#[derive(Introspect, Copy, Drop, Serde)]
#[derive(Introspect, Copy, Drop, Serde, Default)]
enum MyEnum {
#[default]
X: u8,
}

Expand All @@ -69,8 +70,9 @@ struct FooModelMemberChanged {
pub b: u128,
}

#[derive(Introspect, Copy, Drop, Serde)]
#[derive(Introspect, Copy, Drop, Serde, Default)]
enum AnotherEnum {
#[default]
X: u8,
}

Expand Down
Loading
Loading