-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_test.go
46 lines (40 loc) · 1.06 KB
/
block_test.go
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
37
38
39
40
41
42
43
44
45
46
package flyclientdemo
import (
"fmt"
"github.com/stretchr/testify/assert"
"github.com/zcheng9/FlyclientDemo/mmr"
"math/big"
"testing"
"time"
)
func TestBlockChain_GetProof(t *testing.T) {
bc := NewBlockChain()
length := 50000
//first creat a blockchain with length of 50000,you can change the length
for i := 0; i < length; i++ {
b := NewBlock(uint64(i), 2, big.NewInt(10000))
bc.InsertBlock(b)
}
//generate proof
start := time.Now()
proof := bc.GetProof()
fmt.Printf("size of blockchain:%d,size of proof:%d\n",length,len(proof.Elems))
//verify proof with limited information
fmt.Println("gen proof cost:", time.Now().Sub(start))
start = time.Now()
pBlocks, err := mmr.VerifyRequiredBlocks(proof, RightDif)
assert.NoError(t, err)
assert.True(t, proof.VerifyProof(pBlocks))
fmt.Println("verify cost:", time.Now().Sub(start))
//var wg sync.WaitGroup
//fmt.Println("waiting for all goroutine ")
//for n := 0; n < 1000; n++ {
// wg.Add(1)
// go func() {
// defer wg.Done()
//
// }()
//}
//wg.Wait()
//fmt.Println("All goroutines finished!")
}