You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
499 B

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