Skip to content
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

Merged

Conversation

gustavogama-cll
Copy link
Contributor

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.

@gustavogama-cll gustavogama-cll requested a review from a team as a code owner November 28, 2024 22:49
@gustavogama-cll gustavogama-cll marked this pull request as draft November 28, 2024 22:49
testTimelockAddress = os.Getenv("TEST_TIMELOCK_ADDRESS")
testCallProxyAddress = os.Getenv("TEST_PROXY_ADDRESS")
testPrivateKey = os.Getenv("TEST_PRIVATE_KEY")
testNodeURL = "ws://node.url"
Copy link
Contributor Author

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

Copy link

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@gustavogama-cll gustavogama-cll force-pushed the chore-convert-operation-tests-into-unit-tests branch 2 times, most recently from 9a60d38 to f8bbd03 Compare November 28, 2024 23:52
@gustavogama-cll gustavogama-cll changed the title fix: convert operation tests into unit tests using simulated backend chore: convert operation tests into unit tests using simulated backend Nov 28, 2024
}
// --- assert ---
// create instance of the timelock contract using the legacy geth wrapper
legacyTimelockContract, err := contract.NewTimelock(timelockAddress, backend)
Copy link
Contributor Author

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
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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
Copy link
Contributor Author

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()
Copy link
Contributor Author

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

@gustavogama-cll gustavogama-cll force-pushed the chore-convert-operation-tests-into-unit-tests branch from f8bbd03 to 3951403 Compare November 29, 2024 00:21
@gustavogama-cll gustavogama-cll marked this pull request as ready for review November 29, 2024 00:24
Copy link

@graham-chainlink graham-chainlink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

@gustavogama-cll
Copy link
Contributor Author

branch updated due to conflicts with the develop

giogam
giogam previously approved these changes Nov 29, 2024
@giogam giogam self-requested a review November 29, 2024 09:47
Copy link

@giogam giogam left a 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.

@gustavogama-cll gustavogama-cll added this pull request to the merge queue Dec 2, 2024
Merged via the queue into develop with commit 2855b16 Dec 2, 2024
5 checks passed
@gustavogama-cll gustavogama-cll deleted the chore-convert-operation-tests-into-unit-tests branch December 2, 2024 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants