Skip to content

Commit

Permalink
Merge pull request #9683 from vegaprotocol/9679-add-team-support-for-…
Browse files Browse the repository at this point in the history
…referrals

Adding teams support for referrals
  • Loading branch information
peterbarrow authored Oct 9, 2023
2 parents d973fb2 + 149437c commit 661442e
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,16 @@ Feature: Setting and applying referee benefit factors

# Create the referral set and codes
Given the parties create the following referral codes:
| party | code |
| referrer1 | referral-code-1 |
| party | code | is_team | team |
| referrer1 | referral-code-1 | true | team1 |
And the parties apply the following referral codes:
| party | code |
| referee1 | referral-code-1 |
| party | code | is_team | team |
| referee1 | referral-code-1 | true | team1 |

And the team "team1" has the following members:
| party |
| referrer1 |
| referee1 |

Scenario Outline: Referral set generates variable running taker volume with a referee with variable epochs in set (0083-RFPR-036)(0083-RFPR-037)(0083-RFPR-038)(0083-RFPR-039)(0083-RFPR-040)
# Expectation: Referral reward factor and referral discount factor should be set correctly according to the spec
Expand Down
8 changes: 6 additions & 2 deletions core/integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,15 @@ func InitializeScenario(s *godog.ScenarioContext) {
return steps.TheReferralStakingTiersConfiguration(referralProgramConfig, name, table)
})
s.Step(`^the parties create the following referral codes:$`, func(table *godog.Table) error {
return steps.PartiesCreateTheFollowingReferralCode(execsetup.referralProgram, table)
return steps.PartiesCreateTheFollowingReferralCode(execsetup.referralProgram, execsetup.teamsEngine, table)
})
s.Step(`^the parties apply the following referral codes:$`, func(table *godog.Table) error {
return steps.PartiesApplyTheFollowingReferralCode(execsetup.referralProgram, table)
return steps.PartiesApplyTheFollowingReferralCode(execsetup.referralProgram, execsetup.teamsEngine, table)
})
s.Step(`^the team "([^"]*)" has the following members:$`, func(team string, table *godog.Table) error {
return steps.TheTeamHasTheFollowingMembers(execsetup.teamsEngine, team, table)
})

s.Step(`the referral set stats for code "([^"]+)" at epoch "([^"]+)" should have a running volume of (\d+):`, func(code, epoch, volume string, table *godog.Table) error {
return steps.TheReferralSetStatsShouldBe(execsetup.broker, code, epoch, volume, table)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import (
"context"

"code.vegaprotocol.io/vega/core/referral"
"code.vegaprotocol.io/vega/core/teams"
"code.vegaprotocol.io/vega/core/types"
"github.com/cucumber/godog"

commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1"
)

func PartiesApplyTheFollowingReferralCode(referralEngine *referral.Engine, table *godog.Table) error {
func PartiesApplyTheFollowingReferralCode(referralEngine *referral.Engine, teamsEngine *teams.Engine, table *godog.Table) error {
ctx := context.Background()

for _, r := range parseApplyReferralCodeTable(table) {
Expand All @@ -17,6 +20,16 @@ func PartiesApplyTheFollowingReferralCode(referralEngine *referral.Engine, table
if err := checkExpectedError(row, err, nil); err != nil {
return err
}
// If we have team details, submit a new team
if r.HasColumn("is_team") && row.IsTeam() {
team := &commandspb.ApplyReferralCode{
Id: row.Team(),
}
err = teamsEngine.JoinTeam(ctx, row.Party(), team)
if err != nil {
return err
}
}
}
return nil
}
Expand All @@ -28,6 +41,8 @@ func parseApplyReferralCodeTable(table *godog.Table) []RowWrapper {
}, []string{
"error",
"reference",
"is_team",
"team",
})
}

Expand Down Expand Up @@ -61,3 +76,11 @@ func (r applyReferralCodeRow) ExpectError() bool {
func (r applyReferralCodeRow) Reference() string {
return r.row.MustStr("reference")
}

func (r applyReferralCodeRow) IsTeam() bool {
return r.row.Bool("is_team")
}

func (r applyReferralCodeRow) Team() string {
return r.row.Str("team")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import (
"context"

"code.vegaprotocol.io/vega/core/referral"
"code.vegaprotocol.io/vega/core/teams"
"code.vegaprotocol.io/vega/core/types"
"github.com/cucumber/godog"

commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1"
)

func PartiesCreateTheFollowingReferralCode(referralEngine *referral.Engine, table *godog.Table) error {
func PartiesCreateTheFollowingReferralCode(referralEngine *referral.Engine, teamsEngine *teams.Engine, table *godog.Table) error {
ctx := context.Background()

for _, r := range parseCreateReferralCodeTable(table) {
Expand All @@ -17,6 +20,17 @@ func PartiesCreateTheFollowingReferralCode(referralEngine *referral.Engine, tabl
if err := checkExpectedError(row, err, nil); err != nil {
return err
}

if r.HasColumn("is_team") && row.IsTeam() {
team := &commandspb.CreateReferralSet_Team{
Name: row.Team(),
}

err = teamsEngine.CreateTeam(ctx, row.Party(), types.TeamID(row.Team()), team)
if err != nil {
return err
}
}
}
return nil
}
Expand All @@ -26,6 +40,8 @@ func parseCreateReferralCodeTable(table *godog.Table) []RowWrapper {
"party",
"code",
}, []string{
"is_team",
"team",
"error",
"reference",
})
Expand Down Expand Up @@ -61,3 +77,11 @@ func (r createReferralCodeRow) ExpectError() bool {
func (r createReferralCodeRow) Reference() string {
return r.row.MustStr("reference")
}

func (r createReferralCodeRow) IsTeam() bool {
return r.row.Bool("is_team")
}

func (r createReferralCodeRow) Team() string {
return r.row.Str("team")
}
55 changes: 55 additions & 0 deletions core/integration/steps/team_has_the_following_members.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package steps

import (
"fmt"
"sort"

"code.vegaprotocol.io/vega/core/teams"
"github.com/cucumber/godog"
)

func TheTeamHasTheFollowingMembers(teamsEngine *teams.Engine, team string, table *godog.Table) error {
// Get a list of all the parties in a team
members := teamsEngine.GetTeamMembers(team, 0)
rows := []string{}
for _, r := range parseMembersTable(table) {
row := newMembersRow(r)
rows = append(rows, row.Party())
}
sort.Strings(members)
sort.Strings(rows)

// Do we have the same amount of parties in each list?
if len(members) != len(rows) {
return fmt.Errorf("different number of team members between the table (%d) and the engine (%d)", len(rows), len(members))
}

// Do we have the same members in each list?
for i, r := range members {
if r != rows[i] {
return fmt.Errorf("party details are different (%s != %s)", r, rows[i])
}
}
return nil
}

func parseMembersTable(table *godog.Table) []RowWrapper {
return StrictParseTable(table, []string{
"party",
}, []string{})
}

type membersRow struct {
row RowWrapper
}

func newMembersRow(r RowWrapper) membersRow {
row := membersRow{
row: r,
}
return row
}

func (r membersRow) Party() string {
return r.row.MustStr("party")
}

0 comments on commit 661442e

Please sign in to comment.