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

Refactor and enhance evolution collection precompile with tests and new functionalities #634

Merged
merged 81 commits into from
Jun 26, 2024

Conversation

asiniscalchi
Copy link
Member

@asiniscalchi asiniscalchi commented Jun 21, 2024

PR Type

Enhancement, Tests


Description

  • Refactored and enhanced precompile tests for evolution collection and factory.
  • Implemented new precompile actions and refactored existing functions.
  • Added comprehensive tests for precompile functions.
  • Updated autogenerated weights for pallet_laos_evolution.
  • Added new precompile set for evolution collection.
  • Updated module visibility in runtime configuration.

Changes walkthrough 📝

Relevant files
Tests
tests.rs
Refactor and enhance precompile tests with new functionalities.

precompile/evolution-collection/src/tests.rs

  • Updated imports and dependencies.
  • Modified create_collection and mint functions to use EvmDataWriter.
  • Added new tests for function selectors and log generation.
  • Refactored existing tests to use updated precompile methods.
  • +309/-226
    tests.rs
    Add comprehensive tests for evolution collection precompile.

    pallets/laos-evolution/src/precompiles/evolution_collection/tests.rs

  • Added comprehensive tests for precompile functions.
  • Included tests for function selectors, log generation, and error
    handling.
  • Utilized MockHandle and EvmDataWriter for test setup.
  • +594/-0 
    tests.rs
    Refactor and enhance precompile factory tests with new
    functionalities.

    precompile/evolution-collection-factory/src/tests.rs

  • Updated imports and dependencies.
  • Added new tests for function selectors and log generation.
  • Refactored existing tests to use updated precompile methods.
  • +86/-75 
    Enhancement
    lib.rs
    Implement new precompile actions and refactor existing functions.

    precompile/evolution-collection/src/lib.rs

  • Added new Action enum for function selectors.
  • Implemented Precompile trait for EvolutionCollectionPrecompile.
  • Refactored existing functions to use EvmDataWriter and LogsBuilder.
  • Improved error handling with revert_dispatch_error.
  • +235/-212
    weights.rs
    Update autogenerated weights for pallet_laos_evolution.   

    pallets/laos-evolution/src/weights.rs

  • Updated autogenerated weights for pallet_laos_evolution.
  • Added new weight functions for precompile discriminant and owner.
  • Adjusted existing weight functions for better accuracy.
  • +113/-54
    mod.rs
    Add new precompile set for evolution collection.                 

    pallets/laos-evolution/src/precompiles/evolution_collection/mod.rs

  • Added new precompile set for evolution collection.
  • Implemented discriminant and public functions for precompile.
  • Utilized EvmDataWriter and LogsBuilder for function implementation.
  • +275/-0 
    mod.rs
    Update module visibility in runtime configuration.             

    runtime/laos/src/configs/mod.rs

    • Made evm and laos_evolution modules public.
    +2/-2     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @asiniscalchi
    Copy link
    Member Author

    /describe

    Copy link

    PR Description updated to latest commit (9055c58)

    @asiniscalchi asiniscalchi marked this pull request as ready for review June 25, 2024 07:52
    Copy link
    Contributor

    @luispdm luispdm left a comment

    Choose a reason for hiding this comment

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

    If you intend to implement my suggestions, I will re-review the PR.

    If you decide not to implement my suggestions, I will just approve the PR.

    runtime/laos/src/types/account_id_to_h160.rs Outdated Show resolved Hide resolved
    type AccountStore = System;
    type RuntimeHoldReason = ();
    type DustRemoval = ();
    type WeightInfo = ();
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Another suggestion, no need to implement it in this PR. To avoid redeclaring types for every mock and runtime, you can use the with_default macro together with the TestDefaultConfig in the laos-evolution pallet. There's an example in the polkadot-sdk: https://github.com/paritytech/polkadot-sdk/blob/3c213726cf165d8b1155d5151b9c548e879b5ff8/substrate/frame/sudo/src/lib.rs#L152-L185

    Copy link
    Member Author

    Choose a reason for hiding this comment

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

    good point with_default is very handy ... let's try to use it in a refactor in a new PR

    luispdm
    luispdm previously approved these changes Jun 26, 2024
    * poc
    
    * fmt
    
    * fmt
    
    * better assert
    
    * better assert
    
    * better assert
    
    * better comments
    
    * update weights using runtime benchmarking
    @magecnion
    Copy link
    Contributor

    I suggest taking a look at #633 which adds some test and missing runtime weights. It could complement your changes and add value

    Include gas estimation for `create collection` and `owner`
    @asiniscalchi asiniscalchi merged commit 113dab7 into main Jun 26, 2024
    8 checks passed
    @asiniscalchi asiniscalchi deleted the feature/calculate_gas_of_precompiles branch June 26, 2024 12:15
    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.

    4 participants