Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessio Treglia committed Oct 22, 2018
1 parent add15b5 commit 44a6c21
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions client/keys/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package keys

import (
"github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/stretchr/testify/require"
"io/ioutil"
"os"
"testing"
)

func TestGetKeyBaseLocks(t *testing.T) {
dir, err := ioutil.TempDir("", "cosmos-sdk-keys")
require.Nil(t, err)
defer os.RemoveAll(dir)

// Acquire db
kb, err := GetKeyBaseFromDirWithWritePerm(dir)
require.Nil(t, err)
_, _, err = kb.CreateMnemonic("foo", keys.English, "12345678", keys.Secp256k1)
require.Nil(t, err)
// Reset global variable
keybase = nil
// Try to acquire another keybase from the same storage
_, err = GetKeyBaseFromDirWithWritePerm(dir)
require.NotNil(t, err)
_, err = GetKeyBaseFromDirWithWritePerm(dir)
require.NotNil(t, err)

// Close the db and try to acquire the lock
kb.CloseDB()
kb, err = GetKeyBaseFromDirWithWritePerm(dir)
require.Nil(t, err)

// Try to acquire another read-only keybase from the same storage
_, err = GetKeyBaseFromDir(dir)
require.Nil(t, err)

kb.CloseDB()
}

0 comments on commit 44a6c21

Please sign in to comment.