diff --git a/abci/tests/server/client.go b/abci/tests/server/client.go index 10d4a3e58..3ccf715a6 100644 --- a/abci/tests/server/client.go +++ b/abci/tests/server/client.go @@ -51,20 +51,22 @@ func Commit(client abcicli.Client, hashExp []byte) error { return nil } -func DeliverTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) error { - res, _ := client.DeliverTxSync(ctx, types.RequestDeliverTx{Tx: txBytes}) - code, data, log := res.Code, res.Data, res.Log - if code != codeExp { - fmt.Println("Failed test: DeliverTx") - fmt.Printf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v\n", - code, codeExp, log) - return errors.New("deliverTx error") - } - if !bytes.Equal(data, dataExp) { - fmt.Println("Failed test: DeliverTx") - fmt.Printf("DeliverTx response data was unexpected. Got %X expected %X\n", - data, dataExp) - return errors.New("deliverTx error") +func FinalizeBlock(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) error { + res, _ := client.FinalizeBlockSync(ctx, types.RequestFinalizeBlock{Txs: [][]byte{txBytes}}) + for _, tx := range res.Txs { + code, data, log := tx.Code, tx.Data, tx.Log + if code != codeExp { + fmt.Println("Failed test: DeliverTx") + fmt.Printf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v\n", + code, codeExp, log) + return errors.New("deliverTx error") + } + if !bytes.Equal(data, dataExp) { + fmt.Println("Failed test: DeliverTx") + fmt.Printf("DeliverTx response data was unexpected. Got %X expected %X\n", + data, dataExp) + return errors.New("deliverTx error") + } } fmt.Println("Passed test: DeliverTx") return nil diff --git a/abci/tests/test_app/app.go b/abci/tests/test_app/app.go index faf4885de..261f411ac 100644 --- a/abci/tests/test_app/app.go +++ b/abci/tests/test_app/app.go @@ -37,16 +37,29 @@ func commit(client abcicli.Client, hashExp []byte) { } } -func deliverTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) { - res, err := client.DeliverTxSync(ctx, types.RequestDeliverTx{Tx: txBytes}) +type tx struct { + Data []byte + CodeExp uint32 + DataExp []byte +} + +func finalizeBlock(client abcicli.Client, txs []tx) { + var txsData = make([][]byte, len(txs)) + for i, tx := range txs { + txsData[i] = tx.Data + } + + res, err := client.FinalizeBlockSync(ctx, types.RequestFinalizeBlock{Txs: txsData}) if err != nil { panicf("client error: %v", err) } - if res.Code != codeExp { - panicf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v", res.Code, codeExp, res.Log) - } - if !bytes.Equal(res.Data, dataExp) { - panicf("DeliverTx response data was unexpected. Got %X expected %X", res.Data, dataExp) + for i, tx := range res.Txs { + if tx.Code != txs[i].CodeExp { + panicf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v", tx.Code, txs[i].CodeExp, tx.Log) + } + if !bytes.Equal(tx.Data, txs[i].DataExp) { + panicf("DeliverTx response data was unexpected. Got %X expected %X", tx.Data, txs[i].DataExp) + } } } diff --git a/abci/tests/test_app/main.go b/abci/tests/test_app/main.go index 011793888..dfe55825f 100644 --- a/abci/tests/test_app/main.go +++ b/abci/tests/test_app/main.go @@ -81,13 +81,15 @@ func testCounter() { // commit(client, nil) // deliverTx(client, []byte("abc"), code.CodeTypeBadNonce, nil) commit(client, nil) - deliverTx(client, []byte{0x00}, types.CodeTypeOK, nil) + finalizeBlock(client, []tx{{Data: []byte{0x00}, CodeExp: types.CodeTypeOK, DataExp: nil}}) commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1}) // deliverTx(client, []byte{0x00}, code.CodeTypeBadNonce, nil) - deliverTx(client, []byte{0x01}, types.CodeTypeOK, nil) - deliverTx(client, []byte{0x00, 0x02}, types.CodeTypeOK, nil) - deliverTx(client, []byte{0x00, 0x03}, types.CodeTypeOK, nil) - deliverTx(client, []byte{0x00, 0x00, 0x04}, types.CodeTypeOK, nil) + txs := []tx{ + {Data: []byte{0x01}, DataExp: nil, CodeExp: types.CodeTypeOK}, + {Data: []byte{0x00, 0x02}, DataExp: nil, CodeExp: types.CodeTypeOK}, + {Data: []byte{0x00, 0x03}, DataExp: nil, CodeExp: types.CodeTypeOK}, + {Data: []byte{0x00, 0x00, 0x04}, DataExp: nil, CodeExp: types.CodeTypeOK}} + finalizeBlock(client, txs) // deliverTx(client, []byte{0x00, 0x00, 0x06}, code.CodeTypeBadNonce, nil) commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 5}) } diff --git a/internal/mempool/v0/clist_mempool_test.go b/internal/mempool/v0/clist_mempool_test.go index 8244817b0..7fda6712c 100644 --- a/internal/mempool/v0/clist_mempool_test.go +++ b/internal/mempool/v0/clist_mempool_test.go @@ -362,7 +362,7 @@ func TestSerialReap(t *testing.T) { commitRange := func(start, end int) { ctx := context.Background() // Deliver some txs. - var txs = make([][]byte, start-end) + var txs = make([][]byte, end) for i := start; i < end; i++ { txBytes := make([]byte, 8) binary.BigEndian.PutUint64(txBytes, uint64(i)) @@ -409,7 +409,7 @@ func TestSerialReap(t *testing.T) { // Reap again. We should get the same amount reapCheck(1000) - // Commit from the conensus AppConn + // Commit from the consensus AppConn commitRange(0, 500) updateRange(0, 500) diff --git a/state/execution.go b/state/execution.go index afa105982..68012735b 100644 --- a/state/execution.go +++ b/state/execution.go @@ -300,6 +300,7 @@ func execBlockOnProxyApp( var validTxs, invalidTxs = 0, 0 abciResponses := new(tmstate.ABCIResponses) + abciResponses.FinalizeBlock = &abci.ResponseFinalizeBlock{} dtxs := make([]*abci.ResponseDeliverTx, len(block.Txs)) abciResponses.FinalizeBlock.Txs = dtxs @@ -525,14 +526,16 @@ func fireEvents( } } - for i, tx := range block.Data.Txs { - if err := eventBus.PublishEventTx(types.EventDataTx{TxResult: abci.TxResult{ - Height: block.Height, - Index: uint32(i), - Tx: tx, - Result: *(abciResponses.FinalizeBlock.Txs[i]), - }}); err != nil { - logger.Error("failed publishing event TX", "err", err) + if len(abciResponses.FinalizeBlock.Txs) != 0 { + for i, tx := range block.Data.Txs { + if err := eventBus.PublishEventTx(types.EventDataTx{TxResult: abci.TxResult{ + Height: block.Height, + Index: uint32(i), + Tx: tx, + Result: *(abciResponses.FinalizeBlock.Txs[i]), + }}); err != nil { + logger.Error("failed publishing event TX", "err", err) + } } }