consensus_tests

package
v0.0.0-...-1f8a15b Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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()
	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 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"`
	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) 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 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