Skip to content

Commit 496f6a5

Browse files
committed
beautify testing for PrivateKey.Child
1 parent 39aa08a commit 496f6a5

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

golden_addon.go

+11-12
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,6 @@ func main() {
105105
path: []uint32{0, 2147483647, 1, 2147483646, 2},
106106
wantPriv: "xprvA48ALo8BDjcRET68R5RsPzF3H7WeyYYtHcyUeLRGBPHXu6CJSGjwW7dWoeUWTEzT7LG3qk6Eg6x2ZoqD8gtyEFZecpAyvchksfLyg3Zbqam",
107107
},
108-
109-
/*
110-
// Custom tests to trigger specific conditions.
111-
{
112-
// Seed 000000000000000000000000000000da.
113-
name: "Derived privkey with zero high byte m/0",
114-
master: "xprv9s21ZrQH143K4FR6rNeqEK4EBhRgLjWLWhA3pw8iqgAKk82ypz58PXbrzU19opYcxw8JDJQF4id55PwTsN1Zv8Xt6SKvbr2KNU5y8jN8djz",
115-
path: []uint32{0},
116-
wantPriv: "xprv9uC5JqtViMmgcAMUxcsBCBFA7oYCNs4bozPbyvLfddjHou4rMiGEHipz94xNaPb1e4f18TRoPXfiXx4C3cDAcADqxCSRSSWLvMBRWPctSN9",
117-
},
118-
*/
119108
}
120109

121110
seeds := map[string]string{
@@ -192,8 +181,18 @@ func main() {
192181
}
193182

194183
func oneMore() *Goldie {
184+
/*
185+
// Custom tests to trigger specific conditions.
186+
{
187+
// Seed 000000000000000000000000000000da.
188+
name: "Derived privkey with zero high byte m/0",
189+
master: "xprv9s21ZrQH143K4FR6rNeqEK4EBhRgLjWLWhA3pw8iqgAKk82ypz58PXbrzU19opYcxw8JDJQF4id55PwTsN1Zv8Xt6SKvbr2KNU5y8jN8djz",
190+
path: []uint32{0},
191+
wantPriv: "xprv9uC5JqtViMmgcAMUxcsBCBFA7oYCNs4bozPbyvLfddjHou4rMiGEHipz94xNaPb1e4f18TRoPXfiXx4C3cDAcADqxCSRSSWLvMBRWPctSN9",
192+
},
193+
*/
195194
goldie := &Goldie{
196-
Seed: " 000000000000000000000000000000da",
195+
Seed: "000000000000000000000000000000da",
197196
Chains: []ChainGoldie{
198197
{
199198
Path: "m",

master_key.go

-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ func GenerateMasterKey(rand io.Reader, keyID Magic,
1919
}
2020

2121
seed := make([]byte, seedLen)
22-
//if n, err := rand.Read(seed); nil != err || n != seedLen {
23-
// return nil, ErrNoEnoughEntropy
24-
//}
2522
if _, err := io.ReadFull(rand, seed); nil != err {
2623
return nil, ErrNoEnoughEntropy
2724
}

private_key_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func TestPrivateKey_AddressPubKeyHash(t *testing.T) {
4242
}
4343
}
4444

45+
/*
4546
func TestPrivateKey_Child_OK(t *testing.T) {
4647
// The private extended keys for test vectors in [BIP32].
4748
testVec1MasterPrivKey := "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi"
@@ -171,10 +172,14 @@ tests:
171172
}
172173
}
173174
}
175+
*/
174176

175177
func TestPrivateKey_Child_OK2(t *testing.T) {
176-
var testCases []bip32.Goldie
178+
var testCases, addOn []bip32.Goldie
177179
bip32.ReadGoldenJSON(bip32.GoldenName, &testCases)
180+
bip32.ReadGoldenJSON(bip32.GoldenAddOnName, &addOn)
181+
182+
testCases = append(testCases, addOn...)
178183

179184
for _, c := range testCases {
180185
c := c

testdata/bip32_addon.golden

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
]
7171
},
7272
{
73-
"Seed": " 000000000000000000000000000000da",
73+
"Seed": "000000000000000000000000000000da",
7474
"Chains": [
7575
{
7676
"Path": "m",
@@ -85,3 +85,4 @@
8585
]
8686
}
8787
]
88+

testing.go

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
const GoldenBase = "testdata"
1717
const GoldenName = "bip32.golden"
18+
const GoldenAddOnName = "bip32_addon.golden"
1819

1920
var GoldenPath = filepath.Join(GoldenBase, GoldenName)
2021

0 commit comments

Comments
 (0)