diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000000..1203d58f0e --- /dev/null +++ b/.github/workflows/build.yml @@ -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 diff --git a/cmd/pushtx/main.go b/cmd/pushtx/main.go index eb936c7850..fe4540f05b 100644 --- a/cmd/pushtx/main.go +++ b/cmd/pushtx/main.go @@ -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 } diff --git a/cmd/pushtx/main_test.go b/cmd/pushtx/main_test.go index 972edf100b..d815ab3b73 100644 --- a/cmd/pushtx/main_test.go +++ b/cmd/pushtx/main_test.go @@ -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) + } +}