-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathcache_test.go
46 lines (40 loc) · 1.45 KB
/
cache_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2024 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only
package triedb
import (
"bytes"
"testing"
"github.com/ChainSafe/gossamer/internal/primitives/core/hash"
"github.com/ChainSafe/gossamer/internal/primitives/runtime"
"github.com/ChainSafe/gossamer/pkg/trie/triedb/codec"
"github.com/ChainSafe/gossamer/pkg/trie/triedb/nibbles"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_ByteSize(t *testing.T) {
var childHash hash.H256 = runtime.BlakeTwo256{}.Hash([]byte{0})
encodedBranch := codec.Branch{
PartialKey: nibbles.NewNibbles([]byte{1}),
Value: codec.InlineValue([]byte{7, 8, 9}),
Children: [codec.ChildrenCapacity]codec.MerkleValue{
nil, nil, nil, nil, nil,
nil, nil, nil, nil, nil,
codec.HashedNode[hash.H256]{Hash: childHash},
},
}
cachedNode, err := NewCachedNodeFromNode[hash.H256, runtime.BlakeTwo256](encodedBranch)
require.NoError(t, err)
assert.Equal(t, 308, int(cachedNode.ByteSize()))
encodedBranch = codec.Branch{
PartialKey: nibbles.NewNibbles([]byte{1}),
Value: codec.InlineValue(bytes.Repeat([]byte{1}, 33)),
Children: [codec.ChildrenCapacity]codec.MerkleValue{
nil, nil, nil, nil, nil,
nil, nil, nil, nil, nil,
codec.HashedNode[hash.H256]{Hash: childHash},
},
}
cachedNode, err = NewCachedNodeFromNode[hash.H256, runtime.BlakeTwo256](encodedBranch)
require.NoError(t, err)
assert.Equal(t, 308+30, int(cachedNode.ByteSize()))
}