package keys import ( "encoding/hex" "testing" "github.com/stretchr/testify/assert" ) type wifTestCase struct { wif string compressed bool privateKey string version byte } var wifTestCases = []wifTestCase{ { wif: "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn", compressed: true, privateKey: "0000000000000000000000000000000000000000000000000000000000000001", version: 0x80, }, { wif: "5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf", compressed: false, privateKey: "0000000000000000000000000000000000000000000000000000000000000001", version: 0x80, }, { wif: "KxhEDBQyyEFymvfJD96q8stMbJMbZUb6D1PmXqBWZDU2WvbvVs9o", compressed: true, privateKey: "2bfe58ab6d9fd575bdc3a624e4825dd2b375d64ac033fbc46ea79dbab4f69a3e", version: 0x80, }, } func TestWIFEncodeDecode(t *testing.T) { for _, testCase := range wifTestCases { b, err := hex.DecodeString(testCase.privateKey) assert.Nil(t, err) wif, err := WIFEncode(b, testCase.version, testCase.compressed) assert.Nil(t, err) assert.Equal(t, testCase.wif, wif) WIF, err := WIFDecode(wif, testCase.version) assert.Nil(t, err) assert.Equal(t, testCase.privateKey, WIF.PrivateKey.String()) assert.Equal(t, testCase.compressed, WIF.Compressed) assert.Equal(t, testCase.version, WIF.Version) } }