Skip to content

Commit b78f793

Browse files
committed
add: added framework for remote chan tests and TC for token transfer to-and-from ibc-centauri
1 parent f824e6b commit b78f793

20 files changed

+2159
-46
lines changed

scripts/execute-test.sh

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ e2e_test() {
3939
go test -v ./test/e2e -timeout 0 -count=1
4040
}
4141

42+
e2e_hopchain() {
43+
echo "Running e2e hopchain test..."
44+
go test -v ./test/e2e-hopchain -timeout 0 -count=1
45+
}
46+
4247
e2e_demo() {
4348
echo "Configuring e2e demo..."
4449
export PRESERVE_DOCKER=true && go test -v ./test/e2e-demo -testify.m TestSetup
@@ -117,6 +122,9 @@ case "$test" in
117122
"e2e")
118123
e2e_test
119124
;;
125+
"e2e-hopchain")
126+
e2e_hopchain
127+
;;
120128
"e2e-demo")
121129
e2e_demo
122130
;;

test/chains/chain.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import (
55
"context"
66
"encoding/hex"
77
"fmt"
8-
"github.com/strangelove-ventures/interchaintest/v7/ibc"
8+
"math/big"
99
"os"
1010
"strings"
1111

12+
"github.com/strangelove-ventures/interchaintest/v7/ibc"
13+
1214
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
1315
"github.com/cosmos/gogoproto/proto"
1416
conntypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
@@ -63,6 +65,9 @@ type Chain interface {
6365
RestoreConfig([]byte) error
6466
//integration test specific
6567
SendPacketMockDApp(ctx context.Context, targetChain Chain, keyName string, params map[string]interface{}) (PacketTransferResponse, error)
68+
SetupIBCICS20(ctx context.Context, keyName string) (context.Context, error)
69+
SendIBCTokenTransfer(ctx context.Context, sourceChannel, destinationChannel, port, receiver, chainID string, amount uint64) (string, error)
70+
GetWalletBalance(ctx context.Context, address string, denom string) (*big.Int, error)
6671
}
6772

6873
func GetEnvOrDefault(key, defaultValue string) string {
+258
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
package cosmos
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"math/big"
8+
"strings"
9+
10+
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
11+
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
12+
"github.com/docker/docker/client"
13+
"github.com/icon-project/ibc-integration/test/internal/dockerutil"
14+
"github.com/icon-project/ibc-integration/test/testsuite/testconfig"
15+
"github.com/strangelove-ventures/interchaintest/v7/ibc"
16+
"go.uber.org/zap"
17+
)
18+
19+
// CosmosRemoteChain is a local docker testnet for a Cosmos SDK chain.
20+
// Implements the ibc.Chain interface.
21+
type CosmosRemoteChain struct {
22+
testName string
23+
cfg ibc.ChainConfig
24+
log *zap.Logger
25+
Client *client.Client
26+
Network string
27+
testConfig *testconfig.Chain
28+
}
29+
30+
func NewCosmosHeighlinerChainConfig(name string,
31+
binary string,
32+
bech32Prefix string,
33+
denom string,
34+
gasPrices string,
35+
gasAdjustment float64,
36+
trustingPeriod string,
37+
noHostMount bool) ibc.ChainConfig {
38+
return ibc.ChainConfig{
39+
Type: "cosmos",
40+
Name: name,
41+
Bech32Prefix: bech32Prefix,
42+
Denom: denom,
43+
GasPrices: gasPrices,
44+
GasAdjustment: gasAdjustment,
45+
TrustingPeriod: trustingPeriod,
46+
NoHostMount: noHostMount,
47+
Images: []ibc.DockerImage{
48+
{
49+
Repository: fmt.Sprintf("ghcr.io/strangelove-ventures/heighliner/%s", name),
50+
UidGid: dockerutil.GetHeighlinerUserString(),
51+
},
52+
},
53+
Bin: binary,
54+
}
55+
}
56+
57+
func NewCosmosRemoteChain(testName string, chainConfig ibc.ChainConfig, client *client.Client, network string, log *zap.Logger, testConfig *testconfig.Chain) *CosmosRemoteChain {
58+
if chainConfig.EncodingConfig == nil {
59+
cfg := DefaultEncoding()
60+
chainConfig.EncodingConfig = &cfg
61+
}
62+
63+
registry := codectypes.NewInterfaceRegistry()
64+
cryptocodec.RegisterInterfaces(registry)
65+
return &CosmosRemoteChain{
66+
testName: testName,
67+
cfg: chainConfig,
68+
log: log,
69+
Client: client,
70+
Network: network,
71+
testConfig: testConfig,
72+
}
73+
}
74+
75+
// // Implements Chain interface
76+
func (c *CosmosRemoteChain) Config() ibc.ChainConfig {
77+
return c.cfg
78+
}
79+
80+
// // Implements Chain interface
81+
func (c *CosmosRemoteChain) Initialize(ctx context.Context, testName string, cli *client.Client, networkID string) error {
82+
return nil
83+
}
84+
85+
// // Implements Chain interface
86+
func (c *CosmosRemoteChain) GetRPCAddress() string {
87+
return c.testConfig.RPCUri
88+
}
89+
90+
// // Implements Chain interface
91+
func (c *CosmosRemoteChain) GetGRPCAddress() string {
92+
return c.testConfig.RPCUri
93+
}
94+
95+
// // GetHostRPCAddress returns the address of the RPC server accessible by the host.
96+
// // This will not return a valid address until the chain has been started.
97+
func (c *CosmosRemoteChain) GetHostRPCAddress() string {
98+
return c.testConfig.RPCUri
99+
}
100+
101+
// // GetHostGRPCAddress returns the address of the gRPC server accessible by the host.
102+
// // This will not return a valid address until the chain has been started.
103+
func (c *CosmosRemoteChain) GetHostGRPCAddress() string {
104+
return c.testConfig.RPCUri
105+
}
106+
107+
// // HomeDir implements ibc.Chain.
108+
func (c *CosmosRemoteChain) HomeDir() string {
109+
panic("not implemented")
110+
}
111+
112+
// // Implements Chain interface
113+
func (c *CosmosRemoteChain) CreateKey(ctx context.Context, keyName string) error {
114+
panic("not implemented")
115+
}
116+
117+
// Implements Chain interface
118+
func (c *CosmosRemoteChain) RecoverKey(ctx context.Context, keyName, mnemonic string) error {
119+
panic("not implemented")
120+
}
121+
122+
// // Implements Chain interface
123+
func (c *CosmosRemoteChain) GetAddress(ctx context.Context, keyName string) ([]byte, error) {
124+
panic("not implemented")
125+
}
126+
127+
// // BuildWallet will return a Cosmos wallet
128+
// // If mnemonic != "", it will restore using that mnemonic
129+
// // If mnemonic == "", it will create a new key
130+
func (c *CosmosRemoteChain) BuildWallet(ctx context.Context, keyName string, mnemonic string) (ibc.Wallet, error) {
131+
panic("not implemented")
132+
}
133+
134+
// // BuildRelayerWallet will return a Cosmos wallet populated with the mnemonic so that the wallet can
135+
// // be restored in the relayer node using the mnemonic. After it is built, that address is included in
136+
// // genesis with some funds.
137+
func (c *CosmosRemoteChain) BuildRelayerWallet(ctx context.Context, keyName string) (ibc.Wallet, error) {
138+
panic("not implemented")
139+
}
140+
141+
// // Implements Chain interface
142+
func (c *CosmosRemoteChain) SendFunds(ctx context.Context, keyName string, amount ibc.WalletAmount) error {
143+
panic("not implemented")
144+
}
145+
146+
// // Implements Chain interface
147+
func (c *CosmosRemoteChain) SendIBCTransfer(
148+
ctx context.Context,
149+
channelID string,
150+
keyName string,
151+
amount ibc.WalletAmount,
152+
options ibc.TransferOptions,
153+
) (tx ibc.Tx, _ error) {
154+
panic("not implemented")
155+
}
156+
157+
// // StoreContract takes a file path to smart contract and stores it on-chain. Returns the contracts code id.
158+
func (c *CosmosRemoteChain) StoreContract(ctx context.Context, keyName string, fileName string) (string, error) {
159+
panic("not implemented")
160+
}
161+
162+
// // InstantiateContract takes a code id for a smart contract and initialization message and returns the instantiated contract address.
163+
func (c *CosmosRemoteChain) InstantiateContract(ctx context.Context, keyName string, codeID string, initMessage string, needsNoAdminFlag bool, extraExecTxArgs ...string) (string, error) {
164+
panic("not implemented")
165+
}
166+
167+
// // QueryContract performs a smart query, taking in a query struct and returning a error with the response struct populated.
168+
func (c *CosmosRemoteChain) QueryContract(ctx context.Context, contractAddress string, query any, response any) error {
169+
panic("not implemented")
170+
}
171+
172+
// // ExportState exports the chain state at specific height.
173+
// // Implements Chain interface
174+
func (c *CosmosRemoteChain) ExportState(ctx context.Context, height int64) (string, error) {
175+
panic("not implemented")
176+
}
177+
178+
func (c *CosmosRemoteChain) GetGasFeesInNativeDenom(gasPaid int64) int64 {
179+
panic("not implemented")
180+
}
181+
182+
func (c *CosmosRemoteChain) UpgradeVersion(ctx context.Context, cli *client.Client, containerRepo, version string) {
183+
panic("not implemented")
184+
}
185+
186+
// // Bootstraps the chain and starts it from genesis
187+
func (c *CosmosRemoteChain) Start(testName string, ctx context.Context, additionalGenesisWallets ...ibc.WalletAmount) error {
188+
panic("not implemented")
189+
}
190+
191+
// Height implements ibc.Chain
192+
func (c *CosmosRemoteChain) Height(ctx context.Context) (uint64, error) {
193+
panic("not implemented")
194+
}
195+
196+
// // Acknowledgements implements ibc.Chain, returning all acknowledgments in block at height
197+
func (c *CosmosRemoteChain) Acknowledgements(ctx context.Context, height uint64) ([]ibc.PacketAcknowledgement, error) {
198+
panic("not implemented")
199+
}
200+
201+
// // Timeouts implements ibc.Chain, returning all timeouts in block at height
202+
func (c *CosmosRemoteChain) Timeouts(ctx context.Context, height uint64) ([]ibc.PacketTimeout, error) {
203+
panic("not implemented")
204+
}
205+
206+
// // Exec implements ibc.Chain.
207+
func (c *CosmosRemoteChain) Exec(ctx context.Context, cmd []string, env []string) (stdout, stderr []byte, err error) {
208+
cmd = append([]string{"centaurid"}, cmd...)
209+
job := dockerutil.NewImage(c.log, c.Client, c.Network, c.testName, c.cfg.Images[0].Repository, c.cfg.Images[0].Version)
210+
opts := dockerutil.ContainerOptions{
211+
Binds: []string{
212+
c.testConfig.ContractsPath + ":/contracts",
213+
c.testConfig.ConfigPath + ":/centauri/.banksy",
214+
},
215+
Env: env,
216+
}
217+
218+
res := job.Run(ctx, cmd, opts)
219+
return res.Stdout, res.Stderr, res.Err
220+
}
221+
222+
func (c *CosmosRemoteChain) extractAmount(text string) (*big.Int, error) {
223+
entries := strings.Split(text, "\n")
224+
for _, entry := range entries {
225+
values := strings.Split(entry, ":")
226+
key := values[0]
227+
value := values[1]
228+
if key == "amount" {
229+
var balance string
230+
json.Unmarshal([]byte(value), &balance)
231+
n := new(big.Int)
232+
n, ok := n.SetString(balance, 10)
233+
if !ok {
234+
return nil, fmt.Errorf("error converting")
235+
236+
}
237+
return n, nil
238+
239+
}
240+
}
241+
return nil, fmt.Errorf("balance not found")
242+
}
243+
244+
// // GetBalance fetches the current balance for a specific account address and denom.
245+
// // Implements Chain interface
246+
func (c *CosmosRemoteChain) GetWalletBalance(ctx context.Context, address string, denom string) (*big.Int, error) {
247+
commands := []string{"query", "bank", "balances", address}
248+
commands = append(commands,
249+
"--node", c.GetHostRPCAddress(),
250+
"--denom", denom,
251+
)
252+
stdout, _, err := c.Exec(ctx, commands, nil)
253+
if err != nil {
254+
return nil, err
255+
}
256+
amount, err := c.extractAmount(string(stdout[:]))
257+
return amount, err
258+
}

test/chains/cosmos/localnet.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import (
66
"encoding/hex"
77
"encoding/json"
88
"fmt"
9-
interchaintest "github.com/icon-project/ibc-integration/test"
9+
"math/big"
1010
"strconv"
1111
"strings"
1212
"time"
1313

14+
interchaintest "github.com/icon-project/ibc-integration/test"
15+
1416
"github.com/avast/retry-go/v4"
1517
"github.com/cosmos/gogoproto/proto"
1618
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
@@ -776,3 +778,15 @@ func (c *CosmosLocalnet) RestoreConfig(backup []byte) error {
776778
c.Wallets = wallets
777779
return nil
778780
}
781+
782+
func (c *CosmosLocalnet) SetupIBCICS20(ctx context.Context, keyName string) (context.Context, error) {
783+
panic("not implemented")
784+
}
785+
786+
func (c *CosmosLocalnet) SendIBCTokenTransfer(ctx context.Context, sourceChannel, destinationChannel, port, receiver, chainID string, amount uint64) (string, error) {
787+
panic("not implemented")
788+
}
789+
790+
func (c *CosmosLocalnet) GetWalletBalance(ctx context.Context, address string, denom string) (*big.Int, error) {
791+
panic("not implemented")
792+
}

0 commit comments

Comments
 (0)