From 37314347a733617193677713eedbbc9e99d28e11 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Thu, 24 Oct 2024 19:28:24 +0200 Subject: [PATCH] fixup! fixup: refactor foundation address --- x/application/module/helpers_test.go | 6 ++ x/gateway/module/helpers_test.go | 6 ++ x/proof/module/helpers_test.go | 5 ++ x/service/module/tx_add_service_test.go | 5 ++ x/session/keeper/session_hydrator_test.go | 4 +- x/supplier/module/helpers_test.go | 6 ++ x/tokenomics/keeper/keeper.go | 8 +-- x/tokenomics/module/helpers_test.go | 9 ++- x/tokenomics/module/module.go | 67 +++++++++++------------ 9 files changed, 70 insertions(+), 46 deletions(-) diff --git a/x/application/module/helpers_test.go b/x/application/module/helpers_test.go index 24fca8ccd6..9b8ebb7641 100644 --- a/x/application/module/helpers_test.go +++ b/x/application/module/helpers_test.go @@ -8,7 +8,9 @@ import ( "github.com/stretchr/testify/require" "github.com/pokt-network/poktroll/testutil/network" + "github.com/pokt-network/poktroll/testutil/sample" "github.com/pokt-network/poktroll/x/application/types" + tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types" ) // Dummy variable to avoid unused import error. @@ -18,6 +20,10 @@ var _ = strconv.IntSize // It returns the network and a slice of the created application objects. func networkWithApplicationObjects(t *testing.T, n int) (*network.Network, []types.Application) { t.Helper() + + // TODO_TECHDEBT: Remove once dao reward address is promoted to a tokenomics param. + tokenomicstypes.DaoRewardAddress = sample.AccAddress() + cfg := network.DefaultConfig() appGenesisState := network.DefaultApplicationModuleGenesisState(t, n) buf, err := cfg.Codec.MarshalJSON(appGenesisState) diff --git a/x/gateway/module/helpers_test.go b/x/gateway/module/helpers_test.go index cb271b4451..ffb526d2e7 100644 --- a/x/gateway/module/helpers_test.go +++ b/x/gateway/module/helpers_test.go @@ -7,7 +7,9 @@ import ( "github.com/stretchr/testify/require" "github.com/pokt-network/poktroll/testutil/network" + "github.com/pokt-network/poktroll/testutil/sample" "github.com/pokt-network/poktroll/x/gateway/types" + tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types" ) // Dummy variable to avoid unused import error. @@ -16,6 +18,10 @@ var _ = strconv.IntSize // networkWithGatewayObjects creates a network with a populated gateway state of n gateway objects func networkWithGatewayObjects(t *testing.T, n int) (*network.Network, []types.Gateway) { t.Helper() + + // TODO_TECHDEBT: Remove once dao reward address is promoted to a tokenomics param. + tokenomicstypes.DaoRewardAddress = sample.AccAddress() + cfg := network.DefaultConfig() gatewayGenesisState := network.DefaultGatewayModuleGenesisState(t, n) buf, err := cfg.Codec.MarshalJSON(gatewayGenesisState) diff --git a/x/proof/module/helpers_test.go b/x/proof/module/helpers_test.go index 59948a5053..3199be2320 100644 --- a/x/proof/module/helpers_test.go +++ b/x/proof/module/helpers_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/pokt-network/poktroll/testutil/network" + "github.com/pokt-network/poktroll/testutil/sample" testsession "github.com/pokt-network/poktroll/testutil/session" "github.com/pokt-network/poktroll/testutil/testkeyring" apptypes "github.com/pokt-network/poktroll/x/application/types" @@ -18,6 +19,7 @@ import ( sessiontypes "github.com/pokt-network/poktroll/x/session/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" suppliertypes "github.com/pokt-network/poktroll/x/supplier/types" + tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types" ) const ( @@ -41,6 +43,9 @@ func networkWithClaimObjects( ) (net *network.Network, claims []types.Claim, clientCtx cosmosclient.Context) { t.Helper() + // TODO_TECHDEBT: Remove once dao reward address is promoted to a tokenomics param. + tokenomicstypes.DaoRewardAddress = sample.AccAddress() + // Initialize a network config. cfg := network.DefaultConfig() diff --git a/x/service/module/tx_add_service_test.go b/x/service/module/tx_add_service_test.go index 95af7e0faa..b7bc7b7fb3 100644 --- a/x/service/module/tx_add_service_test.go +++ b/x/service/module/tx_add_service_test.go @@ -15,12 +15,17 @@ import ( "google.golang.org/grpc/status" "github.com/pokt-network/poktroll/testutil/network" + "github.com/pokt-network/poktroll/testutil/sample" service "github.com/pokt-network/poktroll/x/service/module" "github.com/pokt-network/poktroll/x/service/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" + tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types" ) func TestCLI_AddService(t *testing.T) { + // TODO_TECHDEBT: Remove once dao reward address is promoted to a tokenomics param. + tokenomicstypes.DaoRewardAddress = sample.AccAddress() + net := network.New(t, network.DefaultConfig()) val := net.Validators[0] ctx := val.ClientCtx diff --git a/x/session/keeper/session_hydrator_test.go b/x/session/keeper/session_hydrator_test.go index 41ebcc63ce..692699f4fe 100644 --- a/x/session/keeper/session_hydrator_test.go +++ b/x/session/keeper/session_hydrator_test.go @@ -26,9 +26,7 @@ var ( ComputeUnitsToTokensMultiplier: 42, } - sharedParamsOpt = keepertest.WithSharedModuleParams(map[string]sdk.Msg{ - sharedtypes.ModuleName: &testSharedParams, - }) + sharedParamsOpt = keepertest.WithSharedModuleParams(&testSharedParams) ) func TestSession_HydrateSession_Success_BaseCase(t *testing.T) { diff --git a/x/supplier/module/helpers_test.go b/x/supplier/module/helpers_test.go index c31fd18395..ff47de6fd2 100644 --- a/x/supplier/module/helpers_test.go +++ b/x/supplier/module/helpers_test.go @@ -7,8 +7,10 @@ import ( "github.com/stretchr/testify/require" "github.com/pokt-network/poktroll/testutil/network" + "github.com/pokt-network/poktroll/testutil/sample" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" "github.com/pokt-network/poktroll/x/supplier/types" + tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types" ) // Dummy variable to avoid unused import error. @@ -18,6 +20,10 @@ var _ = strconv.IntSize // It returns the network and a slice of the created supplier objects. func networkWithSupplierObjects(t *testing.T, n int) (*network.Network, []sharedtypes.Supplier) { t.Helper() + + // TODO_TECHDEBT: Remove once dao reward address is promoted to a tokenomics param. + tokenomicstypes.DaoRewardAddress = sample.AccAddress() + cfg := network.DefaultConfig() supplierGenesisState := network.DefaultSupplierModuleGenesisState(t, n) buf, err := cfg.Codec.MarshalJSON(supplierGenesisState) diff --git a/x/tokenomics/keeper/keeper.go b/x/tokenomics/keeper/keeper.go index 07adce9147..904bcf3387 100644 --- a/x/tokenomics/keeper/keeper.go +++ b/x/tokenomics/keeper/keeper.go @@ -52,6 +52,8 @@ func NewKeeper( sharedKeeper tokenomicstypes.SharedKeeper, sessionKeeper tokenomicstypes.SessionKeeper, serviceKeeper tokenomicstypes.ServiceKeeper, + + tlmProcessors []tlm.TokenLogicModuleProcessor, ) Keeper { if _, err := cosmostypes.AccAddressFromBech32(authority); err != nil { panic(fmt.Sprintf("invalid authority address: %s", authority)) @@ -59,12 +61,6 @@ func NewKeeper( sharedQuerier := prooftypes.NewSharedKeeperQueryClient(sharedKeeper, sessionKeeper) - // TODO_TECHDEBT: remove once dao reward address is promoted to a tokenomics param. - if tokenomicstypes.DaoRewardAddress == "" { - panic(`foundation address MUST be set; add a "-X github.com/pokt-network/poktroll/app.FoundationAddress" element to build.ldglags in the config.yml`) - } - tlmProcessors := tlm.NewDefaultProcessors(tokenomicstypes.DaoRewardAddress) - return Keeper{ cdc: cdc, storeService: storeService, diff --git a/x/tokenomics/module/helpers_test.go b/x/tokenomics/module/helpers_test.go index 63545283c1..5ae39a8122 100644 --- a/x/tokenomics/module/helpers_test.go +++ b/x/tokenomics/module/helpers_test.go @@ -8,7 +8,8 @@ import ( "github.com/stretchr/testify/require" "github.com/pokt-network/poktroll/testutil/network" - "github.com/pokt-network/poktroll/x/tokenomics/types" + "github.com/pokt-network/poktroll/testutil/sample" + tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types" ) // Dummy variable to avoid unused import error. @@ -18,10 +19,14 @@ var _ = strconv.IntSize // with a default tokenomics genesis state. func networkWithDefaultConfig(t *testing.T) *network.Network { t.Helper() + + // TODO_TECHDEBT: Remove once dao reward address is promoted to a tokenomics param. + tokenomicstypes.DaoRewardAddress = sample.AccAddress() + cfg := network.DefaultConfig() tokenomicsGenesisState := network.DefaultTokenomicsModuleGenesisState(t) buf, err := cfg.Codec.MarshalJSON(tokenomicsGenesisState) require.NoError(t, err) - cfg.GenesisState[types.ModuleName] = buf + cfg.GenesisState[tokenomicstypes.ModuleName] = buf return network.New(t, cfg) } diff --git a/x/tokenomics/module/module.go b/x/tokenomics/module/module.go index 8fc02d0fd5..0647c440bf 100644 --- a/x/tokenomics/module/module.go +++ b/x/tokenomics/module/module.go @@ -12,7 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" + cosmostypes "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -21,7 +21,7 @@ import ( tokenomicsmodule "github.com/pokt-network/poktroll/api/poktroll/tokenomics/module" "github.com/pokt-network/poktroll/x/tokenomics/keeper" tlm "github.com/pokt-network/poktroll/x/tokenomics/token_logic_module" - "github.com/pokt-network/poktroll/x/tokenomics/types" + tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types" ) var ( @@ -52,7 +52,7 @@ func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { // Name returns the name of the module as a string. func (AppModuleBasic) Name() string { - return types.ModuleName + return tokenomicstypes.ModuleName } // RegisterLegacyAminoCodec registers the amino codec for the module, which is used @@ -61,27 +61,27 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {} // RegisterInterfaces registers a module's interface types and their concrete implementations as proto.Message. func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { - types.RegisterInterfaces(reg) + tokenomicstypes.RegisterInterfaces(reg) } // DefaultGenesis returns a default GenesisState for the module, marshalled to json.RawMessage. // The default GenesisState need to be defined by the module developer and is primarily used for testing. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesis()) + return cdc.MustMarshalJSON(tokenomicstypes.DefaultGenesis()) } // ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form. func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { - var genState types.GenesisState + var genState tokenomicstypes.GenesisState if err := cdc.UnmarshalJSON(bz, &genState); err != nil { - return types.ErrTokenomicsUnmarshalInvalid.Wrapf("invalid genesis state: %v", err) + return tokenomicstypes.ErrTokenomicsUnmarshalInvalid.Wrapf("invalid genesis state: %v", err) } return genState.Validate() } // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + if err := tokenomicstypes.RegisterQueryHandlerClient(context.Background(), mux, tokenomicstypes.NewQueryClient(clientCtx)); err != nil { panic(err) } } @@ -95,17 +95,17 @@ type AppModule struct { AppModuleBasic tokenomicsKeeper keeper.Keeper - accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper - supplierKeeper types.SupplierKeeper + accountKeeper tokenomicstypes.AccountKeeper + bankKeeper tokenomicstypes.BankKeeper + supplierKeeper tokenomicstypes.SupplierKeeper } func NewAppModule( cdc codec.Codec, tokenomicsKeeper keeper.Keeper, - accountKeeper types.AccountKeeper, - bankKeeper types.BankKeeper, - supplierKeeper types.SupplierKeeper, + accountKeeper tokenomicstypes.AccountKeeper, + bankKeeper tokenomicstypes.BankKeeper, + supplierKeeper tokenomicstypes.SupplierKeeper, ) AppModule { return AppModule{ AppModuleBasic: NewAppModuleBasic(cdc), @@ -118,16 +118,16 @@ func NewAppModule( // RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries func (am AppModule) RegisterServices(cfg module.Configurator) { - types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.tokenomicsKeeper)) - types.RegisterQueryServer(cfg.QueryServer(), am.tokenomicsKeeper) + tokenomicstypes.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.tokenomicsKeeper)) + tokenomicstypes.RegisterQueryServer(cfg.QueryServer(), am.tokenomicsKeeper) } // RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted) -func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} +func (am AppModule) RegisterInvariants(_ cosmostypes.InvariantRegistry) {} // InitGenesis performs the module's genesis initialization. It returns no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) { - var genState types.GenesisState +func (am AppModule) InitGenesis(ctx cosmostypes.Context, cdc codec.JSONCodec, gs json.RawMessage) { + var genState tokenomicstypes.GenesisState // Initialize global index to index in genesis state cdc.MustUnmarshalJSON(gs, &genState) @@ -135,7 +135,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.Ra } // ExportGenesis returns the module's exported genesis state as raw JSON bytes. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { +func (am AppModule) ExportGenesis(ctx cosmostypes.Context, cdc codec.JSONCodec) json.RawMessage { genState := ExportGenesis(ctx, am.tokenomicsKeeper) return cdc.MustMarshalJSON(genState) } @@ -154,7 +154,7 @@ func (am AppModule) BeginBlock(_ context.Context) error { // EndBlock contains the logic that is automatically triggered at the end of each block. // The end block implementation is optional. func (am AppModule) EndBlock(goCtx context.Context) error { - ctx := sdk.UnwrapSDKContext(goCtx) + ctx := cosmostypes.UnwrapSDKContext(goCtx) return EndBlocker(ctx, am.tokenomicsKeeper) } @@ -180,14 +180,14 @@ type ModuleInputs struct { Config *tokenomicsmodule.Module Logger log.Logger - AccountKeeper types.AccountKeeper - BankKeeper types.BankKeeper - ApplicationKeeper types.ApplicationKeeper - SupplierKeeper types.SupplierKeeper - ProofKeeper types.ProofKeeper - SharedKeeper types.SharedKeeper - SessionKeeper types.SessionKeeper - ServiceKeeper types.ServiceKeeper + AccountKeeper tokenomicstypes.AccountKeeper + BankKeeper tokenomicstypes.BankKeeper + ApplicationKeeper tokenomicstypes.ApplicationKeeper + SupplierKeeper tokenomicstypes.SupplierKeeper + ProofKeeper tokenomicstypes.ProofKeeper + SharedKeeper tokenomicstypes.SharedKeeper + SessionKeeper tokenomicstypes.SessionKeeper + ServiceKeeper tokenomicstypes.ServiceKeeper } type ModuleOutputs struct { @@ -204,14 +204,11 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) } - // MintAllocationDAO proportion of minted tokens will be sent to this address - // as a result of global mint TLM processing. - // TODO_TECHDEBT: Promote this value to a tokenomics module parameter. - foundationAddr := in.Config.GetFoundationAddress() - if foundationAddr == "" { + // TODO_TECHDEBT: remove once dao reward address is promoted to a tokenomics param. + if tokenomicstypes.DaoRewardAddress == "" { panic(`foundation address MUST be set; add a "-X github.com/pokt-network/poktroll/app.FoundationAddress" element to build.ldglags in the config.yml`) } - tlmProcessors := tlm.NewDefaultProcessors(foundationAddr) + tlmProcessors := tlm.NewDefaultProcessors(tokenomicstypes.DaoRewardAddress) k := keeper.NewKeeper( in.Cdc,