github.com/dashpay/godash@v0.0.0-20160726055534-e038a21e0e3d/chaincfg/params_test.go (about)

     1  // Copyright (c) 2016 The btcsuite developers
     2  // Copyright (c) 2016 The Dash developers
     3  // Use of this source code is governed by an ISC
     4  // license that can be found in the LICENSE file.
     5  
     6  package chaincfg
     7  
     8  import "testing"
     9  
    10  // TestInvalidHashStr ensures the newShaHashFromStr function panics when used to
    11  // with an invalid hash string.
    12  func TestInvalidHashStr(t *testing.T) {
    13  	defer func() {
    14  		if r := recover(); r == nil {
    15  			t.Errorf("Expected panic for invalid hash, got nil")
    16  		}
    17  	}()
    18  	newShaHashFromStr("banana")
    19  }
    20  
    21  // TestMustRegisterPanic ensures the mustRegister function panics when used to
    22  // register an invalid network.
    23  func TestMustRegisterPanic(t *testing.T) {
    24  	t.Parallel()
    25  
    26  	// Setup a defer to catch the expected panic to ensure it actually
    27  	// paniced.
    28  	defer func() {
    29  		if err := recover(); err == nil {
    30  			t.Error("mustRegister did not panic as expected")
    31  		}
    32  	}()
    33  
    34  	// Intentionally try to register duplicate params to force a panic.
    35  	mustRegister(&MainNetParams)
    36  }