From eab18aec16e8e69a85d060f3a6b4b8134edf50cf Mon Sep 17 00:00:00 2001 From: evgeniy-scherbina Date: Tue, 8 Oct 2024 14:12:17 -0400 Subject: [PATCH] Debug2: temporary commit --- .gitignore | 3 ++ go.mod | 3 +- go.sum | 2 -- tests/e2e/e2e_test.go | 63 ++++++++++++++++++----------------- tests/e2e/kvtool | 2 +- tests/e2e/testutil/account.go | 36 ++++++++++++++++---- tests/e2e/testutil/suite.go | 32 +++++++++--------- tests/util/sdksigner.go | 4 ++- 8 files changed, 86 insertions(+), 59 deletions(-) diff --git a/.gitignore b/.gitignore index e647197ef8..9be50c9747 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,6 @@ build/linux # Go workspace files go.work go.work.sum + +debug.log +run-test.sh diff --git a/go.mod b/go.mod index ab1fdb0acd..10f0f876d0 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 7934ead58c..87357fc0c5 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 63e63c467b..f33fa2d6e7 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -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" ) @@ -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). diff --git a/tests/e2e/kvtool b/tests/e2e/kvtool index 20d8e0dcff..7a258021c1 160000 --- a/tests/e2e/kvtool +++ b/tests/e2e/kvtool @@ -1 +1 @@ -Subproject commit 20d8e0dcff557a456041e7bfea48bf3c6207ef8a +Subproject commit 7a258021c15c671f5146626738c4bbf607b66731 diff --git a/tests/e2e/testutil/account.go b/tests/e2e/testutil/account.go index eebca6300a..09604b2440 100644 --- a/tests/e2e/testutil/account.go +++ b/tests/e2e/testutil/account.go @@ -3,6 +3,7 @@ package testutil import ( "context" "encoding/hex" + "encoding/json" "fmt" "log" "math/big" @@ -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) @@ -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) @@ -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, }, ) } diff --git a/tests/e2e/testutil/suite.go b/tests/e2e/testutil/suite.go index 1316f34543..8963f7a717 100644 --- a/tests/e2e/testutil/suite.go +++ b/tests/e2e/testutil/suite.go @@ -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() diff --git a/tests/util/sdksigner.go b/tests/util/sdksigner.go index 9fdc59efe2..2e34d5ac87 100644 --- a/tests/util/sdksigner.go +++ b/tests/util/sdksigner.go @@ -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 { @@ -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,