mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-24 22:32:15 +00:00
* not related to linter: remove obsolete constants: - `Insecure` and `Secure` and type `Security` are not used anywhere * not related to linter: update example - NewInsecure was deleted; change example to NewRemoteDB * address: Binds to all network interfaces (gosec): - bind to localhost instead of 0.0.0.0 - regenerate test key and cert for this purpose (was valid for ::) and otherwise we would see: transport: authentication handshake failed: x509: certificate is valid for ::, not 127.0.0.1\" (used https://github.com/google/keytransparency/blob/master/scripts/gen_server_keys.sh to regenerate certs) * use sha256 in tests instead of md5; time difference is negligible * nolint usage of math/rand in test and add comment on its import - crypto/rand is slower and we do not need sth more secure in tests * enable linter in circle-ci * another nolint math/rand in test * replace another occurrence of md5 * consistent comment about importing math/rand
44 lines
975 B
Go
44 lines
975 B
Go
package merkle
|
|
|
|
import (
|
|
// it is ok to use math/rand here: we do not need a cryptographically secure random
|
|
// number generator here and we can run the tests a bit faster
|
|
"math/rand"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestKeyPath(t *testing.T) {
|
|
var path KeyPath
|
|
keys := make([][]byte, 10)
|
|
alphanum := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
for d := 0; d < 1e4; d++ {
|
|
path = nil
|
|
|
|
for i := range keys {
|
|
enc := keyEncoding(rand.Intn(int(KeyEncodingMax)))
|
|
keys[i] = make([]byte, rand.Uint32()%20)
|
|
switch enc {
|
|
case KeyEncodingURL:
|
|
for j := range keys[i] {
|
|
keys[i][j] = alphanum[rand.Intn(len(alphanum))]
|
|
}
|
|
case KeyEncodingHex:
|
|
rand.Read(keys[i]) //nolint: gosec
|
|
default:
|
|
panic("Unexpected encoding")
|
|
}
|
|
path = path.AppendKey(keys[i], enc)
|
|
}
|
|
|
|
res, err := KeyPathToKeys(path.String())
|
|
require.Nil(t, err)
|
|
|
|
for i, key := range keys {
|
|
require.Equal(t, key, res[i])
|
|
}
|
|
}
|
|
}
|