Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go kosu/rpc #182

Merged
merged 4 commits into from Jul 23, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

go-kosu: remove rpc.Client

  • Loading branch information
gchaincl committed Jul 23, 2019
commit 2af8033b99d7346f73bcb3ed86669e6855e07375
@@ -5,6 +5,7 @@ import (
"testing"
"time"

"github.com/ethereum/go-ethereum/rpc"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

@@ -17,29 +18,40 @@ import (
func TestRPCLatestHeight(t *testing.T) {
_, closer := tests.StartServer(t, db.NewMemDB())
defer closer()
client := DialInProc(
client := rpc.DialInProc(
NewServer(
abci.NewHTTPClient("http://localhost:26657", nil),
),
)

var latest uint64
// Get the initial (prior the first block is mined)
latest, err := client.LatestHeight()
require.NoError(t, err)
require.NoError(t, client.Call(&latest, "kosu_latestHeight"))
assert.EqualValues(t, 0, latest)

ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
fn := func(i interface{}) {
// this is invoked when a block is mined
latest, err := client.LatestHeight()
require.NoError(t, err)
require.NoError(t, client.Call(&latest, "kosu_latestHeight"))
assert.EqualValues(t, 1, latest)

cancel()
}

err = client.Subscribe(ctx, fn, "tm.event = 'NewBlock'")
ch := make(chan interface{})
defer close(ch)

sub, err := client.Subscribe(ctx, "kosu", ch, "subscribe", "tm.event = 'NewBlock'")
defer sub.Unsubscribe()
require.NoError(t, err)

<-ctx.Done()
for {
select {
case <-ctx.Done():
return
case err := <-sub.Err():
t.Error(err)
case e := <-ch:
fn(e)
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.