celo-blockchain
celo-blockchain copied to clipboard
Add more tests to miner/worker.go
trafficstars
Description
Add more tests. Ideas for some tests to add:
- Check that the pending feed and pending block are properly set
- Check that new blocks and the start channel interrupt the current creation and that the next one starts
- Check that the txs subscription properly feeds into the pending state.
Context
We only test two cases
- That the system produces blocks with transactions (& that those transactions are included).
- Test that the miner does not submit multiple blocks at the same height to istanbul
Some ideas on testing and worker spec
spec:
// Worker Spec
// PUBLIC METHODS:
// start()
// stop()
// isRunning()
// close()
// setValidator/TxFeeRecipient/Extra()
// pending() & pendingBlock()
// LISTENS TO:
// txPool NewTxsEvent()
// blockchain ChainHeadEvent()
// EMITS:
// type.Mux => NewMinedBlockEvent(block)
// event.Feed => pendingLogsFeed
// STATES
// - Stopped
// - Started
// - Closed
cases
// When call start()
// If Stopped
// isRunning() == True
// should start working on a new block
// should start mining blocks (check more than one)
// pendingXXX() should return block currently being mined
// If Started
// isRunning() == True
// should NOT interrupt current block construction
// should keep mining blocks (check more than one)
// If Closed
// isRunning() == False
// should FAIL
// When call stop()
// If Stopped
// should do nothing
// If Started
// should stop mining
// should stop currently being mined block
// pendingXXX() should return pending block obtained from txsEvent transactions
// If Closed
// should FAIL
// When call close()
// If Stopped/Started
// should stop listening to all subscriptions
// should stop generating blocks
// If Closed
// should do nothing
// When new chainHead event
// If Stopped
// should interrupt currently being mined block
// should start new pending block
// If Started
// should interrupt currently being mined block
// should start new block and try to seal it
// If Closed
// should do nothing
// When new txsEvent
// If Stopped
// should include txs on currently pending block
// If Started
// should not block txsEvent emitter
// If Closed
// should do nothing
// When setXXX() is called
// On Any state
// should set XXX
// XXX should only be used on "next block"
// What happens with "pending block" since it's not constructed atomically?