Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
879 changes: 879 additions & 0 deletions app/abci_full_test.go

Large diffs are not rendered by default.

1,024 changes: 537 additions & 487 deletions app/abci_test.go

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,13 @@ func NewHeimdallApp(
auth.NewAppModule(appCodec, app.AccountKeeper, nil, app.GetSubspace(authtypes.ModuleName)),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
stake.NewAppModule(app.StakeKeeper, app.caller),
clerk.NewAppModule(app.ClerkKeeper),
stake.NewAppModule(&app.StakeKeeper),
clerk.NewAppModule(&app.ClerkKeeper),
chainmanager.NewAppModule(app.ChainManagerKeeper),
topup.NewAppModule(app.TopupKeeper, app.caller),
topup.NewAppModule(&app.TopupKeeper),
checkpoint.NewAppModule(&app.CheckpointKeeper),
milestone.NewAppModule(&app.MilestoneKeeper),
bor.NewAppModule(app.BorKeeper, app.caller),
bor.NewAppModule(&app.BorKeeper),
params.NewAppModule(app.ParamsKeeper),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
)
Expand Down Expand Up @@ -601,8 +601,7 @@ func (app *HeimdallApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain)
stakingState := staketypes.GetGenesisStateFromAppState(app.appCodec, genesisState)
checkpointState := checkpointTypes.GetGenesisStateFromAppState(app.appCodec, genesisState)

// check if validator is current validator
// add to val updates else skip
// check if the validator is the current one and add to valUpdates else skip
var valUpdates []abci.ValidatorUpdate

for _, validator := range stakingState.Validators {
Expand Down
74 changes: 74 additions & 0 deletions app/vote_ext_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2311,3 +2311,77 @@ func TestFilterVoteExtensions_PlaceholderPassesCompleteness(t *testing.T) {
err = ValidateVoteExtensions(ctx, reqHeight, filtered, round, &valSet, hApp.MilestoneKeeper)
require.NoError(t, err, "VE validation must pass with placeholder when remaining VP > 2/3")
}

func setupEmptyExtendedVoteInfo(
t *testing.T,
flag cmtTypes.BlockIDFlag,
blockHashBytes []byte,
validator abci.Validator,
privKey cmtcrypto.PrivKey,
height int64,
app *HeimdallApp,
) abci.ExtendedVoteInfo {
t.Helper()

nonRpDummyVoteExt, err := GetDummyNonRpVoteExtension(height, app.ChainID())
require.NoErrorf(t, err, "failed to get dummy nonRpVoteExtension: %v", err)

// create a protobuf msg for ConsolidatedSideTxResponse
voteExtensionProto := sidetxs.VoteExtension{
BlockHash: blockHashBytes,
Height: VoteExtBlockHeight,
}

// marshal it into Protobuf bytes
voteExtensionBytes, err := voteExtensionProto.Marshal()
require.NoErrorf(t, err, "failed to marshal voteExtensionProto: %v", err)

voteInfo := abci.ExtendedVoteInfo{
BlockIdFlag: flag,
VoteExtension: voteExtensionBytes,
Validator: validator,
NonRpVoteExtension: nonRpDummyVoteExt,
}

createSignatureForVoteExtension(t, height, privKey, voteExtensionBytes, nonRpDummyVoteExt, &voteInfo)

return voteInfo
}

func createSignatureForVoteExtension(
t *testing.T,
height int64,
privKey cmtcrypto.PrivKey,
voteExtensionBytes,
nonRpVoteExtensionBytes []byte,
voteInfo *abci.ExtendedVoteInfo,
) {
cve := cmtTypes.CanonicalVoteExtension{
Extension: voteExtensionBytes,
Height: height,
Round: int64(0),
ChainId: "",
}

marshalDelimitedFn := func(msg proto.Message) ([]byte, error) {
var buf bytes.Buffer
if _, err := protoio.NewDelimitedWriter(&buf).WriteMsg(msg); err != nil {
return nil, err
}

return buf.Bytes(), nil
}
extSignBytes, err := marshalDelimitedFn(&cve)
require.NoErrorf(t, err, "failed to encode CanonicalVoteExtension: %v", err)

// Sign the vote extension
signature, err := privKey.Sign(extSignBytes)
require.NoErrorf(t, err, "failed to sign extSignBytes: %v", err)

// Sign nonRpVE
signatureNonRpVE, err := privKey.Sign(nonRpVoteExtensionBytes)
require.NoErrorf(t, err, "failed to sign nonRpVoteExtensionBytes: %v", err)

voteInfo.ExtensionSignature = signature
voteInfo.NonRpExtensionSignature = signatureNonRpVE
}
9 changes: 8 additions & 1 deletion helper/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,14 @@ func (c *ContractCaller) GetBorTxReceipt(txHash common.Hash) (*ethTypes.Receipt,
return c.getTxReceipt(ctx, c.BorChainClient, nil, txHash)
}

func (c *ContractCaller) getTxReceipt(ctx context.Context, client *ethclient.Client, grpcClient *grpc.BorGRPCClient, txHash common.Hash) (*ethTypes.Receipt, error) {
func (c *ContractCaller) getTxReceipt(
ctx context.Context,
client interface {
TransactionReceipt(context.Context, common.Hash) (*ethTypes.Receipt, error)
},
grpcClient *grpc.BorGRPCClient,
txHash common.Hash,
) (*ethTypes.Receipt, error) {
if grpcClient != nil {
return grpcClient.TransactionReceipt(ctx, txHash)
}
Expand Down
16 changes: 6 additions & 10 deletions x/bor/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"

"github.com/0xPolygon/heimdall-v2/helper"
"github.com/0xPolygon/heimdall-v2/sidetxs"
"github.com/0xPolygon/heimdall-v2/x/bor/client/cli"
"github.com/0xPolygon/heimdall-v2/x/bor/keeper"
Expand Down Expand Up @@ -73,13 +72,12 @@ func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) {

// RegisterSideMsgServices registers the side message services for the bor module.
func (am AppModule) RegisterSideMsgServices(sideCfg sidetxs.SideTxConfigurator) {
types.RegisterSideMsgServer(sideCfg, keeper.NewSideMsgServerImpl(&am.keeper))
types.RegisterSideMsgServer(sideCfg, keeper.NewSideMsgServerImpl(am.keeper))
}

// AppModule implements an application module for the bor module.
type AppModule struct {
keeper keeper.Keeper
contractCaller helper.IContractCaller
keeper *keeper.Keeper
}

// GetTxCmd returns the root tx command for the bor module.
Expand All @@ -92,18 +90,16 @@ func (am AppModule) IsAppModule() {}

// RegisterServices registers module services.
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(&am.keeper))
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(am.keeper))
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(*am.keeper))
}

