Skip to content

Commit

Permalink
Merge branch 'develop' into test/monitoringp-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis authored Apr 22, 2022
2 parents c838d5e + 8a4a18e commit ddf3c6f
Show file tree
Hide file tree
Showing 12 changed files with 411 additions and 68 deletions.
2 changes: 1 addition & 1 deletion pkg/types/consensus_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func NewConsensusState(timestamp, nextValHash, rootHash string) ConsensusState {
return ConsensusState{
NextValidatorsHash: nextValHash,
Timestamp: timestamp,
Root: MerkelRool{
Root: MerkleRoot{
Hash: rootHash,
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/consensus_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func TestConsensusState_RootHash(t *testing.T) {
csf := types.ConsensusState{
NextValidatorsHash: "foo",
Root: types.MerkelRool{
Root: types.MerkleRoot{
Hash: "bar",
},
Timestamp: "foobar",
Expand Down
104 changes: 52 additions & 52 deletions pkg/types/ibc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions proto/types/ibc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import "gogoproto/gogo.proto";

option go_package = "github.com/tendermint/spn/pkg/types";

// MerkelRool represents a Merkel Root in ConsensusState
message MerkelRool {
// MerkleRoot represents a Merkle Root in ConsensusState
message MerkleRoot {
string hash = 1;
}

Expand All @@ -15,7 +15,7 @@ message MerkelRool {
message ConsensusState {
string nextValidatorsHash = 1;
string timestamp = 2;
MerkelRool root = 3 [(gogoproto.nullable) = false];
MerkleRoot root = 3 [(gogoproto.nullable) = false];
}


Expand Down
6 changes: 3 additions & 3 deletions x/campaign/simulation/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func SimulateMsgBurnVouchers(
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
campID, simAccount, vouchers, found := GetAccountWithVouchers(ctx, bk, k, accs, false)
campID, simAccount, vouchers, found := GetAccountWithVouchers(r, ctx, bk, k, accs, false)
if !found {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBurnVouchers, "skip burn vouchers"), nil, nil
}
Expand All @@ -292,7 +292,7 @@ func SimulateMsgRedeemVouchers(
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
campID, simAccount, vouchers, found := GetAccountWithVouchers(ctx, bk, k, accs, true)
campID, simAccount, vouchers, found := GetAccountWithVouchers(r, ctx, bk, k, accs, true)
if !found {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgRedeemVouchers, "skip redeem vouchers"), nil, nil
}
Expand Down Expand Up @@ -343,7 +343,7 @@ func SimulateMsgSendVouchers(
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
_, simAccount, vouchers, found := GetAccountWithVouchers(ctx, bk, k, accs, false)
_, simAccount, vouchers, found := GetAccountWithVouchers(r, ctx, bk, k, accs, false)
if !found {
return simtypes.NoOpMsg(banktypes.ModuleName, banktypes.TypeMsgSend, "skip send vouchers"), nil, nil
}
Expand Down
10 changes: 6 additions & 4 deletions x/campaign/simulation/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func GetSharesFromCampaign(r *rand.Rand, ctx sdk.Context, k keeper.Keeper, campI

// GetAccountWithVouchers returns an account that has vouchers for a campaign
func GetAccountWithVouchers(
r *rand.Rand,
ctx sdk.Context,
bk types.BankKeeper,
k keeper.Keeper,
Expand Down Expand Up @@ -178,10 +179,11 @@ func GetAccountWithVouchers(
bk.IterateAccountBalances(ctx, accountAddr, func(coin sdk.Coin) bool {
coinCampID, err := types.VoucherCampaign(coin.Denom)
if err == nil && coinCampID == campID {
// retain a random portion of the balance in the range [0, coin.Amount)
retainAmt := sdk.NewInt(rand.Int63n(coin.Amount.Int64()))
coin.Amount = coin.Amount.Sub(retainAmt)
coins = append(coins, coin)
// fetch a part of each voucher hold by the account
amt, err := simtypes.RandPositiveInt(r, coin.Amount)
if err == nil {
coins = append(coins, sdk.NewCoin(coin.Denom, amt))
}
}
return false
})
Expand Down
6 changes: 3 additions & 3 deletions x/campaign/simulation/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func TestGetAccountWithVouchers(t *testing.T) {
}

t.Run("no account", func(t *testing.T) {
_, _, _, found := simcampaign.GetAccountWithVouchers(ctx, tk.BankKeeper, *tk.CampaignKeeper, accs, false)
_, _, _, found := simcampaign.GetAccountWithVouchers(r, ctx, tk.BankKeeper, *tk.CampaignKeeper, accs, false)
require.False(t, found)
})

Expand All @@ -236,7 +236,7 @@ func TestGetAccountWithVouchers(t *testing.T) {
campaign.MainnetID = tk.LaunchKeeper.AppendChain(ctx, chain)
campaign.CampaignID = tk.CampaignKeeper.AppendCampaign(ctx, campaign)
mint(acc.Address, sample.Vouchers(r, campaign.CampaignID))
campID, acc, coins, found := simcampaign.GetAccountWithVouchers(ctx, tk.BankKeeper, *tk.CampaignKeeper, accs, false)
campID, acc, coins, found := simcampaign.GetAccountWithVouchers(r, ctx, tk.BankKeeper, *tk.CampaignKeeper, accs, false)
require.True(t, found)
require.EqualValues(t, campaign.CampaignID, campID)
require.False(t, coins.Empty())
Expand All @@ -249,7 +249,7 @@ func TestGetAccountWithVouchers(t *testing.T) {
campaign.MainnetInitialized = false
campaign.CampaignID = tk.CampaignKeeper.AppendCampaign(ctx, campaign)
mint(acc.Address, sample.Vouchers(r, campaign.CampaignID))
campID, acc, coins, found := simcampaign.GetAccountWithVouchers(ctx, tk.BankKeeper, *tk.CampaignKeeper, accs, true)
campID, acc, coins, found := simcampaign.GetAccountWithVouchers(r, ctx, tk.BankKeeper, *tk.CampaignKeeper, accs, true)
require.True(t, found)
require.EqualValues(t, campaign.CampaignID, campID)
require.False(t, coins.Empty())
Expand Down
65 changes: 65 additions & 0 deletions x/monitoringc/keeper/grpc_verified_client_ids_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package keeper_test

import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

testkeeper "github.com/tendermint/spn/testutil/keeper"
"github.com/tendermint/spn/testutil/nullify"
"github.com/tendermint/spn/x/monitoringc/types"
)

func TestVerifiedClientIds(t *testing.T) {
ctx, tk, _ := testkeeper.NewTestSetup(t)
wctx := sdk.WrapSDKContext(ctx)
items := createNVerifiedClientID(ctx, tk.MonitoringConsumerKeeper, 2)
for _, tc := range []struct {
desc string
request *types.QueryGetVerifiedClientIdsRequest
response *types.QueryGetVerifiedClientIdsResponse
err error
}{
{
desc: "first",
request: &types.QueryGetVerifiedClientIdsRequest{
LaunchID: items[0].LaunchID,
},
response: &types.QueryGetVerifiedClientIdsResponse{ClientIds: items[0].ClientIDs},
},
{
desc: "second",
request: &types.QueryGetVerifiedClientIdsRequest{
LaunchID: items[1].LaunchID,
},
response: &types.QueryGetVerifiedClientIdsResponse{ClientIds: items[1].ClientIDs},
},
{
desc: "key not found",
request: &types.QueryGetVerifiedClientIdsRequest{
LaunchID: 100000,
},
err: status.Error(codes.Internal, "launch id not found 100000"),
},
{
desc: "invalid request",
err: status.Error(codes.InvalidArgument, "invalid request"),
},
} {
t.Run(tc.desc, func(t *testing.T) {
response, err := tk.MonitoringConsumerKeeper.VerifiedClientIds(wctx, tc.request)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
} else {
require.NoError(t, err)
require.Equal(t,
nullify.Fill(tc.response),
nullify.Fill(response),
)
}
})
}
}
Loading

0 comments on commit ddf3c6f

Please sign in to comment.