Skip to content

Commit

Permalink
declare common constant for polynomial create failure
Browse files Browse the repository at this point in the history
  • Loading branch information
rohenaz committed Aug 27, 2024
1 parent deb8bad commit 77bd468
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Binary file removed primitives/ec/__debug_bin615424829
Binary file not shown.
16 changes: 6 additions & 10 deletions primitives/ec/privatekey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ type privateTestVector struct {
ExpectedPrivateKey string `json:"privateKey"`
}

const createPolyFail = "Failed to create polynomial: %v"

func TestBRC42PrivateVectors(t *testing.T) {
// Determine the directory of the current test file
_, currentFile, _, ok := runtime.Caller(0)
Expand Down Expand Up @@ -121,7 +123,7 @@ func TestPolynomialFromPrivateKey(t *testing.T) {

poly, err := pk.ToPolynomial(threshold)
if err != nil {
t.Fatalf("Failed to create polynomial: %v", err)
t.Fatalf(createPolyFail, err)
}

if len(poly.Points) != threshold {
Expand Down Expand Up @@ -159,7 +161,7 @@ func TestPolynomialFullProcess(t *testing.T) {
// Generate the polynomial
poly, err := privateKey.ToPolynomial(threshold)
if err != nil {
t.Fatalf("Failed to create polynomial: %v", err)
t.Fatalf(createPolyFail, err)
}

// Log the generated polynomial points
Expand Down Expand Up @@ -206,7 +208,7 @@ func TestPolynomialDifferentThresholdsAndShares(t *testing.T) {
privateKey, _ := NewPrivateKey()
poly, err := privateKey.ToPolynomial(tc.threshold)
if err != nil {
t.Fatalf("Failed to create polynomial: %v", err)
t.Fatalf(createPolyFail, err)
}

shares := make([]*shamir.PointInFiniteField, tc.totalShares)
Expand Down Expand Up @@ -355,7 +357,7 @@ func TestPrivateKeyToKeyShares(t *testing.T) {
// it should split the private key into shares correctly
shares, err := privateKey.ToKeyShares(threshold, totalShares)
if err != nil {
t.Fatalf("Failed to create key shares: %v", err)
t.Fatalf("Failed to create initial key shares: %v", err)
}

backup, err := shares.ToBackupFormat()
Expand All @@ -367,12 +369,6 @@ func TestPrivateKeyToKeyShares(t *testing.T) {
t.Errorf("Incorrect number of shares. Expected %d, got %d", totalShares, len(backup))
}

for _, share := range shares.Points {
if share == nil {
t.Errorf("Share is nil")
}
}

if shares.Threshold != threshold {
t.Errorf("Incorrect threshold. Expected %d, got %d", threshold, shares.Threshold)
}
Expand Down

0 comments on commit 77bd468

Please sign in to comment.