mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-26 07:12:16 +00:00
32 lines
499 B
Go
32 lines
499 B
Go
|
package bech32_test
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"crypto/sha256"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/tendermint/tmlibs/bech32"
|
||
|
)
|
||
|
|
||
|
func TestEncodeAndDecode(t *testing.T) {
|
||
|
|
||
|
sum := sha256.Sum256([]byte("hello world\n"))
|
||
|
|
||
|
bech, err := bech32.ConvertAndEncode("shasum", sum[:])
|
||
|
|
||
|
if err != nil {
|
||
|
t.Error(err)
|
||
|
}
|
||
|
hrp, data, err := bech32.DecodeAndConvert(bech)
|
||
|
|
||
|
if err != nil {
|
||
|
t.Error(err)
|
||
|
}
|
||
|
if hrp != "shasum" {
|
||
|
t.Error("Invalid hrp")
|
||
|
}
|
||
|
if bytes.Compare(data, sum[:]) != 0 {
|
||
|
t.Error("Invalid decode")
|
||
|
}
|
||
|
}
|