-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
610ef6f
commit 7388cbd
Showing
2 changed files
with
64 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package simapp | ||
|
||
import ( | ||
"testing" | ||
|
||
"cosmossdk.io/collections" | ||
authtypes "cosmossdk.io/x/auth/types" | ||
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestSyncAccountNumber tests if accounts module account number is set correctly with the value get from auth. | ||
// Also check if the store entry for auth GlobalAccountNumberKey is successfully deleted. | ||
func TestSyncAccountNumber(t *testing.T) { | ||
app := Setup(t, true) | ||
ctx := app.NewUncachedContext(true, cmtproto.Header{}) | ||
|
||
bytesKey := authtypes.GlobalAccountNumberKey | ||
store := app.AuthKeeper.KVStoreService.OpenKVStore(ctx) | ||
|
||
// initially there is no value set yet | ||
v, err := store.Get(bytesKey) | ||
require.NoError(t, err) | ||
require.Nil(t, v) | ||
|
||
// set value for legacy account number | ||
v, err = collections.Uint64Value.Encode(10) | ||
require.NoError(t, err) | ||
err = store.Set(bytesKey, v) | ||
require.NoError(t, err) | ||
|
||
// make sure value are updated | ||
v, err = store.Get(bytesKey) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, v) | ||
num, err := collections.Uint64Value.Decode(v) | ||
require.NoError(t, err) | ||
require.Equal(t, uint64(10), num) | ||
|
||
app.syncAccoutnNumber(ctx) | ||
|
||
// make sure the DB entry for this key is deleted | ||
v, err = store.Get(bytesKey) | ||
require.NoError(t, err) | ||
require.Nil(t, v) | ||
|
||
// check if accounts's account number is updated | ||
currentNum, err := app.AccountsKeeper.AccountNumber.Peek(ctx) | ||
require.NoError(t, err) | ||
require.Equal(t, uint64(10), currentNum) | ||
} |