Skip to content

Commit

Permalink
example seth + wasp test
Browse files Browse the repository at this point in the history
  • Loading branch information
skudasov committed May 12, 2024
1 parent 9c0418e commit d9b5017
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 22 deletions.
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ test_cover:
NETWORK=$(network) ROOT_PRIVATE_KEY=$(root_private_key) go test -v -coverprofile cover.out -count 1 `go list ./... | grep -v examples` -run "TestAPI|TestSmoke|TestContract|TestGasEstimator"
go tool cover -html cover.out

.PHONY: test_wasp
test_wasp:
NETWORK=$(network) ROOT_PRIVATE_KEY=$(root_private_key) go test -v -count 1 `go list ./...` -run TestWithWasp examples_wasp

.PHONY: lint
lint:
golangci-lint --color=always run -v
15 changes: 14 additions & 1 deletion examples_wasp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,21 @@ ephemeral_addresses_number = 60
Then start the Geth and run the test

```
nix develop
make GethSync
// another terminal, from examples_wasp dir
export SETH_LOG_LEVEL=debug
export SETH_CONFIG_PATH=seth.toml
export NETWORK=Geth
export ROOT_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
export LOKI_TENANT_ID=promtail
export LOKI_URL=...
go test -v -run TestWithWasp
```
See both [generator](client_wasp_test.go) and [test](client_wasp_test.go) implementation example

Check your results [here](https://grafana.ops.prod.cldev.sh/d/WaspDebug/waspdebug?orgId=1&from=now-5m&to=now)

Check your results [here](https://grafana.ops.prod.cldev.sh/d/WaspDebug/waspdebug?orgId=1&from=now-5m&to=now)
If you see `key sync timeout`, just increase `ephemeral_addresses_number` to have more load
51 changes: 39 additions & 12 deletions examples_wasp/client_main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
"github.com/smartcontractkit/seth"
ndbc "github.com/smartcontractkit/seth/contracts/bind/debug"
nsdbc "github.com/smartcontractkit/seth/contracts/bind/sub"
network_debug_contract "github.com/smartcontractkit/seth/contracts/bind/debug"
link_token "github.com/smartcontractkit/seth/contracts/bind/link"
network_sub_contract "github.com/smartcontractkit/seth/contracts/bind/sub"
)

func init() {
Expand All @@ -21,17 +23,18 @@ var (

type TestEnvironment struct {
Client *seth.Client
DebugContract *ndbc.NetworkDebugContract
DebugSubContract *nsdbc.NetworkDebugSubContract
DebugContract *network_debug_contract.NetworkDebugContract
DebugSubContract *network_sub_contract.NetworkDebugSubContract
LinkTokenContract *link_token.LinkToken
DebugContractAddress common.Address
DebugSubContractAddress common.Address
DebugContractRaw *bind.BoundContract
ContractMap map[string]string
ContractMap seth.ContractMap
}

func NewDebugContractSetup() (
*seth.Client,
*ndbc.NetworkDebugContract,
*network_debug_contract.NetworkDebugContract,
common.Address,
common.Address,
*bind.BoundContract,
Expand All @@ -49,15 +52,20 @@ func NewDebugContractSetup() (
if err != nil {
return nil, nil, common.Address{}, common.Address{}, nil, err
}
contractMap := make(map[string]string)
contractMap := seth.NewEmptyContractMap()

abiFinder := seth.NewABIFinder(contractMap, cs)
tracer, err := seth.NewTracer(cfg.Network.URLs[0], cs, &abiFinder, cfg, contractMap, addrs)
if err != nil {
return nil, nil, common.Address{}, common.Address{}, nil, err
}

c, err := seth.NewClientRaw(cfg, addrs, pkeys, seth.WithContractStore(cs), seth.WithTracer(tracer))
nm, err := seth.NewNonceManager(cfg, addrs, pkeys)
if err != nil {
return nil, nil, common.Address{}, common.Address{}, nil, errors.Wrap(err, seth.ErrCreateNonceManager)
}

c, err := seth.NewClientRaw(cfg, addrs, pkeys, seth.WithContractStore(cs), seth.WithTracer(tracer), seth.WithNonceManager(nm))
if err != nil {
return nil, nil, common.Address{}, common.Address{}, nil, err
}
Expand All @@ -69,7 +77,7 @@ func NewDebugContractSetup() (
if err != nil {
return nil, nil, common.Address{}, common.Address{}, nil, err
}
contract, err := ndbc.NewNetworkDebugContract(data.Address, c.Client)
contract, err := network_debug_contract.NewNetworkDebugContract(data.Address, c.Client)
if err != nil {
return nil, nil, common.Address{}, common.Address{}, nil, err
}
Expand All @@ -83,14 +91,33 @@ func TestMain(m *testing.M) {
panic(err)
}

contractMap := make(map[string]string)
for k, v := range client.ContractAddressToNameMap {
contractMap[k] = v
linkTokenAbi, err := link_token.LinkTokenMetaData.GetAbi()
if err != nil {
panic(err)
}
linkDeploymentData, err := client.DeployContract(client.NewTXOpts(), "LinkToken", *linkTokenAbi, common.FromHex(link_token.LinkTokenMetaData.Bin))
if err != nil {
panic(err)
}
linkToken, err := link_token.NewLinkToken(linkDeploymentData.Address, client.Client)
if err != nil {
panic(err)
}
linkAbi, err := link_token.LinkTokenMetaData.GetAbi()
if err != nil {
panic(err)
}
client.ContractStore.AddABI("LinkToken", *linkAbi)

contractMap := seth.NewEmptyContractMap()
for k, v := range client.ContractAddressToNameMap.GetContractMap() {
contractMap.AddContract(k, v)
}

TestEnv = TestEnvironment{
Client: client,
DebugContract: debugContract,
LinkTokenContract: linkToken,
DebugContractAddress: debugContractAddress,
DebugSubContractAddress: debugSubContractAddress,
DebugContractRaw: debugContractRaw,
Expand Down
6 changes: 1 addition & 5 deletions examples_wasp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ toolchain go1.21.6

require (
github.com/ethereum/go-ethereum v1.12.2
github.com/pkg/errors v0.9.1
github.com/smartcontractkit/seth v1.0.9
github.com/smartcontractkit/wasp v0.4.7-0.20240328221214-00cd8313cfd4
github.com/stretchr/testify v1.8.4
Expand Down Expand Up @@ -37,7 +38,6 @@ require (
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
Expand Down Expand Up @@ -138,7 +138,6 @@ require (
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/alertmanager v0.26.0 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
Expand All @@ -149,7 +148,6 @@ require (
github.com/prometheus/procfs v0.12.0 // indirect
github.com/prometheus/prometheus v0.47.2-0.20231010075449-4b9c19fe5510 // indirect
github.com/rs/zerolog v1.30.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/sercand/kuberesolver/v5 v5.1.1 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
Expand All @@ -166,8 +164,6 @@ require (
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/urfave/cli/v2 v2.25.7 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.etcd.io/etcd/api/v3 v3.5.7 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.7 // indirect
go.etcd.io/etcd/client/v3 v3.5.7 // indirect
Expand Down

0 comments on commit d9b5017

Please sign in to comment.