Skip to content

Commit

Permalink
wip: update e2e test for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
boodyvo committed Nov 4, 2024
1 parent 26017d4 commit f3401b1
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 16 deletions.
10 changes: 5 additions & 5 deletions client/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ func NewClientWithConfig(grpcUrl string, config KavaGrpcClientConfig) (*KavaGrpc
if grpcUrl == "" {
return nil, errors.New("grpc url cannot be empty")
}
query, error := query.NewQueryClient(grpcUrl)
if error != nil {
return nil, error
queryClient, err := query.NewQueryClient(grpcUrl)
if err != nil {
return nil, err
}
client := &KavaGrpcClient{
Query: query,
Util: util.NewUtil(query),
Query: queryClient,
Util: util.NewUtil(queryClient),
config: config,
}
return client, nil
Expand Down
10 changes: 8 additions & 2 deletions client/grpc/util/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@ package util
import (
"context"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)

// Account fetches an account via an address and returns the unpacked account
func (u *Util) Account(addr string) (authtypes.AccountI, error) {
func (u *Util) Account(addr string) (sdk.AccountI, error) {
fmt.Println("Util fetching account for address:", addr)
res, err := u.query.Auth.Account(context.Background(), &authtypes.QueryAccountRequest{
Address: addr,
})
if err != nil {
return nil, fmt.Errorf("failed to fetch account: %w", err)
}

var acc authtypes.AccountI
var acc sdk.AccountI

fmt.Println("trying to unpack any", res.Account)

err = u.encodingConfig.Marshaler.UnpackAny(res.Account, &acc)
if err != nil {
return nil, fmt.Errorf("failed to unpack account: %w", err)
Expand All @@ -27,6 +32,7 @@ func (u *Util) Account(addr string) (authtypes.AccountI, error) {
// BaseAccount fetches a base account via an address or returns an error if
// the account is not a base account
func (u *Util) BaseAccount(addr string) (authtypes.BaseAccount, error) {
fmt.Println("Util fetching base account for address:", addr)
acc, err := u.Account(addr)
if err != nil {
return authtypes.BaseAccount{}, err
Expand Down
14 changes: 13 additions & 1 deletion client/grpc/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package util

import (
"context"
"cosmossdk.io/log"
dbm "github.com/cosmos/cosmos-db"
"strconv"

grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
Expand All @@ -20,9 +22,19 @@ type Util struct {

// NewUtil creates a new Util instance
func NewUtil(query *query.QueryClient) *Util {
encodingConfig := app.MakeEncodingConfig()
_ = app.NewApp(
log.NewNopLogger(),
dbm.NewMemDB(),
app.DefaultNodeHome,
nil,
encodingConfig,
app.DefaultOptions,
)

return &Util{
query: query,
encodingConfig: app.MakeEncodingConfig(),
encodingConfig: encodingConfig,
}
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ replace (
// Use cosmos-sdk fork with backported fix for unsafe-reset-all, staking transfer events, and custom tally handler support
//github.com/cosmos/cosmos-sdk => github.com/kava-labs/cosmos-sdk v0.47.10-iavl-v1-kava.1
//github.com/cosmos/cosmos-sdk => github.com/kava-labs/cosmos-sdk v0.50.10-test-patch 5f9239e3147358ef034bfc4d19aacb34e5ea2064
github.com/cosmos/cosmos-sdk => github.com/kava-labs/cosmos-sdk v0.0.0-20241029222539-f192238e804f
github.com/cosmos/cosmos-sdk => github.com/kava-labs/cosmos-sdk v0.0.0-20241104154228-9f413992bbe2
//github.com/cosmos/cosmos-sdk => ../cosmos-sdk

//github.com/cosmos/cosmos-sdk/store => cosmossdk.io/store v1.1.1
Expand All @@ -280,7 +280,7 @@ replace (
// Tracking kava-labs/etheremint master branch
// TODO: Tag before release
//github.com/evmos/ethermint => github.com/kava-labs/ethermint v0.21.1-0.20240802224012-586960857184
github.com/evmos/ethermint => github.com/kava-labs/ethermint v0.0.0-20241101205132-84fa56360f15
github.com/evmos/ethermint => github.com/kava-labs/ethermint v0.0.0-20241104150149-8a2ef3e12c4e
//github.com/evmos/ethermint => ../ethermint
// See https://github.com/cosmos/cosmos-sdk/pull/10401, https://github.com/cosmos/cosmos-sdk/commit/0592ba6158cd0bf49d894be1cef4faeec59e8320
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -832,10 +832,10 @@ github.com/kava-labs/cometbft v0.0.0-20241024200036-527d8df9ff12 h1:RqnpnEGEuykj
github.com/kava-labs/cometbft v0.0.0-20241024200036-527d8df9ff12/go.mod h1:5awmm7t/X8LJ+Wd7/TXHcv4hLfFLcexy6fdS9WvOepA=
github.com/kava-labs/cometbft-db v0.0.0-20241007145430-b2740b2e4bed h1:3FNJ3fcD9aA9oOwDphrSEJ8u2kBNj9YoYAwl16UKyv4=
github.com/kava-labs/cometbft-db v0.0.0-20241007145430-b2740b2e4bed/go.mod h1:buPRZKyVp+u5fmwN7tDtOk1zc5xA2z9BJJTy61tNnws=
github.com/kava-labs/cosmos-sdk v0.0.0-20241029222539-f192238e804f h1:hMd+iqnvR1XL5UEsLauUiXAqDDnTixt/X//T3lykV90=
github.com/kava-labs/cosmos-sdk v0.0.0-20241029222539-f192238e804f/go.mod h1:6Eesrx3ZE7vxBZWpK++30H+Uc7Q4ahQWCL7JKU/LEdU=
github.com/kava-labs/ethermint v0.0.0-20241101205132-84fa56360f15 h1:0lNXZVsbJ/3sxn2O1GT83Sg6JAunpvPQ/u0siXVCGic=
github.com/kava-labs/ethermint v0.0.0-20241101205132-84fa56360f15/go.mod h1:dFh15Ndobz1zWqWcJm9ML+0BnMt5m8gS+MhVUcAGLpg=
github.com/kava-labs/cosmos-sdk v0.0.0-20241104154228-9f413992bbe2 h1:rZ3KCm7PZG/IsX2r1L8ZyMhxRL/8FCZ4pGGjPd7obZ0=
github.com/kava-labs/cosmos-sdk v0.0.0-20241104154228-9f413992bbe2/go.mod h1:6Eesrx3ZE7vxBZWpK++30H+Uc7Q4ahQWCL7JKU/LEdU=
github.com/kava-labs/ethermint v0.0.0-20241104150149-8a2ef3e12c4e h1:184b0xnTXkULy16FCgFuUxPIdbISnEpiEIEFY5TuLt0=
github.com/kava-labs/ethermint v0.0.0-20241104150149-8a2ef3e12c4e/go.mod h1:dFh15Ndobz1zWqWcJm9ML+0BnMt5m8gS+MhVUcAGLpg=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
Expand Down
11 changes: 11 additions & 0 deletions tests/e2e/testutil/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package testutil

import (
"context"
"cosmossdk.io/log"
"fmt"
dbm "github.com/cosmos/cosmos-db"
"math/big"
"testing"

Expand Down Expand Up @@ -60,6 +62,15 @@ func NewChain(t *testing.T, details *runner.ChainDetails, fundedAccountMnemonic
erc20s: make(map[common.Address]struct{}),
}
chain.EncodingConfig = app.MakeEncodingConfig()
// we need to register necessary codec for encoding config
_ = app.NewApp(
log.NewNopLogger(),
dbm.NewMemDB(),
app.DefaultNodeHome,
nil,
chain.EncodingConfig,
app.DefaultOptions,
)

// setup keyring
kr, err := keyring.New(
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/testutil/eip712.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package testutil

import (
"context"
"fmt"

"github.com/cosmos/cosmos-sdk/client"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand All @@ -23,10 +24,12 @@ func (suite *E2eTestSuite) NewEip712TxBuilder(
) client.TxBuilder {
// get account details
var accDetails sdk.AccountI
fmt.Println("going to fetch", acc.SdkAddress.String())
a, err := chain.Grpc.Query.Auth.Account(context.Background(), &authtypes.QueryAccountRequest{
Address: acc.SdkAddress.String(),
})
suite.NoError(err)
fmt.Println("a.Account after check: ", a)
err = chain.EncodingConfig.InterfaceRegistry.UnpackAny(a.Account, &accDetails)
suite.NoError(err)

Expand Down
7 changes: 5 additions & 2 deletions tests/util/sdksigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,23 @@ func NewKavaSigner(
}
}

func (s *KavaSigner) pollAccountState() <-chan authtypes.AccountI {
accountState := make(chan authtypes.AccountI)
func (s *KavaSigner) pollAccountState() <-chan sdk.AccountI {
accountState := make(chan sdk.AccountI)

go func() {
for {
request := authtypes.QueryAccountRequest{
Address: GetAccAddress(s.privKey).String(),
}
fmt.Println("pollAccountState: fetching account for address:", request.Address)
response, err := s.authClient.Account(context.Background(), &request)

if err == nil {
var account sdk.AccountI

err = s.encodingConfig.InterfaceRegistry.UnpackAny(response.Account, &account)
fmt.Println("pollAccountState: unpacked account", account)
fmt.Println("pollAccountState: error", err)
if err == nil {
accountState <- account
}
Expand Down

0 comments on commit f3401b1

Please sign in to comment.