consensus_tests

package
v3.0.0-alpha5.0...-c974331 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2024 License: LGPL-3.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Eip4844MerkleProof = spectest.HandlerFunc(func(t *testing.T, root fs.FS, c spectest.TestCase) (err error) {

	proofYaml := MPTBranch{}
	err = spectest.ReadYml(root, "proof.yaml", &proofYaml)
	require.NoError(t, err)

	branch := make([][32]byte, len(proofYaml.Branch))
	for i, b := range proofYaml.Branch {
		branch[i] = libcommon.HexToHash(b)
	}
	leaf := libcommon.HexToHash(proofYaml.Leaf)
	beaconBody := cltypes.NewBeaconBody(&clparams.MainnetBeaconConfig, clparams.DenebVersion)
	require.NoError(t, spectest.ReadSsz(root, c.Version(), spectest.ObjectSSZ, beaconBody))
	proof, err := beaconBody.KzgCommitmentMerkleProof(0)
	require.NoError(t, err)

	require.Equal(t, branch, proof)
	bodyRoot, err := beaconBody.HashSSZ()
	require.NoError(t, err)
	proofHashes := make([]libcommon.Hash, len(proof))
	for i := range proof {
		proofHashes[i] = libcommon.Hash(proof[i])
	}
	require.True(t, utils.IsValidMerkleBranch(leaf, proofHashes, 17, proofYaml.LeafIndex, bodyRoot))
	hashList := solid.NewHashVector(17)
	for i, h := range proof {
		hashList.Set(i, libcommon.Hash(h))
	}
	require.True(t, cltypes.VerifyCommitmentInclusionProof(libcommon.Bytes48(*beaconBody.BlobKzgCommitments.Get(0)), hashList, 0, c.Version(), bodyRoot))
	return nil

})
View Source
var FinalityFinality = spectest.HandlerFunc(func(t *testing.T, root fs.FS, c spectest.TestCase) (err error) {

	testState, err := spectest.ReadBeaconState(root, c.Version(), spectest.PreSsz)
	require.NoError(t, err)

	expectedState, err := spectest.ReadBeaconState(root, c.Version(), spectest.PostSsz)
	require.NoError(t, err)

	blocks, err := spectest.ReadBlocks(root, c.Version())
	if err != nil {
		return err
	}
	startSlot := testState.Slot()
	for _, block := range blocks {
		if err := machine.TransitionState(c.Machine, testState, block); err != nil {
			require.NoError(t, fmt.Errorf("cannot transition state: %w. slot=%d. start_slot=%d", err, block.Block.Slot, startSlot))
		}
	}
	expectedRoot, err := testState.HashSSZ()
	assert.NoError(t, err)

	haveRoot, err := expectedState.HashSSZ()
	assert.NoError(t, err)

	assert.EqualValues(t, haveRoot, expectedRoot, "state root")

	return nil
})
View Source
var ForksFork = spectest.HandlerFunc(func(t *testing.T, root fs.FS, c spectest.TestCase) (err error) {

	preState, err := spectest.ReadBeaconState(root, c.Version()-1, spectest.PreSsz)
	require.NoError(t, err)

	postState, err := spectest.ReadBeaconState(root, c.Version(), spectest.PostSsz)
	expectedError := os.IsNotExist(err)
	if !expectedError {
		require.NoError(t, err)
	}
	switch preState.Version() {
	case clparams.Phase0Version:
		err = preState.UpgradeToAltair()
	case clparams.AltairVersion:
		err = preState.UpgradeToBellatrix()
	case clparams.BellatrixVersion:
		err = preState.UpgradeToCapella()
	case clparams.CapellaVersion:
		err = preState.UpgradeToDeneb()
	case clparams.DenebVersion:
		err = preState.UpgradeToElectra()
	default:
		err = spectest.ErrHandlerNotImplemented(fmt.Sprintf("block state %v", preState.Version()))
	}
	if expectedError {
		assert.Error(t, err)
	}

	haveRoot, err := preState.HashSSZ()
	assert.NoError(t, err)

	expectedRoot, err := postState.HashSSZ()
	assert.NoError(t, err)
	assert.EqualValues(t, haveRoot, expectedRoot, "state root")

	return nil
})
View Source
var LightClientBeaconBlockBodyExecutionMerkleProof = spectest.HandlerFunc(func(t *testing.T, root fs.FS, c spectest.TestCase) (err error) {
	var proof [][32]byte
	switch c.CaseName {
	case "execution_merkle_proof":
		beaconBody := cltypes.NewBeaconBody(&clparams.MainnetBeaconConfig, clparams.DenebVersion)
		require.NoError(t, spectest.ReadSsz(root, c.Version(), spectest.ObjectSSZ, beaconBody))
		proof, err = beaconBody.ExecutionPayloadMerkleProof()
		require.NoError(t, err)
	case "current_sync_committee_merkle_proof":
		state := state.New(&clparams.MainnetBeaconConfig)
		require.NoError(t, spectest.ReadSsz(root, c.Version(), spectest.ObjectSSZ, state))
		proof, err = state.CurrentSyncCommitteeBranch()
		require.NoError(t, err)
	case "next_sync_committee_merkle_proof":
		state := state.New(&clparams.MainnetBeaconConfig)
		require.NoError(t, spectest.ReadSsz(root, c.Version(), spectest.ObjectSSZ, state))
		proof, err = state.NextSyncCommitteeBranch()
		require.NoError(t, err)
	case "finality_root_merkle_proof":
		state := state.New(&clparams.MainnetBeaconConfig)
		require.NoError(t, spectest.ReadSsz(root, c.Version(), spectest.ObjectSSZ, state))

		proof, err = state.FinalityRootBranch()
		require.NoError(t, err)
	default:
		t.Skip("skipping: ", c.CaseName)
	}

	proofYaml := LcBranch{}
	err = spectest.ReadYml(root, "proof.yaml", &proofYaml)
	require.NoError(t, err)

	branch := make([][32]byte, len(proofYaml.Branch))
	for i, b := range proofYaml.Branch {
		branch[i] = libcommon.HexToHash(b)
	}

	require.Equal(t, branch, proof)
	return nil
})
View Source
var SanityBlocks = spectest.HandlerFunc(func(t *testing.T, root fs.FS, c spectest.TestCase) (err error) {
	var meta struct {
		Description            string `yaml:"description"`
		BlsSetting             int    `yaml:"bls_settings"`
		RevealDeadlinesSetting int    `yaml:"reveal_deadlines_setting"`
		BlocksCount            int    `yaml:"blocks_count"`
	}

	err = spectest.ReadMeta(root, "meta.yaml", &meta)
	require.NoError(t, err)

	testState, err := spectest.ReadBeaconState(root, c.Version(), spectest.PreSsz)
	require.NoError(t, err)

	var expectedError bool
	expectedState, err := spectest.ReadBeaconState(root, c.Version(), spectest.PostSsz)
	if os.IsNotExist(err) {
		expectedError = true
	} else {
		require.NoError(t, err)
	}

	blocks, err := spectest.ReadBlocks(root, c.Version())
	require.NoError(t, err)

	var block *cltypes.SignedBeaconBlock
	for _, block = range blocks {
		err = machine.TransitionState(c.Machine, testState, block)
		if err != nil {
			break
		}
	}

	if expectedError {
		require.Error(t, err)
		return nil
	} else {
		require.NoError(t, err)
	}

	finalRoot, err := expectedState.HashSSZ()
	require.NoError(t, err)
	haveRoot, err := testState.HashSSZ()
	require.NoError(t, err)

	assert.EqualValues(t, finalRoot, haveRoot)

	return nil
})
View Source
var SanitySlots = spectest.HandlerFunc(func(t *testing.T, root fs.FS, c spectest.TestCase) (err error) {
	// TODO: this is unused, why?
	var slots int
	err = spectest.ReadMeta(root, "slots.yaml", &slots)
	require.NoError(t, err)

	testState, err := spectest.ReadBeaconState(root, c.Version(), spectest.PreSsz)
	require.NoError(t, err)

	expectedState, err := spectest.ReadBeaconState(root, c.Version(), spectest.PostSsz)
	require.NoError(t, err)

	err = c.Machine.ProcessSlots(testState, expectedState.Slot())
	require.NoError(t, err)

	expectedRoot, err := expectedState.HashSSZ()
	require.NoError(t, err)

	haveRoot, err := testState.HashSSZ()
	require.NoError(t, err)

	assert.EqualValues(t, expectedRoot, haveRoot)
	return nil
})
View Source
var TestFormats = spectest.Appendix{}

