Skip to content

Commit

Permalink
Make DeployContract as const
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Semenyuk <[email protected]>
  • Loading branch information
alex-semenyuk committed Mar 21, 2024
1 parent 5ada2cf commit f4be7bf
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions internal/apiserver/route_post_contract_deploy_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions internal/blockchain/ethereum/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions internal/blockchain/ethereum/ethereum_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions internal/blockchain/fabric/fabric_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -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")
Expand Down
7 changes: 3 additions & 4 deletions internal/blockchain/tezos/tezos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions internal/blockchain/tezos/tezos_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion pkg/core/constants.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -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"
)

0 comments on commit f4be7bf

Please sign in to comment.