Skip to content

Commit

Permalink
improve migrate unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Jul 19, 2024
1 parent d5bfe6f commit d1c0542
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions x/observer/migrations/v8/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"testing"
)

var chainNonces = []types.ChainNonces{
var chainNoncesArray = []types.ChainNonces{
{
Index: chains.BitcoinMainnet.ChainName.String(),
ChainId: chains.BitcoinMainnet.ChainId,
Expand Down Expand Up @@ -70,17 +70,17 @@ func TestMigrateStore(t *testing.T) {
k, ctx, _, _ := keepertest.ObserverKeeper(t)

// set chain nonces
for _, chainNonce := range chainNonces {
for _, chainNonce := range chainNoncesArray {
setChainNoncesLegacy(ctx, *k, chainNonce)
}

// there are 10 chain nonces in the store
chainNonces := k.GetAllChainNonces(ctx)
require.Len(t, chainNonces, 10)
allChainNonces := k.GetAllChainNonces(ctx)
require.Len(t, allChainNonces, 10)

// no chain nonces can be found in the store
for _, chainNonce := range chainNonces {
_, found := k.GetChainNonces(ctx, chainNonce.ChainId)
for _, chainNonces := range allChainNonces {
_, found := k.GetChainNonces(ctx, chainNonces.ChainId)
require.False(t, found)
}

Expand All @@ -89,13 +89,22 @@ func TestMigrateStore(t *testing.T) {
require.NoError(t, err)

// there are 10 chain nonces in the store
chainNonces = k.GetAllChainNonces(ctx)
require.Len(t, chainNonces, 10)
allChainNonces = k.GetAllChainNonces(ctx)
require.Len(t, allChainNonces, 10)

chainIDMap := make(map[int64]bool)

// all chain nonces can be found in the store
for _, chainNonce := range chainNonces {
_, found := k.GetChainNonces(ctx, chainNonce.ChainId)
for _, chainNonces := range allChainNonces {
// chain all chain IDs are different
_, found := chainIDMap[chainNonces.ChainId]
require.False(t, found)
chainIDMap[chainNonces.ChainId] = true

// check value
retrievedChainNonces, found := k.GetChainNonces(ctx, chainNonces.ChainId)
require.True(t, found)
require.Contains(t, chainNoncesArray, retrievedChainNonces)
}
})

Expand Down

0 comments on commit d1c0542

Please sign in to comment.