github.com/stellar/stellar-etl@v1.0.1-0.20240312145900-4874b6bf2b89/internal/transform/account_signer_test.go (about) 1 package transform 2 3 import ( 4 "fmt" 5 "testing" 6 "time" 7 8 "github.com/guregu/null" 9 10 "github.com/stretchr/testify/assert" 11 12 "github.com/stellar/go/ingest" 13 "github.com/stellar/go/xdr" 14 ) 15 16 func TestTransformAccountSigner(t *testing.T) { 17 type inputStruct struct { 18 injest ingest.Change 19 } 20 21 type transformTest struct { 22 input inputStruct 23 wantOutput []AccountSignerOutput 24 wantErr error 25 } 26 27 hardCodedInput := makeSignersTestInput() 28 hardCodedOutput := makeSignersTestOutput() 29 30 tests := []transformTest{ 31 { 32 inputStruct{ 33 ingest.Change{ 34 Type: xdr.LedgerEntryTypeOffer, 35 Pre: nil, 36 Post: &xdr.LedgerEntry{ 37 Data: xdr.LedgerEntryData{ 38 Type: xdr.LedgerEntryTypeOffer, 39 }, 40 }, 41 }, 42 }, 43 nil, fmt.Errorf("could not extract signer data from ledger entry of type: LedgerEntryTypeOffer"), 44 }, 45 { 46 inputStruct{ 47 hardCodedInput, 48 }, 49 hardCodedOutput, nil, 50 }, 51 } 52 53 for _, test := range tests { 54 header := xdr.LedgerHeaderHistoryEntry{ 55 Header: xdr.LedgerHeader{ 56 ScpValue: xdr.StellarValue{ 57 CloseTime: 1000, 58 }, 59 LedgerSeq: 10, 60 }, 61 } 62 actualOutput, actualError := TransformSigners(test.input.injest, header) 63 assert.Equal(t, test.wantErr, actualError) 64 assert.Equal(t, test.wantOutput, actualOutput) 65 } 66 } 67 68 func makeSignersTestInput() ingest.Change { 69 sponsor, _ := xdr.AddressToAccountId("GBADGWKHSUFOC4C7E3KXKINZSRX5KPHUWHH67UGJU77LEORGVLQ3BN3B") 70 71 var ledgerEntry = xdr.LedgerEntry{ 72 LastModifiedLedgerSeq: 30705278, 73 Data: xdr.LedgerEntryData{ 74 Type: xdr.LedgerEntryTypeAccount, 75 Account: &xdr.AccountEntry{ 76 AccountId: testAccount1ID, 77 Balance: 10959979, 78 SeqNum: 117801117454198833, 79 NumSubEntries: 141, 80 InflationDest: &testAccount2ID, 81 Flags: 4, 82 HomeDomain: "examplehome.com", 83 Thresholds: xdr.Thresholds([4]byte{2, 1, 3, 5}), 84 Ext: xdr.AccountEntryExt{ 85 V: 1, 86 V1: &xdr.AccountEntryExtensionV1{ 87 Liabilities: xdr.Liabilities{ 88 Buying: 1000, 89 Selling: 1500, 90 }, 91 Ext: xdr.AccountEntryExtensionV1Ext{ 92 V: 2, 93 V2: &xdr.AccountEntryExtensionV2{ 94 SignerSponsoringIDs: []xdr.SponsorshipDescriptor{ 95 &sponsor, 96 nil, 97 }, 98 }, 99 }, 100 }, 101 }, 102 Signers: []xdr.Signer{ 103 { 104 Key: xdr.SignerKey{ 105 Type: xdr.SignerKeyTypeSignerKeyTypeEd25519, 106 Ed25519: &xdr.Uint256{4, 5, 6}, 107 PreAuthTx: nil, 108 HashX: nil, 109 }, 110 Weight: 10.0, 111 }, { 112 Key: xdr.SignerKey{ 113 Type: xdr.SignerKeyTypeSignerKeyTypeEd25519, 114 Ed25519: &xdr.Uint256{10, 11, 12}, 115 PreAuthTx: nil, 116 HashX: nil, 117 }, 118 Weight: 20.0, 119 }, 120 }, 121 }, 122 }, 123 } 124 return ingest.Change{ 125 Type: xdr.LedgerEntryTypeAccount, 126 Pre: &ledgerEntry, 127 Post: nil, 128 } 129 } 130 131 func makeSignersTestOutput() []AccountSignerOutput { 132 return []AccountSignerOutput{ 133 { 134 AccountID: testAccount1ID.Address(), 135 Signer: "GCEODJVUUVYVFD5KT4TOEDTMXQ76OPFOQC2EMYYMLPXQCUVPOB6XRWPQ", 136 Weight: 2.0, 137 Sponsor: null.String{}, 138 LastModifiedLedger: 30705278, 139 LedgerEntryChange: 2, 140 Deleted: true, 141 LedgerSequence: 10, 142 ClosedAt: time.Date(1970, time.January, 1, 0, 16, 40, 0, time.UTC), 143 }, { 144 AccountID: testAccount1ID.Address(), 145 Signer: "GACAKBQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB3BQ", 146 Weight: 10.0, 147 Sponsor: null.StringFrom("GBADGWKHSUFOC4C7E3KXKINZSRX5KPHUWHH67UGJU77LEORGVLQ3BN3B"), 148 LastModifiedLedger: 30705278, 149 LedgerEntryChange: 2, 150 Deleted: true, 151 LedgerSequence: 10, 152 ClosedAt: time.Date(1970, time.January, 1, 0, 16, 40, 0, time.UTC), 153 }, { 154 AccountID: testAccount1ID.Address(), 155 Signer: "GAFAWDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABNDC", 156 Weight: 20.0, 157 Sponsor: null.String{}, 158 LastModifiedLedger: 30705278, 159 LedgerEntryChange: 2, 160 Deleted: true, 161 LedgerSequence: 10, 162 ClosedAt: time.Date(1970, time.January, 1, 0, 16, 40, 0, time.UTC), 163 }, 164 } 165 }