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

System tests for KEEP<>T staking contracts interactions #33

Merged
merged 7 commits into from
Dec 20, 2021
Merged

Conversation

pdyraga
Copy link
Member

@pdyraga pdyraga commented Nov 19, 2021

System tests are performed on mainnet block 13619810 fork chain using three real stakers from KEEP network: liquid token staker, managed grant staker, and non-managed grant staker.

Stake delegation

  • Given I am KEEP network liquid token staker, when I have authorized T staking contract, when I have not undelegated my legacy stake, stakeKeep should copy my stake to T staking contract.
  • Given I am KEEP network liquid token staker, when I have authorized T staking contract, when I have undelegated my legacy stake, stakeKeep should revert.

Top-ups

  • Given I am KEEP network liquid token staker, when I copied my stake to T staking contract, when I executed top-up of my legacy stake, topUpKeep should top-up my stake in T staking contract.

Stake undelegation

  • Given I am KEEP network liquid token staker, when I copied my stake to T staking contract, when I authorized and deauthorized application, unstakeKeep should release my KEEP stake.
  • Given I am KEEP network liquid token staker, when I copied my stake to T staking contract, when I authorized and deauthorized application, unstakeKeep should let me undelegate my KEEP stake.

Slashing

  • Given I am KEEP network liquid token staker, when I copied my stake to T staking contract, when I authorized application, when I got slashed by the application, processSlashing should slash my KEEP stake.
  • Given I am KEEP network liquid token staker, when I copied my stake to T staking contract, when I authorized application, when I got slashed by the application, notifyKeepStakeDiscrepancy should revert.
  • Given I am KEEP network liquid token staker, when I copied my stake to T staking contract, when I authorized application, when the application seized my stake, processSlashing should seize my KEEP stake.
  • Given I am KEEP network liquid token staker, when I copied my stake to T staking contract, when I authorized application, when the application seized my stake, notifyKeepStakeDiscrepancy should revert.

Exactly the same tests are repeated for two other types of actors:

  • Given I am KEEP network managed grant staker...
  • Given I am KEEP network non-managed grant staker...

The following scenarios are tested:

1. Given I am KEEP network managed grant staker and I have not
undelegated my stake, when I authorize T staking contract,
I can copy my delegation to T staking contract.

2. Given I am KEEP network managed grant staker and I have
undelegated my stake, when I authorize T staking contract,
I can not copy my delegation to T staking contract.

3. Given I am KEEP network non-managed grant staker and
I have not undelegated my stake, when I authorize T staking
contract, I can copy my delegation to T staking contract.

4. Given I am KEEP network non-managed grant staker and
I have undelegated my stake, when I authorize T staking
contract, I can not copy my delegation to T staking contract.

5. Given I am KEEP network liquid token staker and I have not
undelegated my stake, when I authorize T staking contract,
I can copy my delegation to T staking contract.

6. Given I am KEEP network liquid token staker and I have
undelegated my stake, when I authorize T staking contract,
I can not copy my delegation to T staking contract.
The following scenarios are tested:

1. Given I am KEEP network liquid token staker and I copied my stake to T
staking contract, when I executed top-up of my legacy stake,
`topUpKeep` should top-up my stake in T staking contract.

2. Given I am KEEP network non-managed grant staker and I copied my stake to T
staking contract, when I executed top-up of my legacy stake,
`topUpKeep` should top-up my stake in T staking contract.

3. Given I am KEEP network managed grant staker and I copied my stake to T
staking contract, when I executed top-up of my legacy stake,
`topUpKeep` should top-up my stake in T staking contract.
The following scenarios are tested:

1. Given I am KEEP network liquid token staker, when I copied my stake to
T staking contract, when I authorized and deauthorized application,
`unstakeKeep` should release and let me undelegate my KEEP stake.

2. Given I am KEEP network managed grant staker, when I copied my stake to
T staking contract, when I authorized and deauthorized application,
`unstakeKeep` should release and let me undelegate my KEEP stake.

3. Given I am KEEP network non-managed grant staker, when I copied my stake to
T staking contract, when I authorized and deauthorized application,
`unstakeKeep` should release and let me undelegate my KEEP stake.
The following scenarios are tested:

1. Given I am KEEP network liquid token staker, when I copied my stake to
T staking contract, when I authorized application, when I got slashed by
the application, `processSlashing` should slash my KEEP stake.

