Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
Fix e2e scripts (#172)
Browse files Browse the repository at this point in the history
* Fix e2e scripts
  • Loading branch information
dnkolegov authored May 4, 2023
1 parent 933502e commit e622349
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 32 deletions.
1 change: 1 addition & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
testdata/mir/node*
testdata/mir/genesis.car
docker.log
testdata/_runtime
tests.app
8 changes: 4 additions & 4 deletions e2e/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
build:
context: ../
dockerfile: e2e/Dockerfile
command: "/scripts/mir/node.sh 0 /logs"
command: "/scripts/mir/node.sh 0 1230 /logs"
environment:
EUDICO: /usr/local/bin/eudico
LOTUS_PATH: /var/lib/lotus
Expand Down Expand Up @@ -38,7 +38,7 @@ services:
build:
context: ../
dockerfile: e2e/Dockerfile
command: "/scripts/mir/node.sh 1 /logs"
command: "/scripts/mir/node.sh 1 1231 /logs"
environment:
EUDICO: /usr/local/bin/eudico
LOTUS_PATH: /var/lib/lotus
Expand Down Expand Up @@ -68,7 +68,7 @@ services:
build:
context: ../
dockerfile: e2e/Dockerfile
command: "/scripts/mir/node.sh 2 /logs"
command: "/scripts/mir/node.sh 2 1232 /logs"
environment:
EUDICO: /usr/local/bin/eudico
LOTUS_PATH: /var/lib/lotus
Expand Down Expand Up @@ -98,7 +98,7 @@ services:
build:
context: ../
dockerfile: e2e/Dockerfile
command: "/scripts/mir/node.sh 3 /logs"
command: "/scripts/mir/node.sh 3 1233 /logs"
environment:
EUDICO: /usr/local/bin/eudico
LOTUS_PATH: /var/lib/lotus
Expand Down
21 changes: 21 additions & 0 deletions e2e/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net"
"os"
"path"
"path/filepath"
"text/template"

"github.com/libp2p/go-libp2p/core/crypto"
Expand All @@ -16,6 +17,8 @@ import (

addr "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/e2e/internal/fs"

"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/wallet"
)
Expand Down Expand Up @@ -346,6 +349,8 @@ func SaveNewNetworkConfig(size int, firstIP string, nonce int, outputDir string)
return err
}

// --- save node configs

for i, v := range validatorSet.Validators {
nodeConfigDir := path.Join(outputDir, fmt.Sprintf("node%d", i))

Expand All @@ -354,5 +359,21 @@ func SaveNewNetworkConfig(size int, firstIP string, nonce int, outputDir string)
return err
}
}

// --- save genesis.car

r, err := fs.FindRoot()
if err != nil {
panic(err)
}
ScriptPath, err := filepath.Abs(filepath.Join(r, "scripts", "mir"))
if err != nil {
panic(err)
}
err = fs.CopyFile(path.Join(ScriptPath, "genesis.car"), path.Join(outputDir, "genesis.car"))
if err != nil {
panic(err)
}

return nil
}
40 changes: 40 additions & 0 deletions e2e/internal/fs/fs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package fs

import (
"errors"
"os"
"path"
"path/filepath"
)

func FindRoot() (string, error) {
dir, err := os.Getwd()
if err != nil {
return "", err
}

for dir != "" {
info, err := os.Stat(path.Join(dir, "go.mod"))
if err == nil && info != nil && !info.IsDir() {
return dir, nil
}
if err != nil && !errors.Is(err, os.ErrNotExist) {
return "", err
}
dir = filepath.Dir(dir)
}

return dir, nil
}

func CopyFile(src string, dst string) error {
data, err := os.ReadFile(src)
if err != nil {
return err
}
err = os.WriteFile(dst, data, 0644)
if err != nil {
return err
}
return nil
}
2 changes: 1 addition & 1 deletion e2e/tests/utils_test.go → e2e/internal/fs/fs_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tests
package fs

import (
"testing"
Expand Down
3 changes: 2 additions & 1 deletion e2e/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"golang.org/x/sync/errgroup"

"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/e2e/internal/fs"

"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/api/client"
Expand All @@ -33,7 +34,7 @@ var (
)

func init() {
r, err := FindRoot()
r, err := fs.FindRoot()
if err != nil {
panic(err)
}
Expand Down
24 changes: 0 additions & 24 deletions e2e/tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,10 @@ package tests

import (
"bufio"
"errors"
"os"
"path"
"path/filepath"
"strconv"
)

func FindRoot() (string, error) {

dir, err := os.Getwd()
if err != nil {
return "", err
}

for dir != "" {
info, err := os.Stat(path.Join(dir, "go.mod"))
if err == nil && info != nil && !info.IsDir() {
return dir, nil
}
if err != nil && !errors.Is(err, os.ErrNotExist) {
return "", err
}
dir = filepath.Dir(dir)
}

return dir, nil
}

func ReadFileLineByLine(filePath string) ([]string, error) {
var lines []string

Expand Down
5 changes: 3 additions & 2 deletions scripts/mir/node.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env bash

INDEX=$1
STORE=$2
PORT=$2
STORE=$3

tmux new-session -d -s "mir" \; \
new-window -t "mir" \; \
split-window -t "mir:0" -v \; \
send-keys -t "mir:0.0" "./scripts/mir/daemon.sh $INDEX 2>&1 | tee $STORE/daemon_$INDEX.log" Enter \; \
send-keys -t "mir:0.0" "./scripts/mir/daemon.sh $INDEX $PORT 2>&1 | tee $STORE/daemon_$INDEX.log" Enter \; \
send-keys -t "mir:0.1" "./scripts/mir/validator.sh $INDEX 2>&1 | tee $STORE/validator_$INDEX.log" Enter \;

tail -f /dev/null

0 comments on commit e622349

Please sign in to comment.