check duplicates of different types in txrecords

This commit is contained in:
William Banfield
2022-03-11 11:55:59 -05:00
parent 3c35f894f3
commit 6ce11e5e5e
2 changed files with 29 additions and 4 deletions
+4 -4
View File
@@ -264,11 +264,11 @@ func (rpp *ResponsePrepareProposal) Validate(maxSizeBytes int64, otxs [][]byte)
if size > maxSizeBytes {
return fmt.Errorf("transaction data size %d exceeds maximum %d", size, maxSizeBytes)
}
if _, ok := ntx[string(tr.Tx)]; ok {
return errors.New("duplicate included transaction")
}
ntx[string(tr.Tx)] = struct{}{}
}
if _, ok := ntx[string(tr.Tx)]; ok {
return errors.New("TxRecords contains duplicate transaction")
}
ntx[string(tr.Tx)] = struct{}{}
if _, ok := otxsSet[string(tr.Tx)]; ok {
if tr.Action == TxRecord_ADDED {
return fmt.Errorf("unmodified transaction incorrectly marked as %s", tr.Action.String())
+25
View File
@@ -87,6 +87,31 @@ func TestValidateResponsePrepareProposal(t *testing.T) {
err := rpp.Validate(100, [][]byte{})
require.Error(t, err)
})
t.Run("should error on duplicate transactions", func(t *testing.T) {
rpp := &abci.ResponsePrepareProposal{
ModifiedTx: true,
TxRecords: []*abci.TxRecord{
{
Action: abci.TxRecord_ADDED,
Tx: []byte{1, 2, 3, 4, 5},
},
{
Action: abci.TxRecord_ADDED,
Tx: []byte{100},
},
{
Action: abci.TxRecord_REMOVED,
Tx: []byte{1, 2, 3, 4, 5},
},
{
Action: abci.TxRecord_ADDED,
Tx: []byte{200},
},
},
}
err := rpp.Validate(100, [][]byte{})
require.Error(t, err)
})
t.Run("should error on new transactions marked UNMODIFIED", func(t *testing.T) {
rpp := &abci.ResponsePrepareProposal{
ModifiedTx: true,