Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
babadro committed Apr 8, 2023
1 parent d6f0053 commit c313538
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
8 changes: 2 additions & 6 deletions x/staking/migrations/v5/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package v5_test
import (
"math"
"math/rand"
"strconv"
"testing"
"time"

storetypes "cosmossdk.io/store/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/testutil"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
v1 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v1"
v5 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v5"
stackingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -44,7 +44,7 @@ func TestHistoricalKeysMigration(t *testing.T) {
cdc := moduletestutil.MakeTestEncodingConfig().Codec
for height := range testCases {
testCases[height] = testCase{
oldKey: getOldHistoricalInfoKey(height),
oldKey: v1.GetHistoricalInfoKey(height),
newKey: stackingtypes.GetHistoricalInfoKey(height),
historicalInfo: cdc.MustMarshal(createHistoricalInfo(height, "testChainID")),
}
Expand All @@ -66,10 +66,6 @@ func TestHistoricalKeysMigration(t *testing.T) {
}
}

func getOldHistoricalInfoKey(height int64) []byte {
return append(stackingtypes.HistoricalInfoKey, []byte(strconv.FormatInt(height, 10))...)
}

func createHistoricalInfo(height int64, chainID string) *stackingtypes.HistoricalInfo {
return &stackingtypes.HistoricalInfo{Header: cmtproto.Header{ChainID: chainID, Height: height}}
}
21 changes: 11 additions & 10 deletions x/staking/types/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package types_test
import (
"bytes"
"encoding/hex"
math2 "math"
"math/big"
"strconv"
"testing"
"time"

"cosmossdk.io/math"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
Expand Down Expand Up @@ -132,19 +133,19 @@ func TestTestGetValidatorQueueKeyOrder(t *testing.T) {
}

func TestGetHistoricalInfoKey(t *testing.T) {
type args struct {
height int64
}
tests := []struct {
name string
args args
want []byte
height int64
want []byte
}{
// TODO: Add test cases.
{0, append(types.HistoricalInfoKey, []byte{0, 0, 0, 0, 0, 0, 0, 0}...)},
{1, append(types.HistoricalInfoKey, []byte{0, 0, 0, 0, 0, 0, 0, 1}...)},
{2, append(types.HistoricalInfoKey, []byte{0, 0, 0, 0, 0, 0, 0, 2}...)},
{514, append(types.HistoricalInfoKey, []byte{0, 0, 0, 0, 0, 0, 2, 2}...)},
{math2.MaxInt64, append(types.HistoricalInfoKey, []byte{127, 255, 255, 255, 255, 255, 255, 255}...)},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, types.GetHistoricalInfoKey(tt.args.height), "GetHistoricalInfoKey(%v)", tt.args.height)
t.Run(strconv.FormatInt(tt.height, 10), func(t *testing.T) {
require.Equal(t, tt.want, types.GetHistoricalInfoKey(tt.height))
})
}
}

0 comments on commit c313538

Please sign in to comment.