From f4be7bf92253cb2f7d8541e2143b17d9d769d01f Mon Sep 17 00:00:00 2001 From: Alexey Semenyuk Date: Thu, 21 Mar 2024 21:37:57 +0500 Subject: [PATCH] Make DeployContract as const Signed-off-by: Alexey Semenyuk --- internal/apiserver/route_post_contract_deploy_test.go | 4 ++-- internal/blockchain/ethereum/ethereum.go | 6 ++---- internal/blockchain/ethereum/ethereum_test.go | 6 +++--- internal/blockchain/fabric/fabric_test.go | 4 ++-- internal/blockchain/tezos/tezos.go | 7 +++---- internal/blockchain/tezos/tezos_test.go | 6 +++--- pkg/core/constants.go | 7 ++++++- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/internal/apiserver/route_post_contract_deploy_test.go b/internal/apiserver/route_post_contract_deploy_test.go index 85ec40835f..327cab6110 100644 --- a/internal/apiserver/route_post_contract_deploy_test.go +++ b/internal/apiserver/route_post_contract_deploy_test.go @@ -1,4 +1,4 @@ -// Copyright © 2022 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -40,7 +40,7 @@ func TestPostContractDeploy(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mcm.On("DeployContract", mock.Anything, mock.MatchedBy(func(req *core.ContractDeployRequest) bool { + mcm.On(core.DeployContract, mock.Anything, mock.MatchedBy(func(req *core.ContractDeployRequest) bool { return true }), false).Return("banana", nil) r.ServeHTTP(res, req) diff --git a/internal/blockchain/ethereum/ethereum.go b/internal/blockchain/ethereum/ethereum.go index 8e63591d0c..52780213bc 100644 --- a/internal/blockchain/ethereum/ethereum.go +++ b/internal/blockchain/ethereum/ethereum.go @@ -735,7 +735,7 @@ func (e *Ethereum) DeployContract(ctx context.Context, nsOpID, signingKey string e.metrics.BlockchainContractDeployment() } headers := EthconnectMessageHeaders{ - Type: "DeployContract", + Type: core.DeployContract, ID: nsOpID, } body := map[string]interface{}{ @@ -745,9 +745,7 @@ func (e *Ethereum) DeployContract(ctx context.Context, nsOpID, signingKey string "definition": definition, "contract": contract, } - if signingKey != "" { - body["from"] = signingKey - } + body, err = e.applyOptions(ctx, body, options) if err != nil { return true, err diff --git a/internal/blockchain/ethereum/ethereum_test.go b/internal/blockchain/ethereum/ethereum_test.go index c2cae7a23e..9e2d1824a6 100644 --- a/internal/blockchain/ethereum/ethereum_test.go +++ b/internal/blockchain/ethereum/ethereum_test.go @@ -1,4 +1,4 @@ -// Copyright © 2023 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -2604,7 +2604,7 @@ func TestDeployContractOK(t *testing.T) { json.NewDecoder(req.Body).Decode(&body) params := body["params"].([]interface{}) headers := body["headers"].(map[string]interface{}) - assert.Equal(t, "DeployContract", headers["type"]) + assert.Equal(t, core.DeployContract, headers["type"]) assert.Equal(t, float64(1), params[0]) assert.Equal(t, "1000000000000000000000000", params[1]) assert.Equal(t, body["customOption"].(string), "customValue") @@ -2686,7 +2686,7 @@ func TestDeployContractInvalidOption(t *testing.T) { json.NewDecoder(req.Body).Decode(&body) params := body["params"].([]interface{}) headers := body["headers"].(map[string]interface{}) - assert.Equal(t, "DeployContract", headers["type"]) + assert.Equal(t, core.DeployContract, headers["type"]) assert.Equal(t, float64(1), params[0]) assert.Equal(t, "1000000000000000000000000", params[1]) assert.Equal(t, body["customOption"].(string), "customValue") diff --git a/internal/blockchain/fabric/fabric_test.go b/internal/blockchain/fabric/fabric_test.go index bc4b2cd422..ac18e14812 100644 --- a/internal/blockchain/fabric/fabric_test.go +++ b/internal/blockchain/fabric/fabric_test.go @@ -1,4 +1,4 @@ -// Copyright © 2023 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -2529,7 +2529,7 @@ func TestDeployContractOK(t *testing.T) { json.NewDecoder(req.Body).Decode(&body) params := body["params"].([]interface{}) headers := body["headers"].(map[string]interface{}) - assert.Equal(t, "DeployContract", headers["type"]) + assert.Equal(t, core.DeployContract, headers["type"]) assert.Equal(t, float64(1), params[0]) assert.Equal(t, "1000000000000000000000000", params[1]) assert.Equal(t, body["customOption"].(string), "customValue") diff --git a/internal/blockchain/tezos/tezos.go b/internal/blockchain/tezos/tezos.go index 2707d8c88b..3d468793de 100644 --- a/internal/blockchain/tezos/tezos.go +++ b/internal/blockchain/tezos/tezos.go @@ -315,16 +315,15 @@ func (t *Tezos) DeployContract(ctx context.Context, nsOpID, signingKey string, d t.metrics.BlockchainContractDeployment() } headers := TezosconnectMessageHeaders{ - Type: "DeployContract", + Type: core.DeployContract, ID: nsOpID, } body := map[string]interface{}{ "headers": &headers, "contract": contract, + "from": signingKey, } - if signingKey != "" { - body["from"] = signingKey - } + body, err = t.applyOptions(ctx, body, options) if err != nil { return true, err diff --git a/internal/blockchain/tezos/tezos_test.go b/internal/blockchain/tezos/tezos_test.go index b1df5bac20..675f2f3843 100644 --- a/internal/blockchain/tezos/tezos_test.go +++ b/internal/blockchain/tezos/tezos_test.go @@ -1,4 +1,4 @@ -// Copyright © 2023 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -990,7 +990,7 @@ func TestDeployContractOK(t *testing.T) { var body map[string]interface{} json.NewDecoder(req.Body).Decode(&body) headers := body["headers"].(map[string]interface{}) - assert.Equal(t, "DeployContract", headers["type"]) + assert.Equal(t, core.DeployContract, headers["type"]) assert.Equal(t, "123", headers["id"]) assert.Equal(t, contract, body["contract"]) return httpmock.NewJsonResponderOrPanic(200, "")(req) @@ -1048,7 +1048,7 @@ func TestDeployContractInvalidOption(t *testing.T) { var body map[string]interface{} json.NewDecoder(req.Body).Decode(&body) headers := body["headers"].(map[string]interface{}) - assert.Equal(t, "DeployContract", headers["type"]) + assert.Equal(t, core.DeployContract, headers["type"]) assert.Equal(t, "123", headers["id"]) assert.Equal(t, contract, body["contract"]) return httpmock.NewJsonResponderOrPanic(200, "")(req) diff --git a/pkg/core/constants.go b/pkg/core/constants.go index 2c73d82bf3..512c5a15eb 100644 --- a/pkg/core/constants.go +++ b/pkg/core/constants.go @@ -1,4 +1,4 @@ -// Copyright © 2023 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -62,3 +62,8 @@ const ( // SystemTagIdentityUpdate is the tag for messages that broadcast an identity update SystemTagIdentityUpdate = "ff_identity_update" ) + +const ( + // DeployContract is the header for DeployContract request + DeployContract = "DeployContract" +)