-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: get revision for height instead of the latest (#1249)
- Loading branch information
Showing
3 changed files
with
127 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 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 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,105 @@ | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/dymensionxyz/dymint/types" | ||
) | ||
|
||
func TestGetRevisionForHeight(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
rollapp types.Rollapp | ||
height uint64 | ||
expected types.Revision | ||
}{ | ||
{ | ||
name: "no revisions", | ||
rollapp: types.Rollapp{ | ||
RollappID: "test", | ||
Revisions: []types.Revision{}, | ||
}, | ||
height: 100, | ||
expected: types.Revision{}, | ||
}, | ||
{ | ||
name: "single revision, height matches", | ||
rollapp: types.Rollapp{ | ||
RollappID: "test", | ||
Revisions: []types.Revision{ | ||
{Number: 1, StartHeight: 50}, | ||
}, | ||
}, | ||
height: 50, | ||
expected: types.Revision{Number: 1, StartHeight: 50}, | ||
}, | ||
{ | ||
name: "single revision, height does not match", | ||
rollapp: types.Rollapp{ | ||
RollappID: "test", | ||
Revisions: []types.Revision{ | ||
{Number: 1, StartHeight: 50}, | ||
}, | ||
}, | ||
height: 49, | ||
expected: types.Revision{}, | ||
}, | ||
{ | ||
name: "multiple revisions, height matches first", | ||
rollapp: types.Rollapp{ | ||
RollappID: "test", | ||
Revisions: []types.Revision{ | ||
{Number: 1, StartHeight: 50}, | ||
{Number: 2, StartHeight: 100}, | ||
}, | ||
}, | ||
height: 50, | ||
expected: types.Revision{Number: 1, StartHeight: 50}, | ||
}, | ||
{ | ||
name: "multiple revisions, height matches second", | ||
rollapp: types.Rollapp{ | ||
RollappID: "test", | ||
Revisions: []types.Revision{ | ||
{Number: 1, StartHeight: 50}, | ||
{Number: 2, StartHeight: 100}, | ||
}, | ||
}, | ||
height: 100, | ||
expected: types.Revision{Number: 2, StartHeight: 100}, | ||
}, | ||
{ | ||
name: "multiple revisions, height between revisions", | ||
rollapp: types.Rollapp{ | ||
RollappID: "test", | ||
Revisions: []types.Revision{ | ||
{Number: 1, StartHeight: 50}, | ||
{Number: 2, StartHeight: 100}, | ||
}, | ||
}, | ||
height: 75, | ||
expected: types.Revision{Number: 1, StartHeight: 50}, | ||
}, | ||
{ | ||
name: "multiple revisions, height after last revision", | ||
rollapp: types.Rollapp{ | ||
RollappID: "test", | ||
Revisions: []types.Revision{ | ||
{Number: 1, StartHeight: 50}, | ||
{Number: 2, StartHeight: 100}, | ||
}, | ||
}, | ||
height: 150, | ||
expected: types.Revision{Number: 2, StartHeight: 100}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := tt.rollapp.GetRevisionForHeight(tt.height) | ||
require.Equal(t, tt.expected, result) | ||
}) | ||
} | ||
} |