generated from rollkit/template-da-repo
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Allow fetching rollkitmngr state in rollkit-migrate
command for attester sets
#175
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
Draft
Copilot
wants to merge
8
commits into
main
Choose a base branch
from
copilot/fix-164
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+256
−7
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d58cc54
Initial plan
Copilot 48938db
Implement rollkitmngr state fetching in rollkit-migrate command
Copilot 8841575
Improve rollkitmngr state access robustness with multiple key formats…
Copilot 670255e
Add command configuration validation test and finalize implementation
Copilot c0a9468
Replace hacky database access with proper collections framework for r…
Copilot 4aa5521
Remove store modification and use read-only database access for rollk…
Copilot 229d533
Use errors.Join for better error composition in migration command
Copilot 7607a65
Preserve rollkitmngr state error when subsequent errors occur
Copilot 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package server | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cometbft/cometbft/state" | ||
cometbfttypes "github.com/cometbft/cometbft/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCreateRollkitMigrationGenesis_SingleValidator(t *testing.T) { | ||
// Test case: single validator should work with existing logic | ||
validator := &cometbfttypes.Validator{ | ||
Address: []byte("test_validator_addr"), | ||
PubKey: cometbfttypes.NewMockPV().PrivKey.PubKey(), | ||
VotingPower: 100, // Set voting power to avoid the validation error | ||
} | ||
|
||
cometBFTState := state.State{ | ||
ChainID: "test-chain", | ||
InitialHeight: 1, | ||
LastValidators: cometbfttypes.NewValidatorSet([]*cometbfttypes.Validator{validator}), | ||
} | ||
|
||
// Use a temporary directory for testing | ||
tmpDir := t.TempDir() | ||
|
||
// This should succeed with the single validator fallback logic | ||
err := createRollkitMigrationGenesis(tmpDir, cometBFTState) | ||
require.NoError(t, err) | ||
} | ||
|
||
func TestCreateRollkitMigrationGenesis_MultipleValidators_NoRollkitState(t *testing.T) { | ||
// Test case: multiple validators without rollkitmngr state should fail gracefully | ||
validator1 := &cometbfttypes.Validator{ | ||
Address: []byte("test_validator_addr1"), | ||
PubKey: cometbfttypes.NewMockPV().PrivKey.PubKey(), | ||
VotingPower: 100, | ||
} | ||
validator2 := &cometbfttypes.Validator{ | ||
Address: []byte("test_validator_addr2"), | ||
PubKey: cometbfttypes.NewMockPV().PrivKey.PubKey(), | ||
VotingPower: 100, | ||
} | ||
|
||
cometBFTState := state.State{ | ||
ChainID: "test-chain", | ||
InitialHeight: 1, | ||
LastValidators: cometbfttypes.NewValidatorSet([]*cometbfttypes.Validator{validator1, validator2}), | ||
} | ||
|
||
// Use a temporary directory for testing (no rollkitmngr state present) | ||
tmpDir := t.TempDir() | ||
|
||
// This should fail with our new logic when rollkitmngr state is not available | ||
err := createRollkitMigrationGenesis(tmpDir, cometBFTState) | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), "expected exactly one validator") | ||
} | ||
|
||
func TestCreateRollkitMigrationGenesis_NoValidators(t *testing.T) { | ||
// Test case: no validators should return an error | ||
cometBFTState := state.State{ | ||
ChainID: "test-chain", | ||
InitialHeight: 1, | ||
LastValidators: cometbfttypes.NewValidatorSet([]*cometbfttypes.Validator{}), | ||
} | ||
|
||
// Use a temporary directory for testing | ||
tmpDir := t.TempDir() | ||
|
||
// This should fail | ||
err := createRollkitMigrationGenesis(tmpDir, cometBFTState) | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), "no validators found") | ||
} | ||
|
||
func TestGetSequencerFromRollkitMngrState_NoDatabase(t *testing.T) { | ||
// Test case: should fail gracefully when no application database exists | ||
tmpDir := t.TempDir() | ||
|
||
cometBFTState := state.State{ | ||
ChainID: "test-chain", | ||
} | ||
|
||
_, err := getSequencerFromRollkitMngrState(tmpDir, cometBFTState) | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), "no application database found") | ||
} | ||
|
||
func TestSequencerInfo_Validation(t *testing.T) { | ||
// Test the sequencer validation logic by creating a mock scenario | ||
// where we have multiple validators and verify the error messages | ||
|
||
validator1 := &cometbfttypes.Validator{ | ||
Address: []byte("test_validator_addr1"), | ||
PubKey: cometbfttypes.NewMockPV().PrivKey.PubKey(), | ||
VotingPower: 100, | ||
} | ||
validator2 := &cometbfttypes.Validator{ | ||
Address: []byte("test_validator_addr2"), | ||
PubKey: cometbfttypes.NewMockPV().PrivKey.PubKey(), | ||
VotingPower: 100, | ||
} | ||
|
||
cometBFTState := state.State{ | ||
ChainID: "test-chain", | ||
InitialHeight: 1, | ||
LastValidators: cometbfttypes.NewValidatorSet([]*cometbfttypes.Validator{validator1, validator2}), | ||
} | ||
|
||
tmpDir := t.TempDir() | ||
|
||
// This should fail since there's no rollkitmngr state, and provide a helpful error message | ||
err := createRollkitMigrationGenesis(tmpDir, cometBFTState) | ||
require.Error(t, err) | ||
|
||
// The error should mention both the validator count issue and the rollkitmngr state issue | ||
require.Contains(t, err.Error(), "expected exactly one validator") | ||
require.Contains(t, err.Error(), "found 2") | ||
require.Contains(t, err.Error(), "unable to determine sequencer from rollkitmngr state") | ||
} | ||
|
||
func TestMigrateToRollkitCmd_CommandSetup(t *testing.T) { | ||
// Test that the command is properly configured | ||
cmd := MigrateToRollkitCmd() | ||
|
||
require.NotNil(t, cmd) | ||
require.Equal(t, "rollkit-migrate", cmd.Use) | ||
require.Equal(t, "Migrate the data from the CometBFT chain to Rollkit", cmd.Short) | ||
require.NotNil(t, cmd.RunE) | ||
|
||
// Check that the da-height flag is available | ||
flag := cmd.Flags().Lookup("da-height") | ||
require.NotNil(t, flag) | ||
require.Equal(t, "1", flag.DefValue) | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we error joins those errors? as it will be lost otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Now using errors.Join to properly combine the validator count error with the rollkitmngr state error, preserving the error chain for better debugging. Commit 229d533
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't what i mean. Error from L378 is discarded, we should still return it if we end up with errors later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Now preserving the rollkitmngr state error in a variable and including it in the error chain only when subsequent operations fail, rather than discarding it entirely. Commit 89be76c