@@ -7,72 +7,51 @@ mod tests {
7
7
8
8
use myapp :: app :: {myapp_actions, IMyAppActionsDispatcher , IMyAppActionsDispatcherTrait };
9
9
use pixelaw :: core :: actions :: {actions, IActionsDispatcher , IActionsDispatcherTrait };
10
- use pixelaw :: core :: models :: permissions :: {permissions};
11
10
12
11
use pixelaw :: core :: models :: pixel :: {Pixel , PixelUpdate };
13
12
use pixelaw :: core :: models :: pixel :: {pixel};
14
13
use pixelaw :: core :: models :: registry :: {app, app_name, core_actions_address};
14
+ use pixelaw :: core :: tests :: helpers :: {
15
+ setup_core, setup_core_initialized, setup_apps, setup_apps_initialized, ZERO_ADDRESS ,
16
+ set_caller, drop_all_events, TEST_POSITION , WHITE_COLOR , RED_COLOR
17
+ };
15
18
use pixelaw :: core :: utils :: {
16
- get_core_actions, encode_color, decode_color , Direction , Position , DefaultParameters
19
+ get_core_actions, encode_rgba, decode_rgba , Direction , Position , DefaultParameters
17
20
};
18
21
use starknet :: class_hash :: Felt252TryIntoClassHash ;
19
22
20
23
use zeroable :: Zeroable ;
21
24
22
- // Helper function: deploys world and actions
23
- fn deploy_world () -> (IWorldDispatcher , IActionsDispatcher , IMyAppActionsDispatcher ) {
24
- let mut models = array! [
25
- pixel :: TEST_CLASS_HASH ,
26
- app :: TEST_CLASS_HASH ,
27
- app_name :: TEST_CLASS_HASH ,
28
- core_actions_address :: TEST_CLASS_HASH ,
29
- permissions :: TEST_CLASS_HASH ,
30
- ];
31
- let world = spawn_test_world ([" pixelaw" ]. span (), models . span ());
32
-
33
- // Deploy Core actions
34
- let core_actions_address = world
35
- . deploy_contract (' salt1' , actions :: TEST_CLASS_HASH . try_into (). unwrap ());
36
- let core_actions = IActionsDispatcher { contract_address : core_actions_address };
37
-
25
+ fn deploy_app (world : IWorldDispatcher ) -> IMyAppActionsDispatcher {
38
26
// Deploy MyApp actions
39
27
let myapp_actions_address = world
40
28
. deploy_contract (' salt2' , myapp_actions :: TEST_CLASS_HASH . try_into (). unwrap ());
41
- let myapp_actions = IMyAppActionsDispatcher { contract_address : myapp_actions_address };
42
-
43
- // Setup dojo auth
44
- world . grant_writer (selector_from_tag! (" pixelaw-Pixel" ), core_actions_address );
45
- world . grant_writer (selector_from_tag! (" pixelaw-App" ), core_actions_address );
46
- world . grant_writer (selector_from_tag! (" pixelaw-AppName" ), core_actions_address );
47
- world . grant_writer (selector_from_tag! (" pixelaw-Permissions" ), core_actions_address );
48
- world . grant_writer (selector_from_tag! (" pixelaw-CoreActionsAddress" ), core_actions_address );
49
29
50
- // PLEASE ADD YOUR APP PERMISSIONS HERE
51
-
52
- (world , core_actions , myapp_actions )
30
+ IMyAppActionsDispatcher { contract_address : myapp_actions_address }
53
31
}
54
32
55
33
#[test]
56
34
#[available_gas(3000000000)]
57
35
fn test_myapp_actions () {
58
36
// Deploy everything
59
- let (world , core_actions , myapp_actions ) = deploy_world ();
37
+ let (world , _core_actions , player_1 , _player_2 ) = setup_core_initialized ();
60
38
61
- core_actions . init ();
62
- myapp_actions . init ( );
39
+ // Deploy MyApp actions
40
+ let myapp_actions = deploy_app ( world );
63
41
64
- let player1 = starknet :: contract_address_const :: <0x1337 >();
65
- starknet :: testing :: set_account_contract_address (player1 );
42
+ myapp_actions . init ();
66
43
67
- let color = encode_color (1 , 1 , 1 , 1 );
44
+ set_caller (player_1 );
45
+ let color = encode_rgba (1 , 1 , 1 , 1 );
68
46
69
47
myapp_actions
70
48
. interact (
71
49
DefaultParameters {
72
- for_player : Zeroable :: zero () ,
73
- for_system : Zeroable :: zero () ,
50
+ player_override : Option :: None ,
51
+ system_override : Option :: None ,
74
52
position : Position { x : 1 , y : 1 },
75
- color : color
53
+ color : color ,
54
+ area_hint : Option :: None
76
55
},
77
56
);
78
57
0 commit comments