Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions sdk/node_create_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type NodeCreateTransaction struct {
description string
gossipEndpoints []Endpoint
serviceEndpoints []Endpoint
gossipCaCertificate *[]byte
gossipCaCertificate []byte
grpcCertificateHash []byte
adminKey Key
declineReward *bool
Expand Down Expand Up @@ -80,7 +80,7 @@ func _NodeCreateTransactionFromProtobuf(tx Transaction[*NodeCreateTransaction],
description: pb.GetNodeCreate().GetDescription(),
gossipEndpoints: gossipEndpoints,
serviceEndpoints: serviceEndpoints,
gossipCaCertificate: &gossipCaCertificate,
gossipCaCertificate: gossipCaCertificate,
grpcCertificateHash: pb.GetNodeCreate().GetGrpcCertificateHash(),
adminKey: adminKey,
declineReward: &declineReward,
Expand Down Expand Up @@ -160,17 +160,14 @@ func (tx *NodeCreateTransaction) AddServiceEndpoint(endpoint Endpoint) *NodeCrea

// GetGossipCaCertificate the certificate used to sign gossip events.
func (tx *NodeCreateTransaction) GetGossipCaCertificate() []byte {
if tx.gossipCaCertificate == nil {
return []byte{}
}
return *tx.gossipCaCertificate
return tx.gossipCaCertificate
}

// SetGossipCaCertificate the certificate used to sign gossip events.
// This value MUST be the DER encoding of the certificate presented.
func (tx *NodeCreateTransaction) SetGossipCaCertificate(gossipCaCertificate []byte) *NodeCreateTransaction {
tx._RequireNotFrozen()
tx.gossipCaCertificate = &gossipCaCertificate
tx.gossipCaCertificate = gossipCaCertificate
return tx
}

Expand Down Expand Up @@ -287,7 +284,7 @@ func (tx NodeCreateTransaction) buildProtoBody() *services.NodeCreateTransaction
}

if tx.gossipCaCertificate != nil {
body.GossipCaCertificate = *tx.gossipCaCertificate
body.GossipCaCertificate = tx.gossipCaCertificate
}

if tx.grpcCertificateHash != nil {
Expand Down Expand Up @@ -336,7 +333,7 @@ func (tx NodeCreateTransaction) validateTransactionFields() error {
}
}

if tx.gossipCaCertificate != nil && len(*tx.gossipCaCertificate) == 0 {
if tx.gossipCaCertificate != nil && len(tx.gossipCaCertificate) == 0 {
return errGossipCaCertificateEmpty
}

Expand Down
9 changes: 7 additions & 2 deletions sdk/node_delete_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ func (tx NodeDeleteTransaction) buildProtoBody() *services.NodeDeleteTransaction

if tx.nodeID != nil {
body.NodeId = *tx.nodeID
} else {
tx.freezeError = errNodeIdIsRequired
}
return body
}
Expand All @@ -110,6 +108,13 @@ func (tx NodeDeleteTransaction) getMethod(channel *_Channel) _Method {
}
}

func (tx NodeDeleteTransaction) validateTransactionFields() error {
if tx.nodeID == nil {
return errNodeIdIsRequired
}
return nil
}

func (tx NodeDeleteTransaction) constructScheduleProtobuf() (*services.SchedulableTransactionBody, error) {
return tx.buildScheduled()
}
Expand Down
8 changes: 3 additions & 5 deletions sdk/node_delete_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,11 @@ func TestUnitNodeDeleteTransactionFailsWenNodeIDIsNotSet(t *testing.T) {
nodeAccountID := []AccountID{{Account: 10}}
transactionID := TransactionIDGenerate(AccountID{Account: 324})

transaction, err := NewNodeDeleteTransaction().
_, err := NewNodeDeleteTransaction().
SetTransactionID(transactionID).
SetNodeAccountIDs(nodeAccountID).
Freeze()

require.NoError(t, err)

require.Error(t, transaction.freezeError)
assert.ErrorIs(t, errNodeIdIsRequired, transaction.freezeError)
require.Error(t, err)
assert.ErrorIs(t, errNodeIdIsRequired, err)
}
37 changes: 35 additions & 2 deletions sdk/node_update_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,6 @@

if tx.nodeID != nil {
body.NodeId = *tx.nodeID
} else {
tx.freezeError = errNodeIdIsRequired
}

if tx.accountID != nil {
Expand Down Expand Up @@ -366,6 +364,41 @@
}
}

