Skip to content

Commit

Permalink
Move network request to a JSON fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Aug 18, 2022
1 parent b96377b commit c6d5f12
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 15 deletions.
67 changes: 67 additions & 0 deletions exp/lighthorizon/adapters/fixtures/transactions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"_links": {
"self": {
"href": "https://horizon.stellar.org/accounts/GBFHFINUD6NVGSX33PY25DDRCABN3H2JTDMLUEXAUEJVV22HTXVGLEZD/transactions?cursor=179530990183178241\u0026limit=1\u0026order=desc"
},
"next": {
"href": "https://horizon.stellar.org/accounts/GBFHFINUD6NVGSX33PY25DDRCABN3H2JTDMLUEXAUEJVV22HTXVGLEZD/transactions?cursor=179530990183174144\u0026limit=1\u0026order=desc"
},
"prev": {
"href": "https://horizon.stellar.org/accounts/GBFHFINUD6NVGSX33PY25DDRCABN3H2JTDMLUEXAUEJVV22HTXVGLEZD/transactions?cursor=179530990183174144\u0026limit=1\u0026order=asc"
}
},
"_embedded": {
"records": [
{
"_links": {
"self": {
"href": "https://horizon.stellar.org/transactions/55d8aa3693489ffc1d70b8ba33b8b5c012ec098f6f104383e3f090048488febd"
},
"account": {
"href": "https://horizon.stellar.org/accounts/GBFHFINUD6NVGSX33PY25DDRCABN3H2JTDMLUEXAUEJVV22HTXVGLEZD"
},
"ledger": {
"href": "https://horizon.stellar.org/ledgers/41800316"
},
"operations": {
"href": "https://horizon.stellar.org/transactions/55d8aa3693489ffc1d70b8ba33b8b5c012ec098f6f104383e3f090048488febd/operations{?cursor,limit,order}",
"templated": true
},
"effects": {
"href": "https://horizon.stellar.org/transactions/55d8aa3693489ffc1d70b8ba33b8b5c012ec098f6f104383e3f090048488febd/effects{?cursor,limit,order}",
"templated": true
},
"precedes": {
"href": "https://horizon.stellar.org/transactions?order=asc\u0026cursor=179530990183174144"
},
"succeeds": {
"href": "https://horizon.stellar.org/transactions?order=desc\u0026cursor=179530990183174144"
},
"transaction": {
"href": "https://horizon.stellar.org/transactions/55d8aa3693489ffc1d70b8ba33b8b5c012ec098f6f104383e3f090048488febd"
}
},
"id": "55d8aa3693489ffc1d70b8ba33b8b5c012ec098f6f104383e3f090048488febd",
"paging_token": "179530990183174144",
"successful": true,
"hash": "55d8aa3693489ffc1d70b8ba33b8b5c012ec098f6f104383e3f090048488febd",
"ledger": 41800316,
"created_at": "2022-07-17T13:08:41Z",
"source_account": "GBFHFINUD6NVGSX33PY25DDRCABN3H2JTDMLUEXAUEJVV22HTXVGLEZD",
"source_account_sequence": "172589382434294350",
"fee_account": "GBFHFINUD6NVGSX33PY25DDRCABN3H2JTDMLUEXAUEJVV22HTXVGLEZD",
"fee_charged": "100",
"max_fee": "100000",
"operation_count": 1,
"envelope_xdr": "AAAAAgAAAABKcqG0H5tTSvvb8a6McRAC3Z9JmNi6EuChE1rrR53qZQABhqACZSkhAAAKTgAAAAAAAAAAAAAAAQAAAAEAAAAASnKhtB+bU0r72/GujHEQAt2fSZjYuhLgoRNa60ed6mUAAAANAAAAAXlYTE0AAAAAIjbXcP4NPgFSGXXVz3rEhCtwldaxqddo0+mmMumZBr4AAAACVAvkAAAAAABKcqG0H5tTSvvb8a6McRAC3Z9JmNi6EuChE1rrR53qZQAAAAJEUklGVAAAAAAAAAAAAAAAvSOzPqUOGnDIcJOm7T85qDFRM0wfOVoubgkEPk95DZ0AAAEQvqAGdQAAAAEAAAAAAAAAAAAAAAFHneplAAAAQAVm9muIrK31Z+m2ZvhDYhtuoHcc/n+MO0DOaiQjfW+tsUNVCOw7foHiDRVLBdAHBZT+xxa3F+Ek9wQiKzxtQQM=",
"result_xdr": "AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAANAAAAAAAAAAIAAAABAAAAAPaTW9sBV2ja6yDUtPcpGpUrnVEHaTHC4I065TklIsguAAAAAD1H0goAAAAAAAAAAlQE8wsAAAABeVhMTQAAAAAiNtdw/g0+AVIZddXPesSEK3CV1rGp12jT6aYy6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AAAAAAAAAADAAAAAAJ90mMAAAAAYtQJSQAAAAAAAAABAn3SfAAAAAAAAAAASnKhtB+bU0r72/GujHEQAt2fSZjYuhLgoRNa60ed6mUAAAAAENitnwJlKSEAAApNAAAACgAAAAEAAAAAxHHGQ3BiyVBqiTQuU4oa2kBNL0HPHTolX0Mh98bg4XUAAAAAAAAACWxvYnN0ci5jbwAAAAEAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAwAAAAACfdJjAAAAAGLUCUkAAAAA",
"memo_type": "none",
"signatures": [
"BWb2a4isrfVn6bZm+ENiG26gdxz+f4w7QM5qJCN9b62xQ1UI7Dt+geINFUsF0AcFlP7HFrcX4ST3BCIrPG1BAw=="
]
}
]
}
}
23 changes: 8 additions & 15 deletions exp/lighthorizon/adapters/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package adapters

