Skip to content

Commit

Permalink
Debug2: temporary commit
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-scherbina committed Oct 8, 2024
1 parent 641e4f5 commit eab18ae
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 59 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ build/linux
# Go workspace files
go.work
go.work.sum

debug.log
run-test.sh
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ replace (
github.com/cometbft/cometbft => github.com/kava-labs/cometbft v0.37.9-kava.1
github.com/cometbft/cometbft-db => github.com/kava-labs/cometbft-db v0.9.1-kava.2
// 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.47.10-iavl-v1-kava.1
github.com/cosmos/cosmos-sdk => /Users/yevheniishcherbina/go/src/github.com/Kava-Labs/cosmos-sdk
// See https://github.com/cosmos/cosmos-sdk/pull/13093
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2
// Tracking kava-labs/go-ethereum kava/release/v1.10 branch
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -892,8 +892,6 @@ github.com/kava-labs/cometbft v0.37.9-kava.1 h1:0mMsAhpV8p0peD9sabIZ//M4nP6LiiZ0
github.com/kava-labs/cometbft v0.37.9-kava.1/go.mod h1:j0Q3RqrCd+cztWCugs3obbzC4NyHGBPZZjtm/fWV00I=
github.com/kava-labs/cometbft-db v0.9.1-kava.2 h1:ZQaio886ifvml9XtJB4IYHhlArgA3+/a5Zwidg7H2J8=
github.com/kava-labs/cometbft-db v0.9.1-kava.2/go.mod h1:PvUZbx7zeR7I4CAvtKBoii/5ia5gXskKjDjIVpt7gDw=
github.com/kava-labs/cosmos-sdk v0.47.10-iavl-v1-kava.1 h1:vQwrm3sdAG1pkwrsi2mmCHSGDje5fzUR6vApEux/nVA=
github.com/kava-labs/cosmos-sdk v0.47.10-iavl-v1-kava.1/go.mod h1:OwLYEBcsnijCLE8gYkwQ7jycZZ/Acd+a83pJU+V+MKw=
github.com/kava-labs/ethermint v0.21.1-0.20240802224012-586960857184 h1:MWwCXFnkagXk93QiiD41I+S9wyrHZUQWLRFKo2tXL6A=
github.com/kava-labs/ethermint v0.21.1-0.20240802224012-586960857184/go.mod h1:kbyr3La2Co3Hy3U3N2EvVk7W1srQ2x88JUpgsu2KrXo=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
Expand Down
63 changes: 32 additions & 31 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
ibctypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ethtypes "github.com/ethereum/go-ethereum/core/types"
emtypes "github.com/evmos/ethermint/types"

"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/tests/e2e/testutil"
"github.com/kava-labs/kava/tests/util"
)
Expand Down Expand Up @@ -81,35 +79,38 @@ func (suite *IntegrationTestSuite) TestFundedAccount() {
func (suite *IntegrationTestSuite) TestTransferOverEVM() {
// fund an account that can perform the transfer
initialFunds := ukava(1e6) // 1 KAVA
acc := suite.Kava.NewFundedAccount("evm-test-transfer", sdk.NewCoins(initialFunds))

// get a rando account to send kava to
randomAddr := app.RandomAddress()
to := util.SdkToEvmAddress(randomAddr)

// example fetching of nonce (account sequence)
nonce, err := suite.Kava.EvmClient.PendingNonceAt(context.Background(), acc.EvmAddress)
suite.NoError(err)
suite.Equal(uint64(0), nonce) // sanity check. the account should have no prior txs

// transfer kava over EVM
kavaToTransfer := big.NewInt(1e17) // .1 KAVA; akava has 18 decimals.
req := util.EvmTxRequest{
Tx: ethtypes.NewTransaction(nonce, to, kavaToTransfer, 1e5, minEvmGasPrice, nil),
Data: "any ol' data to track this through the system",
}
res := acc.SignAndBroadcastEvmTx(req)
suite.Require().NoError(res.Err)
suite.Equal(ethtypes.ReceiptStatusSuccessful, res.Receipt.Status)

// evm txs refund unused gas. so to know the expected balance we need to know how much gas was used.
ukavaUsedForGas := sdkmath.NewIntFromBigInt(minEvmGasPrice).
Mul(sdkmath.NewIntFromUint64(res.Receipt.GasUsed)).
QuoRaw(1e12) // convert akava to ukava

// expect (9 - gas used) KAVA remaining in account.
balance := suite.Kava.QuerySdkForBalances(acc.SdkAddress)
suite.Equal(sdkmath.NewInt(9e5).Sub(ukavaUsedForGas), balance.AmountOf("ukava"))
acc := suite.Kava.NewFundedAccount("evm-test-transfer", sdk.NewCoins(initialFunds), 12)
_ = acc

return

//// get a rando account to send kava to
//randomAddr := app.RandomAddress()
//to := util.SdkToEvmAddress(randomAddr)
//
//// example fetching of nonce (account sequence)
//nonce, err := suite.Kava.EvmClient.PendingNonceAt(context.Background(), acc.EvmAddress)
//suite.NoError(err)
//suite.Equal(uint64(0), nonce) // sanity check. the account should have no prior txs
//
//// transfer kava over EVM
//kavaToTransfer := big.NewInt(1e17) // .1 KAVA; akava has 18 decimals.
//req := util.EvmTxRequest{
// Tx: ethtypes.NewTransaction(nonce, to, kavaToTransfer, 1e5, minEvmGasPrice, nil),
// Data: "any ol' data to track this through the system",
//}
//res := acc.SignAndBroadcastEvmTx(req)
//suite.Require().NoError(res.Err)
//suite.Equal(ethtypes.ReceiptStatusSuccessful, res.Receipt.Status)
//
//// evm txs refund unused gas. so to know the expected balance we need to know how much gas was used.
//ukavaUsedForGas := sdkmath.NewIntFromBigInt(minEvmGasPrice).
// Mul(sdkmath.NewIntFromUint64(res.Receipt.GasUsed)).
// QuoRaw(1e12) // convert akava to ukava
//
//// expect (9 - gas used) KAVA remaining in account.
//balance := suite.Kava.QuerySdkForBalances(acc.SdkAddress)
//suite.Equal(sdkmath.NewInt(9e5).Sub(ukavaUsedForGas), balance.AmountOf("ukava"))
}

// TestIbcTransfer transfers KAVA from the primary kava chain (suite.Kava) to the ibc chain (suite.Ibc).
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/kvtool
36 changes: 29 additions & 7 deletions tests/e2e/testutil/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package testutil
import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
"log"
"math/big"
Expand Down Expand Up @@ -212,7 +213,7 @@ func (a *SigningAccount) SignRawEvmData(msg []byte) ([]byte, cryptotypes.PubKey,
}

// NewFundedAccount creates a SigningAccount for a random account & funds the account from the whale.
func (chain *Chain) NewFundedAccount(name string, funds sdk.Coins) *SigningAccount {
func (chain *Chain) NewFundedAccount(name string, funds sdk.Coins, opts ...uint64) *SigningAccount {
mnemonic, err := util.RandomMnemonic()
require.NoError(chain.t, err)

Expand All @@ -236,9 +237,25 @@ func (chain *Chain) NewFundedAccount(name string, funds sdk.Coins) *SigningAccou
bal.IsAllGT(funds),
"funded account lacks funds for account %s\nneeds: %s\nhas: %s", name, funds, bal,
)
balBefore := bal.AmountOf("ukava")
fmt.Printf("Balance before tx: %v\n", balBefore)

whale.l.Printf("attempting to fund created account (%s=%s)\n", name, acc.SdkAddress.String())
res := whale.BankSend(acc.SdkAddress, funds)
res := whale.BankSend(acc.SdkAddress, funds, opts...)

resInJSON, err := json.Marshal(res)
require.NoError(chain.t, err)
fmt.Printf("resInJSON: %s\n", resInJSON)
var timeoutHeight uint64
if len(opts) == 1 {
timeoutHeight = opts[0]
}
fmt.Printf("timeoutHeight: %v\n", timeoutHeight)

bal = chain.QuerySdkForBalances(whale.SdkAddress)
balAfter := bal.AmountOf("ukava")
fmt.Printf("Balance after tx: %v\n", balAfter)
fmt.Printf("Balance DIFF: %v\n", balBefore.Sub(balBefore))

require.NoErrorf(chain.t, res.Err, "failed to fund new account %s: %s", name, res.Err)

Expand All @@ -253,13 +270,18 @@ func (a *SigningAccount) NextNonce() (uint64, error) {
}

// BankSend is a helper method for sending funds via x/bank's MsgSend
func (a *SigningAccount) BankSend(to sdk.AccAddress, amount sdk.Coins) util.KavaMsgResponse {
func (a *SigningAccount) BankSend(to sdk.AccAddress, amount sdk.Coins, opts ...uint64) util.KavaMsgResponse {
var timeoutHeight uint64
if len(opts) == 1 {
timeoutHeight = opts[0]
}
return a.SignAndBroadcastKavaTx(
util.KavaMsgRequest{
Msgs: []sdk.Msg{banktypes.NewMsgSend(a.SdkAddress, to, amount)},
GasLimit: 2e5, // 200,000 gas
FeeAmount: sdk.NewCoins(sdk.NewCoin(a.gasDenom, sdkmath.NewInt(200))), // assume min gas price of .001ukava
Data: fmt.Sprintf("sending %s to %s", amount, to),
Msgs: []sdk.Msg{banktypes.NewMsgSend(a.SdkAddress, to, amount)},
GasLimit: 2e5, // 200,000 gas
FeeAmount: sdk.NewCoins(sdk.NewCoin(a.gasDenom, sdkmath.NewInt(200))), // assume min gas price of .001ukava
Data: fmt.Sprintf("sending %s to %s", amount, to),
TimeoutHeight: timeoutHeight,
},
)
}
Expand Down
32 changes: 16 additions & 16 deletions tests/e2e/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,24 +136,24 @@ func (suite *E2eTestSuite) SetupSuite() {
func (suite *E2eTestSuite) TearDownSuite() {
fmt.Println("tearing down test suite.")

whale := suite.Kava.GetAccount(FundedAccountName)

if suite.enableRefunds {
suite.cost.sdkBalanceAfter = suite.Kava.QuerySdkForBalances(whale.SdkAddress)
suite.cost.erc20BalanceAfter = suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
fmt.Println("==BEFORE REFUNDS==")
fmt.Println(suite.cost)

fmt.Println("attempting to return all unused funds")
suite.Kava.ReturnAllFunds()

fmt.Println("==AFTER REFUNDS==")
}
//whale := suite.Kava.GetAccount(FundedAccountName)

//if suite.enableRefunds {
// suite.cost.sdkBalanceAfter = suite.Kava.QuerySdkForBalances(whale.SdkAddress)
// suite.cost.erc20BalanceAfter = suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
// fmt.Println("==BEFORE REFUNDS==")
// fmt.Println(suite.cost)
//
// fmt.Println("attempting to return all unused funds")
// suite.Kava.ReturnAllFunds()
//
// fmt.Println("==AFTER REFUNDS==")
//}

// calculate & output cost summary for funded account
suite.cost.sdkBalanceAfter = suite.Kava.QuerySdkForBalances(whale.SdkAddress)
suite.cost.erc20BalanceAfter = suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
fmt.Println(suite.cost)
//suite.cost.sdkBalanceAfter = suite.Kava.QuerySdkForBalances(whale.SdkAddress)
//suite.cost.erc20BalanceAfter = suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
//fmt.Println(suite.cost)

// close all account request channels
suite.Kava.Shutdown()
Expand Down
4 changes: 3 additions & 1 deletion tests/util/sdksigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ type KavaMsgRequest struct {
Memo string
// Arbitrary data to be referenced in the corresponding KavaMsgResponse, unused
// in signing. This is mostly useful to match KavaMsgResponses with KavaMsgRequests.
Data interface{}
Data interface{}
TimeoutHeight uint64
}

type KavaMsgResponse struct {
Expand Down Expand Up @@ -243,6 +244,7 @@ func (s *KavaSigner) Run(requests <-chan KavaMsgRequest) (<-chan KavaMsgResponse
txBuilder.SetMsgs(currentRequest.Msgs...)
txBuilder.SetGasLimit(currentRequest.GasLimit)
txBuilder.SetFeeAmount(currentRequest.FeeAmount)
txBuilder.SetTimeoutHeight(currentRequest.TimeoutHeight)

signerData := authsigning.SignerData{
ChainID: s.chainID,
Expand Down

0 comments on commit eab18ae

Please sign in to comment.