Skip to content

Commit

Permalink
fix abci test
Browse files Browse the repository at this point in the history
  • Loading branch information
trinitys7 committed Jul 9, 2024
1 parent 01165ea commit b428fa6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
50 changes: 50 additions & 0 deletions tests/e2e/zero_max_cap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package e2e

import (
// "encoding/base64"
// "fmt"
// "strconv"
"testing"
// "time"

// "github.com/cometbft/cometbft/libs/rand"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

// "cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
// "github.com/cosmos/cosmos-sdk/types/address"
// distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
// distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
)

func TestZeroMaxCapScenario1(t *testing.T) {
// scenario:
// given a provider chain P and a consumer chain C
// some amount has been "cross stake" on chain C
// a proposal is created to change max cap to zero
// all delegations will be unstake in one epoch

x := setupExampleChains(t)
consumerCli, consumerContracts, providerCli := setupMeshSecurity(t, x)

// the active set should be stored in the ext staking contract
// and contain all active validator addresses
qRsp := providerCli.QueryExtStaking(Query{"list_active_validators": {}})
require.Len(t, qRsp["validators"], 4, qRsp)
for _, v := range x.ConsumerChain.Vals.Validators {
require.Contains(t, qRsp["validators"], sdk.ValAddress(v.Address).String())
}

// ----------------------------
// ensure nothing staked by the virtual staking contract yet
myExtValidator := sdk.ValAddress(x.ConsumerChain.Vals.Validators[1].Address)
// myExtValidatorAddr := myExtValidator.String()
_, found := x.ConsumerApp.StakingKeeper.GetDelegation(x.ConsumerChain.GetContext(), consumerContracts.staking, myExtValidator)
require.False(t, found)

// the max cap limit is persisted
rsp := consumerCli.QueryMaxCap()
assert.Equal(t, sdk.NewInt64Coin(x.ConsumerDenom, 1_000_000_000), rsp.Cap)
}
2 changes: 1 addition & 1 deletion x/meshsecurity/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestEndBlocker(t *testing.T) {
assert: func(t *testing.T, ctx sdk.Context) {
require.Len(t, capturedCalls, 2)
assert.Equal(t, myContractAddr, capturedCalls[0].contractAddress)
exp := fmt.Sprintf(`{"valset_update":{"additions":[{"address":"%s","commission":"0.000000000000000000","max_commission":"0.000000000000000000","max_change_rate":"0.000000000000000000"}],"removals":[],"updated":[],"jailed":[],"unjailed":[],"slashed":[],"tombstoned":[]}}`, val1.GetOperator())
exp := fmt.Sprintf(`{"handle_valset_update":{"additions":[{"address":"%s","commission":"0.000000000000000000","max_commission":"0.000000000000000000","max_change_rate":"0.000000000000000000"}],"removals":[],"updated":[],"jailed":[],"unjailed":[],"slashed":[],"tombstoned":[]}}`, val1.GetOperator())
assert.JSONEq(t, exp, string(capturedCalls[0].msg))

assert.Equal(t, myOtherContractAddr, capturedCalls[1].contractAddress)
Expand Down

0 comments on commit b428fa6

Please sign in to comment.