Functions

This section is empty.

Types

type BlsAggregateVerify

type BlsAggregateVerify struct {
}

func (*BlsAggregateVerify) Run

func (b *BlsAggregateVerify) Run(t *testing.T, root fs.FS, c spectest.TestCase) (err error)

type EpochProcessing

type EpochProcessing struct {
	Fn func(s abstract.BeaconState) error
}

func NewEpochProcessing

func NewEpochProcessing(fn func(s abstract.BeaconState) error) *EpochProcessing

func (*EpochProcessing) Run

func (b *EpochProcessing) Run(t *testing.T, root fs.FS, c spectest.TestCase) (err error)

type ForkChoice

type ForkChoice struct {
}

func NewForkChoice

func NewForkChoice(fn func(s abstract.BeaconState) error) *ForkChoice

func (*ForkChoice) Run

func (b *ForkChoice) Run(t *testing.T, root fs.FS, c spectest.TestCase) (err error)

type ForkChoiceChecks

type ForkChoiceChecks struct {
	Head *struct {
		Slot *int         `yaml:"slot,omitempty"`
		Root *common.Hash `yaml:"root,omitempty"`
	} `yaml:"head,omitempty"`
	Time                *int `yaml:"time,omitempty"`
	GenesisTime         *int `yaml:"genesis_time,omitempty"`
	JustifiedCheckpoint *struct {
		Epoch *int         `yaml:"epoch,omitempty"`
		Root  *common.Hash `yaml:"root,omitempty"`
	} `yaml:"justified_checkpoint,omitempty"`

	FinalizedCheckpoint *struct {
		Epoch *int         `yaml:"epoch,omitempty"`
		Root  *common.Hash `yaml:"root,omitempty"`
	} `yaml:"finalized_checkpoint,omitempty"`
	ProposerBoostRoot *common.Hash `yaml:"proposer_boost_root,omitempty"`
}

