mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-09-13 21:10:12 +00:00

* [NOD-629] Change GHOSTDAG K to a a single byte using type * [NOD-629] Rename variable * [NOD-629] Rename K to KSize * [NOD-629] Remove redundant casting * [NOD-629] Add test for KSize * [NOD-629] Seperate block serialization and db store * [NOD-629] Make sure K is serialized as uint8 * [NOD-629] Rename KSize to KType * [NOD-629] Comment for test * [NOD-629] Change fail message * [NOD-629] Remove newlines * [NOD-629] Fix test * [NOD-629] Do not use maxuint8, but !0 instead * [NOD-629] Fix test * [NOD-629] Merge conflict * [NOD-629] Fix test; Update comment
41 lines
1.4 KiB
Go
41 lines
1.4 KiB
Go
package blockdag
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/dagconfig"
|
|
"github.com/kaspanet/kaspad/util/daghash"
|
|
"testing"
|
|
)
|
|
|
|
// This test is to ensure the size BlueAnticoneSizesSize is serialized to the size of KType.
|
|
// We verify that by serializing and deserializing the block while making sure that we stay within the expected range.
|
|
func TestBlueAnticoneSizesSize(t *testing.T) {
|
|
dag, teardownFunc, err := DAGSetup("TestBlueAnticoneSizesSize", Config{
|
|
DAGParams: &dagconfig.SimnetParams,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("TestBlueAnticoneSizesSize: Failed to setup DAG instance: %s", err)
|
|
}
|
|
defer teardownFunc()
|
|
|
|
k := dagconfig.KType(0)
|
|
k--
|
|
|
|
if k < dagconfig.KType(0) {
|
|
t.Fatalf("KType must be unsigned")
|
|
}
|
|
|
|
blockHeader := dagconfig.SimnetParams.GenesisBlock.Header
|
|
node, _ := dag.newBlockNode(&blockHeader, newSet())
|
|
hash := daghash.Hash{1}
|
|
// Setting maxKType to maximum value of KType.
|
|
// As we verify above that KType is unsigned we can be sure that maxKType is indeed the maximum value of KType.
|
|
maxKType := ^dagconfig.KType(0)
|
|
node.bluesAnticoneSizes[hash] = maxKType
|
|
serializedNode, _ := serializeBlockNode(node)
|
|
deserializedNode, _ := dag.deserializeBlockNode(serializedNode)
|
|
if deserializedNode.bluesAnticoneSizes[hash] != maxKType {
|
|
t.Fatalf("TestBlueAnticoneSizesSize: BlueAnticoneSize should not change when deserializing. Expected: %v but got %v",
|
|
maxKType, deserializedNode.bluesAnticoneSizes[hash])
|
|
}
|
|
}
|