code.vegaprotocol.io/vega@v0.79.0/core/integration/steps/parties_undelegate_the_following_stake.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 "context" 20 21 "code.vegaprotocol.io/vega/core/delegation" 22 "code.vegaprotocol.io/vega/libs/num" 23 24 "github.com/cucumber/godog" 25 ) 26 27 func PartiesUndelegateTheFollowingStake( 28 engine *delegation.Engine, 29 table *godog.Table, 30 ) error { 31 for _, r := range parseUndelegationTable(table) { 32 row := newUndelegationRow(r) 33 34 if row.When() == "now" { 35 err := engine.UndelegateNow(context.Background(), row.Party(), row.NodeID(), num.NewUint(row.Amount())) 36 37 if err := checkExpectedError(row, err, nil); err != nil { 38 return err 39 } 40 } else { 41 err := engine.UndelegateAtEndOfEpoch(context.Background(), row.Party(), row.NodeID(), num.NewUint(row.Amount())) 42 43 if err := checkExpectedError(row, err, nil); err != nil { 44 return err 45 } 46 } 47 } 48 return nil 49 } 50 51 func parseUndelegationTable(table *godog.Table) []RowWrapper { 52 return StrictParseTable(table, []string{ 53 "party", 54 "node id", 55 "amount", 56 "when", 57 }, []string{ 58 "reference", 59 "error", 60 }) 61 } 62 63 type undelegationRow struct { 64 row RowWrapper 65 } 66 67 func newUndelegationRow(r RowWrapper) undelegationRow { 68 row := undelegationRow{ 69 row: r, 70 } 71 return row 72 } 73 74 func (r undelegationRow) When() string { 75 return r.row.MustStr("when") 76 } 77 78 func (r undelegationRow) Party() string { 79 return r.row.MustStr("party") 80 } 81 82 func (r undelegationRow) NodeID() string { 83 return r.row.MustStr("node id") 84 } 85 86 func (r undelegationRow) Amount() uint64 { 87 return r.row.MustU64("amount") 88 } 89 90 func (r undelegationRow) Error() string { 91 return r.row.Str("error") 92 } 93 94 func (r undelegationRow) ExpectError() bool { 95 return r.row.HasColumn("error") 96 } 97 98 func (r undelegationRow) Reference() string { 99 return r.row.MustStr("reference") 100 }