Merge branch 'develop' into dev/reuse_pubkeys

This commit is contained in:
Dev Ojha 2018-07-26 09:47:57 -07:00 committed by GitHub
commit 4c13b3a642
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 42 deletions

View File

@ -5,7 +5,9 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/crypto/ed25519"
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
cmn "github.com/tendermint/tendermint/libs/common" cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db" dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
@ -28,7 +30,7 @@ func NewCodec() *wire.Codec {
cdc.RegisterInterface((*sdk.Msg)(nil), nil) cdc.RegisterInterface((*sdk.Msg)(nil), nil)
cdc.RegisterConcrete(MsgSend{}, "example/MsgSend", nil) cdc.RegisterConcrete(MsgSend{}, "example/MsgSend", nil)
cdc.RegisterConcrete(MsgIssue{}, "example/MsgIssue", nil) cdc.RegisterConcrete(MsgIssue{}, "example/MsgIssue", nil)
crypto.RegisterAmino(cdc) cryptoAmino.RegisterAmino(cdc)
return cdc return cdc
} }

View File

@ -2,8 +2,9 @@ package app
import ( import (
"testing" "testing"
"github.com/tendermint/tendermint/crypto"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -11,14 +12,14 @@ import (
// Test encoding of app2Tx is correct with both msg types // Test encoding of app2Tx is correct with both msg types
func TestEncoding(t *testing.T) { func TestEncoding(t *testing.T) {
// Create privkeys and addresses // Create privkeys and addresses
priv1 := crypto.GenPrivKeyEd25519() priv1 := ed25519.GenPrivKey()
priv2 := crypto.GenPrivKeyEd25519() priv2 := ed25519.GenPrivKey()
addr1 := priv1.PubKey().Address().Bytes() addr1 := priv1.PubKey().Address().Bytes()
addr2 := priv2.PubKey().Address().Bytes() addr2 := priv2.PubKey().Address().Bytes()
sendMsg := MsgSend{ sendMsg := MsgSend{
From: addr1, From: addr1,
To: addr2, To: addr2,
Amount: sdk.Coins{{"testCoins", sdk.NewInt(100)}}, Amount: sdk.Coins{{"testCoins", sdk.NewInt(100)}},
} }
@ -30,8 +31,8 @@ func TestEncoding(t *testing.T) {
} }
sendTxBefore := app2Tx{ sendTxBefore := app2Tx{
Msg: sendMsg, Msg: sendMsg,
PubKey: priv1.PubKey(), PubKey: priv1.PubKey(),
Signature: sig, Signature: sig,
} }
@ -47,13 +48,13 @@ func TestEncoding(t *testing.T) {
require.Nil(t, err, "Error decoding sendTx") require.Nil(t, err, "Error decoding sendTx")
sendTxAfter := tx1.(app2Tx) sendTxAfter := tx1.(app2Tx)
require.Equal(t, sendTxBefore, sendTxAfter, "Transaction changed after encoding/decoding") require.Equal(t, sendTxBefore, sendTxAfter, "Transaction changed after encoding/decoding")
issueMsg := MsgIssue{ issueMsg := MsgIssue{
Issuer: addr1, Issuer: addr1,
Receiver: addr2, Receiver: addr2,
Coin: sdk.Coin{"testCoin", sdk.NewInt(100)}, Coin: sdk.Coin{"testCoin", sdk.NewInt(100)},
} }
signBytes = issueMsg.GetSignBytes() signBytes = issueMsg.GetSignBytes()
@ -63,8 +64,8 @@ func TestEncoding(t *testing.T) {
} }
issueTxBefore := app2Tx{ issueTxBefore := app2Tx{
Msg: issueMsg, Msg: issueMsg,
PubKey: priv1.PubKey(), PubKey: priv1.PubKey(),
Signature: sig, Signature: sig,
} }
@ -80,4 +81,4 @@ func TestEncoding(t *testing.T) {
require.Equal(t, issueTxBefore, issueTxAfter, "Transaction changed after encoding/decoding") require.Equal(t, issueTxBefore, issueTxAfter, "Transaction changed after encoding/decoding")
} }

View File

@ -1,16 +1,16 @@
package app package app
import ( import (
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
cmn "github.com/tendermint/tendermint/libs/common" cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db" dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/crypto"
bapp "github.com/cosmos/cosmos-sdk/baseapp" bapp "github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/wire"
) )
const ( const (
@ -57,6 +57,6 @@ func UpdatedCodec() *wire.Codec {
cdc.RegisterConcrete(MsgSend{}, "example/MsgSend", nil) cdc.RegisterConcrete(MsgSend{}, "example/MsgSend", nil)
cdc.RegisterConcrete(MsgIssue{}, "example/MsgIssue", nil) cdc.RegisterConcrete(MsgIssue{}, "example/MsgIssue", nil)
auth.RegisterWire(cdc) auth.RegisterWire(cdc)
crypto.RegisterAmino(cdc) cryptoAmino.RegisterAmino(cdc)
return cdc return cdc
} }

View File

@ -1,14 +1,15 @@
package app package app
import ( import (
"github.com/stretchr/testify/require"
"os"
"encoding/json" "encoding/json"
"os"
"testing" "testing"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/ed25519"
dbm "github.com/tendermint/tendermint/libs/db" dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
bapp "github.com/cosmos/cosmos-sdk/baseapp" bapp "github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
@ -44,7 +45,7 @@ func InitTestChain(bc *bapp.BaseApp, chainID string, addrs ...sdk.AccAddress) {
// Generate basic SpendMsg with one input and output // Generate basic SpendMsg with one input and output
func GenerateSpendMsg(sender, receiver sdk.AccAddress, amount sdk.Coins) bank.MsgSend { func GenerateSpendMsg(sender, receiver sdk.AccAddress, amount sdk.Coins) bank.MsgSend {
return bank.MsgSend{ return bank.MsgSend{
Inputs: []bank.Input{{sender, amount}}, Inputs: []bank.Input{{sender, amount}},
Outputs: []bank.Output{{receiver, amount}}, Outputs: []bank.Output{{receiver, amount}},
} }
} }
@ -54,8 +55,8 @@ func TestBadMsg(t *testing.T) {
bc := newTestChain() bc := newTestChain()
// Create privkeys and addresses // Create privkeys and addresses
priv1 := crypto.GenPrivKeyEd25519() priv1 := ed25519.GenPrivKey()
priv2 := crypto.GenPrivKeyEd25519() priv2 := ed25519.GenPrivKey()
addr1 := priv1.PubKey().Address().Bytes() addr1 := priv1.PubKey().Address().Bytes()
addr2 := priv2.PubKey().Address().Bytes() addr2 := priv2.PubKey().Address().Bytes()
@ -64,7 +65,7 @@ func TestBadMsg(t *testing.T) {
// Construct transaction // Construct transaction
fee := auth.StdFee{ fee := auth.StdFee{
Gas: 1000000000000000, Gas: 1000000000000000,
Amount: sdk.Coins{{"testCoin", sdk.NewInt(0)}}, Amount: sdk.Coins{{"testCoin", sdk.NewInt(0)}},
} }
signBytes := auth.StdSignBytes("test-chain", 0, 0, fee, []sdk.Msg{msg}, "") signBytes := auth.StdSignBytes("test-chain", 0, 0, fee, []sdk.Msg{msg}, "")
@ -73,17 +74,17 @@ func TestBadMsg(t *testing.T) {
panic(err) panic(err)
} }
sigs := []auth.StdSignature{auth.StdSignature{ sigs := []auth.StdSignature{auth.StdSignature{
PubKey: priv1.PubKey(), PubKey: priv1.PubKey(),
Signature: sig, Signature: sig,
AccountNumber: 0, AccountNumber: 0,
Sequence: 0, Sequence: 0,
}} }}
tx := auth.StdTx{ tx := auth.StdTx{
Msgs: []sdk.Msg{msg}, Msgs: []sdk.Msg{msg},
Fee: fee, Fee: fee,
Signatures: sigs, Signatures: sigs,
Memo: "", Memo: "",
} }
bc.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{ChainID: "test-chain"}}) bc.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{ChainID: "test-chain"}})
@ -99,8 +100,8 @@ func TestBadMsg(t *testing.T) {
func TestMsgSend(t *testing.T) { func TestMsgSend(t *testing.T) {
bc := newTestChain() bc := newTestChain()
priv1 := crypto.GenPrivKeyEd25519() priv1 := ed25519.GenPrivKey()
priv2 := crypto.GenPrivKeyEd25519() priv2 := ed25519.GenPrivKey()
addr1 := priv1.PubKey().Address().Bytes() addr1 := priv1.PubKey().Address().Bytes()
addr2 := priv2.PubKey().Address().Bytes() addr2 := priv2.PubKey().Address().Bytes()
@ -110,7 +111,7 @@ func TestMsgSend(t *testing.T) {
msg := GenerateSpendMsg(addr1, addr2, sdk.Coins{{"testCoin", sdk.NewInt(100)}}) msg := GenerateSpendMsg(addr1, addr2, sdk.Coins{{"testCoin", sdk.NewInt(100)}})
fee := auth.StdFee{ fee := auth.StdFee{
Gas: 1000000000000000, Gas: 1000000000000000,
Amount: sdk.Coins{{"testCoin", sdk.NewInt(0)}}, Amount: sdk.Coins{{"testCoin", sdk.NewInt(0)}},
} }
signBytes := auth.StdSignBytes("test-chain", 0, 0, fee, []sdk.Msg{msg}, "") signBytes := auth.StdSignBytes("test-chain", 0, 0, fee, []sdk.Msg{msg}, "")
@ -119,17 +120,17 @@ func TestMsgSend(t *testing.T) {
panic(err) panic(err)
} }
sigs := []auth.StdSignature{auth.StdSignature{ sigs := []auth.StdSignature{auth.StdSignature{
PubKey: priv1.PubKey(), PubKey: priv1.PubKey(),
Signature: sig, Signature: sig,
AccountNumber: 0, AccountNumber: 0,
Sequence: 0, Sequence: 0,
}} }}
tx := auth.StdTx{ tx := auth.StdTx{
Msgs: []sdk.Msg{msg}, Msgs: []sdk.Msg{msg},
Fee: fee, Fee: fee,
Signatures: sigs, Signatures: sigs,
Memo: "", Memo: "",
} }
bc.BeginBlock(abci.RequestBeginBlock{}) bc.BeginBlock(abci.RequestBeginBlock{})
@ -138,5 +139,4 @@ func TestMsgSend(t *testing.T) {
require.True(t, res.IsOK(), res.Log) require.True(t, res.IsOK(), res.Log)
}
}