Skip to content

Commit 71f7acb

Browse files
authored
[tmpnet] Update rpc version check to tolerate usage of go run (#3869)
1 parent d48ff81 commit 71f7acb

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

tests/fixture/tmpnet/network.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package tmpnet
55

66
import (
7+
"bytes"
78
"context"
89
"encoding/base64"
910
"encoding/hex"
@@ -1066,7 +1067,7 @@ func checkVMBinaries(log logging.Logger, subnets []*Subnet, avalanchegoPath stri
10661067
return nil
10671068
}
10681069

1069-
avalanchegoRPCVersion, err := getRPCVersion(avalanchegoPath, "--version-json")
1070+
avalanchegoRPCVersion, err := getRPCVersion(log, avalanchegoPath, "--version-json")
10701071
if err != nil {
10711072
log.Warn("unable to check rpcchainvm version for avalanchego", zap.Error(err))
10721073
return nil
@@ -1092,7 +1093,7 @@ func checkVMBinaries(log logging.Logger, subnets []*Subnet, avalanchegoPath stri
10921093
}
10931094

10941095
// Check that the VM's rpcchainvm version matches avalanchego's version
1095-
vmRPCVersion, err := getRPCVersion(vmPath, chain.VersionArgs...)
1096+
vmRPCVersion, err := getRPCVersion(log, vmPath, chain.VersionArgs...)
10961097
if err != nil {
10971098
log.Warn("unable to check rpcchainvm version for VM Binary",
10981099
zap.String("subnet", subnet.Name),
@@ -1123,12 +1124,23 @@ type RPCChainVMVersion struct {
11231124

11241125
// getRPCVersion attempts to invoke the given command with the specified version arguments and
11251126
// retrieve an rpcchainvm version from its output.
1126-
func getRPCVersion(command string, versionArgs ...string) (uint64, error) {
1127+
func getRPCVersion(log logging.Logger, command string, versionArgs ...string) (uint64, error) {
11271128
cmd := exec.Command(command, versionArgs...)
11281129
output, err := cmd.CombinedOutput()
11291130
if err != nil {
11301131
return 0, fmt.Errorf("command %q failed with output: %s", command, output)
11311132
}
1133+
1134+
// Ignore output before the opening brace to tolerate the case of a command being invoked
1135+
// with `go run` and the go toolchain emitting diagnostic logging before the version output.
1136+
if idx := bytes.IndexByte(output, '{'); idx > 0 {
1137+
log.Info("ignoring leading bytes of JSON version output in advance of opening `{`",
1138+
zap.String("command", command),
1139+
zap.String("ignoredLeadingBytes", string(output[:idx])),
1140+
)
1141+
output = output[idx:]
1142+
}
1143+
11321144
version := &RPCChainVMVersion{}
11331145
if err := json.Unmarshal(output, version); err != nil {
11341146
return 0, fmt.Errorf("failed to unmarshal output from command %q: %w, output: %s", command, err, output)

0 commit comments

Comments
 (0)