/
main.go
48 lines (40 loc) · 1.28 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Package transactions offers common infrastructure for testing Transactions
package transactions
import (
"encoding/hex"
"testing"
"github.com/stellar/go/ingest"
"github.com/stellar/go/xdr"
"github.com/stretchr/testify/assert"
)
// TestTransaction transaction meta
type TestTransaction struct {
Index uint32
EnvelopeXDR string
ResultXDR string
FeeChangesXDR string
MetaXDR string
Hash string
}
// BuildLedgerTransaction builds a ledger transaction
func BuildLedgerTransaction(t *testing.T, tx TestTransaction) ingest.LedgerTransaction {
transaction := ingest.LedgerTransaction{
Index: tx.Index,
Envelope: xdr.TransactionEnvelope{},
Result: xdr.TransactionResultPair{},
FeeChanges: xdr.LedgerEntryChanges{},
UnsafeMeta: xdr.TransactionMeta{},
}
tt := assert.New(t)
err := xdr.SafeUnmarshalBase64(tx.EnvelopeXDR, &transaction.Envelope)
tt.NoError(err)
err = xdr.SafeUnmarshalBase64(tx.ResultXDR, &transaction.Result.Result)
tt.NoError(err)
err = xdr.SafeUnmarshalBase64(tx.MetaXDR, &transaction.UnsafeMeta)
tt.NoError(err)
err = xdr.SafeUnmarshalBase64(tx.FeeChangesXDR, &transaction.FeeChanges)
tt.NoError(err)
_, err = hex.Decode(transaction.Result.TransactionHash[:], []byte(tx.Hash))
tt.NoError(err)
return transaction
}