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) {
|
2023-06-02 20:26:19 +00:00
|
|
|
t.Skip("Need to update due to data_gas_used")
|
2023-05-23 18:58:34 +00:00
|
|
|
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-05-23 18:58:34 +00:00
|
|
|
require.Equal(t, common.Hash(root), common.HexToHash("0x7d085d9f2cce04eefb4c0aafad744fd2ce4ff962b2c3589fda53aab084171406"))
|
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
|
|
|
}
|