diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/accountplus/genesis.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/accountplus/genesis.ts index 7d31cd2ac3..00311a9921 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/accountplus/genesis.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/accountplus/genesis.ts @@ -4,13 +4,11 @@ import { DeepPartial } from "../../helpers"; /** Module genesis state */ export interface GenesisState { - /** Module genesis state */ accounts: AccountState[]; } /** Module genesis state */ export interface GenesisStateSDKType { - /** Module genesis state */ accounts: AccountStateSDKType[]; } diff --git a/proto/dydxprotocol/accountplus/accountplus.proto b/proto/dydxprotocol/accountplus/accountplus.proto index 07305b0854..838fa5ab72 100644 --- a/proto/dydxprotocol/accountplus/accountplus.proto +++ b/proto/dydxprotocol/accountplus/accountplus.proto @@ -1,12 +1,15 @@ syntax = "proto3"; package dydxprotocol.accountplus; +import "gogoproto/gogo.proto"; + option go_package = "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types"; // Account State message AccountState { string address = 1; - TimestampNonceDetails timestamp_nonce_details = 2; + TimestampNonceDetails timestamp_nonce_details = 2 + [ (gogoproto.nullable) = false ]; } // Timestamp nonce details diff --git a/proto/dydxprotocol/accountplus/genesis.proto b/proto/dydxprotocol/accountplus/genesis.proto index 0a0129a7f7..9358dca161 100644 --- a/proto/dydxprotocol/accountplus/genesis.proto +++ b/proto/dydxprotocol/accountplus/genesis.proto @@ -1,9 +1,12 @@ syntax = "proto3"; package dydxprotocol.accountplus; +import "gogoproto/gogo.proto"; import "dydxprotocol/accountplus/accountplus.proto"; option go_package = "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types"; // Module genesis state -message GenesisState { repeated AccountState accounts = 1; } +message GenesisState { + repeated AccountState accounts = 1 [ (gogoproto.nullable) = false ]; +} diff --git a/protocol/x/accountplus/genesis.go b/protocol/x/accountplus/genesis.go index 31c81fa546..d84289a0db 100644 --- a/protocol/x/accountplus/genesis.go +++ b/protocol/x/accountplus/genesis.go @@ -14,7 +14,11 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, data types.GenesisState) { } func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + accounts, err := k.GetAllAccountStates(ctx) + if err != nil { + panic(err) + } return &types.GenesisState{ - Accounts: k.GetAllAccountStates(ctx), + Accounts: accounts, } } diff --git a/protocol/x/accountplus/genesis_test.go b/protocol/x/accountplus/genesis_test.go index 5329e7ca73..dc0a82d055 100644 --- a/protocol/x/accountplus/genesis_test.go +++ b/protocol/x/accountplus/genesis_test.go @@ -4,12 +4,9 @@ import ( "math" "testing" - sdk "github.com/cosmos/cosmos-sdk/types" testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" "github.com/dydxprotocol/v4-chain/protocol/x/accountplus" - "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/keeper" - "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/testutils" "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types" "github.com/stretchr/testify/require" ) @@ -20,53 +17,53 @@ func TestImportExportGenesis(t *testing.T) { genesisState *types.GenesisState // The order of this list may not match the order in GenesisState. We want our tests to be deterministic so // order of expectedAccountStates was manually set based on test debug. This ordering should only be changed if - // additional accounts added to genesisState. If a feature breaks the existing ordering, should look into ßwhy. - expectedAccountStates []*types.AccountState + // additional accounts added to genesisState. If a feature breaks the existing ordering, should look into why. + expectedAccountStates []types.AccountState }{ "non-empty genesis": { genesisState: &types.GenesisState{ - Accounts: []*types.AccountState{ + Accounts: []types.AccountState{ { Address: constants.AliceAccAddress.String(), - TimestampNonceDetails: &types.TimestampNonceDetails{ + TimestampNonceDetails: types.TimestampNonceDetails{ TimestampNonces: []uint64{baseTsNonce + 1, baseTsNonce + 2, baseTsNonce + 3}, MaxEjectedNonce: baseTsNonce, }, }, { Address: constants.BobAccAddress.String(), - TimestampNonceDetails: &types.TimestampNonceDetails{ + TimestampNonceDetails: types.TimestampNonceDetails{ TimestampNonces: []uint64{baseTsNonce + 5, baseTsNonce + 6, baseTsNonce + 7}, MaxEjectedNonce: baseTsNonce + 1, }, }, { Address: constants.CarlAccAddress.String(), - TimestampNonceDetails: &types.TimestampNonceDetails{ + TimestampNonceDetails: types.TimestampNonceDetails{ TimestampNonces: []uint64{baseTsNonce + 5, baseTsNonce + 6, baseTsNonce + 7}, MaxEjectedNonce: baseTsNonce + 1, }, }, }, }, - expectedAccountStates: []*types.AccountState{ + expectedAccountStates: []types.AccountState{ { Address: constants.AliceAccAddress.String(), - TimestampNonceDetails: &types.TimestampNonceDetails{ + TimestampNonceDetails: types.TimestampNonceDetails{ TimestampNonces: []uint64{baseTsNonce + 1, baseTsNonce + 2, baseTsNonce + 3}, MaxEjectedNonce: baseTsNonce, }, }, { Address: constants.CarlAccAddress.String(), - TimestampNonceDetails: &types.TimestampNonceDetails{ + TimestampNonceDetails: types.TimestampNonceDetails{ TimestampNonces: []uint64{baseTsNonce + 5, baseTsNonce + 6, baseTsNonce + 7}, MaxEjectedNonce: baseTsNonce + 1, }, }, { Address: constants.BobAccAddress.String(), - TimestampNonceDetails: &types.TimestampNonceDetails{ + TimestampNonceDetails: types.TimestampNonceDetails{ TimestampNonces: []uint64{baseTsNonce + 5, baseTsNonce + 6, baseTsNonce + 7}, MaxEjectedNonce: baseTsNonce + 1, }, @@ -75,9 +72,9 @@ func TestImportExportGenesis(t *testing.T) { }, "empty genesis": { genesisState: &types.GenesisState{ - Accounts: []*types.AccountState{}, + Accounts: []types.AccountState{}, }, - expectedAccountStates: []*types.AccountState{}, + expectedAccountStates: []types.AccountState{}, }, } @@ -87,38 +84,24 @@ func TestImportExportGenesis(t *testing.T) { ctx := tApp.InitChain() k := tApp.App.AccountPlusKeeper - // Initialize genesis state accountplus.InitGenesis(ctx, k, *tc.genesisState) - // Check that keeper state is correct - compareKeeperWithGenesisState(t, ctx, &k, tc.expectedAccountStates) + // Check that keeper accounts states are correct + actualAccountStates, _ := k.GetAllAccountStates(ctx) + require.Equal( + t, + tc.expectedAccountStates, + actualAccountStates, + "Keeper account states do not match Genesis account states", + ) - // Export the genesis state exportedGenesis := accountplus.ExportGenesis(ctx, k) - // Ensure the exported state matches the expected state + // Check that the exported state matches the expected state expectedGenesis := &types.GenesisState{ Accounts: tc.expectedAccountStates, } - requireGenesisStatesEqual(t, exportedGenesis, expectedGenesis) + require.Equal(t, *exportedGenesis, *expectedGenesis) }) } } - -func compareKeeperWithGenesisState( - t *testing.T, - ctx sdk.Context, - k *keeper.Keeper, - expectedAccountStates []*types.AccountState, -) { - // Compare states. Order matters. - isEqual := testutils.CompareAccountStateLists(k.GetAllAccountStates(ctx), expectedAccountStates) - - require.True(t, isEqual, "Keeper account states does not match Genesis account states") -} - -func requireGenesisStatesEqual(t *testing.T, actualGenesisState, expectedGenesisState *types.GenesisState) { - isEqual := testutils.CompareAccountStateLists(actualGenesisState.GetAccounts(), expectedGenesisState.GetAccounts()) - - require.True(t, isEqual, "GenesisState mismatch") -} diff --git a/protocol/x/accountplus/keeper/keeper.go b/protocol/x/accountplus/keeper/keeper.go index 9a42c0f60c..9f3ef67c43 100644 --- a/protocol/x/accountplus/keeper/keeper.go +++ b/protocol/x/accountplus/keeper/keeper.go @@ -11,6 +11,16 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types" ) +func DefaultAccountState(address sdk.AccAddress) types.AccountState { + return types.AccountState{ + Address: address.String(), + TimestampNonceDetails: types.TimestampNonceDetails{ + MaxEjectedNonce: 0, + TimestampNonces: []uint64{}, + }, + } +} + type Keeper struct { cdc codec.BinaryCodec storeKey storetypes.StoreKey @@ -32,61 +42,55 @@ func (k Keeper) InitializeForGenesis(ctx sdk.Context) { } // Get all account details pairs in store -func (k Keeper) GetAllAccountStates(ctx sdk.Context) []*types.AccountState { +func (k Keeper) GetAllAccountStates(ctx sdk.Context) ([]types.AccountState, error) { store := ctx.KVStore(k.storeKey) iterator := storetypes.KVStorePrefixIterator(store, nil) defer iterator.Close() - var accounts []*types.AccountState + accounts := []types.AccountState{} for ; iterator.Valid(); iterator.Next() { - var account types.AccountState - k.cdc.MustUnmarshal(iterator.Value(), &account) - accounts = append(accounts, &account) + accountState, found := k.GetAccountState(ctx, iterator.Key()) + if !found { + return accounts, errors.New("Could not get account state for address: " + sdk.AccAddress(iterator.Key()).String()) + } + accounts = append(accounts, accountState) } - return accounts + return accounts, nil } // Set genesis state func (k Keeper) SetGenesisState(ctx sdk.Context, data types.GenesisState) error { - store := ctx.KVStore(k.storeKey) - for _, account := range data.Accounts { address, err := sdk.AccAddressFromBech32(account.Address) if err != nil { return err } - k.setAccountState(store, address, *account) + k.setAccountState(ctx, address, account) } return nil } -func (k Keeper) InitializeAccount(ctx sdk.Context, address sdk.AccAddress) (types.AccountState, error) { - store := ctx.KVStore(k.storeKey) - - if _, found := k.getAccountState(store, address); found { - return types.AccountState{}, errors.New( +func (k Keeper) InitializeAccount(ctx sdk.Context, address sdk.AccAddress) error { + if _, found := k.GetAccountState(ctx, address); found { + return errors.New( "Cannot initialize AccountState for address with existing AccountState, address: " + address.String(), ) } - initialAccountState := types.AccountState{ - Address: address.String(), - TimestampNonceDetails: DeepCopyTimestampNonceDetails(InitialTimestampNonceDetails), - } - - k.setAccountState(store, address, initialAccountState) + k.setAccountState(ctx, address, DefaultAccountState(address)) - return initialAccountState, nil + return nil } // Get the AccountState from KVStore for a given account address -func (k Keeper) getAccountState( - store storetypes.KVStore, +func (k Keeper) GetAccountState( + ctx sdk.Context, address sdk.AccAddress, ) (types.AccountState, bool) { + store := ctx.KVStore(k.storeKey) bz := store.Get(address.Bytes()) if bz == nil { return types.AccountState{}, false @@ -94,15 +98,22 @@ func (k Keeper) getAccountState( var accountState types.AccountState k.cdc.MustUnmarshal(bz, &accountState) + + // By default empty slices are Unmarshed into nil + if accountState.TimestampNonceDetails.TimestampNonces == nil { + accountState.TimestampNonceDetails.TimestampNonces = make([]uint64, 0) + } + return accountState, true } // Set the AccountState into KVStore for a given account address func (k Keeper) setAccountState( - store storetypes.KVStore, + ctx sdk.Context, address sdk.AccAddress, accountState types.AccountState, ) { + store := ctx.KVStore(k.storeKey) bz := k.cdc.MustMarshal(&accountState) store.Set(address.Bytes(), bz) } diff --git a/protocol/x/accountplus/keeper/keeper_test.go b/protocol/x/accountplus/keeper/keeper_test.go index d9c1c1fd2f..0d0b01b6f4 100644 --- a/protocol/x/accountplus/keeper/keeper_test.go +++ b/protocol/x/accountplus/keeper/keeper_test.go @@ -10,24 +10,23 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" "github.com/dydxprotocol/v4-chain/protocol/x/accountplus" "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/keeper" - "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/testutils" "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types" ) func TestInitializeAccount(t *testing.T) { baseTsNonce := uint64(math.Pow(2, 40)) genesisState := &types.GenesisState{ - Accounts: []*types.AccountState{ + Accounts: []types.AccountState{ { Address: constants.AliceAccAddress.String(), - TimestampNonceDetails: &types.TimestampNonceDetails{ + TimestampNonceDetails: types.TimestampNonceDetails{ TimestampNonces: []uint64{baseTsNonce + 1, baseTsNonce + 2, baseTsNonce + 3}, MaxEjectedNonce: baseTsNonce, }, }, { Address: constants.BobAccAddress.String(), - TimestampNonceDetails: &types.TimestampNonceDetails{ + TimestampNonceDetails: types.TimestampNonceDetails{ TimestampNonces: []uint64{baseTsNonce + 5, baseTsNonce + 6, baseTsNonce + 7}, MaxEjectedNonce: baseTsNonce + 1, }, @@ -38,7 +37,7 @@ func TestInitializeAccount(t *testing.T) { t.Run("Cannot initialize existing account", func(t *testing.T) { ctx, k, _, _ := keepertest.TimestampNonceKeepers(t) accountplus.InitGenesis(ctx, *k, *genesisState) - _, err := k.InitializeAccount(ctx, constants.AliceAccAddress) + err := k.InitializeAccount(ctx, constants.AliceAccAddress) require.NotNil(t, err, "Account should not be able to be initialized if already exists") }) @@ -46,15 +45,13 @@ func TestInitializeAccount(t *testing.T) { ctx, k, _, _ := keepertest.TimestampNonceKeepers(t) accountplus.InitGenesis(ctx, *k, *genesisState) - expectedAccount := types.AccountState{ - Address: constants.CarlAccAddress.String(), - TimestampNonceDetails: keeper.DeepCopyTimestampNonceDetails(keeper.InitialTimestampNonceDetails), - } + expectedAccount := keeper.DefaultAccountState(constants.CarlAccAddress) - account, err := k.InitializeAccount(ctx, constants.CarlAccAddress) + err := k.InitializeAccount(ctx, constants.CarlAccAddress) require.Nil(t, err, "Should be able to initialize account if it did not exist") - isAccountEqual := testutils.CompareAccountStates(&account, &expectedAccount) - require.True(t, isAccountEqual, "Initialized account does not have correct initial state") + actualAccount, found := k.GetAccountState(ctx, constants.CarlAccAddress) + require.True(t, found, "Could not find account") + require.Equal(t, actualAccount, expectedAccount) }) } diff --git a/protocol/x/accountplus/keeper/timestampnonce.go b/protocol/x/accountplus/keeper/timestampnonce.go index 7210cd893d..957b854096 100644 --- a/protocol/x/accountplus/keeper/timestampnonce.go +++ b/protocol/x/accountplus/keeper/timestampnonce.go @@ -1,26 +1,3 @@ package keeper -import ( - "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types" -) - -var InitialTimestampNonceDetails = &types.TimestampNonceDetails{ - MaxEjectedNonce: 0, - TimestampNonces: []uint64{}, -} - -func DeepCopyTimestampNonceDetails(details *types.TimestampNonceDetails) *types.TimestampNonceDetails { - if details == nil { - return nil - } - - copyDetails := &types.TimestampNonceDetails{ - MaxEjectedNonce: details.MaxEjectedNonce, - TimestampNonces: make([]uint64, len(details.TimestampNonces)), - } - - // Copy the slice elements - copy(copyDetails.TimestampNonces, details.TimestampNonces) - - return copyDetails -} +func Placeholder() {} diff --git a/protocol/x/accountplus/keeper/timestampnonce_test.go b/protocol/x/accountplus/keeper/timestampnonce_test.go index e1f22f8051..e2d6fabe21 100644 --- a/protocol/x/accountplus/keeper/timestampnonce_test.go +++ b/protocol/x/accountplus/keeper/timestampnonce_test.go @@ -2,23 +2,6 @@ package keeper_test import ( "testing" - - "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/keeper" - "github.com/google/go-cmp/cmp" - "github.com/stretchr/testify/require" ) -func TestDeepCopyTimestampNonceDetails(t *testing.T) { - details := keeper.InitialTimestampNonceDetails - detailsCopy := keeper.DeepCopyTimestampNonceDetails(details) - - detailsCopy.MaxEjectedNonce = details.MaxEjectedNonce + 1 - detailsCopy.TimestampNonces = append(detailsCopy.TimestampNonces, []uint64{1, 2, 3}...) - - require.NotEqual(t, details.MaxEjectedNonce, detailsCopy.MaxEjectedNonce) - require.False( - t, - cmp.Equal(details.GetTimestampNonces(), detailsCopy.GetTimestampNonces()), - "TimestampNonces not deepcopy", - ) -} +func Placeholder(t *testing.T) {} diff --git a/protocol/x/accountplus/testutils/testutils.go b/protocol/x/accountplus/testutils/testutils.go deleted file mode 100644 index 768757df55..0000000000 --- a/protocol/x/accountplus/testutils/testutils.go +++ /dev/null @@ -1,52 +0,0 @@ -package testutils - -import ( - "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types" - "github.com/google/go-cmp/cmp" -) - -func CompareTimestampNonceDetails(actualDetails, expectedDetails *types.TimestampNonceDetails) bool { - if !cmp.Equal( - actualDetails.GetTimestampNonces(), - expectedDetails.GetTimestampNonces(), - ) { - return false - } - - if actualDetails.GetMaxEjectedNonce() != expectedDetails.GetMaxEjectedNonce() { - return false - } - - return true -} - -func CompareAccountStates(actualAccountstate, expectedAccountState *types.AccountState) bool { - if actualAccountstate.GetAddress() != expectedAccountState.GetAddress() { - return false - } - - if tsNonceDetailsEqual := CompareTimestampNonceDetails( - actualAccountstate.GetTimestampNonceDetails(), - expectedAccountState.GetTimestampNonceDetails(), - ); !tsNonceDetailsEqual { - return false - } - - return true -} - -func CompareAccountStateLists(actualAccountStates, expectedAccountStates []*types.AccountState) bool { - if len(actualAccountStates) != len(expectedAccountStates) { - return false - } - - // We require that the ordering of accountState be deterministic (no sorting) so that should more - // complicated logic be introduced in the future, this test can catch any unintended effects. - for i := range actualAccountStates { - if !CompareAccountStates(actualAccountStates[i], expectedAccountStates[i]) { - return false - } - } - - return true -} diff --git a/protocol/x/accountplus/testutils/testutils_test.go b/protocol/x/accountplus/testutils/testutils_test.go deleted file mode 100644 index fce6cc7690..0000000000 --- a/protocol/x/accountplus/testutils/testutils_test.go +++ /dev/null @@ -1,143 +0,0 @@ -package testutils_test - -import ( - "math" - "testing" - - "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" - "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/testutils" - "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types" - "github.com/stretchr/testify/require" -) - -var baseTsNonce = uint64(math.Pow(2, 40)) - -func TestCompareTimestampNonceDetails(t *testing.T) { - detail1 := &types.TimestampNonceDetails{ - TimestampNonces: []uint64{baseTsNonce + 1, baseTsNonce + 2, baseTsNonce + 3}, - MaxEjectedNonce: baseTsNonce, - } - - detail2 := &types.TimestampNonceDetails{ - TimestampNonces: []uint64{baseTsNonce + 2, baseTsNonce + 3, baseTsNonce + 3}, - MaxEjectedNonce: baseTsNonce, - } - - detail3 := &types.TimestampNonceDetails{ - TimestampNonces: []uint64{baseTsNonce + 1, baseTsNonce + 2, baseTsNonce + 3}, - MaxEjectedNonce: baseTsNonce + 1, - } - - detail4 := &types.TimestampNonceDetails{ - TimestampNonces: []uint64{baseTsNonce + 2, baseTsNonce + 2, baseTsNonce + 3}, - MaxEjectedNonce: baseTsNonce + 1, - } - - emptyDetail := &types.TimestampNonceDetails{} - - var isEqual bool - - // Same detail - isEqual = testutils.CompareTimestampNonceDetails(detail1, detail1) - require.True(t, isEqual, "Details are equal but comparison returned false") - - // Different TimestampNonces - isEqual = testutils.CompareTimestampNonceDetails(detail1, detail2) - require.False(t, isEqual, "TimmestampNonces are different but comparison returned true") - - // Different MaxEjectedNonce - isEqual = testutils.CompareTimestampNonceDetails(detail1, detail3) - require.False(t, isEqual, "MaxEjectedNonce are different but comparison returned true") - - // Different TimestampNonces and MaxEjectedNonce - isEqual = testutils.CompareTimestampNonceDetails(detail1, detail4) - require.False(t, isEqual, "TimestampNonces and MaxEjectedNonce are different but comparison returned true") - - // Empty detail - isEqual = testutils.CompareTimestampNonceDetails(detail1, emptyDetail) - require.False(t, isEqual, "TimestampNonces and MaxEjectedNonce are different but comparison returned true") -} - -func TestCompareAccountStates(t *testing.T) { - accStateReference := &types.AccountState{ - Address: constants.AliceAccAddress.String(), - TimestampNonceDetails: &types.TimestampNonceDetails{ - TimestampNonces: []uint64{baseTsNonce + 1, baseTsNonce + 2, baseTsNonce + 3}, - MaxEjectedNonce: baseTsNonce, - }, - } - - accStateDiffAddress := &types.AccountState{ - Address: constants.BobAccAddress.String(), - TimestampNonceDetails: &types.TimestampNonceDetails{ - TimestampNonces: []uint64{baseTsNonce + 1, baseTsNonce + 2, baseTsNonce + 3}, - MaxEjectedNonce: baseTsNonce, - }, - } - - accStateDiffTimestampNonceDetails := &types.AccountState{ - Address: constants.AliceAccAddress.String(), - TimestampNonceDetails: &types.TimestampNonceDetails{ - TimestampNonces: []uint64{baseTsNonce + 3, baseTsNonce + 2, baseTsNonce + 3}, - MaxEjectedNonce: baseTsNonce, - }, - } - - var isEqual bool - - // Same AccountState - isEqual = testutils.CompareAccountStates(accStateReference, accStateReference) - require.True(t, isEqual, "AccountStates are equal but comparison returned false") - - // Different address - isEqual = testutils.CompareAccountStates(accStateReference, accStateDiffAddress) - require.False(t, isEqual, "AccountStates have different address but comparison returned true") - - // Different TimestampNonceDetails - isEqual = testutils.CompareAccountStates(accStateReference, accStateDiffTimestampNonceDetails) - require.False(t, isEqual, "AccountStates have different TimestampNonceDetails but comparison returned true") -} - -func TestCompareAccoutStateLists(t *testing.T) { - accountStates := []*types.AccountState{ - { - Address: constants.AliceAccAddress.String(), - TimestampNonceDetails: &types.TimestampNonceDetails{ - TimestampNonces: []uint64{baseTsNonce + 1, baseTsNonce + 2, baseTsNonce + 3}, - MaxEjectedNonce: baseTsNonce, - }, - }, - { - Address: constants.BobAccAddress.String(), - TimestampNonceDetails: &types.TimestampNonceDetails{ - TimestampNonces: []uint64{baseTsNonce + 5, baseTsNonce + 6, baseTsNonce + 7}, - MaxEjectedNonce: baseTsNonce + 1, - }, - }, - } - - accountStatesDifferent := []*types.AccountState{ - { - Address: constants.AliceAccAddress.String(), - TimestampNonceDetails: &types.TimestampNonceDetails{ - TimestampNonces: []uint64{baseTsNonce + 2, baseTsNonce + 2, baseTsNonce + 3}, - MaxEjectedNonce: baseTsNonce, - }, - }, - { - Address: constants.BobAccAddress.String(), - TimestampNonceDetails: &types.TimestampNonceDetails{ - TimestampNonces: []uint64{baseTsNonce + 5, baseTsNonce + 6, baseTsNonce + 7}, - MaxEjectedNonce: baseTsNonce + 1, - }, - }, - } - - var isEqual bool - - isEqual = testutils.CompareAccountStateLists(accountStates, accountStates) - require.True(t, isEqual, "AccountState lists are different but comparison returned false") - - isEqual = testutils.CompareAccountStateLists(accountStates, accountStatesDifferent) - require.False(t, isEqual, "AccountState lists are different but comparison returned true") -} diff --git a/protocol/x/accountplus/types/accountplus.pb.go b/protocol/x/accountplus/types/accountplus.pb.go index fcb6dcf482..7ebb29da1d 100644 --- a/protocol/x/accountplus/types/accountplus.pb.go +++ b/protocol/x/accountplus/types/accountplus.pb.go @@ -5,6 +5,7 @@ package types import ( fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" io "io" math "math" @@ -24,8 +25,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Account State type AccountState struct { - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` - TimestampNonceDetails *TimestampNonceDetails `protobuf:"bytes,2,opt,name=timestamp_nonce_details,json=timestampNonceDetails,proto3" json:"timestamp_nonce_details,omitempty"` + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + TimestampNonceDetails TimestampNonceDetails `protobuf:"bytes,2,opt,name=timestamp_nonce_details,json=timestampNonceDetails,proto3" json:"timestamp_nonce_details"` } func (m *AccountState) Reset() { *m = AccountState{} } @@ -68,11 +69,11 @@ func (m *AccountState) GetAddress() string { return "" } -func (m *AccountState) GetTimestampNonceDetails() *TimestampNonceDetails { +func (m *AccountState) GetTimestampNonceDetails() TimestampNonceDetails { if m != nil { return m.TimestampNonceDetails } - return nil + return TimestampNonceDetails{} } // Timestamp nonce details @@ -140,24 +141,25 @@ func init() { } var fileDescriptor_391b06af1cfe6fb0 = []byte{ - // 269 bytes of a gzipped FileDescriptorProto + // 288 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x4a, 0xa9, 0x4c, 0xa9, 0x28, 0x28, 0xca, 0x2f, 0xc9, 0x4f, 0xce, 0xcf, 0xd1, 0x4f, 0x4c, 0x4e, 0xce, 0x2f, 0xcd, 0x2b, 0x29, 0xc8, 0x29, 0x2d, 0x46, 0x66, 0xeb, 0x81, 0x15, 0x08, 0x49, 0x20, 0xab, 0xd5, 0x43, 0x92, - 0x57, 0x9a, 0xc8, 0xc8, 0xc5, 0xe3, 0x08, 0xe1, 0x07, 0x97, 0x24, 0x96, 0xa4, 0x0a, 0x49, 0x70, - 0xb1, 0x27, 0xa6, 0xa4, 0x14, 0xa5, 0x16, 0x17, 0x4b, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0xc1, - 0xb8, 0x42, 0xe9, 0x5c, 0xe2, 0x25, 0x99, 0xb9, 0xa9, 0xc5, 0x25, 0x89, 0xb9, 0x05, 0xf1, 0x79, - 0xf9, 0x79, 0xc9, 0xa9, 0xf1, 0x29, 0xa9, 0x25, 0x89, 0x99, 0x39, 0xc5, 0x12, 0x4c, 0x0a, 0x8c, - 0x1a, 0xdc, 0x46, 0xfa, 0x7a, 0xb8, 0xac, 0xd1, 0x0b, 0x81, 0x69, 0xf4, 0x03, 0xe9, 0x73, 0x81, - 0x68, 0x0b, 0x12, 0x2d, 0xc1, 0x26, 0xac, 0x94, 0xc7, 0x25, 0x8a, 0x55, 0xbd, 0x90, 0x26, 0x97, - 0x00, 0x9a, 0x0b, 0x40, 0x8e, 0x64, 0xd6, 0x60, 0x09, 0xe2, 0x47, 0x35, 0xa9, 0x58, 0x48, 0x8b, - 0x4b, 0x30, 0x37, 0xb1, 0x22, 0x3e, 0x35, 0x2b, 0x35, 0xb9, 0x24, 0x35, 0x05, 0xa2, 0x18, 0xec, - 0x4c, 0x96, 0x20, 0xfe, 0xdc, 0xc4, 0x0a, 0x57, 0x88, 0x38, 0x58, 0xb1, 0x53, 0xf8, 0x89, 0x47, - 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, - 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0xd9, 0xa6, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, - 0x25, 0xe7, 0xe7, 0xea, 0xa3, 0x04, 0x77, 0x99, 0x89, 0x6e, 0x72, 0x46, 0x62, 0x66, 0x9e, 0x3e, - 0x5c, 0xa4, 0x02, 0x25, 0x0a, 0x4a, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0xb2, 0xc6, 0x80, - 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x61, 0x2f, 0x18, 0xab, 0x01, 0x00, 0x00, + 0x97, 0x12, 0x49,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88, 0xb2, 0x4d, 0xcf, 0x2c, 0xc9, + 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x47, 0x89, 0x8a, 0x32, 0x13, 0xdd, 0xe4, 0x8c, 0xc4, + 0xcc, 0x3c, 0x7d, 0xb8, 0x48, 0x05, 0x4a, 0xf4, 0x94, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, + 0x65, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xed, 0x5d, 0xef, 0x80, 0xc7, 0x01, 0x00, 0x00, } func (m *AccountState) Marshal() (dAtA []byte, err error) { @@ -180,18 +182,16 @@ func (m *AccountState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.TimestampNonceDetails != nil { - { - size, err := m.TimestampNonceDetails.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintAccountplus(dAtA, i, uint64(size)) + { + size, err := m.TimestampNonceDetails.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0x12 + i -= size + i = encodeVarintAccountplus(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x12 if len(m.Address) > 0 { i -= len(m.Address) copy(dAtA[i:], m.Address) @@ -269,10 +269,8 @@ func (m *AccountState) Size() (n int) { if l > 0 { n += 1 + l + sovAccountplus(uint64(l)) } - if m.TimestampNonceDetails != nil { - l = m.TimestampNonceDetails.Size() - n += 1 + l + sovAccountplus(uint64(l)) - } + l = m.TimestampNonceDetails.Size() + n += 1 + l + sovAccountplus(uint64(l)) return n } @@ -391,9 +389,6 @@ func (m *AccountState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.TimestampNonceDetails == nil { - m.TimestampNonceDetails = &TimestampNonceDetails{} - } if err := m.TimestampNonceDetails.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/protocol/x/accountplus/types/genesis.pb.go b/protocol/x/accountplus/types/genesis.pb.go index 5945a650a9..13a13d224e 100644 --- a/protocol/x/accountplus/types/genesis.pb.go +++ b/protocol/x/accountplus/types/genesis.pb.go @@ -5,6 +5,7 @@ package types import ( fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" io "io" math "math" @@ -24,7 +25,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Module genesis state type GenesisState struct { - Accounts []*AccountState `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts,omitempty"` + Accounts []AccountState `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -60,7 +61,7 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo -func (m *GenesisState) GetAccounts() []*AccountState { +func (m *GenesisState) GetAccounts() []AccountState { if m != nil { return m.Accounts } @@ -76,19 +77,20 @@ func init() { } var fileDescriptor_03516b8fa43b3a59 = []byte{ - // 183 bytes of a gzipped FileDescriptorProto + // 202 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4b, 0xa9, 0x4c, 0xa9, 0x28, 0x28, 0xca, 0x2f, 0xc9, 0x4f, 0xce, 0xcf, 0xd1, 0x4f, 0x4c, 0x4e, 0xce, 0x2f, 0xcd, 0x2b, 0x29, 0xc8, 0x29, 0x2d, 0xd6, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x03, 0x4b, 0x0a, - 0x49, 0x20, 0xab, 0xd3, 0x43, 0x52, 0x27, 0xa5, 0x85, 0xd3, 0x04, 0x24, 0x36, 0xc4, 0x14, 0xa5, - 0x20, 0x2e, 0x1e, 0x77, 0x88, 0xb1, 0xc1, 0x25, 0x89, 0x25, 0xa9, 0x42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8f, 0xe4, 0x18, 0x2f, + 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, + 0x6e, 0x3c, 0x96, 0x63, 0x88, 0xb2, 0x4d, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, + 0xd5, 0x47, 0x71, 0x6a, 0x99, 0x89, 0x6e, 0x72, 0x46, 0x62, 0x66, 0x9e, 0x3e, 0x5c, 0xa4, 0x02, + 0xc5, 0xf9, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0x60, 0x59, 0x63, 0x40, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xfa, 0x84, 0x6b, 0x24, 0x3f, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -218,7 +220,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Accounts = append(m.Accounts, &AccountState{}) + m.Accounts = append(m.Accounts, AccountState{}) if err := m.Accounts[len(m.Accounts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err }