2024-06-17 15:54:26 +01:00
|
|
|
use bft_json_crdt::json_crdt::BaseCrdt;
|
|
|
|
|
use bft_json_crdt::keypair::make_keypair;
|
2024-06-13 11:35:07 +01:00
|
|
|
use bft_json_crdt::op::ROOT_ID;
|
2024-06-25 13:50:02 +01:00
|
|
|
use side_node::bft_crdt::TransactionList;
|
2024-06-13 11:35:07 +01:00
|
|
|
|
|
|
|
|
// case 1 - send valid updates
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_valid_updates() {
|
2024-06-25 13:50:02 +01:00
|
|
|
// Insert to bft-crdt.doc on local node, test applying the same operation to a remote node
|
2024-06-13 11:35:07 +01:00
|
|
|
// and check that the view is the same
|
2024-06-13 11:36:51 +01:00
|
|
|
let keypair1 = make_keypair();
|
2024-06-17 15:25:22 +01:00
|
|
|
let mut crdt1 = BaseCrdt::<TransactionList>::new(&keypair1);
|
|
|
|
|
|
2024-06-18 17:12:05 +01:00
|
|
|
let val_a = side_node::utils::fake_generic_transaction_json(String::from("a"));
|
|
|
|
|
let val_b = side_node::utils::fake_generic_transaction_json(String::from("b"));
|
|
|
|
|
let val_c = side_node::utils::fake_generic_transaction_json(String::from("c"));
|
2024-06-13 11:35:07 +01:00
|
|
|
|
2024-06-17 15:25:22 +01:00
|
|
|
let _a = crdt1
|
|
|
|
|
.doc
|
|
|
|
|
.list
|
|
|
|
|
.insert(ROOT_ID, val_a.clone())
|
|
|
|
|
.sign(&keypair1);
|
|
|
|
|
let _b = crdt1
|
|
|
|
|
.doc
|
|
|
|
|
.list
|
|
|
|
|
.insert(_a.id(), val_b.clone())
|
|
|
|
|
.sign(&keypair1);
|
|
|
|
|
let _c = crdt1
|
|
|
|
|
.doc
|
|
|
|
|
.list
|
|
|
|
|
.insert(_b.id(), val_c.clone())
|
|
|
|
|
.sign(&keypair1);
|
|
|
|
|
|
2024-06-13 11:36:51 +01:00
|
|
|
let keypair2 = make_keypair();
|
2024-06-17 15:25:22 +01:00
|
|
|
let mut crdt2 = BaseCrdt::<TransactionList>::new(&keypair2);
|
2024-06-13 11:35:07 +01:00
|
|
|
crdt2.apply(_a.clone());
|
|
|
|
|
crdt2.apply(_b);
|
|
|
|
|
crdt2.apply(_c.clone());
|
|
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
|
crdt2.doc.list.view(),
|
2024-06-13 11:36:51 +01:00
|
|
|
crdt1.doc.list.view(),
|
2024-06-13 11:35:07 +01:00
|
|
|
"views should be equal"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
crdt2.apply(_a.clone());
|
|
|
|
|
crdt2.apply(_a);
|
|
|
|
|
|
|
|
|
|
assert_eq!(
|
2024-06-13 11:36:51 +01:00
|
|
|
crdt1.doc.list.view(),
|
2024-06-13 11:35:07 +01:00
|
|
|
crdt2.doc.list.view(),
|
|
|
|
|
"views are still equal after repeated applies"
|
|
|
|
|
);
|
|
|
|
|
}
|