Skip to content

Commit

Permalink
Merge branch 'feat/vesting-delegate' of https://github.com/decentrio/…
Browse files Browse the repository at this point in the history
…mesh-security-sdk into feat/native-immediate-unbonding
  • Loading branch information
neitdung committed Jul 23, 2024
2 parents 2966c74 + cc0a6e6 commit 602f4cc
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 25 deletions.
4 changes: 2 additions & 2 deletions demo/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ type MeshApp struct {
TransferKeeper ibctransferkeeper.Keeper
WasmKeeper wasmkeeper.Keeper
MeshSecKeeper *meshseckeeper.Keeper
MeshSecProvKeeper meshsecprovkeeper.Keeper
MeshSecProvKeeper *meshsecprovkeeper.Keeper

ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -425,7 +425,7 @@ func NewMeshApp(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.MeshSecProvKeeper = *meshsecprovkeeper.NewKeeper(
app.MeshSecProvKeeper = meshsecprovkeeper.NewKeeper(
appCodec,
keys[meshsecprovtypes.StoreKey],
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/e2e.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package e2e

import (
"fmt"
"path/filepath"
"testing"

Expand Down Expand Up @@ -76,7 +75,6 @@ func voteAndPassGovProposal(t *testing.T, chain *ibctesting.TestChain, proposalI
}

func InstantiateContract(t *testing.T, chain *ibctesting.TestChain, codeID uint64, initMsg []byte, funds ...sdk.Coin) sdk.AccAddress {
fmt.Println(codeID, string(initMsg))
instantiateMsg := &wasmtypes.MsgInstantiateContract{
Sender: chain.SenderAccount.GetAddress().String(),
Admin: chain.SenderAccount.GetAddress().String(),
Expand All @@ -101,6 +99,7 @@ type example struct {
ConsumerChain *ibctesting.TestChain
ProviderChain *ibctesting.TestChain
ConsumerApp *app.MeshApp
ProviderApp *app.MeshApp
IbcPath *ibctesting.Path
ProviderDenom string
ConsumerDenom string
Expand All @@ -116,6 +115,7 @@ func setupExampleChains(t *testing.T) example {
ConsumerChain: consChain,
ProviderChain: provChain,
ConsumerApp: consChain.App.(*app.MeshApp),
ProviderApp: provChain.App.(*app.MeshApp),
IbcPath: ibctesting.NewPath(consChain, provChain),
ProviderDenom: sdk.DefaultBondDenom,
ConsumerDenom: sdk.DefaultBondDenom,
Expand All @@ -134,7 +134,7 @@ func setupMeshSecurity(t *testing.T, x example) (*TestConsumerClient, ConsumerCo
x.ConsumerChain.DefaultMsgFees = sdk.NewCoins(sdk.NewCoin(x.ConsumerDenom, math.NewInt(1_000_000)))

providerCli := NewProviderClient(t, x.ProviderChain)
providerContracts := providerCli.BootstrapContracts(x.IbcPath.EndpointA.ConnectionID, converterPortID)
providerContracts := providerCli.BootstrapContracts(x.ProviderApp, x.IbcPath.EndpointA.ConnectionID, converterPortID)

// setup ibc control path: consumer -> provider (direction matters)
x.IbcPath.EndpointB.ChannelConfig = &ibctesting2.ChannelConfig{
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/mvp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestMVP(t *testing.T) {
// 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)
execMsg := fmt.Sprintf(`{"bond":{"amount":{"denom":"%s", "amount":"100000000"}}}`, x.ProviderDenom)
providerCli.MustExecVault(execMsg)

// then query contract state
Expand Down
12 changes: 6 additions & 6 deletions tests/e2e/slashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func TestSlashingScenario1(t *testing.T) {
// Provider chain
// ==============
// Deposit - A user deposits the vault denom to provide some collateral to their account
execMsg := `{"bond":{}}`
providerCli.MustExecVault(execMsg, sdk.NewInt64Coin(x.ProviderDenom, 200_000_000))
execMsg := fmt.Sprintf(`{"bond":{"amount":{"denom":"%s", "amount":"200000000"}}}`, x.ProviderDenom)
providerCli.MustExecVault(execMsg)

// 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 Expand Up @@ -121,8 +121,8 @@ func TestSlashingScenario2(t *testing.T) {
// Provider chain
// ==============
// Deposit - A user deposits the vault denom to provide some collateral to their account
execMsg := `{"bond":{}}`
providerCli.MustExecVault(execMsg, sdk.NewInt64Coin(x.ProviderDenom, 200_000_000))
execMsg := fmt.Sprintf(`{"bond":{"amount":{"denom":"%s", "amount":"200000000"}}}`, x.ProviderDenom)
providerCli.MustExecVault(execMsg)

// 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 Expand Up @@ -208,8 +208,8 @@ func TestSlashingScenario3(t *testing.T) {
// Provider chain
// ==============
// Deposit - A user deposits the vault denom to provide some collateral to their account
execMsg := `{"bond":{}}`
providerCli.MustExecVault(execMsg, sdk.NewInt64Coin(x.ProviderDenom, 200_000_000))
execMsg := fmt.Sprintf(`{"bond":{"amount":{"denom":"%s", "amount":"200000000"}}}`, x.ProviderDenom)
providerCli.MustExecVault(execMsg)

// 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
7 changes: 6 additions & 1 deletion tests/e2e/test_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type ProviderContracts struct {
externalStaking sdk.AccAddress
}

func (p *TestProviderClient) BootstrapContracts(connId, portID string) ProviderContracts {
func (p *TestProviderClient) BootstrapContracts(provApp *app.MeshApp, connId, portID string) ProviderContracts {
var (
unbondingPeriod = 21 * 24 * 60 * 60 // 21 days - make configurable?
localSlashRatioDoubleSign = "0.20"
Expand All @@ -88,6 +88,7 @@ func (p *TestProviderClient) BootstrapContracts(connId, portID string) ProviderC
rewardTokenDenom = sdk.DefaultBondDenom
localTokenDenom = sdk.DefaultBondDenom
)

vaultCodeID := p.chain.StoreCodeFile(buildPathToWasm("mesh_vault.wasm")).CodeID
proxyCodeID := p.chain.StoreCodeFile(buildPathToWasm("mesh_native_staking_proxy.wasm")).CodeID
nativeStakingCodeID := p.chain.StoreCodeFile(buildPathToWasm("mesh_native_staking.wasm")).CodeID
Expand All @@ -96,6 +97,10 @@ func (p *TestProviderClient) BootstrapContracts(connId, portID string) ProviderC
initMsg := []byte(fmt.Sprintf(`{"denom": %q, "local_staking": {"code_id": %d, "msg": %q}}`, localTokenDenom, nativeStakingCodeID, base64.StdEncoding.EncodeToString(nativeInitMsg)))
vaultContract := InstantiateContract(p.t, p.chain, vaultCodeID, initMsg)

ctx := p.chain.GetContext()
params := provApp.MeshSecProvKeeper.GetParams(ctx)
params.VaultAddress = vaultContract.String()
provApp.MeshSecProvKeeper.SetParams(ctx, params)
// external staking
extStakingCodeID := p.chain.StoreCodeFile(buildPathToWasm("mesh_external_staking.wasm")).CodeID
initMsg = []byte(fmt.Sprintf(
Expand Down
4 changes: 3 additions & 1 deletion tests/starship/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ require (
github.com/cosmology-tech/starship/registry v0.0.0-20231216113645-d0facbadb180
github.com/cosmos/go-bip39 v1.0.0
github.com/osmosis-labs/mesh-security-sdk/demo v0.0.0-00010101000000-000000000000
github.com/osmosis-labs/mesh-security-sdk/x v0.0.0-00010101000000-000000000000
github.com/osmosis-labs/mesh-security-sdk/x v0.0.0-20231230023625-3cdce6e349eb
github.com/strangelove-ventures/lens v0.0.0-00010101000000-000000000000
go.uber.org/zap v1.26.0
gopkg.in/yaml.v3 v3.0.1
Expand Down Expand Up @@ -147,6 +147,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/osmosis-labs/mesh-security-sdk/wasmbinding v0.0.0-00010101000000-000000000000 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down Expand Up @@ -201,6 +202,7 @@ replace (

// local work dirs
github.com/osmosis-labs/mesh-security-sdk/demo => ../../demo
github.com/osmosis-labs/mesh-security-sdk/wasmbinding => ../../wasmbinding
github.com/osmosis-labs/mesh-security-sdk/x => ../../x

github.com/strangelove-ventures/lens => github.com/Anmol1696/lens v0.1.1-0.20230705212610-c00628a886a0
Expand Down
9 changes: 4 additions & 5 deletions tests/starship/mvp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -52,8 +51,8 @@ func Test2WayContract(t *testing.T) {
// ==============
// Deposit - A user deposits the vault denom to provide some collateral to their account
fmt.Println("provider chain: deposit vault denom to provide some collateral to account")
execMsg := `{"bond":{}}`
vault, err := providerClient1.MustExecVault(execMsg, sdk.NewInt64Coin(providerClient1.Chain.Denom, 100_000_000))
execMsg := fmt.Sprintf(`{"bond":{"amount":{"denom":"%s", "amount":"100000000"}}}`, providerClient1.Chain.Denom)
vault, err := providerClient1.MustExecVault(execMsg)
require.NoError(t, err)
require.NotEmpty(t, vault)

Expand Down Expand Up @@ -130,8 +129,8 @@ func Test2WayContract(t *testing.T) {
// ==============
// Deposit - A user deposits the vault denom to provide some collateral to their account
fmt.Println("provider chain: deposit vault denom to provide some collateral to account")
execMsg = `{"bond":{}}`
vault, err = providerClient2.MustExecVault(execMsg, sdk.NewInt64Coin(providerClient2.Chain.Denom, 100_000_000))
execMsg = fmt.Sprintf(`{"bond":{"amount":{"denom":"%s", "amount":"100000000"}}}`, providerClient2.Chain.Denom)
vault, err = providerClient2.MustExecVault(execMsg)
require.NoError(t, err)
require.NotEmpty(t, vault)

Expand Down
2 changes: 1 addition & 1 deletion wasmbinding/bindings/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type (
type (
SudoMsg struct {
HandleEpoch *struct{} `json:"handle_epoch,omitempty"`
ValsetUpdate *ValsetUpdate `json:"valset_update,omitempty"`
ValsetUpdate *ValsetUpdate `json:"handle_valset_update,omitempty"`
}

// Validator alias to wasmVM type
Expand Down
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
7 changes: 3 additions & 4 deletions x/meshsecurityprovider/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"encoding/json"
"fmt"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
abci "github.com/cometbft/cometbft/abci/types"

"github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/client/cli"
"github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/keeper"
Expand Down Expand Up @@ -69,16 +69,15 @@ func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry)
type AppModule struct {
AppModuleBasic

k keeper.Keeper
k *keeper.Keeper
}

func (am AppModule) RegisterServices(cfg module.Configurator) {
// types.RegisterMsgServer(cfg.MsgServer(), meshsecurityprovider.NewMsgServerImpl(&am.k))
// queryproto.RegisterQueryServer(cfg.QueryServer(), grpc.Querier{Q: module.NewQuerier(am.k)})
}


func NewAppModule(moduleKeeper keeper.Keeper) AppModule {
func NewAppModule(moduleKeeper *keeper.Keeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
k: moduleKeeper,
Expand Down

0 comments on commit 602f4cc

Please sign in to comment.