diff --git a/chainio/clients/avsregistry/subscriber_test.go b/chainio/clients/avsregistry/subscriber_test.go index 87809bf4..464940ec 100644 --- a/chainio/clients/avsregistry/subscriber_test.go +++ b/chainio/clients/avsregistry/subscriber_test.go @@ -19,36 +19,58 @@ func TestSubscriberAvsRegistry(t *testing.T) { chainSubscriber := client.AvsRegistryChainSubscriber chainWriter := client.AvsRegistryChainWriter - pubKeyRegistrations, event, err := chainSubscriber.SubscribeToNewPubkeyRegistrations() - defer event.Unsubscribe() - require.NoError(t, err) - - // Emit a NewPubkeyRegistration event creating a new operator - keypair, err := bls.NewKeyPairFromString("0x01") - require.NoError(t, err, "Failed to create BLS key pair") - - ecdsaPrivateKey, err := crypto.HexToECDSA(testutils.ANVIL_FIRST_PRIVATE_KEY) - require.NoError(t, err, "Failed to parse ECDSA private key") - - quorumNumbers := types.QuorumNums{0} - - receipt, err := chainWriter.RegisterOperator( - context.Background(), - ecdsaPrivateKey, - keypair, - quorumNumbers, - "", - true, - ) - require.NoError(t, err) - require.NotNil(t, receipt) - - select { - case newPubkeyRegistration := <-pubKeyRegistrations: - expectedOperator := crypto.PubkeyToAddress(ecdsaPrivateKey.PublicKey) - assert.Equal(t, expectedOperator, newPubkeyRegistration.Operator) - case <-time.After(10 * time.Second): - // Throw an error if the event is not received within 10 seconds, making the test fail - t.Fatal("Timed out waiting for NewPubkeyRegistration event") - } + t.Run("subscribe to new pubkey registrations", func(t *testing.T) { + pubKeyRegistrationsC, event, err := chainSubscriber.SubscribeToNewPubkeyRegistrations() + defer event.Unsubscribe() + require.NoError(t, err) + + // Emit a NewPubkeyRegistration event creating a new operator + keypair, err := bls.NewKeyPairFromString("0x01") + require.NoError(t, err, "Failed to create BLS key pair") + + ecdsaPrivateKey, err := crypto.HexToECDSA(testutils.ANVIL_FIRST_PRIVATE_KEY) + require.NoError(t, err, "Failed to parse ECDSA private key") + + quorumNumbers := types.QuorumNums{0} + + receipt, err := chainWriter.RegisterOperator( + context.Background(), + ecdsaPrivateKey, + keypair, + quorumNumbers, + "", + true, + ) + require.NoError(t, err) + require.NotNil(t, receipt) + + select { + case newPubkeyRegistration := <-pubKeyRegistrationsC: + expectedOperator := crypto.PubkeyToAddress(ecdsaPrivateKey.PublicKey) + assert.Equal(t, expectedOperator, newPubkeyRegistration.Operator) + case <-time.After(10 * time.Second): + // Throw an error if the event is not received within 10 seconds, making the test fail + t.Fatal("Timed out waiting for NewPubkeyRegistration event") + } + }) + + t.Run("subscribe to operator socket updates", func(t *testing.T) { + socketC, event, err := chainSubscriber.SubscribeToOperatorSocketUpdates() + defer event.Unsubscribe() + require.NoError(t, err) + + // Emit a SocketUpdate event + socketUpdate := "socket-update" + receipt, err := chainWriter.UpdateSocket(context.Background(), types.Socket(socketUpdate), true) + require.NoError(t, err) + require.NotNil(t, receipt) + + select { + case operatorSocketUpdate := <-socketC: + assert.Equal(t, socketUpdate, operatorSocketUpdate.Socket) + case <-time.After(10 * time.Second): + // Throw an error if the event is not received within 10 seconds, making the test fail + t.Fatal("Timed out waiting for NewPubkeyRegistration event") + } + }) }