// NewAppModule creates a new AppModule object
func NewAppModule(
keeper keeper.Keeper,
contractCaller helper.IContractCaller,
keeper *keeper.Keeper,
) AppModule {
return AppModule{
keeper: keeper,
contractCaller: contractCaller,
keeper: keeper,
}
}

Expand Down
5 changes: 5 additions & 0 deletions x/checkpoint/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ func NewKeeper(
return k
}

// SetContractCaller sets the contract caller in the checkpoint keeper
func (k *Keeper) SetContractCaller(contractCaller helper.IContractCaller) {
k.IContractCaller = contractCaller
}

// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx context.Context) log.Logger {
sdkCtx := sdk.UnwrapSDKContext(ctx)
Expand Down
7 changes: 6 additions & 1 deletion x/clerk/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func NewKeeper(
return keeper
}

// SetContractCaller sets the contract caller in the clerk keeper
func (k *Keeper) SetContractCaller(contractCaller helper.IContractCaller) {
k.contractCaller = contractCaller
}

// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx context.Context) log.Logger {
return sdk.UnwrapSDKContext(ctx).Logger().With("module", "x/"+types.ModuleName)
Expand All @@ -81,7 +86,7 @@ func (k *Keeper) SetEventRecordWithID(ctx context.Context, record types.EventRec
return k.RecordsWithID.Set(ctx, record.Id, record)
}

