mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-11 18:46:12 +00:00
add test for preserving order
This commit is contained in:
+3
-2
@@ -243,8 +243,9 @@ func sortedCopy(txs Txs) Txs {
|
||||
// Both lists must be sorted.
|
||||
func containsAnyTxs(a, b []Tx) (int, bool) {
|
||||
aix, bix := 0, 0
|
||||
|
||||
nextA:
|
||||
for ; aix < len(a); aix++ {
|
||||
LOOP:
|
||||
for bix < len(b) {
|
||||
switch bytes.Compare(b[bix], a[aix]) {
|
||||
case 0:
|
||||
@@ -259,7 +260,7 @@ func containsAnyTxs(a, b []Tx) (int, bool) {
|
||||
return -1, false
|
||||
}
|
||||
case 1:
|
||||
break LOOP
|
||||
continue nextA
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,4 +158,42 @@ func TestValidateTxRecordSet(t *testing.T) {
|
||||
err := txrSet.Validate(100, []Tx{})
|
||||
require.Error(t, err)
|
||||
})
|
||||
t.Run("TxRecordSet preserves order", func(t *testing.T) {
|
||||
trs := []*abci.TxRecord{
|
||||
{
|
||||
Action: abci.TxRecord_ADDED,
|
||||
Tx: Tx([]byte{100}),
|
||||
},
|
||||
{
|
||||
Action: abci.TxRecord_ADDED,
|
||||
Tx: Tx([]byte{99}),
|
||||
},
|
||||
{
|
||||
Action: abci.TxRecord_ADDED,
|
||||
Tx: Tx([]byte{55}),
|
||||
},
|
||||
{
|
||||
Action: abci.TxRecord_ADDED,
|
||||
Tx: Tx([]byte{12}),
|
||||
},
|
||||
{
|
||||
Action: abci.TxRecord_ADDED,
|
||||
Tx: Tx([]byte{66}),
|
||||
},
|
||||
{
|
||||
Action: abci.TxRecord_ADDED,
|
||||
Tx: Tx([]byte{9}),
|
||||
},
|
||||
{
|
||||
Action: abci.TxRecord_ADDED,
|
||||
Tx: Tx([]byte{17}),
|
||||
},
|
||||
}
|
||||
txrSet := NewTxRecordSet(trs)
|
||||
err := txrSet.Validate(100, []Tx{})
|
||||
require.NoError(t, err)
|
||||
for i, tx := range txrSet.IncludedTxs() {
|
||||
require.Equal(t, Tx(trs[i].Tx), tx)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user