github.com/okex/exchain@v1.8.0/libs/tendermint/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/okex/exchain/libs/tendermint/abci/example/kvstore" 11 rpcclient "github.com/okex/exchain/libs/tendermint/rpc/client" 12 rpctest "github.com/okex/exchain/libs/tendermint/rpc/test" 13 "github.com/okex/exchain/libs/tendermint/types" 14 ) 15 16 func TestMain(m *testing.M) { 17 app := kvstore.NewApplication() 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, err := NewHTTPProvider(chainID, rpcAddr) 39 require.Nil(err) 40 require.NotNil(p) 41 42 // let it produce some blocks 43 err = rpcclient.WaitForHeight(p.(*provider).client, 6, nil) 44 require.Nil(err) 45 46 // let's get the highest block 47 fc, err := p.LatestFullCommit(chainID, 1, 1<<63-1) 48 49 require.Nil(err, "%+v", err) 50 sh := fc.Height() 51 assert.True(sh < 5000) 52 53 // let's check this is valid somehow 54 assert.Nil(fc.ValidateFull(chainID)) 55 56 // historical queries now work :) 57 lower := sh - 5 58 fc, err = p.LatestFullCommit(chainID, lower, lower) 59 assert.Nil(err, "%+v", err) 60 assert.Equal(lower, fc.Height()) 61 62 }