Răsfoiți Sursa

remove: test files.

skyfffire 2 ani în urmă
părinte
comite
d106bab99c

+ 0 - 221
common/bitutil/bitutil_test.go

@@ -1,221 +0,0 @@
-// Copyright 2013 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Adapted from: https://golang.org/src/crypto/cipher/xor_test.go
-
-package bitutil
-
-import (
-	"bytes"
-	"testing"
-)
-
-// Tests that bitwise XOR works for various alignments.
-func TestXOR(t *testing.T) {
-	for alignP := 0; alignP < 2; alignP++ {
-		for alignQ := 0; alignQ < 2; alignQ++ {
-			for alignD := 0; alignD < 2; alignD++ {
-				p := make([]byte, 1023)[alignP:]
-				q := make([]byte, 1023)[alignQ:]
-
-				for i := 0; i < len(p); i++ {
-					p[i] = byte(i)
-				}
-				for i := 0; i < len(q); i++ {
-					q[i] = byte(len(q) - i)
-				}
-				d1 := make([]byte, 1023+alignD)[alignD:]
-				d2 := make([]byte, 1023+alignD)[alignD:]
-
-				XORBytes(d1, p, q)
-				safeXORBytes(d2, p, q)
-				if !bytes.Equal(d1, d2) {
-					t.Error("not equal", d1, d2)
-				}
-			}
-		}
-	}
-}
-
-// Tests that bitwise AND works for various alignments.
-func TestAND(t *testing.T) {
-	for alignP := 0; alignP < 2; alignP++ {
-		for alignQ := 0; alignQ < 2; alignQ++ {
-			for alignD := 0; alignD < 2; alignD++ {
-				p := make([]byte, 1023)[alignP:]
-				q := make([]byte, 1023)[alignQ:]
-
-				for i := 0; i < len(p); i++ {
-					p[i] = byte(i)
-				}
-				for i := 0; i < len(q); i++ {
-					q[i] = byte(len(q) - i)
-				}
-				d1 := make([]byte, 1023+alignD)[alignD:]
-				d2 := make([]byte, 1023+alignD)[alignD:]
-
-				ANDBytes(d1, p, q)
-				safeANDBytes(d2, p, q)
-				if !bytes.Equal(d1, d2) {
-					t.Error("not equal")
-				}
-			}
-		}
-	}
-}
-
-// Tests that bitwise OR works for various alignments.
-func TestOR(t *testing.T) {
-	for alignP := 0; alignP < 2; alignP++ {
-		for alignQ := 0; alignQ < 2; alignQ++ {
-			for alignD := 0; alignD < 2; alignD++ {
-				p := make([]byte, 1023)[alignP:]
-				q := make([]byte, 1023)[alignQ:]
-
-				for i := 0; i < len(p); i++ {
-					p[i] = byte(i)
-				}
-				for i := 0; i < len(q); i++ {
-					q[i] = byte(len(q) - i)
-				}
-				d1 := make([]byte, 1023+alignD)[alignD:]
-				d2 := make([]byte, 1023+alignD)[alignD:]
-
-				ORBytes(d1, p, q)
-				safeORBytes(d2, p, q)
-				if !bytes.Equal(d1, d2) {
-					t.Error("not equal")
-				}
-			}
-		}
-	}
-}
-
-// Tests that bit testing works for various alignments.
-func TestTest(t *testing.T) {
-	for align := 0; align < 2; align++ {
-		// Test for bits set in the bulk part
-		p := make([]byte, 1023)[align:]
-		p[100] = 1
-
-		if TestBytes(p) != safeTestBytes(p) {
-			t.Error("not equal")
-		}
-		// Test for bits set in the tail part
-		q := make([]byte, 1023)[align:]
-		q[len(q)-1] = 1
-
-		if TestBytes(q) != safeTestBytes(q) {
-			t.Error("not equal")
-		}
-	}
-}
-
-// Benchmarks the potentially optimized XOR performance.
-func BenchmarkFastXOR1KB(b *testing.B) { benchmarkFastXOR(b, 1024) }
-func BenchmarkFastXOR2KB(b *testing.B) { benchmarkFastXOR(b, 2048) }
-func BenchmarkFastXOR4KB(b *testing.B) { benchmarkFastXOR(b, 4096) }
-
-func benchmarkFastXOR(b *testing.B, size int) {
-	p, q := make([]byte, size), make([]byte, size)
-
-	for i := 0; i < b.N; i++ {
-		XORBytes(p, p, q)
-	}
-}
-
-// Benchmarks the baseline XOR performance.
-func BenchmarkBaseXOR1KB(b *testing.B) { benchmarkBaseXOR(b, 1024) }
-func BenchmarkBaseXOR2KB(b *testing.B) { benchmarkBaseXOR(b, 2048) }
-func BenchmarkBaseXOR4KB(b *testing.B) { benchmarkBaseXOR(b, 4096) }
-
-func benchmarkBaseXOR(b *testing.B, size int) {
-	p, q := make([]byte, size), make([]byte, size)
-
-	for i := 0; i < b.N; i++ {
-		safeXORBytes(p, p, q)
-	}
-}
-
-// Benchmarks the potentially optimized AND performance.
-func BenchmarkFastAND1KB(b *testing.B) { benchmarkFastAND(b, 1024) }
-func BenchmarkFastAND2KB(b *testing.B) { benchmarkFastAND(b, 2048) }
-func BenchmarkFastAND4KB(b *testing.B) { benchmarkFastAND(b, 4096) }
-
-func benchmarkFastAND(b *testing.B, size int) {
-	p, q := make([]byte, size), make([]byte, size)
-
-	for i := 0; i < b.N; i++ {
-		ANDBytes(p, p, q)
-	}
-}
-
-// Benchmarks the baseline AND performance.
-func BenchmarkBaseAND1KB(b *testing.B) { benchmarkBaseAND(b, 1024) }
-func BenchmarkBaseAND2KB(b *testing.B) { benchmarkBaseAND(b, 2048) }
-func BenchmarkBaseAND4KB(b *testing.B) { benchmarkBaseAND(b, 4096) }
-
-func benchmarkBaseAND(b *testing.B, size int) {
-	p, q := make([]byte, size), make([]byte, size)
-
-	for i := 0; i < b.N; i++ {
-		safeANDBytes(p, p, q)
-	}
-}
-
-// Benchmarks the potentially optimized OR performance.
-func BenchmarkFastOR1KB(b *testing.B) { benchmarkFastOR(b, 1024) }
-func BenchmarkFastOR2KB(b *testing.B) { benchmarkFastOR(b, 2048) }
-func BenchmarkFastOR4KB(b *testing.B) { benchmarkFastOR(b, 4096) }
-
-func benchmarkFastOR(b *testing.B, size int) {
-	p, q := make([]byte, size), make([]byte, size)
-
-	for i := 0; i < b.N; i++ {
-		ORBytes(p, p, q)
-	}
-}
-
-// Benchmarks the baseline OR performance.
-func BenchmarkBaseOR1KB(b *testing.B) { benchmarkBaseOR(b, 1024) }
-func BenchmarkBaseOR2KB(b *testing.B) { benchmarkBaseOR(b, 2048) }
-func BenchmarkBaseOR4KB(b *testing.B) { benchmarkBaseOR(b, 4096) }
-
-func benchmarkBaseOR(b *testing.B, size int) {
-	p, q := make([]byte, size), make([]byte, size)
-
-	for i := 0; i < b.N; i++ {
-		safeORBytes(p, p, q)
-	}
-}
-
-var GloBool bool // Exported global will not be dead-code eliminated, at least not yet.
-
-// Benchmarks the potentially optimized bit testing performance.
-func BenchmarkFastTest1KB(b *testing.B) { benchmarkFastTest(b, 1024) }
-func BenchmarkFastTest2KB(b *testing.B) { benchmarkFastTest(b, 2048) }
-func BenchmarkFastTest4KB(b *testing.B) { benchmarkFastTest(b, 4096) }
-
-func benchmarkFastTest(b *testing.B, size int) {
-	p := make([]byte, size)
-	a := false
-	for i := 0; i < b.N; i++ {
-		a = a != TestBytes(p)
-	}
-	GloBool = a // Use of benchmark "result" to prevent total dead code elimination.
-}
-
-// Benchmarks the baseline bit testing performance.
-func BenchmarkBaseTest1KB(b *testing.B) { benchmarkBaseTest(b, 1024) }
-func BenchmarkBaseTest2KB(b *testing.B) { benchmarkBaseTest(b, 2048) }
-func BenchmarkBaseTest4KB(b *testing.B) { benchmarkBaseTest(b, 4096) }
-
-func benchmarkBaseTest(b *testing.B, size int) {
-	p := make([]byte, size)
-	a := false
-	for i := 0; i < b.N; i++ {
-		a = a != safeTestBytes(p)
-	}
-	GloBool = a // Use of benchmark "result" to prevent total dead code elimination.
-}

+ 0 - 181
common/bitutil/compress_test.go

