Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stride ICQ #1076

Merged
merged 10 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ GAIA_VERSION := v7.0.1
AKASH_VERSION := v0.16.3
OSMOSIS_VERSION := v8.0.0
WASMD_VERSION := v0.25.0
DOCKER := $(shell which docker)

GOPATH := $(shell go env GOPATH)
GOBIN := $(GOPATH)/bin

containerProtoVer=v0.2
containerProtoImage=tendermintdev/sdk-proto-gen:$(containerProtoVer)
containerProtoGen=cosmos-sdk-proto-gen-$(containerProtoVer)
containerProtoGenSwagger=cosmos-sdk-proto-gen-swagger-$(containerProtoVer)
containerProtoFmt=cosmos-sdk-proto-fmt-$(containerProtoVer)

all: lint install

###############################################################################
Expand Down Expand Up @@ -82,7 +89,7 @@ ibctest-multiple:
cd ibctest && go test -race -v -run TestRelayerMultiplePathsSingleProcess .

ibctest-scenario: ## Scenario tests are suitable for simple networks of 1 validator and no full nodes. They test specific functionality.
cd ibctest && go test -race -v -run TestScenario .
cd ibctest && go test -race -v -run TestScenario ./...

coverage:
@echo "viewing test coverage..."
Expand Down Expand Up @@ -154,3 +161,9 @@ release:
-w /go/src/$(PACKAGE_NAME) \
goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --rm-dist

proto-gen:
@echo "Generating Protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGen}$$"; then docker start -a $(containerProtoGen); else docker run --name $(containerProtoGen) -v $(CURDIR):/workspace --workdir /workspace $(containerProtoImage) \
sh ./scripts/protocgen.sh; fi
@go mod tidy
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ go 1.19