func (tx NodeUpdateTransaction) validateTransactionFields() error {

Check warning on line 367 in sdk/node_update_transaction.go

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sdk/node_update_transaction.go#L367

Method validateTransactionFields has a cyclomatic complexity of 12 (limit is 8)
if len(tx.gossipEndpoints) > 10 {
return errTooManyGossipEndpoints
}
for _, endpoint := range tx.gossipEndpoints {
if err := endpoint.Validate(); err != nil {
return err
}
}

if len(tx.serviceEndpoints) > 8 {
return errTooManyServiceEndpoints
}
for _, endpoint := range tx.serviceEndpoints {
if err := endpoint.Validate(); err != nil {
return err
}
}

if tx.gossipCaCertificate != nil && len(tx.gossipCaCertificate) == 0 {
return errGossipCaCertificateEmpty
}

if tx.description != "" {
if len(tx.description) > 100 {
return errDescriptionTooLong
}
}

if tx.nodeID == nil {
return errNodeIdIsRequired
}
return nil
}

func (tx NodeUpdateTransaction) constructScheduleProtobuf() (*services.SchedulableTransactionBody, error) {
return tx.buildScheduled()
}
Expand Down
12 changes: 2 additions & 10 deletions sdk/node_update_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,19 +431,11 @@ func TestUnitNodeUpdateTransactionFailsWenNodeIDIsNotSet(t *testing.T) {
nodeAccountID := []AccountID{{Account: 10}}
transactionID := TransactionIDGenerate(AccountID{Account: 324})

transaction, err := NewNodeUpdateTransaction().
_, err := NewNodeUpdateTransaction().
SetTransactionID(transactionID).
SetNodeAccountIDs(nodeAccountID).
Freeze()
require.NoError(t, err)

require.Error(t, transaction.freezeError)
assert.ErrorIs(t, errNodeIdIsRequired, transaction.freezeError)

client, err := _NewMockClient()
client.SetLedgerID(*NewLedgerIDTestnet())
require.NoError(t, err)

_, err = transaction.Execute(client)
require.Error(t, err)
assert.ErrorIs(t, errNodeIdIsRequired, err)
}
2 changes: 2 additions & 0 deletions tck/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ func main() {
"signSchedule": postHandler(HandleError, handler.New(scheduleService.SignSchedule)),
"createNode": postHandler(HandleError, handler.New(nodeService.CreateNode)),
"executeContract": postHandler(HandleError, handler.New(contractService.ExecuteContract)),
"updateNode": postHandler(HandleError, handler.New(nodeService.UpdateNode)),
"deleteNode": postHandler(HandleError, handler.New(nodeService.DeleteNode)),
"generateKey": postHandler(HandleError, handler.New(methods.GenerateKey)),
}

Expand Down
2 changes: 1 addition & 1 deletion tck/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/creachadair/jrpc2 v1.3.2
github.com/hiero-ledger/hiero-sdk-go/v2 v2.66.0
github.com/joho/godotenv v1.5.1
github.com/stretchr/testify v1.11.0
github.com/stretchr/testify v1.11.1
)

replace github.com/hiero-ledger/hiero-sdk-go/v2 => ../
Expand Down
4 changes: 2 additions & 2 deletions tck/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.11.0 h1:ib4sjIrwZKxE5u/Japgo/7SJV3PvgjGiRNAvTVGqQl8=
github.com/stretchr/testify v1.11.0/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM=
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI=
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
Expand Down
131 changes: 131 additions & 0 deletions tck/methods/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import (
"context"
"encoding/hex"
"errors"
"strconv"

"github.com/hiero-ledger/hiero-sdk-go/tck/param"
Expand Down Expand Up @@ -107,6 +108,136 @@
return &response.NodeResponse{NodeId: nodeId, Status: receipt.Status.String()}, nil
}

