2023-01-07 11:25:28 +00:00
|
|
|
package merkle_tree_test
|
|
|
|
|
|
|
|
import (
|
2023-05-23 18:58:34 +00:00
|
|
|
_ "embed"
|
2023-01-07 11:25:28 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-05-23 18:58:34 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/common"
|
|
|
|
"github.com/ledgerwatch/erigon/cl/clparams"
|
2023-01-07 11:25:28 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cl/merkle_tree"
|
2023-05-23 18:58:34 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
|
|
|
"github.com/ledgerwatch/erigon/cl/utils"
|
|
|
|
"github.com/stretchr/testify/require"
|
2023-01-07 11:25:28 +00:00
|
|
|
)
|
|
|
|
|
2023-05-23 18:58:34 +00:00
|
|
|
//go:embed testdata/serialized.ssz_snappy
|
|
|
|
var beaconState []byte
|
2023-01-07 11:25:28 +00:00
|
|
|
|
2023-05-23 18:58:34 +00:00
|
|
|
func TestHashTreeRoot(t *testing.T) {
|
|
|
|
bs := state.New(&clparams.MainnetBeaconConfig)
|
|
|
|
require.NoError(t, utils.DecodeSSZSnappy(bs, beaconState, int(clparams.DenebVersion)))
|
|
|
|
root, err := bs.HashSSZ()
|
2023-01-07 11:25:28 +00:00
|
|
|
require.NoError(t, err)
|
2023-06-03 22:36:16 +00:00
|
|
|
require.Equal(t, common.Hash(root), common.HexToHash("0x9f684cf34c4ac8eb9056051f93498c552b59de6b0977c453ee099be68e58d90c"))
|
2023-01-07 11:25:28 +00:00
|
|
|
}
|
|
|
|
|
2023-05-23 18:58:34 +00:00
|
|
|
func TestHashTreeRootTxs(t *testing.T) {
|
|
|
|
txs := [][]byte{
|
|
|
|
{1, 2, 3},
|
|
|
|
{1, 2, 3},
|
|
|
|
{1, 2, 3},
|
|
|
|
}
|
|
|
|
root, err := merkle_tree.TransactionsListRoot(txs)
|
2023-01-07 11:25:28 +00:00
|
|
|
require.NoError(t, err)
|
2023-05-23 18:58:34 +00:00
|
|
|
require.Equal(t, common.Hash(root), common.HexToHash("0x987269bc1075122edff32bfc38479757103cee5c1ed6e990de7ffee85b5dd18a"))
|
2023-01-07 11:25:28 +00:00
|
|
|
}
|