Skip to content

Commit 4918f74

Browse files
authored
fix(tests): reuse genesis validation formats (#37)
1 parent e7c2455 commit 4918f74

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

genesis_test.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import (
1515
"github.com/stretchr/testify/assert"
1616
)
1717

18+
const (
19+
genesisBlockInvalidFmt = "%s: Genesis block does not appear valid - got %v, want %v"
20+
genesisBlockHashInvalidFmt = "%s: Genesis block hash does not appear valid - got %v, want %v"
21+
)
22+
1823
// TestGenesisBlock tests the genesis block of the main network for validity by
1924
// checking the encoded bytes and hashes.
2025
func TestGenesisBlock(t *testing.T) {
@@ -28,17 +33,13 @@ func TestGenesisBlock(t *testing.T) {
2833

2934
// Ensure the encoded block matches the expected bytes.
3035
if !bytes.Equal(buf.Bytes(), genesisBlockBytes) {
31-
t.Fatalf("TestGenesisBlock: Genesis block does not appear valid - "+
32-
"got %v, want %v", spew.Sdump(buf.Bytes()),
33-
spew.Sdump(genesisBlockBytes))
36+
t.Fatalf(genesisBlockInvalidFmt, "TestGenesisBlock", spew.Sdump(buf.Bytes()), spew.Sdump(genesisBlockBytes))
3437
}
3538

3639
// Check the hash of the block against the expected hash.
3740
hash := MainNetParams.GenesisBlock.BlockHash()
3841
if !MainNetParams.GenesisHash.IsEqual(&hash) {
39-
t.Fatalf("TestGenesisBlock: Genesis block hash does not "+
40-
"appear valid - got %v, want %v", spew.Sdump(hash),
41-
spew.Sdump(MainNetParams.GenesisHash))
42+
t.Fatalf(genesisBlockHashInvalidFmt, "TestGenesisBlock", spew.Sdump(hash), spew.Sdump(MainNetParams.GenesisHash))
4243
}
4344
}
4445

@@ -55,18 +56,13 @@ func TestRegTestGenesisBlock(t *testing.T) {
5556

5657
// Ensure the encoded block matches the expected bytes.
5758
if !bytes.Equal(buf.Bytes(), regTestGenesisBlockBytes) {
58-
t.Fatalf("TestRegTestGenesisBlock: Genesis block does not "+
59-
"appear valid - got %v, want %v",
60-
spew.Sdump(buf.Bytes()),
61-
spew.Sdump(regTestGenesisBlockBytes))
59+
t.Fatalf(genesisBlockInvalidFmt, "TestRegTestGenesisBlock", spew.Sdump(buf.Bytes()), spew.Sdump(regTestGenesisBlockBytes))
6260
}
6361

6462
// Check the hash of the block against the expected hash.
6563
hash := RegressionNetParams.GenesisBlock.BlockHash()
6664
if !RegressionNetParams.GenesisHash.IsEqual(&hash) {
67-
t.Fatalf("TestRegTestGenesisBlock: Genesis block hash does "+
68-
"not appear valid - got %v, want %v", spew.Sdump(hash),
69-
spew.Sdump(RegressionNetParams.GenesisHash))
65+
t.Fatalf(genesisBlockHashInvalidFmt, "TestRegTestGenesisBlock", spew.Sdump(hash), spew.Sdump(RegressionNetParams.GenesisHash))
7066
}
7167
}
7268

@@ -83,18 +79,13 @@ func TestTestNetGenesisBlock(t *testing.T) {
8379

8480
// Ensure the encoded block matches the expected bytes.
8581
if !bytes.Equal(buf.Bytes(), testNetGenesisBlockBytes) {
86-
t.Fatalf("TestTestNetGenesisBlock: Genesis block does not "+
87-
"appear valid - got %v, want %v",
88-
spew.Sdump(buf.Bytes()),
89-
spew.Sdump(testNetGenesisBlockBytes))
82+
t.Fatalf(genesisBlockInvalidFmt, "TestTestNetGenesisBlock", spew.Sdump(buf.Bytes()), spew.Sdump(testNetGenesisBlockBytes))
9083
}
9184

9285
// Check the hash of the block against the expected hash.
9386
hash := TestNetParams.GenesisBlock.BlockHash()
9487
if !TestNetParams.GenesisHash.IsEqual(&hash) {
95-
t.Fatalf("TestTestNetGenesisBlock: Genesis block hash does "+
96-
"not appear valid - got %v, want %v", spew.Sdump(hash),
97-
spew.Sdump(TestNetParams.GenesisHash))
88+
t.Fatalf(genesisBlockHashInvalidFmt, "TestTestNetGenesisBlock", spew.Sdump(hash), spew.Sdump(TestNetParams.GenesisHash))
9889
}
9990
}
10091

0 commit comments

Comments
 (0)