Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ethergo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ root
│ ├── <a href="./backends/geth">geth</a>: Contains an embedded geth backend. This is useful for testing against a local geth instance without forking capabilities. This does not require docker and runs fully embedded in the go application, as such it is faster than the docker-based backends, but less versatile. Used when an rpc address is needed for a localnet.
│ ├── <a href="./backends/preset">preset</a>: Contains a number of preset backends for testing.
│ ├── <a href="./backends/simulated">simulated</a>: The fastest backend, this does not expose an rpc endpoint and uses geth's [simulated backend](https://goethereumbook.org/en/client-simulated/)
├── <a href="./chain">chain</a>: Contains a client for interacting with the chain. This will be removed in a future version. Please use [client](./client) going forward.
├── <s><a href="./chain">chain</a>: Contains a client for interacting with the chain. This will be removed in a future version. Please use [client](./client) going forward.
│ ├── <a href="./chain/chainwatcher">chainwatcher</a>: Watches the chain for events, blocks and logs
│ ├── <a href="./chain/client">client</a>: Contains eth clients w/ rate limiting, workarounds for bugs in some chains, etc.
│ ├── <a href="./chain/gas">gas</a>: Contains a deterministic gas estimator
│ ├── <a href="./chain/watcher">watcher</a>: Client interface for chain watcher.
│ ├── <a href="./chain/watcher">watcher</a>: Client interface for chain watcher.</s>
├── <a href="./contracts">contracts</a>: Contains interfaces for using contracts with the deployer + manager
├── <a href="./client">client</a>: Contains an open tracing compatible ethclient with batching.
├── <a href="./example">example</a>: Contains a full featured example of how to use deployer + manager
├── <a href="./forker">forker</a>: Allows the use of fork tests in live chains without docker using an anvil binary.
├── <a href="./listener">listener</a>: Drop-in contract listener
├── <a href="./manager">manager</a>: Manages contract deployments.
├── <a href="./mocks">mocks</a>: Contains mocks for testing various data types (transactions, addresses, logs, etc)
├── <a href="./parser">parser</a>: Parse hardhat deployments
Expand Down
95 changes: 0 additions & 95 deletions ethergo/chain/listener/listener_test.go

This file was deleted.

98 changes: 0 additions & 98 deletions ethergo/chain/listener/suite_test.go

This file was deleted.

72 changes: 72 additions & 0 deletions ethergo/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,77 @@
}
```

4. (Optional): Create a typecast getter:
To avoid naked casts of contract handle, we can potionally create a typecast getter.
To do this, we're going to create a thin wrapper around deploymanager.

```go
package example
import (
"context"
"github.com/synapsecns/sanguine/ethergo/backends"
"github.com/synapsecns/sanguine/ethergo/contracts"
"github.com/synapsecns/sanguine/ethergo/manager"
"testing"
)

// DeployManager wraps DeployManager and allows typed contract handles to be returned.
type DeployManager struct {
*manager.DeployerManager
}

// NewDeployManager creates a new DeployManager.
func NewDeployManager(t *testing.T) *DeployManager {
t.Helper()

parentManager := manager.NewDeployerManager(t, NewCounterDeployer)
return &DeployManager{parentManager}
}
```

Now we can create a handle to get the contract for us;

```go
package example
// see above for imports

import (
"context"
"github.com/synapsecns/sanguine/ethergo/backends"
"github.com/synapsecns/sanguine/ethergo/contracts"
"github.com/synapsecns/sanguine/ethergo/example/counter"
"github.com/synapsecns/sanguine/ethergo/manager"
"testing"
)

// GetCounter gets the pre-created counter.
func (d *DeployManager) GetCounter(ctx context.Context, backend backends.SimulatedTestBackend) (contract contracts.DeployedContract, handle *counter.CounterRef) {
d.T().Helper()

return manager.GetContract[*counter.CounterRef](ctx, d.T(), d, backend, CounterType)
}
```

5. (Optional) Make sure are dependencies are correct: We can also create a test to assert our dependencides are correctly listed in each deployer. That looks like this:

```go
package example_test

import (
"context"
"github.com/synapsecns/sanguine/ethergo/backends"
"github.com/synapsecns/sanguine/ethergo/contracts"
"github.com/synapsecns/sanguine/ethergo/example"
"github.com/synapsecns/sanguine/ethergo/manager"
"testing"
)


func TestDependenciesCorrect(t *testing.T) {
manager.AssertDependenciesCorrect(context.Background(), t, func() manager.IDeployManager {
return example.NewDeployerManager(t)
})
}
```

That's it! You should be done. As you can see, there's a lot more that can be done here. Passing in a list of all your deployers every time doesn't make sense. You'll want to create a standard testutil and extend it. We also haven't covered that any backend here is interchangable: you can use simulated, ganache, or embedded geth. This tutorial should've covered the basics though
Loading