Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
evm: unit tests (#619)
Browse files Browse the repository at this point in the history
* evm: unit tests

* Add unit tests for DynamicFeeTx.Validate()

* Start get and set signature values tests

* get set values

* Add tests for GetTo()

* Add GetNonce test

* Add GetValue test

* Start copy test

* Add WIP newDynamicFeeTx test

* Add WIP legacy_tx_test

* pair programming session

* Add TestLegacyTxValidate

* Add TestLegacyTxSetSignatureValues & GetSignatureValues

* Add legacyTx tests

* Merge main, forgot to save one file

* Add AccessList tests

* Add chain Config (fork order)

* Add invalid genesis account test

* Add params tests

* Add WIP tracer test

* tracer tests

* Add FormatLogs tests

* Add NewNoOpTracer test

* Refactor to test suite

* Refactor Tx Test suits to only use TxDataTestSuite

* Update link to geth interpreter

* Update x/evm/types/params.go

* Refactor accessListTx Test suits to  use TxDataTestSuite

Co-authored-by: Daniel Burckhardt <daniel.m.burckhardt@gmail.com>
  • Loading branch information
fedekunze and danburck authored Oct 8, 2021
1 parent f69c887 commit 5169721
Show file tree
Hide file tree
Showing 12 changed files with 1,111 additions and 14 deletions.
38 changes: 38 additions & 0 deletions x/evm/types/access_list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package types

import (
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
)

func (suite *TxDataTestSuite) TestTestNewAccessList() {
testCases := []struct {
name string
ethAccessList *ethtypes.AccessList
expAl AccessList
}{
{
"ethAccessList is nil",
nil,
nil,
},
{
"non-empty ethAccessList",
&ethtypes.AccessList{{Address: suite.addr, StorageKeys: []common.Hash{{0}}}},
AccessList{{Address: suite.hexAddr, StorageKeys: []string{common.Hash{}.Hex()}}},
},
}
for _, tc := range testCases {
al := NewAccessList(tc.ethAccessList)

suite.Require().Equal(tc.expAl, al)
}
}

func (suite *TxDataTestSuite) TestAccessListToEthAccessList() {
ethAccessList := ethtypes.AccessList{{Address: suite.addr, StorageKeys: []common.Hash{{0}}}}
al := NewAccessList(&ethAccessList)
actual := al.ToEthAccessList()

suite.Require().Equal(&ethAccessList, actual)
}
20 changes: 19 additions & 1 deletion x/evm/types/chain_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ func TestChainConfigValidate(t *testing.T) {
},
true,
},

{
"invalid CatalystBlock",
ChainConfig{
Expand All @@ -258,6 +257,25 @@ func TestChainConfigValidate(t *testing.T) {
},
true,
},
{
"invalid fork order - skip HomesteadBlock",
ChainConfig{
DAOForkBlock: newIntPtr(0),
EIP150Block: newIntPtr(0),
EIP150Hash: defaultEIP150Hash,
EIP155Block: newIntPtr(0),
EIP158Block: newIntPtr(0),
ByzantiumBlock: newIntPtr(0),
ConstantinopleBlock: newIntPtr(0),
PetersburgBlock: newIntPtr(0),
IstanbulBlock: newIntPtr(0),
MuirGlacierBlock: newIntPtr(0),
BerlinBlock: newIntPtr(0),
LondonBlock: newIntPtr(0),
CatalystBlock: newIntPtr(0),
},
true,
},
}

for _, tc := range testCases {
Expand Down
4 changes: 2 additions & 2 deletions x/evm/types/dynamic_fee_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ func (tx *DynamicFeeTx) GetGasPrice() *big.Int {
return tx.GetGasFeeCap()
}

// GetGasTipCap returns the gas price field.
// GetGasTipCap returns the gas tip cap field.
func (tx *DynamicFeeTx) GetGasTipCap() *big.Int {
if tx.GasTipCap == nil {
return nil
}
return tx.GasTipCap.BigInt()
}

// GetGasFeeCap returns the gas price field.
// GetGasFeeCap returns the gas fee cap field.
func (tx *DynamicFeeTx) GetGasFeeCap() *big.Int {
if tx.GasFeeCap == nil {
return nil
Expand Down
Loading

0 comments on commit 5169721

Please sign in to comment.