@@ -1,181 +0,0 @@
-// Copyright 2017 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package bitutil
-
-import (
-	"bytes"
-	"math/rand"
-	"testing"
-
-	"github.com/ethereum/go-ethereum/common/hexutil"
-)
-
-// Tests that data bitset encoding and decoding works and is bijective.
-func TestEncodingCycle(t *testing.T) {
-	tests := []string{
-		// Tests generated by go-fuzz to maximize code coverage
-		"0x000000000000000000",
-		"0xef0400",
-		"0xdf7070533534333636313639343638373532313536346c1bc33339343837313070706336343035336336346c65fefb3930393233383838ac2f65fefb",
-		"0x7b64000000",
-		"0x000034000000000000",
-		"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f0000000000000000000",
-		"0x4912385c0e7b64000000",
-		"0x000034000000000000000000000000000000",
-		"0x00",
-		"0x000003e834ff7f0000",
-		"0x0000",
-		"0x0000000000000000000000000000000000000000000000000000000000ff00",
-		"0x895f0c6a020f850c6a020f85f88df88d",
-		"0xdf7070533534333636313639343638373432313536346c1bc3315aac2f65fefb",
-		"0x0000000000",
-		"0xdf70706336346c65fefb",
-		"0x00006d643634000000",
-		"0xdf7070533534333636313639343638373532313536346c1bc333393438373130707063363430353639343638373532313536346c1bc333393438336336346c65fe",
-	}
-	for i, tt := range tests {
-		data := hexutil.MustDecode(tt)
-
-		proc, err := bitsetDecodeBytes(bitsetEncodeBytes(data), len(data))
-		if err != nil {
-			t.Errorf("test %d: failed to decompress compressed data: %v", i, err)
-			continue
-		}
-		if !bytes.Equal(data, proc) {
-			t.Errorf("test %d: compress/decompress mismatch: have %x, want %x", i, proc, data)
-		}
-	}
-}
-
-// Tests that data bitset decoding and rencoding works and is bijective.
-func TestDecodingCycle(t *testing.T) {
-	tests := []struct {
-		size  int
-		input string
-		fail  error
-	}{
-		{size: 0, input: "0x"},
-
-		// Crashers generated by go-fuzz
-		{size: 0, input: "0x0020", fail: errUnreferencedData},
-		{size: 0, input: "0x30", fail: errUnreferencedData},
-		{size: 1, input: "0x00", fail: errUnreferencedData},
-		{size: 2, input: "0x07", fail: errMissingData},
-		{size: 1024, input: "0x8000", fail: errZeroContent},
-
-		// Tests generated by go-fuzz to maximize code coverage
-		{size: 29490, input: "0x343137343733323134333839373334323073333930783e3078333930783e70706336346c65303e", fail: errMissingData},
-		{size: 59395, input: "0x00", fail: errUnreferencedData},
-		{size: 52574, input: "0x70706336346c65c0de", fail: errExceededTarget},
-		{size: 42264, input: "0x07", fail: errMissingData},
-		{size: 52, input: "0xa5045bad48f4", fail: errExceededTarget},
-		{size: 52574, input: "0xc0de", fail: errMissingData},
-		{size: 52574, input: "0x"},
-		{size: 29490, input: "0x34313734373332313433383937333432307333393078073034333839373334323073333930783e3078333937333432307333393078073061333930783e70706336346c65303e", fail: errMissingData},
-		{size: 29491, input: "0x3973333930783e30783e", fail: errMissingData},
-
-		{size: 1024, input: "0x808080608080"},
-		{size: 1024, input: "0x808470705e3632383337363033313434303137393130306c6580ef46806380635a80"},
-		{size: 1024, input: "0x8080808070"},
-		{size: 1024, input: "0x808070705e36346c6580ef46806380635a80"},
-		{size: 1024, input: "0x80808046802680"},
-		{size: 1024, input: "0x4040404035"},
-		{size: 1024, input: "0x4040bf3ba2b3f684402d353234373438373934409fe5b1e7ada94ebfd7d0505e27be4035"},
-		{size: 1024, input: "0x404040bf3ba2b3f6844035"},
-		{size: 1024, input: "0x40402d35323437343837393440bfd7d0505e27be4035"},
-	}
-	for i, tt := range tests {
-		data := hexutil.MustDecode(tt.input)
-
-		orig, err := bitsetDecodeBytes(data, tt.size)
-		if err != tt.fail {
-			t.Errorf("test %d: failure mismatch: have %v, want %v", i, err, tt.fail)
-		}
-		if err != nil {
-			continue
-		}
-		if comp := bitsetEncodeBytes(orig); !bytes.Equal(comp, data) {
-			t.Errorf("test %d: decompress/compress mismatch: have %x, want %x", i, comp, data)
-		}
-	}
-}
-
-// TestCompression tests that compression works by returning either the bitset
-// encoded input, or the actual input if the bitset version is longer.
-func TestCompression(t *testing.T) {
-	// Check the compression returns the bitset encoding is shorter
-	in := hexutil.MustDecode("0x4912385c0e7b64000000")
-	out := hexutil.MustDecode("0x80fe4912385c0e7b64")
-
-	if data := CompressBytes(in); !bytes.Equal(data, out) {
-		t.Errorf("encoding mismatch for sparse data: have %x, want %x", data, out)
-	}
-	if data, err := DecompressBytes(out, len(in)); err != nil || !bytes.Equal(data, in) {
-		t.Errorf("decoding mismatch for sparse data: have %x, want %x, error %v", data, in, err)
-	}
-	// Check the compression returns the input if the bitset encoding is longer
-	in = hexutil.MustDecode("0xdf7070533534333636313639343638373532313536346c1bc33339343837313070706336343035336336346c65fefb3930393233383838ac2f65fefb")
-	out = hexutil.MustDecode("0xdf7070533534333636313639343638373532313536346c1bc33339343837313070706336343035336336346c65fefb3930393233383838ac2f65fefb")
-
-	if data := CompressBytes(in); !bytes.Equal(data, out) {
-		t.Errorf("encoding mismatch for dense data: have %x, want %x", data, out)
-	}
-	if data, err := DecompressBytes(out, len(in)); err != nil || !bytes.Equal(data, in) {
-		t.Errorf("decoding mismatch for dense data: have %x, want %x, error %v", data, in, err)
-	}
-	// Check that decompressing a longer input than the target fails
-	if _, err := DecompressBytes([]byte{0xc0, 0x01, 0x01}, 2); err != errExceededTarget {
-		t.Errorf("decoding error mismatch for long data: have %v, want %v", err, errExceededTarget)
-	}
-}
-
-// Crude benchmark for compressing random slices of bytes.
-func BenchmarkEncoding1KBVerySparse(b *testing.B) { benchmarkEncoding(b, 1024, 0.0001) }
-func BenchmarkEncoding2KBVerySparse(b *testing.B) { benchmarkEncoding(b, 2048, 0.0001) }
-func BenchmarkEncoding4KBVerySparse(b *testing.B) { benchmarkEncoding(b, 4096, 0.0001) }
-
-func BenchmarkEncoding1KBSparse(b *testing.B) { benchmarkEncoding(b, 1024, 0.001) }
-func BenchmarkEncoding2KBSparse(b *testing.B) { benchmarkEncoding(b, 2048, 0.001) }
-func BenchmarkEncoding4KBSparse(b *testing.B) { benchmarkEncoding(b, 4096, 0.001) }
-
-func BenchmarkEncoding1KBDense(b *testing.B) { benchmarkEncoding(b, 1024, 0.1) }
-func BenchmarkEncoding2KBDense(b *testing.B) { benchmarkEncoding(b, 2048, 0.1) }
-func BenchmarkEncoding4KBDense(b *testing.B) { benchmarkEncoding(b, 4096, 0.1) }
-
-func BenchmarkEncoding1KBSaturated(b *testing.B) { benchmarkEncoding(b, 1024, 0.5) }
-func BenchmarkEncoding2KBSaturated(b *testing.B) { benchmarkEncoding(b, 2048, 0.5) }
-func BenchmarkEncoding4KBSaturated(b *testing.B) { benchmarkEncoding(b, 4096, 0.5) }
-
-func benchmarkEncoding(b *testing.B, bytes int, fill float64) {
-	// Generate a random slice of bytes to compress
-	random := rand.NewSource(0) // reproducible and comparable
-
-	data := make([]byte, bytes)
-	bits := int(float64(bytes) * 8 * fill)
-
-	for i := 0; i < bits; i++ {
-		idx := random.Int63() % int64(len(data))
-		bit := uint(random.Int63() % 8)
-		data[idx] |= 1 << bit
-	}
-	// Reset the benchmark and measure encoding/decoding
-	b.ResetTimer()
-	b.ReportAllocs()
-	for i := 0; i < b.N; i++ {
-		bitsetDecodeBytes(bitsetEncodeBytes(data), len(data))
-	}
-}

+ 0 - 126
common/bytes_test.go

@@ -1,126 +0,0 @@
-// Copyright 2014 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package common
-
-import (
-	"bytes"
-	"testing"
-)
-
-func TestCopyBytes(t *testing.T) {
-	input := []byte{1, 2, 3, 4}
-
-	v := CopyBytes(input)
-	if !bytes.Equal(v, []byte{1, 2, 3, 4}) {
-		t.Fatal("not equal after copy")
-	}
-	v[0] = 99
-	if bytes.Equal(v, input) {
-		t.Fatal("result is not a copy")
-	}
-}
-
-func TestLeftPadBytes(t *testing.T) {
-	val := []byte{1, 2, 3, 4}
-	padded := []byte{0, 0, 0, 0, 1, 2, 3, 4}
-
-	if r := LeftPadBytes(val, 8); !bytes.Equal(r, padded) {
-		t.Fatalf("LeftPadBytes(%v, 8) == %v", val, r)
-	}
-	if r := LeftPadBytes(val, 2); !bytes.Equal(r, val) {
-		t.Fatalf("LeftPadBytes(%v, 2) == %v", val, r)
-	}
-}
-
-func TestRightPadBytes(t *testing.T) {
-	val := []byte{1, 2, 3, 4}
-	padded := []byte{1, 2, 3, 4, 0, 0, 0, 0}
-
-	if r := RightPadBytes(val, 8); !bytes.Equal(r, padded) {
-		t.Fatalf("RightPadBytes(%v, 8) == %v", val, r)
-	}
-	if r := RightPadBytes(val, 2); !bytes.Equal(r, val) {
-		t.Fatalf("RightPadBytes(%v, 2) == %v", val, r)
-	}
-}
-
-func TestFromHex(t *testing.T) {
-	input := "0x01"
-	expected := []byte{1}
-	result := FromHex(input)
-	if !bytes.Equal(expected, result) {
-		t.Errorf("Expected %x got %x", expected, result)
-	}
-}
-
-func TestIsHex(t *testing.T) {
-	tests := []struct {
-		input string
-		ok    bool
-	}{
-		{"", true},
-		{"0", false},
-		{"00", true},
-		{"a9e67e", true},
-		{"A9E67E", true},
-		{"0xa9e67e", false},
-		{"a9e67e001", false},
-		{"0xHELLO_MY_NAME_IS_STEVEN_@#$^&*", false},
-	}
-	for _, test := range tests {
-		if ok := isHex(test.input); ok != test.ok {
-			t.Errorf("isHex(%q) = %v, want %v", test.input, ok, test.ok)
-		}
-	}
-}
-
-func TestFromHexOddLength(t *testing.T) {
-	input := "0x1"
-	expected := []byte{1}
-	result := FromHex(input)
-	if !bytes.Equal(expected, result) {
-		t.Errorf("Expected %x got %x", expected, result)
-	}
-}
-
-func TestNoPrefixShortHexOddLength(t *testing.T) {
-	input := "1"
-	expected := []byte{1}
-	result := FromHex(input)
-	if !bytes.Equal(expected, result) {
-		t.Errorf("Expected %x got %x", expected, result)
-	}
-}
-
-func TestTrimRightZeroes(t *testing.T) {
-	tests := []struct {
-		arr []byte
-		exp []byte
-	}{
-		{FromHex("0x00ffff00ff0000"), FromHex("0x00ffff00ff")},
-		{FromHex("0x00000000000000"), []byte{}},
-		{FromHex("0xff"), FromHex("0xff")},
-		{[]byte{}, []byte{}},
-		{FromHex("0x00ffffffffffff"), FromHex("0x00ffffffffffff")},
-	}
-	for i, test := range tests {
-		got := TrimRightZeroes(test.arr)
-		if !bytes.Equal(got, test.exp) {
-			t.Errorf("test %d, got %x exp %x", i, got, test.exp)
-		}
-	}
-}

+ 0 - 78
common/compiler/solidity_test.go

@@ -1,78 +0,0 @@
-// Copyright 2015 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package compiler
-
-import (
-	"os/exec"
-	"testing"
-)
-
-const (
-	testSource = `
-pragma solidity >0.0.0;
-contract test {
-   /// @notice Will multiply ` + "`a`" + ` by 7.
-   function multiply(uint a) public returns(uint d) {
-       return a * 7;
-   }
-}
-`
-)
-
-func skipWithoutSolc(t *testing.T) {
-	if _, err := exec.LookPath("solc"); err != nil {
-		t.Skip(err)
-	}
-}
-
-func TestSolidityCompiler(t *testing.T) {
-	skipWithoutSolc(t)
-
-	contracts, err := CompileSolidityString("", testSource)
-	if err != nil {
-		t.Fatalf("error compiling source. result %v: %v", contracts, err)
-	}
-	if len(contracts) != 1 {
-		t.Errorf("one contract expected, got %d", len(contracts))
-	}
-	c, ok := contracts["test"]
-	if !ok {
-		c, ok = contracts["<stdin>:test"]
-		if !ok {
-			t.Fatal("info for contract 'test' not present in result")
-		}
-	}
-	if c.Code == "" {
-		t.Error("empty code")
-	}
-	if c.Info.Source != testSource {
-		t.Error("wrong source")
-	}
-	if c.Info.CompilerVersion == "" {
-		t.Error("empty version")
-	}
-}
-
-func TestSolidityCompileError(t *testing.T) {
-	skipWithoutSolc(t)
-
-	contracts, err := CompileSolidityString("", testSource[4:])
-	if err == nil {
-		t.Errorf("error expected compiling source. got none. result %v", contracts)
-	}
-	t.Logf("error: %v", err)
-}

+ 0 - 71
common/compiler/vyper_test.go

@@ -1,71 +0,0 @@
-// Copyright 2019 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package compiler
-
-import (
-	"os/exec"
-	"testing"
-)
-
-func skipWithoutVyper(t *testing.T) {
-	if _, err := exec.LookPath("vyper"); err != nil {
-		t.Skip(err)
-	}
-}
-
-func TestVyperCompiler(t *testing.T) {
-	skipWithoutVyper(t)
-
-	testSource := []string{"test.v.py"}
-	source, err := slurpFiles(testSource)
-	if err != nil {
-		t.Error("couldn't read test files")
-	}
-	contracts, err := CompileVyper("", testSource...)
-	if err != nil {
-		t.Fatalf("error compiling test.v.py. result %v: %v", contracts, err)
-	}
-	if len(contracts) != 1 {
-		t.Errorf("one contract expected, got %d", len(contracts))
-	}
-	c, ok := contracts["test.v.py"]
-	if !ok {
-		c, ok = contracts["<stdin>:test"]
-		if !ok {
-			t.Fatal("info for contract 'test.v.py' not present in result")
-		}
-	}
-	if c.Code == "" {
-		t.Error("empty code")
-	}
-	if c.Info.Source != source {
-		t.Error("wrong source")
-	}
-	if c.Info.CompilerVersion == "" {
-		t.Error("empty version")
-	}
-}
-
-func TestVyperCompileError(t *testing.T) {
-	skipWithoutVyper(t)
-
-	contracts, err := CompileVyper("", "test_bad.v.py")
-	if err == nil {
-		t.Errorf("error expected compiling test_bad.v.py. got none. result %v", contracts)
-	}
-	t.Logf("error: %v", err)
-}

+ 0 - 45
common/fdlimit/fdlimit_test.go

@@ -1,45 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package fdlimit
-
-import (
-	"fmt"
-	"testing"
-)
-
-// TestFileDescriptorLimits simply tests whether the file descriptor allowance
-// per this process can be retrieved.
-func TestFileDescriptorLimits(t *testing.T) {
-	target := 4096
-	hardlimit, err := Maximum()
-	if err != nil {
-		t.Fatal(err)
-	}
-	if hardlimit < target {
-		t.Skip(fmt.Sprintf("system limit is less than desired test target: %d < %d", hardlimit, target))
-	}
-
-	if limit, err := Current(); err != nil || limit <= 0 {
-		t.Fatalf("failed to retrieve file descriptor limit (%d): %v", limit, err)
-	}
-	if _, err := Raise(uint64(target)); err != nil {
-		t.Fatalf("failed to raise file allowance")
-	}
-	if limit, err := Current(); err != nil || limit < target {
-		t.Fatalf("failed to retrieve raised descriptor limit (have %v, want %v): %v", limit, target, err)
-	}
-}

