diff --git a/note.json b/note.json new file mode 100644 index 00000000..24d852c5 --- /dev/null +++ b/note.json @@ -0,0 +1,155 @@ +{ + "stake": { + "delegator": "cosmos1ph3tq3s5afcg6z4c4mpd9kdklt9a8j7gw8sygn", + "validator": "cosmosvaloper1gtnfjqp6pgkdu6szu5rzk4h5z5d54fadcfsv90", + "stake": { + "denom": "stake", + "amount": "20000000" + }, + "tx_id": 2 + } +} + +[ + Execute { + contract_addr: "cosmos1qg5ega6dykkxc307y25pecuufrjkxkaggkkxh7nad0vhyhtuhw3s6ufdm4", + msg: { + "internal_unstake":{ + "delegator":"cosmos1whqnmupfwm3gfmvjegy0j69z42mfngmg2q8emj", + "validator":"cosmosvaloper1jgaec5l7glsy2l37n25kmqj7p9hrfzsh43df3u", + "amount":{"denom":"stake","amount":"22500000"}} + }, + funds: [] + }, + Execute { + contract_addr: "cosmos1qg5ega6dykkxc307y25pecuufrjkxkaggkkxh7nad0vhyhtuhw3s6ufdm4", + msg: { + "internal_unstake":{ + "delegator":"cosmos1whqnmupfwm3gfmvjegy0j69z42mfngmg2q8emj", + "validator":"cosmosvaloper1mt78w786v2qz24skefvv6x3xulq4495egj33yc", + "amount":{"denom":"stake","amount":"9000000"}}}, funds: [] }] + +panic: +failed to execute scheduled task for contract +"cosmos1xr3rq8yvd7qplsw5yx90ftsr2zdhg4e9z60h5duusgxpv72hud3s493rn8": +execution: {Loading CosmWasm module: execute}: panic [recovered] + +routes: map[ + /cosmos.auth.v1beta1.MsgUpdateParams:0x10378c850 + /cosmos.authz.v1beta1.MsgExec:0x10378c850 + /cosmos.authz.v1beta1.MsgGrant:0x10378c850 + /cosmos.authz.v1beta1.MsgRevoke:0x10378c850 + /cosmos.bank.v1beta1.MsgMultiSend:0x10378c850 + /cosmos.bank.v1beta1.MsgSend:0x10378c850 + /cosmos.bank.v1beta1.MsgSetSendEnabled:0x10378c850 + /cosmos.bank.v1beta1.MsgUpdateParams:0x10378c850 + /cosmos.consensus.v1.MsgUpdateParams:0x10378c850 + /cosmos.crisis.v1beta1.MsgUpdateParams:0x10378c850 + /cosmos.crisis.v1beta1.MsgVerifyInvariant:0x10378c850 + /cosmos.distribution.v1beta1.MsgCommunityPoolSpend:0x10378c850 + /cosmos.distribution.v1beta1.MsgFundCommunityPool:0x10378c850 + /cosmos.distribution.v1beta1.MsgSetWithdrawAddress:0x10378c850 + /cosmos.distribution.v1beta1.MsgUpdateParams:0x10378c850 + /cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward:0x10378c850 / + cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission:0x10378c850 + /cosmos.evidence.v1beta1.MsgSubmitEvidence:0x10378c850 + /cosmos.feegrant.v1beta1.MsgGrantAllowance:0x10378c8 +50 /cosmos.feegrant.v1beta1.MsgRevokeAllowance:0x10378c850 + /cosmos.gov.v1.MsgDeposit:0x10378c850 + /cosmos.gov.v1.MsgExecLegacyContent:0x10378c850 + /cosmos.gov.v1.MsgSubmitProposal:0x10378c850 + /cosmos.gov.v1.MsgUpdateParams:0x10378c850 + /cosmos.gov.v1.MsgVote:0x10378c850 + /cosmos.gov.v1.MsgVoteWeighted:0x10378c850 + /cosmos.gov.v1beta1.MsgDeposit:0x10378c850 + /cosmos.gov.v1beta1.MsgSubmitProposal:0x10378c850 + /cosmos.gov.v1beta1.MsgVote:0x10378c850 + /cosmos.gov.v1beta1.MsgVoteWeighted:0x10378c850 + /cosmos.group.v1.MsgCreateGroup:0x10378c850 + /cosmos.group.v1.MsgCreateGroupPolicy:0x10378c850 + /cosmos.group.v1.MsgCreateGroupWithPolicy:0x10378c850 + /cosmos.group.v1.MsgExec:0x10378c850 + /cosmos.group.v1.MsgLeaveGroup:0x10378c850 + /cosmos.group.v1.MsgSubmitProposal:0x10378c850 + /cosmos.group.v1.MsgUpdateGroupAdmin:0x10378c850 + /cosmos.group.v1.MsgUpdateGroupMembers:0x10378c850 + /cosmos.group.v1.MsgUpdateGroupMetadata:0x10378c850 + /cosmos.group.v1.MsgUpdateGroupPolicyAdmin:0x10378c850 + /cosmos.group.v1.MsgUpdateGroupPolicyDecisionPolicy:0x10378c850 + /cosmos.group.v1.MsgUpdateGroupPolicyMetadata:0x10378c850 + /cosmos.group.v1.MsgVote:0x10378c850 + /cosmos.group.v1.MsgWithdrawProposal:0x10378c850 + /cosmos.mint.v1beta1.MsgUpdateParams:0x10378c850 + /cosmos.nft.v1beta1.MsgSend:0x10378c850 + /cosmos.slashing.v1beta1.MsgUnjail:0x10378c850 + /cosmos.slashing.v1beta1.MsgUpdateParams:0x10378c850 + /cosmos.staking.v1beta1.MsgBeginRedelegate:0x10378c850 + /cosmos.staking.v1beta1.MsgCancelUnbondingDelegation:0x10378c850 + /cosmos.staking.v1beta1.MsgCreateValidator:0x10378c850 + /cosmos.staking.v1beta1.MsgDelegate:0x10378c850 + /cosmos.staking.v1beta1.MsgEditValidator:0x10378c850 + /cosmos.staking.v1beta1.MsgUndelegate:0x10378c850 + /cosmos.staking.v1beta1.MsgUpdateParams:0x10378c850 + /cosmos.upgrade.v1beta1.MsgCancelUpgrade:0x10378c850 + /cosmos.upgrade.v1beta1.MsgSoftwareUpgrade:0x10378c850 + /cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount:0x10378c850 + /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount:0x10378c850 + /cosmos.vesting.v1beta1.MsgCreateVestingAccount:0x10378c850 + /cosmwasm.wasm.v1.MsgAddCodeUploadParamsAddresses:0x10378c850 + /cosmwasm.wasm.v1.MsgClearAdmin:0x10378c850 + /cosmwasm.wasm.v1.MsgExecuteContract:0x10378c850 + /cosmwasm.wasm.v1.MsgInstantiateContract:0x10378c850 + /cosmwasm.wasm.v1.MsgInstantiateContract2:0x10378c850 + /cosmwasm.wasm.v1.MsgMigrateContract:0x10378c850 + /cosmwasm.wasm.v1.MsgPinCodes:0x10378c850 + /cosmwasm.wasm.v1.MsgRemoveCodeUploadParamsAddresses:0x10378c850 + /cosmwasm.wasm.v1.MsgStoreAndInstantiateContract:0x10378c850 + /cosmwasm.wasm.v1.MsgStoreAndMigrateContract:0x10378c850 + /cosmwasm.wasm.v1.MsgStoreCode:0x10378c850 + /cosmwasm.wasm.v1.MsgSudoContract:0x10378c850 + /cosmwasm.wasm.v1.MsgUnpinCodes:0x10378c850 + /cosmwasm.wasm.v1.MsgUpdateAdmin:0x10378c850 + /cosmwasm.wasm.v1.MsgUpdateContractLabel:0x10378c850 + /cosmwasm.wasm.v1.MsgUpdateInstantiateConfig:0x10378c850 + /cosmwasm.wasm.v1.MsgUpdateParams:0x10378c850 + /ibc.applications.fee.v1.MsgPayPacketFee:0x10378c850 + /ibc.applications.fee.v1.MsgPayPacketFeeAsync:0x10378c850 + /ibc.applications.fee.v1.MsgRegisterCounterpartyPayee:0x10378c850 + /ibc.applications.fee.v1.MsgRegisterPayee:0x10378c850 + /ibc.applications.interchain_accounts.controller.v1.MsgRegisterInterchainAccount:0x10378c850 + /ibc.applications.interchain_accounts.controller.v1.MsgSendTx:0x10378c850 + /ibc.applications.transfer.v1.MsgTransfer:0x10378c850 + /ibc.core.channel.v1.MsgAcknowledgement:0x10378c850 + /ibc.core.channel.v1.MsgChannelCloseConfirm:0x10378c850 + /ibc.core.channel.v1.MsgChannelCloseInit:0x10378c850 + /ibc.core.channel.v1.MsgChannelOpenAck:0x10378c850 + /ibc.core.channel.v1.MsgChannelOpenConfirm:0x10378c850 + /ibc.core.channel.v1.MsgChannelOpenInit:0x10378c850 + /ibc.core.channel.v1.MsgChannelOpenTry:0x10378c850 + /ibc.core.channel.v1.MsgRecvPacket:0x10378c850 + /ibc.core.channel.v1.MsgTimeout:0x10378c850 + /ibc.core.channel.v1.MsgTimeoutOnClose:0x10378c850 + /ibc.core.client.v1.MsgCreateClient:0x10378c850 + /ibc.core.client.v1.MsgSubmitMisbehaviour:0x10378c850 + /ibc.core.client.v1.MsgUpdateClient:0x10378c850 + /ibc.core.client.v1.MsgUpgradeClient:0x10378c850 + /ibc.core.connection.v1.MsgConnectionOpenAck:0x10378c850 + /ibc.core.connection.v1.MsgConnectionOpenConfirm:0x10378c850 + /ibc.core.connection.v1.MsgConnectionOpenInit:0x10378c850 + /ibc.core.connection.v1.MsgConnectionOpenTry:0x10378c850 + /osmosis.meshsecurity.v1beta1.MsgSetVirtualStakingMaxCap:0x10378c850] + + + Cannot unbond 49999999 tokens from validator cosmosvaloper1fhm5lj9wcvxwdxmgtz36mnjuhwtk7ly93c3rqg, not enough staked + + data: { + "internal_unstake":{ + "delegator":"cosmos1yw0saxm7nkwl0e8r3kqpar2a0vusdzcaku8mys", + "validator":"cosmosvaloper1szy96jnddalx7s686e4ylres02uv6a5dyxj82c", + "normalize_amount":{"denom":"stake","amount":"9000000"}, + "inverted_amount":{"denom":"stake","amount":"19999999"} + } + } + + failed to execute message; message index: 0: acknowledge packet callback failed: on ack: submessages: Error calling the VM: Error executing Wasm: Wasmer runtime error: RuntimeError: + Aborted: panicked at contracts/consumer/virtual-staking/src/contract.rs:519:9: \ No newline at end of file diff --git a/tests/e2e/mvp_test.go b/tests/e2e/mvp_test.go index 2f330110..aa89b92c 100644 --- a/tests/e2e/mvp_test.go +++ b/tests/e2e/mvp_test.go @@ -36,7 +36,6 @@ func TestMVP(t *testing.T) { // ... x := setupExampleChains(t) consumerCli, consumerContracts, providerCli := setupMeshSecurity(t, x) - sender := x.ProviderChain.SenderAccount.GetAddress() // then the active set should be stored in the ext staking contract // and contain all active validator addresses qRsp := providerCli.QueryExtStaking(Query{"list_active_validators": {}}) @@ -75,13 +74,13 @@ func TestMVP(t *testing.T) { assert.Equal(t, 70_000_000, providerCli.QueryVaultFreeBalance()) // Failure mode of cross-stake... trying to stake to an unknown validator - err := providerCli.ExecStakeRemote(sender, "BAD-VALIDATOR", sdk.NewInt64Coin(x.ProviderDenom, 80_000_000)) + err := providerCli.ExecStakeRemote("BAD-VALIDATOR", sdk.NewInt64Coin(x.ProviderDenom, 80_000_000)) require.Error(t, err) // no change to free balance assert.Equal(t, 70_000_000, providerCli.QueryVaultFreeBalance()) // Cross Stake - A user pulls out additional liens on the same collateral "cross staking" it on different chains. - err = providerCli.ExecStakeRemote(sender, myExtValidatorAddr, sdk.NewInt64Coin(x.ProviderDenom, 80_000_000)) + err = providerCli.ExecStakeRemote(myExtValidatorAddr, sdk.NewInt64Coin(x.ProviderDenom, 80_000_000)) require.NoError(t, err) require.NoError(t, x.Coordinator.RelayAndAckPendingPackets(x.IbcPath)) diff --git a/tests/e2e/slashing_test.go b/tests/e2e/slashing_test.go index 4c391eff..31bcba4b 100644 --- a/tests/e2e/slashing_test.go +++ b/tests/e2e/slashing_test.go @@ -18,7 +18,6 @@ func TestSlashingScenario1(t *testing.T) { // - We use millions instead of unit tokens. x := setupExampleChains(t) consumerCli, _, providerCli := setupMeshSecurity(t, x) - sender := x.ProviderChain.SenderAccount.GetAddress() // Provider chain // ============== // Deposit - A user deposits the vault denom to provide some collateral to their account @@ -37,11 +36,11 @@ func TestSlashingScenario1(t *testing.T) { // Cross Stake - A user pulls out additional liens on the same collateral "cross staking" it on different chains. myExtValidator1 := sdk.ValAddress(x.ConsumerChain.Vals.Validators[1].Address) myExtValidator1Addr := myExtValidator1.String() - err := providerCli.ExecStakeRemote(sender, myExtValidator1Addr, sdk.NewInt64Coin(x.ProviderDenom, 100_000_000)) + err := providerCli.ExecStakeRemote(myExtValidator1Addr, sdk.NewInt64Coin(x.ProviderDenom, 100_000_000)) require.NoError(t, err) myExtValidator2 := sdk.ValAddress(x.ConsumerChain.Vals.Validators[2].Address) myExtValidator2Addr := myExtValidator2.String() - err = providerCli.ExecStakeRemote(sender, myExtValidator2Addr, sdk.NewInt64Coin(x.ProviderDenom, 50_000_000)) + err = providerCli.ExecStakeRemote(myExtValidator2Addr, sdk.NewInt64Coin(x.ProviderDenom, 50_000_000)) require.NoError(t, err) require.NoError(t, x.Coordinator.RelayAndAckPendingPackets(x.IbcPath)) @@ -119,7 +118,6 @@ func TestSlashingScenario2(t *testing.T) { // - We use millions instead of unit tokens. x := setupExampleChains(t) consumerCli, _, providerCli := setupMeshSecurity(t, x) - sender := x.ProviderChain.SenderAccount.GetAddress() // Provider chain // ============== // Deposit - A user deposits the vault denom to provide some collateral to their account @@ -136,7 +134,7 @@ func TestSlashingScenario2(t *testing.T) { // Cross Stake - A user pulls out additional liens on the same collateral "cross staking" it on different chains. myExtValidator1 := sdk.ValAddress(x.ConsumerChain.Vals.Validators[1].Address) myExtValidator1Addr := myExtValidator1.String() - err := providerCli.ExecStakeRemote(sender, myExtValidator1Addr, sdk.NewInt64Coin(x.ProviderDenom, 200_000_000)) + err := providerCli.ExecStakeRemote(myExtValidator1Addr, sdk.NewInt64Coin(x.ProviderDenom, 200_000_000)) require.NoError(t, err) require.NoError(t, x.Coordinator.RelayAndAckPendingPackets(x.IbcPath)) @@ -207,7 +205,6 @@ func TestSlashingScenario3(t *testing.T) { // - We use millions instead of unit tokens. x := setupExampleChains(t) consumerCli, _, providerCli := setupMeshSecurity(t, x) - sender := x.ProviderChain.SenderAccount.GetAddress() // Provider chain // ============== // Deposit - A user deposits the vault denom to provide some collateral to their account @@ -224,7 +221,7 @@ func TestSlashingScenario3(t *testing.T) { // Cross Stake - A user pulls out additional liens on the same collateral "cross staking" it on different chains. myExtValidator1 := sdk.ValAddress(x.ConsumerChain.Vals.Validators[1].Address) myExtValidator1Addr := myExtValidator1.String() - err := providerCli.ExecStakeRemote(sender, myExtValidator1Addr, sdk.NewInt64Coin(x.ProviderDenom, 150_000_000)) + err := providerCli.ExecStakeRemote(myExtValidator1Addr, sdk.NewInt64Coin(x.ProviderDenom, 150_000_000)) require.NoError(t, err) require.NoError(t, x.Coordinator.RelayAndAckPendingPackets(x.IbcPath)) diff --git a/tests/e2e/test_client.go b/tests/e2e/test_client.go index 7641027e..cf3d7e26 100644 --- a/tests/e2e/test_client.go +++ b/tests/e2e/test_client.go @@ -21,9 +21,11 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/osmosis-labs/mesh-security-sdk/demo/app" "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity" + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/keeper" "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/types" ) @@ -244,11 +246,11 @@ func (p TestProviderClient) MustFailExecVault(payload string, funds ...sdk.Coin) return err } -func (p TestProviderClient) MustExecStakeRemote(sender sdk.AccAddress, val string, amt sdk.Coin) { - require.NoError(p.t, p.ExecStakeRemote(sender, val, amt)) +func (p TestProviderClient) MustExecStakeRemote(val string, amt sdk.Coin) { + require.NoError(p.t, p.ExecStakeRemote(val, amt)) } -func (p TestProviderClient) ExecStakeRemote(sender sdk.AccAddress, val string, amt sdk.Coin) error { +func (p TestProviderClient) ExecStakeRemote(val string, amt sdk.Coin) error { payload := fmt.Sprintf(`{"stake_remote":{"contract":"%s", "amount": {"denom":%q, "amount":"%s"}, "msg":%q}}`, p.Contracts.ExternalStaking.String(), amt.Denom, amt.Amount.String(), @@ -405,6 +407,15 @@ func (p *TestConsumerClient) ExecNewEpoch() { } } +func (p *TestConsumerClient) ExecSetMaxCap(cap sdk.Coin) { + msgServer := keeper.NewMsgServer(p.app.MeshSecKeeper) + msgServer.SetVirtualStakingMaxCap(p.chain.GetContext(), &types.MsgSetVirtualStakingMaxCap{ + Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), + Contract: p.contracts.staking.String(), + MaxCap: cap, + }) +} + // MustEnableVirtualStaking add authority to mint/burn virtual tokens gov proposal func (p *TestConsumerClient) MustEnableVirtualStaking(maxCap sdk.Coin) { govProposal := &types.MsgSetVirtualStakingMaxCap{ diff --git a/tests/e2e/zero_max_cap_test.go b/tests/e2e/zero_max_cap_test.go index 23c3cdae..60d0d13a 100644 --- a/tests/e2e/zero_max_cap_test.go +++ b/tests/e2e/zero_max_cap_test.go @@ -1,22 +1,15 @@ package e2e import ( - // "encoding/base64" - // "fmt" - // "strconv" + "fmt" "testing" - // "time" - // "github.com/cometbft/cometbft/libs/rand" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - // "cosmossdk.io/math" + "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) { @@ -39,12 +32,75 @@ func TestZeroMaxCapScenario1(t *testing.T) { // ---------------------------- // 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) + extValidator1 := sdk.ValAddress(x.ConsumerChain.Vals.Validators[1].Address) + extValidator1Addr := extValidator1.String() + + extValidator2 := sdk.ValAddress(x.ConsumerChain.Vals.Validators[2].Address) + extValidator2Addr := extValidator2.String() + + _, found := x.ConsumerApp.StakingKeeper.GetDelegation(x.ConsumerChain.GetContext(), consumerContracts.staking, extValidator1) 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) + + // provider chain + // ============== + // 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) + + // then query contract state + assert.Equal(t, 100_000_000, providerCli.QueryVaultFreeBalance()) + + // Cross Stake + err := providerCli.ExecStakeRemote(extValidator1Addr, sdk.NewInt64Coin(x.ProviderDenom, 50_000_000)) + require.NoError(t, err) + + require.NoError(t, x.Coordinator.RelayAndAckPendingPackets(x.IbcPath)) + require.Equal(t, 50_000_000, providerCli.QueryVaultFreeBalance()) + + err = providerCli.ExecStakeRemote(extValidator2Addr, sdk.NewInt64Coin(x.ProviderDenom, 20_000_000)) + require.NoError(t, err) + + require.NoError(t, x.Coordinator.RelayAndAckPendingPackets(x.IbcPath)) + require.Equal(t, 30_000_000, providerCli.QueryVaultFreeBalance()) + + // consumer chain + // ==================== + // + // then delegated amount is not updated before the epoch + consumerCli.assertTotalDelegated(math.ZeroInt()) // ensure nothing cross staked yet + + // when an epoch ends, the delegation rebalance is triggered + consumerCli.ExecNewEpoch() + + // then the total delegated amount is updated + consumerCli.assertTotalDelegated(math.NewInt(31_500_000)) // 70_000_000 /2 * (1 -0.1) + + // and the delegated amount is updated for the validator + consumerCli.assertShare(extValidator1, math.LegacyMustNewDecFromStr("22.5")) // 50_000_000 /2 * (1 -0.1) / 1_000_000 # default sdk factor + consumerCli.assertShare(extValidator2, math.LegacyNewDec(9)) // 20_000_000 /2 * (1 -0.1) / 1_000_000 # default sdk factor + + // Zero max cap + consumerCli.ExecSetMaxCap(sdk.NewInt64Coin(x.ConsumerDenom, 0)) + + // the max cap limit is persisted + rsp = consumerCli.QueryMaxCap() + assert.Equal(t, sdk.NewInt64Coin(x.ConsumerDenom, 0), rsp.Cap) + + // when an epoch ends, the unstaking msgs is triggered + consumerCli.ExecNewEpoch() + + // 2 internal unstake msg, 1 distribute batch msg + require.Len(t, x.IbcPath.EndpointA.Chain.PendingSendPackets, 3) + require.NoError(t, x.Coordinator.RelayAndAckPendingPackets(x.IbcPath)) + + consumerCli.assertTotalDelegated(math.ZeroInt()) + + x.ProviderChain.NextBlock() + providerCli.MustExecExtStaking(`{"withdraw_unbonded":{}}`) + // When calculate inverted price, 50_000_000 will become 49_999_999, 20_000_000 will be 19_999_999 + assert.Equal(t, 99_999_998, providerCli.QueryVaultFreeBalance()) } diff --git a/tests/starship/mvp_test.go b/tests/starship/mvp_test.go index 54896999..0dd90e62 100644 --- a/tests/starship/mvp_test.go +++ b/tests/starship/mvp_test.go @@ -10,7 +10,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/osmosis-labs/mesh-security-sdk/tests/starship/setup" diff --git a/tests/testdata/mesh_converter.wasm.gz b/tests/testdata/mesh_converter.wasm.gz index c4b9a5da..724c7ce0 100644 Binary files a/tests/testdata/mesh_converter.wasm.gz and b/tests/testdata/mesh_converter.wasm.gz differ diff --git a/tests/testdata/mesh_external_staking.wasm.gz b/tests/testdata/mesh_external_staking.wasm.gz index 4b54f45c..978ec389 100644 Binary files a/tests/testdata/mesh_external_staking.wasm.gz and b/tests/testdata/mesh_external_staking.wasm.gz differ diff --git a/tests/testdata/mesh_native_staking.wasm.gz b/tests/testdata/mesh_native_staking.wasm.gz index 4ec8da26..658d8007 100644 Binary files a/tests/testdata/mesh_native_staking.wasm.gz and b/tests/testdata/mesh_native_staking.wasm.gz differ diff --git a/tests/testdata/mesh_native_staking_proxy.wasm.gz b/tests/testdata/mesh_native_staking_proxy.wasm.gz index 728a9bb1..61d33199 100644 Binary files a/tests/testdata/mesh_native_staking_proxy.wasm.gz and b/tests/testdata/mesh_native_staking_proxy.wasm.gz differ diff --git a/tests/testdata/mesh_osmosis_price_provider.wasm.gz b/tests/testdata/mesh_osmosis_price_provider.wasm.gz index a0c5ee41..44ab4e45 100644 Binary files a/tests/testdata/mesh_osmosis_price_provider.wasm.gz and b/tests/testdata/mesh_osmosis_price_provider.wasm.gz differ diff --git a/tests/testdata/mesh_remote_price_feed.wasm.gz b/tests/testdata/mesh_remote_price_feed.wasm.gz index 799c592f..de9be9ca 100644 Binary files a/tests/testdata/mesh_remote_price_feed.wasm.gz and b/tests/testdata/mesh_remote_price_feed.wasm.gz differ diff --git a/tests/testdata/mesh_simple_price_feed.wasm.gz b/tests/testdata/mesh_simple_price_feed.wasm.gz index 23ce33d3..b05f5ffe 100644 Binary files a/tests/testdata/mesh_simple_price_feed.wasm.gz and b/tests/testdata/mesh_simple_price_feed.wasm.gz differ diff --git a/tests/testdata/mesh_vault.wasm.gz b/tests/testdata/mesh_vault.wasm.gz index 83ebdebd..bf9f528b 100644 Binary files a/tests/testdata/mesh_vault.wasm.gz and b/tests/testdata/mesh_vault.wasm.gz differ diff --git a/tests/testdata/mesh_virtual_staking.wasm.gz b/tests/testdata/mesh_virtual_staking.wasm.gz index 41d026d3..fdfb14a9 100644 Binary files a/tests/testdata/mesh_virtual_staking.wasm.gz and b/tests/testdata/mesh_virtual_staking.wasm.gz differ diff --git a/tests/testdata/version.txt b/tests/testdata/version.txt index 0c6c0836..a6343f0c 100644 --- a/tests/testdata/version.txt +++ b/tests/testdata/version.txt @@ -1 +1 @@ -f7993df7789864bcd5289dc656f30eeef89f7fbf +aba6c2af282155baf185fc60db248365a00761e3 diff --git a/x/meshsecurity/contract/in_message.go b/x/meshsecurity/contract/in_message.go index 704f27cd..7a05867c 100644 --- a/x/meshsecurity/contract/in_message.go +++ b/x/meshsecurity/contract/in_message.go @@ -21,8 +21,8 @@ type ( } UpdateDelegationMsg struct { Amount wasmvmtypes.Coin `json:"amount"` + IsDeduct bool `json:"is_deduct"` Delegator string `json:"delegator"` Validator string `json:"validator"` - IsDeduct bool `json:"is_deduct"` } ) diff --git a/x/meshsecurity/keeper/keeper.go b/x/meshsecurity/keeper/keeper.go index 01370c50..8fffbc12 100644 --- a/x/meshsecurity/keeper/keeper.go +++ b/x/meshsecurity/keeper/keeper.go @@ -148,8 +148,8 @@ func (k Keeper) setTotalDelegated(ctx sdk.Context, actor sdk.AccAddress, newAmou } // GetDelegation returns contract delegation for a specified delegator bond with validator. -func (k Keeper) GetDelegation(ctx sdk.Context, storeKey storetypes.StoreKey, actor, delAddr sdk.AccAddress, valAddr sdk.ValAddress) types.Delegation { - store := ctx.KVStore(storeKey) +func (k Keeper) GetDelegation(ctx sdk.Context, actor, delAddr sdk.AccAddress, valAddr sdk.ValAddress) types.Delegation { + store := ctx.KVStore(k.storeKey) key := types.BuildDelegationKey(actor, delAddr, valAddr) bz := store.Get(key) if bz == nil { @@ -193,7 +193,7 @@ func (k Keeper) GetAllDelegations(ctx sdk.Context, actor sdk.AccAddress, maxRetr func (k Keeper) setDelegation(ctx sdk.Context, actor, delAddr sdk.AccAddress, valAddr sdk.ValAddress, changeAmount math.Int) { store := ctx.KVStore(k.storeKey) - newDelegation := k.GetDelegation(ctx, k.storeKey, actor, delAddr, valAddr) + newDelegation := k.GetDelegation(ctx, actor, delAddr, valAddr) newDelegation.Amount = newDelegation.Amount.Add(changeAmount) if !newDelegation.Amount.IsPositive() { store.Delete(types.BuildDelegationKey(actor, delAddr, valAddr)) diff --git a/x/meshsecurity/keeper/keeper_test.go b/x/meshsecurity/keeper/keeper_test.go index 18d6a6c8..2ac49820 100644 --- a/x/meshsecurity/keeper/keeper_test.go +++ b/x/meshsecurity/keeper/keeper_test.go @@ -123,3 +123,26 @@ func TestSetMaxCapLimit(t *testing.T) { }) } } + +func TestSetDelegation(t *testing.T) { + pCtx, keepers := CreateDefaultTestInput(t) + k := keepers.MeshKeeper + var ( + myContractAddr = sdk.AccAddress(rand.Bytes(32)) + myAccAddr = sdk.AccAddress(rand.Bytes(32)) + myValAddr = sdk.ValAddress(rand.Bytes(32)) + oneStakeCoin = sdk.NewInt64Coin(sdk.DefaultBondDenom, 1) + ) + + ctx, _ := pCtx.CacheContext() + + k.UpdateDelegation(ctx, myContractAddr, myAccAddr, myValAddr, oneStakeCoin, false) + + allDels := k.GetAllDelegations(ctx, myContractAddr, 10) + assert.Len(t, allDels, 1) + assert.Equal(t, allDels[0].Amount, oneStakeCoin.Amount) + + k.UpdateDelegation(ctx, myContractAddr, myAccAddr, myValAddr, oneStakeCoin, true) + allDels = k.GetAllDelegations(ctx, myContractAddr, 10) + assert.Len(t, allDels, 0) +} diff --git a/x/meshsecurity/keeper/stake.go b/x/meshsecurity/keeper/stake.go index 192ff111..d9b1234f 100644 --- a/x/meshsecurity/keeper/stake.go +++ b/x/meshsecurity/keeper/stake.go @@ -122,6 +122,6 @@ func (k Keeper) UpdateDelegation(pCtx sdk.Context, actor, delAddr sdk.AccAddress if isDeduct { amt.Amount = amt.Amount.Neg() } - k.setDelegation(cacheCtx, actor, delAddr, valAddr, amt.Amount.Neg()) + k.setDelegation(cacheCtx, actor, delAddr, valAddr, amt.Amount) done() } diff --git a/x/meshsecurity/keeper/wasm.go b/x/meshsecurity/keeper/wasm.go index af2be09e..33fe9d19 100644 --- a/x/meshsecurity/keeper/wasm.go +++ b/x/meshsecurity/keeper/wasm.go @@ -5,6 +5,7 @@ import ( errorsmod "cosmossdk.io/errors" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/contract" @@ -15,6 +16,7 @@ func (k Keeper) SendHandleEpoch(ctx sdk.Context, contractAddr sdk.AccAddress) er msg := contract.SudoMsg{ HandleEpoch: &struct{}{}, } + ctx = ctx.WithGasMeter(storetypes.NewInfiniteGasMeter()) return k.doSudoCall(ctx, contractAddr, msg) } diff --git a/x/meshsecurity/types/keys.go b/x/meshsecurity/types/keys.go index 1e57428e..1534c089 100644 --- a/x/meshsecurity/types/keys.go +++ b/x/meshsecurity/types/keys.go @@ -125,12 +125,12 @@ func BuildPipedValsetOpKey(op PipedValsetOperation, val sdk.ValAddress, slashInf // BuildDelegationsKey build the delegations's prefix for a contract func BuildDelegationsKey(actor sdk.AccAddress) []byte { - return append(DelegationKey, address.MustLengthPrefix(actor)...) + return append(DelegationKey, address.MustLengthPrefix(actor)...) } // BuildDelegationKey build the prefix for a delegator bond with validator func BuildDelegationKey(actor, delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte { - key := append(BuildDelegationsKey(actor), address.MustLengthPrefix(delAddr)...) + key := append(BuildDelegationsKey(actor), address.MustLengthPrefix(delAddr)...) key = append(key, address.MustLengthPrefix(valAddr)...) return key -} \ No newline at end of file +}