Merge branch main into feature/abci++ppp

This commit is contained in:
Sergio Mena
2022-08-12 13:59:19 +02:00
517 changed files with 61641 additions and 20688 deletions
+5 -6
View File
@@ -1,7 +1,6 @@
package autofile
import (
"io/ioutil"
"os"
"path/filepath"
"syscall"
@@ -24,7 +23,7 @@ func TestSIGHUP(t *testing.T) {
})
// First, create a temporary directory and move into it
dir, err := ioutil.TempDir("", "sighup_test")
dir, err := os.MkdirTemp("", "sighup_test")
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(dir)
@@ -49,7 +48,7 @@ func TestSIGHUP(t *testing.T) {
require.NoError(t, err)
// Move into a different temporary directory
otherDir, err := ioutil.TempDir("", "sighup_test_other")
otherDir, err := os.MkdirTemp("", "sighup_test_other")
require.NoError(t, err)
defer os.RemoveAll(otherDir)
err = os.Chdir(otherDir)
@@ -79,7 +78,7 @@ func TestSIGHUP(t *testing.T) {
}
// The current directory should be empty
files, err := ioutil.ReadDir(".")
files, err := os.ReadDir(".")
require.NoError(t, err)
assert.Empty(t, files)
}
@@ -87,7 +86,7 @@ func TestSIGHUP(t *testing.T) {
// // Manually modify file permissions, close, and reopen using autofile:
// // We expect the file permissions to be changed back to the intended perms.
// func TestOpenAutoFilePerms(t *testing.T) {
// file, err := ioutil.TempFile("", "permission_test")
// file, err := os.CreateTemp("", "permission_test")
// require.NoError(t, err)
// err = file.Close()
// require.NoError(t, err)
@@ -113,7 +112,7 @@ func TestSIGHUP(t *testing.T) {
func TestAutoFileSize(t *testing.T) {
// First, create an AutoFile writing to a tempfile dir
f, err := ioutil.TempFile("", "sighup_test")
f, err := os.CreateTemp("", "sighup_test")
require.NoError(t, err)
err = f.Close()
require.NoError(t, err)
+4 -5
View File
@@ -2,7 +2,6 @@ package autofile
import (
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
@@ -122,7 +121,7 @@ func TestRotateFile(t *testing.T) {
}
}()
dir, err := ioutil.TempDir("", "rotate_test")
dir, err := os.MkdirTemp("", "rotate_test")
require.NoError(t, err)
defer os.RemoveAll(dir)
err = os.Chdir(dir)
@@ -151,21 +150,21 @@ func TestRotateFile(t *testing.T) {
require.NoError(t, err)
// Read g.Head.Path+"000"
body1, err := ioutil.ReadFile(g.Head.Path + ".000")
body1, err := os.ReadFile(g.Head.Path + ".000")
assert.NoError(t, err, "Failed to read first rolled file")
if string(body1) != "Line 1\nLine 2\nLine 3\n" {
t.Errorf("got unexpected contents: [%v]", string(body1))
}
// Read g.Head.Path
body2, err := ioutil.ReadFile(g.Head.Path)
body2, err := os.ReadFile(g.Head.Path)
assert.NoError(t, err, "Failed to read first rolled file")
if string(body2) != "Line 4\nLine 5\nLine 6\n" {
t.Errorf("got unexpected contents: [%v]", string(body2))
}
// Make sure there are no files in the current, temporary directory
files, err := ioutil.ReadDir(".")
files, err := os.ReadDir(".")
require.NoError(t, err)
assert.Empty(t, files)
+1 -2
View File
@@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
@@ -19,7 +18,7 @@ func WriteConfigVals(dir string, vals map[string]string) error {
data += fmt.Sprintf("%s = \"%s\"\n", k, v)
}
cfile := filepath.Join(dir, "config.toml")
return ioutil.WriteFile(cfile, []byte(data), 0600)
return os.WriteFile(cfile, []byte(data), 0600)
}
// RunWithArgs executes the given command with the specified command line args
+2 -2
View File
@@ -2,7 +2,7 @@ package cli
import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
"testing"
@@ -55,7 +55,7 @@ func TestSetupEnv(t *testing.T) {
}
func tempDir() string {
cdir, err := ioutil.TempDir("", "test-cli")
cdir, err := os.MkdirTemp("", "test-cli")
if err != nil {
panic(err)
}
+3 -3
View File
@@ -2,7 +2,7 @@ package log_test
import (
"bytes"
"io/ioutil"
"io"
"strings"
"testing"
@@ -90,11 +90,11 @@ func TestError(t *testing.T) {
}
func BenchmarkTMLoggerSimple(b *testing.B) {
benchmarkRunner(b, log.NewTMLogger(ioutil.Discard), baseInfoMessage)
benchmarkRunner(b, log.NewTMLogger(io.Discard), baseInfoMessage)
}
func BenchmarkTMLoggerContextual(b *testing.B) {
benchmarkRunner(b, log.NewTMLogger(ioutil.Discard), withInfoMessage)
benchmarkRunner(b, log.NewTMLogger(io.Discard), withInfoMessage)
}
func benchmarkRunner(b *testing.B, logger log.Logger, f func(log.Logger)) {
+4 -4
View File
@@ -3,7 +3,7 @@ package log_test
import (
"bytes"
"errors"
"io/ioutil"
"io"
"math"
"regexp"
"testing"
@@ -62,16 +62,16 @@ func TestTMFmtLogger(t *testing.T) {
}
func BenchmarkTMFmtLoggerSimple(b *testing.B) {
benchmarkRunnerKitlog(b, log.NewTMFmtLogger(ioutil.Discard), baseMessage)
benchmarkRunnerKitlog(b, log.NewTMFmtLogger(io.Discard), baseMessage)
}
func BenchmarkTMFmtLoggerContextual(b *testing.B) {
benchmarkRunnerKitlog(b, log.NewTMFmtLogger(ioutil.Discard), withMessage)
benchmarkRunnerKitlog(b, log.NewTMFmtLogger(io.Discard), withMessage)
}
func TestTMFmtLoggerConcurrency(t *testing.T) {
t.Parallel()
testConcurrency(t, log.NewTMFmtLogger(ioutil.Discard), 10000)
testConcurrency(t, log.NewTMFmtLogger(io.Discard), 10000)
}
func benchmarkRunnerKitlog(b *testing.B, logger kitlog.Logger, f func(kitlog.Logger)) {
+3 -4
View File
@@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/signal"
"syscall"
@@ -62,11 +61,11 @@ func FileExists(filePath string) bool {
}
func ReadFile(filePath string) ([]byte, error) {
return ioutil.ReadFile(filePath)
return os.ReadFile(filePath)
}
func MustReadFile(filePath string) []byte {
fileBytes, err := ioutil.ReadFile(filePath)
fileBytes, err := os.ReadFile(filePath)
if err != nil {
Exit(fmt.Sprintf("MustReadFile failed: %v", err))
return nil
@@ -75,7 +74,7 @@ func MustReadFile(filePath string) []byte {
}
func WriteFile(filePath string, contents []byte, mode os.FileMode) error {
return ioutil.WriteFile(filePath, contents, mode)
return os.WriteFile(filePath, contents, mode)
}
func MustWriteFile(filePath string, contents []byte, mode os.FileMode) {
+8 -9
View File
@@ -3,7 +3,6 @@ package os
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
@@ -12,7 +11,7 @@ import (
)
func TestCopyFile(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "example")
tmpfile, err := os.CreateTemp("", "example")
if err != nil {
t.Fatal(err)
}
@@ -29,7 +28,7 @@ func TestCopyFile(t *testing.T) {
if _, err := os.Stat(copyfile); os.IsNotExist(err) {
t.Fatal("copy should exist")
}
data, err := ioutil.ReadFile(copyfile)
data, err := os.ReadFile(copyfile)
if err != nil {
t.Fatal(err)
}
@@ -40,7 +39,7 @@ func TestCopyFile(t *testing.T) {
}
func TestEnsureDir(t *testing.T) {
tmp, err := ioutil.TempDir("", "ensure-dir")
tmp, err := os.MkdirTemp("", "ensure-dir")
require.NoError(t, err)
defer os.RemoveAll(tmp)
@@ -54,7 +53,7 @@ func TestEnsureDir(t *testing.T) {
require.NoError(t, err)
// Should fail on file.
err = ioutil.WriteFile(filepath.Join(tmp, "file"), []byte{}, 0644)
err = os.WriteFile(filepath.Join(tmp, "file"), []byte{}, 0644)
require.NoError(t, err)
err = EnsureDir(filepath.Join(tmp, "file"), 0755)
require.Error(t, err)
@@ -76,7 +75,7 @@ func TestEnsureDir(t *testing.T) {
// the origin is positively a non-directory and that it is ready for copying.
// See https://github.com/tendermint/tendermint/issues/6427
func TestTrickedTruncation(t *testing.T) {
tmpDir, err := ioutil.TempDir(os.TempDir(), "pwn_truncate")
tmpDir, err := os.MkdirTemp(os.TempDir(), "pwn_truncate")
if err != nil {
t.Fatal(err)
}
@@ -84,12 +83,12 @@ func TestTrickedTruncation(t *testing.T) {
originalWALPath := filepath.Join(tmpDir, "wal")
originalWALContent := []byte("I AM BECOME DEATH, DESTROYER OF ALL WORLDS!")
if err := ioutil.WriteFile(originalWALPath, originalWALContent, 0755); err != nil {
if err := os.WriteFile(originalWALPath, originalWALContent, 0755); err != nil {
t.Fatal(err)
}
// 1. Sanity check.
readWAL, err := ioutil.ReadFile(originalWALPath)
readWAL, err := os.ReadFile(originalWALPath)
if err != nil {
t.Fatal(err)
}
@@ -104,7 +103,7 @@ func TestTrickedTruncation(t *testing.T) {
}
// 3. Check the WAL's content
reReadWAL, err := ioutil.ReadFile(originalWALPath)
reReadWAL, err := os.ReadFile(originalWALPath)
if err != nil {
t.Fatal(err)
}
+7
View File
@@ -0,0 +1,7 @@
# This is a temporary directory to hold the peg binary,
# to work around https://github.com/pointlander/peg/issues/129.
# Note that once we have a new version of peg fixing #129,
# we may still want to keep this .gitignore to prevent anyone
# from accidentally running "git add ." and including their built
# peg binary in a commit.
.bin/
+1 -5
View File
@@ -1,11 +1,7 @@
gen_query_parser:
go get -u -v github.com/pointlander/peg
peg -inline -switch query.peg
fuzzy_test:
go get -u -v github.com/dvyukov/go-fuzz/go-fuzz
go get -u -v github.com/dvyukov/go-fuzz/go-fuzz-build
go-fuzz-build github.com/tendermint/tendermint/libs/pubsub/query/fuzz_test
go-fuzz -bin=./fuzz_test-fuzz.zip -workdir=./fuzz_test/output
.PHONY: gen_query_parser fuzzy_test
.PHONY: fuzzy_test
+8 -1
View File
@@ -1,3 +1,10 @@
package query
//go:generate peg -inline -switch query.peg
// Normally I would use go run,
// but the "Code generated by" comment for peg includes the full arg0,
// which includes an unpredictable temporary directory,
// resulting in a nondeterminstic generated source file.
// Using go build is the workaround as detailed in https://github.com/pointlander/peg/issues/129.
//go:generate go build -o ./.bin/peg github.com/pointlander/peg
//go:generate ./.bin/peg -inline -switch query.peg
+5 -3
View File
@@ -39,7 +39,9 @@ type Condition struct {
// invalid.
func New(s string) (*Query, error) {
p := &QueryParser{Buffer: fmt.Sprintf(`"%s"`, s)}
p.Init()
if err := p.Init(); err != nil {
return nil, err
}
if err := p.Parse(); err != nil {
return nil, err
}
@@ -101,7 +103,7 @@ func (q *Query) Conditions() ([]Condition, error) {
buffer, begin, end := q.parser.Buffer, 0, 0
// tokens must be in the following order: tag ("tx.gas") -> operator ("=") -> operand ("7")
for token := range q.parser.Tokens() {
for _, token := range q.parser.Tokens() {
switch token.pegRule {
case rulePegText:
begin, end = int(token.begin), int(token.end)
@@ -213,7 +215,7 @@ func (q *Query) Matches(events map[string][]string) (bool, error) {
// tokens must be in the following order:
// tag ("tx.gas") -> operator ("=") -> operand ("7")
for token := range q.parser.Tokens() {
for _, token := range q.parser.Tokens() {
switch token.pegRule {
case rulePegText:
begin, end = int(token.begin), int(token.end)
File diff suppressed because it is too large Load Diff
+7 -8
View File
@@ -5,7 +5,6 @@ package tempfile
import (
"bytes"
"fmt"
"io/ioutil"
"os"
testing "testing"
@@ -21,13 +20,13 @@ func TestWriteFileAtomic(t *testing.T) {
perm os.FileMode = 0600
)
f, err := ioutil.TempFile("/tmp", "write-atomic-test-")
f, err := os.CreateTemp("/tmp", "write-atomic-test-")
if err != nil {
t.Fatal(err)
}
defer os.Remove(f.Name())
if err = ioutil.WriteFile(f.Name(), old, 0600); err != nil {
if err = os.WriteFile(f.Name(), old, 0600); err != nil {
t.Fatal(err)
}
@@ -35,7 +34,7 @@ func TestWriteFileAtomic(t *testing.T) {
t.Fatal(err)
}
rData, err := ioutil.ReadFile(f.Name())
rData, err := os.ReadFile(f.Name())
if err != nil {
t.Fatal(err)
}
@@ -80,11 +79,11 @@ func TestWriteFileAtomicDuplicateFile(t *testing.T) {
err = WriteFileAtomic(fileToWrite, []byte(expectedString), 0777)
require.NoError(t, err)
// Check that the first atomic file was untouched
firstAtomicFileBytes, err := ioutil.ReadFile(fname)
firstAtomicFileBytes, err := os.ReadFile(fname)
require.NoError(t, err, "Error reading first atomic file")
require.Equal(t, []byte(testString), firstAtomicFileBytes, "First atomic file was overwritten")
// Check that the resultant file is correct
resultantFileBytes, err := ioutil.ReadFile(fileToWrite)
resultantFileBytes, err := os.ReadFile(fileToWrite)
require.NoError(t, err, "Error reading resultant file")
require.Equal(t, []byte(expectedString), resultantFileBytes, "Written file had incorrect bytes")
@@ -131,14 +130,14 @@ func TestWriteFileAtomicManyDuplicates(t *testing.T) {
for i := 0; i < atomicWriteFileMaxNumConflicts+2; i++ {
fileRand := randWriteFileSuffix()
fname := "/tmp/" + atomicWriteFilePrefix + fileRand
firstAtomicFileBytes, err := ioutil.ReadFile(fname)
firstAtomicFileBytes, err := os.ReadFile(fname)
require.Nil(t, err, "Error reading first atomic file")
require.Equal(t, []byte(fmt.Sprintf(testString, i)), firstAtomicFileBytes,
"atomic write file %d was overwritten", i)
}
// Check that the resultant file is correct
resultantFileBytes, err := ioutil.ReadFile(fileToWrite)
resultantFileBytes, err := os.ReadFile(fileToWrite)
require.Nil(t, err, "Error reading resultant file")
require.Equal(t, []byte(expectedString), resultantFileBytes, "Written file had incorrect bytes")
}