mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-28 08:11:08 +00:00
Fixing deprecated ioutils functions
This commit is contained in:
parent
92574e623f
commit
4822fe89d7
@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/client"
|
||||
@ -30,7 +30,7 @@ func broadcast(conf *broadcastConfig) error {
|
||||
|
||||
transactionsHex := conf.Transactions
|
||||
if conf.TransactionsFile != "" {
|
||||
transactionHexBytes, err := ioutil.ReadFile(conf.TransactionsFile)
|
||||
transactionHexBytes, err := os.ReadFile(conf.TransactionsFile)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Could not read hex from %s", conf.TransactionsFile)
|
||||
}
|
||||
|
||||
@ -3,13 +3,14 @@ package main
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/kaspanet/kaspad/cmd/kaspawallet/libkaspawallet/serialization"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/utils/txscript"
|
||||
"github.com/pkg/errors"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func parse(conf *parseConfig) error {
|
||||
@ -22,7 +23,7 @@ func parse(conf *parseConfig) error {
|
||||
|
||||
transactionHex := conf.Transaction
|
||||
if conf.TransactionFile != "" {
|
||||
transactionHexBytes, err := ioutil.ReadFile(conf.TransactionFile)
|
||||
transactionHexBytes, err := os.ReadFile(conf.TransactionFile)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Could not read hex from %s", conf.TransactionFile)
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@ -34,7 +33,7 @@ func sign(conf *signConfig) error {
|
||||
|
||||
transactionsHex := conf.Transaction
|
||||
if conf.TransactionFile != "" {
|
||||
transactionHexBytes, err := ioutil.ReadFile(conf.TransactionFile)
|
||||
transactionHexBytes, err := os.ReadFile(conf.TransactionFile)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Could not read hex from %s", conf.TransactionFile)
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package consensus
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
@ -569,7 +568,7 @@ func (f *factory) NewTestConsensus(config *Config, testName string) (
|
||||
tc testapi.TestConsensus, teardown func(keepDataDir bool), err error) {
|
||||
datadir := f.dataDir
|
||||
if datadir == "" {
|
||||
datadir, err = ioutil.TempDir("", testName)
|
||||
datadir, err = os.MkdirTemp("", testName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package consensus
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/kaspanet/kaspad/domain/prefixmanager/prefix"
|
||||
@ -15,7 +15,7 @@ func TestNewConsensus(t *testing.T) {
|
||||
|
||||
config := &Config{Params: dagconfig.DevnetParams}
|
||||
|
||||
tmpDir, err := ioutil.TempDir("", "TestNewConsensus")
|
||||
tmpDir, err := os.MkdirTemp("", "TestNewConsensus")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
@ -79,5 +79,5 @@ func renderDotScript(dotScript string, filename string) error {
|
||||
return fmt.Errorf("Error getting output of dot: %s\nstderr:\n%s", err, stderr.String())
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(filename, svg, 0600)
|
||||
return os.WriteFile(filename, svg, 0600)
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -380,7 +380,7 @@ func testScripts(t *testing.T, tests [][]interface{}, useSigCache bool) {
|
||||
// TestScripts ensures all of the tests in script_tests.json execute with the
|
||||
// expected results as defined in the test data.
|
||||
func TestScripts(t *testing.T) {
|
||||
file, err := ioutil.ReadFile("data/script_tests.json")
|
||||
file, err := os.ReadFile("data/script_tests.json")
|
||||
if err != nil {
|
||||
t.Fatalf("TestScripts: %v\n", err)
|
||||
}
|
||||
|
||||
@ -4,6 +4,10 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/kaspanet/kaspad/domain"
|
||||
"github.com/kaspanet/kaspad/domain/consensus"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/model"
|
||||
@ -12,17 +16,13 @@ import (
|
||||
"github.com/kaspanet/kaspad/domain/consensus/utils/testutils"
|
||||
"github.com/kaspanet/kaspad/domain/miningmanager/mempool"
|
||||
"github.com/kaspanet/kaspad/infrastructure/db/database/ldb"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCreateStagingConsensus(t *testing.T) {
|
||||
testutils.ForAllNets(t, true, func(t *testing.T, consensusConfig *consensus.Config) {
|
||||
dataDir, err := ioutil.TempDir("", fmt.Sprintf("TestCreateStagingConsensus-%s", consensusConfig.Name))
|
||||
dataDir, err := os.MkdirTemp("", fmt.Sprintf("TestCreateStagingConsensus-%s", consensusConfig.Name))
|
||||
if err != nil {
|
||||
t.Fatalf("ioutil.TempDir: %+v", err)
|
||||
t.Fatalf("os.MkdirTemp: %+v", err)
|
||||
}
|
||||
defer os.RemoveAll(dataDir)
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@ -21,14 +20,14 @@ func TestCreateDefaultConfigFile(t *testing.T) {
|
||||
sampleConfigFile := filepath.Join(filepath.Dir(path), "sample-kaspad.conf")
|
||||
|
||||
// Setup a temporary directory
|
||||
tmpDir, err := ioutil.TempDir("", "kaspad")
|
||||
tmpDir, err := os.MkdirTemp("", "kaspad")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed creating a temporary directory: %v", err)
|
||||
}
|
||||
testpath := filepath.Join(tmpDir, "test.conf")
|
||||
|
||||
// copy config file to location of kaspad binary
|
||||
data, err := ioutil.ReadFile(sampleConfigFile)
|
||||
data, err := os.ReadFile(sampleConfigFile)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed reading sample config file: %v", err)
|
||||
}
|
||||
@ -37,7 +36,7 @@ func TestCreateDefaultConfigFile(t *testing.T) {
|
||||
t.Fatalf("Failed obtaining app path: %v", err)
|
||||
}
|
||||
tmpConfigFile := filepath.Join(appPath, "sample-kaspad.conf")
|
||||
err = ioutil.WriteFile(tmpConfigFile, data, 0644)
|
||||
err = os.WriteFile(tmpConfigFile, data, 0644)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed copying sample config file: %v", err)
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ package database_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/kaspanet/kaspad/infrastructure/db/database"
|
||||
@ -20,7 +20,7 @@ var databasePrepareFuncs = []databasePrepareFunc{
|
||||
|
||||
func prepareLDBForTest(t *testing.T, testName string) (db database.Database, name string, teardownFunc func()) {
|
||||
// Create a temp db to run tests against
|
||||
path, err := ioutil.TempDir("", testName)
|
||||
path, err := os.MkdirTemp("", testName)
|
||||
if err != nil {
|
||||
t.Fatalf("%s: TempDir unexpectedly "+
|
||||
"failed: %s", testName, err)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package ldb
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
|
||||
func prepareDatabaseForTest(t *testing.T, testName string) (ldb *LevelDB, teardownFunc func()) {
|
||||
// Create a temp db to run tests against
|
||||
path, err := ioutil.TempDir("", testName)
|
||||
path, err := os.MkdirTemp("", testName)
|
||||
if err != nil {
|
||||
t.Fatalf("%s: TempDir unexpectedly "+
|
||||
"failed: %s", testName, err)
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package common
|
||||
|
||||
import "io/ioutil"
|
||||
import "os"
|
||||
|
||||
// TempDir returns a temporary directory with the given pattern, prefixed with STABILITY_TEMP_DIR_
|
||||
func TempDir(pattern string) (string, error) {
|
||||
const prefix = "STABILITY_TEMP_DIR_"
|
||||
return ioutil.TempDir("", prefix+pattern)
|
||||
return os.MkdirTemp("", prefix+pattern)
|
||||
}
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
package fast_pruning_ibd_test
|
||||
|
||||
import (
|
||||
"github.com/kaspanet/kaspad/domain/consensus"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/utils/testutils"
|
||||
"github.com/kaspanet/kaspad/domain/dagconfig"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/kaspanet/kaspad/domain/consensus"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/utils/testutils"
|
||||
"github.com/kaspanet/kaspad/domain/dagconfig"
|
||||
)
|
||||
|
||||
// TestGenerateFastPruningIBDTest generates the json needed for dag-for-fast-pruning-ibd-test.json.gz
|
||||
@ -130,7 +130,7 @@ func TestGenerateFastPruningIBDTest(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
file, err := ioutil.TempFile("", "")
|
||||
file, err := os.CreateTemp("", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -63,7 +63,7 @@ func commonConfig() *config.Config {
|
||||
}
|
||||
|
||||
func randomDirectory(t *testing.T) string {
|
||||
dir, err := ioutil.TempDir("", "integration-test")
|
||||
dir, err := os.MkdirTemp("", "integration-test")
|
||||
if err != nil {
|
||||
t.Fatalf("Error creating temporary directory for test: %+v", err)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user