github.com/stellar/stellar-etl@v1.0.1-0.20240312145900-4874b6bf2b89/internal/transform/ledger_transaction_test.go (about) 1 package transform 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/stretchr/testify/assert" 8 9 "github.com/stellar/go/ingest" 10 "github.com/stellar/go/xdr" 11 ) 12 13 func TestTransformTx(t *testing.T) { 14 type inputStruct struct { 15 transaction ingest.LedgerTransaction 16 historyHeader xdr.LedgerHeaderHistoryEntry 17 } 18 type transformTest struct { 19 input inputStruct 20 wantOutput LedgerTransactionOutput 21 wantErr error 22 } 23 24 hardCodedLedgerTransaction, hardCodedLedgerHeader, err := makeLedgerTransactionTestInput() 25 assert.NoError(t, err) 26 hardCodedOutput, err := makeLedgerTransactionTestOutput() 27 assert.NoError(t, err) 28 29 tests := []transformTest{} 30 31 for i := range hardCodedLedgerTransaction { 32 tests = append(tests, transformTest{ 33 input: inputStruct{hardCodedLedgerTransaction[i], hardCodedLedgerHeader[i]}, 34 wantOutput: hardCodedOutput[i], 35 wantErr: nil, 36 }) 37 } 38 39 for _, test := range tests { 40 actualOutput, actualError := TransformLedgerTransaction(test.input.transaction, test.input.historyHeader) 41 assert.Equal(t, test.wantErr, actualError) 42 assert.Equal(t, test.wantOutput, actualOutput) 43 } 44 } 45 46 func makeLedgerTransactionTestOutput() (output []LedgerTransactionOutput, err error) { 47 output = []LedgerTransactionOutput{ 48 LedgerTransactionOutput{ 49 TxEnvelope: "AAAAAgAAAACI4aa0pXFSj6qfJuIObLw/5zyugLRGYwxb7wFSr3B9eAABX5ABjydzAABBtwAAAAEAAAAAAAAAAAAAAABfBqt0AAAAAQAAABdITDVhQ2dvelFISVc3c1NjNVhkY2ZtUgAAAAABAAAAAQAAAAAcR0GXGO76pFs4y38vJVAanjnLg4emNun7zAx0pHcDGAAAAAIAAAAAAAAAAAAAAAAAAAAAAQIDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", 50 Tx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AAAAAAAAABfBqsKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAdG52gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 72 LedgerSequence: 30521818, 73 ClosedAt: time.Date(2020, time.July, 9, 5, 28, 42, 0, time.UTC), 74 }, 75 } 76 return 77 } 78 func makeLedgerTransactionTestInput() (transaction []ingest.LedgerTransaction, historyHeader []xdr.LedgerHeaderHistoryEntry, err error) { 79 hardCodedMemoText := "HL5aCgozQHIW7sSc5XdcfmR" 80 hardCodedTransactionHash := xdr.Hash([32]byte{0xa8, 0x7f, 0xef, 0x5e, 0xeb, 0x26, 0x2, 0x69, 0xc3, 0x80, 0xf2, 0xde, 0x45, 0x6a, 0xad, 0x72, 0xb5, 0x9b, 0xb3, 0x15, 0xaa, 0xac, 0x77, 0x78, 0x60, 0x45, 0x6e, 0x9, 0xda, 0xc0, 0xba, 0xfb}) 81 genericResultResults := &[]xdr.OperationResult{ 82 xdr.OperationResult{ 83 Tr: &xdr.OperationResultTr{ 84 Type: xdr.OperationTypeCreateAccount, 85 CreateAccountResult: &xdr.CreateAccountResult{ 86 Code: 0, 87 }, 88 }, 89 }, 90 } 91 hardCodedMeta := xdr.TransactionMeta{ 92 V: 1, 93 V1: genericTxMeta, 94 } 95 96 source := xdr.MuxedAccount{ 97 Type: xdr.CryptoKeyTypeKeyTypeEd25519, 98 Ed25519: &xdr.Uint256{3, 2, 1}, 99 } 100 destination := xdr.MuxedAccount{ 101 Type: xdr.CryptoKeyTypeKeyTypeEd25519, 102 Ed25519: &xdr.Uint256{1, 2, 3}, 103 } 104 signerKey := xdr.SignerKey{ 105 Type: xdr.SignerKeyTypeSignerKeyTypeEd25519, 106 Ed25519: source.Ed25519, 107 } 108 transaction = []ingest.LedgerTransaction{ 109 ingest.LedgerTransaction{ 110 Index: 1, 111 UnsafeMeta: hardCodedMeta, 112 Envelope: xdr.TransactionEnvelope{ 113 Type: xdr.EnvelopeTypeEnvelopeTypeTx, 114 V1: &xdr.TransactionV1Envelope{ 115 Tx: xdr.Transaction{ 116 SourceAccount: testAccount1, 117 SeqNum: 112351890582290871, 118 Memo: xdr.Memo{ 119 Type: xdr.MemoTypeMemoText, 120 Text: &hardCodedMemoText, 121 }, 122 Fee: 90000, 123 Cond: xdr.Preconditions{ 124 Type: xdr.PreconditionTypePrecondTime, 125 TimeBounds: &xdr.TimeBounds{ 126 MinTime: 0, 127 MaxTime: 1594272628, 128 }, 129 }, 130 Operations: []xdr.Operation{ 131 xdr.Operation{ 132 SourceAccount: &testAccount2, 133 Body: xdr.OperationBody{ 134 Type: xdr.OperationTypePathPaymentStrictReceive, 135 PathPaymentStrictReceiveOp: &xdr.PathPaymentStrictReceiveOp{ 136 Destination: destination, 137 }, 138 }, 139 }, 140 }, 141 }, 142 }, 143 }, 144 Result: xdr.TransactionResultPair{ 145 TransactionHash: hardCodedTransactionHash, 146 Result: xdr.TransactionResult{ 147 FeeCharged: 300, 148 Result: xdr.TransactionResultResult{ 149 Code: xdr.TransactionResultCodeTxFailed, 150 Results: genericResultResults, 151 }, 152 }, 153 }, 154 }, 155 ingest.LedgerTransaction{ 156 Index: 1, 157 UnsafeMeta: hardCodedMeta, 158 Envelope: xdr.TransactionEnvelope{ 159 Type: xdr.EnvelopeTypeEnvelopeTypeTxFeeBump, 160 FeeBump: &xdr.FeeBumpTransactionEnvelope{ 161 Tx: xdr.FeeBumpTransaction{ 162 FeeSource: testAccount3, 163 Fee: 7200, 164 InnerTx: xdr.FeeBumpTransactionInnerTx{ 165 Type: xdr.EnvelopeTypeEnvelopeTypeTx, 166 V1: &xdr.TransactionV1Envelope{ 167 Tx: xdr.Transaction{ 168 SourceAccount: testAccount1, 169 SeqNum: 150015399398735997, 170 Memo: xdr.Memo{ 171 Type: xdr.MemoTypeMemoText, 172 Text: &hardCodedMemoText, 173 }, 174 Cond: xdr.Preconditions{ 175 Type: xdr.PreconditionTypePrecondTime, 176 TimeBounds: &xdr.TimeBounds{ 177 MinTime: 0, 178 MaxTime: 1594272628, 179 }, 180 }, 181 Operations: []xdr.Operation{ 182 xdr.Operation{ 183 SourceAccount: &testAccount2, 184 Body: xdr.OperationBody{ 185 Type: xdr.OperationTypePathPaymentStrictReceive, 186 PathPaymentStrictReceiveOp: &xdr.PathPaymentStrictReceiveOp{ 187 Destination: destination, 188 }, 189 }, 190 }, 191 }, 192 }, 193 }, 194 }, 195 }, 196 }, 197 }, 198 Result: xdr.TransactionResultPair{ 199 TransactionHash: hardCodedTransactionHash, 200 Result: xdr.TransactionResult{ 201 FeeCharged: 300, 202 Result: xdr.TransactionResultResult{ 203 Code: xdr.TransactionResultCodeTxFeeBumpInnerSuccess, 204 InnerResultPair: &xdr.InnerTransactionResultPair{ 205 TransactionHash: hardCodedTransactionHash, 206 Result: xdr.InnerTransactionResult{ 207 FeeCharged: 100, 208 Result: xdr.InnerTransactionResultResult{ 209 Code: xdr.TransactionResultCodeTxSuccess, 210 Results: &[]xdr.OperationResult{ 211 xdr.OperationResult{ 212 Tr: &xdr.OperationResultTr{ 213 CreateAccountResult: &xdr.CreateAccountResult{}, 214 }, 215 }, 216 }, 217 }, 218 }, 219 }, 220 Results: &[]xdr.OperationResult{ 221 xdr.OperationResult{}, 222 }, 223 }, 224 }, 225 }, 226 }, 227 ingest.LedgerTransaction{ 228 Index: 1, 229 UnsafeMeta: hardCodedMeta, 230 Envelope: xdr.TransactionEnvelope{ 231 Type: xdr.EnvelopeTypeEnvelopeTypeTx, 232 V1: &xdr.TransactionV1Envelope{ 233 Tx: xdr.Transaction{ 234 SourceAccount: testAccount2, 235 SeqNum: 118426953012574851, 236 Memo: xdr.Memo{ 237 Type: xdr.MemoTypeMemoText, 238 Text: &hardCodedMemoText, 239 }, 240 Fee: 100, 241 Cond: xdr.Preconditions{ 242 Type: xdr.PreconditionTypePrecondV2, 243 V2: &xdr.PreconditionsV2{ 244 TimeBounds: &xdr.TimeBounds{ 245 MinTime: 0, 246 MaxTime: 1594272628, 247 }, 248 LedgerBounds: &xdr.LedgerBounds{ 249 MinLedger: 5, 250 MaxLedger: 10, 251 }, 252 ExtraSigners: []xdr.SignerKey{signerKey}, 253 }, 254 }, 255 Operations: []xdr.Operation{ 256 xdr.Operation{ 257 SourceAccount: &testAccount4, 258 Body: xdr.OperationBody{ 259 Type: xdr.OperationTypePathPaymentStrictReceive, 260 PathPaymentStrictReceiveOp: &xdr.PathPaymentStrictReceiveOp{ 261 Destination: destination, 262 }, 263 }, 264 }, 265 }, 266 }, 267 }, 268 }, 269 Result: xdr.TransactionResultPair{ 270 TransactionHash: hardCodedTransactionHash, 271 Result: xdr.TransactionResult{ 272 FeeCharged: 100, 273 Result: xdr.TransactionResultResult{ 274 Code: xdr.TransactionResultCodeTxFailed, 275 Results: genericResultResults, 276 }, 277 }, 278 }, 279 }, 280 } 281 historyHeader = []xdr.LedgerHeaderHistoryEntry{ 282 xdr.LedgerHeaderHistoryEntry{ 283 Header: xdr.LedgerHeader{ 284 LedgerSeq: 30521816, 285 ScpValue: xdr.StellarValue{CloseTime: 1594272522}, 286 }, 287 }, 288 xdr.LedgerHeaderHistoryEntry{ 289 Header: xdr.LedgerHeader{ 290 LedgerSeq: 30521817, 291 ScpValue: xdr.StellarValue{CloseTime: 1594272522}, 292 }, 293 }, 294 xdr.LedgerHeaderHistoryEntry{ 295 Header: xdr.LedgerHeader{ 296 LedgerSeq: 30521818, 297 ScpValue: xdr.StellarValue{CloseTime: 1594272522}, 298 }, 299 }, 300 } 301 return 302 }