import (
"encoding/json"
"net/http"
"net/url"
"os"
"path/filepath"
"strconv"
"testing"

Expand All @@ -22,26 +23,18 @@ import (
// transaction to JSON by actually pulling a transaction from the
// known-to-be-true horizon.stellar.org, turning it into an "ingested"
// transaction, and serializing it.
//
// TODO: Instead of making an unreliable network request, we should just create
// a "known" transaction on-the-fly. We could just hard-code the fields from
// Horizon, anyway.
func TestTransactionAdapter(t *testing.T) {
const URL = "https://horizon.stellar.org/accounts/GBFHFINUD6NVGSX33PY25DDRCABN3H2JTDMLUEXAUEJVV22HTXVGLEZD/transactions?cursor=179530990183178241&limit=1&order=desc"

parsed, err := url.Parse(URL)
require.NoError(t, err)

resp, err := http.Get(URL)
require.NoError(t, err)
require.Equal(t, 200, resp.StatusCode)
f, err := os.Open(filepath.Join("./fixtures", "transactions.json"))
require.NoErrorf(t, err, "are fixtures missing?")

page := protocol.TransactionsPage{}
decoder := json.NewDecoder(resp.Body)
decoder := json.NewDecoder(f)
require.NoError(t, decoder.Decode(&page))
require.Len(t, page.Embedded.Records, 1)
expectedTx := page.Embedded.Records[0]

parsedUrl, err := url.Parse(page.Links.Self.Href)
require.NoError(t, err)
parsedToid, err := strconv.ParseInt(expectedTx.PagingToken(), 10, 64)
require.NoError(t, err)
expectedTxIndex := toid.Parse(parsedToid).TransactionOrder
Expand Down Expand Up @@ -79,7 +72,7 @@ func TestTransactionAdapter(t *testing.T) {
NetworkPassphrase: network.PublicNetworkPassphrase,
}

result, err := PopulateTransaction(parsed, &tx, xdr.NewEncodingBuffer())
result, err := PopulateTransaction(parsedUrl, &tx, xdr.NewEncodingBuffer())
require.NoError(t, err)
assert.Equal(t, expectedTx, result)
}

0 comments on commit c6d5f12

Please sign in to comment.