github.com/dashpay/godash@v0.0.0-20160726055534-e038a21e0e3d/blockchain/difficulty_test.go (about) 1 // Copyright (c) 2014 The btcsuite developers 2 // Copyright (c) 2016 The Dash developers 3 // Use of this source code is governed by an ISC 4 // license that can be found in the LICENSE file. 5 6 package blockchain_test 7 8 import ( 9 "math/big" 10 "testing" 11 12 "github.com/dashpay/godash/blockchain" 13 ) 14 15 func TestBigToCompact(t *testing.T) { 16 tests := []struct { 17 in int64 18 out uint32 19 }{ 20 {0, 0}, 21 {-1, 25231360}, 22 } 23 24 for x, test := range tests { 25 n := big.NewInt(test.in) 26 r := blockchain.BigToCompact(n) 27 if r != test.out { 28 t.Errorf("TestBigToCompact test #%d failed: got %d want %d\n", 29 x, r, test.out) 30 return 31 } 32 } 33 } 34 35 func TestCompactToBig(t *testing.T) { 36 tests := []struct { 37 in uint32 38 out int64 39 }{ 40 {10000000, 0}, 41 } 42 43 for x, test := range tests { 44 n := blockchain.CompactToBig(test.in) 45 want := big.NewInt(test.out) 46 if n.Cmp(want) != 0 { 47 t.Errorf("TestCompactToBig test #%d failed: got %d want %d\n", 48 x, n.Int64(), want.Int64()) 49 return 50 } 51 } 52 } 53 54 func TestCalcWork(t *testing.T) { 55 tests := []struct { 56 in uint32 57 out int64 58 }{ 59 {10000000, 0}, 60 } 61 62 for x, test := range tests { 63 bits := uint32(test.in) 64 65 r := blockchain.CalcWork(bits) 66 if r.Int64() != test.out { 67 t.Errorf("TestCalcWork test #%d failed: got %v want %d\n", 68 x, r.Int64(), test.out) 69 return 70 } 71 } 72 }