type ForkChoicePayloadStatus

type ForkChoicePayloadStatus struct {
	Status          string `yaml:"status"`
	LatestValidHash string `yaml:"latest_valid_hash"`
	ValidationError string `yaml:"validation_error"`
}

type ForkChoiceStep

type ForkChoiceStep struct {
	Tick             *int                     `yaml:"tick,omitempty"`
	Valid            *bool                    `yaml:"valid,omitempty"`
	Attestation      *string                  `yaml:"attestation,omitempty"`
	Block            *string                  `yaml:"block,omitempty"`
	Blobs            *string                  `yaml:"blobs,omitempty"`
	Proofs           []string                 `yaml:"proofs,omitempty"`
	PowBlock         *string                  `yaml:"pow_block,omitempty"`
	AttesterSlashing *string                  `yaml:"attester_slashing,omitempty"`
	BlockHash        *string                  `yaml:"block_hash,omitempty"`
	PayloadStatus    *ForkChoicePayloadStatus `yaml:"payload_status,omitempty"`
	Checks           *ForkChoiceChecks        `yaml:"checks,omitempty"`
}

func (*ForkChoiceStep) GetAttestation

func (f *ForkChoiceStep) GetAttestation() string

func (*ForkChoiceStep) GetAttesterSlashing

func (f *ForkChoiceStep) GetAttesterSlashing() string

func (*ForkChoiceStep) GetBlobs

func (f *ForkChoiceStep) GetBlobs() string

func (*ForkChoiceStep) GetBlock

func (f *ForkChoiceStep) GetBlock() string

func (*ForkChoiceStep) GetBlockHash

func (f *ForkChoiceStep) GetBlockHash() string

func (*ForkChoiceStep) GetChecks

func (f *ForkChoiceStep) GetChecks() *ForkChoiceChecks

func (*ForkChoiceStep) GetPayloadStatus

func (f *ForkChoiceStep) GetPayloadStatus() *ForkChoicePayloadStatus

func (*ForkChoiceStep) GetPowBlock

func (f *ForkChoiceStep) GetPowBlock() string

func (*ForkChoiceStep) GetTick

func (f *ForkChoiceStep) GetTick() int

func (*ForkChoiceStep) GetValid

func (f *ForkChoiceStep) GetValid() bool

func (*ForkChoiceStep) StepType

func (f *ForkChoiceStep) StepType() string

type LcBranch

type LcBranch struct {
	Branch []string `yaml:"branch"`
}

type MPTBranch

type MPTBranch struct {
	Branch    []string `yaml:"branch"`
	Leaf      string   `yaml:"leaf"`
	LeafIndex uint64   `yaml:"leaf_index"`
}

type RewardsCore

type RewardsCore struct {
}

func (*RewardsCore) Run

func (b *RewardsCore) Run(t *testing.T, root fs.FS, c spectest.TestCase) (err error)

type Root

type Root struct {
	Root string `yaml:"root"`
}

type ShufflingCore

type ShufflingCore struct {
}

func (*ShufflingCore) Run

func (b *ShufflingCore) Run(t *testing.T, root fs.FS, c spectest.TestCase) (err error)

type TransitionCore

type TransitionCore struct {
}

func (*TransitionCore) Run

func (b *TransitionCore) Run(t *testing.T, root fs.FS, c spectest.TestCase) (err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL