Skip to content

Commit

Permalink
Add mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
mooselumph committed Oct 14, 2024
1 parent b186cb7 commit 10952c6
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
33 changes: 33 additions & 0 deletions chainio/mock/indexer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package mock

import (
"context"

"github.com/Layr-Labs/eigenda/chainio"
"github.com/Layr-Labs/eigenda/chainio/thegraph"
"github.com/stretchr/testify/mock"
)

type MockIndexedChainState struct {
mock.Mock
}

var _ thegraph.IndexedChainState = (*MockIndexedChainState)(nil)

func (m *MockIndexedChainState) GetIndexedOperatorState(ctx context.Context, blockNumber uint, quorums []chainio.QuorumID) (*chainio.IndexedOperatorState, error) {
args := m.Called()
var value *chainio.IndexedOperatorState
if args.Get(0) != nil {
value = args.Get(0).(*chainio.IndexedOperatorState)
}
return value, args.Error(1)
}

func (m *MockIndexedChainState) GetIndexedOperatorInfoByOperatorId(ctx context.Context, operatorId chainio.OperatorID, blockNumber uint32) (*chainio.IndexedOperatorInfo, error) {
args := m.Called()
var value *chainio.IndexedOperatorInfo
if args.Get(0) != nil {
value = args.Get(0).(*chainio.IndexedOperatorInfo)
}
return value, args.Error(1)
}
61 changes: 61 additions & 0 deletions chainio/mock/writer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package mock

import (
"context"
"crypto/ecdsa"
"math/big"

"github.com/Layr-Labs/eigenda/api/grpc/churner"
"github.com/Layr-Labs/eigenda/chainio"
"github.com/Layr-Labs/eigenda/crypto/ecc/bn254"
"github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/mock"
)

type MockWriter struct {
mock.Mock
}

var _ chainio.Writer = (*MockWriter)(nil)

func (t *MockWriter) RegisterOperator(
ctx context.Context,
keypair *bn254.KeyPair,
socket string,
quorumIds []chainio.QuorumID,
operatorEcdsaPrivateKey *ecdsa.PrivateKey,
operatorToAvsRegistrationSigSalt [32]byte,
operatorToAvsRegistrationSigExpiry *big.Int,
) error {
args := t.Called(ctx, keypair, socket, quorumIds, operatorEcdsaPrivateKey, operatorToAvsRegistrationSigSalt, operatorToAvsRegistrationSigExpiry)
return args.Error(0)
}

func (t *MockWriter) RegisterOperatorWithChurn(
ctx context.Context,
keypair *bn254.KeyPair,
socket string,
quorumIds []chainio.QuorumID,
operatorEcdsaPrivateKey *ecdsa.PrivateKey,
operatorToAvsRegistrationSigSalt [32]byte,
operatorToAvsRegistrationSigExpiry *big.Int,
churnReply *churner.ChurnReply) error {
args := t.Called(ctx, keypair, socket, quorumIds, operatorEcdsaPrivateKey, operatorToAvsRegistrationSigSalt, operatorToAvsRegistrationSigExpiry, churnReply)
return args.Error(0)
}

func (t *MockWriter) DeregisterOperator(ctx context.Context, pubkeyG1 *bn254.G1Point, blockNumber uint32, quorumIds []chainio.QuorumID) error {
args := t.Called()
return args.Error(0)
}

func (t *MockWriter) UpdateOperatorSocket(ctx context.Context, socket string) error {
args := t.Called()
return args.Error(0)
}

func (t *MockWriter) BuildEjectOperatorsTxn(ctx context.Context, operatorsByQuorum [][]chainio.OperatorID) (*types.Transaction, error) {
args := t.Called(ctx, operatorsByQuorum)
result := args.Get(0)
return result.(*types.Transaction), args.Error(1)
}

0 comments on commit 10952c6

Please sign in to comment.