Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing path predicates and rewards #292

Merged
merged 16 commits into from
Aug 8, 2023
Merged

Implementing path predicates and rewards #292

merged 16 commits into from
Aug 8, 2023

Conversation

kellan-simiotics
Copy link
Contributor

Changes

How to test these changes?

Related issues

@kellan-simiotics kellan-simiotics marked this pull request as draft April 21, 2023 16:24
@kellan-simiotics kellan-simiotics changed the title Setting path rewards for one stage. Getting/setting path rewards Apr 24, 2023
@kellan-simiotics kellan-simiotics changed the title Getting/setting path rewards getting/setting path rewards Apr 24, 2023
@kellan-simiotics kellan-simiotics changed the title getting/setting path rewards Implementing path rewards Apr 24, 2023
@kellan-simiotics kellan-simiotics marked this pull request as ready for review April 25, 2023 14:32
Kellan Wampler and others added 9 commits April 26, 2023 01:02
…g that several different pool ids can be received as rewards for different stages/paths in the same session.

.
And hooked it up to Python CLI and tests.
Hooked it up to `stakeTokensIntoSession`.
…dle both staking predicates and path choice predicates. Tested get/set for path choice predicates. Still need to implment and test the predicate check on path choice.
Copy link
Collaborator

@zomglings zomglings left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments and questions. I need to look more closely at the new tests and review the Solidity changes with more care, too.

I plan to do so a little later today @kellan-simiotics . In the mean time can you please address my current comments?

