Skip to content

Commit

Permalink
wormchain: change ioutil to io and os (wormhole-foundation#3970)
Browse files Browse the repository at this point in the history
* ioutil to io and os

* io to os
  • Loading branch information
charltonliv authored and bruce-riley committed Jul 30, 2024
1 parent b90ea59 commit f4001a8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
14 changes: 8 additions & 6 deletions near/test/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ package main
import (
"bytes"
"fmt"

"github.com/tidwall/gjson"

// "encoding/base64"
"io/ioutil"
"io"
"net/http"
"strings"
"time"
Expand All @@ -27,7 +29,7 @@ func getTxStatus(tx string, src string) ([]byte, error) {
}

defer resp.Body.Close()
return ioutil.ReadAll(resp.Body)
return io.ReadAll(resp.Body)
}

func getBlock(block uint64) ([]byte, error) {
Expand All @@ -39,7 +41,7 @@ func getBlock(block uint64) ([]byte, error) {
}

defer resp.Body.Close()
return ioutil.ReadAll(resp.Body)
return io.ReadAll(resp.Body)
}

func getFinalBlock() ([]byte, error) {
Expand All @@ -51,7 +53,7 @@ func getFinalBlock() ([]byte, error) {
}

defer resp.Body.Close()
return ioutil.ReadAll(resp.Body)
return io.ReadAll(resp.Body)
}

func getChunk(chunk string) ([]byte, error) {
Expand All @@ -64,7 +66,7 @@ func getChunk(chunk string) ([]byte, error) {
}

defer resp.Body.Close()
return ioutil.ReadAll(resp.Body)
return io.ReadAll(resp.Body)
}

func inspectBody(block uint64, body gjson.Result) error {
Expand Down Expand Up @@ -121,7 +123,7 @@ func inspectBody(block uint64, body gjson.Result) error {
if !strings.HasPrefix(event, "EVENT_JSON:") {
continue
}
// event_json := gjson.ParseBytes(event[11:])
//event_json := gjson.ParseBytes(event[11:])
fmt.Printf("log: %s\n", event[11:])
}
}
Expand Down
8 changes: 5 additions & 3 deletions node/pkg/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func waitForStatusServer(ctx context.Context, logger *zap.Logger, statusAddr str
func TestMain(m *testing.M) {
logger, _ = zap.NewDevelopment()
readiness.NoPanic = true // otherwise we'd panic when running multiple guardians
retVal := m.Run()
retVal := m.Run() // Routine 2393 started here.
logger.Info("test exiting", zap.Int("retVal", retVal))
os.Exit(retVal)
}
Expand Down Expand Up @@ -903,7 +903,7 @@ func TestWatcherConfigs(t *testing.T) {
err: "L1finalizer does not exist. Please check the order of the watcher configurations in watcherConfigs.",
},
}
runGuardianConfigTests(t, tc)
runGuardianConfigTests(t, tc) // These are the tests that have the data races. Some generate fatal errors.
}

func TestGuardianConfigs(t *testing.T) {
Expand Down Expand Up @@ -939,6 +939,7 @@ func runGuardianConfigTests(t *testing.T, testCases []testCaseGuardianConfig) {
// because we're only instantiating the guardians and kill them right after they started running, 2s should be plenty of time
const testTimeout = time.Second * 2

// func() {
// Test's main lifecycle context.
rootCtx, rootCtxCancel := context.WithTimeout(context.Background(), testTimeout)
defer rootCtxCancel()
Expand All @@ -951,7 +952,7 @@ func runGuardianConfigTests(t *testing.T, testCases []testCaseGuardianConfig) {
defer close(fatalHook)
zapLogger, zapObserver, _ := setupLogsCapture(t, zap.WithFatalHook(fatalHook))

supervisor.New(rootCtx, zapLogger, func(ctx context.Context) error {
supervisor.New(rootCtx, zapLogger, func(ctx context.Context) error { // Routine 2620 started here.
// Create a sub-context with cancel function that we can pass to G.run.
ctx, ctxCancel := context.WithCancel(ctx)
defer ctxCancel()
Expand Down Expand Up @@ -987,6 +988,7 @@ func runGuardianConfigTests(t *testing.T, testCases []testCaseGuardianConfig) {
assert.NotEqual(t, rootCtx.Err(), context.DeadlineExceeded)
assert.Equal(t, tc.err, "") // we only want to end up here if we did not expect an error.
}
// }()
}
}

Expand Down
7 changes: 2 additions & 5 deletions wormchain/testutil/keeper/wormhole.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package keeper

import (
"io/ioutil"
"os"
"testing"
"time"

Expand Down Expand Up @@ -97,10 +97,7 @@ func WormholeKeeperAndWasmd(t testing.TB) (*keeper.Keeper, wasmkeeper.Keeper, *w
appapp.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey])
scopedWasmKeeper := appapp.CapabilityKeeper.ScopeToModule(wasm.ModuleName)

wasmDir, err := ioutil.TempDir("", "")
if err != nil {
panic(err)
}
wasmDir := os.TempDir()
wasmKeeper := wasm.NewKeeper(
appCodec,
keys[wasmtypes.StoreKey],
Expand Down
9 changes: 4 additions & 5 deletions wormchain/x/wormhole/client/cli/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/binary"
"encoding/hex"
"fmt"
"io/ioutil"
"math/big"
"os"
"strings"
Expand Down Expand Up @@ -79,11 +78,11 @@ func CmdGenerateTestGuardianKey() *cobra.Command {
private_key := [32]byte{}
key.D.FillBytes(private_key[:])

err = ioutil.WriteFile(outPrivatePath, []byte(hex.EncodeToString(private_key[:])), 0644)
err = os.WriteFile(outPrivatePath, []byte(hex.EncodeToString(private_key[:])), 0644)
if err != nil {
return err
}
ioutil.WriteFile(outPublicPath, []byte(hex.EncodeToString(addr.Bytes())), 0644)
os.WriteFile(outPublicPath, []byte(hex.EncodeToString(addr.Bytes())), 0644)
if err != nil {
return err
}
Expand Down Expand Up @@ -131,15 +130,15 @@ func CmdDecodeAddress() *cobra.Command {

func ImportKeyFromFile(filePath string) (*ecdsa.PrivateKey, error) {
priv := ecdsa.PrivateKey{}
bz, err := ioutil.ReadFile(filePath)
bz, err := os.ReadFile(filePath)
if err != nil {
return &priv, err
}
return ImportKeyFromHex(string(bz))
}

func ImportPublicKeyFromFile(filePath string) ([]byte, error) {
hexBz, err := ioutil.ReadFile(filePath)
hexBz, err := os.ReadFile(filePath)
if err != nil {
return []byte{}, err
}
Expand Down
4 changes: 2 additions & 2 deletions wormchain/x/wormhole/client/cli/tx_wasmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cli

import (
"fmt"
"io/ioutil"
"os"
"strconv"

"encoding/hex"
Expand All @@ -22,7 +22,7 @@ import (
var _ = strconv.Itoa(0)

func parseStoreCodeArgs(file string, sender sdk.AccAddress, vaa []byte) (types.MsgStoreCode, error) {
wasm, err := ioutil.ReadFile(file)
wasm, err := os.ReadFile(file)
if err != nil {
return types.MsgStoreCode{}, err
}
Expand Down

0 comments on commit f4001a8

Please sign in to comment.