cosmos-sdk/core/testing/context.go
testinginprod b03a2c6b0a
feat(coretesting): add test events service. (#20579)
Co-authored-by: unknown unknown <unknown@unknown>
2024-06-21 14:56:25 +00:00

42 lines
865 B
Go

package coretesting
import (
"context"
"google.golang.org/protobuf/runtime/protoiface"
"cosmossdk.io/core/event"
"cosmossdk.io/core/store"
)
type dummyKey struct{}
func Context() context.Context {
dummy := &dummyCtx{
stores: map[string]store.KVStore{},
events: map[string][]event.Event{},
protoEvents: map[string][]protoiface.MessageV1{},
}
ctx := context.WithValue(context.Background(), dummyKey{}, dummy)
return ctx
}
type dummyCtx struct {
// maps store by the actor.
stores map[string]store.KVStore
// maps event emitted by the actor.
events map[string][]event.Event
// maps proto events emitted by the actor.
protoEvents map[string][]protoiface.MessageV1
}
func unwrap(ctx context.Context) *dummyCtx {
dummy := ctx.Value(dummyKey{})
if dummy == nil {
panic("invalid ctx without dummy")
}
return dummy.(*dummyCtx)
}