-
Notifications
You must be signed in to change notification settings - Fork 592
Test validator's ability to rewind upon span rotation #1960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
537f5c2
Test validator's ability to rewind upon span rotation
cffls ab76434
Add unit tests
cffls 7f6a7b8
Remove dup code
cffls 3dc41ea
Parallelize tests
cffls 4cf2305
Merge remote-tracking branch 'origin/develop' into test_span_rotation…
cffls File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| package ethconfig | ||
|
|
||
| import ( | ||
| "context" | ||
| "math/big" | ||
| "testing" | ||
|
|
||
| borTypes "github.com/0xPolygon/heimdall-v2/x/bor/types" | ||
| stakeTypes "github.com/0xPolygon/heimdall-v2/x/stake/types" | ||
| ctypes "github.com/cometbft/cometbft/rpc/core/types" | ||
| "github.com/ethereum/go-ethereum/consensus/bor" | ||
| "github.com/ethereum/go-ethereum/consensus/bor/clerk" | ||
| "github.com/ethereum/go-ethereum/consensus/bor/heimdall/checkpoint" | ||
| "github.com/ethereum/go-ethereum/consensus/bor/heimdall/milestone" | ||
| "github.com/ethereum/go-ethereum/core/rawdb" | ||
| "github.com/ethereum/go-ethereum/params" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // mockHeimdallClient implements bor.IHeimdallClient for testing | ||
| type mockHeimdallClient struct{} | ||
|
|
||
| func (m *mockHeimdallClient) Close() {} | ||
| func (m *mockHeimdallClient) StateSyncEvents(context.Context, uint64, int64) ([]*clerk.EventRecordWithTime, error) { | ||
| return nil, nil | ||
| } | ||
| func (m *mockHeimdallClient) GetSpan(_ context.Context, spanID uint64) (*borTypes.Span, error) { | ||
| return &borTypes.Span{ | ||
| Id: spanID, StartBlock: 0, EndBlock: 255, | ||
| ValidatorSet: stakeTypes.ValidatorSet{ | ||
| Validators: []*stakeTypes.Validator{{ValId: 1, Signer: "0x96C42C56fdb78294F96B0cFa33c92bed7D75F96a", VotingPower: 100}}, | ||
| }, | ||
| }, nil | ||
| } | ||
| func (m *mockHeimdallClient) GetLatestSpan(ctx context.Context) (*borTypes.Span, error) { | ||
| return m.GetSpan(ctx, 0) | ||
| } | ||
| func (m *mockHeimdallClient) FetchCheckpoint(context.Context, int64) (*checkpoint.Checkpoint, error) { | ||
| return nil, nil | ||
| } | ||
| func (m *mockHeimdallClient) FetchCheckpointCount(context.Context) (int64, error) { return 0, nil } | ||
| func (m *mockHeimdallClient) FetchMilestone(context.Context) (*milestone.Milestone, error) { | ||
| return nil, nil | ||
| } | ||
| func (m *mockHeimdallClient) FetchMilestoneCount(context.Context) (int64, error) { return 0, nil } | ||
| func (m *mockHeimdallClient) FetchStatus(context.Context) (*ctypes.SyncInfo, error) { | ||
| return &ctypes.SyncInfo{CatchingUp: false}, nil | ||
| } | ||
|
|
||
| // newTestBorChainConfig creates a minimal Bor chain config for testing | ||
| func newTestBorChainConfig() *params.ChainConfig { | ||
| return ¶ms.ChainConfig{ | ||
| ChainID: big.NewInt(137), | ||
| HomesteadBlock: big.NewInt(0), | ||
| EIP150Block: big.NewInt(0), | ||
| EIP155Block: big.NewInt(0), | ||
| EIP158Block: big.NewInt(0), | ||
| ByzantiumBlock: big.NewInt(0), | ||
| ConstantinopleBlock: big.NewInt(0), | ||
| PetersburgBlock: big.NewInt(0), | ||
| IstanbulBlock: big.NewInt(0), | ||
| MuirGlacierBlock: big.NewInt(0), | ||
| BerlinBlock: big.NewInt(0), | ||
| LondonBlock: big.NewInt(0), | ||
| Bor: ¶ms.BorConfig{ | ||
| Period: map[string]uint64{"0": 2}, | ||
| ProducerDelay: map[string]uint64{"0": 4}, | ||
| Sprint: map[string]uint64{"0": 64}, | ||
| BackupMultiplier: map[string]uint64{"0": 2}, | ||
| ValidatorContract: "0x0000000000000000000000000000000000001000", | ||
| StateReceiverContract: "0x0000000000000000000000000000000000001001", | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func TestCreateConsensusEngine_OverrideHeimdallClient(t *testing.T) { | ||
| t.Parallel() | ||
| ethConfig := &Config{ | ||
| OverrideHeimdallClient: &mockHeimdallClient{}, | ||
| WithoutHeimdall: false, | ||
| } | ||
|
|
||
| engine, err := CreateConsensusEngine(newTestBorChainConfig(), ethConfig, rawdb.NewMemoryDatabase(), nil) | ||
| require.NoError(t, err) | ||
| defer engine.Close() | ||
|
|
||
| _, ok := engine.(*bor.Bor) | ||
| require.True(t, ok, "Expected Bor consensus engine") | ||
| } | ||
|
|
||
| func TestCreateConsensusEngine_WithoutHeimdall(t *testing.T) { | ||
| t.Parallel() | ||
| ethConfig := &Config{WithoutHeimdall: true} | ||
|
|
||
| engine, err := CreateConsensusEngine(newTestBorChainConfig(), ethConfig, rawdb.NewMemoryDatabase(), nil) | ||
| require.NoError(t, err) | ||
| defer engine.Close() | ||
|
|
||
| _, ok := engine.(*bor.Bor) | ||
| require.True(t, ok, "Expected Bor consensus engine") | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.