2017-05-04 11:29:25 +02:00
|
|
|
package testsuite
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2018-06-22 06:59:02 +02:00
|
|
|
abcicli "github.com/tendermint/tendermint/abci/client"
|
|
|
|
"github.com/tendermint/tendermint/abci/types"
|
2017-05-04 11:29:25 +02:00
|
|
|
cmn "github.com/tendermint/tmlibs/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
func InitChain(client abcicli.Client) error {
|
|
|
|
total := 10
|
2018-05-31 21:45:14 -04:00
|
|
|
vals := make([]types.Validator, total)
|
2017-05-04 11:29:25 +02:00
|
|
|
for i := 0; i < total; i++ {
|
2018-02-03 02:39:34 -05:00
|
|
|
pubkey := cmn.RandBytes(33)
|
2017-05-04 11:29:25 +02:00
|
|
|
power := cmn.RandInt()
|
2018-05-31 21:45:14 -04:00
|
|
|
vals[i] = types.Ed25519Validator(pubkey, int64(power))
|
2017-05-04 11:29:25 +02:00
|
|
|
}
|
2018-02-16 19:49:33 -05:00
|
|
|
_, err := client.InitChainSync(types.RequestInitChain{
|
2018-06-01 22:03:47 -04:00
|
|
|
Validators: vals,
|
2018-02-16 19:49:33 -05:00
|
|
|
})
|
2017-05-04 11:29:25 +02:00
|
|
|
if err != nil {
|
2017-12-16 15:49:35 -07:00
|
|
|
fmt.Printf("Failed test: InitChain - %v\n", err)
|
2017-05-04 11:29:25 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println("Passed test: InitChain")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetOption(client abcicli.Client, key, value string) error {
|
2017-12-26 15:46:06 -08:00
|
|
|
_, err := client.SetOptionSync(types.RequestSetOption{Key: key, Value: value})
|
2017-10-20 18:44:37 +02:00
|
|
|
if err != nil {
|
2017-05-04 11:29:25 +02:00
|
|
|
fmt.Println("Failed test: SetOption")
|
2018-02-27 04:03:21 -08:00
|
|
|
fmt.Printf("error while setting %v=%v: \nerror: %v\n", key, value, err)
|
2017-10-20 18:44:37 +02:00
|
|
|
return err
|
2017-05-04 11:29:25 +02:00
|
|
|
}
|
|
|
|
fmt.Println("Passed test: SetOption")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func Commit(client abcicli.Client, hashExp []byte) error {
|
2017-10-20 18:44:37 +02:00
|
|
|
res, err := client.CommitSync()
|
2017-12-26 15:46:06 -08:00
|
|
|
data := res.Data
|
2017-10-20 18:44:37 +02:00
|
|
|
if err != nil {
|
2017-05-04 11:29:25 +02:00
|
|
|
fmt.Println("Failed test: Commit")
|
2017-12-26 15:46:06 -08:00
|
|
|
fmt.Printf("error while committing: %v\n", err)
|
2017-10-20 18:44:37 +02:00
|
|
|
return err
|
2017-05-04 11:29:25 +02:00
|
|
|
}
|
2017-10-20 18:44:37 +02:00
|
|
|
if !bytes.Equal(data, hashExp) {
|
2017-05-04 11:29:25 +02:00
|
|
|
fmt.Println("Failed test: Commit")
|
2017-12-26 04:52:02 -08:00
|
|
|
fmt.Printf("Commit hash was unexpected. Got %X expected %X\n", data, hashExp)
|
2017-05-04 11:29:25 +02:00
|
|
|
return errors.New("CommitTx failed")
|
|
|
|
}
|
|
|
|
fmt.Println("Passed test: Commit")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-10-20 18:44:37 +02:00
|
|
|
func DeliverTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) error {
|
|
|
|
res, _ := client.DeliverTxSync(txBytes)
|
2017-05-04 11:29:25 +02:00
|
|
|
code, data, log := res.Code, res.Data, res.Log
|
|
|
|
if code != codeExp {
|
|
|
|
fmt.Println("Failed test: DeliverTx")
|
2017-12-12 22:44:55 -06:00
|
|
|
fmt.Printf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v\n",
|
2017-05-04 11:29:25 +02:00
|
|
|
code, codeExp, log)
|
|
|
|
return errors.New("DeliverTx error")
|
|
|
|
}
|
|
|
|
if !bytes.Equal(data, dataExp) {
|
|
|
|
fmt.Println("Failed test: DeliverTx")
|
2017-12-12 22:44:55 -06:00
|
|
|
fmt.Printf("DeliverTx response data was unexpected. Got %X expected %X\n",
|
2017-05-04 11:29:25 +02:00
|
|
|
data, dataExp)
|
|
|
|
return errors.New("DeliverTx error")
|
|
|
|
}
|
|
|
|
fmt.Println("Passed test: DeliverTx")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-10-20 18:44:37 +02:00
|
|
|
func CheckTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) error {
|
|
|
|
res, _ := client.CheckTxSync(txBytes)
|
2017-05-04 11:29:25 +02:00
|
|
|
code, data, log := res.Code, res.Data, res.Log
|
|
|
|
if code != codeExp {
|
|
|
|
fmt.Println("Failed test: CheckTx")
|
2017-12-12 22:44:55 -06:00
|
|
|
fmt.Printf("CheckTx response code was unexpected. Got %v expected %v. Log: %v\n",
|
2017-05-04 11:29:25 +02:00
|
|
|
code, codeExp, log)
|
|
|
|
return errors.New("CheckTx")
|
|
|
|
}
|
|
|
|
if !bytes.Equal(data, dataExp) {
|
|
|
|
fmt.Println("Failed test: CheckTx")
|
2017-12-12 22:44:55 -06:00
|
|
|
fmt.Printf("CheckTx response data was unexpected. Got %X expected %X\n",
|
2017-05-04 11:29:25 +02:00
|
|
|
data, dataExp)
|
|
|
|
return errors.New("CheckTx")
|
|
|
|
}
|
|
|
|
fmt.Println("Passed test: CheckTx")
|
|
|
|
return nil
|
|
|
|
}
|