code.vegaprotocol.io/vega@v0.79.0/core/integration/steps/the_validators.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 "code.vegaprotocol.io/vega/core/delegation" 20 "code.vegaprotocol.io/vega/core/integration/stubs" 21 "code.vegaprotocol.io/vega/libs/num" 22 23 "github.com/cucumber/godog" 24 ) 25 26 func TheValidators( 27 topology *stubs.TopologyStub, 28 stakingAcountStub *stubs.StakingAccountStub, 29 delegtionEngine *delegation.Engine, 30 table *godog.Table, 31 ) error { 32 for _, r := range parseTable(table) { 33 row := newValidatorRow(r) 34 topology.AddValidator(row.id(), row.pubKey()) 35 36 amt, _ := num.UintFromString(row.stakingAccountBalance(), 10) 37 stakingAcountStub.IncrementBalance(row.pubKey(), amt) 38 } 39 40 return nil 41 } 42 43 func newValidatorRow(r RowWrapper) validatorRow { 44 row := validatorRow{ 45 row: r, 46 } 47 return row 48 } 49 50 func parseTable(table *godog.Table) []RowWrapper { 51 return StrictParseTable(table, []string{ 52 "id", 53 "staking account balance", 54 }, []string{ 55 "pub_key", 56 }) 57 } 58 59 type validatorRow struct { 60 row RowWrapper 61 } 62 63 func (r validatorRow) pubKey() string { 64 pk, ok := r.row.StrB("pub_key") 65 if !ok { 66 return r.id() 67 } 68 return pk 69 } 70 71 func (r validatorRow) id() string { 72 return r.row.MustStr("id") 73 } 74 75 func (r validatorRow) stakingAccountBalance() string { 76 return r.row.MustStr("staking account balance") 77 }