Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add tests for execution grpc server and astria configs #17

Merged
merged 17 commits into from
May 31, 2024

Conversation

bharath-123
Copy link
Contributor

@bharath-123 bharath-123 commented May 16, 2024

This PR adds the following:

  1. Tests for astria execution grpc server
  2. Tests for astria config
  3. Abstraction of astria validation logic and unit tests for them.

@bharath-123 bharath-123 changed the base branch from main to bharath/fix-existing-tests May 16, 2024 11:13
@bharath-123 bharath-123 force-pushed the bharath/add-execution-server-tests branch 2 times, most recently from def1207 to a0190ef Compare May 16, 2024 11:17
@bharath-123 bharath-123 changed the title feat: Add tests for execution grpc server feat: Add integration tests for execution grpc server May 16, 2024
@bharath-123 bharath-123 changed the title feat: Add integration tests for execution grpc server feat: Add tests for execution grpc server May 16, 2024
@bharath-123 bharath-123 marked this pull request as ready for review May 16, 2024 11:20
@bharath-123 bharath-123 changed the title feat: Add tests for execution grpc server feat: Add tests for execution grpc server and configs May 20, 2024
@bharath-123 bharath-123 changed the title feat: Add tests for execution grpc server and configs feat: Add tests for execution grpc server and astria configs May 20, 2024
@bharath-123 bharath-123 force-pushed the bharath/add-execution-server-tests branch from 99ca51f to b10c667 Compare May 22, 2024 05:56
@bharath-123 bharath-123 force-pushed the bharath/add-execution-server-tests branch from b10c667 to 3c13860 Compare May 22, 2024 06:03
Base automatically changed from bharath/fix-existing-tests to main May 24, 2024 09:16
@bharath-123 bharath-123 force-pushed the bharath/add-execution-server-tests branch from 3c13860 to 1a4b890 Compare May 27, 2024 15:59
@@ -22,4 +22,4 @@ jobs:
- name: Run tests
run: go test -short ./...
env:
GOOS: linux
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: new line

@@ -474,6 +474,7 @@ func (c *Clique) verifySeal(snap *Snapshot, header *types.Header, parents []*typ
return err
}
if _, ok := snap.Signers[signer]; !ok {
fmt.Printf("Failing here")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?

)

// if sequencer tx is valid, then a unmarshalled ethereum transaction is returned. if not valid, nil is returned
func (s *ExecutionServiceServerV1Alpha2) ValidateAndUnmarshalSequencerTx(tx *sequencerblockv1alpha1.RollupData) (*types.Transaction, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is best as a method on the execution server. Maybe best choice for now, but only thing it's ingesting is bridge config information. Perhaps it could just take those as parameters?

This also only validates deposit tx types. Perhaps those should be validated elsewhere similar to how we validate the eth txs elsewhere just build the deposit don't validate validate elsewhere? These could be follow up changes though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i thought the same too. I think it makes sense to pass the bridge config

Copy link
Contributor Author

@bharath-123 bharath-123 May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i think we can refactor the validation logic in the future. It would be better to seperate out the unmarshall step and validate step. but then we end up unmarshalling twice for validation.

)

// if sequencer tx is valid, then a unmarshalled ethereum transaction is returned. if not valid, nil is returned
func ValidateAndUnmarshalSequencerTx(tx *sequencerblockv1alpha1.RollupData, bridgeAddresses map[string]*params.AstriaBridgeAddressConfig, bridgeAllowedAssetIDs map[[32]byte]struct{}) (*types.Transaction, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't need to be exported - make this private

"github.com/ethereum/go-ethereum/params"
)

// if sequencer tx is valid, then a unmarshalled ethereum transaction is returned. if not valid, nil is returned
Copy link
Contributor

@noot noot May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// if sequencer tx is valid, then a unmarshalled ethereum transaction is returned. if not valid, nil is returned
// `validateAndUnmarshalSequencerTx` returns an ethereum transaction if the given rollup data bytes are valid.

maybe describe what the validation for deposits looks like also?

