github.com/spacemeshos/poet@v0.8.5/prover/prover_test.go (about)

     1  package prover
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/stretchr/testify/require"
     9  
    10  	"github.com/spacemeshos/poet/hash"
    11  	"github.com/spacemeshos/poet/shared"
    12  	"github.com/spacemeshos/poet/verifier"
    13  )
    14  
    15  func TestGetProof(t *testing.T) {
    16  	r := require.New(t)
    17  
    18  	challenge := []byte("challenge this")
    19  	leafs, merkleProof, err := GenerateProofWithoutPersistency(
    20  		context.Background(),
    21  		TreeConfig{Datadir: t.TempDir()},
    22  		hash.GenLabelHashFunc(challenge),
    23  		hash.GenMerkleHashFunc(challenge),
    24  		time.Now().Add(100*time.Millisecond),
    25  		5,
    26  	)
    27  	r.NoError(err)
    28  	t.Logf("root: %x", merkleProof.Root)
    29  	t.Logf("proof: %x", merkleProof.ProvenLeaves)
    30  	t.Logf("leafs: %d", leafs)
    31  
    32  	err = verifier.Validate(*merkleProof, hash.GenLabelHashFunc(challenge), hash.GenMerkleHashFunc(challenge), leafs, 5)
    33  	r.NoError(err)
    34  }
    35  
    36  func BenchmarkGetProof(b *testing.B) {
    37  	challenge := []byte("challenge this! challenge this! ")
    38  	securityParam := shared.T
    39  	duration := time.Second * 30
    40  	leafs, _, err := GenerateProofWithoutPersistency(
    41  		context.Background(),
    42  		TreeConfig{Datadir: b.TempDir()},
    43  		hash.GenLabelHashFunc(challenge),
    44  		hash.GenMerkleHashFunc(challenge),
    45  		time.Now().Add(duration),
    46  		securityParam,
    47  	)
    48  	if err != nil {
    49  		b.Fatal(err)
    50  	}
    51  	b.ReportMetric(float64(leafs)/duration.Seconds(), "leafs/sec")
    52  	b.ReportMetric(float64(leafs), "leafs/op")
    53  	b.SetBytes(int64(leafs) * 32)
    54  }