rpc: decouple test fixtures from node implementation (#6533)

This commit is contained in:
Sam Kleinman
2021-06-04 09:10:38 -04:00
committed by GitHub
parent 618c945d54
commit 663c0bba9c
15 changed files with 366 additions and 229 deletions
+28 -20
View File
@@ -21,10 +21,17 @@ import (
// Automatically getting new headers and verifying them.
func ExampleClient_Update() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
conf := rpctest.CreateConfig()
// Start a test application
app := kvstore.NewApplication()
n := rpctest.StartTendermint(app, rpctest.SuppressStdout)
defer func() { rpctest.StopTendermint(n) }()
_, closer, err := rpctest.StartTendermint(ctx, conf, app, rpctest.SuppressStdout)
if err != nil {
stdlog.Fatal(err)
}
defer func() { _ = closer(ctx) }()
// give Tendermint time to generate some blocks
time.Sleep(5 * time.Second)
@@ -35,17 +42,14 @@ func ExampleClient_Update() {
}
defer os.RemoveAll(dbDir)
var (
config = n.Config()
chainID = config.ChainID()
)
chainID := conf.ChainID()
primary, err := httpp.New(chainID, config.RPC.ListenAddress)
primary, err := httpp.New(chainID, conf.RPC.ListenAddress)
if err != nil {
stdlog.Fatal(err)
}
block, err := primary.LightBlock(context.Background(), 2)
block, err := primary.LightBlock(ctx, 2)
if err != nil {
stdlog.Fatal(err)
}
@@ -56,7 +60,7 @@ func ExampleClient_Update() {
}
c, err := light.NewClient(
context.Background(),
ctx,
chainID,
light.TrustOptions{
Period: 504 * time.Hour, // 21 days
@@ -79,7 +83,7 @@ func ExampleClient_Update() {
time.Sleep(2 * time.Second)
h, err := c.Update(context.Background(), time.Now())
h, err := c.Update(ctx, time.Now())
if err != nil {
stdlog.Fatal(err)
}
@@ -94,10 +98,18 @@ func ExampleClient_Update() {
// Manually getting light blocks and verifying them.
func ExampleClient_VerifyLightBlockAtHeight() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
conf := rpctest.CreateConfig()
// Start a test application
app := kvstore.NewApplication()
n := rpctest.StartTendermint(app, rpctest.SuppressStdout)
defer func() { rpctest.StopTendermint(n) }()
_, closer, err := rpctest.StartTendermint(ctx, conf, app, rpctest.SuppressStdout)
if err != nil {
stdlog.Fatal(err)
}
defer func() { _ = closer(ctx) }()
// give Tendermint time to generate some blocks
time.Sleep(5 * time.Second)
@@ -108,17 +120,14 @@ func ExampleClient_VerifyLightBlockAtHeight() {
}
defer os.RemoveAll(dbDir)
var (
config = n.Config()
chainID = config.ChainID()
)
chainID := conf.ChainID()
primary, err := httpp.New(chainID, config.RPC.ListenAddress)
primary, err := httpp.New(chainID, conf.RPC.ListenAddress)
if err != nil {
stdlog.Fatal(err)
}
block, err := primary.LightBlock(context.Background(), 2)
block, err := primary.LightBlock(ctx, 2)
if err != nil {
stdlog.Fatal(err)
}
@@ -128,8 +137,7 @@ func ExampleClient_VerifyLightBlockAtHeight() {
stdlog.Fatal(err)
}
c, err := light.NewClient(
context.Background(),
c, err := light.NewClient(ctx,
chainID,
light.TrustOptions{
Period: 504 * time.Hour, // 21 days