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

Resolve confusion of #[test] vs. #[ink::test] #714

Closed
cmichi opened this issue Mar 3, 2021 · 2 comments
Closed

Resolve confusion of #[test] vs. #[ink::test] #714

cmichi opened this issue Mar 3, 2021 · 2 comments
Labels
A-ink_lang [ink_lang] Work item B-research Research task that has open questions that need to be resolved.

Comments

@cmichi
Copy link
Collaborator

cmichi commented Mar 3, 2021

Escalated from use-ink/cargo-contract#190.

Problem

There is often confusion when to use #[test] vs. #[ink::test].

The implication of #[ink::test] is that the test annotated with it is run in a emulated chain environment (we call this "off-chain testing"). This comes with a bit of overhead for spawning this emulation. This emulation is not needed for every test, only for the ones where e.g. chain storage or the env() API is involved.

For users starting out with ink! it can be hard to know when it's necessary to have an emulated chain, which can result in strange errors if #[test] is used but an emulation is necessary.

Proposals

  1. Just replace #[test] with #[ink::test] for every single test and live with the slight performance overhead.
  2. Improve naming and split attribute like this:
    #[test]
    #[ink::emulate_chain]
    fn foo_test() { ... }
    

My opinion

My opinion is that we will always have this issue as long as we use different attributes for tests which require an emulated chain and ones which don't. I would just replace #[test] with #[ink::test] in all examples and public documentation and trade a slight decrease in performance for an improved UX with less friction.

@cmichi cmichi added A-ink_lang [ink_lang] Work item B-research Research task that has open questions that need to be resolved. labels Mar 3, 2021
@hychen
Copy link
Contributor

hychen commented Mar 4, 2021

I prefer proposal#1. As a developer who builds something on ink!, I'll assume I should always use [ink!...] macros provided by ink! everywhere as minimum build blocks of my smart contracts. To figure out when to use #[test], when to use #[ink:test] is kind of an abstract leak to me.

@cmichi
Copy link
Collaborator Author

cmichi commented Apr 6, 2021

All necessary repos have been adapted, closing this issue.

@cmichi cmichi closed this as completed Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ink_lang [ink_lang] Work item B-research Research task that has open questions that need to be resolved.
Projects
None yet
Development

No branches or pull requests

2 participants