diff options
author | Sonic <sonic@dexon.org> | 2018-11-12 09:18:03 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | aa0a3d80802bd137a661a8562f796d6f4763eac4 (patch) | |
tree | e89a5b38bff8fc45ced7bec828ab6a8c7535374b /dex/protocol_test.go | |
parent | 665b5c0c80b48e31a6da1f0afc36fc95c4580295 (diff) | |
download | dexon-aa0a3d80802bd137a661a8562f796d6f4763eac4.tar dexon-aa0a3d80802bd137a661a8562f796d6f4763eac4.tar.gz dexon-aa0a3d80802bd137a661a8562f796d6f4763eac4.tar.bz2 dexon-aa0a3d80802bd137a661a8562f796d6f4763eac4.tar.lz dexon-aa0a3d80802bd137a661a8562f796d6f4763eac4.tar.xz dexon-aa0a3d80802bd137a661a8562f796d6f4763eac4.tar.zst dexon-aa0a3d80802bd137a661a8562f796d6f4763eac4.zip |
dex: porting test to enode (#9)
Diffstat (limited to 'dex/protocol_test.go')
-rw-r--r-- | dex/protocol_test.go | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/dex/protocol_test.go b/dex/protocol_test.go index 2e9ba3470..b0e89230a 100644 --- a/dex/protocol_test.go +++ b/dex/protocol_test.go @@ -17,6 +17,8 @@ package dex import ( + "crypto/ecdsa" + "encoding/hex" "fmt" "reflect" "sync" @@ -34,7 +36,6 @@ import ( "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/eth/downloader" "github.com/dexon-foundation/dexon/p2p" - "github.com/dexon-foundation/dexon/p2p/discover" "github.com/dexon-foundation/dexon/rlp" ) @@ -72,7 +73,7 @@ func testStatusMsgErrors(t *testing.T, protocol int) { }, { code: StatusMsg, data: statusData{uint32(protocol), 999, td, head.Hash(), genesis.Hash()}, - wantError: errResp(ErrNetworkIdMismatch, "999 (!= 1)"), + wantError: errResp(ErrNetworkIdMismatch, "999 (!= 237)"), }, { code: StatusMsg, data: statusData{uint32(protocol), DefaultConfig.NetworkId, td, head.Hash(), common.Hash{3}}, @@ -237,7 +238,7 @@ func TestRecvNodeMetas(t *testing.T) { defer p.close() meta := NodeMeta{ - ID: nodeID(1), + ID: randomID(), } ch := make(chan newMetasEvent) @@ -265,8 +266,8 @@ func TestSendNodeMetas(t *testing.T) { defer pm.Stop() allmetas := make([]*NodeMeta, 100) - for nonce := range allmetas { - allmetas[nonce] = &NodeMeta{ID: nodeID(int64(nonce))} + for i := 0; i < len(allmetas); i++ { + allmetas[i] = &NodeMeta{ID: randomID()} } // Connect several peers. They should all receive the pending transactions. @@ -548,7 +549,8 @@ func TestSendVote(t *testing.T) { for i, tt := range testPeers { p, _ := newTestPeer(fmt.Sprintf("peer #%d", i), dex64, pm, true) if tt.label != nil { - pm.peers.addDirectPeer(p.id, *tt.label) + b := crypto.FromECDSAPub(p.Node().Pubkey()) + pm.peers.addDirectPeer(hex.EncodeToString(b), *tt.label) } wg.Add(1) go checkvote(p, tt.isReceiver) @@ -558,17 +560,14 @@ func TestSendVote(t *testing.T) { wg.Wait() } -type mockPublicKey struct { - id enode.ID -} +type mockPublicKey ecdsa.PublicKey func (p *mockPublicKey) VerifySignature(hash coreCommon.Hash, signature coreCrypto.Signature) bool { return true } func (p *mockPublicKey) Bytes() []byte { - b, _ := p.id.Pubkey() - return crypto.FromECDSAPub(b) + return crypto.FromECDSAPub((*ecdsa.PublicKey)(p)) } func TestRecvDKGPrivateShare(t *testing.T) { @@ -627,7 +626,7 @@ func TestSendDKGPrivateShare(t *testing.T) { }, } - go pm.SendDKGPrivateShare(&mockPublicKey{p1.ID()}, &privateShare) + go pm.SendDKGPrivateShare((*mockPublicKey)(p1.Node().Pubkey()), &privateShare) msg, err := p1.app.ReadMsg() if err != nil { t.Errorf("%v: read error: %v", p1.Peer, err) |