From 7d5b3f9b0e3f06e630dfb5ad7fd882d7c0ded39d Mon Sep 17 00:00:00 2001 From: tnasu Date: Mon, 19 Jun 2023 23:10:02 +0900 Subject: [PATCH] (fixup) Test the reverted CheckTxSync callback parameter from https://github.com/Finschia/ostracon/pull/163/files#diff-eafa5360d0b71c14dba6ad5b29be23f69f0fe93e0751fe89fe208a5dafcfbbcf --- consensus/mempool_test.go | 2 +- consensus/reactor_test.go | 4 +-- consensus/replay_test.go | 12 ++++----- mempool/bench_test.go | 4 +-- mempool/cache_test.go | 4 +-- mempool/clist_mempool_test.go | 46 +++++++++++++++++------------------ mempool/mock/mempool.go | 4 +-- mempool/reactor_test.go | 4 +-- node/node_test.go | 4 +-- test/fuzz/mempool/checktx.go | 2 +- 10 files changed, 43 insertions(+), 43 deletions(-) diff --git a/consensus/mempool_test.go b/consensus/mempool_test.go index 8bcde0b71..9be7d0e87 100644 --- a/consensus/mempool_test.go +++ b/consensus/mempool_test.go @@ -105,7 +105,7 @@ func deliverTxsRange(cs *State, start, end int) { for i := start; i < end; i++ { txBytes := make([]byte, 8) binary.BigEndian.PutUint64(txBytes, uint64(i)) - _, err := assertMempool(cs.txNotifier).CheckTxSync(txBytes, mempl.TxInfo{}) + err := assertMempool(cs.txNotifier).CheckTxSync(txBytes, nil, mempl.TxInfo{}) if err != nil { panic(fmt.Sprintf("Error after CheckTx: %v", err)) } diff --git a/consensus/reactor_test.go b/consensus/reactor_test.go index 690fb1489..90052789e 100644 --- a/consensus/reactor_test.go +++ b/consensus/reactor_test.go @@ -221,7 +221,7 @@ func TestReactorCreatesBlockWhenEmptyBlocksFalse(t *testing.T) { defer stopConsensusNet(log.TestingLogger(), reactors, eventBuses) // send a tx - if _, err := assertMempool(css[3].txNotifier).CheckTxSync([]byte{1, 2, 3}, mempl.TxInfo{}); err != nil { + if err := assertMempool(css[3].txNotifier).CheckTxSync([]byte{1, 2, 3}, nil, mempl.TxInfo{}); err != nil { t.Error(err) } @@ -549,7 +549,7 @@ func waitForAndValidateBlock( err := validateBlock(newBlock, activeVals) assert.Nil(t, err) for _, tx := range txs { - _, err := assertMempool(css[j].txNotifier).CheckTxSync(tx, mempl.TxInfo{}) + err := assertMempool(css[j].txNotifier).CheckTxSync(tx, nil, mempl.TxInfo{}) assert.Nil(t, err) } }, css) diff --git a/consensus/replay_test.go b/consensus/replay_test.go index 5582faab2..4b46cb949 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -121,7 +121,7 @@ func sendTxs(ctx context.Context, cs *State) { return default: tx := []byte{byte(i)} - if _, err := assertMempool(cs.txNotifier).CheckTxSync(tx, mempl.TxInfo{}); err != nil { + if err := assertMempool(cs.txNotifier).CheckTxSync(tx, nil, mempl.TxInfo{}); err != nil { panic(err) } i++ @@ -471,7 +471,7 @@ func TestSimulateValidatorsChange(t *testing.T) { valPubKey1ABCI, err := cryptoenc.PubKeyToProto(newValidatorPubKey1) assert.Nil(t, err) newValidatorTx1 := kvstore.MakeValSetChangeTx(valPubKey1ABCI, testMinPower) - _, err = assertMempool(css[0].txNotifier).CheckTxSync(newValidatorTx1, mempl.TxInfo{}) + err = assertMempool(css[0].txNotifier).CheckTxSync(newValidatorTx1, nil, mempl.TxInfo{}) assert.Nil(t, err) }) @@ -485,7 +485,7 @@ func TestSimulateValidatorsChange(t *testing.T) { updatePubKey1ABCI, err := cryptoenc.PubKeyToProto(updateValidatorPubKey1) require.NoError(t, err) updateValidatorTx1 := kvstore.MakeValSetChangeTx(updatePubKey1ABCI, 25) - _, err = assertMempool(css[0].txNotifier).CheckTxSync(updateValidatorTx1, mempl.TxInfo{}) + err = assertMempool(css[0].txNotifier).CheckTxSync(updateValidatorTx1, nil, mempl.TxInfo{}) assert.Nil(t, err) }) @@ -502,14 +502,14 @@ func TestSimulateValidatorsChange(t *testing.T) { newVal2ABCI, err := cryptoenc.PubKeyToProto(newValidatorPubKey2) require.NoError(t, err) newValidatorTx2 := kvstore.MakeValSetChangeTx(newVal2ABCI, testMinPower) - _, err = assertMempool(css[0].txNotifier).CheckTxSync(newValidatorTx2, mempl.TxInfo{}) + err = assertMempool(css[0].txNotifier).CheckTxSync(newValidatorTx2, nil, mempl.TxInfo{}) assert.Nil(t, err) newValidatorPubKey3, err := css[nVals+2].privValidator.GetPubKey() require.NoError(t, err) newVal3ABCI, err := cryptoenc.PubKeyToProto(newValidatorPubKey3) require.NoError(t, err) newValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, testMinPower) - _, err = assertMempool(css[0].txNotifier).CheckTxSync(newValidatorTx3, mempl.TxInfo{}) + err = assertMempool(css[0].txNotifier).CheckTxSync(newValidatorTx3, nil, mempl.TxInfo{}) assert.Nil(t, err) }) @@ -549,7 +549,7 @@ func TestSimulateValidatorsChange(t *testing.T) { newVal3ABCI, err := cryptoenc.PubKeyToProto(newValidatorPubKey3) require.NoError(t, err) removeValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, 0) - _, err = assertMempool(css[0].txNotifier).CheckTxSync(removeValidatorTx3, mempl.TxInfo{}) + err = assertMempool(css[0].txNotifier).CheckTxSync(removeValidatorTx3, nil, mempl.TxInfo{}) assert.Nil(t, err) }) diff --git a/mempool/bench_test.go b/mempool/bench_test.go index 4e2fa92dd..9feb8be6c 100644 --- a/mempool/bench_test.go +++ b/mempool/bench_test.go @@ -18,7 +18,7 @@ func BenchmarkReap(b *testing.B) { for i := 0; i < size; i++ { tx := make([]byte, 8) binary.BigEndian.PutUint64(tx, uint64(i)) - mempool.CheckTxSync(tx, TxInfo{}) // nolint: errcheck + mempool.CheckTxSync(tx, nil, TxInfo{}) // nolint: errcheck } b.ResetTimer() for i := 0; i < b.N; i++ { @@ -53,7 +53,7 @@ func BenchmarkCheckTxSync(b *testing.B) { for i := 0; i < b.N; i++ { tx := make([]byte, 8) binary.BigEndian.PutUint64(tx, uint64(i)) - mempool.CheckTxSync(tx, TxInfo{}) // nolint: errcheck + mempool.CheckTxSync(tx, nil, TxInfo{}) // nolint: errcheck } } diff --git a/mempool/cache_test.go b/mempool/cache_test.go index ce72b27a9..236e87c1f 100644 --- a/mempool/cache_test.go +++ b/mempool/cache_test.go @@ -59,7 +59,7 @@ func TestCacheAfterUpdate(t *testing.T) { for tcIndex, tc := range tests { for i := 0; i < tc.numTxsToCreate; i++ { tx := types.Tx{byte(i)} - _, err := mempool.CheckTxSync(tx, TxInfo{}) + err := mempool.CheckTxSync(tx, nil, TxInfo{}) require.NoError(t, err) } @@ -74,7 +74,7 @@ func TestCacheAfterUpdate(t *testing.T) { for _, v := range tc.reAddIndices { tx := types.Tx{byte(v)} - _, _ = mempool.CheckTxSync(tx, TxInfo{}) + _ = mempool.CheckTxSync(tx, nil, TxInfo{}) } cache := mempool.cache.(*mapTxCache) diff --git a/mempool/clist_mempool_test.go b/mempool/clist_mempool_test.go index 81c1c861f..74e498f1f 100644 --- a/mempool/clist_mempool_test.go +++ b/mempool/clist_mempool_test.go @@ -81,7 +81,7 @@ func checkTxs(t *testing.T, mempool Mempool, count int, peerID uint16) types.Txs if err != nil { t.Error(err) } - if _, err := mempool.CheckTxSync(txBytes, txInfo); err != nil { + if err := mempool.CheckTxSync(txBytes, nil, txInfo); err != nil { // Skip invalid txs. // TestMempoolFilters will fail otherwise. It asserts a number of txs // returned. @@ -196,7 +196,7 @@ func TestMempoolUpdate(t *testing.T) { err := mempool.Update(newTestBlock(1, []types.Tx{[]byte{0x01}}), abciResponses(1, ocabci.CodeTypeOK), nil, nil) require.NoError(t, err) - _, err = mempool.CheckTxSync([]byte{0x01}, TxInfo{}) + err = mempool.CheckTxSync([]byte{0x01}, nil, TxInfo{}) if assert.Error(t, err) { assert.Equal(t, ErrTxInCache, err) } @@ -204,7 +204,7 @@ func TestMempoolUpdate(t *testing.T) { // 2. Removes valid txs from the mempool { - _, err := mempool.CheckTxSync([]byte{0x02}, TxInfo{}) + err := mempool.CheckTxSync([]byte{0x02}, nil, TxInfo{}) require.NoError(t, err) err = mempool.Update(newTestBlock(1, []types.Tx{[]byte{0x02}}), abciResponses(1, ocabci.CodeTypeOK), nil, nil) require.NoError(t, err) @@ -213,13 +213,13 @@ func TestMempoolUpdate(t *testing.T) { // 3. Removes invalid transactions from the cache and the mempool (if present) { - _, err := mempool.CheckTxSync([]byte{0x03}, TxInfo{}) + err := mempool.CheckTxSync([]byte{0x03}, nil, TxInfo{}) require.NoError(t, err) err = mempool.Update(newTestBlock(1, []types.Tx{[]byte{0x03}}), abciResponses(1, 1), nil, nil) require.NoError(t, err) assert.Zero(t, mempool.Size()) - _, err = mempool.CheckTxSync([]byte{0x03}, TxInfo{}) + err = mempool.CheckTxSync([]byte{0x03}, nil, TxInfo{}) require.NoError(t, err) } } @@ -240,7 +240,7 @@ func TestMempool_KeepInvalidTxsInCache(t *testing.T) { b := make([]byte, 8) binary.BigEndian.PutUint64(b, 1) - _, err := mempool.CheckTxSync(b, TxInfo{}) + err := mempool.CheckTxSync(b, nil, TxInfo{}) require.NoError(t, err) // simulate new block @@ -251,13 +251,13 @@ func TestMempool_KeepInvalidTxsInCache(t *testing.T) { require.NoError(t, err) // a must be added to the cache - _, err = mempool.CheckTxSync(a, TxInfo{}) + err = mempool.CheckTxSync(a, nil, TxInfo{}) if assert.Error(t, err) { assert.Equal(t, ErrTxInCache, err) } // b must remain in the cache - _, err = mempool.CheckTxSync(b, TxInfo{}) + err = mempool.CheckTxSync(b, nil, TxInfo{}) if assert.Error(t, err) { assert.Equal(t, ErrTxInCache, err) } @@ -271,10 +271,10 @@ func TestMempool_KeepInvalidTxsInCache(t *testing.T) { // remove a from the cache to test (2) mempool.cache.Remove(a) - _, err := mempool.CheckTxSync(a, TxInfo{}) + err := mempool.CheckTxSync(a, nil, TxInfo{}) require.NoError(t, err) - _, err = mempool.CheckTxSync(a, TxInfo{}) + err = mempool.CheckTxSync(a, nil, TxInfo{}) if assert.Error(t, err) { assert.Equal(t, ErrTxInCache, err) } @@ -348,7 +348,7 @@ func TestSerialReap(t *testing.T) { // This will succeed txBytes := make([]byte, 8) binary.BigEndian.PutUint64(txBytes, uint64(i)) - _, err := mempool.CheckTxSync(txBytes, TxInfo{}) + err := mempool.CheckTxSync(txBytes, nil, TxInfo{}) _, cached := cacheMap[string(txBytes)] if cached { require.NotNil(t, err, "expected error for cached tx") @@ -358,7 +358,7 @@ func TestSerialReap(t *testing.T) { cacheMap[string(txBytes)] = struct{}{} // Duplicates are cached and should return error - _, err = mempool.CheckTxSync(txBytes, TxInfo{}) + err = mempool.CheckTxSync(txBytes, nil, TxInfo{}) require.NotNil(t, err, "Expected error after CheckTx on duplicated tx") } } @@ -466,7 +466,7 @@ func TestMempoolCloseWAL(t *testing.T) { require.Equal(t, 1, len(m2), "expecting the wal match in") // 5. Write some contents to the WAL - _, err = mempool.CheckTxSync(types.Tx([]byte("foo")), TxInfo{}) + err = mempool.CheckTxSync(types.Tx([]byte("foo")), nil, TxInfo{}) require.NoError(t, err) walFilepath := mempool.wal.Path sum1 := checksumFile(walFilepath, t) @@ -477,7 +477,7 @@ func TestMempoolCloseWAL(t *testing.T) { // 7. Invoke CloseWAL() and ensure it discards the // WAL thus any other write won't go through. mempool.CloseWAL() - _, err = mempool.CheckTxSync(types.Tx([]byte("bar")), TxInfo{}) + err = mempool.CheckTxSync(types.Tx([]byte("bar")), nil, TxInfo{}) require.NoError(t, err) sum2 := checksumFile(walFilepath, t) require.Equal(t, sum1, sum2, "expected no change to the WAL after invoking CloseWAL() since it was discarded") @@ -516,7 +516,7 @@ func TestMempool_CheckTxChecksTxSize(t *testing.T) { tx := tmrand.Bytes(testCase.len) - _, err := mempl.CheckTxSync(tx, TxInfo{}) + err := mempl.CheckTxSync(tx, nil, TxInfo{}) bv := gogotypes.BytesValue{Value: tx} bz, err2 := bv.Marshal() require.NoError(t, err2) @@ -542,7 +542,7 @@ func TestMempoolTxsBytes(t *testing.T) { assert.EqualValues(t, 0, mempool.TxsBytes()) // 2. len(tx) after CheckTx - _, err := mempool.CheckTxSync([]byte{0x01}, TxInfo{}) + err := mempool.CheckTxSync([]byte{0x01}, nil, TxInfo{}) require.NoError(t, err) assert.EqualValues(t, 1, mempool.TxsBytes()) @@ -553,7 +553,7 @@ func TestMempoolTxsBytes(t *testing.T) { assert.EqualValues(t, 0, mempool.TxsBytes()) // 4. zero after Flush - _, err = mempool.CheckTxSync([]byte{0x02, 0x03}, TxInfo{}) + err = mempool.CheckTxSync([]byte{0x02, 0x03}, nil, TxInfo{}) require.NoError(t, err) assert.EqualValues(t, 2, mempool.TxsBytes()) @@ -561,9 +561,9 @@ func TestMempoolTxsBytes(t *testing.T) { assert.EqualValues(t, 0, mempool.TxsBytes()) // 5. ErrMempoolIsFull is returned when/if MaxTxsBytes limit is reached. - _, err = mempool.CheckTxSync([]byte{0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04}, TxInfo{}) + err = mempool.CheckTxSync([]byte{0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04}, nil, TxInfo{}) require.NoError(t, err) - _, err = mempool.CheckTxSync([]byte{0x05}, TxInfo{}) + err = mempool.CheckTxSync([]byte{0x05}, nil, TxInfo{}) if assert.Error(t, err) { assert.IsType(t, ErrMempoolIsFull{}, err) } @@ -577,7 +577,7 @@ func TestMempoolTxsBytes(t *testing.T) { txBytes := make([]byte, 8) binary.BigEndian.PutUint64(txBytes, uint64(0)) - _, err = mempool.CheckTxSync(txBytes, TxInfo{}) + err = mempool.CheckTxSync(txBytes, nil, TxInfo{}) require.NoError(t, err) assert.EqualValues(t, 8, mempool.TxsBytes()) @@ -603,7 +603,7 @@ func TestMempoolTxsBytes(t *testing.T) { assert.EqualValues(t, 0, mempool.TxsBytes()) // 7. Test RemoveTxByKey function - _, err = mempool.CheckTxSync([]byte{0x06}, TxInfo{}) + err = mempool.CheckTxSync([]byte{0x06}, nil, TxInfo{}) require.NoError(t, err) assert.EqualValues(t, 1, mempool.TxsBytes()) mempool.RemoveTxByKey(TxKey([]byte{0x07}), true) @@ -647,7 +647,7 @@ func TestMempoolRemoteAppConcurrency(t *testing.T) { tx := txs[txNum] // this will err with ErrTxInCache many times ... - mempool.CheckTxSync(tx, TxInfo{SenderID: uint16(peerID)}) // nolint: errcheck + mempool.CheckTxSync(tx, nil, TxInfo{SenderID: uint16(peerID)}) // nolint: errcheck } err := mempool.FlushAppConn() require.NoError(t, err) @@ -731,7 +731,7 @@ func TestTxMempoolPostCheckError(t *testing.T) { } tx := types.Tx{1} - _, err := mempool.CheckTxSync(tx, TxInfo{}) + err := mempool.CheckTxSync(tx, nil, TxInfo{}) require.NoError(t, err) req := abci.RequestCheckTx{ diff --git a/mempool/mock/mempool.go b/mempool/mock/mempool.go index 163646c25..87490c571 100644 --- a/mempool/mock/mempool.go +++ b/mempool/mock/mempool.go @@ -17,8 +17,8 @@ var _ mempl.Mempool = Mempool{} func (Mempool) Lock() {} func (Mempool) Unlock() {} func (Mempool) Size() int { return 0 } -func (Mempool) CheckTxSync(_ types.Tx, _ mempl.TxInfo) (*ocabci.Response, error) { - return nil, nil +func (Mempool) CheckTxSync(_ types.Tx, _ func(*ocabci.Response), _ mempl.TxInfo) error { + return nil } func (Mempool) CheckTxAsync(_ types.Tx, _ mempl.TxInfo, _ func(error), _ func(*ocabci.Response)) { } diff --git a/mempool/reactor_test.go b/mempool/reactor_test.go index 63d2ab438..031e24e6b 100644 --- a/mempool/reactor_test.go +++ b/mempool/reactor_test.go @@ -177,7 +177,7 @@ func TestReactor_MaxTxBytes(t *testing.T) { // Broadcast a tx, which has the max size // => ensure it's received by the second reactor. tx1 := tmrand.Bytes(config.Mempool.MaxTxBytes) - _, err := reactors[0].mempool.CheckTxSync(tx1, TxInfo{SenderID: UnknownPeerID}) + err := reactors[0].mempool.CheckTxSync(tx1, nil, TxInfo{SenderID: UnknownPeerID}) require.NoError(t, err) waitForTxsOnReactors(t, []types.Tx{tx1}, reactors) @@ -187,7 +187,7 @@ func TestReactor_MaxTxBytes(t *testing.T) { // Broadcast a tx, which is beyond the max size // => ensure it's not sent tx2 := tmrand.Bytes(config.Mempool.MaxTxBytes + 1) - _, err = reactors[0].mempool.CheckTxSync(tx2, TxInfo{SenderID: UnknownPeerID}) + err = reactors[0].mempool.CheckTxSync(tx2, nil, TxInfo{SenderID: UnknownPeerID}) require.Error(t, err) } diff --git a/node/node_test.go b/node/node_test.go index 2ca318cc5..9f5587b24 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -303,7 +303,7 @@ func TestCreateProposalBlock(t *testing.T) { txLength := 100 for i := 0; i <= maxBytes/txLength; i++ { tx := tmrand.Bytes(txLength) - _, err := mempool.CheckTxSync(tx, mempl.TxInfo{}) + err := mempool.CheckTxSync(tx, nil, mempl.TxInfo{}) assert.NoError(t, err) } @@ -377,7 +377,7 @@ func TestMaxProposalBlockSize(t *testing.T) { // fill the mempool with one txs just below the maximum size txLength := int(types.MaxDataBytesNoEvidence(maxBytes, 1)) tx := tmrand.Bytes(txLength - 4) // to account for the varint - _, err = mempool.CheckTxSync(tx, mempl.TxInfo{}) + err = mempool.CheckTxSync(tx, nil, mempl.TxInfo{}) assert.NoError(t, err) blockExec := sm.NewBlockExecutor( diff --git a/test/fuzz/mempool/checktx.go b/test/fuzz/mempool/checktx.go index 31c139ee7..53269b6ae 100644 --- a/test/fuzz/mempool/checktx.go +++ b/test/fuzz/mempool/checktx.go @@ -25,7 +25,7 @@ func init() { } func Fuzz(data []byte) int { - _, err := mempool.CheckTxSync(data, mempl.TxInfo{}) + err := mempool.CheckTxSync(data, nil, mempl.TxInfo{}) if err != nil { return 0 }