-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding genesis validation + tests (#561)
* feat: adding genesis validation + tests * fix: imports * Update modules/apps/29-fee/types/genesis.go * fix: nit * Update modules/apps/29-fee/types/genesis_test.go Co-authored-by: Aditya <[email protected]> * nit: imporve default gen val test * chore: move packetId + val to channeltypes and use validate fn Co-authored-by: Aditya <[email protected]>
- Loading branch information
1 parent
d419972
commit 4dbc83e
Showing
6 changed files
with
253 additions
and
58 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
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 |
---|---|---|
@@ -1,49 +1,186 @@ | ||
package types_test | ||
|
||
/* | ||
import ( | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/require" | ||
"github.com/tendermint/tendermint/crypto/secp256k1" | ||
|
||
"github.com/cosmos/ibc-go/modules/apps/transfer/types" | ||
"github.com/cosmos/ibc-go/modules/apps/29-fee/types" | ||
channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" | ||
ibctesting "github.com/cosmos/ibc-go/testing" | ||
) | ||
|
||
var ( | ||
addr1 = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() | ||
addr2 = sdk.AccAddress("testaddr2").String() | ||
validCoins = sdk.Coins{sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)}} | ||
validCoins2 = sdk.Coins{sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(200)}} | ||
validCoins3 = sdk.Coins{sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(300)}} | ||
) | ||
|
||
func TestValidateGenesis(t *testing.T) { | ||
var ( | ||
packetId *channeltypes.PacketId | ||
fee types.Fee | ||
refundAcc string | ||
sender string | ||
counterparty string | ||
portID string | ||
channelID string | ||
seq uint64 | ||
) | ||
|
||
testCases := []struct { | ||
name string | ||
genState *types.GenesisState | ||
malleate func() | ||
expPass bool | ||
}{ | ||
{ | ||
name: "default", | ||
genState: types.DefaultGenesisState(), | ||
expPass: true, | ||
"valid genesis", | ||
func() {}, | ||
true, | ||
}, | ||
{ | ||
"valid genesis", | ||
&types.GenesisState{ | ||
PortId: "portidone", | ||
"invalid packetId: invalid channel", | ||
func() { | ||
packetId = channeltypes.NewPacketId( | ||
"", | ||
portID, | ||
seq, | ||
) | ||
}, | ||
true, | ||
false, | ||
}, | ||
{ | ||
"invalid packetId: invalid port", | ||
func() { | ||
packetId = channeltypes.NewPacketId( | ||
channelID, | ||
"", | ||
seq, | ||
) | ||
}, | ||
false, | ||
}, | ||
{ | ||
"invalid client", | ||
&types.GenesisState{ | ||
PortId: "(INVALIDPORT)", | ||
"invalid packetId: invalid sequence", | ||
func() { | ||
packetId = channeltypes.NewPacketId( | ||
channelID, | ||
portID, | ||
0, | ||
) | ||
}, | ||
false, | ||
}, | ||
{ | ||
"invalid packetId: invalid fee", | ||
func() { | ||
fee = types.Fee{ | ||
sdk.Coins{}, | ||
sdk.Coins{}, | ||
sdk.Coins{}, | ||
} | ||
}, | ||
false, | ||
}, | ||
{ | ||
"invalid packetId: invalid refundAcc", | ||
func() { | ||
refundAcc = "" | ||
}, | ||
false, | ||
}, | ||
{ | ||
"invalid FeeEnabledChannel: invalid ChannelID", | ||
func() { | ||
channelID = "" | ||
}, | ||
false, | ||
}, | ||
{ | ||
"invalid FeeEnabledChannel: invalid PortID", | ||
func() { | ||
portID = "" | ||
}, | ||
false, | ||
}, | ||
{ | ||
"invalid RegisteredRelayers: invalid sender", | ||
func() { | ||
sender = "" | ||
}, | ||
false, | ||
}, | ||
{ | ||
"invalid RegisteredRelayers: invalid counterparty", | ||
func() { | ||
counterparty = "" | ||
}, | ||
false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
err := tc.genState.Validate() | ||
portID = types.PortID | ||
channelID = ibctesting.FirstChannelID | ||
seq = uint64(1) | ||
|
||
// build PacketId & Fee | ||
packetId = channeltypes.NewPacketId( | ||
portID, | ||
channelID, | ||
seq, | ||
) | ||
fee = types.Fee{ | ||
validCoins, | ||
validCoins2, | ||
validCoins3, | ||
} | ||
|
||
refundAcc = addr1 | ||
|
||
// relayer addresses | ||
sender = addr1 | ||
counterparty = addr2 | ||
|
||
tc.malleate() | ||
|
||
genState := types.GenesisState{ | ||
IdentifiedFees: []*types.IdentifiedPacketFee{ | ||
{ | ||
PacketId: packetId, | ||
Fee: fee, | ||
RefundAddress: refundAcc, | ||
Relayers: nil, | ||
}, | ||
}, | ||
FeeEnabledChannels: []*types.FeeEnabledChannel{ | ||
{ | ||
PortId: portID, | ||
ChannelId: channelID, | ||
}, | ||
}, | ||
RegisteredRelayers: []*types.RegisteredRelayerAddress{ | ||
{ | ||
Address: sender, | ||
CounterpartyAddress: counterparty, | ||
}, | ||
}, | ||
} | ||
|
||
err := genState.Validate() | ||
if tc.expPass { | ||
require.NoError(t, err, tc.name) | ||
} else { | ||
require.Error(t, err, tc.name) | ||
} | ||
} | ||
} | ||
*/ | ||
|
||
func TestValidateDefaultGenesis(t *testing.T) { | ||
err := types.DefaultGenesisState().Validate() | ||
require.NoError(t, err) | ||
} |
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
Oops, something went wrong.