@crowdedkingdoms/ckx-kit 0.1.1-dev.1 → 0.2.0-test.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.
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "crowdy-client-sdk"
3
- version = "0.1.0-dev.1"
3
+ version = "0.1.0-test.1"
4
4
  edition = "2021"
5
5
  description = "Guest SDK for the CLIENT half of a ck-exec mod: browser WASM (ck ABI v0 + the client host calls)."
6
6
  license = "MIT OR Apache-2.0"
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.9.0
4
- toolchain_commit=8b4ef8929c4fd1bb7ccf604032ad75b970aca1a2
5
- sdk_commit=b4194c7a13e2f3b74279cb4f715c4bcdaba70023
6
- ckx_sdk_version=0.8.0
3
+ toolchain_version=v1.10.1
4
+ toolchain_commit=a4138b1fe89995230126c505a084689e8a6d2d53
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdedkingdoms/ckx-kit",
3
- "version": "0.1.1-dev.1",
3
+ "version": "0.2.0-test.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",
@@ -9,5 +9,5 @@ publish = false
9
9
  crate-type = ["cdylib"]
10
10
 
11
11
  [dependencies]
12
- ckx-sdk = "0.8.0"
12
+ ckx-sdk = "0.9.0"
13
13
  serde = { version = "1", features = ["derive"] }
@@ -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() };
@@ -9,5 +9,5 @@ publish = false
9
9
  crate-type = ["cdylib"]
10
10
 
11
11
  [dependencies]
12
- ckx-sdk = "0.8.0"
12
+ ckx-sdk = "0.9.0"
13
13
  serde = { version = "1", features = ["derive"] }
@@ -9,6 +9,6 @@ publish = false
9
9
  crate-type = ["cdylib"]
10
10
 
11
11
  [dependencies]
12
- ckx-sdk = "0.8.0"
12
+ ckx-sdk = "0.9.0"
13
13
  serde = { version = "1", features = ["derive"] }
14
14
  serde_json = "1"
@@ -9,5 +9,5 @@ publish = false
9
9
  crate-type = ["cdylib"]
10
10
 
11
11
  [dependencies]
12
- ckx-sdk = "0.8.0"
12
+ ckx-sdk = "0.9.0"
13
13
  serde = { version = "1", features = ["derive"] }
@@ -9,6 +9,6 @@ publish = false
9
9
  crate-type = ["cdylib"]
10
10
 
11
11
  [dependencies]
12
- ckx-sdk = "0.8.0"
12
+ ckx-sdk = "0.9.0"
13
13
  serde = { version = "1", features = ["derive"] }
14
14
  serde_json = "1"
@@ -39,35 +39,32 @@ ckx_sdk::export_hub!(Counter);
39
39
 
40
40
  #[cfg(test)]
41
41
  mod tests {
42
- use super::*;
42
+ use ckx_sdk::testing::TestHub;
43
43
 
44
- fn ctx() -> Ctx {
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 ctx = ctx();
51
- let mut hub = Counter::spawn(&ctx, &[]).unwrap();
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 ctx = ctx();
61
- let mut hub = Counter::spawn(&ctx, &[]).unwrap();
62
- let one = encode(&1i64).unwrap();
63
- assert!(hub.handle(&ctx, Call { caller: Caller::Instance(2), method: "add", payload: &one }).is_err());
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 the_snapshot_restores_the_total() {
68
- let ctx = ctx();
69
- let mut hub = Counter { total: 42 };
70
- let snapshot = hub.persist(&ctx).unwrap();
71
- assert_eq!(Counter::load(&ctx, &snapshot, 1).unwrap().total, 42);
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 ctx = Ctx { app: 1, instance: 1, epoch: 1, version: 1, kind: Kind::Spoke, node_type: "combat".into(), key: String::new() };
48
- let mut spoke = Combat::start(&ctx).unwrap();
49
- let hit = encode(&Hit { attack: 10, defense: 4 }).unwrap();
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
  }
package/vendor.lock CHANGED
@@ -16,7 +16,7 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
16
16
 
17
17
  [[package]]
18
18
  name = "ckx-sdk"
19
- version = "0.8.0"
19
+ version = "0.9.0"
20
20
  dependencies = [
21
21
  "base64",
22
22
  "rmp-serde",