diff --git a/.github/workflows/sims.yml b/.github/workflows/sims.yml index e39407176d2e..52d6a41ae3c9 100644 --- a/.github/workflows/sims.yml +++ b/.github/workflows/sims.yml @@ -21,17 +21,24 @@ jobs: if: "!contains(github.event.head_commit.message, 'skip-sims')" steps: - uses: actions/checkout@v2 - - run: | - make build + - uses: actions/setup-go@v2.1.2 + with: + go-version: 1.15 + - name: Display go version + run: go version + - run: make build install-runsim: runs-on: ubuntu-latest needs: build steps: - uses: actions/setup-go@v2.1.2 - - name: install runsim - run: | - export GO111MODULE="on" && go get github.com/cosmos/tools/cmd/runsim@v1.0.0 + with: + go-version: 1.15 + - name: Display go version + run: go version + - name: Install runsim + run: export GO111MODULE="on" && go get github.com/cosmos/tools/cmd/runsim@v1.0.0 - uses: actions/cache@v2.1.1 with: path: ~/go/bin @@ -42,6 +49,11 @@ jobs: needs: [build, install-runsim] steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v2.1.2 + with: + go-version: 1.15 + - name: Display go version + run: go version - uses: technote-space/get-diff-action@v3 with: SUFFIX_FILTER: | @@ -65,6 +77,11 @@ jobs: needs: [build, install-runsim] steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v2.1.2 + with: + go-version: 1.15 + - name: Display go version + run: go version - uses: technote-space/get-diff-action@v3 with: SUFFIX_FILTER: | @@ -88,6 +105,11 @@ jobs: needs: [build, install-runsim] steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v2.1.2 + with: + go-version: 1.15 + - name: Display go version + run: go version - uses: technote-space/get-diff-action@v3 with: SUFFIX_FILTER: | @@ -111,6 +133,11 @@ jobs: needs: [build, install-runsim] steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v2.1.2 + with: + go-version: 1.15 + - name: Display go version + run: go version - uses: technote-space/get-diff-action@v3 with: SUFFIX_FILTER: | diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index 4515f515e470..bb7cba20c4ac 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -15,7 +15,7 @@ jobs: - name: Install Go uses: actions/setup-go@v2.1.2 with: - go-version: 1.14 + go-version: 1.15 - name: Unshallow run: git fetch --prune --unshallow - name: Create release diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f07c0198bccd..a55d28f3249f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,6 +19,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/setup-go@v2.1.2 + with: + go-version: 1.15 + - name: Display go version + run: go version - name: install tparse run: | export GO111MODULE="on" && go get github.com/mfridman/tparse@v0.8.3 @@ -31,6 +35,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v2.1.2 + with: + go-version: 1.15 + - name: Display go version + run: go version - uses: technote-space/get-diff-action@v1 id: git_diff with: @@ -48,6 +57,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v2.1.2 + with: + go-version: 1.15 + - name: Display go version + run: go version - name: Create a file with all the pkgs run: go list ./... > pkgs.txt - name: Split pkgs into 4 files @@ -76,6 +90,11 @@ jobs: timeout-minutes: 15 steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v2.1.2 + with: + go-version: 1.15 + - name: Display go version + run: go version - uses: technote-space/get-diff-action@v3 id: git_diff with: @@ -113,6 +132,11 @@ jobs: timeout-minutes: 15 steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v2.1.2 + with: + go-version: 1.15 + - name: Display go version + run: go version - uses: technote-space/get-diff-action@v3 id: git_diff with: @@ -150,6 +174,11 @@ jobs: timeout-minutes: 15 steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v2.1.2 + with: + go-version: 1.15 + - name: Display go version + run: go version - uses: technote-space/get-diff-action@v3 id: git_diff with: @@ -187,6 +216,11 @@ jobs: timeout-minutes: 15 steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v2.1.2 + with: + go-version: 1.15 + - name: Display go version + run: go version - uses: technote-space/get-diff-action@v3 id: git_diff with: @@ -224,6 +258,11 @@ jobs: timeout-minutes: 15 steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v2.1.2 + with: + go-version: 1.15 + - name: Display go version + run: go version - uses: technote-space/get-diff-action@v3 id: git_diff with: @@ -249,6 +288,11 @@ jobs: timeout-minutes: 15 steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v2.1.2 + with: + go-version: 1.15 + - name: Display go version + run: go version - uses: technote-space/get-diff-action@v3 id: git_diff with: @@ -274,6 +318,11 @@ jobs: timeout-minutes: 15 steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v2.1.2 + with: + go-version: 1.15 + - name: Display go version + run: go version - uses: technote-space/get-diff-action@v3 id: git_diff with: @@ -299,6 +348,11 @@ jobs: timeout-minutes: 15 steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v2.1.2 + with: + go-version: 1.15 + - name: Display go version + run: go version - uses: technote-space/get-diff-action@v3 id: git_diff with: diff --git a/README.md b/README.md index 6707950f07ef..38763419615b 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ It is being used to build [`Gaia`](https://github.com/cosmos/gaia), the first im **WARNING**: The SDK has mostly stabilized, but we are still making some breaking changes. -**Note**: Requires [Go 1.14+](https://golang.org/dl/) +**Note**: Requires [Go 1.15+](https://golang.org/dl/) ## Quick Start diff --git a/client/keys/add_ledger_test.go b/client/keys/add_ledger_test.go index bd433b1330e3..e3ecd91bb50a 100644 --- a/client/keys/add_ledger_test.go +++ b/client/keys/add_ledger_test.go @@ -37,9 +37,7 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) { cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) // Prepare a keybase - kbHome, kbCleanUp := testutil.NewTestCaseDir(t) - require.NotNil(t, kbHome) - t.Cleanup(kbCleanUp) + kbHome := t.TempDir() cmd.SetArgs([]string{ "keyname1", @@ -86,11 +84,7 @@ func Test_runAddCmdLedger(t *testing.T) { cmd := AddKeyCommand() cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) mockIn := testutil.ApplyMockIODiscardOutErr(cmd) - - // Prepare a keybase - kbHome, kbCleanUp := testutil.NewTestCaseDir(t) - require.NotNil(t, kbHome) - t.Cleanup(kbCleanUp) + kbHome := t.TempDir() cmd.SetArgs([]string{ "keyname1", diff --git a/client/keys/add_test.go b/client/keys/add_test.go index 42a6164ba5c6..ea9bdf5bebce 100644 --- a/client/keys/add_test.go +++ b/client/keys/add_test.go @@ -20,12 +20,9 @@ func Test_runAddCmdBasic(t *testing.T) { cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) mockIn := testutil.ApplyMockIODiscardOutErr(cmd) - - kbHome, kbCleanUp := testutil.NewTestCaseDir(t) - require.NotNil(t, kbHome) - t.Cleanup(kbCleanUp) - + kbHome := t.TempDir() kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn) + require.NoError(t, err) t.Cleanup(func() { _ = kb.Delete("keyname1") diff --git a/client/keys/delete_test.go b/client/keys/delete_test.go index fc70c7e85286..da863ef1253a 100644 --- a/client/keys/delete_test.go +++ b/client/keys/delete_test.go @@ -15,9 +15,7 @@ import ( func Test_runDeleteCmd(t *testing.T) { // Now add a temporary keybase - kbHome, cleanUp := testutil.NewTestCaseDir(t) - t.Cleanup(cleanUp) - + kbHome := t.TempDir() cmd := DeleteKeyCommand() cmd.Flags().AddFlagSet(Commands(kbHome).PersistentFlags()) mockIn := testutil.ApplyMockIODiscardOutErr(cmd) diff --git a/client/keys/export_test.go b/client/keys/export_test.go index 39ed112079e3..7f48795c51cb 100644 --- a/client/keys/export_test.go +++ b/client/keys/export_test.go @@ -20,8 +20,7 @@ func Test_runExportCmd(t *testing.T) { mockIn := testutil.ApplyMockIODiscardOutErr(cmd) // Now add a temporary keybase - kbHome, cleanUp := testutil.NewTestCaseDir(t) - t.Cleanup(cleanUp) + kbHome := t.TempDir() // create a key kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn) diff --git a/client/keys/import_test.go b/client/keys/import_test.go index 34a90ffcd3ce..d6e98a74ec22 100644 --- a/client/keys/import_test.go +++ b/client/keys/import_test.go @@ -20,10 +20,9 @@ func Test_runImportCmd(t *testing.T) { mockIn := testutil.ApplyMockIODiscardOutErr(cmd) // Now add a temporary keybase - kbHome, cleanUp := testutil.NewTestCaseDir(t) - t.Cleanup(cleanUp) - + kbHome := t.TempDir() kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn) + require.NoError(t, err) t.Cleanup(func() { kb.Delete("keyname1") // nolint:errcheck diff --git a/client/keys/list_test.go b/client/keys/list_test.go index 9c9f93716daf..78c4e94857bb 100644 --- a/client/keys/list_test.go +++ b/client/keys/list_test.go @@ -18,11 +18,8 @@ func Test_runListCmd(t *testing.T) { cmd := ListKeysCmd() cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) - kbHome1, cleanUp1 := testutil.NewTestCaseDir(t) - t.Cleanup(cleanUp1) - - kbHome2, cleanUp2 := testutil.NewTestCaseDir(t) - t.Cleanup(cleanUp2) + kbHome1 := t.TempDir() + kbHome2 := t.TempDir() mockIn := testutil.ApplyMockIODiscardOutErr(cmd) kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome2, mockIn) diff --git a/client/keys/migrate_test.go b/client/keys/migrate_test.go index c03dca024b22..2918d1e93468 100644 --- a/client/keys/migrate_test.go +++ b/client/keys/migrate_test.go @@ -18,11 +18,9 @@ func Test_runMigrateCmd(t *testing.T) { _ = testutil.ApplyMockIODiscardOutErr(cmd) cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) - kbHome, kbCleanUp := testutil.NewTestCaseDir(t) - copy.Copy("testdata", kbHome) - assert.NotNil(t, kbHome) - t.Cleanup(kbCleanUp) + kbHome := t.TempDir() + copy.Copy("testdata", kbHome) cmd.SetArgs([]string{ "keyname1", fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), diff --git a/client/keys/show_test.go b/client/keys/show_test.go index 9760b92d7099..d07756a7e316 100644 --- a/client/keys/show_test.go +++ b/client/keys/show_test.go @@ -49,9 +49,7 @@ func Test_runShowCmd(t *testing.T) { cmd.SetArgs([]string{"invalid1", "invalid2"}) require.EqualError(t, cmd.Execute(), "invalid1 is not a valid name or address: decoding bech32 failed: invalid index of 1") - kbHome, cleanUp := testutil.NewTestCaseDir(t) - t.Cleanup(cleanUp) - + kbHome := t.TempDir() fakeKeyName1 := "runShowCmd_Key1" fakeKeyName2 := "runShowCmd_Key2" diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index 825b158c1430..41a021fef1b5 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -12,7 +12,6 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/simapp" - "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/signing" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -122,11 +121,8 @@ func TestBuildUnsignedTx(t *testing.T) { } func TestSign(t *testing.T) { - dir, clean := testutil.NewTestCaseDir(t) - t.Cleanup(clean) - path := hd.CreateHDPath(118, 0, 0).String() - kr, err := keyring.New(t.Name(), "test", dir, nil) + kr, err := keyring.New(t.Name(), "test", t.TempDir(), nil) require.NoError(t, err) var from = "test_sign" diff --git a/crypto/keyring/keyring_ledger_test.go b/crypto/keyring/keyring_ledger_test.go index dd193d9d5002..275e3edd576a 100644 --- a/crypto/keyring/keyring_ledger_test.go +++ b/crypto/keyring/keyring_ledger_test.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/crypto/hd" - "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -52,8 +51,8 @@ func TestInMemoryCreateLedger(t *testing.T) { // TestSignVerify does some detailed checks on how we sign and validate // signatures func TestSignVerifyKeyRingWithLedger(t *testing.T) { - dir, cleanup := testutil.NewTestCaseDir(t) - t.Cleanup(cleanup) + dir := t.TempDir() + kb, err := New("keybasename", "test", dir, nil) require.NoError(t, err) @@ -89,8 +88,7 @@ func TestSignVerifyKeyRingWithLedger(t *testing.T) { } func TestAltKeyring_SaveLedgerKey(t *testing.T) { - dir, clean := testutil.NewTestCaseDir(t) - t.Cleanup(clean) + dir := t.TempDir() keyring, err := New(t.Name(), BackendTest, dir, nil) require.NoError(t, err) diff --git a/crypto/keyring/keyring_test.go b/crypto/keyring/keyring_test.go index ac2ba0381c12..32f76dae903e 100644 --- a/crypto/keyring/keyring_test.go +++ b/crypto/keyring/keyring_test.go @@ -15,7 +15,6 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -30,9 +29,9 @@ func init() { } func TestNewKeyring(t *testing.T) { - dir, cleanup := testutil.NewTestCaseDir(t) + dir := t.TempDir() mockIn := strings.NewReader("") - t.Cleanup(cleanup) + kr, err := New("cosmos", BackendFile, dir, mockIn) require.NoError(t, err) @@ -48,9 +47,7 @@ func TestNewKeyring(t *testing.T) { } func TestKeyManagementKeyRing(t *testing.T) { - dir, cleanup := testutil.NewTestCaseDir(t) - t.Cleanup(cleanup) - kb, err := New("keybasename", "test", dir, nil) + kb, err := New("keybasename", "test", t.TempDir(), nil) require.NoError(t, err) algo := hd.Secp256k1 @@ -130,8 +127,7 @@ func TestKeyManagementKeyRing(t *testing.T) { } func TestSignVerifyKeyRing(t *testing.T) { - dir, cleanup := testutil.NewTestCaseDir(t) - t.Cleanup(cleanup) + dir := t.TempDir() kb, err := New("keybasename", "test", dir, nil) require.NoError(t, err) @@ -209,9 +205,7 @@ func TestSignVerifyKeyRing(t *testing.T) { } func TestExportImportKeyRing(t *testing.T) { - dir, cleanup := testutil.NewTestCaseDir(t) - t.Cleanup(cleanup) - kb, err := New("keybasename", "test", dir, nil) + kb, err := New("keybasename", "test", t.TempDir(), nil) require.NoError(t, err) info, _, err := kb.NewMnemonic("john", English, sdk.FullFundraiserPath, hd.Secp256k1) @@ -243,9 +237,7 @@ func TestExportImportKeyRing(t *testing.T) { } func TestExportImportPubKeyKeyRing(t *testing.T) { - dir, cleanup := testutil.NewTestCaseDir(t) - t.Cleanup(cleanup) - kb, err := New("keybasename", "test", dir, nil) + kb, err := New("keybasename", "test", t.TempDir(), nil) require.NoError(t, err) algo := hd.Secp256k1 @@ -283,8 +275,7 @@ func TestExportImportPubKeyKeyRing(t *testing.T) { } func TestAdvancedKeyManagementKeyRing(t *testing.T) { - dir, cleanup := testutil.NewTestCaseDir(t) - t.Cleanup(cleanup) + dir := t.TempDir() kb, err := New("keybasename", "test", dir, nil) require.NoError(t, err) @@ -319,8 +310,8 @@ func TestAdvancedKeyManagementKeyRing(t *testing.T) { } func TestSeedPhraseKeyRing(t *testing.T) { - dir, cleanup := testutil.NewTestCaseDir(t) - t.Cleanup(cleanup) + dir := t.TempDir() + kb, err := New("keybasename", "test", dir, nil) require.NoError(t, err) @@ -350,9 +341,7 @@ func TestSeedPhraseKeyRing(t *testing.T) { } func TestKeyringKeybaseExportImportPrivKey(t *testing.T) { - dir, cleanup := testutil.NewTestCaseDir(t) - t.Cleanup(cleanup) - kb, err := New("keybasename", "test", dir, nil) + kb, err := New("keybasename", "test", t.TempDir(), nil) require.NoError(t, err) _, _, err = kb.NewMnemonic("john", English, sdk.FullFundraiserPath, hd.Secp256k1) @@ -730,10 +719,7 @@ func TestInMemorySeedPhrase(t *testing.T) { } func TestKeyChain_ShouldFailWhenAddingSameGeneratedAccount(t *testing.T) { - dir, clean := testutil.NewTestCaseDir(t) - t.Cleanup(clean) - - kr, err := New(t.Name(), BackendTest, dir, nil) + kr, err := New(t.Name(), BackendTest, t.TempDir(), nil) require.NoError(t, err) // Given we create a mnemonic @@ -802,8 +788,7 @@ func ExampleNew() { } func TestAltKeyring_List(t *testing.T) { - dir, clean := testutil.NewTestCaseDir(t) - t.Cleanup(clean) + dir := t.TempDir() keyring, err := New(t.Name(), BackendTest, dir, nil) require.NoError(t, err) @@ -836,10 +821,7 @@ func TestAltKeyring_List(t *testing.T) { } func TestAltKeyring_NewAccount(t *testing.T) { - dir, clean := testutil.NewTestCaseDir(t) - t.Cleanup(clean) - - keyring, err := New(t.Name(), BackendTest, dir, nil) + keyring, err := New(t.Name(), BackendTest, t.TempDir(), nil) require.NoError(t, err) entropy, err := bip39.NewEntropy(defaultEntropySize) @@ -865,10 +847,7 @@ func TestAltKeyring_NewAccount(t *testing.T) { } func TestAltKeyring_Get(t *testing.T) { - dir, clean := testutil.NewTestCaseDir(t) - t.Cleanup(clean) - - keyring, err := New(t.Name(), BackendTest, dir, nil) + keyring, err := New(t.Name(), BackendTest, t.TempDir(), nil) require.NoError(t, err) uid := someKey @@ -881,10 +860,7 @@ func TestAltKeyring_Get(t *testing.T) { } func TestAltKeyring_KeyByAddress(t *testing.T) { - dir, clean := testutil.NewTestCaseDir(t) - t.Cleanup(clean) - - keyring, err := New(t.Name(), BackendTest, dir, nil) + keyring, err := New(t.Name(), BackendTest, t.TempDir(), nil) require.NoError(t, err) uid := someKey @@ -897,10 +873,7 @@ func TestAltKeyring_KeyByAddress(t *testing.T) { } func TestAltKeyring_Delete(t *testing.T) { - dir, clean := testutil.NewTestCaseDir(t) - t.Cleanup(clean) - - keyring, err := New(t.Name(), BackendTest, dir, nil) + keyring, err := New(t.Name(), BackendTest, t.TempDir(), nil) require.NoError(t, err) uid := someKey @@ -920,10 +893,7 @@ func TestAltKeyring_Delete(t *testing.T) { } func TestAltKeyring_DeleteByAddress(t *testing.T) { - dir, clean := testutil.NewTestCaseDir(t) - t.Cleanup(clean) - - keyring, err := New(t.Name(), BackendTest, dir, nil) + keyring, err := New(t.Name(), BackendTest, t.TempDir(), nil) require.NoError(t, err) uid := someKey @@ -943,10 +913,7 @@ func TestAltKeyring_DeleteByAddress(t *testing.T) { } func TestAltKeyring_SavePubKey(t *testing.T) { - dir, clean := testutil.NewTestCaseDir(t) - t.Cleanup(clean) - - keyring, err := New(t.Name(), BackendTest, dir, nil) + keyring, err := New(t.Name(), BackendTest, t.TempDir(), nil) require.NoError(t, err) list, err := keyring.List() @@ -969,10 +936,7 @@ func TestAltKeyring_SavePubKey(t *testing.T) { } func TestAltKeyring_SaveMultisig(t *testing.T) { - dir, clean := testutil.NewTestCaseDir(t) - t.Cleanup(clean) - - keyring, err := New(t.Name(), BackendTest, dir, nil) + keyring, err := New(t.Name(), BackendTest, t.TempDir(), nil) require.NoError(t, err) mnemonic1, _, err := keyring.NewMnemonic("key1", English, sdk.FullFundraiserPath, hd.Secp256k1) @@ -1000,10 +964,7 @@ func TestAltKeyring_SaveMultisig(t *testing.T) { } func TestAltKeyring_Sign(t *testing.T) { - dir, clean := testutil.NewTestCaseDir(t) - t.Cleanup(clean) - - keyring, err := New(t.Name(), BackendTest, dir, nil) + keyring, err := New(t.Name(), BackendTest, t.TempDir(), nil) require.NoError(t, err) uid := "jack" @@ -1019,10 +980,7 @@ func TestAltKeyring_Sign(t *testing.T) { } func TestAltKeyring_SignByAddress(t *testing.T) { - dir, clean := testutil.NewTestCaseDir(t) - t.Cleanup(clean) - - keyring, err := New(t.Name(), BackendTest, dir, nil) + keyring, err := New(t.Name(), BackendTest, t.TempDir(), nil) require.NoError(t, err) uid := "jack" @@ -1038,10 +996,7 @@ func TestAltKeyring_SignByAddress(t *testing.T) { } func TestAltKeyring_ImportExportPrivKey(t *testing.T) { - dir, clean := testutil.NewTestCaseDir(t) - t.Cleanup(clean) - - keyring, err := New(t.Name(), BackendTest, dir, nil) + keyring, err := New(t.Name(), BackendTest, t.TempDir(), nil) require.NoError(t, err) uid := theID @@ -1067,10 +1022,7 @@ func TestAltKeyring_ImportExportPrivKey(t *testing.T) { } func TestAltKeyring_ImportExportPrivKey_ByAddress(t *testing.T) { - dir, clean := testutil.NewTestCaseDir(t) - t.Cleanup(clean) - - keyring, err := New(t.Name(), BackendTest, dir, nil) + keyring, err := New(t.Name(), BackendTest, t.TempDir(), nil) require.NoError(t, err) uid := theID @@ -1097,10 +1049,7 @@ func TestAltKeyring_ImportExportPrivKey_ByAddress(t *testing.T) { } func TestAltKeyring_ImportExportPubKey(t *testing.T) { - dir, clean := testutil.NewTestCaseDir(t) - t.Cleanup(clean) - - keyring, err := New(t.Name(), BackendTest, dir, nil) + keyring, err := New(t.Name(), BackendTest, t.TempDir(), nil) require.NoError(t, err) uid := theID @@ -1122,10 +1071,7 @@ func TestAltKeyring_ImportExportPubKey(t *testing.T) { } func TestAltKeyring_ImportExportPubKey_ByAddress(t *testing.T) { - dir, clean := testutil.NewTestCaseDir(t) - t.Cleanup(clean) - - keyring, err := New(t.Name(), BackendTest, dir, nil) + keyring, err := New(t.Name(), BackendTest, t.TempDir(), nil) require.NoError(t, err) uid := theID @@ -1147,10 +1093,7 @@ func TestAltKeyring_ImportExportPubKey_ByAddress(t *testing.T) { } func TestAltKeyring_ConstructorSupportedAlgos(t *testing.T) { - dir, clean := testutil.NewTestCaseDir(t) - t.Cleanup(clean) - - keyring, err := New(t.Name(), BackendTest, dir, nil) + keyring, err := New(t.Name(), BackendTest, t.TempDir(), nil) require.NoError(t, err) // should fail when using unsupported signing algorythm. @@ -1162,10 +1105,7 @@ func TestAltKeyring_ConstructorSupportedAlgos(t *testing.T) { require.NoError(t, err) // but we can create a new keybase with our provided algos. - dir2, clean2 := testutil.NewTestCaseDir(t) - t.Cleanup(clean2) - - keyring2, err := New(t.Name(), BackendTest, dir2, nil, func(options *Options) { + keyring2, err := New(t.Name(), BackendTest, t.TempDir(), nil, func(options *Options) { options.SupportedAlgos = SigningAlgoList{ notSupportedAlgo{}, } diff --git a/crypto/keyring/legacy_test.go b/crypto/keyring/legacy_test.go index 38457a32732f..27503bdea056 100644 --- a/crypto/keyring/legacy_test.go +++ b/crypto/keyring/legacy_test.go @@ -9,20 +9,18 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/cosmos/cosmos-sdk/testutil" ) func TestNewLegacyKeyBase(t *testing.T) { - dir, cleanup := testutil.NewTestCaseDir(t) - t.Cleanup(cleanup) + dir := t.TempDir() + kb, err := keyring.NewLegacy("keybasename", dir) require.NoError(t, err) require.NoError(t, kb.Close()) } func TestLegacyKeybase(t *testing.T) { - dir, cleanup := testutil.NewTestCaseDir(t) - t.Cleanup(cleanup) + dir := t.TempDir() // Backup testdata require.NoError(t, copy.Copy("testdata", dir)) diff --git a/crypto/keys/multisig/multisig.go b/crypto/keys/multisig/multisig.go index b4b3eb870d56..d5ea39e30d42 100644 --- a/crypto/keys/multisig/multisig.go +++ b/crypto/keys/multisig/multisig.go @@ -5,11 +5,12 @@ import ( tmcrypto "github.com/tendermint/tendermint/crypto" + proto "github.com/gogo/protobuf/proto" + "github.com/cosmos/cosmos-sdk/codec/types" crypto "github.com/cosmos/cosmos-sdk/crypto/types" multisigtypes "github.com/cosmos/cosmos-sdk/crypto/types/multisig" "github.com/cosmos/cosmos-sdk/types/tx/signing" - proto "github.com/gogo/protobuf/proto" ) var _ multisigtypes.PubKey = &LegacyAminoPubKey{} diff --git a/crypto/keys/multisig/multisig_test.go b/crypto/keys/multisig/multisig_test.go index c418d42ceb06..d04531b941c3 100644 --- a/crypto/keys/multisig/multisig_test.go +++ b/crypto/keys/multisig/multisig_test.go @@ -3,17 +3,19 @@ package multisig_test import ( "testing" + tmcrypto "github.com/tendermint/tendermint/crypto" + "github.com/cosmos/cosmos-sdk/codec/types" crypto "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - tmcrypto "github.com/tendermint/tendermint/crypto" + + "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/codec" kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/types/tx/signing" - "github.com/stretchr/testify/require" ) func TestAddress(t *testing.T) { diff --git a/go.mod b/go.mod index ddea90b76e58..e5206e7d24d3 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -go 1.14 +go 1.15 module github.com/cosmos/cosmos-sdk diff --git a/server/constructors_test.go b/server/constructors_test.go index 694f9f538492..c131c2c987de 100644 --- a/server/constructors_test.go +++ b/server/constructors_test.go @@ -5,23 +5,18 @@ import ( "testing" "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/testutil" ) func Test_openDB(t *testing.T) { t.Parallel() - dir, cleanup := testutil.NewTestCaseDir(t) - t.Cleanup(cleanup) - _, err := openDB(dir) + _, err := openDB(t.TempDir()) require.NoError(t, err) } func Test_openTraceWriter(t *testing.T) { t.Parallel() - dir, cleanup := testutil.NewTestCaseDir(t) - t.Cleanup(cleanup) - fname := filepath.Join(dir, "logfile") + + fname := filepath.Join(t.TempDir(), "logfile") w, err := openTraceWriter(fname) require.NoError(t, err) require.NotNil(t, w) diff --git a/server/export_test.go b/server/export_test.go index 4e96d8114887..ac0cf6b6596e 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -25,14 +25,12 @@ import ( "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/simapp" - "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/genutil" ) func TestExportCmd_ConsensusParams(t *testing.T) { - tempDir, clean := testutil.NewTestCaseDir(t) - defer clean() + tempDir := t.TempDir() _, ctx, genDoc, cmd := setupApp(t, tempDir) @@ -58,12 +56,10 @@ func TestExportCmd_ConsensusParams(t *testing.T) { } func TestExportCmd_HomeDir(t *testing.T) { - tempDir, clean := testutil.NewTestCaseDir(t) - defer clean() - - _, ctx, _, cmd := setupApp(t, tempDir) + _, ctx, _, cmd := setupApp(t, t.TempDir()) cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, "foobar")}) + err := cmd.ExecuteContext(ctx) require.EqualError(t, err, "stat foobar/config/genesis.json: no such file or directory") } @@ -98,9 +94,7 @@ func TestExportCmd_Height(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - tempDir, clean := testutil.NewTestCaseDir(t) - defer clean() - + tempDir := t.TempDir() app, ctx, _, cmd := setupApp(t, tempDir) // Fast forward to block `tc.fastForward`. @@ -128,8 +122,7 @@ func TestExportCmd_Height(t *testing.T) { } func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *tmtypes.GenesisDoc, *cobra.Command) { - err := createConfigFolder(tempDir) - if err != nil { + if err := createConfigFolder(tempDir); err != nil { t.Fatalf("error creating config folder: %s", err) } @@ -142,11 +135,9 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t serverCtx.Config.RootDir = tempDir clientCtx := client.Context{}.WithJSONMarshaler(app.AppCodec()) - genDoc := newDefaultGenesisDoc() - err = saveGenesisFile(genDoc, serverCtx.Config.GenesisFile()) - require.NoError(t, err) + require.NoError(t, saveGenesisFile(genDoc, serverCtx.Config.GenesisFile())) app.InitChain( abci.RequestInitChain{ Validators: []abci.ValidatorUpdate{}, @@ -154,7 +145,6 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t AppStateBytes: genDoc.AppState, }, ) - app.Commit() cmd := server.ExportCmd( diff --git a/server/init_test.go b/server/init_test.go index 3cd3309ef2fb..d7439fe115f4 100644 --- a/server/init_test.go +++ b/server/init_test.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/server" - "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/types" ) @@ -25,10 +24,8 @@ func TestGenerateCoinKey(t *testing.T) { func TestGenerateSaveCoinKey(t *testing.T) { t.Parallel() - dir, cleanup := testutil.NewTestCaseDir(t) - t.Cleanup(cleanup) - kb, err := keyring.New(t.Name(), "test", dir, nil) + kb, err := keyring.New(t.Name(), "test", t.TempDir(), nil) require.NoError(t, err) addr, mnemonic, err := server.GenerateSaveCoinKey(kb, "keyname", false, hd.Secp256k1) @@ -47,10 +44,8 @@ func TestGenerateSaveCoinKey(t *testing.T) { func TestGenerateSaveCoinKeyOverwriteFlag(t *testing.T) { t.Parallel() - dir, cleanup := testutil.NewTestCaseDir(t) - t.Cleanup(cleanup) - kb, err := keyring.New(t.Name(), "test", dir, nil) + kb, err := keyring.New(t.Name(), "test", t.TempDir(), nil) require.NoError(t, err) keyname := "justakey" diff --git a/simapp/simd/cmd/genaccounts_test.go b/simapp/simd/cmd/genaccounts_test.go index da980b7be173..9efc5343e7a3 100644 --- a/simapp/simd/cmd/genaccounts_test.go +++ b/simapp/simd/cmd/genaccounts_test.go @@ -14,7 +14,6 @@ import ( "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/simapp" simcmd "github.com/cosmos/cosmos-sdk/simapp/simd/cmd" - "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/genutil" @@ -54,9 +53,7 @@ func TestAddGenesisAccountCmd(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - home, cleanup := testutil.NewTestCaseDir(t) - defer cleanup() - + home := t.TempDir() logger := log.NewNopLogger() cfg, err := genutiltest.CreateDefaultTendermintConfig(home) require.NoError(t, err) diff --git a/testutil/ioutil.go b/testutil/ioutil.go index 0df67fd35da1..9a5c697f885d 100644 --- a/testutil/ioutil.go +++ b/testutil/ioutil.go @@ -12,15 +12,6 @@ import ( "github.com/stretchr/testify/require" ) -// NewTestCaseDir creates a new temporary directory for a test case. -// Returns the directory path and a cleanup function. -// nolint: errcheck -func NewTestCaseDir(t testing.TB) (string, func()) { - dir, err := ioutil.TempDir("", strings.ReplaceAll(t.Name(), "/", "_")+"_") - require.NoError(t, err) - return dir, func() { os.RemoveAll(dir) } -} - // BufferReader is implemented by types that read from a string buffer. type BufferReader interface { io.Reader diff --git a/testutil/ioutil_test.go b/testutil/ioutil_test.go index 272ff323b321..4a05fb08dcb2 100644 --- a/testutil/ioutil_test.go +++ b/testutil/ioutil_test.go @@ -10,23 +10,6 @@ import ( "github.com/cosmos/cosmos-sdk/testutil" ) -func TestNewTestCaseDir(t *testing.T) { - dir1, cleanup1 := testutil.NewTestCaseDir(t) - dir2, cleanup2 := testutil.NewTestCaseDir(t) - - require.NotEqual(t, dir1, dir2) - require.DirExists(t, dir1) - require.DirExists(t, dir2) - - cleanup1() - - require.NoDirExists(t, dir1) - require.DirExists(t, dir2) - - cleanup2() - require.NoDirExists(t, dir2) -} - func TestApplyMockIO(t *testing.T) { cmd := &cobra.Command{} oldStdin := cmd.InOrStdin() diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index ce3edb994fd4..996b458ffc2e 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -773,9 +773,7 @@ func TestGetBroadcastCommand_WithoutOfflineFlag(t *testing.T) { cmd := authcli.GetBroadcastCommand() _, out := testutil.ApplyMockIO(cmd) - - testDir, cleanFunc := testutil.NewTestCaseDir(t) - t.Cleanup(cleanFunc) + testDir := t.TempDir() // Create new file with tx builder := txCfg.NewTxBuilder() diff --git a/x/distribution/client/cli/cli_test.go b/x/distribution/client/cli/cli_test.go index 35b212a81e39..8b3f02db903f 100644 --- a/x/distribution/client/cli/cli_test.go +++ b/x/distribution/client/cli/cli_test.go @@ -6,7 +6,6 @@ import ( "context" "fmt" "io/ioutil" - "os" "strings" "testing" "time" @@ -687,9 +686,8 @@ func (s *IntegrationTestSuite) TestNewFundCommunityPoolCmd() { func (s *IntegrationTestSuite) TestGetCmdSubmitProposal() { val := s.network.Validators[0] - invalidPropFile, err := ioutil.TempFile(os.TempDir(), "invalid_community_spend_proposal.*.json") + invalidPropFile, err := ioutil.TempFile(s.T().TempDir(), "invalid_community_spend_proposal.*.json") s.Require().NoError(err) - defer os.Remove(invalidPropFile.Name()) invalidProp := `{ "title": "", @@ -702,9 +700,8 @@ func (s *IntegrationTestSuite) TestGetCmdSubmitProposal() { _, err = invalidPropFile.WriteString(invalidProp) s.Require().NoError(err) - validPropFile, err := ioutil.TempFile(os.TempDir(), "valid_community_spend_proposal.*.json") + validPropFile, err := ioutil.TempFile(s.T().TempDir(), "valid_community_spend_proposal.*.json") s.Require().NoError(err) - defer os.Remove(validPropFile.Name()) validProp := fmt.Sprintf(`{ "title": "Community Pool Spend", diff --git a/x/genutil/client/cli/gentx_test.go b/x/genutil/client/cli/gentx_test.go index eeadcde28c41..a433a97643d2 100644 --- a/x/genutil/client/cli/gentx_test.go +++ b/x/genutil/client/cli/gentx_test.go @@ -48,9 +48,7 @@ func (s *IntegrationTestSuite) TearDownSuite() { func (s *IntegrationTestSuite) TestGenTxCmd() { val := s.network.Validators[0] - - dir, clean := testutil.NewTestCaseDir(s.T()) - defer clean() + dir := s.T().TempDir() cmd := cli.GenTxCmd( simapp.ModuleBasics, diff --git a/x/genutil/client/cli/init_test.go b/x/genutil/client/cli/init_test.go index 74fbdf8afbe4..213a20e0028c 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -21,7 +21,6 @@ import ( cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/mock" - "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/genutil" @@ -54,9 +53,7 @@ func TestInitCmd(t *testing.T) { for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { - home, cleanup := testutil.NewTestCaseDir(t) - defer cleanup() - + home := t.TempDir() logger := log.NewNopLogger() cfg, err := genutiltest.CreateDefaultTendermintConfig(home) require.NoError(t, err) @@ -89,17 +86,8 @@ func TestInitCmd(t *testing.T) { } -func setupClientHome(t *testing.T) func() { - _, cleanup := testutil.NewTestCaseDir(t) - return cleanup -} - func TestEmptyState(t *testing.T) { - t.Cleanup(setupClientHome(t)) - - home, cleanup := testutil.NewTestCaseDir(t) - t.Cleanup(cleanup) - + home := t.TempDir() logger := log.NewNopLogger() cfg, err := genutiltest.CreateDefaultTendermintConfig(home) require.NoError(t, err) @@ -148,10 +136,7 @@ func TestEmptyState(t *testing.T) { } func TestStartStandAlone(t *testing.T) { - home, cleanup := testutil.NewTestCaseDir(t) - t.Cleanup(cleanup) - t.Cleanup(setupClientHome(t)) - + home := t.TempDir() logger := log.NewNopLogger() interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) @@ -180,10 +165,10 @@ func TestStartStandAlone(t *testing.T) { } func TestInitNodeValidatorFiles(t *testing.T) { - home, cleanup := testutil.NewTestCaseDir(t) + home := t.TempDir() cfg, err := genutiltest.CreateDefaultTendermintConfig(home) - t.Cleanup(cleanup) nodeID, valPubKey, err := genutil.InitializeNodeValidatorFiles(cfg) + require.Nil(t, err) require.NotEqual(t, "", nodeID) require.NotEqual(t, 0, len(valPubKey.Bytes())) diff --git a/x/genutil/client/cli/migrate_test.go b/x/genutil/client/cli/migrate_test.go index 95506fb3c249..807c0d32b4e6 100644 --- a/x/genutil/client/cli/migrate_test.go +++ b/x/genutil/client/cli/migrate_test.go @@ -20,8 +20,7 @@ func TestGetMigrationCallback(t *testing.T) { } func TestMigrateGenesis(t *testing.T) { - home, cleanup := testutil.NewTestCaseDir(t) - t.Cleanup(cleanup) + home := t.TempDir() cdc := makeCodec() diff --git a/x/genutil/utils_test.go b/x/genutil/utils_test.go index 5327664ec1ef..d1a80d58c1c0 100644 --- a/x/genutil/utils_test.go +++ b/x/genutil/utils_test.go @@ -6,16 +6,13 @@ import ( "testing" "time" - "github.com/cosmos/cosmos-sdk/testutil" - "github.com/stretchr/testify/require" ) func TestExportGenesisFileWithTime(t *testing.T) { t.Parallel() - dir, cleanup := testutil.NewTestCaseDir(t) - t.Cleanup(cleanup) - fname := filepath.Join(dir, "genesis.json") + fname := filepath.Join(t.TempDir(), "genesis.json") + require.NoError(t, ExportGenesisFileWithTime(fname, "test", nil, json.RawMessage(`{"account_owner": "Bob"}`), time.Now())) } diff --git a/x/gov/client/cli/cli_test.go b/x/gov/client/cli/cli_test.go index 47bc19be9767..ab8b75741e86 100644 --- a/x/gov/client/cli/cli_test.go +++ b/x/gov/client/cli/cli_test.go @@ -5,7 +5,6 @@ package cli_test import ( "fmt" "io/ioutil" - "os" "testing" "github.com/gogo/protobuf/proto" @@ -47,9 +46,8 @@ func (s *IntegrationTestSuite) TearDownSuite() { func (s *IntegrationTestSuite) TestNewCmdSubmitProposal() { val := s.network.Validators[0] - invalidPropFile, err := ioutil.TempFile(os.TempDir(), "invalid_text_proposal.*.json") + invalidPropFile, err := ioutil.TempFile(s.T().TempDir(), "invalid_text_proposal.*.json") s.Require().NoError(err) - defer os.Remove(invalidPropFile.Name()) invalidProp := `{ "title": "", @@ -61,9 +59,8 @@ func (s *IntegrationTestSuite) TestNewCmdSubmitProposal() { _, err = invalidPropFile.WriteString(invalidProp) s.Require().NoError(err) - validPropFile, err := ioutil.TempFile(os.TempDir(), "valid_text_proposal.*.json") + validPropFile, err := ioutil.TempFile(s.T().TempDir(), "valid_text_proposal.*.json") s.Require().NoError(err) - defer os.Remove(validPropFile.Name()) validProp := fmt.Sprintf(`{ "title": "Text Proposal", diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index 7ede1c65dfdf..3fa408ba212f 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -1,8 +1,7 @@ package keeper_test import ( - "io/ioutil" - "os" + "path/filepath" "testing" "github.com/stretchr/testify/suite" @@ -22,15 +21,11 @@ type KeeperTestSuite struct { func (s *KeeperTestSuite) SetupTest() { app := simapp.Setup(false) - - homeDir, err := ioutil.TempDir(os.TempDir(), "x_upgrade_keeper_test") - s.Require().NoError(err) - - // recreate keeper in order to use a custom home path - app.UpgradeKeeper = keeper.NewKeeper( + homeDir := filepath.Join(s.T().TempDir(), "x_upgrade_keeper_test") + app.UpgradeKeeper = keeper.NewKeeper( // recreate keeper in order to use a custom home path make(map[int64]bool), app.GetKey(types.StoreKey), app.AppCodec(), homeDir, ) - + s.T().Log("home dir:", homeDir) s.homeDir = homeDir s.app = app } diff --git a/x/upgrade/types/storeloader_test.go b/x/upgrade/types/storeloader_test.go index 7fd147013e55..f1afa4176b53 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -16,7 +16,6 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/store/rootmulti" store "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -67,15 +66,15 @@ func checkStore(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte // Test that LoadLatestVersion actually does. func TestSetLoader(t *testing.T) { // set a temporary home dir - homeDir, cleanup := testutil.NewTestCaseDir(t) - t.Cleanup(cleanup) - + homeDir := t.TempDir() upgradeInfoFilePath := filepath.Join(homeDir, "upgrade-info.json") upgradeInfo := &store.UpgradeInfo{ Name: "test", Height: 0, } + data, err := json.Marshal(upgradeInfo) require.NoError(t, err) + err = ioutil.WriteFile(upgradeInfoFilePath, data, 0644) require.NoError(t, err)