@crowdedkingdoms/ckx-kit 0.1.0-dev.1 → 0.2.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -5
- package/crates/ckx-sdk/Cargo.toml +1 -1
- package/crates/ckx-sdk/src/abi.rs +106 -27
- package/crates/ckx-sdk/src/cron.rs +1 -1
- package/crates/ckx-sdk/src/lib.rs +26 -0
- package/crates/ckx-sdk/src/limits.rs +52 -0
- package/crates/ckx-sdk/src/model.rs +1 -1
- package/crates/ckx-sdk/src/node.rs +28 -31
- package/crates/ckx-sdk/src/rt.rs +80 -9
- package/crates/ckx-sdk/src/testing.rs +1442 -0
- package/kit.pin +4 -4
- package/package.json +2 -2
- package/starters/grid-mod/Cargo.toml +1 -1
- package/starters/grid-mod/src/lib.rs +23 -0
- package/starters/matchmaker/Cargo.toml +1 -1
- package/starters/npc-mobs/Cargo.toml +1 -1
- package/starters/session/Cargo.toml +1 -1
- package/starters/world-tick/Cargo.toml +1 -1
- package/templates/hub/src/lib.rs +15 -18
- package/templates/spoke/src/lib.rs +5 -5
- package/vendor.lock +1 -1
package/kit.pin
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# The platform toolchain release this kit was copied from (sync-kit.sh in the platform's
|
|
2
2
|
# repository). The paths in `copied` are byte-identical to it: change them there, never here.
|
|
3
|
-
toolchain_version=v1.
|
|
4
|
-
toolchain_commit=
|
|
5
|
-
sdk_commit=
|
|
6
|
-
ckx_sdk_version=0.
|
|
3
|
+
toolchain_version=v1.10.1
|
|
4
|
+
toolchain_commit=718763af61dd6b775bae731566130732901b6902
|
|
5
|
+
sdk_commit=4aa2af5aa86c3b1d90ed7eb10f65a0fcd14a1387
|
|
6
|
+
ckx_sdk_version=0.9.0
|
|
7
7
|
crowdy_client_sdk_version=0.1.0
|
|
8
8
|
rust_version=1.97.1
|
|
9
9
|
copied=crates/ckx-sdk/src crates/crowdy-client-sdk/src tools/instrument/Cargo.toml tools/instrument/Cargo.lock tools/instrument/src checks/src/build/exec-source.ts checks/src/build/exec-source.spec.ts checks/src/build/rust-source-guard.ts checks/src/build/rust-source-guard.spec.ts checks/src/build/wasm-inspect.ts checks/src/build/wasm-inspect.spec.ts checks/src/build/client-capabilities.ts checks/src/build/client-capabilities.spec.ts checks/src/test-support/wasm-module.ts checks/compute-toolchain/host-catalog.json starters rust-toolchain.toml vendor.lock
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crowdedkingdoms/ckx-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-dev.1",
|
|
4
4
|
"description": "Build, check and test Crowded Kingdoms ck-exec mods, hubs and spokes on your machine, as the platform builds them",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"homepage": "https://docs.crowdedkingdoms.com/exec/intro",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/CrowdedKingdoms/ckx-kit.git"
|
|
9
|
+
"url": "git+https://github.com/CrowdedKingdoms/ckx-kit.git"
|
|
10
10
|
},
|
|
11
11
|
"bugs": "https://github.com/CrowdedKingdoms/ckx-kit/issues",
|
|
12
12
|
"keywords": [
|
|
@@ -70,8 +70,31 @@ ckx_sdk::export_hub!(GridMod);
|
|
|
70
70
|
|
|
71
71
|
#[cfg(test)]
|
|
72
72
|
mod tests {
|
|
73
|
+
use ckx_sdk::testing::{FakeGrid, TestHub};
|
|
74
|
+
|
|
73
75
|
use super::*;
|
|
74
76
|
|
|
77
|
+
#[test]
|
|
78
|
+
fn visitors_are_welcomed_and_the_mod_reaches_no_other_node() {
|
|
79
|
+
let grid = FakeGrid::new(7, ChunkPos::new(0, 0, 0), ChunkPos::new(3, 1, 3), 42);
|
|
80
|
+
let mut m = TestHub::<GridMod>::mod_on("grid-mod", grid).unwrap();
|
|
81
|
+
let hello: String = m.call_typed(Caller::Player(9), "visit", &()).unwrap();
|
|
82
|
+
assert_eq!(hello, "welcome to grid 7, visitor 1");
|
|
83
|
+
let refusal: Option<String> = m.call_typed(Caller::Player(9), "probe", &()).unwrap();
|
|
84
|
+
assert_eq!(refusal.as_deref(), Some("Denied: `mod:grid-mod` may not call `world`"));
|
|
85
|
+
assert_eq!(m.call(Caller::Instance(1), "visit", &[]).unwrap_err().status, Status::Denied, "only players call mods");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
#[test]
|
|
89
|
+
fn world_events_are_kept_across_a_restart() {
|
|
90
|
+
let grid = FakeGrid::new(7, ChunkPos::new(0, 0, 0), ChunkPos::new(3, 1, 3), 42);
|
|
91
|
+
let mut m = TestHub::<GridMod>::mod_on("grid-mod", grid).unwrap();
|
|
92
|
+
m.world(&[WorldEvent { grid: 7, kind: WorldEvent::VOXELS.into(), chunk: [1, 0, 1] }]).unwrap();
|
|
93
|
+
assert_eq!((m.hub().voxels, m.persist_asked()), (1, 1));
|
|
94
|
+
m.restart().unwrap();
|
|
95
|
+
assert_eq!(m.hub().last_chunk, Some([1, 0, 1]));
|
|
96
|
+
}
|
|
97
|
+
|
|
75
98
|
#[test]
|
|
76
99
|
fn world_events_are_counted_by_kind() {
|
|
77
100
|
let mut m = GridMod { grid: 7, ..GridMod::default() };
|
package/templates/hub/src/lib.rs
CHANGED
|
@@ -39,35 +39,32 @@ ckx_sdk::export_hub!(Counter);
|
|
|
39
39
|
|
|
40
40
|
#[cfg(test)]
|
|
41
41
|
mod tests {
|
|
42
|
-
use
|
|
42
|
+
use ckx_sdk::testing::TestHub;
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
Ctx { app: 1, instance: 1, epoch: 1, version: 1, kind: Kind::Hub, node_type: "counter".into(), key: "main".into() }
|
|
46
|
-
}
|
|
44
|
+
use super::*;
|
|
47
45
|
|
|
48
46
|
#[test]
|
|
49
47
|
fn players_add_and_anyone_reads() {
|
|
50
|
-
let
|
|
51
|
-
let
|
|
52
|
-
let five = encode(&5i64).unwrap();
|
|
53
|
-
hub.handle(&ctx, Call { caller: Caller::Player(7), method: "add", payload: &five }).unwrap();
|
|
54
|
-
let total: i64 = decode(&hub.handle(&ctx, Call { caller: Caller::Instance(2), method: "get", payload: &[] }).unwrap()).unwrap();
|
|
48
|
+
let mut hub = TestHub::<Counter>::spawn("counter", "main").unwrap();
|
|
49
|
+
let total: i64 = hub.call_typed(Caller::Player(7), "add", &5i64).unwrap();
|
|
55
50
|
assert_eq!(total, 5);
|
|
51
|
+
let read: i64 = hub.call_typed(Caller::Instance(2), "get", &()).unwrap();
|
|
52
|
+
assert_eq!(read, 5);
|
|
56
53
|
}
|
|
57
54
|
|
|
58
55
|
#[test]
|
|
59
56
|
fn only_players_add() {
|
|
60
|
-
let
|
|
61
|
-
let
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
let mut hub = TestHub::<Counter>::spawn("counter", "main").unwrap();
|
|
58
|
+
let refused = hub.call_typed::<_, i64>(Caller::Instance(2), "add", &1i64).unwrap_err();
|
|
59
|
+
assert_eq!(refused.status, Status::AppError);
|
|
60
|
+
assert_eq!(hub.hub().total, 0);
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
#[test]
|
|
67
|
-
fn
|
|
68
|
-
let
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
assert_eq!(
|
|
64
|
+
fn the_total_survives_a_restart() {
|
|
65
|
+
let mut hub = TestHub::<Counter>::spawn("counter", "main").unwrap();
|
|
66
|
+
hub.call_typed::<_, i64>(Caller::Player(7), "add", &42i64).unwrap();
|
|
67
|
+
hub.restart().unwrap();
|
|
68
|
+
assert_eq!(hub.hub().total, 42);
|
|
72
69
|
}
|
|
73
70
|
}
|
|
@@ -34,6 +34,8 @@ ckx_sdk::export_spoke!(Combat);
|
|
|
34
34
|
|
|
35
35
|
#[cfg(test)]
|
|
36
36
|
mod tests {
|
|
37
|
+
use ckx_sdk::testing::TestSpoke;
|
|
38
|
+
|
|
37
39
|
use super::*;
|
|
38
40
|
|
|
39
41
|
#[test]
|
|
@@ -44,10 +46,8 @@ mod tests {
|
|
|
44
46
|
|
|
45
47
|
#[test]
|
|
46
48
|
fn the_endpoint_answers_in_messagepack() {
|
|
47
|
-
let
|
|
48
|
-
let
|
|
49
|
-
|
|
50
|
-
let reply = spoke.handle(&ctx, Call { caller: Caller::Instance(3), method: "damage", payload: &hit }).unwrap();
|
|
51
|
-
assert_eq!(decode::<u32>(&reply).unwrap(), 8);
|
|
49
|
+
let mut spoke = TestSpoke::<Combat>::start("combat").unwrap();
|
|
50
|
+
let hurt: u32 = spoke.call_typed(Caller::Instance(3), "damage", &Hit { attack: 10, defense: 4 }).unwrap();
|
|
51
|
+
assert_eq!(hurt, 8);
|
|
52
52
|
}
|
|
53
53
|
}
|