-
Notifications
You must be signed in to change notification settings - Fork 10
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
Conversation
…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.
There was a problem hiding this 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; |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
cli/enginecli/test_gofp.py
Outdated
@@ -1,10 +1,13 @@ | |||
import unittest |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
cli/enginecli/test_gofp.py
Outdated
@@ -178,6 +181,50 @@ | |||
"type": "event", | |||
} | |||
|
|||
PATH_REWARD_CHANGED_ABI = { |
There was a problem hiding this comment.
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?
cli/enginecli/test_gofp.py
Outdated
|
||
|
||
class TestPlayerFlow(GOFPTestCase): | ||
def test_player_can_stake_and_unstake_nfts(self): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
cli/enginecli/test_gofp.py
Outdated
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): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, same as above.
cli/enginecli/test_gofp.py
Outdated
self.assertEqual(erc1155_transfer_event["args"]["id"], self.reward_pool_id) | ||
self.assertEqual( | ||
erc1155_transfer_event["args"]["value"], | ||
(2**1) * (3**2), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Changes
How to test these changes?
Related issues