-
Notifications
You must be signed in to change notification settings - Fork 468
Description
Target
As discussed recently, it would be a beneficial to integrate DRink!
to the ink! E2E framework. The ultimate goal would be to enable developers to write:
#[ink::e2e_test(backend = "node")]
fn contract_test() { ... }
// or
#[ink::e2e_test(backend = "runtime-only", runtime = my_chain_lib::Runtime)]
fn contract_test() { ... }
i.e. to be able to either:
- run contract tests on a full stack (as it is done now: running a node in the background, by default
substrate-contracts-node
), or - run contract tests directly in the runtime (just like pallet unit tests); this is the approach that
DRink!
library provides (together with a customizable runtime)
Rationale
While every production contract ought to be tested in the full target environment, it is often very onerous to run such tests during early/local development. This is due to e.g. node/network configuration issues, blocktime/finalization or overhead coming from asynchronous communication between e2e client and RPC chain service. Thus we find it useful, to skip the whole node layer while testing contracts (although the topic applies to generally whole runtime testing).
Interacting directly with runtime might be seen as 'quasi-end-to-end' testing, and hence can't replace old framework, but still gives some benefits:
- synchronous, instant operations (no need for sending transaction, transaction pool processing, block production, finalization, block/event subscriptions, etc.)
- direct, full-power access to runtime (skipping million blocks, setting timestamps, balance control)
- access to runtime internals (e.g. accessing contract's debug buffer or contract execution stack frames in the contracts pallet)
- no setup apart from choosing runtime (no node-per-test running, opening ports etc.)
Plan
The work will be done as a series of smaller steps
### Tasks
- [x] Make `drink` generic over runtime (to do outside this repository)
- [x] Create a trait for E2E backend - put current `Client`'s capabilities behind a trait + use opaque type in the test body
- [x] Add to `ink::e2e_test` macro a new attribute for choosing backend. In case of `"runtime-only"` one, allow for specifying desired runtime. There should be also an option for choosing custom backend implementation.
- [x] Implement the trait for `Session` from `drink` library