diff --git a/x/wasm/keeper/metrics.go b/x/wasm/keeper/metrics.go index 4c4b959f50..93f88581ca 100644 --- a/x/wasm/keeper/metrics.go +++ b/x/wasm/keeper/metrics.go @@ -29,6 +29,9 @@ type WasmVMMetricsCollector struct { // NewWasmVMMetricsCollector constructor func NewWasmVMMetricsCollector(s metricSource) *WasmVMMetricsCollector { + if s == nil { + panic("wasmvm instance must not be nil") + } return &WasmVMMetricsCollector{ source: s, CacheHitsDescr: prometheus.NewDesc("wasmvm_cache_hits_total", "Total number of cache hits", []string{"type"}, nil), diff --git a/x/wasm/keeper/options_test.go b/x/wasm/keeper/options_test.go index d15b3bf58a..2d65584142 100644 --- a/x/wasm/keeper/options_test.go +++ b/x/wasm/keeper/options_test.go @@ -1,6 +1,7 @@ package keeper import ( + "github.com/prometheus/client_golang/prometheus" "reflect" "testing" @@ -31,6 +32,14 @@ func TestConstructorOptions(t *testing.T) { assert.IsType(t, &wasmtesting.MockWasmer{}, k.wasmVM) }, }, + "vm cache metrics": { + srcOpt: WithVMCacheMetrics(prometheus.DefaultRegisterer), + verify: func(t *testing.T, k Keeper) { + t.Helper() + registered := prometheus.DefaultRegisterer.Unregister(NewWasmVMMetricsCollector(k.wasmVM)) + assert.True(t, registered) + }, + }, "decorate wasmvm": { srcOpt: WithWasmEngineDecorator(func(old types.WasmerEngine) types.WasmerEngine { require.IsType(t, &wasmvm.VM{}, old)