code.vegaprotocol.io/vega@v0.79.0/core/integration/features/verified/0059-STKG-delegation.feature (about)

     1  Feature: Staking & Delegation 
     2  
     3    Background:
     4      Given the following network parameters are set:
     5        | name                                              | value  |
     6        | reward.asset                                      | VEGA   |
     7        | validators.epoch.length                           | 10s    |
     8        | validators.delegation.minAmount                   | 10     |
     9        | reward.staking.delegation.delegatorShare          |  0.883 |
    10        | reward.staking.delegation.minimumValidatorStake   |  100   |
    11        | reward.staking.delegation.maxPayoutPerParticipant | 100000 |
    12        | reward.staking.delegation.competitionLevel        |  1.1   |
    13        | reward.staking.delegation.minValidators           |  5     |
    14        | reward.staking.delegation.optimalStakeMultiplier  |  5.0   |
    15  
    16  
    17      Given time is updated to "2021-08-26T00:00:00Z"
    18      Given the average block duration is "2"
    19  
    20      And the validators:
    21        | id     | staking account balance |
    22        | node1  |         1000000         |
    23        | node2  |         1000000         |
    24        | node3  |         1000000         |
    25        | node4  |         1000000         |
    26        | node5  |         1000000         |
    27        | node6  |         1000000         |
    28        | node7  |         1000000         |
    29        | node8  |         1000000         |
    30        | node9  |         1000000         |
    31        | node10 |         1000000         |
    32        | node11 |         1000000         |
    33        | node12 |         1000000         |
    34        | node13 |         1000000         |
    35  
    36      #set up the self delegation of the validators
    37      Then the parties submit the following delegations:
    38        | party  | node id  | amount |
    39        | node1  |  node1   | 10000  | 
    40        | node2  |  node2   | 10000  |       
    41        | node3  |  node3   | 10000  | 
    42        | node4  |  node4   | 10000  | 
    43        | node5  |  node5   | 10000  | 
    44        | node6  |  node6   | 10000  | 
    45        | node7  |  node7   | 10000  | 
    46        | node8  |  node8   | 10000  | 
    47        | node9  |  node9   | 10000  | 
    48        | node10 |  node10  | 10000  | 
    49        | node11 |  node11  | 10000  | 
    50        | node12 |  node12  | 10000  | 
    51        | node13 |  node13  | 10000  | 
    52  
    53      And the parties deposit on staking account the following amount:  
    54        | party  | asset  | amount |
    55        | party1 | VEGA   | 10000  |
    56  
    57      #complete the first epoch for the self delegation to take effect
    58      Then the network moves ahead "7" blocks
    59  
    60    Scenario: A party can delegate to a validator and undelegate at the end of an epoch (0059-STKG-002, 0059-STKG-013, 0059-STKG-014)
    61      Description: A party with a balance in the staking account can delegate to a validator
    62  
    63      When the parties submit the following delegations:
    64      | party  | node id  | amount |
    65      | party1 |  node1   |  100   | 
    66      | party1 |  node2   |  200   |       
    67      | party1 |  node3   |  300   |   
    68      
    69      #we are now in epoch 1 so the delegation balance for epoch 1 should not include the delegation but the hypothetical balance for epoch 2 should 
    70      Then the parties should have the following delegation balances for epoch 1:
    71      | party  | node id  | amount |
    72      | party1 |  node1   |   0    | 
    73      | party1 |  node2   |   0    |       
    74      | party1 |  node3   |   0    |        
    75  
    76      And the parties should have the following delegation balances for epoch 2:
    77      | party  | node id  | amount |
    78      | party1 |  node1   | 100   | 
    79      | party1 |  node2   | 200   |       
    80      | party1 |  node3   | 300   |        
    81  
    82      When the network moves ahead "7" blocks
    83      Then the parties should have the following delegation balances for epoch 2:
    84      | party  | node id  | amount |
    85      | party1 |  node1   | 100    | 
    86      | party1 |  node2   | 200    |       
    87      | party1 |  node3   | 300    |   
    88  
    89      Then the parties submit the following undelegations:
    90      | party  | node id  | amount |      when     |
    91      | party1 |  node1   |  100   |  end of epoch |
    92      | party1 |  node2   |  200   |  end of epoch |              
    93      | party1 |  node3   |  300   |  end of epoch |           
    94  
    95      Then the parties should have the following delegation balances for epoch 2:
    96      | party  | node id  | amount |
    97      | party1 |  node1   | 100    | 
    98      | party1 |  node2   | 200    |       
    99      | party1 |  node3   | 300    |   
   100  
   101      And the parties should have the following delegation balances for epoch 3:
   102      | party  | node id  | amount |
   103      | party1 |  node1   |   0    | 
   104      | party1 |  node2   |   0    |       
   105      | party1 |  node3   |   0    |   
   106  
   107      #advance to the end of epoch for the undelegation to take place 
   108      When the network moves ahead "7" blocks
   109      Then the parties should have the following delegation balances for epoch 3:
   110      | party  | node id  | amount |
   111      | party1 |  node1   |   0    | 
   112      | party1 |  node2   |   0    |       
   113      | party1 |  node3   |   0    |   
   114  
   115    Scenario: A party cannot delegate less than minimum delegateable stake (0059-STKG-001)
   116      Description: A party attempts to delegate less than minimum delegateable stake from its staking account to a validator minimum delegateable stake
   117  
   118      When the parties submit the following delegations:
   119      | party  | node id  | amount | reference | error                                                                             |
   120      | party1 |  node1   |    1   |      a    | delegation amount is lower than the minimum amount for delegation for a validator |
   121      | party1 |  node2   |    2   |      b    | delegation amount is lower than the minimum amount for delegation for a validator |    
   122      | party1 |  node3   |    3   |      c    | delegation amount is lower than the minimum amount for delegation for a validator |
   123  
   124      #we are now in epoch 1 so the delegation balance for epoch 1 should not include the delegation but the hypothetical balance for epoch 2 should 
   125      Then the parties should have the following delegation balances for epoch 1:
   126      | party  | node id  | amount |
   127      | party1 |  node1   |   0    | 
   128      | party1 |  node2   |   0    |       
   129      | party1 |  node3   |   0    |        
   130  
   131      And the parties should have the following delegation balances for epoch 2:
   132      | party  | node id  | amount |
   133      | party1 |  node1   |    0   | 
   134      | party1 |  node2   |    0   |       
   135      | party1 |  node3   |    0   |        
   136  
   137    Scenario: A party cannot delegate more than it has in staking account (0059-STKG-additional-tests)
   138      Description: A party attempts to delegate more than it has in its staking account to a validator
   139  
   140      When the parties submit the following delegations:
   141      | party  | node id  |   amount   | reference | error                               |
   142      | party1 |  node1   |    10001   |      a    | insufficient balance for delegation |
   143      | party1 |  node2   |    10002   |      b    | insufficient balance for delegation |    
   144      | party1 |  node3   |    10003   |      c    | insufficient balance for delegation |
   145  
   146      #we are now in epoch 1 so the delegation balance for epoch 1 should not include the delegation but the hypothetical balance for epoch 2 should 
   147      Then the parties should have the following delegation balances for epoch 1:
   148      | party  | node id  | amount |
   149      | party1 |  node1   |   0    | 
   150      | party1 |  node2   |   0    |       
   151      | party1 |  node3   |   0    |        
   152  
   153      And the parties should have the following delegation balances for epoch 2:
   154      | party  | node id  | amount |
   155      | party1 |  node1   |    0   | 
   156      | party1 |  node2   |    0   |       
   157      | party1 |  node3   |    0   |        
   158  
   159    Scenario: A party cannot cumulatively delegate more than it has in staking account (0059-STKG-additional-tests)
   160      
   161      When the parties submit the following delegations:
   162      | party  | node id  |   amount   | reference | error                               |
   163      | party1 |  node1   |     5000   |           |                                     |
   164      | party1 |  node2   |     5001   |      a    | insufficient balance for delegation |
   165  
   166      Then the parties should have the following delegation balances for epoch 1:
   167      | party  | node id  | amount |
   168      | party1 |  node1   |   0    | 
   169      | party1 |  node2   |   0    |       
   170      | party1 |  node3   |   0    |        
   171  
   172      And the parties should have the following delegation balances for epoch 2:
   173      | party  | node id  | amount |
   174      | party1 |  node1   |   5000 | 
   175      | party1 |  node2   |    0   |       
   176      | party1 |  node3   |    0   |        
   177    
   178    Scenario: A party changes delegation from one validator to another in the same epoch (0059-STKG-014)
   179      Description: A party can change delegatation from one Validator to another
   180  
   181      When the parties submit the following delegations:
   182      | party  | node id  |   amount  | 
   183      | party1 |  node1   |    100   | 
   184      | party1 |  node2   |    100   | 
   185      | party1 |  node3   |    100   | 
   186  
   187      Then the parties should have the following delegation balances for epoch 2:
   188      | party  | node id  | amount |
   189      | party1 |  node1   | 100   | 
   190      | party1 |  node2   | 100   |       
   191      | party1 |  node3   | 100   |        
   192  
   193      #advance to the end of the epoch for the delegation to become effective
   194      When the network moves ahead "7" blocks    
   195      Then the parties should have the following delegation balances for epoch 2:
   196      | party  | node id  | amount |
   197      | party1 |  node1   | 100    | 
   198      | party1 |  node2   | 100    |       
   199      | party1 |  node3   | 100    |   
   200  
   201      #start epoch 2
   202      #now request to undelegate from node2 and node3 
   203      And the parties submit the following undelegations:
   204      | party  | node id  | amount |      when     |
   205      | party1 |  node2   |  80    |  end of epoch |     
   206      | party1 |  node3   |  90    |  end of epoch | 
   207  
   208      Then the parties submit the following delegations:
   209      | party  | node id  |  amount | 
   210      | party1 |  node1   |    80   | 
   211      | party1 |  node1   |    90   | 
   212  
   213      And the parties should have the following delegation balances for epoch 3:
   214      | party  | node id  | amount |
   215      | party1 |  node1   | 270    | 
   216      | party1 |  node2   | 20     |       
   217      | party1 |  node3   | 10     |   
   218  
   219      #advance to the end of the epoch for the delegation to become effective
   220      When the network moves ahead "7" blocks 
   221      Then the parties should have the following delegation balances for epoch 3:
   222      | party  | node id  | amount |
   223      | party1 |  node1   | 270    | 
   224      | party1 |  node2   | 20     |       
   225      | party1 |  node3   | 10     | 
   226  
   227    Scenario: A party cannot delegate to an unknown node (0059-STKG-additional-tests)
   228      Description: A party should fail in trying to delegate to a non existing node
   229  
   230      When the parties submit the following delegations:
   231      | party  | node id   |   amount | reference | error           |
   232      | party1 |  unknown1 |    100   |      a    | invalid node ID |
   233      | party1 |  unknonw2 |    200   |      b    | invalid node ID |    
   234  
   235    Scenario: A party cannot undelegate from an unknown node (0059-STKG-additional-tests)
   236      Description: A party should fail in trying to undelegate from a non existing node
   237  
   238      When the parties submit the following undelegations:
   239      | party  | node id   |   amount |     when     | reference | error           |
   240      | party1 |  unknown1 |    100   | end of epoch |      a    | invalid node ID |
   241      | party1 |  unknonw2 |    200   | end of epoch |      b    | invalid node ID |     
   242  
   243      Scenario: A party cannot delegate more than their staking account balance considering all active and pending delegation 
   244      Description: A party has pending delegations and is trying to exceed their stake account balance delegation, 
   245      i.e. the balance of their pending delegation + requested delegation exceeds stake account balance
   246    
   247      When the parties submit the following delegations:
   248      | party  | node id  |  amount | reference | error                               |
   249      | party1 |  node1   |   5000  |           |                                     |
   250      | party1 |  node2   |   6000  |     a     | insufficient balance for delegation |    
   251  
   252      #advance to the end of the epoch
   253      When the network moves ahead "7" blocks    
   254      Then the parties should have the following delegation balances for epoch 2:
   255      | party  | node id  | amount |
   256      | party1 |  node1   | 5000   | 
   257  
   258      Then the parties submit the following delegations:
   259      | party  | node id  |  amount | reference | error                               |
   260      | party1 |  node2   |   1000  |           |                                     |    
   261      | party1 |  node2   |   7578  |     a     | insufficient balance for delegation |     
   262  
   263    Scenario: A party cannot delegate more than their staking account balance considering all active and pending undelegation (0059-STKG-007)
   264      Description: A party has pending delegations and undelegations and is trying to exceed their stake account balance delegation, 
   265      i.e. the balance of their pending delegation + requested delegation exceeds stake account balance
   266      
   267      When the parties submit the following delegations:
   268      | party  | node id  |  amount | reference | error                               |
   269      | party1 |  node1   |   5000  |           |                                     |
   270  
   271      #advance to the end of the epoch
   272      When the network moves ahead "7" blocks
   273      Then the parties should have the following delegation balances for epoch 2:
   274      | party  | node id  | amount |
   275      | party1 |  node1   | 5000   | 
   276  
   277      Then the parties submit the following undelegations:
   278      | party  | node id  | amount |    when      |
   279      | party1 |  node1   |  1000  | end of epoch |
   280  
   281      #party1 already have 423 delegated so they can only theoretically delegate 10000-423 = 9577
   282      Then the parties submit the following delegations:
   283      | party  | node id  |  amount | reference | error                               |
   284      | party1 |  node2   |   1000  |           |                                     |    
   285      | party1 |  node2   |   8578  |     a     | insufficient balance for delegation |    
   286  
   287    Scenario: A party can request delegate and undelegate from the same node at the same epoch such that the request can balance each other without affecting the actual delegate balance (0059-STKG-0013)
   288      Description: party requests to delegate to node1 at the end of the epoch and regrets it and undelegate the whole amount to delegate it to node2
   289    
   290      When the parties submit the following delegations:
   291      | party  | node id  |  amount | 
   292      | party1 |  node1   |   1000  | 
   293  
   294      And the parties submit the following undelegations:
   295      | party  | node id  | amount |    when      |
   296      | party1 |  node1   |  1000  | end of epoch |
   297  
   298      And the parties submit the following delegations:
   299      | party  | node id  |  amount | 
   300      | party1 |  node2   |   1000  | 
   301  
   302      Then the parties should have the following delegation balances for epoch 2:
   303      | party  | node id  | amount |
   304      | party1 |  node1   | 0      | 
   305      | party1 |  node2   | 1000   | 
   306      
   307    Scenario: A party has active delegations and submits an undelegate request followed by a delegation request that covers only part of the undelegation such that the undelegation still takes place (0059-STKG-013)
   308      Description: A party delegated tokens to node1 at previous epoch such that the delegations is now active and is requesting to undelegate some of the tokens at the end of the current epoch. Then regret some of it and submit a delegation request that undoes some of the undelegation but still some of it remains. 
   309  
   310      When the parties submit the following delegations:
   311      | party  | node id  |  amount | 
   312      | party1 |  node1   |   1000  | 
   313  
   314      When the network moves ahead "7" blocks
   315  
   316      Then the parties submit the following undelegations:
   317      | party  | node id  | amount |    when      |
   318      | party1 |  node1   |  1000  | end of epoch |
   319  
   320      And the parties submit the following delegations:
   321      | party  | node id  |  amount | 
   322      | party1 |  node1   |   100   |
   323  
   324      Then the parties should have the following delegation balances for epoch 3:
   325      | party  | node id  | amount |
   326      | party1 |  node1   | 100    | 
   327  
   328    Scenario: A party cannot undelegate more than the delegated balance (0059-STKG-additional-tests)
   329      Description: A party trying to undeleagte from a node more than the amount that was delegated to it should fail 
   330  
   331      And the parties submit the following delegations:
   332      | party  | node id  | amount |
   333      | party1 |  node1   |  100   | 
   334      | party1 |  node2   |  200   |       
   335      | party1 |  node3   |  300   |   
   336  
   337      #advance to the beginning of the next epoch 
   338      When the network moves ahead "7" blocks
   339  
   340      Then the parties submit the following undelegations:
   341      | party  | node id   |   amount |     when     | reference | error                                    |
   342      | party1 |  node1    |    101   | end of epoch |      a    | incorrect token amount for undelegation  |
   343      | party1 |  node2    |    201   | end of epoch |      b    | incorrect token amount for undelegation  |    
   344      | party1 |  node3    |    301   | end of epoch |      c    | incorrect token amount for undelegation  |    
   345      | party1 |  node1    |    100   | end of epoch |           |                                          |
   346      | party1 |  node2    |    200   | end of epoch |           |                                          |    
   347      | party1 |  node3    |    300   | end of epoch |           |                                          |  
   348  
   349    Scenario: A node can self delegate to itself and undelegate at the end of an epoch (0059-STKG-additional-tests)
   350      Description: A node with a balance in the staking account can delegate to itself
   351  
   352      When the parties submit the following delegations:
   353      | party  | node id  | amount |
   354      | node1   |  node1  |  1000  | 
   355      
   356      #we are now in epoch 1 so the delegation balance for epoch 1 should not include the delegation but the hypothetical balance for epoch 2 should 
   357      Then the parties should have the following delegation balances for epoch 1:
   358      | party  | node id  | amount |
   359      | node1  |  node1   |  10000 | 
   360          
   361      And the parties should have the following delegation balances for epoch 2:
   362      | party  | node id  | amount |
   363      | node1  |  node1   | 11000  | 
   364      
   365      When the network moves ahead "7" blocks   
   366      Then the parties should have the following delegation balances for epoch 2:
   367      | party  | node id  | amount |
   368      | node1 |  node1   | 11000  | 
   369  
   370      Then the parties submit the following undelegations:
   371      | party  | node id  | amount |    when      |
   372      | node1  |  node1   |  5000  | end of epoch |
   373      
   374      Then the parties should have the following delegation balances for epoch 2:
   375      | party  | node id  | amount |
   376      | node1  |  node1   | 11000  | 
   377      
   378      And the parties should have the following delegation balances for epoch 3:
   379      | party  | node id  | amount |
   380      | node1  |  node1   |  6000  | 
   381      
   382      #advance to the end of epoch for the undelegation to take place 
   383      When the network moves ahead "7" blocks
   384      Then the parties should have the following delegation balances for epoch 3:
   385      | party  | node id  | amount |
   386      | node1  |  node1   |  6000  | 
   387        
   388    Scenario: A party can undelegate all of their stake at the end of the epoch (0059-STKG-0014)
   389      Description: A with delegated stake and pending delegation can request to undelegate all. This will be translated to undelegating all the stake they have at the time and will be executed at the end of the epoch
   390  
   391      When the parties submit the following delegations:
   392      | party  | node id  | amount |
   393      | party1 |  node1   |  1000  | 
   394  
   395      #end epoch 1 for the delegation to take effect   
   396      When the network moves ahead "7" blocks    
   397      Then the parties should have the following delegation balances for epoch 2:
   398      | party  | node id  | amount |
   399      | party1 |  node1   |  1000  | 
   400  
   401      Then the parties submit the following delegations:
   402      | party  | node id  | amount |
   403      | party1  |  node1   |  50   | 
   404      | party1  |  node2   |  123  | 
   405      
   406      #we are in the middle of epoch2 and the party1 requests to undelegate all of their stake to party1
   407      Then the parties submit the following undelegations:
   408      | party  | node id  | amount |    when      |
   409      | party1 |  node1   |  0     | end of epoch |
   410  
   411      #therefore we expect their expected balance for epoch 3 for party1 node1 is 0
   412      Then the parties should have the following delegation balances for epoch 3:
   413      | party  | node id  | amount |
   414      | party1 |  node1   |   0    |
   415      | party1 |  node2   |   123  |  
   416      
   417      #advance to the end of epoch2 for the delegations/undelegations to be applied
   418      When the network moves ahead "7" blocks
   419      Then the parties should have the following delegation balances for epoch 3:
   420      | party  | node id  | amount |
   421      | party1 |  node1   |   0    | 
   422      | party1 |  node2   |   123  |    
   423  
   424    Scenario: A party can request to undelegate their stake or part of it right now (0059-STKG-015)
   425      Description: A party with delegated stake and/or pending delegation can request to undelegate all or part of it immediately as opposed to at the end of the epoch
   426  
   427      When the parties submit the following delegations:
   428      | party  | node id  | amount |
   429      | party1 |  node1   |  1000  | 
   430  
   431      #end epoch 1 for the delegation to take effect   
   432      When the network moves ahead "7" blocks 
   433      Then the parties should have the following delegation balances for epoch 2:
   434      | party  | node id  | amount |
   435      | party1 |  node1   |  1000  | 
   436  
   437      Then the parties submit the following delegations:
   438      | party  | node id  | amount |
   439      | party1  |  node1   |  50   | 
   440      | party1  |  node2   |  123  | 
   441      
   442      #we are in the middle of epoch2 and the party1 requests to undelegate all of their stake to party1
   443      Then the parties submit the following undelegations:
   444      | party  | node id  | amount |  when  |
   445      | party1 |  node1   |  0     |  now   |
   446  
   447      #therefore we expect their current balance for epoch 2 for party1 node1 is 0
   448      Then the parties should have the following delegation balances for epoch 2:
   449      | party  | node id  | amount |
   450      | party1 |  node1   |   0    |
   451      | party1 |  node2   |   0    |
   452      
   453      #the expected balance for the following epoch should be the same for party1/node1 because undelegation has already been applied and for party1/node1 should include the expected delegation
   454      And the parties should have the following delegation balances for epoch 3:
   455      | party  | node id  | amount |
   456      | party1 |  node1   |   0    |
   457      | party1 |  node2   |  123   |
   458  
   459      #advance to the end of epoch2 for the delegations/undelegations to be applied - and expect no change for node1 because undelegation has already taken place
   460      #the delegation from party1 to node2 will have been applied 
   461      When the network moves ahead "7" blocks
   462      Then the parties should have the following delegation balances for epoch 3:
   463      | party  | node id  | amount |
   464      | party1 |  node1   |   0    | 
   465      | party1 |  node2   |   123  |  
   466    
   467    Scenario: A party withdraws from their staking account during an epoch - their stake is being undelegated automatically to match the difference (0059-STKG-011, 0059-STKG-012)
   468      Description: A party with delegated stake withdraws from their staking account during an epoch - at the end of the epoch when delegations are processed the party will be forced to undelegate the difference between the stake they have delegated and their staking account balance. 
   469  
   470      When the parties submit the following delegations:
   471      | party  | node id  | amount |
   472      | party1 |  node1   |  1000  | 
   473  
   474      #end epoch 1 for the delegation to take effect   
   475      When the network moves ahead "7" blocks   
   476      Then the parties should have the following delegation balances for epoch 2:
   477      | party  | node id  | amount |
   478      | party1 |  node1   |  1000  | 
   479  
   480      Given the parties withdraw from staking account the following amount:  
   481      | party  | asset  | amount |
   482      | party1 | VEGA   |  9500  |
   483  
   484      # advance to the end of epoch2
   485      When the network moves ahead "7" blocks
   486      # we expect the actual balance of epoch 2 for party1 has changed retrospectively to 500 to reflect that the party has insufficient balance in their staking account to cover 1000 delegated tokens   
   487      Then the parties should have the following delegation balances for epoch 2:
   488      | party  | node id  | amount |
   489      | party1 |  node1   |  500   |   
   490  
   491      And the parties should have the following delegation balances for epoch 3:
   492      | party  | node id  | amount |
   493      | party1 |  node1   |  500   |
   494  
   495    Scenario: Undelegate now followed by withdraw - same behaviour as either undelegate now or withdraw (0059-STKG-011, 0059-STKG-014, 0059-STKG-015)
   496  
   497      When the parties submit the following delegations:
   498      | party  | node id  | amount |
   499      | party1 |  node1   |  1000  | 
   500  
   501      #end epoch 1 for the delegation to take effect   
   502      When the network moves ahead "7" blocks   
   503      Then the parties should have the following delegation balances for epoch 2:
   504      | party  | node id  | amount |
   505      | party1 |  node1   |  1000  | 
   506  
   507      Then the parties submit the following undelegations:
   508      | party  | node id  | amount |  when  |
   509      | party1 |  node1   |  500   |  now   |
   510  
   511      # start epoch2    
   512      Given the parties withdraw from staking account the following amount:  
   513      | party  | asset  | amount |
   514      | party1 | VEGA   |  9600  |
   515  
   516      # advance to the end of epoch2
   517      When the network moves ahead "7" blocks
   518      Then the parties should have the following delegation balances for epoch 2:
   519      | party  | node id  | amount |
   520      | party1 |  node1   |  400   |   
   521  
   522      And the parties should have the following delegation balances for epoch 3:
   523      | party  | node id  | amount |
   524      | party1 |  node1   |  400   |     
   525  
   526    Scenario: Withdrawal followed by undelegate now (same epoch) - same behaviour as either undelegate now or withdraw (0059-STKG-011, 0059-STKG-014, 0059-STKG-015)
   527  
   528      When the parties submit the following delegations:
   529      | party  | node id  | amount |
   530      | party1 |  node1   |  1000  | 
   531  
   532      #end epoch 1 for the delegation to take effect   
   533      When the network moves ahead "7" blocks
   534      Then the parties should have the following delegation balances for epoch 2:
   535      | party  | node id  | amount |
   536      | party1 |  node1   |  1000  | 
   537  
   538      # start epoch2
   539      Given the parties withdraw from staking account the following amount:  
   540      | party  | asset  | amount |
   541      | party1 | VEGA   |  9500  |
   542  
   543      Then the parties submit the following undelegations:
   544      | party  | node id  | amount |  when  |
   545      | party1 |  node1   |    400 |  now   |
   546  
   547      # advance to the end of epoch2
   548      When the network moves ahead "7" blocks
   549      Then the parties should have the following delegation balances for epoch 2:
   550      | party  | node id  | amount |
   551      | party1 |  node1   |    500 |   
   552  
   553      And the parties should have the following delegation balances for epoch 3:
   554      | party  | node id  | amount |
   555      | party1 |  node1   |    500 |    
   556  
   557    Scenario: Withdrawal followed by undelegate now (next epoch) - results in additional undelegation (0059-STKG-011, 0059-STKG-014, 0059-STKG-015)
   558  
   559      When the parties submit the following delegations:
   560      | party  | node id  | amount |
   561      | party1 |  node1   |  1000  | 
   562  
   563      #end epoch 1 for the delegation to take effect   
   564      When the network moves ahead "7" blocks 
   565      Then the parties should have the following delegation balances for epoch 2:
   566      | party  | node id  | amount |
   567      | party1 |  node1   |  1000  | 
   568  
   569      Given the parties withdraw from staking account the following amount:  
   570      | party  | asset  | amount |
   571      | party1 | VEGA   |  9500  |
   572  
   573      # advance to the end of epoch2
   574      When the network moves ahead "7" blocks
   575      Then the parties should have the following delegation balances for epoch 2:
   576      | party  | node id  | amount |
   577      | party1 |  node1   |    500 |   
   578  
   579      Then the parties submit the following undelegations:
   580      | party  | node id  | amount |  when  |
   581      | party1 |  node1   |    200 |  now   |
   582  
   583      And the parties should have the following delegation balances for epoch 3:
   584      | party  | node id  | amount |
   585      | party1 |  node1   |    300 |
   586  
   587      Then the parties submit the following undelegations:
   588      | party  | node id  | amount |  when  |
   589      | party1 |  node1   |    200 |  now   |
   590  
   591      And the parties should have the following delegation balances for epoch 3:
   592      | party  | node id  | amount |
   593      | party1 |  node1   |    100 |    
   594  
   595      When the network moves ahead "7" blocks
   596  
   597      And the parties should have the following delegation balances for epoch 3:
   598      | party  | node id  | amount |
   599      | party1 |  node1   |    100 |    
   600  
   601    Scenario: Mix undelegate now & end of epoch (0059-STKG-013, 0059-STKG-014)
   602  
   603      When the parties submit the following delegations:
   604      | party  | node id  | amount |
   605      | party1 |  node1   |  1000  | 
   606  
   607      #end epoch 1 for the delegation to take effect   
   608      When the network moves ahead "7" blocks
   609      Then the parties should have the following delegation balances for epoch 2:
   610      | party  | node id  | amount |
   611      | party1 |  node1   |  1000  | 
   612  
   613      Then the parties submit the following undelegations:
   614      | party  | node id  | amount | when         |
   615      | party1 |  node1   |    500 | now          |
   616      | party1 |  node1   |    400 | end of epoch |
   617  
   618      # advance to the end of epoch2
   619      When the network moves ahead "7" blocks
   620      # we expect the actual balance of epoch 2 for party1 has changed retrospectively to 500 to reflect that the party has insufficient balance in their staking account to cover 1000 delegated tokens   
   621      Then the parties should have the following delegation balances for epoch 2:
   622      | party  | node id  | amount |
   623      | party1 |  node1   |    500 |   
   624  
   625      And the parties should have the following delegation balances for epoch 3:
   626      | party  | node id  | amount |
   627      | party1 |  node1   |    100 |    
   628  
   629      When the network moves ahead "7" blocks
   630  
   631      And the parties should have the following delegation balances for epoch 3:
   632      | party  | node id  | amount |
   633      | party1 |  node1   |    100 |    
   634  
   635    Scenario: A validator gets past maximum stake by changing network parameter (0059-STKG-additional-tests)
   636      Description: A party attempts to delegate token stake which exceed maximum stake for a validator
   637  
   638      When the parties submit the following delegations:
   639      | party  | node id  |   amount  | 
   640      | party1 |  node1   |    1500   | 
   641      | party1 |  node2   |    2000   | 
   642      | party1 |  node3   |    2500   | 
   643  
   644      #we are now in epoch 1 so the delegation balance for epoch 1 should not include the delegation but the hypothetical balance for epoch 2 should 
   645      Then the parties should have the following delegation balances for epoch 1:
   646      | party  | node id  | amount |
   647      | party1 |  node1   |   0    | 
   648      | party1 |  node2   |   0    |       
   649      | party1 |  node3   |   0    |        
   650  
   651      And the parties should have the following delegation balances for epoch 2:
   652      | party  | node id  | amount |
   653      | party1 |  node1   | 1500   | 
   654      | party1 |  node2   | 2000   |       
   655      | party1 |  node3   | 2500   |        
   656  
   657      When the network moves ahead "7" blocks 
   658  
   659      Then the parties should have the following delegation balances for epoch 2:
   660      | party  | node id  | amount |
   661      | party1 |  node1   | 1500   | 
   662      | party1 |  node2   | 2000   |       
   663      | party1 |  node3   | 2500   |   
   664  
   665      Given the following network parameters are set:
   666        | name                                            | value |
   667        | reward.staking.delegation.competitionLevel      | 1.01  |
   668  
   669       When the network moves ahead "7" blocks   
   670  
   671       Then the parties should have the following delegation balances for epoch 3:
   672        | party  | node id  | amount |
   673        | party1 |  node1   | 1500   | 
   674        | party1 |  node2   | 2000   |       
   675        | party1 |  node3   | 2500   |   
   676  
   677       Given the following network parameters are set:
   678        | name                                            | value |
   679        | reward.staking.delegation.competitionLevel      | 1.2   |
   680  
   681      When the network moves ahead "7" blocks   
   682  
   683       # Changing the competitionLevel raises the max delegation limit, however not expecting more delegation to automatically get deployed.
   684       Then the parties should have the following delegation balances for epoch 4:
   685        | party  | node id  | amount |
   686        | party1 |  node1   | 1500   | 
   687        | party1 |  node2   | 2000   |       
   688        | party1 |  node3   | 2500   |   
   689  
   690  
   691      When the parties submit the following delegations:
   692        | party  | node id  |   amount  | 
   693        | party1 |  node1   |    1000   | 
   694        | party1 |  node2   |     500   | 
   695        | party1 |  node3   |    2200   | 
   696  
   697      When the network moves ahead "1" blocks
   698    
   699      # Given new delegations the new expected limit is 2758, however not expecting to see it reflected in delegation balances until epoch ends
   700      Then the parties should have the following delegation balances for epoch 5:
   701        | party  | node id  | amount |
   702        | party1 |  node1   | 2500   | 
   703        | party1 |  node2   | 2500   |       
   704        | party1 |  node3   | 4700   |   
   705  
   706      When the network moves ahead "6" blocks
   707  
   708      Then the parties should have the following delegation balances for epoch 5:
   709        | party  | node id  | amount |
   710        | party1 |  node1   | 2500   | 
   711        | party1 |  node2   | 2500   |       
   712        | party1 |  node3   | 4700   |
   713  
   714    Scenario: A party undelegates now and then withdraws from their staking account during an epoch - their stake is undelegated automatically to match the difference (0059-STKG-011)
   715      Description: A party undelegates now and then withdraws from their staking account during an epoch - then immediately delegations are processed the party will be forced to undelegate the difference between the stake they have delegated and their staking account balance. 
   716  
   717      When the parties submit the following delegations:
   718      | party  | node id  | amount |
   719      | party1 |  node1   | 1000   | 
   720  
   721      #end epoch 1 for the delegation to take effect   
   722      When the network moves ahead "7" blocks   
   723      Then the parties should have the following delegation balances for epoch 2:
   724      | party  | node id  | amount |
   725      | party1 |  node1   | 1000   | 
   726    
   727      Then the parties submit the following undelegations:
   728      | party  | node id  | amount | when |
   729      | party1 |  node1   |  500   | now  |
   730  
   731      And the parties withdraw from staking account the following amount:  
   732      | party  | asset  | amount |
   733      | party1 | VEGA   |  9600  |
   734  
   735      And the parties should have the following staking account balances:
   736      | party  | asset | amount |
   737      | party1 | VEGA  | 400    |  
   738  
   739      # advance to the end of epoch2
   740      When the network moves ahead "7" blocks  
   741      # we expect the actual balance of epoch 2 for party1 has changed retrospectively to 400 to reflect that the party has insufficient balance in their staking account to cover 1000-500 delegated tokens   
   742      Then the parties should have the following delegation balances for epoch 2:
   743      | party  | node id  | amount |
   744      | party1 |  node1   |  400   | 
   745  
   746      And the parties should have the following delegation balances for epoch 3:
   747      | party  | node id  | amount |
   748      | party1 |  node1   |  400   |     
   749  
   750    Scenario: A party delegates and then withdraws from their staking account during the same epoch such that delegation is a successful ( (0059-STKG-002, 0059-STKG-005, 0059-STKG-006, 0059-STKG-007, 0059-STKG-011)
   751      Description: A party delegates now and then withdraws from their staking account during the same epoch such that delegation is a successful
   752  
   753      When the parties submit the following delegations:
   754      | party  | node id  | amount |
   755      | party1 |  node1   | 1000   | 
   756  
   757      And the parties withdraw from staking account the following amount:  
   758      | party  | asset  | amount |
   759      | party1 | VEGA   |  9000  |
   760  
   761      #end epoch 1 for the delegation to take effect   
   762      When the network moves ahead "7" blocks      
   763      Then the parties should have the following delegation balances for epoch 2:
   764      | party  | node id  | amount |
   765      | party1 |  node1   | 1000   | 
   766  
   767      # advance to the end of epoch2
   768      When the network moves ahead "7" blocks   
   769      # we expect the actual balance of epoch 2 for party1 to be upated to 500 to reflect that the party has sufficient balance in their staking account to cover 1000 delegated tokens   
   770      Then the parties should have the following delegation balances for epoch 2:
   771      | party  | node id  | amount |
   772      | party1 |  node1   |  1000  |   
   773  
   774       And the parties should have the following staking account balances:
   775      | party  | asset | amount |
   776      | party1 | VEGA  | 1000   |  
   777  
   778      And the parties should have the following delegation balances for epoch 3:
   779      | party  | node id  | amount |
   780      | party1 |  node1   |  1000  |     
   781  
   782    Scenario: A party delegates and then withdraws from their staking account during the same epoch such that delegation fails (0059-STKG-002, 0059-STKG-005)
   783      Description: A party delegates now and then withdraws from their staking account during the same epoch such that delegation fails
   784  
   785      When the parties submit the following delegations:
   786      | party  | node id  | amount |
   787      | party1 |  node1   | 1000   | 
   788  
   789      And the parties withdraw from staking account the following amount:  
   790      | party  | asset  | amount |
   791      | party1 | VEGA   |  9500  |
   792  
   793      #end epoch 1 for the delegation to take effect   
   794      When the network moves ahead "7" blocks   
   795      Then the parties should have the following delegation balances for epoch 2:
   796      | party  | node id  | amount |
   797      | party1 |  node1   | 500    | 
   798  
   799      # advance to the end of epoch2
   800      When the network moves ahead "7" blocks   
   801      # we expect the actual balance of epoch 2 for party1 has changed retrospectively to 0 to reflect that the party has insufficient balance in their staking account to cover 1000 delegated tokens    
   802      Then the parties should have the following delegation balances for epoch 2:
   803      | party  | node id  | amount |
   804      | party1 |  node1   |  500   |   
   805  
   806       And the parties should have the following staking account balances:
   807      | party  | asset | amount |
   808      | party1 | VEGA  | 500    |  
   809  
   810      And the parties should have the following delegation balances for epoch 3:
   811      | party  | node id  | amount |
   812      | party1 |  node1   |  500   |    
   813  
   814    Scenario: A party withdraws from their staking account during an epoch - their stake is undelegated automatically to match the difference (0059-STKG-012)
   815      Description: A party with delegated stake withdraws from their staking account during an epoch - at the end of the epoch when delegations are processed the party will be forced to undelegate the difference between the stake they have delegated and their staking account balance. 
   816  
   817      When the parties submit the following delegations:
   818      | party  | node id  | amount |
   819      | party1 |  node1   |  1000  | 
   820  
   821      #end epoch 2 for the delegation to take effect   
   822      When the network moves ahead "7" blocks      
   823      Then the parties should have the following delegation balances for epoch 2:
   824      | party  | node id  | amount |
   825      | party1 |  node1   |  1000  | 
   826  
   827      And the parties should have the following staking account balances:
   828      | party  | asset | amount |
   829      | party1 | VEGA  | 10000  |   
   830  
   831      Given the parties withdraw from staking account the following amount:  
   832      | party  | asset  | amount |
   833      | party1 | VEGA   |  9500  |
   834  
   835      And the parties submit the following undelegations:
   836      | party  | node id  | amount | when |
   837      | party1 |  node1   |  1000  | now  |    
   838  
   839      # advance to the end of epoch3
   840      When the network moves ahead "7" blocks   
   841      # we expect the actual balance of epoch 3 for party1 has changed retrospectively to 0 to reflect that the 500 tokens have undelegated too
   842      Then the parties should have the following delegation balances for epoch 3:
   843      | party  | node id  | amount |
   844      | party1 |  node1   |  0     |  
   845  
   846      And the parties should have the following staking account balances:
   847      | party  | asset | amount |
   848      | party1 | VEGA  | 500    |