aboutsummaryrefslogtreecommitdiffstats
path: root/dex/protocol_test.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-03-27 20:47:32 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:59 +0800
commit0c63646ca8b06bb527737cd6e2a7fe58f169efff (patch)
treeb0666613c2a3cb84d53b60597bfef5ec45548c3a /dex/protocol_test.go
parent91981becf98b988470810aa1c26d86de2d294e29 (diff)
downloaddexon-0c63646ca8b06bb527737cd6e2a7fe58f169efff.tar
dexon-0c63646ca8b06bb527737cd6e2a7fe58f169efff.tar.gz
dexon-0c63646ca8b06bb527737cd6e2a7fe58f169efff.tar.bz2
dexon-0c63646ca8b06bb527737cd6e2a7fe58f169efff.tar.lz
dexon-0c63646ca8b06bb527737cd6e2a7fe58f169efff.tar.xz
dexon-0c63646ca8b06bb527737cd6e2a7fe58f169efff.tar.zst
dexon-0c63646ca8b06bb527737cd6e2a7fe58f169efff.zip
core: merge notarySet and DKGSet (#265)
* vendor: sync to latest core * core: merge notarySet and dkgSet * dex: optimize network traffic for finalized block
Diffstat (limited to 'dex/protocol_test.go')
-rw-r--r--dex/protocol_test.go105
1 files changed, 25 insertions, 80 deletions
diff --git a/dex/protocol_test.go b/dex/protocol_test.go
index 517df97d9..7e0e1a9a4 100644
--- a/dex/protocol_test.go
+++ b/dex/protocol_test.go
@@ -438,6 +438,10 @@ func TestRecvVotes(t *testing.T) {
Height: 13,
},
},
+ PartialSignature: dkg.PartialSignature{
+ Type: "456",
+ Signature: []byte("psig"),
+ },
Signature: coreCrypto.Signature{
Type: "123",
Signature: []byte("sig"),
@@ -453,7 +457,7 @@ func TestRecvVotes(t *testing.T) {
select {
case msg := <-ch:
rvote := msg.(*coreTypes.Vote)
- if rlpHash(rvote) != rlpHash(vote) {
+ if !reflect.DeepEqual(rvote, &vote) {
t.Errorf("vote mismatch")
}
case <-time.After(1 * time.Second):
@@ -474,6 +478,10 @@ func TestSendVotes(t *testing.T) {
Height: 13,
},
},
+ PartialSignature: dkg.PartialSignature{
+ Type: "456",
+ Signature: []byte("psig"),
+ },
Signature: coreCrypto.Signature{
Type: "123",
Signature: []byte("sig"),
@@ -531,10 +539,6 @@ func TestSendVotes(t *testing.T) {
label: &peerLabel{set: notaryset, round: 11},
isReceiver: false,
},
- {
- label: &peerLabel{set: dkgset, round: 10},
- isReceiver: false,
- },
}
pm.peers.label2Nodes = make(map[peerLabel]map[string]*enode.Node)
@@ -669,6 +673,10 @@ func TestRecvAgreement(t *testing.T) {
Height: 13,
},
},
+ PartialSignature: dkg.PartialSignature{
+ Type: "456",
+ Signature: []byte("psig"),
+ },
Signature: coreCrypto.Signature{
Type: "123",
Signature: []byte("sig"),
@@ -676,9 +684,10 @@ func TestRecvAgreement(t *testing.T) {
}
agreement := coreTypes.AgreementResult{
- BlockHash: coreCommon.Hash{9, 9, 9},
- Position: vote.Position,
- Votes: []coreTypes.Vote{vote},
+ BlockHash: coreCommon.Hash{9, 9, 9},
+ Position: vote.Position,
+ Votes: []coreTypes.Vote{vote},
+ Randomness: []byte{9, 4, 8, 7},
}
if err := p2p.Send(p.app, AgreementMsg, &agreement); err != nil {
@@ -714,6 +723,10 @@ func TestSendAgreement(t *testing.T) {
Height: 13,
},
},
+ PartialSignature: dkg.PartialSignature{
+ Type: "456",
+ Signature: []byte("psig"),
+ },
Signature: coreCrypto.Signature{
Type: "123",
Signature: []byte("sig"),
@@ -721,9 +734,10 @@ func TestSendAgreement(t *testing.T) {
}
agreement := coreTypes.AgreementResult{
- BlockHash: coreCommon.Hash{9, 9, 9},
- Position: vote.Position,
- Votes: []coreTypes.Vote{vote},
+ BlockHash: coreCommon.Hash{9, 9, 9},
+ Position: vote.Position,
+ Votes: []coreTypes.Vote{vote},
+ Randomness: []byte{9, 4, 8, 7},
}
waitForRegister(pm, 1)
@@ -745,75 +759,6 @@ func TestSendAgreement(t *testing.T) {
}
}
-func TestRecvRandomnesses(t *testing.T) {
- pm, _ := newTestProtocolManagerMust(t, downloader.FullSync, 0, nil, nil)
- pm.SetReceiveCoreMessage(true)
-
- p, _ := newTestPeer("peer", dex64, pm, true)
- defer pm.Stop()
- defer p.close()
-
- randomness := coreTypes.BlockRandomnessResult{
- BlockHash: coreCommon.Hash{8, 8, 8},
- Position: coreTypes.Position{
- Round: 10,
- Height: 13,
- },
- Randomness: []byte{7, 7, 7, 7},
- }
-
- if err := p2p.Send(p.app, RandomnessMsg, []*coreTypes.BlockRandomnessResult{&randomness}); err != nil {
- t.Fatalf("send error: %v", err)
- }
-
- ch := pm.ReceiveChan()
- select {
- case msg := <-ch:
- r := msg.(*coreTypes.BlockRandomnessResult)
- if !reflect.DeepEqual(r, &randomness) {
- t.Errorf("randomness mismatch")
- }
- case <-time.After(1 * time.Second):
- t.Errorf("no randomness received within 1 seconds")
- }
-}
-
-func TestSendRandomnesses(t *testing.T) {
- pm, _ := newTestProtocolManagerMust(t, downloader.FullSync, 0, nil, nil)
- pm.SetReceiveCoreMessage(true)
-
- p, _ := newTestPeer("peer", dex64, pm, true)
- defer pm.Stop()
- defer p.close()
-
- randomness := coreTypes.BlockRandomnessResult{
- BlockHash: coreCommon.Hash{8, 8, 8},
- Position: coreTypes.Position{
- Round: 10,
- Height: 13,
- },
- Randomness: []byte{7, 7, 7, 7},
- }
-
- waitForRegister(pm, 1)
- pm.BroadcastRandomnessResult(&randomness)
- msg, err := p.app.ReadMsg()
- if err != nil {
- t.Errorf("%v: read error: %v", p.Peer, err)
- } else if msg.Code != RandomnessMsg {
- t.Errorf("%v: got code %d, want %d", p.Peer, msg.Code, RandomnessMsg)
- }
-
- var rs []*coreTypes.BlockRandomnessResult
- if err := msg.Decode(&rs); err != nil {
- t.Errorf("%v: %v", p.Peer, err)
- }
-
- if !reflect.DeepEqual(rs, []*coreTypes.BlockRandomnessResult{&randomness}) {
- t.Errorf("randomness mismatch")
- }
-}
-
func waitForRegister(pm *ProtocolManager, num int) {
for {
if pm.peers.Len() >= num {