diff --git a/app/app.go b/app/app.go index c52cd692..c97955b2 100644 --- a/app/app.go +++ b/app/app.go @@ -400,7 +400,7 @@ func NewTgradeApp( govRouter, wasmDir, twasmConfig, - supportedFeatures, + availableCapabilities, wasmOpts..., ) diff --git a/testing/main_test.go b/testing/main_test.go index 0bb53e95..e4600edc 100644 --- a/testing/main_test.go +++ b/testing/main_test.go @@ -140,7 +140,7 @@ func encodeBech32Addr(src []byte) string { // ContractBech32Address build a tgrade bech32 contract address func ContractBech32Address(codeID, instanceID uint64) string { - return encodeBech32Addr(wasmkeeper.BuildContractAddress(codeID, instanceID)) + return encodeBech32Addr(wasmkeeper.BuildContractAddressClassic(codeID, instanceID)) } func AwaitValsetEpochCompleted(t *testing.T) { diff --git a/x/poe/bootstrap_test.go b/x/poe/bootstrap_test.go index f347ecf5..55d86f6b 100644 --- a/x/poe/bootstrap_test.go +++ b/x/poe/bootstrap_test.go @@ -29,15 +29,15 @@ import ( func TestBootstrapPoEContracts(t *testing.T) { t.Skip() var ( - engagementContractAddr = wasmkeeper.BuildContractAddress(1, 1) - ocContractAddr = wasmkeeper.BuildContractAddress(2, 2) - stakingContractAdddr = wasmkeeper.BuildContractAddress(3, 3) - mixerContractAddr = wasmkeeper.BuildContractAddress(4, 4) - communityPoolContractAddr = wasmkeeper.BuildContractAddress(5, 5) - valsetContractAddr = wasmkeeper.BuildContractAddress(6, 6) - distributionContractAddr = wasmkeeper.BuildContractAddress(1, 6) // created by a contract so not really persisted - ocGovProposalContractAddr = wasmkeeper.BuildContractAddress(7, 7) // instanceID = 7 - valVotingContractAddr = wasmkeeper.BuildContractAddress(8, 8) + engagementContractAddr = wasmkeeper.BuildContractAddressClassic(1, 1) + ocContractAddr = wasmkeeper.BuildContractAddressClassic(2, 2) + stakingContractAdddr = wasmkeeper.BuildContractAddressClassic(3, 3) + mixerContractAddr = wasmkeeper.BuildContractAddressClassic(4, 4) + communityPoolContractAddr = wasmkeeper.BuildContractAddressClassic(5, 5) + valsetContractAddr = wasmkeeper.BuildContractAddressClassic(6, 6) + distributionContractAddr = wasmkeeper.BuildContractAddressClassic(1, 6) // created by a contract so not really persisted + ocGovProposalContractAddr = wasmkeeper.BuildContractAddressClassic(7, 7) // instanceID = 7 + valVotingContractAddr = wasmkeeper.BuildContractAddressClassic(8, 8) ) var ( defaultLimit uint64 = 20 diff --git a/x/poe/contract/tg4_engagement_integration_test.go b/x/poe/contract/tg4_engagement_integration_test.go index e652fcc5..023497ae 100644 --- a/x/poe/contract/tg4_engagement_integration_test.go +++ b/x/poe/contract/tg4_engagement_integration_test.go @@ -3,9 +3,10 @@ package contract_test import ( _ "embed" "encoding/json" + "testing" + "github.com/confio/tgrade/x/poe" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "testing" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" @@ -26,7 +27,7 @@ func TestEngagementUpdateAdmin(t *testing.T) { var bootstrapAccountAddr sdk.AccAddress = rand.Bytes(address.Len) k := example.TWasmKeeper.GetContractKeeper() - codeID, err := k.Create(ctx, bootstrapAccountAddr, tg4Engagement, nil) + codeID, _, err := k.Create(ctx, bootstrapAccountAddr, tg4Engagement, nil) require.NoError(t, err) var newAddress sdk.AccAddress = rand.Bytes(address.Len) diff --git a/x/poe/contract/tgrade_trusted_circle_integration_test.go b/x/poe/contract/tgrade_trusted_circle_integration_test.go index 91dfe4d7..4d78c5cc 100644 --- a/x/poe/contract/tgrade_trusted_circle_integration_test.go +++ b/x/poe/contract/tgrade_trusted_circle_integration_test.go @@ -41,7 +41,7 @@ func TestInitTrustedCircle(t *testing.T) { initBz, err := json.Marshal(init) require.NoError(t, err) t.Log(string(initBz)) - codeID, err := contractKeeper.Create(ctx, creator, tgTrustedCircles, nil) + codeID, _, err := contractKeeper.Create(ctx, creator, tgTrustedCircles, nil) require.NoError(t, err) // when contractAddr, _, err := contractKeeper.Instantiate(ctx, codeID, creator, nil, initBz, "poe", sdk.NewCoins(depositAmount)) diff --git a/x/poe/contract/tgrade_validator_voting_integration_test.go b/x/poe/contract/tgrade_validator_voting_integration_test.go index 08926bd6..f630ea96 100644 --- a/x/poe/contract/tgrade_validator_voting_integration_test.go +++ b/x/poe/contract/tgrade_validator_voting_integration_test.go @@ -53,7 +53,7 @@ func TestValidatorsGovProposal(t *testing.T) { var maxDuration int64 = 6000000 // upload any contract that is not pinned - codeID, err := contractKeeper.Create(ctx, anyAddress, validatorVotingContract, nil) + codeID, _, err := contractKeeper.Create(ctx, anyAddress, validatorVotingContract, nil) require.NoError(t, err) require.False(t, example.TWasmKeeper.IsPinnedCode(ctx, codeID), "pinned") specs := map[string]struct { diff --git a/x/twasm/address_utils.go b/x/twasm/address_utils.go index a94fc26b..69d3595c 100644 --- a/x/twasm/address_utils.go +++ b/x/twasm/address_utils.go @@ -7,5 +7,5 @@ import ( // ContractAddress generator function. Same as in wasm func ContractAddress(codeID, instanceID uint64) sdk.AccAddress { - return wasmkeeper.BuildContractAddress(codeID, instanceID) + return wasmkeeper.BuildContractAddressClassic(codeID, instanceID) } diff --git a/x/twasm/keeper/genesis_test.go b/x/twasm/keeper/genesis_test.go index d36e67b3..efb6bfa5 100644 --- a/x/twasm/keeper/genesis_test.go +++ b/x/twasm/keeper/genesis_test.go @@ -340,5 +340,5 @@ func setContractPrivilege(t *testing.T, ctx sdk.Context, keepers TestKeepers, co // genContractAddress generates a contract address as wasmd keeper does func genContractAddress(codeID, instanceID uint64) sdk.AccAddress { - return wasmkeeper.BuildContractAddress(codeID, instanceID) + return wasmkeeper.BuildContractAddressClassic(codeID, instanceID) } diff --git a/x/twasm/testing/contract_keeper_mock.go b/x/twasm/testing/contract_keeper_mock.go index 213d836d..e948879b 100644 --- a/x/twasm/testing/contract_keeper_mock.go +++ b/x/twasm/testing/contract_keeper_mock.go @@ -11,7 +11,7 @@ var _ wasmtypes.ContractOpsKeeper = &ContractOpsKeeperMock{} // ContractOpsKeeperMock implements wasmtypes.ContractOpsKeeper for testing purpose type ContractOpsKeeperMock struct { - CreateFn func(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte, instantiateAccess *wasmtypes.AccessConfig) (codeID uint64, err error) + CreateFn func(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte, instantiateAccess *wasmtypes.AccessConfig) (codeID uint64, checksum []byte, err error) InstantiateFn func(ctx sdk.Context, codeID uint64, creator, admin sdk.AccAddress, initMsg []byte, label string, deposit sdk.Coins) (sdk.AccAddress, []byte, error) ExecuteFn func(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) MigrateFn func(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newCodeID uint64, msg []byte) ([]byte, error) @@ -24,7 +24,7 @@ type ContractOpsKeeperMock struct { SetAccessConfigFn func(ctx sdk.Context, codeID uint64, config wasmtypes.AccessConfig) error } -func (m ContractOpsKeeperMock) Create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte, instantiateAccess *wasmtypes.AccessConfig) (codeID uint64, err error) { +func (m ContractOpsKeeperMock) Create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte, instantiateAccess *wasmtypes.AccessConfig) (codeID uint64, checksum []byte, err error) { if m.CreateFn == nil { panic("not expected to be called") } diff --git a/x/twasm/types/wasm_genesis_helper.go b/x/twasm/types/wasm_genesis_helper.go deleted file mode 100644 index 85fbf4d4..00000000 --- a/x/twasm/types/wasm_genesis_helper.go +++ /dev/null @@ -1,115 +0,0 @@ -package types - -import ( - "bytes" - "crypto/sha256" - "fmt" - - "github.com/CosmWasm/wasmd/x/wasm/keeper" - - "github.com/CosmWasm/wasmd/x/wasm/types" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// Copy pasted from Wasmd - https://github.com/CosmWasm/wasmd/blob/master/x/wasm/client/cli/genesis_msg.go - -type codeMeta struct { - CodeID uint64 `json:"code_id"` - Info types.CodeInfo `json:"info"` -} - -func getAllCodes(state *types.GenesisState) ([]codeMeta, error) { - all := make([]codeMeta, len(state.Codes)) - for i, c := range state.Codes { - all[i] = codeMeta{ - CodeID: c.CodeID, - Info: c.CodeInfo, - } - } - // add inflight - seq := codeSeqValue(state) - for _, m := range state.GenMsgs { - if msg := m.GetStoreCode(); msg != nil { - var accessConfig types.AccessConfig - if msg.InstantiatePermission != nil { - accessConfig = *msg.InstantiatePermission - } else { - // default - creator, err := sdk.AccAddressFromBech32(msg.Sender) - if err != nil { - return nil, fmt.Errorf("sender: %s", err) - } - accessConfig = state.Params.InstantiateDefaultPermission.With(creator) - } - hash := sha256.Sum256(msg.WASMByteCode) - all = append(all, codeMeta{ - CodeID: seq, - Info: types.CodeInfo{ - CodeHash: hash[:], - Creator: msg.Sender, - InstantiateConfig: accessConfig, - }, - }) - seq++ - } - } - return all, nil -} - -type contractMeta struct { - ContractAddress string `json:"contract_address"` - Info types.ContractInfo `json:"info"` -} - -func getAllContracts(state *types.GenesisState) []contractMeta { - all := make([]contractMeta, len(state.Contracts)) - for i, c := range state.Contracts { - all[i] = contractMeta{ - ContractAddress: c.ContractAddress, - Info: c.ContractInfo, - } - } - // add inflight - seq := contractSeqValue(state) - for _, m := range state.GenMsgs { - if msg := m.GetInstantiateContract(); msg != nil { - all = append(all, contractMeta{ - ContractAddress: keeper.BuildContractAddress(msg.CodeID, seq).String(), - Info: types.ContractInfo{ - CodeID: msg.CodeID, - Creator: msg.Sender, - Admin: msg.Admin, - Label: msg.Label, - }, - }) - seq++ - } - } - return all -} - -// contractSeqValue reads the contract sequence from the genesis or -// returns default start value used in the keeper -func contractSeqValue(state *types.GenesisState) uint64 { - var seq uint64 = 1 - for _, s := range state.Sequences { - if bytes.Equal(s.IDKey, types.KeyLastInstanceID) { - seq = s.Value - break - } - } - return seq -} - -// codeSeqValue reads the code sequence from the genesis or -// returns default start value used in the keeper -func codeSeqValue(state *types.GenesisState) uint64 { - var seq uint64 = 1 - for _, s := range state.Sequences { - if bytes.Equal(s.IDKey, types.KeyLastCodeID) { - seq = s.Value - break - } - } - return seq -}