-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a373fdd
commit 75ae7a8
Showing
7 changed files
with
125 additions
and
100 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 |
---|---|---|
@@ -1,74 +1,101 @@ | ||
package app_test | ||
|
||
// import ( | ||
// "strconv" | ||
import ( | ||
"math/big" | ||
|
||
// gethcore "github.com/ethereum/go-ethereum/core/types" | ||
// gethparams "github.com/ethereum/go-ethereum/params" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
// "github.com/NibiruChain/nibiru/x/evm/evmtest" | ||
// ) | ||
gethparams "github.com/ethereum/go-ethereum/params" | ||
|
||
// func (s *TestSuite) TestMsgEthereumTx_SimpleTransfer() { | ||
// testCases := []struct { | ||
// name string | ||
// scenario func() | ||
// }{ | ||
// { | ||
// name: "happy: AccessListTx", | ||
// scenario: func() { | ||
// deps := evmtest.NewTestDeps() | ||
// ethAcc := deps.Sender | ||
"github.com/NibiruChain/nibiru/app" | ||
"github.com/NibiruChain/nibiru/x/evm" | ||
"github.com/NibiruChain/nibiru/x/evm/evmtest" | ||
|
||
// s.T().Log("create eth tx msg") | ||
// var innerTxData []byte = nil | ||
// var accessList gethcore.AccessList = nil | ||
// ethTxMsg, err := evmtest.NewEthTxMsgFromTxData( | ||
// &deps, | ||
// gethcore.AccessListTxType, | ||
// innerTxData, | ||
// deps.StateDB().GetNonce(ethAcc.EthAddr), | ||
// accessList, | ||
// ) | ||
// s.NoError(err) | ||
"github.com/NibiruChain/nibiru/x/evm/statedb" | ||
) | ||
|
||
// resp, err := deps.Chain.EvmKeeper.EthereumTx(deps.GoCtx(), ethTxMsg) | ||
// s.Require().NoError(err) | ||
var NextNoOpAnteHandler sdk.AnteHandler = func( | ||
ctx sdk.Context, tx sdk.Tx, simulate bool, | ||
) (newCtx sdk.Context, err error) { | ||
return ctx, nil | ||
} | ||
|
||
// gasUsed := strconv.FormatUint(resp.GasUsed, 10) | ||
// wantGasUsed := strconv.FormatUint(gethparams.TxGas, 10) | ||
// s.Equal(gasUsed, wantGasUsed) | ||
// }, | ||
// }, | ||
// { | ||
// name: "happy: LegacyTx", | ||
// scenario: func() { | ||
// deps := evmtest.NewTestDeps() | ||
// ethAcc := deps.Sender | ||
func (s *TestSuite) TestAnteDecoratorVerifyEthAcc_CheckTx() { | ||
happyCreateContractTx := func(deps *evmtest.TestDeps) *evm.MsgEthereumTx { | ||
ethContractCreationTxParams := &evm.EvmTxArgs{ | ||
ChainID: deps.Chain.EvmKeeper.EthChainID(deps.Ctx), | ||
Nonce: 1, | ||
Amount: big.NewInt(10), | ||
GasLimit: 1000, | ||
GasPrice: big.NewInt(1), | ||
} | ||
tx := evm.NewTx(ethContractCreationTxParams) | ||
tx.From = deps.Sender.EthAddr.Hex() | ||
return tx | ||
} | ||
|
||
// s.T().Log("create eth tx msg") | ||
// var innerTxData []byte = nil | ||
// var accessList gethcore.AccessList = nil | ||
// ethTxMsg, err := evmtest.NewEthTxMsgFromTxData( | ||
// &deps, | ||
// gethcore.LegacyTxType, | ||
// innerTxData, | ||
// deps.StateDB().GetNonce(ethAcc.EthAddr), | ||
// accessList, | ||
// ) | ||
// s.NoError(err) | ||
testCases := []struct { | ||
name string | ||
beforeTxSetup func(deps *evmtest.TestDeps, sdb *statedb.StateDB) | ||
txSetup func(deps *evmtest.TestDeps) *evm.MsgEthereumTx | ||
wantErr string | ||
}{ | ||
{ | ||
name: "happy: sender with funds", | ||
beforeTxSetup: func(deps *evmtest.TestDeps, sdb *statedb.StateDB) { | ||
gasLimit := new(big.Int).SetUint64( | ||
gethparams.TxGasContractCreation + 500, | ||
) | ||
// Force account to be a smart contract | ||
sdb.AddBalance(deps.Sender.EthAddr, gasLimit) | ||
}, | ||
txSetup: happyCreateContractTx, | ||
wantErr: "", | ||
}, | ||
{ | ||
name: "sad: sender has insufficient gas balance", | ||
beforeTxSetup: func(deps *evmtest.TestDeps, sdb *statedb.StateDB) {}, | ||
txSetup: happyCreateContractTx, | ||
wantErr: "sender balance < tx cost", | ||
}, | ||
{ | ||
name: "sad: sender cannot be a contract -> no contract bytecode", | ||
beforeTxSetup: func(deps *evmtest.TestDeps, sdb *statedb.StateDB) { | ||
// Force account to be a smart contract | ||
sdb.SetCode(deps.Sender.EthAddr, []byte("evm bytecode stuff")) | ||
}, | ||
txSetup: happyCreateContractTx, | ||
wantErr: "sender is not EOA", | ||
}, | ||
{ | ||
name: "sad: invalid tx", | ||
beforeTxSetup: func(deps *evmtest.TestDeps, sdb *statedb.StateDB) {}, | ||
txSetup: func(deps *evmtest.TestDeps) *evm.MsgEthereumTx { | ||
return new(evm.MsgEthereumTx) | ||
}, | ||
wantErr: "failed to unpack tx data", | ||
}, | ||
} | ||
|
||
// resp, err := deps.Chain.EvmKeeper.EthereumTx(deps.GoCtx(), ethTxMsg) | ||
// s.Require().NoError(err) | ||
for _, tc := range testCases { | ||
s.Run(tc.name, func() { | ||
deps := evmtest.NewTestDeps() | ||
stateDB := deps.StateDB() | ||
anteDec := app.NewAnteDecVerifyEthAcc(deps.Chain.AppKeepers) | ||
|
||
// gasUsed := strconv.FormatUint(resp.GasUsed, 10) | ||
// wantGasUsed := strconv.FormatUint(gethparams.TxGas, 10) | ||
// s.Equal(gasUsed, wantGasUsed) | ||
// }, | ||
// }, | ||
// } | ||
tc.beforeTxSetup(&deps, stateDB) | ||
tx := tc.txSetup(&deps) | ||
s.Require().NoError(stateDB.Commit()) | ||
|
||
// for _, tc := range testCases { | ||
// s.Run(tc.name, tc.scenario) | ||
// } | ||
// } | ||
deps.Ctx = deps.Ctx.WithIsCheckTx(true) | ||
_, err := anteDec.AnteHandle( | ||
deps.Ctx, tx, false, NextNoOpAnteHandler, | ||
) | ||
if tc.wantErr != "" { | ||
s.Require().ErrorContains(err, tc.wantErr) | ||
return | ||
} | ||
s.Require().NoError(err) | ||
}) | ||
} | ||
} |
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