github.com/consensys/gnark-crypto@v0.14.0/ecc/bn254/ecdsa/marshal_test.go (about) 1 // Copyright 2020 Consensys Software Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Code generated by consensys/gnark-crypto DO NOT EDIT 16 17 package ecdsa 18 19 import ( 20 "crypto/rand" 21 "crypto/subtle" 22 "testing" 23 24 "github.com/leanovate/gopter" 25 "github.com/leanovate/gopter/prop" 26 ) 27 28 const ( 29 nbFuzzShort = 10 30 nbFuzz = 100 31 ) 32 33 func TestSerialization(t *testing.T) { 34 t.Parallel() 35 parameters := gopter.DefaultTestParameters() 36 if testing.Short() { 37 parameters.MinSuccessfulTests = nbFuzzShort 38 } else { 39 parameters.MinSuccessfulTests = nbFuzz 40 } 41 42 properties := gopter.NewProperties(parameters) 43 44 properties.Property("[BN254] ECDSA serialization: SetBytes(Bytes()) should stay the same", prop.ForAll( 45 func() bool { 46 privKey, _ := GenerateKey(rand.Reader) 47 48 var end PrivateKey 49 buf := privKey.Bytes() 50 n, err := end.SetBytes(buf[:]) 51 if err != nil { 52 return false 53 } 54 if n != sizePrivateKey { 55 return false 56 } 57 58 return end.PublicKey.Equal(&privKey.PublicKey) && subtle.ConstantTimeCompare(end.scalar[:], privKey.scalar[:]) == 1 59 60 }, 61 )) 62 63 properties.TestingRun(t, gopter.ConsoleReporter(false)) 64 }