Browse Source

check duplicates of different types in txrecords

wb/txrset
William Banfield 2 years ago
parent
commit
6ce11e5e5e
No known key found for this signature in database GPG Key ID: EFAD3442BF29E3AC
2 changed files with 29 additions and 4 deletions
  1. +4
    -4
      abci/types/types.go
  2. +25
    -0
      abci/types/types_test.go

+ 4
- 4
abci/types/types.go 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
- 0
abci/types/types_test.go 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,


Loading…
Cancel
Save