This repository was archived by the owner on Feb 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 747
fix migration down; check for greater forkIDs instead of the next +1 #3182
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package pgstatestorage_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/0xPolygonHermez/zkevm-node/state" | ||
| "github.com/0xPolygonHermez/zkevm-node/state/pgstatestorage" | ||
| "github.com/0xPolygonHermez/zkevm-node/test/dbutils" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestAddForkIDInterval(t *testing.T) { | ||
| if err := dbutils.InitOrResetState(stateDBCfg); err != nil { | ||
| panic(err) | ||
| } | ||
| pgStateStorage = pgstatestorage.NewPostgresStorage(state.Config{}, stateDb) | ||
| testState = state.NewState(stateCfg, pgstatestorage.NewPostgresStorage(stateCfg, stateDb), executorClient, stateTree, nil, nil) | ||
|
|
||
| for i := 1; i <= 6; i++ { | ||
| err = testState.AddForkID(ctx, state.ForkIDInterval{FromBatchNumber: uint64(i * 10), ToBatchNumber: uint64(i*10) + 9, ForkId: uint64(i)}, nil) | ||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| testCases := []struct { | ||
| name string | ||
| forkIDToAdd state.ForkIDInterval | ||
| expectedError error | ||
| }{ | ||
| { | ||
| name: "fails to add because forkID already exists", | ||
| forkIDToAdd: state.ForkIDInterval{ForkId: 3}, | ||
| expectedError: fmt.Errorf("error checking forkID sequence. Last ForkID stored: 6. New ForkID received: 3"), | ||
| }, | ||
| { | ||
| name: "fails to add because forkID is smaller than the latest forkID", | ||
| forkIDToAdd: state.ForkIDInterval{ForkId: 5}, | ||
| expectedError: fmt.Errorf("error checking forkID sequence. Last ForkID stored: 6. New ForkID received: 5"), | ||
| }, | ||
| { | ||
| name: "fails to add because forkID is equal to the latest forkID", | ||
| forkIDToAdd: state.ForkIDInterval{ForkId: 6}, | ||
| expectedError: fmt.Errorf("error checking forkID sequence. Last ForkID stored: 6. New ForkID received: 6"), | ||
| }, | ||
| { | ||
| name: "adds successfully", | ||
| forkIDToAdd: state.ForkIDInterval{ForkId: 7}, | ||
| expectedError: nil, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| tc := tc | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| ctx := context.Background() | ||
| dbTx, err := testState.BeginStateTransaction(ctx) | ||
| require.NoError(t, err) | ||
|
|
||
| err = testState.AddForkIDInterval(ctx, tc.forkIDToAdd, dbTx) | ||
|
|
||
| if tc.expectedError == nil { | ||
| assert.Nil(t, err) | ||
| } else { | ||
| assert.Equal(t, tc.expectedError.Error(), err.Error()) | ||
| } | ||
|
|
||
| require.NoError(t, dbTx.Commit(ctx)) | ||
| }) | ||
| } | ||
| } |
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.
While this fixes "my" problem, I believe that this restriction shouldn't be here. Conceptually, the node is an implementation of the protocol, and the protocol allow to move from ForkID X to Y, where Y < X, and even X == Y.
FYI @invocamanman