bridgevm: recover the plugin test that .gitignore was hiding

A bare `plugin` line in .gitignore matched every <vm>/cmd/plugin DIRECTORY, so
`git add` inside one printed a hint and staged nothing. This file was written
and passing and was not in the repository. Another lane anchored the pattern to
/plugin; this is the file that was stranded behind it.

Work that is written, green, and invisible is the worst of the three states: it
looks done to whoever wrote it and does not exist to anyone else.
This commit is contained in:
2026-08-28 15:04:51 -07:00
parent eb02967a9a
commit 95a5c2e478
+55
View File
@@ -0,0 +1,55 @@
// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package main
import (
"bytes"
"io"
"os"
"testing"
"github.com/stretchr/testify/require"
"github.com/luxfi/chains/bridgevm"
)
// TestTheVersionIsTheVMs. An operator asks this binary what it is, and the
// answer used to be a string literal beside the VM's own version: bump either
// one and the plugin reports a version it is not.
func TestTheVersionIsTheVMs(t *testing.T) {
args := os.Args
os.Args = []string{args[0], "version"}
t.Cleanup(func() { os.Args = args })
require.Equal(t, "Bridge-VM/"+bridgevm.Version.String()+"\n", capture(t, run))
}
// A plugin invoked with anything else serves the VM, which needs the node on
// the other end of the pipe; that path is the process's whole purpose and
// cannot run inside a test.
func TestAnUnknownArgumentIsNotTheVersion(t *testing.T) {
args := os.Args
os.Args = []string{args[0], "version", "extra"}
t.Cleanup(func() { os.Args = args })
require.Equal(t, "Bridge-VM/"+bridgevm.Version.String()+"\n", capture(t, run))
}
// capture runs f with stdout redirected and returns what it printed.
func capture(t *testing.T, f func() error) string {
t.Helper()
r, w, err := os.Pipe()
require.NoError(t, err)
stdout := os.Stdout
os.Stdout = w
defer func() { os.Stdout = stdout }()
require.NoError(t, f())
require.NoError(t, w.Close())
var buf bytes.Buffer
_, err = io.Copy(&buf, r)
require.NoError(t, err)
return buf.String()
}