代码拉取完成,页面将自动刷新
// Copyright (c) 2013-2014 The btcsuite developers
// Copyright (c) 2015-2019 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package base58
import (
"strings"
"testing"
)
// TestBase58Check ensures CheckDecode and CheckEncode produces the expected
// results for inputs with a given version as well as decoding errors.
func TestBase58Check(t *testing.T) {
tests := []struct {
version [2]byte
decoded string
encoded string
}{
{[2]byte{20, 0}, "", "Axk2WA6L"},
{[2]byte{20, 0}, " ", "kxg5DGCa1"},
{[2]byte{20, 0}, "-", "kxhWqwoTY"},
{[2]byte{20, 0}, "0", "kxhrrcZDw"},
{[2]byte{20, 0}, "1", "kxhzgbzwe"},
{[2]byte{20, 0}, "-1", "4M2qnQVfVwu"},
{[2]byte{20, 0}, "11", "4M2smzp65NR"},
{[2]byte{20, 0}, "abc", "FmT72s9HXyp6"},
{[2]byte{20, 0}, "1234598760", "3UFLKR4oYrL1hSX1Eu2W3F"},
{[2]byte{20, 0}, "abcdefghijklmnopqrstuvwxyz", "2M5VSfthNqvveeGWTcKRgY4Rm258o4ZDKBZGkAQ799jp"},
{[2]byte{20, 0}, "00000000000000000000000000000000000000000000000000000000000000", "3cmTs9hNQGCVmurJUgS7UokKFYZCCJWvWfYRBCaox5hXDn3Giiy1u9AEKn7vLS8K87BcDr6Ckr4JYRnnaSMRDsB49i3eU"},
}
for i, test := range tests {
// Test encoding.
gotEncoded := CheckEncode([]byte(test.decoded), test.version)
if gotEncoded != test.encoded {
t.Errorf("CheckEncode test #%d failed: got %q, want: %q", i,
gotEncoded, test.encoded)
continue
}
// Test decoding.
gotDecoded, version, err := CheckDecode(test.encoded)
if err != nil {
t.Errorf("CheckDecode test #%d failed with err: %v", i, err)
} else if version != test.version {
t.Errorf("CheckDecode test #%d failed: got version: %x, want: %x",
i, version, test.version)
} else if string(gotDecoded) != test.decoded {
t.Errorf("CheckDecode test #%d failed: got: %q, want: %q", i,
gotDecoded, test.decoded)
}
}
// Test the two decoding failure cases:
// case 1: Checksum error.
_, _, err := CheckDecode("Axk2WA6M")
if err != ErrChecksum {
t.Error("Checkdecode test failed, expected ErrChecksum")
}
// case 2: invalid formats (string lengths below 6 mean the version byte
// and/or the checksum bytes are missing).
for size := 0; size < 6; size++ {
testString := strings.Repeat("1", size)
_, _, err = CheckDecode(testString)
if err != ErrInvalidFormat {
t.Error("Checkdecode test failed, expected ErrInvalidFormat")
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。