Skip to content

Commit

Permalink
test: Ledger support (#2782)
Browse files Browse the repository at this point in the history
Closes #2225

Note: this test won't fail when Goreleaser creates binaries that break
Ledger support. However, this may catch when we bump a dependency that
breaks Ledger support.
  • Loading branch information
rootulp authored Oct 31, 2023
1 parent 1f0a521 commit e6b64a6
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions test/ledger/ledger_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package ledger

import (
"bytes"
"os"
"os/exec"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestLedgerSupport(t *testing.T) {
if testing.Short() {
t.Skip("skipping ledger support test in short mode.")
}

type testCase struct {
name string
ledger bool
want string
}

testCases := []testCase{
{
name: "ledger support enabled",
ledger: true,
want: "Error: failed to generate ledger key: failed to retrieve device: ledger nano S: LedgerHID device (idx 0) not found. Ledger LOCKED OR Other Program/Web Browser may have control of device.\n",
},
{
name: "ledger support disabled",
ledger: false,
want: "Error: failed to generate ledger key: failed to retrieve device: ledger nano S: support for ledger devices is not available in this executable\n",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
var cmd *exec.Cmd
if tc.ledger {
// Generate the binary with Ledger support
cmd = exec.Command("go", "build", "-tags", "ledger", "-o", "celestia-appd", "../../cmd/celestia-appd")
} else {
// Generate the binary without Ledger support
cmd = exec.Command("go", "build", "-o", "celestia-appd", "../../cmd/celestia-appd")
}
err := cmd.Run()
require.NoError(t, err)

// Clean up the binary
defer os.Remove("celestia-appd")

// Run the binary
cmd = exec.Command("./celestia-appd", "keys", "add", "test-key-name", "--ledger")
var out bytes.Buffer
cmd.Stderr = &out
err = cmd.Run()
require.Error(t, err)
assert.Equal(t, tc.want, out.String())
})
}
}

0 comments on commit e6b64a6

Please sign in to comment.