-
Notifications
You must be signed in to change notification settings - Fork 266
feat(E2E): Enable e2e tests to run in different networks based on chain spec #2403
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
base: main
Are you sure you want to change the base?
Changes from all commits
3808991
15bfac1
643ffae
4ba3644
d2def49
8bfed47
254d89d
677b51f
1f9adde
9feafa5
2b6134e
d005c9b
eb07614
4a4a418
1ffbefb
1476986
d1a874b
b73614d
707e861
f0f9fdc
a5a0c1d
b5dea33
a25bf87
d101890
4d87fe3
08c0477
77c28f6
cf72d88
a555d92
d565753
6cb00a4
66efca7
eeb6568
1449a87
c3090f5
e3f44dc
24f4e76
2a864a4
4cb5fa5
e494d75
3237b69
98a95e4
750123f
b7f3471
4c32ee5
5440398
cf12e3d
c505cbf
2de566c
a6c36a2
8c68d2a
9c610cb
07cff99
4c0dbf6
c6d8cd2
147785d
560e1c5
aa5514f
3730fa9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,15 +27,31 @@ This will automatically build your beacond docker image from the local source | |
| code, and spin up a Kurtosis network based on the config file in | ||
| `testing/e2e/config/defaults.go`. | ||
|
|
||
| Currently, the e2e tests runs in different kurtosis enclaves. Check the default configuration in `TestBeaconKitE2ESuite()`. | ||
| Play around with the configuration to see how it works. You need to pass the chain ID and chain spec name to the `suite.WithChain()` function. Ensure that the chain ID and chain spec name are valid. | ||
|
|
||
|
|
||
| ## Configuration | ||
| In case you want to configure(change) the validator set, consider doing changes in `defaultValidators`. | ||
| The user can specify the number of replicas they want per type. | ||
|
|
||
| All the default configuration are listed in `testing/e2e/config/defaults.go` | ||
|
|
||
| Note: Currently the chainID for this local network is 80087, which is our dev network configuration (this is fixed in the kurtosis env setup and will be made configurable in a future version). To make changes to the 80087 chain spec used, modify parameters [here](https://github.com/berachain/beacon-kit/blob/main/config/spec/devnet.go#L40). | ||
| Note: The default chainID for this local network is 80087, which is our dev network configuration. To make changes to the 80087 chain spec used, modify parameters [here](https://github.com/berachain/beacon-kit/blob/main/config/spec/devnet.go#L40). | ||
|
|
||
| ## Configure the default network configuration | ||
| To change the chainID, modify the `ChainID` field in the `NetworkConfiguration` struct in `defaultNetworkConfiguration` | ||
| function in `testing/e2e/config/defaults.go`. | ||
|
|
||
| To change the chainSpec, modify the `ChainSpec` field in the `NetworkConfiguration` struct in `defaultNetworkConfiguration` | ||
| function in `testing/e2e/config/defaults.go`. | ||
|
|
||
| ## Add your tests | ||
| Add your tests in here like how it is done in `TestBasicStartup()` | ||
| To add your tests, you need to do the following: | ||
| 1. Create a new file in the `testing/e2e/` directory. | ||
| 2. Add your tests in here like how it is done in `runBasicStartup()` | ||
| 3. Register your tests in `TestRunE2E()`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any way we can avoid this registration?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idea: #2403 (review) |
||
| 4. Then specify the chainID and chainSpec in `SetupSuiteWithOptions()` in `e2e_test.go`. | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,16 @@ const ( | |
| ClientValidator4 = "cl-validator-beaconkit-4" | ||
| ) | ||
|
|
||
| // default network configuration. | ||
| // | ||
| //nolint:gochecknoglobals // it's a default value | ||
| var ( | ||
| // defaultChainID is the default chain ID for the network. | ||
| defaultChainID = 80087 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these be |
||
| // defaultChainSpec is the default chain spec for the network. | ||
| defaultChainSpec = "devnet" | ||
| ) | ||
|
|
||
| // DefaultE2ETestConfig provides a default configuration for end-to-end tests, | ||
| // pre-populating with a standard set of validators and no additional | ||
| // services. | ||
|
|
@@ -50,6 +60,8 @@ func DefaultE2ETestConfig() *E2ETestConfig { | |
|
|
||
| func defaultNetworkConfiguration() NetworkConfiguration { | ||
| return NetworkConfiguration{ | ||
| ChainID: defaultChainID, | ||
| ChainSpec: defaultChainSpec, | ||
| Validators: defaultValidators(), | ||
| FullNodes: defaultFullNodes(), | ||
| SeedNodes: defaultSeedNodes(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,7 +57,11 @@ type ValidatorTestStruct struct { | |
| // TODO: | ||
| // 1) Add staking tests for adding a new validator to the network. | ||
| // 2) Add staking tests for hitting the validator set cap and eviction. | ||
| func (s *BeaconKitE2ESuite) TestDepositRobustness() { | ||
| func (s *BeaconKitE2ESuite) runDepositRobustness() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems unintuitive to have tests not be named as such - affects readability
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also my IDE doesn't let me run this test individually now |
||
| s.Logger().Info("Running Deposit Robustness") | ||
| // Get the current network | ||
| network := s.GetCurrentNetwork() | ||
| s.Require().NotNil(network, "Network instance is nil") | ||
| // TODO: make test use configurable chain spec. | ||
| chainspec, err := spec.DevnetChainSpec() | ||
| s.Require().NoError(err) | ||
|
|
@@ -80,7 +84,7 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { | |
| ) | ||
|
|
||
| // Get the chain ID. | ||
| chainID, err := s.JSONRPCBalancer().ChainID(s.Ctx()) | ||
| chainID, err := network.JSONRPCBalancer().ChainID(s.Ctx()) | ||
| s.Require().NoError(err) | ||
|
|
||
| // Get the chain spec used by the e2e nodes. TODO: make configurable. | ||
|
|
@@ -90,7 +94,7 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { | |
| // Bind the deposit contract. | ||
| depositContractAddress := gethcommon.Address(chainSpec.DepositContractAddress()) | ||
|
|
||
| dc, err := deposit.NewDepositContract(depositContractAddress, s.JSONRPCBalancer()) | ||
| dc, err := deposit.NewDepositContract(depositContractAddress, network.JSONRPCBalancer()) | ||
| s.Require().NoError(err) | ||
|
|
||
| // Enforce the deposit count at genesis is equal to the number of validators. | ||
|
|
@@ -139,7 +143,7 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { | |
| s.Require().NotNil(val.Validator) | ||
| creds := [32]byte(val.Validator.WithdrawalCredentials) | ||
| withdrawalAddress := gethcommon.Address(creds[12:]) | ||
| withdrawalBalance, jErr := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress, nil) | ||
| withdrawalBalance, jErr := network.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress, nil) | ||
| s.Require().NoError(jErr) | ||
|
|
||
| // Populate the validators testing struct so we can keep track of the pre-state. | ||
|
|
@@ -155,24 +159,27 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { | |
| } | ||
|
|
||
| // Sender account | ||
| sender := s.TestAccounts()[0] | ||
| accounts := s.GetAccounts() | ||
| s.Require().NotNil(accounts, "Test accounts are nil") | ||
| s.Require().NotEmpty(accounts, "No test accounts available") | ||
|
|
||
| sender := accounts[0] | ||
|
|
||
| // Get the block num | ||
| blkNum, err := s.JSONRPCBalancer().BlockNumber(s.Ctx()) | ||
| blkNum, err := network.JSONRPCBalancer().BlockNumber(s.Ctx()) | ||
| s.Require().NoError(err) | ||
|
|
||
| // Get original evm balance | ||
| balance, err := s.JSONRPCBalancer().BalanceAt( | ||
| balance, err := network.JSONRPCBalancer().BalanceAt( | ||
| s.Ctx(), sender.Address(), new(big.Int).SetUint64(blkNum), | ||
| ) | ||
| s.Require().NoError(err) | ||
|
|
||
| // Get the nonce. | ||
| nonce, err := s.JSONRPCBalancer().NonceAt( | ||
| nonce, err := network.JSONRPCBalancer().NonceAt( | ||
| s.Ctx(), sender.Address(), new(big.Int).SetUint64(blkNum), | ||
| ) | ||
| s.Require().NoError(err) | ||
|
|
||
| var ( | ||
| tx *coretypes.Transaction | ||
| clientPubkey []byte | ||
|
|
@@ -214,13 +221,13 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { | |
| "Waiting for the final deposit tx to be mined", | ||
| "num", NumDepositsLoad, "hash", tx.Hash().Hex(), | ||
| ) | ||
| receipt, err := bind.WaitMined(s.Ctx(), s.JSONRPCBalancer(), tx) | ||
| receipt, err := bind.WaitMined(s.Ctx(), network.JSONRPCBalancer(), tx) | ||
| s.Require().NoError(err) | ||
| s.Require().Equal(coretypes.ReceiptStatusSuccessful, receipt.Status) | ||
| s.Logger().Info("Final deposit tx mined successfully", "hash", receipt.TxHash.Hex()) | ||
|
|
||
| // Give time for the nodes to catch up. | ||
| err = s.WaitForNBlockNumbers(NumDepositsLoad / chainspec.MaxDepositsPerBlock()) | ||
| err = s.WaitForNBlockNumbers(network, NumDepositsLoad/chainspec.MaxDepositsPerBlock()) | ||
| s.Require().NoError(err) | ||
|
|
||
| // Compare height of nodes 0 and 1 | ||
|
|
@@ -231,7 +238,7 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { | |
| s.Require().InDelta(height.Response.LastBlockHeight, height2.Response.LastBlockHeight, 1) | ||
|
|
||
| // Check to see if evm balance decreased. | ||
| postDepositBalance, err := s.JSONRPCBalancer().BalanceAt(s.Ctx(), sender.Address(), nil) | ||
| postDepositBalance, err := network.JSONRPCBalancer().BalanceAt(s.Ctx(), sender.Address(), nil) | ||
| s.Require().NoError(err) | ||
|
|
||
| // Check that the eth spent is somewhere~ (gas) between | ||
|
|
@@ -246,11 +253,11 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { | |
| // Check that all validators' voting power have increased by | ||
| // (NumDepositsLoad / NumValidators) * depositAmountWei | ||
| // after the end of the epoch (next multiple of SlotsPerEpoch after receipt.BlockNumber). | ||
| blkNum, err = s.JSONRPCBalancer().BlockNumber(s.Ctx()) | ||
| blkNum, err = network.JSONRPCBalancer().BlockNumber(s.Ctx()) | ||
| s.Require().NoError(err) | ||
| nextEpoch := chainspec.SlotToEpoch(math.Slot(blkNum)) + 1 | ||
| nextEpochBlockNum := nextEpoch.Unwrap() * chainspec.SlotsPerEpoch() | ||
| err = s.WaitForFinalizedBlockNumber(nextEpochBlockNum + 1) | ||
| err = s.WaitForFinalizedBlockNumber(network, nextEpochBlockNum+1) | ||
| s.Require().NoError(err) | ||
|
|
||
| increaseAmt := new(big.Int).Mul(depositAmountGwei, big.NewInt(int64(NumDepositsLoad/config.NumValidators))) | ||
|
|
@@ -264,7 +271,7 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() { | |
|
|
||
| // withdrawal balance is in Wei, so we'll convert it to Gwei. | ||
| withdrawalAddress := gethcommon.Address(val.WithdrawalCredentials[12:]) | ||
| withdrawalBalanceAfter, jErr := s.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress, nil) | ||
| withdrawalBalanceAfter, jErr := network.JSONRPCBalancer().BalanceAt(s.Ctx(), withdrawalAddress, nil) | ||
| s.Require().NoError(jErr) | ||
| withdrawalDiff := new(big.Int).Sub(withdrawalBalanceAfter, val.WithdrawalBalance) | ||
| withdrawalDiff.Div(withdrawalDiff, weiPerGwei) | ||
|
|
||
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.
Given that we default to
mainnetchain spec in beacond - feels unintuitive to have the default for tests bedevnet. Perhaps worth renaming