-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: clarified whitelisted relayer logs
- Loading branch information
Showing
5 changed files
with
123 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package consensus_test | ||
|
||
import ( | ||
"testing" | ||
|
||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
"github.com/gogo/protobuf/proto" | ||
prototypes "github.com/gogo/protobuf/types" | ||
"github.com/stretchr/testify/require" | ||
"github.com/tendermint/tendermint/abci/types" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
|
||
"github.com/dymensionxyz/dymension-rdk/server/consensus" | ||
"github.com/dymensionxyz/dymension-rdk/testutil/utils" | ||
seqtypes "github.com/dymensionxyz/dymension-rdk/x/sequencers/types" | ||
) | ||
|
||
func TestProcessConsensusMessages_ConsensusMsgUpsertSequencer(t *testing.T) { | ||
var ( | ||
app = utils.Setup(t, false) | ||
ctx = app.BaseApp.NewContext(false, tmproto.Header{}) | ||
consensusMsgHandler = consensus.AllowedMessagesHandler([]string{ | ||
proto.MessageName(new(seqtypes.ConsensusMsgUpsertSequencer)), | ||
}) | ||
operator = utils.Proposer.GetOperator() | ||
rewardAddr = utils.AccAddress() | ||
relayers = []string{ | ||
utils.AccAddress().String(), | ||
utils.AccAddress().String(), | ||
utils.AccAddress().String(), | ||
} | ||
) | ||
anyPubKey, err := codectypes.NewAnyWithValue(utils.ConsPrivKey.PubKey()) | ||
require.NoError(t, err) | ||
|
||
testCases := []struct { | ||
name string | ||
consensusMsg proto.Message | ||
expectedErr bool | ||
}{ | ||
{ | ||
name: "Valid message", | ||
consensusMsg: &seqtypes.ConsensusMsgUpsertSequencer{ | ||
Signer: authtypes.NewModuleAddress(seqtypes.ModuleName).String(), | ||
Operator: operator.String(), | ||
ConsPubKey: anyPubKey, | ||
RewardAddr: rewardAddr.String(), | ||
Relayers: relayers, | ||
}, | ||
expectedErr: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
responses := consensus.ProcessConsensusMessages( | ||
ctx, | ||
app.AppCodec(), | ||
consensusMsgHandler, | ||
app.MsgServiceRouter(), | ||
[]*prototypes.Any{FromProtoMsgToAny(tc.consensusMsg)}, | ||
) | ||
|
||
if tc.expectedErr { | ||
require.NotEmpty(t, responses) | ||
for _, resp := range responses { | ||
require.IsType(t, &types.ConsensusMessageResponse_Error{}, resp.Response) | ||
} | ||
} else { | ||
require.Len(t, responses, 1) | ||
require.IsType(t, &types.ConsensusMessageResponse_Ok{}, responses[0].Response) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func FromProtoMsgToAny(msg proto.Message) *prototypes.Any { | ||
theType, err := proto.Marshal(msg) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
return &prototypes.Any{ | ||
TypeUrl: proto.MessageName(msg), | ||
Value: theType, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters