Skip to content

[KLC-1409] Update integration tests with Klever Blockchain Mock#12

Merged
nickgs1337 merged 6 commits intomainfrom
KLC-1409-update-integration-tests-with-klever-chain-mock
Jun 4, 2025
Merged

[KLC-1409] Update integration tests with Klever Blockchain Mock#12
nickgs1337 merged 6 commits intomainfrom
KLC-1409-update-integration-tests-with-klever-chain-mock

Conversation

@nickgs1337
Copy link
Copy Markdown

@nickgs1337 nickgs1337 commented Jun 4, 2025

Summary

This PR aproaches the task purpouse of adjusting existing mocks to match the rest of the project structure. Many files were changed and also applied some renaming in old methods.

This PR does not fixes all the tests, the enabled tests are passing in VSCode, but, some disabled tests still failing. I fixed many issues with the failing tests, but, i did not go any further on the investigation because the error was occuring in bridge logic layer apparently, so to avoid missfixing some test because of a missunderstand of the bridge workflow, i prefer to leave that tests as is to the professionals.

Introduction

This pull request introduces significant changes to transition the codebase from supporting the MultiversX blockchain to supporting the Klever blockchain. The changes include renaming functions, data structures, and files to reflect this shift, as well as adding new mock implementations for integration testing with Klever blockchain components.

Transition to Klever Blockchain Support:

  • Renaming Functions and Data Structures:

    • Updated function names in factory/ethKleverBridgeComponents.go to replace references to "MultiversX" with "KleverBlockchain" (e.g., createEthereumToMultiversXBridgecreateEthereumToKleverBlockchainBridge). [1] [2] [3]
  • File and Type Renaming:

    • Renamed integrationTests/mock/multiversXContractStateMock.go to integrationTests/mock/KleverContractStateMock.go and updated all type names within the file to align with Klever blockchain terminology (e.g., multiversXProposedStatuskleverBlockchainProposedStatus). [1] [2] [3]

New Mock Implementations for Klever Blockchain:

  • kleverBlockchainAccountsMock:

    • Added a mock implementation for Klever blockchain accounts to simulate account creation, nonce updates, and retrieval.
  • KleverBlockchainMock:

    • Introduced a comprehensive mock for Klever blockchain interactions, including methods for estimating transaction fees, executing VM queries, managing accounts, and sending transactions. This mock replaces the previous MultiversX-related mock functionality.

Miscellaneous Updates:

  • Hashing Updates:
    • Replaced MultiversX-specific hashing logic with Klever blockchain hashing using the blake2b algorithm. [1] [2]

These changes collectively prepare the codebase for integration with the Klever blockchain ecosystem, ensuring compatibility and providing robust testing support.

Summary by CodeRabbit

  • Refactor
    • Updated all references from "MultiversX" to "KleverBlockchain" across mocks, types, and configuration, including renaming types, methods, and file naming patterns.
    • Adjusted configuration and test files to use new naming conventions and mock implementations for the Klever blockchain.
    • Renamed internal method calls to reflect Klever blockchain naming without changing functionality.
  • New Features
    • Introduced mock implementations for Klever blockchain accounts and chain, supporting integration testing with in-memory account and transaction management.
  • Chores
    • Added an empty workspace configuration file for Klever blockchain integration.
  • Removed
    • Deleted legacy MultiversX mock implementations and related test code.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jun 4, 2025

Walkthrough

The codebase was refactored to replace all references to the MultiversX blockchain with the Klever blockchain, affecting mock implementations, configuration keys, file naming conventions, and method/type names throughout integration tests and factory components. New mock files for Klever blockchain were introduced, while MultiversX-specific mocks were removed. No core logic or control flow was altered.

Changes

