mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-07 22:54:17 -05:00
* updating the goethereum dependency * fixing dependencies * reverting workspace * more fixes, work in progress * trying with upgraded geth version * fixing deprecated functions except for the time related ones on eth1 distance due to time issues * fixing time issues * gaz * fixing test and upgrading some dependencies and reverting others * Disable cgo in hid, delete old vendored usb library * changelog * rolling back dependencies * fixing go mod tidy * Geth v1.13.6 * fix tests * Add ping interval, set to 500ms for tests. This didnt work * Update to v1.14.8 * Spread it out to different bootnodes * Fix it * Remove Memsize * Update all out of date dependencies * Fix geth body change * Fix Test * Fix Build * Fix Tests * Fix Tests Again * Fix Tests Again * Fix Tests * Fix Test * Copy USB Package for HID * Push it up * Finally fix all tests with felix's changes * updating geth dependency * Update go-ethereum to v1.14.11 * fixing import * reverting blob change * fixing Implicit memory aliasing in for loop. * WIP changes * wip getting a little further on e2e runs * getting a little further * getting a little further * setting everything to capella * more partial fixes * more fixes but still WIP * fixing access list transactions" * some cleanup * making configs dynamic * reverting time * skip lower bound in builder * updating to geth v1.14.12 * fixing verify blob to pointer * go mod tidy * fixing linting * missed removing another terminal difficulty item * another missed update * updating more dependencies to fix cicd * fixing holiman dependency update * downgrading geth to 1.14.11 due to p2p loop issue * reverting builder middleware caused by downgrade * fixing more rollback issues * upgrading back to 1.14.12 after discussing with preston * mod tidy * gofmt * partial review feedback * trying to start e2e from bellatrix instead * reverting some changes --------- Co-authored-by: Preston Van Loon <preston@pvl.dev> Co-authored-by: nisdas <nishdas93@gmail.com>
85 lines
3.5 KiB
Go
85 lines
3.5 KiB
Go
package deposit_test
|
|
|
|
import (
|
|
"context"
|
|
"encoding/binary"
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum"
|
|
"github.com/ethereum/go-ethereum/common"
|
|
depositcontract "github.com/prysmaticlabs/prysm/v5/contracts/deposit"
|
|
"github.com/prysmaticlabs/prysm/v5/contracts/deposit/mock"
|
|
"github.com/prysmaticlabs/prysm/v5/runtime/interop"
|
|
"github.com/prysmaticlabs/prysm/v5/testing/assert"
|
|
"github.com/prysmaticlabs/prysm/v5/testing/require"
|
|
)
|
|
|
|
func TestSetupRegistrationContract_OK(t *testing.T) {
|
|
_, err := mock.Setup()
|
|
assert.NoError(t, err, "Can not deploy validator registration contract")
|
|
}
|
|
|
|
// negative test case, deposit with less than 1 ETH which is less than the top off amount.
|
|
func TestRegister_Below1ETH(t *testing.T) {
|
|
testAccount, err := mock.Setup()
|
|
require.NoError(t, err)
|
|
|
|
// Generate deposit data
|
|
privKeys, pubKeys, err := interop.DeterministicallyGenerateKeys(0 /*startIndex*/, 1)
|
|
require.NoError(t, err)
|
|
depositDataItems, depositDataRoots, err := interop.DepositDataFromKeys(privKeys, pubKeys)
|
|
require.NoError(t, err)
|
|
|
|
var depositDataRoot [32]byte
|
|
copy(depositDataRoot[:], depositDataRoots[0])
|
|
testAccount.TxOpts.Value = mock.LessThan1Eth()
|
|
_, err = testAccount.Contract.Deposit(testAccount.TxOpts, pubKeys[0].Marshal(), depositDataItems[0].WithdrawalCredentials, depositDataItems[0].Signature, depositDataRoot)
|
|
assert.ErrorContains(t, "execution reverted", err, "Validator registration should have failed with insufficient deposit")
|
|
}
|
|
|
|
// normal test case, test depositing 32 ETH and verify HashChainValue event is correctly emitted.
|
|
func TestValidatorRegister_OK(t *testing.T) {
|
|
testAccount, err := mock.Setup()
|
|
require.NoError(t, err)
|
|
testAccount.TxOpts.Value = mock.Amount32Eth()
|
|
|
|
// Generate deposit data
|
|
privKeys, pubKeys, err := interop.DeterministicallyGenerateKeys(0 /*startIndex*/, 1)
|
|
require.NoError(t, err)
|
|
depositDataItems, depositDataRoots, err := interop.DepositDataFromKeys(privKeys, pubKeys)
|
|
require.NoError(t, err)
|
|
|
|
var depositDataRoot [32]byte
|
|
copy(depositDataRoot[:], depositDataRoots[0])
|
|
_, err = testAccount.Contract.Deposit(testAccount.TxOpts, pubKeys[0].Marshal(), depositDataItems[0].WithdrawalCredentials, depositDataItems[0].Signature, depositDataRoot)
|
|
testAccount.Backend.Commit()
|
|
require.NoError(t, err, "Validator registration failed")
|
|
_, err = testAccount.Contract.Deposit(testAccount.TxOpts, pubKeys[0].Marshal(), depositDataItems[0].WithdrawalCredentials, depositDataItems[0].Signature, depositDataRoot)
|
|
testAccount.Backend.Commit()
|
|
assert.NoError(t, err, "Validator registration failed")
|
|
_, err = testAccount.Contract.Deposit(testAccount.TxOpts, pubKeys[0].Marshal(), depositDataItems[0].WithdrawalCredentials, depositDataItems[0].Signature, depositDataRoot)
|
|
testAccount.Backend.Commit()
|
|
assert.NoError(t, err, "Validator registration failed")
|
|
|
|
query := ethereum.FilterQuery{
|
|
Addresses: []common.Address{
|
|
testAccount.ContractAddr,
|
|
},
|
|
}
|
|
|
|
logs, err := testAccount.Backend.Client().FilterLogs(context.Background(), query)
|
|
assert.NoError(t, err, "Unable to get logs of deposit contract")
|
|
|
|
merkleTreeIndex := make([]uint64, 5)
|
|
|
|
for i, log := range logs {
|
|
_, _, _, _, idx, err := depositcontract.UnpackDepositLogData(log.Data)
|
|
require.NoError(t, err, "Unable to unpack log data")
|
|
merkleTreeIndex[i] = binary.LittleEndian.Uint64(idx)
|
|
}
|
|
|
|
assert.Equal(t, uint64(0), merkleTreeIndex[0], "Deposit event total deposit count mismatched")
|
|
assert.Equal(t, uint64(1), merkleTreeIndex[1], "Deposit event total deposit count mismatched")
|
|
assert.Equal(t, uint64(2), merkleTreeIndex[2], "Deposit event total deposit count mismatched")
|
|
}
|