diff --git a/crates/bft-json-crdt/tests/byzantine.rs b/crates/bft-json-crdt/tests/byzantine.rs index 661f50e..f195da1 100644 --- a/crates/bft-json-crdt/tests/byzantine.rs +++ b/crates/bft-json-crdt/tests/byzantine.rs @@ -25,41 +25,6 @@ struct ListExample { list: ListCrdt, } -// case 1 - send valid updates -#[test] -fn test_valid_updates() { - // Insert to crdt.doc on local node, test applying the same operation to a remote node - // and check that the view is the same - let key = make_keypair(); - let mut crdt = BaseCrdt::::new(&key); - let _a = crdt.doc.list.insert(ROOT_ID, 'a').sign(&key); - let _b = crdt.doc.list.insert(_a.id(), 'b').sign(&key); - let _c = crdt.doc.list.insert(_b.id(), 'c').sign(&key); - - assert_eq!(crdt.doc.list.view(), vec!['a', 'b', 'c']); - - let key2 = make_keypair(); - let mut crdt2 = BaseCrdt::::new(&key2); - crdt2.apply(_a.clone()); - crdt2.apply(_b); - crdt2.apply(_c.clone()); - - assert_eq!( - crdt2.doc.list.view(), - crdt.doc.list.view(), - "views should be equal" - ); - - crdt2.apply(_a.clone()); - crdt2.apply(_a); - - assert_eq!( - crdt.doc.list.view(), - crdt2.doc.list.view(), - "views are still equal after repeated applies" - ); -} - // case 2a + 2b #[test] fn test_equivocation() { diff --git a/side-node/tests/crdt.rs b/side-node/tests/crdt.rs new file mode 100644 index 0000000..7a97da4 --- /dev/null +++ b/side-node/tests/crdt.rs @@ -0,0 +1,45 @@ +use bft_crdt_derive::add_crdt_fields; +use bft_json_crdt::json_crdt::{BaseCrdt, CrdtNode, IntoCrdtNode}; +use bft_json_crdt::op::ROOT_ID; +use bft_json_crdt::{keypair::make_keypair, list_crdt::ListCrdt}; + +#[add_crdt_fields] +#[derive(Clone, CrdtNode)] +struct ListExample { + list: ListCrdt, +} + +// case 1 - send valid updates +#[test] +fn test_valid_updates() { + // Insert to crdt.doc on local node, test applying the same operation to a remote node + // and check that the view is the same + let key = make_keypair(); + let mut crdt = BaseCrdt::::new(&key); + let _a = crdt.doc.list.insert(ROOT_ID, 'a').sign(&key); + let _b = crdt.doc.list.insert(_a.id(), 'b').sign(&key); + let _c = crdt.doc.list.insert(_b.id(), 'c').sign(&key); + + assert_eq!(crdt.doc.list.view(), vec!['a', 'b', 'c']); + + let key2 = make_keypair(); + let mut crdt2 = BaseCrdt::::new(&key2); + crdt2.apply(_a.clone()); + crdt2.apply(_b); + crdt2.apply(_c.clone()); + + assert_eq!( + crdt2.doc.list.view(), + crdt.doc.list.view(), + "views should be equal" + ); + + crdt2.apply(_a.clone()); + crdt2.apply(_a); + + assert_eq!( + crdt.doc.list.view(), + crdt2.doc.list.view(), + "views are still equal after repeated applies" + ); +}