This constructs the map of hashes of zero blocks from constants instead of calculating it at startup time. A new test verifies that the map is correct.
This commit is contained in:
@@ -4,6 +4,7 @@ package protocol
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -610,3 +611,13 @@ func TestIsEquivalent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSha256OfEmptyBlock(t *testing.T) {
|
||||
// every block size should have a correct entry in sha256OfEmptyBlock
|
||||
for blockSize := MinBlockSize; blockSize <= MaxBlockSize; blockSize *= 2 {
|
||||
expected := sha256.Sum256(make([]byte, blockSize))
|
||||
if sha256OfEmptyBlock[blockSize] != expected {
|
||||
t.Error("missing or wrong hash for block of size", blockSize)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user