require (
github.com/avast/retry-go/v4 v4.3.1
github.com/cosmos/cosmos-proto v1.0.0-alpha7
github.com/cosmos/cosmos-sdk v0.46.6
github.com/cosmos/ibc-go/v5 v5.1.0
github.com/gogo/protobuf v1.3.3
github.com/google/go-cmp v0.5.9
github.com/google/go-github/v43 v43.0.0
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/jsternberg/zap-logfmt v1.3.0
github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b
github.com/prometheus/client_golang v1.12.2
Expand Down Expand Up @@ -52,7 +55,6 @@ require (
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/confio/ics23/go v0.7.0 // indirect
github.com/cosmos/btcutil v1.0.4 // indirect
github.com/cosmos/cosmos-proto v1.0.0-alpha7 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/cosmos/iavl v0.19.4 // indirect
Expand Down Expand Up @@ -85,15 +87,13 @@ require (
github.com/googleapis/go-type-adapters v1.0.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.6.1 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-uuid v1.0.1 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaWhq2GjuNUt0aUU0YBYw=
Expand All @@ -396,9 +397,8 @@ github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjh
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo=
github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I=
github.com/hashicorp/go-uuid v1.0.0 h1:RS8zrF7PhGwyNPOtxSClXXj9HA8feRnJzgnI1RJCSnM=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
Expand Down
15 changes: 15 additions & 0 deletions ibctest/stride/codecs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package stride

import (
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
rlystride "github.com/cosmos/relayer/v2/relayer/chains/cosmos/stride"
"github.com/strangelove-ventures/ibctest/v5/chain/cosmos"
)

func Encoding() *simappparams.EncodingConfig {
cfg := cosmos.DefaultEncoding()

rlystride.RegisterInterfaces(cfg.InterfaceRegistry)

return &cfg
}
261 changes: 261 additions & 0 deletions ibctest/stride/setup_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
package stride_test

import (
"context"
"encoding/json"
"fmt"

"github.com/cosmos/cosmos-sdk/codec"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
chantypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types"
rlystride "github.com/cosmos/relayer/v2/relayer/chains/cosmos/stride"
"github.com/icza/dyno"
"github.com/strangelove-ventures/ibctest/v5/chain/cosmos"
"github.com/strangelove-ventures/ibctest/v5/ibc"
"github.com/strangelove-ventures/ibctest/v5/test"
)

const (
StrideAdminAccount = "admin"
StrideAdminMnemonic = "tone cause tribe this switch near host damage idle fragile antique tail soda alien depth write wool they rapid unfold body scan pledge soft"
)

const (
DayEpochIndex = 1
DayEpochLen = "100s"
StrideEpochIndex = 2
StrideEpochLen = "40s"
IntervalLen = 1
VotingPeriod = "30s"
MaxDepositPeriod = "30s"
UnbondingTime = "200s"
TrustingPeriod = "199s"
)

var AllowMessages = []string{
"/cosmos.bank.v1beta1.MsgSend",
"/cosmos.bank.v1beta1.MsgMultiSend",
"/cosmos.staking.v1beta1.MsgDelegate",
"/cosmos.staking.v1beta1.MsgUndelegate",
"/cosmos.staking.v1beta1.MsgRedeemTokensforShares",
"/cosmos.staking.v1beta1.MsgTokenizeShares",
"/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
"/cosmos.distribution.v1beta1.MsgSetWithdrawAddress",
"/ibc.applications.transfer.v1.MsgTransfer",
}

type HostZoneAccount struct {
Address string `json:"address"`
// Delegations [] `json:"delegations"`
Target string `json:"target"`
}

type HostZoneValidator struct {
Address string `json:"address"`
CommissionRate string `json:"commissionRate"`
DelegationAmt string `json:"delegationAmt"`
InternalExchangeRate string `json:"internalExchangeRate"`
Name string `json:"name"`
Status string `json:"status"`
Weight string `json:"weight"`
}

type HostZoneWrapper struct {
HostZone HostZone `json:"HostZone"`
}

type HostZone struct {
HostDenom string `json:"HostDenom"`
IBCDenom string `json:"IBCDenom"`
LastRedemptionRate string `json:"LastRedemptionRate"`
RedemptionRate string `json:"RedemptionRate"`
Address string `json:"address"`
Bech32prefix string `json:"bech32pref ix"`
ChainID string `json:"chainId"`
ConnectionID string `json:"connectionId"`
DelegationAccount HostZoneAccount `json:"delegationAccount"`
FeeAccount HostZoneAccount `json:"feeAccount"`
RedemptionAccount HostZoneAccount `json:"redemptionAccount"`
WithdrawalAccount HostZoneAccount `json:"withdrawalAccount"`
StakedBal string `json:"stakedBal"`
TransferChannelId string `json:"transferChannelId"`
UnbondingFrequency string `json:"unbondingFrequency"`
Validators []HostZoneValidator `json:"validators"`
BlacklistedValidators []HostZoneValidator `json:"blacklistedValidators"`
}

type DepositRecord struct {
Id string `json:"id,omitempty"`
Amount string `json:"amount,omitempty"`
Denom string `json:"denom,omitempty"`
HostZoneId string `json:"hostZoneId,omitempty"`
Status string `json:"status,omitempty"`
DepositEpochNumber string `json:"depositEpochNumber,omitempty"`
Source string `json:"source,omitempty"`
}

type DepositRecordWrapper struct {
DepositRecord []DepositRecord `json:"DepositRecord"`
}

type UserRedemptionRecordWrapper struct {
UserRedemptionRecord []UserRedemptionRecord `json:"UserRedemptionRecord"`
}

type UserRedemptionRecord struct {
ID string `json:"id"`
Sender string `json:"sender"`
Receiver string `json:"receiver"`
Amount string `json:"amount"`
Denom string `json:"denom"`
HostZoneID string `json:"hostZoneId"`
EpochNumber string `json:"epochNumber"`
ClaimIsPending bool `json:"claimIsPending"`
}

func ModifyGenesisStride() func(ibc.ChainConfig, []byte) ([]byte, error) {
return func(cfg ibc.ChainConfig, genbz []byte) ([]byte, error) {
g := make(map[string]interface{})
if err := json.Unmarshal(genbz, &g); err != nil {
return nil, fmt.Errorf("failed to unmarshal genesis file: %w", err)
}

if err := dyno.Set(g, DayEpochLen, "app_state", "epochs", "epochs", DayEpochIndex, "duration"); err != nil {
return nil, err
}
if err := dyno.Set(g, StrideEpochLen, "app_state", "epochs", "epochs", StrideEpochIndex, "duration"); err != nil {
return nil, err
}
if err := dyno.Set(g, UnbondingTime, "app_state", "staking", "params", "unbonding_time"); err != nil {
return nil, err
}
if err := dyno.Set(g, IntervalLen, "app_state", "stakeibc", "params", "rewards_interval"); err != nil {
return nil, err
}
if err := dyno.Set(g, IntervalLen, "app_state", "stakeibc", "params", "delegate_interval"); err != nil {
return nil, err
}
if err := dyno.Set(g, IntervalLen, "app_state", "stakeibc", "params", "deposit_interval"); err != nil {
return nil, err
}
if err := dyno.Set(g, IntervalLen, "app_state", "stakeibc", "params", "redemption_rate_interval"); err != nil {
return nil, err
}
if err := dyno.Set(g, IntervalLen, "app_state", "stakeibc", "params", "reinvest_interval"); err != nil {
return nil, err
}
if err := dyno.Set(g, VotingPeriod, "app_state", "gov", "voting_params", "voting_period"); err != nil {
return nil, fmt.Errorf("failed to set voting period in genesis json: %w", err)
}
if err := dyno.Set(g, MaxDepositPeriod, "app_state", "gov", "deposit_params", "max_deposit_period"); err != nil {
return nil, fmt.Errorf("failed to set voting period in genesis json: %w", err)
}

out, err := json.Marshal(g)
if err != nil {
return nil, fmt.Errorf("failed to marshal genesis bytes to json: %w", err)
}
return out, nil
}
}

func ModifyGenesisStrideCounterparty() func(ibc.ChainConfig, []byte) ([]byte, error) {
return func(cfg ibc.ChainConfig, genbz []byte) ([]byte, error) {
g := make(map[string]interface{})
if err := json.Unmarshal(genbz, &g); err != nil {
return nil, fmt.Errorf("failed to unmarshal genesis file: %w", err)
}

if err := dyno.Set(g, UnbondingTime,
"app_state", "staking", "params", "unbonding_time",
); err != nil {
return nil, err
}

if err := dyno.Set(g, AllowMessages,
"app_state", "interchainaccounts", "host_genesis_state", "params", "allow_messages",
); err != nil {
return nil, err
}

out, err := json.Marshal(g)
if err != nil {
return nil, fmt.Errorf("failed to marshal genesis bytes to json: %w", err)
}
return out, nil
}
}

// PollForMsgSubmitQueryResponse polls until finding a block with a MsgSubmitQueryResponse message
func PollForMsgSubmitQueryResponse(
ctx context.Context,
chain *cosmos.CosmosChain,
startHeight, maxHeight uint64,
chainID string,
) (*rlystride.MsgSubmitQueryResponse, error) {
cdc := codec.NewProtoCodec(chain.Config().EncodingConfig.InterfaceRegistry)

doPoll := func(ctx context.Context, height uint64) (any, error) {
heightInt64 := int64(height)
block, err := chain.Validators[0].Client.Block(ctx, &heightInt64)
if err != nil {
return nil, err
}

for _, tx := range block.Block.Txs {
sdkTx, err := authtx.DefaultTxDecoder(cdc)(tx)
if err != nil {
continue
}
for _, msg := range sdkTx.GetMsgs() {
if msgSubmitQueryResponse, ok := msg.(*rlystride.MsgSubmitQueryResponse); ok {
return msgSubmitQueryResponse, nil
}
}
}
return nil, fmt.Errorf("no MsgSubmitQueryResponse found")
}
bp := test.BlockPoller{CurrentHeight: chain.Height, PollFunc: doPoll}
p, err := bp.DoPoll(ctx, startHeight, maxHeight)
if err != nil {
return nil, err
}
return p.(*rlystride.MsgSubmitQueryResponse), nil
}

// PollForMsgSubmitQueryResponse polls until finding a block with a MsgSubmitQueryResponse message
func PollForMsgChannelOpenConfirm(
ctx context.Context,
chain *cosmos.CosmosChain,
startHeight, maxHeight uint64,
chainID string,
) (*chantypes.MsgChannelOpenConfirm, error) {
cdc := codec.NewProtoCodec(chain.Config().EncodingConfig.InterfaceRegistry)

doPoll := func(ctx context.Context, height uint64) (any, error) {
heightInt64 := int64(height)
block, err := chain.Validators[0].Client.Block(ctx, &heightInt64)
if err != nil {
return nil, err
}

for _, tx := range block.Block.Txs {
sdkTx, err := authtx.DefaultTxDecoder(cdc)(tx)
if err != nil {
continue
}
for _, msg := range sdkTx.GetMsgs() {
if msgChannelOpenConfirm, ok := msg.(*chantypes.MsgChannelOpenConfirm); ok {
return msgChannelOpenConfirm, nil
}
}
}
return nil, fmt.Errorf("no MsgChannelOpenConfirm found")
}
bp := test.BlockPoller{CurrentHeight: chain.Height, PollFunc: doPoll}
p, err := bp.DoPoll(ctx, startHeight, maxHeight)
if err != nil {
return nil, err
}
return p.(*chantypes.MsgChannelOpenConfirm), nil
}
Loading