Documentation
¶
Overview ¶
Copyright (c) 2023-2024 Nibi, Inc.
Copyright (c) 2023-2024 Nibi, Inc.
Index ¶
- Constants
- Variables
- func AssertBankBalanceEqualWithDescription(t *testing.T, deps TestDeps, denom string, account gethcommon.Address, ...)
- func AssertERC20BalanceEqualWithDescription(t *testing.T, deps TestDeps, evmObj *vm.EVM, erc20, account gethcommon.Address, ...)
- func BuildTx(deps *TestDeps, ethExtentions bool, gasLimit uint64, fees sdk.Coins, ...) sdk.FeeTx
- func CreateFunTokenForBankCoin(deps TestDeps, bankDenom string, s *suite.Suite) (funtoken evm.FunToken)
- func DeployAndExecuteERC20Transfer(deps *TestDeps, t *testing.T) (erc20Transfer *evm.MsgEthereumTx, predecessors []*evm.MsgEthereumTx, ...)
- func EnsureNibiruPrefix()
- func ExecuteNibiTransfer(deps *TestDeps, t *testing.T) (*evm.MsgEthereumTx, *evm.MsgEthereumTxResponse)
- func GasLimitCreateContract() *big.Int
- func GenerateEthTxMsgAndSigner(jsonTxArgs evm.JsonTxArgs, deps *TestDeps, sender EthPrivKeyAcc) (evmTxMsg *evm.MsgEthereumTx, gethSigner gethcore.Signer, ...)
- func HappyCreateContractTx(deps *TestDeps) *evm.MsgEthereumTx
- func HappyTransferTx(deps *TestDeps, nonce uint64) *evm.MsgEthereumTx
- func LogLiteEventErc20Transfer(contract gethcommon.Address, from, to gethcommon.Address, amt *big.Int) evm.LogLite
- func LogLiteEventWnibiDeposit(contract, dst gethcommon.Address, amt *big.Int) evm.LogLite
- func NewEthTxMsgAsCmt(t *testing.T) (txBz cmttypes.Tx, ethTxMsgs []*evm.MsgEthereumTx, clientCtx client.Context)
- func NewEthTxMsgFromTxData(deps *TestDeps, txType GethTxType, innerTxData []byte, nonce uint64, ...) (*evm.MsgEthereumTx, error)
- func NewEthTxMsgs(count uint64) (ethTxMsgs []*evm.MsgEthereumTx)
- func NewMsgEthereumTx(args ArgsEthTx) (msgEthereumTx *evm.MsgEthereumTx, err error)
- func NewSigner(sk cryptotypes.PrivKey) keyring.Signer
- func NonEvmMsgTx(deps *TestDeps) sdk.Tx
- func TxTemplateAccessListTx() *gethcore.AccessListTx
- func TxTemplateDynamicFeeTx() *gethcore.DynamicFeeTx
- func TxTemplateLegacyTx() *gethcore.LegacyTx
- func ValidLegacyTx() *evm.LegacyTx
- type ArgsCreateContract
- type ArgsEthTx
- type ArgsExecuteContract
- type BalanceAssertNIBI
- type DeployContractResult
- type EthPrivKeyAcc
- type FunTokenBalanceAssert
- type GethTxType
- type Signer
- type TestDeps
- func (deps *TestDeps) Commit()
- func (deps TestDeps) Ctx() sdk.Context
- func (deps TestDeps) CtxInit() sdk.Context
- func (deps *TestDeps) DeployWNIBI(s *suite.Suite)
- func (deps *TestDeps) GethSigner() gethcore.Signer
- func (deps TestDeps) GoCtx() context.Context
- func (deps TestDeps) IsActiveStateTransition() bool
- func (deps TestDeps) IsEqualSDB(otherSdb *evmstate.SDB) bool
- func (deps *TestDeps) MimicEthereumTx(s *suite.Suite, doTx func(evmObj *vm.EVM, sdb *evmstate.SDB))
- func (deps TestDeps) NewEVM() (*vm.EVM, *evmstate.SDB)
- func (deps *TestDeps) NewStateDB() *evmstate.SDB
- func (deps *TestDeps) RunUpgrade(upgrade upgrades.Upgrade) error
- func (deps *TestDeps) SetCtx(ctx sdk.Context)
- type TxTransferWei
Constants ¶
const ( // FunTokenGasLimitSendToEvm consists of gas for 3 calls: // 1. transfer erc20 from sender to module // ~60_000 gas for regular erc20 transfer (our own ERC20Minter contract) // could be higher for user created contracts, let's cap with 200_000 // 2. mint native coin (made from erc20) or burn erc20 token (made from coin) // ~60_000 gas for either mint or burn // 3. send from module to account: // ~65_000 gas (bank send) FunTokenGasLimitSendToEvm uint64 = 400_000 )
Variables ¶
var DefaultEthCallGasLimit = srvconfig.DefaultEthCallGasLimit
Functions ¶
func CreateFunTokenForBankCoin ¶
func CreateFunTokenForBankCoin( deps TestDeps, bankDenom string, s *suite.Suite, ) (funtoken evm.FunToken)
CreateFunTokenForBankCoin: Uses the "TestDeps.Sender" account to create a "FunToken" mapping for a new coin
func DeployAndExecuteERC20Transfer ¶
func DeployAndExecuteERC20Transfer( deps *TestDeps, t *testing.T, ) ( erc20Transfer *evm.MsgEthereumTx, predecessors []*evm.MsgEthereumTx, contractAddr gethcommon.Address, )
DeployAndExecuteERC20Transfer deploys a test ERC-20, executes one transfer, and returns the transfer tx, the deploy tx (as a predecessor), and the contract address.
## Determinism: Why we use a fixed recipient address
Intrinsic gas charges depend on calldata bytes. Since Istanbul (EIP-2028), each zero byte is 4 gas and each non-zero byte is 16 gas (+12 per non-zero byte). In an ERC-20 transfer(address,uint256), the address occupies the last 20 bytes of a 32-byte word (left-padded with zeros). Random recipients change the count of non-zero bytes and make gas/gasUsed assertions flaky.
To keep tests stable, this helper uses a fixed recipient address whose byte pattern is constant. The intrinsic gas term is then reproducible.
References:
- EIP-2028: https://eips.ethereum.org/EIPS/eip-2028
- Solidity ABI padding rules: https://docs.soliditylang.org/en/latest/abi-spec.html
func EnsureNibiruPrefix ¶ added in v2.8.0
func EnsureNibiruPrefix()
Ensures that the Bech32 address prefix is configured to "nibi" instead of a another one like "cosmos", which will panic on Nibiru.
func ExecuteNibiTransfer ¶
func ExecuteNibiTransfer(deps *TestDeps, t *testing.T) (*evm.MsgEthereumTx, *evm.MsgEthereumTxResponse)
ExecuteNibiTransfer executes nibi transfer
func GasLimitCreateContract ¶
func GenerateEthTxMsgAndSigner ¶
func GenerateEthTxMsgAndSigner( jsonTxArgs evm.JsonTxArgs, deps *TestDeps, sender EthPrivKeyAcc, ) (evmTxMsg *evm.MsgEthereumTx, gethSigner gethcore.Signer, krSigner keyring.Signer, err error)
GenerateEthTxMsgAndSigner estimates gas, sets gas limit and returns signer for the tx.
Usage:
```go
evmTxMsg, gethSigner, krSigner, _ := GenerateEthTxMsgAndSigner(
jsonTxArgs, &deps, sender,
)
err := evmTxMsg.Sign(gethSigner, sender.KeyringSigner)
```
func HappyCreateContractTx ¶
func HappyCreateContractTx(deps *TestDeps) *evm.MsgEthereumTx
func HappyTransferTx ¶
func HappyTransferTx(deps *TestDeps, nonce uint64) *evm.MsgEthereumTx
func LogLiteEventErc20Transfer ¶ added in v2.8.0
func LogLiteEventErc20Transfer( contract gethcommon.Address, from, to gethcommon.Address, amt *big.Int, ) evm.LogLite
Constructs an ERC20 Transfer event
func LogLiteEventWnibiDeposit ¶ added in v2.8.0
Constructs a WNIBI.sol Deposit event
func NewEthTxMsgAsCmt ¶
func NewEthTxMsgAsCmt(t *testing.T) ( txBz cmttypes.Tx, ethTxMsgs []*evm.MsgEthereumTx, clientCtx client.Context, )
NewEthTxMsgAsCmt: Helper that returns an Ethereum tx msg converted into tx bytes used in the Consensus Engine.
func NewEthTxMsgFromTxData ¶
func NewEthTxMsgFromTxData( deps *TestDeps, txType GethTxType, innerTxData []byte, nonce uint64, to *gethcommon.Address, value *big.Int, gas uint64, accessList gethcore.AccessList, ) (*evm.MsgEthereumTx, error)
NewEthTxMsgFromTxData creates an Ethereum transaction message based on the specified txType (Legacy, AccessList, or DynamicFee). This function populates transaction fields like nonce, recipient, value, and gas, with an optional access list for AccessList and DynamicFee types. The transaction is signed using the provided dependencies.
Parameters:
- deps: Required dependencies including the sender address and signer.
- txType: Transaction type (Legacy, AccessList, or DynamicFee).
- innerTxData: Byte slice of transaction data (input).
- nonce: Transaction nonce.
- to: Recipient address.
- value: ETH value (in wei) to transfer.
- gas: Gas limit for the transaction.
- accessList: Access list for AccessList and DynamicFee types.
Returns:
- *evm.MsgEthereumTx: Ethereum transaction message ready for submission.
- error: Any error encountered during creation or signing.
func NewEthTxMsgs ¶
func NewEthTxMsgs(count uint64) (ethTxMsgs []*evm.MsgEthereumTx)
func NewMsgEthereumTx ¶ added in v2.8.0
func NewMsgEthereumTx( args ArgsEthTx, ) (msgEthereumTx *evm.MsgEthereumTx, err error)
func NonEvmMsgTx ¶
func TxTemplateAccessListTx ¶
func TxTemplateAccessListTx() *gethcore.AccessListTx
func TxTemplateDynamicFeeTx ¶
func TxTemplateDynamicFeeTx() *gethcore.DynamicFeeTx
func TxTemplateLegacyTx ¶
func ValidLegacyTx ¶
ValidLegacyTx: Useful initial condition for tests Exported only for use in tests.
Types ¶
type ArgsCreateContract ¶
type ArgsCreateContract struct {
EthAcc EthPrivKeyAcc
EthChainIDInt *big.Int
GasPrice *big.Int
Nonce uint64
GasLimit *big.Int
}
ArgsCreateContract: Arguments to call with `CreateContractTxMsg` to make Ethereum transactions that create contracts.
It is recommended to use a gas price of `big.NewInt(1)` for simpler op code calculations in gas units.
type ArgsEthTx ¶ added in v2.8.0
type ArgsEthTx struct {
CreateContract *ArgsCreateContract
ExecuteContract *ArgsExecuteContract
}
type ArgsExecuteContract ¶
type ArgsExecuteContract struct {
EthAcc EthPrivKeyAcc
EthChainIDInt *big.Int
ContractAddress *gethcommon.Address
Data []byte
GasPrice *big.Int
Nonce uint64
GasLimit *big.Int
}
ArgsExecuteContract: Arguments to call with `ExecuteContractTxMsg` to make Ethereum transactions that execute contracts.
type BalanceAssertNIBI ¶ added in v2.7.0
type DeployContractResult ¶
type DeployContractResult struct {
TxResp *evm.MsgEthereumTxResponse
EthTxMsg *evm.MsgEthereumTx
ContractData embeds.CompiledEvmContract
Nonce uint64
ContractAddr gethcommon.Address
}
func DeployContract ¶
func DeployContract( deps *TestDeps, contract embeds.CompiledEvmContract, args ...any, ) (result *DeployContractResult, err error)
type EthPrivKeyAcc ¶
type EthPrivKeyAcc struct {
EthAddr gethcommon.Address
NibiruAddr sdk.AccAddress
PrivKey *ethsecp256k1.PrivKey
KeyringSigner keyring.Signer
}
func NewEthPrivAcc ¶
func NewEthPrivAcc() EthPrivKeyAcc
NewEthPrivAcc returns an Ethereum private key, its corresponding Eth address, Nibiru address, and keyring signer.
func NewEthPrivAccs ¶
func NewEthPrivAccs(n int) []EthPrivKeyAcc
NewEthPrivAccs calls [NewEthAccInfo] n times.
type FunTokenBalanceAssert ¶
type GethTxType ¶
type GethTxType = uint8
GethTxType represents different Ethereum transaction types as defined in go-ethereum, such as Legacy, AccessList, and DynamicFee transactions.
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
Signer defines a type that is used on testing for signing MsgEthereumTx
func (Signer) SignByAddress ¶
SignByAddress sign byte messages with a user key providing the address.
type TestDeps ¶
type TestDeps struct {
App *app.NibiruApp
EvmKeeper *evmstate.Keeper
GenState *evm.GenesisState
Sender EthPrivKeyAcc
// contains filtered or unexported fields
}
func NewTestDeps ¶
func NewTestDeps() TestDeps
func (*TestDeps) Commit ¶ added in v2.8.0
func (deps *TestDeps) Commit()
Commit mutates the *TestDeps, committing changes from the current *evmstate.SDB and resetting it to nil. You can think of this like saving previous changes and potentially starting a new Etheruem tx is starting because reverting the old state DB is no longer possible after *TestDeps.Commit
func (TestDeps) Ctx ¶
Ctx returns the current EVM state DB context if one it is initialized and falls back to the initial ctx from when the TestDeps instance was constructed.
func (TestDeps) CtxInit ¶ added in v2.8.0
CtxInit returns the initial context from when the TestDeps instance was constructed.
func (*TestDeps) DeployWNIBI ¶ added in v2.7.0
func (*TestDeps) GethSigner ¶
func (TestDeps) IsActiveStateTransition ¶ added in v2.8.0
func (TestDeps) IsEqualSDB ¶ added in v2.8.0
func (*TestDeps) MimicEthereumTx ¶ added in v2.7.0
func (*TestDeps) NewStateDB ¶
NewStateDB returns the current *evmstate.SDB pointer for the *TestDeps instance. This function mutates the *TestDeps and initializes the state DB it one is not set already.
func (*TestDeps) RunUpgrade ¶ added in v2.7.0
type TxTransferWei ¶
type TxTransferWei struct {
Deps *TestDeps
To gethcommon.Address
AmountWei *big.Int
GasLimit uint64
}
func (TxTransferWei) Build ¶
func (tx TxTransferWei) Build() (evmTxMsg *evm.MsgEthereumTx, err error)
func (TxTransferWei) Run ¶
func (tx TxTransferWei) Run() (evmResp *evm.MsgEthereumTxResponse, err error)
func (TxTransferWei) ToJsonTxArgs ¶ added in v2.8.0
func (tx TxTransferWei) ToJsonTxArgs() (jsonTxArgs *evm.JsonTxArgs, jsonBz []byte)