-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Pablo Deymonnaz <[email protected]> Co-authored-by: Pablo Deymonnaz <[email protected]>
- Loading branch information
1 parent
521033d
commit 0264584
Showing
5 changed files
with
333 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package elcontracts_test | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
erc20 "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IERC20" | ||
"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/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestChainReader(t *testing.T) { | ||
clients, anvilHttpEndpoint := testclients.BuildTestClients(t) | ||
|
||
contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) | ||
operator := types.Operator{ | ||
Address: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", | ||
} | ||
|
||
t.Run("is operator registered", func(t *testing.T) { | ||
isOperator, err := clients.ElChainReader.IsOperatorRegistered(&bind.CallOpts{}, operator) | ||
assert.NoError(t, err) | ||
assert.Equal(t, isOperator, true) | ||
}) | ||
|
||
t.Run("get operator details", func(t *testing.T) { | ||
operatorDetails, err := clients.ElChainReader.GetOperatorDetails(&bind.CallOpts{}, operator) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, operatorDetails) | ||
assert.Equal(t, operator.Address, operatorDetails.Address) | ||
}) | ||
|
||
t.Run("get strategy and underlying token", func(t *testing.T) { | ||
strategyAddr := contractAddrs.Erc20MockStrategy | ||
strategy, underlyingTokenAddr, err := clients.ElChainReader.GetStrategyAndUnderlyingToken( | ||
&bind.CallOpts{}, | ||
strategyAddr, | ||
) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, strategy) | ||
assert.NotEqual(t, common.Address{}, underlyingTokenAddr) | ||
|
||
erc20Token, err := erc20.NewContractIERC20(underlyingTokenAddr, clients.EthHttpClient) | ||
assert.NoError(t, err) | ||
|
||
tokenName, err := erc20Token.Name(&bind.CallOpts{}) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, tokenName) | ||
}) | ||
|
||
t.Run("get strategy and underlying ERC20 token", func(t *testing.T) { | ||
strategyAddr := contractAddrs.Erc20MockStrategy | ||
strategy, contractUnderlyingToken, underlyingTokenAddr, err := clients.ElChainReader.GetStrategyAndUnderlyingERC20Token( | ||
&bind.CallOpts{}, | ||
strategyAddr, | ||
) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, strategy) | ||
assert.NotEqual(t, common.Address{}, underlyingTokenAddr) | ||
assert.NotNil(t, contractUnderlyingToken) | ||
|
||
tokenName, err := contractUnderlyingToken.Name(&bind.CallOpts{}) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, tokenName) | ||
}) | ||
|
||
t.Run("service manager can slash operator until block", func(t *testing.T) { | ||
_, err := clients.ElChainReader.ServiceManagerCanSlashOperatorUntilBlock( | ||
&bind.CallOpts{}, | ||
common.HexToAddress(operator.Address), | ||
contractAddrs.ServiceManager, | ||
) | ||
assert.NoError(t, err) | ||
}) | ||
|
||
t.Run("operator is frozen", func(t *testing.T) { | ||
isFrozen, err := clients.ElChainReader.OperatorIsFrozen( | ||
&bind.CallOpts{}, | ||
common.HexToAddress(operator.Address), | ||
) | ||
assert.NoError(t, err) | ||
assert.Equal(t, isFrozen, false) | ||
}) | ||
|
||
t.Run("get operator shares in strategy", func(t *testing.T) { | ||
shares, err := clients.ElChainReader.GetOperatorSharesInStrategy( | ||
&bind.CallOpts{}, | ||
common.HexToAddress(operator.Address), | ||
contractAddrs.Erc20MockStrategy, | ||
) | ||
assert.NoError(t, err) | ||
assert.NotZero(t, shares) | ||
}) | ||
|
||
t.Run("calculate delegation approval digest hash", func(t *testing.T) { | ||
staker := common.Address{0x0} | ||
delegationApprover := common.Address{0x0} | ||
approverSalt := [32]byte{} | ||
expiry := big.NewInt(0) | ||
digest, err := clients.ElChainReader.CalculateDelegationApprovalDigestHash( | ||
&bind.CallOpts{}, | ||
staker, | ||
common.HexToAddress(operator.Address), | ||
delegationApprover, | ||
approverSalt, | ||
expiry, | ||
) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, digest) | ||
}) | ||
|
||
t.Run("calculate operator AVS registration digest hash", func(t *testing.T) { | ||
avs := common.Address{0x0} | ||
salt := [32]byte{} | ||
expiry := big.NewInt(0) | ||
digest, err := clients.ElChainReader.CalculateOperatorAVSRegistrationDigestHash( | ||
&bind.CallOpts{}, | ||
common.HexToAddress(operator.Address), | ||
avs, | ||
salt, | ||
expiry, | ||
) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, digest) | ||
}) | ||
} |
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,148 @@ | ||
package elcontracts_test | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
"os" | ||
"testing" | ||
|
||
"github.com/Layr-Labs/eigensdk-go/chainio/clients" | ||
"github.com/Layr-Labs/eigensdk-go/logging" | ||
"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 TestRegisterOperator(t *testing.T) { | ||
testConfig := testutils.GetDefaultTestConfig() | ||
anvilC, err := testutils.StartAnvilContainer(testConfig.AnvilStateFileName) | ||
require.NoError(t, err) | ||
anvilHttpEndpoint, err := anvilC.Endpoint(context.Background(), "http") | ||
require.NoError(t, err) | ||
anvilWsEndpoint, err := anvilC.Endpoint(context.Background(), "ws") | ||
require.NoError(t, err) | ||
logger := logging.NewTextSLogger(os.Stdout, &logging.SLoggerOptions{Level: testConfig.LogLevel}) | ||
|
||
contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) | ||
require.NoError(t, err) | ||
|
||
chainioConfig := clients.BuildAllConfig{ | ||
EthHttpUrl: anvilHttpEndpoint, | ||
EthWsUrl: anvilWsEndpoint, | ||
RegistryCoordinatorAddr: contractAddrs.RegistryCoordinator.String(), | ||
OperatorStateRetrieverAddr: contractAddrs.OperatorStateRetriever.String(), | ||
AvsName: "exampleAvs", | ||
PromMetricsIpPortAddress: ":9090", | ||
} | ||
|
||
t.Run("register as an operator", func(t *testing.T) { | ||
// Fund the new address with 5 ether | ||
fundedAccount := "0x408EfD9C90d59298A9b32F4441aC9Df6A2d8C3E1" | ||
fundedPrivateKeyHex := "3339854a8622364bcd5650fa92eac82d5dccf04089f5575a761c9b7d3c405b1c" | ||
richPrivateKeyHex := "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" | ||
code, _, err := anvilC.Exec( | ||
context.Background(), | ||
[]string{"cast", | ||
"send", | ||
"0x408EfD9C90d59298A9b32F4441aC9Df6A2d8C3E1", | ||
"--value", | ||
"5ether", | ||
"--private-key", | ||
richPrivateKeyHex, | ||
}, | ||
) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 0, code) | ||
|
||
ecdsaPrivateKey, err := crypto.HexToECDSA(fundedPrivateKeyHex) | ||
require.NoError(t, err) | ||
|
||
clients, err := clients.BuildAll( | ||
chainioConfig, | ||
ecdsaPrivateKey, | ||
logger, | ||
) | ||
require.NoError(t, err) | ||
|
||
operator := | ||
types.Operator{ | ||
Address: fundedAccount, | ||
DelegationApproverAddress: "0xd5e099c71b797516c10ed0f0d895f429c2781142", | ||
StakerOptOutWindowBlocks: 100, | ||
MetadataUrl: "https://madhur-test-public.s3.us-east-2.amazonaws.com/metadata.json", | ||
} | ||
|
||
receipt, err := clients.ElChainWriter.RegisterAsOperator(context.Background(), operator, true) | ||
assert.NoError(t, err) | ||
assert.True(t, receipt.Status == 1) | ||
}) | ||
|
||
t.Run("register as an operator already registered", func(t *testing.T) { | ||
operatorAddress := "0x408EfD9C90d59298A9b32F4441aC9Df6A2d8C3E1" | ||
operatorPrivateKeyHex := "3339854a8622364bcd5650fa92eac82d5dccf04089f5575a761c9b7d3c405b1c" | ||
|
||
ecdsaPrivateKey, err := crypto.HexToECDSA(operatorPrivateKeyHex) | ||
require.NoError(t, err) | ||
|
||
clients, err := clients.BuildAll( | ||
chainioConfig, | ||
ecdsaPrivateKey, | ||
logger, | ||
) | ||
require.NoError(t, err) | ||
|
||
operator := | ||
types.Operator{ | ||
Address: operatorAddress, | ||
DelegationApproverAddress: "0xd5e099c71b797516c10ed0f0d895f429c2781142", | ||
StakerOptOutWindowBlocks: 100, | ||
MetadataUrl: "https://madhur-test-public.s3.us-east-2.amazonaws.com/metadata.json", | ||
} | ||
|
||
_, err = clients.ElChainWriter.RegisterAsOperator(context.Background(), operator, true) | ||
assert.Error(t, err) | ||
}) | ||
} | ||
|
||
func TestChainWriter(t *testing.T) { | ||
clients, anvilHttpEndpoint := testclients.BuildTestClients(t) | ||
contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) | ||
|
||
t.Run("update operator details", func(t *testing.T) { | ||
walletModified, err := crypto.HexToECDSA("2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6") | ||
assert.NoError(t, err) | ||
walletModifiedAddress := crypto.PubkeyToAddress(walletModified.PublicKey) | ||
|
||
operatorModified := types.Operator{ | ||
Address: walletModifiedAddress.Hex(), | ||
DelegationApproverAddress: walletModifiedAddress.Hex(), | ||
StakerOptOutWindowBlocks: 101, | ||
MetadataUrl: "eigensdk-go", | ||
} | ||
|
||
receipt, err := clients.ElChainWriter.UpdateOperatorDetails(context.Background(), operatorModified, true) | ||
assert.NoError(t, err) | ||
assert.True(t, receipt.Status == 1) | ||
}) | ||
|
||
t.Run("update metadata URI", func(t *testing.T) { | ||
receipt, err := clients.ElChainWriter.UpdateMetadataURI(context.Background(), "https://0.0.0.0", true) | ||
assert.NoError(t, err) | ||
assert.True(t, receipt.Status == 1) | ||
}) | ||
|
||
t.Run("deposit ERC20 into strategy", func(t *testing.T) { | ||
amount := big.NewInt(1) | ||
receipt, err := clients.ElChainWriter.DepositERC20IntoStrategy( | ||
context.Background(), | ||
contractAddrs.Erc20MockStrategy, | ||
amount, | ||
true, | ||
) | ||
assert.NoError(t, err) | ||
assert.True(t, receipt.Status == 1) | ||
}) | ||
} |
Oops, something went wrong.