github.com/evdatsion/aphelion-dpos-bft@v0.32.1/lite/client/provider_test.go (about) 1 package client 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 10 "github.com/evdatsion/aphelion-dpos-bft/abci/example/kvstore" 11 rpcclient "github.com/evdatsion/aphelion-dpos-bft/rpc/client" 12 rpctest "github.com/evdatsion/aphelion-dpos-bft/rpc/test" 13 "github.com/evdatsion/aphelion-dpos-bft/types" 14 ) 15 16 func TestMain(m *testing.M) { 17 app := kvstore.NewKVStoreApplication() 18 node := rpctest.StartTendermint(app) 19 20 code := m.Run() 21 22 rpctest.StopTendermint(node) 23 os.Exit(code) 24 } 25 26 func TestProvider(t *testing.T) { 27 assert, require := assert.New(t), require.New(t) 28 29 cfg := rpctest.GetConfig() 30 defer os.RemoveAll(cfg.RootDir) 31 rpcAddr := cfg.RPC.ListenAddress 32 genDoc, err := types.GenesisDocFromFile(cfg.GenesisFile()) 33 if err != nil { 34 panic(err) 35 } 36 chainID := genDoc.ChainID 37 t.Log("chainID:", chainID) 38 p := NewHTTPProvider(chainID, rpcAddr) 39 require.NotNil(t, p) 40 41 // let it produce some blocks 42 err = rpcclient.WaitForHeight(p.(*provider).client, 6, nil) 43 require.Nil(err) 44 45 // let's get the highest block 46 fc, err := p.LatestFullCommit(chainID, 1, 1<<63-1) 47 48 require.Nil(err, "%+v", err) 49 sh := fc.Height() 50 assert.True(sh < 5000) 51 52 // let's check this is valid somehow 53 assert.Nil(fc.ValidateFull(chainID)) 54 55 // historical queries now work :) 56 lower := sh - 5 57 fc, err = p.LatestFullCommit(chainID, lower, lower) 58 assert.Nil(err, "%+v", err) 59 assert.Equal(lower, fc.Height()) 60 61 }