Skip to content

Commit

Permalink
replace panics
Browse files Browse the repository at this point in the history
  • Loading branch information
afkbyte committed Jan 9, 2025
1 parent 96a4793 commit 6fbfcd4
Showing 1 changed file with 32 additions and 96 deletions.
128 changes: 32 additions & 96 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,40 +365,28 @@ type AvsSyncComponents struct {

func NewAvsSyncComponents(t *testing.T, anvilHttpEndpoint string, contractAddresses ContractAddresses, operators []common.Address, syncInterval time.Duration) *AvsSyncComponents {
logger, err := logging.NewZapLogger(logging.Development)
if err != nil {
panic(err)
}
require.NoError(t, err)
ecdsaPrivKey, err := crypto.HexToECDSA("ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80")
if err != nil {
panic(err)
}
require.NoError(t, err)
ecdsaAddr := crypto.PubkeyToAddress(ecdsaPrivKey.PublicKey)

reg := prometheus.NewRegistry()
rpcCollector := rpccalls.NewCollector("", reg)

ethInstrumentedHttpClient, err := eth.NewInstrumentedClient(anvilHttpEndpoint, rpcCollector)
if err != nil {
panic(err)
}
require.NoError(t, err)

rpcCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
chainid, err := ethInstrumentedHttpClient.ChainID(rpcCtx)
if err != nil {
panic(err)
}
require.NoError(t, err)
// confusing interface, see https://github.com/Layr-Labs/eigensdk-go/issues/90
signerFn, _, err := signerv2.SignerFromConfig(signerv2.Config{
PrivateKey: ecdsaPrivKey,
}, chainid)
if err != nil {
panic(err)
}
require.NoError(t, err)
wallet, err := walletsdk.NewPrivateKeyWallet(ethInstrumentedHttpClient, signerFn, ecdsaAddr, logger)
if err != nil {
panic(err)
}
require.NoError(t, err)

txMgr := txmgr.NewSimpleTxManager(wallet, ethInstrumentedHttpClient, logger, ecdsaAddr)

Expand All @@ -409,9 +397,7 @@ func NewAvsSyncComponents(t *testing.T, anvilHttpEndpoint string, contractAddres
ethInstrumentedHttpClient,
txMgr,
)
if err != nil {
panic(err)
}
require.NoError(t, err)
avsReader, err := avsregistry.BuildAvsRegistryChainReader(
contractAddresses.RegistryCoordinator,
contractAddresses.OperatorStateRetriever,
Expand Down Expand Up @@ -448,9 +434,7 @@ func NewAvsSyncComponents(t *testing.T, anvilHttpEndpoint string, contractAddres

func startAnvilTestContainer(additionalFlags ...string) testcontainers.Container {
integrationDir, err := os.Getwd()
if err != nil {
panic(err)
}
require.NoError(t, err)

Check failure on line 437 in integration_test.go

View workflow job for this annotation

GitHub Actions / Run Tests

undefined: t

cmdArgs := []string{
"--host", "0.0.0.0",
Expand Down Expand Up @@ -479,9 +463,7 @@ func startAnvilTestContainer(additionalFlags ...string) testcontainers.Container
ContainerRequest: req,
Started: true,
})
if err != nil {
panic(err)
}
require.NoError(t, err)

Check failure on line 466 in integration_test.go

View workflow job for this annotation

GitHub Actions / Run Tests

undefined: t

// this is needed temporarily because anvil restarts at 0 block when we load a state...
// see comment in start-anvil-chain-with-el-and-avs-deployed.sh
Expand All @@ -494,9 +476,7 @@ func startAnvilTestContainer(additionalFlags ...string) testcontainers.Container

func advanceChainByNBlocks(n int, anvilC testcontainers.Container) {
anvilEndpoint, err := anvilC.Endpoint(context.Background(), "")
if err != nil {
panic(err)
}
require.NoError(t, err)

Check failure on line 479 in integration_test.go

View workflow job for this annotation

GitHub Actions / Run Tests

undefined: t
rpcUrl := "http://" + anvilEndpoint
// this is just the first anvil address, which is funded so can send ether
// we just send a transaction to ourselves to advance the chain
Expand All @@ -506,31 +486,21 @@ func advanceChainByNBlocks(n int, anvilC testcontainers.Container) {
n, rpcUrl),
)
err = cmd.Run()
if err != nil {
panic(err)
}
require.NoError(t, err)

Check failure on line 489 in integration_test.go

View workflow job for this annotation

GitHub Actions / Run Tests

undefined: t
}

// TODO(samlaf): move this function to eigensdk
func registerOperatorWithAvs(wallet walletsdk.Wallet, ethHttpUrl string, contractAddresses ContractAddresses, ecdsaPrivKeyHex string, blsPrivKeyHex string, waitForMine bool) {
ethHttpClient, err := ethclient.Dial(ethHttpUrl)
if err != nil {
panic(err)
}
require.NoError(t, err)

Check failure on line 495 in integration_test.go

View workflow job for this annotation

GitHub Actions / Run Tests

undefined: t
blsKeyPair, err := bls.NewKeyPairFromString(blsPrivKeyHex)
if err != nil {
panic(err)
}
require.NoError(t, err)

Check failure on line 497 in integration_test.go

View workflow job for this annotation

GitHub Actions / Run Tests

undefined: t
ecdsaPrivKey, err := crypto.HexToECDSA(ecdsaPrivKeyHex)
if err != nil {
panic(err)
}
require.NoError(t, err)

Check failure on line 499 in integration_test.go

View workflow job for this annotation

GitHub Actions / Run Tests

undefined: t
ecdsaAddr := crypto.PubkeyToAddress(ecdsaPrivKey.PublicKey)

logger, err := logging.NewZapLogger(logging.Development)
if err != nil {
panic(err)
}
require.NoError(t, err)

Check failure on line 503 in integration_test.go

View workflow job for this annotation

GitHub Actions / Run Tests

undefined: t
txMgr := txmgr.NewSimpleTxManager(wallet, ethHttpClient, logger, ecdsaAddr)

avsWriter, err := avsregistry.BuildAvsRegistryChainWriter(
Expand All @@ -540,31 +510,23 @@ func registerOperatorWithAvs(wallet walletsdk.Wallet, ethHttpUrl string, contrac
ethHttpClient,
txMgr,
)
if err != nil {
panic(err)
}
require.NoError(t, err)

Check failure on line 513 in integration_test.go

View workflow job for this annotation

GitHub Actions / Run Tests

undefined: t

quorumNumbers := []types.QuorumNum{0}
socket := "Not Needed"
operatorToAvsRegistrationSigSalt := [32]byte{123}
curBlockNum, err := ethHttpClient.BlockNumber(context.Background())
if err != nil {
panic(err)
}
require.NoError(t, err)

Check failure on line 519 in integration_test.go

View workflow job for this annotation

GitHub Actions / Run Tests

undefined: t
curBlock, err := ethHttpClient.BlockByNumber(context.Background(), big.NewInt(int64(curBlockNum)))
if err != nil {
panic(err)
}
require.NoError(t, err)
sigValidForSeconds := int64(1_000_000)
operatorToAvsRegistrationSigExpiry := big.NewInt(int64(curBlock.Time()) + sigValidForSeconds)
_, err = avsWriter.RegisterOperatorInQuorumWithAVSRegistryCoordinator(
context.Background(),
ecdsaPrivKey, operatorToAvsRegistrationSigSalt, operatorToAvsRegistrationSigExpiry,
blsKeyPair, quorumNumbers, socket, waitForMine,
)
if err != nil {
panic(err)
}
require.NoError(t, err)
}

// TODO(samlaf): move this function to eigensdk
Expand All @@ -579,19 +541,13 @@ func depositErc20IntoStrategyForOperator(
waitForMined bool,
) {
ethHttpClient, err := ethclient.Dial(ethHttpUrl)
if err != nil {
panic(err)
}
require.NoError(t, err)
ecdsaPrivKey, err := crypto.HexToECDSA(ecdsaPrivKeyHex)
if err != nil {
panic(err)
}
require.NoError(t, err)
ecdsaAddr := crypto.PubkeyToAddress(ecdsaPrivKey.PublicKey)

logger, err := logging.NewZapLogger(logging.Development)
if err != nil {
panic(err)
}
require.NoError(t, err)
noopMetrics := metrics.NewNoopMetrics()

txMgr := txmgr.NewSimpleTxManager(wallet, ethHttpClient, logger, ecdsaAddr)
Expand All @@ -603,44 +559,28 @@ func depositErc20IntoStrategyForOperator(
noopMetrics,
txMgr,
)
if err != nil {
panic(err)
}
require.NoError(t, err)

_, err = elWriter.DepositERC20IntoStrategy(context.Background(), erc20MockStrategyAddr, amount, waitForMined)
if err != nil {
panic(err)
}
require.NoError(t, err)

}

func getContractAddressesFromContractRegistry(ethHttpUrl string) ContractAddresses {
ethHttpClient, err := ethclient.Dial(ethHttpUrl)
if err != nil {
panic(err)
}
require.NoError(t, err)
// The ContractsRegistry contract should always be deployed at this address on anvil
// it's the address of the contract created at nonce 0 by the first anvil account (0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266)
contractsRegistry, err := contractreg.NewContractContractsRegistry(common.HexToAddress("0x5FbDB2315678afecb367f032d93F642f64180aa3"), ethHttpClient)
if err != nil {
panic(err)
}
require.NoError(t, err)
registryCoordinatorAddr, err := contractsRegistry.Contracts(&bind.CallOpts{}, "eigencertRegistryCoordinator")
if err != nil {
panic(err)
}
require.NoError(t, err)
operatorStateRetrieverAddr, err := contractsRegistry.Contracts(&bind.CallOpts{}, "eigencertOperatorStateRetriever")
if err != nil {
panic(err)
}
require.NoError(t, err)
delegationManagerAddr, err := contractsRegistry.Contracts(&bind.CallOpts{}, "delegationManager")
if err != nil {
panic(err)
}
require.NoError(t, err)
erc20MockStrategyAddr, err := contractsRegistry.Contracts(&bind.CallOpts{}, "erc20MockStrategy")
if err != nil {
panic(err)
}
require.NoError(t, err)
return ContractAddresses{
RegistryCoordinator: registryCoordinatorAddr,
OperatorStateRetriever: operatorStateRetrieverAddr,
Expand All @@ -651,9 +591,7 @@ func getContractAddressesFromContractRegistry(ethHttpUrl string) ContractAddress

func createWalletForOperator(t *testing.T, privKeyHex string, ethClient *ethclient.Client) walletsdk.Wallet {
logger, err := logging.NewZapLogger(logging.Development)
if err != nil {
panic(err)
}
require.NoError(t, err)

ecdsaPrivKey, err := crypto.HexToECDSA(privKeyHex)
if err != nil {
Expand All @@ -662,9 +600,7 @@ func createWalletForOperator(t *testing.T, privKeyHex string, ethClient *ethclie
ecdsaAddr := crypto.PubkeyToAddress(ecdsaPrivKey.PublicKey)

chainID, err := ethClient.ChainID(context.Background())
if err != nil {
panic(err)
}
require.NoError(t, err)

signerFn, _, err := signerv2.SignerFromConfig(signerv2.Config{
PrivateKey: ecdsaPrivKey,
Expand Down

0 comments on commit 6fbfcd4

Please sign in to comment.