File(s) Change Summary
factory/ethKleverBridgeComponents.go Renamed methods and invocations from MultiversX to KleverBlockchain in bridge components.
integrationTests/mock/KleverAccountsMock.go Added Klever blockchain accounts mock with methods for account retrieval and nonce updates.
integrationTests/mock/KleverChainMock.go Added comprehensive Klever blockchain mock implementing proxy interface for integration testing.
integrationTests/mock/KleverContractStateMock.go Refactored contract state mock: renamed types, variables, and methods from MultiversX to KleverBlockchain.
integrationTests/mock/multiversXAccountsMock.go Removed MultiversX accounts mock.
integrationTests/mock/multiversXChainMock.go Removed MultiversX chain mock and all related methods.
integrationTests/relayers/common.go Updated config: changed PEM file pattern and state machine keys to KleverBlockchain equivalents.
integrationTests/relayers/ethToKleverBlockchain_test.go Updated test to use KleverBlockchainMock instead of MultiversXChainMock; adjusted function signatures.
integrationTests/relayers/kleverBlockchainToEth_test.go Refactored test: replaced MultiversX mocks/types with KleverBlockchain equivalents; updated helper signatures.
integrationTests/relayers/slowTests/framework/keys.go Changed relayer PEM file naming pattern from multiversx to klever.
kleverchain.workspace.json Added empty workspace JSON file.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Integration Test
    participant KleverMock as KleverBlockchainMock
    participant AccountsMock as KleverAccountsMock

    Test->>KleverMock: SendTransaction/SendTransactions
    KleverMock->>AccountsMock: updateNonce(address, nonce)
    Test->>KleverMock: ExecuteVMQuery
    KleverMock-->>Test: Return VM query response
    Test->>KleverMock: GetAccount(address)
    KleverMock-->>Test: Return mock account
Loading

Poem

In fields of code where blockchains hop,
MultiversX has made a swap—
Klever’s now the name we cheer,
With mocks and keys that all appear.
A bridge rebuilt, a test anew,
The rabbits dance in code review!
🐇✨

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e999059 and 3dde181.

⛔ Files ignored due to path filters (3)
  • integrationTests/relayers/testdata/klever0.pem is excluded by !**/*.pem
  • integrationTests/relayers/testdata/klever1.pem is excluded by !**/*.pem
  • integrationTests/relayers/testdata/klever2.pem is excluded by !**/*.pem
📒 Files selected for processing (1)
  • integrationTests/mock/KleverChainMock.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • integrationTests/mock/KleverChainMock.go
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

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
Copy Markdown

@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: 6

🔭 Outside diff range comments (1)
integrationTests/mock/KleverContractStateMock.go (1)

492-503: 🛠️ Refactor suggestion

Shadowing the imported address package and discarding errors hampers readability

address variable shadows the imported package name, and the error from NewAddressFromBytes is only logged via panic.
Return a NOK VM response instead of crashing, and rename the local to avoid confusion:

- addressBytes, err := hex.DecodeString(hexAddress)
+ addrBytes, err := hex.DecodeString(hexAddress)

- address, err := address.NewAddressFromBytes(addressBytes)
+ addr, err := address.NewAddressFromBytes(addrBytes)
  if err != nil {
-     panic(err)
+     return createNokVmResponse(err)
  }
- bech32Address := address.Bech32()
+ bech32Address := addr.Bech32()
🧹 Nitpick comments (11)
kleverchain.workspace.json (1)

1-1: Document or remove empty workspace file
This file currently contains only {}; please clarify its intended content or usage in project workflows or remove it if it's unnecessary as a placeholder.

integrationTests/relayers/ethToKleverBlockchain_test.go (3)

103-103: Refactor variable name for clarity
The mock instantiation is assigned to multiversXChainMock despite using NewKleverBlockchainMock(). Rename the variable to kleverChainMock (and update its references) to avoid confusion.


319-319: Consistent mock variable naming in second test
Similarly, change multiversXChainMock := mock.NewKleverBlockchainMock() to kleverChainMock := mock.NewKleverBlockchainMock() and update all downstream uses.


399-400: Update helper function parameter name
In createMockBridgeComponentsArgs, the parameter multiversXChainMock *mock.KleverBlockchainMock should be renamed to kleverChainMock to match the new mock type and avoid mixing legacy naming.

integrationTests/mock/KleverAccountsMock.go (1)

29-32: updateNonce should populate the Account if it was just created

getOrCreate returns a blank models.Account{}.
Consider at least storing the address string so further assertions can rely on it:

 if !found {
     acc = &models.Account{}
     mock.accounts[addrAsString] = acc
 }
+acc.Address = addrAsString
integrationTests/relayers/kleverBlockchainToEth_test.go (3)

34-41: Rename test to reflect Klever instead of MultiversX

After the migration the test name and helper still contain “MultiversX”.
Keeping old names is confusing and may mislead grep-based tooling.

-func TestRelayersShouldExecuteSimpleTransfersFromMultiversXToEth(t *testing.T) {
+func TestRelayersShouldExecuteSimpleTransfersFromKleverToEth(t *testing.T) {

Apply similar renames for the second test and helper functions.


61-69: Variable name no longer matches the underlying type

multiversXChainMock := mock.NewKleverBlockchainMock()

Using multiversXChainMock for a Klever mock breaks readability and may cause accidental mix-ups later.
Rename to klvChainMock (or similar) throughout the file.


249-257: Use Klever address generator for deposit source

testsCommon.CreateRandomMultiversXAddress() survived the rename.
Switch to a Klever-specific helper (or reuse a generic one) to avoid semantic confusion.

-From:   testsCommon.CreateRandomMultiversXAddress(),
+From:   testsCommon.CreateRandomKleverAddress(),
integrationTests/mock/KleverChainMock.go (1)

64-69: Prefer read lock for pure read operation

GetAccount acquires a full write lock (Lock) even though it only reads from the map after getOrCreate.
Use RLock to improve concurrency – getOrCreate already handles mutation internally.

integrationTests/mock/KleverContractStateMock.go (2)

157-163: Avoid per-call Blake2b hasher allocation

factoryHasher.NewHasher("blake2b") is relatively expensive and is invoked on every status / transfer creation.
Cache the hasher once at struct level (or use sync.Once) to improve test-suite latency.

-type kleverBlockchainContractStateMock struct {
+type kleverBlockchainContractStateMock struct {
     *tokensRegistryMock
+    hasher hashing.Hasher
     ...
 }

 func newKleverBlockchainContractStateMock() *kleverBlockchainContractStateMock {
     mock := &kleverBlockchainContractStateMock{
         tokensRegistryMock: &tokensRegistryMock{},
+        hasher:             must(factoryHasher.NewHasher("blake2b")),
     }

(Use a small helper must() or inline error handling.)

Also applies to: 220-226


215-218: Minor: unnecessary temporary indexIncrementValue

indexIncrementValue is constant (6) and only used once:

- indexIncrementValue := 6
- ...
- currentIndex += indexIncrementValue
+ currentIndex += 6
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8fdeaff and e999059.

⛔ Files ignored due to path filters (3)
  • integrationTests/relayers/testdata/multiversx0.pem is excluded by !**/*.pem
  • integrationTests/relayers/testdata/multiversx1.pem is excluded by !**/*.pem
  • integrationTests/relayers/testdata/multiversx2.pem is excluded by !**/*.pem
