|
|
@ -1,7 +1,6 @@ |
|
|
|
package p2p |
|
|
|
|
|
|
|
import ( |
|
|
|
"bytes" |
|
|
|
"os" |
|
|
|
"path/filepath" |
|
|
|
"testing" |
|
|
@ -52,30 +51,3 @@ func TestNodeKeySaveAs(t *testing.T) { |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.FileExists(t, filePath) |
|
|
|
} |
|
|
|
|
|
|
|
//----------------------------------------------------------
|
|
|
|
|
|
|
|
func padBytes(bz []byte, targetBytes int) []byte { |
|
|
|
return append(bz, bytes.Repeat([]byte{0xFF}, targetBytes-len(bz))...) |
|
|
|
} |
|
|
|
|
|
|
|
func TestPoWTarget(t *testing.T) { |
|
|
|
|
|
|
|
targetBytes := 20 |
|
|
|
cases := []struct { |
|
|
|
difficulty uint |
|
|
|
target []byte |
|
|
|
}{ |
|
|
|
{0, padBytes([]byte{}, targetBytes)}, |
|
|
|
{1, padBytes([]byte{127}, targetBytes)}, |
|
|
|
{8, padBytes([]byte{0}, targetBytes)}, |
|
|
|
{9, padBytes([]byte{0, 127}, targetBytes)}, |
|
|
|
{10, padBytes([]byte{0, 63}, targetBytes)}, |
|
|
|
{16, padBytes([]byte{0, 0}, targetBytes)}, |
|
|
|
{17, padBytes([]byte{0, 0, 127}, targetBytes)}, |
|
|
|
} |
|
|
|
|
|
|
|
for _, c := range cases { |
|
|
|
assert.Equal(t, MakePoWTarget(c.difficulty, 20*8), c.target) |
|
|
|
} |
|
|
|
} |