Skip to content

Commit

Permalink
fix strange ignored file issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Unique-Divine committed Oct 29, 2024
1 parent 717ce1c commit 04a6897
Showing 1 changed file with 93 additions and 89 deletions.
182 changes: 93 additions & 89 deletions x/evm/evmtest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,95 +26,6 @@ import (
"github.com/NibiruChain/nibiru/v2/x/evm/embeds"
)

type GethTxType = uint8

func TxTemplateAccessListTx() *gethcore.AccessListTx {
return &gethcore.AccessListTx{
GasPrice: big.NewInt(1),
Gas: gethparams.TxGas,
To: &gethcommon.Address{},
Value: big.NewInt(0),
Data: []byte{},
}
}

func TxTemplateLegacyTx() *gethcore.LegacyTx {
return &gethcore.LegacyTx{
GasPrice: big.NewInt(1),
Gas: gethparams.TxGas,
To: &gethcommon.Address{},
Value: big.NewInt(0),
Data: []byte{},
}
}

func TxTemplateDynamicFeeTx() *gethcore.DynamicFeeTx {
return &gethcore.DynamicFeeTx{
GasFeeCap: big.NewInt(10),
GasTipCap: big.NewInt(2),
Gas: gethparams.TxGas,
To: &gethcommon.Address{},
Value: big.NewInt(0),
Data: []byte{},
}
}

func NewEthTxMsgFromTxData(
deps *TestDeps,
txType GethTxType,
innerTxData []byte,
nonce uint64,
to *gethcommon.Address,
value *big.Int,
gas uint64,
accessList gethcore.AccessList,
) (*evm.MsgEthereumTx, error) {
if innerTxData == nil {
innerTxData = []byte{}
}

var ethCoreTx *gethcore.Transaction
switch txType {
case gethcore.LegacyTxType:
innerTx := TxTemplateLegacyTx()
innerTx.Nonce = nonce
innerTx.Data = innerTxData
innerTx.To = to
innerTx.Value = value
innerTx.Gas = gas
ethCoreTx = gethcore.NewTx(innerTx)
case gethcore.AccessListTxType:
innerTx := TxTemplateAccessListTx()
innerTx.Nonce = nonce
innerTx.Data = innerTxData
innerTx.AccessList = accessList
innerTx.To = to
innerTx.Value = value
innerTx.Gas = gas
ethCoreTx = gethcore.NewTx(innerTx)
case gethcore.DynamicFeeTxType:
innerTx := TxTemplateDynamicFeeTx()
innerTx.Nonce = nonce
innerTx.Data = innerTxData
innerTx.To = to
innerTx.Value = value
innerTx.Gas = gas
innerTx.AccessList = accessList
ethCoreTx = gethcore.NewTx(innerTx)
default:
return nil, fmt.Errorf(
"received unknown tx type (%v) in NewEthTxMsgFromTxData", txType)
}

ethTxMsg := new(evm.MsgEthereumTx)
if err := ethTxMsg.FromEthereumTx(ethCoreTx); err != nil {
return ethTxMsg, err
}

ethTxMsg.From = deps.Sender.EthAddr.Hex()
return ethTxMsg, ethTxMsg.Sign(deps.GethSigner(), deps.Sender.KeyringSigner)
}

// ExecuteNibiTransfer executes nibi transfer
func ExecuteNibiTransfer(deps *TestDeps, t *testing.T) *evm.MsgEthereumTx {
nonce := deps.StateDB().GetNonce(deps.Sender.EthAddr)
Expand Down Expand Up @@ -326,6 +237,10 @@ func TransferWei(
return err
}

// --------------------------------------------------
// Templates
// --------------------------------------------------

// ValidLegacyTx: Useful initial condition for tests
// Exported only for use in tests.
func ValidLegacyTx() *evm.LegacyTx {
Expand All @@ -342,3 +257,92 @@ func ValidLegacyTx() *evm.LegacyTx {
S: []byte{},
}
}

type GethTxType = uint8

func TxTemplateAccessListTx() *gethcore.AccessListTx {
return &gethcore.AccessListTx{
GasPrice: big.NewInt(1),
Gas: gethparams.TxGas,
To: &gethcommon.Address{},
Value: big.NewInt(0),
Data: []byte{},
}
}

func TxTemplateLegacyTx() *gethcore.LegacyTx {
return &gethcore.LegacyTx{
GasPrice: big.NewInt(1),
Gas: gethparams.TxGas,
To: &gethcommon.Address{},
Value: big.NewInt(0),
Data: []byte{},
}
}

func TxTemplateDynamicFeeTx() *gethcore.DynamicFeeTx {
return &gethcore.DynamicFeeTx{
GasFeeCap: big.NewInt(10),
GasTipCap: big.NewInt(2),
Gas: gethparams.TxGas,
To: &gethcommon.Address{},
Value: big.NewInt(0),
Data: []byte{},
}
}

func NewEthTxMsgFromTxData(
deps *TestDeps,
txType GethTxType,
innerTxData []byte,
nonce uint64,
to *gethcommon.Address,
value *big.Int,
gas uint64,
accessList gethcore.AccessList,
) (*evm.MsgEthereumTx, error) {
if innerTxData == nil {
innerTxData = []byte{}
}

var ethCoreTx *gethcore.Transaction
switch txType {
case gethcore.LegacyTxType:
innerTx := TxTemplateLegacyTx()
innerTx.Nonce = nonce
innerTx.Data = innerTxData
innerTx.To = to
innerTx.Value = value
innerTx.Gas = gas
ethCoreTx = gethcore.NewTx(innerTx)
case gethcore.AccessListTxType:
innerTx := TxTemplateAccessListTx()
innerTx.Nonce = nonce
innerTx.Data = innerTxData
innerTx.AccessList = accessList
innerTx.To = to
innerTx.Value = value
innerTx.Gas = gas
ethCoreTx = gethcore.NewTx(innerTx)
case gethcore.DynamicFeeTxType:
innerTx := TxTemplateDynamicFeeTx()
innerTx.Nonce = nonce
innerTx.Data = innerTxData
innerTx.To = to
innerTx.Value = value
innerTx.Gas = gas
innerTx.AccessList = accessList
ethCoreTx = gethcore.NewTx(innerTx)
default:
return nil, fmt.Errorf(
"received unknown tx type (%v) in NewEthTxMsgFromTxData", txType)
}

ethTxMsg := new(evm.MsgEthereumTx)
if err := ethTxMsg.FromEthereumTx(ethCoreTx); err != nil {
return ethTxMsg, err
}

ethTxMsg.From = deps.Sender.EthAddr.Hex()
return ethTxMsg, ethTxMsg.Sign(deps.GethSigner(), deps.Sender.KeyringSigner)
}

0 comments on commit 04a6897

Please sign in to comment.