Skip to content

Commit

Permalink
remove unnecessary test
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-ogrady committed Nov 2, 2022
1 parent 1463d9d commit f23fa80
Showing 1 changed file with 68 additions and 71 deletions.
139 changes: 68 additions & 71 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package core
import (
"fmt"
"math/big"
"os"
"testing"
"time"

Expand All @@ -21,8 +20,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/fsnotify/fsnotify"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var (
Expand Down Expand Up @@ -104,74 +101,74 @@ func awaitWatcherEventsSubside(watcher *fsnotify.Watcher, subsideTimeout time.Du
<-done
}

func TestTrieCleanJournal(t *testing.T) {
require := require.New(t)
assert := assert.New(t)

trieCleanJournal := t.TempDir()
trieCleanJournalWatcher, err := fsnotify.NewWatcher()
require.NoError(err)
defer func() {
assert.NoError(trieCleanJournalWatcher.Close())
}()
require.NoError(trieCleanJournalWatcher.Add(trieCleanJournal))

create := func(db ethdb.Database, chainConfig *params.ChainConfig, lastAcceptedHash common.Hash) (*BlockChain, error) {
config := *archiveConfig
config.TrieCleanJournal = trieCleanJournal
config.TrieCleanRejournal = 100 * time.Millisecond
return createBlockChain(db, &config, chainConfig, lastAcceptedHash)
}

var (
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
key2, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
addr1 = crypto.PubkeyToAddress(key1.PublicKey)
addr2 = crypto.PubkeyToAddress(key2.PublicKey)
// We use two separate databases since GenerateChain commits the state roots to its underlying
// database.
genDB = rawdb.NewMemoryDatabase()
chainDB = rawdb.NewMemoryDatabase()
)

// Ensure that key1 has some funds in the genesis block.
genesisBalance := big.NewInt(1000000)
gspec := &Genesis{
Config: &params.ChainConfig{HomesteadBlock: new(big.Int)},
Alloc: GenesisAlloc{addr1: {Balance: genesisBalance}},
}
genesis := gspec.MustCommit(genDB)
_ = gspec.MustCommit(chainDB)

blockchain, err := create(chainDB, gspec.Config, common.Hash{})
require.NoError(err)
defer blockchain.Stop()

// This call generates a chain of 3 blocks.
signer := types.HomesteadSigner{}
// Generate chain of blocks using [genDB] instead of [chainDB] to avoid writing
// to the BlockChain's database while generating blocks.
chain, _, err := GenerateChain(gspec.Config, genesis, blockchain.engine, genDB, 3, 10, func(i int, gen *BlockGen) {
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1)
gen.AddTx(tx)
})
require.NoError(err)

// Insert and accept the generated chain
_, err = blockchain.InsertChain(chain)
require.NoError(err)

for _, block := range chain {
require.NoError(blockchain.Accept(block))
}
blockchain.DrainAcceptorQueue()

awaitWatcherEventsSubside(trieCleanJournalWatcher, time.Second)
// Assert that a new file is created in the trie clean journal
dirEntries, err := os.ReadDir(trieCleanJournal)
require.NoError(err)
require.NotEmpty(dirEntries)
}
// func TestTrieCleanJournal(t *testing.T) {
// require := require.New(t)
// assert := assert.New(t)
//
// trieCleanJournal := t.TempDir()
// trieCleanJournalWatcher, err := fsnotify.NewWatcher()
// require.NoError(err)
// defer func() {
// assert.NoError(trieCleanJournalWatcher.Close())
// }()
// require.NoError(trieCleanJournalWatcher.Add(trieCleanJournal))
//
// create := func(db ethdb.Database, chainConfig *params.ChainConfig, lastAcceptedHash common.Hash) (*BlockChain, error) {
// config := *archiveConfig
// config.TrieCleanJournal = trieCleanJournal
// config.TrieCleanRejournal = 100 * time.Millisecond
// return createBlockChain(db, &config, chainConfig, lastAcceptedHash)
// }
//
// var (
// key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
// key2, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
// addr1 = crypto.PubkeyToAddress(key1.PublicKey)
// addr2 = crypto.PubkeyToAddress(key2.PublicKey)
// // We use two separate databases since GenerateChain commits the state roots to its underlying
// // database.
// genDB = rawdb.NewMemoryDatabase()
// chainDB = rawdb.NewMemoryDatabase()
// )
//
// // Ensure that key1 has some funds in the genesis block.
// genesisBalance := big.NewInt(1000000)
// gspec := &Genesis{
// Config: &params.ChainConfig{HomesteadBlock: new(big.Int)},
// Alloc: GenesisAlloc{addr1: {Balance: genesisBalance}},
// }
// genesis := gspec.MustCommit(genDB)
// _ = gspec.MustCommit(chainDB)
//
// blockchain, err := create(chainDB, gspec.Config, common.Hash{})
// require.NoError(err)
// defer blockchain.Stop()
//
// // This call generates a chain of 3 blocks.
// signer := types.HomesteadSigner{}
// // Generate chain of blocks using [genDB] instead of [chainDB] to avoid writing
// // to the BlockChain's database while generating blocks.
// chain, _, err := GenerateChain(gspec.Config, genesis, blockchain.engine, genDB, 3, 10, func(i int, gen *BlockGen) {
// tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1)
// gen.AddTx(tx)
// })
// require.NoError(err)
//
// // Insert and accept the generated chain
// _, err = blockchain.InsertChain(chain)
// require.NoError(err)
//
// for _, block := range chain {
// require.NoError(blockchain.Accept(block))
// }
// blockchain.DrainAcceptorQueue()
//
// awaitWatcherEventsSubside(trieCleanJournalWatcher, time.Second)
// // Assert that a new file is created in the trie clean journal
// dirEntries, err := os.ReadDir(trieCleanJournal)
// require.NoError(err)
// require.NotEmpty(dirEntries)
// }

func TestArchiveBlockChainSnapsDisabled(t *testing.T) {
create := func(db ethdb.Database, chainConfig *params.ChainConfig, lastAcceptedHash common.Hash) (*BlockChain, error) {
Expand Down

0 comments on commit f23fa80

Please sign in to comment.