github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/p2pserver/sync/sync_router_test.go (about)

     1  /*
     2   * Copyright (C) 2018 The ontology Authors
     3   * This file is part of The ontology library.
     4   *
     5   * The ontology is free software: you can redistribute it and/or modify
     6   * it under the terms of the GNU Lesser General Public License as published by
     7   * the Free Software Foundation, either version 3 of the License, or
     8   * (at your option) any later version.
     9   *
    10   * The ontology is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU Lesser General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU Lesser General Public License
    16   * along with The ontology.  If not, see <http://www.gnu.org/licenses/>.
    17   */
    18  
    19  package sync
    20  
    21  import (
    22  	"github.com/ontio/ontology-crypto/keypair"
    23  	"github.com/ontio/ontology-eventbus/actor"
    24  	"github.com/ontio/ontology/common/log"
    25  	msgCommon "github.com/sixexorg/magnetic-ring/p2pserver/common"
    26  	"github.com/sixexorg/magnetic-ring/p2pserver/net/netserver"
    27  	"github.com/sixexorg/magnetic-ring/p2pserver/net/protocol"
    28  	"github.com/stretchr/testify/assert"
    29  	"testing"
    30  )
    31  
    32  func testHandler(data *msgCommon.MsgPayload, p2p p2p.P2P, pid *actor.PID, args ...interface{}) error {
    33  	log.Info("Test handler")
    34  	return nil
    35  }
    36  
    37  // TestMsgRouter tests a basic function of a message router
    38  func TestMsgRouter(t *testing.T) {
    39  	_, pub, _ := keypair.GenerateKeyPair(keypair.PK_ECDSA, keypair.P256)
    40  	network := netserver.NewNetServer(pub)
    41  	msgRouter := NewMsgRouter(network)
    42  	assert.NotNil(t, msgRouter)
    43  
    44  	msgRouter.RegisterMsgHandler("test", testHandler)
    45  	msgRouter.UnRegisterMsgHandler("test")
    46  	msgRouter.Start()
    47  	msgRouter.Stop()
    48  }