+ 0 - 203
common/hexutil/hexutil_test.go

@@ -1,203 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package hexutil
-
-import (
-	"bytes"
-	"math/big"
-	"testing"
-)
-
-type marshalTest struct {
-	input interface{}
-	want  string
-}
-
-type unmarshalTest struct {
-	input        string
-	want         interface{}
-	wantErr      error // if set, decoding must fail on any platform
-	wantErr32bit error // if set, decoding must fail on 32bit platforms (used for Uint tests)
-}
-
-var (
-	encodeBytesTests = []marshalTest{
-		{[]byte{}, "0x"},
-		{[]byte{0}, "0x00"},
-		{[]byte{0, 0, 1, 2}, "0x00000102"},
-	}
-
-	encodeBigTests = []marshalTest{
-		{referenceBig("0"), "0x0"},
-		{referenceBig("1"), "0x1"},
-		{referenceBig("ff"), "0xff"},
-		{referenceBig("112233445566778899aabbccddeeff"), "0x112233445566778899aabbccddeeff"},
-		{referenceBig("80a7f2c1bcc396c00"), "0x80a7f2c1bcc396c00"},
-		{referenceBig("-80a7f2c1bcc396c00"), "-0x80a7f2c1bcc396c00"},
-	}
-
-	encodeUint64Tests = []marshalTest{
-		{uint64(0), "0x0"},
-		{uint64(1), "0x1"},
-		{uint64(0xff), "0xff"},
-		{uint64(0x1122334455667788), "0x1122334455667788"},
-	}
-
-	encodeUintTests = []marshalTest{
-		{uint(0), "0x0"},
-		{uint(1), "0x1"},
-		{uint(0xff), "0xff"},
-		{uint(0x11223344), "0x11223344"},
-	}
-
-	decodeBytesTests = []unmarshalTest{
-		// invalid
-		{input: ``, wantErr: ErrEmptyString},
-		{input: `0`, wantErr: ErrMissingPrefix},
-		{input: `0x0`, wantErr: ErrOddLength},
-		{input: `0x023`, wantErr: ErrOddLength},
-		{input: `0xxx`, wantErr: ErrSyntax},
-		{input: `0x01zz01`, wantErr: ErrSyntax},
-		// valid
-		{input: `0x`, want: []byte{}},
-		{input: `0X`, want: []byte{}},
-		{input: `0x02`, want: []byte{0x02}},
-		{input: `0X02`, want: []byte{0x02}},
-		{input: `0xffffffffff`, want: []byte{0xff, 0xff, 0xff, 0xff, 0xff}},
-		{
-			input: `0xffffffffffffffffffffffffffffffffffff`,
-			want:  []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
-		},
-	}
-
-	decodeBigTests = []unmarshalTest{
-		// invalid
-		{input: `0`, wantErr: ErrMissingPrefix},
-		{input: `0x`, wantErr: ErrEmptyNumber},
-		{input: `0x01`, wantErr: ErrLeadingZero},
-		{input: `0xx`, wantErr: ErrSyntax},
-		{input: `0x1zz01`, wantErr: ErrSyntax},
-		{
-			input:   `0x10000000000000000000000000000000000000000000000000000000000000000`,
-			wantErr: ErrBig256Range,
-		},
-		// valid
-		{input: `0x0`, want: big.NewInt(0)},
-		{input: `0x2`, want: big.NewInt(0x2)},
-		{input: `0x2F2`, want: big.NewInt(0x2f2)},
-		{input: `0X2F2`, want: big.NewInt(0x2f2)},
-		{input: `0x1122aaff`, want: big.NewInt(0x1122aaff)},
-		{input: `0xbBb`, want: big.NewInt(0xbbb)},
-		{input: `0xfffffffff`, want: big.NewInt(0xfffffffff)},
-		{
-			input: `0x112233445566778899aabbccddeeff`,
-			want:  referenceBig("112233445566778899aabbccddeeff"),
-		},
-		{
-			input: `0xffffffffffffffffffffffffffffffffffff`,
-			want:  referenceBig("ffffffffffffffffffffffffffffffffffff"),
-		},
-		{
-			input: `0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff`,
-			want:  referenceBig("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),
-		},
-	}
-
-	decodeUint64Tests = []unmarshalTest{
-		// invalid
-		{input: `0`, wantErr: ErrMissingPrefix},
-		{input: `0x`, wantErr: ErrEmptyNumber},
-		{input: `0x01`, wantErr: ErrLeadingZero},
-		{input: `0xfffffffffffffffff`, wantErr: ErrUint64Range},
-		{input: `0xx`, wantErr: ErrSyntax},
-		{input: `0x1zz01`, wantErr: ErrSyntax},
-		// valid
-		{input: `0x0`, want: uint64(0)},
-		{input: `0x2`, want: uint64(0x2)},
-		{input: `0x2F2`, want: uint64(0x2f2)},
-		{input: `0X2F2`, want: uint64(0x2f2)},
-		{input: `0x1122aaff`, want: uint64(0x1122aaff)},
-		{input: `0xbbb`, want: uint64(0xbbb)},
-		{input: `0xffffffffffffffff`, want: uint64(0xffffffffffffffff)},
-	}
-)
-
-func TestEncode(t *testing.T) {
-	for _, test := range encodeBytesTests {
-		enc := Encode(test.input.([]byte))
-		if enc != test.want {
-			t.Errorf("input %x: wrong encoding %s", test.input, enc)
-		}
-	}
-}
-
-func TestDecode(t *testing.T) {
-	for _, test := range decodeBytesTests {
-		dec, err := Decode(test.input)
-		if !checkError(t, test.input, err, test.wantErr) {
-			continue
-		}
-		if !bytes.Equal(test.want.([]byte), dec) {
-			t.Errorf("input %s: value mismatch: got %x, want %x", test.input, dec, test.want)
-			continue
-		}
-	}
-}
-
-func TestEncodeBig(t *testing.T) {
-	for _, test := range encodeBigTests {
-		enc := EncodeBig(test.input.(*big.Int))
-		if enc != test.want {
-			t.Errorf("input %x: wrong encoding %s", test.input, enc)
-		}
-	}
-}
-
-func TestDecodeBig(t *testing.T) {
-	for _, test := range decodeBigTests {
-		dec, err := DecodeBig(test.input)
-		if !checkError(t, test.input, err, test.wantErr) {
-			continue
-		}
-		if dec.Cmp(test.want.(*big.Int)) != 0 {
-			t.Errorf("input %s: value mismatch: got %x, want %x", test.input, dec, test.want)
-			continue
-		}
-	}
-}
-
-func TestEncodeUint64(t *testing.T) {
-	for _, test := range encodeUint64Tests {
-		enc := EncodeUint64(test.input.(uint64))
-		if enc != test.want {
-			t.Errorf("input %x: wrong encoding %s", test.input, enc)
-		}
-	}
-}
-
-func TestDecodeUint64(t *testing.T) {
-	for _, test := range decodeUint64Tests {
-		dec, err := DecodeUint64(test.input)
-		if !checkError(t, test.input, err, test.wantErr) {
-			continue
-		}
-		if dec != test.want.(uint64) {
-			t.Errorf("input %s: value mismatch: got %x, want %x", test.input, dec, test.want)
-			continue
-		}
-	}
-}

+ 0 - 45
common/hexutil/json_example_test.go

@@ -1,45 +0,0 @@
-// Copyright 2017 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package hexutil_test
-
-import (
-	"encoding/json"
-	"fmt"
-
-	"github.com/ethereum/go-ethereum/common/hexutil"
-)
-
-type MyType [5]byte
-
-func (v *MyType) UnmarshalText(input []byte) error {
-	return hexutil.UnmarshalFixedText("MyType", input, v[:])
-}
-
-func (v MyType) String() string {
-	return hexutil.Bytes(v[:]).String()
-}
-
-func ExampleUnmarshalFixedText() {
-	var v1, v2 MyType
-	fmt.Println("v1 error:", json.Unmarshal([]byte(`"0x01"`), &v1))
-	fmt.Println("v2 error:", json.Unmarshal([]byte(`"0x0101010101"`), &v2))
-	fmt.Println("v2:", v2)
-	// Output:
-	// v1 error: hex string has length 2, want 10 for MyType
-	// v2 error: <nil>
-	// v2: 0x0101010101
-}

+ 0 - 374
common/hexutil/json_test.go

@@ -1,374 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package hexutil
-
-import (
-	"bytes"
-	"encoding/hex"
-	"encoding/json"
-	"errors"
-	"math/big"
-	"testing"
-)
-
-func checkError(t *testing.T, input string, got, want error) bool {
-	if got == nil {
-		if want != nil {
-			t.Errorf("input %s: got no error, want %q", input, want)
-			return false
-		}
-		return true
-	}
-	if want == nil {
-		t.Errorf("input %s: unexpected error %q", input, got)
-	} else if got.Error() != want.Error() {
-		t.Errorf("input %s: got error %q, want %q", input, got, want)
-	}
-	return false
-}
-
-func referenceBig(s string) *big.Int {
-	b, ok := new(big.Int).SetString(s, 16)
-	if !ok {
-		panic("invalid")
-	}
-	return b
-}
-
-func referenceBytes(s string) []byte {
-	b, err := hex.DecodeString(s)
-	if err != nil {
-		panic(err)
-	}
-	return b
-}
-
-var errJSONEOF = errors.New("unexpected end of JSON input")
-
-var unmarshalBytesTests = []unmarshalTest{
-	// invalid encoding
-	{input: "", wantErr: errJSONEOF},
-	{input: "null", wantErr: errNonString(bytesT)},
-	{input: "10", wantErr: errNonString(bytesT)},
-	{input: `"0"`, wantErr: wrapTypeError(ErrMissingPrefix, bytesT)},
-	{input: `"0x0"`, wantErr: wrapTypeError(ErrOddLength, bytesT)},
-	{input: `"0xxx"`, wantErr: wrapTypeError(ErrSyntax, bytesT)},
-	{input: `"0x01zz01"`, wantErr: wrapTypeError(ErrSyntax, bytesT)},
-
-	// valid encoding
-	{input: `""`, want: referenceBytes("")},
-	{input: `"0x"`, want: referenceBytes("")},
-	{input: `"0x02"`, want: referenceBytes("02")},
-	{input: `"0X02"`, want: referenceBytes("02")},
-	{input: `"0xffffffffff"`, want: referenceBytes("ffffffffff")},
-	{
-		input: `"0xffffffffffffffffffffffffffffffffffff"`,
-		want:  referenceBytes("ffffffffffffffffffffffffffffffffffff"),
-	},
-}
-
-func TestUnmarshalBytes(t *testing.T) {
-	for _, test := range unmarshalBytesTests {
-		var v Bytes
-		err := json.Unmarshal([]byte(test.input), &v)
-		if !checkError(t, test.input, err, test.wantErr) {
-			continue
-		}
-		if !bytes.Equal(test.want.([]byte), v) {
-			t.Errorf("input %s: value mismatch: got %x, want %x", test.input, &v, test.want)
-			continue
-		}
-	}
-}
-
-func BenchmarkUnmarshalBytes(b *testing.B) {
-	input := []byte(`"0x123456789abcdef123456789abcdef"`)
-	for i := 0; i < b.N; i++ {
-		var v Bytes
-		if err := v.UnmarshalJSON(input); err != nil {
-			b.Fatal(err)
-		}
-	}
-}
-
-func TestMarshalBytes(t *testing.T) {
-	for _, test := range encodeBytesTests {
-		in := test.input.([]byte)
-		out, err := json.Marshal(Bytes(in))
-		if err != nil {
-			t.Errorf("%x: %v", in, err)
-			continue
-		}
-		if want := `"` + test.want + `"`; string(out) != want {
-			t.Errorf("%x: MarshalJSON output mismatch: got %q, want %q", in, out, want)
-			continue
-		}
-		if out := Bytes(in).String(); out != test.want {
-			t.Errorf("%x: String mismatch: got %q, want %q", in, out, test.want)
-			continue
-		}
-	}
-}
-
-var unmarshalBigTests = []unmarshalTest{
-	// invalid encoding
-	{input: "", wantErr: errJSONEOF},
-	{input: "null", wantErr: errNonString(bigT)},
-	{input: "10", wantErr: errNonString(bigT)},
-	{input: `"0"`, wantErr: wrapTypeError(ErrMissingPrefix, bigT)},
-	{input: `"0x"`, wantErr: wrapTypeError(ErrEmptyNumber, bigT)},
-	{input: `"0x01"`, wantErr: wrapTypeError(ErrLeadingZero, bigT)},
-	{input: `"0xx"`, wantErr: wrapTypeError(ErrSyntax, bigT)},
-	{input: `"0x1zz01"`, wantErr: wrapTypeError(ErrSyntax, bigT)},
-	{
-		input:   `"0x10000000000000000000000000000000000000000000000000000000000000000"`,
-		wantErr: wrapTypeError(ErrBig256Range, bigT),
-	},
-
-	// valid encoding
-	{input: `""`, want: big.NewInt(0)},
-	{input: `"0x0"`, want: big.NewInt(0)},
-	{input: `"0x2"`, want: big.NewInt(0x2)},
-	{input: `"0x2F2"`, want: big.NewInt(0x2f2)},
-	{input: `"0X2F2"`, want: big.NewInt(0x2f2)},
-	{input: `"0x1122aaff"`, want: big.NewInt(0x1122aaff)},
-	{input: `"0xbBb"`, want: big.NewInt(0xbbb)},
-	{input: `"0xfffffffff"`, want: big.NewInt(0xfffffffff)},
-	{
-		input: `"0x112233445566778899aabbccddeeff"`,
-		want:  referenceBig("112233445566778899aabbccddeeff"),
-	},
-	{
-		input: `"0xffffffffffffffffffffffffffffffffffff"`,
-		want:  referenceBig("ffffffffffffffffffffffffffffffffffff"),
-	},
-	{
-		input: `"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"`,
-		want:  referenceBig("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),
-	},
-}
-
-func TestUnmarshalBig(t *testing.T) {
-	for _, test := range unmarshalBigTests {
-		var v Big
-		err := json.Unmarshal([]byte(test.input), &v)
-		if !checkError(t, test.input, err, test.wantErr) {
-			continue
-		}
-		if test.want != nil && test.want.(*big.Int).Cmp((*big.Int)(&v)) != 0 {
-			t.Errorf("input %s: value mismatch: got %x, want %x", test.input, (*big.Int)(&v), test.want)
-			continue
-		}
-	}
-}
-
-func BenchmarkUnmarshalBig(b *testing.B) {
-	input := []byte(`"0x123456789abcdef123456789abcdef"`)
-	for i := 0; i < b.N; i++ {
-		var v Big
-		if err := v.UnmarshalJSON(input); err != nil {
-			b.Fatal(err)
-		}
-	}
-}
-
-func TestMarshalBig(t *testing.T) {
-	for _, test := range encodeBigTests {
-		in := test.input.(*big.Int)
-		out, err := json.Marshal((*Big)(in))
-		if err != nil {
-			t.Errorf("%d: %v", in, err)
-			continue
-		}
-		if want := `"` + test.want + `"`; string(out) != want {
-			t.Errorf("%d: MarshalJSON output mismatch: got %q, want %q", in, out, want)
-			continue
-		}
-		if out := (*Big)(in).String(); out != test.want {
-			t.Errorf("%x: String mismatch: got %q, want %q", in, out, test.want)
-			continue
-		}
-	}
-}
-
-var unmarshalUint64Tests = []unmarshalTest{
-	// invalid encoding
-	{input: "", wantErr: errJSONEOF},
-	{input: "null", wantErr: errNonString(uint64T)},
-	{input: "10", wantErr: errNonString(uint64T)},
-	{input: `"0"`, wantErr: wrapTypeError(ErrMissingPrefix, uint64T)},
-	{input: `"0x"`, wantErr: wrapTypeError(ErrEmptyNumber, uint64T)},
-	{input: `"0x01"`, wantErr: wrapTypeError(ErrLeadingZero, uint64T)},
-	{input: `"0xfffffffffffffffff"`, wantErr: wrapTypeError(ErrUint64Range, uint64T)},
-	{input: `"0xx"`, wantErr: wrapTypeError(ErrSyntax, uint64T)},
-	{input: `"0x1zz01"`, wantErr: wrapTypeError(ErrSyntax, uint64T)},
-
-	// valid encoding
-	{input: `""`, want: uint64(0)},
-	{input: `"0x0"`, want: uint64(0)},
-	{input: `"0x2"`, want: uint64(0x2)},
-	{input: `"0x2F2"`, want: uint64(0x2f2)},
-	{input: `"0X2F2"`, want: uint64(0x2f2)},
-	{input: `"0x1122aaff"`, want: uint64(0x1122aaff)},
-	{input: `"0xbbb"`, want: uint64(0xbbb)},
-	{input: `"0xffffffffffffffff"`, want: uint64(0xffffffffffffffff)},
-}
-
-func TestUnmarshalUint64(t *testing.T) {
-	for _, test := range unmarshalUint64Tests {
-		var v Uint64
-		err := json.Unmarshal([]byte(test.input), &v)
-		if !checkError(t, test.input, err, test.wantErr) {
-			continue
-		}
-		if uint64(v) != test.want.(uint64) {
-			t.Errorf("input %s: value mismatch: got %d, want %d", test.input, v, test.want)
-			continue
-		}
-	}
-}
-
-func BenchmarkUnmarshalUint64(b *testing.B) {
-	input := []byte(`"0x123456789abcdf"`)
-	for i := 0; i < b.N; i++ {
-		var v Uint64
-		v.UnmarshalJSON(input)
-	}
-}
-
-func TestMarshalUint64(t *testing.T) {
-	for _, test := range encodeUint64Tests {
-		in := test.input.(uint64)
-		out, err := json.Marshal(Uint64(in))
-		if err != nil {
-			t.Errorf("%d: %v", in, err)
-			continue
-		}
-		if want := `"` + test.want + `"`; string(out) != want {
-			t.Errorf("%d: MarshalJSON output mismatch: got %q, want %q", in, out, want)
-			continue
-		}
-		if out := (Uint64)(in).String(); out != test.want {
-			t.Errorf("%x: String mismatch: got %q, want %q", in, out, test.want)
-			continue
-		}
-	}
-}
-
-func TestMarshalUint(t *testing.T) {
-	for _, test := range encodeUintTests {
-		in := test.input.(uint)
-		out, err := json.Marshal(Uint(in))
-		if err != nil {
-			t.Errorf("%d: %v", in, err)
-			continue
-		}
-		if want := `"` + test.want + `"`; string(out) != want {
-			t.Errorf("%d: MarshalJSON output mismatch: got %q, want %q", in, out, want)
-			continue
-		}
-		if out := (Uint)(in).String(); out != test.want {
-			t.Errorf("%x: String mismatch: got %q, want %q", in, out, test.want)
-			continue
-		}
-	}
-}
-
-var (
-	// These are variables (not constants) to avoid constant overflow
-	// checks in the compiler on 32bit platforms.
-	maxUint33bits = uint64(^uint32(0)) + 1
-	maxUint64bits = ^uint64(0)
-)
-
-var unmarshalUintTests = []unmarshalTest{
-	// invalid encoding
-	{input: "", wantErr: errJSONEOF},
-	{input: "null", wantErr: errNonString(uintT)},
-	{input: "10", wantErr: errNonString(uintT)},
-	{input: `"0"`, wantErr: wrapTypeError(ErrMissingPrefix, uintT)},
-	{input: `"0x"`, wantErr: wrapTypeError(ErrEmptyNumber, uintT)},
-	{input: `"0x01"`, wantErr: wrapTypeError(ErrLeadingZero, uintT)},
-	{input: `"0x100000000"`, want: uint(maxUint33bits), wantErr32bit: wrapTypeError(ErrUintRange, uintT)},
-	{input: `"0xfffffffffffffffff"`, wantErr: wrapTypeError(ErrUintRange, uintT)},
-	{input: `"0xx"`, wantErr: wrapTypeError(ErrSyntax, uintT)},
-	{input: `"0x1zz01"`, wantErr: wrapTypeError(ErrSyntax, uintT)},
-
-	// valid encoding
-	{input: `""`, want: uint(0)},
-	{input: `"0x0"`, want: uint(0)},
-	{input: `"0x2"`, want: uint(0x2)},
-	{input: `"0x2F2"`, want: uint(0x2f2)},
-	{input: `"0X2F2"`, want: uint(0x2f2)},
-	{input: `"0x1122aaff"`, want: uint(0x1122aaff)},
-	{input: `"0xbbb"`, want: uint(0xbbb)},
-	{input: `"0xffffffff"`, want: uint(0xffffffff)},
-	{input: `"0xffffffffffffffff"`, want: uint(maxUint64bits), wantErr32bit: wrapTypeError(ErrUintRange, uintT)},
-}
-
-func TestUnmarshalUint(t *testing.T) {
-	for _, test := range unmarshalUintTests {
-		var v Uint
-		err := json.Unmarshal([]byte(test.input), &v)
-		if uintBits == 32 && test.wantErr32bit != nil {
-			checkError(t, test.input, err, test.wantErr32bit)
-			continue
-		}
-		if !checkError(t, test.input, err, test.wantErr) {
-			continue
-		}
-		if uint(v) != test.want.(uint) {
-			t.Errorf("input %s: value mismatch: got %d, want %d", test.input, v, test.want)
-			continue
-		}
-	}
-}
-
-func TestUnmarshalFixedUnprefixedText(t *testing.T) {
-	tests := []struct {
-		input   string
-		want    []byte
-		wantErr error
-	}{
-		{input: "0x2", wantErr: ErrOddLength},
-		{input: "2", wantErr: ErrOddLength},
-		{input: "4444", wantErr: errors.New("hex string has length 4, want 8 for x")},
-		{input: "4444", wantErr: errors.New("hex string has length 4, want 8 for x")},
-		// check that output is not modified for partially correct input
-		{input: "444444gg", wantErr: ErrSyntax, want: []byte{0, 0, 0, 0}},
-		{input: "0x444444gg", wantErr: ErrSyntax, want: []byte{0, 0, 0, 0}},
-		// valid inputs
-		{input: "44444444", want: []byte{0x44, 0x44, 0x44, 0x44}},
-		{input: "0x44444444", want: []byte{0x44, 0x44, 0x44, 0x44}},
-	}
-
-	for _, test := range tests {
-		out := make([]byte, 4)
-		err := UnmarshalFixedUnprefixedText("x", []byte(test.input), out)
-		switch {
-		case err == nil && test.wantErr != nil:
-			t.Errorf("%q: got no error, expected %q", test.input, test.wantErr)
-		case err != nil && test.wantErr == nil:
-			t.Errorf("%q: unexpected error %q", test.input, err)
-		case err != nil && err.Error() != test.wantErr.Error():
-			t.Errorf("%q: error mismatch: got %q, want %q", test.input, err, test.wantErr)
-		}
-		if test.want != nil && !bytes.Equal(out, test.want) {
-			t.Errorf("%q: output mismatch: got %x, want %x", test.input, out, test.want)
-		}
-	}
-}

+ 0 - 327
common/math/big_test.go

@@ -1,327 +0,0 @@
-// Copyright 2017 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package math
-
-import (
-	"bytes"
-	"encoding/hex"
-	"math/big"
-	"testing"
-
-	"github.com/ethereum/go-ethereum/common"
-)
-
-func TestHexOrDecimal256(t *testing.T) {
-	tests := []struct {
-		input string
-		num   *big.Int
-		ok    bool
-	}{
-		{"", big.NewInt(0), true},
-		{"0", big.NewInt(0), true},
-		{"0x0", big.NewInt(0), true},
-		{"12345678", big.NewInt(12345678), true},
-		{"0x12345678", big.NewInt(0x12345678), true},
-		{"0X12345678", big.NewInt(0x12345678), true},
-		// Tests for leading zero behaviour:
-		{"0123456789", big.NewInt(123456789), true}, // note: not octal
-		{"00", big.NewInt(0), true},
-		{"0x00", big.NewInt(0), true},
-		{"0x012345678abc", big.NewInt(0x12345678abc), true},
-		// Invalid syntax:
-		{"abcdef", nil, false},
-		{"0xgg", nil, false},
-		// Larger than 256 bits:
-		{"115792089237316195423570985008687907853269984665640564039457584007913129639936", nil, false},
-	}
-	for _, test := range tests {
-		var num HexOrDecimal256
-		err := num.UnmarshalText([]byte(test.input))
-		if (err == nil) != test.ok {
-			t.Errorf("ParseBig(%q) -> (err == nil) == %t, want %t", test.input, err == nil, test.ok)
-			continue
-		}
-		if test.num != nil && (*big.Int)(&num).Cmp(test.num) != 0 {
-			t.Errorf("ParseBig(%q) -> %d, want %d", test.input, (*big.Int)(&num), test.num)
-		}
-	}
-}
-
-func TestMustParseBig256(t *testing.T) {
-	defer func() {
-		if recover() == nil {
-			t.Error("MustParseBig should've panicked")
-		}
-	}()
-	MustParseBig256("ggg")
-}
-
-func TestBigMax(t *testing.T) {
-	a := big.NewInt(10)
-	b := big.NewInt(5)
-
-	max1 := BigMax(a, b)
-	if max1 != a {
-		t.Errorf("Expected %d got %d", a, max1)
-	}
-
-	max2 := BigMax(b, a)
-	if max2 != a {
-		t.Errorf("Expected %d got %d", a, max2)
-	}
-}
-
-func TestBigMin(t *testing.T) {
-	a := big.NewInt(10)
-	b := big.NewInt(5)
-
-	min1 := BigMin(a, b)
-	if min1 != b {
-		t.Errorf("Expected %d got %d", b, min1)
-	}
-
-	min2 := BigMin(b, a)
-	if min2 != b {
-		t.Errorf("Expected %d got %d", b, min2)
-	}
-}
-
-func TestFirstBigSet(t *testing.T) {
-	tests := []struct {
-		num *big.Int
-		ix  int
-	}{
-		{big.NewInt(0), 0},
-		{big.NewInt(1), 0},
-		{big.NewInt(2), 1},
-		{big.NewInt(0x100), 8},
-	}
-	for _, test := range tests {
-		if ix := FirstBitSet(test.num); ix != test.ix {
-			t.Errorf("FirstBitSet(b%b) = %d, want %d", test.num, ix, test.ix)
-		}
-	}
-}
-
-func TestPaddedBigBytes(t *testing.T) {
-	tests := []struct {
-		num    *big.Int
-		n      int
-		result []byte
-	}{
-		{num: big.NewInt(0), n: 4, result: []byte{0, 0, 0, 0}},
-		{num: big.NewInt(1), n: 4, result: []byte{0, 0, 0, 1}},
-		{num: big.NewInt(512), n: 4, result: []byte{0, 0, 2, 0}},
-		{num: BigPow(2, 32), n: 4, result: []byte{1, 0, 0, 0, 0}},
-	}
-	for _, test := range tests {
-		if result := PaddedBigBytes(test.num, test.n); !bytes.Equal(result, test.result) {
-			t.Errorf("PaddedBigBytes(%d, %d) = %v, want %v", test.num, test.n, result, test.result)
-		}
-	}
-}
-
-func BenchmarkPaddedBigBytesLargePadding(b *testing.B) {
-	bigint := MustParseBig256("123456789123456789123456789123456789")
-	for i := 0; i < b.N; i++ {
-		PaddedBigBytes(bigint, 200)
-	}
-}
-
-func BenchmarkPaddedBigBytesSmallPadding(b *testing.B) {
-	bigint := MustParseBig256("0x18F8F8F1000111000110011100222004330052300000000000000000FEFCF3CC")
-	for i := 0; i < b.N; i++ {
-		PaddedBigBytes(bigint, 5)
-	}
-}
-
-func BenchmarkPaddedBigBytesSmallOnePadding(b *testing.B) {
-	bigint := MustParseBig256("0x18F8F8F1000111000110011100222004330052300000000000000000FEFCF3CC")
-	for i := 0; i < b.N; i++ {
-		PaddedBigBytes(bigint, 32)
-	}
-}
-
-func BenchmarkByteAtBrandNew(b *testing.B) {
-	bigint := MustParseBig256("0x18F8F8F1000111000110011100222004330052300000000000000000FEFCF3CC")
-	for i := 0; i < b.N; i++ {
-		bigEndianByteAt(bigint, 15)
-	}
-}
-
-func BenchmarkByteAt(b *testing.B) {
-	bigint := MustParseBig256("0x18F8F8F1000111000110011100222004330052300000000000000000FEFCF3CC")
-	for i := 0; i < b.N; i++ {
-		bigEndianByteAt(bigint, 15)
-	}
-}
-
-func BenchmarkByteAtOld(b *testing.B) {
-
-	bigint := MustParseBig256("0x18F8F8F1000111000110011100222004330052300000000000000000FEFCF3CC")
-	for i := 0; i < b.N; i++ {
-		PaddedBigBytes(bigint, 32)
-	}
-}
-
-func TestReadBits(t *testing.T) {
-	check := func(input string) {
-		want, _ := hex.DecodeString(input)
-		int, _ := new(big.Int).SetString(input, 16)
-		buf := make([]byte, len(want))
-		ReadBits(int, buf)
-		if !bytes.Equal(buf, want) {
-			t.Errorf("have: %x\nwant: %x", buf, want)
-		}
-	}
-	check("000000000000000000000000000000000000000000000000000000FEFCF3F8F0")
-	check("0000000000012345000000000000000000000000000000000000FEFCF3F8F0")
-	check("18F8F8F1000111000110011100222004330052300000000000000000FEFCF3F8F0")
-}
-
-func TestU256(t *testing.T) {
-	tests := []struct{ x, y *big.Int }{
-		{x: big.NewInt(0), y: big.NewInt(0)},
-		{x: big.NewInt(1), y: big.NewInt(1)},
-		{x: BigPow(2, 255), y: BigPow(2, 255)},
-		{x: BigPow(2, 256), y: big.NewInt(0)},
-		{x: new(big.Int).Add(BigPow(2, 256), big.NewInt(1)), y: big.NewInt(1)},
-		// negative values
-		{x: big.NewInt(-1), y: new(big.Int).Sub(BigPow(2, 256), big.NewInt(1))},
-		{x: big.NewInt(-2), y: new(big.Int).Sub(BigPow(2, 256), big.NewInt(2))},
-		{x: BigPow(2, -255), y: big.NewInt(1)},
-	}
-	for _, test := range tests {
-		if y := U256(new(big.Int).Set(test.x)); y.Cmp(test.y) != 0 {
-			t.Errorf("U256(%x) = %x, want %x", test.x, y, test.y)
-		}
-	}
-}
-
-func TestU256Bytes(t *testing.T) {
-	ubytes := make([]byte, 32)
-	ubytes[31] = 1
-
-	unsigned := U256Bytes(big.NewInt(1))
-	if !bytes.Equal(unsigned, ubytes) {
-		t.Errorf("expected %x got %x", ubytes, unsigned)
-	}
-}
-
-func TestBigEndianByteAt(t *testing.T) {
-	tests := []struct {
-		x   string
-		y   int
-		exp byte
-	}{
-		{"00", 0, 0x00},
-		{"01", 1, 0x00},
-		{"00", 1, 0x00},
-		{"01", 0, 0x01},
-		{"0000000000000000000000000000000000000000000000000000000000102030", 0, 0x30},
-		{"0000000000000000000000000000000000000000000000000000000000102030", 1, 0x20},
-		{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 31, 0xAB},
-		{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 32, 0x00},
-		{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 500, 0x00},
-	}
-	for _, test := range tests {
-		v := new(big.Int).SetBytes(common.Hex2Bytes(test.x))
-		actual := bigEndianByteAt(v, test.y)
-		if actual != test.exp {
-			t.Fatalf("Expected  [%v] %v:th byte to be %v, was %v.", test.x, test.y, test.exp, actual)
-		}
-
-	}
-}
-func TestLittleEndianByteAt(t *testing.T) {
-	tests := []struct {
-		x   string
-		y   int
-		exp byte
-	}{
-		{"00", 0, 0x00},
-		{"01", 1, 0x00},
-		{"00", 1, 0x00},
-		{"01", 0, 0x00},
-		{"0000000000000000000000000000000000000000000000000000000000102030", 0, 0x00},
-		{"0000000000000000000000000000000000000000000000000000000000102030", 1, 0x00},
-		{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 31, 0x00},
-		{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 32, 0x00},
-		{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 0, 0xAB},
-		{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 1, 0xCD},
-		{"00CDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff", 0, 0x00},
-		{"00CDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff", 1, 0xCD},
-		{"0000000000000000000000000000000000000000000000000000000000102030", 31, 0x30},
-		{"0000000000000000000000000000000000000000000000000000000000102030", 30, 0x20},
-		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 32, 0x0},
-		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 31, 0xFF},
-		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 0xFFFF, 0x0},
-	}
-	for _, test := range tests {
-		v := new(big.Int).SetBytes(common.Hex2Bytes(test.x))
-		actual := Byte(v, 32, test.y)
-		if actual != test.exp {
-			t.Fatalf("Expected  [%v] %v:th byte to be %v, was %v.", test.x, test.y, test.exp, actual)
-		}
-
-	}
-}
-
-func TestS256(t *testing.T) {
-	tests := []struct{ x, y *big.Int }{
-		{x: big.NewInt(0), y: big.NewInt(0)},
-		{x: big.NewInt(1), y: big.NewInt(1)},
-		{x: big.NewInt(2), y: big.NewInt(2)},
-		{
-			x: new(big.Int).Sub(BigPow(2, 255), big.NewInt(1)),
-			y: new(big.Int).Sub(BigPow(2, 255), big.NewInt(1)),
-		},
-		{
-			x: BigPow(2, 255),
-			y: new(big.Int).Neg(BigPow(2, 255)),
-		},
-		{
-			x: new(big.Int).Sub(BigPow(2, 256), big.NewInt(1)),
-			y: big.NewInt(-1),
-		},
-		{
-			x: new(big.Int).Sub(BigPow(2, 256), big.NewInt(2)),
-			y: big.NewInt(-2),
-		},
-	}
-	for _, test := range tests {
-		if y := S256(test.x); y.Cmp(test.y) != 0 {
-			t.Errorf("S256(%x) = %x, want %x", test.x, y, test.y)
-		}
-	}
-}
-
-func TestExp(t *testing.T) {
-	tests := []struct{ base, exponent, result *big.Int }{
-		{base: big.NewInt(0), exponent: big.NewInt(0), result: big.NewInt(1)},
-		{base: big.NewInt(1), exponent: big.NewInt(0), result: big.NewInt(1)},
-		{base: big.NewInt(1), exponent: big.NewInt(1), result: big.NewInt(1)},
-		{base: big.NewInt(1), exponent: big.NewInt(2), result: big.NewInt(1)},
-		{base: big.NewInt(3), exponent: big.NewInt(144), result: MustParseBig256("507528786056415600719754159741696356908742250191663887263627442114881")},
-		{base: big.NewInt(2), exponent: big.NewInt(255), result: MustParseBig256("57896044618658097711785492504343953926634992332820282019728792003956564819968")},
-	}
-	for _, test := range tests {
-		if result := Exp(test.base, test.exponent); result.Cmp(test.result) != 0 {
-			t.Errorf("Exp(%d, %d) = %d, want %d", test.base, test.exponent, result, test.result)
-		}
-	}
-}

