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

Mock sdk/syscalls for testing #1731

Open
Stebalien opened this issue Mar 28, 2023 · 0 comments
Open

Mock sdk/syscalls for testing #1731

Stebalien opened this issue Mar 28, 2023 · 0 comments
Labels
Kind: Improvement An improvement of something that exists. Topic: Testing

Comments

@Stebalien
Copy link
Member

We should have a "mock sdk" for native unit testing (i.e., without a wasm VM). For completeness, we should provide both an SDK mock and a low-level syscall mock.

The core design is to introduce:

  1. A compile time flag to enable the mock sdk/runtime.
  2. A special MockRuntime trait that:
    1. Is invoked by the mock syscalls/sdk.
    2. Is implemented by the user and/or testing framework.
  3. A thread-local variable to store a MockRuntime. A unit test would bind a new runtime to said thread-local variable while executing the test.
  4. Mock implementations of the syscalls and/or sdk methods that call the MockRuntime currently stashed in the thread-local variable instead of making "real" system calls.

Mock SDK

The first option is to mock the SDK itself. I.e., the high-level methods but not fvm_sdk::sys::*.

Advantages:

  • Higher-level and easier to mock.

Disadvantages:

  • Can't be used to test the SDK.
  • Not appropriate for testing alternative SDKs.

Mock Syscalls

The second option is to mock fvm_sdk::sys. Basically, we'd replace the current FFI declarations with actual functions that call into a mock runtime.

Advantages:

  • Low-level and suitable for testing the SDK itself.

Disadvantages:

  • Requires re-implementing the FVM's logic around IPLD block IDs.
  • Annoying to work with low-level/FFI-safe types (lots of encoding, decoding, raw pointers, etc.
@Stebalien Stebalien added Kind: Improvement An improvement of something that exists. Topic: Testing labels Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Kind: Improvement An improvement of something that exists. Topic: Testing
Projects
None yet
Development

No branches or pull requests

1 participant