From d49043abfd2853a6a6ade6dfa077c2dc7050223d Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Tue, 5 Mar 2024 17:23:43 -0600 Subject: [PATCH] WIP - fix integration tests --- integration_tests/cellarfees_test.go | 118 +-------------------------- integration_tests/setup_test.go | 17 ++-- 2 files changed, 9 insertions(+), 126 deletions(-) diff --git a/integration_tests/cellarfees_test.go b/integration_tests/cellarfees_test.go index 308d921c..508378dc 100644 --- a/integration_tests/cellarfees_test.go +++ b/integration_tests/cellarfees_test.go @@ -8,11 +8,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - "github.com/ethereum/go-ethereum" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" auctiontypes "github.com/peggyjv/sommelier/v7/x/auction/types" - cellarfeestypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + cellarfeestypesv2 "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" corktypes "github.com/peggyjv/sommelier/v7/x/cork/types/v2" ) @@ -31,7 +29,7 @@ func (s *IntegrationTestSuite) TestCellarFees() { auctionQueryClient := auctiontypes.NewQueryClient(clientCtx) bankQueryClient := banktypes.NewQueryClient(clientCtx) - cellarfeesQueryClient := cellarfeestypes.NewQueryClient(clientCtx) + cellarfeesQueryClient := cellarfeestypesv2.NewQueryClient(clientCtx) corkQueryClient := corktypes.NewQueryClient(clientCtx) distQueryClient := disttypes.NewQueryClient(clientCtx) @@ -52,7 +50,7 @@ func (s *IntegrationTestSuite) TestCellarFees() { ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) defer cancel() - acctsRes, err := cellarfeesQueryClient.QueryModuleAccounts(ctx, &cellarfeestypes.QueryModuleAccountsRequest{}) + acctsRes, err := cellarfeesQueryClient.QueryModuleAccounts(ctx, &cellarfeestypesv2.QueryModuleAccountsRequest{}) s.Require().NoError(err, "Failed to query module accounts") feesAddress := acctsRes.FeesAddress @@ -63,116 +61,6 @@ func (s *IntegrationTestSuite) TestCellarFees() { }) s.Require().NoError(err, "Failed to query fee balance of denom %s", alphaERC20Contract.Hex()) s.Require().Zero(balanceRes.Balance.Amount.Uint64()) - balanceRes, err = bankQueryClient.Balance(ctx, &banktypes.QueryBalanceRequest{ - Address: feesAddress, - Denom: fmt.Sprintf("gravity%s", betaERC20Contract.Hex()), - }) - s.Require().NoError(err, "Failed to query fee balance of denom %s", betaERC20Contract.Hex()) - s.Require().Zero(balanceRes.Balance.Amount.Uint64()) - - s.T().Logf("Approving Gravity to spend Alpha ERC20") - approveData := PackApproveERC20(gravityContract) - err = SendEthTransaction(ethClient, &val.ethereumKey, alphaERC20Contract, approveData) - s.Require().NoError(err, "Error approving spending ALPHA balance for the gravity contract on behalf of the first validator") - - s.T().Logf("Approving Gravity to spend Beta ERC20") - approveData = PackApproveERC20(gravityContract) - err = SendEthTransaction(ethClient, &val.ethereumKey, betaERC20Contract, approveData) - s.Require().NoError(err, "Error approving spending BETA balance for the gravity contract on behalf of the first validator") - - s.T().Logf("Waiting for allowance confirmations..") - data := PackAllowance(common.HexToAddress(ethereumSender), gravityContract) - s.Require().Eventually(func() bool { - res, _ := ethClient.CallContract(context.Background(), ethereum.CallMsg{ - From: common.HexToAddress(ethereumSender), - To: &alphaERC20Contract, - Gas: 0, - Data: data, - }, nil) - - allowance := UnpackEthUInt(res).BigInt() - s.T().Logf("Allowance: %v", allowance) - - return sdk.NewIntFromBigInt(allowance).GT(sdk.ZeroInt()) - }, time.Second*10, time.Second, "AlphaERC20 allowance not found") - - data = PackAllowance(common.HexToAddress(ethereumSender), gravityContract) - s.Require().Eventually(func() bool { - res, _ := ethClient.CallContract(context.Background(), ethereum.CallMsg{ - From: common.HexToAddress(ethereumSender), - To: &betaERC20Contract, - Gas: 0, - Data: data, - }, nil) - - allowance := UnpackEthUInt(res).BigInt() - s.T().Logf("Allowance: %v", allowance) - - return sdk.NewIntFromBigInt(allowance).GT(sdk.ZeroInt()) - }, time.Second*10, time.Second, "BetaERC20 allowance not found") - - s.T().Log("Sending ALPHA fees to cellarfees module account") - acc, err := sdk.AccAddressFromBech32(feesAddress) - s.Require().NoError(err, "Failed to derive fees account address from bech32 string: %s", feesAddress) - sendData := PackSendToCosmos(alphaERC20Contract, acc, sdk.NewInt(50000)) - err = SendEthTransaction(ethClient, &val.ethereumKey, gravityContract, sendData) - s.Require().NoError(err, "Failed to send fees transaction to Cosmos") - - s.T().Log("Sending BETA fees to cellarfees module account") - acc, err = sdk.AccAddressFromBech32(feesAddress) - s.Require().NoError(err, "Failed to derive fees account address from bech32 string: %s", feesAddress) - sendData = PackSendToCosmos(betaERC20Contract, acc, sdk.NewInt(20000)) - err = SendEthTransaction(ethClient, &val.ethereumKey, gravityContract, sendData) - s.Require().NoError(err, "Failed to send fees transaction to Cosmos") - - s.T().Log("Waiting for fees to be received...") - s.Require().Eventually(func() bool { - res, err := bankQueryClient.Balance(context.Background(), - &banktypes.QueryBalanceRequest{ - Address: feesAddress, - Denom: alphaFeeDenom, - }) - s.Require().NoError(err) - s.T().Logf("fee balance: %s", res.Balance) - - return res.Balance.Amount.GT(sdk.ZeroInt()) - }, time.Second*60, time.Second*6, "ALPHA Fees never received by cellarfees account") - - s.Require().Eventually(func() bool { - res, err := bankQueryClient.Balance(context.Background(), - &banktypes.QueryBalanceRequest{ - Address: feesAddress, - Denom: betaFeeDenom, - }) - s.Require().NoError(err) - s.T().Logf("fee balance: %s", res.Balance) - - return res.Balance.Amount.GT(sdk.ZeroInt()) - }, time.Second*60, time.Second*6, "BETA Fees never received by cellarfees account") - - s.T().Log("Fees received! Confirming no auction gets started yet...") - for i := 0; i < 10; i++ { - res, _ := auctionQueryClient.QueryActiveAuctions(ctx, &auctiontypes.QueryActiveAuctionsRequest{}) - if res == nil { - continue - } - - for _, auction := range res.Auctions { - s.Require().NotEqual(auction.StartingTokensForSale.Denom, alphaFeeDenom) - s.Require().NotEqual(auction.StartingTokensForSale.Denom, betaFeeDenom) - } - - time.Sleep(time.Second) - } - - s.T().Log("Sending ERC20 fees a second time") - sendData = PackSendToCosmos(alphaERC20Contract, acc, sdk.NewInt(100000)) - err = SendEthTransaction(ethClient, &val.ethereumKey, gravityContract, sendData) - s.Require().NoError(err, "Failed to send fees transaction to Cosmos") - - sendData = PackSendToCosmos(betaERC20Contract, acc, sdk.NewInt(120000)) - err = SendEthTransaction(ethClient, &val.ethereumKey, gravityContract, sendData) - s.Require().NoError(err, "Failed to send fees transaction to Cosmos") s.T().Log("Waiting for auctions to start") alphaAuctionID, betaAuctionID := uint32(0), uint32(0) diff --git a/integration_tests/setup_test.go b/integration_tests/setup_test.go index 47dac1a0..3f771bda 100644 --- a/integration_tests/setup_test.go +++ b/integration_tests/setup_test.go @@ -22,6 +22,7 @@ import ( auctiontypes "github.com/peggyjv/sommelier/v7/x/auction/types" axelarcorktypes "github.com/peggyjv/sommelier/v7/x/axelarcork/types" cellarfeestypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + cellarfeestypesv2 "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" corktypesunversioned "github.com/peggyjv/sommelier/v7/x/cork/types" corktypes "github.com/peggyjv/sommelier/v7/x/cork/types/v2" pubsubtypes "github.com/peggyjv/sommelier/v7/x/pubsub/types" @@ -69,6 +70,7 @@ pohf4PJrfacqpi7PoXBk -----END CERTIFICATE----- ` axelarSweepDenom = "sweep" + ibcDenom = "ibc/1" ) var ( @@ -79,7 +81,7 @@ var ( gravityContract = common.HexToAddress("0x04C89607413713Ec9775E14b954286519d836FEf") counterContract = common.HexToAddress("0x0000000000000000000000000000000000000000") alphaERC20Contract = common.HexToAddress("0x0000000000000000000000000000000000000000") - betaERC20Contract = common.HexToAddress("0x0000000000000000000000000000000000000000") + alphaERC20Denom = fmt.Sprintf("gravity%s", alphaERC20Contract.Hex()) unusedGenesisContract = common.HexToAddress("0x0000000000000000000000000000000000000001") alphaFeeDenom = "" @@ -408,7 +410,6 @@ func (s *IntegrationTestSuite) initGenesis() { // Add an auction for integration testing of the auction module alphaFeeDenom = fmt.Sprintf("gravity%s", alphaERC20Contract.Hex()) - betaFeeDenom = fmt.Sprintf("gravity%s", betaERC20Contract.Hex()) var auctionGenState auctiontypes.GenesisState s.Require().NoError(cdc.UnmarshalJSON(appGenState[auctiontypes.ModuleName], &auctionGenState)) auctionGenState.TokenPrices = append(auctionGenState.TokenPrices, &auctiontypes.TokenPrice{ @@ -417,12 +418,6 @@ func (s *IntegrationTestSuite) initGenesis() { UsdPrice: sdk.MustNewDecFromStr("1.0"), LastUpdatedBlock: 0, }) - auctionGenState.TokenPrices = append(auctionGenState.TokenPrices, &auctiontypes.TokenPrice{ - Denom: betaFeeDenom, - Exponent: 6, - UsdPrice: sdk.MustNewDecFromStr("5.0"), - LastUpdatedBlock: 0, - }) auctionGenState.TokenPrices = append(auctionGenState.TokenPrices, &auctiontypes.TokenPrice{ Denom: testDenom, Exponent: 6, @@ -463,14 +458,14 @@ func (s *IntegrationTestSuite) initGenesis() { appGenState[axelarcorktypes.ModuleName] = bz // set cellarfees gen state - cellarfeesGenState := cellarfeestypes.DefaultGenesisState() + cellarfeesGenState := cellarfeestypesv2.DefaultGenesisState() s.Require().NoError(cdc.UnmarshalJSON(appGenState[cellarfeestypes.ModuleName], &cellarfeesGenState)) - cellarfeesGenState.Params = cellarfeestypes.Params{ - FeeAccrualAuctionThreshold: 2, + cellarfeesGenState.Params = cellarfeestypesv2.Params{ RewardEmissionPeriod: 100, InitialPriceDecreaseRate: sdk.MustNewDecFromStr("0.05"), PriceDecreaseBlockInterval: uint64(1000), AuctionInterval: 50, + AuctionThresholdUsdValue: sdk.MustNewDecFromStr("100.00"), } bz, err = cdc.MarshalJSON(&cellarfeesGenState) s.Require().NoError(err)