e91ec58aa1
* evm: fixed commented out simulations, pubsub, and handler tests fixes #640 simulations are very basic: they can be built and executed, but they don't generate any EVM-related transactions yet. (It should be a matter of adding simulation-related code to the modules + potentially extra helpers to the simulation.) handler tests miss some extra assertions due to changes in the return values snapshotting logic (ADR-001 and ADR-002). Besides the test suites identified in the audit, there's also "importer_test.go" which wasn't yet fixed. (it'd require major rewriting + extra test resources) * gofumpt
83 lines
1.5 KiB
Go
83 lines
1.5 KiB
Go
package pubsub
|
|
|
|
import (
|
|
"log"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
coretypes "github.com/tendermint/tendermint/rpc/core/types"
|
|
)
|
|
|
|
func TestAddTopic(t *testing.T) {
|
|
q := NewEventBus()
|
|
err := q.AddTopic("kek", make(<-chan coretypes.ResultEvent))
|
|
require.NoError(t, err)
|
|
|
|
err = q.AddTopic("lol", make(<-chan coretypes.ResultEvent))
|
|
require.NoError(t, err)
|
|
|
|
err = q.AddTopic("lol", make(<-chan coretypes.ResultEvent))
|
|
require.Error(t, err)
|
|
|
|
require.EqualValues(t, []string{"kek", "lol"}, q.Topics())
|
|
}
|
|
|
|
func TestSubscribe(t *testing.T) {
|
|
q := NewEventBus()
|
|
kekSrc := make(chan coretypes.ResultEvent)
|
|
|
|
q.AddTopic("kek", kekSrc)
|
|
|
|
lolSrc := make(chan coretypes.ResultEvent)
|
|
|
|
q.AddTopic("lol", lolSrc)
|
|
|
|
kekSubC, err := q.Subscribe("kek")
|
|
require.NoError(t, err)
|
|
|
|
lolSubC, err := q.Subscribe("lol")
|
|
require.NoError(t, err)
|
|
|
|
lol2SubC, err := q.Subscribe("lol")
|
|
require.NoError(t, err)
|
|
|
|
wg := new(sync.WaitGroup)
|
|
wg.Add(4)
|
|
|
|
emptyMsg := coretypes.ResultEvent{}
|
|
go func() {
|
|
defer wg.Done()
|
|
msg := <-kekSubC
|
|
log.Println("kek:", msg)
|
|
require.EqualValues(t, emptyMsg, msg)
|
|
}()
|
|
|
|
go func() {
|
|
defer wg.Done()
|
|
msg := <-lolSubC
|
|
log.Println("lol:", msg)
|
|
require.EqualValues(t, emptyMsg, msg)
|
|
}()
|
|
|
|
go func() {
|
|
defer wg.Done()
|
|
msg := <-lol2SubC
|
|
log.Println("lol2:", msg)
|
|
require.EqualValues(t, emptyMsg, msg)
|
|
}()
|
|
|
|
go func() {
|
|
defer wg.Done()
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
close(kekSrc)
|
|
close(lolSrc)
|
|
}()
|
|
|
|
wg.Wait()
|
|
time.Sleep(time.Second)
|
|
}
|