Skip to content

Commit

Permalink
add one unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
brewmaster012 committed Jan 21, 2024
1 parent e032572 commit 233ced4
Showing 1 changed file with 50 additions and 4 deletions.
54 changes: 50 additions & 4 deletions app/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,32 @@ func TestIsSystemTx(t *testing.T) {
isAuthorized := func(_ string) bool {
return true
}
isAuthorizedFalse := func(_ string) bool {
return false
}

tests := []struct {
name string
tx sdk.Tx
wantIs bool
name string
tx sdk.Tx
isAuthorized func(string) bool
wantIs bool
}{
{
"MsgCreateTSSVoter",
buildTxFromMsg(&crosschaintypes.MsgCreateTSSVoter{
Creator: sample.AccAddress(),
TssPubkey: "pubkey1234",
}),
isAuthorizedFalse,
false,
},
{
"MsgCreateTSSVoter",
buildTxFromMsg(&crosschaintypes.MsgCreateTSSVoter{
Creator: sample.AccAddress(),
TssPubkey: "pubkey1234",
}),
isAuthorized,
true,
},
{
Expand All @@ -73,21 +87,29 @@ func TestIsSystemTx(t *testing.T) {
Creator: sample.AccAddress(),
TssPubkey: "pubkey1234",
}),
isAuthorized,

true,
},
{
"MsgSend",
buildTxFromMsg(&banktypes.MsgSend{}),
isAuthorized,

false,
},
{
"MsgExec{MsgSend}",
buildAuthzTxFromMsg(&banktypes.MsgSend{}),
isAuthorized,

false,
},
{
"MsgCreateValidator",
buildTxFromMsg(&stakingtypes.MsgCreateValidator{}),
isAuthorized,

false,
},

Expand All @@ -96,13 +118,17 @@ func TestIsSystemTx(t *testing.T) {
buildTxFromMsg(&crosschaintypes.MsgVoteOnObservedInboundTx{
Creator: sample.AccAddress(),
}),
isAuthorized,

true,
},
{
"MsgExec{MsgVoteOnObservedInboundTx}",
buildAuthzTxFromMsg(&crosschaintypes.MsgVoteOnObservedInboundTx{
Creator: sample.AccAddress(),
}),
isAuthorized,

true,
},

Expand All @@ -111,75 +137,95 @@ func TestIsSystemTx(t *testing.T) {
buildTxFromMsg(&crosschaintypes.MsgVoteOnObservedOutboundTx{
Creator: sample.AccAddress(),
}),
isAuthorized,

true,
},
{
"MsgExec{MsgVoteOnObservedOutboundTx}",
buildAuthzTxFromMsg(&crosschaintypes.MsgVoteOnObservedOutboundTx{
Creator: sample.AccAddress(),
}),
isAuthorized,

true,
},
{
"MsgAddToOutTxTracker",
buildTxFromMsg(&crosschaintypes.MsgAddToOutTxTracker{
Creator: sample.AccAddress(),
}),
isAuthorized,

true,
},
{
"MsgExec{MsgAddToOutTxTracker}",
buildAuthzTxFromMsg(&crosschaintypes.MsgAddToOutTxTracker{
Creator: sample.AccAddress(),
}),
isAuthorized,

true,
},
{
"MsgCreateTSSVoter",
buildTxFromMsg(&crosschaintypes.MsgCreateTSSVoter{
Creator: sample.AccAddress(),
}),
isAuthorized,

true,
},
{
"MsgExec{MsgCreateTSSVoter}",
buildAuthzTxFromMsg(&crosschaintypes.MsgCreateTSSVoter{
Creator: sample.AccAddress(),
}),
isAuthorized,

true,
},
{
"MsgAddBlockHeader",
buildTxFromMsg(&observertypes.MsgAddBlockHeader{
Creator: sample.AccAddress(),
}),
isAuthorized,

true,
},
{
"MsgExec{MsgAddBlockHeader}",
buildAuthzTxFromMsg(&observertypes.MsgAddBlockHeader{
Creator: sample.AccAddress(),
}),
isAuthorized,

true,
},
{
"MsgAddBlameVote",
buildTxFromMsg(&observertypes.MsgAddBlameVote{
Creator: sample.AccAddress(),
}),
isAuthorized,

true,
},
{
"MsgExec{MsgAddBlameVote}",
buildAuthzTxFromMsg(&observertypes.MsgAddBlameVote{
Creator: sample.AccAddress(),
}),
isAuthorized,

true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
is := ante.IsSystemTx(tt.tx, isAuthorized)
is := ante.IsSystemTx(tt.tx, tt.isAuthorized)
require.Equal(t, tt.wantIs, is)
})
}
Expand Down

0 comments on commit 233ced4

Please sign in to comment.