Skip to content

Commit

Permalink
Maybe this will fix the problem.
Browse files Browse the repository at this point in the history
  • Loading branch information
DariuszDepta committed Oct 12, 2023
1 parent 99ade09 commit 9394faf
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions x/wasm/keeper/addresses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package keeper
import (
"encoding/json"
"fmt"
tmbytes "github.com/cometbft/cometbft/libs/bytes"
"testing"

tmbytes "github.com/cometbft/cometbft/libs/bytes"
"github.com/stretchr/testify/require"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -14,12 +14,18 @@ import (
func TestBuildContractAddressClassic(t *testing.T) {
// preserve current Bech32 settings and restore them after test completion
x, y := sdk.GetConfig().GetBech32AccountAddrPrefix(), sdk.GetConfig().GetBech32AccountPubPrefix()
c := sdk.IsAddrCacheEnabled()
t.Cleanup(func() {
sdk.GetConfig().SetBech32PrefixForAccount(x, y)
sdk.SetAddrCacheEnabled(c)
})

// set custom Bech32 settings
sdk.GetConfig().SetBech32PrefixForAccount("purple", "purple")
// disables address cache, AccAddress -> String conversion is then slower,
// but does not lead to errors like:
// runtime error: invalid memory address or nil pointer dereference
sdk.SetAddrCacheEnabled(false)

// prepare test data
type Spec struct {
Expand Down Expand Up @@ -112,7 +118,7 @@ func TestBuildContractAddressPredictable(t *testing.T) {
t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) {
// when
gotAddr := BuildContractAddressPredictable(spec.In.Checksum, spec.In.Creator, spec.In.Salt.Bytes(), []byte(spec.In.Msg))

// then
require.Equal(t, spec.Out.Address.String(), gotAddr.String())
require.NoError(t, sdk.VerifyAddressFormat(gotAddr))
})
Expand Down

0 comments on commit 9394faf

Please sign in to comment.