2. Given I am KEEP network liquid token staker, when I copied my stake to
T staking contract, when I authorized application, when I got slashed by
the application, `notifyKeepStakeDiscrepancy` should revert.

3. Given I am KEEP network liquid token staker, when I copied my stake to
T staking contract, when I authorized application, when the application
seized my stake, `processSlashing` should seize my KEEP stake.

4. Given I am KEEP network liquid token staker, when I copied my stake to
T staking contract, when I authorized application, when the application
seized my stake, `notifyKeepStakeDiscrepancy` should revert.

5. Given I am KEEP network managed grant staker, when I copied my stake to
T staking contract, when I authorized application, when I got slashed by
the application, `processSlashing` should slash my KEEP stake.

6. Given I am KEEP network managed grant staker, when I copied my stake to
T staking contract, when I authorized application, when I got slashed by
the application, `notifyKeepStakeDiscrepancy` should revert.

7. Given I am KEEP network managed grant staker, when I copied my stake to
T staking contract, when I authorized application, when the application
seized my stake, `processSlashing` should seize my KEEP stake.

8. Given I am KEEP network managed grant staker, when I copied my stake to
T staking contract, when I authorized application, when the application
seized my stake, `notifyKeepStakeDiscrepancy` should revert.

9. Given I am KEEP network non-managed grant staker, when I copied my stake to
T staking contract, when I authorized application, when I got slashed by
the application, `processSlashing` should slash my KEEP stake.

10. Given I am KEEP network non-managed grant staker, when I copied my stake to
T staking contract, when I authorized application, when I got slashed by
the application, `notifyKeepStakeDiscrepancy` should revert.

11. Given I am KEEP network non-managed grant staker, when I copied my stake to
T staking contract, when I authorized application, when the application
seized my stake, `processSlashing` should seize my KEEP stake.

12. Given I am KEEP network non-managed grant staker, when I copied my stake to
T staking contract, when I authorized application, when the application
seized my stake, `notifyKeepStakeDiscrepancy` should revert.
@michalinacienciala
Copy link
Contributor

@pdyraga, what do you think about adding a test checking if unstakeKeep gets reverted if the amount of T after the unstake would be lower than the highest application authorization?

"Given I am KEEP network [...], when I copied my stake to T staking contract, when I authorized application, unstakeKeep should revert."

Copy link
Member

@nkuba nkuba left a comment

Choose a reason for hiding this comment

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

Can we migrate system tests to TS?

test/system/init-contracts.js Show resolved Hide resolved
test/system/staking.test.js Show resolved Hide resolved
nkuba
nkuba previously approved these changes Dec 20, 2021
@pdyraga
Copy link
Member Author

pdyraga commented Dec 20, 2021

Can we migrate system tests to TS?

Not a bad idea but I'd do that later for all tests. This is captured in #5.

@pdyraga
Copy link
Member Author

pdyraga commented Dec 20, 2021

@pdyraga, what do you think about adding a test checking if unstakeKeep gets reverted if the amount of T after the unstake would be lower than the highest application authorization?

"Given I am KEEP network [...], when I copied my stake to T staking contract, when I authorized application, unstakeKeep should revert."

This logic in unstakeKeep does not involve interaction with KEEP staking contract and is covered by unit tests. I would prefer to leave this part to unit tests and have system tests covering only these paths where KEEP staking contract is involved. Especially that system tests are really expensive to execute compared with unit tests.

function unstakeKeep(address operator)
external
override
onlyOwnerOrOperator(operator)
{
OperatorInfo storage operatorStruct = operators[operator];
uint96 keepInTStake = operatorStruct.keepInTStake;
require(keepInTStake != 0, "Nothing to unstake");
require(
getMinStaked(operator, StakeType.KEEP) == 0,
"Keep stake still authorized"
);
emit Unstaked(operator, keepInTStake);
operatorStruct.keepInTStake = 0;
decreaseStakeCheckpoint(operator, keepInTStake);

@nkuba
Copy link
Member

nkuba commented Dec 20, 2021

LGTM!

@nkuba nkuba merged commit 15fdfd7 into main Dec 20, 2021
@nkuba nkuba deleted the system-tests branch December 20, 2021 10:26
@pdyraga pdyraga added this to the solidity/v1.1.0 milestone Dec 31, 2021
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.

3 participants