@@ -3,9 +3,9 @@ package keeper
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
+ tmbytes "github.com/cometbft/cometbft/libs/bytes"
6
7
"testing"
7
8
8
- tmbytes "github.com/cometbft/cometbft/libs/bytes"
9
9
"github.com/stretchr/testify/require"
10
10
11
11
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -14,12 +14,18 @@ import (
14
14
func TestBuildContractAddressClassic (t * testing.T ) {
15
15
// preserve current Bech32 settings and restore them after test completion
16
16
x , y := sdk .GetConfig ().GetBech32AccountAddrPrefix (), sdk .GetConfig ().GetBech32AccountPubPrefix ()
17
+ c := sdk .IsAddrCacheEnabled ()
17
18
t .Cleanup (func () {
18
19
sdk .GetConfig ().SetBech32PrefixForAccount (x , y )
20
+ sdk .SetAddrCacheEnabled (c )
19
21
})
20
22
21
23
// set custom Bech32 settings
22
24
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 )
23
29
24
30
// prepare test data
25
31
type Spec struct {
@@ -112,7 +118,7 @@ func TestBuildContractAddressPredictable(t *testing.T) {
112
118
t .Run (fmt .Sprintf ("case %d" , i ), func (t * testing.T ) {
113
119
// when
114
120
gotAddr := BuildContractAddressPredictable (spec .In .Checksum , spec .In .Creator , spec .In .Salt .Bytes (), []byte (spec .In .Msg ))
115
-
121
+ // then
116
122
require .Equal (t , spec .Out .Address .String (), gotAddr .String ())
117
123
require .NoError (t , sdk .VerifyAddressFormat (gotAddr ))
118
124
})
0 commit comments