Skip to content

Commit

Permalink
add tests for constrains on shares vs threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
rohenaz committed Aug 27, 2024
1 parent 489af51 commit deb8bad
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Binary file added primitives/ec/__debug_bin615424829
Binary file not shown.
31 changes: 31 additions & 0 deletions primitives/ec/privatekey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,37 @@ func TestPrivateKeyToKeyShares(t *testing.T) {
}
}

// threshold should be between 2 and 99"
func TestThresholdLargerThanTotalShares(t *testing.T) {
privateKey, _ := NewPrivateKey()
_, err := privateKey.ToKeyShares(100, 5)
if err == nil {
t.Errorf("Expected error for threshold must be less than total shares")
}
}

func TestTotalSharesLessThanTwo(t *testing.T) {
privateKey, _ := NewPrivateKey()
_, err := privateKey.ToKeyShares(2, 1)
if err == nil {
t.Errorf("Expected error for totalShares must be at least 2")
}
}

func TestFewerPointsThanThreshold(t *testing.T) {
privateKey, _ := NewPrivateKey()
shares, err := privateKey.ToKeyShares(3, 5)
if err != nil {
t.Fatalf("Failed to create key shares: %v", err)
}

shares.Points = shares.Points[:2]
_, err = PrivateKeyFromKeyShares(shares)
if err == nil {
t.Errorf("Expected error for fewer points than threshold")
}
}

// should throw an error for invalid threshold
func TestInvalidThreshold(t *testing.T) {
privateKey, _ := NewPrivateKey()
Expand Down

0 comments on commit deb8bad

Please sign in to comment.