add test for preserving order

This commit is contained in:
William Banfield
2022-03-15 00:32:42 -04:00
parent e080b9c740
commit 11edd067e7
2 changed files with 41 additions and 2 deletions
+3 -2
View File
@@ -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
}
}
}
+38
View File
@@ -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)
}
})
}