From b7e6daa0541db84bff4a7d9630b1ae9c35a5ea56 Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Tue, 19 Sep 2023 08:54:30 +0200 Subject: [PATCH 01/11] add bank multi-send api test --- tests/e2e/e2e_bank_test.go | 70 +++++++++++++++++++++++++++-------- tests/e2e/e2e_exec_test.go | 43 +++++++++++++++++++++ tests/e2e/e2e_setup_test.go | 74 +++++++++++++++++++------------------ tests/e2e/e2e_test.go | 22 +++++------ tests/e2e/query.go | 6 +++ 5 files changed, 152 insertions(+), 63 deletions(-) diff --git a/tests/e2e/e2e_bank_test.go b/tests/e2e/e2e_bank_test.go index bb9e7ffbc2f..d49c5d6236a 100644 --- a/tests/e2e/e2e_bank_test.go +++ b/tests/e2e/e2e_bank_test.go @@ -9,46 +9,84 @@ import ( func (s *IntegrationTestSuite) testBankTokenTransfer() { s.Run("send_photon_between_accounts", func() { - var err error - senderAddress, _ := s.chainA.validators[0].keyInfo.GetAddress() - sender := senderAddress.String() - recipientAddress, _ := s.chainA.validators[1].keyInfo.GetAddress() - recipient := recipientAddress.String() + var ( + err error + valIdx = 0 + c = s.chainA + api = fmt.Sprintf("http://%s", s.valResources[c.id][valIdx].GetHostPort("1317/tcp")) + ) - chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chainA.id][0].GetHostPort("1317/tcp")) + alice, _ := c.genesisAccounts[1].keyInfo.GetAddress() + bob, _ := c.genesisAccounts[2].keyInfo.GetAddress() + charlie, _ := c.genesisAccounts[3].keyInfo.GetAddress() var ( - beforeSenderUAtomBalance sdk.Coin - beforeRecipientUAtomBalance sdk.Coin + beforeAliceUAtomBalance, + beforeBobUAtomBalance, + beforeCharlieUAtomBalance, + afterAliceUAtomBalance, + afterBobUAtomBalance, + afterCharlieUAtomBalance sdk.Coin ) s.Require().Eventually( func() bool { - beforeSenderUAtomBalance, err = getSpecificBalance(chainAAPIEndpoint, sender, uatomDenom) + beforeAliceUAtomBalance, err = getSpecificBalance(api, alice.String(), uatomDenom) + s.Require().NoError(err) + + beforeBobUAtomBalance, err = getSpecificBalance(api, alice.String(), uatomDenom) s.Require().NoError(err) - beforeRecipientUAtomBalance, err = getSpecificBalance(chainAAPIEndpoint, recipient, uatomDenom) + beforeCharlieUAtomBalance, err = getSpecificBalance(api, alice.String(), uatomDenom) s.Require().NoError(err) - return beforeSenderUAtomBalance.IsValid() && beforeRecipientUAtomBalance.IsValid() + return beforeAliceUAtomBalance.IsValid() && beforeBobUAtomBalance.IsValid() && beforeCharlieUAtomBalance.IsValid() }, 10*time.Second, 5*time.Second, ) - s.execBankSend(s.chainA, 0, sender, recipient, tokenAmount.String(), standardFees.String(), false) + s.execBankSend(s.chainA, 0, alice.String(), bob.String(), tokenAmount.String(), standardFees.String(), false) s.Require().Eventually( func() bool { - afterSenderUAtomBalance, err := getSpecificBalance(chainAAPIEndpoint, sender, uatomDenom) + afterAliceUAtomBalance, err = getSpecificBalance(api, alice.String(), uatomDenom) + s.Require().NoError(err) + + afterBobUAtomBalance, err = getSpecificBalance(api, bob.String(), uatomDenom) + s.Require().NoError(err) + + decremented := beforeAliceUAtomBalance.Sub(tokenAmount).Sub(standardFees).IsEqual(afterAliceUAtomBalance) + incremented := beforeBobUAtomBalance.Add(tokenAmount).IsEqual(afterBobUAtomBalance) + + return decremented && incremented + }, + time.Minute, + 5*time.Second, + ) + + // reuse account balances results for next multi-send + beforeAliceUAtomBalance, beforeBobUAtomBalance = afterAliceUAtomBalance, afterBobUAtomBalance + + // alice sends tokens to bob and charlie at once + s.execBankMultiSend(s.chainA, 0, alice.String(), []string{bob.String(), charlie.String()}, tokenAmount.String(), standardFees.String(), false) + + s.Require().Eventually( + func() bool { + afterAliceUAtomBalance, err = getSpecificBalance(api, alice.String(), uatomDenom) + s.Require().NoError(err) + + afterBobUAtomBalance, err = getSpecificBalance(api, bob.String(), uatomDenom) s.Require().NoError(err) - afterRecipientUAtomBalance, err := getSpecificBalance(chainAAPIEndpoint, recipient, uatomDenom) + afterCharlieUAtomBalance, err = getSpecificBalance(api, charlie.String(), uatomDenom) s.Require().NoError(err) - decremented := beforeSenderUAtomBalance.Sub(tokenAmount).Sub(standardFees).IsEqual(afterSenderUAtomBalance) - incremented := beforeRecipientUAtomBalance.Add(tokenAmount).IsEqual(afterRecipientUAtomBalance) + // assert alice's accounts gets decremented the amount of token twice + decremented := beforeAliceUAtomBalance.Sub(tokenAmount).Sub(tokenAmount).Sub(standardFees).IsEqual(afterAliceUAtomBalance) + incremented := beforeBobUAtomBalance.Add(tokenAmount).IsEqual(afterBobUAtomBalance) && + beforeCharlieUAtomBalance.Add(tokenAmount).IsEqual(afterCharlieUAtomBalance) return decremented && incremented }, diff --git a/tests/e2e/e2e_exec_test.go b/tests/e2e/e2e_exec_test.go index 2ba718b430b..b8ae2d45c8f 100644 --- a/tests/e2e/e2e_exec_test.go +++ b/tests/e2e/e2e_exec_test.go @@ -284,6 +284,44 @@ func (s *IntegrationTestSuite) execBankSend( s.executeGaiaTxCommand(ctx, c, gaiaCommand, valIdx, s.expectErrExecValidation(c, valIdx, expectErr)) } +func (s *IntegrationTestSuite) execBankMultiSend( + c *chain, + valIdx int, + from string, + to []string, + amt string, + fees string, + expectErr bool, + opt ...flagOption, +) { + // TODO remove the hardcode opt after refactor, all methods should accept custom flags + opt = append(opt, withKeyValue(flagFees, fees)) + opt = append(opt, withKeyValue(flagFrom, from)) + opts := applyOptions(c.id, opt) + + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + + s.T().Logf("sending %s tokens from %s to %s on chain %s", amt, from, to, c.id) + + gaiaCommand := []string{ + gaiadBinary, + txCommand, + banktypes.ModuleName, + "multi-send", + from, + } + + gaiaCommand = append(gaiaCommand, to...) + gaiaCommand = append(gaiaCommand, amt, "-y") + + for flag, value := range opts { + gaiaCommand = append(gaiaCommand, fmt.Sprintf("--%s=%v", flag, value)) + } + + s.executeGaiaTxCommand(ctx, c, gaiaCommand, valIdx, s.expectErrExecValidation(c, valIdx, expectErr)) +} + type txBankSend struct { from string to string @@ -605,6 +643,8 @@ func (s *IntegrationTestSuite) executeGaiaTxCommand(ctx context.Context, c *chai }) s.Require().NoError(err) + fmt.Println(gaiaCommand) + err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ Context: ctx, Detach: false, @@ -616,6 +656,9 @@ func (s *IntegrationTestSuite) executeGaiaTxCommand(ctx context.Context, c *chai stdOut := outBuf.Bytes() stdErr := errBuf.Bytes() + fmt.Println("stdOut", string(stdOut)) + fmt.Println("stdErr", string(stdErr)) + if !validation(stdOut, stdErr) { s.Require().FailNowf("Exec validation failed", "stdout: %s, stderr: %s", string(stdOut), string(stdErr)) diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index 9aa1ef43de7..28bc6765a52 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -164,45 +164,47 @@ func (s *IntegrationTestSuite) SetupSuite() { s.initValidatorConfigs(s.chainB) s.runValidators(s.chainB, 10) - time.Sleep(10 * time.Second) - s.runIBCRelayer0() - s.runIBCRelayer1() + if runIBCTest { + time.Sleep(10 * time.Second) + s.runIBCRelayer0() + s.runIBCRelayer1() + } } func (s *IntegrationTestSuite) TearDownSuite() { - if str := os.Getenv("GAIA_E2E_SKIP_CLEANUP"); len(str) > 0 { - skipCleanup, err := strconv.ParseBool(str) - s.Require().NoError(err) - - if skipCleanup { - return - } - } - - s.T().Log("tearing down e2e integration test suite...") - - s.Require().NoError(s.dkrPool.Purge(s.hermesResource1)) - // if runIBCTest, s.hermesResource0 already purged in TestIBC() - // in GovSoftwareUpgrade test, s.TearDownSuite() then s.SetupSuite() - // if IBCTest runs before GovSoftwareUpgrade, s.hermesResource0 is already purged. - if !HermesResource0Purged { - s.Require().NoError(s.dkrPool.Purge(s.hermesResource0)) - } - - for _, vr := range s.valResources { - for _, r := range vr { - s.Require().NoError(s.dkrPool.Purge(r)) - } - } - - s.Require().NoError(s.dkrPool.RemoveNetwork(s.dkrNet)) - - os.RemoveAll(s.chainA.dataDir) - os.RemoveAll(s.chainB.dataDir) - - for _, td := range s.tmpDirs { - os.RemoveAll(td) - } + // if str := os.Getenv("GAIA_E2E_SKIP_CLEANUP"); len(str) > 0 { + // skipCleanup, err := strconv.ParseBool(str) + // s.Require().NoError(err) + + // if skipCleanup { + // return + // } + // } + + // s.T().Log("tearing down e2e integration test suite...") + + // s.Require().NoError(s.dkrPool.Purge(s.hermesResource1)) + // // if runIBCTest, s.hermesResource0 already purged in TestIBC() + // // in GovSoftwareUpgrade test, s.TearDownSuite() then s.SetupSuite() + // // if IBCTest runs before GovSoftwareUpgrade, s.hermesResource0 is already purged. + // if !HermesResource0Purged { + // s.Require().NoError(s.dkrPool.Purge(s.hermesResource0)) + // } + + // for _, vr := range s.valResources { + // for _, r := range vr { + // s.Require().NoError(s.dkrPool.Purge(r)) + // } + // } + + // s.Require().NoError(s.dkrPool.RemoveNetwork(s.dkrNet)) + + // os.RemoveAll(s.chainA.dataDir) + // os.RemoveAll(s.chainB.dataDir) + + // for _, td := range s.tmpDirs { + // os.RemoveAll(td) + // } } func (s *IntegrationTestSuite) initNodes(c *chain) { diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 6f5d231b2ef..6090aae6312 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -4,17 +4,17 @@ import "fmt" var ( runBankTest = true - runBypassMinFeeTest = true - runEncodeTest = true - runEvidenceTest = true - runFeeGrantTest = true - runGlobalFeesTest = true - runGovTest = true - runIBCTest = true - runSlashingTest = true - runStakingAndDistributionTest = true - runVestingTest = true - runRestInterfacesTest = true + runBypassMinFeeTest = false + runEncodeTest = false + runEvidenceTest = false + runFeeGrantTest = false + runGlobalFeesTest = false + runGovTest = false + runIBCTest = false + runSlashingTest = false + runStakingAndDistributionTest = false + runVestingTest = false + runRestInterfacesTest = false ) func (s *IntegrationTestSuite) TestRestInterfaces() { diff --git a/tests/e2e/query.go b/tests/e2e/query.go index 15d4e10aa4d..011e71c5c3e 100644 --- a/tests/e2e/query.go +++ b/tests/e2e/query.go @@ -22,6 +22,9 @@ import ( ) func queryGaiaTx(endpoint, txHash string) error { + + fmt.Println(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", endpoint, txHash)) + resp, err := http.Get(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", endpoint, txHash)) if err != nil { return fmt.Errorf("failed to execute HTTP request: %w", err) @@ -33,12 +36,15 @@ func queryGaiaTx(endpoint, txHash string) error { } var result map[string]interface{} + if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { return fmt.Errorf("failed to read response body: %w", err) } txResp := result["tx_response"].(map[string]interface{}) + // fmt.Printf("%#+v\n", txResp) + if v := txResp["code"]; v.(float64) != 0 { return fmt.Errorf("tx %s failed with status code %v", txHash, v) } From 8acc9a4cc576944495fcce57c4ea44c1fd7611a3 Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Tue, 19 Sep 2023 11:29:29 +0200 Subject: [PATCH 02/11] add cancel-unbond ET --- tests/e2e/e2e_bank_test.go | 37 ++++++++------- tests/e2e/e2e_exec_test.go | 55 +++++++++++++++++++++++ tests/e2e/e2e_setup_test.go | 74 +++++++++++++++--------------- tests/e2e/e2e_staking_test.go | 85 +++++++++++++++++++++++++++++++++-- tests/e2e/e2e_test.go | 22 ++++----- tests/e2e/query.go | 15 +++++++ 6 files changed, 217 insertions(+), 71 deletions(-) diff --git a/tests/e2e/e2e_bank_test.go b/tests/e2e/e2e_bank_test.go index d49c5d6236a..0997ef4a2e9 100644 --- a/tests/e2e/e2e_bank_test.go +++ b/tests/e2e/e2e_bank_test.go @@ -9,36 +9,34 @@ import ( func (s *IntegrationTestSuite) testBankTokenTransfer() { s.Run("send_photon_between_accounts", func() { - var ( - err error - valIdx = 0 - c = s.chainA - api = fmt.Sprintf("http://%s", s.valResources[c.id][valIdx].GetHostPort("1317/tcp")) + err error + valIdx = 0 + c = s.chainA + chainEndpoint = fmt.Sprintf("http://%s", s.valResources[c.id][valIdx].GetHostPort("1317/tcp")) ) + // define one sender and two recipient accounts alice, _ := c.genesisAccounts[1].keyInfo.GetAddress() bob, _ := c.genesisAccounts[2].keyInfo.GetAddress() charlie, _ := c.genesisAccounts[3].keyInfo.GetAddress() - var ( - beforeAliceUAtomBalance, + var beforeAliceUAtomBalance, beforeBobUAtomBalance, beforeCharlieUAtomBalance, afterAliceUAtomBalance, afterBobUAtomBalance, afterCharlieUAtomBalance sdk.Coin - ) s.Require().Eventually( func() bool { - beforeAliceUAtomBalance, err = getSpecificBalance(api, alice.String(), uatomDenom) + beforeAliceUAtomBalance, err = getSpecificBalance(chainEndpoint, alice.String(), uatomDenom) s.Require().NoError(err) - beforeBobUAtomBalance, err = getSpecificBalance(api, alice.String(), uatomDenom) + beforeBobUAtomBalance, err = getSpecificBalance(chainEndpoint, alice.String(), uatomDenom) s.Require().NoError(err) - beforeCharlieUAtomBalance, err = getSpecificBalance(api, alice.String(), uatomDenom) + beforeCharlieUAtomBalance, err = getSpecificBalance(chainEndpoint, alice.String(), uatomDenom) s.Require().NoError(err) return beforeAliceUAtomBalance.IsValid() && beforeBobUAtomBalance.IsValid() && beforeCharlieUAtomBalance.IsValid() @@ -47,14 +45,15 @@ func (s *IntegrationTestSuite) testBankTokenTransfer() { 5*time.Second, ) + // alice sends token to bob s.execBankSend(s.chainA, 0, alice.String(), bob.String(), tokenAmount.String(), standardFees.String(), false) s.Require().Eventually( func() bool { - afterAliceUAtomBalance, err = getSpecificBalance(api, alice.String(), uatomDenom) + afterAliceUAtomBalance, err = getSpecificBalance(chainEndpoint, alice.String(), uatomDenom) s.Require().NoError(err) - afterBobUAtomBalance, err = getSpecificBalance(api, bob.String(), uatomDenom) + afterBobUAtomBalance, err = getSpecificBalance(chainEndpoint, bob.String(), uatomDenom) s.Require().NoError(err) decremented := beforeAliceUAtomBalance.Sub(tokenAmount).Sub(standardFees).IsEqual(afterAliceUAtomBalance) @@ -66,24 +65,24 @@ func (s *IntegrationTestSuite) testBankTokenTransfer() { 5*time.Second, ) - // reuse account balances results for next multi-send + // save the current account balances of alice and bob beforeAliceUAtomBalance, beforeBobUAtomBalance = afterAliceUAtomBalance, afterBobUAtomBalance - // alice sends tokens to bob and charlie at once + // alice sends tokens to bob and charlie, at once s.execBankMultiSend(s.chainA, 0, alice.String(), []string{bob.String(), charlie.String()}, tokenAmount.String(), standardFees.String(), false) s.Require().Eventually( func() bool { - afterAliceUAtomBalance, err = getSpecificBalance(api, alice.String(), uatomDenom) + afterAliceUAtomBalance, err = getSpecificBalance(chainEndpoint, alice.String(), uatomDenom) s.Require().NoError(err) - afterBobUAtomBalance, err = getSpecificBalance(api, bob.String(), uatomDenom) + afterBobUAtomBalance, err = getSpecificBalance(chainEndpoint, bob.String(), uatomDenom) s.Require().NoError(err) - afterCharlieUAtomBalance, err = getSpecificBalance(api, charlie.String(), uatomDenom) + afterCharlieUAtomBalance, err = getSpecificBalance(chainEndpoint, charlie.String(), uatomDenom) s.Require().NoError(err) - // assert alice's accounts gets decremented the amount of token twice + // assert alice's account gets decremented the amount of tokens twice decremented := beforeAliceUAtomBalance.Sub(tokenAmount).Sub(tokenAmount).Sub(standardFees).IsEqual(afterAliceUAtomBalance) incremented := beforeBobUAtomBalance.Add(tokenAmount).IsEqual(afterBobUAtomBalance) && beforeCharlieUAtomBalance.Add(tokenAmount).IsEqual(afterCharlieUAtomBalance) diff --git a/tests/e2e/e2e_exec_test.go b/tests/e2e/e2e_exec_test.go index b8ae2d45c8f..789883d232c 100644 --- a/tests/e2e/e2e_exec_test.go +++ b/tests/e2e/e2e_exec_test.go @@ -493,6 +493,61 @@ func (s *IntegrationTestSuite) executeDelegate(c *chain, valIdx int, amount, val s.T().Logf("%s successfully delegated %s to %s", delegatorAddr, amount, valOperAddress) } +func (s *IntegrationTestSuite) executeUnbondDelegation(c *chain, valIdx int, amount, valOperAddress, delegatorAddr, home, delegateFees string) { //nolint:unparam + + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + + s.T().Logf("Executing gaiad tx staking unbond %s", c.id) + + gaiaCommand := []string{ + gaiadBinary, + txCommand, + stakingtypes.ModuleName, + "unbond", + valOperAddress, + amount, + fmt.Sprintf("--%s=%s", flags.FlagFrom, delegatorAddr), + fmt.Sprintf("--%s=%s", flags.FlagChainID, c.id), + fmt.Sprintf("--%s=%s", flags.FlagGasPrices, delegateFees), + "--keyring-backend=test", + fmt.Sprintf("--%s=%s", flags.FlagHome, home), + "--output=json", + "-y", + } + + s.executeGaiaTxCommand(ctx, c, gaiaCommand, valIdx, s.defaultExecValidation(c, valIdx)) + s.T().Logf("%s successfully undelegated %s to %s", delegatorAddr, amount, valOperAddress) +} + +func (s *IntegrationTestSuite) executeCancelUnbondingDelegation(c *chain, valIdx int, amount, valOperAddress, creationHeight, delegatorAddr, home, delegateFees string) { //nolint:unparam + + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + + s.T().Logf("Executing gaiad tx staking cancel-unbond %s", c.id) + + gaiaCommand := []string{ + gaiadBinary, + txCommand, + stakingtypes.ModuleName, + "cancel-unbond", + valOperAddress, + amount, + creationHeight, + fmt.Sprintf("--%s=%s", flags.FlagFrom, delegatorAddr), + fmt.Sprintf("--%s=%s", flags.FlagChainID, c.id), + fmt.Sprintf("--%s=%s", flags.FlagGasPrices, delegateFees), + "--keyring-backend=test", + fmt.Sprintf("--%s=%s", flags.FlagHome, home), + "--output=json", + "-y", + } + + s.executeGaiaTxCommand(ctx, c, gaiaCommand, valIdx, s.defaultExecValidation(c, valIdx)) + s.T().Logf("%s successfully undelegated %s to %s", delegatorAddr, amount, valOperAddress) +} + func (s *IntegrationTestSuite) executeRedelegate(c *chain, valIdx int, amount, originalValOperAddress, newValOperAddress, delegatorAddr, home, delegateFees string, diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index 28bc6765a52..9aa1ef43de7 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -164,47 +164,45 @@ func (s *IntegrationTestSuite) SetupSuite() { s.initValidatorConfigs(s.chainB) s.runValidators(s.chainB, 10) - if runIBCTest { - time.Sleep(10 * time.Second) - s.runIBCRelayer0() - s.runIBCRelayer1() - } + time.Sleep(10 * time.Second) + s.runIBCRelayer0() + s.runIBCRelayer1() } func (s *IntegrationTestSuite) TearDownSuite() { - // if str := os.Getenv("GAIA_E2E_SKIP_CLEANUP"); len(str) > 0 { - // skipCleanup, err := strconv.ParseBool(str) - // s.Require().NoError(err) - - // if skipCleanup { - // return - // } - // } - - // s.T().Log("tearing down e2e integration test suite...") - - // s.Require().NoError(s.dkrPool.Purge(s.hermesResource1)) - // // if runIBCTest, s.hermesResource0 already purged in TestIBC() - // // in GovSoftwareUpgrade test, s.TearDownSuite() then s.SetupSuite() - // // if IBCTest runs before GovSoftwareUpgrade, s.hermesResource0 is already purged. - // if !HermesResource0Purged { - // s.Require().NoError(s.dkrPool.Purge(s.hermesResource0)) - // } - - // for _, vr := range s.valResources { - // for _, r := range vr { - // s.Require().NoError(s.dkrPool.Purge(r)) - // } - // } - - // s.Require().NoError(s.dkrPool.RemoveNetwork(s.dkrNet)) - - // os.RemoveAll(s.chainA.dataDir) - // os.RemoveAll(s.chainB.dataDir) - - // for _, td := range s.tmpDirs { - // os.RemoveAll(td) - // } + if str := os.Getenv("GAIA_E2E_SKIP_CLEANUP"); len(str) > 0 { + skipCleanup, err := strconv.ParseBool(str) + s.Require().NoError(err) + + if skipCleanup { + return + } + } + + s.T().Log("tearing down e2e integration test suite...") + + s.Require().NoError(s.dkrPool.Purge(s.hermesResource1)) + // if runIBCTest, s.hermesResource0 already purged in TestIBC() + // in GovSoftwareUpgrade test, s.TearDownSuite() then s.SetupSuite() + // if IBCTest runs before GovSoftwareUpgrade, s.hermesResource0 is already purged. + if !HermesResource0Purged { + s.Require().NoError(s.dkrPool.Purge(s.hermesResource0)) + } + + for _, vr := range s.valResources { + for _, r := range vr { + s.Require().NoError(s.dkrPool.Purge(r)) + } + } + + s.Require().NoError(s.dkrPool.RemoveNetwork(s.dkrNet)) + + os.RemoveAll(s.chainA.dataDir) + os.RemoveAll(s.chainB.dataDir) + + for _, td := range s.tmpDirs { + os.RemoveAll(td) + } } func (s *IntegrationTestSuite) initNodes(c *chain) { diff --git a/tests/e2e/e2e_staking_test.go b/tests/e2e/e2e_staking_test.go index e9ab52ab9e9..c3c667a06bc 100644 --- a/tests/e2e/e2e_staking_test.go +++ b/tests/e2e/e2e_staking_test.go @@ -2,9 +2,12 @@ package e2e import ( "fmt" + "strconv" "time" + "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/staking/types" ) func (s *IntegrationTestSuite) testStaking() { @@ -41,8 +44,11 @@ func (s *IntegrationTestSuite) testStaking() { 5*time.Second, ) - // Alice re-delegate uatom from Validator A to Validator B - s.executeRedelegate(s.chainA, 0, delegation.String(), validatorAddressA, validatorAddressB, delegatorAddress.String(), gaiaHomePath, fees.String()) + redelegationAmount := delegationAmount.Quo(sdk.NewInt(2)) + redelegation := sdk.NewCoin(uatomDenom, redelegationAmount) // 250 atom + + // Alice re-delegate half of her uatom delegation from Validator A to Validator B + s.executeRedelegate(s.chainA, 0, redelegation.String(), validatorAddressA, validatorAddressB, delegatorAddress.String(), gaiaHomePath, fees.String()) // Validate re-delegation successful s.Require().Eventually( @@ -51,7 +57,80 @@ func (s *IntegrationTestSuite) testStaking() { amt := res.GetDelegationResponse().GetDelegation().GetShares() s.Require().NoError(err) - return amt.Equal(sdk.NewDecFromInt(delegationAmount)) + return amt.Equal(sdk.NewDecFromInt(redelegationAmount)) + }, + 20*time.Second, + 5*time.Second, + ) + + var ( + currDelegation sdk.Coin + currDelegationAmount math.Int + ) + + // query alice's current delegation from validator A + s.Require().Eventually( + func() bool { + res, err := queryDelegation(chainEndpoint, validatorAddressA, delegatorAddress.String()) + amt := res.GetDelegationResponse().GetDelegation().GetShares() + s.Require().NoError(err) + + currDelegationAmount = amt.TruncateInt() + currDelegation = sdk.NewCoin(uatomDenom, currDelegationAmount) + + return currDelegation.IsValid() + }, + 20*time.Second, + 5*time.Second, + ) + + // Alice unbonds all her uatom delegation from Validator A + s.executeUnbondDelegation(s.chainA, 0, currDelegation.String(), validatorAddressA, delegatorAddress.String(), gaiaHomePath, fees.String()) + + var ( + ubdDelegationEntry types.UnbondingDelegationEntry + ) + + // validate unbonding delegations + s.Require().Eventually( + func() bool { + res, err := queryUnbondingDelegation(chainEndpoint, validatorAddressA, delegatorAddress.String()) + s.Require().NoError(err) + + s.Require().Len(res.GetUnbond().Entries, 1) + ubdDelegationEntry = res.GetUnbond().Entries[0] + + return ubdDelegationEntry.Balance.Equal(currDelegationAmount) + }, + 20*time.Second, + 5*time.Second, + ) + + // cancel the full amount of unbonding delegations from Validator A + s.executeCancelUnbondingDelegation( + s.chainA, + 0, + currDelegation.String(), + validatorAddressA, + strconv.Itoa(int(ubdDelegationEntry.CreationHeight)), + delegatorAddress.String(), + gaiaHomePath, + fees.String(), + ) + + // validate that unbonding delegation was successfully canceled + s.Require().Eventually( + func() bool { + resDel, err := queryDelegation(chainEndpoint, validatorAddressA, delegatorAddress.String()) + amt := resDel.GetDelegationResponse().GetDelegation().GetShares() + s.Require().NoError(err) + + // expect that no unbonding delegations are found for validator A + _, err = queryUnbondingDelegation(chainEndpoint, validatorAddressA, delegatorAddress.String()) + s.Require().Error(err) + + // expect to get the delegation back + return amt.Equal(sdk.NewDecFromInt(currDelegationAmount)) }, 20*time.Second, 5*time.Second, diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 6090aae6312..6f5d231b2ef 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -4,17 +4,17 @@ import "fmt" var ( runBankTest = true - runBypassMinFeeTest = false - runEncodeTest = false - runEvidenceTest = false - runFeeGrantTest = false - runGlobalFeesTest = false - runGovTest = false - runIBCTest = false - runSlashingTest = false - runStakingAndDistributionTest = false - runVestingTest = false - runRestInterfacesTest = false + runBypassMinFeeTest = true + runEncodeTest = true + runEvidenceTest = true + runFeeGrantTest = true + runGlobalFeesTest = true + runGovTest = true + runIBCTest = true + runSlashingTest = true + runStakingAndDistributionTest = true + runVestingTest = true + runRestInterfacesTest = true ) func (s *IntegrationTestSuite) TestRestInterfaces() { diff --git a/tests/e2e/query.go b/tests/e2e/query.go index 011e71c5c3e..9e6728e2b1a 100644 --- a/tests/e2e/query.go +++ b/tests/e2e/query.go @@ -127,6 +127,21 @@ func queryDelegation(endpoint string, validatorAddr string, delegatorAddr string return res, nil } +func queryUnbondingDelegation(endpoint string, validatorAddr string, delegatorAddr string) (stakingtypes.QueryUnbondingDelegationResponse, error) { + var res stakingtypes.QueryUnbondingDelegationResponse + + fmt.Println(fmt.Sprintf(fmt.Sprintf("%s/cosmos/staking/v1beta1/validators/%s/delegations/%s/unbonding_delegation", endpoint, validatorAddr, delegatorAddr))) + body, err := httpGet(fmt.Sprintf("%s/cosmos/staking/v1beta1/validators/%s/delegations/%s/unbonding_delegation", endpoint, validatorAddr, delegatorAddr)) + if err != nil { + return res, err + } + + if err = cdc.UnmarshalJSON(body, &res); err != nil { + return res, err + } + return res, nil +} + func queryDelegatorWithdrawalAddress(endpoint string, delegatorAddr string) (disttypes.QueryDelegatorWithdrawAddressResponse, error) { var res disttypes.QueryDelegatorWithdrawAddressResponse From 57fb79e0337fbb93eb0dcc80f111b190d223168d Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Tue, 19 Sep 2023 16:10:40 +0200 Subject: [PATCH 03/11] nits --- tests/e2e/e2e_bank_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/e2e/e2e_bank_test.go b/tests/e2e/e2e_bank_test.go index 0997ef4a2e9..a8be02ad023 100644 --- a/tests/e2e/e2e_bank_test.go +++ b/tests/e2e/e2e_bank_test.go @@ -11,9 +11,8 @@ func (s *IntegrationTestSuite) testBankTokenTransfer() { s.Run("send_photon_between_accounts", func() { var ( err error - valIdx = 0 c = s.chainA - chainEndpoint = fmt.Sprintf("http://%s", s.valResources[c.id][valIdx].GetHostPort("1317/tcp")) + chainEndpoint = fmt.Sprintf("http://%s", s.valResources[c.id][0].GetHostPort("1317/tcp")) ) // define one sender and two recipient accounts From bdd6dce4bb47c3405b69fda336b3ad5e0c08bb6a Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Tue, 19 Sep 2023 16:25:15 +0200 Subject: [PATCH 04/11] nits --- tests/e2e/e2e_bank_test.go | 4 ++-- tests/e2e/e2e_exec_test.go | 11 +++-------- tests/e2e/e2e_staking_test.go | 2 +- tests/e2e/query.go | 5 ----- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/tests/e2e/e2e_bank_test.go b/tests/e2e/e2e_bank_test.go index a8be02ad023..1b0b4357a67 100644 --- a/tests/e2e/e2e_bank_test.go +++ b/tests/e2e/e2e_bank_test.go @@ -44,7 +44,7 @@ func (s *IntegrationTestSuite) testBankTokenTransfer() { 5*time.Second, ) - // alice sends token to bob + // alice sends tokens to bob s.execBankSend(s.chainA, 0, alice.String(), bob.String(), tokenAmount.String(), standardFees.String(), false) s.Require().Eventually( @@ -64,7 +64,7 @@ func (s *IntegrationTestSuite) testBankTokenTransfer() { 5*time.Second, ) - // save the current account balances of alice and bob + // save the updated account balances of alice and bob beforeAliceUAtomBalance, beforeBobUAtomBalance = afterAliceUAtomBalance, afterBobUAtomBalance // alice sends tokens to bob and charlie, at once diff --git a/tests/e2e/e2e_exec_test.go b/tests/e2e/e2e_exec_test.go index 789883d232c..aa7b6fec5e1 100644 --- a/tests/e2e/e2e_exec_test.go +++ b/tests/e2e/e2e_exec_test.go @@ -466,6 +466,7 @@ func (s *IntegrationTestSuite) runGovExec(c *chain, valIdx int, submitterAddr, g // }) // } +// TODO rename to execDelegate for consistency func (s *IntegrationTestSuite) executeDelegate(c *chain, valIdx int, amount, valOperAddress, delegatorAddr, home, delegateFees string) { //nolint:unparam ctx, cancel := context.WithTimeout(context.Background(), time.Minute) @@ -493,8 +494,7 @@ func (s *IntegrationTestSuite) executeDelegate(c *chain, valIdx int, amount, val s.T().Logf("%s successfully delegated %s to %s", delegatorAddr, amount, valOperAddress) } -func (s *IntegrationTestSuite) executeUnbondDelegation(c *chain, valIdx int, amount, valOperAddress, delegatorAddr, home, delegateFees string) { //nolint:unparam - +func (s *IntegrationTestSuite) execUnbondDelegation(c *chain, valIdx int, amount, valOperAddress, delegatorAddr, home, delegateFees string) { //nolint:unparam ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() @@ -548,8 +548,8 @@ func (s *IntegrationTestSuite) executeCancelUnbondingDelegation(c *chain, valIdx s.T().Logf("%s successfully undelegated %s to %s", delegatorAddr, amount, valOperAddress) } +// TODO rename to execDelegate for consistency func (s *IntegrationTestSuite) executeRedelegate(c *chain, valIdx int, amount, originalValOperAddress, - newValOperAddress, delegatorAddr, home, delegateFees string, ) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) @@ -698,8 +698,6 @@ func (s *IntegrationTestSuite) executeGaiaTxCommand(ctx context.Context, c *chai }) s.Require().NoError(err) - fmt.Println(gaiaCommand) - err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ Context: ctx, Detach: false, @@ -711,9 +709,6 @@ func (s *IntegrationTestSuite) executeGaiaTxCommand(ctx context.Context, c *chai stdOut := outBuf.Bytes() stdErr := errBuf.Bytes() - fmt.Println("stdOut", string(stdOut)) - fmt.Println("stdErr", string(stdErr)) - if !validation(stdOut, stdErr) { s.Require().FailNowf("Exec validation failed", "stdout: %s, stderr: %s", string(stdOut), string(stdErr)) diff --git a/tests/e2e/e2e_staking_test.go b/tests/e2e/e2e_staking_test.go index c3c667a06bc..7bcdbcedb68 100644 --- a/tests/e2e/e2e_staking_test.go +++ b/tests/e2e/e2e_staking_test.go @@ -85,7 +85,7 @@ func (s *IntegrationTestSuite) testStaking() { ) // Alice unbonds all her uatom delegation from Validator A - s.executeUnbondDelegation(s.chainA, 0, currDelegation.String(), validatorAddressA, delegatorAddress.String(), gaiaHomePath, fees.String()) + s.execUnbondDelegation(s.chainA, 0, currDelegation.String(), validatorAddressA, delegatorAddress.String(), gaiaHomePath, fees.String()) var ( ubdDelegationEntry types.UnbondingDelegationEntry diff --git a/tests/e2e/query.go b/tests/e2e/query.go index 9e6728e2b1a..73b0375b06d 100644 --- a/tests/e2e/query.go +++ b/tests/e2e/query.go @@ -22,9 +22,6 @@ import ( ) func queryGaiaTx(endpoint, txHash string) error { - - fmt.Println(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", endpoint, txHash)) - resp, err := http.Get(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", endpoint, txHash)) if err != nil { return fmt.Errorf("failed to execute HTTP request: %w", err) @@ -129,8 +126,6 @@ func queryDelegation(endpoint string, validatorAddr string, delegatorAddr string func queryUnbondingDelegation(endpoint string, validatorAddr string, delegatorAddr string) (stakingtypes.QueryUnbondingDelegationResponse, error) { var res stakingtypes.QueryUnbondingDelegationResponse - - fmt.Println(fmt.Sprintf(fmt.Sprintf("%s/cosmos/staking/v1beta1/validators/%s/delegations/%s/unbonding_delegation", endpoint, validatorAddr, delegatorAddr))) body, err := httpGet(fmt.Sprintf("%s/cosmos/staking/v1beta1/validators/%s/delegations/%s/unbonding_delegation", endpoint, validatorAddr, delegatorAddr)) if err != nil { return res, err From b67180c84d3a308db818892d21593886b53b2afe Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Tue, 19 Sep 2023 16:27:02 +0200 Subject: [PATCH 05/11] nits --- tests/e2e/e2e_exec_test.go | 4 ++-- tests/e2e/e2e_staking_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/e2e/e2e_exec_test.go b/tests/e2e/e2e_exec_test.go index aa7b6fec5e1..b62ecafce67 100644 --- a/tests/e2e/e2e_exec_test.go +++ b/tests/e2e/e2e_exec_test.go @@ -494,7 +494,7 @@ func (s *IntegrationTestSuite) executeDelegate(c *chain, valIdx int, amount, val s.T().Logf("%s successfully delegated %s to %s", delegatorAddr, amount, valOperAddress) } -func (s *IntegrationTestSuite) execUnbondDelegation(c *chain, valIdx int, amount, valOperAddress, delegatorAddr, home, delegateFees string) { //nolint:unparam +func (s *IntegrationTestSuite) execUnbondDelegation(c *chain, valIdx int, amount, valOperAddress, delegatorAddr, home, delegateFees string) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() @@ -520,7 +520,7 @@ func (s *IntegrationTestSuite) execUnbondDelegation(c *chain, valIdx int, amount s.T().Logf("%s successfully undelegated %s to %s", delegatorAddr, amount, valOperAddress) } -func (s *IntegrationTestSuite) executeCancelUnbondingDelegation(c *chain, valIdx int, amount, valOperAddress, creationHeight, delegatorAddr, home, delegateFees string) { //nolint:unparam +func (s *IntegrationTestSuite) execCancelUnbondingDelegation(c *chain, valIdx int, amount, valOperAddress, creationHeight, delegatorAddr, home, delegateFees string) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() diff --git a/tests/e2e/e2e_staking_test.go b/tests/e2e/e2e_staking_test.go index 7bcdbcedb68..aef20268d7f 100644 --- a/tests/e2e/e2e_staking_test.go +++ b/tests/e2e/e2e_staking_test.go @@ -107,7 +107,7 @@ func (s *IntegrationTestSuite) testStaking() { ) // cancel the full amount of unbonding delegations from Validator A - s.executeCancelUnbondingDelegation( + s.execCancelUnbondingDelegation( s.chainA, 0, currDelegation.String(), From 13bdcee9397158037a4e15e9774e74030a701206 Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Tue, 19 Sep 2023 16:41:41 +0200 Subject: [PATCH 06/11] reformat --- tests/e2e/e2e_bank_test.go | 7 ++++--- tests/e2e/query.go | 3 --- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/e2e/e2e_bank_test.go b/tests/e2e/e2e_bank_test.go index 1b0b4357a67..2f9e050af2c 100644 --- a/tests/e2e/e2e_bank_test.go +++ b/tests/e2e/e2e_bank_test.go @@ -11,8 +11,9 @@ func (s *IntegrationTestSuite) testBankTokenTransfer() { s.Run("send_photon_between_accounts", func() { var ( err error + valIdx = 0 c = s.chainA - chainEndpoint = fmt.Sprintf("http://%s", s.valResources[c.id][0].GetHostPort("1317/tcp")) + chainEndpoint = fmt.Sprintf("http://%s", s.valResources[c.id][valIdx].GetHostPort("1317/tcp")) ) // define one sender and two recipient accounts @@ -45,7 +46,7 @@ func (s *IntegrationTestSuite) testBankTokenTransfer() { ) // alice sends tokens to bob - s.execBankSend(s.chainA, 0, alice.String(), bob.String(), tokenAmount.String(), standardFees.String(), false) + s.execBankSend(s.chainA, valIdx, alice.String(), bob.String(), tokenAmount.String(), standardFees.String(), false) s.Require().Eventually( func() bool { @@ -68,7 +69,7 @@ func (s *IntegrationTestSuite) testBankTokenTransfer() { beforeAliceUAtomBalance, beforeBobUAtomBalance = afterAliceUAtomBalance, afterBobUAtomBalance // alice sends tokens to bob and charlie, at once - s.execBankMultiSend(s.chainA, 0, alice.String(), []string{bob.String(), charlie.String()}, tokenAmount.String(), standardFees.String(), false) + s.execBankMultiSend(s.chainA, valIdx, alice.String(), []string{bob.String(), charlie.String()}, tokenAmount.String(), standardFees.String(), false) s.Require().Eventually( func() bool { diff --git a/tests/e2e/query.go b/tests/e2e/query.go index 73b0375b06d..44d12bb303a 100644 --- a/tests/e2e/query.go +++ b/tests/e2e/query.go @@ -39,9 +39,6 @@ func queryGaiaTx(endpoint, txHash string) error { } txResp := result["tx_response"].(map[string]interface{}) - - // fmt.Printf("%#+v\n", txResp) - if v := txResp["code"]; v.(float64) != 0 { return fmt.Errorf("tx %s failed with status code %v", txHash, v) } From 891e4d189b20ef71272454093c075dd19d54e0b7 Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Wed, 20 Sep 2023 09:36:50 +0200 Subject: [PATCH 07/11] fix --- tests/e2e/e2e_bank_test.go | 10 ++++++---- tests/e2e/e2e_exec_test.go | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/e2e/e2e_bank_test.go b/tests/e2e/e2e_bank_test.go index 2f9e050af2c..2abae83599d 100644 --- a/tests/e2e/e2e_bank_test.go +++ b/tests/e2e/e2e_bank_test.go @@ -28,15 +28,16 @@ func (s *IntegrationTestSuite) testBankTokenTransfer() { afterBobUAtomBalance, afterCharlieUAtomBalance sdk.Coin + // get balances of sender and recipient accounts s.Require().Eventually( func() bool { beforeAliceUAtomBalance, err = getSpecificBalance(chainEndpoint, alice.String(), uatomDenom) s.Require().NoError(err) - beforeBobUAtomBalance, err = getSpecificBalance(chainEndpoint, alice.String(), uatomDenom) + beforeBobUAtomBalance, err = getSpecificBalance(chainEndpoint, bob.String(), uatomDenom) s.Require().NoError(err) - beforeCharlieUAtomBalance, err = getSpecificBalance(chainEndpoint, alice.String(), uatomDenom) + beforeCharlieUAtomBalance, err = getSpecificBalance(chainEndpoint, charlie.String(), uatomDenom) s.Require().NoError(err) return beforeAliceUAtomBalance.IsValid() && beforeBobUAtomBalance.IsValid() && beforeCharlieUAtomBalance.IsValid() @@ -48,6 +49,7 @@ func (s *IntegrationTestSuite) testBankTokenTransfer() { // alice sends tokens to bob s.execBankSend(s.chainA, valIdx, alice.String(), bob.String(), tokenAmount.String(), standardFees.String(), false) + // check that the transfer was successful s.Require().Eventually( func() bool { afterAliceUAtomBalance, err = getSpecificBalance(chainEndpoint, alice.String(), uatomDenom) @@ -61,7 +63,7 @@ func (s *IntegrationTestSuite) testBankTokenTransfer() { return decremented && incremented }, - time.Minute, + 10*time.Second, 5*time.Second, ) @@ -89,7 +91,7 @@ func (s *IntegrationTestSuite) testBankTokenTransfer() { return decremented && incremented }, - time.Minute, + 10*time.Second, 5*time.Second, ) }) diff --git a/tests/e2e/e2e_exec_test.go b/tests/e2e/e2e_exec_test.go index b62ecafce67..4a599dedf38 100644 --- a/tests/e2e/e2e_exec_test.go +++ b/tests/e2e/e2e_exec_test.go @@ -548,7 +548,7 @@ func (s *IntegrationTestSuite) execCancelUnbondingDelegation(c *chain, valIdx in s.T().Logf("%s successfully undelegated %s to %s", delegatorAddr, amount, valOperAddress) } -// TODO rename to execDelegate for consistency +// TODO rename to execRedelegate for consistency func (s *IntegrationTestSuite) executeRedelegate(c *chain, valIdx int, amount, originalValOperAddress, newValOperAddress, delegatorAddr, home, delegateFees string, ) { From cc67a8cbd8ed5049fc6efe59552a334a59d16082 Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Wed, 20 Sep 2023 09:43:12 +0200 Subject: [PATCH 08/11] reformat --- tests/e2e/e2e_exec_test.go | 8 +++----- tests/e2e/e2e_staking_test.go | 4 ++-- tests/e2e/e2e_vesting_test.go | 6 +++--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/e2e/e2e_exec_test.go b/tests/e2e/e2e_exec_test.go index 4a599dedf38..32936c6ad2e 100644 --- a/tests/e2e/e2e_exec_test.go +++ b/tests/e2e/e2e_exec_test.go @@ -466,8 +466,7 @@ func (s *IntegrationTestSuite) runGovExec(c *chain, valIdx int, submitterAddr, g // }) // } -// TODO rename to execDelegate for consistency -func (s *IntegrationTestSuite) executeDelegate(c *chain, valIdx int, amount, valOperAddress, delegatorAddr, home, delegateFees string) { //nolint:unparam +func (s *IntegrationTestSuite) execDelegate(c *chain, valIdx int, amount, valOperAddress, delegatorAddr, home, delegateFees string) { //nolint:unparam ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() @@ -545,11 +544,10 @@ func (s *IntegrationTestSuite) execCancelUnbondingDelegation(c *chain, valIdx in } s.executeGaiaTxCommand(ctx, c, gaiaCommand, valIdx, s.defaultExecValidation(c, valIdx)) - s.T().Logf("%s successfully undelegated %s to %s", delegatorAddr, amount, valOperAddress) + s.T().Logf("%s successfully canceled unbonding %s to %s", delegatorAddr, amount, valOperAddress) } -// TODO rename to execRedelegate for consistency -func (s *IntegrationTestSuite) executeRedelegate(c *chain, valIdx int, amount, originalValOperAddress, +func (s *IntegrationTestSuite) execRedelegate(c *chain, valIdx int, amount, originalValOperAddress, newValOperAddress, delegatorAddr, home, delegateFees string, ) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) diff --git a/tests/e2e/e2e_staking_test.go b/tests/e2e/e2e_staking_test.go index aef20268d7f..66019b4d116 100644 --- a/tests/e2e/e2e_staking_test.go +++ b/tests/e2e/e2e_staking_test.go @@ -29,7 +29,7 @@ func (s *IntegrationTestSuite) testStaking() { delegation := sdk.NewCoin(uatomDenom, delegationAmount) // 500 atom // Alice delegate uatom to Validator A - s.executeDelegate(s.chainA, 0, delegation.String(), validatorAddressA, delegatorAddress.String(), gaiaHomePath, fees.String()) + s.execDelegate(s.chainA, 0, delegation.String(), validatorAddressA, delegatorAddress.String(), gaiaHomePath, fees.String()) // Validate delegation successful s.Require().Eventually( @@ -48,7 +48,7 @@ func (s *IntegrationTestSuite) testStaking() { redelegation := sdk.NewCoin(uatomDenom, redelegationAmount) // 250 atom // Alice re-delegate half of her uatom delegation from Validator A to Validator B - s.executeRedelegate(s.chainA, 0, redelegation.String(), validatorAddressA, validatorAddressB, delegatorAddress.String(), gaiaHomePath, fees.String()) + s.execRedelegate(s.chainA, 0, redelegation.String(), validatorAddressA, validatorAddressB, delegatorAddress.String(), gaiaHomePath, fees.String()) // Validate re-delegation successful s.Require().Eventually( diff --git a/tests/e2e/e2e_vesting_test.go b/tests/e2e/e2e_vesting_test.go index 0483cb8343c..6d652a1d8b3 100644 --- a/tests/e2e/e2e_vesting_test.go +++ b/tests/e2e/e2e_vesting_test.go @@ -59,7 +59,7 @@ func (s *IntegrationTestSuite) testDelayedVestingAccount(api string) { s.Require().Equal(vestingBalance.AmountOf(uatomDenom), balance.Amount) // Delegate coins should succeed - s.executeDelegate(chain, valIdx, vestingDelegationAmount.String(), valOpAddr, + s.execDelegate(chain, valIdx, vestingDelegationAmount.String(), valOpAddr, vestingDelayedAcc.String(), gaiaHomePath, vestingDelegationFees.String()) // Validate delegation successful @@ -128,7 +128,7 @@ func (s *IntegrationTestSuite) testContinuousVestingAccount(api string) { s.Require().Equal(vestingBalance.AmountOf(uatomDenom), balance.Amount) // Delegate coins should succeed - s.executeDelegate(chain, valIdx, vestingDelegationAmount.String(), + s.execDelegate(chain, valIdx, vestingDelegationAmount.String(), valOpAddr, continuousVestingAcc.String(), gaiaHomePath, vestingDelegationFees.String()) // Validate delegation successful @@ -267,7 +267,7 @@ func (s *IntegrationTestSuite) testPeriodicVestingAccount(api string) { //nolint } // Delegate coins should succeed - s.executeDelegate(chain, valIdx, vestingDelegationAmount.String(), valOpAddr, + s.execDelegate(chain, valIdx, vestingDelegationAmount.String(), valOpAddr, periodicVestingAddr, gaiaHomePath, vestingDelegationFees.String()) // Validate delegation successful From df6ed5f13164d5e78da0e710575b4dde13ca5f0e Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Wed, 20 Sep 2023 09:49:41 +0200 Subject: [PATCH 09/11] lint --- tests/e2e/e2e_exec_test.go | 1 - tests/e2e/e2e_staking_test.go | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/e2e/e2e_exec_test.go b/tests/e2e/e2e_exec_test.go index 32936c6ad2e..134dfdb909b 100644 --- a/tests/e2e/e2e_exec_test.go +++ b/tests/e2e/e2e_exec_test.go @@ -520,7 +520,6 @@ func (s *IntegrationTestSuite) execUnbondDelegation(c *chain, valIdx int, amount } func (s *IntegrationTestSuite) execCancelUnbondingDelegation(c *chain, valIdx int, amount, valOperAddress, creationHeight, delegatorAddr, home, delegateFees string) { - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() diff --git a/tests/e2e/e2e_staking_test.go b/tests/e2e/e2e_staking_test.go index 66019b4d116..0a616530d28 100644 --- a/tests/e2e/e2e_staking_test.go +++ b/tests/e2e/e2e_staking_test.go @@ -87,9 +87,7 @@ func (s *IntegrationTestSuite) testStaking() { // Alice unbonds all her uatom delegation from Validator A s.execUnbondDelegation(s.chainA, 0, currDelegation.String(), validatorAddressA, delegatorAddress.String(), gaiaHomePath, fees.String()) - var ( - ubdDelegationEntry types.UnbondingDelegationEntry - ) + var ubdDelegationEntry types.UnbondingDelegationEntry // validate unbonding delegations s.Require().Eventually( From 15b00a9fd582b5622c61bfbdfd14b1c8e7fa8ce8 Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Tue, 26 Sep 2023 10:39:59 +0200 Subject: [PATCH 10/11] remove simapp from genesis test --- x/globalfee/genesis_test.go | 305 ++++++++++++++++++------------------ 1 file changed, 155 insertions(+), 150 deletions(-) diff --git a/x/globalfee/genesis_test.go b/x/globalfee/genesis_test.go index e0730540202..7cb6f974856 100644 --- a/x/globalfee/genesis_test.go +++ b/x/globalfee/genesis_test.go @@ -1,161 +1,166 @@ package globalfee -// import ( -// "testing" -// "time" +import ( + "testing" + "time" -// "github.com/cosmos/cosmos-sdk/simapp" -// simappparams "github.com/cosmos/cosmos-sdk/simapp/params" -// "github.com/cosmos/cosmos-sdk/store" -// storetypes "github.com/cosmos/cosmos-sdk/store/types" -// sdk "github.com/cosmos/cosmos-sdk/types" -// paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" -// paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" -// "github.com/stretchr/testify/assert" -// "github.com/stretchr/testify/require" -// "github.com/tendermint/tendermint/libs/log" -// tmproto "github.com/tendermint/tendermint/proto/tendermint/types" -// dbm "github.com/tendermint/tm-db" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" -// "github.com/cosmos/gaia/v11/x/globalfee/types" -// ) + dbm "github.com/cometbft/cometbft-db" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" -// func TestDefaultGenesis(t *testing.T) { -// encCfg := simapp.MakeTestEncodingConfig() -// gotJSON := AppModuleBasic{}.DefaultGenesis(encCfg.Marshaler) -// assert.JSONEq(t, -// `{"params":{"minimum_gas_prices":[],"bypass_min_fee_msg_types":["/ibc.core.channel.v1.MsgRecvPacket","/ibc.core.channel.v1.MsgAcknowledgement","/ibc.core.client.v1.MsgUpdateClient","/ibc.core.channel.v1.MsgTimeout","/ibc.core.channel.v1.MsgTimeoutOnClose"], "max_total_bypass_min_fee_msg_gas_usage":"1000000"}}`, -// string(gotJSON), string(gotJSON)) -// } + "github.com/cometbft/cometbft/libs/log" + "github.com/cosmos/cosmos-sdk/store" + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" -// func TestValidateGenesis(t *testing.T) { -// encCfg := simapp.MakeTestEncodingConfig() -// specs := map[string]struct { -// src string -// expErr bool -// }{ -// "all good": { -// src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"1"}], "bypass_min_fee_msg_types":["/ibc.core.channel.v1.MsgRecvPacket"]}}`, -// expErr: false, -// }, -// "empty minimum": { -// src: `{"params":{"minimum_gas_prices":[], "bypass_min_fee_msg_types":[]}}`, -// expErr: false, -// }, -// "minimum and bypass not set": { -// src: `{"params":{}}`, -// expErr: false, -// }, -// "minimum not set": { -// src: `{"params":{"bypass_min_fee_msg_types":[]}}`, -// expErr: false, -// }, -// "bypass not set": { -// src: `{"params":{"minimum_gas_prices":[]}}`, -// expErr: false, -// }, -// "zero amount allowed": { -// src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"0"}]}}`, -// expErr: false, -// }, -// "duplicate denoms not allowed": { -// src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"1"},{"denom":"ALX", "amount":"2"}]}}`, -// expErr: true, -// }, -// "negative amounts not allowed": { -// src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"-1"}]}}`, -// expErr: true, -// }, -// "denom must be sorted": { -// src: `{"params":{"minimum_gas_prices":[{"denom":"ZLX", "amount":"1"},{"denom":"ALX", "amount":"2"}]}}`, -// expErr: true, -// }, -// "empty bypass msg types not allowed": { -// src: `{"params":{"bypass_min_fee_msg_types":[""]}}`, -// expErr: true, -// }, -// "sorted denoms is allowed": { -// src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"1"},{"denom":"ZLX", "amount":"2"}]}}`, -// expErr: false, -// }, -// } -// for name, spec := range specs { -// t.Run(name, func(t *testing.T) { -// gotErr := AppModuleBasic{}.ValidateGenesis(encCfg.Marshaler, nil, []byte(spec.src)) -// if spec.expErr { -// require.Error(t, gotErr) -// return -// } -// require.NoError(t, gotErr) -// }) -// } -// } + gaiaparams "github.com/cosmos/gaia/v11/app/params" + "github.com/cosmos/gaia/v11/x/globalfee/types" -// func TestInitExportGenesis(t *testing.T) { -// specs := map[string]struct { -// src string -// exp types.GenesisState -// }{ -// "single fee": { -// src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"1"}], "bypass_min_fee_msg_types":["/ibc.core.channel.v1.MsgRecvPacket"]}}`, -// exp: types.GenesisState{ -// Params: types.Params{ -// MinimumGasPrices: sdk.NewDecCoins(sdk.NewDecCoin("ALX", sdk.NewInt(1))), -// BypassMinFeeMsgTypes: []string{"/ibc.core.channel.v1.MsgRecvPacket"}, -// }, -// }, -// }, -// "multiple fee options": { -// src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"1"}, {"denom":"BLX", "amount":"0.001"}], "bypass_min_fee_msg_types":["/ibc.core.channel.v1.MsgRecvPacket","/ibc.core.channel.v1.MsgTimeoutOnClose"]}}`, -// exp: types.GenesisState{ -// Params: types.Params{ -// MinimumGasPrices: sdk.NewDecCoins(sdk.NewDecCoin("ALX", sdk.NewInt(1)), -// sdk.NewDecCoinFromDec("BLX", sdk.NewDecWithPrec(1, 3))), -// BypassMinFeeMsgTypes: []string{"/ibc.core.channel.v1.MsgRecvPacket", "/ibc.core.channel.v1.MsgTimeoutOnClose"}, -// }, -// }, -// }, -// "no fee set": { -// src: `{"params":{}}`, -// exp: types.GenesisState{ -// Params: types.Params{ -// MinimumGasPrices: sdk.DecCoins{}, -// BypassMinFeeMsgTypes: []string{}, -// }, -// }, -// }, -// } -// for name, spec := range specs { -// t.Run(name, func(t *testing.T) { -// ctx, encCfg, subspace := setupTestStore(t) -// m := NewAppModule(subspace) -// m.InitGenesis(ctx, encCfg.Marshaler, []byte(spec.src)) -// gotJSON := m.ExportGenesis(ctx, encCfg.Marshaler) -// var got types.GenesisState -// require.NoError(t, encCfg.Marshaler.UnmarshalJSON(gotJSON, &got)) -// assert.Equal(t, spec.exp, got, string(gotJSON)) -// }) -// } -// } + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) -// func setupTestStore(t *testing.T) (sdk.Context, simappparams.EncodingConfig, paramstypes.Subspace) { -// t.Helper() -// db := dbm.NewMemDB() -// ms := store.NewCommitMultiStore(db) -// encCfg := simapp.MakeTestEncodingConfig() -// keyParams := sdk.NewKVStoreKey(paramstypes.StoreKey) -// tkeyParams := sdk.NewTransientStoreKey(paramstypes.TStoreKey) -// ms.MountStoreWithDB(keyParams, storetypes.StoreTypeIAVL, db) -// ms.MountStoreWithDB(tkeyParams, storetypes.StoreTypeTransient, db) -// require.NoError(t, ms.LoadLatestVersion()) +func TestDefaultGenesis(t *testing.T) { + encCfg := gaiaparams.MakeEncodingConfig() + gotJSON := AppModuleBasic{}.DefaultGenesis(encCfg.Marshaler) + assert.JSONEq(t, + `{"params":{"minimum_gas_prices":[],"bypass_min_fee_msg_types":["/ibc.core.channel.v1.MsgRecvPacket","/ibc.core.channel.v1.MsgAcknowledgement","/ibc.core.client.v1.MsgUpdateClient","/ibc.core.channel.v1.MsgTimeout","/ibc.core.channel.v1.MsgTimeoutOnClose"], "max_total_bypass_min_fee_msg_gas_usage":"1000000"}}`, + string(gotJSON), string(gotJSON)) +} -// paramsKeeper := paramskeeper.NewKeeper(encCfg.Marshaler, encCfg.Amino, keyParams, tkeyParams) +func TestValidateGenesis(t *testing.T) { + encCfg := gaiaparams.MakeEncodingConfig() + specs := map[string]struct { + src string + expErr bool + }{ + "all good": { + src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"1"}], "bypass_min_fee_msg_types":["/ibc.core.channel.v1.MsgRecvPacket"]}}`, + expErr: false, + }, + "empty minimum": { + src: `{"params":{"minimum_gas_prices":[], "bypass_min_fee_msg_types":[]}}`, + expErr: false, + }, + "minimum and bypass not set": { + src: `{"params":{}}`, + expErr: false, + }, + "minimum not set": { + src: `{"params":{"bypass_min_fee_msg_types":[]}}`, + expErr: false, + }, + "bypass not set": { + src: `{"params":{"minimum_gas_prices":[]}}`, + expErr: false, + }, + "zero amount allowed": { + src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"0"}]}}`, + expErr: false, + }, + "duplicate denoms not allowed": { + src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"1"},{"denom":"ALX", "amount":"2"}]}}`, + expErr: true, + }, + "negative amounts not allowed": { + src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"-1"}]}}`, + expErr: true, + }, + "denom must be sorted": { + src: `{"params":{"minimum_gas_prices":[{"denom":"ZLX", "amount":"1"},{"denom":"ALX", "amount":"2"}]}}`, + expErr: true, + }, + "empty bypass msg types not allowed": { + src: `{"params":{"bypass_min_fee_msg_types":[""]}}`, + expErr: true, + }, + "sorted denoms is allowed": { + src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"1"},{"denom":"ZLX", "amount":"2"}]}}`, + expErr: false, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + gotErr := AppModuleBasic{}.ValidateGenesis(encCfg.Marshaler, nil, []byte(spec.src)) + if spec.expErr { + require.Error(t, gotErr) + return + } + require.NoError(t, gotErr) + }) + } +} -// ctx := sdk.NewContext(ms, tmproto.Header{ -// Height: 1234567, -// Time: time.Date(2020, time.April, 22, 12, 0, 0, 0, time.UTC), -// }, false, log.NewNopLogger()) +func TestInitExportGenesis(t *testing.T) { + specs := map[string]struct { + src string + exp types.GenesisState + }{ + "single fee": { + src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"1"}], "bypass_min_fee_msg_types":["/ibc.core.channel.v1.MsgRecvPacket"]}}`, + exp: types.GenesisState{ + Params: types.Params{ + MinimumGasPrices: sdk.NewDecCoins(sdk.NewDecCoin("ALX", sdk.NewInt(1))), + BypassMinFeeMsgTypes: []string{"/ibc.core.channel.v1.MsgRecvPacket"}, + }, + }, + }, + "multiple fee options": { + src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"1"}, {"denom":"BLX", "amount":"0.001"}], "bypass_min_fee_msg_types":["/ibc.core.channel.v1.MsgRecvPacket","/ibc.core.channel.v1.MsgTimeoutOnClose"]}}`, + exp: types.GenesisState{ + Params: types.Params{ + MinimumGasPrices: sdk.NewDecCoins(sdk.NewDecCoin("ALX", sdk.NewInt(1)), + sdk.NewDecCoinFromDec("BLX", sdk.NewDecWithPrec(1, 3))), + BypassMinFeeMsgTypes: []string{"/ibc.core.channel.v1.MsgRecvPacket", "/ibc.core.channel.v1.MsgTimeoutOnClose"}, + }, + }, + }, + "no fee set": { + src: `{"params":{}}`, + exp: types.GenesisState{ + Params: types.Params{ + MinimumGasPrices: sdk.DecCoins{}, + BypassMinFeeMsgTypes: []string{}, + }, + }, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + ctx, encCfg, subspace := setupTestStore(t) + m := NewAppModule(subspace) + m.InitGenesis(ctx, encCfg.Marshaler, []byte(spec.src)) + gotJSON := m.ExportGenesis(ctx, encCfg.Marshaler) + var got types.GenesisState + require.NoError(t, encCfg.Marshaler.UnmarshalJSON(gotJSON, &got)) + assert.Equal(t, spec.exp, got, string(gotJSON)) + }) + } +} -// subspace := paramsKeeper.Subspace(ModuleName).WithKeyTable(types.ParamKeyTable()) -// return ctx, encCfg, subspace -// } +func setupTestStore(t *testing.T) (sdk.Context, gaiaparams.EncodingConfig, paramstypes.Subspace) { + t.Helper() + db := dbm.NewMemDB() + ms := store.NewCommitMultiStore(db) + encCfg := gaiaparams.MakeEncodingConfig() + keyParams := sdk.NewKVStoreKey(paramstypes.StoreKey) + tkeyParams := sdk.NewTransientStoreKey(paramstypes.TStoreKey) + ms.MountStoreWithDB(keyParams, storetypes.StoreTypeIAVL, db) + ms.MountStoreWithDB(tkeyParams, storetypes.StoreTypeTransient, db) + require.NoError(t, ms.LoadLatestVersion()) + + ctx := sdk.NewContext(ms, tmproto.Header{ + Height: 1234567, + Time: time.Date(2020, time.April, 22, 12, 0, 0, 0, time.UTC), + }, false, log.NewNopLogger()) + + subspace := paramtypes.NewSubspace(encCfg.Marshaler, + encCfg.Amino, + keyParams, + tkeyParams, + paramtypes.ModuleName, + ) + return ctx, encCfg, subspace +} From 1d950cd383ef32846d000e36a2e53ec2ca8258fc Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Tue, 26 Sep 2023 11:20:28 +0200 Subject: [PATCH 11/11] nit --- x/globalfee/genesis_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/x/globalfee/genesis_test.go b/x/globalfee/genesis_test.go index 7cb6f974856..073e355ae2a 100644 --- a/x/globalfee/genesis_test.go +++ b/x/globalfee/genesis_test.go @@ -13,7 +13,6 @@ import ( "github.com/cometbft/cometbft/libs/log" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" gaiaparams "github.com/cosmos/gaia/v11/app/params" "github.com/cosmos/gaia/v11/x/globalfee/types" @@ -156,11 +155,11 @@ func setupTestStore(t *testing.T) (sdk.Context, gaiaparams.EncodingConfig, param Time: time.Date(2020, time.April, 22, 12, 0, 0, 0, time.UTC), }, false, log.NewNopLogger()) - subspace := paramtypes.NewSubspace(encCfg.Marshaler, + subspace := paramstypes.NewSubspace(encCfg.Marshaler, encCfg.Amino, keyParams, tkeyParams, - paramtypes.ModuleName, + paramstypes.ModuleName, ) return ctx, encCfg, subspace }