Skip to content

Commit

Permalink
depracte-ioutil (#934)
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat authored Aug 24, 2022
1 parent 2a37cfd commit 4875db2
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 49 deletions.
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
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
4 changes: 2 additions & 2 deletions x/wasm/keeper/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package keeper

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

Expand Down Expand Up @@ -52,7 +52,7 @@ func TestReflectContractSend(t *testing.T) {
require.Equal(t, uint64(1), reflectID)

// upload hackatom escrow code
escrowCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
escrowCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)
escrowID, err := keeper.Create(ctx, creator, escrowCode, nil)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/keeper/snapshotter_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package keeper_test

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

Expand Down Expand Up @@ -53,7 +53,7 @@ func TestSnapshotter(t *testing.T) {

srcCodeIDToChecksum := make(map[uint64][]byte, len(spec.wasmFiles))
for i, v := range spec.wasmFiles {
wasmCode, err := ioutil.ReadFile(v)
wasmCode, err := os.ReadFile(v)
require.NoError(t, err)
codeID, err := contractKeeper.Create(ctx, genesisAddr, wasmCode, nil)
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions x/wasm/keeper/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package keeper

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

wasmvmtypes "github.com/CosmWasm/wasmvm/types"
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestInitializeStaking(t *testing.T) {
creator := k.Faucet.NewFundedAccount(ctx, deposit...)

// upload staking derivates code
stakingCode, err := ioutil.ReadFile("./testdata/staking.wasm")
stakingCode, err := os.ReadFile("./testdata/staking.wasm")
require.NoError(t, err)
stakingID, err := keeper.Create(ctx, creator, stakingCode, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -189,7 +189,7 @@ func initializeStaking(t *testing.T) initInfo {
creator := k.Faucet.NewFundedAccount(ctx, deposit...)

// upload staking derivates code
stakingCode, err := ioutil.ReadFile("./testdata/staking.wasm")
stakingCode, err := os.ReadFile("./testdata/staking.wasm")
require.NoError(t, err)
stakingID, err := k.ContractKeeper.Create(ctx, creator, stakingCode, nil)
require.NoError(t, err)
Expand Down
Loading

0 comments on commit 4875db2

Please sign in to comment.