Skip to content

Commit

Permalink
feat(e2e): wired IBC Eureka (#13)
Browse files Browse the repository at this point in the history
Co-authored-by: Gjermund Garaba <[email protected]>
  • Loading branch information
srdtrk and gjermundgaraba authored Aug 3, 2024
1 parent 4d13a4a commit e85d570
Show file tree
Hide file tree
Showing 24 changed files with 681 additions and 73 deletions.
26 changes: 26 additions & 0 deletions abi/ICS02Client.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,32 @@
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "event",
"name": "ICS02ClientAdded",
"inputs": [
{
"name": "clientId",
"type": "string",
"indexed": false,
"internalType": "string"
},
{
"name": "counterpartyInfo",
"type": "tuple",
"indexed": false,
"internalType": "struct IICS02ClientMsgs.CounterpartyInfo",
"components": [
{
"name": "clientId",
"type": "string",
"internalType": "string"
}
]
}
],
"anonymous": false
},
{
"type": "event",
"name": "OwnershipTransferred",
Expand Down
16 changes: 16 additions & 0 deletions abi/ICS20Transfer.json
Original file line number Diff line number Diff line change
Expand Up @@ -786,5 +786,21 @@
"internalType": "address"
}
]
},
{
"type": "error",
"name": "StringsInsufficientHexLength",
"inputs": [
{
"name": "value",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "length",
"type": "uint256",
"internalType": "uint256"
}
]
}
]
19 changes: 19 additions & 0 deletions abi/ICS26Router.json
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,25 @@
],
"anonymous": false
},
{
"type": "event",
"name": "IBCAppAdded",
"inputs": [
{
"name": "portId",
"type": "string",
"indexed": false,
"internalType": "string"
},
{
"name": "app",
"type": "address",
"indexed": false,
"internalType": "address"
}
],
"anonymous": false
},
{
"type": "event",
"name": "OwnershipTransferred",
Expand Down
4 changes: 2 additions & 2 deletions e2e/artifacts/genesis.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"trustedClientState": "00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000012754500000000000000000000000000000000000000000000000000000000001baf800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000673696d642d310000000000000000000000000000000000000000000000000000",
"trustedConsensusState": "0000000000000000000000000000000000000000000000000000000066ab62a7782b36a3951ae33c2c2db63a19ae913fde60a610e8f57b374828b55096b06af1771618ec2069e0bbe62a3945f88c29684a10a89e9b212ba24a268a3ab18ed6c5",
"trustedClientState": "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000012754500000000000000000000000000000000000000000000000000000000001baf800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000673696d642d310000000000000000000000000000000000000000000000000000",
"trustedConsensusState": "0000000000000000000000000000000000000000000000000000000066acb767c22394cd988169e4cff51cf02eee69039b119d7b3959ce598de9adf8de4524014ae23e439252e05b6db14d268bff60e595ec7666772339b013b449e5e7f0e00e",
"updateClientVkey": "0x008d1636cb723e4319abda291c18f7dd68e37c2703f6da3733c3a998bfa039f3",
"membershipVkey": "0x0014aa880aba41e680e859af6ebdefef52df9902ab61975bd1bb340c9b820b2a",
"ucAndMembershipVkey": "0x001d0fed4a58085ccac826775bfe0553ae6e42e52521aa52c3601396854dc4e8"
Expand Down
2 changes: 1 addition & 1 deletion e2e/interchaintestv8/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ go test -v . -run=$TEST_SUITE_FN/$TEST_NAME
where `$TEST_NAME` is one of the test names of the `$TEST_SUITE_FN`. For example, to run the `TestDeploy` test, you would run:

```text
go test -v . -run=TestWithSP1ICS07TendermintTestSuite/TestDeploy
go test -v . -run=TestWithIbcEurekaTestSuite/TestDeploy
```
2 changes: 2 additions & 0 deletions e2e/interchaintestv8/chainconfig/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
mock "github.com/cosmos/ibc-go/v8/modules/light-clients/00-mock"
solomachine "github.com/cosmos/ibc-go/v8/modules/light-clients/06-solomachine"
ibctmtypes "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
localhost "github.com/cosmos/ibc-go/v8/modules/light-clients/09-localhost"
Expand Down Expand Up @@ -78,6 +79,7 @@ func encodingConfig(bech32Prefix string) *sdktestutil.TestEncodingConfig {
solomachine.RegisterInterfaces(interfaceRegistry)
ibctmtypes.RegisterInterfaces(interfaceRegistry)
localhost.RegisterInterfaces(interfaceRegistry)
mock.RegisterInterfaces(interfaceRegistry)

// sdk types
upgradetypes.RegisterInterfaces(interfaceRegistry)
Expand Down
90 changes: 88 additions & 2 deletions e2e/interchaintestv8/e2esuite/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,34 @@ package e2esuite

import (
"context"
"crypto/ecdsa"
"encoding/json"
"fmt"
"math/big"
"regexp"
"strconv"
"strings"
"time"
"unicode"

"cosmossdk.io/math"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
ethcommon "github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"

sdkmath "cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/chain/ethereum"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testutil"

"github.com/srdtrk/solidity-ibc-eureka/e2e/v8/testvalues"
)

type ForgeScriptReturnValues struct {
Expand Down Expand Up @@ -78,7 +93,7 @@ func (s *TestSuite) fundAddress(ctx context.Context, chain *cosmos.CosmosChain,
err := chain.SendFunds(ctx, keyName, ibc.WalletAmount{
Address: address,
Denom: chain.Config().Denom,
Amount: math.NewInt(1_000_000_000),
Amount: sdkmath.NewInt(1_000_000_000),
})
s.Require().NoError(err)

Expand Down Expand Up @@ -109,10 +124,81 @@ func (s *TestSuite) GetEthContractsFromDeployOutput(stdout string) DeployedContr
s.Require().NoError(err)

s.Require().NotEmpty(embeddedContracts.Erc20)
s.Require().True(IsLowercase(embeddedContracts.Erc20))
s.Require().NotEmpty(embeddedContracts.Ics02Client)
s.Require().True(IsLowercase(embeddedContracts.Ics02Client))
s.Require().NotEmpty(embeddedContracts.Ics07Tendermint)
s.Require().True(IsLowercase(embeddedContracts.Ics07Tendermint))
s.Require().NotEmpty(embeddedContracts.Ics20Transfer)
s.Require().True(IsLowercase(embeddedContracts.Ics20Transfer))
s.Require().NotEmpty(embeddedContracts.Ics26Router)
s.Require().True(IsLowercase(embeddedContracts.Ics26Router))

return embeddedContracts
}

// GetRelayerUsers returns two ibc.Wallet instances which can be used for the relayer users
// on the two chains.
func (s *TestSuite) GetRelayerUsers(ctx context.Context) (ibc.Wallet, ibc.Wallet) {
eth, simd := s.ChainA, s.ChainB

ethUsers := interchaintest.GetAndFundTestUsers(s.T(), ctx, s.T().Name(), testvalues.StartingEthBalance, eth)

cosmosUserFunds := sdkmath.NewInt(testvalues.StartingTokenAmount)
cosmosUsers := interchaintest.GetAndFundTestUsers(s.T(), ctx, s.T().Name(), cosmosUserFunds, simd)

return ethUsers[0], cosmosUsers[0]
}

// GetEvmEvent parses the logs in the given receipt and returns the first event that can be parsed
func GetEvmEvent[T any](receipt *ethtypes.Receipt, parseFn func(log ethtypes.Log) (*T, error)) (event *T, err error) {
for _, l := range receipt.Logs {
event, err = parseFn(*l)
if err == nil && event != nil {
break
}
}

if event == nil {
err = fmt.Errorf("event not found")
}

return
}

func (s *TestSuite) GetTxReciept(ctx context.Context, chain *ethereum.EthereumChain, hash ethcommon.Hash) *ethtypes.Receipt {
client, err := ethclient.Dial(chain.GetHostRPCAddress())
s.Require().NoError(err)

var receipt *ethtypes.Receipt
err = testutil.WaitForCondition(time.Second*10, time.Second, func() (bool, error) {
receipt, err = client.TransactionReceipt(ctx, hash)
if err != nil {
return false, nil
}

return receipt != nil, nil
})
s.Require().NoError(err)
return receipt
}

func (s *TestSuite) GetTransactOpts(key *ecdsa.PrivateKey) *bind.TransactOpts {
chainIDStr, err := strconv.ParseInt(s.ChainA.Config().ChainID, 10, 64)
s.Require().NoError(err)
chainID := big.NewInt(chainIDStr)

txOpts, err := bind.NewKeyedTransactorWithChainID(key, chainID)
s.Require().NoError(err)

return txOpts
}

func IsLowercase(s string) bool {
for _, r := range s {
if !unicode.IsLower(r) && unicode.IsLetter(r) {
return false
}
}
return true
}
3 changes: 3 additions & 0 deletions e2e/interchaintestv8/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ require (
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.38.0 // indirect
cosmossdk.io/client/v2 v2.0.0-beta.1 // indirect
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/core v0.11.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.1.0 // indirect
cosmossdk.io/x/circuit v0.1.1 // indirect
cosmossdk.io/x/evidence v0.1.1 // indirect
cosmossdk.io/x/feegrant v0.1.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
Expand Down
Loading

0 comments on commit e85d570

Please sign in to comment.