Skip to content

Commit

Permalink
Add test scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Aug 19, 2024
1 parent 4b42b15 commit b3d63ed
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions clients/stellarcore/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import (
"testing"

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

"github.com/stellar/go/keypair"
proto "github.com/stellar/go/protocols/stellarcore"
"github.com/stellar/go/support/http/httptest"
"github.com/stellar/go/xdr"
)

func TestSubmitTransaction(t *testing.T) {
Expand Down Expand Up @@ -75,3 +78,28 @@ func TestManualClose_NotAvailable(t *testing.T) {

assert.EqualError(t, err, "exception in response: Set MANUAL_CLOSE=true")
}

func TestGetLedgerEntries(t *testing.T) {
hmock := httptest.NewClient()
c := &Client{HTTP: hmock, URL: "http://localhost:11626"}

// happy path - new transaction
hmock.On("GET", "http://localhost:11626/getledgerentry").
ReturnString(http.StatusOK,
`{"ledger": 1234, "entries": [ {"e": "pretend it's xdr lol", "state": "Dead" }]}`,
)

var key xdr.LedgerKey
acc, err := xdr.AddressToAccountId(keypair.MustRandom().Address())
require.NoError(t, err)
key.SetAccount(acc)

resp, err := c.GetLedgerEntries(context.Background(), 1234, key)
require.NoError(t, err)

require.EqualValues(t, 1234, resp.Ledger)
require.Len(t, resp.Entries, 1)
require.Equal(t, resp.Entries[0].State, proto.DeadState)

require.EqualError(t, err, "exception in response: Set MANUAL_CLOSE=true")
}

0 comments on commit b3d63ed

Please sign in to comment.