From b651aeb1a3893021cc0d5c5f99dcecccade08c76 Mon Sep 17 00:00:00 2001 From: stuckDaemon Date: Tue, 24 May 2022 16:22:21 +0200 Subject: [PATCH 1/4] CI - manual trigger --- .github/workflows/ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 59ca7303..332095cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,10 +1,9 @@ -name: Alicenet CI +name: kAlicenet CI on: + workflow_dispatch: push: branches: [ main, candidate ] - paths: - - "blockchain" pull_request: branches: [ main, candidate ] From 811c48a03ec36400386e9f0a737959b2222acb19 Mon Sep 17 00:00:00 2001 From: stuckDaemon Date: Wed, 25 May 2022 12:49:40 +0200 Subject: [PATCH 2/4] CI log formatting --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 332095cc..81c27216 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: kAlicenet CI +name: Alicenet CI on: workflow_dispatch: @@ -201,4 +201,4 @@ jobs: run: | set -euo pipefail ./scripts/main.sh init 5 - go test -v -timeout=45m ${{ matrix.test-cmd }} + go test -json -v -timeout=15m ${{ matrix.test-cmd }} 2>&1 | tee /tmp/gotest.log | gotestfmt From 1a7360e05e5304ac4d3323df6f9ad77fb2e6e022 Mon Sep 17 00:00:00 2001 From: stuckDaemon Date: Wed, 25 May 2022 15:10:49 +0200 Subject: [PATCH 3/4] Introducing ENABLE_SCRIPT_LOG as env variable to show scripts logs, hidden otherwise --- README.md | 7 +++++ blockchain/dkg/dtest/setup.go | 57 +++++++++++++++++++++++------------ 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index b7c74102..4e3b71ef 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,13 @@ with [Madnet Wallet](https://github.com/MadBase/MadNetWallet-v2). # TEST +### Verbose log +To show all the scripts logs in the console during tests you must set the env variable `ENABLE_SCRIPT_LOG` to `true`. +For instance to run blockchain tests you will execute +```shell +ENABLE_SCRIPT_LOG=true go test -v github.com/MadBase/MadNet/blockchain +``` + ### Random Kill and Restart Randomly kill and restart the individual validators. There should be no noticeable change in the behavior of the other diff --git a/blockchain/dkg/dtest/setup.go b/blockchain/dkg/dtest/setup.go index 31ee6e9b..7b32d68d 100644 --- a/blockchain/dkg/dtest/setup.go +++ b/blockchain/dkg/dtest/setup.go @@ -40,6 +40,12 @@ import ( "github.com/MadBase/MadNet/crypto/bn256/cloudflare" ) +type nullReader struct{} +type nullWriter struct{} + +func (nullReader) Read(p []byte) (n int, err error) { return len(p), nil } +func (nullWriter) Write(p []byte) (n int, err error) { return len(p), nil } + func InitializeNewDetDkgStateInfo(n int) ([]*objects.DkgState, []*ecdsa.PrivateKey) { return InitializeNewDkgStateInfo(n, true) } @@ -481,13 +487,12 @@ func StartHardHatNode(eth *blockchain.EthereumDetails) error { fmt.Println("scriptPathJoined2: ", scriptPathJoined) cmd := exec.Cmd{ - Path: scriptPathJoined, - Args: []string{scriptPathJoined, "hardhat_node"}, - Dir: filepath.Join(rootPath...), - Stdout: os.Stdout, - Stderr: os.Stderr, + Path: scriptPathJoined, + Args: []string{scriptPathJoined, "hardhat_node"}, + Dir: filepath.Join(rootPath...), } + setCommandStdOut(&cmd) err := cmd.Start() // if there is an error with our execution @@ -525,6 +530,21 @@ func StartHardHatNode(eth *blockchain.EthereumDetails) error { return nil } +// setCommandStdOut If ENABLE_SCRIPT_LOG env variable is set as 'true' the command will show scripts logs +func setCommandStdOut(cmd *exec.Cmd) { + + flagValue, found := os.LookupEnv("ENABLE_SCRIPT_LOG") + enabled, err := strconv.ParseBool(flagValue) + + if err == nil && found && enabled { + cmd.Stdout = nullWriter{} + cmd.Stderr = nullWriter{} + } else { + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + } +} + func InitializeValidatorFiles(n int) error { rootPath := GetMadnetRootPath() @@ -534,13 +554,12 @@ func InitializeValidatorFiles(n int) error { fmt.Println("scriptPathJoined2: ", scriptPathJoined) cmd := exec.Cmd{ - Path: scriptPathJoined, - Args: []string{scriptPathJoined, "init", strconv.Itoa(n)}, - Dir: filepath.Join(rootPath...), - Stdout: os.Stdout, - Stderr: os.Stderr, + Path: scriptPathJoined, + Args: []string{scriptPathJoined, "init", strconv.Itoa(n)}, + Dir: filepath.Join(rootPath...), } + setCommandStdOut(&cmd) err := cmd.Start() if err != nil { return fmt.Errorf("could not generate validator files: %s", err) @@ -563,13 +582,12 @@ func StartDeployScripts(eth *blockchain.EthereumDetails, ctx context.Context) er } cmd := exec.Cmd{ - Path: scriptPathJoined, - Args: []string{scriptPathJoined, "deploy"}, - Dir: filepath.Join(rootPath...), - Stdout: os.Stdout, - Stderr: os.Stderr, + Path: scriptPathJoined, + Args: []string{scriptPathJoined, "deploy"}, + Dir: filepath.Join(rootPath...), } + setCommandStdOut(&cmd) err = cmd.Run() // if there is an error with our execution @@ -658,13 +676,12 @@ func RegisterValidators(eth *blockchain.EthereumDetails, validatorAddresses []st args = append(args, validatorAddresses...) cmd := exec.Cmd{ - Path: scriptPathJoined, - Args: args, - Dir: filepath.Join(rootPath...), - Stdout: os.Stdout, - Stderr: os.Stderr, + Path: scriptPathJoined, + Args: args, + Dir: filepath.Join(rootPath...), } + setCommandStdOut(&cmd) err := cmd.Run() // if there is an error with our execution From ec03511f1dcd17277d28b97933b6389e74276d44 Mon Sep 17 00:00:00 2001 From: stuckDaemon Date: Wed, 25 May 2022 15:23:35 +0200 Subject: [PATCH 4/4] Switch the logic for enable flag --- blockchain/dkg/dtest/setup.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/blockchain/dkg/dtest/setup.go b/blockchain/dkg/dtest/setup.go index 7b32d68d..ee76f41e 100644 --- a/blockchain/dkg/dtest/setup.go +++ b/blockchain/dkg/dtest/setup.go @@ -40,10 +40,8 @@ import ( "github.com/MadBase/MadNet/crypto/bn256/cloudflare" ) -type nullReader struct{} type nullWriter struct{} -func (nullReader) Read(p []byte) (n int, err error) { return len(p), nil } func (nullWriter) Write(p []byte) (n int, err error) { return len(p), nil } func InitializeNewDetDkgStateInfo(n int) ([]*objects.DkgState, []*ecdsa.PrivateKey) { @@ -537,11 +535,11 @@ func setCommandStdOut(cmd *exec.Cmd) { enabled, err := strconv.ParseBool(flagValue) if err == nil && found && enabled { - cmd.Stdout = nullWriter{} - cmd.Stderr = nullWriter{} - } else { cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr + } else { + cmd.Stdout = nullWriter{} + cmd.Stderr = nullWriter{} } }