|
1 | 1 | package keeper
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "encoding/hex" |
4 | 5 | "encoding/json"
|
5 | 6 | "fmt"
|
6 | 7 | "testing"
|
7 | 8 |
|
8 | 9 | tmbytes "github.com/cometbft/cometbft/libs/bytes"
|
| 10 | + "github.com/stretchr/testify/assert" |
9 | 11 | "github.com/stretchr/testify/require"
|
10 | 12 |
|
11 | 13 | sdk "github.com/cosmos/cosmos-sdk/types"
|
| 14 | + |
| 15 | + "github.com/CosmWasm/wasmd/x/wasm/types" |
12 | 16 | )
|
13 | 17 |
|
14 | 18 | func prepareCleanup(t *testing.T) {
|
@@ -69,6 +73,24 @@ func TestBuildContractAddressClassic(t *testing.T) {
|
69 | 73 | }
|
70 | 74 | }
|
71 | 75 |
|
| 76 | +func TestBuildContractAddressPredictableShort(t *testing.T) { |
| 77 | + types.ContractAddrLen = 20 |
| 78 | + // reset to default value after test completion |
| 79 | + defer func() { types.ContractAddrLen = 32 }() |
| 80 | + |
| 81 | + checksum, err := hex.DecodeString("13a1fc994cc6d1c81b746ee0c0ff6f90043875e0bf1d9be6b7d779fc978dc2a5") |
| 82 | + require.NoError(t, err) |
| 83 | + creator, err := sdk.AccAddressFromHexUnsafe("9999999999aaaaaaaaaabbbbbbbbbbcccccccccc") |
| 84 | + require.NoError(t, err) |
| 85 | + salt, err := hex.DecodeString("61") |
| 86 | + require.NoError(t, err) |
| 87 | + expAddr, err := sdk.AccAddressFromHexUnsafe("5e865d3e45ad3e961f77fd77d46543417ced44d9") |
| 88 | + require.NoError(t, err) |
| 89 | + |
| 90 | + addr := BuildContractAddressPredictable(checksum, creator, salt, []byte{}) |
| 91 | + assert.Equal(t, expAddr, addr) |
| 92 | +} |
| 93 | + |
72 | 94 | func TestBuildContractAddressPredictable(t *testing.T) {
|
73 | 95 | // set cleanup function
|
74 | 96 | prepareCleanup(t)
|
|
0 commit comments