@@ -3,9 +3,9 @@ package keeper
33import (
44 "encoding/json"
55 "fmt"
6+ tmbytes "github.com/cometbft/cometbft/libs/bytes"
67 "testing"
78
8- tmbytes "github.com/cometbft/cometbft/libs/bytes"
99 "github.com/stretchr/testify/require"
1010
1111 sdk "github.com/cosmos/cosmos-sdk/types"
@@ -14,12 +14,18 @@ import (
1414func TestBuildContractAddressClassic (t * testing.T ) {
1515 // preserve current Bech32 settings and restore them after test completion
1616 x , y := sdk .GetConfig ().GetBech32AccountAddrPrefix (), sdk .GetConfig ().GetBech32AccountPubPrefix ()
17+ c := sdk .IsAddrCacheEnabled ()
1718 t .Cleanup (func () {
1819 sdk .GetConfig ().SetBech32PrefixForAccount (x , y )
20+ sdk .SetAddrCacheEnabled (c )
1921 })
2022
2123 // set custom Bech32 settings
2224 sdk .GetConfig ().SetBech32PrefixForAccount ("purple" , "purple" )
25+ // disables address cache, AccAddress -> String conversion is then slower,
26+ // but does not lead to errors like:
27+ // runtime error: invalid memory address or nil pointer dereference
28+ sdk .SetAddrCacheEnabled (false )
2329
2430 // prepare test data
2531 type Spec struct {
@@ -112,7 +118,7 @@ func TestBuildContractAddressPredictable(t *testing.T) {
112118 t .Run (fmt .Sprintf ("case %d" , i ), func (t * testing.T ) {
113119 // when
114120 gotAddr := BuildContractAddressPredictable (spec .In .Checksum , spec .In .Creator , spec .In .Salt .Bytes (), []byte (spec .In .Msg ))
115-
121+ // then
116122 require .Equal (t , spec .Out .Address .String (), gotAddr .String ())
117123 require .NoError (t , sdk .VerifyAddressFormat (gotAddr ))
118124 })
0 commit comments