github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/encoding/base58/base58_test.go (about)

     1  // Copyright 2012 chaishushan@gmail.com. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package base58
     6  
     7  import (
     8  	"testing"
     9  )
    10  
    11  type test struct {
    12  	en, de string
    13  }
    14  
    15  var golden = []test{
    16  	{"", ""},
    17  	{"\x61", "2g"},
    18  	{"\x62\x62\x62", "a3gV"},
    19  	{"\x63\x63\x63", "aPEr"},
    20  	{"\x73\x69\x6d\x70\x6c\x79\x20\x61\x20\x6c\x6f\x6e\x67\x20\x73\x74\x72\x69\x6e\x67", "2cFupjhnEsSn59qHXstmK2ffpLv2"},
    21  	{"\x00\xeb\x15\x23\x1d\xfc\xeb\x60\x92\x58\x86\xb6\x7d\x06\x52\x99\x92\x59\x15\xae\xb1\x72\xc0\x66\x47", "1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L"},
    22  	{"\x51\x6b\x6f\xcd\x0f", "ABnLTmg"},
    23  	{"\xbf\x4f\x89\x00\x1e\x67\x02\x74\xdd", "3SEo3LWLoPntC"},
    24  	{"\x57\x2e\x47\x94", "3EFU7m"},
    25  	{"\xec\xac\x89\xca\xd9\x39\x23\xc0\x23\x21", "EJDM8drfXA6uyA"},
    26  	{"\x10\xc8\x51\x1e", "Rt5zm"},
    27  	{"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", "1111111111"},
    28  }
    29  
    30  func TestEncodeBase58(t *testing.T) {
    31  	for _, g := range golden {
    32  		s := string(EncodeBase58([]byte(g.en)))
    33  		if s != g.de {
    34  			t.Errorf("Bad EncodeBase58. Need=%v, Got=%v", g.de, s)
    35  		}
    36  	}
    37  }
    38  
    39  func TestDecodeBase58(t *testing.T) {
    40  	for _, g := range golden {
    41  		s := string(DecodeBase58([]byte(g.de)))
    42  		if s != g.en {
    43  			t.Errorf("Bad DecodeBase58. Need=%v, Got=%v", g.en, s)
    44  		}
    45  	}
    46  }
    47  
    48  func TestBase58Check(t *testing.T) {
    49  	ba := []byte("Bitcoin")
    50  	ba = EncodeBase58Check(ba)
    51  	if !DecodeBase58Check(ba) {
    52  		t.Errorf("TestBase58Check. Got=%v", ba)
    53  	}
    54  }