diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 59ca7303..81c27216 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,10 +1,9 @@ name: Alicenet CI on: + workflow_dispatch: push: branches: [ main, candidate ] - paths: - - "blockchain" pull_request: branches: [ main, candidate ] @@ -202,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 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..ee76f41e 100644 --- a/blockchain/dkg/dtest/setup.go +++ b/blockchain/dkg/dtest/setup.go @@ -40,6 +40,10 @@ import ( "github.com/MadBase/MadNet/crypto/bn256/cloudflare" ) +type nullWriter struct{} + +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 +485,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 +528,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 = os.Stdout + cmd.Stderr = os.Stderr + } else { + cmd.Stdout = nullWriter{} + cmd.Stderr = nullWriter{} + } +} + func InitializeValidatorFiles(n int) error { rootPath := GetMadnetRootPath() @@ -534,13 +552,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 +580,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 +674,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