-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathacc_cache_test.go
43 lines (34 loc) · 1.47 KB
/
acc_cache_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package interchaintest
import (
"testing"
"github.com/cometbft/cometbft/crypto/ed25519"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)
// See https://github.com/cosmos/cosmos-sdk/issues/15317 for description of bug.
// Basically, in cosmos SDK, there is an account address cache that will ignore the bech32 prefix setting.
// This will cause the AccAddress.String() to print out unexpected prefixes.
// If this function fails you are on an unsafe SDK version that should NOT be used with the relayer.
func TestAccCacheBugfix(t *testing.T) {
sdk.SetAddrCacheEnabled(false)
// Use a random key
priv := ed25519.GenPrivKey()
pub := priv.PubKey()
//Set to 'osmo'
prefix := "osmo"
sdkConf := sdk.GetConfig()
sdkConf.SetBech32PrefixForAccount(prefix, prefix+"pub")
sdkConf.SetBech32PrefixForValidator(prefix+"valoper", prefix+"valoperpub")
sdkConf.SetBech32PrefixForConsensusNode(prefix+"valcons", prefix+"valconspub")
addrOsmo := sdk.AccAddress(pub.Address())
osmoAddrBech32 := addrOsmo.String()
//Set to 'cosmos'
prefix = "cosmos"
sdkConf.SetBech32PrefixForAccount(prefix, prefix+"pub")
sdkConf.SetBech32PrefixForValidator(prefix+"valoper", prefix+"valoperpub")
sdkConf.SetBech32PrefixForConsensusNode(prefix+"valcons", prefix+"valconspub")
addrCosmos := sdk.AccAddress(pub.Address())
cosmosAddrBech32 := addrCosmos.String()
//If the addresses are equal, the AccAddress caching caused a bug
require.NotEqual(t, osmoAddrBech32, cosmosAddrBech32)
}