Skip to content

Commit

Permalink
Test initial ema score
Browse files Browse the repository at this point in the history
  • Loading branch information
guilherme-brandao committed Dec 18, 2024
1 parent 0862872 commit db18762
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions x/emissions/module/rewards/scores_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1804,3 +1804,41 @@ func (s *RewardsTestSuite) TestGenerateReputerScoresWithZeroListeningCoefficient
s.Require().NoError(err)
s.Require().True(coefficient.Coefficient.Equal(params.EpsilonReputer))
}

func (s *RewardsTestSuite) TestCalculateTopicInitialEmaScore() {
// Setup test scores
scores := []types.Score{
{Score: alloraMath.MustNewDecFromString("0.5")},

Check failure on line 1811 in x/emissions/module/rewards/scores_test.go

View workflow job for this annotation

GitHub Actions / lint

types.Score is missing fields TopicId, BlockHeight, Address (exhaustruct)
{Score: alloraMath.MustNewDecFromString("0.3")},

Check failure on line 1812 in x/emissions/module/rewards/scores_test.go

View workflow job for this annotation

GitHub Actions / lint

types.Score is missing fields TopicId, BlockHeight, Address (exhaustruct)
{Score: alloraMath.MustNewDecFromString("0.1")},

Check failure on line 1813 in x/emissions/module/rewards/scores_test.go

View workflow job for this annotation

GitHub Actions / lint

types.Score is missing fields TopicId, BlockHeight, Address (exhaustruct)
{Score: alloraMath.MustNewDecFromString("0.4")},

Check failure on line 1814 in x/emissions/module/rewards/scores_test.go

View workflow job for this annotation

GitHub Actions / lint

types.Score is missing fields TopicId, BlockHeight, Address (exhaustruct)
{Score: alloraMath.MustNewDecFromString("0.2")},

Check failure on line 1815 in x/emissions/module/rewards/scores_test.go

View workflow job for this annotation

GitHub Actions / lint

types.Score is missing fields TopicId, BlockHeight, Address (exhaustruct)
}

// Calculate initial EMA score
initialScore, err := rewards.CalculateTopicInitialEmaScore(s.ctx, s.emissionsKeeper, scores)
s.Require().NoError(err)

// Get lambda from params
params, err := s.emissionsKeeper.GetParams(s.ctx)
s.Require().NoError(err)
lambda := params.SortitionLambdaPenalty

// Calculate expected score manually
// Standard deviation ≈ 0.1581139
stdDev := alloraMath.MustNewDecFromString("0.1581139")
lambdaStdDev, err := lambda.Mul(stdDev)
s.Require().NoError(err)

// Lowest score is 0.1
lowestScore := alloraMath.MustNewDecFromString("0.1")
expectedScore, err := lowestScore.Sub(lambdaStdDev)
s.Require().NoError(err)

// Verify result matches expected
diff, err := initialScore.Sub(expectedScore)
s.Require().NoError(err)
absDiff, err := diff.Abs()
s.Require().NoError(err)
s.Require().True(absDiff.Lt(alloraMath.MustNewDecFromString("0.000001")))
}

0 comments on commit db18762

Please sign in to comment.