Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
aljo242 committed Jul 11, 2024
1 parent c566b3c commit 0f371c6
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 61 deletions.
21 changes: 14 additions & 7 deletions x/feemarket/ante/suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,14 @@ func (s *TestSuite) SetupHandlers(mock bool) {

// TestCase represents a test case used in test tables.
type TestCase struct {
Name string
Malleate func(*TestSuite) TestCaseArgs
RunAnte bool
RunPost bool
Simulate bool
ExpPass bool
ExpErr error
Name string
Malleate func(*TestSuite) TestCaseArgs
RunAnte bool
RunPost bool
Simulate bool
ExpPass bool
ExpErr error
ExpectConsumedGas uint64
}

type TestCaseArgs struct {
Expand Down Expand Up @@ -185,6 +186,7 @@ func (s *TestSuite) RunTestCase(t *testing.T, tc TestCase, args TestCaseArgs) {

if tc.RunPost {
newCtx, handleErr = s.PostHandler(s.Ctx, tx, tc.Simulate, true)

}

if tc.ExpPass {
Expand All @@ -193,6 +195,11 @@ func (s *TestSuite) RunTestCase(t *testing.T, tc TestCase, args TestCaseArgs) {
require.NotNil(t, newCtx)

s.Ctx = newCtx
if tc.RunPost {
consumedGas := newCtx.GasMeter().GasConsumed()
require.Equal(t, tc.ExpectConsumedGas, consumedGas)
}

} else {
switch {
case txErr != nil:
Expand Down
118 changes: 64 additions & 54 deletions x/feemarket/post/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ func TestSendTip(t *testing.T) {
func TestPostHandle(t *testing.T) {
// Same data for every test case
const (
baseDenom = "stake"
resolvableDenom = "atom"
baseDenom = "stake"
resolvableDenom = "atom"
expectedConsumedGas = 33339
gasLimit = expectedConsumedGas
)

// exact cost of transaction
gasLimit := uint64(27284)
validFeeAmount := types.DefaultMinBaseGasPrice.MulInt64(int64(gasLimit))
validFeeAmountWithTip := validFeeAmount.Add(math.LegacyNewDec(100))
validFee := sdk.NewCoins(sdk.NewCoin(baseDenom, validFeeAmount.TruncateInt()))
Expand Down Expand Up @@ -204,11 +204,12 @@ func TestPostHandle(t *testing.T) {
FeeAmount: validFee,
}
},
RunAnte: true,
RunPost: true,
Simulate: true,
ExpPass: true,
ExpErr: nil,
RunAnte: true,
RunPost: true,
Simulate: true,
ExpPass: true,
ExpErr: nil,
ExpectConsumedGas: expectedConsumedGas,
},
{
Name: "signer has enough funds, should pass, no tip",
Expand All @@ -223,11 +224,12 @@ func TestPostHandle(t *testing.T) {
FeeAmount: validFee,
}
},
RunAnte: true,
RunPost: true,
Simulate: false,
ExpPass: true,
ExpErr: nil,
RunAnte: true,
RunPost: true,
Simulate: false,
ExpPass: true,
ExpErr: nil,
ExpectConsumedGas: expectedConsumedGas,
},
{
Name: "signer has enough funds, should pass with tip",
Expand All @@ -242,11 +244,12 @@ func TestPostHandle(t *testing.T) {
FeeAmount: validFeeWithTip,
}
},
RunAnte: true,
RunPost: true,
Simulate: false,
ExpPass: true,
ExpErr: nil,
RunAnte: true,
RunPost: true,
Simulate: false,
ExpPass: true,
ExpErr: nil,
ExpectConsumedGas: expectedConsumedGas,
},
{
Name: "signer has enough funds, should pass with tip - simulate",
Expand All @@ -261,11 +264,12 @@ func TestPostHandle(t *testing.T) {
FeeAmount: validFeeWithTip,
}
},
RunAnte: true,
RunPost: true,
Simulate: true,
ExpPass: true,
ExpErr: nil,
RunAnte: true,
RunPost: true,
Simulate: true,
ExpPass: true,
ExpErr: nil,
ExpectConsumedGas: expectedConsumedGas,
},
{
Name: "signer has enough funds, should pass, no tip - resolvable denom",
Expand All @@ -280,11 +284,12 @@ func TestPostHandle(t *testing.T) {
FeeAmount: validResolvableFee,
}
},
RunAnte: true,
RunPost: true,
Simulate: false,
ExpPass: true,
ExpErr: nil,
RunAnte: true,
RunPost: true,
Simulate: false,
ExpPass: true,
ExpErr: nil,
ExpectConsumedGas: expectedConsumedGas,
},
{
Name: "signer has enough funds, should pass, no tip - resolvable denom - simulate",
Expand All @@ -299,11 +304,12 @@ func TestPostHandle(t *testing.T) {
FeeAmount: validResolvableFee,
}
},
RunAnte: true,
RunPost: true,
Simulate: true,
ExpPass: true,
ExpErr: nil,
RunAnte: true,
RunPost: true,
Simulate: true,
ExpPass: true,
ExpErr: nil,
ExpectConsumedGas: expectedConsumedGas,
},
{
Name: "signer has enough funds, should pass with tip - resolvable denom",
Expand All @@ -318,11 +324,12 @@ func TestPostHandle(t *testing.T) {
FeeAmount: validResolvableFeeWithTip,
}
},
RunAnte: true,
RunPost: true,
Simulate: false,
ExpPass: true,
ExpErr: nil,
RunAnte: true,
RunPost: true,
Simulate: false,
ExpPass: true,
ExpErr: nil,
ExpectConsumedGas: expectedConsumedGas,
},
{
Name: "signer has enough funds, should pass with tip - resolvable denom - simulate",
Expand All @@ -337,11 +344,12 @@ func TestPostHandle(t *testing.T) {
FeeAmount: validResolvableFeeWithTip,
}
},
RunAnte: true,
RunPost: true,
Simulate: true,
ExpPass: true,
ExpErr: nil,
RunAnte: true,
RunPost: true,
Simulate: true,
ExpPass: true,
ExpErr: nil,
ExpectConsumedGas: expectedConsumedGas,
},
{
Name: "0 gas given should pass in simulate - no fee",
Expand All @@ -354,11 +362,12 @@ func TestPostHandle(t *testing.T) {
FeeAmount: nil,
}
},
RunAnte: true,
RunPost: false,
Simulate: true,
ExpPass: true,
ExpErr: nil,
RunAnte: true,
RunPost: false,
Simulate: true,
ExpPass: true,
ExpErr: nil,
ExpectConsumedGas: expectedConsumedGas,
},
{
Name: "0 gas given should pass in simulate - fee",
Expand All @@ -371,11 +380,12 @@ func TestPostHandle(t *testing.T) {
FeeAmount: validFee,
}
},
RunAnte: true,
RunPost: false,
Simulate: true,
ExpPass: true,
ExpErr: nil,
RunAnte: true,
RunPost: false,
Simulate: true,
ExpPass: true,
ExpErr: nil,
ExpectConsumedGas: expectedConsumedGas,
},
{
Name: "no fee - fail",
Expand Down

0 comments on commit 0f371c6

Please sign in to comment.