From 70cead153b81425c382ee2324aa4f571f3eaf9cb Mon Sep 17 00:00:00 2001 From: TAKAMI Torao Date: Thu, 13 Aug 2020 14:22:43 +0900 Subject: [PATCH] fix review point --- abci/example/kvstore/helpers.go | 4 ++-- abci/tests/server/client.go | 7 ++++--- abci/tests/tests.go | 9 +++++++++ crypto/encoding/codec_test.go | 17 +++++++++++------ types/priv_validator.go | 3 --- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/abci/example/kvstore/helpers.go b/abci/example/kvstore/helpers.go index 81be6c97f..f904f7761 100644 --- a/abci/example/kvstore/helpers.go +++ b/abci/example/kvstore/helpers.go @@ -1,8 +1,8 @@ package kvstore import ( + "github.com/tendermint/tendermint/abci/tests" "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/crypto/composite" tmrand "github.com/tendermint/tendermint/libs/rand" tmtypes "github.com/tendermint/tendermint/types" ) @@ -10,7 +10,7 @@ import ( // RandVal creates one random validator, with a key derived // from the input value func RandVal(i int) types.ValidatorUpdate { - pk := composite.GenPrivKey().PubKey() + pk := tests.GenDefaultPrivKey().PubKey() pubkey := tmtypes.TM2PB.PubKey(pk) power := tmrand.Uint16() + 1 v := types.NewValidatorUpdate(tmtypes.ABCIPubKeyTypeComposite, pubkey.Data, int64(power)) diff --git a/abci/tests/server/client.go b/abci/tests/server/client.go index acb16e44d..7155d4b38 100644 --- a/abci/tests/server/client.go +++ b/abci/tests/server/client.go @@ -5,7 +5,8 @@ import ( "errors" "fmt" - "github.com/tendermint/tendermint/crypto/composite" + "github.com/tendermint/tendermint/abci/tests" + tmtypes "github.com/tendermint/tendermint/types" abcicli "github.com/tendermint/tendermint/abci/client" @@ -17,10 +18,10 @@ func InitChain(client abcicli.Client) error { total := 10 vals := make([]types.ValidatorUpdate, total) for i := 0; i < total; i++ { - pk := composite.GenPrivKey().PubKey() + pk := tests.GenDefaultPrivKey().PubKey() pubkey := tmtypes.TM2PB.PubKey(pk).Data power := tmrand.Int() - vals[i] = types.NewValidatorUpdate("composite", pubkey, int64(power)) + vals[i] = types.NewValidatorUpdate(tmtypes.ABCIPubKeyTypeComposite, pubkey, int64(power)) } _, err := client.InitChainSync(types.RequestInitChain{ Validators: vals, diff --git a/abci/tests/tests.go b/abci/tests/tests.go index ca8701d29..70ade8236 100644 --- a/abci/tests/tests.go +++ b/abci/tests/tests.go @@ -1 +1,10 @@ package tests + +import ( + "github.com/tendermint/tendermint/crypto" + "github.com/tendermint/tendermint/crypto/composite" +) + +func GenDefaultPrivKey() crypto.PrivKey { + return composite.GenPrivKey() +} diff --git a/crypto/encoding/codec_test.go b/crypto/encoding/codec_test.go index 6b5499c1a..40e15661b 100644 --- a/crypto/encoding/codec_test.go +++ b/crypto/encoding/codec_test.go @@ -3,15 +3,14 @@ package encoding import ( "testing" + "github.com/tendermint/tendermint/crypto" + "github.com/tendermint/tendermint/crypto/ed25519" + "github.com/tendermint/tendermint/crypto/bls" "github.com/tendermint/tendermint/crypto/composite" - "github.com/tendermint/tendermint/crypto/ed25519" ) -func TestPubKeyFromToProto(t *testing.T) { - vrf := ed25519.GenPrivKey() - signer := bls.GenPrivKey() - sk := composite.NewPrivKeyComposite(signer, vrf) +func testPubKeyFromToProto(t *testing.T, sk crypto.PrivKey) { pk := sk.PubKey() pbPubKey, err := PubKeyToProto(pk) if err != nil { @@ -26,6 +25,12 @@ func TestPubKeyFromToProto(t *testing.T) { t.Fatalf("The retrieved public key was not composite key: %+v", pk2) } if !cpk.Equals(pk) { - t.Fatalf("The retrieved composite public key was not match: %+v != %+v", cpk, pk) + t.Fatalf("The retrieved public key was not match: %+v != %+v", cpk, pk) } } + +func TestPubKeyFromToProto(t *testing.T) { + testPubKeyFromToProto(t, ed25519.GenPrivKey()) + testPubKeyFromToProto(t, bls.GenPrivKey()) + testPubKeyFromToProto(t, composite.NewPrivKeyComposite(bls.GenPrivKey(), ed25519.GenPrivKey())) +} diff --git a/types/priv_validator.go b/types/priv_validator.go index abc6b9e74..d0427b1f1 100644 --- a/types/priv_validator.go +++ b/types/priv_validator.go @@ -74,9 +74,6 @@ func NewMockPVWithParams(privKey crypto.PrivKey, breakProposalSigning, breakVote // Implements PrivValidator. func (pv MockPV) GetPubKey() (crypto.PubKey, error) { - //signKey := bls.GenPrivKey() - //vrfKey := ed25519.GenPrivKey() - //return composite.NewPrivKeyComposite(signKey, vrfKey).PubKey(), nil return pv.PrivKey.PubKey(), nil }