github.com/stellar/stellar-etl@v1.0.1-0.20240312145900-4874b6bf2b89/internal/transform/claimable_balance_test.go (about) 1 package transform 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/guregu/null" 8 "github.com/stellar/go/ingest" 9 "github.com/stellar/go/xdr" 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestTransformClaimableBalance(t *testing.T) { 14 type inputStruct struct { 15 ingest ingest.Change 16 } 17 type transformTest struct { 18 input inputStruct 19 wantOutput ClaimableBalanceOutput 20 wantErr error 21 } 22 inputChange := makeClaimableBalanceTestInput() 23 output := makeClaimableBalanceTestOutput() 24 25 input := inputStruct{ 26 inputChange, 27 } 28 29 tests := []transformTest{ 30 { 31 input: input, 32 wantOutput: output, 33 wantErr: nil, 34 }, 35 } 36 37 for _, test := range tests { 38 header := xdr.LedgerHeaderHistoryEntry{ 39 Header: xdr.LedgerHeader{ 40 ScpValue: xdr.StellarValue{ 41 CloseTime: 1000, 42 }, 43 LedgerSeq: 10, 44 }, 45 } 46 actualOutput, actualError := TransformClaimableBalance(test.input.ingest, header) 47 assert.Equal(t, test.wantErr, actualError) 48 assert.Equal(t, test.wantOutput, actualOutput) 49 } 50 } 51 52 func makeClaimableBalanceTestInput() ingest.Change { 53 ledgerEntry := xdr.LedgerEntry{ 54 Ext: xdr.LedgerEntryExt{ 55 V: 1, 56 V1: &xdr.LedgerEntryExtensionV1{ 57 SponsoringId: &xdr.AccountId{ 58 Type: 0, 59 Ed25519: &xdr.Uint256{1, 2, 3, 4, 5, 6, 7, 8, 9}, 60 }, 61 Ext: xdr.LedgerEntryExtensionV1Ext{ 62 V: 1, 63 }, 64 }, 65 }, 66 LastModifiedLedgerSeq: 30705278, 67 Data: xdr.LedgerEntryData{ 68 Type: xdr.LedgerEntryTypeClaimableBalance, 69 ClaimableBalance: &xdr.ClaimableBalanceEntry{ 70 BalanceId: genericClaimableBalance, 71 Claimants: []xdr.Claimant{ 72 { 73 Type: 0, 74 V0: &xdr.ClaimantV0{ 75 Destination: testAccount1ID, 76 }, 77 }, 78 }, 79 Asset: xdr.Asset{ 80 Type: xdr.AssetTypeAssetTypeCreditAlphanum12, 81 AlphaNum12: &xdr.AlphaNum12{ 82 AssetCode: xdr.AssetCode12{1, 2, 3, 4, 5, 6, 7, 8, 9}, 83 Issuer: testAccount3ID, 84 }, 85 }, 86 Amount: 9990000000, 87 Ext: xdr.ClaimableBalanceEntryExt{ 88 V: 1, 89 V1: &xdr.ClaimableBalanceEntryExtensionV1{ 90 Ext: xdr.ClaimableBalanceEntryExtensionV1Ext{ 91 V: 1, 92 }, 93 Flags: 10, 94 }, 95 }, 96 }, 97 }, 98 } 99 return ingest.Change{ 100 Type: xdr.LedgerEntryTypeClaimableBalance, 101 Pre: &ledgerEntry, 102 Post: nil, 103 } 104 } 105 106 func makeClaimableBalanceTestOutput() ClaimableBalanceOutput { 107 return ClaimableBalanceOutput{ 108 BalanceID: "000000000102030405060708090000000000000000000000000000000000000000000000", 109 Claimants: []Claimant{ 110 { 111 Destination: "GCEODJVUUVYVFD5KT4TOEDTMXQ76OPFOQC2EMYYMLPXQCUVPOB6XRWPQ", 112 Predicate: xdr.ClaimPredicate{ 113 Type: xdr.ClaimPredicateTypeClaimPredicateUnconditional, 114 }, 115 }, 116 }, 117 AssetIssuer: "GBT4YAEGJQ5YSFUMNKX6BPBUOCPNAIOFAVZOF6MIME2CECBMEIUXFZZN", 118 AssetType: "credit_alphanum12", 119 AssetCode: "\x01\x02\x03\x04\x05\x06\a\b\t", 120 AssetAmount: 999, 121 AssetID: -4023078858747574648, 122 Sponsor: null.StringFrom("GAAQEAYEAUDAOCAJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABO3W"), 123 Flags: 10, 124 LastModifiedLedger: 30705278, 125 LedgerEntryChange: 2, 126 Deleted: true, 127 LedgerSequence: 10, 128 ClosedAt: time.Date(1970, time.January, 1, 0, 16, 40, 0, time.UTC), 129 } 130 }