Skip to content

Commit

Permalink
Start DID's nonces from 0. (#193)
Browse files Browse the repository at this point in the history
* WIP

* Fix tests and bump up version
  • Loading branch information
olegnn authored Dec 6, 2024
1 parent 8a5d2a7 commit 179ca70
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 209 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ authors = ["Dock.io"]
build = "build.rs"
edition = "2021"
name = "dock-node"
version = "0.31.0"
version = "0.32.0"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
Expand All @@ -28,7 +28,7 @@ optional = true

[dependencies.dock-runtime]
path = "../runtime"
version = "0.31.0"
version = "0.32.0"

[dependencies.beefy-primitives]
git = "https://github.com/paritytech/substrate.git"
Expand Down
8 changes: 4 additions & 4 deletions pallets/core/src/modules/accumulator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ crate::did_or_did_method_key! {

let (author, author_kp) = newdid();
let author = AccumulatorOwner(author.into());
let mut next_nonce = 10 + 1;
let mut next_nonce = 1;
check_nonce(&author, next_nonce - 1);

run_to_block(11);

let (author_1, author_1_kp) = newdid();
let author_1 = AccumulatorOwner(author_1.into());
let next_nonce_1 = 11 + 1;
let next_nonce_1 = 1;
check_nonce(&author_1, next_nonce_1 - 1);

run_to_block(30);
Expand Down Expand Up @@ -300,7 +300,7 @@ crate::did_or_did_method_key! {

let (author, author_kp) = newdid();
let author = AccumulatorOwner(author.into());
let mut next_nonce = 10 + 1;
let mut next_nonce = 1;

run_to_block(20);

Expand Down Expand Up @@ -509,7 +509,7 @@ crate::did_or_did_method_key! {
vec![<Test as frame_system::Config>::Hashing::hash(&$id[..])]
)));
assert!(AccumMod::get_accumulator_with_public_key_and_params(&$id).is_none());
next_nonce = next_nonce + 1;
next_nonce += 1;