bridgeAddress := string(deposit.BridgeAddress.GetInner())
bac, ok := bridgeAddresses[bridgeAddress]
if !ok {
log.Debug("ignoring deposit tx from unknown bridge", "bridgeAddress", bridgeAddress)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't log in this function, just put the required error contents in the returned error, as the caller will log

Comment on lines 181 to 183
if err := n.Start(); err != nil {
t.Fatal("can't start node:", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have to actually start the node here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all the server tests require it to start, i have just abstracted it into one place. The validation_test doesn't need it and I can add a flag to only start it when needed.

Comment on lines 27 to 30
conn, err := grpc.Dial(GrpcEndpointWithoutPrefix(n), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("Failed to dial gRPC: %v", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to not actually start the gRPC server but just call methods directly on serviceV1Alpha1? that seems like it would work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would work. I just thought that this would be a more solid integration test where we run all the grpc node setup logic too.

Comment on lines 35 to 37
if err != nil {
t.Fatalf("GetGenesisInfo failed: %v", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to use something like this: https://pkg.go.dev/github.com/stretchr/testify/require

then you can do:

Suggested change
if err != nil {
t.Fatalf("GetGenesisInfo failed: %v", err)
}
if err != nil {
t.Fatalf("GetGenesisInfo failed: %v", err)
}
Suggested change
if err != nil {
t.Fatalf("GetGenesisInfo failed: %v", err)
}
require.Nil(t, err, "GetGenesisInfo failed")

and for the equals checks, can use require.Equal(t, a, b)

@bharath-123 bharath-123 force-pushed the bharath/add-execution-server-tests branch from aa5dd01 to 2273524 Compare May 29, 2024 16:38
txsToProcess = append(txsToProcess, ethTx)
unmarshalledTx, err := validateAndUnmarshalSequencerTx(tx, s.bridgeAddresses, s.bridgeAllowedAssetIDs)
if err != nil {
log.Error("failed to validate sequencer tx, ignoring", "tx", tx, "err", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.Error("failed to validate sequencer tx, ignoring", "tx", tx, "err", err)
log.Debug("failed to validate sequencer tx, ignoring", "tx", tx, "err", err)

ethservice, serviceV1Alpha1 := setupExecutionService(t, 10)

genesisInfo, err := serviceV1Alpha1.GetGenesisInfo(context.Background(), &astriaPb.GetGenesisInfoRequest{})
require.Nil(t, err, "GetGenesisInfo failed: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
require.Nil(t, err, "GetGenesisInfo failed: %v", err)
require.Nil(t, err, "GetGenesisInfo failed")

don't need to log the error as it'll already get logged by require - same for other lines

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't know that!

txs := []*types.Transaction{}
marshalledTxs := []*sequencerblockv1alpha1.RollupData{}
for i := 0; i < 5; i++ {
unsignedTx := types.NewTransaction(uint64(i), common.HexToAddress("0x9a9070028361F7AAbeB3f2F2Dc07F82C4a98A02a"), big.NewInt(1), params.TxGas, big.NewInt(params.InitialBaseFee*2), nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put the address as a var outside the loop

txs := []*types.Transaction{}
marshalledTxs := []*sequencerblockv1alpha1.RollupData{}
for i := 0; i < 5; i++ {
unsignedTx := types.NewTransaction(uint64(i), common.HexToAddress("0x9a9070028361F7AAbeB3f2F2Dc07F82C4a98A02a"), big.NewInt(1), params.TxGas, big.NewInt(params.InitialBaseFee*2), nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here about the address

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually make it a global var since it seems to be used a lot of places

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Config: &config,
Alloc: core.GenesisAlloc{
testAddr: {Balance: testBalance},
params.BeaconRootsStorageAddress: {Balance: common.Big0, Code: common.Hex2Bytes("3373fffffffffffffffffffffffffffffffffffffffe14604457602036146024575f5ffd5b620180005f350680545f35146037575f5ffd5b6201800001545f5260205ff35b6201800042064281555f359062018000015500")},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, what is this code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eip-4788 stuff, address where historical beacon roots are stored. but we can remove it. don't need it. i copied this over from another test.

Comment on lines 107 to 113
n, err := node.New(&node.Config{
P2P: p2p.Config{
ListenAddr: "0.0.0.0:0",
NoDiscovery: true,
MaxPeers: 25,
},
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to disable p2p? don't think we should start p2p in a unit test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it!

Comment on lines 114 to 116
if err != nil {
t.Fatal("can't create node:", err)
}
Copy link
Contributor

@noot noot May 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use require, same for other places in this file


}

func GrpcEndpointWithoutPrefix(n *node.Node) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove (unused?)

"testing"
)

func randomBlobTx() *types.Transaction {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func randomBlobTx() *types.Transaction {
func testBlobTx() *types.Transaction {

since it isn't random, same with randomDepositTx below

Copy link
Contributor

@noot noot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! only minor suggestions :)

@bharath-123 bharath-123 merged commit 9185612 into main May 31, 2024
2 checks passed
@bharath-123 bharath-123 deleted the bharath/add-execution-server-tests branch May 31, 2024 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants