erigon-pulse/cmd/ef-tests-cl/consensus_tests/shuffling.go
a 30430d585a
begin refactor of beacon state (#7433)
this first major move separates the transient beacon state cache from
the underlying tree.

leaf updates are enforced in the setters, which should make programming
easier.

all exported methods of the raw.BeaconState should be safe to call
(without disrupting internal state)

changes many functions to consume *raw.BeaconState in perparation for
interface


beyond refactor it also:

adds a pool for the leaves of the validator ssz hash 

adds a pool for the snappy writers
  
removed the parallel hash experiment (high memory use)
2023-05-04 15:18:42 +02:00

39 lines
1.2 KiB
Go

package consensus_tests
import (
"io/fs"
"testing"
"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon/cl/utils"
"github.com/ledgerwatch/erigon/cmd/ef-tests-cl/spectest"
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/shuffling"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type ShufflingCore struct {
}
func (b *ShufflingCore) Run(t *testing.T, root fs.FS, c spectest.TestCase) (err error) {
var meta struct {
Seed common.Hash `yaml:"seed"`
Count int `yaml:"count"`
Mapping []int `yaml:"mapping"`
}
if err := spectest.ReadMeta(root, "mapping.yaml", &meta); err != nil {
return err
}
s := state.GetEmptyBeaconState()
keccakOptimized := utils.OptimizedKeccak256NotThreadSafe()
preInputs := shuffling.ComputeShuffledIndexPreInputs(s.BeaconConfig(), meta.Seed)
for idx, v := range meta.Mapping {
shuffledIdx, err := shuffling.ComputeShuffledIndex(s.BeaconConfig(), uint64(idx), uint64(meta.Count), meta.Seed, preInputs, keccakOptimized)
require.NoError(t, err)
assert.EqualValues(t, v, shuffledIdx)
}
return nil
}