+ 0 - 116
common/math/integer_test.go

@@ -1,116 +0,0 @@
-// Copyright 2017 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package math
-
-import (
-	"testing"
-)
-
-type operation byte
-
-const (
-	sub operation = iota
-	add
-	mul
-)
-
-func TestOverflow(t *testing.T) {
-	for i, test := range []struct {
-		x        uint64
-		y        uint64
-		overflow bool
-		op       operation
-	}{
-		// add operations
-		{MaxUint64, 1, true, add},
-		{MaxUint64 - 1, 1, false, add},
-
-		// sub operations
-		{0, 1, true, sub},
-		{0, 0, false, sub},
-
-		// mul operations
-		{0, 0, false, mul},
-		{10, 10, false, mul},
-		{MaxUint64, 2, true, mul},
-		{MaxUint64, 1, false, mul},
-	} {
-		var overflows bool
-		switch test.op {
-		case sub:
-			_, overflows = SafeSub(test.x, test.y)
-		case add:
-			_, overflows = SafeAdd(test.x, test.y)
-		case mul:
-			_, overflows = SafeMul(test.x, test.y)
-		}
-
-		if test.overflow != overflows {
-			t.Errorf("%d failed. Expected test to be %v, got %v", i, test.overflow, overflows)
-		}
-	}
-}
-
-func TestHexOrDecimal64(t *testing.T) {
-	tests := []struct {
-		input string
-		num   uint64
-		ok    bool
-	}{
-		{"", 0, true},
-		{"0", 0, true},
-		{"0x0", 0, true},
-		{"12345678", 12345678, true},
-		{"0x12345678", 0x12345678, true},
-		{"0X12345678", 0x12345678, true},
-		// Tests for leading zero behaviour:
-		{"0123456789", 123456789, true}, // note: not octal
-		{"0x00", 0, true},
-		{"0x012345678abc", 0x12345678abc, true},
-		// Invalid syntax:
-		{"abcdef", 0, false},
-		{"0xgg", 0, false},
-		// Doesn't fit into 64 bits:
-		{"18446744073709551617", 0, false},
-	}
-	for _, test := range tests {
-		var num HexOrDecimal64
-		err := num.UnmarshalText([]byte(test.input))
-		if (err == nil) != test.ok {
-			t.Errorf("ParseUint64(%q) -> (err == nil) = %t, want %t", test.input, err == nil, test.ok)
-			continue
-		}
-		if err == nil && uint64(num) != test.num {
-			t.Errorf("ParseUint64(%q) -> %d, want %d", test.input, num, test.num)
-		}
-	}
-}
-
-func TestMustParseUint64(t *testing.T) {
-	if v := MustParseUint64("12345"); v != 12345 {
-		t.Errorf(`MustParseUint64("12345") = %d, want 12345`, v)
-	}
-}
-
-func TestMustParseUint64Panic(t *testing.T) {
-	defer func() {
-		if recover() == nil {
-			t.Error("MustParseBig should've panicked")
-		}
-	}()
-	MustParseUint64("ggg")
-}

