add varcheck

add vendorcheck
add goimports
add lint coverage on tests
example_test turned into actual test
add small check on np const to avoid lint varcheck err
update travis task to use lint
remove lint task contents from makefile
This commit is contained in:
Thomas Modeneis 2018-04-05 15:00:20 +02:00
parent c41a7cc5fa
commit 9671bfcaa0
5 changed files with 19 additions and 13 deletions

View file

@ -13,8 +13,7 @@ matrix:
- sudo chown root:$USER /etc/fuse.conf
- go run build/ci.go install
- go run build/ci.go test -coverage
- make install-linters
- make lint
- go run build/ci.go lint
# These are the latest Go versions.
- os: linux

View file

@ -38,15 +38,9 @@ test: all
build/env.sh go run build/ci.go test
lint: ## Run linters. Use make install-linters first.
vendorcheck ./...
gometalinter --disable-all -E vet -E goimports -E varcheck -E gofmt -E misspell -E goconst -E unconvert -E gosimple --deadline=10m --min-occurrences=6 --tests --vendor ./...
build/env.sh go run build/ci.go lint
install-linters: ## Install linters
go get -u github.com/FiloSottile/vendorcheck
go get -u github.com/alecthomas/gometalinter
gometalinter --vendored-linters --install
format: # Formats the code. Must have goimports installed (use make install-linters).
format: # Formats the code. Must have goimports installed
goimports -w -local github.com/ethereum/go-ethereum ./
clean:

View file

@ -324,12 +324,17 @@ func doLint(cmdline []string) {
}
// Get metalinter and install all supported linters
build.MustRun(goTool("get", "gopkg.in/alecthomas/gometalinter.v2"))
build.MustRun(goTool("get", "github.com/FiloSottile/vendorcheck"))
build.MustRunCommand(filepath.Join(GOBIN, "vendorcheck"), "./...")
build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v2"), "--install")
// Run fast linters batched together
configs := []string{
"--vendor",
"--disable-all",
"--enable=goimports",
"--enable=varcheck",
"--enable=vet",
"--enable=gofmt",
"--enable=misspell",
@ -340,7 +345,7 @@ func doLint(cmdline []string) {
// Run slow linters one by one
for _, linter := range []string{"unconvert", "gosimple"} {
configs = []string{"--vendor", "--deadline=10m", "--disable-all", "--enable=" + linter}
configs = []string{"--vendor", "--tests", "--deadline=10m", "--disable-all", "--enable=" + linter}
build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v2"), append(configs, packages...)...)
}
}

View file

@ -26,7 +26,7 @@ var P = bigFromBase10("218882428718392752222464057452572750886963111572978236626
var p2 = [4]uint64{0x3c208c16d87cfd47, 0x97816a916871ca8d, 0xb85045b68181585d, 0x30644e72e131a029}
// np is the negative inverse of p, mod 2^256.
//var np = [4]uint64{0x87d20782e4866389, 0x9ede7d651eca6ac9, 0xd8afcbd01833da80, 0xf57a22b791888c6b}
var np = [4]uint64{0x87d20782e4866389, 0x9ede7d651eca6ac9, 0xd8afcbd01833da80, 0xf57a22b791888c6b}
// rN1 is R^-1 where R = 2^256 mod p.
var rN1 = &gfP{0xed84884a014afa37, 0xeb2022850278edf8, 0xcf63e9cfb74492d9, 0x2e67157159e5c639}

View file

@ -6,9 +6,12 @@ package bn256
import (
"crypto/rand"
"testing"
"github.com/stretchr/testify/require"
)
func ExamplePair() {
func TestExamplePair(t *testing.T) {
// This implements the tripartite Diffie-Hellman algorithm from "A One
// Round Protocol for Tripartite Diffie-Hellman", A. Joux.
// http://www.springerlink.com/content/cddc57yyva0hburb/fulltext.pdf
@ -40,4 +43,9 @@ func ExamplePair() {
k3.ScalarMult(k3, c)
// k1, k2 and k3 will all be equal.
require.Equal(t, k1, k2)
require.Equal(t, k1, k3)
require.Equal(t, len(np), 4) //Avoid gometalinter varcheck err on np
}