Skip to content

Commit

Permalink
Add a flag to point to a pre-deployed contract address (#4)
Browse files Browse the repository at this point in the history
* readme

* add new flag parameters for pre-defined contract addresses

* add if statement to skip deployment if predefined address exist

* fix
  • Loading branch information
gatsbyz authored Oct 7, 2022
1 parent 4f86fbe commit 78bc5a6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
6 changes: 4 additions & 2 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ Usage:
Flags:
--chain-id uint The chain id for the transactions that we're going to send (default 1256)
-c, --concurrency int Number of multiple requests to perform at a time. Default is one request at a time. (default 1)
--del-address string A pre-deployed delegator contract address
--lt-address string A pre-deployed load test contract address
-f, --function --mode f A specific function to be called if running with --mode f (default 1)
-h, --help help for loadtest
-i, --iterations uint If we're making contract calls, this controls how many times the contract will execute the instruction in a loop (default 100)
Expand Down Expand Up @@ -405,7 +407,7 @@ we'll startup geth.


# v3
go run cmd/borv3/main.go server --dev \
go run main.go server --dev \
--dev.period 2 \
--ws --ws.port 8546 \
--http --http.port 8545 \
Expand Down Expand Up @@ -459,7 +461,7 @@ INFO [08-14|16:09:31.452] Generated ephemeral JWT secret secret=0xdfa5
I'll usually then use that line to attach

#+begin_src shell
./build/bin/geth attach /var/folders/zs/k8swqskj1t79cgnjh6yt0fqm0000gn/T/geth.ip
./build/bin/geth attach /var/folders/zs/k8swqskj1t79cgnjh6yt0fqm0000gn/T/geth.ipc
#+end_src

After attaching to geth, we can fund the default load testing account
Expand Down
29 changes: 24 additions & 5 deletions cmd/loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ type (
Seed *int64
IsAvail *bool
AvailAppID *uint32
LtAddress *string
DelAddress *string

// Computed
CurrentGas *big.Int
Expand Down Expand Up @@ -267,6 +269,8 @@ func init() {
ltp.Seed = loadtestCmd.PersistentFlags().Int64("seed", 123456, "A seed for generating random values and addresses")
ltp.IsAvail = loadtestCmd.PersistentFlags().Bool("data-avail", false, "Is this a test of avail rather than an EVM / Geth Chain")
ltp.AvailAppID = loadtestCmd.PersistentFlags().Uint32("app-id", 0, "The AppID used for avail")
ltp.LtAddress = loadtestCmd.PersistentFlags().String("lt-address", "", "A pre-deployed load test contract address")
ltp.DelAddress = loadtestCmd.PersistentFlags().String("del-address", "", "A pre-deployed delegator contract address")

inputLoadTestParams = *ltp

Expand Down Expand Up @@ -507,16 +511,30 @@ func mainLoop(ctx context.Context, c *ethclient.Client) error {
}
cops := new(bind.CallOpts)

ltAddr, _, _, err := contracts.DeployLoadTester(tops, c)
if err != nil {
log.Error().Err(err).Msg("Failed to create the load testing contract. Do you have the right chain id? Do you have enough funds?")
return err
var ltAddr ethcommon.Address
if *inputLoadTestParams.ToAddress == "" {
ltAddr, _, _, err = contracts.DeployLoadTester(tops, c)
if err != nil {
log.Error().Err(err).Msg("Failed to create the load testing contract. Do you have the right chain id? Do you have enough funds?")
return err
}
} else {
ltAddr = ethcommon.HexToAddress(*inputLoadTestParams.LtAddress)
}
log.Trace().Interface("contractaddress", ltAddr).Msg("Load test contract address")
// bump the nonce since deploying a contract should cause it to increase
currentNonce = currentNonce + 1

delegatorAddr, _, _, err := contracts.DeployDelegator(tops, c)
var delegatorAddr ethcommon.Address
if *inputLoadTestParams.ToAddress == "" {
delegatorAddr, _, _, err = contracts.DeployDelegator(tops, c)
if err != nil {
log.Error().Err(err).Msg("Failed to create the load testing contract. Do you have the right chain id? Do you have enough funds?")
return err
}
} else {
delegatorAddr = ethcommon.HexToAddress(*inputLoadTestParams.DelAddress)
}
if err != nil {
log.Error().Err(err).Msg("Failed to create the delegator contract. Do you have the right chain id? Do you have enough funds?")
return err
Expand All @@ -540,6 +558,7 @@ func mainLoop(ctx context.Context, c *ethclient.Client) error {
waitCounter := 30
for {
ltCounter, err := ltContract.GetCallCounter(cops)

if err != nil {
log.Trace().Msg("Waiting for contract to deploy")
time.Sleep(time.Second)
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/centrifuge/go-substrate-rpc-client/v4 v4.0.6
github.com/ethereum/go-ethereum v1.10.20
github.com/ethereum/go-ethereum v1.10.25
github.com/gizak/termui/v3 v3.1.0
github.com/libp2p/go-libp2p v0.22.0
github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae
Expand Down Expand Up @@ -103,5 +103,3 @@ require (
)

replace github.com/centrifuge/go-substrate-rpc-client/v4 => github.com/prabal-banerjee/go-substrate-rpc-client/v4 v4.0.0-avail-alpha


2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/ethereum/go-ethereum v1.10.20 h1:75IW830ClSS40yrQC1ZCMZCt5I+zU16oqId2SiQwdQ4=
github.com/ethereum/go-ethereum v1.10.20/go.mod h1:LWUN82TCHGpxB3En5HVmLLzPD7YSrEUFmFfN1nKkVN0=
github.com/ethereum/go-ethereum v1.10.25 h1:5dFrKJDnYf8L6/5o42abCE6a9yJm9cs4EJVRyYMr55s=
github.com/ethereum/go-ethereum v1.10.25/go.mod h1:EYFyF19u3ezGLD4RqOkLq+ZCXzYbLoNDdZlMt7kyKFg=
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
Expand Down

0 comments on commit 78bc5a6

Please sign in to comment.