github.com/tendermint/tmlibs@v0.9.0/bech32/bech32_test.go (about)

     1  package bech32_test
     2  
     3  import (
     4  	"bytes"
     5  	"crypto/sha256"
     6  	"testing"
     7  
     8  	"github.com/tendermint/tmlibs/bech32"
     9  )
    10  
    11  func TestEncodeAndDecode(t *testing.T) {
    12  
    13  	sum := sha256.Sum256([]byte("hello world\n"))
    14  
    15  	bech, err := bech32.ConvertAndEncode("shasum", sum[:])
    16  
    17  	if err != nil {
    18  		t.Error(err)
    19  	}
    20  	hrp, data, err := bech32.DecodeAndConvert(bech)
    21  
    22  	if err != nil {
    23  		t.Error(err)
    24  	}
    25  	if hrp != "shasum" {
    26  		t.Error("Invalid hrp")
    27  	}
    28  	if bytes.Compare(data, sum[:]) != 0 {
    29  		t.Error("Invalid decode")
    30  	}
    31  }