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

dojo-lang: add plugin test for contract with components #1246

Merged
merged 1 commit into from
Dec 8, 2023
Merged
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
4 changes: 2 additions & 2 deletions crates/dojo-lang/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl DojoContract {
let elements = enum_ast.variants(db).elements(db);

let variants = elements.iter().map(|e| e.as_syntax_node().get_text(db)).collect::<Vec<_>>();
let variants = variants.join(", ");
let variants = variants.join(",\n");

rewrite_nodes.push(RewriteNode::interpolate_patched(
"
Expand Down Expand Up @@ -164,7 +164,7 @@ impl DojoContract {
let elements = struct_ast.members(db).elements(db);

let members = elements.iter().map(|e| e.as_syntax_node().get_text(db)).collect::<Vec<_>>();
let members = members.join(", ");
let members = members.join(",\n");

rewrite_nodes.push(RewriteNode::interpolate_patched(
"
Expand Down
180 changes: 178 additions & 2 deletions crates/dojo-lang/src/plugin_test_data/system
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ mod ctxnamed {

#[dojo::contract]
mod withevent {

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
Expand All @@ -51,6 +50,41 @@ mod withevent {
}
}

#[starknet::component]
mod testcomponent1 {
#[storage]
struct Storage {}
}

#[starknet::component]
mod testcomponent2 {
#[storage]
struct Storage {}
}

#[dojo::contract]
mod withcomponent {

component!(path: testcomponent1, storage: testcomponent1_storage, event: testcomponent1_event);
component!(path: testcomponent2, storage: testcomponent2_storage, event: testcomponent2_event);

#[storage]
struct Storage {
#[substorage(v0)]
testcomponent1_storage: testcomponent1::Storage,
#[substorage(v0)]
testcomponent2_storage: testcomponent2::Storage,
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
testcomponent1_event: testcomponent1::Event,
testcomponent2_event: testcomponent2::Event,
}
}

//! > generated_cairo_code
#[starknet::contract]
mod spawn {
Expand Down Expand Up @@ -161,6 +195,16 @@ mod ctxnamed {
}

//! > expected_diagnostics
error: Unsupported attribute.
--> test_src/lib.cairo:47:1
#[starknet::component]
^********************^

error: Unsupported attribute.
--> test_src/lib.cairo:53:1
#[starknet::component]
^********************^

error: Unsupported attribute.
--> test_src/lib.cairo[spawn]:2:17
#[starknet::contract]
Expand All @@ -181,6 +225,21 @@ error: Unsupported attribute.
#[starknet::contract]
^*******************^

error: Unsupported attribute.
--> test_src/lib.cairo[withcomponent]:2:17
#[starknet::contract]
^*******************^

error: Unsupported attribute.
--> test_src/lib.cairo:49:5
#[storage]
^********^

error: Unsupported attribute.
--> test_src/lib.cairo:55:5
#[storage]
^********^

error: Unknown inline item macro: 'component'.
--> test_src/lib.cairo[spawn]:9:21
component!(path: dojo::components::upgradeable::upgradeable, storage: upgradeable, event: UpgradeableEvent);
Expand Down Expand Up @@ -326,8 +385,80 @@ error: Unsupported attribute.
#[substorage(v0)]
^***************^

error: Unknown inline item macro: 'component'.
--> test_src/lib.cairo[withcomponent]:9:21
component!(path: dojo::components::upgradeable::upgradeable, storage: upgradeable, event: UpgradeableEvent);
^**********************************************************************************************************^

error: Unsupported attribute.
--> test_src/lib.cairo[withcomponent]:11:21
#[external(v0)]
^*************^

error: Unsupported attribute.
--> test_src/lib.cairo[withcomponent]:16:21
#[external(v0)]
^*************^

error: Unsupported attribute.
--> test_src/lib.cairo[withcomponent]:23:21
#[abi(embed_v0)]
^**************^

error: Unknown inline item macro: 'component'.
--> test_src/lib.cairo[withcomponent]:27:5
component!(path: testcomponent1, storage: testcomponent1_storage, event: testcomponent1_event);
^*********************************************************************************************^

error: Unknown inline item macro: 'component'.
--> test_src/lib.cairo[withcomponent]:28:5
component!(path: testcomponent2, storage: testcomponent2_storage, event: testcomponent2_event);
^*********************************************************************************************^

error: Unsupported attribute.
--> test_src/lib.cairo[withcomponent]:30:13
#[storage]
^********^

error: Unsupported attribute.
--> test_src/lib.cairo[withcomponent]:33:17
#[substorage(v0)]
^***************^

error: Unsupported attribute.
--> test_src/lib.cairo[withcomponent]:35:25
#[substorage(v0)]
^***************^

error: Unsupported attribute.
--> test_src/lib.cairo[withcomponent]:37:9
#[substorage(v0)]
^***************^

error: Unsupported attribute.
--> test_src/lib.cairo[withcomponent]:41:13
#[event]
^******^

error: Unsupported attribute.
--> test_src/lib.cairo[withcomponent]:45:25
#[flat]
^*****^

//! > expanded_cairo_code
#[starknet::contract]
#[starknet::component]
mod testcomponent1 {
#[storage]
struct Storage {}
}

#[starknet::component]
mod testcomponent2 {
#[storage]
struct Storage {}
}

#[starknet::contract]
mod spawn {
use dojo::world;
use dojo::world::IWorldDispatcher;
Expand Down Expand Up @@ -509,3 +640,48 @@ impl EventDrop of Drop::<Event>;
impl TestEventDrop of Drop::<TestEvent>;

}

#[starknet::contract]
mod withcomponent {
use dojo::world;
use dojo::world::IWorldDispatcher;
use dojo::world::IWorldDispatcherTrait;
use dojo::world::IWorldProvider;

#[external(v0)]
fn dojo_resource(self: @ContractState) -> felt252 {
'withcomponent'
}

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

#[abi(embed_v0)]
impl UpgradableImpl = dojo::components::upgradeable::upgradeable::UpgradableImpl<ContractState>;

#[storage]
struct Storage {
world_dispatcher: IWorldDispatcher,
#[substorage(v0)]
upgradeable: dojo::components::upgradeable::upgradeable::Storage,
#[substorage(v0)]
testcomponent1_storage: testcomponent1::Storage,
#[substorage(v0)]
testcomponent2_storage: testcomponent2::Storage
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
UpgradeableEvent: dojo::components::upgradeable::upgradeable::Event,
#[flat]
testcomponent1_event: testcomponent1::Event,
testcomponent2_event: testcomponent2::Event
}
impl EventDrop of Drop::<Event>;

}
Loading