github.com/annchain/OG@v0.0.9/og/verifier/tx_format_verifier_test.go (about)

     1  package verifier
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/annchain/OG/arefactor/og_interface"
     6  	"github.com/annchain/OG/common/crypto"
     7  	"github.com/annchain/OG/deprecated/ogcrypto"
     8  	"github.com/annchain/OG/og/types"
     9  	"github.com/annchain/OG/og/types/archive"
    10  
    11  	"testing"
    12  	"time"
    13  )
    14  
    15  type TestSigner struct {
    16  	ogcrypto.SignerSecp256k1
    17  }
    18  
    19  func (s *TestSigner) CanRecoverPubFromSig() bool {
    20  	return true
    21  }
    22  
    23  func TestVerify(t *testing.T) {
    24  	signer := crypto.NewSigner(crypto.CryptoTypeSecp256k1)
    25  	pub, priv := signer.RandomKeyPair()
    26  	var txis types.Txis
    27  	//var sigTerGets [][]byte
    28  	addr := pub.Address()
    29  	for i := 0; i < 10000; i++ {
    30  		tx := archive.RandomTx()
    31  		tx.From = &addr
    32  		tx.Signature = signer.Sign(priv, tx.SignatureTargets()).SignatureBytes
    33  		tx.PublicKey = pub.KeyBytes
    34  		txis = append(txis, tx)
    35  	}
    36  	v := TxFormatVerifier{NoVerifyMineHash: true, NoVerifyMaxTxHash: true}
    37  	now := time.Now()
    38  	fmt.Println("start ", now)
    39  	for i, tx := range txis {
    40  		ok := v.VerifySignature(tx)
    41  		if !ok {
    42  			t.Fatal(ok, tx, i)
    43  		}
    44  	}
    45  	fmt.Println("used ", time.Since(now))
    46  	start := time.Now()
    47  	newSigner := &TestSigner{}
    48  	og_interface.Signer = newSigner
    49  	fmt.Println(og_interface.Signer.CanRecoverPubFromSig())
    50  	for i, tx := range txis {
    51  		ok := v.VerifySignature(tx)
    52  		if !ok {
    53  			t.Fatal(ok, tx, i)
    54  		}
    55  	}
    56  	fmt.Println("used ", time.Since(start))
    57  
    58  }