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

Feat ICP Context contract #985

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open

Feat ICP Context contract #985

wants to merge 31 commits into from

Conversation

alenmestrov
Copy link
Member

@alenmestrov alenmestrov commented Nov 26, 2024

Created ICP Version of Context Contract

Summary

This PR adds the Internet Computer (ICP) implementation of the context-config contract, mirroring the existing NEAR implementation.

Changes

New Implementation

  • Added ICP-specific contract implementation using Candid types.
  • Implemented core types matching NEAR's structure:
    • Base ICIdentity wrapper for 32-byte arrays.
    • Identity types: ICSignerId, ICContextIdentity, ICContextId.
    • Application types: ICApplication, ICApplicationId, ICBlobId.
    • Request types: Request, ContextRequest, ContextRequestKind.
    • Capability management: ICCapability.

Integration Tests

  • Added comprehensive test suite covering:
    • Basic context operations.
    • Member management.
    • Capability management.
    • Edge cases and timestamp scenarios.
    • Concurrent operations.

Compatibility

  • Ensures compatibility with NEAR implementation through proper type conversions.
  • Maintains consistent behavior across both platforms.

Testing

  • All tests pass in the local ICP test environment (PocketIC).

Build and Test Instructions

  1. Prerequisites:
  • Ensure that DFX is installed.

  • Add candid-extractor cargo add candid-extractor for generation of .did file

  1. Build Script: Use the provided build.sh script to build, deploy, and prepare the contract for local testing.

    • The script performs the following steps:

      • Checks that device has wasm32 target installed
      • Builds the wasm contract
      • Generates .did file based on contract
      • Stops the local environment (if its not running it doesn't do anything)
      • Starts the local environment
      • Deploys the contract
  2. Run Tests: Execute the following command to build and run the integration tests:

    ./build.sh && cargo test --test integration -- --nocapture

Notes

  • To be able to test the contract you will need to download and add pocket-ic in the context-config folder
  • Currently, deployment and update of the proxy contract is not implemented, this will be done after finalization of Proxy Contract

@alenmestrov alenmestrov self-assigned this Nov 26, 2024
@alenmestrov alenmestrov marked this pull request as ready for review November 27, 2024 18:45
contracts/icp/context-config/.env Outdated Show resolved Hide resolved
contracts/icp/context-config/src/error.rs Outdated Show resolved Hide resolved
contracts/icp/context-config/src/types.rs Outdated Show resolved Hide resolved
contracts/icp/context-config/src/types.rs Outdated Show resolved Hide resolved
contracts/icp/context-config/src/types.rs Outdated Show resolved Hide resolved
@frdomovic
Copy link
Member

Add this requirement for building and deploying the contract - https://crates.io/crates/candid-extractor

contracts/icp/context-config/Cargo.lock Outdated Show resolved Hide resolved
contracts/icp/context-config/src/guard.rs Outdated Show resolved Hide resolved
contracts/icp/context-config/src/guard.rs Outdated Show resolved Hide resolved
contracts/icp/context-config/src/mutate.rs Outdated Show resolved Hide resolved
contracts/icp/context-config/src/mutate.rs Outdated Show resolved Hide resolved
contracts/icp/context-config/src/mutate.rs Outdated Show resolved Hide resolved
contracts/icp/context-config/src/types.rs Outdated Show resolved Hide resolved
contracts/icp/context-config/src/types.rs Outdated Show resolved Hide resolved
contracts/icp/context-config/src/types.rs Outdated Show resolved Hide resolved
contracts/icp/context-config/src/lib.rs Show resolved Hide resolved
contracts/icp/context-config/src/types.rs Outdated Show resolved Hide resolved
contracts/icp/context-config/tests/integration.rs Outdated Show resolved Hide resolved
contracts/icp/context-config/src/mutate.rs Outdated Show resolved Hide resolved
contracts/icp/context-config/src/mutate.rs Outdated Show resolved Hide resolved
contracts/icp/context-config/src/mutate.rs Outdated Show resolved Hide resolved
contracts/icp/context-config/src/types.rs Outdated Show resolved Hide resolved
contracts/icp/context-config/src/types.rs Outdated Show resolved Hide resolved
contracts/icp/context-config/src/types.rs Outdated Show resolved Hide resolved
contracts/icp/context-config/src/types.rs Outdated Show resolved Hide resolved
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