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

     1  package main
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  	"os"
     7  
     8  	abcicli "github.com/tendermint/tendermint/abci/client"
     9  	"github.com/tendermint/tendermint/abci/types"
    10  	"github.com/tendermint/tendermint/libs/log"
    11  )
    12  
    13  func startClient(abciType string) abcicli.Client {
    14  	// Start client
    15  	client, err := abcicli.NewClient("tcp://127.0.0.1:26658", abciType, true)
    16  	if err != nil {
    17  		panic(err.Error())
    18  	}
    19  	logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
    20  	client.SetLogger(logger.With("module", "abcicli"))
    21  	if err := client.Start(); err != nil {
    22  		panicf("connecting to abci_app: %v", err.Error())
    23  	}
    24  
    25  	return client
    26  }
    27  
    28  func setOption(client abcicli.Client, key, value string) {
    29  	_, err := client.SetOptionSync(types.RequestSetOption{Key: key, Value: value})
    30  	if err != nil {
    31  		panicf("setting %v=%v: \nerr: %v", key, value, err)
    32  	}
    33  }
    34  
    35  func commit(client abcicli.Client, hashExp []byte) {
    36  	res, err := client.CommitSync()
    37  	if err != nil {
    38  		panicf("client error: %v", err)
    39  	}
    40  	if !bytes.Equal(res.Data, hashExp) {
    41  		panicf("Commit hash was unexpected. Got %X expected %X", res.Data, hashExp)
    42  	}
    43  }
    44  
    45  func deliverTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) {
    46  	res, err := client.DeliverTxSync(types.RequestDeliverTx{Tx: txBytes})
    47  	if err != nil {
    48  		panicf("client error: %v", err)
    49  	}
    50  	if res.Code != codeExp {
    51  		panicf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v", res.Code, codeExp, res.Log)
    52  	}
    53  	if !bytes.Equal(res.Data, dataExp) {
    54  		panicf("DeliverTx response data was unexpected. Got %X expected %X", res.Data, dataExp)
    55  	}
    56  }
    57  
    58  /*func checkTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) {
    59  	res, err := client.CheckTxSync(txBytes)
    60  	if err != nil {
    61  		panicf("client error: %v", err)
    62  	}
    63  	if res.IsErr() {
    64  		panicf("checking tx %X: %v\nlog: %v", txBytes, res.Log)
    65  	}
    66  	if res.Code != codeExp {
    67  		panicf("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
    68  			res.Code, codeExp, res.Log)
    69  	}
    70  	if !bytes.Equal(res.Data, dataExp) {
    71  		panicf("CheckTx response data was unexpected. Got %X expected %X",
    72  			res.Data, dataExp)
    73  	}
    74  }*/
    75  
    76  func panicf(format string, a ...interface{}) {
    77  	panic(fmt.Sprintf(format, a...))
    78  }