Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions node/cn/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,9 @@ func handleBidMsg(pm *ProtocolManager, p Peer, msg p2p.Msg) error {
if pm.IsAuctionModuleDisabled() {
return nil
}
if p.ConnType() != common.CONSENSUSNODE {
return errResp(ErrInvalidMsgCode, "bid message from a non-CN peer: conntype %d", p.ConnType())
}

var data *auction.Bid
if err := msg.Decode(&data); err != nil {
Expand Down
38 changes: 38 additions & 0 deletions node/cn/handler_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ func TestHandleBidMsg(t *testing.T) {

msg := generateMsg(t, BidMsg, testBid)

mockPeer.EXPECT().ConnType().Return(common.CONSENSUSNODE).AnyTimes()
mockPeer.EXPECT().GetVersion().Return(kaia63).Times(11)
assert.Error(t, pm.handleMsg(mockPeer, addrs[0], msg), "should return error when protocol version is not kaia66")

Expand All @@ -874,6 +875,43 @@ func TestHandleBidMsg(t *testing.T) {
mockCtrl.Finish()
}

func TestHandleBidMsgFromNonCNPeer(t *testing.T) {
tcs := []struct {
name string
connType common.ConnType
auctionOff bool
wantErr bool
wantCalls int
}{
{"cn", common.CONSENSUSNODE, false, false, 1},
{"en", common.ENDPOINTNODE, false, true, 0},
{"pn", common.PROXYNODE, false, true, 0},
{"en without auction", common.ENDPOINTNODE, true, false, 0},
}
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

mockPeer := NewMockPeer(mockCtrl)
mockPeer.EXPECT().ConnType().Return(tc.connType).AnyTimes()
mockPeer.EXPECT().GetVersion().Return(kaia66).AnyTimes()
mockPeer.EXPECT().GetID().Return(nodeids[0].String()).AnyTimes()

pm := &ProtocolManager{}
if !tc.auctionOff {
mockAuction := auction_mock.NewMockAuctionModule(mockCtrl)
mockAuction.EXPECT().HandleBid(gomock.Any(), gomock.Any()).Times(tc.wantCalls)
pm.auctionModule = mockAuction
}
msg := generateMsg(t, BidMsg, &auction.Bid{BidData: auction.BidData{Bid: common.Big0}})

err := pm.handleMsg(mockPeer, addrs[0], msg)
assert.Equal(t, tc.wantErr, err != nil, "err: %v", err)
})
}
}

func TestHandleBlobSidecarsRequestMsg(t *testing.T) {
// test if the blob sidecars are retrieved from the block chain
{
Expand Down
Loading