@@ -23,6 +23,7 @@ import (
2323 tmtypes "github.com/cometbft/cometbft/types"
2424 "github.com/stretchr/testify/require"
2525 "github.com/tidwall/sjson"
26+ "golang.org/x/exp/maps"
2627
2728 "github.com/cosmos/cosmos-sdk/server"
2829 sdk "github.com/cosmos/cosmos-sdk/types"
@@ -154,7 +155,7 @@ func (s *SystemUnderTest) StartChain(t *testing.T, xargs ...string) {
154155 t .Helper ()
155156 s .Log ("Start chain\n " )
156157 s .ChainStarted = true
157- s .startNodesAsync (t , append ([]string {"start" , "--trace" , "-- log_level=info" , "--log_no_color" }, xargs ... )... )
158+ s .startNodesAsync (t , append ([]string {"start" , "--log_level=info" , "--log_no_color" }, xargs ... )... )
158159
159160 s .AwaitNodeUp (t , s .rpcAddr )
160161
@@ -332,10 +333,10 @@ func (s *SystemUnderTest) StopChain() {
332333
333334func (s * SystemUnderTest ) withEachPid (cb func (p * os.Process )) {
334335 s .pidsLock .RLock ()
335- pids := s .pids
336+ pids := maps . Keys ( s .pids )
336337 s .pidsLock .RUnlock ()
337338
338- for pid := range pids {
339+ for _ , pid := range pids {
339340 p , err := os .FindProcess (pid )
340341 if err != nil {
341342 continue
@@ -528,28 +529,28 @@ func (s *SystemUnderTest) ForEachNodeExecAndWait(t *testing.T, cmds ...[]string)
528529 for j , xargs := range cmds {
529530 xargs = append (xargs , "--home" , home )
530531 s .Logf ("Execute `%s %s`\n " , s .execBinary , strings .Join (xargs , " " ))
531- out := runShellCmd (t , s .execBinary , xargs ... )
532+ out := MustRunShellCmd (t , s .execBinary , xargs ... )
532533 s .Logf ("Result: %s\n " , out )
533534 result [i ][j ] = out
534535 }
535536 })
536537 return result
537538}
538539
539- func runShellCmd (t * testing.T , cmd string , args ... string ) string {
540+ func MustRunShellCmd (t * testing.T , cmd string , args ... string ) string {
540541 t .Helper ()
541- out , err := runShellCmdX (cmd , args ... )
542+ out , err := RunShellCmd (cmd , args ... )
542543 require .NoError (t , err )
543544 return out
544545}
545546
546- func runShellCmdX (cmd string , args ... string ) (string , error ) {
547+ func RunShellCmd (cmd string , args ... string ) (string , error ) {
547548 c := exec .Command ( //nolint:gosec // used by tests only
548549 locateExecutable (cmd ),
549550 args ... ,
550551 )
551552 c .Dir = WorkDir
552- out , err := c .CombinedOutput ()
553+ out , err := c .Output ()
553554 if err != nil {
554555 return string (out ), fmt .Errorf ("run `%s %s`: out: %s: %w" , cmd , strings .Join (args , " " ), string (out ), err )
555556 }
@@ -560,7 +561,7 @@ func runShellCmdX(cmd string, args ...string) (string, error) {
560561func (s * SystemUnderTest ) startNodesAsync (t * testing.T , xargs ... string ) {
561562 t .Helper ()
562563 s .withEachNodeHome (func (i int , home string ) {
563- args := append (xargs , "--home" , home )
564+ args := append (xargs , "--home=" + home )
564565 s .Logf ("Execute `%s %s`\n " , s .execBinary , strings .Join (args , " " ))
565566 cmd := exec .Command ( //nolint:gosec // used by tests only
566567 locateExecutable (s .execBinary ),
@@ -569,24 +570,27 @@ func (s *SystemUnderTest) startNodesAsync(t *testing.T, xargs ...string) {
569570 cmd .Dir = WorkDir
570571 s .watchLogs (i , cmd )
571572 require .NoError (t , cmd .Start (), "node %d" , i )
572-
573- pid := cmd .Process .Pid
574- s .pidsLock .Lock ()
575- s .pids [pid ] = struct {}{}
576- s .pidsLock .Unlock ()
577- s .Logf ("Node started: %d\n " , pid )
573+ s .Logf ("Node started: %d\n " , cmd .Process .Pid )
578574
579575 // cleanup when stopped
580- go func (pid int ) {
581- _ = cmd .Wait () // blocks until shutdown
582- s .pidsLock .Lock ()
583- delete (s .pids , pid )
584- s .pidsLock .Unlock ()
585- s .Logf ("Node stopped: %d\n " , pid )
586- }(pid )
576+ s .awaitProcessCleanup (cmd )
587577 })
588578}
589579
580+ func (s * SystemUnderTest ) awaitProcessCleanup (cmd * exec.Cmd ) {
581+ pid := cmd .Process .Pid
582+ s .pidsLock .Lock ()
583+ s .pids [pid ] = struct {}{}
584+ s .pidsLock .Unlock ()
585+ go func () {
586+ _ = cmd .Wait () // blocks until shutdown
587+ s .Logf ("Node stopped: %d\n " , pid )
588+ s .pidsLock .Lock ()
589+ delete (s .pids , pid )
590+ s .pidsLock .Unlock ()
591+ }()
592+ }
593+
590594func (s * SystemUnderTest ) withEachNodeHome (cb func (i int , home string )) {
591595 for i := 0 ; i < s .nodesCount ; i ++ {
592596 cb (i , s .nodePath (i ))
@@ -658,7 +662,7 @@ func (s *SystemUnderTest) resetBuffers() {
658662}
659663
660664// AddFullnode starts a new fullnode that connects to the existing chain but is not a validator.
661- func (s * SystemUnderTest ) AddFullnode (t * testing.T , minGasPrices string , beforeStart ... func (nodeNumber int , nodePath string )) Node {
665+ func (s * SystemUnderTest ) AddFullnode (t * testing.T , beforeStart ... func (nodeNumber int , nodePath string )) Node {
662666 t .Helper ()
663667 s .MarkDirty ()
664668 s .nodesCount ++
@@ -668,7 +672,7 @@ func (s *SystemUnderTest) AddFullnode(t *testing.T, minGasPrices string, beforeS
668672
669673 // prepare new node
670674 moniker := fmt .Sprintf ("node%d" , nodeNumber )
671- args := []string {"init" , moniker , "--home" , nodePath , "--overwrite" }
675+ args := []string {"init" , moniker , "--home=" + nodePath , "--overwrite" }
672676 s .Logf ("Execute `%s %s`\n " , s .execBinary , strings .Join (args , " " ))
673677 cmd := exec .Command ( //nolint:gosec // used by tests only
674678 locateExecutable (s .execBinary ),
@@ -679,12 +683,15 @@ func (s *SystemUnderTest) AddFullnode(t *testing.T, minGasPrices string, beforeS
679683 require .NoError (t , cmd .Run (), "failed to start node with id %d" , nodeNumber )
680684 require .NoError (t , saveGenesis (nodePath , []byte (s .ReadGenesisJSON (t ))))
681685
682- // quick hack: copy config and overwrite by start params
683- configFile := filepath .Join (WorkDir , nodePath , "config" , "config.toml" )
684- _ = os .Remove (configFile )
685- _ , err := copyFile (filepath .Join (WorkDir , s .nodePath (0 ), "config" , "config.toml" ), configFile )
686- require .NoError (t , err )
686+ configPath := filepath .Join (WorkDir , nodePath , "config" )
687687
688+ // quick hack: copy config and overwrite by start params
689+ for _ , tomlFile := range []string {"config.toml" , "app.toml" } {
690+ configFile := filepath .Join (configPath , tomlFile )
691+ _ = os .Remove (configFile )
692+ _ , err := copyFile (filepath .Join (WorkDir , s .nodePath (0 ), "config" , tomlFile ), configFile )
693+ require .NoError (t , err )
694+ }
688695 // start node
689696 allNodes := s .AllNodes (t )
690697 node := allNodes [len (allNodes )- 1 ]
@@ -701,7 +708,6 @@ func (s *SystemUnderTest) AddFullnode(t *testing.T, minGasPrices string, beforeS
701708 fmt .Sprintf ("--p2p.laddr=tcp://localhost:%d" , node .P2PPort ),
702709 fmt .Sprintf ("--rpc.laddr=tcp://localhost:%d" , node .RPCPort ),
703710 fmt .Sprintf ("--grpc.address=localhost:%d" , 9090 + nodeNumber ),
704- fmt .Sprintf ("--minimum-gas-prices=%s" , minGasPrices ),
705711 "--p2p.pex=false" ,
706712 "--moniker=" + moniker ,
707713 "--log_level=info" ,
@@ -716,6 +722,7 @@ func (s *SystemUnderTest) AddFullnode(t *testing.T, minGasPrices string, beforeS
716722 cmd .Dir = WorkDir
717723 s .watchLogs (nodeNumber , cmd )
718724 require .NoError (t , cmd .Start (), "node %d" , nodeNumber )
725+ s .awaitProcessCleanup (cmd )
719726 return node
720727}
721728
0 commit comments