code.vegaprotocol.io/vega@v0.79.0/core/integration/steps/parties_delegate_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 PartiesDelegateTheFollowingStake( 28 engine *delegation.Engine, 29 table *godog.Table, 30 ) error { 31 for _, r := range parseDelegationTable(table) { 32 row := newDelegationRow(r) 33 err := engine.Delegate(context.Background(), row.Party(), row.NodeID(), num.NewUint(row.Amount())) 34 if err := checkExpectedError(row, err, nil); err != nil { 35 return err 36 } 37 } 38 return nil 39 } 40 41 func parseDelegationTable(table *godog.Table) []RowWrapper { 42 return StrictParseTable(table, []string{ 43 "party", 44 "node id", 45 "amount", 46 }, []string{ 47 "reference", 48 "error", 49 }) 50 } 51 52 type delegationRow struct { 53 row RowWrapper 54 } 55 56 func newDelegationRow(r RowWrapper) delegationRow { 57 row := delegationRow{ 58 row: r, 59 } 60 return row 61 } 62 63 func (r delegationRow) Party() string { 64 return r.row.MustStr("party") 65 } 66 67 func (r delegationRow) NodeID() string { 68 return r.row.MustStr("node id") 69 } 70 71 func (r delegationRow) Amount() uint64 { 72 return r.row.MustU64("amount") 73 } 74 75 func (r delegationRow) Error() string { 76 return r.row.Str("error") 77 } 78 79 func (r delegationRow) ExpectError() bool { 80 return r.row.HasColumn("error") 81 } 82 83 func (r delegationRow) Reference() string { 84 return r.row.MustStr("reference") 85 }