@@ -63,7 +76,7 @@ library LibGOFP {
uint256 numSessions;
mapping(uint256 => Session) sessionById;
// session => stage => stageReward
mapping(uint256 => mapping(uint256 => StageReward)) sessionStageReward;
mapping(uint256 => mapping(uint256 => Reward)) sessionStageReward;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will be a problem, but we need to check if this change will corrupt data when we upgrade existing contracts.

The reason I think it won't is because of how struct storage positions are calculated: https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html

uint256 maxStakable,
address gofpAddress,
uint256 sessionId,
address player,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kellan-simiotics : Can you create a .md file in this PR which discusses predicates, and explains our reasoning behind the signatures? We can pull content from our slack conversation about it.

@@ -1,10 +1,13 @@
import unittest
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

locust changes in this file:

Generated (from repo root) with:

locust -r . main HEAD -f json -o diffs.json

Top-level objects with changes in test_gofp.py:

jq '.locust[] | select(.file == "cli/enginecli/test_gofp.py") | .changes[].name' diffs.json

Returns:

"TestPlayerFlow"
"TestAdminFlow"
"TestCallbacks"
"GOFPTestCase"
"TestFullGames"
"math"
"web3"
".None.GOFPFacet"
".None.MockTerminus"
".None.MockErc20"
".None.MockERC721"
".None.GOFPPredicates"

(The .None. looks like a small bug in locust)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GOFPTestCase:

$ jq '.locust[] | select(.file == "cli/enginecli/test_gofp.py") | .changes[] | select(.name == "GOFPTestCase")' diffs.json
{
  "name": "GOFPTestCase",
  "type": "class",
  "line": 284,
  "changed_lines": 21,
  "total_lines": 85,
  "children": [
    {
      "name": "GOFPTestCase.setUpClass",
      "type": "function",
      "line": 286,
      "changed_lines": 21,
      "total_lines": 78,
      "children": []
    },
    {
      "name": ".None.GOFPPredicates",
      "type": "usage",
      "line": 302,
      "changed_lines": 1,
      "total_lines": 1,
      "children": []
    },
    {
      "name": ".None.GOFPPredicates.GOFPPredicates",
      "type": "usage",
      "line": 302,
      "changed_lines": 1,
      "total_lines": 1,
      "children": []
    }
  ]
}

It's just the deployment of predicates.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestCallbacks:

$ jq '.locust[] | select(.file == "cli/enginecli/test_gofp.py") | .changes[] | select(.name == "TestCallbacks") | .children[] | select(.type == "function") | .name' diffs.json
"TestCallbacks.test_session_staking_predicate"
"TestCallbacks.test_path_choice_predicate"

These tests check that admins can set predicates, and that the predicate callbacks function as expected.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestPlayerFlow:

$ jq '.locust[] | select(.file == "cli/enginecli/test_gofp.py") | .changes[] | select(.name == "TestPlayerFlow") | .children[] | select(.type == "function")' diffs.json
{
  "name": "TestPlayerFlow.test_player_can_stake_and_unstake_nfts",
  "type": "function",
  "line": 1701,
  "changed_lines": 148,
  "total_lines": 148,
  "children": []
}
{
  "name": "TestPlayerFlow.test_player_can_stake_into_free_session",
  "type": "function",
  "line": 1850,
  "changed_lines": 39,
  "total_lines": 79,
  "children": []
}
{
  "name": "TestPlayerFlow.test_player_is_rewarded_for_making_a_choice_in_stages_that_have_rewards",
  "type": "function",
  "line": 2959,
  "changed_lines": 120,
  "total_lines": 140,
  "children": []
}
{
  "name": "TestPlayerFlow.test_player_is_rewarded_for_choosing_path_that_has_reward",
  "type": "function",
  "line": 3100,
  "changed_lines": 187,
  "total_lines": 187,
  "children": []
}
{
  "name": "TestPlayerFlow.test_player_can_receive_different_pool_ids_in_stage_and_path_rewards",
  "type": "function",
  "line": 3288,
  "changed_lines": 77,
  "total_lines": 148,
  "children": []
}

These method test path reward functionality, but not predicates.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestAdminFlow:

$ jq '.locust[] | select(.file == "cli/enginecli/test_gofp.py") | .changes[] | select(.name == "TestAdminFlow") | .children[] | select(.type == "function")' diffs.json
{
  "name": "TestAdminFlow.test_create_forgiving_session_then_get_session_active",
  "type": "function",
  "line": 468,
  "changed_lines": 1,
  "total_lines": 46,
  "children": []
}
{
  "name": "TestAdminFlow.test_setting_same_stage_reward_twice_overwrites_first_value",
  "type": "function",
  "line": 1393,
  "changed_lines": 35,
  "total_lines": 58,
  "children": []
}
{
  "name": "TestAdminFlow.test_set_and_get_path_rewards",
  "type": "function",
  "line": 1452,
  "changed_lines": 101,
  "total_lines": 121,
  "children": []
}
{
  "name": "TestAdminFlow.test_non_game_master_cannot_set_path_rewards",
  "type": "function",
  "line": 1574,
  "changed_lines": 52,
  "total_lines": 52,
  "children": []
}
{
  "name": "TestAdminFlow.test_setting_same_path_reward_twice_overwrites_first_value",
  "type": "function",
  "line": 1627,
  "changed_lines": 71,
  "total_lines": 71,
  "children": []
}

Nothing related to predicates (that stuff is in TestCallbacks). Tests reward flows for admins - pertinent to new path rewards.

@@ -178,6 +181,50 @@
"type": "event",
}

PATH_REWARD_CHANGED_ABI = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we testing that an appropriate event gets fired when we set up a predicate?



class TestPlayerFlow(GOFPTestCase):
def test_player_can_stake_and_unstake_nfts(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a new test introduced in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think it's an error with the diff editor.

for token_id in unstaked_token_ids:
self.assertEqual(self.nft.owner_of(token_id), self.player.address)

def test_player_can_stake_into_free_session(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, is this a new test introduced in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, same as above.

self.assertEqual(erc1155_transfer_event["args"]["id"], self.reward_pool_id)
self.assertEqual(
erc1155_transfer_event["args"]["value"],
(2**1) * (3**2),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we write this together?

It is clever, but it makes it hard to understand what's happening in the test. What do you think @kellan-simiotics ? Should we do it in a more dull but readable way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment.

@zomglings zomglings changed the title Implementing path rewards Implementing path predicates and rewards Jun 23, 2023
Copy link
Collaborator

@zomglings zomglings left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Collaborator

@zomglings zomglings left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@zomglings zomglings merged commit 643f269 into main Aug 8, 2023
1 check passed
@zomglings zomglings deleted the garden-v2 branch August 8, 2023 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants