test

Attribute Macro test 

Source
#[test]
Expand description

Defines a drink!-based test.

§Requirements

  • Your crate must have drink in its dependencies (and it shouldn’t be renamed).
  • You mustn’t import drink::test in the scope, where the macro is used. In other words, you should always use the macro only with a qualified path #[drink::test].
  • Your crate cannot be part of a cargo workspace.

§Impact

This macro will take care of building all needed contracts for the test. The building process will be executed during compile time.

Contracts to be built:

  • current cargo package if contains a ink-as-dependency feature
  • all dependencies declared in the Cargo.toml file with the ink-as-dependency feature enabled (works with non-local packages as well).

§Compilation features

  1. The root contract package (if any) is assumed to be built without any features.

  2. All contract dependencies will be built with a union of all features enabled on that package (through potentially different configurations or dependency paths), excluding ink-as-dependency and std features.

§Creating a session object

The macro will also create a new mutable session object and pass it to the decorated function by value. You can configure which sandbox should be used (by specifying a path to a type implementing ink_sandbox::Sandbox trait. Thus, your testcase function should accept a single argument: mut session: Session<_>.

By default, the macro will use drink::minimal::MinimalSandbox.

§Example

#[drink::test]
fn testcase(mut session: Session<MinimalSandbox>) {
    session
        .deploy_bundle(&get_bundle(), "new", NO_ARGS, NO_SALT, NO_ENDOWMENT)
        .unwrap();
}