fixes post rebase

This commit is contained in:
Ethan Buchman
2018-03-17 23:09:04 +01:00
parent 07a1f4dc15
commit 683663f680
7 changed files with 41 additions and 19 deletions
+16 -5
View File
@@ -7,20 +7,23 @@ import (
"io/ioutil"
"net/http"
"os"
"path/filepath"
"regexp"
"testing"
"time"
"github.com/cosmos/cosmos-sdk/client"
keys "github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/tests"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
cryptoKeys "github.com/tendermint/go-crypto/keys"
"github.com/tendermint/tendermint/p2p"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
tmtypes "github.com/tendermint/tendermint/types"
"github.com/cosmos/cosmos-sdk/client"
keys "github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/tests"
"github.com/cosmos/cosmos-sdk/x/auth"
)
func TestKeys(t *testing.T) {
@@ -280,12 +283,20 @@ func setupEnvironment(t *testing.T) (kill func(), port string, seed string) {
require.Nil(t, err)
seed = tests.TestInitBasecoin(t, dir)
// get chain ID
bz, err := ioutil.ReadFile(filepath.Join(dir, "config", "genesis.json"))
require.Nil(t, err)
var gen tmtypes.GenesisDoc
err = json.Unmarshal(bz, &gen)
require.Nil(t, err)
cmdNode := tests.StartNodeServerForTest(t, dir)
cmdLCD, port := tests.StartLCDServerForTest(t, dir)
cmdLCD, port := tests.StartLCDServerForTest(t, dir, gen.ChainID)
kill = func() {
cmdLCD.Process.Kill()
cmdLCD.Process.Wait()
cmdNode.Process.Kill()
cmdNode.Process.Wait()
os.Remove(dir)
}
return kill, port, seed
+1
View File
@@ -53,6 +53,7 @@ func StartServer(t *testing.T) chan error {
viper.Set(flagWithTendermint, true)
startCmd := StartCmd(mock.NewApp, log.NewNopLogger())
startCmd.Flags().Set(flagAddress, FreeTCPAddr(t)) // set to a new free address
startCmd.Flags().Set("rpc.laddr", FreeTCPAddr(t)) // set to a new free address
timeout := time.Duration(3) * time.Second
return RunOrTimeout(startCmd, timeout, t)
+5 -4
View File
@@ -224,11 +224,10 @@ func StartNodeServerForTest(t *testing.T, home string) *exec.Cmd {
cmdName := whereIsBasecoind()
cmdArgs := []string{"start", "--home", home}
cmd := exec.Command(cmdName, cmdArgs...)
err := cmd.Start()
require.Nil(t, err)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Start()
require.Nil(t, err)
// FIXME: if there is a nondeterministic node start failure,
// we should probably make this read the logs to wait for RPC
@@ -238,7 +237,7 @@ func StartNodeServerForTest(t *testing.T, home string) *exec.Cmd {
}
// expects TestInitBaseCoin to have been run
func StartLCDServerForTest(t *testing.T, home string) (cmd *exec.Cmd, port string) {
func StartLCDServerForTest(t *testing.T, home, chainID string) (cmd *exec.Cmd, port string) {
cmdName := whereIsBasecli()
port = strings.Split(server.FreeTCPAddr(t), ":")[2]
cmdArgs := []string{
@@ -247,6 +246,8 @@ func StartLCDServerForTest(t *testing.T, home string) (cmd *exec.Cmd, port strin
home,
"--bind",
fmt.Sprintf("localhost:%s", port),
"--chain-id",
chainID,
}
cmd = exec.Command(cmdName, cmdArgs...)
cmd.Stdout = os.Stdout
+12 -1
View File
@@ -1,6 +1,9 @@
package types
import "encoding/json"
import (
"encoding/json"
"fmt"
)
// Transactions messages must fulfill the Msg
type Msg interface {
@@ -90,6 +93,13 @@ func NewStdFee(gas int64, amount ...Coin) StdFee {
}
func (fee StdFee) Bytes() []byte {
// normalize. XXX
// this is a sign of something ugly
// (in the lcd_test, client side its null,
// server side its [])
if len(fee.Amount) == 0 {
fee.Amount = Coins{}
}
bz, err := json.Marshal(fee) // TODO
if err != nil {
panic(err)
@@ -115,6 +125,7 @@ type StdSignDoc struct {
// StdSignBytes returns the bytes to sign for a transaction.
// TODO: change the API to just take a chainID and StdTx ?
func StdSignBytes(chainID string, sequences []int64, fee StdFee, msg Msg) []byte {
fmt.Println("FEE BYTES BABY", fee, string(fee.Bytes()))
bz, err := json.Marshal(StdSignDoc{
ChainID: chainID,
Sequences: sequences,
+1
View File
@@ -125,6 +125,7 @@ func processSig(
return nil, sdk.ErrInternal("setting PubKey on signer's account").Result()
}
}
// Check sig.
if !pubKey.VerifyBytes(signBytes, sig.Signature) {
return nil, sdk.ErrUnauthorized("signature verification failed").Result()
+4 -1
View File
@@ -103,8 +103,11 @@ func (c Commander) SignMessage(msg sdk.Msg, kb cryptokeys.Keybase, accountName s
Sequence: viper.GetInt64(client.FlagName),
}}
// TODO: fees
var fee sdk.StdFee
// marshal bytes
tx := sdk.NewStdTx(msg, sigs)
tx := sdk.NewStdTx(msg, fee, sigs)
txBytes, err := c.Cdc.MarshalBinary(tx)
if err != nil {
+2 -8
View File
@@ -71,20 +71,14 @@ func SendRequestHandler(cdc *wire.Codec) func(http.ResponseWriter, *http.Request
// build message
msg := commands.BuildMsg(info.PubKey.Address(), to, m.Amount)
if err != nil {
if err != nil { // XXX rechecking same error ?
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
return
}
signMsg := sdk.StdSignMsg{
ChainID: m.ChainID,
Sequences: []int64{m.Sequence},
Msg: msg,
}
// sign
txBytes, err := builder.SignAndBuild(m.LocalAccountName, m.Password, signMsg, c.Cdc)
txBytes, err := builder.SignAndBuild(m.LocalAccountName, m.Password, msg, c.Cdc)
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(err.Error()))