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

🔐 SubmitClaims on dataverse #26

Merged
merged 14 commits into from
Sep 17, 2024
Merged

🔐 SubmitClaims on dataverse #26

merged 14 commits into from
Sep 17, 2024

Conversation

bdeneux
Copy link
Contributor

@bdeneux bdeneux commented Sep 12, 2024

🔐 Send SubmitClaims Transaction

This PR adds a new feature allowing the sending of the SubmitClaims execute message on the chain. It takes a signed credential, converts it to n-quad RDF, and encodes it in base64 to be sent to the dataverse smart contract.

💳 Transaction Service

To achieve this, a new client has been added to handle sending transactions on the Cosmos blockchain: tx.Client. This client includes a transaction builder to simplify the preparation of sending a transaction.

While there is room for improvement to make transaction sending easier and more powerful, the current implementation provides a good starting point. Potential improvements include:

  • More tests for error cases, such as failed transactions or signing issues.
  • Building the TxConfig in a more appropriate place.
  • Allowing the choice of denom for the keyring key and signature management.
  • Typed execute message send to the smart contract
  • And many other enhancements...

🔑 Keyring

This PR also improves key and mnemonic management by using an interface for the Keys provided to the proxy or the credential generator. This change facilitates usage in a mocked environment and lays the groundwork for future improvements, such as supporting alternatives to mnemonics.

Copy link
Contributor

coderabbitai bot commented Sep 12, 2024

Walkthrough

The changes introduce enhancements across multiple files, primarily focusing on improving mock generation for testing, refining client interfaces, and updating transaction handling mechanisms. Key modifications include renaming and restructuring client types, implementing new transaction submission functionalities, and updating associated tests to ensure proper functionality. The changes also involve the addition of error handling constants and the encapsulation of key management functionalities.

Changes

