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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/client"
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/client"
|
||||||
@ -30,7 +30,7 @@ func broadcast(conf *broadcastConfig) error {
|
|||||||
|
|
||||||
transactionsHex := conf.Transactions
|
transactionsHex := conf.Transactions
|
||||||
if conf.TransactionsFile != "" {
|
if conf.TransactionsFile != "" {
|
||||||
transactionHexBytes, err := ioutil.ReadFile(conf.TransactionsFile)
|
transactionHexBytes, err := os.ReadFile(conf.TransactionsFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Could not read hex from %s", conf.TransactionsFile)
|
return errors.Wrapf(err, "Could not read hex from %s", conf.TransactionsFile)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,13 +3,14 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/cmd/kaspawallet/libkaspawallet/serialization"
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/libkaspawallet/serialization"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/txscript"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/txscript"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"io/ioutil"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func parse(conf *parseConfig) error {
|
func parse(conf *parseConfig) error {
|
||||||
@ -22,7 +23,7 @@ func parse(conf *parseConfig) error {
|
|||||||
|
|
||||||
transactionHex := conf.Transaction
|
transactionHex := conf.Transaction
|
||||||
if conf.TransactionFile != "" {
|
if conf.TransactionFile != "" {
|
||||||
transactionHexBytes, err := ioutil.ReadFile(conf.TransactionFile)
|
transactionHexBytes, err := os.ReadFile(conf.TransactionFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Could not read hex from %s", conf.TransactionFile)
|
return errors.Wrapf(err, "Could not read hex from %s", conf.TransactionFile)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -34,7 +33,7 @@ func sign(conf *signConfig) error {
|
|||||||
|
|
||||||
transactionsHex := conf.Transaction
|
transactionsHex := conf.Transaction
|
||||||
if conf.TransactionFile != "" {
|
if conf.TransactionFile != "" {
|
||||||
transactionHexBytes, err := ioutil.ReadFile(conf.TransactionFile)
|
transactionHexBytes, err := os.ReadFile(conf.TransactionFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Could not read hex from %s", conf.TransactionFile)
|
return errors.Wrapf(err, "Could not read hex from %s", conf.TransactionFile)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package consensus
|
package consensus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -569,7 +568,7 @@ func (f *factory) NewTestConsensus(config *Config, testName string) (
|
|||||||
tc testapi.TestConsensus, teardown func(keepDataDir bool), err error) {
|
tc testapi.TestConsensus, teardown func(keepDataDir bool), err error) {
|
||||||
datadir := f.dataDir
|
datadir := f.dataDir
|
||||||
if datadir == "" {
|
if datadir == "" {
|
||||||
datadir, err = ioutil.TempDir("", testName)
|
datadir, err = os.MkdirTemp("", testName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package consensus
|
package consensus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/domain/prefixmanager/prefix"
|
"github.com/kaspanet/kaspad/domain/prefixmanager/prefix"
|
||||||
@ -15,7 +15,7 @@ func TestNewConsensus(t *testing.T) {
|
|||||||
|
|
||||||
config := &Config{Params: dagconfig.DevnetParams}
|
config := &Config{Params: dagconfig.DevnetParams}
|
||||||
|
|
||||||
tmpDir, err := ioutil.TempDir("", "TestNewConsensus")
|
tmpDir, err := os.MkdirTemp("", "TestNewConsensus")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"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 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/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"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
|
// TestScripts ensures all of the tests in script_tests.json execute with the
|
||||||
// expected results as defined in the test data.
|
// expected results as defined in the test data.
|
||||||
func TestScripts(t *testing.T) {
|
func TestScripts(t *testing.T) {
|
||||||
file, err := ioutil.ReadFile("data/script_tests.json")
|
file, err := os.ReadFile("data/script_tests.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("TestScripts: %v\n", err)
|
t.Fatalf("TestScripts: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/domain"
|
"github.com/kaspanet/kaspad/domain"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus"
|
"github.com/kaspanet/kaspad/domain/consensus"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model"
|
"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/consensus/utils/testutils"
|
||||||
"github.com/kaspanet/kaspad/domain/miningmanager/mempool"
|
"github.com/kaspanet/kaspad/domain/miningmanager/mempool"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/db/database/ldb"
|
"github.com/kaspanet/kaspad/infrastructure/db/database/ldb"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateStagingConsensus(t *testing.T) {
|
func TestCreateStagingConsensus(t *testing.T) {
|
||||||
testutils.ForAllNets(t, true, func(t *testing.T, consensusConfig *consensus.Config) {
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("ioutil.TempDir: %+v", err)
|
t.Fatalf("os.MkdirTemp: %+v", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dataDir)
|
defer os.RemoveAll(dataDir)
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -21,14 +20,14 @@ func TestCreateDefaultConfigFile(t *testing.T) {
|
|||||||
sampleConfigFile := filepath.Join(filepath.Dir(path), "sample-kaspad.conf")
|
sampleConfigFile := filepath.Join(filepath.Dir(path), "sample-kaspad.conf")
|
||||||
|
|
||||||
// Setup a temporary directory
|
// Setup a temporary directory
|
||||||
tmpDir, err := ioutil.TempDir("", "kaspad")
|
tmpDir, err := os.MkdirTemp("", "kaspad")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed creating a temporary directory: %v", err)
|
t.Fatalf("Failed creating a temporary directory: %v", err)
|
||||||
}
|
}
|
||||||
testpath := filepath.Join(tmpDir, "test.conf")
|
testpath := filepath.Join(tmpDir, "test.conf")
|
||||||
|
|
||||||
// copy config file to location of kaspad binary
|
// copy config file to location of kaspad binary
|
||||||
data, err := ioutil.ReadFile(sampleConfigFile)
|
data, err := os.ReadFile(sampleConfigFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed reading sample config file: %v", err)
|
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)
|
t.Fatalf("Failed obtaining app path: %v", err)
|
||||||
}
|
}
|
||||||
tmpConfigFile := filepath.Join(appPath, "sample-kaspad.conf")
|
tmpConfigFile := filepath.Join(appPath, "sample-kaspad.conf")
|
||||||
err = ioutil.WriteFile(tmpConfigFile, data, 0644)
|
err = os.WriteFile(tmpConfigFile, data, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed copying sample config file: %v", err)
|
t.Fatalf("Failed copying sample config file: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ package database_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/db/database"
|
"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()) {
|
func prepareLDBForTest(t *testing.T, testName string) (db database.Database, name string, teardownFunc func()) {
|
||||||
// Create a temp db to run tests against
|
// Create a temp db to run tests against
|
||||||
path, err := ioutil.TempDir("", testName)
|
path, err := os.MkdirTemp("", testName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s: TempDir unexpectedly "+
|
t.Fatalf("%s: TempDir unexpectedly "+
|
||||||
"failed: %s", testName, err)
|
"failed: %s", testName, err)
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package ldb
|
package ldb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
func prepareDatabaseForTest(t *testing.T, testName string) (ldb *LevelDB, teardownFunc func()) {
|
func prepareDatabaseForTest(t *testing.T, testName string) (ldb *LevelDB, teardownFunc func()) {
|
||||||
// Create a temp db to run tests against
|
// Create a temp db to run tests against
|
||||||
path, err := ioutil.TempDir("", testName)
|
path, err := os.MkdirTemp("", testName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s: TempDir unexpectedly "+
|
t.Fatalf("%s: TempDir unexpectedly "+
|
||||||
"failed: %s", testName, err)
|
"failed: %s", testName, err)
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import "io/ioutil"
|
import "os"
|
||||||
|
|
||||||
// TempDir returns a temporary directory with the given pattern, prefixed with STABILITY_TEMP_DIR_
|
// TempDir returns a temporary directory with the given pattern, prefixed with STABILITY_TEMP_DIR_
|
||||||
func TempDir(pattern string) (string, error) {
|
func TempDir(pattern string) (string, error) {
|
||||||
const prefix = "STABILITY_TEMP_DIR_"
|
const prefix = "STABILITY_TEMP_DIR_"
|
||||||
return ioutil.TempDir("", prefix+pattern)
|
return os.MkdirTemp("", prefix+pattern)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
package fast_pruning_ibd_test
|
package fast_pruning_ibd_test
|
||||||
|
|
||||||
import (
|
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"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"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
|
// 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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ func commonConfig() *config.Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func randomDirectory(t *testing.T) string {
|
func randomDirectory(t *testing.T) string {
|
||||||
dir, err := ioutil.TempDir("", "integration-test")
|
dir, err := os.MkdirTemp("", "integration-test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error creating temporary directory for test: %+v", err)
|
t.Fatalf("Error creating temporary directory for test: %+v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user