Make contract addresses predictable
This commit is contained in:
@@ -2,6 +2,7 @@ package keeper
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -116,9 +117,8 @@ func TestInstantiateProposal(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// then
|
||||
contractAddr, err := sdk.AccAddressFromBech32("cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr")
|
||||
require.NoError(t, err)
|
||||
|
||||
codeHash := keepers.WasmKeeper.GetCodeInfo(ctx, 1).CodeHash
|
||||
contractAddr := BuildContractAddress(codeHash, oneAddress, "testing")
|
||||
cInfo := wasmKeeper.GetContractInfo(ctx, contractAddr)
|
||||
require.NotNil(t, cInfo)
|
||||
assert.Equal(t, uint64(1), cInfo.CodeID)
|
||||
@@ -188,9 +188,8 @@ func TestInstantiateProposal_NoAdmin(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// then
|
||||
contractAddr, err := sdk.AccAddressFromBech32("cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr")
|
||||
require.NoError(t, err)
|
||||
|
||||
codeHash := keepers.WasmKeeper.GetCodeInfo(ctx, 1).CodeHash
|
||||
contractAddr := BuildContractAddress(codeHash, oneAddress, "testing")
|
||||
cInfo := wasmKeeper.GetContractInfo(ctx, contractAddr)
|
||||
require.NotNil(t, cInfo)
|
||||
assert.Equal(t, uint64(1), cInfo.CodeID)
|
||||
@@ -229,9 +228,9 @@ func TestMigrateProposal(t *testing.T) {
|
||||
require.NoError(t, wasmKeeper.importCode(ctx, 2, codeInfoFixture, wasmCode))
|
||||
|
||||
var (
|
||||
anyAddress sdk.AccAddress = bytes.Repeat([]byte{0x1}, types.ContractAddrLen)
|
||||
otherAddress sdk.AccAddress = bytes.Repeat([]byte{0x2}, types.ContractAddrLen)
|
||||
contractAddr = BuildContractAddress(1, 1)
|
||||
anyAddress = DeterministicAccountAddress(t, 1)
|
||||
otherAddress = DeterministicAccountAddress(t, 2)
|
||||
contractAddr = BuildContractAddress(codeInfoFixture.CodeHash, RandomAccountAddress(t), "")
|
||||
)
|
||||
|
||||
contractInfoFixture := types.ContractInfoFixture(func(c *types.ContractInfo) {
|
||||
@@ -408,12 +407,13 @@ func TestSudoProposal(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAdminProposals(t *testing.T) {
|
||||
var (
|
||||
otherAddress sdk.AccAddress = bytes.Repeat([]byte{0x2}, types.ContractAddrLen)
|
||||
contractAddr = BuildContractAddress(1, 1)
|
||||
)
|
||||
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
|
||||
require.NoError(t, err)
|
||||
var (
|
||||
otherAddress = DeterministicAccountAddress(t, 2)
|
||||
codeHash = sha256.Sum256(wasmCode)
|
||||
contractAddr = BuildContractAddress(codeHash[:], RandomAccountAddress(t), "")
|
||||
)
|
||||
|
||||
specs := map[string]struct {
|
||||
state types.ContractInfo
|
||||
|
||||
Reference in New Issue
Block a user