📒 Files selected for processing (11)
  • factory/ethKleverBridgeComponents.go (3 hunks)
  • integrationTests/mock/KleverAccountsMock.go (1 hunks)
  • integrationTests/mock/KleverChainMock.go (1 hunks)
  • integrationTests/mock/KleverContractStateMock.go (24 hunks)
  • integrationTests/mock/multiversXAccountsMock.go (0 hunks)
  • integrationTests/mock/multiversXChainMock.go (0 hunks)
  • integrationTests/relayers/common.go (2 hunks)
  • integrationTests/relayers/ethToKleverBlockchain_test.go (4 hunks)
  • integrationTests/relayers/kleverBlockchainToEth_test.go (7 hunks)
  • integrationTests/relayers/slowTests/framework/keys.go (1 hunks)
  • kleverchain.workspace.json (1 hunks)
💤 Files with no reviewable changes (2)
  • integrationTests/mock/multiversXAccountsMock.go
  • integrationTests/mock/multiversXChainMock.go
🧰 Additional context used
🧬 Code Graph Analysis (4)
integrationTests/relayers/ethToKleverBlockchain_test.go (1)
integrationTests/mock/KleverChainMock.go (2)
  • NewKleverBlockchainMock (34-40)
  • KleverBlockchainMock (26-31)
integrationTests/mock/KleverAccountsMock.go (2)
clients/klever/proxy/models/accounts.go (1)
  • Account (8-13)
clients/klever/blockchain/address/interfaces.go (1)
  • Address (3-10)
integrationTests/relayers/kleverBlockchainToEth_test.go (5)
integrationTests/mock/KleverChainMock.go (2)
  • NewKleverBlockchainMock (34-40)
  • KleverBlockchainMock (26-31)
integrationTests/mock/KleverContractStateMock.go (2)
  • KleverBlockchainPendingBatch (40-43)
  • KleverBlockchainDeposit (46-52)
