diff --git a/Cargo.lock b/Cargo.lock index 63cffe5b0..236c52d25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1582,7 +1582,7 @@ dependencies = [ [[package]] name = "dock-node" -version = "0.31.0" +version = "0.32.0" dependencies = [ "async-trait", "beefy-gadget", @@ -1808,7 +1808,7 @@ dependencies = [ [[package]] name = "dock-runtime" -version = "0.31.0" +version = "0.32.0" dependencies = [ "beefy-merkle-tree", "beefy-primitives", diff --git a/node/Cargo.toml b/node/Cargo.toml index 12758ea50..dacbe1b19 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -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"] @@ -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" diff --git a/pallets/core/src/modules/accumulator/tests.rs b/pallets/core/src/modules/accumulator/tests.rs index 8e0419430..43d45b3f0 100644 --- a/pallets/core/src/modules/accumulator/tests.rs +++ b/pallets/core/src/modules/accumulator/tests.rs @@ -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); @@ -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); @@ -509,7 +509,7 @@ crate::did_or_did_method_key! { vec![::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); diff --git a/pallets/core/src/modules/attest/tests.rs b/pallets/core/src/modules/attest/tests.rs index 604d0da5f..44dd6252d 100644 --- a/pallets/core/src/modules/attest/tests.rs +++ b/pallets/core/src/modules/attest/tests.rs @@ -23,12 +23,12 @@ crate::did_or_did_method_key! { Origin::signed(0), SetAttestationClaim { attest: att.clone(), - nonce: 10 + 1, + nonce: 1, }, did_sig::( &SetAttestationClaim { attest: att, - nonce: 10 + 1, + nonce: 1, }, &kp, did, @@ -82,7 +82,7 @@ crate::did_or_did_method_key! { let sig = did_sig::( &SetAttestationClaim { attest: att.clone(), - nonce: 10 + 1, + nonce: 1, }, &kpa, Attester(dida.into()), @@ -94,7 +94,7 @@ crate::did_or_did_method_key! { Origin::signed(0), SetAttestationClaim { attest: att, - nonce: 10 + 2, + nonce: 2, }, sig, ) @@ -119,12 +119,12 @@ crate::did_or_did_method_key! { Origin::signed(0), SetAttestationClaim { attest: att.clone(), - nonce: 10 + 1, + nonce: 1, }, did_sig::( &SetAttestationClaim { attest: att, - nonce: 10 + 1, + nonce: 1, }, &kpb, Attester(dida.into()), @@ -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( @@ -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, @@ -166,7 +166,7 @@ crate::did_or_did_method_key! { iri: None, }, &kp, - 11 + 1 + 2 ) .unwrap_err(), Er::PriorityTooLow.into() @@ -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( @@ -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() @@ -211,7 +211,7 @@ crate::did_or_did_method_key! { let (did, kp) = newdid(); let did = Attester(did.into()); let prios: Vec = (0..200).map(|_| rand::random::()).collect(); - let mut nonce = 10 + 1; + let mut nonce = 1; for priority in &prios { check_nonce(&did, nonce - 1); @@ -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, @@ -254,10 +254,10 @@ 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 { @@ -265,7 +265,7 @@ crate::did_or_did_method_key! { iri: None, }, &kp, - 11 + 1, + 2, ) .unwrap_err(); assert_eq!(err, Er::PriorityTooLow.into()); @@ -287,7 +287,7 @@ crate::did_or_did_method_key! { iri: None, } ); - check_nonce(&did, 10); + check_nonce(&did, 0); set_claim( &did, &Attestation { @@ -295,10 +295,10 @@ crate::did_or_did_method_key! { 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::::get(did), Attestation { @@ -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, diff --git a/pallets/core/src/modules/blob/tests.rs b/pallets/core/src/modules/blob/tests.rs index 7dae8b64b..86e99fb05 100644 --- a/pallets/core/src/modules/blob/tests.rs +++ b/pallets/core/src/modules/blob/tests.rs @@ -59,7 +59,7 @@ 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. @@ -67,7 +67,7 @@ crate::did_or_did_method_key! { Blobs::::get(id), Some((BlobOwner(author.into()), noise.try_into().unwrap())) ); - check_nonce(&author, block_no + 1); + check_nonce(&author, 1); } ext().execute_with(|| { @@ -89,11 +89,11 @@ crate::did_or_did_method_key! { let noise = random_bytes(size); let id = BlobId(rand::random()); assert_eq!(Blobs::::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(|| { @@ -111,26 +111,26 @@ crate::did_or_did_method_key! { let id = BlobId(rand::random()); let (author, author_kp) = newdid(); assert_eq!(Blobs::::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::::BlobAlreadyExists.into()); - check_nonce(&author, 10 + 1); + check_nonce(&author, 1); }); } @@ -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::::NoKeyForDid.into()); }); @@ -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::::InvalidSignature.into()); - check_nonce(&author, 10); + check_nonce(&author, 0); } { @@ -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::( &AddBlob { blob: bl, - nonce: 20 + 1, + nonce: 1, }, &author_kp, BlobOwner(author.into()), @@ -209,7 +209,7 @@ crate::did_or_did_method_key! { ) .unwrap_err(); assert_eq!(err, did::Error::::InvalidSignature.into()); - check_nonce(&author, 20); + check_nonce(&author, 0); } }) } diff --git a/pallets/core/src/modules/did/tests.rs b/pallets/core/src/modules/did/tests.rs index 84488ffc2..1fc536e11 100644 --- a/pallets/core/src/modules/did/tests.rs +++ b/pallets/core/src/modules/did/tests.rs @@ -185,7 +185,7 @@ fn onchain_keyless_did_creation() { assert!(!DIDModule::is_controller(&did_1, &controller_2)); assert!(DIDModule::is_controller(&did_1, &controller_1)); - check_did_detail(&did_1, 0, 0, 1, 20); + check_did_detail(&did_1, 0, 0, 1, 0); assert_noop!( DIDModule::new_onchain( @@ -215,7 +215,7 @@ fn onchain_keyless_did_creation() { assert!(DIDModule::is_controller(&did_2, &controller_1)); assert!(DIDModule::is_controller(&did_2, &controller_2)); - check_did_detail(&did_2, 0, 0, 3, 55); + check_did_detail(&did_2, 0, 0, 3, 0); }); } @@ -255,7 +255,7 @@ fn onchain_keyed_did_creation_with_self_control() { vec![].into_iter().collect() )); assert!(DIDModule::is_self_controlled(&did_1)); - check_did_detail(&did_1, 1, 1, 1, 5); + check_did_detail(&did_1, 1, 1, 1, 0); let key_1 = DidKeys::::get(did_1, IncId::from(1u32)).unwrap(); not_key_agreement(&key_1); @@ -277,7 +277,7 @@ fn onchain_keyed_did_creation_with_self_control() { .collect() )); assert!(DIDModule::is_self_controlled(&did_2)); - check_did_detail(&did_2, 1, 1, 2, 6); + check_did_detail(&did_2, 1, 1, 2, 0); let key_2 = DidKeys::::get(did_2, IncId::from(1u32)).unwrap(); not_key_agreement(&key_2); @@ -296,7 +296,7 @@ fn onchain_keyed_did_creation_with_self_control() { .collect() )); assert!(DIDModule::is_self_controlled(&did_3)); - check_did_detail(&did_3, 1, 1, 3, 7); + check_did_detail(&did_3, 1, 1, 3, 0); let key_3 = DidKeys::::get(did_3, IncId::from(1u32)).unwrap(); not_key_agreement(&key_3); @@ -314,7 +314,7 @@ fn onchain_keyed_did_creation_with_self_control() { vec![Controller(did_3.into())].into_iter().collect() )); assert!(!DIDModule::is_self_controlled(&did_4)); - check_did_detail(&did_4, 1, 0, 1, 8); + check_did_detail(&did_4, 1, 0, 1, 0); // x25519 key cannot be added for incompatible relationship types for add in [VerRelType::NONE, VerRelType::KEY_AGREEMENT] { @@ -393,7 +393,7 @@ fn onchain_keyed_did_creation_with_self_control() { assert!(key.can_control()); assert!(key.can_authenticate_or_control()); assert!(!key.for_key_agreement()); - check_did_detail(&did, 1, 1, 1, 10); + check_did_detail(&did, 1, 1, 1, 0); } run_to_block(13); @@ -439,7 +439,7 @@ fn onchain_keyed_did_creation_with_self_control() { assert!(key.can_authenticate_or_control()); } assert!(!key.for_key_agreement()); - check_did_detail(&did, 1, 0, 1, 13); + check_did_detail(&did, 1, 0, 1, 0); } run_to_block(19); @@ -459,7 +459,7 @@ fn onchain_keyed_did_creation_with_self_control() { assert!(key_8.can_sign()); assert!(key_8.can_authenticate()); assert!(!key_8.can_control()); - check_did_detail(&did_8, 1, 0, 1, 19); + check_did_detail(&did_8, 1, 0, 1, 0); run_to_block(20); @@ -487,7 +487,7 @@ fn onchain_keyed_did_creation_with_self_control() { assert!(key_9_3.can_sign()); assert!(key_9_3.can_authenticate()); assert!(!key_9_3.can_control()); - check_did_detail(&did_9, 3, 0, 1, 20); + check_did_detail(&did_9, 3, 0, 1, 0); run_to_block(22); @@ -518,7 +518,7 @@ fn onchain_keyed_did_creation_with_self_control() { assert!(key_10_3.can_sign()); assert!(!key_10_3.can_authenticate()); assert!(key_10_3.can_control()); - check_did_detail(&did_10, 3, 1, 1, 22); + check_did_detail(&did_10, 3, 1, 1, 0); run_to_block(23); @@ -548,7 +548,7 @@ fn onchain_keyed_did_creation_with_self_control() { assert!(key_11_2.can_sign()); assert!(!key_11_2.can_authenticate()); assert!(key_11_2.can_control()); - check_did_detail(&did_11, 2, 1, 3, 23); + check_did_detail(&did_11, 2, 1, 3, 0); }); } @@ -589,7 +589,7 @@ fn onchain_keyed_did_creation_with_and_without_self_control() { )); assert!(!DIDModule::is_self_controlled(&did_1)); assert!(DIDModule::is_controller(&did_1, &controller_1)); - check_did_detail(&did_1, 1, 0, 1, 10); + check_did_detail(&did_1, 1, 0, 1, 0); run_to_block(11); @@ -605,7 +605,7 @@ fn onchain_keyed_did_creation_with_and_without_self_control() { )); assert!(!DIDModule::is_self_controlled(&did_2)); assert!(DIDModule::is_controller(&did_2, &controller_2)); - check_did_detail(&did_2, 1, 0, 1, 11); + check_did_detail(&did_2, 1, 0, 1, 0); run_to_block(12); @@ -621,7 +621,7 @@ fn onchain_keyed_did_creation_with_and_without_self_control() { )); assert!(!DIDModule::is_self_controlled(&did_3)); assert!(DIDModule::is_controller(&did_3, &controller_3)); - check_did_detail(&did_3, 1, 0, 1, 12); + check_did_detail(&did_3, 1, 0, 1, 0); run_to_block(13); @@ -637,7 +637,7 @@ fn onchain_keyed_did_creation_with_and_without_self_control() { )); assert!(!DIDModule::is_self_controlled(&did_4)); assert!(DIDModule::is_controller(&did_4, &controller_4)); - check_did_detail(&did_4, 2, 0, 1, 13); + check_did_detail(&did_4, 2, 0, 1, 0); run_to_block(14); @@ -656,7 +656,7 @@ fn onchain_keyed_did_creation_with_and_without_self_control() { )); assert!(DIDModule::is_self_controlled(&did_5)); assert!(DIDModule::is_controller(&did_5, &controller_1)); - check_did_detail(&did_5, 2, 1, 2, 14); + check_did_detail(&did_5, 2, 1, 2, 0); run_to_block(15); @@ -678,7 +678,7 @@ fn onchain_keyed_did_creation_with_and_without_self_control() { )); assert!(DIDModule::is_self_controlled(&did_6)); assert!(DIDModule::is_controller(&did_6, &controller_1)); - check_did_detail(&did_6, 2, 2, 2, 15); + check_did_detail(&did_6, 2, 2, 2, 0); }); } @@ -709,7 +709,7 @@ fn add_keys_to_did() { PublicKey::sr25519(pk_sr_1), VerRelType::NONE, )], - nonce: 4, + nonce: 1, }; let sig = SigValue::sr25519(&add_keys.to_state_change().encode(), &pair_sr_1); assert_noop!( @@ -732,7 +732,7 @@ fn add_keys_to_did() { let add_keys = AddKeys { did: did_1, keys: vec![], - nonce: 5, + nonce: 1, }; let sig = SigValue::sr25519(&add_keys.to_state_change().encode(), &pair_sr_1); assert_noop!( @@ -761,7 +761,7 @@ fn add_keys_to_did() { PublicKey::sr25519(pk_sr_1), VerRelType::NONE, )], - nonce: 5, + nonce: 1, }; let sig = SigValue::sr25519(&add_keys.to_state_change().encode(), &pair_sr_1); assert_noop!( @@ -789,7 +789,7 @@ fn add_keys_to_did() { vec![].into_iter().collect() )); assert!(DIDModule::is_self_controlled(&did_1)); - check_did_detail(&did_1, 3, 2, 1, 5); + check_did_detail(&did_1, 3, 2, 1, 0); run_to_block(7); @@ -808,7 +808,7 @@ fn add_keys_to_did() { .collect() )); assert!(!DIDModule::is_self_controlled(&did_2)); - check_did_detail(&did_2, 1, 0, 1, 7); + check_did_detail(&did_2, 1, 0, 1, 0); run_to_block(10); @@ -816,7 +816,7 @@ fn add_keys_to_did() { let add_keys = AddKeys { did: did_2, keys: vec![UncheckedDidKey::new(pk_secp_1, VerRelType::NONE)], - nonce: 5 + 1, + nonce: 1, }; let sig = SigValue::ed25519(&add_keys.to_state_change().encode(), &pair_ed_1); assert_noop!( @@ -860,7 +860,7 @@ fn add_keys_to_did() { let add_keys = AddKeys { did: did_2, keys: vec![UncheckedDidKey::new(pk_secp_1, VerRelType::NONE)], - nonce: 5 + 1, + nonce: 1, }; // Using some arbitrary bytes as signature let sig = SigValue::Sr25519([109; 64].into()); @@ -882,7 +882,7 @@ fn add_keys_to_did() { let add_keys = AddKeys { did: did_2, keys: vec![UncheckedDidKey::new(pk_secp_1, VerRelType::NONE)], - nonce: 5 + 1, + nonce: 1, }; let sig = SigValue::sr25519(&add_keys.to_state_change().encode(), &pair_sr_1); assert_noop!( @@ -927,7 +927,7 @@ fn add_keys_to_did() { let add_keys = AddKeys { did: did_2, keys: vec![key], - nonce: 5 + 1, + nonce: 1, }; let sig = SigValue::sr25519(&add_keys.to_state_change().encode(), &pair_sr_1); assert_noop!( @@ -963,7 +963,7 @@ fn add_keys_to_did() { let add_keys = AddKeys { did: did_2, keys: vec![key], - nonce: 5 + 1, + nonce: 1, }; let sig = SigValue::sr25519(&add_keys.to_state_change().encode(), &pair_sr_1); assert_noop!( @@ -989,7 +989,7 @@ fn add_keys_to_did() { PublicKey::x25519(pk_ed_1), VerRelType::KEY_AGREEMENT, )], - nonce: 5 + 1, + nonce: 1, }; let sig = SigValue::sr25519(&add_keys.to_state_change().encode(), &pair_sr_1); assert_ok!(DIDModule::add_keys( @@ -1003,8 +1003,8 @@ fn add_keys_to_did() { .into() )); assert!(!DIDModule::is_self_controlled(&did_2)); - check_did_detail(&did_2, 2, 0, 1, 7); - check_did_detail(&did_1, 3, 2, 1, 6); + check_did_detail(&did_2, 2, 0, 1, 0); + check_did_detail(&did_1, 3, 2, 1, 1); only_key_agreement(&DidKeys::::get(did_2, IncId::from(2u32)).unwrap()); @@ -1019,7 +1019,7 @@ fn add_keys_to_did() { VerRelType::AUTHENTICATION | VerRelType::ASSERTION, ), ], - nonce: 6 + 1, + nonce: 2, }; // Controller uses a key without the capability to update DID @@ -1051,8 +1051,8 @@ fn add_keys_to_did() { .into() )); assert!(!DIDModule::is_self_controlled(&did_2)); - check_did_detail(&did_2, 5, 0, 1, 7); - check_did_detail(&did_1, 3, 2, 1, 7); + check_did_detail(&did_2, 5, 0, 1, 0); + check_did_detail(&did_1, 3, 2, 1, 2); DidKeys::::get(did_2, IncId::from(3u32)).unwrap(); DidKeys::::get(did_2, IncId::from(4u32)).unwrap(); DidKeys::::get(did_2, IncId::from(5u32)).unwrap(); @@ -1063,7 +1063,7 @@ fn add_keys_to_did() { PublicKey::ed25519(pk_ed_1), VerRelType::NONE, )], - nonce: 7 + 1, + nonce: 3, }; let sig = SigValue::sr25519(&add_keys.to_state_change().encode(), &pair_sr_1); assert_ok!(DIDModule::add_keys( @@ -1077,7 +1077,7 @@ fn add_keys_to_did() { .into() )); - check_did_detail(&did_1, 4, 3, 1, 8); + check_did_detail(&did_1, 4, 3, 1, 3); DidKeys::::get(did_1, IncId::from(4u32)).unwrap() }); } @@ -1111,7 +1111,7 @@ fn remove_keys_from_did() { vec![].into_iter().collect() )); assert!(DIDModule::is_self_controlled(&did_1)); - check_did_detail(&did_1, 4, 2, 1, 2); + check_did_detail(&did_1, 4, 2, 1, 0); run_to_block(5); @@ -1129,12 +1129,12 @@ fn remove_keys_from_did() { .map(Controller) .collect() )); - check_did_detail(&did_2, 1, 0, 1, 5); + check_did_detail(&did_2, 1, 0, 1, 0); run_to_block(10); // Nonce should be 1 greater than existing 2, i.e. 3 - for nonce in [1, 2, 4, 5, 6, 7, 8, 10, 10000] { + for nonce in [2, 4, 5, 6, 7, 8, 10, 10000] { let remove_keys = RemoveKeys { did: did_2, keys: vec![1u32.into()].into_iter().collect(), @@ -1160,7 +1160,7 @@ fn remove_keys_from_did() { let remove_keys = RemoveKeys { did: did_2, keys: vec![1u32.into()].into_iter().collect(), - nonce: 5 + 1, + nonce: 1, }; let sig = SigValue::ed25519(&remove_keys.to_state_change().encode(), &pair_ed_1); assert_noop!( @@ -1180,7 +1180,7 @@ fn remove_keys_from_did() { let remove_keys = RemoveKeys { did: did_1, keys: vec![1u32.into()].into_iter().collect(), - nonce: 2 + 1, + nonce: 1, }; let sig = SigValue::ed25519(&remove_keys.to_state_change().encode(), &pair_ed_1); assert_ok!(DIDModule::remove_keys( @@ -1193,12 +1193,12 @@ fn remove_keys_from_did() { } .into() )); - check_did_detail(&did_1, 4, 1, 1, 3); + check_did_detail(&did_1, 4, 1, 1, 1); let remove_keys = RemoveKeys { did: did_1, keys: vec![3u32.into()].into_iter().collect(), - nonce: 3 + 1, + nonce: 2, }; let sig = SigValue::ed25519(&remove_keys.to_state_change().encode(), &pair_ed_1); assert_ok!(DIDModule::remove_keys( @@ -1211,12 +1211,12 @@ fn remove_keys_from_did() { } .into() )); - check_did_detail(&did_1, 4, 1, 1, 4); + check_did_detail(&did_1, 4, 1, 1, 2); let remove_keys = RemoveKeys { did: did_2, keys: vec![1u32.into()].into_iter().collect(), - nonce: 4 + 1, + nonce: 3, }; let sig = SigValue::ed25519(&remove_keys.to_state_change().encode(), &pair_ed_1); assert_ok!(DIDModule::remove_keys( @@ -1229,8 +1229,8 @@ fn remove_keys_from_did() { } .into() )); - check_did_detail(&did_1, 4, 1, 1, 5); - check_did_detail(&did_2, 1, 0, 1, 5); + check_did_detail(&did_1, 4, 1, 1, 3); + check_did_detail(&did_2, 1, 0, 1, 0); run_to_block(30); @@ -1250,12 +1250,12 @@ fn remove_keys_from_did() { .map(Controller) .collect() )); - check_did_detail(&did_5, 1, 1, 2, 30); + check_did_detail(&did_5, 1, 1, 2, 0); let remove_keys = RemoveKeys { did: did_5, keys: vec![1u32.into()].into_iter().collect(), - nonce: 5 + 1, + nonce: 4, }; let sig = SigValue::ed25519(&remove_keys.to_state_change().encode(), &pair_ed_1); assert_ok!(DIDModule::remove_keys( @@ -1268,8 +1268,8 @@ fn remove_keys_from_did() { } .into() )); - check_did_detail(&did_5, 1, 0, 1, 30); - check_did_detail(&did_1, 4, 1, 1, 6); + check_did_detail(&did_5, 1, 0, 1, 0); + check_did_detail(&did_1, 4, 1, 1, 4); let remove_controllers = RemoveControllers { did: did_5, @@ -1278,7 +1278,7 @@ fn remove_keys_from_did() { .map(DidOrDidMethodKey::from) .map(Controller) .collect(), - nonce: 6 + 1, + nonce: 5, }; let sig = SigValue::ed25519(&remove_controllers.to_state_change().encode(), &pair_ed_1); assert_ok!(DIDModule::remove_controllers( @@ -1291,8 +1291,8 @@ fn remove_keys_from_did() { } .into() )); - check_did_detail(&did_5, 1, 0, 0, 30); - check_did_detail(&did_1, 4, 1, 1, 7); + check_did_detail(&did_5, 1, 0, 0, 0); + check_did_detail(&did_1, 4, 1, 1, 5); }); } @@ -1327,7 +1327,7 @@ fn remove_controllers_from_did() { Default::default() )); assert!(DIDModule::is_self_controlled(&did_1)); - check_did_detail(&did_1, 4, 2, 1, 2); + check_did_detail(&did_1, 4, 2, 1, 0); run_to_block(5); @@ -1345,7 +1345,7 @@ fn remove_controllers_from_did() { .map(Controller) .collect() )); - check_did_detail(&did_2, 1, 0, 1, 5); + check_did_detail(&did_2, 1, 0, 1, 0); // This DID has no keys but controlled by other DIDs assert_ok!(DIDModule::new_onchain( @@ -1358,12 +1358,12 @@ fn remove_controllers_from_did() { .map(Controller) .collect() )); - check_did_detail(&did_3, 0, 0, 2, 5); + check_did_detail(&did_3, 0, 0, 2, 0); run_to_block(10); // Nonce should be 1 greater than existing 2, i.e. 3 - for nonce in [1, 2, 4, 5, 10, 10000] { + for nonce in [2, 4, 5, 10, 10000] { let remove_controllers = RemoveControllers { did: did_2, controllers: vec![did_1] @@ -1397,7 +1397,7 @@ fn remove_controllers_from_did() { .map(DidOrDidMethodKey::from) .map(Controller) .collect(), - nonce: 3, + nonce: 1, }; let sig = SigValue::ed25519(&remove_controllers.to_state_change().encode(), &pair_ed_1); assert_noop!( @@ -1422,7 +1422,7 @@ fn remove_controllers_from_did() { .map(DidOrDidMethodKey::from) .map(Controller) .collect(), - nonce: 5 + 1, + nonce: 1, }; let sig = SigValue::ed25519(&remove_controllers.to_state_change().encode(), &pair_ed_1); assert_noop!( @@ -1446,7 +1446,7 @@ fn remove_controllers_from_did() { .map(DidOrDidMethodKey::from) .map(Controller) .collect(), - nonce: 3, + nonce: 1, }; let sig = SigValue::ed25519(&remove_controllers.to_state_change().encode(), &pair_ed_1); assert_ok!(DIDModule::remove_controllers( @@ -1460,7 +1460,7 @@ fn remove_controllers_from_did() { .into() )); assert!(!DIDModule::is_self_controlled(&did_1)); - check_did_detail(&did_1, 4, 2, 0, 3); + check_did_detail(&did_1, 4, 2, 0, 1); assert!(DIDModule::is_controller(&did_3, &Controller(did_2.into()))); let remove_controllers = RemoveControllers { @@ -1470,7 +1470,7 @@ fn remove_controllers_from_did() { .map(DidOrDidMethodKey::from) .map(Controller) .collect(), - nonce: 3 + 1, + nonce: 2, }; let sig = SigValue::sr25519(&remove_controllers.to_state_change().encode(), &pair_sr_1); assert_ok!(DIDModule::remove_controllers( @@ -1484,8 +1484,8 @@ fn remove_controllers_from_did() { .into() )); assert!(!DIDModule::is_controller(&did_3, &Controller(did_2.into()))); - check_did_detail(&did_1, 4, 2, 0, 4); - check_did_detail(&did_3, 0, 0, 1, 5); + check_did_detail(&did_1, 4, 2, 0, 2); + check_did_detail(&did_3, 0, 0, 1, 0); }); } @@ -1513,7 +1513,7 @@ fn add_controllers_to_did() { let add_controllers = AddControllers { did: did_1, controllers: vec![].into_iter().collect(), - nonce: 5, + nonce: 1, }; let sig = SigValue::sr25519(&add_controllers.to_state_change().encode(), &pair_sr); assert_noop!( @@ -1537,7 +1537,7 @@ fn add_controllers_to_did() { .map(DidOrDidMethodKey::from) .map(Controller) .collect(), - nonce: 5, + nonce: 1, }; let sig = SigValue::sr25519(&add_controllers.to_state_change().encode(), &pair_sr); assert_noop!( @@ -1565,7 +1565,7 @@ fn add_controllers_to_did() { vec![].into_iter().collect() )); assert!(DIDModule::is_self_controlled(&did_1)); - check_did_detail(&did_1, 2, 1, 1, 5); + check_did_detail(&did_1, 2, 1, 1, 0); run_to_block(6); @@ -1582,7 +1582,7 @@ fn add_controllers_to_did() { )); assert!(DIDModule::is_self_controlled(&did_1)); - check_did_detail(&did_3, 1, 1, 2, 6); + check_did_detail(&did_3, 1, 1, 2, 0); run_to_block(10); // This DID does not control itself @@ -1601,7 +1601,7 @@ fn add_controllers_to_did() { )); assert!(!DIDModule::is_self_controlled(&did_2)); assert!(DIDModule::is_controller(&did_2, &Controller(did_1.into()))); - check_did_detail(&did_2, 1, 0, 1, 10); + check_did_detail(&did_2, 1, 0, 1, 0); run_to_block(15); @@ -1613,7 +1613,7 @@ fn add_controllers_to_did() { .map(DidOrDidMethodKey::from) .map(Controller) .collect(), - nonce: 10 + 1, + nonce: 1, }; let sig = SigValue::sr25519(&add_controllers.to_state_change().encode(), &pair_sr); assert_noop!( @@ -1665,7 +1665,7 @@ fn add_controllers_to_did() { .map(DidOrDidMethodKey::from) .map(Controller) .collect(), - nonce: 5 + 1, + nonce: 1, }; let sig = SigValue::Secp256k1([35; 65].into()); assert_noop!( @@ -1696,8 +1696,8 @@ fn add_controllers_to_did() { )); assert!(!DIDModule::is_self_controlled(&did_2)); assert!(DIDModule::is_controller(&did_2, &Controller(did_3.into()))); - check_did_detail(&did_1, 2, 1, 1, 6); - check_did_detail(&did_2, 1, 0, 2, 10); + check_did_detail(&did_1, 2, 1, 1, 1); + check_did_detail(&did_2, 1, 0, 2, 0); run_to_block(15); @@ -1709,7 +1709,7 @@ fn add_controllers_to_did() { .map(DidOrDidMethodKey::from) .map(Controller) .collect(), - nonce: 6 + 1, + nonce: 1, }; let sig = SigValue::secp256k1(&add_controllers.to_state_change().encode(), &sk_secp_2); assert_ok!(DIDModule::add_controllers( @@ -1725,8 +1725,8 @@ fn add_controllers_to_did() { assert!(!DIDModule::is_self_controlled(&did_2)); assert!(DIDModule::is_controller(&did_2, &Controller(did_4.into()))); assert!(DIDModule::is_controller(&did_2, &Controller(did_5.into()))); - check_did_detail(&did_3, 1, 1, 2, 7); - check_did_detail(&did_2, 1, 0, 4, 10); + check_did_detail(&did_3, 1, 1, 2, 1); + check_did_detail(&did_2, 1, 0, 4, 0); // Add controllers to self let add_controllers = AddControllers { @@ -1736,7 +1736,7 @@ fn add_controllers_to_did() { .map(DidOrDidMethodKey::from) .map(Controller) .collect(), - nonce: 7 + 1, + nonce: 2, }; let sig = SigValue::secp256k1(&add_controllers.to_state_change().encode(), &sk_secp_2); assert_ok!(DIDModule::add_controllers( @@ -1751,7 +1751,7 @@ fn add_controllers_to_did() { )); assert!(DIDModule::is_controller(&did_3, &Controller(did_4.into()))); assert!(DIDModule::is_controller(&did_3, &Controller(did_5.into()))); - check_did_detail(&did_3, 1, 1, 4, 8); + check_did_detail(&did_3, 1, 1, 4, 2); }); } @@ -1781,7 +1781,7 @@ fn becoming_controller() { )], vec![].into_iter().collect() )); - check_did_detail(&did_1, 1, 1, 1, 5); + check_did_detail(&did_1, 1, 1, 1, 0); run_to_block(10); @@ -1799,7 +1799,7 @@ fn becoming_controller() { .collect() )); assert!(!DIDModule::is_self_controlled(&did_2)); - check_did_detail(&did_2, 1, 0, 1, 10); + check_did_detail(&did_2, 1, 0, 1, 0); run_to_block(15); @@ -1809,7 +1809,7 @@ fn becoming_controller() { PublicKey::ed25519(pk_ed), VerRelType::ASSERTION, )], - nonce: 5 + 1, + nonce: 1, }; let sig = SigValue::sr25519(&add_keys.to_state_change().encode(), &pair_sr); assert_ok!(DIDModule::add_keys( @@ -1823,8 +1823,8 @@ fn becoming_controller() { .into() )); assert!(!DIDModule::is_self_controlled(&did_2)); - check_did_detail(&did_2, 2, 0, 1, 10); - check_did_detail(&did_1, 1, 1, 1, 6); + check_did_detail(&did_2, 2, 0, 1, 0); + check_did_detail(&did_1, 1, 1, 1, 1); run_to_block(20); @@ -1834,7 +1834,7 @@ fn becoming_controller() { pk_secp, VerRelType::CAPABILITY_INVOCATION, )], - nonce: 6 + 1, + nonce: 2, }; let sig = SigValue::sr25519(&add_keys.to_state_change().encode(), &pair_sr); assert_ok!(DIDModule::add_keys( @@ -1848,8 +1848,8 @@ fn becoming_controller() { .into() )); assert!(DIDModule::is_self_controlled(&did_2)); - check_did_detail(&did_2, 3, 1, 2, 10); - check_did_detail(&did_1, 1, 1, 1, 7); + check_did_detail(&did_2, 3, 1, 2, 0); + check_did_detail(&did_1, 1, 1, 1, 2); }); } @@ -1895,7 +1895,7 @@ fn any_controller_can_update() { vec![].into_iter().collect() )); assert!(DIDModule::is_self_controlled(&did_1)); - check_did_detail(&did_1, 1, 1, 1, 3); + check_did_detail(&did_1, 1, 1, 1, 0); run_to_block(5); @@ -1909,7 +1909,7 @@ fn any_controller_can_update() { vec![].into_iter().collect() )); assert!(DIDModule::is_self_controlled(&did_2)); - check_did_detail(&did_2, 1, 1, 1, 5); + check_did_detail(&did_2, 1, 1, 1, 0); assert_ok!(DIDModule::new_onchain( Origin::signed(alice), @@ -1918,7 +1918,7 @@ fn any_controller_can_update() { vec![].into_iter().collect() )); assert!(DIDModule::is_self_controlled(&did_3)); - check_did_detail(&did_3, 1, 1, 1, 5); + check_did_detail(&did_3, 1, 1, 1, 0); run_to_block(7); @@ -1933,7 +1933,7 @@ fn any_controller_can_update() { .collect() )); assert!(DIDModule::is_self_controlled(&did_4)); - check_did_detail(&did_4, 1, 1, 2, 7); + check_did_detail(&did_4, 1, 1, 2, 0); run_to_block(14); @@ -1944,7 +1944,7 @@ fn any_controller_can_update() { .map(DidOrDidMethodKey::from) .map(Controller) .collect(), - nonce: 5 + 1, + nonce: 1, }; let sig = SigValue::sr25519(&add_controllers.to_state_change().encode(), &pair_sr); assert_ok!(DIDModule::add_controllers( @@ -1957,8 +1957,8 @@ fn any_controller_can_update() { } .into() )); - check_did_detail(&did_4, 1, 1, 3, 7); - check_did_detail(&did_2, 1, 1, 1, 6); + check_did_detail(&did_4, 1, 1, 3, 0); + check_did_detail(&did_2, 1, 1, 1, 1); run_to_block(15); @@ -1968,7 +1968,7 @@ fn any_controller_can_update() { PublicKey::sr25519(pk_sr), VerRelType::NONE, )], - nonce: 3 + 1, + nonce: 1, }; let sig = SigValue::ed25519(&add_keys.to_state_change().encode(), &pair_ed); assert_ok!(DIDModule::add_keys( @@ -1981,8 +1981,8 @@ fn any_controller_can_update() { } .into() )); - check_did_detail(&did_4, 2, 2, 3, 7); - check_did_detail(&did_1, 1, 1, 1, 4); + check_did_detail(&did_4, 2, 2, 3, 0); + check_did_detail(&did_1, 1, 1, 1, 1); }); } @@ -2018,7 +2018,7 @@ fn service_endpoints() { types: ServiceEndpointType::LINKED_DOMAINS, origins: origins_1.clone().try_into().unwrap(), }, - nonce: 5 + 1, + nonce: 1, }; let sig = SigValue::sr25519(&add_service_endpoint.to_state_change().encode(), &pair_sr); @@ -2050,7 +2050,7 @@ fn service_endpoints() { vec![].into_iter().collect() )); assert!(DIDModule::is_self_controlled(&did)); - check_did_detail(&did, 2, 1, 1, 5); + check_did_detail(&did, 2, 1, 1, 0); run_to_block(10); @@ -2062,7 +2062,7 @@ fn service_endpoints() { types: ServiceEndpointType::LINKED_DOMAINS, origins: origins_1.clone().try_into().unwrap(), }, - nonce: 5 + 1, + nonce: 1, }; let sig = SigValue::ed25519(&add_service_endpoint.to_state_change().encode(), &pair_ed); @@ -2147,7 +2147,7 @@ fn service_endpoints() { did, id, endpoint: ep, - nonce: 5 + 1, + nonce: 1, }; let sig = SigValue::sr25519(&add_service_endpoint.to_state_change().encode(), &pair_sr); @@ -2175,7 +2175,7 @@ fn service_endpoints() { types: ServiceEndpointType::LINKED_DOMAINS, origins: origins_1.clone().try_into().unwrap(), }, - nonce: 5 + 1, + nonce: 1, }; let sig = SigValue::sr25519(&add_service_endpoint.to_state_change().encode(), &pair_sr); @@ -2197,7 +2197,7 @@ fn service_endpoints() { origins: origins_1.try_into().unwrap(), } ); - check_did_detail(&did, 2, 1, 1, 6); + check_did_detail(&did, 2, 1, 1, 1); run_to_block(15); @@ -2209,7 +2209,7 @@ fn service_endpoints() { types: ServiceEndpointType::LINKED_DOMAINS, origins: origins_2.clone().try_into().unwrap(), }, - nonce: 6 + 1, + nonce: 2, }; let sig = SigValue::sr25519(&add_service_endpoint.to_state_change().encode(), &pair_sr); @@ -2234,7 +2234,7 @@ fn service_endpoints() { types: ServiceEndpointType::LINKED_DOMAINS, origins: origins_2.clone().try_into().unwrap(), }, - nonce: 6 + 1, + nonce: 2, }; let sig = SigValue::sr25519(&add_service_endpoint.to_state_change().encode(), &pair_sr); @@ -2256,7 +2256,7 @@ fn service_endpoints() { origins: origins_2.try_into().unwrap(), } ); - check_did_detail(&did, 2, 1, 1, 7); + check_did_detail(&did, 2, 1, 1, 2); run_to_block(16); @@ -2264,7 +2264,7 @@ fn service_endpoints() { let rem_service_endpoint = RemoveServiceEndpoint { did, id: endpoint_1_id.clone(), - nonce: 7 + 1, + nonce: 1, }; let sig = SigValue::ed25519(&rem_service_endpoint.to_state_change().encode(), &pair_ed); @@ -2286,7 +2286,7 @@ fn service_endpoints() { let rem_service_endpoint = RemoveServiceEndpoint { did, id: ServiceEndpointId(vec![].try_into().unwrap()), - nonce: 7 + 1, + nonce: 3, }; let sig = SigValue::sr25519(&rem_service_endpoint.to_state_change().encode(), &pair_sr); @@ -2307,7 +2307,7 @@ fn service_endpoints() { let rem_service_endpoint = RemoveServiceEndpoint { did, id: endpoint_1_id.clone(), - nonce: 7 + 1, + nonce: 3, }; let sig = SigValue::sr25519(&rem_service_endpoint.to_state_change().encode(), &pair_sr); @@ -2322,13 +2322,13 @@ fn service_endpoints() { .into() )); assert!(DIDModule::did_service_endpoint(did, &endpoint_1_id).is_none()); - check_did_detail(&did, 2, 1, 1, 8); + check_did_detail(&did, 2, 1, 1, 3); // id already removed, removing again fails let rem_service_endpoint = RemoveServiceEndpoint { did, id: endpoint_1_id, - nonce: 8 + 1, + nonce: 4, }; let sig = SigValue::sr25519(&rem_service_endpoint.to_state_change().encode(), &pair_sr); assert_noop!( @@ -2348,7 +2348,7 @@ fn service_endpoints() { let rem_service_endpoint = RemoveServiceEndpoint { did, id: endpoint_2_id.clone(), - nonce: 8 + 1, + nonce: 4, }; let sig = SigValue::sr25519(&rem_service_endpoint.to_state_change().encode(), &pair_sr); @@ -2363,9 +2363,9 @@ fn service_endpoints() { .into() )); assert!(DIDModule::did_service_endpoint(did, &endpoint_2_id).is_none()); - check_did_detail(&did, 2, 1, 1, 9); + check_did_detail(&did, 2, 1, 1, 4); - let rem_did = DidRemoval { did, nonce: 9 + 1 }; + let rem_did = DidRemoval { did, nonce: 5 }; let sig = SigValue::ed25519(&rem_did.to_state_change().encode(), &pair_ed); assert_noop!( @@ -2382,9 +2382,9 @@ fn service_endpoints() { Error::::InsufficientVerificationRelationship ); - check_did_detail(&did, 2, 1, 1, 9); + check_did_detail(&did, 2, 1, 1, 4); - let rem_did = DidRemoval { did, nonce: 9 + 1 }; + let rem_did = DidRemoval { did, nonce: 5 }; let sig = SigValue::sr25519(&rem_did.to_state_change().encode(), &pair_sr); assert_ok!(DIDModule::remove_onchain_did( @@ -2429,7 +2429,7 @@ fn did_removal() { vec![].into_iter().collect() )); assert!(DIDModule::is_self_controlled(&did_1)); - check_did_detail(&did_1, 1, 1, 1, 5); + check_did_detail(&did_1, 1, 1, 1, 0); run_to_block(10); @@ -2448,7 +2448,7 @@ fn did_removal() { .collect() )); assert!(!DIDModule::is_self_controlled(&did_2)); - check_did_detail(&did_2, 1, 0, 1, 10); + check_did_detail(&did_2, 1, 0, 1, 0); run_to_block(15); @@ -2467,7 +2467,7 @@ fn did_removal() { .collect() )); assert!(DIDModule::is_self_controlled(&did_3)); - check_did_detail(&did_3, 1, 1, 2, 15); + check_did_detail(&did_3, 1, 1, 2, 0); run_to_block(20); @@ -2486,12 +2486,12 @@ fn did_removal() { .collect() )); assert!(DIDModule::is_self_controlled(&did_4)); - check_did_detail(&did_4, 1, 1, 2, 20); + check_did_detail(&did_4, 1, 1, 2, 0); // did_2 does not control itself so it cannot remove itself let rem_did = DidRemoval { did: did_2, - nonce: 10 + 1, + nonce: 1, }; let sig = SigValue::ed25519(&rem_did.to_state_change().encode(), &pair_ed); assert_noop!( @@ -2507,12 +2507,12 @@ fn did_removal() { ), Error::::InsufficientVerificationRelationship ); - check_did_detail(&did_2, 1, 0, 1, 10); + check_did_detail(&did_2, 1, 0, 1, 0); // did_2 is controlled by did_1 so it can be removed by did_1 let rem_did = DidRemoval { did: did_2, - nonce: 5 + 1, + nonce: 1, }; let sig = SigValue::sr25519(&rem_did.to_state_change().encode(), &pair_sr); assert_ok!(DIDModule::remove_onchain_did( @@ -2526,12 +2526,12 @@ fn did_removal() { .into() )); ensure_onchain_did_gone(&did_2); - check_did_detail(&did_1, 1, 1, 1, 6); + check_did_detail(&did_1, 1, 1, 1, 1); // Nonce should be correct when its deleted let rem_did = DidRemoval { did: did_3, - nonce: 5, + nonce: 0, }; let sig = SigValue::sr25519(&rem_did.to_state_change().encode(), &pair_sr); assert_noop!( @@ -2547,13 +2547,13 @@ fn did_removal() { ), did::Error::::InvalidNonce ); - check_did_detail(&did_1, 1, 1, 1, 6); - check_did_detail(&did_3, 1, 1, 2, 15); + check_did_detail(&did_1, 1, 1, 1, 1); + check_did_detail(&did_3, 1, 1, 2, 0); // did_3 is controlled by itself and did_1 and thus did_1 can remove it let rem_did = DidRemoval { did: did_3, - nonce: 6 + 1, + nonce: 2, }; let sig = SigValue::sr25519(&rem_did.to_state_change().encode(), &pair_sr); assert_ok!(DIDModule::remove_onchain_did( @@ -2567,13 +2567,13 @@ fn did_removal() { .into() )); ensure_onchain_did_gone(&did_3); - check_did_detail(&did_1, 1, 1, 1, 7); + check_did_detail(&did_1, 1, 1, 1, 2); // did_4 is controlled by itself and did_3 but did_3 has been removed so it can no // longer remove did_4 let rem_did = DidRemoval { did: did_4, - nonce: 15 + 1, + nonce: 1, }; let sig = SigValue::ed25519(&rem_did.to_state_change().encode(), &pair_ed); assert_noop!( @@ -2589,12 +2589,12 @@ fn did_removal() { ), Error::::NoKeyForDid ); - check_did_detail(&did_4, 1, 1, 2, 20); + check_did_detail(&did_4, 1, 1, 2, 0); // did_4 removes itself let rem_did = DidRemoval { did: did_4, - nonce: 20 + 1, + nonce: 1, }; let sig = SigValue::sr25519(&rem_did.to_state_change().encode(), &pair_sr); assert_ok!(DIDModule::remove_onchain_did( @@ -2612,7 +2612,7 @@ fn did_removal() { // did_1 removes itself let rem_did = DidRemoval { did: did_1, - nonce: 7 + 1, + nonce: 3, }; let sig = SigValue::sr25519(&rem_did.to_state_change().encode(), &pair_sr); assert_ok!(DIDModule::remove_onchain_did( @@ -2663,7 +2663,7 @@ fn batched_did_changes() { )], vec![].into_iter().collect() )); - check_did_detail(&did_1, 1, 1, 1, 10); + check_did_detail(&did_1, 1, 1, 1, 0); run_to_block(11); @@ -2674,7 +2674,7 @@ fn batched_did_changes() { PublicKey::x25519(pk_ed), VerRelType::KEY_AGREEMENT, )], - nonce: 10 + 1, + nonce: 1, }; let sig = SigValue::sr25519(&add_keys.to_state_change().encode(), &pair_sr); @@ -2685,7 +2685,7 @@ fn batched_did_changes() { types: ServiceEndpointType::LINKED_DOMAINS, origins: origins_1.clone().try_into().unwrap(), }, - nonce: 10 + 2, + nonce: 2, }; let sig_1 = SigValue::sr25519(&add_service_endpoint.to_state_change().encode(), &pair_sr); @@ -2710,7 +2710,7 @@ fn batched_did_changes() { .into() )); - check_did_detail(&did_1, 2, 1, 1, 12); + check_did_detail(&did_1, 2, 1, 1, 2); assert_eq!( DIDModule::did_service_endpoint(did_1, &endpoint_1_id).unwrap(), ServiceEndpoint { @@ -2730,7 +2730,7 @@ fn batched_did_changes() { PublicKey::x25519(pk_ed), VerRelType::KEY_AGREEMENT, )], - nonce: 12 + 1, + nonce: 3, }; let sig = SigValue::sr25519(&add_keys.to_state_change().encode(), &pair_sr); @@ -2740,7 +2740,7 @@ fn batched_did_changes() { PublicKey::ed25519(pk_ed), VerRelType::ASSERTION, )], - nonce: 12 + 2, + nonce: 4, }; let sig_2 = SigValue::sr25519(&add_keys_2.to_state_change().encode(), &pair_sr); @@ -2751,7 +2751,7 @@ fn batched_did_changes() { types: ServiceEndpointType::LINKED_DOMAINS, origins: origins_2.clone().try_into().unwrap(), }, - nonce: 12 + 3, + nonce: 5, }; let sig_3 = SigValue::sr25519(&add_service_endpoint.to_state_change().encode(), &pair_sr); @@ -2799,8 +2799,8 @@ fn batched_did_changes() { .into() )); - check_did_detail(&did_2, 3, 0, 1, 13); - check_did_detail(&did_1, 2, 1, 1, 15); + check_did_detail(&did_2, 3, 0, 1, 0); + check_did_detail(&did_1, 2, 1, 1, 5); assert_eq!( DIDModule::did_service_endpoint(did_2, &endpoint_2_id).unwrap(), ServiceEndpoint { diff --git a/pallets/core/src/modules/offchain_signatures/tests.rs b/pallets/core/src/modules/offchain_signatures/tests.rs index ab3cdecf9..5e4bfee25 100644 --- a/pallets/core/src/modules/offchain_signatures/tests.rs +++ b/pallets/core/src/modules/offchain_signatures/tests.rs @@ -77,13 +77,13 @@ with_each_scheme! { run_to_block(5); let (author, author_kp) = newdidordidmethodkey(); - let mut next_nonce = 5 + 1; + let mut next_nonce = 1; check_nonce(&author, next_nonce - 1); run_to_block(6); let (author_1, author_1_kp) = newdidordidmethodkey(); - let mut next_nonce_1 = 6 + 1; + let mut next_nonce_1 = 1; check_nonce(&author_1, next_nonce_1 - 1); run_to_block(10); @@ -466,13 +466,13 @@ with_each_scheme! { run_to_block(10); let (did, did_kp) = newdidordidmethodkey(); - let mut next_nonce = 10 + 1; + let mut next_nonce = 1; check_did_detail(&did, 1, 1, 1, next_nonce - 1); run_to_block(20); let (did_1, did_1_kp) = newdid(); - let mut next_nonce_1 = 20 + 1; + let mut next_nonce_1 = 1; check_nonce(&did_1, next_nonce_1 - 1); check_did_detail(&did_1, 1, 1, 1, next_nonce_1 - 1); @@ -540,7 +540,7 @@ with_each_scheme! { run_to_block(10); let (author, author_kp) = newdid(); - let mut next_nonce = 10 + 1; + let mut next_nonce = 1; check_nonce(&author, next_nonce - 1); run_to_block(15); @@ -625,7 +625,7 @@ with_each_scheme! { run_to_block(45); let (author_1, author_kp_1) = newdid(); - let mut next_nonce_1 = 45 + 1; + let mut next_nonce_1 = 1; run_to_block(50); @@ -958,7 +958,7 @@ with_each_scheme! { ext().execute_with(|| { run_to_block(10); let (author, _) = newdid(); - let next_nonce = 10 + 1; + let next_nonce = 1; run_to_block(20); let (author_1, _) = newdid(); diff --git a/pallets/core/src/modules/trust_registry/tests.rs b/pallets/core/src/modules/trust_registry/tests.rs index 202953ba6..61c4efa41 100644 --- a/pallets/core/src/modules/trust_registry/tests.rs +++ b/pallets/core/src/modules/trust_registry/tests.rs @@ -147,7 +147,7 @@ crate::did_or_did_method_key! { .try_into() .unwrap(), gov_framework: Bytes(vec![1; 100]).try_into().unwrap(), - nonce: 2, + nonce: did_nonce::(convener).unwrap(), }; let alice = 1u64; @@ -201,7 +201,7 @@ crate::did_or_did_method_key! { .try_into() .unwrap(), gov_framework: Bytes(vec![1; 100]).try_into().unwrap(), - nonce: 2, + nonce: did_nonce::(Convener(other.into())).unwrap(), }; let other_did_sig = did_sig( &init_or_update_trust_registry_already_exists, @@ -226,7 +226,7 @@ crate::did_or_did_method_key! { .try_into() .unwrap(), gov_framework: Bytes(vec![1; 100]).try_into().unwrap(), - nonce: 3, + nonce: did_nonce::(Convener(convener.into())).unwrap(), }; let sig = did_sig( &reinit_or_update_trust_registry, @@ -471,7 +471,7 @@ crate::did_or_did_method_key! { .try_into() .unwrap(), gov_framework: Bytes(vec![1; 100]).try_into().unwrap(), - nonce: 2, + nonce: did_nonce::(convener).unwrap(), }; let alice = 1u64; @@ -504,7 +504,7 @@ crate::did_or_did_method_key! { let update_delegated = UpdateDelegatedIssuers { delegated: SetOrModify::Set(delegated.clone()), registry_id: init_or_update_trust_registry.registry_id, - nonce: 2u32.into(), + nonce: did_nonce::(other).unwrap(), }; let sig = did_sig(&update_delegated, &other_kp, other, 1u32); @@ -593,7 +593,7 @@ crate::did_or_did_method_key! { let update_delegated = UpdateDelegatedIssuers { delegated: SetOrModify::Set(delegated.clone()), registry_id: init_or_update_trust_registry.registry_id, - nonce: 2u32.into(), + nonce: did_nonce::(other_1).unwrap(), }; let sig = did_sig(&update_delegated, &other_kp_1, other_1, 1u32); @@ -631,7 +631,7 @@ crate::did_or_did_method_key! { let update_delegated = UpdateDelegatedIssuers:: { delegated: SetOrModify::Set(Default::default()), registry_id: init_or_update_trust_registry.registry_id, - nonce: 3u32.into(), + nonce: did_nonce::(other).unwrap(), }; let sig = did_sig(&update_delegated, &other_kp, other, 1u32); @@ -994,7 +994,7 @@ crate::did_or_did_method_key! { .try_into() .unwrap(), gov_framework: Bytes(vec![1; 100]).try_into().unwrap(), - nonce: 2, + nonce: did_nonce::(convener).unwrap(), }; let sig = did_sig( &init_or_update_trust_registry, @@ -1128,7 +1128,7 @@ crate::did_or_did_method_key! { let add_other_schema_metadata = SetSchemasMetadata { registry_id: init_or_update_trust_registry.registry_id, schemas: add_schema_metadata.schemas.clone(), - nonce: 2, + nonce: did_nonce::(Convener(other.into())).unwrap(), }; let other_sig = did_sig( @@ -1186,7 +1186,7 @@ crate::did_or_did_method_key! { .try_into() .unwrap(), gov_framework: Bytes(vec![1; 100]).try_into().unwrap(), - nonce: 2, + nonce: did_nonce::(Convener(convener.into())).unwrap(), }; let sig = did_sig( &init_or_update_trust_registry, diff --git a/pallets/core/src/util/with_nonce.rs b/pallets/core/src/util/with_nonce.rs index 9b866decf..75cdf4796 100644 --- a/pallets/core/src/util/with_nonce.rs +++ b/pallets/core/src/util/with_nonce.rs @@ -64,7 +64,7 @@ impl WithNonce { where T: frame_system::Config::BlockNumber>, { - Self::new_with_nonce(data, >::block_number()) + Self::new_with_nonce(data, 0u8.into()) } /// Adds supplied nonce to the given `data`. diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 75914071c..ebd393a24 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -2,7 +2,7 @@ authors = ["Dock.io"] edition = "2021" name = "dock-runtime" -version = "0.31.0" +version = "0.32.0" license = "Apache-2.0" [package.metadata.docs.rs]