Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/github.com/CosmWasm/wa…
Browse files Browse the repository at this point in the history
…smvm/v2-2.1.5
  • Loading branch information
Eric-Warehime authored Feb 7, 2025
2 parents 87d1cbe + 5b7c34e commit 599bb74
Show file tree
Hide file tree
Showing 16 changed files with 370 additions and 89 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Export only validators that are participating in consensus
([\#3490](https://github.com/cosmos/gaia/pull/3490))
8 changes: 2 additions & 6 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# CODEOWNERS: https://help.github.com/articles/about-codeowners/

# Primary repo maintainers
* @cosmos/informal_gaia_maintain @cosmos/interchain_inc_gaia_write

# CODEOWNERS for the CODEOWNER file

/.github/CODEOWNERS @cosmos/informal_gaia_maintain
* @cosmos/interchain_inc_gaia_write

# CODEOWNERS for interchain tests

/tests/interchain @dasanchez @LexaMichaelides @fastfadingviolets @cosmos/informal_gaia_maintain @cosmos/interchain_inc_gaia_write
/tests/interchain @dasanchez @LexaMichaelides @fastfadingviolets @cosmos/interchain_inc_gaia_write
2 changes: 1 addition & 1 deletion .github/workflows/docker-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
flavor: "latest=false"

- name: Build and push docker image
uses: docker/build-push-action@v6.12.0
uses: docker/build-push-action@v6.13.0
with:
context: .
file: Dockerfile
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/md-link-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: gaurav-nelson/[email protected].15
- uses: gaurav-nelson/[email protected].16
with:
folder-path: "docs"
file-extension: ".mdx"
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9.0.0
- uses: actions/stale@v9.1.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-pr-message: "This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions."
Expand Down
13 changes: 13 additions & 0 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gaia

import (
"encoding/json"
"sort"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

Expand Down Expand Up @@ -43,6 +44,18 @@ func (app *GaiaApp) ExportAppStateAndValidators(
}

validators, err := staking.WriteValidators(ctx, app.StakingKeeper)
if err != nil {
return servertypes.ExportedApp{}, err
}
sort.SliceStable(validators, func(i, j int) bool {
return validators[i].Power > validators[j].Power
})
// we have to trim this to only active consensus validators
maxVals := app.ProviderKeeper.GetMaxProviderConsensusValidators(ctx)
if len(validators) > int(maxVals) {
validators = validators[:maxVals]
}

return servertypes.ExportedApp{
AppState: appState,
Validators: validators,
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ require (
github.com/skip-mev/feemarket v1.1.1
github.com/spf13/cast v1.7.1
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/pflag v1.0.6
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.10.0
)
Expand Down Expand Up @@ -129,7 +129,7 @@ require (
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.2.2 // indirect
github.com/golang/glog v1.2.4 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,8 @@ github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.2.2 h1:1+mZ9upx1Dh6FmUTFR1naJ77miKiXgALjWOZ3NVFPmY=
github.com/golang/glog v1.2.2/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/golang/glog v1.2.4 h1:CNNw5U8lSiiBk7druxtSHHTsRWcxKoac6kZKm2peBBc=
github.com/golang/glog v1.2.4/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -1237,8 +1237,9 @@ github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3k
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
Expand Down
Binary file added tests/e2e/data/counter.wasm
Binary file not shown.
126 changes: 126 additions & 0 deletions tests/e2e/e2e_cw_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package e2e

import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"os"
"path/filepath"
"time"

"github.com/cosmos/cosmos-sdk/client/flags"
)

func (s *IntegrationTestSuite) testCWCounter() {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
valIdx := 0
val := s.chainA.validators[valIdx]
address, _ := val.keyInfo.GetAddress()
sender := address.String()
dirName, err := os.Getwd()
s.Require().NoError(err)

// Copy file to container path and store the contract
src := filepath.Join(dirName, "data/counter.wasm")
dst := filepath.Join(val.configDir(), "config", "counter.wasm")
_, err = copyFile(src, dst)
s.Require().NoError(err)
storeWasmPath := configFile("counter.wasm")
s.storeWasm(ctx, s.chainA, valIdx, sender, storeWasmPath)

// Instantiate the contract
s.instantiateWasm(ctx, s.chainA, valIdx, sender, "1", "{\"count\":0}", "counter")
chainEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chainA.id][0].GetHostPort("1317/tcp"))
contractAddr, err := queryWasmContractAddress(chainEndpoint, address.String())
s.Require().NoError(err)

// Execute the contract
s.executeWasm(ctx, s.chainA, valIdx, sender, contractAddr, "{\"increment\":{}}")

// Validate count increment
query := map[string]interface{}{
"get_count": map[string]interface{}{},
}
queryJSON, err := json.Marshal(query)
s.Require().NoError(err)
queryMsg := base64.StdEncoding.EncodeToString(queryJSON)
data, err := queryWasmSmartContractState(chainEndpoint, contractAddr, queryMsg)
s.Require().NoError(err)
var counterResp map[string]int
err = json.Unmarshal(data, &counterResp)
s.Require().NoError(err)
s.Require().Equal(1, counterResp["count"])
}

func (s *IntegrationTestSuite) storeWasm(ctx context.Context, c *chain, valIdx int, sender, wasmPath string) {
storeCmd := []string{
gaiadBinary,
txCommand,
"wasm",
"store",
wasmPath,
fmt.Sprintf("--from=%s", sender),
fmt.Sprintf("--%s=%s", flags.FlagFees, standardFees.String()),
fmt.Sprintf("--%s=%s", flags.FlagChainID, c.id),
"--gas=2000000",
"--keyring-backend=test",
"--broadcast-mode=sync",
"--output=json",
"-y",
}

s.T().Logf("%s storing wasm on host chain %s", sender, s.chainB.id)
s.executeGaiaTxCommand(ctx, c, storeCmd, valIdx, s.defaultExecValidation(c, valIdx))
s.T().Log("successfully sent store wasm tx")
}

func (s *IntegrationTestSuite) instantiateWasm(ctx context.Context, c *chain, valIdx int, sender, codeID,
msg, label string,
) {
storeCmd := []string{
gaiadBinary,
txCommand,
"wasm",
"instantiate",
codeID,
msg,
fmt.Sprintf("--from=%s", sender),
fmt.Sprintf("--%s=%s", flags.FlagFees, standardFees.String()),
fmt.Sprintf("--%s=%s", flags.FlagChainID, c.id),
fmt.Sprintf("--label=%s", label),
"--no-admin",
"--gas=250000",
"--keyring-backend=test",
"--broadcast-mode=sync",
"--output=json",
"-y",
}

s.T().Logf("%s instantiating wasm on host chain %s", sender, s.chainB.id)
s.executeGaiaTxCommand(ctx, c, storeCmd, valIdx, s.defaultExecValidation(c, valIdx))
s.T().Log("successfully sent instantiate wasm tx")
}

func (s *IntegrationTestSuite) executeWasm(ctx context.Context, c *chain, valIdx int, sender, addr, msg string) {
execCmd := []string{
gaiadBinary,
txCommand,
"wasm",
"execute",
addr,
msg,
fmt.Sprintf("--from=%s", sender),
fmt.Sprintf("--%s=%s", flags.FlagFees, standardFees.String()),
fmt.Sprintf("--%s=%s", flags.FlagChainID, c.id),
"--gas=250000",
"--keyring-backend=test",
"--broadcast-mode=sync",
"--output=json",
"-y",
}
s.T().Logf("%s executing wasm on host chain %s", sender, s.chainB.id)
s.executeGaiaTxCommand(ctx, c, execCmd, valIdx, s.defaultExecValidation(c, valIdx))
s.T().Log("successfully sent execute wasm tx")
}
8 changes: 8 additions & 0 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var (
runLsmTest = true
runRateLimitTest = true
runTxExtensionsTest = true
runCWTest = true
)

func (s *IntegrationTestSuite) TestRestInterfaces() {
Expand Down Expand Up @@ -131,3 +132,10 @@ func (s *IntegrationTestSuite) TestTxExtensions() {
s.bankSendWithNonCriticalExtensionOptions()
s.failedBankSendWithNonCriticalExtensionOptions()
}

func (s *IntegrationTestSuite) TestCW() {
if !runCWTest {
s.T().Skip()
}
s.testCWCounter()
}
30 changes: 30 additions & 0 deletions tests/e2e/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
)

func queryGaiaTx(endpoint, txHash string) error {
Expand Down Expand Up @@ -373,3 +375,31 @@ func queryBlocksPerEpoch(endpoint string) (int64, error) {

return response.Params.BlocksPerEpoch, nil
}

func queryWasmContractAddress(endpoint, creator string) (string, error) {
body, err := httpGet(fmt.Sprintf("%s/cosmwasm/wasm/v1/contracts/creator/%s", endpoint, creator))
if err != nil {
return "", fmt.Errorf("failed to execute HTTP request: %w", err)
}

var response wasmtypes.QueryContractsByCreatorResponse
if err = cdc.UnmarshalJSON(body, &response); err != nil {
return "", err
}

return response.ContractAddresses[0], nil
}

func queryWasmSmartContractState(endpoint, address, msg string) ([]byte, error) {
body, err := httpGet(fmt.Sprintf("%s/cosmwasm/wasm/v1/contract/%s/smart/%s", endpoint, address, msg))
if err != nil {
return nil, fmt.Errorf("failed to execute HTTP request: %w", err)
}

var response wasmtypes.QuerySmartContractStateResponse
if err = cdc.UnmarshalJSON(body, &response); err != nil {
return nil, err
}

return response.Data, nil
}
Loading

0 comments on commit 599bb74

Please sign in to comment.