+ 0 - 162
common/mclock/simclock_test.go

@@ -1,162 +0,0 @@
-// Copyright 2018 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package mclock
-
-import (
-	"testing"
-	"time"
-)
-
-var _ Clock = System{}
-var _ Clock = new(Simulated)
-
-func TestSimulatedAfter(t *testing.T) {
-	var (
-		timeout = 30 * time.Minute
-		offset  = 99 * time.Hour
-		adv     = 11 * time.Minute
-		c       Simulated
-	)
-	c.Run(offset)
-
-	end := c.Now().Add(timeout)
-	ch := c.After(timeout)
-	for c.Now() < end.Add(-adv) {
-		c.Run(adv)
-		select {
-		case <-ch:
-			t.Fatal("Timer fired early")
-		default:
-		}
-	}
-
-	c.Run(adv)
-	select {
-	case stamp := <-ch:
-		want := AbsTime(0).Add(offset).Add(timeout)
-		if stamp != want {
-			t.Errorf("Wrong time sent on timer channel: got %v, want %v", stamp, want)
-		}
-	default:
-		t.Fatal("Timer didn't fire")
-	}
-}
-
-func TestSimulatedAfterFunc(t *testing.T) {
-	var c Simulated
-
-	called1 := false
-	timer1 := c.AfterFunc(100*time.Millisecond, func() { called1 = true })
-	if c.ActiveTimers() != 1 {
-		t.Fatalf("%d active timers, want one", c.ActiveTimers())
-	}
-	if fired := timer1.Stop(); !fired {
-		t.Fatal("Stop returned false even though timer didn't fire")
-	}
-	if c.ActiveTimers() != 0 {
-		t.Fatalf("%d active timers, want zero", c.ActiveTimers())
-	}
-	if called1 {
-		t.Fatal("timer 1 called")
-	}
-	if fired := timer1.Stop(); fired {
-		t.Fatal("Stop returned true after timer was already stopped")
-	}
-
-	called2 := false
-	timer2 := c.AfterFunc(100*time.Millisecond, func() { called2 = true })
-	c.Run(50 * time.Millisecond)
-	if called2 {
-		t.Fatal("timer 2 called")
-	}
-	c.Run(51 * time.Millisecond)
-	if !called2 {
-		t.Fatal("timer 2 not called")
-	}
-	if fired := timer2.Stop(); fired {
-		t.Fatal("Stop returned true after timer has fired")
-	}
-}
-
-func TestSimulatedSleep(t *testing.T) {
-	var (
-		c       Simulated
-		timeout = 1 * time.Hour
-		done    = make(chan AbsTime, 1)
-	)
-	go func() {
-		c.Sleep(timeout)
-		done <- c.Now()
-	}()
-
-	c.WaitForTimers(1)
-	c.Run(2 * timeout)
-	select {
-	case stamp := <-done:
-		want := AbsTime(2 * timeout)
-		if stamp != want {
-			t.Errorf("Wrong time after sleep: got %v, want %v", stamp, want)
-		}
-	case <-time.After(5 * time.Second):
-		t.Fatal("Sleep didn't return in time")
-	}
-}
-
-func TestSimulatedTimerReset(t *testing.T) {
-	var (
-		c       Simulated
-		timeout = 1 * time.Hour
-	)
-	timer := c.NewTimer(timeout)
-	c.Run(2 * timeout)
-	select {
-	case ftime := <-timer.C():
-		if ftime != AbsTime(timeout) {
-			t.Fatalf("wrong time %v sent on timer channel, want %v", ftime, AbsTime(timeout))
-		}
-	default:
-		t.Fatal("timer didn't fire")
-	}
-
-	timer.Reset(timeout)
-	c.Run(2 * timeout)
-	select {
-	case ftime := <-timer.C():
-		if ftime != AbsTime(3*timeout) {
-			t.Fatalf("wrong time %v sent on timer channel, want %v", ftime, AbsTime(3*timeout))
-		}
-	default:
-		t.Fatal("timer didn't fire again")
-	}
-}
-
-func TestSimulatedTimerStop(t *testing.T) {
-	var (
-		c       Simulated
-		timeout = 1 * time.Hour
-	)
-	timer := c.NewTimer(timeout)
-	c.Run(2 * timeout)
-	if timer.Stop() {
-		t.Errorf("Stop returned true for fired timer")
-	}
-	select {
-	case <-timer.C():
-	default:
-		t.Fatal("timer didn't fire")
-	}
-}

