fix (x/accounts): Fix genesis condition check (#20645)

This commit is contained in:
son trinh 2024-06-12 23:25:02 +07:00 committed by GitHub
parent 40492cdf10
commit abeb7eee3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View File

@ -74,7 +74,7 @@ func (k Keeper) ImportState(ctx context.Context, genState *v1.GenesisState) erro
// we set the latest account number only if there were any genesis accounts, otherwise
// we leave it unset.
if genState.Accounts != nil {
if len(genState.Accounts) != 0 {
// due to sequence semantics, we store the next account number.
err = k.AccountNumber.Set(ctx, lastAccountNumber+1)
if err != nil {

View File

@ -84,6 +84,23 @@ func TestGenesis(t *testing.T) {
// AccountNumber should be set to the highest account number in the genesis state + 2
// (one is the sequence offset, the other is the genesis account being added through init msg)
require.Equal(t, state.Accounts[0].AccountNumber+2, currentAccNum)
// Test when init with empty accounts list, account number is not modified
// make genesis state accounts empty
state.Accounts = []*v1.GenesisAccount{}
// set another value for account number
err = k.AccountNumber.Set(ctx, uint64(10))
require.NoError(t, err)
err = k.ImportState(ctx, state)
require.NoError(t, err)
currentAccNum, err = k.AccountNumber.Peek(ctx)
require.NoError(t, err)
// AccountNumber should be 10 + 1
// (one is the genesis account being added through init msg)
require.Equal(t, uint64(11), currentAccNum)
}
func TestImportAccountError(t *testing.T) {