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
@@ -518,7 +518,7 @@ func (r *BlockchainReactor) ReceiveEnvelope(e p2p.Envelope) {
}
func (r *BlockchainReactor) Receive(chID byte, peer p2p.Peer, msgBytes []byte) {
var msg *bcproto.Message
msg := &bcproto.Message{}
err := proto.Unmarshal(msgBytes, msg)
if err != nil {
panic(err)
+28
View File
@@ -415,6 +415,34 @@ func TestReactorHelperMode(t *testing.T) {
}
}
func TestLegacyReactorReceiveBasic(t *testing.T) {
config := cfg.ResetTestRoot("blockchain_reactor_v2_test")
defer os.RemoveAll(config.RootDir)
genDoc, privVals := randGenesisDoc(config.ChainID(), 1, false, 30)
params := testReactorParams{
logger: log.TestingLogger(),
genDoc: genDoc,
privVals: privVals,
startHeight: 20,
mockA: true,
}
reactor := newTestReactor(params)
mockSwitch := &mockSwitchIo{switchedToConsensus: false}
reactor.io = mockSwitch
peer := p2p.CreateRandomPeer(false)
reactor.InitPeer(peer)
reactor.AddPeer(peer)
m := &bcproto.StatusRequest{}
wm := m.Wrap()
msg, err := proto.Marshal(wm)
assert.NoError(t, err)
assert.NotPanics(t, func() {
reactor.Receive(BlockchainChannel, peer, msg)
})
}
func TestReactorSetSwitchNil(t *testing.T) {
config := cfg.ResetTestRoot("blockchain_reactor_v2_test")
defer os.RemoveAll(config.RootDir)