add allocate in Receive calls (#9667)

This commit is contained in:
William Banfield
2022-11-04 14:04:35 -04:00
committed by GitHub
parent 7417ddf351
commit e7b9ee7cef
20 changed files with 231 additions and 12 deletions
+1 -1
View File
@@ -93,7 +93,7 @@ func (evR *Reactor) ReceiveEnvelope(e p2p.Envelope) {
}
func (evR *Reactor) Receive(chID byte, peer p2p.Peer, msgBytes []byte) {
var msg *tmproto.EvidenceList
msg := &tmproto.EvidenceList{}
err := proto.Unmarshal(msgBytes, msg)
if err != nil {
panic(err)
+28
View File
@@ -9,6 +9,7 @@ import (
"github.com/fortytw2/leaktest"
"github.com/go-kit/log/term"
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
@@ -369,6 +370,33 @@ func exampleVote(t byte) *types.Vote {
ValidatorIndex: 56789,
}
}
func TestLegacyReactorReceiveBasic(t *testing.T) {
config := cfg.TestConfig()
N := 1
stateDBs := make([]sm.Store, N)
val := types.NewMockPV()
stateDBs[0] = initializeValidatorState(val, 1)
reactors, _ := makeAndConnectReactorsAndPools(config, stateDBs)
var (
reactor = reactors[0]
peer = &p2pmocks.Peer{}
)
quitChan := make(<-chan struct{})
peer.On("Quit").Return(quitChan)
reactor.InitPeer(peer)
reactor.AddPeer(peer)
e := &tmproto.EvidenceList{}
msg, err := proto.Marshal(e)
assert.NoError(t, err)
assert.NotPanics(t, func() {
reactor.Receive(evidence.EvidenceChannel, peer, msg)
})
}
//nolint:lll //ignore line length for tests
func TestEvidenceVectors(t *testing.T) {