-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: convert operation tests into unit tests using simulated backend #118
chore: convert operation tests into unit tests using simulated backend #118
Conversation
testTimelockAddress = os.Getenv("TEST_TIMELOCK_ADDRESS") | ||
testCallProxyAddress = os.Getenv("TEST_PROXY_ADDRESS") | ||
testPrivateKey = os.Getenv("TEST_PRIVATE_KEY") | ||
testNodeURL = "ws://node.url" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we no longer depend on pre-deployed test contracts whose info is unknown to anyone because it's stored as secrets on github
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you are removing env variables here, are these env parameters still needed in GH workflows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, I forgot to remove that! Thanks for the reminder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in the latest commit.
9a60d38
to
f8bbd03
Compare
pkg/timelock/operations_test.go
Outdated
} | ||
// --- assert --- | ||
// create instance of the timelock contract using the legacy geth wrapper | ||
legacyTimelockContract, err := contract.NewTimelock(timelockAddress, backend) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is temporary; we'll get rid of it once PR #119 is merged.
hexAddress string | ||
privateKey *ecdsa.PrivateKey | ||
hexPrivateKey string | ||
Address common.Address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make fields public as we now use this type outside of the integration
package
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type Backend interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this interface provides a small abstraction so that we may use geth's in-memory simulated backend or the rpc client (connected to the testcontainer running h geth in dev mode) interchangeably (and without clunky casts).
simulated.Client | ||
} | ||
|
||
func (b *rpcBackend) Commit() common.Hash { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the Commit
method is not really needed for the rpc backend; the geth service will mine a few block every X seconds.
@@ -0,0 +1,165 @@ | |||
package integration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All onchain operations (deployments and contract calls) are now implemented in this file.
I've also made them independent of the testify
suite instance (which we've used for the integration tests) so that it's easy to reuse the operations in other test files.
transactor, backend, minDelay, adminAccount, proposers, executors, cancellers, bypassers) | ||
require.NoError(t, err) | ||
|
||
backend.Commit() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to explicitly call Commit
before WaitMined
for the in-memory simulated backend to work
f8bbd03
to
3951403
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
3951403
to
e747cff
Compare
branch updated due to conflicts with the develop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, approved but then noticed one small thing.
e747cff
to
a35ce96
Compare
A tests in
operations_test.go
depend on contracts that are pre-deployed on an EVM testnet -- which means one needs be online and know their addresses in order to run the tests in a local development environment.This PR fixes the problem by converting these tests to integration tests. In practice, we're reusing some of the building blocks setup previously for the other set of tests which rely on the geth instance that runs using test containers. But this set of tests relies on geth's simulated backend.