mirror of https://github.com/certusone/dc4bc.git
Merge branch 'fsm-draft' into feat/airgapped-client-tests
This commit is contained in:
commit
367fda77f4
|
@ -43,7 +43,7 @@ func (m *DKGProposalFSM) actionInitDKGProposal(inEvent fsm.Event, args ...interf
|
||||||
for participantId, participant := range m.payload.SignatureProposalPayload.Quorum {
|
for participantId, participant := range m.payload.SignatureProposalPayload.Quorum {
|
||||||
m.payload.DKGProposalPayload.Quorum[participantId] = &internal.DKGProposalParticipant{
|
m.payload.DKGProposalPayload.Quorum[participantId] = &internal.DKGProposalParticipant{
|
||||||
Addr: participant.Addr,
|
Addr: participant.Addr,
|
||||||
DkgPubKey: participant.DkgPubKey,
|
DkgPubKey: make([]byte, len(participant.DkgPubKey)),
|
||||||
Status: internal.CommitAwaitConfirmation,
|
Status: internal.CommitAwaitConfirmation,
|
||||||
UpdatedAt: participant.UpdatedAt,
|
UpdatedAt: participant.UpdatedAt,
|
||||||
}
|
}
|
||||||
|
@ -411,6 +411,7 @@ func (m *DKGProposalFSM) actionMasterKeyConfirmationReceived(inEvent fsm.Event,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dkgProposalParticipant.DkgMasterKey = make([]byte, len(request.MasterKey))
|
||||||
copy(dkgProposalParticipant.DkgMasterKey, request.MasterKey)
|
copy(dkgProposalParticipant.DkgMasterKey, request.MasterKey)
|
||||||
dkgProposalParticipant.Status = internal.MasterKeyConfirmed
|
dkgProposalParticipant.Status = internal.MasterKeyConfirmed
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
package state_machines
|
package state_machines
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/ed25519"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"encoding/base64"
|
||||||
"crypto/x509"
|
|
||||||
"fmt"
|
|
||||||
sif "github.com/depools/dc4bc/fsm/state_machines/signing_proposal_fsm"
|
sif "github.com/depools/dc4bc/fsm/state_machines/signing_proposal_fsm"
|
||||||
"log"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -17,11 +16,20 @@ import (
|
||||||
"github.com/depools/dc4bc/fsm/types/responses"
|
"github.com/depools/dc4bc/fsm/types/responses"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testExternalParticipants struct {
|
const (
|
||||||
Addr string
|
addrMockLen = 32
|
||||||
PrivKey *rsa.PrivateKey
|
keysMockLen = 128
|
||||||
PubKey *rsa.PublicKey
|
)
|
||||||
DkgPubKey []byte
|
|
||||||
|
type testParticipantsPayload struct {
|
||||||
|
Addr string
|
||||||
|
HotPrivKey ed25519.PrivateKey
|
||||||
|
HotPubKey ed25519.PublicKey
|
||||||
|
DkgPubKey []byte
|
||||||
|
DkgCommit []byte
|
||||||
|
DkgDeal []byte
|
||||||
|
DkgResponse []byte
|
||||||
|
DkgPartialKey []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -29,7 +37,10 @@ var (
|
||||||
|
|
||||||
dkgId = "1b7a6382afe0fbe2ff127a5779f5e9b042e685cabefeadcf4ef27c6089a56bfb"
|
dkgId = "1b7a6382afe0fbe2ff127a5779f5e9b042e685cabefeadcf4ef27c6089a56bfb"
|
||||||
|
|
||||||
testParticipants = map[int]*testExternalParticipants{}
|
// map {addr} -> {participant}
|
||||||
|
testAddrMapParticipants = map[string]*testParticipantsPayload{}
|
||||||
|
// map {dkg_queue_id} -> {participant}
|
||||||
|
testIdMapParticipants = map[int]*testParticipantsPayload{}
|
||||||
|
|
||||||
testParticipantsListRequest = requests.SignatureProposalParticipantsListRequest{
|
testParticipantsListRequest = requests.SignatureProposalParticipantsListRequest{
|
||||||
Participants: []*requests.SignatureProposalParticipantsEntry{},
|
Participants: []*requests.SignatureProposalParticipantsEntry{},
|
||||||
|
@ -40,44 +51,20 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
r := rand.Reader
|
|
||||||
|
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
key, err := rsa.GenerateKey(r, 2048)
|
|
||||||
|
|
||||||
if err != nil {
|
participant := &testParticipantsPayload{
|
||||||
log.Fatal("Cannot generate key for user:", err)
|
Addr: base64.StdEncoding.EncodeToString(genDataMock(addrMockLen)),
|
||||||
return
|
HotPrivKey: genDataMock(keysMockLen),
|
||||||
|
HotPubKey: genDataMock(keysMockLen),
|
||||||
|
DkgPubKey: genDataMock(keysMockLen),
|
||||||
|
DkgCommit: genDataMock(keysMockLen),
|
||||||
|
DkgDeal: genDataMock(keysMockLen),
|
||||||
|
DkgResponse: genDataMock(keysMockLen),
|
||||||
|
DkgPartialKey: genDataMock(keysMockLen),
|
||||||
}
|
}
|
||||||
|
testAddrMapParticipants[participant.Addr] = participant
|
||||||
key.Precompute()
|
|
||||||
|
|
||||||
pubKeyMock := make([]byte, 128)
|
|
||||||
|
|
||||||
rand.Read(pubKeyMock)
|
|
||||||
|
|
||||||
participant := &testExternalParticipants{
|
|
||||||
Addr: fmt.Sprintf("User %d", i),
|
|
||||||
PrivKey: key,
|
|
||||||
PubKey: &key.PublicKey,
|
|
||||||
DkgPubKey: pubKeyMock,
|
|
||||||
}
|
|
||||||
testParticipants[i] = participant
|
|
||||||
}
|
}
|
||||||
|
|
||||||
participantsForRequest := make([]*requests.SignatureProposalParticipantsEntry, 0)
|
|
||||||
|
|
||||||
for _, participant := range testParticipants {
|
|
||||||
|
|
||||||
participantsForRequest = append(participantsForRequest, &requests.SignatureProposalParticipantsEntry{
|
|
||||||
Addr: participant.Addr,
|
|
||||||
PubKey: x509.MarshalPKCS1PublicKey(participant.PubKey),
|
|
||||||
DkgPubKey: participant.DkgPubKey,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
testParticipantsListRequest.Participants = participantsForRequest
|
|
||||||
testParticipantsListRequest.SigningThreshold = len(participantsForRequest)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreate_Positive(t *testing.T) {
|
func TestCreate_Positive(t *testing.T) {
|
||||||
|
@ -91,6 +78,12 @@ func TestCreate_Positive(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func genDataMock(len int) []byte {
|
||||||
|
data := make([]byte, len)
|
||||||
|
rand.Read(data)
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
func compareErrNil(t *testing.T, got error) {
|
func compareErrNil(t *testing.T, got error) {
|
||||||
if got != nil {
|
if got != nil {
|
||||||
t.Fatalf("expected nil error, got {%s}", got)
|
t.Fatalf("expected nil error, got {%s}", got)
|
||||||
|
@ -122,7 +115,6 @@ func compareState(t *testing.T, expected fsm.State, got fsm.State) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test Workflow
|
// Test Workflow
|
||||||
|
|
||||||
func Test_SignatureProposal_Init(t *testing.T) {
|
func Test_SignatureProposal_Init(t *testing.T) {
|
||||||
testFSMInstance, err := Create(dkgId)
|
testFSMInstance, err := Create(dkgId)
|
||||||
|
|
||||||
|
@ -139,28 +131,42 @@ func Test_SignatureProposal_Init(t *testing.T) {
|
||||||
if testFSMInstance.machine.Name() != spf.FsmName {
|
if testFSMInstance.machine.Name() != spf.FsmName {
|
||||||
t.Fatalf("expected machine name {%s}", spf.FsmName)
|
t.Fatalf("expected machine name {%s}", spf.FsmName)
|
||||||
}
|
}
|
||||||
|
|
||||||
compareState(t, spf.StateParticipantsConfirmationsInit, testFSMInstance.machine.State())
|
compareState(t, spf.StateParticipantsConfirmationsInit, testFSMInstance.machine.State())
|
||||||
|
|
||||||
testFSMDump, err = testFSMInstance.Dump()
|
testFSMDump, err = testFSMInstance.Dump()
|
||||||
|
|
||||||
compareErrNil(t, err)
|
compareErrNil(t, err)
|
||||||
|
|
||||||
compareDumpNotZero(t, testFSMDump)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_SignatureProposal_Positive(t *testing.T) {
|
// EventInitProposal
|
||||||
|
func Test_SignatureProposal_EventInitProposal(t *testing.T) {
|
||||||
|
var fsmResponse *fsm.Response
|
||||||
|
|
||||||
testFSMInstance, err := FromDump(testFSMDump)
|
testFSMInstance, err := FromDump(testFSMDump)
|
||||||
|
|
||||||
compareErrNil(t, err)
|
compareErrNil(t, err)
|
||||||
|
|
||||||
compareFSMInstanceNotNil(t, testFSMInstance)
|
compareFSMInstanceNotNil(t, testFSMInstance)
|
||||||
|
|
||||||
fsmResponse, dump, err := testFSMInstance.Do(spf.EventInitProposal, testParticipantsListRequest)
|
// Make request
|
||||||
|
request := make([]*requests.SignatureProposalParticipantsEntry, 0)
|
||||||
|
|
||||||
|
for _, participant := range testAddrMapParticipants {
|
||||||
|
|
||||||
|
request = append(request, &requests.SignatureProposalParticipantsEntry{
|
||||||
|
Addr: participant.Addr,
|
||||||
|
PubKey: participant.HotPubKey,
|
||||||
|
DkgPubKey: participant.DkgPubKey,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
testParticipantsListRequest.Participants = request
|
||||||
|
testParticipantsListRequest.SigningThreshold = len(request)
|
||||||
|
|
||||||
|
fsmResponse, testFSMDump, err = testFSMInstance.Do(spf.EventInitProposal, testParticipantsListRequest)
|
||||||
|
|
||||||
compareErrNil(t, err)
|
compareErrNil(t, err)
|
||||||
|
|
||||||
compareDumpNotZero(t, dump)
|
compareDumpNotZero(t, testFSMDump)
|
||||||
|
|
||||||
compareFSMResponseNotNil(t, fsmResponse)
|
compareFSMResponseNotNil(t, fsmResponse)
|
||||||
|
|
||||||
|
@ -176,10 +182,8 @@ func Test_SignatureProposal_Positive(t *testing.T) {
|
||||||
t.Fatalf("expected response len {%d}, got {%d}", len(testParticipantsListRequest.Participants), len(testParticipantsListResponse))
|
t.Fatalf("expected response len {%d}, got {%d}", len(testParticipantsListRequest.Participants), len(testParticipantsListResponse))
|
||||||
}
|
}
|
||||||
|
|
||||||
participantsMap := map[int]*responses.SignatureProposalParticipantInvitationEntry{}
|
|
||||||
|
|
||||||
for _, participant := range testParticipantsListResponse {
|
for _, participant := range testParticipantsListResponse {
|
||||||
if _, ok := participantsMap[participant.ParticipantId]; ok {
|
if _, ok := testIdMapParticipants[participant.ParticipantId]; ok {
|
||||||
t.Fatalf("expected unique {ParticipantId}")
|
t.Fatalf("expected unique {ParticipantId}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,31 +191,41 @@ func Test_SignatureProposal_Positive(t *testing.T) {
|
||||||
t.Fatalf("expected not empty {Addr}")
|
t.Fatalf("expected not empty {Addr}")
|
||||||
}
|
}
|
||||||
|
|
||||||
participantsMap[participant.ParticipantId] = participant
|
participantEntry, ok := testAddrMapParticipants[participant.Addr]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("expected exist {Addr}")
|
||||||
|
}
|
||||||
|
|
||||||
|
testIdMapParticipants[participant.ParticipantId] = participantEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
tm = tm.Add(1 * time.Hour)
|
}
|
||||||
|
|
||||||
participantsCount := len(participantsMap)
|
// EventConfirmSignatureProposal
|
||||||
|
func Test_SignatureProposal_EventConfirmSignatureProposal(t *testing.T) {
|
||||||
|
var fsmResponse *fsm.Response
|
||||||
|
|
||||||
|
participantsCount := len(testIdMapParticipants)
|
||||||
|
|
||||||
participantCounter := participantsCount
|
participantCounter := participantsCount
|
||||||
|
|
||||||
for _, participant := range participantsMap {
|
for participantId, _ := range testIdMapParticipants {
|
||||||
participantCounter--
|
participantCounter--
|
||||||
testFSMInstance, err = FromDump(dump)
|
testFSMInstance, err := FromDump(testFSMDump)
|
||||||
|
|
||||||
compareErrNil(t, err)
|
compareErrNil(t, err)
|
||||||
|
|
||||||
compareFSMInstanceNotNil(t, testFSMInstance)
|
compareFSMInstanceNotNil(t, testFSMInstance)
|
||||||
|
|
||||||
fsmResponse, dump, err = testFSMInstance.Do(spf.EventConfirmSignatureProposal, requests.SignatureProposalParticipantRequest{
|
fsmResponse, testFSMDump, err = testFSMInstance.Do(spf.EventConfirmSignatureProposal, requests.SignatureProposalParticipantRequest{
|
||||||
ParticipantId: participant.ParticipantId,
|
ParticipantId: participantId,
|
||||||
CreatedAt: tm,
|
CreatedAt: time.Now(),
|
||||||
})
|
})
|
||||||
|
|
||||||
compareErrNil(t, err)
|
compareErrNil(t, err)
|
||||||
|
|
||||||
compareDumpNotZero(t, dump)
|
compareDumpNotZero(t, testFSMDump)
|
||||||
|
|
||||||
compareFSMResponseNotNil(t, fsmResponse)
|
compareFSMResponseNotNil(t, fsmResponse)
|
||||||
|
|
||||||
|
@ -222,50 +236,77 @@ func Test_SignatureProposal_Positive(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
compareState(t, spf.StateSignatureProposalCollected, fsmResponse.State)
|
compareState(t, spf.StateSignatureProposalCollected, fsmResponse.State)
|
||||||
|
}
|
||||||
|
|
||||||
testFSMInstance, err = FromDump(dump)
|
func Test_DkgProposal_Positive(t *testing.T) {
|
||||||
|
var fsmResponse *fsm.Response
|
||||||
|
|
||||||
fsmResponse, dump, err = testFSMInstance.Do(dpf.EventDKGInitProcess, requests.DefaultRequest{
|
testFSMInstance, err := FromDump(testFSMDump)
|
||||||
|
|
||||||
|
compareErrNil(t, err)
|
||||||
|
|
||||||
|
compareFSMInstanceNotNil(t, testFSMInstance)
|
||||||
|
|
||||||
|
fsmResponse, testFSMDump, err = testFSMInstance.Do(dpf.EventDKGInitProcess, requests.DefaultRequest{
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
})
|
})
|
||||||
|
|
||||||
compareErrNil(t, err)
|
compareErrNil(t, err)
|
||||||
|
|
||||||
compareDumpNotZero(t, dump)
|
compareDumpNotZero(t, testFSMDump)
|
||||||
|
|
||||||
compareFSMResponseNotNil(t, fsmResponse)
|
compareFSMResponseNotNil(t, fsmResponse)
|
||||||
|
|
||||||
|
response, ok := fsmResponse.Data.(responses.DKGProposalPubKeysParticipantResponse)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("expected response {DKGProposalPubKeysParticipantResponse}")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(response) != len(testParticipantsListRequest.Participants) {
|
||||||
|
t.Fatalf("expected response len {%d}, got {%d}", len(testParticipantsListRequest.Participants), len(response))
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, responseEntry := range response {
|
||||||
|
if _, ok := testIdMapParticipants[responseEntry.ParticipantId]; !ok {
|
||||||
|
t.Fatalf("expected exist {ParticipantId}")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(responseEntry.DkgPubKey) == 0 {
|
||||||
|
t.Fatalf("expected {DkgPubKey} non zero length")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(testIdMapParticipants[responseEntry.ParticipantId].DkgPubKey, responseEntry.DkgPubKey) {
|
||||||
|
t.Fatalf("expected valid {DkgPubKey}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
compareState(t, dpf.StateDkgCommitsAwaitConfirmations, fsmResponse.State)
|
compareState(t, dpf.StateDkgCommitsAwaitConfirmations, fsmResponse.State)
|
||||||
|
|
||||||
// Commits
|
// Commits
|
||||||
|
}
|
||||||
|
|
||||||
for _, participant := range participantsMap {
|
func Test_DkgProposal_EventDKGCommitConfirmationReceived(t *testing.T) {
|
||||||
participantCounter--
|
var fsmResponse *fsm.Response
|
||||||
testFSMInstance, err = FromDump(dump)
|
|
||||||
|
pCounter := 0
|
||||||
|
for participantId, participant := range testIdMapParticipants {
|
||||||
|
pCounter--
|
||||||
|
testFSMInstance, err := FromDump(testFSMDump)
|
||||||
|
|
||||||
compareErrNil(t, err)
|
compareErrNil(t, err)
|
||||||
|
|
||||||
compareFSMInstanceNotNil(t, testFSMInstance)
|
compareFSMInstanceNotNil(t, testFSMInstance)
|
||||||
|
|
||||||
if _, ok := testParticipants[participant.ParticipantId]; !ok {
|
fsmResponse, testFSMDump, err = testFSMInstance.Do(dpf.EventDKGCommitConfirmationReceived, requests.DKGProposalCommitConfirmationRequest{
|
||||||
t.Fatalf("not found external user data for response fingerprint")
|
ParticipantId: participantId,
|
||||||
}
|
Commit: participant.DkgCommit,
|
||||||
|
|
||||||
commitMock := make([]byte, 128)
|
|
||||||
_, err := rand.Read(commitMock)
|
|
||||||
if err != nil {
|
|
||||||
compareErrNil(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fsmResponse, dump, err = testFSMInstance.Do(dpf.EventDKGCommitConfirmationReceived, requests.DKGProposalCommitConfirmationRequest{
|
|
||||||
ParticipantId: participant.ParticipantId,
|
|
||||||
Commit: commitMock,
|
|
||||||
CreatedAt: tm,
|
CreatedAt: tm,
|
||||||
})
|
})
|
||||||
|
|
||||||
compareErrNil(t, err)
|
compareErrNil(t, err)
|
||||||
|
|
||||||
compareDumpNotZero(t, dump)
|
compareDumpNotZero(t, testFSMDump)
|
||||||
|
|
||||||
compareFSMResponseNotNil(t, fsmResponse)
|
compareFSMResponseNotNil(t, fsmResponse)
|
||||||
|
|
||||||
|
@ -273,35 +314,53 @@ func Test_SignatureProposal_Positive(t *testing.T) {
|
||||||
|
|
||||||
compareState(t, dpf.StateDkgDealsAwaitConfirmations, fsmResponse.State)
|
compareState(t, dpf.StateDkgDealsAwaitConfirmations, fsmResponse.State)
|
||||||
|
|
||||||
// Deals
|
response, ok := fsmResponse.Data.(responses.DKGProposalCommitParticipantResponse)
|
||||||
|
|
||||||
for _, participant := range participantsMap {
|
if !ok {
|
||||||
participantCounter--
|
t.Fatalf("expected response {DKGProposalCommitParticipantResponse}")
|
||||||
testFSMInstance, err = FromDump(dump)
|
}
|
||||||
|
|
||||||
|
if len(response) != len(testParticipantsListRequest.Participants) {
|
||||||
|
t.Fatalf("expected response len {%d}, got {%d}", len(testParticipantsListRequest.Participants), len(response))
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, responseEntry := range response {
|
||||||
|
if _, ok := testIdMapParticipants[responseEntry.ParticipantId]; !ok {
|
||||||
|
t.Fatalf("expected exist {ParticipantId}")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(responseEntry.DkgCommit) == 0 {
|
||||||
|
t.Fatalf("expected {DkgCommit} non zero length")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(testIdMapParticipants[responseEntry.ParticipantId].DkgCommit, responseEntry.DkgCommit) {
|
||||||
|
t.Fatalf("expected valid {DkgCommit}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deals
|
||||||
|
func Test_DkgProposal_EventDKGDealConfirmationReceived(t *testing.T) {
|
||||||
|
var fsmResponse *fsm.Response
|
||||||
|
|
||||||
|
pCounter := 0
|
||||||
|
for participantId, participant := range testIdMapParticipants {
|
||||||
|
pCounter--
|
||||||
|
testFSMInstance, err := FromDump(testFSMDump)
|
||||||
|
|
||||||
compareErrNil(t, err)
|
compareErrNil(t, err)
|
||||||
|
|
||||||
compareFSMInstanceNotNil(t, testFSMInstance)
|
compareFSMInstanceNotNil(t, testFSMInstance)
|
||||||
|
|
||||||
if _, ok := testParticipants[participant.ParticipantId]; !ok {
|
fsmResponse, testFSMDump, err = testFSMInstance.Do(dpf.EventDKGDealConfirmationReceived, requests.DKGProposalDealConfirmationRequest{
|
||||||
t.Fatalf("not found external user data for response fingerprint")
|
ParticipantId: participantId,
|
||||||
}
|
Deal: participant.DkgDeal,
|
||||||
|
|
||||||
dealMock := make([]byte, 128)
|
|
||||||
_, err := rand.Read(dealMock)
|
|
||||||
if err != nil {
|
|
||||||
compareErrNil(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fsmResponse, dump, err = testFSMInstance.Do(dpf.EventDKGDealConfirmationReceived, requests.DKGProposalDealConfirmationRequest{
|
|
||||||
ParticipantId: participant.ParticipantId,
|
|
||||||
Deal: dealMock,
|
|
||||||
CreatedAt: tm,
|
CreatedAt: tm,
|
||||||
})
|
})
|
||||||
|
|
||||||
compareErrNil(t, err)
|
compareErrNil(t, err)
|
||||||
|
|
||||||
compareDumpNotZero(t, dump)
|
compareDumpNotZero(t, testFSMDump)
|
||||||
|
|
||||||
compareFSMResponseNotNil(t, fsmResponse)
|
compareFSMResponseNotNil(t, fsmResponse)
|
||||||
|
|
||||||
|
@ -309,35 +368,53 @@ func Test_SignatureProposal_Positive(t *testing.T) {
|
||||||
|
|
||||||
compareState(t, dpf.StateDkgResponsesAwaitConfirmations, fsmResponse.State)
|
compareState(t, dpf.StateDkgResponsesAwaitConfirmations, fsmResponse.State)
|
||||||
|
|
||||||
// Responses
|
response, ok := fsmResponse.Data.(responses.DKGProposalDealParticipantResponse)
|
||||||
|
|
||||||
for _, participant := range participantsMap {
|
if !ok {
|
||||||
participantCounter--
|
t.Fatalf("expected response {DKGProposalDealParticipantResponse}")
|
||||||
testFSMInstance, err = FromDump(dump)
|
}
|
||||||
|
|
||||||
|
if len(response) != len(testParticipantsListRequest.Participants) {
|
||||||
|
t.Fatalf("expected response len {%d}, got {%d}", len(testParticipantsListRequest.Participants), len(response))
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, responseEntry := range response {
|
||||||
|
if _, ok := testIdMapParticipants[responseEntry.ParticipantId]; !ok {
|
||||||
|
t.Fatalf("expected exist {ParticipantId}")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(responseEntry.DkgDeal) == 0 {
|
||||||
|
t.Fatalf("expected {DkgDeal} non zero length")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(testIdMapParticipants[responseEntry.ParticipantId].DkgDeal, responseEntry.DkgDeal) {
|
||||||
|
t.Fatalf("expected valid {DkgDeal}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Responses
|
||||||
|
func Test_DkgProposal_EventDKGResponseConfirmationReceived(t *testing.T) {
|
||||||
|
var fsmResponse *fsm.Response
|
||||||
|
|
||||||
|
pCounter := 0
|
||||||
|
for participantId, participant := range testIdMapParticipants {
|
||||||
|
pCounter--
|
||||||
|
testFSMInstance, err := FromDump(testFSMDump)
|
||||||
|
|
||||||
compareErrNil(t, err)
|
compareErrNil(t, err)
|
||||||
|
|
||||||
compareFSMInstanceNotNil(t, testFSMInstance)
|
compareFSMInstanceNotNil(t, testFSMInstance)
|
||||||
|
|
||||||
if _, ok := testParticipants[participant.ParticipantId]; !ok {
|
fsmResponse, testFSMDump, err = testFSMInstance.Do(dpf.EventDKGResponseConfirmationReceived, requests.DKGProposalResponseConfirmationRequest{
|
||||||
t.Fatalf("not found external user data for response fingerprint")
|
ParticipantId: participantId,
|
||||||
}
|
Response: participant.DkgResponse,
|
||||||
|
|
||||||
responseMock := make([]byte, 128)
|
|
||||||
_, err := rand.Read(responseMock)
|
|
||||||
if err != nil {
|
|
||||||
compareErrNil(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fsmResponse, dump, err = testFSMInstance.Do(dpf.EventDKGResponseConfirmationReceived, requests.DKGProposalResponseConfirmationRequest{
|
|
||||||
ParticipantId: participant.ParticipantId,
|
|
||||||
Response: responseMock,
|
|
||||||
CreatedAt: tm,
|
CreatedAt: tm,
|
||||||
})
|
})
|
||||||
|
|
||||||
compareErrNil(t, err)
|
compareErrNil(t, err)
|
||||||
|
|
||||||
compareDumpNotZero(t, dump)
|
compareDumpNotZero(t, testFSMDump)
|
||||||
|
|
||||||
compareFSMResponseNotNil(t, fsmResponse)
|
compareFSMResponseNotNil(t, fsmResponse)
|
||||||
|
|
||||||
|
@ -345,57 +422,79 @@ func Test_SignatureProposal_Positive(t *testing.T) {
|
||||||
|
|
||||||
compareState(t, dpf.StateDkgMasterKeyAwaitConfirmations, fsmResponse.State)
|
compareState(t, dpf.StateDkgMasterKeyAwaitConfirmations, fsmResponse.State)
|
||||||
|
|
||||||
// Master keys
|
response, ok := fsmResponse.Data.(responses.DKGProposalResponseParticipantResponse)
|
||||||
|
|
||||||
masterKeyMock := make([]byte, 128)
|
if !ok {
|
||||||
_, err = rand.Read(masterKeyMock)
|
t.Fatalf("expected response {DKGProposalResponseParticipantResponse}")
|
||||||
if err != nil {
|
|
||||||
compareErrNil(t, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, participant := range participantsMap {
|
if len(response) != len(testParticipantsListRequest.Participants) {
|
||||||
participantCounter--
|
t.Fatalf("expected response len {%d}, got {%d}", len(testParticipantsListRequest.Participants), len(response))
|
||||||
testFSMInstance, err = FromDump(dump)
|
}
|
||||||
|
|
||||||
|
for _, responseEntry := range response {
|
||||||
|
if _, ok := testIdMapParticipants[responseEntry.ParticipantId]; !ok {
|
||||||
|
t.Fatalf("expected exist {ParticipantId}")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(responseEntry.DkgResponse) == 0 {
|
||||||
|
t.Fatalf("expected {DkgResponse} non zero length")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(testIdMapParticipants[responseEntry.ParticipantId].DkgResponse, responseEntry.DkgResponse) {
|
||||||
|
t.Fatalf("expected valid {DkgResponse}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Master keys
|
||||||
|
func Test_DkgProposal_EventDKGMasterKeyConfirmationReceived(t *testing.T) {
|
||||||
|
var fsmResponse *fsm.Response
|
||||||
|
|
||||||
|
pCounter := 0
|
||||||
|
for participantId, participant := range testIdMapParticipants {
|
||||||
|
pCounter--
|
||||||
|
testFSMInstance, err := FromDump(testFSMDump)
|
||||||
|
|
||||||
compareErrNil(t, err)
|
compareErrNil(t, err)
|
||||||
|
|
||||||
compareFSMInstanceNotNil(t, testFSMInstance)
|
compareFSMInstanceNotNil(t, testFSMInstance)
|
||||||
|
|
||||||
if _, ok := testParticipants[participant.ParticipantId]; !ok {
|
fsmResponse, testFSMDump, err = testFSMInstance.Do(dpf.EventDKGMasterKeyConfirmationReceived, requests.DKGProposalMasterKeyConfirmationRequest{
|
||||||
t.Fatalf("not found external user data for response fingerprint")
|
ParticipantId: participantId,
|
||||||
}
|
MasterKey: participant.DkgPartialKey,
|
||||||
|
|
||||||
fsmResponse, dump, err = testFSMInstance.Do(dpf.EventDKGMasterKeyConfirmationReceived, requests.DKGProposalMasterKeyConfirmationRequest{
|
|
||||||
ParticipantId: participant.ParticipantId,
|
|
||||||
MasterKey: masterKeyMock,
|
|
||||||
CreatedAt: tm,
|
CreatedAt: tm,
|
||||||
})
|
})
|
||||||
|
|
||||||
compareErrNil(t, err)
|
compareErrNil(t, err)
|
||||||
|
|
||||||
compareDumpNotZero(t, dump)
|
compareDumpNotZero(t, testFSMDump)
|
||||||
|
|
||||||
compareFSMResponseNotNil(t, fsmResponse)
|
compareFSMResponseNotNil(t, fsmResponse)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
compareState(t, dpf.StateDkgMasterKeyCollected, fsmResponse.State)
|
compareState(t, dpf.StateDkgMasterKeyCollected, fsmResponse.State)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Signing
|
// Signing
|
||||||
|
func Test_SigningProposal_Positive(t *testing.T) {
|
||||||
|
var fsmResponse *fsm.Response
|
||||||
|
|
||||||
testFSMInstance, err = FromDump(dump)
|
testFSMInstance, err := FromDump(testFSMDump)
|
||||||
|
|
||||||
compareErrNil(t, err)
|
compareErrNil(t, err)
|
||||||
|
|
||||||
compareFSMInstanceNotNil(t, testFSMInstance)
|
compareFSMInstanceNotNil(t, testFSMInstance)
|
||||||
|
|
||||||
fsmResponse, dump, err = testFSMInstance.Do(sif.EventSigningInit, requests.DefaultRequest{
|
fsmResponse, testFSMDump, err = testFSMInstance.Do(sif.EventSigningInit, requests.DefaultRequest{
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
})
|
})
|
||||||
|
|
||||||
compareErrNil(t, err)
|
compareErrNil(t, err)
|
||||||
|
|
||||||
compareDumpNotZero(t, dump)
|
compareDumpNotZero(t, testFSMDump)
|
||||||
|
|
||||||
compareFSMResponseNotNil(t, fsmResponse)
|
compareFSMResponseNotNil(t, fsmResponse)
|
||||||
|
|
||||||
|
@ -403,13 +502,13 @@ func Test_SignatureProposal_Positive(t *testing.T) {
|
||||||
|
|
||||||
// Start
|
// Start
|
||||||
|
|
||||||
testFSMInstance, err = FromDump(dump)
|
testFSMInstance, err = FromDump(testFSMDump)
|
||||||
|
|
||||||
compareErrNil(t, err)
|
compareErrNil(t, err)
|
||||||
|
|
||||||
compareFSMInstanceNotNil(t, testFSMInstance)
|
compareFSMInstanceNotNil(t, testFSMInstance)
|
||||||
|
|
||||||
fsmResponse, dump, err = testFSMInstance.Do(sif.EventSigningStart, requests.SigningProposalStartRequest{
|
fsmResponse, testFSMDump, err = testFSMInstance.Do(sif.EventSigningStart, requests.SigningProposalStartRequest{
|
||||||
ParticipantId: 1,
|
ParticipantId: 1,
|
||||||
SrcPayload: []byte("message to sign"),
|
SrcPayload: []byte("message to sign"),
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
|
@ -417,7 +516,7 @@ func Test_SignatureProposal_Positive(t *testing.T) {
|
||||||
|
|
||||||
compareErrNil(t, err)
|
compareErrNil(t, err)
|
||||||
|
|
||||||
compareDumpNotZero(t, dump)
|
compareDumpNotZero(t, testFSMDump)
|
||||||
|
|
||||||
compareFSMResponseNotNil(t, fsmResponse)
|
compareFSMResponseNotNil(t, fsmResponse)
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,6 @@ func (m *SigningProposalFSM) actionProposalResponseByParticipant(inEvent fsm.Eve
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy(signingProposalParticipant.DkgCommit, request.DkgCommit)
|
|
||||||
switch inEvent {
|
switch inEvent {
|
||||||
case EventConfirmSigningConfirmation:
|
case EventConfirmSigningConfirmation:
|
||||||
signingProposalParticipant.Status = internal.SigningConfirmed
|
signingProposalParticipant.Status = internal.SigningConfirmed
|
||||||
|
@ -227,6 +226,7 @@ func (m *SigningProposalFSM) actionPartialKeyConfirmationReceived(inEvent fsm.Ev
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
signingProposalParticipant.PartialKey = make([]byte, len(request.PartialKey))
|
||||||
copy(signingProposalParticipant.PartialKey, request.PartialKey)
|
copy(signingProposalParticipant.PartialKey, request.PartialKey)
|
||||||
signingProposalParticipant.Status = internal.SigningPartialKeysConfirmed
|
signingProposalParticipant.Status = internal.SigningPartialKeysConfirmed
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue