Attribute Macro drink_next::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

Note: Depending on a non-local contract is not tested yet.

§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 runtime should be used (by specifying a path to a type implementing drink::runtime::Runtime trait. Thus, your testcase function should accept a single argument: mut session: Session<_>.

By default, the macro will use drink::runtime::MinimalRuntime.

§Example

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