-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Define the Header of the verison 0.3 - Support the serde of multiple versions - Test the client API with espresso dev ndoe
- Loading branch information
1 parent
8e47e5d
commit 86687b7
Showing
10 changed files
with
671 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"os/exec" | ||
"testing" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/log" | ||
) | ||
|
||
var workingDir = "./dev-node" | ||
|
||
func TestApiWithEspressoDevNode(t *testing.T) { | ||
ctx := context.Background() | ||
cleanup := runEspresso(t, ctx) | ||
defer cleanup() | ||
|
||
err := waitForEspressoNode(t, ctx) | ||
if err != nil { | ||
t.Fatal("failed to start espresso dev node", err) | ||
} | ||
|
||
client := NewClient("http://localhost:21000") | ||
|
||
blockHeight, err := client.FetchLatestBlockHeight(ctx) | ||
if err != nil { | ||
t.Fatal("failed to fetch block height") | ||
} | ||
|
||
_, err = client.FetchHeaderByHeight(ctx, blockHeight) | ||
if err != nil { | ||
t.Fatal("failed to fetch header", err) | ||
} | ||
|
||
_, err = client.FetchVidCommonByHeight(ctx, blockHeight) | ||
if err != nil { | ||
t.Fatal("failed to fetch vid common", err) | ||
} | ||
|
||
_, err = client.FetchHeadersByRange(ctx, 1, blockHeight) | ||
if err != nil { | ||
t.Fatal("failed to fetch headers by range", err) | ||
} | ||
|
||
} | ||
|
||
func runEspresso(t *testing.T, ctx context.Context) func() { | ||
shutdown := func() { | ||
p := exec.Command("docker", "compose", "down") | ||
p.Dir = workingDir | ||
err := p.Run() | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
shutdown() | ||
invocation := []string{"compose", "up", "-d", "--build"} | ||
nodes := []string{ | ||
"espresso-dev-node", | ||
} | ||
invocation = append(invocation, nodes...) | ||
procees := exec.Command("docker", invocation...) | ||
procees.Dir = workingDir | ||
|
||
go func() { | ||
if err := procees.Run(); err != nil { | ||
log.Error(err.Error()) | ||
panic(err) | ||
} | ||
}() | ||
return shutdown | ||
} | ||
|
||
func waitForWith( | ||
t *testing.T, | ||
ctxinput context.Context, | ||
timeout time.Duration, | ||
interval time.Duration, | ||
condition func() bool, | ||
) error { | ||
ctx, cancel := context.WithTimeout(ctxinput, timeout) | ||
defer cancel() | ||
|
||
for { | ||
if condition() { | ||
return nil | ||
} | ||
select { | ||
case <-time.After(interval): | ||
case <-ctx.Done(): | ||
return ctx.Err() | ||
} | ||
} | ||
} | ||
|
||
func waitForEspressoNode(t *testing.T, ctx context.Context) error { | ||
return waitForWith(t, ctx, 400*time.Second, 1*time.Second, func() bool { | ||
out, err := exec.Command("curl", "-s", "-L", "-f", "http://localhost:21000/availability/block/10").Output() | ||
if err != nil { | ||
log.Warn("error executing curl command:", "err", err) | ||
return false | ||
} | ||
|
||
return len(out) > 0 | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ESPRESSO_SEQUENCER_API_PORT=21000 | ||
ESPRESSO_BUILDER_PORT=23000 | ||
ESPRESSO_DEV_NODE_PORT=20000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
version: '3.9' | ||
services: | ||
espresso-dev-node: | ||
image: ghcr.io/espressosystems/espresso-sequencer/espresso-dev-node:main | ||
ports: | ||
- "$ESPRESSO_SEQUENCER_API_PORT:$ESPRESSO_SEQUENCER_API_PORT" | ||
- "$ESPRESSO_BUILDER_PORT:$ESPRESSO_BUILDER_PORT" | ||
- "$ESPRESSO_DEV_NODE_PORT:$ESPRESSO_DEV_NODE_PORT" | ||
environment: | ||
- ESPRESSO_SEQUENCER_API_PORT | ||
- ESPRESSO_BUILDER_PORT | ||
- ESPRESSO_DEV_NODE_PORT | ||
- RUST_LOG=info | ||
- RUST_LOG_FORMAT | ||
extra_hosts: | ||
- "host.docker.internal:host-gateway" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.