Repository navigation
refactor: Go 1.25 modernization, dedup, and test suite overhaul - #354
Merged
Merged
Conversation
Dedup shared logic into unexported helpers (privateKeyFromHex, ecies deriveKeys, HD-key wrappers, GetPublicKeysForPath loop), reuse hash.Sha256d for the address double-SHA256, adopt slices.Backward and for-range loops, tidy fee guards, and add OP_RETURN prefix constants. Public API and wire formats unchanged.
Convert legacy if/else tables to t.Run named subtests with t.Parallel() and testify, centralize shared constants, add reusable fixtures/helpers, and add tests for DefaultStandardFee, GenerateSharedKeyPair, A25 accessors plus fuzz targets for TxFromHex and DecodeWIF.
The test-suite modernization moved test-vector lines, so the existing file:line fingerprints in .gitleaksignore no longer matched. Regenerated the allowlist against the current tree so all known test fixtures (not real secrets) are covered. Verified clean in both no-git and git-log scan modes.
There was a problem hiding this comment.
Pull request overview
This PR modernizes the Go codebase for Go 1.25, deduplicates internal implementations, and overhauls the test suite toward parallel subtests, shared fixtures, and added fuzz/coverage targets—while aiming to preserve the public API and runtime behavior.
Changes:
- Refactors internals to reuse shared helpers/stdlib equivalents (e.g., ECIES key derivation helper, address double-SHA via
hash.Sha256d, transaction cleanup). - Standardizes tests to
t.Runsubtests witht.Parallel()plus shared test fixtures/helpers and new fuzz targets. - Updates docs and tooling metadata (README feature list,
.gitleaksignorefingerprints).
Reviewed changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| wif.go | Uses modern for range <int> loop form in padding helper. |
| wif_test.go | Removes in-file WIF constants in favor of shared test constants. |
| wif_fuzz_test.go | Adds fuzz target for DecodeWIF. |
| verify_test.go | Converts table tests to named parallel subtests; modernizes benchmarks. |
| transaction.go | Adds OP_RETURN prefix constants, uses slices.Backward, tightens fee clamping logic. |
| transaction_test.go | Converts tests/benchmarks to subtests + helpers; reduces duplication. |
| transaction_fuzz_test.go | Adds fuzz target for TxFromHex. |
| transaction_creation_test.go | Expands extended transaction tests; introduces more parallel subtests and helper usage. |
| testhelpers_test.go | Introduces shared test helpers (newTestUtxo, newTestOpReturns, mustTestPrivKey, mustHDKey). |
| test_constants_test.go | Centralizes frequently reused test constants and case-name strings. |
| sign.go | Updates empty-string checks to idiomatic == "". |
| sign_verify_extended_test.go | Adds t.Parallel() to many subtests. |
| sign_test.go | Refactors to require-based assertions and parallel subtests. |
| script.go | Updates empty-string checks to idiomatic == "". |
| script_test.go | Refactors to named parallel subtests with testify assertions. |
| README.md | Documents additional public functions in the feature list. |
| pubkey.go | Updates empty-string checks to idiomatic == "". |
| pubkey_test.go | Refactors to named parallel subtests; reuses shared constants. |
| private_key.go | Deduplicates hex private-key parsing via privateKeyFromHex; updates empty checks. |
| private_key_test.go | Refactors to named parallel subtests; reuses shared constants; modernizes benchmarks. |
| private_key_fuzz_test.go | Updates fuzz seeds to use shared WIF constants. |
| misc_functions_test.go | Adds t.Parallel() to many subtests and reuses helper functions. |
| hd_key.go | Deduplicates path pubkey derivation; routes xpub parsing through GenerateHDKeyFromString. |
| hd_key_test.go | Refactors many tests to named parallel subtests and updated fixtures. |
| encryption.go | Reuses existing primitives (EncryptShared) and simplifies private-key parsing call path. |
| encryption_test.go | Refactors to named parallel subtests with stronger assertions. |
| ecies.go | Extracts shared key-derivation logic into helper deriveKeys. |
| ecies_test.go | Adds parallel subtests and shared case-name usage. |
| coverage_gaps_test.go | Adds coverage for fee defaults, shared keypair symmetry, and A25 accessors. |
| address.go | Replaces hand-rolled double-SHA256 with hash.Sha256d; modernizes empty checks. |
| address_test.go | Refactors to named parallel subtests with testify assertions. |
| .gitleaksignore | Updates allowlist fingerprints to match relocated/edited test vectors. |
Suppressed comments (2)
hd_key_test.go:288
- Same issue here: the table entry uses XOR (^) instead of exponentiation, so the "2^31+1" / "2^32-1" values do not match the test name intent and won’t cover boundary derivation cases. Use bit shifts / max constants (e.g., (uint32(1)<<31)+1 and math.MaxUint32).
{"chain 10 num 10", validKey, 10, 10, false, false},
{"chain 100 num 100", validKey, 100, 100, false, false},
{"chain 2^31+1 num 2^32-1", validKey, 2 ^ 31 + 1, 2 ^ 32 - 1, false, false},
{"chain 1<<8 num 1<<8", validKey, 1 << 8, 1 << 8, false, false},
hd_key_test.go:401
- This test-case uses XOR (^) in "2 ^ 31 + 1", which evaluates to 30, not (1<<31)+1. If the intent is to exercise a high-bit child index, switch to (uint32(1)<<31)+1 (or a similar boundary) to match the name and improve coverage.
{"num 10", validKey, 10, false, false},
{"num 100", validKey, 100, false, false},
{"num 2^31+1", validKey, 2 ^ 31 + 1, false, false},
{"num 1<<8", validKey, 1 << 8, false, false},
{"num 1<<9", validKey, 1 << 9, false, false},
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The chain/num values used 2 ^ 31 + 1 and 2 ^ 32 - 1, which are XOR (30 and 33) in Go, not the intended 2^31+1 / 2^32-1 boundaries. Use shift expressions (1<<31 + 1, 1<<32 - 1) to match the case names and actually exercise high-bit hardened derivation, consistent with the sibling 1<<N cases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
A Go 1.25 modernization and deduplication pass. The public API, wire formats, and behavior are unchanged.
Production internals (behavior-preserving):
privateKeyFromHex(3 call sites), ECIESderiveKeys, collapsed the identical HD-key string wrappers, and loopedGetPublicKeysForPath's twin blocks.hash.Sha256dfor the address double-SHA256 (removed the hand-rolledcrypto/sha256version).slices.Backward,for range n,for b.Loop()in benchmarks, ands == ""for string emptiness.transaction.go: merged redundant fee guards and hoisted OP_RETURN prefix constants.Tests:
if/else/t.Fatalftests tot.Runnamed subtests witht.Parallel()and testifyrequire/assert.test_constants_test.goand added reusable fixtures/helpers (newTestUtxo,newTestOpReturns,mustTestPrivKey,mustHDKey).DefaultStandardFee,GenerateSharedKeyPair, and theA25accessors, plus fuzz targets forTxFromHexandDecodeWIF.Security/tooling:
.gitleaksignore: the test refactor relocated test-vector lines, so the existingfile:linefingerprints no longer matched. Regenerated the allowlist against the current tree. All entries are documentation/test fixtures — not real secrets.Docs: README feature list now documents a few previously-omitted public functions (Address from PubKey, Validate a Base58 Address, PubKey from Signature, Create Tx with Change using WIF).
Why It Was Necessary
The library is already on Go 1.25 but carried pre-1.22 idioms, hand-rolled implementations that duplicated stdlib/SDK functionality, and two eras of test style. This pass removes duplication (a maintenance hazard), aligns the code with modern Go, and makes the test suite uniform, parallel, and better-covered — without touching the widely-imported public API.
Testing Performed
magex test/magex test:race— passmagex lint(golangci-lint, 62 linters +go vet) — 0 issuesstaticcheck ./...,gofumpt -l .— cleango-pre-commit run --all-files— pass, including gitleaksgitleaks detectin both--no-gitand git-log modes — no leaks foundImpact / Risk
Low. No exported signature, name, or behavior changes — a drop-in for all downstream consumers. Error strings are unchanged (error wrapping intentionally not introduced). Crypto-internal refactors are guarded by the existing byte-for-byte compatibility vectors.
Notifications