Skip to content

Commit

Permalink
fixup! fixup: refactor foundation address
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanchriswhite committed Oct 24, 2024
1 parent 0ad6387 commit 3731434
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 46 deletions.
6 changes: 6 additions & 0 deletions x/application/module/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions x/gateway/module/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions x/proof/module/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand All @@ -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()

Expand Down
5 changes: 5 additions & 0 deletions x/service/module/tx_add_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions x/session/keeper/session_hydrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions x/supplier/module/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
8 changes: 2 additions & 6 deletions x/tokenomics/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,15 @@ 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))
}

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,
Expand Down
9 changes: 7 additions & 2 deletions x/tokenomics/module/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}
67 changes: 32 additions & 35 deletions x/tokenomics/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}
Expand All @@ -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),
Expand All @@ -118,24 +118,24 @@ 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)

InitGenesis(ctx, am.tokenomicsKeeper, genState)
}

// 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)
}
Expand All @@ -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)
}

Expand All @@ -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 {
Expand All @@ -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,
Expand Down

0 comments on commit 3731434

Please sign in to comment.