1package vmkit23import"gno.land/p/nt/avl/v0"45// TestHost is a deterministic in-memory [Host] for unit tests and for6// measuring a machine without a chain under it.7//8
Functions
not supported for pure packages by the node (vm/qfuncs)
Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.
// Nothing here reads the chain, so a test that uses it produces the same
9// numbers on every host. Storage is an avl tree rather than a map because gno
10// map iteration order is unspecified, and [TestHost.Keys] has to be stable for
11// a test to assert on it.
12//
13// Send is denied unless [TestHost.Grant] funded a budget, which is how the
14// capability rule gets tested: a guest that tries to send without a grant must
15// come back [Trapped], not silently succeed.
16type TestHost struct {
17 caller address
18 origin address
19 now int64
20 height int64
21
22 store *avl.Tree // hex key -> []byte
23
24 in []byte
25 out []byte
26 events []string
27 logs []string
28
29 sendBudget int64
30 sends []Transfer
31}
32
33// Transfer records one successful [TestHost.Send].
34type Transfer struct {
35 To address
36 Amount int64
37}
38
39// NewTestHost returns a host with no capabilities granted, height 1, time 0,
40// and empty input.
41func NewTestHost() *TestHost {
42return &TestHost{
43 height: 1,
44 store: avl.NewTree(),
45 }
46}
47
48// WithCaller sets the address the guest sees as its caller and origin.