Browse Source

Merge branch 'master' into testing-logger-cleanup

pull/8153/head
Sam Kleinman 3 years ago
committed by GitHub
parent
commit
5656fc0532
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 6 deletions
  1. +5
    -5
      internal/mempool/reactor_test.go
  2. +1
    -1
      internal/state/execution.go
  3. +58
    -0
      internal/state/execution_test.go

+ 5
- 5
internal/mempool/reactor_test.go View File

@ -139,14 +139,14 @@ func (rts *reactorTestSuite) waitForTxns(t *testing.T, txs []types.Tx, ids ...ty
} }
wg.Add(1) wg.Add(1)
go func(pool *TxMempool) {
go func(name types.NodeID, pool *TxMempool) {
defer wg.Done() defer wg.Done()
require.Eventually(t, func() bool { return len(txs) == pool.Size() }, require.Eventually(t, func() bool { return len(txs) == pool.Size() },
time.Minute, time.Minute,
250*time.Millisecond, 250*time.Millisecond,
"ntx=%d, size=%d", len(txs), pool.Size(),
"node=%q, ntx=%d, size=%d", name, len(txs), pool.Size(),
) )
}(pool)
}(name, pool)
} }
wg.Wait() wg.Wait()
} }
@ -196,8 +196,8 @@ func TestReactorBroadcastDoesNotPanic(t *testing.T) {
} }
func TestReactorBroadcastTxs(t *testing.T) { func TestReactorBroadcastTxs(t *testing.T) {
numTxs := 1000
numNodes := 10
numTxs := 512
numNodes := 4
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()


+ 1
- 1
internal/state/execution.go View File

@ -147,7 +147,7 @@ func (blockExec *BlockExecutor) CreateProposalBlock(
txrSet := types.NewTxRecordSet(rpp.TxRecords) txrSet := types.NewTxRecordSet(rpp.TxRecords)
if err := txrSet.Validate(maxDataBytes, block.Txs); err != nil { if err := txrSet.Validate(maxDataBytes, block.Txs); err != nil {
return nil, err
panic(fmt.Errorf("ResponsePrepareProposal validation: %w", err))
} }
for _, rtx := range txrSet.RemovedTxs() { for _, rtx := range txrSet.RemovedTxs() {


+ 58
- 0
internal/state/execution_test.go View File

@ -650,6 +650,64 @@ func TestEmptyPrepareProposal(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
} }
// TestPrepareProposalPanicOnInvalid tests that the block creation logic panics
// if the ResponsePrepareProposal returned from the application is invalid.
func TestPrepareProposalPanicOnInvalid(t *testing.T) {
const height = 2
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := log.TestingLogger()
eventBus := eventbus.NewDefault(logger)
require.NoError(t, eventBus.Start(ctx))
state, stateDB, privVals := makeState(t, 1, height)
stateStore := sm.NewStore(stateDB)
evpool := &mocks.EvidencePool{}
evpool.On("PendingEvidence", mock.Anything).Return([]types.Evidence{}, int64(0))
mp := &mpmocks.Mempool{}
mp.On("ReapMaxBytesMaxGas", mock.Anything, mock.Anything).Return(types.Txs{})
app := abcimocks.NewBaseMock()
// create an invalid ResponsePrepareProposal
rpp := abci.ResponsePrepareProposal{
ModifiedTx: true,
TxRecords: []*abci.TxRecord{
{
Action: abci.TxRecord_REMOVED,
Tx: []byte("new tx"),
},
},
}
app.On("PrepareProposal", mock.Anything).Return(rpp, nil)
cc := abciclient.NewLocalClient(logger, app)
proxyApp := proxy.New(cc, logger, proxy.NopMetrics())
err := proxyApp.Start(ctx)
require.NoError(t, err)
blockExec := sm.NewBlockExecutor(
stateStore,
logger,
proxyApp,
mp,
evpool,
nil,
eventBus,
)
pa, _ := state.Validators.GetByIndex(0)
commit := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals)
require.Panics(t,
func() {
blockExec.CreateProposalBlock(ctx, height, state, commit, pa, nil) //nolint:errcheck
})
mp.AssertExpectations(t)
}
// TestPrepareProposalRemoveTxs tests that any transactions marked as REMOVED // TestPrepareProposalRemoveTxs tests that any transactions marked as REMOVED
// are not included in the block produced by CreateProposalBlock. The test also // are not included in the block produced by CreateProposalBlock. The test also
// ensures that any transactions removed are also removed from the mempool. // ensures that any transactions removed are also removed from the mempool.


Loading…
Cancel
Save