erigon-pulse/cl/spectest/consensus_tests/shuffling.go
Giulio rebuffo 57bcbaa21f
Adds flags to enable/disable backfilling and enable full historical beacon node (#8813)
* Correct naming of hash func in Eth2
* Customizable mode of operation for Caplin
2023-11-22 13:24:35 +01:00

42 lines
1.2 KiB
Go

package consensus_tests
import (
"io/fs"
"testing"
"github.com/ledgerwatch/erigon/spectest"
"github.com/ledgerwatch/erigon/cl/clparams"
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
"github.com/ledgerwatch/erigon/cl/phase1/core/state/shuffling"
"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon/cl/utils"
"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.New(&clparams.MainnetBeaconConfig)
keccakOptimized := utils.OptimizedSha256NotThreadSafe()
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
}