-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
598acac
commit 74fdc71
Showing
17 changed files
with
717 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
Oops, something went wrong.