Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove io/ioutil #934

Merged
merged 2 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benchmarks/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package benchmarks

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

Expand Down Expand Up @@ -119,7 +119,7 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo {
wasmApp.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: height, Time: time.Now()}})

// upload the code
cw20Code, err := ioutil.ReadFile("./testdata/cw20_base.wasm")
cw20Code, err := os.ReadFile("./testdata/cw20_base.wasm")
require.NoError(b, err)
storeMsg := wasmtypes.MsgStoreCode{
Sender: addr.String(),
Expand Down
7 changes: 3 additions & 4 deletions x/wasm/client/cli/genesis_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cli
import (
"context"
"encoding/json"
"io/ioutil"
"os"
"path"
"testing"
Expand Down Expand Up @@ -42,7 +41,7 @@ func TestGenesisStoreCodeCmd(t *testing.T) {
minimalWasmGenesis := types.GenesisState{
Params: types.DefaultParams(),
}
anyValidWasmFile, err := ioutil.TempFile(t.TempDir(), "wasm")
anyValidWasmFile, err := os.CreateTemp(t.TempDir(), "wasm")
require.NoError(t, err)
anyValidWasmFile.Write(wasmIdent)
require.NoError(t, anyValidWasmFile.Close())
Expand Down Expand Up @@ -109,7 +108,7 @@ func TestInstantiateContractCmd(t *testing.T) {
minimalWasmGenesis := types.GenesisState{
Params: types.DefaultParams(),
}
anyValidWasmFile, err := ioutil.TempFile(t.TempDir(), "wasm")
anyValidWasmFile, err := os.CreateTemp(t.TempDir(), "wasm")
require.NoError(t, err)
anyValidWasmFile.Write(wasmIdent)
require.NoError(t, anyValidWasmFile.Close())
Expand Down Expand Up @@ -368,7 +367,7 @@ func TestExecuteContractCmd(t *testing.T) {
minimalWasmGenesis := types.GenesisState{
Params: types.DefaultParams(),
}
anyValidWasmFile, err := ioutil.TempFile(t.TempDir(), "wasm")
anyValidWasmFile, err := os.CreateTemp(t.TempDir(), "wasm")
require.NoError(t, err)
anyValidWasmFile.Write(wasmIdent)
require.NoError(t, anyValidWasmFile.Close())
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"strconv"

wasmvm "github.com/CosmWasm/wasmvm"
Expand Down Expand Up @@ -174,7 +174,7 @@ func GetCmdQueryCode() *cobra.Command {
}

fmt.Printf("Downloading wasm code to %s\n", args[1])
return ioutil.WriteFile(args[1], res.Data, 0o600)
return os.WriteFile(args[1], res.Data, 0o600)
},
}
flags.AddQueryFlagsToCmd(cmd)
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cli
import (
"errors"
"fmt"
"io/ioutil"
"os"
"strconv"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -81,7 +81,7 @@ func StoreCodeCmd() *cobra.Command {
}

func parseStoreCodeArgs(file string, sender sdk.AccAddress, flags *flag.FlagSet) (types.MsgStoreCode, error) {
wasm, err := ioutil.ReadFile(file)
wasm, err := os.ReadFile(file)
if err != nil {
return types.MsgStoreCode{}, err
}
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/ibctesting/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"compress/gzip"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"

wasmd "github.com/CosmWasm/wasmd/app"
Expand Down Expand Up @@ -37,7 +37,7 @@ func (chain *TestChain) SeedNewContractInstance() sdk.AccAddress {
}

func (chain *TestChain) StoreCodeFile(filename string) types.MsgStoreCodeResponse {
wasmCode, err := ioutil.ReadFile(filename)
wasmCode, err := os.ReadFile(filename)
require.NoError(chain.t, err)
if strings.HasSuffix(filename, "wasm") { // compress for gas limit
var buf bytes.Buffer
Expand Down
6 changes: 3 additions & 3 deletions x/wasm/ioutils/ioutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"compress/gzip"
"errors"
"io"
"io/ioutil"
"os"
"strings"
"testing"

Expand All @@ -16,10 +16,10 @@ import (
)

func TestUncompress(t *testing.T) {
wasmRaw, err := ioutil.ReadFile("../keeper/testdata/hackatom.wasm")
wasmRaw, err := os.ReadFile("../keeper/testdata/hackatom.wasm")
require.NoError(t, err)

wasmGzipped, err := ioutil.ReadFile("../keeper/testdata/hackatom.wasm.gzip")
wasmGzipped, err := os.ReadFile("../keeper/testdata/hackatom.wasm.gzip")
require.NoError(t, err)

const maxSize = 400_000
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/ioutils/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package ioutils

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

"github.com/stretchr/testify/require"
)

func GetTestData() ([]byte, []byte, []byte, error) {
wasmCode, err := ioutil.ReadFile("../keeper/testdata/hackatom.wasm")
wasmCode, err := os.ReadFile("../keeper/testdata/hackatom.wasm")
if err != nil {
return nil, nil, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/keeper/bench_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package keeper

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

"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
Expand Down Expand Up @@ -89,7 +89,7 @@ func BenchmarkCompilation(b *testing.B) {
ctx, keepers := createTestInput(b, false, SupportedFeatures, wasmConfig, db)

// print out code size for comparisons
code, err := ioutil.ReadFile(spec.wasmFile)
code, err := os.ReadFile(spec.wasmFile)
require.NoError(b, err)
b.Logf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b(size: %d) ", len(code))

Expand Down
11 changes: 5 additions & 6 deletions x/wasm/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/base64"
"errors"
"fmt"
"io/ioutil"
"math/rand"
"os"
"testing"
Expand Down Expand Up @@ -40,7 +39,7 @@ func TestGenesisExportImport(t *testing.T) {
wasmKeeper, srcCtx, srcStoreKeys := setupKeeper(t)
contractKeeper := NewGovPermissionKeeper(wasmKeeper)

wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)

// store some test data
Expand Down Expand Up @@ -153,7 +152,7 @@ func TestGenesisExportImport(t *testing.T) {
}

func TestGenesisInit(t *testing.T) {
wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)

myCodeInfo := wasmTypes.CodeInfoFixture(wasmTypes.WithSHA256CodeHash(wasmCode))
Expand Down Expand Up @@ -498,7 +497,7 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) {
keeper, ctx, _ := setupKeeper(t)
contractKeeper := NewGovPermissionKeeper(keeper)

wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)

wasmCodeHash := sha256.Sum256(wasmCode)
Expand Down Expand Up @@ -564,7 +563,7 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) {
}

func TestSupportedGenMsgTypes(t *testing.T) {
wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)
var (
myAddress sdk.AccAddress = bytes.Repeat([]byte{1}, types.ContractAddrLen)
Expand Down Expand Up @@ -636,7 +635,7 @@ func TestSupportedGenMsgTypes(t *testing.T) {

func setupKeeper(t *testing.T) (*Keeper, sdk.Context, []sdk.StoreKey) {
t.Helper()
tempDir, err := ioutil.TempDir("", "wasm")
tempDir, err := os.MkdirTemp("", "wasm")
require.NoError(t, err)
t.Cleanup(func() { os.RemoveAll(tempDir) })
var (
Expand Down
8 changes: 4 additions & 4 deletions x/wasm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"bytes"
"encoding/json"
"errors"
"io/ioutil"
"math"
"os"
"testing"
"time"

Expand All @@ -31,7 +31,7 @@ import (

// When migrated to go 1.16, embed package should be used instead.
func init() {
b, err := ioutil.ReadFile("./testdata/hackatom.wasm")
b, err := os.ReadFile("./testdata/hackatom.wasm")
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -348,7 +348,7 @@ func TestCreateWithGzippedPayload(t *testing.T) {
deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000))
creator := keepers.Faucet.NewFundedAccount(ctx, deposit...)

wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm.gzip")
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm.gzip")
require.NoError(t, err, "reading gzipped WASM code")

contractID, err := keeper.Create(ctx, creator, wasmCode, nil)
Expand Down Expand Up @@ -1097,7 +1097,7 @@ func TestMigrateWithDispatchedMessage(t *testing.T) {
creator := keepers.Faucet.NewFundedAccount(ctx, deposit.Add(deposit...)...)
fred := keepers.Faucet.NewFundedAccount(ctx, sdk.NewInt64Coin("denom", 5000))

burnerCode, err := ioutil.ReadFile("./testdata/burner.wasm")
burnerCode, err := os.ReadFile("./testdata/burner.wasm")
require.NoError(t, err)

originalContractID, err := keeper.Create(ctx, creator, hackatomWasm, nil)
Expand Down
8 changes: 4 additions & 4 deletions x/wasm/keeper/legacy_querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -24,7 +24,7 @@ func TestLegacyQueryContractState(t *testing.T) {
creator := keepers.Faucet.NewFundedAccount(ctx, deposit.Add(deposit...)...)
anyAddr := keepers.Faucet.NewFundedAccount(ctx, sdk.NewInt64Coin("denom", 5000))

wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)

contractID, err := keepers.ContractKeeper.Create(ctx, creator, wasmCode, nil)
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestLegacyQueryContractListByCodeOrdering(t *testing.T) {
creator := keepers.Faucet.NewFundedAccount(ctx, deposit.Add(deposit...)...)
anyAddr := keepers.Faucet.NewFundedAccount(ctx, topUp...)

wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)

codeID, err := keepers.ContractKeeper.Create(ctx, creator, wasmCode, nil)
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestLegacyQueryContractHistory(t *testing.T) {
}

func TestLegacyQueryCodeList(t *testing.T) {
wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)

specs := map[string]struct {
Expand Down
12 changes: 6 additions & 6 deletions x/wasm/keeper/proposal_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/hex"
"encoding/json"
"errors"
"io/ioutil"
"os"
"testing"

"github.com/cosmos/cosmos-sdk/x/params/client/utils"
Expand All @@ -30,7 +30,7 @@ func TestStoreCodeProposal(t *testing.T) {
CodeUploadAccess: types.AllowNobody,
InstantiateDefaultPermission: types.AccessTypeNobody,
})
wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)

myActorAddress := RandomBech32AccountAddress(t)
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestInstantiateProposal(t *testing.T) {
InstantiateDefaultPermission: types.AccessTypeNobody,
})

wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)

require.NoError(t, wasmKeeper.importCode(ctx, 1,
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestInstantiateProposal_NoAdmin(t *testing.T) {
InstantiateDefaultPermission: types.AccessTypeNobody,
})

wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)

require.NoError(t, wasmKeeper.importCode(ctx, 1,
Expand Down Expand Up @@ -203,7 +203,7 @@ func TestMigrateProposal(t *testing.T) {
InstantiateDefaultPermission: types.AccessTypeNobody,
})

wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)

codeInfoFixture := types.CodeInfoFixture(types.WithSHA256CodeHash(wasmCode))
Expand Down Expand Up @@ -394,7 +394,7 @@ func TestAdminProposals(t *testing.T) {
otherAddress sdk.AccAddress = bytes.Repeat([]byte{0x2}, types.ContractAddrLen)
contractAddr = BuildContractAddress(1, 1)
)
wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)

specs := map[string]struct {
Expand Down
10 changes: 5 additions & 5 deletions x/wasm/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"testing"
"time"

Expand Down Expand Up @@ -265,7 +265,7 @@ func TestQueryContractListByCodeOrdering(t *testing.T) {
creator := keepers.Faucet.NewFundedAccount(ctx, deposit...)
anyAddr := keepers.Faucet.NewFundedAccount(ctx, topUp...)

wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)

codeID, err := keepers.ContractKeeper.Create(ctx, creator, wasmCode, nil)
Expand Down Expand Up @@ -454,7 +454,7 @@ func TestQueryContractHistory(t *testing.T) {
}

func TestQueryCodeList(t *testing.T) {
wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)

ctx, keepers := CreateTestInput(t, false, SupportedFeatures)
Expand Down Expand Up @@ -656,7 +656,7 @@ func TestQueryPinnedCodes(t *testing.T) {
}

func TestQueryCodeInfo(t *testing.T) {
wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)

ctx, keepers := CreateTestInput(t, false, SupportedFeatures)
Expand Down Expand Up @@ -711,7 +711,7 @@ func TestQueryCodeInfo(t *testing.T) {
}

func TestQueryCodeInfoList(t *testing.T) {
wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)

ctx, keepers := CreateTestInput(t, false, SupportedFeatures)
Expand Down
Loading