(no commit message provided)

This commit is contained in:
Prad Nukala
2024-07-05 22:20:13 -04:00
committed by Prad Nukala (aider)
commit 5fd43dfd6b
457 changed files with 115535 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
package e2e
import (
"context"
"testing"
"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
)
func TestBasicChain(t *testing.T) {
cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{
&DefaultChainSpec,
})
chains, err := cf.Chains(t.Name())
require.NoError(t, err)
chain := chains[0].(*cosmos.CosmosChain)
ic := interchaintest.NewInterchain().
AddChain(chain)
ctx := context.Background()
client, network := interchaintest.DockerSetup(t)
require.NoError(t, ic.Build(ctx, nil, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: true,
}))
t.Cleanup(func() {
_ = ic.Close()
})
// faucet funds to the user
users := interchaintest.GetAndFundTestUsers(t, ctx, "default", GenesisFundsAmount, chain)
user := users[0]
// balance check
balance, err := chain.GetBalance(ctx, user.FormattedAddress(), Denom)
require.NoError(t, err)
require.True(t, balance.Equal(GenesisFundsAmount), "user balance should be equal to genesis funds")
}
+278
View File
@@ -0,0 +1,278 @@
module github.com/di-dao/core/interchaintest
go 1.21
toolchain go1.21.0
replace (
// not tagged properly (SDK v51)
cosmossdk.io/core => cosmossdk.io/core v0.11.0
github.com/ChainSafe/go-schnorrkel => github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d
github.com/ChainSafe/go-schnorrkel/1 => github.com/ChainSafe/go-schnorrkel v1.0.0
github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.22.2 //indirect
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
// breaks SDK app.toml parsing for client configs.
github.com/spf13/viper => github.com/spf13/viper v1.17.0
// If using custom internal modules, replace your app here with the parent application
// github.com/di-dao/core => ../.
github.com/vedhavyas/go-subkey => github.com/strangelove-ventures/go-subkey v1.0.7
)
require (
cosmossdk.io/math v1.3.0
github.com/cosmos/cosmos-sdk v0.50.5
github.com/cosmos/ibc-go/v8 v8.2.0
github.com/strangelove-ventures/globalfee v0.50.0
github.com/strangelove-ventures/interchaintest/v8 v8.1.0
github.com/strangelove-ventures/poa v0.50.0
github.com/strangelove-ventures/tokenfactory v0.50.0
github.com/stretchr/testify v1.9.0
go.uber.org/zap v1.27.0
)
require (
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/storage v1.37.0 // indirect
cosmossdk.io/api v0.7.3 // indirect
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/core v0.12.0 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/store v1.0.2 // indirect
cosmossdk.io/x/feegrant v0.1.0 // indirect
cosmossdk.io/x/tx v0.13.1 // indirect
cosmossdk.io/x/upgrade v0.1.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/ChainSafe/go-schnorrkel v1.1.0 // indirect
github.com/ChainSafe/go-schnorrkel/1 v0.0.0-00010101000000-000000000000 // indirect
github.com/ComposableFi/go-subkey/v2 v2.0.0-tm03420 // indirect
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/StirlingMarketingGroup/go-namecase v1.0.0 // indirect
github.com/avast/retry-go/v4 v4.5.1 // indirect
github.com/aws/aws-sdk-go v1.46.6 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/errors v1.11.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v1.1.0 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cometbft/cometbft v0.38.8 // indirect
github.com/cometbft/cometbft-db v0.9.1 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-db v1.0.2 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.4 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.4.11 // indirect
github.com/cosmos/iavl v1.0.1 // indirect
github.com/cosmos/ibc-go/modules/capability v1.0.0 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/decred/base58 v1.0.5 // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v2 v2.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v24.0.9+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
github.com/emicklei/dot v1.6.1 // indirect
github.com/ethereum/go-ethereum v1.14.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
github.com/go-kit/kit v0.13.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.3 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gorilla/handlers v1.5.2 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.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.7.5 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-metrics v0.5.2 // indirect
github.com/hashicorp/go-plugin v1.5.2 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/huandu/skiplist v1.2.0 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/icza/dyno v0.0.0-20230330125955-09f820a8d9c0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-libp2p v0.33.2 // indirect
github.com/linxGnu/grocksdb v1.8.12 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mimoo/StrobeGo v0.0.0-20220103164710-9a04d6ca976b // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/misko9/go-substrate-rpc-client/v4 v4.0.0-20230913220906-b988ea7da0c2 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/multiformats/go-multiaddr v0.12.3 // indirect
github.com/multiformats/go-multibase v0.2.0 // indirect
github.com/multiformats/go-multicodec v0.9.0 // indirect
github.com/multiformats/go-multihash v0.2.3 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/onsi/gomega v1.30.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc // indirect
github.com/pierrec/xxHash v0.1.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.49.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/cors v1.10.1 // indirect
github.com/rs/zerolog v1.32.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.18.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tidwall/btree v1.7.0 // indirect
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
go.etcd.io/bbolt v1.3.8 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.47.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.20.0 // indirect
google.golang.org/api v0.162.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect
google.golang.org/grpc v1.62.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
lukechampine.com/blake3 v1.2.2 // indirect
lukechampine.com/uint128 v1.3.0 // indirect
modernc.org/cc/v3 v3.41.0 // indirect
modernc.org/ccgo/v3 v3.16.15 // indirect
modernc.org/libc v1.29.0 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/sqlite v1.28.0 // indirect
modernc.org/strutil v1.2.0 // indirect
modernc.org/token v1.1.0 // indirect
nhooyr.io/websocket v1.8.10 // indirect
pgregory.net/rapid v1.1.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
File diff suppressed because it is too large Load Diff
+137
View File
@@ -0,0 +1,137 @@
package e2e
import (
"context"
"testing"
"cosmossdk.io/math"
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
interchaintestrelayer "github.com/strangelove-ventures/interchaintest/v8/relayer"
"github.com/strangelove-ventures/interchaintest/v8/testreporter"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest"
)
const (
ibcPath = "ibc-path"
)
func TestIBC(t *testing.T) {
t.Parallel()
ctx := context.Background()
cfgA := DefaultChainConfig
cfgA.ChainID = cfgA.ChainID + "-1"
cfgB := DefaultChainConfig
cfgB.ChainID = cfgB.ChainID + "-2"
cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t, zaptest.Level(zapcore.DebugLevel)), []*interchaintest.ChainSpec{
{
Name: DefaultChainConfig.Name,
Version: ChainImage.Version,
ChainName: cfgA.ChainID,
NumValidators: &NumberVals,
NumFullNodes: &NumberFullNodes,
ChainConfig: cfgA,
},
{
Name: DefaultChainConfig.Name,
Version: ChainImage.Version,
ChainName: cfgB.ChainID,
NumValidators: &NumberVals,
NumFullNodes: &NumberFullNodes,
ChainConfig: cfgB,
},
})
chains, err := cf.Chains(t.Name())
require.NoError(t, err)
chainA, chainB := chains[0].(*cosmos.CosmosChain), chains[1].(*cosmos.CosmosChain)
// Relayer Factory
client, network := interchaintest.DockerSetup(t)
rf := interchaintest.NewBuiltinRelayerFactory(
ibc.CosmosRly,
zaptest.NewLogger(t, zaptest.Level(zapcore.DebugLevel)),
interchaintestrelayer.CustomDockerImage(RelayerRepo, RelayerVersion, "100:1000"),
interchaintestrelayer.StartupFlags("--processor", "events", "--block-history", "100"),
)
r := rf.Build(t, client, network)
ic := interchaintest.NewInterchain().
AddChain(chainA).
AddChain(chainB).
AddRelayer(r, "relayer").
AddLink(interchaintest.InterchainLink{
Chain1: chainA,
Chain2: chainB,
Relayer: r,
Path: ibcPath,
})
rep := testreporter.NewNopReporter()
eRep := rep.RelayerExecReporter(t)
// Build interchain
require.NoError(t, ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: false,
}))
// Create and Fund User Wallets
fundAmount := math.NewInt(10_000_000)
users := interchaintest.GetAndFundTestUsers(t, ctx, "default", fundAmount, chainA, chainB)
userA := users[0]
userB := users[1]
userAInitial, err := chainA.GetBalance(ctx, userA.FormattedAddress(), chainA.Config().Denom)
require.NoError(t, err)
require.True(t, userAInitial.Equal(fundAmount))
// Get Channel ID
aInfo, err := r.GetChannels(ctx, eRep, chainA.Config().ChainID)
require.NoError(t, err)
aChannelID := aInfo[0].ChannelID
bInfo, err := r.GetChannels(ctx, eRep, chainB.Config().ChainID)
require.NoError(t, err)
bChannelID := bInfo[0].ChannelID
// Send Transaction
amountToSend := math.NewInt(1_000_000)
dstAddress := userB.FormattedAddress()
transfer := ibc.WalletAmount{
Address: dstAddress,
Denom: chainA.Config().Denom,
Amount: amountToSend,
}
_, err = chainA.SendIBCTransfer(ctx, aChannelID, userA.KeyName(), transfer, ibc.TransferOptions{})
require.NoError(t, err)
// relay MsgRecvPacket to chainB, then MsgAcknowledgement back to chainA
require.NoError(t, r.Flush(ctx, eRep, ibcPath, aChannelID))
// test source wallet has decreased funds
expectedBal := userAInitial.Sub(amountToSend)
aNewBal, err := chainA.GetBalance(ctx, userA.FormattedAddress(), chainA.Config().Denom)
require.NoError(t, err)
require.True(t, aNewBal.Equal(expectedBal))
// Trace IBC Denom
srcDenomTrace := transfertypes.ParseDenomTrace(transfertypes.GetPrefixedDenom("transfer", bChannelID, chainA.Config().Denom))
dstIbcDenom := srcDenomTrace.IBCDenom()
// Test destination wallet has increased funds
bNewBal, err := chainB.GetBalance(ctx, userB.FormattedAddress(), dstIbcDenom)
require.NoError(t, err)
require.True(t, bNewBal.Equal(amountToSend))
}
+231
View File
@@ -0,0 +1,231 @@
package e2e
import (
"context"
"encoding/json"
"testing"
"time"
"cosmossdk.io/math"
"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
interchaintestrelayer "github.com/strangelove-ventures/interchaintest/v8/relayer"
"github.com/strangelove-ventures/interchaintest/v8/testreporter"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
type PacketMetadata struct {
Forward *ForwardMetadata `json:"forward"`
}
type ForwardMetadata struct {
Receiver string `json:"receiver"`
Port string `json:"port"`
Channel string `json:"channel"`
Timeout time.Duration `json:"timeout"`
Retries *uint8 `json:"retries,omitempty"`
Next *string `json:"next,omitempty"`
RefundSequence *uint64 `json:"refund_sequence,omitempty"`
}
func TestPacketForwardMiddleware(t *testing.T) {
if testing.Short() {
t.Skip()
}
var (
ctx = context.Background()
client, network = interchaintest.DockerSetup(t)
rep = testreporter.NewNopReporter()
eRep = rep.RelayerExecReporter(t)
chainID_A, chainID_B, chainID_C = "chain-a", "chain-b", "chain-c"
chainA, chainB, chainC *cosmos.CosmosChain
)
// base config which all networks will use as defaults.
baseCfg := DefaultChainConfig
// Set specific chain ids for each so they are their own unique networks
baseCfg.ChainID = chainID_A
configA := baseCfg
baseCfg.ChainID = chainID_B
configB := baseCfg
baseCfg.ChainID = chainID_C
configC := baseCfg
// Create chain factory with multiple individual networks.
numVals := 1
numFullNodes := 0
cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{
{
Name: configA.Name,
ChainConfig: configA,
NumValidators: &numVals,
NumFullNodes: &numFullNodes,
},
{
Name: configA.Name,
ChainConfig: configB,
NumValidators: &numVals,
NumFullNodes: &numFullNodes,
},
{
Name: configA.Name,
ChainConfig: configC,
NumValidators: &numVals,
NumFullNodes: &numFullNodes,
},
})
// Get chains from the chain factory
chains, err := cf.Chains(t.Name())
require.NoError(t, err)
chainA, chainB, chainC = chains[0].(*cosmos.CosmosChain), chains[1].(*cosmos.CosmosChain), chains[2].(*cosmos.CosmosChain)
r := interchaintest.NewBuiltinRelayerFactory(
ibc.CosmosRly,
zaptest.NewLogger(t),
interchaintestrelayer.CustomDockerImage(RelayerRepo, RelayerVersion, "100:1000"),
interchaintestrelayer.StartupFlags("--processor", "events", "--block-history", "100"),
).Build(t, client, network)
const pathAB = "ab"
const pathBC = "bc"
ic := interchaintest.NewInterchain().
AddChain(chainA).
AddChain(chainB).
AddChain(chainC).
AddRelayer(r, "relayer").
AddLink(interchaintest.InterchainLink{
Chain1: chainA,
Chain2: chainB,
Relayer: r,
Path: pathAB,
}).
AddLink(interchaintest.InterchainLink{
Chain1: chainB,
Chain2: chainC,
Relayer: r,
Path: pathBC,
})
require.NoError(t, ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
BlockDatabaseFile: interchaintest.DefaultBlockDatabaseFilepath(),
SkipPathCreation: false,
}))
t.Cleanup(func() {
_ = ic.Close()
})
users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), GenesisFundsAmount, chainA, chainB, chainC)
abChan, err := ibc.GetTransferChannel(ctx, r, eRep, chainID_A, chainID_B)
require.NoError(t, err)
baChan := abChan.Counterparty
cbChan, err := ibc.GetTransferChannel(ctx, r, eRep, chainID_C, chainID_B)
require.NoError(t, err)
bcChan := cbChan.Counterparty
// Start the relayer on all paths
err = r.StartRelayer(ctx, eRep, pathAB, pathBC)
require.NoError(t, err)
t.Cleanup(
func() {
err := r.StopRelayer(ctx, eRep)
if err != nil {
t.Logf("an error occurred while stopping the relayer: %s", err)
}
},
)
// Get original account balances
userA, userB, userC := users[0], users[1], users[2]
var transferAmount math.Int = math.NewInt(100_000)
// Compose the prefixed denoms and ibc denom for asserting balances
firstHopDenom := transfertypes.GetPrefixedDenom(baChan.PortID, baChan.ChannelID, chainA.Config().Denom)
secondHopDenom := transfertypes.GetPrefixedDenom(cbChan.PortID, cbChan.ChannelID, firstHopDenom)
firstHopDenomTrace := transfertypes.ParseDenomTrace(firstHopDenom)
secondHopDenomTrace := transfertypes.ParseDenomTrace(secondHopDenom)
firstHopIBCDenom := firstHopDenomTrace.IBCDenom()
secondHopIBCDenom := secondHopDenomTrace.IBCDenom()
firstHopEscrowAccount := sdk.MustBech32ifyAddressBytes(chainA.Config().Bech32Prefix, transfertypes.GetEscrowAddress(abChan.PortID, abChan.ChannelID))
secondHopEscrowAccount := sdk.MustBech32ifyAddressBytes(chainB.Config().Bech32Prefix, transfertypes.GetEscrowAddress(bcChan.PortID, bcChan.ChannelID))
t.Run("multi-hop a->b->c", func(t *testing.T) {
// Send packet from Chain A->Chain B->Chain C
transfer := ibc.WalletAmount{
Address: userB.FormattedAddress(),
Denom: chainA.Config().Denom,
Amount: transferAmount,
}
firstHopMetadata := &PacketMetadata{
Forward: &ForwardMetadata{
Receiver: userC.FormattedAddress(),
Channel: bcChan.ChannelID,
Port: bcChan.PortID,
},
}
memo, err := json.Marshal(firstHopMetadata)
require.NoError(t, err)
chainAHeight, err := chainA.Height(ctx)
require.NoError(t, err)
transferTx, err := chainA.SendIBCTransfer(ctx, abChan.ChannelID, userA.KeyName(), transfer, ibc.TransferOptions{Memo: string(memo)})
require.NoError(t, err)
_, err = testutil.PollForAck(ctx, chainA, chainAHeight, chainAHeight+30, transferTx.Packet)
require.NoError(t, err)
err = testutil.WaitForBlocks(ctx, 1, chainA)
require.NoError(t, err)
chainABalance, err := chainA.GetBalance(ctx, userA.FormattedAddress(), chainA.Config().Denom)
require.NoError(t, err)
chainBBalance, err := chainB.GetBalance(ctx, userB.FormattedAddress(), firstHopIBCDenom)
require.NoError(t, err)
chainCBalance, err := chainC.GetBalance(ctx, userC.FormattedAddress(), secondHopIBCDenom)
require.NoError(t, err)
require.Equal(t, GenesisFundsAmount.Sub(transferAmount).Int64(), chainABalance.Int64())
require.Equal(t, int64(0), chainBBalance.Int64())
require.Equal(t, int64(100000), chainCBalance.Int64())
firstHopEscrowBalance, err := chainA.GetBalance(ctx, firstHopEscrowAccount, chainA.Config().Denom)
require.NoError(t, err)
secondHopEscrowBalance, err := chainB.GetBalance(ctx, secondHopEscrowAccount, firstHopIBCDenom)
require.NoError(t, err)
require.Equal(t, transferAmount.Int64(), firstHopEscrowBalance.Int64())
require.Equal(t, transferAmount.Int64(), secondHopEscrowBalance.Int64())
})
}
+135
View File
@@ -0,0 +1,135 @@
package e2e
import (
"context"
"fmt"
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/poa"
"github.com/stretchr/testify/require"
)
func POASetPower(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, valoper string, power int64, flags ...string) (sdk.TxResponse, error) {
cmd := TxCommandBuilder(ctx, chain, []string{"tx", "poa", "set-power", valoper, fmt.Sprintf("%d", power)}, user.KeyName(), flags...)
return ExecuteTransaction(ctx, chain, cmd)
}
func POARemove(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, valoper string) (sdk.TxResponse, error) {
cmd := TxCommandBuilder(ctx, chain, []string{"tx", "poa", "remove", valoper}, user.KeyName())
return ExecuteTransaction(ctx, chain, cmd)
}
func POARemovePending(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, valoper string) (sdk.TxResponse, error) {
cmd := TxCommandBuilder(ctx, chain, []string{"tx", "poa", "remove-pending", valoper}, user.KeyName())
return ExecuteTransaction(ctx, chain, cmd)
}
func POACreatePendingValidator(
t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet,
ed25519PubKey string, moniker string, commissionRate string, commissionMaxRate string, commissionMaxChangeRate string,
) (sdk.TxResponse, error) {
file := "validator_file.json"
content := fmt.Sprintf(`{
"pubkey": {"@type":"/cosmos.crypto.ed25519.PubKey","key":"%s"},
"amount": "0%s",
"moniker": "%s",
"identity": "",
"website": "https://website.com",
"security": "security@cosmos.xyz",
"details": "description",
"commission-rate": "%s",
"commission-max-rate": "%s",
"commission-max-change-rate": "%s",
"min-self-delegation": "1"
}`, ed25519PubKey, chain.Config().Denom, moniker, commissionRate, commissionMaxRate, commissionMaxChangeRate)
err := chain.GetNode().WriteFile(ctx, []byte(content), file)
require.NoError(t, err)
filePath := fmt.Sprintf("%s/%s", chain.GetNode().HomeDir(), file)
cmd := TxCommandBuilder(ctx, chain, []string{"tx", "poa", "create-validator", filePath}, user.KeyName())
return ExecuteTransaction(ctx, chain, cmd)
}
func SubmitGovernanceProposalForValidatorChanges(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, validator string, power uint64, unsafe bool) string {
govAddr := "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn"
powerMsg := []cosmos.ProtoMessage{
&poa.MsgSetPower{
Sender: govAddr,
ValidatorAddress: validator,
Power: power,
Unsafe: unsafe,
},
}
title := fmt.Sprintf("Update" + validator + "Power")
desc := fmt.Sprintf("Updating power for validator %s to %d", validator, power)
proposal, err := chain.BuildProposal(powerMsg, title, desc, desc, fmt.Sprintf(`50%s`, chain.Config().Denom), user.FormattedAddress(), false)
require.NoError(t, err, "error building proposal")
fmt.Printf("proposal: %+v\n", proposal)
txProp, err := chain.SubmitProposal(ctx, user.KeyName(), proposal)
t.Log("txProp", txProp)
require.NoError(t, err, "error submitting proposal")
return txProp.ProposalID
}
func GetPOAParams(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain) poa.Params {
var res poa.ParamsResponse
ExecuteQuery(ctx, chain, []string{"query", "poa", "params"}, &res)
return res.Params
}
func GetPOAConsensusPower(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, valoperAddr string) int64 {
res, err := poa.NewQueryClient(chain.GetNode().GrpcConn).ConsensusPower(ctx, &poa.QueryConsensusPowerRequest{ValidatorAddress: valoperAddr})
require.NoError(t, err)
return res.ConsensusPower
}
func GetPOAPending(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain) []poa.Validator {
res, err := poa.NewQueryClient(chain.GetNode().GrpcConn).PendingValidators(ctx, &poa.QueryPendingValidatorsRequest{})
require.NoError(t, err)
return res.Pending
}
func POAUpdateParams(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, admins []string, gracefulExit bool) (sdk.TxResponse, error) {
// admin1,admin2,admin3
adminList := ""
for _, admin := range admins {
adminList += admin + ","
}
adminList = adminList[:len(adminList)-1]
gracefulParam := "true"
if !gracefulExit {
gracefulParam = "false"
}
cmd := TxCommandBuilder(ctx, chain, []string{"tx", "poa", "update-params", adminList, gracefulParam}, user.KeyName())
return ExecuteTransaction(ctx, chain, cmd)
}
func POAUpdateStakingParams(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, sp stakingtypes.Params) (sdk.TxResponse, error) {
command := []string{"tx", "poa", "update-staking-params",
sp.UnbondingTime.String(),
fmt.Sprintf("%d", sp.MaxValidators),
fmt.Sprintf("%d", sp.MaxEntries),
fmt.Sprintf("%d", sp.HistoricalEntries),
sp.BondDenom,
fmt.Sprintf("%d", sp.MinCommissionRate),
}
cmd := TxCommandBuilder(ctx, chain, command, user.KeyName())
return ExecuteTransaction(ctx, chain, cmd)
}
+182
View File
@@ -0,0 +1,182 @@
package e2e
import (
"context"
"fmt"
"testing"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
"github.com/strangelove-ventures/poa"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)
const (
numPOAVals = 2
)
func TestPOA(t *testing.T) {
if testing.Short() {
t.Skip("skipping in short mode")
}
// setup base chain
chains := interchaintest.CreateChainWithConfig(t, numPOAVals, NumberFullNodes, Name, ChainImage.Version, DefaultChainConfig)
chain := chains[0].(*cosmos.CosmosChain)
enableBlockDB := false
ctx, _, _, _ := interchaintest.BuildInitialChain(t, chains, enableBlockDB)
// setup accounts
acc0, err := interchaintest.GetAndFundTestUserWithMnemonic(ctx, "acc0", AccMnemonic, GenesisFundsAmount, chain)
require.NoError(t, err)
acc1, err := interchaintest.GetAndFundTestUserWithMnemonic(ctx, "acc1", Acc1Mnemonic, GenesisFundsAmount, chain)
require.NoError(t, err)
users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), GenesisFundsAmount, chain)
incorrectUser := users[0]
// get validator operator addresses
vals, err := chain.StakingQueryValidators(ctx, stakingtypes.Bonded.String())
require.NoError(t, err)
require.Equal(t, len(vals), numPOAVals)
validators := make([]string, len(vals))
for i, v := range vals {
validators[i] = v.OperatorAddress
}
// === Test Cases ===
testStakingDisabled(t, ctx, chain, validators, acc0, acc1)
testPowerErrors(t, ctx, chain, validators, incorrectUser, acc0)
testPending(t, ctx, chain, acc0)
testRemoveValidator(t, ctx, chain, validators, acc0)
}
func testRemoveValidator(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, validators []string, acc0 ibc.Wallet) {
t.Log("\n===== TEST REMOVE VALIDATOR =====")
powerOne := int64(9_000_000_000_000)
powerTwo := int64(2_500_000)
res, _ := POASetPower(t, ctx, chain, acc0, validators[0], powerOne, "--unsafe")
fmt.Printf("%+v", res)
res, _ = POASetPower(t, ctx, chain, acc0, validators[1], powerTwo, "--unsafe")
fmt.Printf("%+v", res)
// decode res.TxHash into a TxResponse
txRes, err := chain.GetTransaction(res.TxHash)
require.NoError(t, err)
fmt.Printf("%+v", txRes)
if err := testutil.WaitForBlocks(ctx, 2, chain); err != nil {
t.Fatal(err)
}
vals, err := chain.StakingQueryValidators(ctx, stakingtypes.Bonded.String())
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("%d", powerOne), vals[0].Tokens.String())
require.Equal(t, fmt.Sprintf("%d", powerTwo), vals[1].Tokens.String())
// validate the validators both have a conesnsus-power of /1_000_000
p1 := GetPOAConsensusPower(t, ctx, chain, vals[0].OperatorAddress)
require.EqualValues(t, powerOne/1_000_000, p1) // = 9000000
p2 := GetPOAConsensusPower(t, ctx, chain, vals[1].OperatorAddress)
require.EqualValues(t, powerTwo/1_000_000, p2) // = 2
// remove the 2nd validator (lower power)
POARemove(t, ctx, chain, acc0, validators[1])
// allow the poa.BeginBlocker to update new status
if err := testutil.WaitForBlocks(ctx, 5, chain); err != nil {
t.Fatal(err)
}
vals, err = chain.StakingQueryValidators(ctx, stakingtypes.Bonded.String())
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("%d", powerOne), vals[0].Tokens.String())
require.Equal(t, 1, len(vals))
vals, err = chain.StakingQueryValidators(ctx, stakingtypes.Unbonded.String())
require.NoError(t, err)
require.Equal(t, "0", vals[0].Tokens.String())
require.Equal(t, 1, len(vals))
p2 = GetPOAConsensusPower(t, ctx, chain, vals[0].OperatorAddress)
require.EqualValues(t, 0, p2)
}
func testStakingDisabled(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, validators []string, acc0, acc1 ibc.Wallet) {
t.Log("\n===== TEST STAKING DISABLED =====")
err := chain.GetNode().StakingDelegate(ctx, acc0.KeyName(), validators[0], "1stake")
require.Error(t, err)
require.Contains(t, err.Error(), poa.ErrStakingActionNotAllowed.Error())
granter := acc1
grantee := acc0
// Grant grantee (acc0) the ability to delegate from granter (acc1)
res, err := chain.GetNode().AuthzGrant(ctx, granter, grantee.FormattedAddress(), "generic", "--msg-type", "/cosmos.staking.v1beta1.MsgDelegate")
require.NoError(t, err)
require.EqualValues(t, res.Code, 0)
// Generate nested message
nested := []string{"tx", "staking", "delegate", validators[0], "1stake"}
nestedCmd := TxCommandBuilder(ctx, chain, nested, granter.FormattedAddress())
// Execute nested message via a wrapped Exec
_, err = chain.GetNode().AuthzExec(ctx, grantee, nestedCmd)
require.Error(t, err)
require.Contains(t, err.Error(), poa.ErrStakingActionNotAllowed.Error())
}
func testPending(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, acc0 ibc.Wallet) {
t.Log("\n===== TEST PENDING =====")
res, _ := POACreatePendingValidator(t, ctx, chain, acc0, "pl3Q8OQwtC7G2dSqRqsUrO5VZul7l40I+MKUcejqRsg=", "testval", "0.10", "0.25", "0.05")
require.EqualValues(t, 0, res.Code)
require.NoError(t, testutil.WaitForBlocks(ctx, 2, chain))
pv := GetPOAPending(t, ctx, chain)
require.Equal(t, 1, len(pv))
require.Equal(t, "0", pv[0].Tokens.String())
require.Equal(t, "1", pv[0].MinSelfDelegation.String())
res, _ = POARemovePending(t, ctx, chain, acc0, pv[0].OperatorAddress)
require.EqualValues(t, 0, res.Code)
// validate it was removed
pv = GetPOAPending(t, ctx, chain)
require.Equal(t, 0, len(pv))
}
func testPowerErrors(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, validators []string, incorrectUser ibc.Wallet, admin ibc.Wallet) {
t.Log("\n===== TEST POWER ERRORS =====")
var res sdk.TxResponse
var err error
t.Run("fail: set-power message from a non authorized user", func(t *testing.T) {
res, _ = POASetPower(t, ctx, chain, incorrectUser, validators[1], 1_000_000)
res, err := chain.GetTransaction(res.TxHash)
require.NoError(t, err)
require.Contains(t, res.RawLog, poa.ErrNotAnAuthority.Error())
})
t.Run("fail: set-power message below minimum power requirement (self bond)", func(t *testing.T) {
res, err = POASetPower(t, ctx, chain, admin, validators[0], 1)
require.Error(t, err) // cli validate error
require.Contains(t, err.Error(), poa.ErrPowerBelowMinimum.Error())
})
t.Run("fail: set-power message above 30%% without unsafe flag", func(t *testing.T) {
res, _ = POASetPower(t, ctx, chain, admin, validators[0], 9_000_000_000_000_000)
res, err := chain.GetTransaction(res.TxHash)
require.NoError(t, err)
require.Contains(t, res.RawLog, poa.ErrUnsafePower.Error())
})
}
+175
View File
@@ -0,0 +1,175 @@
package e2e
import (
"context"
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
globalfee "github.com/strangelove-ventures/globalfee/x/globalfee/types"
poa "github.com/strangelove-ventures/poa"
tokenfactory "github.com/strangelove-ventures/tokenfactory/x/tokenfactory/types"
)
var (
VotingPeriod = "15s"
MaxDepositPeriod = "10s"
Denom = "usnr"
Name = "sonr"
ChainID = "chainid-1"
Binary = "sonrd"
Bech32 = "idx"
NumberVals = 1
NumberFullNodes = 0
GenesisFundsAmount = sdkmath.NewInt(1000_000000) // 1k tokens
ChainImage = ibc.NewDockerImage("core", "local", "1025:1025")
DefaultGenesis = []cosmos.GenesisKV{
// default
cosmos.NewGenesisKV("app_state.gov.params.voting_period", VotingPeriod),
cosmos.NewGenesisKV("app_state.gov.params.max_deposit_period", MaxDepositPeriod),
cosmos.NewGenesisKV("app_state.gov.params.min_deposit.0.denom", Denom),
cosmos.NewGenesisKV("app_state.gov.params.min_deposit.0.amount", "1"),
// poa: gov & testing account
cosmos.NewGenesisKV("app_state.poa.params.admins", []string{"idx10d07y265gmmuvt4z0w9aw880jnsr700j9kqcfa", "idx1hj5fveer5cjtn4wd6wstzugjfdxzl0xpecp0nd"}),
// globalfee: set minimum fee requirements
cosmos.NewGenesisKV("app_state.globalfee.params.minimum_gas_prices", sdk.DecCoins{sdk.NewDecCoinFromDec(Denom, sdkmath.LegacyMustNewDecFromStr("0.0"))}),
// tokenfactory: set create cost in set denom or in gas usage.
cosmos.NewGenesisKV("app_state.tokenfactory.params.denom_creation_fee", nil),
cosmos.NewGenesisKV("app_state.tokenfactory.params.denom_creation_gas_consume", 1), // cost 1 gas to create a new denom
}
DefaultChainConfig = ibc.ChainConfig{
Images: []ibc.DockerImage{
ChainImage,
},
GasAdjustment: 1.5,
ModifyGenesis: cosmos.ModifyGenesis(DefaultGenesis),
EncodingConfig: func() *moduletestutil.TestEncodingConfig {
cfg := cosmos.DefaultEncoding()
// TODO: add encoding types here for the modules you want to use
tokenfactory.RegisterInterfaces(cfg.InterfaceRegistry)
globalfee.RegisterInterfaces(cfg.InterfaceRegistry)
poa.RegisterInterfaces(cfg.InterfaceRegistry)
return &cfg
}(),
Type: "cosmos",
Name: Name,
ChainID: ChainID,
Bin: Binary,
Bech32Prefix: Bech32,
Denom: Denom,
CoinType: "118",
GasPrices: "0" + Denom,
TrustingPeriod: "336h",
}
DefaultChainSpec = interchaintest.ChainSpec{
Name: Name,
ChainName: Name,
Version: ChainImage.Version,
ChainConfig: DefaultChainConfig,
NumValidators: &NumberVals,
NumFullNodes: &NumberFullNodes,
}
// cosmos1hj5fveer5cjtn4wd6wstzugjfdxzl0xpxvjjvr - test_node.sh
AccMnemonic = "decorate bright ozone fork gallery riot bus exhaust worth way bone indoor calm squirrel merry zero scheme cotton until shop any excess stage laundry"
Acc1Mnemonic = "wealth flavor believe regret funny network recall kiss grape useless pepper cram hint member few certain unveil rather brick bargain curious require crowd raise"
RelayerRepo = "ghcr.io/cosmos/relayer"
RelayerVersion = "main"
)
// Other Helpers
func ExecuteQuery(ctx context.Context, chain *cosmos.CosmosChain, cmd []string, i interface{}, extraFlags ...string) {
flags := []string{
"--node", chain.GetRPCAddress(),
"--output=json",
}
flags = append(flags, extraFlags...)
ExecuteExec(ctx, chain, cmd, i, flags...)
}
func ExecuteExec(ctx context.Context, chain *cosmos.CosmosChain, cmd []string, i interface{}, extraFlags ...string) {
command := []string{chain.Config().Bin}
command = append(command, cmd...)
command = append(command, extraFlags...)
fmt.Println(command)
stdout, _, err := chain.Exec(ctx, command, nil)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(stdout))
if err := json.Unmarshal(stdout, &i); err != nil {
fmt.Println(err)
}
}
// Executes a command from CommandBuilder
func ExecuteTransaction(ctx context.Context, chain *cosmos.CosmosChain, cmd []string) (sdk.TxResponse, error) {
var err error
var stdout []byte
stdout, _, err = chain.Exec(ctx, cmd, nil)
if err != nil {
return sdk.TxResponse{}, err
}
if err := testutil.WaitForBlocks(ctx, 2, chain); err != nil {
return sdk.TxResponse{}, err
}
var res sdk.TxResponse
if err := json.Unmarshal(stdout, &res); err != nil {
return res, err
}
return res, err
}
func TxCommandBuilder(ctx context.Context, chain *cosmos.CosmosChain, cmd []string, fromUser string, extraFlags ...string) []string {
return TxCommandBuilderNode(ctx, chain.GetNode(), cmd, fromUser, extraFlags...)
}
func TxCommandBuilderNode(ctx context.Context, node *cosmos.ChainNode, cmd []string, fromUser string, extraFlags ...string) []string {
command := []string{node.Chain.Config().Bin}
command = append(command, cmd...)
command = append(command, "--node", node.Chain.GetRPCAddress())
command = append(command, "--home", node.HomeDir())
command = append(command, "--chain-id", node.Chain.Config().ChainID)
command = append(command, "--from", fromUser)
command = append(command, "--keyring-backend", keyring.BackendTest)
command = append(command, "--output=json")
command = append(command, "--yes")
gasFlag := false
for _, flag := range extraFlags {
if flag == "--gas" {
gasFlag = true
}
}
if !gasFlag {
command = append(command, "--gas", "500000")
}
command = append(command, extraFlags...)
return command
}
+63
View File
@@ -0,0 +1,63 @@
package e2e
import (
"testing"
"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/stretchr/testify/require"
)
func TestTokenFactory(t *testing.T) {
if testing.Short() {
t.Skip("skipping in short mode")
}
// setup base chain
chains := interchaintest.CreateChainWithConfig(t, NumberVals, NumberFullNodes, Name, ChainImage.Version, DefaultChainConfig)
chain := chains[0].(*cosmos.CosmosChain)
ctx, ic, _, _ := interchaintest.BuildInitialChain(t, chains, false)
users := interchaintest.GetAndFundTestUsers(t, ctx, "default", GenesisFundsAmount, chain, chain)
user := users[0]
user2 := users[1]
uaddr := user.FormattedAddress()
uaddr2 := user2.FormattedAddress()
node := chain.GetNode()
tfDenom, _, err := node.TokenFactoryCreateDenom(ctx, user, "ictestdenom", 2_500_00)
t.Log("TF Denom: ", tfDenom)
require.NoError(t, err)
t.Log("Mint TF Denom to user")
node.TokenFactoryMintDenom(ctx, user.FormattedAddress(), tfDenom, 100)
if balance, err := chain.GetBalance(ctx, uaddr, tfDenom); err != nil {
t.Fatal(err)
} else if balance.Int64() != 100 {
t.Fatal("balance not 100")
}
t.Log("Mint TF Denom to another user")
node.TokenFactoryMintDenomTo(ctx, user.FormattedAddress(), tfDenom, 70, user2.FormattedAddress())
if balance, err := chain.GetBalance(ctx, uaddr2, tfDenom); err != nil {
t.Fatal(err)
} else if balance.Int64() != 70 {
t.Fatal("balance not 70")
}
t.Log("Change admin to uaddr2")
_, err = node.TokenFactoryChangeAdmin(ctx, user.KeyName(), tfDenom, uaddr2)
require.NoError(t, err)
// ensure the admin is the contract
res, err := chain.TokenFactoryQueryAdmin(ctx, tfDenom)
require.NoError(t, err)
require.EqualValues(t, res.AuthorityMetadata.Admin, uaddr2, "admin not uaddr2. Did not properly transfer.")
t.Cleanup(func() {
_ = ic.Close()
})
}