From 2d58ba6ea65b9b8cb7dba904d26d8a2fcf41a83e 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 | 2 +- internal/blockchain/ethereum/ethereum.go | 6 ++---- internal/blockchain/ethereum/ethereum_test.go | 4 ++-- internal/blockchain/fabric/fabric_test.go | 2 +- internal/blockchain/tezos/tezos.go | 7 +++---- internal/blockchain/tezos/tezos_test.go | 4 ++-- pkg/core/constants.go | 5 +++++ 7 files changed, 16 insertions(+), 14 deletions(-) diff --git a/internal/apiserver/route_post_contract_deploy_test.go b/internal/apiserver/route_post_contract_deploy_test.go index 85ec40835f..ba963479bd 100644 --- a/internal/apiserver/route_post_contract_deploy_test.go +++ b/internal/apiserver/route_post_contract_deploy_test.go @@ -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..8df82e7e66 100644 --- a/internal/blockchain/ethereum/ethereum_test.go +++ b/internal/blockchain/ethereum/ethereum_test.go @@ -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..694c510df6 100644 --- a/internal/blockchain/fabric/fabric_test.go +++ b/internal/blockchain/fabric/fabric_test.go @@ -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..b00aa161b9 100644 --- a/internal/blockchain/tezos/tezos_test.go +++ b/internal/blockchain/tezos/tezos_test.go @@ -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..3789e8f8cd 100644 --- a/pkg/core/constants.go +++ b/pkg/core/constants.go @@ -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" +)