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

feat(dojo-core): make the schema upgrade less strict #2925

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
42 changes: 41 additions & 1 deletion crates/dojo/core-cairo-test/src/tests/helpers/model.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use dojo::model::ModelStorage;
use core::starknet::ContractAddress;

use dojo::world::IWorldDispatcher;
Expand Down Expand Up @@ -54,6 +55,33 @@ struct FooModelMemberAdded {
pub b: u128,
}

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

#[derive(Introspect, Copy, Drop, Serde)]
#[dojo::model]
struct FooModelMemberChanged {
#[key]
pub caller: ContractAddress,
pub a: MyEnum,
pub b: u128,
}

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

#[derive(Introspect, Copy, Drop, Serde)]
#[dojo::model]
struct FooModelMemberIllegalChange {
#[key]
pub caller: ContractAddress,
pub a: AnotherEnum,
pub b: u128,
}

pub fn deploy_world_for_model_upgrades() -> IWorldDispatcher {
let namespace_def = NamespaceDef {
Expand All @@ -66,8 +94,20 @@ pub fn deploy_world_for_model_upgrades() -> IWorldDispatcher {
),
TestResource::Model(m_FooModelMemberAddedButMoved::TEST_CLASS_HASH.try_into().unwrap()),
TestResource::Model(m_FooModelMemberAdded::TEST_CLASS_HASH.try_into().unwrap()),
TestResource::Model(m_FooModelMemberChanged::TEST_CLASS_HASH.try_into().unwrap()),
TestResource::Model(m_FooModelMemberIllegalChange::TEST_CLASS_HASH.try_into().unwrap()),
]
.span(),
};
spawn_test_world([namespace_def].span()).dispatcher
let world = spawn_test_world([namespace_def].span()).dispatcher;

// write some model values to be able to check if after a successfully upgrade, these values
// remain the same
let mut world_storage = dojo::world::WorldStorageTrait::new(world, @"dojo");
let caller = starknet::contract_address_const::<0xb0b>();

world_storage.write_model(@FooModelMemberAdded { caller, a: 123, b: 456 });
world_storage.write_model(@FooModelMemberChanged { caller, a: MyEnum::X(42), b: 456 });

world
}
Loading
Loading