@@ -11,7 +11,79 @@ import (
1111 sdk "github.com/cosmos/cosmos-sdk/types"
1212)
1313
14- func TestBuildContractAddress (t * testing.T ) {
14+ func TestBuildContractAddressClassic (t * testing.T ) {
15+ // preserve current Bech32 settings and make sure they will be restores when this test finishes
16+ x , y := sdk .GetConfig ().GetBech32AccountAddrPrefix (), sdk .GetConfig ().GetBech32AccountPubPrefix ()
17+ t .Cleanup (func () {
18+ sdk .GetConfig ().SetBech32PrefixForAccount (x , y )
19+ })
20+ // set custom Bech32 settings
21+ sdk .GetConfig ().SetBech32PrefixForAccount ("juno" , "juno" )
22+ // prepare test data
23+ type Spec struct {
24+ In struct {
25+ CodeId uint64 `json:"codeId"`
26+ InstanceId uint64 `json:"InstanceId"`
27+ } `json:"in"`
28+ Out struct {
29+ Address sdk.AccAddress `json:"address"`
30+ } `json:"out"`
31+ }
32+ var specs []Spec
33+ require .NoError (t , json .Unmarshal ([]byte (goldenMasterClassicContractAddr ), & specs ))
34+ require .NotEmpty (t , specs )
35+ // run test on prepared test data
36+ for i , spec := range specs {
37+ t .Run (fmt .Sprintf ("case %d" , i ), func (t * testing.T ) {
38+ // when
39+ gotAddr := BuildContractAddressClassic (spec .In .CodeId , spec .In .InstanceId )
40+ // then
41+ require .Equal (t , spec .Out .Address .String (), gotAddr .String ())
42+ require .NoError (t , sdk .VerifyAddressFormat (gotAddr ))
43+ })
44+ }
45+ }
46+
47+ const goldenMasterClassicContractAddr = `[
48+ {
49+ "in": {
50+ "codeId": 0,
51+ "instanceId": 0
52+ },
53+ "out": {
54+ "address": "juno1w0w8sasnut0jx0vvsnvlc8nayq0q2ej8xgrpwgel05tn6wy4r57qytf73z"
55+ }
56+ },
57+ {
58+ "in": {
59+ "codeId": 0,
60+ "instanceId": 1
61+ },
62+ "out": {
63+ "address": "juno156r47kpk4va938pmtpuee4fh77847gqcw2dmpl2nnpwztwfgz04sej49ew"
64+ }
65+ },
66+ {
67+ "in": {
68+ "codeId": 1,
69+ "instanceId": 0
70+ },
71+ "out": {
72+ "address": "juno1mzdhwvvh22wrt07w59wxyd58822qavwkx5lcej7aqfkpqqlhaqfsenlwu2"
73+ }
74+ },
75+ {
76+ "in": {
77+ "codeId": 1,
78+ "instanceId": 1
79+ },
80+ "out": {
81+ "address": "juno14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9skjuwg8"
82+ }
83+ }
84+ ]`
85+
86+ func TestBuildContractAddressPredictable (t * testing.T ) {
1587 x , y := sdk .GetConfig ().GetBech32AccountAddrPrefix (), sdk .GetConfig ().GetBech32AccountPubPrefix ()
1688 t .Cleanup (func () {
1789 sdk .GetConfig ().SetBech32PrefixForAccount (x , y )
0 commit comments