aboutsummaryrefslogtreecommitdiffstats
path: root/core/dkg-tsig-protocol_test.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-09-19 17:41:57 +0800
committerGitHub <noreply@github.com>2018-09-19 17:41:57 +0800
commita2a733e6f98018cb2ecc4b3982386be8892d7433 (patch)
tree1b894a5f57b89a63c2bc61fa950bd665837fd137 /core/dkg-tsig-protocol_test.go
parent54fa224dbbf1b1c0f8d54a3f10a81adb321ce1e4 (diff)
downloaddexon-consensus-a2a733e6f98018cb2ecc4b3982386be8892d7433.tar
dexon-consensus-a2a733e6f98018cb2ecc4b3982386be8892d7433.tar.gz
dexon-consensus-a2a733e6f98018cb2ecc4b3982386be8892d7433.tar.bz2
dexon-consensus-a2a733e6f98018cb2ecc4b3982386be8892d7433.tar.lz
dexon-consensus-a2a733e6f98018cb2ecc4b3982386be8892d7433.tar.xz
dexon-consensus-a2a733e6f98018cb2ecc4b3982386be8892d7433.tar.zst
dexon-consensus-a2a733e6f98018cb2ecc4b3982386be8892d7433.zip
core: Nack Complaint (#116)
Diffstat (limited to 'core/dkg-tsig-protocol_test.go')
-rw-r--r--core/dkg-tsig-protocol_test.go74
1 files changed, 63 insertions, 11 deletions
diff --git a/core/dkg-tsig-protocol_test.go b/core/dkg-tsig-protocol_test.go
index f1c0017..1ea65b2 100644
--- a/core/dkg-tsig-protocol_test.go
+++ b/core/dkg-tsig-protocol_test.go
@@ -60,7 +60,7 @@ func (r *testDKGReceiver) ProposeDKGComplaint(complaint *types.DKGComplaint) {
var err error
complaint.Signature, err = r.prvKey.Sign(hashDKGComplaint(complaint))
r.s.Require().NoError(err)
- r.complaints[complaint.ProposerID] = complaint
+ r.complaints[complaint.PrivateShare.ProposerID] = complaint
}
func (r *testDKGReceiver) ProposeDKGMasterPublicKey(
@@ -95,16 +95,8 @@ func (s *DKGTSIGProtocolTestSuite) setupDKGParticipants(n int) {
}
}
-// TestDKGTSIGProtocol will test the entire DKG+TISG protocol including
-// exchanging private shares, recovering share secret, creating partial sign and
-// recovering threshold signature.
-// All participants are good people in this test.
-func (s *DKGTSIGProtocolTestSuite) TestDKGTSIGProtocol() {
- k := 3
- n := 10
- round := uint64(1)
- gov, err := test.NewGovernance(5, 100)
- s.Require().NoError(err)
+func (s *DKGTSIGProtocolTestSuite) newProtocols(k, n int, round uint64) (
+ map[types.ValidatorID]*testDKGReceiver, map[types.ValidatorID]*dkgProtocol) {
s.setupDKGParticipants(n)
receivers := make(map[types.ValidatorID]*testDKGReceiver, n)
@@ -120,6 +112,21 @@ func (s *DKGTSIGProtocolTestSuite) TestDKGTSIGProtocol() {
)
s.Require().NotNil(receivers[vID].mpk)
}
+ return receivers, protocols
+}
+
+// TestDKGTSIGProtocol will test the entire DKG+TISG protocol including
+// exchanging private shares, recovering share secret, creating partial sign and
+// recovering threshold signature.
+// All participants are good people in this test.
+func (s *DKGTSIGProtocolTestSuite) TestDKGTSIGProtocol() {
+ k := 3
+ n := 10
+ round := uint64(1)
+ gov, err := test.NewGovernance(5, 100)
+ s.Require().NoError(err)
+
+ receivers, protocols := s.newProtocols(k, n, round)
for _, receiver := range receivers {
gov.AddDKGMasterPublicKey(receiver.mpk)
@@ -137,6 +144,10 @@ func (s *DKGTSIGProtocolTestSuite) TestDKGTSIGProtocol() {
}
}
+ for _, protocol := range protocols {
+ protocol.proposeNackComplaints()
+ }
+
for _, recv := range receivers {
s.Require().Len(recv.complaints, 0)
}
@@ -186,6 +197,47 @@ func (s *DKGTSIGProtocolTestSuite) TestDKGTSIGProtocol() {
s.True(gpk.verifySignature(msgHash, sig))
}
+func (s *DKGTSIGProtocolTestSuite) TestNackComplaint() {
+ k := 3
+ n := 10
+ round := uint64(1)
+ gov, err := test.NewGovernance(5, 100)
+ s.Require().NoError(err)
+
+ receivers, protocols := s.newProtocols(k, n, round)
+
+ byzantineID := s.vIDs[0]
+
+ for _, receiver := range receivers {
+ gov.AddDKGMasterPublicKey(receiver.mpk)
+ }
+
+ for _, protocol := range protocols {
+ s.Require().NoError(
+ protocol.processMasterPublicKeys(gov.DKGMasterPublicKeys(round)))
+ }
+
+ for senderID, receiver := range receivers {
+ s.Require().Len(receiver.prvShare, n)
+ if senderID == byzantineID {
+ continue
+ }
+ for vID, prvShare := range receiver.prvShare {
+ s.Require().NoError(protocols[vID].processPrivateShare(prvShare))
+ }
+ }
+
+ for _, protocol := range protocols {
+ protocol.proposeNackComplaints()
+ }
+
+ for _, recv := range receivers {
+ complaint, exist := recv.complaints[byzantineID]
+ s.Require().True(exist)
+ s.True(verifyDKGComplaintSignature(complaint, eth.SigToPub))
+ }
+}
+
func TestDKGTSIGProtocol(t *testing.T) {
suite.Run(t, new(DKGTSIGProtocolTestSuite))
}