wasm_storage_conformance (wasm_storage v0.1.0)

View Source

The checks every storage provider must pass, as plain functions.

The wasm_storage contract (the storage contract) is checked case by case against a provider you describe with two funs. Run it from Common Test for your own provider:

all() -> wasm_storage_conformance:cases().

init_per_testcase(_, Config) ->
    Dir = ?config(priv_dir, Config),
    Path = filename:join(Dir, "dev"),
    [{target, #{open => fun() -> wasm_storage:open({my_provider, Path},
                                                   #{create => true}) end,
                reopen => fun() -> wasm_storage:open({my_provider, Path},
                                                     #{}) end}}
     | Config].

Case(Config) ->
    ok = wasm_storage_conformance:run(Case, ?config(target, Config)).

open returns a fresh, empty device. reopen, optional, returns a second handle to the same device; the cases that need it are skipped without it. A failing case raises error({conformance, Case, Detail}).

Summary

Functions

The names of every case, in a sensible order.

Run one case. Returns ok or {skip, Why}.

Types

target()

-type target() ::
          #{open := fun(() -> {ok, wasm_storage:handle()}),
            reopen => fun(() -> {ok, wasm_storage:handle()})}.

Functions

cases()

-spec cases() -> [atom()].

The names of every case, in a sensible order.

run/2

-spec run(atom(), target()) -> ok | {skip, term()}.

Run one case. Returns ok or {skip, Why}.