tendermint/example/block_aware/block_aware_test.go

56 lines
1.4 KiB
Go
Raw Normal View History

2016-11-03 19:50:57 -04:00
package main
import (
"strconv"
"strings"
"testing"
2017-04-28 00:37:18 +04:00
abcicli "github.com/tendermint/abci/client"
2017-01-12 15:47:55 -05:00
"github.com/tendermint/abci/server"
"github.com/tendermint/abci/types"
2017-04-28 00:37:18 +04:00
"github.com/tendermint/tmlibs/log"
2016-11-03 19:50:57 -04:00
)
func TestChainAware(t *testing.T) {
app := NewChainAwareApplication()
// Start the listener
2016-12-26 22:12:32 -08:00
srv, err := server.NewServer("unix://test.sock", "socket", app)
2016-11-03 19:50:57 -04:00
if err != nil {
t.Fatal(err)
}
2017-05-03 11:39:15 +04:00
srv.SetLogger(log.With(log.TestingLogger(), "module", "abci-server"))
2016-12-26 22:12:32 -08:00
defer srv.Stop()
2016-11-03 19:50:57 -04:00
// Connect to the socket
2017-01-12 15:47:55 -05:00
client, err := abcicli.NewSocketClient("unix://test.sock", false)
2016-11-03 19:50:57 -04:00
if err != nil {
2017-04-28 00:37:18 +04:00
t.Fatalf("Error starting socket client: %v", err.Error())
2016-11-03 19:50:57 -04:00
}
2017-05-03 11:39:15 +04:00
client.SetLogger(log.With(log.TestingLogger(), "module", "abci-client"))
2016-11-03 19:50:57 -04:00
client.Start()
defer client.Stop()
n := uint64(5)
2016-11-16 16:22:52 -05:00
hash := []byte("fake block hash")
header := &types.Header{}
2016-11-03 19:50:57 -04:00
for i := uint64(0); i < n; i++ {
2016-11-16 16:22:52 -05:00
client.BeginBlockSync(hash, header)
2016-11-03 19:50:57 -04:00
client.EndBlockSync(i)
client.CommitSync()
}
r := app.Query(types.RequestQuery{})
spl := strings.Split(string(r.Value), ",")
2016-11-03 19:50:57 -04:00
if len(spl) != 2 {
t.Fatal("expected %d,%d ; got %s", n, n, string(r.Value))
2016-11-03 19:50:57 -04:00
}
beginCount, _ := strconv.Atoi(spl[0])
endCount, _ := strconv.Atoi(spl[1])
if uint64(beginCount) != n {
t.Fatalf("expected beginCount of %d, got %d", n, beginCount)
} else if uint64(endCount) != n {
t.Fatalf("expected endCount of %d, got %d", n, endCount)
}
}