"testing"
"time"
- "github.com/tendermint/go-crypto"
-
cfg "github.com/vapor/config"
+ "github.com/vapor/consensus"
conn "github.com/vapor/p2p/connection"
+ "github.com/vapor/p2p/signlib"
"github.com/vapor/version"
)
const testCh = 0x01
func TestPeerBasic(t *testing.T) {
+ privKey, err := signlib.NewPrivKey()
+ if err != nil {
+ t.Fatal(err)
+ }
+
// simulate remote peer
- rp := &remotePeer{PrivKey: crypto.GenPrivKeyEd25519(), Config: testCfg}
+ rp := &remotePeer{PrivKey: privKey, Config: testCfg}
rp.Start()
defer rp.Stop()
func TestPeerSend(t *testing.T) {
config := testCfg
-
+ privKey, err := signlib.NewPrivKey()
+ if err != nil {
+ t.Fatal(err)
+ }
// simulate remote peer
- rp := &remotePeer{PrivKey: crypto.GenPrivKeyEd25519(), Config: config}
+ rp := &remotePeer{PrivKey: privKey, Config: config}
rp.Start()
defer rp.Stop()
{ID: testCh, Priority: 1},
}
reactorsByCh := map[byte]Reactor{testCh: NewTestReactor(chDescs, true)}
- privkey := crypto.GenPrivKeyEd25519()
+ privKey, err := signlib.NewPrivKey()
+ if err != nil {
+ return nil, err
+ }
peerConfig := DefaultPeerConfig(config)
- pc, err := newOutboundPeerConn(addr, privkey, peerConfig)
+ pc, err := newOutboundPeerConn(addr, privKey, peerConfig)
if err != nil {
return nil, err
}
}
type remotePeer struct {
- PrivKey crypto.PrivKeyEd25519
+ PrivKey signlib.PrivKey
Config *cfg.Config
addr *NetAddress
quit chan struct{}
}
_, err = pc.HandshakeTimeout(&NodeInfo{
- PubKey: rp.PrivKey.PubKey().Unwrap().(crypto.PubKeyEd25519),
- Moniker: "remote_peer",
- Network: rp.Config.ChainID,
- Version: version.Version,
- ListenAddr: l.Addr().String(),
+ PubKey: rp.PrivKey.XPub().String(),
+ Moniker: "remote_peer",
+ Network: rp.Config.ChainID,
+ Version: version.Version,
+ ListenAddr: l.Addr().String(),
+ ServiceFlag: consensus.DefaultServices,
}, 5*time.Second)
if err != nil {
fmt.Println("Failed to perform handshake:", err)
}
type inboundPeer struct {
- PrivKey crypto.PrivKeyEd25519
+ PrivKey signlib.PrivKey
config *cfg.Config
}
}
_, err = pc.HandshakeTimeout(&NodeInfo{
- PubKey: ip.PrivKey.PubKey().Unwrap().(crypto.PubKeyEd25519),
+ PubKey: ip.PrivKey.XPub().String(),
Moniker: "remote_peer",
Network: ip.config.ChainID,
Version: version.Version,