forked from bnb-chain/tss-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsafe_prime_test.go
55 lines (47 loc) · 1.38 KB
/
safe_prime_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright © 2019 Binance
//
// This file is part of Binance. The full Binance copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.
package common
import (
"context"
"math/big"
"runtime"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func Test_getSafePrime(t *testing.T) {
prime := new(big.Int).SetInt64(5)
sPrime := getSafePrime(prime)
assert.True(t, sPrime.ProbablyPrime(50))
}
func Test_getSafePrime_Bad(t *testing.T) {
prime := new(big.Int).SetInt64(12)
sPrime := getSafePrime(prime)
assert.False(t, sPrime.ProbablyPrime(50))
}
func Test_Validate(t *testing.T) {
prime := new(big.Int).SetInt64(5)
sPrime := getSafePrime(prime)
sgp := &GermainSafePrime{prime, sPrime}
assert.True(t, sgp.Validate())
}
func Test_Validate_Bad(t *testing.T) {
prime := new(big.Int).SetInt64(12)
sPrime := getSafePrime(prime)
sgp := &GermainSafePrime{prime, sPrime}
assert.False(t, sgp.Validate())
}
func TestGetRandomGermainPrimeConcurrent(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Minute)
defer cancel()
sgps, err := GetRandomSafePrimesConcurrent(ctx, 1024, 2, runtime.NumCPU())
assert.NoError(t, err)
assert.Equal(t, 2, len(sgps))
for _, sgp := range sgps {
assert.NotNil(t, sgp)
assert.True(t, sgp.Validate())
}
}