Skip to content

Commit

Permalink
e2e: allow PoA admin override with ENV variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Feb 27, 2024
1 parent f67be75 commit 90e59b7
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 20 deletions.
49 changes: 29 additions & 20 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,15 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

// !IMPORTANT: testnet only (reece's addr)
const POAAdmin = "manifest10r39fueph9fq7a6lgswu4zdsg8t3gxlqdwwncm"
func GetPoAAdmin() string {
// used only in e2e testing with interchaintest
if address := os.Getenv("OVERRIDE_POA_ADMIN_ADDRESS"); address != "" {
return address
}

// !IMPORTANT: testnet only (reece's addr). Change this to a mainnet address
return "manifest10r39fueph9fq7a6lgswu4zdsg8t3gxlqdwwncm"
}

// We pull these out so we can set them with LDFLAGS in the Makefile
var (
Expand Down Expand Up @@ -344,7 +351,7 @@ func NewApp(
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]),
POAAdmin,
GetPoAAdmin(),
runtime.EventService{},
)
bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore)
Expand All @@ -371,14 +378,14 @@ func NewApp(
maccPerms,
authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()),
sdk.GetConfig().GetBech32AccountAddrPrefix(),
POAAdmin,
GetPoAAdmin(),
)
app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec,
runtime.NewKVStoreService(keys[banktypes.StoreKey]),
app.AccountKeeper,
BlockedAddresses(),
POAAdmin,
GetPoAAdmin(),
logger,
)

Expand All @@ -387,7 +394,7 @@ func NewApp(
runtime.NewKVStoreService(keys[stakingtypes.StoreKey]),
app.AccountKeeper,
app.BankKeeper,
POAAdmin,
GetPoAAdmin(),
authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
)
Expand All @@ -398,7 +405,7 @@ func NewApp(
app.AccountKeeper,
app.BankKeeper,
authtypes.FeeCollectorName,
POAAdmin,
GetPoAAdmin(),
)

app.DistrKeeper = distrkeeper.NewKeeper(
Expand All @@ -408,15 +415,15 @@ func NewApp(
app.BankKeeper,
app.StakingKeeper,
authtypes.FeeCollectorName,
POAAdmin,
GetPoAAdmin(),
)

app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec,
legacyAmino,
runtime.NewKVStoreService(keys[slashingtypes.StoreKey]),
app.StakingKeeper,
POAAdmin,
GetPoAAdmin(),
)

app.POAKeeper = poakeeper.NewKeeper(
Expand All @@ -436,7 +443,7 @@ func NewApp(
invCheckPeriod,
app.BankKeeper,
authtypes.FeeCollectorName,
POAAdmin,
GetPoAAdmin(),
app.AccountKeeper.AddressCodec(),
)

Expand All @@ -451,7 +458,7 @@ func NewApp(
app.CircuitKeeper = circuitkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[circuittypes.StoreKey]),
POAAdmin,
GetPoAAdmin(),
app.AccountKeeper.AddressCodec(),
)
app.BaseApp.SetCircuitBreaker(&app.CircuitKeeper)
Expand Down Expand Up @@ -487,7 +494,7 @@ func NewApp(
appCodec,
homePath,
app.BaseApp,
POAAdmin,
GetPoAAdmin(),
)

