Skip to content

Commit

Permalink
fix mvp test and compile error
Browse files Browse the repository at this point in the history
  • Loading branch information
trinitys7 committed Aug 19, 2024
1 parent 9c03e66 commit b5a7291
Show file tree
Hide file tree
Showing 17 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion tests/e2e/mvp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestMVP(t *testing.T) {
// ==============
// Deposit - A user deposits the vault denom to provide some collateral to their account
execMsg := fmt.Sprintf(`{"bond":{"amount":{"denom":"%s", "amount":"100000000"}}}`, x.ProviderDenom)
providerCli.MustExecVault(execMsg)
providerCli.MustExecVault(execMsg, sdk.NewCoin(x.ProviderDenom, sdk.NewInt(100000000)))

// then query contract state
assert.Equal(t, 100_000_000, providerCli.QueryVaultFreeBalance())
Expand Down
7 changes: 4 additions & 3 deletions tests/e2e/slashing_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package e2e

import (
"cosmossdk.io/math"
"encoding/base64"
"fmt"
"testing"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)

func TestSlashingScenario1(t *testing.T) {
Expand All @@ -22,7 +23,7 @@ func TestSlashingScenario1(t *testing.T) {
// ==============
// Deposit - A user deposits the vault denom to provide some collateral to their account
execMsg := fmt.Sprintf(`{"bond":{"amount":{"denom":"%s", "amount":"200000000"}}}`, x.ProviderDenom)
providerCli.MustExecVault(execMsg)
providerCli.MustExecVault(execMsg, sdk.NewCoin(x.ProviderDenom, sdk.NewInt(200000000)))

// Stake Locally - A user triggers a local staking action to a chosen validator.
myLocalValidatorAddr := sdk.ValAddress(x.ProviderChain.Vals.Validators[0].Address).String()
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/test_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (p *TestConsumerClient) BootstrapContracts() ConsumerContract {
virtStakeCodeID := p.chain.StoreCodeFile(buildPathToWasm("mesh_virtual_staking.wasm")).CodeID
// instantiate converter
codeID = p.chain.StoreCodeFile(buildPathToWasm("mesh_converter.wasm")).CodeID
initMsg = []byte(fmt.Sprintf(`{"price_feed": %q, "discount": %q, "remote_denom": %q,"virtual_staking_code_id": %d}`,
initMsg = []byte(fmt.Sprintf(`{"price_feed": %q, "discount": %q, "remote_denom": %q,"virtual_staking_code_id": %d, "tombstoned_unbond_enable": true}`,
priceFeedContract.String(), discount, remoteDenom, virtStakeCodeID))
converterContract := InstantiateContract(p.t, p.chain, codeID, initMsg)

Expand Down
Binary file modified tests/testdata/mesh_converter.wasm.gz
Binary file not shown.
Binary file modified tests/testdata/mesh_external_staking.wasm.gz
Binary file not shown.
Binary file modified tests/testdata/mesh_native_staking.wasm.gz
Binary file not shown.
Binary file modified tests/testdata/mesh_native_staking_proxy.wasm.gz
Binary file not shown.
Binary file modified tests/testdata/mesh_osmosis_price_provider.wasm.gz
Binary file not shown.
Binary file modified tests/testdata/mesh_remote_price_feed.wasm.gz
Binary file not shown.
Binary file modified tests/testdata/mesh_simple_price_feed.wasm.gz
Binary file not shown.
Binary file modified tests/testdata/mesh_vault.wasm.gz
Binary file not shown.
Binary file modified tests/testdata/mesh_virtual_staking.wasm.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/testdata/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
34284a38601ff132e8d7b5594a87794faa71bbed
e8d2571a5e581d53921cb12be56a8d29b53a5c7c
2 changes: 1 addition & 1 deletion x/meshsecurity/contract/out_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type (
Power int64 `json:"power"`
SlashAmount string `json:"slash_amount"`
SlashRatio string `json:"slash_ratio"`
IsTomestoned bool `json:"is_tomestoned"`
IsTombstoned bool `json:"is_tombstoned"`
}

// ValsetUpdate updates to the active validator set
Expand Down
16 changes: 8 additions & 8 deletions x/meshsecurity/keeper/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,18 @@ func NewStakingDecorator(stakingKeeper slashingtypes.StakingKeeper, k *Keeper) *
}

// Slash captures the slash event and calls the decorated staking keeper slash method
func (s StakingDecorator) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, power int64, height int64, slashRatio sdk.Dec, infraction stakingtypes.Infraction) math.Int {
func (s StakingDecorator) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeight int64, power int64, slashFactor sdk.Dec) math.Int {
return s.SlashWithInfractionReason(ctx, consAddr, infractionHeight, power, slashFactor, stakingtypes.Infraction_INFRACTION_UNSPECIFIED)
}

// SlashWithInfractionReason implementation doesn't require the infraction (types.Infraction) to work but is required by Interchain Security.
func (s StakingDecorator) SlashWithInfractionReason(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeight int64, power int64, slashFactor sdk.Dec, infraction stakingtypes.Infraction) math.Int {
val := s.StakingKeeper.ValidatorByConsAddr(ctx, consAddr)
totalSlashAmount := s.StakingKeeper.Slash(ctx, consAddr, power, height, slashRatio)
totalSlashAmount := s.StakingKeeper.Slash(ctx, consAddr, infractionHeight, power, slashFactor)
if val == nil {
ModuleLogger(ctx).
Error("can not propagate slash: validator not found", "validator", consAddr.String())
} else if err := s.k.ScheduleSlashed(ctx, val.GetOperator(), power, height, totalSlashAmount, slashRatio, infraction); err != nil {
} else if err := s.k.ScheduleSlashed(ctx, val.GetOperator(), power, infractionHeight, totalSlashAmount, slashFactor, infraction); err != nil {
ModuleLogger(ctx).
Error("can not propagate slash: schedule event",
"cause", err,
Expand All @@ -129,11 +134,6 @@ func (s StakingDecorator) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, power
return totalSlashAmount
}

// SlashWithInfractionReason implementation doesn't require the infraction (types.Infraction) to work but is required by Interchain Security.
func (s StakingDecorator) SlashWithInfractionReason(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeight int64, power int64, slashFactor sdk.Dec, infraction stakingtypes.Infraction) math.Int {
return s.Slash(ctx, consAddr, infractionHeight, power, slashFactor, infraction)
}

// Jail captures the jail event and calls the decorated staking keeper jail method
func (s StakingDecorator) Jail(ctx sdk.Context, consAddr sdk.ConsAddress) {
val := s.StakingKeeper.ValidatorByConsAddr(ctx, consAddr)
Expand Down
2 changes: 1 addition & 1 deletion x/meshsecurity/keeper/valset_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (k Keeper) ValsetUpdateReport(ctx sdk.Context) (contract.ValsetUpdate, erro
Time: ctx.BlockTime().Unix(),
SlashAmount: slashAmount,
SlashRatio: slashRatio,
IsTomestoned: infraction == int32(stakingtypes.Infraction_INFRACTION_DOUBLE_SIGN),
IsTombstoned: infraction == int32(stakingtypes.Infraction_INFRACTION_DOUBLE_SIGN),
}
*set = append(*set, valSlash)
return false
Expand Down
2 changes: 1 addition & 1 deletion x/meshsecurity/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func BuildPipedValsetOpKey(op PipedValsetOperation, val sdk.ValAddress, slashInf
if slashInfo == nil {
panic("slash info is nil")
}
sn = 8 + 8 + 1 + len(slashInfo.TotalSlashAmount) + len(slashInfo.SlashFraction) // 8 for height, 8 for power, +1 for total amount length
sn = 8 + 8 + 4 + 1 + len(slashInfo.TotalSlashAmount) + len(slashInfo.SlashFraction) // 8 for height, 8 for power, 4 for infraction, +1 for total amount length
}
r := make([]byte, pn+an+sn+1+1) // +1 for address prefix, +1 for op
copy(r, PipedValsetPrefix)
Expand Down

0 comments on commit b5a7291

Please sign in to comment.