tendermint/crypto/merkle/proof_key_path_test.go

42 lines
810 B
Go
Raw Normal View History

2018-07-12 23:50:39 -07:00
package merkle
import (
"math/rand"
"testing"
"github.com/stretchr/testify/require"
)
func TestKeyPath(t *testing.T) {
var path KeyPath
keys := make([][]byte, 10)
2018-07-16 19:25:04 -07:00
alphanum := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
for d := 0; d < 1e4; d++ {
path = nil
2018-07-12 23:50:39 -07:00
for i := range keys {
enc := keyEncoding(rand.Intn(int(KeyEncodingMax)))
2018-07-16 19:25:04 -07:00
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])
default:
panic("Unexpected encoding")
}
2018-07-12 23:50:39 -07:00
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])
}
}
}