Skip to content

Commit 9f3db12

Browse files
committed
fix test
fix fix test
1 parent fefa25a commit 9f3db12

File tree

3 files changed

+336
-13
lines changed

3 files changed

+336
-13
lines changed

pkg/eigenState/operatorAllocations/operatorAllocations_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"strings"
77
"testing"
8+
"time"
89

910
"github.com/Layr-Labs/sidecar/internal/config"
1011
"github.com/Layr-Labs/sidecar/internal/tests"
@@ -52,6 +53,15 @@ func Test_OperatorAllocations(t *testing.T) {
5253

5354
blockNumber := uint64(102)
5455

56+
// Create the block first (required for foreign key constraint)
57+
block := &storage.Block{
58+
Number: blockNumber,
59+
Hash: "test_hash",
60+
BlockTime: time.Now(),
61+
}
62+
res := grm.Model(&storage.Block{}).Create(block)
63+
assert.Nil(t, res.Error)
64+
5565
log := &storage.TransactionLog{
5666
TransactionHash: "some hash",
5767
TransactionIndex: big.NewInt(100).Uint64(),
@@ -87,7 +97,7 @@ func Test_OperatorAllocations(t *testing.T) {
8797

8898
results := make([]*OperatorAllocation, 0)
8999
query := `select * from operator_allocations where block_number = ?`
90-
res := model.DB.Raw(query, blockNumber).Scan(&results)
100+
res = model.DB.Raw(query, blockNumber).Scan(&results)
91101
assert.Nil(t, res.Error)
92102
assert.Equal(t, 1, len(results))
93103

pkg/rewards/operatorAllocationSnapshots.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const operatorAllocationSnapshotsQuery = `
1111
SELECT *,
1212
ROW_NUMBER() OVER (PARTITION BY operator, avs, strategy, operator_set_id, cast(block_time AS DATE) ORDER BY block_time DESC, log_index DESC) AS rn
1313
FROM operator_allocations oa
14-
INNER JOIN blocks b ON oa.block_number = b.number
14+
INNER JOIN blocks b ON oa.effective_block = b.number
1515
WHERE b.block_time < TIMESTAMP '{{.cutoffDate}}'
1616
),
1717
-- Get the latest record for each day
@@ -42,8 +42,8 @@ const operatorAllocationSnapshotsQuery = `
4242
-- Deallocation (decrease or no change): Round DOWN to current day
4343
CASE
4444
WHEN LAG(magnitude) OVER (PARTITION BY operator, avs, strategy, operator_set_id ORDER BY block_time, block_number, log_index) IS NULL THEN
45-
-- First allocation: round down to current day (conservative default)
46-
date_trunc('day', block_time)
45+
-- First allocation: round up to next day
46+
date_trunc('day', block_time) + INTERVAL '1' day
4747
WHEN magnitude > LAG(magnitude) OVER (PARTITION BY operator, avs, strategy, operator_set_id ORDER BY block_time, block_number, log_index) THEN
4848
-- Increase: round up to next day
4949
date_trunc('day', block_time) + INTERVAL '1' day

0 commit comments

Comments
 (0)