func (n *NodeService) UpdateNode(_ context.Context, params param.UpdateNodeParams) (*response.NodeResponse, error) {

Check warning on line 111 in tck/methods/node.go

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tck/methods/node.go#L111

Method UpdateNode has 83 lines of code (limit is 50)

Check failure on line 111 in tck/methods/node.go

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tck/methods/node.go#L111

Method UpdateNode has a cyclomatic complexity of 25 (limit is 12)
transaction := hiero.NewNodeUpdateTransaction().SetGrpcDeadline(&threeSecondsDuration)

if params.NodeId != nil {
nodeId, err := strconv.ParseUint(*params.NodeId, 10, 64)
if err != nil {
return nil, err
}
transaction.SetNodeID(nodeId)
}

if err := utils.SetAccountIDIfPresent(params.AccountId, transaction.SetAccountID); err != nil {
return nil, err
}

if params.Description != nil {
transaction.SetDescription(*params.Description)
}

if params.GossipEndpoints != nil {
if len(*params.GossipEndpoints) == 0 {
return nil, errors.New("gossip endpoints must not be empty")
}
for _, endpointParam := range *params.GossipEndpoints {
endpoint, err := convertEndpointParam(endpointParam)
if err != nil {
return nil, err
}
transaction.AddGossipEndpoint(endpoint)
}
}

if params.ServiceEndpoints != nil {
if len(*params.ServiceEndpoints) == 0 {
return nil, errors.New("service endpoints must not be empty")
}
for _, endpointParam := range *params.ServiceEndpoints {
endpoint, err := convertEndpointParam(endpointParam)
if err != nil {
return nil, err
}
transaction.AddServiceEndpoint(endpoint)
}
}

if params.GossipCaCertificate != nil {
certBytes, err := hex.DecodeString(*params.GossipCaCertificate)
if err != nil {
return nil, err
}
transaction.SetGossipCaCertificate(certBytes)
}

if params.GrpcCertificateHash != nil {
hashBytes, err := hex.DecodeString(*params.GrpcCertificateHash)
if err != nil {
return nil, err
}
transaction.SetGrpcCertificateHash(hashBytes)
}

if err := utils.SetKeyIfPresent(params.AdminKey, transaction.SetAdminKey); err != nil {
return nil, err
}

if params.DeclineReward != nil {
transaction.SetDeclineReward(*params.DeclineReward)
}

if params.GrpcWebProxyEndpoint != nil {
endpoint, err := convertEndpointParam(*params.GrpcWebProxyEndpoint)
if err != nil {
return nil, err
}
transaction.SetGrpcWebProxyEndpoint(endpoint)
}

if params.CommonTransactionParams != nil {
err := params.CommonTransactionParams.FillOutTransaction(transaction, n.sdkService.Client)
if err != nil {
return nil, err
}
}

txResponse, err := transaction.Execute(n.sdkService.Client)
if err != nil {
return nil, err
}

receipt, err := txResponse.SetValidateStatus(true).GetReceipt(n.sdkService.Client)
if err != nil {
return nil, err
}

var nodeId = strconv.FormatUint(receipt.NodeID, 10)

return &response.NodeResponse{NodeId: nodeId, Status: receipt.Status.String()}, nil
}

func (n *NodeService) DeleteNode(_ context.Context, params param.DeleteNodeParams) (*response.NodeResponse, error) {
transaction := hiero.NewNodeDeleteTransaction().SetGrpcDeadline(&threeSecondsDuration)

if params.NodeId != nil {
nodeId, err := strconv.ParseUint(*params.NodeId, 10, 64)
if err != nil {
return nil, err
}
transaction.SetNodeID(nodeId)
}

if params.CommonTransactionParams != nil {
err := params.CommonTransactionParams.FillOutTransaction(transaction, n.sdkService.Client)
if err != nil {
return nil, err
}
}

txResponse, err := transaction.Execute(n.sdkService.Client)
if err != nil {
return nil, err
}

receipt, err := txResponse.SetValidateStatus(true).GetReceipt(n.sdkService.Client)
if err != nil {
return nil, err
}

return &response.NodeResponse{Status: receipt.Status.String()}, nil
}

func convertEndpointParam(endpointParam param.EndpointParams) (hiero.Endpoint, error) {
endpoint := hiero.Endpoint{}

Expand Down
18 changes: 18 additions & 0 deletions tck/param/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,21 @@ type CreateNodeParams struct {
GrpcWebProxyEndpoint *EndpointParams `json:"grpcWebProxyEndpoint,omitempty"`
CommonTransactionParams *CommonTransactionParams `json:"commonTransactionParams,omitempty"`
}
type UpdateNodeParams struct {
NodeId *string `json:"nodeId,omitempty"`
AccountId *string `json:"accountId,omitempty"`
Description *string `json:"description,omitempty"`
GossipEndpoints *[]EndpointParams `json:"gossipEndpoints,omitempty"`
ServiceEndpoints *[]EndpointParams `json:"serviceEndpoints,omitempty"`
GossipCaCertificate *string `json:"gossipCaCertificate,omitempty"`
GrpcCertificateHash *string `json:"grpcCertificateHash,omitempty"`
AdminKey *string `json:"adminKey,omitempty"`
DeclineReward *bool `json:"declineReward,omitempty"`
GrpcWebProxyEndpoint *EndpointParams `json:"grpcWebProxyEndpoint,omitempty"`
CommonTransactionParams *CommonTransactionParams `json:"commonTransactionParams,omitempty"`
}

type DeleteNodeParams struct {
NodeId *string `json:"nodeId,omitempty"`
CommonTransactionParams *CommonTransactionParams `json:"commonTransactionParams,omitempty"`
}
Loading