Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cd2efcb
test: first unit tests passing after refactor
ntn-x2 Aug 2, 2021
99ba362
feat: refactor complete
ntn-x2 Aug 3, 2021
ce9ade2
feat: revert DID creation to old version and update test cases
ntn-x2 Aug 3, 2021
7752137
fix: update test cases and benchmarks
ntn-x2 Aug 4, 2021
92cc170
wip: comment out current weights
ntn-x2 Aug 4, 2021
64dc85b
feat: delegation pallet storage refactor (#226)
ntn-x2 Aug 3, 2021
92bda81
fix: refine code after checking the changes
ntn-x2 Aug 4, 2021
cc52a6c
chore: update comments to reflect latest changes
ntn-x2 Aug 4, 2021
fd9de55
bench: update benchmarks
ntn-x2 Aug 4, 2021
939c9db
chore: fmt
ntn-x2 Aug 4, 2021
9360ec3
bench: add peregrine benchmarks
ntn-x2 Aug 4, 2021
c084dd7
fix: add new DID weights to peregrine runtime
ntn-x2 Aug 4, 2021
2dc0e97
Merge branch 'develop' into aa-did-pallet-origin
ntn-x2 Aug 4, 2021
0930911
chore: bump runtime version
ntn-x2 Aug 4, 2021
d415ee1
merge develop branch
ntn-x2 Aug 4, 2021
a6d0946
chore: fmt + clippy
ntn-x2 Aug 4, 2021
ddab01b
chore: clippy
ntn-x2 Aug 4, 2021
d4f9462
fix: test errors
ntn-x2 Aug 4, 2021
64f36ec
Merge remote-tracking branch 'origin/develop' into aa-did-pallet-origin
ntn-x2 Aug 4, 2021
25ba666
fix: typo in docs
ntn-x2 Aug 4, 2021
677a827
chore: remove useless elements in unit tests
ntn-x2 Aug 4, 2021
d8bddbf
feat: remove TryFrom for DidDetails
ntn-x2 Aug 4, 2021
87f68d6
chore: fmt
ntn-x2 Aug 4, 2021
9b1df9f
Merge remote-tracking branch 'origin/develop' into aa-did-pallet-origin
ntn-x2 Aug 4, 2021
391260f
fix: replace tuple with two parameters in from_creation_details
ntn-x2 Aug 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: update test cases and benchmarks
  • Loading branch information
ntn-x2 committed Aug 4, 2021
commit 77521373700275c753f3d7bbdfbbfc27319d8111
149 changes: 75 additions & 74 deletions pallets/did/src/benchmarking.rs

Large diffs are not rendered by default.

38 changes: 14 additions & 24 deletions pallets/did/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,28 +363,20 @@ pub mod pallet {
details.new_endpoint_url.as_ref().map_or(0u32, |url| url.len().saturated_into::<u32>())
))
)]
pub fn create(
origin: OriginFor<T>,
details: DidCreationDetails<T>,
signature: DidSignature,
) -> DispatchResult {
pub fn create(origin: OriginFor<T>, details: DidCreationDetails<T>, signature: DidSignature) -> DispatchResult {
let sender = ensure_signed(origin)?;

let did_identifier = details.did.clone();

// There has to be no other DID with the same identifier already saved on chain,
// otherwise generate a DidAlreadyPresent error.
ensure!(
!<Did<T>>::contains_key(&did_identifier),
<Error<T>>::DidAlreadyPresent
);
ensure!(!<Did<T>>::contains_key(&did_identifier), <Error<T>>::DidAlreadyPresent);

let account_did_auth_key = did_identifier
.verify_and_recover_signature(&details.encode(), &signature)
.map_err(<Error<T>>::from)?;

let did_entry =
DidDetails::try_from((details.clone(), account_did_auth_key)).map_err(<Error<T>>::from)?;
let did_entry = DidDetails::try_from((details.clone(), account_did_auth_key)).map_err(<Error<T>>::from)?;

log::debug!("Creating DID {:?}", &did_identifier);
<Did<T>>::insert(&did_identifier, did_entry);
Expand Down Expand Up @@ -474,10 +466,7 @@ pub mod pallet {
details.new_endpoint_url.as_ref().map_or(0u32, |url| url.len().saturated_into::<u32>())
))
)]
pub fn update(
origin: OriginFor<T>,
details: DidUpdateDetails<T>,
) -> DispatchResult {
pub fn update(origin: OriginFor<T>, details: DidUpdateDetails<T>) -> DispatchResult {
let did_subject = T::EnsureOrigin::ensure_origin(origin)?;

let did_details = <Did<T>>::get(&did_subject).ok_or(<Error<T>>::DidNotPresent)?;
Expand Down Expand Up @@ -517,9 +506,7 @@ pub mod pallet {
/// - Kills: Did entry associated to the DID identifier
/// # </weight>
#[pallet::weight(<T as pallet::Config>::WeightInfo::submit_did_delete_operation())]
pub fn delete(
origin: OriginFor<T>
) -> DispatchResult {
pub fn delete(origin: OriginFor<T>) -> DispatchResult {
let did_subject = T::EnsureOrigin::ensure_origin(origin)?;

ensure!(
Expand Down Expand Up @@ -640,9 +627,15 @@ impl<T: Config> Pallet<T> {
<Did<T>>::get(&operation.did).ok_or(DidError::StorageError(StorageError::DidNotPresent))?;

Self::validate_counter_value(operation.tx_counter, &did_details)?;
// Increase the tx counter as soon as it is considered valid, no matter if the signature is valid or not.
// Increase the tx counter as soon as it is considered valid, no matter if the
// signature is valid or not.
did_details.increase_tx_counter().map_err(DidError::StorageError)?;
Self::verify_payload_signature_with_did_key_type(operation.encode().as_ref(), signature, &did_details, operation.operation_authorization_key_type)?;
Self::verify_payload_signature_with_did_key_type(
operation.encode().as_ref(),
signature,
&did_details,
operation.operation_authorization_key_type,
)?;

<Did<T>>::insert(&operation.did, did_details);

Expand All @@ -655,10 +648,7 @@ impl<T: Config> Pallet<T> {
// as that would result in the DID being unusable, since we do not have yet any
// mechanism in place to wrap the counter value around when the limit is
// reached.
fn validate_counter_value(
counter: u64,
did_details: &DidDetails<T>,
) -> Result<(), DidError> {
fn validate_counter_value(counter: u64, did_details: &DidDetails<T>) -> Result<(), DidError> {
// Verify that the DID has not reached the maximum tx counter value
ensure!(
did_details.get_tx_counter_value() < u64::MAX,
Expand Down
8 changes: 4 additions & 4 deletions pallets/did/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ impl did::DeriveDidCallAuthorizationVerificationKeyRelationship for Call {
#[cfg(feature = "runtime-benchmarks")]
if *self == Self::get_call_for_did_call_benchmark() {
// Always require an authentication key to dispatch calls during benchmarking
return Some(did::DidOperationAuthorizationKey::DidKey(did::DidVerificationKeyRelationship::Authentication));
return Some(did::DidVerificationKeyRelationship::Authentication);
}
None
}
Expand All @@ -346,15 +346,15 @@ pub fn generate_test_did_call(
DidVerificationKeyRelationship::AssertionMethod => get_attestation_key_call(),
DidVerificationKeyRelationship::Authentication => get_authentication_key_call(),
DidVerificationKeyRelationship::CapabilityDelegation => get_delegation_key_call(),
_ => get_none_key_call()
_ => get_none_key_call(),
};
did::DidAuthorizedCallOperationWithVerificationRelationship {
operation: did::DidAuthorizedCallOperation {
did: caller,
call,
tx_counter: 1u64
tx_counter: 1u64,
},
operation_authorization_key_type: verification_key_required
operation_authorization_key_type: verification_key_required,
}
}

Expand Down
Loading