github.com/cryptoecc/eth-ecc@v0.0.3/consensus/eccpow/algorithm_test.go (about) 1 package eccpow 2 3 import ( 4 "reflect" 5 "testing" 6 7 "github.com/cryptoecc/ETH-ECC/common" 8 "github.com/cryptoecc/ETH-ECC/common/hexutil" 9 "github.com/cryptoecc/ETH-ECC/core/types" 10 ) 11 12 func TestRandomSeed(t *testing.T) { 13 header := new(types.Header) 14 header.Difficulty = ProbToDifficulty(Table[0].miningProb) 15 parameters, _ := setParameters(header) 16 17 a := generateH(parameters) 18 b := generateH(parameters) 19 20 if !reflect.DeepEqual(a, b) { 21 t.Error("Wrong matrix") 22 } else { 23 t.Log("Pass") 24 } 25 } 26 27 func TestLDPC(t *testing.T) { 28 /* 29 prevHash := hexutil.MustDecode("0x0000000000000000000000000000000000000000000000000000000000000000") 30 curHash := hexutil.MustDecode("0xca2ff06caae7c94dc968be7d76d0fbf60dd2e1989ee9bf0d5931e48564d5143b") 31 nonce, mixDigest := RunLDPC(prevHash, curHash) 32 33 wantDigest := hexutil.MustDecode("0x535306ee4b42c92aecd0e71fca98572064f049c2babb2769faa3bbd87d67ec2d") 34 35 if !bytes.Equal(mixDigest, wantDigest) { 36 t.Errorf("light hashimoto digest mismatch: have %x, want %x", mixDigest, wantDigest) 37 } 38 39 t.Log(nonce) 40 */ 41 header := new(types.Header) 42 //t.Log(hexutil.Encode(header.ParentHash)) 43 header.Difficulty = ProbToDifficulty(Table[0].miningProb) 44 var hash []byte 45 hashVector, outputWord, LDPCNonce, digest := RunOptimizedConcurrencyLDPC(header, hash) 46 47 t.Logf("Hash vector : %v\n", hashVector) 48 t.Logf("Outputword : %v\n", outputWord) 49 t.Logf("LDPC Nonce : %v\n", LDPCNonce) 50 t.Logf("Digest : %v\n", digest) 51 } 52 53 func BenchmarkECCPoW(b *testing.B) { 54 //prevHash := hexutil.MustDecode("0xd783efa4d392943503f28438ad5830b2d5964696ffc285f338585e9fe0a37a05") 55 //curHash := hexutil.MustDecode("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347") 56 57 header := new(types.Header) 58 header.Difficulty = ProbToDifficulty(Table[0].miningProb) 59 var hash []byte 60 b.ResetTimer() 61 for i := 0; i < b.N; i++ { 62 RunOptimizedConcurrencyLDPC(header, hash) 63 } 64 } 65 66 func TestHashRate(t *testing.T) { 67 var ( 68 hashrate = []hexutil.Uint64{100, 200, 300} 69 expect uint64 70 ids = []common.Hash{common.HexToHash("a"), common.HexToHash("b"), common.HexToHash("c")} 71 ) 72 ecc := NewTester(nil, false) 73 defer ecc.Close() 74 75 if tot := ecc.Hashrate(); tot != 0 { 76 t.Error("expect the result should be zero") 77 } 78 79 api := &API{ecc} 80 for i := 0; i < len(hashrate); i++ { 81 if res := api.SubmitHashRate(hashrate[i], ids[i]); !res { 82 t.Error("remote miner submit hashrate failed") 83 } 84 expect += uint64(hashrate[i]) 85 } 86 if tot := ecc.Hashrate(); tot != float64(expect) { 87 t.Error("expect total hashrate should be same") 88 } 89 }