current_block += 10;
run_to_block(current_block);
Expand Down
44 changes: 22 additions & 22 deletions pallets/core/src/modules/attest/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ crate::did_or_did_method_key! {
Origin::signed(0),
SetAttestationClaim {
attest: att.clone(),
nonce: 10 + 1,
nonce: 1,
},
did_sig::<Test, _, _, _>(
&SetAttestationClaim {
attest: att,
nonce: 10 + 1,
nonce: 1,
},
&kp,
did,
Expand Down Expand Up @@ -82,7 +82,7 @@ crate::did_or_did_method_key! {
let sig = did_sig::<Test, _, _, _>(
&SetAttestationClaim {
attest: att.clone(),
nonce: 10 + 1,
nonce: 1,
},
&kpa,
Attester(dida.into()),
Expand All @@ -94,7 +94,7 @@ crate::did_or_did_method_key! {
Origin::signed(0),
SetAttestationClaim {
attest: att,
nonce: 10 + 2,
nonce: 2,
},
sig,
)
Expand All @@ -119,12 +119,12 @@ crate::did_or_did_method_key! {
Origin::signed(0),
SetAttestationClaim {
attest: att.clone(),
nonce: 10 + 1,
nonce: 1,
},
did_sig::<Test, _, _, _>(
&SetAttestationClaim {
attest: att,
nonce: 10 + 1,
nonce: 1,
},
&kpb,
Attester(dida.into()),
Expand All @@ -144,7 +144,7 @@ crate::did_or_did_method_key! {

let (did, kp) = newdid();
let did = Attester(did.into());
check_nonce(&did, 10);
check_nonce(&did, 0);

// same iri
set_claim(
Expand All @@ -154,10 +154,10 @@ crate::did_or_did_method_key! {
iri: None,
},
&kp,
10 + 1,
1,
)
.unwrap();
check_nonce(&did, 10 + 1);
check_nonce(&did, 1);
assert_eq!(
set_claim(
&did,
Expand All @@ -166,7 +166,7 @@ crate::did_or_did_method_key! {
iri: None,
},
&kp,
11 + 1
2
)
.unwrap_err(),
Er::PriorityTooLow.into()
Expand All @@ -180,10 +180,10 @@ crate::did_or_did_method_key! {
iri: Some(vec![0].try_into().unwrap()),
},
&kp,
11 + 1,
2,
)
.unwrap();
check_nonce(&did, 11 + 1);
check_nonce(&did, 2);

assert_eq!(
set_claim(
Expand All @@ -193,7 +193,7 @@ crate::did_or_did_method_key! {
iri: Some(vec![0, 2, 3].try_into().unwrap()),
},
&kp,
12 + 1
3
)
.unwrap_err(),
Er::PriorityTooLow.into()
Expand All @@ -211,7 +211,7 @@ crate::did_or_did_method_key! {
let (did, kp) = newdid();
let did = Attester(did.into());
let prios: Vec<u64> = (0..200).map(|_| rand::random::<u64>()).collect();
let mut nonce = 10 + 1;
let mut nonce = 1;
for priority in &prios {
check_nonce(&did, nonce - 1);

Expand Down Expand Up @@ -245,7 +245,7 @@ crate::did_or_did_method_key! {

let (did, kp) = newdid();
let did = Attester(did.into());
check_nonce(&did, 10);
check_nonce(&did, 0);

set_claim(
&did,
Expand All @@ -254,18 +254,18 @@ crate::did_or_did_method_key! {
iri: None,
},
&kp,
10 + 1,
1,
)
.unwrap();
check_nonce(&did, 10 + 1);
check_nonce(&did, 1);
let err = set_claim(
&did,
&Attestation {
priority: u64::max_value(),
iri: None,
},
&kp,
11 + 1,
2,
)
.unwrap_err();
assert_eq!(err, Er::PriorityTooLow.into());
Expand All @@ -287,18 +287,18 @@ crate::did_or_did_method_key! {
iri: None,
}
);
check_nonce(&did, 10);
check_nonce(&did, 0);
set_claim(
&did,
&Attestation {
priority: 1,
iri: Some(vec![0, 1, 2].try_into().unwrap()),
},
&kp,
10 + 1,
1,
)
.unwrap();
check_nonce(&did, 10 + 1);
check_nonce(&did, 1);
assert_eq!(
Attestations::<Test>::get(did),
Attestation {
Expand All @@ -318,7 +318,7 @@ crate::did_or_did_method_key! {
let (did, kp) = newdid();
let did = Attester(did.into());
for (i, priority) in [1, 2, 4].iter().enumerate() {
let nonce = 10 + 1 + i as u64;
let nonce = 1 + i as u64;
check_nonce(&did, nonce - 1);
set_claim(
&did,
Expand Down
36 changes: 18 additions & 18 deletions pallets/core/src/modules/blob/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ crate::did_or_did_method_key! {
noise.clone(),
BlobOwner(author.into()),
author_kp,
block_no + 1,
1,
)
.unwrap();
// Can retrieve a valid blob and the blob contents and author match the given ones.
assert_eq!(
Blobs::<Test>::get(id),
Some((BlobOwner(author.into()), noise.try_into().unwrap()))
);
check_nonce(&author, block_no + 1);
check_nonce(&author, 1);
}

ext().execute_with(|| {
Expand All @@ -89,11 +89,11 @@ crate::did_or_did_method_key! {
let noise = random_bytes(size);
let id = BlobId(rand::random());
assert_eq!(Blobs::<Test>::get(id), None);
check_nonce(&author, block_no);
check_nonce(&author, 0);
assert!(
create_blob(id, noise, BlobOwner(author.into()), author_kp, block_no + 1).is_err()
create_blob(id, noise, BlobOwner(author.into()), author_kp, 1).is_err()
);
check_nonce(&author, block_no);
check_nonce(&author, 0);
}

ext().execute_with(|| {
Expand All @@ -111,26 +111,26 @@ crate::did_or_did_method_key! {
let id = BlobId(rand::random());
let (author, author_kp) = newdid();
assert_eq!(Blobs::<Test>::get(id), None);
check_nonce(&author, 10);
check_nonce(&author, 0);
create_blob(
id,
random_bytes(10),
BlobOwner(author.into()),
author_kp.clone(),
10 + 1,
1,
)
.unwrap();
check_nonce(&author, 10 + 1);
check_nonce(&author, 1);
let err = create_blob(
id,
random_bytes(10),
BlobOwner(author.into()),
author_kp,
11 + 1,
2,
)
.unwrap_err();
assert_eq!(err, Error::<Test>::BlobAlreadyExists.into());
check_nonce(&author, 10 + 1);
check_nonce(&author, 1);
});
}

Expand All @@ -142,7 +142,7 @@ crate::did_or_did_method_key! {
// Adding a blob with an unregistered DID fails with error DidDoesNotExist.
let author = BlobOwner(Did(rand::random()).into());
let author_kp = gen_kp();
let err = create_blob(BlobId(rand::random()), random_bytes(10), author, author_kp, 10 + 1)
let err = create_blob(BlobId(rand::random()), random_bytes(10), author, author_kp, 1)
.unwrap_err();
assert_eq!(err, did::Error::<Test>::NoKeyForDid.into());
});
Expand All @@ -166,18 +166,18 @@ crate::did_or_did_method_key! {
},
nonce: 10 + 1,
};
check_nonce(&author, 10);
check_nonce(&author, 0);
let err = BlobMod::new(
Origin::signed(ABBA),
AddBlob {
blob: bl,
nonce: 10 + 1,
nonce: 1,
},
did_sig(&att, &author_kp, BlobOwner(author.into()), 1),
)
.unwrap_err();
assert_eq!(err, did::Error::<Test>::InvalidSignature.into());
check_nonce(&author, 10);
check_nonce(&author, 0);
}

{
Expand All @@ -190,17 +190,17 @@ crate::did_or_did_method_key! {
id: BlobId(rand::random()),
blob: random_bytes(10).try_into().unwrap(),
};
check_nonce(&author, 20);
check_nonce(&author, 0);
let err = BlobMod::new(
Origin::signed(ABBA),
AddBlob {
blob: bl.clone(),
nonce: 20 + 1,
nonce: 1,
},
did_sig::<Test, _, _, _>(
&AddBlob {
blob: bl,
nonce: 20 + 1,
nonce: 1,
},
&author_kp,
BlobOwner(author.into()),
Expand All @@ -209,7 +209,7 @@ crate::did_or_did_method_key! {
)
.unwrap_err();
assert_eq!(err, did::Error::<Test>::InvalidSignature.into());
check_nonce(&author, 20);
check_nonce(&author, 0);
}
})
}
Expand Down
Loading

0 comments on commit 179ca70

Please sign in to comment.