mirror of
https://github.com/btcsuite/btcd.git
synced 2024-11-19 01:40:07 +01:00
Supplementary chainhash test cases
This commit is contained in:
parent
72ea23ed1e
commit
e0e4916afb
@ -7,6 +7,7 @@ package chainhash
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -194,3 +195,28 @@ func TestNewHashFromStr(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestHashJsonMarshal tests json marshal and unmarshal.
|
||||
func TestHashJsonMarshal(t *testing.T) {
|
||||
hashStr := "000000000003ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"
|
||||
|
||||
hash, err := NewHashFromStr(hashStr)
|
||||
if err != nil {
|
||||
t.Errorf("NewHashFromStr error:%v, hashStr:%s", err, hashStr)
|
||||
}
|
||||
|
||||
hashBytes, err := json.Marshal(hash)
|
||||
if err != nil {
|
||||
t.Errorf("Marshal json error:%v, hash:%v", err, hashBytes)
|
||||
}
|
||||
|
||||
var newHash Hash
|
||||
err = json.Unmarshal(hashBytes, &newHash)
|
||||
if err != nil {
|
||||
t.Errorf("Unmarshal json error:%v, hash:%v", err, hashBytes)
|
||||
}
|
||||
|
||||
if !hash.IsEqual(&newHash) {
|
||||
t.Errorf("String: wrong hash string - got %v, want %v", newHash.String(), hashStr)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user