fix : test-integration

This commit is contained in:
Shivam Sharma 2023-07-17 16:39:12 +08:00
parent a8e85c4f87
commit 54acb92cb4
4 changed files with 33 additions and 15 deletions

View file

@ -589,6 +589,15 @@ func (g *Genesis) MustCommit(db ethdb.Database) *types.Block {
return block return block
} }
// GenesisBlockForTesting creates and writes a block in which addr has the given wei balance.
func GenesisBlockForTesting(db ethdb.Database, addr common.Address, balance *big.Int) *types.Block {
g := Genesis{
Alloc: GenesisAlloc{addr: {Balance: balance}},
BaseFee: big.NewInt(params.InitialBaseFee),
}
return g.MustCommit(db)
}
// DefaultGenesisBlock returns the Ethereum main net genesis block. // DefaultGenesisBlock returns the Ethereum main net genesis block.
func DefaultGenesisBlock() *Genesis { func DefaultGenesisBlock() *Genesis {
return &Genesis{ return &Genesis{

View file

@ -103,13 +103,8 @@ func (b *TestBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.
return nil, nil return nil, nil
} }
func (b *TestBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error) { func (b *TestBackend) GetLogs(ctx context.Context, hash common.Hash, number uint64) ([][]*types.Log, error) {
number := rawdb.ReadHeaderNumber(b.DB, hash) receipts := rawdb.ReadReceipts(b.DB, hash, number, params.TestChainConfig)
if number == nil {
return nil, nil
}
receipts := rawdb.ReadReceipts(b.DB, hash, *number, params.TestChainConfig)
logs := make([][]*types.Log, len(receipts)) logs := make([][]*types.Log, len(receipts))
for i, receipt := range receipts { for i, receipt := range receipts {
@ -175,3 +170,15 @@ func (b *TestBackend) ServiceFilter(ctx context.Context, session *bloombits.Matc
func (b *TestBackend) SubscribeStateSyncEvent(ch chan<- core.StateSyncEvent) event.Subscription { func (b *TestBackend) SubscribeStateSyncEvent(ch chan<- core.StateSyncEvent) event.Subscription {
return b.stateSyncFeed.Subscribe(ch) return b.stateSyncFeed.Subscribe(ch)
} }
func (b *TestBackend) ChainConfig() *params.ChainConfig { panic("not implemented") }
func (b *TestBackend) CurrentHeader() *types.Header { panic("not implemented") }
func (b *TestBackend) GetBody(context.Context, common.Hash, rpc.BlockNumber) (*types.Body, error) {
panic("not implemented")
}
func (b *TestBackend) PendingBlockAndReceipts() (*types.Block, types.Receipts) {
panic("not implemented")
}

View file

@ -62,7 +62,7 @@ func areDifferentHashes(receipts []map[string]interface{}) bool {
} }
// Test for GetTransactionReceiptsByBlock // Test for GetTransactionReceiptsByBlock
func testGetTransactionReceiptsByBlock(t *testing.T, publicBlockchainAPI *ethapi.PublicBlockChainAPI) { func testGetTransactionReceiptsByBlock(t *testing.T, publicBlockchainAPI *ethapi.BlockChainAPI) {
// check 1 : zero transactions // check 1 : zero transactions
receiptsOut, err := publicBlockchainAPI.GetTransactionReceiptsByBlock(context.Background(), rpc.BlockNumberOrHashWithNumber(1)) receiptsOut, err := publicBlockchainAPI.GetTransactionReceiptsByBlock(context.Background(), rpc.BlockNumberOrHashWithNumber(1))
if err != nil { if err != nil {
@ -101,7 +101,7 @@ func testGetTransactionReceiptsByBlock(t *testing.T, publicBlockchainAPI *ethapi
} }
// Test for GetTransactionByBlockNumberAndIndex // Test for GetTransactionByBlockNumberAndIndex
func testGetTransactionByBlockNumberAndIndex(t *testing.T, publicTransactionPoolAPI *ethapi.PublicTransactionPoolAPI) { func testGetTransactionByBlockNumberAndIndex(t *testing.T, publicTransactionPoolAPI *ethapi.TransactionAPI) {
// check 1 : False ( no transaction ) // check 1 : False ( no transaction )
tx := publicTransactionPoolAPI.GetTransactionByBlockNumberAndIndex(context.Background(), rpc.BlockNumber(1), 0) tx := publicTransactionPoolAPI.GetTransactionByBlockNumberAndIndex(context.Background(), rpc.BlockNumber(1), 0)
assert.Nil(t, tx) assert.Nil(t, tx)
@ -249,7 +249,7 @@ func TestAPIs(t *testing.T) {
// Testing GetTransactionByBlockNumberAndIndex // Testing GetTransactionByBlockNumberAndIndex
nonceLock := new(ethapi.AddrLocker) nonceLock := new(ethapi.AddrLocker)
publicTransactionPoolAPI := ethapi.NewPublicTransactionPoolAPI(backend.APIBackend, nonceLock) publicTransactionPoolAPI := ethapi.NewTransactionAPI(backend.APIBackend, nonceLock)
testGetTransactionByBlockNumberAndIndex(t, publicTransactionPoolAPI) testGetTransactionByBlockNumberAndIndex(t, publicTransactionPoolAPI)
} }

View file

@ -29,6 +29,7 @@ import (
"github.com/ethereum/go-ethereum/consensus/misc" "github.com/ethereum/go-ethereum/consensus/misc"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/txpool"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
@ -219,7 +220,7 @@ func buildNextBlock(t *testing.T, _bor consensus.Engine, chain *core.BlockChain,
ctx := context.Background() ctx := context.Background()
// Finalize and seal the block // Finalize and seal the block
block, _ := _bor.FinalizeAndAssemble(ctx, chain, b.header, state, b.txs, nil, b.receipts) block, _ := _bor.FinalizeAndAssemble(ctx, chain, b.header, state, b.txs, nil, b.receipts, []*types.Withdrawal{})
// Write state changes to db // Write state changes to db
root, err := state.Commit(chain.Config().IsEIP158(b.header.Number)) root, err := state.Commit(chain.Config().IsEIP158(b.header.Number))
@ -227,7 +228,7 @@ func buildNextBlock(t *testing.T, _bor consensus.Engine, chain *core.BlockChain,
panic(fmt.Sprintf("state write error: %v", err)) panic(fmt.Sprintf("state write error: %v", err))
} }
if err := state.Database().TrieDB().Commit(root, false, nil); err != nil { if err := state.Database().TrieDB().Commit(root, false); err != nil {
panic(fmt.Sprintf("trie write error: %v", err)) panic(fmt.Sprintf("trie write error: %v", err))
} }
@ -255,7 +256,7 @@ func (b *blockGen) addTxWithChain(bc *core.BlockChain, statedb *state.StateDB, t
b.setCoinbase(coinbase) b.setCoinbase(coinbase)
} }
statedb.Prepare(tx.Hash(), len(b.txs)) statedb.SetTxContext(tx.Hash(), len(b.txs))
receipt, err := core.ApplyTransaction(bc.Config(), bc, &b.header.Coinbase, b.gasPool, statedb, b.header, tx, &b.header.GasUsed, vm.Config{}, nil) receipt, err := core.ApplyTransaction(bc.Config(), bc, &b.header.Coinbase, b.gasPool, statedb, b.header, tx, &b.header.GasUsed, vm.Config{}, nil)
if err != nil { if err != nil {
@ -433,7 +434,8 @@ func InitGenesis(t *testing.T, faucets []*ecdsa.PrivateKey, fileLocation string,
} }
genesis.Config.ChainID = big.NewInt(15001) genesis.Config.ChainID = big.NewInt(15001)
genesis.Config.EIP150Hash = common.Hash{} genesis.Config.EIP150Block = big.NewInt(0)
genesis.Config.Bor.Sprint["0"] = sprintSize genesis.Config.Bor.Sprint["0"] = sprintSize
return genesis return genesis
@ -466,7 +468,7 @@ func InitMiner(genesis *core.Genesis, privKey *ecdsa.PrivateKey, withoutHeimdall
SyncMode: downloader.FullSync, SyncMode: downloader.FullSync,
DatabaseCache: 256, DatabaseCache: 256,
DatabaseHandles: 256, DatabaseHandles: 256,
TxPool: core.DefaultTxPoolConfig, TxPool: txpool.DefaultConfig,
GPO: ethconfig.Defaults.GPO, GPO: ethconfig.Defaults.GPO,
Ethash: ethconfig.Defaults.Ethash, Ethash: ethconfig.Defaults.Ethash,
Miner: miner.Config{ Miner: miner.Config{