Skip to content

Commit

Permalink
latest setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Nov 29, 2024
1 parent 598acac commit 74fdc71
Show file tree
Hide file tree
Showing 17 changed files with 717 additions and 11 deletions.
12 changes: 4 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ endif
###############################################################################

ictest-basic:
@echo "Running basic e2e test"
@echo "Running Basic e2e test"
@cd interchaintest && go test -race -v -run TestBasicChain .

ictest-ibc:
Expand All @@ -260,20 +260,16 @@ ictest-ibc:

ictest-ics:
@echo "Running ICS e2e test"
@cd interchaintest && go test -race -v -run TestICSConnection .
@cd interchaintest && go test -race -v -run TestICSProviderSuite ./integration

ictest-wasm:
@echo "Running cosmwasm e2e test"
@echo "Running Cosmwasm e2e test"
@cd interchaintest && go test -race -v -run TestCosmWasmIntegration .

ictest-packetforward:
@echo "Running packet forward middleware e2e test"
@echo "Running PacketForward e2e test"
@cd interchaintest && go test -race -v -run TestPacketForwardMiddleware .

ictest-poa:
@echo "Running proof of authority e2e test"
@cd interchaintest && go test -race -v -run TestPOA .

ictest-tokenfactory:
@echo "Running token factory e2e test"
@cd interchaintest && go test -race -v -run TestTokenFactory .
Expand Down
58 changes: 58 additions & 0 deletions interchaintest/basic_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package e2e

import (
"context"
"testing"

"cosmossdk.io/math"

"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/testreporter"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
)

func TestBasicChain(t *testing.T) {
ctx := context.Background()
rep := testreporter.NewNopReporter()
eRep := rep.RelayerExecReporter(t)
client, network := interchaintest.DockerSetup(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)

// Setup Interchain
ic := interchaintest.NewInterchain().
AddChain(chain)

require.NoError(t, ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: false,
}))
t.Cleanup(func() {
_ = ic.Close()
})

amt := math.NewInt(10_000_000)
users := interchaintest.GetAndFundTestUsers(t, ctx, "default", amt,
chain,
)
user := users[0]

t.Run("validate funding", func(t *testing.T) {
bal, err := chain.BankQueryBalance(ctx, user.FormattedAddress(), chain.Config().Denom)
require.NoError(t, err)
require.EqualValues(t, amt, bal)

})

}
102 changes: 102 additions & 0 deletions interchaintest/cosmwasm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package e2e

import (
"context"
"encoding/json"
"testing"

"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/testreporter"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
)

type GetCountResponse struct {
// {"data":{"count":0}}
Data *GetCountObj `json:"data"`
}

type GetCountObj struct {
Count int64 `json:"count"`
}

func TestCosmWasmIntegration(t *testing.T) {
t.Parallel()
ctx := context.Background()
rep := testreporter.NewNopReporter()
eRep := rep.RelayerExecReporter(t)
client, network := interchaintest.DockerSetup(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)

// Setup Interchain
ic := interchaintest.NewInterchain().
AddChain(chain)

require.NoError(t, ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: false,
}))
t.Cleanup(func() {
_ = ic.Close()
})

users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), GenesisFundsAmount, chain)
user := users[0]

StdExecute(t, ctx, chain, user)
}

func StdExecute(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet) (contractAddr string) {
_, contractAddr = SetupContract(t, ctx, chain, user.KeyName(), "contracts/cw_template.wasm", `{"count":0}`)
chain.ExecuteContract(ctx, user.KeyName(), contractAddr, `{"increment":{}}`, "--fees", "10000"+chain.Config().Denom)

var res GetCountResponse
err := SmartQueryString(t, ctx, chain, contractAddr, `{"get_count":{}}`, &res)
require.NoError(t, err)

require.Equal(t, int64(1), res.Data.Count)

return contractAddr
}

func SmartQueryString(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, contractAddr, queryMsg string, res interface{}) error {
var jsonMap map[string]interface{}
if err := json.Unmarshal([]byte(queryMsg), &jsonMap); err != nil {
t.Fatal(err)
}
err := chain.QueryContract(ctx, contractAddr, jsonMap, &res)
return err
}

func SetupContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, keyname string, fileLoc string, message string, extraFlags ...string) (codeId, contract string) {
codeId, err := chain.StoreContract(ctx, keyname, fileLoc)
if err != nil {
t.Fatal(err)
}

needsNoAdminFlag := true
for _, flag := range extraFlags {
if flag == "--admin" {
needsNoAdminFlag = false
}
}

contractAddr, err := chain.InstantiateContract(ctx, keyname, codeId, message, needsNoAdminFlag, extraFlags...)
if err != nil {
t.Fatal(err)
}

return codeId, contractAddr
}
102 changes: 102 additions & 0 deletions interchaintest/ibc_rate_limit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package e2e

import (
"context"
"fmt"
"testing"

"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/stretchr/testify/require"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest"
)

func TestIBCRateLimit(t *testing.T) {
if testing.Short() {
t.Skip()
}

t.Parallel()
ctx := context.Background()
rep := testreporter.NewNopReporter()
eRep := rep.RelayerExecReporter(t)
client, network := interchaintest.DockerSetup(t)

cs := &DefaultChainSpec
cs.ModifyGenesis = cosmos.ModifyGenesis([]cosmos.GenesisKV{cosmos.NewGenesisKV("app_state.ratelimit.blacklisted_denoms", []string{cs.Denom})})

cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{
cs,
&SecondDefaultChainSpec,
})

chains, err := cf.Chains(t.Name())
require.NoError(t, err)

chain := chains[0].(*cosmos.CosmosChain)
secondary := chains[1].(*cosmos.CosmosChain)

// Relayer Factory
r := interchaintest.NewBuiltinRelayerFactory(
ibc.CosmosRly,
zaptest.NewLogger(t, zaptest.Level(zapcore.DebugLevel)),
interchaintestrelayer.CustomDockerImage(RelayerRepo, RelayerVersion, "100:1000"),
interchaintestrelayer.StartupFlags("--processor", "events", "--block-history", "200"),
).Build(t, client, network)

ic := interchaintest.NewInterchain().
AddChain(chain).
AddChain(secondary).
AddRelayer(r, "relayer")

ic = ic.AddLink(interchaintest.InterchainLink{
Chain1: chain,
Chain2: secondary,
Relayer: r,
Path: ibcPath,
})

// 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, chain, secondary)
userA, userB := users[0], users[1]

userAInitial, err := chain.GetBalance(ctx, userA.FormattedAddress(), chain.Config().Denom)
fmt.Println("userAInitial", userAInitial)
require.NoError(t, err)
require.True(t, userAInitial.Equal(fundAmount))

// Get Channel ID
aInfo, err := r.GetChannels(ctx, eRep, chain.Config().ChainID)
require.NoError(t, err)
aChannelID, err := getTransferChannel(aInfo)
require.NoError(t, err)
fmt.Println("aChannelID", aChannelID)

// Send Transaction
amountToSend := math.NewInt(1_000_000)
dstAddress := userB.FormattedAddress()
transfer := ibc.WalletAmount{
Address: dstAddress,
Denom: chain.Config().Denom,
Amount: amountToSend,
}

// Validate transfer error occurs
_, err = chain.SendIBCTransfer(ctx, aChannelID, userA.KeyName(), transfer, ibc.TransferOptions{})
require.Error(t, err)
require.Contains(t, err.Error(), "denom is blacklisted")
}
Loading

0 comments on commit 74fdc71

Please sign in to comment.