Skip to content

Commit

Permalink
Merge pull request #253 from vegaprotocol/251-move-over-to-wallet-v2
Browse files Browse the repository at this point in the history
Update tools to use wallet v2
  • Loading branch information
peterbarrow authored Jan 10, 2023
2 parents 476b005 + 7bfd1ad commit d09ff18
Show file tree
Hide file tree
Showing 16 changed files with 223 additions and 395 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
- [237](https://github.com/vegaprotocol/vegatools/issues/237) - Rename of Oracles to Data Sources
- [240](https://github.com/vegaprotocol/vegatools/issues/240) - Add support for filling price levels before perf testing begins
- [247](https://github.com/vegaprotocol/vegatools/issues/247) - Made ganache value optional for perftool
- [251](https://github.com/vegaprotocol/vegatools/issues/251) - Changed code to use wallet V2 and updated protobuf mod to correct version

### 🐛 Fixes
- [78](https://github.com/vegaprotocol/vegatools/pull/78) - Fix build with missing dependency
Expand Down
2 changes: 1 addition & 1 deletion checkpoint/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
checkpoint "code.vegaprotocol.io/vega/protos/vega/checkpoint/v1"
events "code.vegaprotocol.io/vega/protos/vega/events/v1"

"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"
)

var (
Expand Down
6 changes: 3 additions & 3 deletions checkpoint/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
checkpoint "code.vegaprotocol.io/vega/protos/vega/checkpoint/v1"
events "code.vegaprotocol.io/vega/protos/vega/events/v1"

"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
"github.com/gogo/protobuf/jsonpb"
"golang.org/x/crypto/sha3"
"google.golang.org/protobuf/proto"
)

type all struct {
Expand Down Expand Up @@ -413,7 +413,7 @@ func dummy() *all {
TimeWindow: 10,
ScalingFactor: 0.7,
},
TriggeringRatio: 0.5,
TriggeringRatio: "0.5",
AuctionExtension: 10,
},
RiskParameters: &vega.NewMarketConfiguration_LogNormal{
Expand Down
2 changes: 2 additions & 0 deletions cmd/perftest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func init() {
perfTestCmd.Flags().StringVarP(&opts.WalletURL, "wallet", "w", "", "address of the wallet server")
perfTestCmd.Flags().StringVarP(&opts.FaucetURL, "faucet", "f", "", "address of the faucet server")
perfTestCmd.Flags().StringVarP(&opts.GanacheURL, "ganache", "g", "", "address of the ganache server")
perfTestCmd.Flags().StringVarP(&opts.TokenKeysFile, "tokenkeys", "t", "", "path to api token keys file")
perfTestCmd.Flags().IntVarP(&opts.CommandsPerSecond, "cps", "c", 100, "commands per second")
perfTestCmd.Flags().IntVarP(&opts.RuntimeSeconds, "runtime", "r", 60, "runtime in seconds")
perfTestCmd.Flags().IntVarP(&opts.UserCount, "users", "u", 10, "number of users to send commands with")
Expand All @@ -36,6 +37,7 @@ func init() {
perfTestCmd.MarkFlagRequired("address")
perfTestCmd.MarkFlagRequired("wallet")
perfTestCmd.MarkFlagRequired("faucet")
perfTestCmd.MarkFlagRequired("tokenkeys")
}

func runPerfTest(cmd *cobra.Command, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion eventpersister/eventpersister.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1"
"code.vegaprotocol.io/vegatools/stream"

"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"
)

// Run is the main function of `eventpersister` package
Expand Down
2 changes: 1 addition & 1 deletion eventsource/eventsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1"

"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"
)

func sendAllEvents(sendEvents func([]*eventspb.BusEvent) error, evtFile *os.File,
Expand Down
2 changes: 1 addition & 1 deletion eventsource/socketclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (

eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1"

"github.com/golang/protobuf/proto"
mangos "go.nanomsg.org/mangos/v3"
"go.nanomsg.org/mangos/v3/protocol"
"go.nanomsg.org/mangos/v3/protocol/push"
"google.golang.org/protobuf/proto"

// Required for socket client
_ "go.nanomsg.org/mangos/v3/transport/inproc"
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ go 1.19

require (
code.vegaprotocol.io/shared v0.0.0-20221010085458-55c50711135f
code.vegaprotocol.io/vega v0.62.2-0.20221118155204-060bc3b13f56
github.com/cosmos/iavl v0.19.1
code.vegaprotocol.io/vega v0.66.0
github.com/cosmos/iavl v0.19.4
github.com/ethereum/go-ethereum v1.10.21
github.com/gdamore/tcell/v2 v2.5.2
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.5.2
github.com/shopspring/decimal v1.3.1
github.com/spf13/cobra v1.6.0
github.com/stretchr/testify v1.8.0
Expand Down Expand Up @@ -38,6 +37,7 @@ require (
github.com/gdamore/encoding v1.0.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/uuid v1.3.0 // indirect
Expand All @@ -54,7 +54,7 @@ require (
github.com/rjeczalik/notify v0.9.1 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tendermint/tendermint v0.34.23 // indirect
github.com/tendermint/tendermint v0.34.24 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
Expand Down
14 changes: 7 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
code.vegaprotocol.io/shared v0.0.0-20221010085458-55c50711135f h1:ivaWSXN7XKESShqYw/QFuT6b2mvThWPQLO7lW5sadHs=
code.vegaprotocol.io/shared v0.0.0-20221010085458-55c50711135f/go.mod h1:XzX67GsyOHzvytMr0QOHX4CCTdCZDYKUUi88rx40Nt0=
code.vegaprotocol.io/vega v0.62.2-0.20221118155204-060bc3b13f56 h1:4Yqk9HyAvv+whbzUGuulvIR85UxNhyxl9RqMv4BMnII=
code.vegaprotocol.io/vega v0.62.2-0.20221118155204-060bc3b13f56/go.mod h1:kferwPYB97SNdznVdU2Ao3AoNlao5NH+C68ityenuVk=
code.vegaprotocol.io/vega v0.66.0 h1:6IYqaQn+INPpMzz795N6oLuXBfLtRIC3I1C47Bs9EZ4=
code.vegaprotocol.io/vega v0.66.0/go.mod h1:hnqQGTSfFafoDICM8IeOcr/+rfXANT9v8NpwIRue0SA=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/zstd v1.4.1 h1:3oxKN3wbHibqx897utPC2LTQU4J+IHWWJO+glkAkpFM=
github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
Expand All @@ -12,7 +12,7 @@ github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDO
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c=
github.com/btcsuite/btcd v0.22.2 h1:vBZ+lGGd1XubpOWO67ITJpAEsICWhA0YzqkcpkgNBfo=
github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k=
github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
Expand All @@ -30,8 +30,8 @@ github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8Nz
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y=
github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw=
github.com/cosmos/iavl v0.19.1 h1:3gaq9b6SjiB0KBTygRnAvEGml2pQlu1TH8uma5g63Ys=
github.com/cosmos/iavl v0.19.1/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw=
github.com/cosmos/iavl v0.19.4 h1:t82sN+Y0WeqxDLJRSpNd8YFX5URIrT+p8n6oJbJ2Dok=
github.com/cosmos/iavl v0.19.4/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw=
github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
Expand Down Expand Up @@ -205,8 +205,8 @@ github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PK
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a h1:1ur3QoCqvE5fl+nylMaIr9PVV1w343YRDtsy+Rwu7XI=
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48=
github.com/tendermint/tendermint v0.34.23 h1:JZYsdc59aOiT5efou+BHILJv8x6FlRyvlor84Xq9Tb0=
github.com/tendermint/tendermint v0.34.23/go.mod h1:rXVrl4OYzmIa1I91av3iLv2HS0fGSiucyW9J4aMTpKI=
github.com/tendermint/tendermint v0.34.24 h1:879MKKJWYYPJEMMKME+DWUTY4V9f/FBpnZDI82ky+4k=
github.com/tendermint/tendermint v0.34.24/go.mod h1:rXVrl4OYzmIa1I91av3iLv2HS0fGSiucyW9J4aMTpKI=
github.com/tendermint/tm-db v0.6.7 h1:fE00Cbl0jayAoqlExN6oyQJ7fR/ZtoVOmvPJ//+shu8=
github.com/tendermint/tm-db v0.6.7/go.mod h1:byQDzFkZV1syXr/ReXS808NxA2xvyuuVgXOJ/088L6I=
github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw=
Expand Down
3 changes: 1 addition & 2 deletions perftest/datanode.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

datanode "code.vegaprotocol.io/vega/protos/data-node/api/v2"
proto "code.vegaprotocol.io/vega/protos/vega"
v1 "code.vegaprotocol.io/vega/protos/vega/commands/v1"
)

type dnWrapper struct {
Expand Down Expand Up @@ -121,7 +120,7 @@ func (d *dnWrapper) waitForMarketEnactment(marketID string, maxWaitSeconds int)

func (d *dnWrapper) voteOnProposal(users []UserDetails, propID string, voters int) error {
for i := 0; i < voters; i++ {
err := d.wallet.SendVote(users[i], &v1.VoteSubmission{ProposalId: propID, Value: proto.Vote_VALUE_YES})
err := d.wallet.SendVote(users[i], propID)
if err != nil {
return err
}
Expand Down
57 changes: 44 additions & 13 deletions perftest/perftest.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package perftest

import (
"bufio"
"flag"
"fmt"
"log"
"math/rand"
"os"
"strconv"
"strings"
"time"

"google.golang.org/grpc"
Expand All @@ -22,6 +25,7 @@ type Opts struct {
WalletURL string
FaucetURL string
GanacheURL string
TokenKeysFile string
CommandsPerSecond int
RuntimeSeconds int
UserCount int
Expand Down Expand Up @@ -70,10 +74,28 @@ func (p *perfLoadTesting) connectToDataNode(dataNodeAddr string) (map[string]str
}
}

func (p *perfLoadTesting) CreateUsers(userCount int) error {
var err error
p.users, err = p.wallet.CreateOrLoadWallets(userCount)
return err
func (p *perfLoadTesting) LoadUsers(tokenFilePath string, userCount int) error {
// See if we have a token file defined and if so load all the wallet names and api-keys
p.users = []UserDetails{}
tokenFile, err := os.Open(tokenFilePath)
if err != nil {
return err
}
fileScanner := bufio.NewScanner(tokenFile)
fileScanner.Split(bufio.ScanLines)

for fileScanner.Scan() {
lineParts := strings.Split(fileScanner.Text(), " ")
if len(lineParts) == 2 {
pubKey, _ := p.wallet.GetFirstKey(lineParts[1])

p.users = append(p.users, UserDetails{userName: lineParts[0], token: lineParts[1], pubKey: pubKey})
}
if len(p.users) == userCount {
break
}
}
return nil
}

func (p *perfLoadTesting) depositTokens(assets map[string]string, faucetURL, ganacheURL string, voters int) error {
Expand Down Expand Up @@ -168,7 +190,7 @@ func (p *perfLoadTesting) proposeAndEnactMarket(numberOfMarkets, voters, maxLPSh
markets := p.dataNode.getMarkets()
if len(markets) == 0 {
for i := 0; i < numberOfMarkets; i++ {
err := p.wallet.SendNewMarketProposal(i, p.users[0])
err := p.wallet.NewMarket(i, p.users[0])
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -361,7 +383,8 @@ func (p *perfLoadTesting) sendTradingLoad(marketIDs []string, users, ops, runTim
Size: 3,
Side: proto.Side_SIDE_BUY,
Type: proto.Order_TYPE_MARKET,
TimeInForce: proto.Order_TIME_IN_FORCE_IOC})
TimeInForce: proto.Order_TIME_IN_FORCE_IOC,
Reference: "MarketBuy"})
if err != nil {
log.Println("Failed to send market buy order", err)
}
Expand All @@ -370,7 +393,8 @@ func (p *perfLoadTesting) sendTradingLoad(marketIDs []string, users, ops, runTim
Size: 3,
Side: proto.Side_SIDE_SELL,
Type: proto.Order_TYPE_MARKET,
TimeInForce: proto.Order_TIME_IN_FORCE_IOC})
TimeInForce: proto.Order_TIME_IN_FORCE_IOC,
Reference: "MarketSell"})
if err != nil {
log.Println("Failed to send market sell order", err)
}
Expand All @@ -385,7 +409,8 @@ func (p *perfLoadTesting) sendTradingLoad(marketIDs []string, users, ops, runTim
Size: 1,
Side: proto.Side_SIDE_SELL,
Type: proto.Order_TYPE_LIMIT,
TimeInForce: proto.Order_TIME_IN_FORCE_GTC})
TimeInForce: proto.Order_TIME_IN_FORCE_GTC,
Reference: "NonTouchingLimitSell"})
if err != nil {
log.Println("Failed to send non crossing random limit sell order", err)
}
Expand All @@ -396,7 +421,8 @@ func (p *perfLoadTesting) sendTradingLoad(marketIDs []string, users, ops, runTim
Size: 1,
Side: proto.Side_SIDE_BUY,
Type: proto.Order_TYPE_LIMIT,
TimeInForce: proto.Order_TIME_IN_FORCE_GTC})
TimeInForce: proto.Order_TIME_IN_FORCE_GTC,
Reference: "NonTouchingLimitBuy"})
if err != nil {
log.Println("Failed to send non crossing random limit buy order", err)
}
Expand Down Expand Up @@ -568,11 +594,16 @@ func Run(opts Opts) error {
fmt.Println("Complete")

// Create a set of users
fmt.Print("Creating users...")
err = plt.CreateUsers(opts.UserCount)
if err != nil {
fmt.Print("Loading users from token API file...")
if len(opts.TokenKeysFile) > 0 {
err = plt.LoadUsers(opts.TokenKeysFile, opts.UserCount)
if err != nil {
fmt.Println("FAILED")
return err
}
} else {
fmt.Println("FAILED")
return err
return fmt.Errorf("error: unable to open token file")
}
fmt.Println("Complete")

Expand Down
Loading

0 comments on commit d09ff18

Please sign in to comment.