cmd/pushtx, .github/workflows: add build workflow, show raw hex in output

Co-authored-by: drQedwards <213266729+drQedwards@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-03-12 16:10:29 +00:00
parent b91a437b09
commit 9ed063f56e
3 changed files with 84 additions and 0 deletions

37
.github/workflows/build.yml vendored Normal file
View file

@ -0,0 +1,37 @@
name: Build
on:
push:
branches:
- master
- copilot/**
pull_request:
branches:
- master
workflow_dispatch:
jobs:
build:
name: Build All
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: false
- uses: actions/cache@v4
with:
path: build/cache
key: ${{ runner.os }}-build-tools-cache-${{ hashFiles('build/checksums.txt') }}
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
cache: false
- name: Build all commands
run: make all
- name: Run pushtx tests
run: go test ./cmd/pushtx/ -v

View file

@ -107,6 +107,10 @@ func run(args []string, stdin io.Reader) error {
}
fmt.Println("Transaction submitted successfully")
fmt.Println("Hash:", hash.Hex())
// Print the raw hex transaction as the last output for easy
// copy-paste into block explorers like etherscan.io/pushTx.
fmt.Println("Raw tx: 0x" + hex.EncodeToString(rawTx))
return nil
}

View file

@ -19,9 +19,11 @@ package main
import (
"crypto/ecdsa"
"encoding/json"
"io"
"math/big"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
@ -241,3 +243,44 @@ func TestRunEqualsSyntax(t *testing.T) {
t.Fatal("unexpected error:", err)
}
}
func TestRunOutputEndsWithRawHex(t *testing.T) {
srv := fakeRPC(t, false)
defer srv.Close()
_, txHex := signedTestTx(t)
// Capture stdout to verify "Raw tx:" appears in output.
oldStdout := os.Stdout
r, w, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
os.Stdout = w
runErr := run([]string{"--rpc", srv.URL, txHex}, strings.NewReader(""))
w.Close()
os.Stdout = oldStdout
if runErr != nil {
t.Fatal("unexpected error:", runErr)
}
out, err := io.ReadAll(r)
if err != nil {
t.Fatal(err)
}
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
lastLine := lines[len(lines)-1]
// The last line must be the raw hex transaction.
if !strings.HasPrefix(lastLine, "Raw tx: 0x") {
t.Fatalf("last output line = %q, want prefix \"Raw tx: 0x\"", lastLine)
}
// Verify the hex payload round-trips back to the input.
rawHex := strings.TrimPrefix(lastLine, "Raw tx: ")
if rawHex != txHex {
t.Fatalf("raw hex mismatch:\n got %s\n want %s", rawHex, txHex)
}
}