+ 0 - 124
common/prque/lazyqueue_test.go

@@ -1,124 +0,0 @@
-// Copyright 2019 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package prque
-
-import (
-	"math/rand"
-	"sync"
-	"testing"
-	"time"
-
-	"github.com/ethereum/go-ethereum/common/mclock"
-)
-
-const (
-	testItems        = 1000
-	testPriorityStep = 100
-	testSteps        = 1000000
-	testStepPeriod   = time.Millisecond
-	testQueueRefresh = time.Second
-	testAvgRate      = float64(testPriorityStep) / float64(testItems) / float64(testStepPeriod)
-)
-
-type lazyItem struct {
-	p, maxp int64
-	last    mclock.AbsTime
-	index   int
-}
-
-func testPriority(a interface{}) int64 {
-	return a.(*lazyItem).p
-}
-
-func testMaxPriority(a interface{}, until mclock.AbsTime) int64 {
-	i := a.(*lazyItem)
-	dt := until - i.last
-	i.maxp = i.p + int64(float64(dt)*testAvgRate)
-	return i.maxp
-}
-
-func testSetIndex(a interface{}, i int) {
-	a.(*lazyItem).index = i
-}
-
-func TestLazyQueue(t *testing.T) {
-	rand.Seed(time.Now().UnixNano())
-	clock := &mclock.Simulated{}
-	q := NewLazyQueue(testSetIndex, testPriority, testMaxPriority, clock, testQueueRefresh)
-
-	var (
-		items  [testItems]lazyItem
-		maxPri int64
-	)
-
-	for i := range items[:] {
-		items[i].p = rand.Int63n(testPriorityStep * 10)
-		if items[i].p > maxPri {
-			maxPri = items[i].p
-		}
-		items[i].index = -1
-		q.Push(&items[i])
-	}
-
-	var (
-		lock   sync.Mutex
-		wg     sync.WaitGroup
-		stopCh = make(chan chan struct{})
-	)
-	defer wg.Wait()
-	wg.Add(1)
-	go func() {
-		defer wg.Done()
-		for {
-			select {
-			case <-clock.After(testQueueRefresh):
-				lock.Lock()
-				q.Refresh()
-				lock.Unlock()
-			case <-stopCh:
-				return
-			}
-		}
-	}()
-
-	for c := 0; c < testSteps; c++ {
-		i := rand.Intn(testItems)
-		lock.Lock()
-		items[i].p += rand.Int63n(testPriorityStep*2-1) + 1
-		if items[i].p > maxPri {
-			maxPri = items[i].p
-		}
-		items[i].last = clock.Now()
-		if items[i].p > items[i].maxp {
-			q.Update(items[i].index)
-		}
-		if rand.Intn(100) == 0 {
-			p := q.PopItem().(*lazyItem)
-			if p.p != maxPri {
-				lock.Unlock()
-				close(stopCh)
-				t.Fatalf("incorrect item (best known priority %d, popped %d)", maxPri, p.p)
-			}
-			q.Push(p)
-		}
-		lock.Unlock()
-		clock.Run(testStepPeriod)
-		clock.WaitForTimers(1)
-	}
-
-	close(stopCh)
-}

+ 0 - 130
common/prque/prque_test.go

@@ -1,130 +0,0 @@
-// CookieJar - A contestant's algorithm toolbox
-// Copyright (c) 2013 Peter Szilagyi. All rights reserved.
-//
-// CookieJar is dual licensed: use of this source code is governed by a BSD
-// license that can be found in the LICENSE file. Alternatively, the CookieJar
-// toolbox may be used in accordance with the terms and conditions contained
-// in a signed written agreement between you and the author(s).
-
-package prque
-
-import (
-	"math/rand"
-	"testing"
-)
-
-func TestPrque(t *testing.T) {
-	// Generate a batch of random data and a specific priority order
-	size := 16 * blockSize
-	prio := rand.Perm(size)
-	data := make([]int, size)
-	for i := 0; i < size; i++ {
-		data[i] = rand.Int()
-	}
-	queue := New(nil)
-	for rep := 0; rep < 2; rep++ {
-		// Fill a priority queue with the above data
-		for i := 0; i < size; i++ {
-			queue.Push(data[i], int64(prio[i]))
-			if queue.Size() != i+1 {
-				t.Errorf("queue size mismatch: have %v, want %v.", queue.Size(), i+1)
-			}
-		}
-		// Create a map the values to the priorities for easier verification
-		dict := make(map[int64]int)
-		for i := 0; i < size; i++ {
-			dict[int64(prio[i])] = data[i]
-		}
-		// Pop out the elements in priority order and verify them
-		prevPrio := int64(size + 1)
-		for !queue.Empty() {
-			val, prio := queue.Pop()
-			if prio > prevPrio {
-				t.Errorf("invalid priority order: %v after %v.", prio, prevPrio)
-			}
-			prevPrio = prio
-			if val != dict[prio] {
-				t.Errorf("push/pop mismatch: have %v, want %v.", val, dict[prio])
-			}
-			delete(dict, prio)
-		}
-	}
-}
-
-func TestReset(t *testing.T) {
-	// Generate a batch of random data and a specific priority order
-	size := 16 * blockSize
-	prio := rand.Perm(size)
-	data := make([]int, size)
-	for i := 0; i < size; i++ {
-		data[i] = rand.Int()
-	}
-	queue := New(nil)
-	for rep := 0; rep < 2; rep++ {
-		// Fill a priority queue with the above data
-		for i := 0; i < size; i++ {
-			queue.Push(data[i], int64(prio[i]))
-			if queue.Size() != i+1 {
-				t.Errorf("queue size mismatch: have %v, want %v.", queue.Size(), i+1)
-			}
-		}
-		// Create a map the values to the priorities for easier verification
-		dict := make(map[int64]int)
-		for i := 0; i < size; i++ {
-			dict[int64(prio[i])] = data[i]
-		}
-		// Pop out half the elements in priority order and verify them
-		prevPrio := int64(size + 1)
-		for i := 0; i < size/2; i++ {
-			val, prio := queue.Pop()
-			if prio > prevPrio {
-				t.Errorf("invalid priority order: %v after %v.", prio, prevPrio)
-			}
-			prevPrio = prio
-			if val != dict[prio] {
-				t.Errorf("push/pop mismatch: have %v, want %v.", val, dict[prio])
-			}
-			delete(dict, prio)
-		}
-		// Reset and ensure it's empty
-		queue.Reset()
-		if !queue.Empty() {
-			t.Errorf("priority queue not empty after reset: %v", queue)
-		}
-	}
-}
-
-func BenchmarkPush(b *testing.B) {
-	// Create some initial data
-	data := make([]int, b.N)
-	prio := make([]int64, b.N)
-	for i := 0; i < len(data); i++ {
-		data[i] = rand.Int()
-		prio[i] = rand.Int63()
-	}
-	// Execute the benchmark
-	b.ResetTimer()
-	queue := New(nil)
-	for i := 0; i < len(data); i++ {
-		queue.Push(data[i], prio[i])
-	}
-}
-
-func BenchmarkPop(b *testing.B) {
-	// Create some initial data
-	data := make([]int, b.N)
-	prio := make([]int64, b.N)
-	for i := 0; i < len(data); i++ {
-		data[i] = rand.Int()
-		prio[i] = rand.Int63()
-	}
-	queue := New(nil)
-	for i := 0; i < len(data); i++ {
-		queue.Push(data[i], prio[i])
-	}
-	// Execute the benchmark
-	b.ResetTimer()
-	for !queue.Empty() {
-		queue.Pop()
-	}
-}

+ 0 - 100
common/prque/sstack_test.go

