Skip to content

Commit

Permalink
Add compliance tests (#339)
Browse files Browse the repository at this point in the history
Co-authored-by: tomasarrachea <tomas.arrachea@lambdaclass.com>
  • Loading branch information
pablodeymo and TomasArrachea authored Oct 2, 2024
1 parent 0b642fa commit 91ca9d4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
4 changes: 3 additions & 1 deletion cmd/egnaddrs/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ func TestEgnAddrsWithServiceManagerFlag(t *testing.T) {
// read input from JSON if available, otherwise use default values
var defaultInput = struct {
ServiceManagerAddress common.Address `json:"service_manager_address"`
RpcUrl string `json:"rpc_url"`
}{
ServiceManagerAddress: testutils.GetContractAddressesFromContractRegistry(anvilEndpoint).ServiceManager,
RpcUrl: anvilEndpoint,
}
testData := testutils.NewTestData(defaultInput)

args := []string{"egnaddrs"}
args = append(args, "--service-manager", testData.Input.ServiceManagerAddress.Hex())
args = append(args, "--rpc-url", anvilEndpoint)
args = append(args, "--rpc-url", testData.Input.RpcUrl)
// we just make sure it doesn't crash
run(args)
}
Expand Down
20 changes: 17 additions & 3 deletions services/avsregistry/avsregistry_chaincaller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package avsregistry

import (
"context"
"encoding/hex"
"errors"

"math/big"
Expand Down Expand Up @@ -33,11 +34,24 @@ func (f *fakeOperatorInfoService) GetOperatorInfo(
return f.operatorInfo, true
}

func TestAvsRegistryServiceChainCaller_getOperatorPubkeys(t *testing.T) {
func TestAvsRegistryServiceChainCaller_GetOperatorPubkeys(t *testing.T) {
logger := testutils.GetTestLogger()
testOperator1 := fakes.TestOperator{
var defaultInput = struct {
OperatorAddr types.OperatorAddr `json:"operator_address"`
OperatorId string `json:"operator_id"`
}{
OperatorAddr: common.HexToAddress("0x1"),
OperatorId: types.OperatorId{1},
OperatorId: "0000000000000000000000000000000000000000000000000000000000000001",
}
testData := testutils.NewTestData(defaultInput)

opid, err := hex.DecodeString(testData.Input.OperatorId)
if err != nil {
t.Fatalf("failed to decode operator id: %v", err)
}
testOperator1 := fakes.TestOperator{
OperatorAddr: testData.Input.OperatorAddr,
OperatorId: types.OperatorId(opid),
OperatorInfo: types.OperatorInfo{
Pubkeys: types.OperatorPubkeys{
G1Pubkey: bls.NewG1Point(big.NewInt(1), big.NewInt(1)),
Expand Down
35 changes: 25 additions & 10 deletions signerv2/kms_signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,28 @@ func teardown() {
_ = anvil.Terminate(context.Background())
}

func TestSendTransaction(t *testing.T) {
func TestSignTransactionWithKmsSigner(t *testing.T) {
logger := testutils.GetTestLogger()
ethClient, err := ethclient.Dial(anvilEndpoint)
assert.Nil(t, err)
chainID, err := ethClient.ChainID(context.Background())
assert.Nil(t, err)
zeroAddr := common.HexToAddress("0x0")

// read input from JSON if available, otherwise use default values
var defaultInput = struct {
ChainID big.Int `json:"chain_id"`
Nonce uint64 `json:"nonce"`
To common.Address `json:"to"`
Value big.Int `json:"value"`
}{
ChainID: *big.NewInt(0),
Nonce: 0,
To: zeroAddr,
Value: *big.NewInt(1_000_000_000_000_000_000),
}
testData := testutils.NewTestData(defaultInput)

c, err := testutils.NewKMSClient(mappedLocalstackPort)
assert.Nil(t, err)
assert.NotNil(t, keyMetadata.KeyId)
Expand All @@ -97,11 +118,6 @@ func TestSendTransaction(t *testing.T) {
err = rpcClient.CallContext(context.Background(), nil, "anvil_setBalance", keyAddr, 2_000_000_000_000_000_000)
assert.Nil(t, err)

logger := testutils.GetTestLogger()
ethClient, err := ethclient.Dial(anvilEndpoint)
assert.Nil(t, err)
chainID, err := ethClient.ChainID(context.Background())
assert.Nil(t, err)
signer := signerv2.NewKMSSigner(context.Background(), c, pk, *keyMetadata.KeyId, chainID)
assert.Nil(t, err)
assert.NotNil(t, signer)
Expand All @@ -110,12 +126,11 @@ func TestSendTransaction(t *testing.T) {
assert.NotNil(t, pkWallet)
txMgr := txmgr.NewSimpleTxManager(pkWallet, ethClient, logger, keyAddr)
assert.NotNil(t, txMgr)
zeroAddr := common.HexToAddress("0x0")
receipt, err := txMgr.Send(context.Background(), gtypes.NewTx(&gtypes.DynamicFeeTx{
ChainID: chainID,
Nonce: 0,
ChainID: &testData.Input.ChainID,
Nonce: testData.Input.Nonce,
To: &zeroAddr,
Value: big.NewInt(1_000_000_000_000_000_000),
Value: &testData.Input.Value,
}), true)
assert.Nil(t, err)
assert.NotNil(t, receipt)
Expand Down

0 comments on commit 91ca9d4

Please sign in to comment.