From 683663f680e7957c52535248fd2bac964c05aa8c Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sat, 17 Mar 2018 23:09:04 +0100 Subject: [PATCH] fixes post rebase --- client/lcd/lcd_test.go | 21 ++++++++++++++++----- server/test_helpers.go | 1 + tests/tests.go | 9 +++++---- types/tx_msg.go | 13 ++++++++++++- x/auth/ante.go | 1 + x/bank/commands/sendtx.go | 5 ++++- x/bank/rest/sendtx.go | 10 ++-------- 7 files changed, 41 insertions(+), 19 deletions(-) diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index 25be57db30..9d27248d70 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -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 diff --git a/server/test_helpers.go b/server/test_helpers.go index e490da3773..103af7c331 100644 --- a/server/test_helpers.go +++ b/server/test_helpers.go @@ -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) diff --git a/tests/tests.go b/tests/tests.go index 844b58c2ee..845ac69259 100644 --- a/tests/tests.go +++ b/tests/tests.go @@ -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 diff --git a/types/tx_msg.go b/types/tx_msg.go index 21bc330540..e4af1d8040 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -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, diff --git a/x/auth/ante.go b/x/auth/ante.go index 43b9bb8341..08bb185778 100644 --- a/x/auth/ante.go +++ b/x/auth/ante.go @@ -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() diff --git a/x/bank/commands/sendtx.go b/x/bank/commands/sendtx.go index 43d5b26195..5d1a6e05cf 100644 --- a/x/bank/commands/sendtx.go +++ b/x/bank/commands/sendtx.go @@ -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 { diff --git a/x/bank/rest/sendtx.go b/x/bank/rest/sendtx.go index 70443ab802..407a53420e 100644 --- a/x/bank/rest/sendtx.go +++ b/x/bank/rest/sendtx.go @@ -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()))