-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
validate onchain operator ID against local operator ID
- Loading branch information
Showing
7 changed files
with
194 additions
and
9 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
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
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
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
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
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,155 @@ | ||
package node_test | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"os" | ||
"runtime" | ||
"testing" | ||
"time" | ||
|
||
"github.com/Layr-Labs/eigenda/common" | ||
"github.com/Layr-Labs/eigenda/common/geth" | ||
"github.com/Layr-Labs/eigenda/core" | ||
coremock "github.com/Layr-Labs/eigenda/core/mock" | ||
"github.com/Layr-Labs/eigenda/node" | ||
gethcommon "github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
var privateKey = "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" | ||
var opID = [32]byte{} | ||
|
||
type components struct { | ||
node *node.Node | ||
tx *coremock.MockTransactor | ||
} | ||
|
||
func newComponents(t *testing.T) *components { | ||
dbPath := t.TempDir() | ||
keyPair, err := core.GenRandomBlsKeys() | ||
if err != nil { | ||
panic("failed to create a BLS Key") | ||
} | ||
copy(opID[:], []byte(fmt.Sprintf("%d", 3))) | ||
config := &node.Config{ | ||
Timeout: 10 * time.Second, | ||
ExpirationPollIntervalSec: 1, | ||
QuorumIDList: []core.QuorumID{0}, | ||
DbPath: dbPath, | ||
ID: opID, | ||
NumBatchValidators: runtime.GOMAXPROCS(0), | ||
EnableNodeApi: false, | ||
EnableMetrics: false, | ||
RegisterNodeAtStart: false, | ||
} | ||
loggerConfig := common.DefaultLoggerConfig() | ||
logger, err := common.NewLogger(loggerConfig) | ||
if err != nil { | ||
panic("failed to create a logger") | ||
} | ||
|
||
err = os.MkdirAll(config.DbPath, os.ModePerm) | ||
if err != nil { | ||
panic("failed to create a directory for db") | ||
} | ||
tx := &coremock.MockTransactor{} | ||
|
||
mockVal := coremock.NewMockShardValidator() | ||
mockVal.On("ValidateBlob", mock.Anything, mock.Anything).Return(nil) | ||
mockVal.On("ValidateBatch", mock.Anything, mock.Anything, mock.Anything).Return(nil) | ||
|
||
chainState, _ := coremock.MakeChainDataMock(map[uint8]int{ | ||
0: 4, | ||
1: 4, | ||
2: 4, | ||
}) | ||
|
||
store, err := node.NewLevelDBStore(dbPath, logger, nil, 1e9, 1e9) | ||
if err != nil { | ||
panic("failed to create a new levelDB store") | ||
} | ||
defer os.Remove(dbPath) | ||
|
||
return &components{ | ||
node: &node.Node{ | ||
Config: config, | ||
Logger: logger, | ||
KeyPair: keyPair, | ||
Metrics: nil, | ||
Store: store, | ||
ChainState: chainState, | ||
Validator: mockVal, | ||
Transactor: tx, | ||
}, | ||
tx: tx, | ||
} | ||
} | ||
|
||
func TestNodeStartNoAddress(t *testing.T) { | ||
c := newComponents(t) | ||
c.node.Config.RegisterNodeAtStart = false | ||
|
||
c.tx.On("OperatorIDToAddress", mock.Anything).Return(gethcommon.HexToAddress("0x1"), nil) | ||
|
||
err := c.node.Start(context.Background()) | ||
assert.NoError(t, err) | ||
} | ||
|
||
func TestNodeStartNoAddressNotRegistered(t *testing.T) { | ||
c := newComponents(t) | ||
c.node.Config.RegisterNodeAtStart = false | ||
|
||
c.tx.On("OperatorIDToAddress", mock.Anything).Return(gethcommon.Address{0}, errors.New("execution reverted")) | ||
|
||
err := c.node.Start(context.Background()) | ||
assert.Error(t, err) | ||
} | ||
|
||
func TestNodeStartOperatorIDMatch(t *testing.T) { | ||
c := newComponents(t) | ||
c.node.Config.RegisterNodeAtStart = true | ||
c.node.Config.EthClientConfig = geth.EthClientConfig{ | ||
RPCURLs: []string{"http://localhost:8545"}, | ||
PrivateKeyString: privateKey, | ||
NumConfirmations: 1, | ||
} | ||
c.tx.On("GetRegisteredQuorumIdsForOperator", mock.Anything).Return([]core.QuorumID{}, nil) | ||
c.tx.On("GetOperatorSetParams", mock.Anything, mock.Anything).Return(&core.OperatorSetParam{ | ||
MaxOperatorCount: uint32(4), | ||
ChurnBIPsOfOperatorStake: uint16(1000), | ||
ChurnBIPsOfTotalStake: uint16(10), | ||
}, nil) | ||
c.tx.On("GetNumberOfRegisteredOperatorForQuorum", mock.Anything, mock.Anything).Return(uint32(0), nil) | ||
c.tx.On("RegisterOperator", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) | ||
|
||
c.tx.On("OperatorAddressToID", mock.Anything).Return(core.OperatorID(opID), nil) | ||
|
||
err := c.node.Start(context.Background()) | ||
assert.NoError(t, err) | ||
} | ||
|
||
func TestNodeStartOperatorIDDoesNotMatch(t *testing.T) { | ||
c := newComponents(t) | ||
c.node.Config.RegisterNodeAtStart = true | ||
c.node.Config.EthClientConfig = geth.EthClientConfig{ | ||
RPCURLs: []string{"http://localhost:8545"}, | ||
PrivateKeyString: privateKey, | ||
NumConfirmations: 1, | ||
} | ||
c.tx.On("GetRegisteredQuorumIdsForOperator", mock.Anything).Return([]core.QuorumID{}, nil) | ||
c.tx.On("GetOperatorSetParams", mock.Anything, mock.Anything).Return(&core.OperatorSetParam{ | ||
MaxOperatorCount: uint32(4), | ||
ChurnBIPsOfOperatorStake: uint16(1000), | ||
ChurnBIPsOfTotalStake: uint16(10), | ||
}, nil) | ||
c.tx.On("GetNumberOfRegisteredOperatorForQuorum", mock.Anything, mock.Anything).Return(uint32(0), nil) | ||
c.tx.On("RegisterOperator", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) | ||
|
||
c.tx.On("OperatorAddressToID", mock.Anything).Return(core.OperatorID{1}, nil) | ||
|
||
err := c.node.Start(context.Background()) | ||
assert.ErrorContains(t, err, "operator ID mismatch") | ||
} |
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