move PrivKeys to internal folder

read https://golang.org/cmd/go/#hdr-Internal_Directories if you want to
know how internal directories work
This commit is contained in:
Anton Kaliaev
2019-07-09 17:42:04 +04:00
parent 8d43cdd846
commit 45a447aa2f
5 changed files with 38 additions and 39 deletions
+3 -2
View File
@@ -6,13 +6,14 @@ import (
"github.com/stretchr/testify/assert"
lerr "github.com/tendermint/tendermint/lite/errors"
pks "github.com/tendermint/tendermint/lite/internal/privkeys"
"github.com/tendermint/tendermint/types"
)
func TestBaseVerifier(t *testing.T) {
assert := assert.New(t)
keys := GenPrivKeys(4)
keys := pks.GenPrivKeys(4)
// 20, 30, 40, 50 - the first 3 don't have 2/3, the last 3 do!
vals := keys.ToValidators(20, 10)
// and a Verifier based on our known set
@@ -20,7 +21,7 @@ func TestBaseVerifier(t *testing.T) {
cert := NewBaseVerifier(chainID, 2, vals)
cases := []struct {
keys PrivKeys
keys pks.PrivKeys
vals *types.ValidatorSet
height int64
first, last int // who actually signs
@@ -1,15 +1,14 @@
package lite
package privkeys
import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/tendermint/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time"
)
// privKeys is a helper type for testing.
// PrivKeys is a helper type for testing.
//
// It lets us simulate signing with many keys. The main use case is to create
// a set, and call GenSignedHeader to get properly signed header for testing.
@@ -18,7 +17,7 @@ import (
// and can optionally extend the validator set later with Extend.
type PrivKeys []crypto.PrivKey
// genPrivKeys produces an array of private keys to generate commits.
// GenPrivKeys produces an array of private keys to generate commits.
func GenPrivKeys(n int) PrivKeys {
res := make(PrivKeys, n)
for i := range res {
@@ -84,6 +83,18 @@ func (pkz PrivKeys) signHeader(header *types.Header, first, last int) *types.Com
return types.NewCommit(blockID, commitSigs)
}
// GenSignedHeader calls genHeader and signHeader and combines them into a SignedHeader.
func (pkz PrivKeys) GenSignedHeader(chainID string, height int64, txs types.Txs,
valset, nextValset *types.ValidatorSet, appHash, consHash, resHash []byte, first, last int) types.SignedHeader {
header := genHeader(chainID, height, txs, valset, nextValset, appHash, consHash, resHash)
check := types.SignedHeader{
Header: header,
Commit: pkz.signHeader(header, first, last),
}
return check
}
func makeVote(header *types.Header, valset *types.ValidatorSet, key crypto.PrivKey) *types.Vote {
addr := key.PubKey().Address()
idx, _ := valset.GetByAddress(addr)
@@ -127,27 +138,3 @@ func genHeader(chainID string, height int64, txs types.Txs,
LastResultsHash: resHash,
}
}
// GenSignedHeader calls genHeader and signHeader and combines them into a SignedHeader.
func (pkz PrivKeys) GenSignedHeader(chainID string, height int64, txs types.Txs,
valset, nextValset *types.ValidatorSet, appHash, consHash, resHash []byte, first, last int) types.SignedHeader {
header := genHeader(chainID, height, txs, valset, nextValset, appHash, consHash, resHash)
check := types.SignedHeader{
Header: header,
Commit: pkz.signHeader(header, first, last),
}
return check
}
// GenFullCommit calls genHeader and signHeader and combines them into a FullCommit.
func (pkz PrivKeys) GenFullCommit(chainID string, height int64, txs types.Txs,
valset, nextValset *types.ValidatorSet, appHash, consHash, resHash []byte, first, last int) FullCommit {
header := genHeader(chainID, height, txs, valset, nextValset, appHash, consHash, resHash)
commit := types.SignedHeader{
Header: header,
Commit: pkz.signHeader(header, first, last),
}
return NewFullCommit(commit, valset, nextValset)
}
+8 -4
View File
@@ -10,6 +10,7 @@ import (
dbm "github.com/tendermint/tendermint/libs/db"
log "github.com/tendermint/tendermint/libs/log"
lerr "github.com/tendermint/tendermint/lite/errors"
pks "github.com/tendermint/tendermint/lite/internal/privkeys"
"github.com/tendermint/tendermint/types"
)
@@ -48,7 +49,7 @@ func TestMultiProvider(t *testing.T) {
func checkProvider(t *testing.T, p PersistentProvider, chainID, app string) {
assert, require := assert.New(t), require.New(t)
appHash := []byte(app)
keys := GenPrivKeys(5)
keys := pks.GenPrivKeys(5)
count := 10
// Make a bunch of full commits.
@@ -56,7 +57,9 @@ func checkProvider(t *testing.T, p PersistentProvider, chainID, app string) {
for i := 0; i < count; i++ {
vals := keys.ToValidators(10, int64(count/2))
h := int64(20 + 10*i)
fcz[i] = keys.GenFullCommit(chainID, h, nil, vals, vals, appHash, []byte("params"), []byte("results"), 0, 5)
signedHeader := keys.GenSignedHeader(chainID, h, nil, vals, vals, appHash,
[]byte("params"), []byte("results"), 0, 5)
fcz[i] = NewFullCommit(signedHeader, vals, vals)
}
// Check that provider is initially empty.
@@ -113,14 +116,15 @@ func TestMultiLatestFullCommit(t *testing.T) {
chainID := "cache-best-height"
appHash := []byte("01234567")
keys := GenPrivKeys(5)
keys := pks.GenPrivKeys(5)
count := 10
// Set a bunch of full commits.
for i := 0; i < count; i++ {
vals := keys.ToValidators(10, int64(count/2))
h := int64(10 * (i + 1))
fc := keys.GenFullCommit(chainID, h, nil, vals, vals, appHash, []byte("params"), []byte("results"), 0, 5)
signedHeader := keys.GenSignedHeader(chainID, h, nil, vals, vals, appHash, []byte("params"), []byte("results"), 0, 5)
fc := NewFullCommit(signedHeader, vals, vals)
err := p2.SaveFullCommit(fc)
require.NoError(err)
}
+3
View File
@@ -1,3 +1,6 @@
/*
Package verifying
*/
package verifying
import (
+9 -5
View File
@@ -35,10 +35,11 @@ func TestProviderValidPath(t *testing.T) {
nextVals := nkeys.ToValidators(vote, 0)
h := int64(1 + i)
appHash := []byte(fmt.Sprintf("h=%d", h))
fcz[i] = keys.GenFullCommit(
signedHeader := keys.GenSignedHeader(
chainID, h, nil,
vals, nextVals,
appHash, consHash, resHash, 0, len(keys))
fcz[i] = lite.NewFullCommit(signedHeader, vals, nextVals)
// Extend the keys by 1 each time.
keys = nkeys
nkeys = nkeys.Extend(1)
@@ -129,14 +130,15 @@ func TestProviderDynamicVerification(t *testing.T) {
}
func makeFullCommit(height int64, keys lite.PrivKeys, vals, nextVals *types.ValidatorSet, chainID string) lite.FullCommit {
height += 1
height++
consHash := []byte("special-params")
appHash := []byte(fmt.Sprintf("h=%d", height))
resHash := []byte(fmt.Sprintf("res=%d", height))
return keys.GenFullCommit(
signedHeader := keys.GenSignedHeader(
chainID, height, nil,
vals, nextVals,
appHash, consHash, resHash, 0, len(keys))
return lite.NewFullCommit(signedHeader, vals, nextVals)
}
func TestVerifingProviderHistorical(t *testing.T) {
@@ -160,10 +162,11 @@ func TestVerifingProviderHistorical(t *testing.T) {
h := int64(1 + i)
appHash := []byte(fmt.Sprintf("h=%d", h))
resHash := []byte(fmt.Sprintf("res=%d", h))
fcz[i] = keys.GenFullCommit(
signedHeader := keys.GenSignedHeader(
chainID, h, nil,
vals, nextVals,
appHash, consHash, resHash, 0, len(keys))
fcz[i] = lite.NewFullCommit(signedHeader, vals, nextVals)
// Extend the keys by 1 each time.
keys = nkeys
nkeys = nkeys.Extend(1)
@@ -241,10 +244,11 @@ func TestConcurrentProvider(t *testing.T) {
h := int64(1 + i)
appHash := []byte(fmt.Sprintf("h=%d", h))
resHash := []byte(fmt.Sprintf("res=%d", h))
fcz[i] = keys.GenFullCommit(
signedHeader := keys.GenSignedHeader(
chainID, h, nil,
vals, nextVals,
appHash, consHash, resHash, 0, len(keys))
fcz[i] = lite.NewFullCommit(signedHeader, vals, nextVals)
// Extend the keys by 1 each time.
keys = nkeys
nkeys = nkeys.Extend(1)