code.vegaprotocol.io/vega@v0.79.0/core/integration/steps/party_should_receive_the_following_rewards.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package steps
    17  
    18  import (
    19  	"fmt"
    20  
    21  	"code.vegaprotocol.io/vega/core/integration/stubs"
    22  	"code.vegaprotocol.io/vega/libs/num"
    23  
    24  	"github.com/cucumber/godog"
    25  )
    26  
    27  func PartiesShouldReceiveTheFollowingReward(
    28  	broker *stubs.BrokerStub,
    29  	table *godog.Table,
    30  	epochSeq string,
    31  ) error {
    32  	rewards := broker.GetRewards(epochSeq)
    33  
    34  	for _, r := range parseRewardsTable(table) {
    35  		row := rewardRow{row: r}
    36  
    37  		actualReward := num.UintZero().String()
    38  		if reward, ok := rewards[stubs.AssetParty{Asset: row.Asset(), Party: row.Party()}]; ok {
    39  			actualReward = reward.Amount.String()
    40  		}
    41  
    42  		if row.Amount() != actualReward {
    43  			return errMismatchedReward(row, actualReward)
    44  		}
    45  	}
    46  	return nil
    47  }
    48  
    49  func errMismatchedReward(row rewardRow, actualReward string) error {
    50  	return formatDiff(
    51  		fmt.Sprintf("reward amount did not match for party(%s)", row.Party()),
    52  		map[string]string{
    53  			"reward amount": row.Amount(),
    54  		},
    55  		map[string]string{
    56  			"reward amount": actualReward,
    57  		},
    58  	)
    59  }
    60  
    61  func parseRewardsTable(table *godog.Table) []RowWrapper {
    62  	return StrictParseTable(table, []string{
    63  		"party",
    64  		"asset",
    65  		"amount",
    66  	}, nil)
    67  }
    68  
    69  type rewardRow struct {
    70  	row RowWrapper
    71  }
    72  
    73  func (r rewardRow) Asset() string {
    74  	return r.row.MustStr("asset")
    75  }
    76  
    77  func (r rewardRow) Party() string {
    78  	return r.row.MustStr("party")
    79  }
    80  
    81  func (r rewardRow) Amount() string {
    82  	return r.row.MustStr("amount")
    83  }