Skip to content
This repository was archived by the owner on Nov 11, 2024. It is now read-only.

Commit 969004b

Browse files
authored
feat: use dynamic namespaces (#31)
* feat: use dynamic namespaces * fix: port the new testing suite with dynamic namespaces * fix: ensure events namespace permission is correctly checked * fmt and remove ci since dojo-core is only for archiving * add cairo fmt back
1 parent 7215d47 commit 969004b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2625
-2558
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,13 @@ env:
1111
RUST_VERSION: 1.80.0
1212

1313
jobs:
14-
test:
15-
runs-on: ubuntu-latest-4-cores
16-
container:
17-
image: ghcr.io/dojoengine/dojo-core-dev:5995840
18-
steps:
19-
- uses: actions/checkout@v3
20-
- uses: Swatinem/rust-cache@v2
21-
- run: |
22-
scripts/tests.sh
23-
2414
cairofmt:
2515
runs-on: ubuntu-latest
2616
steps:
2717
- uses: actions/checkout@v3
2818
- uses: software-mansion/setup-scarb@v1
2919
with:
30-
scarb-version: "2.7.1"
20+
scarb-version: "2.8.4"
3121
- run: |
3222
bash scripts/cairo_fmt.sh --check
3323

crates/compiler/src/plugin/semantics/test_data/get

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -132,28 +132,9 @@ Block(
132132
pattern: Variable(
133133
__Health,
134134
),
135-
expr: FunctionCall(
136-
ExprFunctionCall {
137-
function: ?4::get::<core::felt252, core::felt252Drop, core::Felt252Serde>,
138-
args: [
139-
Value(
140-
Snapshot(
141-
ExprSnapshot {
142-
inner: Var(
143-
LocalVarId(test::world),
144-
),
145-
ty: @dojo::world::iworld::IWorldDispatcher,
146-
},
147-
),
148-
),
149-
Value(
150-
Var(
151-
LocalVarId(test::key),
152-
),
153-
),
154-
],
155-
coupon_arg: None,
156-
ty: test::Health,
135+
expr: Missing(
136+
ExprMissing {
137+
ty: <missing>,
157138
},
158139
),
159140
},
@@ -169,7 +150,17 @@ Block(
169150
)
170151

171152
//! > semantic_diagnostics
172-
error: Trait has no implementation in context: dojo::model::model::ModelStore::<test::Health>.
153+
error: Identifier not found.
173154
--> lib.cairo:12:1
174155
get!(world, key, (Health))
175156
^************************^
157+
158+
warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`.
159+
--> lib.cairo:10:22
160+
fn test_func() { let key: felt252 = 0xb0b;
161+
^*^
162+
163+
warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`.
164+
--> lib.cairo:11:5
165+
let world = IWorldDispatcher{contract_address: 0x0.try_into().unwrap()}; {
166+
^***^

crates/compiler/src/plugin/semantics/test_data/set

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -84,52 +84,9 @@ Block(
8484
statements: [
8585
Expr(
8686
StatementExpr {
87-
expr: FunctionCall(
88-
ExprFunctionCall {
89-
function: dojo::model::model::ModelStoreImpl::<test::Health, dojo::model::model::ModelImpl::<test::Health, test::HealthModelParser, test::health_definition::HealthDefinitionImpl::<test::Health>, test::HealthSerde>, test::HealthDrop>::set,
90-
args: [
91-
Value(
92-
Var(
93-
LocalVarId(test::world),
94-
),
95-
),
96-
Value(
97-
Snapshot(
98-
ExprSnapshot {
99-
inner: StructCtor(
100-
ExprStructCtor {
101-
concrete_struct_id: test::Health,
102-
members: [
103-
(
104-
MemberId(test::id),
105-
Literal(
106-
ExprLiteral {
107-
value: 2827,
108-
ty: core::integer::u32,
109-
},
110-
),
111-
),
112-
(
113-
MemberId(test::health),
114-
Literal(
115-
ExprLiteral {
116-
value: 79,
117-
ty: core::integer::u16,
118-
},
119-
),
120-
),
121-
],
122-
base_struct: None,
123-
ty: test::Health,
124-
},
125-
),
126-
ty: @test::Health,
127-
},
128-
),
129-
),
130-
],
131-
coupon_arg: None,
132-
ty: (),
87+
expr: Missing(
88+
ExprMissing {
89+
ty: <missing>,
13390
},
13491
),
13592
},
@@ -141,7 +98,57 @@ Block(
14198
)
14299

143100
//! > semantic_diagnostics
101+
error: Identifier not found.
102+
--> lib.cairo:12:1
103+
set!(world, (Health{id: 0xb0b, health: 79}))
104+
^******************************************^
105+
144106
warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`.
145107
--> lib.cairo:10:22
146108
fn test_func() { let key: felt252 = 0xb0b;
147109
^*^
110+
111+
warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`.
112+
--> lib.cairo:11:5
113+
let world = IWorldDispatcher{contract_address: 0x0.try_into().unwrap()}; {
114+
^***^
115+
116+
error: Identifier not found.
117+
--> lib.cairo:3:1
118+
#[derive(Copy, Drop, Serde)]
119+
^**************************^
120+
121+
error: Impl not found.
122+
--> lib.cairo:3:1
123+
#[derive(Copy, Drop, Serde)]
124+
^**************************^
125+
126+
error: Identifier not found.
127+
--> lib.cairo:3:1
128+
#[derive(Copy, Drop, Serde)]
129+
^**************************^
130+
131+
error: Impl item function `HealthDefinitionImpl::namespace` is not a member of trait `ModelDefinition`.
132+
--> lib.cairo:3:1
133+
#[derive(Copy, Drop, Serde)]
134+
^**************************^
135+
136+
error: Impl item function `HealthDefinitionImpl::tag` is not a member of trait `ModelDefinition`.
137+
--> lib.cairo:3:1
138+
#[derive(Copy, Drop, Serde)]
139+
^**************************^
140+
141+
error: Impl item function `HealthDefinitionImpl::selector` is not a member of trait `ModelDefinition`.
142+
--> lib.cairo:3:1
143+
#[derive(Copy, Drop, Serde)]
144+
^**************************^
145+
146+
error: Impl item function `HealthDefinitionImpl::name_hash` is not a member of trait `ModelDefinition`.
147+
--> lib.cairo:3:1
148+
#[derive(Copy, Drop, Serde)]
149+
^**************************^
150+
151+
error: Impl item function `HealthDefinitionImpl::namespace_hash` is not a member of trait `ModelDefinition`.
152+
--> lib.cairo:3:1
153+
#[derive(Copy, Drop, Serde)]
154+
^**************************^

crates/contracts/Scarb.lock

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@ version = 1
33

44
[[package]]
55
name = "dojo"
6-
version = "1.0.0-rc.1"
6+
version = "1.0.0-rc.0"
7+
dependencies = [
8+
"dojo_plugin",
9+
]
10+
11+
[[package]]
12+
name = "dojo_plugin"
13+
version = "2.8.4"
14+
source = "git+https://github.com/dojoengine/dojo?branch=feat%2Fdojo-1-rc0#3bf1276163fe9dbfe0f65775de8363e358510c77"

crates/contracts/Scarb.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ cairo-version = "=2.8.4"
33
edition = "2024_07"
44
description = "The Dojo Core library for autonomous worlds."
55
name = "dojo"
6-
version = "1.0.0-rc.1"
6+
version = "1.0.0-rc.0"
77

88
[dependencies]
99
starknet = "=2.8.4"
10+
dojo_plugin = { git = "https://github.com/dojoengine/dojo", branch = "feat/dojo-1-rc0" }
11+
12+
[dev-dependencies]
13+
cairo_test = "=2.8.4"
1014

1115
[lib]
1216

crates/contracts/src/contract/components/upgradeable.cairo

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub mod upgradeable_cpt {
3030

3131
pub mod Errors {
3232
pub const INVALID_CLASS: felt252 = 'class_hash cannot be zero';
33-
pub const INVALID_CLASS_CONTENT: felt252 = 'class_hash not world provider';
33+
pub const INVALID_CLASS_CONTENT: felt252 = 'class_hash not Dojo IContract';
3434
pub const INVALID_CALLER: felt252 = 'must be called by world';
3535
pub const INVALID_WORLD_ADDRESS: felt252 = 'invalid world address';
3636
}
@@ -41,17 +41,19 @@ pub mod upgradeable_cpt {
4141
> of super::IUpgradeable<ComponentState<TContractState>> {
4242
fn upgrade(ref self: ComponentState<TContractState>, new_class_hash: ClassHash) {
4343
assert(
44-
self.get_contract().world().contract_address.is_non_zero(),
44+
self.get_contract().world_dispatcher().contract_address.is_non_zero(),
4545
Errors::INVALID_WORLD_ADDRESS
4646
);
4747
assert(
48-
get_caller_address() == self.get_contract().world().contract_address,
48+
get_caller_address() == self.get_contract().world_dispatcher().contract_address,
4949
Errors::INVALID_CALLER
5050
);
5151
assert(new_class_hash.is_non_zero(), Errors::INVALID_CLASS);
5252

53+
// Seems like the match doesn't catch the error is the entrypoint is
54+
// not found.
5355
match starknet::syscalls::library_call_syscall(
54-
new_class_hash, selector!("world"), [].span(),
56+
new_class_hash, selector!("dojo_name"), [].span(),
5557
) {
5658
Result::Ok(_) => {
5759
replace_class_syscall(new_class_hash).unwrap();

crates/contracts/src/contract/components/world_provider.cairo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use dojo::world::IWorldDispatcher;
22

33
#[starknet::interface]
44
pub trait IWorldProvider<T> {
5-
fn world(self: @T) -> IWorldDispatcher;
5+
fn world_dispatcher(self: @T) -> IWorldDispatcher;
66
}
77

88
#[starknet::component]
@@ -21,7 +21,7 @@ pub mod world_provider_cpt {
2121
pub impl WorldProvider<
2222
TContractState, +HasComponent<TContractState>
2323
> of super::IWorldProvider<ComponentState<TContractState>> {
24-
fn world(self: @ComponentState<TContractState>) -> IWorldDispatcher {
24+
fn world_dispatcher(self: @ComponentState<TContractState>) -> IWorldDispatcher {
2525
self.world_dispatcher.read()
2626
}
2727
}

crates/contracts/src/contract/contract.cairo

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[starknet::interface]
2+
pub trait IContract<T> {
3+
fn dojo_name(self: @T) -> ByteArray;
4+
}
Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,23 @@
11
use dojo::meta::Layout;
22
use dojo::meta::introspect::Ty;
3-
use dojo::world::IWorldDispatcher;
43

54
#[derive(Drop, Serde, Debug, PartialEq)]
65
pub struct EventDefinition {
76
pub name: ByteArray,
8-
pub namespace: ByteArray,
9-
pub namespace_selector: felt252,
107
pub version: u8,
118
pub layout: Layout,
129
pub schema: Ty
1310
}
1411

1512
pub trait Event<T> {
16-
fn emit(self: @T, world: IWorldDispatcher);
17-
1813
fn name() -> ByteArray;
19-
fn namespace() -> ByteArray;
20-
fn tag() -> ByteArray;
21-
2214
fn version() -> u8;
23-
24-
fn selector() -> felt252;
25-
fn instance_selector(self: @T) -> felt252;
26-
27-
fn name_hash() -> felt252;
28-
fn namespace_hash() -> felt252;
29-
3015
fn definition() -> EventDefinition;
31-
3216
fn layout() -> Layout;
3317
fn schema() -> Ty;
34-
3518
fn historical() -> bool;
3619
fn keys(self: @T) -> Span<felt252>;
3720
fn values(self: @T) -> Span<felt252>;
38-
}
39-
40-
#[starknet::interface]
41-
pub trait IEvent<T> {
42-
fn name(self: @T) -> ByteArray;
43-
fn namespace(self: @T) -> ByteArray;
44-
fn tag(self: @T) -> ByteArray;
45-
46-
fn version(self: @T) -> u8;
47-
48-
fn selector(self: @T) -> felt252;
49-
fn name_hash(self: @T) -> felt252;
50-
fn namespace_hash(self: @T) -> felt252;
51-
52-
fn definition(self: @T) -> EventDefinition;
53-
54-
fn layout(self: @T) -> Layout;
55-
fn schema(self: @T) -> Ty;
56-
}
57-
58-
#[cfg(target: "test")]
59-
pub trait EventTest<T> {
60-
fn emit_test(self: @T, world: IWorldDispatcher);
21+
/// Returns the selector of the model computed for the given namespace hash.
22+
fn selector(namespace_hash: felt252) -> felt252;
6123
}

0 commit comments

Comments
 (0)