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

Add example for mocking chain extensions in off-chain tests #882

Merged

Conversation

cmichi
Copy link
Collaborator

@cmichi cmichi commented Jul 29, 2021

No description provided.

@cmichi cmichi requested a review from HCastano July 29, 2021 17:42
examples/rand-extension/lib.rs Outdated Show resolved Hide resolved
examples/rand-extension/lib.rs Show resolved Hide resolved
@HCastano HCastano added the A-examples [examples] Work item label Jul 29, 2021
fn chain_extension_works() {
// given
struct MockedExtension;
impl ink_env::test::ChainExtension for MockedExtension {

Choose a reason for hiding this comment

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

Do I need to mock chain extension inside every test function? Is there anyway to define outside and use that in all functions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You can also define it outside, I just mocked it in here since it's only used in this one test.

@frankli-dev
Copy link

I'm getting the following error

862 |             impl ink_env::test::ChainExtension for MockedExtension {
    |                                 ^^^^^^^^^^^^^^ private trait
    |
note: the trait `ChainExtension` is defined here
   --> /Users/mac/.cargo/registry/src/github.com-1ecc6299db9ec823/ink_env-3.0.0-rc3/src/engine/off_chain/test_api.rs:18:5
    |
18  |     chain_extension::ChainExtension,

I think, this PR covers the above issue but does it mean that once the PR is merged, I need to use the latest ink?

@cmichi
Copy link
Collaborator Author

cmichi commented Jul 30, 2021

I think, this PR covers the above issue but does it mean that once the PR is merged, I need to use the latest ink?

@frankli-dev Yes, until we release the next release candidate you need to reference the git repository for your Cargo.toml dependencies. The error you get is because this PR was not merged yet, after it's merged it will work.

@cmichi cmichi merged commit eb44ace into master Jul 30, 2021
@cmichi cmichi deleted the cmichi-implement-off-chain-testing-for-chain-extensions branch July 30, 2021 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-examples [examples] Work item
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants