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

Merged
merged 24 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
dccc7c1
core: less strict for schema upgrade checking
remybar Jan 17, 2025
f0184c3
improve primitive upgrade check
remybar Jan 18, 2025
1d0f0a3
update tests
remybar Jan 19, 2025
fc19c1f
fixed layouts cannot be upgraded
remybar Jan 22, 2025
7837839
variant renaming is not allowed
remybar Jan 22, 2025
c79dc05
add a test to be sure that variant without data cannot be upgraded to…
remybar Jan 22, 2025
60e1800
read back model values after an upgrade
remybar Jan 22, 2025
a6846a6
add primitive type upgrade performance check
remybar Jan 22, 2025
99cd88e
Improve primitive upgrade check performance
remybar Jan 22, 2025
b95bda1
rebuild artifacts + some fixes
remybar Jan 22, 2025
8f1076e
limit key member enum type upgrade to variant adding
remybar Jan 22, 2025
ba81c6c
rebuild artifacts
remybar Jan 22, 2025
9445f25
remove starknet:: prefix for ContractAddress and ClassHash introspect…
remybar Jan 23, 2025
bed0284
support EthAddress primitive type introspection
remybar Jan 23, 2025
8890161
update test artifacts
remybar Jan 23, 2025
4e5ab63
support 'starknet::ContractAddress' and 'starknet::ClassHash' primiti…
remybar Jan 23, 2025
ca1084c
update test artifacts
remybar Jan 23, 2025
0e3dfa6
some adjusments to be consistent
remybar Jan 24, 2025
9cce7eb
update test artifacts
remybar Jan 24, 2025
9de79b2
cannot upgrade primitive to usize + Option<T> test
remybar Jan 27, 2025
c7c9cc1
ban usize usage for introspect and model keys
remybar Jan 28, 2025
0d5eb1b
update test artifacts
remybar Jan 28, 2025
8dcf075
chore: bump scarb
glihm Jan 28, 2025
e15a97c
tests: update test db
glihm Jan 28, 2025
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
42 changes: 41 additions & 1 deletion crates/dojo/core-cairo-test/src/tests/helpers/model.cairo
remybar marked this conversation as resolved.
Show resolved Hide resolved
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, u8),
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), 189), b: 456 });

world
}
Loading
Loading