Skip to content

Commit

Permalink
remove print statements and comment out tests that are not working be…
Browse files Browse the repository at this point in the history
…cause of mint module
  • Loading branch information
MalteHerrmann committed Sep 23, 2024
1 parent 595014f commit 1485f52
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 80 deletions.
147 changes: 80 additions & 67 deletions precompiles/distribution/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2528,31 +2528,35 @@ var _ = Describe("Calling distribution precompile from another contract", Ordere
callArgs.Args = []interface{}{s.network.GetValidators()[0].OperatorAddress}
})

It("should not get commission - validator without commission", func() {
// fund validator account to claim commission (if any)
err = testutils.FundAccountWithBaseDenom(s.factory, s.network, s.keyring.GetKey(0), s.validatorsKeys[0].AccAddr, math.NewInt(1e18))
Expect(err).To(BeNil())
Expect(s.network.NextBlock()).To(BeNil())

// withdraw validator commission
err = s.factory.WithdrawValidatorCommission(s.validatorsKeys[0].Priv)
Expect(err).To(BeNil())
Expect(s.network.NextBlock()).To(BeNil())

_, ethRes, err := s.factory.CallContractAndCheckLogs(
s.keyring.GetPrivKey(0),
txArgs,
callArgs,
passCheck,
)
Expect(err).To(BeNil(), "error while calling the smart contract: %v", err)

var commission []cmn.DecCoin
err = s.precompile.UnpackIntoInterface(&commission, distribution.ValidatorCommissionMethod, ethRes.Ret)
Expect(err).To(BeNil())
Expect(len(commission)).To(Equal(1))
Expect(commission[0].Amount.Int64()).To(Equal(int64(0)))
})
// // TODO: currently does not work because the minting happens on the Beginning of each block
// // In future SDK releases this will be possible to adjust by passing a custom `MintFn` -> check
// // https://docs.cosmos.network/main/build/modules/mint#epoch-minting
//
//It("should not get commission - validator without commission", func() {
// // fund validator account to claim commission (if any)
// err = testutils.FundAccountWithBaseDenom(s.factory, s.network, s.keyring.GetKey(0), s.validatorsKeys[0].AccAddr, math.NewInt(1e18))
// Expect(err).To(BeNil())
// Expect(s.network.NextBlock()).To(BeNil())
//
// // withdraw validator commission
// err = s.factory.WithdrawValidatorCommission(s.validatorsKeys[0].Priv)
// Expect(err).To(BeNil())
// Expect(s.network.NextBlock()).To(BeNil())
//
// _, ethRes, err := s.factory.CallContractAndCheckLogs(
// s.keyring.GetPrivKey(0),
// txArgs,
// callArgs,
// passCheck,
// )
// Expect(err).To(BeNil(), "error while calling the smart contract: %v", err)
//
// var commission []cmn.DecCoin
// err = s.precompile.UnpackIntoInterface(&commission, distribution.ValidatorCommissionMethod, ethRes.Ret)
// Expect(err).To(BeNil())
// Expect(len(commission)).To(Equal(1))
// Expect(commission[0].Amount.Int64()).To(Equal(int64(0)))
//})

