forked from babylonlabs-io/babylon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbtc_schnorr_pub_rand_test.go
More file actions
36 lines (28 loc) · 960 Bytes
/
Copy pathbtc_schnorr_pub_rand_test.go
File metadata and controls
36 lines (28 loc) · 960 Bytes
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
package types_test
import (
"math/rand"
"testing"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/stretchr/testify/require"
"github.com/babylonlabs-io/babylon/v4/testutil/datagen"
"github.com/babylonlabs-io/babylon/v4/types"
)
func FuzzSchnorrPubRand(f *testing.F) {
datagen.AddRandomSeedsToFuzzer(f, 10)
f.Fuzz(func(t *testing.T, seed int64) {
r := rand.New(rand.NewSource(seed))
randBytes := datagen.GenRandomByteArray(r, 32)
var fieldVal btcec.FieldVal
fieldVal.SetByteSlice(randBytes)
// FieldVal -> SchnorrPubRand -> FieldVal
pubRand := types.NewSchnorrPubRandFromFieldVal(&fieldVal)
fieldVal2 := pubRand.ToFieldValNormalized()
require.True(t, fieldVal.Equals(fieldVal2))
// SchnorrPubRand -> bytes -> SchnorrPubRand
randBytes2 := pubRand.MustMarshal()
pubRand2, err := types.NewSchnorrPubRand(randBytes)
require.NoError(t, err)
require.Equal(t, randBytes, randBytes2)
require.Equal(t, pubRand, pubRand2)
})
}