github.com/stellar/stellar-etl@v1.0.1-0.20240312145900-4874b6bf2b89/internal/transform/config_setting_test.go (about)

     1  package transform
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  
    10  	"github.com/stellar/go/ingest"
    11  	"github.com/stellar/go/xdr"
    12  )
    13  
    14  func TestTransformConfigSetting(t *testing.T) {
    15  	type transformTest struct {
    16  		input      ingest.Change
    17  		wantOutput ConfigSettingOutput
    18  		wantErr    error
    19  	}
    20  
    21  	hardCodedInput := makeConfigSettingTestInput()
    22  	hardCodedOutput := makeConfigSettingTestOutput()
    23  	tests := []transformTest{
    24  		{
    25  			ingest.Change{
    26  				Type: xdr.LedgerEntryTypeOffer,
    27  				Pre:  nil,
    28  				Post: &xdr.LedgerEntry{
    29  					Data: xdr.LedgerEntryData{
    30  						Type: xdr.LedgerEntryTypeOffer,
    31  					},
    32  				},
    33  			},
    34  			ConfigSettingOutput{}, fmt.Errorf("Could not extract config setting from ledger entry; actual type is LedgerEntryTypeOffer"),
    35  		},
    36  	}
    37  
    38  	for i := range hardCodedInput {
    39  		tests = append(tests, transformTest{
    40  			input:      hardCodedInput[i],
    41  			wantOutput: hardCodedOutput[i],
    42  			wantErr:    nil,
    43  		})
    44  	}
    45  
    46  	for _, test := range tests {
    47  		header := xdr.LedgerHeaderHistoryEntry{
    48  			Header: xdr.LedgerHeader{
    49  				ScpValue: xdr.StellarValue{
    50  					CloseTime: 1000,
    51  				},
    52  				LedgerSeq: 10,
    53  			},
    54  		}
    55  		actualOutput, actualError := TransformConfigSetting(test.input, header)
    56  		assert.Equal(t, test.wantErr, actualError)
    57  		assert.Equal(t, test.wantOutput, actualOutput)
    58  	}
    59  }
    60  
    61  func makeConfigSettingTestInput() []ingest.Change {
    62  	var contractMaxByte xdr.Uint32 = 0
    63  
    64  	contractDataLedgerEntry := xdr.LedgerEntry{
    65  		LastModifiedLedgerSeq: 24229503,
    66  		Data: xdr.LedgerEntryData{
    67  			Type: xdr.LedgerEntryTypeConfigSetting,
    68  			ConfigSetting: &xdr.ConfigSettingEntry{
    69  				ConfigSettingId:      xdr.ConfigSettingIdConfigSettingContractMaxSizeBytes,
    70  				ContractMaxSizeBytes: &contractMaxByte,
    71  			},
    72  		},
    73  	}
    74  
    75  	return []ingest.Change{
    76  		{
    77  			Type: xdr.LedgerEntryTypeConfigSetting,
    78  			Pre:  &xdr.LedgerEntry{},
    79  			Post: &contractDataLedgerEntry,
    80  		},
    81  	}
    82  }
    83  
    84  func makeConfigSettingTestOutput() []ConfigSettingOutput {
    85  	contractMapType := make([]map[string]string, 0, 0)
    86  	bucket := make([]uint64, 0, 0)
    87  
    88  	return []ConfigSettingOutput{
    89  		{
    90  			ConfigSettingId:                 0,
    91  			ContractMaxSizeBytes:            0,
    92  			LedgerMaxInstructions:           0,
    93  			TxMaxInstructions:               0,
    94  			FeeRatePerInstructionsIncrement: 0,
    95  			TxMemoryLimit:                   0,
    96  			LedgerMaxReadLedgerEntries:      0,
    97  			LedgerMaxReadBytes:              0,
    98  			LedgerMaxWriteLedgerEntries:     0,
    99  			LedgerMaxWriteBytes:             0,
   100  			TxMaxReadLedgerEntries:          0,
   101  			TxMaxReadBytes:                  0,
   102  			TxMaxWriteLedgerEntries:         0,
   103  			TxMaxWriteBytes:                 0,
   104  			FeeReadLedgerEntry:              0,
   105  			FeeWriteLedgerEntry:             0,
   106  			FeeRead1Kb:                      0,
   107  			BucketListTargetSizeBytes:       0,
   108  			WriteFee1KbBucketListLow:        0,
   109  			WriteFee1KbBucketListHigh:       0,
   110  			BucketListWriteFeeGrowthFactor:  0,
   111  			FeeHistorical1Kb:                0,
   112  			TxMaxContractEventsSizeBytes:    0,
   113  			FeeContractEvents1Kb:            0,
   114  			LedgerMaxTxsSizeBytes:           0,
   115  			TxMaxSizeBytes:                  0,
   116  			FeeTxSize1Kb:                    0,
   117  			ContractCostParamsCpuInsns:      contractMapType,
   118  			ContractCostParamsMemBytes:      contractMapType,
   119  			ContractDataKeySizeBytes:        0,
   120  			ContractDataEntrySizeBytes:      0,
   121  			MaxEntryTtl:                     0,
   122  			MinTemporaryTtl:                 0,
   123  			MinPersistentTtl:                0,
   124  			AutoBumpLedgers:                 0,
   125  			PersistentRentRateDenominator:   0,
   126  			TempRentRateDenominator:         0,
   127  			MaxEntriesToArchive:             0,
   128  			BucketListSizeWindowSampleSize:  0,
   129  			EvictionScanSize:                0,
   130  			StartingEvictionScanLevel:       0,
   131  			LedgerMaxTxCount:                0,
   132  			BucketListSizeWindow:            bucket,
   133  			LastModifiedLedger:              24229503,
   134  			LedgerEntryChange:               1,
   135  			Deleted:                         false,
   136  			LedgerSequence:                  10,
   137  			ClosedAt:                        time.Date(1970, time.January, 1, 0, 16, 40, 0, time.UTC),
   138  		},
   139  	}
   140  }