Files
tendermint/internal/pubsub/example_test.go
M. J. Fromberger 441ecbaeec types: rename and extend the EventData interface (#7687)
This is the interface shared by types that can be used as event data in, for
example, subscriptions via the RPC.

To be compatible with the RPC service, data need to support JSON encoding.
Require this as part of the interface.
2022-01-26 07:01:55 -08:00

35 lines
891 B
Go

package pubsub_test
import (
"context"
"testing"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/internal/pubsub"
"github.com/tendermint/tendermint/internal/pubsub/query"
"github.com/tendermint/tendermint/libs/log"
)
func TestExample(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
s := newTestServer(ctx, t, log.TestingLogger())
sub := newTestSub(t).must(s.SubscribeWithArgs(ctx, pubsub.SubscribeArgs{
ClientID: "example-client",
Query: query.MustCompile(`abci.account.name='John'`),
}))
events := []abci.Event{
{
Type: "abci.account",
Attributes: []abci.EventAttribute{{Key: "name", Value: "John"}},
},
}
require.NoError(t, s.PublishWithEvents(ctx, pubstring("Tombstone"), events))
sub.mustReceive(ctx, pubstring("Tombstone"))
}