File(s) Change Summary
Makefile Added mock generation commands for various transaction-related clients and services to enhance testing capabilities.
auth/proxy.go, auth/proxy_test.go Changed the dvClient type to dataverse.QueryClient and updated tests to reflect the new mock client type.
credential/generate.go, credential/generate_test.go Modified the WithSigner function to accept a keys.Keyring instead of verifiable.Signer, and updated tests accordingly.
dataverse/client.go, dataverse/client_test.go Introduced a new TxClient interface for transaction handling, renamed existing client types, and updated related tests to use the new query client.
dataverse/errors.go Added new error constants for improved error handling related to RDF conversion, JSON marshaling, and transaction submission.
dataverse/export_test.go Added new functions for creating query and transaction clients, enhancing modularity.
dataverse/governance.go, dataverse/governance_test.go Updated methods to use queryClient instead of client, reflecting a focus on querying functionalities.
dataverse/tx.go, dataverse/tx_test.go Implemented transaction submission functionality and associated tests for the SubmitClaims method.
keys/keyring.go, keys/mnemonic.go, keys/mnemonic_test.go Introduced a new Keyring interface and updated the Key struct for better encapsulation, along with tests for key generation from mnemonics.
provider/storage/http.go, provider/storage/proxy.go Changed the way DID is accessed and updated the Proxy struct to use keys.Keyring and dataverse.QueryClient.
testutil/* Generated mock implementations for various interfaces, including QueryClient, Keyring, Transaction, and ServiceClient, to facilitate unit testing.
tx/client.go, tx/client_test.go Created a new transaction client interface and implemented the SendTx method, along with comprehensive tests for various transaction scenarios.
tx/transaction.go, tx/transaction_test.go Introduced a transaction management system with a Transaction interface and associated tests for transaction creation and signing.

Possibly related PRs

  • Add authenticate proxy #10: The changes in the Makefile for generating mocks related to credential parsing are relevant as they enhance the testing capabilities, similar to the mock generation commands added in the main PR for transaction-related mocks.
  • Get cognitarium address on new dataverse client #18: The addition of mock generation commands for the QueryClient interface in the Makefile aligns with the main PR's focus on enhancing testing capabilities through mock generation for transaction handling.
  • Implement GetResourceGovAddr #21: The implementation of GetResourceGovAddr in the dataverse/client.go file is directly related to the changes in the main PR, as both involve enhancements to client functionality and testing capabilities within the dataverse context.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Sep 12, 2024

Codecov Report

Attention: Patch coverage is 57.69231% with 77 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tx/transaction.go 27.69% 47 Missing ⚠️
dataverse/client.go 7.69% 12 Missing ⚠️
dataverse/tx.go 72.22% 5 Missing and 5 partials ⚠️
provider/storage/proxy.go 0.00% 5 Missing ⚠️
tx/client.go 95.55% 1 Missing and 1 partial ⚠️
provider/storage/http.go 0.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
auth/proxy.go 89.47% <ø> (ø)
credential/generate.go 88.23% <100.00%> (ø)
dataverse/errors.go 100.00% <ø> (ø)
dataverse/governance.go 100.00% <100.00%> (ø)
keys/mnemonic.go 80.00% <100.00%> (ø)
provider/storage/http.go 0.00% <0.00%> (ø)
tx/client.go 95.55% <95.55%> (ø)
provider/storage/proxy.go 0.00% <0.00%> (ø)
dataverse/tx.go 72.22% <72.22%> (ø)
dataverse/client.go 33.33% <7.69%> (-16.67%) ⬇️
... and 1 more

@bdeneux bdeneux marked this pull request as ready for review September 12, 2024 14:34
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

Outside diff range and nitpick comments (3)
keys/mnemonic_test.go (1)

11-59: LGTM! Consider adding more test cases.

The test function is well-structured and covers the important scenarios. The use of the goconvey library for assertions is effective.

To further improve the test coverage, consider adding more test cases to cover edge cases and error scenarios, such as:

  • Empty mnemonic
  • Mnemonic with invalid checksum
  • Mnemonic with invalid word count
Tools
Gitleaks

23-23: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

tx/transaction_test.go (1)

11-75: Comprehensive test coverage, but consider adding more test cases.

The TestNewTransaction function provides a comprehensive set of test cases for the NewTransaction function. The test cases cover various scenarios with different options, and the use of the goconvey library makes the assertions readable and expressive.

However, consider adding the following test cases to improve the test coverage:

  1. A test case for the scenario where multiple options are provided together. This will ensure that the function behaves correctly when multiple options are combined.
  2. A test case for the scenario where an invalid option is provided. This will ensure that the function handles invalid options gracefully and returns an error.
dataverse/tx_test.go (1)

18-75: LGTM! Consider adding more test cases.

The test function is well-structured and follows the Given-When-Then pattern using the goconvey library. The mocking of the dependencies is done correctly using the gomock library, and the assertions in the test case are appropriate and cover the expected behavior.

However, consider adding more test cases to cover error scenarios and edge cases to ensure the robustness of the SubmitClaims method.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cfa146b and 02e1a67.

Files selected for processing (29)
  • Makefile (1 hunks)
  • auth/proxy.go (1 hunks)
  • auth/proxy_test.go (1 hunks)
  • credential/generate.go (3 hunks)
  • credential/generate_test.go (2 hunks)
  • dataverse/client.go (4 hunks)
  • dataverse/client_test.go (1 hunks)
  • dataverse/errors.go (1 hunks)
  • dataverse/export_test.go (1 hunks)
  • dataverse/governance.go (3 hunks)
  • dataverse/governance_test.go (3 hunks)
  • dataverse/tx.go (1 hunks)
  • dataverse/tx_test.go (1 hunks)
  • keys/keyring.go (1 hunks)
  • keys/mnemonic.go (3 hunks)
  • keys/mnemonic_test.go (1 hunks)
  • provider/storage/http.go (1 hunks)
  • provider/storage/proxy.go (5 hunks)
  • testutil/auth_client_mocks.go (1 hunks)
  • testutil/dataverse_mocks.go (5 hunks)
  • testutil/keyring_mocks.go (1 hunks)
  • testutil/signer_mocks.go (0 hunks)
  • testutil/transaction_mocks.go (1 hunks)
  • testutil/tx_mocks.go (1 hunks)
  • testutil/tx_service_mocks.go (1 hunks)
  • tx/client.go (1 hunks)
  • tx/client_test.go (1 hunks)
  • tx/transaction.go (1 hunks)
  • tx/transaction_test.go (1 hunks)
Files not reviewed due to no reviewable changes (1)
  • testutil/signer_mocks.go
Files skipped from review due to trivial changes (7)
  • dataverse/governance.go
  • dataverse/governance_test.go
  • testutil/auth_client_mocks.go
  • testutil/keyring_mocks.go
  • testutil/transaction_mocks.go
  • testutil/tx_mocks.go
  • testutil/tx_service_mocks.go
Additional context used
GitHub Check: codecov/patch
dataverse/tx.go

[warning] 19-19: dataverse/tx.go#L19
Added line #L19 was not covered by tests


[warning] 28-28: dataverse/tx.go#L28
Added line #L28 was not covered by tests


[warning] 44-44: dataverse/tx.go#L44
Added line #L44 was not covered by tests


[warning] 57-57: dataverse/tx.go#L57
Added line #L57 was not covered by tests


[warning] 63-63: dataverse/tx.go#L63
Added line #L63 was not covered by tests

provider/storage/http.go

[warning] 17-17: provider/storage/http.go#L17
Added line #L17 was not covered by tests

keys/mnemonic.go

[warning] 59-59: keys/mnemonic.go#L59
Added line #L59 was not covered by tests

provider/storage/proxy.go

[warning] 44-44: provider/storage/proxy.go#L44
Added line #L44 was not covered by tests


[warning] 57-57: provider/storage/proxy.go#L57
Added line #L57 was not covered by tests


[warning] 78-78: provider/storage/proxy.go#L78
Added line #L78 was not covered by tests


[warning] 100-100: provider/storage/proxy.go#L100
Added line #L100 was not covered by tests


[warning] 102-102: provider/storage/proxy.go#L102
Added line #L102 was not covered by tests

tx/client.go

[warning] 66-66: tx/client.go#L66
Added line #L66 was not covered by tests


[warning] 85-85: tx/client.go#L85
Added line #L85 was not covered by tests

tx/transaction.go

[warning] 69-71: tx/transaction.go#L69-L71
Added lines #L69 - L71 were not covered by tests


[warning] 78-80: tx/transaction.go#L78-L80
Added lines #L78 - L80 were not covered by tests


[warning] 83-88: tx/transaction.go#L83-L88
Added lines #L83 - L88 were not covered by tests


[warning] 91-97: tx/transaction.go#L91-L97
Added lines #L91 - L97 were not covered by tests


[warning] 100-101: tx/transaction.go#L100-L101
Added lines #L100 - L101 were not covered by tests


[warning] 104-110: tx/transaction.go#L104-L110
Added lines #L104 - L110 were not covered by tests


[warning] 113-115: tx/transaction.go#L113-L115
Added lines #L113 - L115 were not covered by tests


[warning] 118-120: tx/transaction.go#L118-L120
Added lines #L118 - L120 were not covered by tests


[warning] 123-123: tx/transaction.go#L123
Added line #L123 was not covered by tests


[warning] 129-130: tx/transaction.go#L129-L130
Added lines #L129 - L130 were not covered by tests


[warning] 132-133: tx/transaction.go#L132-L133
Added lines #L132 - L133 were not covered by tests


[warning] 135-137: tx/transaction.go#L135-L137
Added lines #L135 - L137 were not covered by tests

dataverse/client.go

[warning] 77-77: dataverse/client.go#L77
Added line #L77 was not covered by tests


[warning] 80-80: dataverse/client.go#L80
Added line #L80 was not covered by tests


[warning] 113-116: dataverse/client.go#L113-L116
Added lines #L113 - L116 were not covered by tests


[warning] 118-123: dataverse/client.go#L118-L123
Added lines #L118 - L123 were not covered by tests

Gitleaks
keys/mnemonic_test.go

23-23: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

Additional comments not posted (48)
keys/keyring.go (1)

1-18: LGTM!

The Keyring interface is well-defined and follows the best practices of Go interfaces. The methods are clearly named and serve specific purposes related to signing messages and retrieving key information. The comments provide clear explanations for each method, making the interface easy to understand and use.

The interface provides a solid foundation for implementing a keyring that can sign messages in the Axone SDK. It encapsulates the necessary functionality and allows for flexibility in the implementation.

dataverse/errors.go (1)

11-14: LGTM!

The addition of the new error constants ErrConvertRDF, ErrMarshalJSON, and ErrSendTx improves the error handling capabilities of the module. The error messages are clear, concise, and accurately describe the error scenarios. The constants follow the existing naming convention and are correctly typed as MessageError.

Great job on enhancing the clarity and specificity of error handling within the codebase!

dataverse/export_test.go (2)

11-22: LGTM!

The renaming of NewDataverseClient to NewDataverseQueryClient aligns well with the architectural enhancement to separate query and transaction functionalities. The function implementation looks good.


24-43: Looks good!

The addition of the NewDataverseTxClient function nicely complements the NewDataverseQueryClient function and provides a more comprehensive interface for interacting with the Dataverse. The function implementation looks solid.

keys/mnemonic.go (4)

11-12: LGTM!

The declaration that the Key struct implements the Keyring interface is correct and helps in enforcing type safety.


15-17: Good encapsulation!

Renaming the fields of the Key struct from public to private is a good practice for data hiding and maintaining a clean API. It enforces the use of getter methods for accessing these values.


39-41: Bech32 prefix configuration looks good.

Setting the Bech32 prefix for accounts using the sdk.GetConfig().SetBech32PrefixForAccount method is necessary for proper address encoding and decoding.

Regarding the TODO comment, I agree that making the Bech32 prefix configurable in the future is a good idea as it allows flexibility and customization. Let's keep this in mind for future enhancements.


62-71: Getter methods for encapsulation.

Adding getter methods DID, DIDKeyID, and Addr to provide access to the private fields of the Key struct is a good practice for encapsulation and maintaining a clean API. The implementations of the getter methods are straightforward and return the corresponding private fields.

keys/mnemonic_test.go (1)

23-23: Ignore the static analysis hint.

The static analysis hint about a potential generic API key on line 23 is a false positive. The mnemonic phrase on line 23 is not an API key, but a test input used to generate a key for testing purposes. It is safe to ignore this hint.

Tools
Gitleaks

23-23: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

auth/proxy.go (2)

24-24: LGTM!

The change from dataverse.Client to dataverse.QueryClient for the dvClient field in the authProxy struct is a good refinement. It indicates that the authProxy is now expected to utilize a more specialized interface for querying operations, which aligns with the PR objective of refining client interfaces. This change is unlikely to have any negative impact on the functionality of the authProxy.


31-31: LGTM!

The change from dataverse.Client to dataverse.QueryClient for the dvClient parameter in the NewProxy function is consistent with the change made to the dvClient field in the authProxy struct. It ensures that the NewProxy function is expecting the correct type of client when creating a new authProxy instance. This change is necessary and appropriate.

credential/generate.go (3)

7-7: LGTM!

The import statement for "github.com/axone-protocol/axone-sdk/keys" has been correctly added to support the changes made to the WithSigner function.


32-33: LGTM!

The comment for the WithSigner function has been correctly updated to indicate that the signature is optional and a non-signed Verifiable Credential (VC) can still be generated.


53-56: LGTM!

The changes made to the WithSigner function are consistent with the updated comment and the addition of the import statement for "github.com/axone-protocol/axone-sdk/keys". The modifications reflect a shift in the underlying implementation of the signing mechanism, indicating that it now expects a Keyring type, which likely encapsulates key management functionalities. The use of the DIDKeyID() method from the keys.Keyring interface suggests a more integrated approach to handling decentralized identifiers (DIDs) within the signing process. There are no apparent issues with the changes made to the WithSigner function.

dataverse/tx_test.go (1)

77-88: LGTM!

The helper function is simple and straightforward. It generates a verifiable credential for testing purposes using the credential package and the template.NewGovernance function. The use of panic for error handling is acceptable for a test helper function.

provider/storage/proxy.go (4)

23-23: LGTM!

The change in the type of the key field from *keys.Key to keys.Keyring is a significant but necessary modification. It aligns with the overall refactoring aimed at enhancing the flexibility and functionality of the Proxy struct.


25-25: LGTM!

The modification of the dvClient type from dataverse.Client to dataverse.QueryClient suggests a refinement in the client's functionality or interface. This change aligns with the overall enhancements being made to the Proxy struct.


37-37: LGTM!

The changes in the NewProxy function, specifically the modifications to the key and dvClient parameter types, align with the updates made to the Proxy struct. These adjustments ensure consistency in how the Proxy is instantiated and utilized.

Also applies to: 39-39


Line range hint 1-114: Remaining changes look good!

The remaining modifications in the file, such as accessing the DID through the DID() method of the key field in the Read and Store methods, are consistent with the overall refactoring of the Proxy struct and its associated functionality. These changes ensure a cohesive and unified approach to utilizing the key and accessing the DID throughout the codebase.

Tools
GitHub Check: codecov/patch

[warning] 44-44: provider/storage/proxy.go#L44
Added line #L44 was not covered by tests

auth/proxy_test.go (1)

65-65: LGTM!

The change in the mock client instantiation enhances the specificity of the mock used in the authentication proxy tests. The mock's expectations and return values remain unchanged, focusing on the method AskGovPermittedActions.

dataverse/client_test.go (1)

33-34: LGTM!

The renaming of the client creation function from dataverse.NewClient to dataverse.NewQueryClient is consistent with the provided list of alterations. The change does not introduce any new issues or inconsistencies in the test.

tx/client.go (4)

19-21: LGTM!

The Client interface definition looks good. It encapsulates the functionality of sending a transaction, which aligns with the PR objectives. The method signature is clear and concise.


23-27: LGTM!

The client struct definition looks good. It encapsulates the necessary dependencies to send a transaction. The field names are clear and descriptive.


29-35: LGTM!

The NewClient constructor function looks good. It takes the necessary dependencies as parameters and returns a new instance of the client struct. The parameter names are clear and descriptive.


37-56: Verify the implementation of the getAccountNumberSequence method and the GetSignedTx method of the Transaction interface.

The SendTx method implementation looks good. It retrieves the account number and sequence, builds a signed transaction, and broadcasts it using the provided dependencies. The error handling is appropriate, returning descriptive errors in case of failures. The method aligns with the PR objectives of sending a transaction.

However, the method relies on the getAccountNumberSequence method and the GetSignedTx method of the Transaction interface, which are not shown in this code segment. Please ensure that these methods are implemented correctly and have appropriate error handling.

Run the following script to verify the implementation of the getAccountNumberSequence method and the GetSignedTx method of the Transaction interface:

Verification successful

Both getAccountNumberSequence and GetSignedTx methods are implemented correctly.

The getAccountNumberSequence method retrieves account details and handles errors appropriately. The GetSignedTx method in tx/transaction.go sets up the transaction builder, configures the transaction, and returns the encoded transaction bytes, handling errors as expected. Both methods align with the requirements for the SendTx method.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the `getAccountNumberSequence` method and the `GetSignedTx` method of the `Transaction` interface.

# Test 1: Search for the implementation of the `getAccountNumberSequence` method. Expect: The method should retrieve the account number and sequence from the `authClient` and return them along with any error.
rg --type go -A 10 $'func \(c \*client\) getAccountNumberSequence\('

# Test 2: Search for the implementation of the `GetSignedTx` method of the `Transaction` interface. Expect: The method should build a signed transaction using the provided account number, sequence, and chain ID, and return the encoded transaction bytes along with any error.
rg --type go -A 10 $'func \(t \*Transaction\) GetSignedTx\('

Length of output: 629


Script:

#!/bin/bash
# Description: Search for the `GetSignedTx` method in the codebase, considering it might be part of a different struct or interface.

# Search for any implementation of a method named `GetSignedTx` in Go files.
rg --type go -A 10 'func \(\w+ \*?\w+\) GetSignedTx\('

Length of output: 1953

tx/transaction.go (3)

15-18: LGTM!

The Transaction interface definition is clear and concise, with appropriate method signatures for the intended functionality. Good job keeping the sign method unexported for better encapsulation.


69-80: Add test coverage for the WithSigner function and sign method.

The WithSigner function and sign method implementation look good. The WithSigner function provides a convenient way to set the signer for a transaction, and the sign method correctly sets up the necessary structs for signing.

However, the static analysis hints indicate missing test coverage for lines 69-71 and 78-80. It's important to add tests to ensure the correctness of the signing functionality.

Do you want me to help write the missing tests for these lines? I can generate test cases that cover the WithSigner function and sign method.

Tools
GitHub Check: codecov/patch

[warning] 69-71: tx/transaction.go#L69-L71
Added lines #L69 - L71 were not covered by tests


[warning] 78-80: tx/transaction.go#L78-L80
Added lines #L78 - L80 were not covered by tests


126-144: Add test coverage for the GetSignedTx method.

The GetSignedTx method implementation looks good. It correctly builds the transaction using the TxBuilder, sets the necessary fields, signs the transaction, and encodes it using the TxEncoder.

However, the static analysis hints indicate missing test coverage for lines 129-130, 132-133, and 135-137. It's important to add tests to ensure the correctness of the transaction building and signing functionality.

Do you want me to help write the missing tests for these lines? I can generate test cases that cover the GetSignedTx method, including scenarios for successful and failed transaction building and signing.

Tools
GitHub Check: codecov/patch

[warning] 129-130: tx/transaction.go#L129-L130
Added lines #L129 - L130 were not covered by tests


[warning] 132-133: tx/transaction.go#L132-L133
Added lines #L132 - L133 were not covered by tests


[warning] 135-137: tx/transaction.go#L135-L137
Added lines #L135 - L137 were not covered by tests

dataverse/client.go (5)

10-14: LGTM!

The new imports are necessary for the functionality being added in this file. The import statements look good.


Line range hint 18-44: Great job on separating the query and transaction functionality!

The renaming of Client to QueryClient and the introduction of the TxClient interface are excellent design choices. It improves the clarity and separation of concerns in the codebase.

The SubmitClaims method taking a signed verifiable credential ensures the integrity of the submitted data.


97-105: The txClient struct is well-designed!

The txClient struct includes the necessary fields for transaction handling, such as tx.Client, client.TxConfig, and keys.Keyring.

Embedding the queryClient in txClient is a good design choice as it allows the transaction client to inherit the query functionality.


107-124: The NewTxClient function is implemented correctly, but test coverage is missing.

The NewTxClient function is well-structured and sets up the transaction client correctly by calling NewQueryClient to initialize the query functionality.

However, the static analysis hints indicate that the added lines (113-116 and 118-123) are not covered by tests.

Please ensure that adequate test coverage is added for the NewTxClient function. You can use the following script to check the test coverage:

If you need any help in adding the missing tests for NewTxClient, feel free to let me know. I'd be happy to assist you in writing the test cases to improve the code coverage.

Tools
GitHub Check: codecov/patch

[warning] 113-116: dataverse/client.go#L113-L116
Added lines #L113 - L116 were not covered by tests


[warning] 118-123: dataverse/client.go#L118-L123
Added lines #L118 - L123 were not covered by tests


Line range hint 48-84: The changes to the queryClient and NewQueryClient look good, but test coverage is missing.

The addition of the contractAddr field to the queryClient struct and the renaming of NewClient to NewQueryClient are appropriate changes.

However, the static analysis hints indicate that some of the added lines (77 and 80) are not covered by tests.

Please ensure that adequate test coverage is added for the modified NewQueryClient function. You can use the following script to check the test coverage:

Verification successful

Test Coverage for NewQueryClient Verified

The NewQueryClient function is covered by tests in the dataverse/client_test.go file. The tests verify both successful client creation and error handling, ensuring that the function's behavior is adequately tested.

  • dataverse/client_test.go: Contains tests for NewQueryClient.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check test coverage for the `NewQueryClient` function.

# Test: Run tests with coverage and generate a coverage report.
go test -coverprofile=coverage.out ./dataverse

# Test: Check if lines 77 and 80 are covered. Expect: Both lines are covered.
go tool cover -func=coverage.out | grep -E 'client.go:(77|80)'

Length of output: 253


Script:

#!/bin/bash
# Find all Go test files in the repository.
fd --extension go --glob '*_test.go'

# Search for references to `NewQueryClient` in the test files.
rg 'NewQueryClient' --glob '*_test.go' -A 5

Length of output: 938

credential/generate_test.go (4)

67-67: LGTM!

The change in the mocking strategy from MockSigner to MockKeyring is appropriate for accommodating the new key management functionality. The change is localized to the test file and does not affect the production code.


70-70: LGTM!

The addition of the expectation for the DIDKeyID() method enhances the test's accuracy in reflecting the expected behavior of the credential generation process. The expected DID key ID matches the format used in the assertions later in the test.


76-76: LGTM!

The addition of the WithSigner option when creating the credential generator enhances the testability of the credential generation process by allowing the signer to be mocked. This change is consistent with the overall modifications in the test to use a mock keyring for signing credentials.


85-85: LGTM!

The update to the assertion for the verificationMethod in the generated credential's proof is consistent with the change in the expected DID key ID format returned by the mock signer. The assertion now accurately verifies that the generated credential's proof contains the correct verificationMethod based on the DID key ID, enhancing the test's accuracy in validating the generated credential's proof.

tx/client_test.go (1)

19-116: LGTM!

The test function is well-structured and covers different scenarios. It uses the gomock library to mock the dependencies, the goconvey library to write the test assertions, and the testutil package to create the mocks. The test function also uses the context package to pass the context to the SendTx method, the testing package to run the test, the fmt package to create the error messages, and the github.com/cosmos/cosmos-sdk packages to create the test data. Overall, the test function follows the best practices and is a good addition to the codebase.

Makefile (5)

80-80: LGTM!

The command for generating mocks for dataverse/client.go follows the established pattern and conventions. It specifies the source file, mock name, package, and destination file correctly.


85-85: LGTM!

The command for generating mocks for the QueryClient interface from the github.com/cosmos/cosmos-sdk/x/auth/types package follows the established pattern and conventions. It specifies the package, mock name, and destination file correctly.


86-86: LGTM!

The command for generating mocks for the ServiceClient interface from the github.com/cosmos/cosmos-sdk/types/tx package follows the established pattern and conventions. It specifies the package, mock name, and destination file correctly.


88-89: LGTM!

The commands for generating mocks for tx/transaction.go and tx/client.go follow the established pattern and conventions. They specify the source files, package, and destination files correctly. The mock name is also specified for tx/client.go to provide a clear naming convention.


90-90: LGTM!

The command for generating mocks for keys/keyring.go follows the established pattern and conventions. It specifies the source file, package, and destination file correctly.

testutil/dataverse_mocks.go (5)

6-6: LGTM!

The comment has been updated to reflect the new mock names used in the mockgen command.


20-34: Looks good!

The renaming of MockClient to MockQueryClient and the associated types provides better clarity on the purpose of these mocks. The changes are consistent and improve the readability of the code.


Line range hint 39-55: LGTM!

The EXPECT method and the RecordCallWithMethodType call have been correctly updated to use the new MockQueryClient type.


88-122: Excellent addition!

The new MockDataverseTxClient correctly mocks the TxClient interface and provides a way to simulate the SubmitClaims method in tests. The implementation is consistent with the existing mocks and follows the expected pattern.


16-16: Good catch!

The import statement for the verifiable package is required for the SubmitClaims method in MockDataverseTxClient. Thanks for adding it.

dataverse/tx.go Show resolved Hide resolved
dataverse/tx.go Show resolved Hide resolved
provider/storage/http.go Show resolved Hide resolved
keys/mnemonic.go Show resolved Hide resolved
provider/storage/proxy.go Show resolved Hide resolved
provider/storage/proxy.go Show resolved Hide resolved
tx/client.go Show resolved Hide resolved
@bdeneux bdeneux self-assigned this Sep 12, 2024
Copy link
Member

@amimart amimart left a comment

Choose a reason for hiding this comment

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

Wonderful! Let's go with this and improve it depending on our needs, this design already cover most of them I guess :)

Copy link
Member

@ccamel ccamel left a comment

Choose a reason for hiding this comment

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

That's good! Thanks 👍

@bdeneux bdeneux merged commit 91de0b6 into main Sep 17, 2024
13 of 14 checks passed
@bdeneux bdeneux deleted the feat/submit-claims branch September 17, 2024 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants