forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alessio Treglia
committed
Oct 22, 2018
1 parent
add15b5
commit 44a6c21
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |