Fixed up some typos and variable names to make my editor happier

This commit is contained in:
Dave Hrycyszyn
2024-05-30 14:52:02 +01:00
parent 88e2392772
commit 0dec1c58bd

View File

@@ -16,7 +16,7 @@ use serde_json::json;
// 3. send malformed updates (e.g. missing fields) // 3. send malformed updates (e.g. missing fields)
// this we don't test as we assume transport layer only allows valid messages // this we don't test as we assume transport layer only allows valid messages
// 4. overwhelm message queue by sending many updates far into the future // 4. overwhelm message queue by sending many updates far into the future
// also untestested! currently we keep an unbounded message queue // also untested! currently we keep an unbounded message queue
// 5. block actual messages from honest actors (eclipse attack) // 5. block actual messages from honest actors (eclipse attack)
#[add_crdt_fields] #[add_crdt_fields]
@@ -29,9 +29,9 @@ struct ListExample {
#[test] #[test]
fn test_equivocation() { fn test_equivocation() {
let key = make_keypair(); let key = make_keypair();
let testkey = make_keypair(); let test_key = make_keypair();
let mut crdt = BaseCrdt::<ListExample>::new(&key); let mut crdt = BaseCrdt::<ListExample>::new(&key);
let mut testcrdt = BaseCrdt::<ListExample>::new(&testkey); let mut test_crdt = BaseCrdt::<ListExample>::new(&test_key);
let _a = crdt.doc.list.insert(ROOT_ID, 'a').sign(&key); let _a = crdt.doc.list.insert(ROOT_ID, 'a').sign(&key);
let _b = crdt.doc.list.insert(_a.id(), 'b').sign(&key); let _b = crdt.doc.list.insert(_a.id(), 'b').sign(&key);
@@ -47,26 +47,26 @@ fn test_equivocation() {
assert_eq!(crdt.apply(fake_op.clone()), OpState::ErrHashMismatch); assert_eq!(crdt.apply(fake_op.clone()), OpState::ErrHashMismatch);
assert_eq!(crdt.apply(fake_op_seq.clone()), OpState::ErrHashMismatch); assert_eq!(crdt.apply(fake_op_seq.clone()), OpState::ErrHashMismatch);
assert_eq!(testcrdt.apply(fake_op_seq), OpState::ErrHashMismatch); assert_eq!(test_crdt.apply(fake_op_seq), OpState::ErrHashMismatch);
assert_eq!(testcrdt.apply(fake_op), OpState::ErrHashMismatch); assert_eq!(test_crdt.apply(fake_op), OpState::ErrHashMismatch);
assert_eq!(testcrdt.apply(_a), OpState::Ok); assert_eq!(test_crdt.apply(_a), OpState::Ok);
assert_eq!(testcrdt.apply(_b), OpState::Ok); assert_eq!(test_crdt.apply(_b), OpState::Ok);
// make sure it doesnt accept either of the fake operations // make sure it doesn't accept either of the fake operations
assert_eq!(crdt.doc.list.view(), vec!['a', 'b']); assert_eq!(crdt.doc.list.view(), vec!['a', 'b']);
assert_eq!(crdt.doc.list.view(), testcrdt.doc.list.view()); assert_eq!(crdt.doc.list.view(), test_crdt.doc.list.view());
} }
// case 2c // case 2c
#[test] #[test]
fn test_forge_update() { fn test_forge_update() {
let key = make_keypair(); let key = make_keypair();
let testkey = make_keypair(); let test_key = make_keypair();
let mut crdt = BaseCrdt::<ListExample>::new(&key); let mut crdt = BaseCrdt::<ListExample>::new(&key);
let mut testcrdt = BaseCrdt::<ListExample>::new(&testkey); let mut test_crdt = BaseCrdt::<ListExample>::new(&test_key);
let _a = crdt.doc.list.insert(ROOT_ID, 'a').sign(&key); let _a = crdt.doc.list.insert(ROOT_ID, 'a').sign(&key);
let fake_key = make_keypair(); // generate a new keypair as we dont have privkey of list.our_id let fake_key = make_keypair(); // generate a new keypair as we don't have private key of list.our_id
let mut op = Op { let mut op = Op {
origin: _a.inner.id, origin: _a.inner.id,
author: crdt.doc.id, // pretend to be the owner of list author: crdt.doc.id, // pretend to be the owner of list
@@ -83,10 +83,10 @@ fn test_forge_update() {
let signed = op.sign(&fake_key); let signed = op.sign(&fake_key);
assert_eq!(crdt.apply(signed.clone()), OpState::ErrHashMismatch); assert_eq!(crdt.apply(signed.clone()), OpState::ErrHashMismatch);
assert_eq!(testcrdt.apply(signed), OpState::ErrHashMismatch); assert_eq!(test_crdt.apply(signed), OpState::ErrHashMismatch);
assert_eq!(testcrdt.apply(_a), OpState::Ok); assert_eq!(test_crdt.apply(_a), OpState::Ok);
// make sure it doesnt accept fake operation // make sure it doesn't accept fake operation
assert_eq!(crdt.doc.list.view(), vec!['a']); assert_eq!(crdt.doc.list.view(), vec!['a']);
} }
@@ -105,9 +105,9 @@ struct Nested2 {
#[test] #[test]
fn test_path_update() { fn test_path_update() {
let key = make_keypair(); let key = make_keypair();
let testkey = make_keypair(); let test_key = make_keypair();
let mut crdt = BaseCrdt::<Nested>::new(&key); let mut crdt = BaseCrdt::<Nested>::new(&key);
let mut testcrdt = BaseCrdt::<Nested>::new(&testkey); let mut test_crdt = BaseCrdt::<Nested>::new(&test_key);
let mut _true = crdt.doc.a.b.set(true); let mut _true = crdt.doc.a.b.set(true);
_true.path = vec![PathSegment::Field("x".to_string())]; _true.path = vec![PathSegment::Field("x".to_string())];
let mut _false = crdt.doc.a.b.set(false); let mut _false = crdt.doc.a.b.set(false);
@@ -116,19 +116,22 @@ fn test_path_update() {
PathSegment::Index(_false.id), PathSegment::Index(_false.id),
]; ];
let signedtrue = _true.sign(&key); let signed_true = _true.sign(&key);
let signedfalse = _false.sign(&key); let signed_false = _false.sign(&key);
let mut signedfalsefakepath = signedfalse.clone(); let mut signed_false_fake_path = signed_false.clone();
signedfalsefakepath.inner.path = vec![ signed_false_fake_path.inner.path = vec![
PathSegment::Field("a".to_string()), PathSegment::Field("a".to_string()),
PathSegment::Field("b".to_string()), PathSegment::Field("b".to_string()),
]; ];
assert_eq!(testcrdt.apply(signedtrue), OpState::ErrPathMismatch); assert_eq!(test_crdt.apply(signed_true), OpState::ErrPathMismatch);
assert_eq!(testcrdt.apply(signedfalse), OpState::ErrPathMismatch); assert_eq!(test_crdt.apply(signed_false), OpState::ErrPathMismatch);
assert_eq!(testcrdt.apply(signedfalsefakepath), OpState::ErrDigestMismatch); assert_eq!(
test_crdt.apply(signed_false_fake_path),
OpState::ErrDigestMismatch
);
// make sure it doesnt accept fake operation // make sure it doesn't accept fake operation
assert_eq!(crdt.doc.a.b.view(), json!(false).into()); assert_eq!(crdt.doc.a.b.view(), json!(false).into());
assert_eq!(testcrdt.doc.a.b.view(), json!(null).into()); assert_eq!(test_crdt.doc.a.b.view(), json!(null).into());
} }