Skip to content

Commit

Permalink
feat(e2e): upgraded to interchaintest v8 and SDK 0.50 (#72)
Browse files Browse the repository at this point in the history
* deps: updated to interchaintest v8

* imp: added UidGid

* deps: bumped to go 1.21

* ci: updated e2e/lint

* e2e: fix

* e2e: improvement

* e2e: improve test

* imp: gas added

* e2e: min deposit

* e2e: remove depositMsg

* e2e: trying to add diagnostics

* ci: disable fail fast

* ci: fix syntax

* ci: always upload logs

* fix: maybe

* imp: added new gitignore

* imp

* e2e: test passing

* fix

* fix: test

* fix

* imp: time
  • Loading branch information
srdtrk authored Feb 1, 2024
1 parent 9340739 commit d43e3e6
Show file tree
Hide file tree
Showing 16 changed files with 862 additions and 400 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ jobs:
steps:
- uses: actions/setup-go@v4
with:
go-version: "1.20"
go-version: "1.21"
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.6.0
uses: golangci/golangci-lint-action@v3.7.0
with:
version: v1.53.2
version: v1.54
args: --timeout 5m
working-directory: e2e/interchaintest
build:
strategy:
fail-fast: false
matrix:
test:
- TestIcaContractChannelHandshake
Expand Down Expand Up @@ -69,7 +70,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
go-version: "1.21"
check-latest: true
cache-dependency-path: |
e2e/interchaintest/go.sum
Expand All @@ -81,3 +82,11 @@ jobs:
else
go test -v . -run TestWithContractTestSuite -testify.m ${{ matrix.test }}
fi
- name: Upload Diagnostics on Failure
uses: actions/upload-artifact@v4
if: ${{ failure() }}
continue-on-error: true
with:
name: '${{ matrix.entrypoint }}-${{ matrix.test }}'
path: e2e/diagnostics
retention-days: 5
2 changes: 2 additions & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Diagnostics
diagnostics/
15 changes: 10 additions & 5 deletions e2e/interchaintest/chain_config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package main

import (
interchaintest "github.com/strangelove-ventures/interchaintest/v7"
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos/wasm"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
interchaintest "github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos/wasm"
"github.com/strangelove-ventures/interchaintest/v8/ibc"

mysuite "github.com/srdtrk/cw-ica-controller/interchaintest/v2/testsuite"
)

var chainSpecs = []*interchaintest.ChainSpec{
Expand All @@ -16,7 +18,8 @@ var chainSpecs = []*interchaintest.ChainSpec{
Images: []ibc.DockerImage{
{
Repository: "cosmwasm/wasmd", // FOR LOCAL IMAGE USE: Docker Image Name
Version: "v0.45.0", // FOR LOCAL IMAGE USE: Docker Image Tag
Version: "v0.50.0", // FOR LOCAL IMAGE USE: Docker Image Tag
UidGid: "1025:1025",
},
},
Bin: "wasmd",
Expand All @@ -39,14 +42,16 @@ var chainSpecs = []*interchaintest.ChainSpec{
Images: []ibc.DockerImage{
{
Repository: "ghcr.io/cosmos/ibc-go-simd", // FOR LOCAL IMAGE USE: Docker Image Name
Version: "v7.3.0", // FOR LOCAL IMAGE USE: Docker Image Tag
Version: "v8.1.0", // FOR LOCAL IMAGE USE: Docker Image Tag
UidGid: "1025:1025",
},
},
Bin: "simd",
Bech32Prefix: "cosmos",
Denom: "stake",
GasPrices: "0.00stake",
GasAdjustment: 1.3,
EncodingConfig: mysuite.SDKEncodingConfig(),
TrustingPeriod: "508h",
NoHostMount: false,
},
Expand Down
126 changes: 64 additions & 62 deletions e2e/interchaintest/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ import (

sdkmath "cosmossdk.io/math"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"

"github.com/strangelove-ventures/interchaintest/v7"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
"github.com/strangelove-ventures/interchaintest/v7/testutil"
"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testutil"

mysuite "github.com/srdtrk/cw-ica-controller/interchaintest/v2/testsuite"
"github.com/srdtrk/cw-ica-controller/interchaintest/v2/types"
Expand Down Expand Up @@ -92,6 +93,7 @@ func (s *ContractTestSuite) SetupContractTestSuite(ctx context.Context, encoding
ownershipResponse, err := types.QueryAnyMsg[icacontroller.OwnershipResponse](ctx, &s.Contract.Contract, icacontroller.OwnershipRequest)
s.Require().NoError(err)

s.Require().NotEmpty(contractState.IcaInfo.IcaAddress)
s.Contract.SetIcaAddress(contractState.IcaInfo.IcaAddress)

s.Require().Equal(s.UserA.FormattedAddress(), ownershipResponse.Owner)
Expand Down Expand Up @@ -352,32 +354,29 @@ func (s *ContractTestSuite) IcaContractExecutionTestWithEncoding(encoding string
s.Run(fmt.Sprintf("TestSendCustomIcaMessagesSuccess-%s", encoding), func() {
// Send custom ICA messages through the contract:
// Let's create a governance proposal on simd and deposit some funds to it.
testProposal := govtypes.TextProposal{
Title: "IBC Gov Proposal",
Description: "tokens for all!",
}
protoAny, err := codectypes.NewAnyWithValue(&testProposal)
s.Require().NoError(err)
proposalMsg := &govtypes.MsgSubmitProposal{
Content: protoAny,
InitialDeposit: sdk.NewCoins(sdk.NewCoin(simd.Config().Denom, sdkmath.NewInt(5_000))),
Proposer: s.Contract.IcaAddress,
}
govAddress := s.GetModuleAddress(ctx, simd, govtypes.ModuleName)

// Create deposit message:
depositMsg := &govtypes.MsgDeposit{
ProposalId: 1,
Depositor: s.Contract.IcaAddress,
Amount: sdk.NewCoins(sdk.NewCoin(simd.Config().Denom, sdkmath.NewInt(10_000_000))),
testProposal := &controllertypes.MsgUpdateParams{
Signer: govAddress,
Params: controllertypes.Params{
ControllerEnabled: false,
},
}

proposalMsg, err := govv1.NewMsgSubmitProposal(
[]sdk.Msg{testProposal},
sdk.NewCoins(sdk.NewCoin(simd.Config().Denom, sdkmath.NewInt(10_000_000))),
s.Contract.IcaAddress, "e2e", "e2e", "e2e", false,
)
s.Require().NoError(err)

intialBalance, err := simd.GetBalance(ctx, s.Contract.IcaAddress, simd.Config().Denom)
s.Require().NoError(err)

// Execute the contract:
sendCustomIcaMsg := icacontroller.NewExecuteMsg_SendCustomIcaMessages_FromProto(
simd.Config().EncodingConfig.Codec,
[]proto.Message{proposalMsg, depositMsg},
[]proto.Message{proposalMsg},
encoding, nil, nil,
)
err = s.Contract.Execute(ctx, wasmdUser.KeyName(), sendCustomIcaMsg)
Expand All @@ -394,15 +393,15 @@ func (s *ContractTestSuite) IcaContractExecutionTestWithEncoding(encoding string
s.Require().Equal(uint64(0), callbackCounter.Error)

// Check if the proposal was created:
proposal, err := simd.QueryProposal(ctx, "1")
proposalResp, err := mysuite.GRPCQuery[govv1.QueryProposalResponse](ctx, simd, &govv1.QueryProposalRequest{
ProposalId: 1,
})
s.Require().NoError(err)
s.Require().Equal(simd.Config().Denom, proposal.TotalDeposit[0].Denom)
s.Require().Equal(fmt.Sprint(10_000_000+5_000), proposal.TotalDeposit[0].Amount)
// We do not check title and description of the proposal because this is a legacy proposal.
s.Require().Equal("e2e", proposalResp.Proposal.Title)

postBalance, err := simd.GetBalance(ctx, s.Contract.IcaAddress, simd.Config().Denom)
s.Require().NoError(err)
s.Require().Equal(intialBalance.Sub(sdkmath.NewInt(10_000_000+5_000)), postBalance)
s.Require().Equal(intialBalance.Sub(sdkmath.NewInt(10_000_000)), postBalance)
})

s.Run(fmt.Sprintf("TestSendCosmosMsgsSuccess-%s", encoding), func() {
Expand Down Expand Up @@ -466,15 +465,15 @@ func (s *ContractTestSuite) IcaContractExecutionTestWithEncoding(encoding string
s.Require().Equal(sdkmath.NewInt(10_000_000), delResp.DelegationResponse.Balance.Amount)

// Check if the vote was successful:
voteRequest := govtypes.QueryVoteRequest{
voteRequest := govv1.QueryVoteRequest{
ProposalId: 1,
Voter: s.Contract.IcaAddress,
}
voteResp, err := mysuite.GRPCQuery[govtypes.QueryVoteResponse](ctx, simd, &voteRequest)
voteResp, err := mysuite.GRPCQuery[govv1.QueryVoteResponse](ctx, simd, &voteRequest)
s.Require().NoError(err)
s.Require().Len(voteResp.Vote.Options, 1)
s.Require().Equal(govtypes.OptionYes, voteResp.Vote.Options[0].Option)
s.Require().Equal(sdkmath.LegacyNewDec(1), voteResp.Vote.Options[0].Weight)
s.Require().Equal(govv1.OptionYes, voteResp.Vote.Options[0].Option)
s.Require().Equal(sdkmath.LegacyNewDec(1).String(), voteResp.Vote.Options[0].Weight)
})

s.Run(fmt.Sprintf("TestSendCustomIcaMessagesError-%s", encoding), func() {
Expand Down Expand Up @@ -531,39 +530,36 @@ func (s *ContractTestSuite) SendCosmosMsgsTestWithEncoding(encoding string) {
s.Run(fmt.Sprintf("TestStargate-%s", encoding), func() {
// Send custom ICA messages through the contract:
// Let's create a governance proposal on simd and deposit some funds to it.
testProposal := govtypes.TextProposal{
Title: "IBC Gov Proposal",
Description: "tokens for all!",
}
protoAny, err := codectypes.NewAnyWithValue(&testProposal)
s.Require().NoError(err)
proposalMsg := &govtypes.MsgSubmitProposal{
Content: protoAny,
InitialDeposit: sdk.NewCoins(sdk.NewCoin(simd.Config().Denom, sdkmath.NewInt(5_000))),
Proposer: s.Contract.IcaAddress,
}
govAddress := s.GetModuleAddress(ctx, simd, govtypes.ModuleName)

// Create deposit message:
depositMsg := &govtypes.MsgDeposit{
ProposalId: 1,
Depositor: s.Contract.IcaAddress,
Amount: sdk.NewCoins(sdk.NewCoin(simd.Config().Denom, sdkmath.NewInt(10_000_000))),
testProposal := controllertypes.MsgUpdateParams{
Signer: govAddress,
Params: controllertypes.Params{
ControllerEnabled: false,
},
}

proposalMsg, err := govv1.NewMsgSubmitProposal(
[]sdk.Msg{&testProposal},
sdk.NewCoins(sdk.NewCoin(simd.Config().Denom, sdkmath.NewInt(10_000_000))),
s.Contract.IcaAddress, "e2e", "e2e", "e2e", false,
)
s.Require().NoError(err)

initialBalance, err := simd.GetBalance(ctx, s.Contract.IcaAddress, simd.Config().Denom)
s.Require().NoError(err)

if encoding == icatypes.EncodingProtobuf {
// Execute the contract:
sendStargateMsg := icacontroller.NewExecuteMsg_SendCosmosMsgs_FromProto(
[]proto.Message{proposalMsg, depositMsg}, nil, nil,
[]proto.Message{proposalMsg}, nil, nil,
)
err = s.Contract.Execute(ctx, wasmdUser.KeyName(), sendStargateMsg)
s.Require().NoError(err)
} else if encoding == icatypes.EncodingProto3JSON {
sendCustomIcaMsg := icacontroller.NewExecuteMsg_SendCustomIcaMessages_FromProto(
simd.Config().EncodingConfig.Codec,
[]proto.Message{proposalMsg, depositMsg},
[]proto.Message{proposalMsg},
icatypes.EncodingProto3JSON, nil, nil,
)
err = s.Contract.Execute(ctx, wasmdUser.KeyName(), sendCustomIcaMsg)
Expand All @@ -581,15 +577,15 @@ func (s *ContractTestSuite) SendCosmosMsgsTestWithEncoding(encoding string) {
s.Require().Equal(uint64(0), callbackCounter.Error)

// Check if the proposal was created:
proposal, err := simd.QueryProposal(ctx, "1")
proposalResp, err := mysuite.GRPCQuery[govv1.QueryProposalResponse](ctx, simd, &govv1.QueryProposalRequest{
ProposalId: 1,
})
s.Require().NoError(err)
s.Require().Equal(simd.Config().Denom, proposal.TotalDeposit[0].Denom)
s.Require().Equal(fmt.Sprint(10_000_000+5_000), proposal.TotalDeposit[0].Amount)
// We do not check title and description of the proposal because this is a legacy proposal.
s.Require().Equal("e2e", proposalResp.Proposal.Title)

postBalance, err := simd.GetBalance(ctx, s.Contract.IcaAddress, simd.Config().Denom)
s.Require().NoError(err)
s.Require().Equal(initialBalance.Sub(sdkmath.NewInt(10_000_000+5_000)), postBalance)
s.Require().Equal(initialBalance.Sub(sdkmath.NewInt(10_000_000)), postBalance)
})

s.Run(fmt.Sprintf("TestDelegateAndVoteWeightedAndCommunityPool-%s", encoding), func() {
Expand Down Expand Up @@ -674,19 +670,25 @@ func (s *ContractTestSuite) SendCosmosMsgsTestWithEncoding(encoding string) {
s.Require().Equal(sdkmath.NewInt(10_000_000), delResp.DelegationResponse.Balance.Amount)

// Check if the vote was successful:
voteRequest := govtypes.QueryVoteRequest{
voteRequest := govv1.QueryVoteRequest{
ProposalId: 1,
Voter: s.Contract.IcaAddress,
}
voteResp, err := mysuite.GRPCQuery[govtypes.QueryVoteResponse](ctx, simd, &voteRequest)
voteResp, err := mysuite.GRPCQuery[govv1.QueryVoteResponse](ctx, simd, &voteRequest)
s.Require().NoError(err)
s.Require().Len(voteResp.Vote.Options, 2)
s.Require().Equal(govtypes.OptionYes, voteResp.Vote.Options[0].Option)

expWeight, err := sdkmath.LegacyNewDecFromStr("0.5")
s.Require().NoError(err)
s.Require().Equal(expWeight, voteResp.Vote.Options[0].Weight)
s.Require().Equal(govtypes.OptionAbstain, voteResp.Vote.Options[1].Option)
s.Require().Equal(expWeight, voteResp.Vote.Options[1].Weight)
actualWeight, err := sdkmath.LegacyNewDecFromStr(voteResp.Vote.Options[0].Weight)
s.Require().NoError(err)
actualWeight2, err := sdkmath.LegacyNewDecFromStr(voteResp.Vote.Options[1].Weight)
s.Require().NoError(err)

s.Require().Equal(govv1.OptionYes, voteResp.Vote.Options[0].Option)
s.Require().True(expWeight.Equal(actualWeight))
s.Require().Equal(govv1.OptionAbstain, voteResp.Vote.Options[1].Option)
s.Require().True(expWeight.Equal(actualWeight2))
})

s.Run(fmt.Sprintf("TestSendAndSetWithdrawAddress-%s", encoding), func() {
Expand Down
Loading

0 comments on commit d43e3e6

Please sign in to comment.