Skip to content

refactor: replace func-typed injection seams in pkg/pchain with interfaces#30

Merged
owenwahlgren merged 4 commits into
mainfrom
refactor/pchain-tx-seams
Jun 10, 2026
Merged

refactor: replace func-typed injection seams in pkg/pchain with interfaces#30
owenwahlgren merged 4 commits into
mainfrom
refactor/pchain-tx-seams

Conversation

@owenwahlgren

Copy link
Copy Markdown
Collaborator

Summary

The nine issue*Tx helpers in pkg/pchain/pchain.go took the avalanchego wallet call as a function-typed parameter so unit tests could stub it. With multi-parameter builders the inline function types grew longer than the helper bodies — and the pattern was recently copied in #28 into a 10-parameter version that drew, let's say, feedback from upstream.

This replaces each seam with a single-method issuer interface mirroring the corresponding wallet/chain/p wallet method, so w.PWallet() satisfies them directly:

// Before
func issueSendTx(
    issueBaseTx func(outputs []*avax.TransferableOutput, options ...common.Option) (*txs.Tx, error),
    avaxAssetID ids.ID, to ids.ShortID, amountNAVAX uint64, options ...common.Option,
) (ids.ID, error)

// After
type baseTxIssuer interface {
    IssueBaseTx(outputs []*avax.TransferableOutput, options ...common.Option) (*txs.Tx, error)
}

func issueSendTx(issuer baseTxIssuer, avaxAssetID ids.ID, to ids.ShortID, amountNAVAX uint64, options ...common.Option) (ids.ID, error)
  • No function-typed parameters remain in pkg/pchain (grep-verified)
  • No behavior change: exported API (Send, AddValidator, CreateSubnet, …), error messages, and %w wrapping identical
  • Tests converted from inline closures to small stub structs with capture fields; all 11 tests keep identical assertions (arg mapping for amounts, owners, durations, shares, signer, option propagation, error wrapping)
  • This also establishes the pattern feat: support ACP-236 auto-renewed staking commands #28 should rebase onto for AddAutoRenewedValidatorTx

Note: includes the same whitespace-only gofmt fixes as #29 (five files unformatted on main) — whichever merges second rebases trivially.

Validation

  • gofmt -l . clean, go vet ./... clean, staticcheck v0.6.1 clean (plain + e2e tags)
  • go test -race ./pkg/... ./cmd/... all pass; -tags=integration compile check passes
  • go test -tags=clie2e ./e2e/... -run "Help|Params|MissingArgs" passes

…faces

The issue*Tx helpers took the wallet call as a function-typed parameter
so unit tests could stub it. With multi-parameter builders the inline
function types grew longer than the helper bodies (and the pattern was
recently copied into an even larger 10-parameter signature in #28).

Replace each seam with a single-method issuer interface mirroring the
corresponding avalanchego wallet/chain/p method, so w.PWallet()
satisfies them directly and tests stub a small struct instead of a
closure. No behavior change: exported API, error messages, and
wrapping are identical. Also gofmt's five files that were unformatted
on main (same whitespace fixes as #29).
…lnerabilities

govulncheck fails CI on main: GO-2026-5037 (crypto/x509), GO-2026-4971
(net), GO-2026-4918 (net/http + golang.org/x/net) are reachable from
keystore key generation, wallet dialing, and network ID lookup. All are
fixed in go1.25.10/1.25.11 and x/net v0.53.0.

- go.mod: go 1.25.9 -> 1.25.11; x/net v0.47.0 -> v0.53.0 (pulls
  x/crypto, x/sys, x/term, x/text et al. forward)
- ci.yml: bump setup-go and GOTOOLCHAIN pins to 1.25.11

govulncheck now reports 0 reachable vulnerabilities.
@owenwahlgren owenwahlgren merged commit 532c0e2 into main Jun 10, 2026
6 checks passed
@owenwahlgren owenwahlgren deleted the refactor/pchain-tx-seams branch June 10, 2026 20:32
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.

3 participants