@@ -1,100 +0,0 @@
-// CookieJar - A contestant's algorithm toolbox
-// Copyright (c) 2013 Peter Szilagyi. All rights reserved.
-//
-// CookieJar is dual licensed: use of this source code is governed by a BSD
-// license that can be found in the LICENSE file. Alternatively, the CookieJar
-// toolbox may be used in accordance with the terms and conditions contained
-// in a signed written agreement between you and the author(s).
-
-package prque
-
-import (
-	"math/rand"
-	"sort"
-	"testing"
-)
-
-func TestSstack(t *testing.T) {
-	// Create some initial data
-	size := 16 * blockSize
-	data := make([]*item, size)
-	for i := 0; i < size; i++ {
-		data[i] = &item{rand.Int(), rand.Int63()}
-	}
-	stack := newSstack(nil, false)
-	for rep := 0; rep < 2; rep++ {
-		// Push all the data into the stack, pop out every second
-		secs := []*item{}
-		for i := 0; i < size; i++ {
-			stack.Push(data[i])
-			if i%2 == 0 {
-				secs = append(secs, stack.Pop().(*item))
-			}
-		}
-		rest := []*item{}
-		for stack.Len() > 0 {
-			rest = append(rest, stack.Pop().(*item))
-		}
-		// Make sure the contents of the resulting slices are ok
-		for i := 0; i < size; i++ {
-			if i%2 == 0 && data[i] != secs[i/2] {
-				t.Errorf("push/pop mismatch: have %v, want %v.", secs[i/2], data[i])
-			}
-			if i%2 == 1 && data[i] != rest[len(rest)-i/2-1] {
-				t.Errorf("push/pop mismatch: have %v, want %v.", rest[len(rest)-i/2-1], data[i])
-			}
-		}
-	}
-}
-
-func TestSstackSort(t *testing.T) {
-	// Create some initial data
-	size := 16 * blockSize
-	data := make([]*item, size)
-	for i := 0; i < size; i++ {
-		data[i] = &item{rand.Int(), int64(i)}
-	}
-	// Push all the data into the stack
-	stack := newSstack(nil, false)
-	for _, val := range data {
-		stack.Push(val)
-	}
-	// Sort and pop the stack contents (should reverse the order)
-	sort.Sort(stack)
-	for _, val := range data {
-		out := stack.Pop()
-		if out != val {
-			t.Errorf("push/pop mismatch after sort: have %v, want %v.", out, val)
-		}
-	}
-}
-
-func TestSstackReset(t *testing.T) {
-	// Create some initial data
-	size := 16 * blockSize
-	data := make([]*item, size)
-	for i := 0; i < size; i++ {
-		data[i] = &item{rand.Int(), rand.Int63()}
-	}
-	stack := newSstack(nil, false)
-	for rep := 0; rep < 2; rep++ {
-		// Push all the data into the stack, pop out every second
-		secs := []*item{}
-		for i := 0; i < size; i++ {
-			stack.Push(data[i])
-			if i%2 == 0 {
-				secs = append(secs, stack.Pop().(*item))
-			}
-		}
-		// Reset and verify both pulled and stack contents
-		stack.Reset()
-		if stack.Len() != 0 {
-			t.Errorf("stack not empty after reset: %v", stack)
-		}
-		for i := 0; i < size; i++ {
-			if i%2 == 0 && data[i] != secs[i/2] {
-				t.Errorf("push/pop mismatch: have %v, want %v.", secs[i/2], data[i])
-			}
-		}
-	}
-}

+ 0 - 38
common/size_test.go

@@ -1,38 +0,0 @@
-// Copyright 2014 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package common
-
-import (
-	"testing"
-)
-
-func TestStorageSizeString(t *testing.T) {
-	tests := []struct {
-		size StorageSize
-		str  string
-	}{
-		{2381273, "2.27 MiB"},
-		{2192, "2.14 KiB"},
-		{12, "12.00 B"},
-	}
-
-	for _, test := range tests {
-		if test.size.String() != test.str {
-			t.Errorf("%f: got %q, want %q", float64(test.size), test.size.String(), test.str)
-		}
-	}
-}

+ 0 - 539
common/types_test.go

@@ -1,539 +0,0 @@
-// Copyright 2015 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package common
-
-import (
-	"bytes"
-	"database/sql/driver"
-	"encoding/json"
-	"fmt"
-	"math/big"
-	"reflect"
-	"strings"
-	"testing"
-)
-
-func TestBytesConversion(t *testing.T) {
-	bytes := []byte{5}
-	hash := BytesToHash(bytes)
-
-	var exp Hash
-	exp[31] = 5
-
-	if hash != exp {
-		t.Errorf("expected %x got %x", exp, hash)
-	}
-}
-
-func TestIsHexAddress(t *testing.T) {
-	tests := []struct {
-		str string
-		exp bool
-	}{
-		{"0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed", true},
-		{"5aaeb6053f3e94c9b9a09f33669435e7ef1beaed", true},
-		{"0X5aaeb6053f3e94c9b9a09f33669435e7ef1beaed", true},
-		{"0XAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", true},
-		{"0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", true},
-		{"0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed1", false},
-		{"0x5aaeb6053f3e94c9b9a09f33669435e7ef1beae", false},
-		{"5aaeb6053f3e94c9b9a09f33669435e7ef1beaed11", false},
-		{"0xxaaeb6053f3e94c9b9a09f33669435e7ef1beaed", false},
-	}
-
-	for _, test := range tests {
-		if result := IsHexAddress(test.str); result != test.exp {
-			t.Errorf("IsHexAddress(%s) == %v; expected %v",
-				test.str, result, test.exp)
-		}
-	}
-}
-
-func TestHashJsonValidation(t *testing.T) {
-	var tests = []struct {
-		Prefix string
-		Size   int
-		Error  string
-	}{
-		{"", 62, "json: cannot unmarshal hex string without 0x prefix into Go value of type common.Hash"},
-		{"0x", 66, "hex string has length 66, want 64 for common.Hash"},
-		{"0x", 63, "json: cannot unmarshal hex string of odd length into Go value of type common.Hash"},
-		{"0x", 0, "hex string has length 0, want 64 for common.Hash"},
-		{"0x", 64, ""},
-		{"0X", 64, ""},
-	}
-	for _, test := range tests {
-		input := `"` + test.Prefix + strings.Repeat("0", test.Size) + `"`
-		var v Hash
-		err := json.Unmarshal([]byte(input), &v)
-		if err == nil {
-			if test.Error != "" {
-				t.Errorf("%s: error mismatch: have nil, want %q", input, test.Error)
-			}
-		} else {
-			if err.Error() != test.Error {
-				t.Errorf("%s: error mismatch: have %q, want %q", input, err, test.Error)
-			}
-		}
-	}
-}
-
-func TestAddressUnmarshalJSON(t *testing.T) {
-	var tests = []struct {
-		Input     string
-		ShouldErr bool
-		Output    *big.Int
-	}{
-		{"", true, nil},
-		{`""`, true, nil},
-		{`"0x"`, true, nil},
-		{`"0x00"`, true, nil},
-		{`"0xG000000000000000000000000000000000000000"`, true, nil},
-		{`"0x0000000000000000000000000000000000000000"`, false, big.NewInt(0)},
-		{`"0x0000000000000000000000000000000000000010"`, false, big.NewInt(16)},
-	}
-	for i, test := range tests {
-		var v Address
-		err := json.Unmarshal([]byte(test.Input), &v)
-		if err != nil && !test.ShouldErr {
-			t.Errorf("test #%d: unexpected error: %v", i, err)
-		}
-		if err == nil {
-			if test.ShouldErr {
-				t.Errorf("test #%d: expected error, got none", i)
-			}
-			if got := new(big.Int).SetBytes(v.Bytes()); got.Cmp(test.Output) != 0 {
-				t.Errorf("test #%d: address mismatch: have %v, want %v", i, got, test.Output)
-			}
-		}
-	}
-}
-
-func TestAddressHexChecksum(t *testing.T) {
-	var tests = []struct {
-		Input  string
-		Output string
-	}{
-		// Test cases from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md#specification
-		{"0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed", "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"},
-		{"0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359", "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359"},
-		{"0xdbf03b407c01e7cd3cbea99509d93f8dddc8c6fb", "0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB"},
-		{"0xd1220a0cf47c7b9be7a2e6ba89f429762e7b9adb", "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb"},
-		// Ensure that non-standard length input values are handled correctly
-		{"0xa", "0x000000000000000000000000000000000000000A"},
-		{"0x0a", "0x000000000000000000000000000000000000000A"},
-		{"0x00a", "0x000000000000000000000000000000000000000A"},
-		{"0x000000000000000000000000000000000000000a", "0x000000000000000000000000000000000000000A"},
-	}
-	for i, test := range tests {
-		output := HexToAddress(test.Input).Hex()
-		if output != test.Output {
-			t.Errorf("test #%d: failed to match when it should (%s != %s)", i, output, test.Output)
-		}
-	}
-}
-
-func BenchmarkAddressHex(b *testing.B) {
-	testAddr := HexToAddress("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed")
-	for n := 0; n < b.N; n++ {
-		testAddr.Hex()
-	}
-}
-
-func TestMixedcaseAccount_Address(t *testing.T) {
-
-	// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md
-	// Note: 0X{checksum_addr} is not valid according to spec above
-
-	var res []struct {
-		A     MixedcaseAddress
-		Valid bool
-	}
-	if err := json.Unmarshal([]byte(`[
-		{"A" : "0xae967917c465db8578ca9024c205720b1a3651A9", "Valid": false},
-		{"A" : "0xAe967917c465db8578ca9024c205720b1a3651A9", "Valid": true},
-		{"A" : "0XAe967917c465db8578ca9024c205720b1a3651A9", "Valid": false},
-		{"A" : "0x1111111111111111111112222222222223333323", "Valid": true}
-		]`), &res); err != nil {
-		t.Fatal(err)
-	}
-
-	for _, r := range res {
-		if got := r.A.ValidChecksum(); got != r.Valid {
-			t.Errorf("Expected checksum %v, got checksum %v, input %v", r.Valid, got, r.A.String())
-		}
-	}
-
-	//These should throw exceptions:
-	var r2 []MixedcaseAddress
-	for _, r := range []string{
-		`["0x11111111111111111111122222222222233333"]`,     // Too short
-		`["0x111111111111111111111222222222222333332"]`,    // Too short
-		`["0x11111111111111111111122222222222233333234"]`,  // Too long
-		`["0x111111111111111111111222222222222333332344"]`, // Too long
-		`["1111111111111111111112222222222223333323"]`,     // Missing 0x
-		`["x1111111111111111111112222222222223333323"]`,    // Missing 0
-		`["0xG111111111111111111112222222222223333323"]`,   //Non-hex
-	} {
-		if err := json.Unmarshal([]byte(r), &r2); err == nil {
-			t.Errorf("Expected failure, input %v", r)
-		}
-
-	}
-
-}
-
-func TestHash_Scan(t *testing.T) {
-	type args struct {
-		src interface{}
-	}
-	tests := []struct {
-		name    string
-		args    args
-		wantErr bool
-	}{
-		{
-			name: "working scan",
-			args: args{src: []byte{
-				0xb2, 0x6f, 0x2b, 0x34, 0x2a, 0xab, 0x24, 0xbc, 0xf6, 0x3e,
-				0xa2, 0x18, 0xc6, 0xa9, 0x27, 0x4d, 0x30, 0xab, 0x9a, 0x15,
-				0xa2, 0x18, 0xc6, 0xa9, 0x27, 0x4d, 0x30, 0xab, 0x9a, 0x15,
-				0x10, 0x00,
-			}},
-			wantErr: false,
-		},
-		{
-			name:    "non working scan",
-			args:    args{src: int64(1234567890)},
-			wantErr: true,
-		},
-		{
-			name: "invalid length scan",
-			args: args{src: []byte{
-				0xb2, 0x6f, 0x2b, 0x34, 0x2a, 0xab, 0x24, 0xbc, 0xf6, 0x3e,
-				0xa2, 0x18, 0xc6, 0xa9, 0x27, 0x4d, 0x30, 0xab, 0x9a, 0x15,
-				0xa2, 0x18, 0xc6, 0xa9, 0x27, 0x4d, 0x30, 0xab, 0x9a, 0x15,
-			}},
-			wantErr: true,
-		},
-	}
-	for _, tt := range tests {
-		t.Run(tt.name, func(t *testing.T) {
-			h := &Hash{}
-			if err := h.Scan(tt.args.src); (err != nil) != tt.wantErr {
-				t.Errorf("Hash.Scan() error = %v, wantErr %v", err, tt.wantErr)
-			}
-
-			if !tt.wantErr {
-				for i := range h {
-					if h[i] != tt.args.src.([]byte)[i] {
-						t.Errorf(
-							"Hash.Scan() didn't scan the %d src correctly (have %X, want %X)",
-							i, h[i], tt.args.src.([]byte)[i],
-						)
-					}
-				}
-			}
-		})
-	}
-}
-
-func TestHash_Value(t *testing.T) {
-	b := []byte{
-		0xb2, 0x6f, 0x2b, 0x34, 0x2a, 0xab, 0x24, 0xbc, 0xf6, 0x3e,
-		0xa2, 0x18, 0xc6, 0xa9, 0x27, 0x4d, 0x30, 0xab, 0x9a, 0x15,
-		0xa2, 0x18, 0xc6, 0xa9, 0x27, 0x4d, 0x30, 0xab, 0x9a, 0x15,
-		0x10, 0x00,
-	}
-	var usedH Hash
-	usedH.SetBytes(b)
-	tests := []struct {
-		name    string
-		h       Hash
-		want    driver.Value
-		wantErr bool
-	}{
-		{
-			name:    "Working value",
-			h:       usedH,
-			want:    b,
-			wantErr: false,
-		},
-	}
-	for _, tt := range tests {
-		t.Run(tt.name, func(t *testing.T) {
-			got, err := tt.h.Value()
-			if (err != nil) != tt.wantErr {
-				t.Errorf("Hash.Value() error = %v, wantErr %v", err, tt.wantErr)
-				return
-			}
-			if !reflect.DeepEqual(got, tt.want) {
-				t.Errorf("Hash.Value() = %v, want %v", got, tt.want)
-			}
-		})
-	}
-}
-
-func TestAddress_Scan(t *testing.T) {
-	type args struct {
-		src interface{}
-	}
-	tests := []struct {
-		name    string
-		args    args
-		wantErr bool
-	}{
-		{
-			name: "working scan",
-			args: args{src: []byte{
-				0xb2, 0x6f, 0x2b, 0x34, 0x2a, 0xab, 0x24, 0xbc, 0xf6, 0x3e,
-				0xa2, 0x18, 0xc6, 0xa9, 0x27, 0x4d, 0x30, 0xab, 0x9a, 0x15,
-			}},
-			wantErr: false,
-		},
-		{
-			name:    "non working scan",
-			args:    args{src: int64(1234567890)},
-			wantErr: true,
-		},
-		{
-			name: "invalid length scan",
-			args: args{src: []byte{
-				0xb2, 0x6f, 0x2b, 0x34, 0x2a, 0xab, 0x24, 0xbc, 0xf6, 0x3e,
-				0xa2, 0x18, 0xc6, 0xa9, 0x27, 0x4d, 0x30, 0xab, 0x9a,
-			}},
-			wantErr: true,
-		},
-	}
-	for _, tt := range tests {
-		t.Run(tt.name, func(t *testing.T) {
-			a := &Address{}
-			if err := a.Scan(tt.args.src); (err != nil) != tt.wantErr {
-				t.Errorf("Address.Scan() error = %v, wantErr %v", err, tt.wantErr)
-			}
-
-			if !tt.wantErr {
-				for i := range a {
-					if a[i] != tt.args.src.([]byte)[i] {
-						t.Errorf(
-							"Address.Scan() didn't scan the %d src correctly (have %X, want %X)",
-							i, a[i], tt.args.src.([]byte)[i],
-						)
-					}
-				}
-			}
-		})
-	}
-}
-
-func TestAddress_Value(t *testing.T) {
-	b := []byte{
-		0xb2, 0x6f, 0x2b, 0x34, 0x2a, 0xab, 0x24, 0xbc, 0xf6, 0x3e,
-		0xa2, 0x18, 0xc6, 0xa9, 0x27, 0x4d, 0x30, 0xab, 0x9a, 0x15,
-	}
-	var usedA Address
-	usedA.SetBytes(b)
-	tests := []struct {
-		name    string
-		a       Address
-		want    driver.Value
-		wantErr bool
-	}{
-		{
-			name:    "Working value",
-			a:       usedA,
-			want:    b,
-			wantErr: false,
-		},
-	}
-	for _, tt := range tests {
-		t.Run(tt.name, func(t *testing.T) {
-			got, err := tt.a.Value()
-			if (err != nil) != tt.wantErr {
-				t.Errorf("Address.Value() error = %v, wantErr %v", err, tt.wantErr)
-				return
-			}
-			if !reflect.DeepEqual(got, tt.want) {
-				t.Errorf("Address.Value() = %v, want %v", got, tt.want)
-			}
-		})
-	}
-}
-
-func TestAddress_Format(t *testing.T) {
-	b := []byte{
-		0xb2, 0x6f, 0x2b, 0x34, 0x2a, 0xab, 0x24, 0xbc, 0xf6, 0x3e,
-		0xa2, 0x18, 0xc6, 0xa9, 0x27, 0x4d, 0x30, 0xab, 0x9a, 0x15,
-	}
-	var addr Address
-	addr.SetBytes(b)
-
-	tests := []struct {
-		name string
-		out  string
-		want string
-	}{
-		{
-			name: "println",
-			out:  fmt.Sprintln(addr),
-			want: "0xB26f2b342AAb24BCF63ea218c6A9274D30Ab9A15\n",
-		},
-		{
-			name: "print",
-			out:  fmt.Sprint(addr),
-			want: "0xB26f2b342AAb24BCF63ea218c6A9274D30Ab9A15",
-		},
-		{
-			name: "printf-s",
-			out: func() string {
-				buf := new(bytes.Buffer)
-				fmt.Fprintf(buf, "%s", addr)
-				return buf.String()
-			}(),
-			want: "0xB26f2b342AAb24BCF63ea218c6A9274D30Ab9A15",
-		},
-		{
-			name: "printf-q",
-			out:  fmt.Sprintf("%q", addr),
-			want: `"0xB26f2b342AAb24BCF63ea218c6A9274D30Ab9A15"`,
-		},
-		{
-			name: "printf-x",
-			out:  fmt.Sprintf("%x", addr),
-			want: "b26f2b342aab24bcf63ea218c6a9274d30ab9a15",
-		},
-		{
-			name: "printf-X",
-			out:  fmt.Sprintf("%X", addr),
-			want: "B26F2B342AAB24BCF63EA218C6A9274D30AB9A15",
-		},
-		{
-			name: "printf-#x",
-			out:  fmt.Sprintf("%#x", addr),
-			want: "0xb26f2b342aab24bcf63ea218c6a9274d30ab9a15",
-		},
-		{
-			name: "printf-v",
-			out:  fmt.Sprintf("%v", addr),
-			want: "0xB26f2b342AAb24BCF63ea218c6A9274D30Ab9A15",
-		},
-		// The original default formatter for byte slice
-		{
-			name: "printf-d",
-			out:  fmt.Sprintf("%d", addr),
-			want: "[178 111 43 52 42 171 36 188 246 62 162 24 198 169 39 77 48 171 154 21]",
-		},
-		// Invalid format char.
-		{
-			name: "printf-t",
-			out:  fmt.Sprintf("%t", addr),
-			want: "%!t(address=b26f2b342aab24bcf63ea218c6a9274d30ab9a15)",
-		},
-	}
-	for _, tt := range tests {
-		t.Run(tt.name, func(t *testing.T) {
-			if tt.out != tt.want {
-				t.Errorf("%s does not render as expected:\n got %s\nwant %s", tt.name, tt.out, tt.want)
-			}
-		})
-	}
-}
-
-func TestHash_Format(t *testing.T) {
-	var hash Hash
-	hash.SetBytes([]byte{
-		0xb2, 0x6f, 0x2b, 0x34, 0x2a, 0xab, 0x24, 0xbc, 0xf6, 0x3e,
-		0xa2, 0x18, 0xc6, 0xa9, 0x27, 0x4d, 0x30, 0xab, 0x9a, 0x15,
-		0xa2, 0x18, 0xc6, 0xa9, 0x27, 0x4d, 0x30, 0xab, 0x9a, 0x15,
-		0x10, 0x00,
-	})
-
-	tests := []struct {
-		name string
-		out  string
-		want string
-	}{
-		{
-			name: "println",
-			out:  fmt.Sprintln(hash),
-			want: "0xb26f2b342aab24bcf63ea218c6a9274d30ab9a15a218c6a9274d30ab9a151000\n",
-		},
-		{
-			name: "print",
-			out:  fmt.Sprint(hash),
-			want: "0xb26f2b342aab24bcf63ea218c6a9274d30ab9a15a218c6a9274d30ab9a151000",
-		},
-		{
-			name: "printf-s",
-			out: func() string {
-				buf := new(bytes.Buffer)
-				fmt.Fprintf(buf, "%s", hash)
-				return buf.String()
-			}(),
-			want: "0xb26f2b342aab24bcf63ea218c6a9274d30ab9a15a218c6a9274d30ab9a151000",
-		},
-		{
-			name: "printf-q",
-			out:  fmt.Sprintf("%q", hash),
-			want: `"0xb26f2b342aab24bcf63ea218c6a9274d30ab9a15a218c6a9274d30ab9a151000"`,
-		},
-		{
-			name: "printf-x",
-			out:  fmt.Sprintf("%x", hash),
-			want: "b26f2b342aab24bcf63ea218c6a9274d30ab9a15a218c6a9274d30ab9a151000",
-		},
-		{
-			name: "printf-X",
-			out:  fmt.Sprintf("%X", hash),
-			want: "B26F2B342AAB24BCF63EA218C6A9274D30AB9A15A218C6A9274D30AB9A151000",
-		},
-		{
-			name: "printf-#x",
-			out:  fmt.Sprintf("%#x", hash),
-			want: "0xb26f2b342aab24bcf63ea218c6a9274d30ab9a15a218c6a9274d30ab9a151000",
-		},
-		{
-			name: "printf-#X",
-			out:  fmt.Sprintf("%#X", hash),
-			want: "0XB26F2B342AAB24BCF63EA218C6A9274D30AB9A15A218C6A9274D30AB9A151000",
-		},
-		{
-			name: "printf-v",
-			out:  fmt.Sprintf("%v", hash),
-			want: "0xb26f2b342aab24bcf63ea218c6a9274d30ab9a15a218c6a9274d30ab9a151000",
-		},
-		// The original default formatter for byte slice
-		{
-			name: "printf-d",
-			out:  fmt.Sprintf("%d", hash),
-			want: "[178 111 43 52 42 171 36 188 246 62 162 24 198 169 39 77 48 171 154 21 162 24 198 169 39 77 48 171 154 21 16 0]",
-		},
-		// Invalid format char.
-		{
-			name: "printf-t",
-			out:  fmt.Sprintf("%t", hash),
-			want: "%!t(hash=b26f2b342aab24bcf63ea218c6a9274d30ab9a15a218c6a9274d30ab9a151000)",
-		},
-	}
-	for _, tt := range tests {
-		t.Run(tt.name, func(t *testing.T) {
-			if tt.out != tt.want {
-				t.Errorf("%s does not render as expected:\n got %s\nwant %s", tt.name, tt.out, tt.want)
-			}
-		})
-	}
-}

