diff --git a/app/test_helpers.go b/app/test_helpers.go index c9541181..d87aae1a 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -109,6 +109,8 @@ func Setup( panic(err) } genesisState[feemarkettypes.ModuleName] = app.AppCodec().MustMarshalJSON(feemarketGenesis) + } else { + genesisState[feemarkettypes.ModuleName] = app.AppCodec().MustMarshalJSON(feemarkettypes.DefaultGenesisState()) } stateBytes, err := json.MarshalIndent(genesisState, "", " ") diff --git a/x/asset/keeper/keeper.go b/x/asset/keeper/keeper.go index 53a86e13..222b6e2e 100644 --- a/x/asset/keeper/keeper.go +++ b/x/asset/keeper/keeper.go @@ -15,13 +15,13 @@ import ( type ( Keeper struct { - cdc codec.BinaryCodec - storeKey storetypes.StoreKey - memKey storetypes.StoreKey - paramstore paramtypes.Subspace - bankKeeper types.BankKeeper - ak types.AccountKeeper - PrivilegesMap map[string]types.PrivilegeI + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + memKey storetypes.StoreKey + paramstore paramtypes.Subspace + bankKeeper types.BankKeeper + ak types.AccountKeeper + PrivilegeManager map[string]types.PrivilegeI } ) @@ -35,33 +35,32 @@ func NewKeeper( ps paramtypes.Subspace, bankKeeper types.BankKeeper, ak types.AccountKeeper, - privileges ...types.PrivilegeI, ) *Keeper { // set KeyTable if it has not already been set if !ps.HasKeyTable() { ps = ps.WithKeyTable(types.ParamKeyTable()) } - privilegesMap := map[string]types.PrivilegeI{} - for _, priv := range privileges { - if _, ok := privilegesMap[priv.Name()]; ok { - continue - } - - privilegesMap[priv.Name()] = priv - // regiester the privilege's interfaces - priv.RegisterInterfaces() + return &Keeper{ + cdc: cdc, + storeKey: storeKey, + memKey: memKey, + paramstore: ps, + bankKeeper: bankKeeper, + ak: ak, + PrivilegeManager: map[string]types.PrivilegeI{}, } +} - return &Keeper{ - cdc: cdc, - storeKey: storeKey, - memKey: memKey, - paramstore: ps, - bankKeeper: bankKeeper, - ak: ak, - PrivilegesMap: privilegesMap, +func (k Keeper) AddPrivilege(priv types.PrivilegeI) error { + if _, ok := k.PrivilegeManager[priv.Name()]; ok { + return fmt.Errorf("privilege %s already exists", priv.Name()) } + + k.PrivilegeManager[priv.Name()] = priv + // regiester the privilege's interfaces + priv.RegisterInterfaces() + return nil } func (k Keeper) Logger(ctx sdk.Context) log.Logger { diff --git a/x/asset/keeper/keeper_test.go b/x/asset/keeper/keeper_test.go index 34364f76..51c473de 100644 --- a/x/asset/keeper/keeper_test.go +++ b/x/asset/keeper/keeper_test.go @@ -2,94 +2,35 @@ package keeper_test import ( "testing" - "time" - "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/evmos/ethermint/crypto/ethsecp256k1" - "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/tendermint/tendermint/crypto/tmhash" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" - "github.com/tendermint/tendermint/version" + govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" "github.com/realiotech/realio-network/app" - realiotypes "github.com/realiotech/realio-network/types" + "github.com/realiotech/realio-network/x/asset/keeper" "github.com/realiotech/realio-network/x/asset/types" - - "github.com/realiotech/realio-network/testutil" ) type KeeperTestSuite struct { suite.Suite - app *app.RealioNetwork - ctx sdk.Context - queryClient types.QueryClient - testUser1Acc sdk.AccAddress - testUser1Address string - testUser2Acc sdk.AccAddress - testUser2Address string - testUser3Acc sdk.AccAddress - testUser3Address string -} + app *app.RealioNetwork + ctx sdk.Context -func (suite *KeeperTestSuite) SetupTest() { - suite.DoSetupTest(suite.T()) + assetKeeper *keeper.Keeper + govkeeper govkeeper.Keeper + msgServer types.MsgServer } -func (suite *KeeperTestSuite) DoSetupTest(t *testing.T) { - checkTx := false - - // user 1 key - suite.testUser1Acc = testutil.GenAddress() - suite.testUser1Address = suite.testUser1Acc.String() - - // user 2 key - suite.testUser2Acc = testutil.GenAddress() - suite.testUser2Address = suite.testUser2Acc.String() - - // user 3 key - suite.testUser3Acc = testutil.GenAddress() - suite.testUser3Address = suite.testUser3Acc.String() - - // consensus key - priv, err := ethsecp256k1.GenerateKey() - require.NoError(t, err) - consAddress := sdk.ConsAddress(priv.PubKey().Address()) - - // init app - suite.app = app.Setup(checkTx, nil, 1) - - // Set Context - suite.ctx = suite.app.BaseApp.NewContext(checkTx, tmproto.Header{ - Height: 1, - ChainID: realiotypes.TestnetChainID, - Time: time.Now().UTC(), - ProposerAddress: consAddress.Bytes(), - - Version: tmversion.Consensus{ - Block: version.BlockProtocol, - }, - LastBlockId: tmproto.BlockID{ - Hash: tmhash.Sum([]byte("block_id")), - PartSetHeader: tmproto.PartSetHeader{ - Total: 11, - Hash: tmhash.Sum([]byte("partset_header")), - }, - }, - AppHash: tmhash.Sum([]byte("app")), - DataHash: tmhash.Sum([]byte("data")), - EvidenceHash: tmhash.Sum([]byte("evidence")), - ValidatorsHash: tmhash.Sum([]byte("validators")), - NextValidatorsHash: tmhash.Sum([]byte("next_validators")), - ConsensusHash: tmhash.Sum([]byte("consensus")), - LastResultsHash: tmhash.Sum([]byte("last_result")), - }) +func (suite *KeeperTestSuite) SetupTest() { + app := app.Setup(false, nil, 3) - queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry()) - types.RegisterQueryServer(queryHelper, suite.app.AssetKeeper) - suite.queryClient = types.NewQueryClient(queryHelper) + suite.app = app + suite.ctx = app.BaseApp.NewContext(false, tmproto.Header{Height: app.LastBlockHeight() + 1}) + suite.assetKeeper = &app.AssetKeeper + suite.govkeeper = app.GovKeeper + suite.msgServer = keeper.NewMsgServerImpl(app.AssetKeeper) } func TestKeeperTestSuite(t *testing.T) { diff --git a/x/asset/keeper/msg_server.go b/x/asset/keeper/msg_server.go index 712d0ff9..b580eb20 100644 --- a/x/asset/keeper/msg_server.go +++ b/x/asset/keeper/msg_server.go @@ -158,7 +158,7 @@ func (k msgServer) UnassignPrivilege(goCtx context.Context, msg *types.MsgUnassi tm, found := k.GetTokenManagement(ctx, msg.TokenId) if !found { - return nil, errorsmod.Wrapf(sdkerrors.ErrNotFound, "token with denom %s is not exists", msg.TokenId) + return nil, errorsmod.Wrapf(sdkerrors.ErrNotFound, "token with denom %s doesn't exists", msg.TokenId) } if tm.Manager != msg.Manager { return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "sender is not token manager") @@ -220,7 +220,7 @@ func (k msgServer) ExecutePrivilege(goCtx context.Context, msg *types.MsgExecute return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "user does not not have %s privilege", privName) } - privImplementation, ok := k.PrivilegesMap[privName] + privImplementation, ok := k.PrivilegeManager[privName] if !ok { return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "privilege name %s is not registered yet", privName) } diff --git a/x/asset/keeper/msg_server_test.go b/x/asset/keeper/msg_server_test.go new file mode 100644 index 00000000..04d89870 --- /dev/null +++ b/x/asset/keeper/msg_server_test.go @@ -0,0 +1,7 @@ +package keeper_test + +// import ( +// "fmt" +// "testing" + +// ) diff --git a/x/asset/keeper/token.go b/x/asset/keeper/store.go similarity index 100% rename from x/asset/keeper/token.go rename to x/asset/keeper/store.go