Skip to content

feat: TxBuilder implementation for Cosmos and EVM#17

Merged
qj0r9j0vc2 merged 40 commits into
mainfrom
feat/txcontroller-e2e
Jan 24, 2026
Merged

feat: TxBuilder implementation for Cosmos and EVM#17
qj0r9j0vc2 merged 40 commits into
mainfrom
feat/txcontroller-e2e

Conversation

@qj0r9j0vc2

Copy link
Copy Markdown
Member

Summary

  • Implement TxBuilder interface for Cosmos SDK chains
  • Implement TxBuilder interface for EVM chains
  • Add gRPC plugin support for cross-process TxBuilder operations
  • Add comprehensive test coverage

Changes

  • Cosmos TxBuilder: BuildTx, SignTx, BroadcastTx with SDK v0.50 support
  • EVM TxBuilder: Native transfer transactions with ECDSA signing
  • Plugin gRPC: Client/server implementation for TxBuilder operations
  • Tests: Unit tests for all TxBuilder methods

feat: implement UpgradeController and full upgrade management
feat: add TxController with E2E testing
Add TxBuilder implementation for Cosmos SDK chains with:
- SDK version detection via ABCI info endpoint
- Feature detection based on SDK version (gov-v1, authz, group, feegrant)
- Semantic version parsing with pre-release support
- Factory function with config validation
- Stub implementations for BuildTx, SignTx, BroadcastTx
Add QueryAccount method to TxBuilder that queries the Cosmos SDK
REST API to fetch account number and sequence needed for transaction
signing. Supports both BaseAccount and ModuleAccount types.
Add message builders for governance votes, bank sends, and staking
delegations with proper Cosmos SDK type handling.

- Create msgs.go with payload types and BuildMessage function
- Implement parseVoteOption for gov vote options (yes/no/abstain/no_with_veto)
- Add ParseGasPrice and ParseAmount utility functions
- Update BuildTx to query account info and construct unsigned tx
- Add comprehensive tests for all transaction types

The BuildTx implementation creates JSON-encoded tx bytes as a placeholder
that will be replaced with proper protobuf encoding in Task 6.
- Add validation for zero/negative amounts in ParseAmount
- Add validation for empty to_address in BankSendPayload
- Add validation for empty validator_address in StakingDelegatePayload
- Add test for decimal amount rejection in TestParseAmount
- Add test for zero amount rejection in TestParseAmount
- Add test for nowithveto variant in TestParseVoteOption
- Add signing.go with LoadPrivateKey and SignBytes helper functions
- Implement SignTx method in TxBuilder to sign transactions
- Add comprehensive tests for key loading, signing, and error cases

The signing implementation uses Cosmos SDK's secp256k1 package for
cryptographic operations. LoadPrivateKey validates 32-byte key length,
and SignBytes produces signatures that can be verified with the
corresponding public key.
- Add nil check for privKey in SignTx after LoadPrivateKey
- Add input validation for privKey and signDoc in SignBytes
- Add named constant secp256k1PrivKeySize for key length validation
- Add tests for nil signDoc and nil privKey in SignBytes
Implement the BroadcastTx method for Cosmos SDK chains using the
CometBFT JSON-RPC broadcast_tx_sync endpoint. This completes Task 5
of the TxBuilder implementation.

Changes:
- Create broadcast.go with BroadcastMode, BroadcastRequest, and
  BroadcastResponse types
- Implement BroadcastTx method that encodes tx as base64, sends
  JSON-RPC request, and parses the response
- Add comprehensive tests for success, RPC errors, non-zero codes,
  network errors, invalid JSON, nil input, empty bytes, HTTP errors,
  and context cancellation
- Add interface compliance check: var _ network.TxBuilder = (*TxBuilder)(nil)
Add EVM TxBuilder implementation with:
- TxBuilder struct with rpcEndpoint, chainID, client, and httpClient fields
- NewTxBuilder constructor with validation and ethclient connection
- SupportedTxTypes returning TxTypeBankSend
- Placeholder methods for BuildTx, SignTx, and BroadcastTx
- Close method for cleanup
- Interface compliance check for network.TxBuilder
Implement the BuildTx method for EVM TxBuilder to support native token
transfers (TxTypeBankSend). This includes:

- Create msgs.go with NativeTransferPayload struct and parsing functions
- ParseNativeTransferPayload validates hex addresses via common.IsHexAddress
- ParseAmount converts wei amount strings to *big.Int
- BuildTx switches on TxType and calls buildNativeTransfer helper
- buildNativeTransfer creates legacy EVM transactions with:
  - Nonce from client (or 0 for testing)
  - Gas price from request or network suggestion
  - Default 21000 gas limit for native transfers
  - RLP encoding for TxBytes
  - SignDoc using types.LatestSignerForChainID().Hash()
- Add comprehensive tests for all functionality
- Fix JSON marshal error handling in test functions (lines 20, 47, 106, 132, 158)
- Add test case for invalid hex data in TestParseNativeTransferPayload
- Add test case for empty to_address field validation
- Add nonce verification assertions in TestBuildTx functions
- Replace magic number with DefaultGasPriceGwei constant (1 Gwei in wei)
- Add nil signedTx validation in BroadcastTx
- Add empty TxBytes validation in BroadcastTx
- Add httpClient nil check with default fallback
- Add test for nil signed transaction error
- Add test for empty transaction bytes error
- Add test for RPC error response handling
- Fix outdated stub tests in txbuilder_test.go
- Add grpcTxBuilder wrapper for remote TxBuilder access
- Implement CreateTxBuilder, BuildTx, SignTx, BroadcastTx via gRPC
- Add TxBuilderFactory interface compliance to GRPCClient
- Wire TxBuilder operations into plugin gRPC server
- Update proto definitions for TxBuilder messages
- Keep network.TxBuilder interface from pkg/network
- Remove duplicate plugin.TxBuilder types
- Update tests to use network package types
Fixes naming conflict between the local 'plugin' package and the
imported 'github.com/hashicorp/go-plugin' by using 'hcplugin' alias.
- Remove unused SignDoc struct initialization in cosmos/txbuilder.go
- Fix gofmt formatting in cosmos/config.go
- Fix gofmt formatting in evm/sign_test.go
@qj0r9j0vc2 qj0r9j0vc2 merged commit 1bd10c5 into main Jan 24, 2026
14 checks passed
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.

1 participant