Skip to content

Commit

Permalink
add malleated tx test
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-forbes committed Jul 25, 2022
1 parent 81e8f8f commit 3354f6b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions mempool/v1/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1

import (
"bytes"
"crypto/sha256"
"errors"
"fmt"
"math/rand"
Expand Down Expand Up @@ -652,3 +653,30 @@ func TestTxMempool_CheckTxPostCheckError(t *testing.T) {
})
}
}

func TestMalleatedTxRemoval(t *testing.T) {
txmp := setup(t, 500)
originalTx := []byte{1, 2, 3, 4}
malleatedTx := []byte{1, 2}
originalHash := sha256.Sum256(originalTx)

// create the wrapped child transaction
wTx, err := types.WrapMalleatedTx(originalHash[:], malleatedTx)
require.NoError(t, err)

// add the parent transaction to the mempool
err = txmp.CheckTx(originalTx, nil, mempool.TxInfo{})
require.NoError(t, err)

// remove the parent from the mempool using the wrapped child tx
err = txmp.Update(1, []types.Tx{wTx}, abciResponses(1, abci.CodeTypeOK), nil, nil)
require.NoError(t, err)
}

func abciResponses(n int, code uint32) []*abci.ResponseDeliverTx {
responses := make([]*abci.ResponseDeliverTx, 0, n)
for i := 0; i < n; i++ {
responses = append(responses, &abci.ResponseDeliverTx{Code: code})
}
return responses
}

0 comments on commit 3354f6b

Please sign in to comment.