-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init SDK once per process to avoid client panics (#352)
- Loading branch information
1 parent
0b0d052
commit 2299ce6
Showing
3 changed files
with
36 additions
and
1 deletion.
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
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,24 @@ | ||
package params | ||
|
||
import ( | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestInitCosmosSdk(t *testing.T) { | ||
// sdk initialized only once | ||
assert.NotPanics(t, func() { InitCosmosSdk("wasm", "atom") }) | ||
assert.NotPanics(t, func() { InitCosmosSdk("notwasm", "cosmos") }) | ||
// calling the internal implementation panics when called a second time | ||
assert.Panics(t, func() { initCosmosSdk("wasm", "cosmos") }) | ||
|
||
// first call to Init wins | ||
sdkConfig := sdk.GetConfig() | ||
assert.Equal(t, sdkConfig.GetBech32AccountAddrPrefix(), "wasm") | ||
_, ok := sdk.GetDenomUnit("atom") | ||
assert.True(t, ok) | ||
_, ok = sdk.GetDenomUnit("cosmos") | ||
assert.False(t, ok) | ||
} |
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