Skip to content

feat: add Aptos capability view proto helpers#1992

Merged
ilija42 merged 4 commits intomainfrom
feature/aptos-view-proto-helpers
Apr 22, 2026
Merged

feat: add Aptos capability view proto helpers#1992
ilija42 merged 4 commits intomainfrom
feature/aptos-view-proto-helpers

Conversation

@cawthorne
Copy link
Copy Markdown
Contributor

Summary

  • add shared pkg/capabilities/v2/chain-capabilities/aptos helpers for converting capability ViewPayload and TypeTag protos into Aptos domain types
  • move the Aptos read payload/type-tag conversion logic out of the capability implementation and into chainlink-common
  • preserve the current short-address left-padding behavior used by existing Aptos read callers while centralizing the validation in one place

Testing

  • GOWORK=off go test ./pkg/capabilities/v2/chain-capabilities/aptos -count=1

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 21, 2026

✅ API Diff Results - github.com/smartcontractkit/chainlink-common

✅ Compatible Changes (2)

pkg/capabilities/v2/chain-capabilities/aptos (2)
  • ConvertTypeTagFromProto — ➕ Added

  • ConvertViewPayloadFromProto — ➕ Added


📄 View full apidiff report

@cawthorne cawthorne marked this pull request as ready for review April 21, 2026 13:35
@cawthorne cawthorne requested review from a team as code owners April 21, 2026 13:35
Copilot AI review requested due to automatic review settings April 21, 2026 13:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds shared Aptos capability-view proto conversion helpers to map capability protos (ViewPayload, TypeTag) into Aptos domain types, centralizing validation and preserving short-address left-padding behavior.

Changes:

  • Introduce ConvertViewPayloadFromProto and ConvertTypeTagFromProto for capability protos → pkg/types/chains/aptos domain types.
  • Implement account-address left-padding (up to 32 bytes) during conversion.
  • Add unit tests covering nested tag conversion and several invalid-input cases.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
pkg/capabilities/v2/chain-capabilities/aptos/proto_helpers.go Implements proto→domain conversion helpers for Aptos view payloads and type tags, including short-address left-padding.
pkg/capabilities/v2/chain-capabilities/aptos/proto_helpers_test.go Adds tests for nested vector/struct/generic conversion and validation error cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +17 to +30
if payload.Module == nil {
return nil, fmt.Errorf("viewRequest.Payload.Module is required")
}
if payload.Module.Name == "" {
return nil, fmt.Errorf("viewRequest.Payload.Module.Name is required")
}
if payload.Function == "" {
return nil, fmt.Errorf("viewRequest.Payload.Function is required")
}

moduleAddress, err := convertAccountAddressFromProto(payload.Module.Address, "module")
if err != nil {
return nil, err
}
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

payload.Module.Address can be empty/nil; convertAccountAddressFromProto will then return the all-zero address without error. Since the module address is required to identify the view function, this should be rejected explicitly (e.g., require len(payload.Module.Address) > 0 and return a "...Module.Address is required" error) to avoid silently calling address 0x0.

Copilot uses AI. Check for mistakes.
Comment on lines +87 to +112
case TypeTagKind_TYPE_TAG_KIND_STRUCT:
structTag := tag.GetStruct()
if structTag == nil {
return nil, fmt.Errorf("struct tag missing struct value")
}

structAddress, err := convertAccountAddressFromProto(structTag.Address, "struct")
if err != nil {
return nil, err
}

typeParams := make([]typesaptos.TypeTag, 0, len(structTag.TypeParams))
for i, tp := range structTag.TypeParams {
converted, err := ConvertTypeTagFromProto(tp)
if err != nil {
return nil, fmt.Errorf("invalid struct type param at index %d: %w", i, err)
}
typeParams = append(typeParams, *converted)
}

return &typesaptos.TypeTag{Value: typesaptos.StructTag{
Address: structAddress,
Module: structTag.Module,
Name: structTag.Name,
TypeParams: typeParams,
}}, nil
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the STRUCT branch, structTag.Address is allowed to be empty (converted to 0x0) and structTag.Module/structTag.Name are not validated. A Move struct type is not well-formed without these fields, so this converter should enforce non-empty Address, Module, and Name and return a clear validation error when missing.

Copilot uses AI. Check for mistakes.
Comment on lines +15 to +24
return nil, fmt.Errorf("viewRequest.Payload is required")
}
if payload.Module == nil {
return nil, fmt.Errorf("viewRequest.Payload.Module is required")
}
if payload.Module.Name == "" {
return nil, fmt.Errorf("viewRequest.Payload.Module.Name is required")
}
if payload.Function == "" {
return nil, fmt.Errorf("viewRequest.Payload.Function is required")
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation errors in this helper reference viewRequest.Payload..., but the API accepts a *ViewPayload directly. Consider aligning the error strings with the function’s input (e.g., payload is required, payload.module is required) so callers who use the helper outside a ViewRequest context aren’t misled.

Suggested change
return nil, fmt.Errorf("viewRequest.Payload is required")
}
if payload.Module == nil {
return nil, fmt.Errorf("viewRequest.Payload.Module is required")
}
if payload.Module.Name == "" {
return nil, fmt.Errorf("viewRequest.Payload.Module.Name is required")
}
if payload.Function == "" {
return nil, fmt.Errorf("viewRequest.Payload.Function is required")
return nil, fmt.Errorf("payload is required")
}
if payload.Module == nil {
return nil, fmt.Errorf("payload.module is required")
}
if payload.Module.Name == "" {
return nil, fmt.Errorf("payload.module.name is required")
}
if payload.Function == "" {
return nil, fmt.Errorf("payload.function is required")

Copilot uses AI. Check for mistakes.
Comment on lines +57 to +82
func TestConvertViewPayloadFromProto_RejectsInvalidPayloadInputs(t *testing.T) {
t.Parallel()

_, err := aptoscap.ConvertViewPayloadFromProto(nil)
require.ErrorContains(t, err, "viewRequest.Payload is required")

_, err = aptoscap.ConvertViewPayloadFromProto(&aptoscap.ViewPayload{Function: "name"})
require.ErrorContains(t, err, "viewRequest.Payload.Module is required")

_, err = aptoscap.ConvertViewPayloadFromProto(&aptoscap.ViewPayload{
Module: &aptoscap.ModuleID{Address: []byte{0x01}, Name: "coin"},
})
require.ErrorContains(t, err, "viewRequest.Payload.Function is required")

_, err = aptoscap.ConvertViewPayloadFromProto(&aptoscap.ViewPayload{
Module: &aptoscap.ModuleID{Address: []byte{0x01}},
Function: "name",
})
require.ErrorContains(t, err, "viewRequest.Payload.Module.Name is required")

_, err = aptoscap.ConvertViewPayloadFromProto(&aptoscap.ViewPayload{
Module: &aptoscap.ModuleID{Address: make([]byte, typesaptos.AccountAddressLength+1), Name: "coin"},
Function: "name",
})
require.ErrorContains(t, err, "module address too long")
}
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The negative tests don’t currently cover (a) missing/empty module address and (b) struct type tags with empty module/name (or empty address). If the helper is intended to centralize validation, please add test cases for these required-field scenarios to lock in the expected errors.

Copilot uses AI. Check for mistakes.
@ilija42 ilija42 added this pull request to the merge queue Apr 22, 2026
Merged via the queue into main with commit 52b7a5a Apr 22, 2026
32 of 33 checks passed
@ilija42 ilija42 deleted the feature/aptos-view-proto-helpers branch April 22, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants