github.com/pokt-network/tendermint@v0.32.11-0.20230426215212-59310158d3e9/abci/tests/test_app/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  	"os"
     7  	"os/exec"
     8  	"time"
     9  
    10  	"github.com/tendermint/tendermint/abci/example/code"
    11  	"github.com/tendermint/tendermint/abci/types"
    12  )
    13  
    14  var abciType string
    15  
    16  func init() {
    17  	abciType = os.Getenv("ABCI")
    18  	if abciType == "" {
    19  		abciType = "socket"
    20  	}
    21  }
    22  
    23  func main() {
    24  	testCounter()
    25  }
    26  
    27  const (
    28  	maxABCIConnectTries = 10
    29  )
    30  
    31  func ensureABCIIsUp(typ string, n int) error {
    32  	var err error
    33  	cmdString := "abci-cli echo hello"
    34  	if typ == "grpc" {
    35  		cmdString = "abci-cli --abci grpc echo hello"
    36  	}
    37  
    38  	for i := 0; i < n; i++ {
    39  		cmd := exec.Command("bash", "-c", cmdString)
    40  		_, err = cmd.CombinedOutput()
    41  		if err == nil {
    42  			break
    43  		}
    44  		<-time.After(500 * time.Millisecond)
    45  	}
    46  	return err
    47  }
    48  
    49  func testCounter() {
    50  	abciApp := os.Getenv("ABCI_APP")
    51  	if abciApp == "" {
    52  		panic("No ABCI_APP specified")
    53  	}
    54  
    55  	fmt.Printf("Running %s test with abci=%s\n", abciApp, abciType)
    56  	subCommand := fmt.Sprintf("abci-cli %s", abciApp)
    57  	cmd := exec.Command("bash", "-c", subCommand)
    58  	cmd.Stdout = os.Stdout
    59  	if err := cmd.Start(); err != nil {
    60  		log.Fatalf("starting %q err: %v", abciApp, err)
    61  	}
    62  	defer cmd.Wait()
    63  	defer cmd.Process.Kill()
    64  
    65  	if err := ensureABCIIsUp(abciType, maxABCIConnectTries); err != nil {
    66  		log.Fatalf("echo failed: %v", err)
    67  	}
    68  
    69  	client := startClient(abciType)
    70  	defer client.Stop()
    71  
    72  	setOption(client, "serial", "on")
    73  	commit(client, nil)
    74  	deliverTx(client, []byte("abc"), code.CodeTypeBadNonce, nil)
    75  	commit(client, nil)
    76  	deliverTx(client, []byte{0x00}, types.CodeTypeOK, nil)
    77  	commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1})
    78  	deliverTx(client, []byte{0x00}, code.CodeTypeBadNonce, nil)
    79  	deliverTx(client, []byte{0x01}, types.CodeTypeOK, nil)
    80  	deliverTx(client, []byte{0x00, 0x02}, types.CodeTypeOK, nil)
    81  	deliverTx(client, []byte{0x00, 0x03}, types.CodeTypeOK, nil)
    82  	deliverTx(client, []byte{0x00, 0x00, 0x04}, types.CodeTypeOK, nil)
    83  	deliverTx(client, []byte{0x00, 0x00, 0x06}, code.CodeTypeBadNonce, nil)
    84  	commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 5})
    85  }