clients/klever/blockchain/address/interfaces.go (1)
  • Address (3-10)
testsCommon/addressGenerators.go (1)
  • CreateRandomEthereumAddress (11-16)
integrationTests/mock/ethereumChainMock.go (1)
  • EthereumChainMock (30-50)
integrationTests/mock/KleverChainMock.go (8)
clients/klever/proxy/models/vmValues.go (2)
  • VmValueRequest (29-35)
  • VmValuesResponseData (8-10)
clients/klever/blockchain/address/interfaces.go (1)
  • Address (3-10)
clients/klever/proxy/models/accounts.go (1)
  • Account (8-13)
clients/klever/proxy/models/transactions.go (1)
  • KDAFungibleTokenData (50-54)
clients/klever/proxy/models/network.go (2)
  • NetworkConfig (12-19)
  • NodeOverview (32-44)
clients/klever/blockchain/address/address.go (1)
  • NewAddress (59-80)
integrationTests/testscommon.go (1)
  • TestMarshalizer (31-31)
integrationTests/mock/KleverContractStateMock.go (2)
  • KleverBlockchainPendingBatch (40-43)
  • KleverBlockchainDeposit (46-52)
🔇 Additional comments (10)
integrationTests/relayers/slowTests/framework/keys.go (1)

22-22: Rename PEM path format for Klever keys
The update from "multiversx%d.pem" to "klever%d.pem" looks correct. Ensure that any existing test fixture files or scripts producing PEM files are updated to match this new pattern.

integrationTests/relayers/common.go (2)

96-96: Align Klever private key file path
Using fmt.Sprintf("klever%d.pem", index) is consistent with the renamed PEM format. No further action needed unless downstream code still references the old filename.


111-112: Update state machine keys to Klever context
The keys "EthereumToKleverBlockchain" and "KleverBlockchainToEthereum" correctly replace the old MultiversX constants. This matches factory renames and ensures state machines are wired properly.

factory/ethKleverBridgeComponents.go (4)

177-181: Invoke renamed bridge creation method
The call to createEthereumToKleverBlockchainBridge correctly replaces the old MultiversX variant. Ensure no leftover calls to createEthereumToMultiversXBridge remain.


182-186: Invoke renamed state machine creation method
Calling createEthereumToKleverBlockchainStateMachine is consistent with the new naming. All related tests and state machine mappings should align with this.


487-555: Rename createEthereumToKleverBlockchainBridge function signature
The function has been updated to match the new naming. Verify that the StateMachine keys ("EthereumToKleverBlockchain") correspond to this name in configuration.


674-709: Rename createEthereumToKleverBlockchainStateMachine function signature
The renamed state machine constructor aligns with the bridge method. Confirm that polling handlers and log identifiers use the updated name.

integrationTests/relayers/kleverBlockchainToEth_test.go (1)

117-120: callIsFromBalanceValidator still looks for “PendingMvxBatches”

The stack-frame check is now brittle because the function names changed. Update the substring to the Klever equivalent or refactor the validator detection altogether.

integrationTests/mock/KleverChainMock.go (1)

156-163: addTokensPair already locks – avoid double locking

AddTokensPair acquires the outer lock and then calls mock.addTokensPair, which (inside kleverBlockchainContractStateMock) also takes a lock.
Consider exposing an un-locked helper or dropping the outer lock to prevent future deadlocks if lock ordering changes.

integrationTests/mock/KleverContractStateMock.go (1)

560-576: Inconsistent ReturnCode capitalisation between OK/NOK responses

createOkVmResponse returns "Ok" (capital “O”) while createNokVmResponse returns "nok" (lowercase).
If callers perform case-sensitive checks (very common in mocks), this asymmetry causes subtle bugs.

-            ReturnCode: "Ok",
+            ReturnCode: "ok",

or change the NOK path to "Nok" – just keep them aligned.

@nickgs1337
Copy link
Copy Markdown
Author

I am manually merging this PR because there are some CI errors, but the CI is not set up yet. Also, it is not the purpose of this PR to fix the CI.

@nickgs1337 nickgs1337 merged commit 65b0425 into main Jun 4, 2025
1 of 6 checks passed
@nickgs1337 nickgs1337 deleted the KLC-1409-update-integration-tests-with-klever-chain-mock branch June 4, 2025 13:10
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.

2 participants