Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Refactor eets blockchain test flow #237

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2760,7 +2760,6 @@ func (bc *BlockChain) ApplyTransaction(chainConfig *params.ChainConfig, author *
}
// Create a new context to be used in the EVM environment
blockContext := NewEVMBlockContext(header, bc, author)

txContext := NewEVMTxContext(msg, header, chainConfig)
// Create a new environment which holds all relevant information
// about the transaction and calling mechanisms.
Expand Down
2 changes: 2 additions & 0 deletions blockchain/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ func (b *BlockGen) AddTxWithChain(bc *BlockChain, tx *types.Transaction) {
b.receipts = append(b.receipts, receipt)
}

// AddTxWithChainEvenHasError is an AddTx that inherits the vmConfig of the received chain
// and does not panic even if an error occurs.
func (b *BlockGen) AddTxWithChainEvenHasError(bc *BlockChain, tx *types.Transaction) error {
b.statedb.SetTxContext(tx.Hash(), common.Hash{}, len(b.txs))
var vmConfig vm.Config
Expand Down
15 changes: 10 additions & 5 deletions blockchain/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,6 @@ func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig {
}
}

var CreateContractWithCodeFormatInExecutionSpecTest bool

// ToBlock creates the genesis block and writes state of a genesis specification
// to the given database (or discards it if nil).
func (g *Genesis) ToBlock(baseStateRoot common.Hash, db database.DBManager) *types.Block {
Expand All @@ -312,10 +310,17 @@ func (g *Genesis) ToBlock(baseStateRoot common.Hash, db database.DBManager) *typ
for addr, account := range g.Alloc {
if len(account.Code) != 0 {
originalCode := stateDB.GetCode(addr)
if CreateContractWithCodeFormatInExecutionSpecTest {
stateDB.CreateSmartContractAccount(addr, params.CodeFormatEVM, g.Config.Rules(new(big.Int).SetUint64(g.Number)))
rules := g.Config.Rules(new(big.Int).SetUint64(g.Number))
if rules.IsPrague {
if _, ok := types.ParseDelegation(account.Code); ok {
stateDB.SetCodeToEOA(addr, account.Code, rules)
} else {
stateDB.CreateSmartContractAccount(addr, params.CodeFormatEVM, rules)
stateDB.SetCode(addr, account.Code)
}
} else {
stateDB.SetCode(addr, account.Code)
}
stateDB.SetCode(addr, account.Code)
// If originalCode is not nil,
// just update the code and don't change the other states
if originalCode != nil {
Expand Down
4 changes: 0 additions & 4 deletions rlp/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -1085,10 +1085,6 @@ func (s *Stream) readFull(buf []byte) (err error) {
return err
}

func (s *Stream) ReadByte() (byte, error) {
return s.readByte()
}

// readByte reads a single byte from the underlying stream.
func (s *Stream) readByte() (byte, error) {
if err := s.willRead(1); err != nil {
Expand Down
27 changes: 0 additions & 27 deletions tests/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,10 @@ package tests
import (
"testing"

"github.com/kaiachain/kaia/blockchain"
"github.com/kaiachain/kaia/common"
"github.com/stretchr/testify/suite"
)

func TestBlockchain(t *testing.T) {
t.Parallel()

bt := new(testMatcher)
// General state tests are 'exported' as blockchain tests, but we can run them natively.
bt.skipLoad(`^GeneralStateTests/`)
// Skip random failures due to selfish mining test.
// bt.skipLoad(`^bcForgedTest/bcForkUncle\.json`)
bt.skipLoad(`^bcMultiChainTest/(ChainAtoChainB_blockorder|CallContractFromNotBestBlock)`)
bt.skipLoad(`^bcTotalDifficultyTest/(lotsOfLeafs|lotsOfBranches|sideChainWithMoreTransactions)`)
// This test is broken
bt.fails(`blockhashNonConstArg_Constantinople`, "Broken test")

// Still failing tests
// bt.skipLoad(`^bcWalletTest.*_Byzantium$`)

// TODO-Kaia Update BlockchainTests first to enable this test, since block header has been changed in Kaia.
//bt.walk(t, blockTestDir, func(t *testing.T, name string, test *BlockTest) {
// if err := bt.checkFailure(t, name, test.Run()); err != nil {
// t.Error(err)
// }
//})
}

// TestExecutionSpecState runs the state_test fixtures from execution-spec-tests.
type ExecutionSpecBlockTestSuite struct {
suite.Suite
Expand All @@ -63,13 +38,11 @@ type ExecutionSpecBlockTestSuite struct {
func (suite *ExecutionSpecBlockTestSuite) SetupSuite() {
suite.originalIsPrecompiledContractAddress = common.IsPrecompiledContractAddress
common.IsPrecompiledContractAddress = isPrecompiledContractAddressForEthTest
blockchain.CreateContractWithCodeFormatInExecutionSpecTest = true
}

func (suite *ExecutionSpecBlockTestSuite) TearDownSuite() {
// Reset global variables for test
common.IsPrecompiledContractAddress = suite.originalIsPrecompiledContractAddress
blockchain.CreateContractWithCodeFormatInExecutionSpecTest = false
}

func (suite *ExecutionSpecBlockTestSuite) TestExecutionSpecBlock() {
Expand Down
Loading