1 package chaincfg
2 3 import "testing"
4 5 // TestInvalidHashStr ensures the newShaHashFromStr function panics when used to with an invalid hash string.
6 func TestInvalidHashStr(t *testing.T) {
7 defer func() {
8 if r := recover(); r == nil {
9 t.Errorf("Expected panic for invalid hash, got nil")
10 }
11 }()
12 newHashFromStr("banana")
13 }
14 15 // TestMustRegisterPanic ensures the mustRegister function panics when used to register an invalid network.
16 func TestMustRegisterPanic(t *testing.T) {
17 t.Parallel()
18 // Setup a defer to catch the expected panic to ensure it actually paniced.
19 defer func() {
20 if e := recover(); e == nil {
21 t.Error("mustRegister did not panic as expected")
22 }
23 }()
24 // Intentionally try to register duplicate netparams to force a panic.
25 mustRegister(&MainNetParams)
26 }
27