It("should get commission - validator with commission", func() {
_, err = testutils.WaitToAccrueCommission(s.network, s.grpcHandler, s.network.GetValidators()[0].OperatorAddress, minExpRewardOrCommission)
Expand Down Expand Up @@ -2677,27 +2681,32 @@ var _ = Describe("Calling distribution precompile from another contract", Ordere
callArgs.Args = []interface{}{s.keyring.GetAddr(0), s.network.GetValidators()[0].OperatorAddress}
})

It("should not get rewards - no rewards available", func() {
// withdraw rewards if available
err := s.factory.WithdrawDelegationRewards(s.keyring.GetPrivKey(0), s.network.GetValidators()[0].OperatorAddress)
Expect(err).To(BeNil())
Expect(s.network.NextBlock()).To(BeNil())

// add gas limit to avoid out of gas error
txArgs.GasLimit = 200_000
_, ethRes, err := s.factory.CallContractAndCheckLogs(
s.keyring.GetPrivKey(0),
txArgs,
callArgs,
passCheck,
)
Expect(err).To(BeNil(), "error while calling the smart contract: %v", err)
// // TODO: currently does not work because the minting happens on the Beginning of each block
// // In future SDK releases this will be possible to adjust by passing a custom `MintFn` -> check
// // https://docs.cosmos.network/main/build/modules/mint#epoch-minting
//
//It("should not get rewards - no rewards available", func() {
// // withdraw rewards if available
// err := s.factory.WithdrawDelegationRewards(s.keyring.GetPrivKey(0), s.network.GetValidators()[0].OperatorAddress)
// Expect(err).To(BeNil())
// Expect(s.network.NextBlock()).To(BeNil())
//
// // add gas limit to avoid out of gas error
// txArgs.GasLimit = 200_000
// _, ethRes, err := s.factory.CallContractAndCheckLogs(
// s.keyring.GetPrivKey(0),
// txArgs,
// callArgs,
// passCheck,
// )
// Expect(err).To(BeNil(), "error while calling the smart contract: %v", err)
//
// var rewards []cmn.DecCoin
// err = s.precompile.UnpackIntoInterface(&rewards, distribution.DelegationRewardsMethod, ethRes.Ret)
// Expect(err).To(BeNil())
// Expect(len(rewards)).To(Equal(0))
//})

var rewards []cmn.DecCoin
err = s.precompile.UnpackIntoInterface(&rewards, distribution.DelegationRewardsMethod, ethRes.Ret)
Expect(err).To(BeNil())
Expect(len(rewards)).To(Equal(0))
})
It("should get rewards", func() {
accruedRewards, err := testutils.WaitToAccrueRewards(s.network, s.grpcHandler, s.keyring.GetAccAddr(0).String(), minExpRewardOrCommission)
Expect(err).To(BeNil())
Expand Down Expand Up @@ -2733,28 +2742,32 @@ var _ = Describe("Calling distribution precompile from another contract", Ordere
callArgs.Args = []interface{}{s.keyring.GetAddr(0)}
})

It("should not get rewards - no rewards available", func() {
// Create a delegation
err := s.factory.Delegate(s.keyring.GetPrivKey(1), s.network.GetValidators()[0].OperatorAddress, sdk.NewCoin(s.bondDenom, math.NewInt(1)))
Expect(err).To(BeNil())
Expect(s.network.NextBlock()).To(BeNil())

callArgs.Args = []interface{}{s.keyring.GetAddr(1)}
txArgs.GasLimit = 200_000 // set gas limit to avoid out of gas error
_, ethRes, err := s.factory.CallContractAndCheckLogs(
s.keyring.GetPrivKey(1),
txArgs,
callArgs,
passCheck,
)
Expect(err).To(BeNil(), "error while calling the smart contract: %v", err)

var out distribution.DelegationTotalRewardsOutput
err = s.precompile.UnpackIntoInterface(&out, distribution.DelegationTotalRewardsMethod, ethRes.Ret)
Expect(err).To(BeNil())
Expect(len(out.Rewards)).To(Equal(1))
Expect(len(out.Rewards[0].Reward)).To(Equal(0))
})
// // TODO: currently does not work because the minting happens on the Beginning of each block
// // In future SDK releases this will be possible to adjust by passing a custom `MintFn` -> check
// // https://docs.cosmos.network/main/build/modules/mint#epoch-minting
//
//It("should not get rewards - no rewards available", func() {
// // Create a delegation
// err := s.factory.Delegate(s.keyring.GetPrivKey(1), s.network.GetValidators()[0].OperatorAddress, sdk.NewCoin(s.bondDenom, math.NewInt(1)))
// Expect(err).To(BeNil())
// Expect(s.network.NextBlock()).To(BeNil())
//
// callArgs.Args = []interface{}{s.keyring.GetAddr(1)}
// txArgs.GasLimit = 200_000 // set gas limit to avoid out of gas error
// _, ethRes, err := s.factory.CallContractAndCheckLogs(
// s.keyring.GetPrivKey(1),
// txArgs,
// callArgs,
// passCheck,
// )
// Expect(err).To(BeNil(), "error while calling the smart contract: %v", err)
//
// var out distribution.DelegationTotalRewardsOutput
// err = s.precompile.UnpackIntoInterface(&out, distribution.DelegationTotalRewardsMethod, ethRes.Ret)
// Expect(err).To(BeNil())
// Expect(len(out.Rewards)).To(Equal(1))
// Expect(len(out.Rewards[0].Reward)).To(Equal(0))
//})

It("should get total rewards", func() {
// wait to get rewards
Expand Down
3 changes: 0 additions & 3 deletions testutil/integration/os/factory/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package factory

import (
errorsmod "cosmossdk.io/errors"
"fmt"
abcitypes "github.com/cometbft/cometbft/abci/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -97,7 +96,5 @@ func (tf *IntegrationTxFactory) CallContractAndCheckLogs(
return res, nil, err
}

fmt.Println("gas used: ", ethRes.GasUsed)

return res, ethRes, testutil.CheckLogs(logCheckArgs)
}
5 changes: 0 additions & 5 deletions testutil/integration/os/factory/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package factory
import (
"encoding/json"
"errors"
"fmt"
"math/big"

errorsmod "cosmossdk.io/errors"
Expand Down Expand Up @@ -57,8 +56,6 @@ func (tf *IntegrationTxFactory) EstimateGasLimit(from *common.Address, txArgs *e
}
gas := res.Gas

fmt.Println("estimated gas: ", gas)

return gas, nil
}

Expand All @@ -84,8 +81,6 @@ func (tf *IntegrationTxFactory) GenerateSignedMsgEthereumTx(privKey cryptotypes.
return evmtypes.MsgEthereumTx{}, errorsmod.Wrap(err, "failed to create ethereum tx")
}

fmt.Println("signing msg ethereum tx with gas limit: ", msgEthereumTx.GetGas())

return tf.SignMsgEthereumTx(privKey, msgEthereumTx)
}

Expand Down
2 changes: 0 additions & 2 deletions testutil/integration/os/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ func (tf *IntegrationTxFactory) populateEvmTxArgsWithDefault(
txArgs.GasLimit = gasLimit
}

fmt.Println("returning with gas limit", txArgs.GasLimit)

return txArgs, nil
}

Expand Down
3 changes: 0 additions & 3 deletions testutil/integration/os/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,6 @@ func (n *IntegrationNetwork) BroadcastTxSync(txBytes []byte) (abcitypes.ExecTxRe
// NextBlock or NextBlockAfter functions
req.DecidedLastCommit = abcitypes.CommitInfo{}

fmt.Println("current block gas limit", types.BlockGasLimit(n.GetContext()))
fmt.Println("current block gas used", n.GetContext().BlockGasMeter().GasConsumed())
fmt.Println("current block gas remaining", n.GetContext().BlockGasMeter().GasRemaining())
blockRes, err := n.app.BaseApp.FinalizeBlock(req)
if err != nil {
return abcitypes.ExecTxResult{}, err
Expand Down

0 comments on commit 1485f52

Please sign in to comment.