test: Add test for free tx lane (#305)

This commit is contained in:
Eric Warehime 2023-12-19 11:05:19 -08:00 committed by GitHub
parent 25ac0bd7c2
commit 8d514000cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,15 @@ import (
"fmt"
"testing"
"github.com/skip-mev/chaintestutil/network"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
tmcli "github.com/cometbft/cometbft/libs/cli"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
@ -114,3 +123,52 @@ func (s *NetworkTestSuite) QueryBlockSDKLanes() (*blocksdktypes.QueryLanesRespon
client := blocksdktypes.NewQueryClient(cc)
return client.Lanes(context.Background(), &blocksdktypes.QueryLanesRequest{})
}
func (s *NetworkTestSuite) TestFreeTxNoFees() {
val := s.NetworkSuite.Network.Validators[0]
acc := *s.Accounts[0]
cc, closeConn, err := s.NetworkSuite.GetGRPC()
s.Require().NoError(err)
defer closeConn()
// Get original acc balance
bankClient := banktypes.NewQueryClient(cc)
resp, err := bankClient.Balance(context.Background(), &banktypes.QueryBalanceRequest{
Address: acc.Address().String(),
Denom: s.NetworkSuite.Network.Config.BondDenom,
})
require.NoError(s.T(), err)
originalBalance := resp.Balance.Amount
// Send a free tx (delegation)
coin := sdk.NewCoin(s.NetworkSuite.Network.Config.BondDenom, math.NewInt(10))
txBz, err := s.NetworkSuite.CreateTxBytes(
context.Background(),
network.TxGenInfo{
Account: acc,
GasLimit: 999999999,
TimeoutHeight: 999999999,
Fee: sdk.NewCoins(coin),
},
&stakingtypes.MsgDelegate{
DelegatorAddress: acc.Address().String(),
ValidatorAddress: val.ValAddress.String(),
Amount: coin,
},
)
require.NoError(s.T(), err)
bcastResp, err := val.RPCClient.BroadcastTxCommit(context.Background(), txBz)
require.NoError(s.T(), err)
require.Equal(s.T(), uint32(0), bcastResp.CheckTx.Code)
require.Equal(s.T(), uint32(0), bcastResp.TxResult.Code)
// Get updated acc balance
resp, err = bankClient.Balance(context.Background(), &banktypes.QueryBalanceRequest{
Address: acc.Address().String(),
Denom: s.NetworkSuite.Network.Config.BondDenom,
})
require.NoError(s.T(), err)
// Assert update acc balance is equal to original balance less the delegation
require.Equal(s.T(), originalBalance.Sub(coin.Amount), resp.Balance.Amount)
}