mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-18 22:14:35 +00:00
lite2: actually run example tests + clock drift (#4487)
Closes: #4488 ## Commits: * run example tests * introduce max clock drift clockDrift variable from the spec. 10s should cover most of the clients. References: - http://vancouver-webpages.com/time/web.html - https://blog.codinghorror.com/keeping-time-on-the-pc/ * fix ExampleClient_Update * add test * increase clock drift * fix linter warning
This commit is contained in:
+21
-15
@@ -11,7 +11,6 @@ import (
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
"github.com/tendermint/tendermint/abci/example/kvstore"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
"github.com/tendermint/tendermint/lite2/provider"
|
||||
httpp "github.com/tendermint/tendermint/lite2/provider/http"
|
||||
dbs "github.com/tendermint/tendermint/lite2/store/db"
|
||||
@@ -19,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
// Automatically getting new headers and verifying them.
|
||||
func TestExample_Client_AutoUpdate(t *testing.T) {
|
||||
func ExampleClient_Update() {
|
||||
// give Tendermint time to generate some blocks
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
@@ -57,10 +56,10 @@ func TestExample_Client_AutoUpdate(t *testing.T) {
|
||||
Hash: header.Hash(),
|
||||
},
|
||||
primary,
|
||||
[]provider.Provider{primary}, // TODO: primary should not be used here
|
||||
[]provider.Provider{primary}, // NOTE: primary should not be used here
|
||||
dbs.New(db, chainID),
|
||||
UpdatePeriod(1*time.Second),
|
||||
Logger(log.TestingLogger()),
|
||||
UpdatePeriod(0), // NOTE: value should be greater than zero
|
||||
// Logger(log.TestingLogger()),
|
||||
)
|
||||
if err != nil {
|
||||
stdlog.Fatal(err)
|
||||
@@ -76,17 +75,29 @@ func TestExample_Client_AutoUpdate(t *testing.T) {
|
||||
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
// XXX: 30 * time.Minute clock drift is needed because a) Tendermint strips
|
||||
// monotonic component (see types/time/time.go) b) single instance is being
|
||||
// run.
|
||||
err = c.Update(time.Now().Add(30 * time.Minute))
|
||||
if err != nil {
|
||||
stdlog.Fatal(err)
|
||||
}
|
||||
|
||||
h, err := c.TrustedHeader(0)
|
||||
if err != nil {
|
||||
stdlog.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println("got header", h.Height)
|
||||
// Output: got header 3
|
||||
if h.Height > 2 {
|
||||
fmt.Println("successful update")
|
||||
} else {
|
||||
fmt.Println("update failed")
|
||||
}
|
||||
// Output: successful update
|
||||
}
|
||||
|
||||
// Manually getting headers and verifying them.
|
||||
func TestExample_Client_ManualUpdate(t *testing.T) {
|
||||
func ExampleClient_VerifyHeaderAtHeight() {
|
||||
// give Tendermint time to generate some blocks
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
@@ -127,17 +138,12 @@ func TestExample_Client_ManualUpdate(t *testing.T) {
|
||||
[]provider.Provider{primary}, // TODO: primary should not be used here
|
||||
dbs.New(db, chainID),
|
||||
UpdatePeriod(0),
|
||||
Logger(log.TestingLogger()),
|
||||
// Logger(log.TestingLogger()),
|
||||
)
|
||||
if err != nil {
|
||||
stdlog.Fatal(err)
|
||||
}
|
||||
err = c.Start()
|
||||
if err != nil {
|
||||
stdlog.Fatal(err)
|
||||
}
|
||||
defer func() {
|
||||
c.Stop()
|
||||
c.Cleanup()
|
||||
}()
|
||||
|
||||
@@ -158,7 +164,7 @@ func TestExample_Client_ManualUpdate(t *testing.T) {
|
||||
func TestMain(m *testing.M) {
|
||||
// start a tendermint node (and kvstore) in the background to test against
|
||||
app := kvstore.NewApplication()
|
||||
node := rpctest.StartTendermint(app)
|
||||
node := rpctest.StartTendermint(app, rpctest.SuppressStdout)
|
||||
|
||||
code := m.Run()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user