-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* return non nil empty values * add missing log fields at marshal receipt * put base_fee and gas price at context creation
- Loading branch information
Showing
22 changed files
with
586 additions
and
98 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,36 @@ | ||
package keepers | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"cosmossdk.io/collections" | ||
"cosmossdk.io/math" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
type opchildKeeperForGasPriceKeeper interface { | ||
MinGasPrices(ctx context.Context) (sdk.DecCoins, error) | ||
} | ||
|
||
type GasPriceKeeper struct { | ||
opck opchildKeeperForGasPriceKeeper | ||
} | ||
|
||
func newGasPriceKeeper(opck opchildKeeperForGasPriceKeeper) GasPriceKeeper { | ||
return GasPriceKeeper{ | ||
opck: opck, | ||
} | ||
} | ||
|
||
func (k GasPriceKeeper) GasPrice(ctx context.Context, denom string) (math.LegacyDec, error) { | ||
gasPrices, err := k.opck.MinGasPrices(ctx) | ||
if err != nil && errors.Is(err, collections.ErrNotFound) { | ||
// allow this case due to init_genesis ordering | ||
return math.LegacyZeroDec(), nil | ||
} else if err != nil { | ||
return math.LegacyZeroDec(), err | ||
} | ||
|
||
return gasPrices.AmountOf(denom), nil | ||
} |
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
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,132 @@ | ||
package ante_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
|
||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types" | ||
|
||
"cosmossdk.io/log" | ||
dbm "github.com/cosmos/cosmos-db" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" | ||
"github.com/cosmos/cosmos-sdk/server" | ||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" | ||
"github.com/cosmos/cosmos-sdk/testutil/testdata" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/tx/signing" | ||
authsign "github.com/cosmos/cosmos-sdk/x/auth/signing" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli" | ||
|
||
minitiaapp "github.com/initia-labs/minievm/app" | ||
evmconfig "github.com/initia-labs/minievm/x/evm/config" | ||
evmtypes "github.com/initia-labs/minievm/x/evm/types" | ||
) | ||
|
||
// AnteTestSuite is a test suite to be used with ante handler tests. | ||
type AnteTestSuite struct { | ||
suite.Suite | ||
|
||
app *minitiaapp.MinitiaApp | ||
ctx sdk.Context | ||
clientCtx client.Context | ||
txBuilder client.TxBuilder | ||
} | ||
|
||
// returns context and app with params set on account keeper | ||
func (suite *AnteTestSuite) createTestApp(tempDir string) (*minitiaapp.MinitiaApp, sdk.Context) { | ||
appOptions := make(simtestutil.AppOptionsMap, 0) | ||
appOptions[flags.FlagHome] = tempDir | ||
appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue | ||
|
||
app := minitiaapp.NewMinitiaApp( | ||
log.NewNopLogger(), dbm.NewMemDB(), dbm.NewMemDB(), dbm.NewMemDB(), nil, true, evmconfig.DefaultEVMConfig(), appOptions, | ||
) | ||
ctx := app.BaseApp.NewUncachedContext(false, tmproto.Header{}) | ||
err := app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()) | ||
suite.NoError(err) | ||
|
||
err = app.EVMKeeper.Params.Set(ctx, evmtypes.DefaultParams()) | ||
suite.NoError(err) | ||
|
||
return app, ctx | ||
} | ||
|
||
// SetupTest setups a new test, with new app, context, and anteHandler. | ||
func (suite *AnteTestSuite) SetupTest() { | ||
tempDir := suite.T().TempDir() | ||
suite.app, suite.ctx = suite.createTestApp(tempDir) | ||
suite.ctx = suite.ctx.WithBlockHeight(1) | ||
|
||
// Set up TxConfig. | ||
encodingConfig := minitiaapp.MakeEncodingConfig() | ||
|
||
// We're using TestMsg encoding in some tests, so register it here. | ||
encodingConfig.Amino.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil) | ||
testdata.RegisterInterfaces(encodingConfig.InterfaceRegistry) | ||
|
||
suite.clientCtx = client.Context{}. | ||
WithTxConfig(encodingConfig.TxConfig) | ||
} | ||
|
||
// CreateTestTx is a helper function to create a tx given multiple inputs. | ||
func (suite *AnteTestSuite) CreateTestTx(privs []cryptotypes.PrivKey, accNums []uint64, accSeqs []uint64, chainID string) (authsign.Tx, error) { | ||
defaultSignMode, err := authsign.APISignModeToInternal(suite.clientCtx.TxConfig.SignModeHandler().DefaultMode()) | ||
suite.NoError(err) | ||
|
||
// First round: we gather all the signer infos. We use the "set empty | ||
// signature" hack to do that. | ||
var sigsV2 []signing.SignatureV2 | ||
for i, priv := range privs { | ||
|
||
sigV2 := signing.SignatureV2{ | ||
PubKey: priv.PubKey(), | ||
Data: &signing.SingleSignatureData{ | ||
SignMode: defaultSignMode, | ||
Signature: nil, | ||
}, | ||
Sequence: accSeqs[i], | ||
} | ||
|
||
sigsV2 = append(sigsV2, sigV2) | ||
} | ||
err = suite.txBuilder.SetSignatures(sigsV2...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Second round: all signer infos are set, so each signer can sign. | ||
sigsV2 = []signing.SignatureV2{} | ||
for i, priv := range privs { | ||
signerData := authsign.SignerData{ | ||
Address: sdk.AccAddress(priv.PubKey().Address()).String(), | ||
ChainID: chainID, | ||
AccountNumber: accNums[i], | ||
Sequence: accSeqs[i], | ||
PubKey: priv.PubKey(), | ||
} | ||
sigV2, err := tx.SignWithPrivKey( | ||
context.TODO(), defaultSignMode, signerData, | ||
suite.txBuilder, priv, suite.clientCtx.TxConfig, accSeqs[i]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
sigsV2 = append(sigsV2, sigV2) | ||
} | ||
err = suite.txBuilder.SetSignatures(sigsV2...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return suite.txBuilder.GetTx(), nil | ||
} | ||
|
||
func TestAnteTestSuite(t *testing.T) { | ||
suite.Run(t, new(AnteTestSuite)) | ||
} |
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,8 @@ | ||
package ante | ||
|
||
// private type creates an interface key for Context that cannot be accessed by any other package | ||
type contextKey int | ||
|
||
const ( | ||
ContextKeyGasPrices contextKey = iota | ||
) |
Oops, something went wrong.