Skip to content

Commit

Permalink
Export more funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
amishas157 committed Nov 26, 2024
1 parent dcae12f commit 323425d
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 51 deletions.
5 changes: 5 additions & 0 deletions cmd/command_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

var executableName = "stellar-etl"
var update = flag.Bool("update", false, "update the golden files of this test")
var gotFolder = "testdata/got/"

type CloudStorage interface {
UploadTo(credentialsPath, bucket, path string) error
Expand Down Expand Up @@ -331,3 +332,7 @@ func sortByName(files []os.DirEntry) {
return files[i].Name() < files[j].Name()
})
}

func GotTestDir(t *testing.T, filename string) string {
return filepath.Join(gotFolder, t.Name(), filename)
}
8 changes: 4 additions & 4 deletions cmd/export_assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ func TestExportAssets(t *testing.T) {
tests := []CliTest{
{
name: "assets from one ledger",
args: []string{"export_assets", "-s", "30820015", "-e", "30820015", "-o", gotTestDir(t, "one_ledger_assets.txt")},
args: []string{"export_assets", "-s", "30820015", "-e", "30820015", "-o", GotTestDir(t, "one_ledger_assets.txt")},
golden: "one_ledger_assets.golden",
wantErr: nil,
},
{
name: "assets from 10 ledgers",
args: []string{"export_assets", "-s", "30822015", "-e", "30822025", "-o", gotTestDir(t, "10_ledgers_assets.txt")},
args: []string{"export_assets", "-s", "30822015", "-e", "30822025", "-o", GotTestDir(t, "10_ledgers_assets.txt")},
golden: "10_ledgers_assets.golden",
wantErr: nil,
},
{
name: "range too large",
args: []string{"export_assets", "-s", "30822015", "-e", "30822025", "-l", "5", "-o", gotTestDir(t, "large_range_assets.txt")},
args: []string{"export_assets", "-s", "30822015", "-e", "30822025", "-l", "5", "-o", GotTestDir(t, "large_range_assets.txt")},
golden: "large_range_assets.golden",
wantErr: nil,
},
{
name: "ledger with no assets",
args: []string{"export_assets", "-s", "10363513", "-e", "10363513", "-o", gotTestDir(t, "ledger_no_assets.txt")},
args: []string{"export_assets", "-s", "10363513", "-e", "10363513", "-o", GotTestDir(t, "ledger_no_assets.txt")},
golden: "ledger_no_assets.golden",
wantErr: nil,
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/export_contract_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func TestExportContractEvents(t *testing.T) {
tests := []CliTest{
{
name: "contract events from multiple ledger",
args: []string{"export_contract_events", "-s", "52271338", "-e", "52271350", "-o", gotTestDir(t, "large_range_ledger_txs.txt")},
args: []string{"export_contract_events", "-s", "52271338", "-e", "52271350", "-o", GotTestDir(t, "large_range_ledger_txs.txt")},
golden: "large_range_ledger_txs.golden",
wantErr: nil,
},
Expand Down
8 changes: 4 additions & 4 deletions cmd/export_effects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ func TestExportEffects(t *testing.T) {
tests := []CliTest{
{
name: "effects from one ledger",
args: []string{"export_effects", "-s", "30820015", "-e", "30820015", "-o", gotTestDir(t, "one_ledger_effects.txt")},
args: []string{"export_effects", "-s", "30820015", "-e", "30820015", "-o", GotTestDir(t, "one_ledger_effects.txt")},
golden: "one_ledger_effects.golden",
wantErr: nil,
},
{
name: "effects from 10 ledgers",
args: []string{"export_effects", "-s", "30822015", "-e", "30822025", "-o", gotTestDir(t, "10_ledgers_effects.txt")},
args: []string{"export_effects", "-s", "30822015", "-e", "30822025", "-o", GotTestDir(t, "10_ledgers_effects.txt")},
golden: "10_ledgers_effects.golden",
wantErr: nil,
},
{
name: "range too large",
args: []string{"export_effects", "-s", "25820678", "-e", "25821678", "-l", "5", "-o", gotTestDir(t, "large_range_effects.txt")},
args: []string{"export_effects", "-s", "25820678", "-e", "25821678", "-l", "5", "-o", GotTestDir(t, "large_range_effects.txt")},
golden: "large_range_effects.golden",
wantErr: nil,
},
{
name: "ledger with no effects",
args: []string{"export_effects", "-s", "10363513", "-e", "10363513", "-o", gotTestDir(t, "ledger_no_effects.txt")},
args: []string{"export_effects", "-s", "10363513", "-e", "10363513", "-o", GotTestDir(t, "ledger_no_effects.txt")},
golden: "ledger_no_effects.golden",
wantErr: nil,
},
Expand Down
20 changes: 10 additions & 10 deletions cmd/export_ledger_entry_changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,70 +25,70 @@ func TestExportChanges(t *testing.T) {
},
{
name: "All changes from ledger entry",
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "49265302", "-e", "49265350", "-o", gotTestDir(t, "all/")},
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "49265302", "-e", "49265350", "-o", GotTestDir(t, "all/")},
golden: "all.golden",
wantErr: nil,
sortForComparison: true,
},
{
name: "Account changes from ledger entry",
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "49265302", "-e", "49265400", "-o", gotTestDir(t, "accounts/"), "--export-accounts", "true"},
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "49265302", "-e", "49265400", "-o", GotTestDir(t, "accounts/"), "--export-accounts", "true"},
golden: "accounts.golden",
wantErr: nil,
sortForComparison: true,
},
{
name: "Claimable balance from ledger entry",
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "49265302", "-e", "49265400", "-o", gotTestDir(t, "claimable_balances/"), "--export-balances", "true"},
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "49265302", "-e", "49265400", "-o", GotTestDir(t, "claimable_balances/"), "--export-balances", "true"},
golden: "claimable_balances.golden",
wantErr: nil,
sortForComparison: true,
},
{
name: "trustlines from ledger entry",
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "49265302", "-e", "49265400", "-o", gotTestDir(t, "trustlines/"), "--export-trustlines", "true"},
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "49265302", "-e", "49265400", "-o", GotTestDir(t, "trustlines/"), "--export-trustlines", "true"},
golden: "trustlines.golden",
wantErr: nil,
sortForComparison: true,
},
{
name: "Offers from ledger entry",
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "49265302", "-e", "49265400", "-o", gotTestDir(t, "offers/"), "--export-offers", "true"},
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "49265302", "-e", "49265400", "-o", GotTestDir(t, "offers/"), "--export-offers", "true"},
golden: "offers.golden",
wantErr: nil,
sortForComparison: true,
},
{
name: "Pools from ledger entry",
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "49265302", "-e", "49265400", "-o", gotTestDir(t, "pools/"), "--export-pools", "true"},
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "49265302", "-e", "49265400", "-o", GotTestDir(t, "pools/"), "--export-pools", "true"},
golden: "pools.golden",
wantErr: nil,
sortForComparison: true,
},
{
name: "Contract code from ledger entry",
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "50666990", "-e", "50666999", "-o", gotTestDir(t, "contract_code/"), "--export-contract-code", "true"},
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "50666990", "-e", "50666999", "-o", GotTestDir(t, "contract_code/"), "--export-contract-code", "true"},
golden: "contract_code.golden",
wantErr: nil,
sortForComparison: true,
},
{
name: "Contract data from ledger entry",
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "51340657", "-e", "51340757", "-o", gotTestDir(t, "contract_data/"), "--export-contract-data", "true"},
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "51340657", "-e", "51340757", "-o", GotTestDir(t, "contract_data/"), "--export-contract-data", "true"},
golden: "contract_data.golden",
wantErr: nil,
sortForComparison: true,
},
{
name: "Config setting from ledger entry",
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "50457424", "-e", "50457440", "-o", gotTestDir(t, "config_setting/"), "--export-config-settings", "true"},
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "50457424", "-e", "50457440", "-o", GotTestDir(t, "config_setting/"), "--export-config-settings", "true"},
golden: "config_setting.golden",
wantErr: nil,
sortForComparison: true,
},
{
name: "ttl from ledger entry",
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "50603521", "-e", "50603621", "-o", gotTestDir(t, "ttl/"), "--export-ttl", "true"},
args: []string{"export_ledger_entry_changes", "-x", coreExecutablePath, "-c", coreConfigPath, "-s", "50603521", "-e", "50603621", "-o", GotTestDir(t, "ttl/"), "--export-ttl", "true"},
golden: "ttl.golden",
wantErr: nil,
sortForComparison: true,
Expand Down
2 changes: 1 addition & 1 deletion cmd/export_ledger_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func TestExportLedgerTransaction(t *testing.T) {
tests := []CliTest{
{
name: "Transactions from one ledger",
args: []string{"export_ledger_transaction", "-s", "30820015", "-e", "30820015", "-o", gotTestDir(t, "ledger_transactions.txt")},
args: []string{"export_ledger_transaction", "-s", "30820015", "-e", "30820015", "-o", GotTestDir(t, "ledger_transactions.txt")},
golden: "ledger_transactions.golden",
wantErr: nil,
},
Expand Down
15 changes: 4 additions & 11 deletions cmd/export_ledgers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"testing"
)

var gotFolder = "testdata/got/"

func TestMain(m *testing.M) {
if err := os.Chdir(".."); err != nil {
cmdLogger.Error("could not change directory", err)
Expand All @@ -29,10 +26,6 @@ func TestMain(m *testing.M) {
os.Exit(exitCode)
}

func gotTestDir(t *testing.T, filename string) string {
return filepath.Join(gotFolder, t.Name(), filename)
}

func TestExportLedger(t *testing.T) {
tests := []CliTest{
{
Expand All @@ -55,25 +48,25 @@ func TestExportLedger(t *testing.T) {
},
{
name: "single ledger",
args: []string{"export_ledgers", "-s", "30822015", "-e", "30822015", "-o", gotTestDir(t, "single_ledger.txt")},
args: []string{"export_ledgers", "-s", "30822015", "-e", "30822015", "-o", GotTestDir(t, "single_ledger.txt")},
golden: "single_ledger.golden",
wantErr: nil,
},
{
name: "10 ledgers",
args: []string{"export_ledgers", "-s", "30822015", "-e", "30822025", "-o", gotTestDir(t, "10_ledgers.txt")},
args: []string{"export_ledgers", "-s", "30822015", "-e", "30822025", "-o", GotTestDir(t, "10_ledgers.txt")},
golden: "10_ledgers.golden",
wantErr: nil,
},
{
name: "range too large",
args: []string{"export_ledgers", "-s", "30822015", "-e", "30822025", "-l", "5", "-o", gotTestDir(t, "large_range_ledgers.txt")},
args: []string{"export_ledgers", "-s", "30822015", "-e", "30822025", "-l", "5", "-o", GotTestDir(t, "large_range_ledgers.txt")},
golden: "large_range_ledgers.golden",
wantErr: nil,
},
{
name: "range from 2024",
args: []string{"export_ledgers", "-s", "52929555", "-e", "52929960", "-o", gotTestDir(t, "2024_ledgers.txt")},
args: []string{"export_ledgers", "-s", "52929555", "-e", "52929960", "-o", GotTestDir(t, "2024_ledgers.txt")},
golden: "2024_ledgers.golden",
wantErr: nil,
},
Expand Down
8 changes: 4 additions & 4 deletions cmd/export_operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ func TestExportOperations(t *testing.T) {
tests := []CliTest{
{
name: "operations from one ledger",
args: []string{"export_operations", "-s", "30820015", "-e", "30820015", "-o", gotTestDir(t, "one_ledger_ops.txt")},
args: []string{"export_operations", "-s", "30820015", "-e", "30820015", "-o", GotTestDir(t, "one_ledger_ops.txt")},
golden: "one_ledger_ops.golden",
wantErr: nil,
},
{
name: "operations from 10 ledgers",
args: []string{"export_operations", "-s", "30822015", "-e", "30822025", "-o", gotTestDir(t, "10_ledgers_ops.txt")},
args: []string{"export_operations", "-s", "30822015", "-e", "30822025", "-o", GotTestDir(t, "10_ledgers_ops.txt")},
golden: "10_ledgers_ops.golden",
wantErr: nil,
},
{
name: "range too large",
args: []string{"export_operations", "-s", "30822015", "-e", "30822025", "-l", "5", "-o", gotTestDir(t, "large_range_ops.txt")},
args: []string{"export_operations", "-s", "30822015", "-e", "30822025", "-l", "5", "-o", GotTestDir(t, "large_range_ops.txt")},
golden: "large_range_ops.golden",
wantErr: nil,
},
{
name: "ledger with no operations",
args: []string{"export_operations", "-s", "10363513", "-e", "10363513", "-o", gotTestDir(t, "ledger_no_ops.txt")},
args: []string{"export_operations", "-s", "10363513", "-e", "10363513", "-o", GotTestDir(t, "ledger_no_ops.txt")},
golden: "ledger_no_ops.golden",
wantErr: nil,
},
Expand Down
8 changes: 4 additions & 4 deletions cmd/export_trades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ func TestExportTrades(t *testing.T) {
tests := []CliTest{
{
name: "trades from one ledger",
args: []string{"export_trades", "-s", "28770265", "-e", "28770265", "-o", gotTestDir(t, "one_ledger_trades.txt")},
args: []string{"export_trades", "-s", "28770265", "-e", "28770265", "-o", GotTestDir(t, "one_ledger_trades.txt")},
golden: "one_ledger_trades.golden",
wantErr: nil,
},
{
name: "trades from 10 ledgers",
args: []string{"export_trades", "-s", "28770265", "-e", "28770275", "-o", gotTestDir(t, "10_ledgers_trades.txt")},
args: []string{"export_trades", "-s", "28770265", "-e", "28770275", "-o", GotTestDir(t, "10_ledgers_trades.txt")},
golden: "10_ledgers_trades.golden",
wantErr: nil,
},
{
name: "range too large",
args: []string{"export_trades", "-s", "28770265", "-e", "28770275", "-l", "5", "-o", gotTestDir(t, "large_range_trades.txt")},
args: []string{"export_trades", "-s", "28770265", "-e", "28770275", "-l", "5", "-o", GotTestDir(t, "large_range_trades.txt")},
golden: "large_range_trades.golden",
wantErr: nil,
},
{
name: "ledger with no trades",
args: []string{"export_trades", "-s", "10363513", "-e", "10363513", "-o", gotTestDir(t, "ledger_no_trades.txt")},
args: []string{"export_trades", "-s", "10363513", "-e", "10363513", "-o", GotTestDir(t, "ledger_no_trades.txt")},
golden: "ledger_no_trades.golden",
wantErr: nil,
},
Expand Down
8 changes: 4 additions & 4 deletions cmd/export_transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ func TestExportTransactions(t *testing.T) {
tests := []CliTest{
{
name: "transactions from one ledger",
args: []string{"export_transactions", "-s", "30820015", "-e", "30820015", "-o", gotTestDir(t, "one_ledger_txs.txt")},
args: []string{"export_transactions", "-s", "30820015", "-e", "30820015", "-o", GotTestDir(t, "one_ledger_txs.txt")},
golden: "one_ledger_txs.golden",
wantErr: nil,
},
{
name: "transactions from 10 ledgers",
args: []string{"export_transactions", "-s", "30822015", "-e", "30822025", "-o", gotTestDir(t, "10_ledgers_txs.txt")},
args: []string{"export_transactions", "-s", "30822015", "-e", "30822025", "-o", GotTestDir(t, "10_ledgers_txs.txt")},
golden: "10_ledgers_txs.golden",
wantErr: nil,
},
{
name: "range too large",
args: []string{"export_transactions", "-s", "30822015", "-e", "30822025", "-l", "5", "-o", gotTestDir(t, "large_range_txs.txt")},
args: []string{"export_transactions", "-s", "30822015", "-e", "30822025", "-l", "5", "-o", GotTestDir(t, "large_range_txs.txt")},
golden: "large_range_txs.golden",
wantErr: nil,
},
{
name: "ledger with no transactions",
args: []string{"export_transactions", "-s", "10363513", "-e", "10363513", "-o", gotTestDir(t, "ledger_no_txs.txt")},
args: []string{"export_transactions", "-s", "10363513", "-e", "10363513", "-o", GotTestDir(t, "ledger_no_txs.txt")},
golden: "ledger_no_txs.golden",
wantErr: nil,
},
Expand Down
Loading

0 comments on commit 323425d

Please sign in to comment.