-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into refactor/fallback
- Loading branch information
Showing
4 changed files
with
119 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package fuzz_test | ||
|
||
import ( | ||
"math" | ||
"testing" | ||
|
||
sdkmath "cosmossdk.io/math" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/require" | ||
"pgregory.net/rapid" | ||
|
||
"github.com/skip-mev/feemarket/x/feemarket/ante" | ||
) | ||
|
||
type input struct { | ||
payFee sdk.Coin | ||
gasLimit int64 | ||
currentGasPrice sdk.DecCoin | ||
} | ||
|
||
// TestGetTxPriority ensures that tx priority is properly bounded | ||
func TestGetTxPriority(t *testing.T) { | ||
rapid.Check(t, func(t *rapid.T) { | ||
inputs := createRandomInput(t) | ||
|
||
priority := ante.GetTxPriority(inputs.payFee, inputs.gasLimit, inputs.currentGasPrice) | ||
require.GreaterOrEqual(t, priority, int64(0)) | ||
require.LessOrEqual(t, priority, int64(math.MaxInt64)) | ||
}) | ||
} | ||
|
||
// CreateRandomInput returns a random inputs to the priority function. | ||
func createRandomInput(t *rapid.T) input { | ||
denom := "skip" | ||
|
||
price := rapid.Int64Range(1, 1_000_000_000).Draw(t, "gas price") | ||
priceDec := sdkmath.LegacyNewDecWithPrec(price, 6) | ||
|
||
gasLimit := rapid.Int64Range(1_000_000, 1_000_000_000_000).Draw(t, "gas limit") | ||
|
||
if priceDec.MulInt64(gasLimit).GTE(sdkmath.LegacyNewDec(math.MaxInt64)) { | ||
t.Fatalf("not supposed to happen") | ||
} | ||
|
||
payFeeAmt := rapid.Int64Range(priceDec.MulInt64(gasLimit).TruncateInt64(), math.MaxInt64).Draw(t, "fee amount") | ||
|
||
return input{ | ||
payFee: sdk.NewCoin(denom, sdkmath.NewInt(payFeeAmt)), | ||
gasLimit: gasLimit, | ||
currentGasPrice: sdk.NewDecCoinFromDec(denom, priceDec), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters