github.com/amazechain/amc@v0.1.3/common/crypto/bls/lbs_ntest.go (about)

     1  //go:build (android || (linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && !blst_disabled
     2  
     3  package bls
     4  
     5  import (
     6  	"bytes"
     7  	"encoding/hex"
     8  	"errors"
     9  	"strings"
    10  
    11  	"github.com/amazechain/amc/common/crypto/bls/blst"
    12  	"github.com/amazechain/amc/common/crypto/bls/common"
    13  	"github.com/stretchr/testify/assert"
    14  	//"github.com/stretchr/testify/assert"
    15  )
    16  
    17  func E2P(err error) {
    18  	if err != nil {
    19  		panic(err)
    20  	}
    21  }
    22  
    23  func TestSignVerify2() error {
    24  	priv, err := RandKey()
    25  	if err != nil {
    26  		return err
    27  	}
    28  	pub := priv.PublicKey()
    29  	msg := []byte("hello")
    30  	sig := priv.Sign(msg)
    31  	if !sig.Verify(pub, msg) {
    32  		return errors.New("Signature did not verify")
    33  	}
    34  	return nil
    35  }
    36  
    37  func TestAggregateVerify2() error {
    38  	pubkeys := make([]common.PublicKey, 0, 100)
    39  	sigs := make([]common.Signature, 0, 100)
    40  	var msgs [][32]byte
    41  	for i := 0; i < 100; i++ {
    42  		msg := [32]byte{'h', 'e', 'l', 'l', 'o', byte(i)}
    43  		priv, err := RandKey()
    44  		if err != nil {
    45  			return err
    46  		}
    47  		pub := priv.PublicKey()
    48  		sig := priv.Sign(msg[:])
    49  		pubkeys = append(pubkeys, pub)
    50  		sigs = append(sigs, sig)
    51  		msgs = append(msgs, msg)
    52  	}
    53  	aggSig := AggregateSignatures(sigs)
    54  	if !aggSig.AggregateVerify(pubkeys, msgs) {
    55  		return errors.New("Signature did not verify")
    56  	}
    57  	return nil
    58  }
    59  
    60  func TestAggregateVerify_CompressedSignatures2() error {
    61  	pubkeys := make([]common.PublicKey, 0, 100)
    62  	sigs := make([]common.Signature, 0, 100)
    63  	var sigBytes [][]byte
    64  	var msgs [][32]byte
    65  	for i := 0; i < 100; i++ {
    66  		msg := [32]byte{'h', 'e', 'l', 'l', 'o', byte(i)}
    67  		priv, err := RandKey()
    68  		if err != nil {
    69  			return err
    70  		}
    71  		pub := priv.PublicKey()
    72  		sig := priv.Sign(msg[:])
    73  		pubkeys = append(pubkeys, pub)
    74  		sigs = append(sigs, sig)
    75  		sigBytes = append(sigBytes, sig.Marshal())
    76  		msgs = append(msgs, msg)
    77  	}
    78  	aggSig := AggregateSignatures(sigs)
    79  	if !aggSig.AggregateVerify(pubkeys, msgs) {
    80  		return errors.New("Signature did not verify")
    81  	}
    82  
    83  	aggSig2, err := AggregateCompressedSignatures(sigBytes)
    84  	if err != nil {
    85  		return err
    86  	}
    87  	if bytes.Compare(aggSig.Marshal(), aggSig2.Marshal()) != 0 {
    88  		return errors.New("Signature did not match up")
    89  	}
    90  	return nil
    91  }
    92  
    93  func TestFastAggregateVerify2() error {
    94  	pubkeys := make([]common.PublicKey, 0, 100)
    95  	sigs := make([]common.Signature, 0, 100)
    96  	msg := [32]byte{'h', 'e', 'l', 'l', 'o'}
    97  	for i := 0; i < 100; i++ {
    98  		priv, err := RandKey()
    99  		if err != nil {
   100  			return err
   101  		}
   102  		pub := priv.PublicKey()
   103  		sig := priv.Sign(msg[:])
   104  		pubkeys = append(pubkeys, pub)
   105  		sigs = append(sigs, sig)
   106  	}
   107  	aggSig := AggregateSignatures(sigs)
   108  	if !aggSig.FastAggregateVerify(pubkeys, msg) {
   109  		return errors.New("Signature did not verify")
   110  	}
   111  	return nil
   112  }
   113  
   114  func TestVerifyCompressed2() error {
   115  	priv, err := RandKey()
   116  	if err != nil {
   117  		return err
   118  	}
   119  	pub := priv.PublicKey()
   120  	msg := []byte("hello")
   121  	sig := priv.Sign(msg)
   122  	if !sig.Verify(pub, msg) {
   123  		return errors.New("Non compressed signature did not verify")
   124  	}
   125  
   126  	if !blst.VerifyCompressed(sig.Marshal(), pub.Marshal(), msg) {
   127  		return errors.New("Compressed signatures and pubkeys did not verify")
   128  	}
   129  	return nil
   130  }
   131  
   132  func TestMultipleSignatureVerification2() error {
   133  	pubkeys := make([]common.PublicKey, 0, 100)
   134  	sigs := make([][]byte, 0, 100)
   135  	var msgs [][32]byte
   136  	for i := 0; i < 100; i++ {
   137  		msg := [32]byte{'h', 'e', 'l', 'l', 'o', byte(i)}
   138  		priv, err := RandKey()
   139  		if err != nil {
   140  			return err
   141  		}
   142  		pub := priv.PublicKey()
   143  		sig := priv.Sign(msg[:]).Marshal()
   144  		pubkeys = append(pubkeys, pub)
   145  		sigs = append(sigs, sig)
   146  		msgs = append(msgs, msg)
   147  	}
   148  	verify, err := VerifyMultipleSignatures(sigs, msgs, pubkeys)
   149  	if err != nil {
   150  		return err
   151  	}
   152  	if !verify {
   153  		return errors.New("Signature did not verify")
   154  	}
   155  	return nil
   156  }
   157  
   158  func TestFastAggregateVerify_ReturnsFalseOnEmptyPubKeyList2() error {
   159  	var pubkeys []common.PublicKey
   160  	msg := [32]byte{'h', 'e', 'l', 'l', 'o'}
   161  
   162  	aggSig := NewAggregateSignature()
   163  	if aggSig.FastAggregateVerify(pubkeys, msg) {
   164  		return errors.New("Expected FastAggregateVerify to return false with empty input")
   165  	}
   166  	return nil
   167  }
   168  
   169  func TestEth2FastAggregateVerify2() error {
   170  	pubkeys := make([]common.PublicKey, 0, 100)
   171  	sigs := make([]common.Signature, 0, 100)
   172  	msg := [32]byte{'h', 'e', 'l', 'l', 'o'}
   173  	for i := 0; i < 100; i++ {
   174  		priv, err := RandKey()
   175  		if err != nil {
   176  			return err
   177  		}
   178  		pub := priv.PublicKey()
   179  		sig := priv.Sign(msg[:])
   180  		pubkeys = append(pubkeys, pub)
   181  		sigs = append(sigs, sig)
   182  	}
   183  	aggSig := AggregateSignatures(sigs)
   184  	if !aggSig.Eth2FastAggregateVerify(pubkeys, msg) {
   185  		return errors.New("Signature did not verify")
   186  	}
   187  	return nil
   188  }
   189  
   190  func TestEth2FastAggregateVerify_ReturnsFalseOnEmptyPubKeyList2() error {
   191  	var pubkeys []common.PublicKey
   192  	msg := [32]byte{'h', 'e', 'l', 'l', 'o'}
   193  
   194  	aggSig := NewAggregateSignature()
   195  	if aggSig.Eth2FastAggregateVerify(pubkeys, msg) {
   196  		return errors.New("Expected Eth2FastAggregateVerify to return false with empty input")
   197  	}
   198  	return nil
   199  }
   200  
   201  func TestEth2FastAggregateVerify_ReturnsTrueOnG2PointAtInfinity2() error {
   202  	var pubkeys []common.PublicKey
   203  	msg := [32]byte{'h', 'e', 'l', 'l', 'o'}
   204  
   205  	g2PointAtInfinity := append([]byte{0xC0}, make([]byte, 95)...)
   206  	aggSig, err := SignatureFromBytes(g2PointAtInfinity)
   207  	if err != nil {
   208  		return err
   209  	}
   210  	if !aggSig.Eth2FastAggregateVerify(pubkeys, msg) {
   211  		return errors.New("Eth2FastAggregateVerify error")
   212  	}
   213  	return nil
   214  }
   215  
   216  func TestSignatureFromBytes2() error {
   217  	tests := []struct {
   218  		name  string
   219  		input []byte
   220  		err   error
   221  	}{
   222  		{
   223  			name: "Nil",
   224  			err:  errors.New("signature must be 96 bytes"),
   225  		},
   226  		{
   227  			name:  "Empty",
   228  			input: []byte{},
   229  			err:   errors.New("signature must be 96 bytes"),
   230  		},
   231  		{
   232  			name:  "Short",
   233  			input: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
   234  			err:   errors.New("signature must be 96 bytes"),
   235  		},
   236  		{
   237  			name:  "Long",
   238  			input: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
   239  			err:   errors.New("signature must be 96 bytes"),
   240  		},
   241  		{
   242  			name:  "Bad",
   243  			input: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
   244  			err:   errors.New("could not unmarshal bytes into signature"),
   245  		},
   246  		{
   247  			name:  "Good",
   248  			input: []byte{0xab, 0xb0, 0x12, 0x4c, 0x75, 0x74, 0xf2, 0x81, 0xa2, 0x93, 0xf4, 0x18, 0x5c, 0xad, 0x3c, 0xb2, 0x26, 0x81, 0xd5, 0x20, 0x91, 0x7c, 0xe4, 0x66, 0x65, 0x24, 0x3e, 0xac, 0xb0, 0x51, 0x00, 0x0d, 0x8b, 0xac, 0xf7, 0x5e, 0x14, 0x51, 0x87, 0x0c, 0xa6, 0xb3, 0xb9, 0xe6, 0xc9, 0xd4, 0x1a, 0x7b, 0x02, 0xea, 0xd2, 0x68, 0x5a, 0x84, 0x18, 0x8a, 0x4f, 0xaf, 0xd3, 0x82, 0x5d, 0xaf, 0x6a, 0x98, 0x96, 0x25, 0xd7, 0x19, 0xcc, 0xd2, 0xd8, 0x3a, 0x40, 0x10, 0x1f, 0x4a, 0x45, 0x3f, 0xca, 0x62, 0x87, 0x8c, 0x89, 0x0e, 0xca, 0x62, 0x23, 0x63, 0xf9, 0xdd, 0xb8, 0xf3, 0x67, 0xa9, 0x1e, 0x84},
   249  		},
   250  	}
   251  
   252  	for _, test := range tests {
   253  		res, err := SignatureFromBytes(test.input)
   254  		if test.err != nil {
   255  			if err == nil {
   256  				return errors.New("No error returned")
   257  			}
   258  			//assert.ErrorContains(t, test.err, err.Error(), "Unexpected error returned")
   259  		} else {
   260  			if err != nil {
   261  				return err
   262  			}
   263  			if bytes.Compare(res.Marshal(), test.input) != 0 {
   264  				return errors.New("bytes.Compare(res.Marshal(), test.input)!=0")
   265  			}
   266  		}
   267  	}
   268  	return nil
   269  }
   270  
   271  func TestMultipleSignatureFromBytes2() error {
   272  	tests := []struct {
   273  		name  string
   274  		input [][]byte
   275  		err   error
   276  	}{
   277  		{
   278  			name: "Nil",
   279  			err:  errors.New("0 signatures provided to the method"),
   280  		},
   281  		{
   282  			name:  "Empty",
   283  			input: [][]byte{},
   284  			err:   errors.New("0 signatures provided to the method"),
   285  		},
   286  		{
   287  			name:  "Short",
   288  			input: [][]byte{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
   289  			err:   errors.New("signature must be 96 bytes"),
   290  		},
   291  		{
   292  			name:  "Long",
   293  			input: [][]byte{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
   294  			err:   errors.New("signature must be 96 bytes"),
   295  		},
   296  		{
   297  			name: "Bad",
   298  			input: [][]byte{{0x8f, 0xc0, 0xb4, 0x9e, 0x2e, 0xac, 0x50, 0x86, 0xe2, 0xe2, 0xaa, 0xf, 0xdc, 0x54, 0x23, 0x51, 0x6, 0xd8, 0x29, 0xf5, 0xae, 0x3, 0x5d, 0xb8, 0x31, 0x4d, 0x26, 0x3, 0x48, 0x18, 0xb9, 0x1f, 0x6b, 0xd7, 0x86, 0xb4, 0xa2, 0x69, 0xc7, 0xe7, 0xf5, 0xc0, 0x93, 0x19, 0x6e, 0xfd, 0x33, 0xb8, 0x1, 0xe1, 0x1f, 0x4e, 0xb4, 0xb1, 0xa0, 0x1, 0x30, 0x48, 0x8a, 0x6c, 0x97, 0x29, 0xd6, 0xcb, 0x1c, 0x45, 0xef, 0x87, 0xba, 0x4f, 0xce, 0x22, 0x84, 0x48, 0xad, 0x16, 0xf7, 0x5c, 0xb2, 0xa8, 0x34, 0xb9, 0xee, 0xb8, 0xbf, 0xe5, 0x58, 0x2c, 0x44, 0x7b, 0x1f, 0x9c, 0x22, 0x26, 0x3a, 0x22},
   299  				{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
   300  			err: errors.New("could not unmarshal bytes into signature"),
   301  		},
   302  		{
   303  			name: "Good",
   304  			input: [][]byte{
   305  				{0xab, 0xb0, 0x12, 0x4c, 0x75, 0x74, 0xf2, 0x81, 0xa2, 0x93, 0xf4, 0x18, 0x5c, 0xad, 0x3c, 0xb2, 0x26, 0x81, 0xd5, 0x20, 0x91, 0x7c, 0xe4, 0x66, 0x65, 0x24, 0x3e, 0xac, 0xb0, 0x51, 0x00, 0x0d, 0x8b, 0xac, 0xf7, 0x5e, 0x14, 0x51, 0x87, 0x0c, 0xa6, 0xb3, 0xb9, 0xe6, 0xc9, 0xd4, 0x1a, 0x7b, 0x02, 0xea, 0xd2, 0x68, 0x5a, 0x84, 0x18, 0x8a, 0x4f, 0xaf, 0xd3, 0x82, 0x5d, 0xaf, 0x6a, 0x98, 0x96, 0x25, 0xd7, 0x19, 0xcc, 0xd2, 0xd8, 0x3a, 0x40, 0x10, 0x1f, 0x4a, 0x45, 0x3f, 0xca, 0x62, 0x87, 0x8c, 0x89, 0x0e, 0xca, 0x62, 0x23, 0x63, 0xf9, 0xdd, 0xb8, 0xf3, 0x67, 0xa9, 0x1e, 0x84},
   306  				{0xb7, 0x86, 0xe5, 0x7, 0x43, 0xe2, 0x53, 0x6c, 0x15, 0x51, 0x9c, 0x6, 0x2a, 0xa7, 0xe5, 0x12, 0xf9, 0xb7, 0x77, 0x93, 0x3f, 0x55, 0xb3, 0xaf, 0x38, 0xf7, 0x39, 0xe4, 0x84, 0x6d, 0x88, 0x44, 0x52, 0x77, 0x65, 0x42, 0x95, 0xd9, 0x79, 0x93, 0x7e, 0xc8, 0x12, 0x60, 0xe3, 0x24, 0xea, 0x8, 0x10, 0x52, 0xcd, 0xd2, 0x7f, 0x5d, 0x25, 0x3a, 0xa8, 0x9b, 0xb7, 0x65, 0xa9, 0x31, 0xea, 0x7c, 0x85, 0x13, 0x53, 0xc0, 0xa3, 0x88, 0xd1, 0xa5, 0x54, 0x85, 0x2, 0x2d, 0xf8, 0xa1, 0xd7, 0xc1, 0x60, 0x58, 0x93, 0xec, 0x7c, 0xf9, 0x33, 0x43, 0x4, 0x48, 0x40, 0x97, 0xef, 0x67, 0x2a, 0x27},
   307  				{0xb2, 0x12, 0xd0, 0xec, 0x46, 0x76, 0x6b, 0x24, 0x71, 0x91, 0x2e, 0xa8, 0x53, 0x9a, 0x48, 0xa3, 0x78, 0x30, 0xc, 0xe8, 0xf0, 0x86, 0xa3, 0x68, 0xec, 0xe8, 0x96, 0x43, 0x34, 0xda, 0xf, 0xf4, 0x65, 0x48, 0xbb, 0xe0, 0x92, 0xa1, 0x8, 0x12, 0x18, 0x46, 0xe6, 0x4a, 0xd6, 0x92, 0x88, 0xe, 0x2, 0xf5, 0xf3, 0x2a, 0x96, 0xb1, 0x4, 0xf1, 0x11, 0xa9, 0x92, 0x79, 0x52, 0x0, 0x64, 0x34, 0xeb, 0x25, 0xe, 0xf4, 0x29, 0x6b, 0x39, 0x4e, 0x28, 0x78, 0xfe, 0x25, 0xa3, 0xc0, 0x88, 0x5a, 0x40, 0xfd, 0x71, 0x37, 0x63, 0x79, 0xcd, 0x6b, 0x56, 0xda, 0xee, 0x91, 0x26, 0x72, 0xfc, 0xbc},
   308  				{0x8f, 0xc0, 0xb4, 0x9e, 0x2e, 0xac, 0x50, 0x86, 0xe2, 0xe2, 0xaa, 0xf, 0xdc, 0x54, 0x23, 0x51, 0x6, 0xd8, 0x29, 0xf5, 0xae, 0x3, 0x5d, 0xb8, 0x31, 0x4d, 0x26, 0x3, 0x48, 0x18, 0xb9, 0x1f, 0x6b, 0xd7, 0x86, 0xb4, 0xa2, 0x69, 0xc7, 0xe7, 0xf5, 0xc0, 0x93, 0x19, 0x6e, 0xfd, 0x33, 0xb8, 0x1, 0xe1, 0x1f, 0x4e, 0xb4, 0xb1, 0xa0, 0x1, 0x30, 0x48, 0x8a, 0x6c, 0x97, 0x29, 0xd6, 0xcb, 0x1c, 0x45, 0xef, 0x87, 0xba, 0x4f, 0xce, 0x22, 0x84, 0x48, 0xad, 0x16, 0xf7, 0x5c, 0xb2, 0xa8, 0x34, 0xb9, 0xee, 0xb8, 0xbf, 0xe5, 0x58, 0x2c, 0x44, 0x7b, 0x1f, 0x9c, 0x22, 0x26, 0x3a, 0x22},
   309  			},
   310  		},
   311  	}
   312  
   313  	for _, test := range tests {
   314  		res, err := MultipleSignaturesFromBytes(test.input)
   315  		if test.err != nil {
   316  			if err == nil {
   317  				return errors.New("No error returned")
   318  			}
   319  			if !strings.Contains(test.err.Error(), err.Error()) {
   320  				return errors.New("Unexpected error returned")
   321  			}
   322  		} else {
   323  			if err != nil {
   324  				return err
   325  			}
   326  			for i, s := range res {
   327  				if bytes.Compare(s.Marshal(), test.input[i]) != 0 {
   328  					return errors.New("329:bytes.Compare(s.Marshal(), test.input[i])!=0")
   329  				}
   330  			}
   331  		}
   332  	}
   333  	return nil
   334  }
   335  
   336  func TestCopy2() error {
   337  	priv, err := RandKey()
   338  	if err != nil {
   339  		return err
   340  	}
   341  
   342  	signatureA := priv.Sign([]byte("foo"))
   343  	signatureB := signatureA.Copy()
   344  
   345  	if signatureA == signatureB {
   346  		return errors.New("signatureA equal to signatureB")
   347  	}
   348  
   349  	signatureC := priv.Sign([]byte("bar"))
   350  	if assert.ObjectsAreEqual(signatureC, signatureB) {
   351  		return errors.New("assert.ObjectsAreEqual(signatureC, signatureB){")
   352  	}
   353  	return nil
   354  }
   355  
   356  func TestSecretKeyFromBytes2() error {
   357  	b, _ := hex.DecodeString("5de474bbf3fee5dfda9047287f596c6e6c0271876305357e399fffba6a5f9a9f")
   358  	tests := []struct {
   359  		name  string
   360  		input []byte
   361  		err   error
   362  	}{
   363  		{
   364  			name: "Nil",
   365  			err:  errors.New("secret key must be 32 bytes"),
   366  		},
   367  		{
   368  			name:  "Empty",
   369  			input: []byte{},
   370  			err:   errors.New("secret key must be 32 bytes"),
   371  		},
   372  		{
   373  			name:  "Short",
   374  			input: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
   375  			err:   errors.New("secret key must be 32 bytes"),
   376  		},
   377  		{
   378  			name:  "Long",
   379  			input: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
   380  			err:   errors.New("secret key must be 32 bytes"),
   381  		},
   382  		{
   383  			name:  "Bad",
   384  			input: []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
   385  			err:   common.ErrSecretUnmarshal,
   386  		},
   387  		{
   388  			name:  "Good",
   389  			input: []byte{0x25, 0x29, 0x5f, 0x0d, 0x1d, 0x59, 0x2a, 0x90, 0xb3, 0x33, 0xe2, 0x6e, 0x85, 0x14, 0x97, 0x08, 0x20, 0x8e, 0x9f, 0x8e, 0x8b, 0xc1, 0x8f, 0x6c, 0x77, 0xbd, 0x62, 0xf8, 0xad, 0x7a, 0x68, 0x66},
   390  		},
   391  		{
   392  			name:  "myTest",
   393  			input: b,
   394  		},
   395  	}
   396  
   397  	for _, test := range tests {
   398  		res, err := SecretKeyFromBytes(test.input)
   399  		if test.err != nil {
   400  			if err == nil {
   401  				return errors.New("No error returned")
   402  			}
   403  			if !strings.Contains(test.err.Error(), err.Error()) {
   404  				return errors.New("Unexpected error returned")
   405  			}
   406  		} else {
   407  			if err != nil {
   408  				return err
   409  			}
   410  			if bytes.Compare(res.Marshal(), test.input) != 0 {
   411  				return errors.New("bytes.Compare(res.Marshal(), test.input)!=0")
   412  			}
   413  		}
   414  	}
   415  	return nil
   416  }