예제 #1
0
파일: cmd.go 프로젝트: este-xx/go-expanse
func CheckLegalese(datadir string) {
	// check "first run"
	if !common.FileExist(datadir) {
		r, _ := PromptConfirm(legalese)
		if !r {
			Fatalf("Must accept to continue. Shutting down...\n")
		}
	}
}
예제 #2
0
func newDb() *LDBDatabase {
	file := filepath.Join("/", "tmp", "ldbtesttmpfile")
	if common.FileExist(file) {
		os.RemoveAll(file)
	}
	db, _ := NewLDBDatabase(file, 0)

	return db
}
예제 #3
0
// Tests that packages generated by the binder can be successfully compiled and
// the requested tester run against it.
func TestBindings(t *testing.T) {
	// Skip the test if no Go command can be found
	gocmd := runtime.GOROOT() + "/bin/go"
	if !common.FileExist(gocmd) {
		t.Skip("go sdk not found for testing")
	}
	// Skip the test if the go-ethereum sources are symlinked (https://github.com/golang/go/issues/14845)
	linkTestCode := fmt.Sprintf("package linktest\nfunc CheckSymlinks(){\nfmt.Println(backends.NewNilBackend())\n}")
	linkTestDeps, err := imports.Process("", []byte(linkTestCode), nil)
	if err != nil {
		t.Fatalf("failed check for goimports symlink bug: %v", err)
	}
	if !strings.Contains(string(linkTestDeps), "go-ethereum") {
		t.Skip("symlinked environment doesn't support bind (https://github.com/golang/go/issues/14845)")
	}
	// Create a temporary workspace for the test suite
	ws, err := ioutil.TempDir("", "")
	if err != nil {
		t.Fatalf("failed to create temporary workspace: %v", err)
	}
	defer os.RemoveAll(ws)

	pkg := filepath.Join(ws, "bindtest")
	if err = os.MkdirAll(pkg, 0700); err != nil {
		t.Fatalf("failed to create package: %v", err)
	}
	// Generate the test suite for all the contracts
	for i, tt := range bindTests {
		// Generate the binding and create a Go source file in the workspace
		bind, err := Bind([]string{tt.name}, []string{tt.abi}, []string{tt.bytecode}, "bindtest")
		if err != nil {
			t.Fatalf("test %d: failed to generate binding: %v", i, err)
		}
		if err = ioutil.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+".go"), []byte(bind), 0600); err != nil {
			t.Fatalf("test %d: failed to write binding: %v", i, err)
		}
		// Generate the test file with the injected test code
		code := fmt.Sprintf("package bindtest\nimport \"testing\"\nfunc Test%s(t *testing.T){\n%s\n}", tt.name, tt.tester)
		blob, err := imports.Process("", []byte(code), nil)
		if err != nil {
			t.Fatalf("test %d: failed to generate tests: %v", i, err)
		}
		if err := ioutil.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+"_test.go"), blob, 0600); err != nil {
			t.Fatalf("test %d: failed to write tests: %v", i, err)
		}
	}
	// Test the entire package and report any failures
	cmd := exec.Command(gocmd, "test", "-v")
	cmd.Dir = pkg
	if out, err := cmd.CombinedOutput(); err != nil {
		t.Fatalf("failed to run binding test: %v\n%s", err, out)
	}
}