Skip to content

Commit

Permalink
Root validation working
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcgary committed Oct 29, 2024
1 parent 5204a0e commit 6f661f5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion internal/tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ type GoldStagingExpectedResult struct {
Amount string `csv:"amount"`
}

func GetGoldStagingExpectedResults(projectBase string, snapshotDate string) ([]*GoldStagingExpectedResult, error) {
func GetGoldExpectedResults(projectBase string, snapshotDate string) ([]*GoldStagingExpectedResult, error) {
path := getTestdataPathFromProjectRoot(projectBase, fmt.Sprintf("/7_goldStaging/expectedResults_%s.csv", snapshotDate))
return getExpectedResultsCsvFile[GoldStagingExpectedResult](path)
}
19 changes: 19 additions & 0 deletions pkg/rewards/8_goldFinal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rewards

import (
"go.uber.org/zap"
"time"
)

const _8_goldFinalQuery = `
Expand All @@ -15,6 +16,14 @@ SELECT
FROM {{.goldStagingTable}}
`

type GoldRow struct {
Earner string
Snapshot time.Time
RewardHash string
Token string
Amount string
}

func (rc *RewardsCalculator) GenerateGold8FinalTable(startDate string, snapshotDate string) error {
allTableNames := getGoldTableNames(snapshotDate)

Expand All @@ -38,3 +47,13 @@ func (rc *RewardsCalculator) GenerateGold8FinalTable(startDate string, snapshotD
}
return nil
}

func (rc *RewardsCalculator) ListGoldRows() ([]*GoldRow, error) {
var goldRows []*GoldRow
res := rc.grm.Raw("select * from gold_table").Scan(&goldRows)
if res.Error != nil {
rc.logger.Sugar().Errorw("Failed to list gold rows", "error", res.Error)
return nil, res.Error
}
return goldRows, nil
}
32 changes: 19 additions & 13 deletions pkg/rewards/rewards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,18 @@ func Test_Rewards(t *testing.T) {
t.Fatal(err)
}

snapshotDates = []string{"2024-08-02", "2024-08-11", "2024-08-12", "2024-08-19"}
snapshotDates = []string{
"2024-08-02",
"2024-08-11",
"2024-08-12",
// "2024-08-13",
// "2024-08-14",
// "2024-08-15",
// "2024-08-16",
// "2024-08-17",
// "2024-08-18",
"2024-08-19",
}

fmt.Printf("Hydration duration: %v\n", time.Since(testStart))
testStart = time.Now()
Expand Down Expand Up @@ -305,26 +316,21 @@ func Test_Rewards(t *testing.T) {
fmt.Printf("\tRows in gold_table: %v - [time: %v]\n", rows, time.Since(testStart))
testStart = time.Now()

goldStagingRows, err := rc.ListGoldStagingRowsForSnapshot(snapshotDate)
goldRows, err := rc.ListGoldRows()
assert.Nil(t, err)

t.Logf("Gold staging rows for snapshot %s: %d", snapshotDate, len(goldStagingRows))
t.Logf("Gold staging rows for snapshot %s: %d", snapshotDate, len(goldRows))

fmt.Printf("Total duration for rewards compute %s: %v\n", snapshotDate, time.Since(snapshotStartTime))
testStart = time.Now()

//if !slices.Contains([]string{"2024-08-02", "2024-08-12"}, snapshotDate) {
// t.Logf("Skipping gold staging validation for snapshot date: %s", snapshotDate)
// continue
//}

expectedRows, err := tests.GetGoldStagingExpectedResults(projectRoot, snapshotDate)
expectedRows, err := tests.GetGoldExpectedResults(projectRoot, snapshotDate)
if err != nil {
t.Fatal(err)
}

assert.Equal(t, len(expectedRows), len(goldStagingRows))
t.Logf("Expected rows: %d, Gold staging rows: %d", len(expectedRows), len(goldStagingRows))
assert.Equal(t, len(expectedRows), len(goldRows))
t.Logf("Expected rows: %d, Gold staging rows: %d", len(expectedRows), len(goldRows))

expectedRowsMap := make(map[string]*tests.GoldStagingExpectedResult)

Expand All @@ -339,8 +345,8 @@ func Test_Rewards(t *testing.T) {

missingRows := 0
invalidAmounts := 0
for i, row := range goldStagingRows {
key := fmt.Sprintf("%s_%s_%s_%s", row.Earner, row.Snapshot, row.RewardHash, row.Token)
for i, row := range goldRows {
key := fmt.Sprintf("%s_%s_%s_%s", row.Earner, row.Snapshot.Format(time.DateOnly), row.RewardHash, row.Token)
foundRow, ok := expectedRowsMap[key]
if !ok {
missingRows++
Expand Down

0 comments on commit 6f661f5

Please sign in to comment.