Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add unit tests for DIP components #609

Merged
merged 77 commits into from
Mar 1, 2024
Merged

chore: add unit tests for DIP components #609

merged 77 commits into from
Mar 1, 2024

Conversation

ntn-x2
Copy link
Member

@ntn-x2 ntn-x2 commented Feb 12, 2024

Partially fixes https://github.com/KILTprotocol/ticket/issues/2562.

Tests for the DIP provider components

The DIP provider components are tested in this PR. Specifically:

  • The pallet-deposit-storage pallet main logic.
  • The DepositHooks hook for deleting an identity commitment when a deposit is released directly. It used to leave in the Peregrine runtime but it now lives in runtime-common and is generic over the runtime. This was required for testing the hook logic.
  • The pallet-dip-provider pallet main logic.
  • The FixedDepositCollectorViaDepositsPallet hook for reserving and releasing deposits when identity commitments are deleted. It uses a different mock than the pallet mock.
  • The generate_proof and generate_commitment functions, along with the DidMerkleRootGenerator.
  • The LinkedDidInfoProvider.

The PR also contains minor refactoring that was necessary to do proper mocking of the different pieces of the runtime to test the components above. The main changes are:

  • Move from a multi-module to a single-module approach, where files do not contain more than a module.
  • Move the DepositHooks from being Peregrine-specific to being runtime-agnostic, in runtime-common.

This PR only adds tests for the DIP provider components. The DIP consumer will be tested in a separate PR.

Base automatically changed from aa/dip-improvements to develop February 22, 2024 08:07
Copy link
Member

@Ad96el Ad96el left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice changes and good test coverage 🙌 .

We should also include some try_runtime tests for the provider pallet.

Some concerns about the logging. I would change them debug logs.

I guess the file structure can be simplified.

@ntn-x2
Copy link
Member Author

ntn-x2 commented Feb 28, 2024

We should also include some try_runtime tests for the provider pallet.

@Ad96el I agree, but as long as we don't have any migration logic I though to spare some time and skip it, for now. What benefit would it give us at this point? I'm all ears.

@Ad96el
Copy link
Member

Ad96el commented Feb 28, 2024

I was thinking of having sanity tests. We could test that each commitment has an entry in the deposit pallet. For that, we need the try-runtime tests. If I remember correctly, this is not tested or? Please correct me if am wrong.

@ntn-x2
Copy link
Member Author

ntn-x2 commented Feb 28, 2024

I was thinking of having sanity tests. We could test that each commitment has an entry in the deposit pallet.

This is a good test to add, I agree! I would still rather keep the pallets isolated from each other tho, as they have been designed. So what is the best strategy to do this with try-runtime? Ideally we would add these checks where the hooks are implemented, but as far as I know try-runtime only works for pallets?

@Ad96el
Copy link
Member

Ad96el commented Feb 28, 2024

Yes, try-runtime only works on pallet level.

So I guess the best way is, that the trait itself have a function which is feature guided via try-runtime. So we can still guarantee it is generic for other chains, but we can introduce them in our chain.

@ntn-x2
Copy link
Member Author

ntn-x2 commented Feb 29, 2024

So I guess the best way is, that the trait itself have a function which is feature guided via try-runtime. So we can still guarantee it is generic for other chains, but we can introduce them in our chain.

Ok, thanks for the input. I will think if this is good or if it defeats any decoupling principles.

Copy link
Member

@Ad96el Ad96el left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ntn-x2 ntn-x2 merged commit 811b207 into develop Mar 1, 2024
2 checks passed
@ntn-x2 ntn-x2 deleted the aa/dip-unit-tests branch March 1, 2024 13:41
Ad96el pushed a commit that referenced this pull request Apr 2, 2024
Partially fixes KILTprotocol/ticket#2562.

## Tests for the DIP provider components

The DIP provider components are tested in this PR. Specifically:

* The `pallet-deposit-storage` pallet main logic.
* The `DepositHooks` hook for deleting an identity commitment when a
deposit is released directly. It used to leave in the Peregrine runtime
but it now lives in `runtime-common` and is generic over the runtime.
This was required for testing the hook logic.
* The `pallet-dip-provider` pallet main logic.
* The `FixedDepositCollectorViaDepositsPallet` hook for reserving and
releasing deposits when identity commitments are deleted. It uses a
different mock than the pallet mock.
* The `generate_proof` and `generate_commitment` functions, along with
the `DidMerkleRootGenerator`.
* The `LinkedDidInfoProvider`.

The PR also contains minor refactoring that was necessary to do proper
mocking of the different pieces of the runtime to test the components
above. The main changes are:

* Move from a multi-module to a single-module approach, where files do
not contain more than a module.
* Move the `DepositHooks` from being Peregrine-specific to being
runtime-agnostic, in `runtime-common`.

**This PR only adds tests for the DIP provider components. The DIP
consumer will be tested in a separate PR.**
ntn-x2 added a commit that referenced this pull request Apr 4, 2024
Partially fixes KILTprotocol/ticket#2562.

## Tests for the DIP provider components

The DIP provider components are tested in this PR. Specifically:

* The `pallet-deposit-storage` pallet main logic.
* The `DepositHooks` hook for deleting an identity commitment when a
deposit is released directly. It used to leave in the Peregrine runtime
but it now lives in `runtime-common` and is generic over the runtime.
This was required for testing the hook logic.
* The `pallet-dip-provider` pallet main logic.
* The `FixedDepositCollectorViaDepositsPallet` hook for reserving and
releasing deposits when identity commitments are deleted. It uses a
different mock than the pallet mock.
* The `generate_proof` and `generate_commitment` functions, along with
the `DidMerkleRootGenerator`.
* The `LinkedDidInfoProvider`.

The PR also contains minor refactoring that was necessary to do proper
mocking of the different pieces of the runtime to test the components
above. The main changes are:

* Move from a multi-module to a single-module approach, where files do
not contain more than a module.
* Move the `DepositHooks` from being Peregrine-specific to being
runtime-agnostic, in `runtime-common`.

**This PR only adds tests for the DIP provider components. The DIP
consumer will be tested in a separate PR.**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants