From 08377cf773bdd2f4eeee3418fba7ffe8078f8825 Mon Sep 17 00:00:00 2001 From: Lucian Hymer Date: Mon, 15 Apr 2024 15:08:43 -0600 Subject: [PATCH] feat(api): fix tests, only continue indexer query on success --- ...st_cmd_scorer_dump_data_eth_model_score.py | 2 +- api/scorer/test/test_choose_binary_scorer.py | 38 ++++++++----------- api/scorer/test/test_create_community_id.py | 2 +- indexer/src/staking_indexer.rs | 2 +- 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/api/data_model/test/test_cmd_scorer_dump_data_eth_model_score.py b/api/data_model/test/test_cmd_scorer_dump_data_eth_model_score.py index 65135cb0b..8724af7df 100644 --- a/api/data_model/test/test_cmd_scorer_dump_data_eth_model_score.py +++ b/api/data_model/test/test_cmd_scorer_dump_data_eth_model_score.py @@ -19,7 +19,7 @@ def create_cache_table(): # This test is expected to only fork on postgres because on SQLite the unmanaged model cannot be created successfully assert ( db_engine == "django.db.backends.postgresql" - ), "This test is currently only supposed to work on postgres. Models cannot be created on SQLite atm." + ), f"This test is currently only supposed to work on postgres. Models cannot be created on SQLite atm. Current engine: {db_engine}" # Disable foreign key constraint checks # TODO: this is unfortunatly not work for SQLite, it does not have the desired effect ... diff --git a/api/scorer/test/test_choose_binary_scorer.py b/api/scorer/test/test_choose_binary_scorer.py index 7d645985f..d5e794731 100644 --- a/api/scorer/test/test_choose_binary_scorer.py +++ b/api/scorer/test/test_choose_binary_scorer.py @@ -29,11 +29,11 @@ def test_as_a_developer_i_want_to_choose_the_gitcoin_binary_community_score(): "that I select the Gitcoin Binary Community Score as an option", target_fixture="scorersPutResponse", ) -def scorers_put_response(access_token, scorer_community): - scorer = scorer_community.scorer +def scorers_put_response(access_token, scorer_community_with_binary_scorer): + scorer = scorer_community_with_binary_scorer.scorer client = Client() return client.put( - f"/account/communities/{scorer_community.id}/scorers", + f"/account/communities/{scorer_community_with_binary_scorer.id}/scorers", json.dumps({"scorer_type": scorer.Type.WEIGHTED_BINARY}), HTTP_AUTHORIZATION=f"Bearer {access_token}", ) @@ -48,8 +48,8 @@ def _(scorersPutResponse): @then("it automatically becomes the new rule in the respective community") -def _(scorer_community): - scorer = Community.objects.get(id=scorer_community.id).scorer +def _(scorer_community_with_binary_scorer): + scorer = Community.objects.get(id=scorer_community_with_binary_scorer.id).scorer scorer.binaryweightedscorer.threshold = 1 scorer.binaryweightedscorer.save() assert scorer.type == "WEIGHTED_BINARY" @@ -58,23 +58,17 @@ def _(scorer_community): @when("I choose to score a passport", target_fixture="scoreResponse") -def score_response(scorer_community, scorer_api_key): +def score_response(scorer_community_with_binary_scorer, scorer_api_key): """I choose to score a passport.""" - with patch( - "registry.tasks.score_passport_passport.delay" - ) as mock_score_passport_task: - with patch( - "registry.atasks.aget_passport", return_value=mock_passport - ) as get_passport: - with patch( - "registry.atasks.validate_credential", side_effect=[[], []] - ) as validate_credential: + with patch("registry.tasks.score_passport_passport.delay"): + with patch("registry.atasks.aget_passport", return_value=mock_passport): + with patch("registry.atasks.validate_credential", side_effect=[[], []]): client = Client() submitResponse = client.post( "/registry/submit-passport", json.dumps( { - "community": scorer_community.id, + "community": scorer_community_with_binary_scorer.id, "address": "0x71Ad3e3057Ca74967239C66ca6D3A9C2A43a58fC", } ), @@ -90,7 +84,7 @@ def score_response(scorer_community, scorer_api_key): ) assert Decimal(response["score"]) == Decimal("1.000000000") return client.get( - f"/registry/score/{scorer_community.id}/0x71ad3e3057ca74967239c66ca6d3a9c2a43a58fc", + f"/registry/score/{scorer_community_with_binary_scorer.id}/0x71ad3e3057ca74967239c66ca6d3a9c2a43a58fc", content_type="application/json", HTTP_AUTHORIZATION=f"Bearer {scorer_api_key}", ) @@ -147,9 +141,7 @@ def _(scorer_community_with_binary_scorer, scorer_api_key): "scorer_weighted.computation.acalculate_weighted_score", return_value=[{"sum_of_weights": Decimal("70"), "earned_points": {}}], ): - with patch( - "registry.atasks.aget_passport", return_value=mock_passport - ) as aget_passport: + with patch("registry.atasks.aget_passport", return_value=mock_passport): with patch("registry.atasks.validate_credential", side_effect=[[], []]): client = Client() submitResponse = client.post( @@ -208,7 +200,7 @@ def _(scorer_community_with_binary_scorer, scorer_api_key): with patch( "scorer_weighted.computation.acalculate_weighted_score", return_value=[{"sum_of_weights": Decimal("90"), "earned_points": {}}], - ) as calculate_weighted_score: + ): with patch("registry.atasks.aget_passport", return_value=mock_passport): with patch("registry.atasks.validate_credential", side_effect=[[], []]): client = Client() @@ -243,7 +235,7 @@ def _(scorer_community_with_binary_scorer, scorer_api_key): "threshold": "75.00000", "type": "ThresholdScoreCheck", } - assert submit_response_data["error"] == None + assert submit_response_data["error"] is None return client.get( f"/registry/score/{scorer_community_with_binary_scorer.id}/0x71Ad3e3057Ca74967239C66ca6D3A9C2A43a58fC", @@ -268,4 +260,4 @@ def _(scoreResponseFor1): "threshold": "75.00000", "type": "ThresholdScoreCheck", } - assert score_response_data["error"] == None + assert score_response_data["error"] is None diff --git a/api/scorer/test/test_create_community_id.py b/api/scorer/test/test_create_community_id.py index 5a7923973..07dbc22e7 100644 --- a/api/scorer/test/test_create_community_id.py +++ b/api/scorer/test/test_create_community_id.py @@ -72,4 +72,4 @@ def _(): community = Community.objects.all()[0] scorer = community.scorer.binaryweightedscorer assert scorer.threshold == Decimal("20.00") - assert scorer.weights["Discord"] == "0.709878" + assert scorer.weights["Discord"] == "0.516" diff --git a/indexer/src/staking_indexer.rs b/indexer/src/staking_indexer.rs index 026761a92..c92df2d56 100644 --- a/indexer/src/staking_indexer.rs +++ b/indexer/src/staking_indexer.rs @@ -141,6 +141,7 @@ impl<'a> StakingIndexer<'a> { for (event, meta) in previous_events.iter() { self.process_staking_event(&event, &meta, &client).await?; } + last_queried_block = query_end_block; } Err(err) => { eprintln!( @@ -149,7 +150,6 @@ impl<'a> StakingIndexer<'a> { ); } } - last_queried_block = query_end_block; } eprintln!(