-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2022 ChainSafe Systems (ON) | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
package trie | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ChainSafe/gossamer/dot/types" | ||
"github.com/ChainSafe/gossamer/internal/trie/node" | ||
"github.com/ChainSafe/gossamer/lib/common" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_Trie_GenesisBlock(t *testing.T) { | ||
t.Parallel() | ||
|
||
withHash := func(header types.Header) types.Header { | ||
header.Hash() | ||
return header | ||
} | ||
|
||
testCases := map[string]struct { | ||
trie Trie | ||
genesisHeader types.Header | ||
errSentinel error | ||
errMessage string | ||
}{ | ||
"empty trie": { | ||
genesisHeader: withHash(types.Header{ | ||
ParentHash: common.Hash{0}, | ||
StateRoot: EmptyHash, | ||
ExtrinsicsRoot: EmptyHash, | ||
Digest: types.NewDigest(), | ||
}), | ||
}, | ||
"non empty trie": { | ||
trie: Trie{ | ||
root: &node.Node{ | ||
Key: []byte{1, 2, 3}, | ||
SubValue: []byte{4, 5, 6}, | ||
}, | ||
}, | ||
genesisHeader: withHash(types.Header{ | ||
ParentHash: common.Hash{0}, | ||
StateRoot: common.Hash{ | ||
0x25, 0xc1, 0x86, 0xd4, 0x5b, 0xc9, 0x1d, 0x9f, | ||
0xf5, 0xfd, 0x29, 0xd3, 0x29, 0x8a, 0xa3, 0x63, | ||
0x83, 0xf3, 0x2d, 0x14, 0xa8, 0xbd, 0xde, 0xc9, | ||
0x7b, 0x57, 0x92, 0x78, 0x67, 0xfc, 0x8a, 0xfa}, | ||
ExtrinsicsRoot: EmptyHash, | ||
Digest: types.NewDigest(), | ||
}), | ||
}, | ||
} | ||
|
||
for name, testCase := range testCases { | ||
testCase := testCase | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
trie := testCase.trie | ||
|
||
genesisHeader, err := trie.GenesisBlock() | ||
|
||
assert.ErrorIs(t, err, testCase.errSentinel) | ||
if testCase.errSentinel != nil { | ||
assert.EqualError(t, err, testCase.errMessage) | ||
} | ||
assert.Equal(t, testCase.genesisHeader, genesisHeader) | ||
}) | ||
} | ||
} |