diff --git a/.changeset/itchy-cameras-scream.md b/.changeset/itchy-cameras-scream.md new file mode 100644 index 00000000000..01a3eca84ad --- /dev/null +++ b/.changeset/itchy-cameras-scream.md @@ -0,0 +1,5 @@ +--- +"chainlink": minor +--- + +#updated Move BoxOutput util function to the only place it is called. diff --git a/core/gethwrappers/go_generate_test.go b/core/gethwrappers/go_generate_test.go index ff53cf715e3..bbe328a6726 100644 --- a/core/gethwrappers/go_generate_test.go +++ b/core/gethwrappers/go_generate_test.go @@ -17,8 +17,6 @@ import ( cutils "github.com/smartcontractkit/chainlink-common/pkg/utils" "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" - "github.com/smartcontractkit/chainlink/v2/core/utils" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -39,7 +37,7 @@ func TestCheckContractHashesFromLastGoGenerate(t *testing.T) { wd = "" } require.Equal(t, versions.GethVersion, GethVersion, - color.HiRedString(utils.BoxOutput("please re-run `go generate %s` and commit the"+ + color.HiRedString(BoxOutput("please re-run `go generate %s` and commit the"+ "changes", wd))) for _, contractVersionInfo := range versions.ContractVersions { @@ -96,7 +94,7 @@ func compareCurrentCompilerArtifactAgainstRecordsAndSoliditySources( require.NoError(t, err) recompileCommand := fmt.Sprintf("(cd %s/contracts; make wrappers-all)", rootDir) assert.Equal(t, versionInfo.Hash, hash, - utils.BoxOutput(`compiled %s and/or %s has changed; please rerun + BoxOutput(`compiled %s and/or %s has changed; please rerun %s, and commit the changes`, versionInfo.AbiPath, versionInfo.BinaryPath, recompileCommand)) } diff --git a/core/gethwrappers/utils.go b/core/gethwrappers/utils.go index 59268c295e2..b46fbfae6e5 100644 --- a/core/gethwrappers/utils.go +++ b/core/gethwrappers/utils.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "strings" ) // VersionHash is the hash used to detect changes in the underlying contract @@ -61,3 +62,31 @@ func TempDir(dirPrefix string) (string, func()) { } } } + +// BoxOutput formats its arguments as fmt.Printf, and encloses them in a box of +// arrows pointing at their content, in order to better highlight it. See +// ExampleBoxOutput +func BoxOutput(errorMsgTemplate string, errorMsgValues ...interface{}) string { + errorMsgTemplate = fmt.Sprintf(errorMsgTemplate, errorMsgValues...) + lines := strings.Split(errorMsgTemplate, "\n") + maxlen := 0 + for _, line := range lines { + if len(line) > maxlen { + maxlen = len(line) + } + } + internalLength := maxlen + 4 + output := "↘" + strings.Repeat("↓", internalLength) + "↙\n" // top line + output += "→ " + strings.Repeat(" ", maxlen) + " ←\n" + readme := strings.Repeat("README ", maxlen/7) + output += "→ " + readme + strings.Repeat(" ", maxlen-len(readme)) + " ←\n" + output += "→ " + strings.Repeat(" ", maxlen) + " ←\n" + for _, line := range lines { + output += "→ " + line + strings.Repeat(" ", maxlen-len(line)) + " ←\n" + } + output += "→ " + strings.Repeat(" ", maxlen) + " ←\n" + output += "→ " + readme + strings.Repeat(" ", maxlen-len(readme)) + " ←\n" + output += "→ " + strings.Repeat(" ", maxlen) + " ←\n" + return "\n" + output + "↗" + strings.Repeat("↑", internalLength) + "↖" + // bottom line + "\n\n" +} diff --git a/core/gethwrappers/utils_test.go b/core/gethwrappers/utils_test.go new file mode 100644 index 00000000000..671cd8b0d51 --- /dev/null +++ b/core/gethwrappers/utils_test.go @@ -0,0 +1,27 @@ +package gethwrappers_test + +import ( + "testing" + + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers" + + "github.com/stretchr/testify/assert" +) + +func TestBoxOutput(t *testing.T) { + t.Parallel() + + output := gethwrappers.BoxOutput("some error %d %s", 123, "foo") + const expected = "\n" + + "↘↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↙\n" + + "→ ←\n" + + "→ README README ←\n" + + "→ ←\n" + + "→ some error 123 foo ←\n" + + "→ ←\n" + + "→ README README ←\n" + + "→ ←\n" + + "↗↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↖\n" + + "\n" + assert.Equal(t, expected, output) +} diff --git a/core/utils/utils.go b/core/utils/utils.go index 98c2607baff..5f0954df1d0 100644 --- a/core/utils/utils.go +++ b/core/utils/utils.go @@ -513,34 +513,6 @@ func (m *KeyedMutex) LockInt64(key int64) func() { return mtx.Unlock } -// BoxOutput formats its arguments as fmt.Printf, and encloses them in a box of -// arrows pointing at their content, in order to better highlight it. See -// ExampleBoxOutput -func BoxOutput(errorMsgTemplate string, errorMsgValues ...interface{}) string { - errorMsgTemplate = fmt.Sprintf(errorMsgTemplate, errorMsgValues...) - lines := strings.Split(errorMsgTemplate, "\n") - maxlen := 0 - for _, line := range lines { - if len(line) > maxlen { - maxlen = len(line) - } - } - internalLength := maxlen + 4 - output := "↘" + strings.Repeat("↓", internalLength) + "↙\n" // top line - output += "→ " + strings.Repeat(" ", maxlen) + " ←\n" - readme := strings.Repeat("README ", maxlen/7) - output += "→ " + readme + strings.Repeat(" ", maxlen-len(readme)) + " ←\n" - output += "→ " + strings.Repeat(" ", maxlen) + " ←\n" - for _, line := range lines { - output += "→ " + line + strings.Repeat(" ", maxlen-len(line)) + " ←\n" - } - output += "→ " + strings.Repeat(" ", maxlen) + " ←\n" - output += "→ " + readme + strings.Repeat(" ", maxlen-len(readme)) + " ←\n" - output += "→ " + strings.Repeat(" ", maxlen) + " ←\n" - return "\n" + output + "↗" + strings.Repeat("↑", internalLength) + "↖" + // bottom line - "\n\n" -} - // ConcatBytes appends a bunch of byte arrays into a single byte array func ConcatBytes(bufs ...[]byte) []byte { return bytes.Join(bufs, []byte{}) diff --git a/core/utils/utils_test.go b/core/utils/utils_test.go index 587bd46efb9..d1dd829ef64 100644 --- a/core/utils/utils_test.go +++ b/core/utils/utils_test.go @@ -205,24 +205,6 @@ func TestHashPassword(t *testing.T) { assert.False(t, ok) } -func TestBoxOutput(t *testing.T) { - t.Parallel() - - output := utils.BoxOutput("some error %d %s", 123, "foo") - const expected = "\n" + - "↘↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↙\n" + - "→ ←\n" + - "→ README README ←\n" + - "→ ←\n" + - "→ some error 123 foo ←\n" + - "→ ←\n" + - "→ README README ←\n" + - "→ ←\n" + - "↗↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↖\n" + - "\n" - assert.Equal(t, expected, output) -} - func TestISO8601UTC(t *testing.T) { t.Parallel()