|
|
@ -1,7 +1,6 @@ |
|
|
|
package types_test |
|
|
|
|
|
|
|
import ( |
|
|
|
fmt "fmt" |
|
|
|
"testing" |
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
@ -71,127 +70,3 @@ func TestHashDeterministicFieldsOnly(t *testing.T) { |
|
|
|
require.NoError(t, err) |
|
|
|
require.Equal(t, merkle.HashFromByteSlices(r1), merkle.HashFromByteSlices(r2)) |
|
|
|
} |
|
|
|
|
|
|
|
func TestValidateResponsePrepareProposal(t *testing.T) { |
|
|
|
t.Run("should error on total transaction size exceeding max data size", 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{6, 7, 8, 9, 10}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
err := rpp.Validate(9, [][]byte{}) |
|
|
|
require.Error(t, err) |
|
|
|
}) |
|
|
|
t.Run("should error on duplicate transactions with the same action", 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_ADDED, |
|
|
|
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 duplicate transactions with mixed actions", 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, |
|
|
|
TxRecords: []*abci.TxRecord{ |
|
|
|
{ |
|
|
|
Action: abci.TxRecord_UNMODIFIED, |
|
|
|
Tx: []byte{1, 2, 3, 4, 5}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
err := rpp.Validate(100, [][]byte{}) |
|
|
|
fmt.Println(err) |
|
|
|
require.Error(t, err) |
|
|
|
}) |
|
|
|
t.Run("should error on new transactions marked REMOVED", func(t *testing.T) { |
|
|
|
rpp := &abci.ResponsePrepareProposal{ |
|
|
|
ModifiedTx: true, |
|
|
|
TxRecords: []*abci.TxRecord{ |
|
|
|
{ |
|
|
|
Action: abci.TxRecord_REMOVED, |
|
|
|
Tx: []byte{1, 2, 3, 4, 5}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
err := rpp.Validate(100, [][]byte{}) |
|
|
|
fmt.Println(err) |
|
|
|
require.Error(t, err) |
|
|
|
}) |
|
|
|
t.Run("should error on existing transaction marked as ADDED", func(t *testing.T) { |
|
|
|
rpp := &abci.ResponsePrepareProposal{ |
|
|
|
ModifiedTx: true, |
|
|
|
TxRecords: []*abci.TxRecord{ |
|
|
|
{ |
|
|
|
Action: abci.TxRecord_ADDED, |
|
|
|
Tx: []byte{1, 2, 3, 4, 5}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
err := rpp.Validate(100, [][]byte{{1, 2, 3, 4, 5}}) |
|
|
|
require.Error(t, err) |
|
|
|
}) |
|
|
|
t.Run("should error if any transaction marked as UNKNOWN", func(t *testing.T) { |
|
|
|
rpp := &abci.ResponsePrepareProposal{ |
|
|
|
ModifiedTx: true, |
|
|
|
TxRecords: []*abci.TxRecord{ |
|
|
|
{ |
|
|
|
Action: abci.TxRecord_UNKNOWN, |
|
|
|
Tx: []byte{1, 2, 3, 4, 5}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
err := rpp.Validate(100, [][]byte{}) |
|
|
|
require.Error(t, err) |
|
|
|
}) |
|
|
|
} |