-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create test for SubscribeToNewPubkeyRegistrations
- Loading branch information
1 parent
04449ff
commit 2828d04
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package avsregistry_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/Layr-Labs/eigensdk-go/crypto/bls" | ||
"github.com/Layr-Labs/eigensdk-go/testutils" | ||
"github.com/Layr-Labs/eigensdk-go/testutils/testclients" | ||
"github.com/Layr-Labs/eigensdk-go/types" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSubscriberAvsRegistry(t *testing.T) { | ||
client, _ := testclients.BuildTestClients(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") | ||
} | ||
} |