// SetEventRecord adds record to store.
// SetEventRecord adds the record to the store.
func (k *Keeper) SetEventRecord(ctx context.Context, record types.EventRecord) error {
if err := k.SetEventRecordWithID(ctx, record); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion x/clerk/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (s *KeeperTestSuite) SetupTest() {
s.msgServer = clerkKeeper.NewMsgServerImpl(keeper)

s.sideMsgCfg = sidetxs.NewSideTxConfigurator()
types.RegisterSideMsgServer(s.sideMsgCfg, clerkKeeper.NewSideMsgServerImpl(keeper))
types.RegisterSideMsgServer(s.sideMsgCfg, clerkKeeper.NewSideMsgServerImpl(&keeper))
}

func (s *KeeperTestSuite) TestHasGetSetEventRecord() {
Expand Down
4 changes: 2 additions & 2 deletions x/clerk/keeper/side_msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import (
)

type sideMsgServer struct {
Keeper
*Keeper
}

var msgEventRecord = sdk.MsgTypeURL(&types.MsgEventRecord{})

// NewSideMsgServerImpl returns an implementation of the clerk SideMsgServer interface
// for the provided Keeper.
func NewSideMsgServerImpl(keeper Keeper) sidetxs.SideMsgServer {
func NewSideMsgServerImpl(keeper *Keeper) sidetxs.SideMsgServer {
return &sideMsgServer{Keeper: keeper}
}

Expand Down
8 changes: 4 additions & 4 deletions x/clerk/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (

// AppModule implements an application module for the clerk module.
type AppModule struct {
keeper keeper.Keeper
keeper *keeper.Keeper
}

// Name returns the clerk module's name.
Expand Down Expand Up @@ -77,8 +77,8 @@ func (am AppModule) IsAppModule() {}

// RegisterServices registers module services.
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg, keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg, keeper.NewQueryServer(&am.keeper))
types.RegisterMsgServer(cfg, keeper.NewMsgServerImpl(*am.keeper))
types.RegisterQueryServer(cfg, keeper.NewQueryServer(am.keeper))
}

// RegisterSideMsgServices registers side handler module services.
Expand All @@ -87,7 +87,7 @@ func (am AppModule) RegisterSideMsgServices(sideCfg sidetxs.SideTxConfigurator)
}

// NewAppModule creates a new AppModule object
func NewAppModule(keeper keeper.Keeper) AppModule {
func NewAppModule(keeper *keeper.Keeper) AppModule {
return AppModule{
keeper: keeper,
}
Expand Down
5 changes: 5 additions & 0 deletions x/milestone/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func NewKeeper(
return k
}

// SetContractCaller sets the contract caller in the milestone keeper
func (k *Keeper) SetContractCaller(contractCaller helper.IContractCaller) {
k.IContractCaller = contractCaller
}

func (k Keeper) SetLastMilestoneBlock(ctx context.Context, block uint64) error {
err := k.lastMilestoneBlock.Set(ctx, block)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions x/stake/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ func (k *Keeper) SetCheckpointKeeper(checkpointKeeper types.CheckpointKeeper) {
k.setupComplete = true
}

// SetContractCaller sets the contract caller in the stake keeper
func (k *Keeper) SetContractCaller(contractCaller helper.IContractCaller) {
k.contractCaller = contractCaller
}

// PanicIfSetupIsIncomplete panics if the setup is incomplete, meaning that the checkpointKeeper is not set
func (k *Keeper) PanicIfSetupIsIncomplete() {
if !k.setupComplete {
Expand Down
15 changes: 6 additions & 9 deletions x/stake/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"

"github.com/0xPolygon/heimdall-v2/helper"
"github.com/0xPolygon/heimdall-v2/sidetxs"
"github.com/0xPolygon/heimdall-v2/x/stake/client/cli"
"github.com/0xPolygon/heimdall-v2/x/stake/keeper"
Expand All @@ -44,15 +43,13 @@ type AppModuleBasic struct{}

// AppModule implements an application module for the stake module.
type AppModule struct {
keeper keeper.Keeper
contractCaller helper.IContractCaller
keeper *keeper.Keeper
}

// NewAppModule creates a new AppModule object
func NewAppModule(keeper keeper.Keeper, contractCaller helper.IContractCaller) AppModule {
func NewAppModule(keeper *keeper.Keeper) AppModule {
return AppModule{
keeper: keeper,
contractCaller: contractCaller,
keeper: keeper,
}
}

Expand Down Expand Up @@ -104,13 +101,13 @@ func (am AppModule) IsAppModule() {}

// RegisterServices registers module services.
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(&am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(&am.keeper))
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(am.keeper))
}

// RegisterSideMsgServices registers side handler module services.
func (am AppModule) RegisterSideMsgServices(sideCfg sidetxs.SideTxConfigurator) {
types.RegisterSideMsgServer(sideCfg, keeper.NewSideMsgServerImpl(&am.keeper))
types.RegisterSideMsgServer(sideCfg, keeper.NewSideMsgServerImpl(am.keeper))
}

// QuerierRoute returns the stake module's querier route name.
Expand Down
5 changes: 5 additions & 0 deletions x/topup/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ func NewKeeper(
return k
}

// SetContractCaller sets the contract caller in the topup keeper
func (k *Keeper) SetContractCaller(contractCaller helper.IContractCaller) {
k.contractCaller = contractCaller
}

// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx context.Context) log.Logger {
sdkCtx := sdk.UnwrapSDKContext(ctx)
Expand Down
15 changes: 6 additions & 9 deletions x/topup/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/cosmos/cosmos-sdk/types/simulation"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"

"github.com/0xPolygon/heimdall-v2/helper"
"github.com/0xPolygon/heimdall-v2/sidetxs"
"github.com/0xPolygon/heimdall-v2/x/topup/keeper"
topupSimulation "github.com/0xPolygon/heimdall-v2/x/topup/simulation"
Expand All @@ -37,15 +36,13 @@ var (

// AppModule implements an application module for the topup module.
type AppModule struct {
keeper keeper.Keeper
contractCaller helper.IContractCaller
keeper *keeper.Keeper
}

// NewAppModule creates a new AppModule object
func NewAppModule(keeper keeper.Keeper, contractCaller helper.IContractCaller) AppModule {
func NewAppModule(keeper *keeper.Keeper) AppModule {
return AppModule{
keeper: keeper,
contractCaller: contractCaller,
keeper: keeper,
}
}

Expand All @@ -61,7 +58,7 @@ func (AppModule) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {

// RegisterSideMsgServices registers side handler module services.
func (am AppModule) RegisterSideMsgServices(sideCfg sidetxs.SideTxConfigurator) {
types.RegisterSideMsgServer(sideCfg, keeper.NewSideMsgServerImpl(&am.keeper))
types.RegisterSideMsgServer(sideCfg, keeper.NewSideMsgServerImpl(am.keeper))
}

// DefaultGenesis returns default genesis state as raw bytes for the x/topup module.
Expand Down Expand Up @@ -97,8 +94,8 @@ func (am AppModule) IsAppModule() {

// RegisterServices registers module services.
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(&am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(&am.keeper))
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(am.keeper))
}

// QuerierRoute returns the stake module's querier route name.
Expand Down
Loading