app.IBCKeeper = ibckeeper.NewKeeper(
Expand All @@ -497,7 +504,7 @@ func NewApp(
app.StakingKeeper,
app.UpgradeKeeper,
scopedIBCKeeper,
POAAdmin,
GetPoAAdmin(),
)

// Register the proposal types
Expand All @@ -523,7 +530,7 @@ func NewApp(
app.DistrKeeper,
app.MsgServiceRouter(),
govConfig,
POAAdmin,
GetPoAAdmin(),
)

app.GovKeeper = *govKeeper.SetHooks(
Expand Down Expand Up @@ -558,7 +565,7 @@ func NewApp(
app.MintKeeper,
app.BankKeeper,
logger,
POAAdmin,
GetPoAAdmin(),
)

// Create the TokenFactory Keeper
Expand All @@ -570,7 +577,7 @@ func NewApp(
app.DistrKeeper,
tokenFactoryCapabilities,
app.POAKeeper.IsAdmin,
POAAdmin,
GetPoAAdmin(),
)

// IBC Fee Module keeper
Expand All @@ -592,7 +599,7 @@ func NewApp(
app.AccountKeeper,
app.BankKeeper,
scopedTransferKeeper,
POAAdmin,
GetPoAAdmin(),
)

app.ICAHostKeeper = icahostkeeper.NewKeeper(
Expand All @@ -605,7 +612,7 @@ func NewApp(
app.AccountKeeper,
scopedICAHostKeeper,
app.MsgServiceRouter(),
POAAdmin,
GetPoAAdmin(),
)
app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
appCodec,
Expand All @@ -616,7 +623,7 @@ func NewApp(
app.IBCKeeper.PortKeeper,
scopedICAControllerKeeper,
app.MsgServiceRouter(),
POAAdmin,
GetPoAAdmin(),
)

// Set legacy router for backwards compatibility with gov v1beta1
Expand Down Expand Up @@ -841,6 +848,8 @@ func NewApp(
app.ScopedICAHostKeeper = scopedICAHostKeeper
app.ScopedICAControllerKeeper = scopedICAControllerKeeper

app.setAnteHandler(txConfig)

// In v0.46, the SDK introduces _postHandlers_. PostHandlers are like
// antehandlers, but are run _after_ the `runMsgs` execution. They are also
// defined as a chain, and have the same signature as antehandlers.
Expand Down Expand Up @@ -1123,7 +1132,7 @@ func BlockedAddresses() map[string]bool {
}

// allow the following addresses to receive funds
delete(modAccAddrs, POAAdmin)
delete(modAccAddrs, govtypes.ModuleName)

return modAccAddrs
}
Expand Down
83 changes: 83 additions & 0 deletions interchaintest/mainfest_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package interchaintest

import (
"context"
"fmt"
"testing"

"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/testreporter"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest"
)

func TestManifest(t *testing.T) {
t.Parallel()

ctx := context.Background()
cfgA := LocalChainConfig
cfgA.Env = []string{
fmt.Sprintf("OVERRIDE_POA_ADMIN_ADDRESS=%s", accAddr),
}

fmt.Printf("cfgA: %+v\n", cfgA)

cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t, zaptest.Level(zapcore.DebugLevel)), []*interchaintest.ChainSpec{
{
Name: "manifest",
Version: "local",
ChainName: cfgA.ChainID,
NumValidators: &vals,
NumFullNodes: &fullNodes,
ChainConfig: cfgA,
},
//
})

chains, err := cf.Chains(t.Name())
require.NoError(t, err)
manifestA := chains[0].(*cosmos.CosmosChain)

// Relayer Factory
client, network := interchaintest.DockerSetup(t)

ic := interchaintest.NewInterchain().
AddChain(manifestA)

rep := testreporter.NewNopReporter()
eRep := rep.RelayerExecReporter(t)

// Build interchain
require.NoError(t, ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: false,
}))

// Chains
appChain := chains[0].(*cosmos.CosmosChain)

// load in the PoA admin to sudo mint via the TokenFactory
poaAdmin, err := interchaintest.GetAndFundTestUserWithMnemonic(ctx, "acc0", accMnemonic, DefaultGenesisAmt, appChain)
if err != nil {
t.Fatal(err)
}
poaAdminAddr := poaAdmin.FormattedAddress()
t.Logf("poaAdminAddr: %s\n", poaAdminAddr)

// users := interchaintest.GetAndFundTestUsers(t, ctx, "default", DefaultGenesisAmt, appChain, appChain)
// user := users[0]
// uaddr := user.FormattedAddress()

// user2 := users[1]
// uaddr2 := user2.FormattedAddress()

// node := appChain.GetNode()

t.Cleanup(func() {
_ = ic.Close()
})
}

0 comments on commit 90e59b7

Please sign in to comment.