+ 0 - 26
log/async_file_writer_test.go

@@ -1,26 +0,0 @@
-package log
-
-import (
-	"io/ioutil"
-	"os"
-	"strings"
-	"testing"
-)
-
-func TestWriter(t *testing.T) {
-	w := NewAsyncFileWriter("./hello.log", 100)
-	w.Start()
-	w.Write([]byte("hello\n"))
-	w.Write([]byte("world\n"))
-	w.Stop()
-	files, _ := ioutil.ReadDir("./")
-	for _, f := range files {
-		fn := f.Name()
-		if strings.HasPrefix(fn, "hello") {
-			t.Log(fn)
-			content, _ := ioutil.ReadFile(fn)
-			t.Log(content)
-			os.Remove(fn)
-		}
-	}
-}

+ 0 - 95
log/format_test.go

@@ -1,95 +0,0 @@
-package log
-
-import (
-	"math"
-	"math/big"
-	"math/rand"
-	"testing"
-)
-
-func TestPrettyInt64(t *testing.T) {
-	tests := []struct {
-		n int64
-		s string
-	}{
-		{0, "0"},
-		{10, "10"},
-		{-10, "-10"},
-		{100, "100"},
-		{-100, "-100"},
-		{1000, "1000"},
-		{-1000, "-1000"},
-		{10000, "10000"},
-		{-10000, "-10000"},
-		{99999, "99999"},
-		{-99999, "-99999"},
-		{100000, "100,000"},
-		{-100000, "-100,000"},
-		{1000000, "1,000,000"},
-		{-1000000, "-1,000,000"},
-		{math.MaxInt64, "9,223,372,036,854,775,807"},
-		{math.MinInt64, "-9,223,372,036,854,775,808"},
-	}
-	for i, tt := range tests {
-		if have := FormatLogfmtInt64(tt.n); have != tt.s {
-			t.Errorf("test %d: format mismatch: have %s, want %s", i, have, tt.s)
-		}
-	}
-}
-
-func TestPrettyUint64(t *testing.T) {
-	tests := []struct {
-		n uint64
-		s string
-	}{
-		{0, "0"},
-		{10, "10"},
-		{100, "100"},
-		{1000, "1000"},
-		{10000, "10000"},
-		{99999, "99999"},
-		{100000, "100,000"},
-		{1000000, "1,000,000"},
-		{math.MaxUint64, "18,446,744,073,709,551,615"},
-	}
-	for i, tt := range tests {
-		if have := FormatLogfmtUint64(tt.n); have != tt.s {
-			t.Errorf("test %d: format mismatch: have %s, want %s", i, have, tt.s)
-		}
-	}
-}
-
-func TestPrettyBigInt(t *testing.T) {
-	tests := []struct {
-		int string
-		s   string
-	}{
-		{"111222333444555678999", "111,222,333,444,555,678,999"},
-		{"-111222333444555678999", "-111,222,333,444,555,678,999"},
-		{"11122233344455567899900", "11,122,233,344,455,567,899,900"},
-		{"-11122233344455567899900", "-11,122,233,344,455,567,899,900"},
-	}
-
-	for _, tt := range tests {
-		v, _ := new(big.Int).SetString(tt.int, 10)
-		if have := formatLogfmtBigInt(v); have != tt.s {
-			t.Errorf("invalid output %s, want %s", have, tt.s)
-		}
-	}
-}
-
-var sink string
-
-func BenchmarkPrettyInt64Logfmt(b *testing.B) {
-	b.ReportAllocs()
-	for i := 0; i < b.N; i++ {
-		sink = FormatLogfmtInt64(rand.Int63())
-	}
-}
-
-func BenchmarkPrettyUint64Logfmt(b *testing.B) {
-	b.ReportAllocs()
-	for i := 0; i < b.N; i++ {
-		sink = FormatLogfmtUint64(rand.Uint64())
-	}
-}