Skip to content

Commit

Permalink
feat: check models and events upgradability
Browse files Browse the repository at this point in the history
  • Loading branch information
remybar committed Nov 5, 2024
1 parent cf1d99f commit f6cff5f
Show file tree
Hide file tree
Showing 46 changed files with 1,812 additions and 877 deletions.
48 changes: 29 additions & 19 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ rpassword = "7.2.0"
rstest = "0.18.2"
rstest_reuse = "0.6.0"
salsa = "0.16.1"
scarb = { git = "/~https://github.com/dojoengine/scarb", branch = "dojo-284" }
scarb-ui = { git = "/~https://github.com/dojoengine/scarb", branch = "dojo-284" }
#scarb = { path = "/Users/glihm/swm/scarb/scarb" }
#scarb-ui = { path = "/Users/glihm/swm/scarb/utils/scarb-ui" }
scarb = { git = "/~https://github.com/remybar/scarb", branch = "upgradeable_models" }
scarb-ui = { git = "/~https://github.com/remybar/scarb", branch = "upgradeable_models" }
#scarb = { git = "/~https://github.com/dojoengine/scarb", branch = "dojo-284" }
#scarb-ui = { git = "/~https://github.com/dojoengine/scarb", branch = "dojo-284" }
semver = "1.0.5"
serde = { version = "1.0", features = [ "derive" ] }
serde_json = { version = "1.0", features = [ "arbitrary_precision" ] }
Expand Down
1 change: 0 additions & 1 deletion bin/sozo/src/commands/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ fn inspect_resource(resource_name_or_tag: &str, world_diff: &WorldDiff) {
} else {
naming::compute_bytearray_hash(resource_name_or_tag)
};

let resource_diff = world_diff.resources.get(&selector);

if resource_diff.is_none() {
Expand Down
27 changes: 24 additions & 3 deletions crates/dojo/core-cairo-test/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,35 @@ mod tests {
pub(crate) mod selector_attack;
}

mod helpers;
mod helpers {
mod helpers;
pub use helpers::{
DOJO_NSH, SimpleEvent, e_SimpleEvent, Foo, m_Foo, foo_invalid_name, foo_setter,
test_contract, test_contract_with_dojo_init_args, Sword, Case, Character, Abilities,
Stats, Weapon, Ibar, IbarDispatcher, IbarDispatcherTrait, bar, deploy_world,
deploy_world_and_bar, deploy_world_and_foo, drop_all_events, IFooSetter,
IFooSetterDispatcher, IFooSetterDispatcherTrait, NotCopiable
};

mod event;
pub use event::{
FooEventBadLayoutType, e_FooEventBadLayoutType, deploy_world_for_event_upgrades
};

mod model;
pub use model::deploy_world_for_model_upgrades;
}

mod world {
mod acl;
mod contract;
//mod entities;
//mod resources;
mod world;
mod event;
mod metadata;
mod model;
mod namespace;
mod storage;
mod world;
}

mod utils {
Expand Down
6 changes: 5 additions & 1 deletion crates/dojo/core-cairo-test/src/tests/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub trait IQuantumLeap<T> {
#[starknet::contract]
pub mod test_contract_upgrade {
use dojo::contract::IContract;
use dojo::meta::IDeployedResource;
use dojo::world::IWorldDispatcher;
use dojo::contract::components::world_provider::IWorldProvider;

Expand All @@ -58,7 +59,10 @@ pub mod test_contract_upgrade {
}

#[abi(embed_v0)]
pub impl ContractImpl of IContract<ContractState> {
pub impl ContractImpl of IContract<ContractState> {}

#[abi(embed_v0)]
pub impl Contract_DeployedContractImpl of IDeployedResource<ContractState> {
fn dojo_name(self: @ContractState) -> ByteArray {
"test_contract"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,18 @@
#[starknet::contract]
pub mod attacker_contract {
use dojo::world::IWorldDispatcher;
use dojo::contract::components::world_provider::IWorldProvider;
use dojo::contract::IContract;
use starknet::storage::StoragePointerReadAccess;

#[storage]
struct Storage {
world_dispatcher: IWorldDispatcher,
}

#[abi(embed_v0)]
pub impl ContractImpl of IContract<ContractState> {
pub impl DojoDeployedModelImpl of dojo::meta::IDeployedResource<ContractState> {
fn dojo_name(self: @ContractState) -> ByteArray {
"test_1"
}
}

#[abi(embed_v0)]
impl WorldProviderImpl of IWorldProvider<ContractState> {
fn world_dispatcher(self: @ContractState) -> IWorldDispatcher {
self.world_dispatcher.read()
}
}
}

#[starknet::contract]
Expand All @@ -34,15 +24,25 @@ pub mod attacker_model {
struct Storage {}

#[abi(embed_v0)]
impl DojoModelImpl of dojo::model::IModel<ContractState> {
impl DojoDeployedModelImpl of dojo::meta::IDeployedResource<ContractState> {
fn dojo_name(self: @ContractState) -> ByteArray {
"foo"
}
}

#[abi(embed_v0)]
impl DojoStoredModelImpl of dojo::meta::interface::IStoredResource<ContractState> {
fn layout(self: @ContractState) -> dojo::meta::Layout {
dojo::meta::Layout::Fixed([].span())
}

fn version(self: @ContractState) -> u8 {
1
fn schema(self: @ContractState) -> dojo::meta::introspect::Struct {
dojo::meta::introspect::Struct { name: 'm1', attrs: [].span(), children: [].span() }
}
}

#[abi(embed_v0)]
impl DojoModelImpl of dojo::model::IModel<ContractState> {
fn unpacked_size(self: @ContractState) -> Option<usize> {
Option::None
}
Expand All @@ -51,20 +51,11 @@ pub mod attacker_model {
Option::None
}

fn layout(self: @ContractState) -> dojo::meta::Layout {
dojo::meta::Layout::Fixed([].span())
}

fn schema(self: @ContractState) -> dojo::meta::introspect::Ty {
dojo::meta::introspect::Ty::Primitive('felt252')
}

fn definition(self: @ContractState) -> dojo::model::ModelDef {
dojo::model::ModelDef {
name: Self::dojo_name(self),
version: Self::version(self),
layout: Self::layout(self),
schema: Self::schema(self),
name: DojoDeployedModelImpl::dojo_name(self),
layout: DojoStoredModelImpl::layout(self),
schema: DojoStoredModelImpl::schema(self),
packed_size: Self::packed_size(self),
unpacked_size: Self::unpacked_size(self),
}
Expand Down
Loading

0 comments on commit f6cff5f

Please sign in to comment.