-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
def1207
to
a0190ef
Compare
99ca51f
to
b10c667
Compare
9bd89b4
to
bb5bc7f
Compare
b10c667
to
3c13860
Compare
bb5bc7f
to
6ae7856
Compare
3c13860
to
1a4b890
Compare
.github/workflows/run-tests.yml
Outdated
@@ -22,4 +22,4 @@ jobs: | |||
- name: Run tests | |||
run: go test -short ./... | |||
env: | |||
GOOS: linux |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: new line
consensus/clique/clique.go
Outdated
@@ -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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove?
grpc/execution/validation.go
Outdated
) | ||
|
||
// 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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
grpc/execution/validation.go
Outdated
) | ||
|
||
// 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) { |
There was a problem hiding this comment.
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
grpc/execution/validation.go
Outdated
"github.com/ethereum/go-ethereum/params" | ||
) | ||
|
||
// if sequencer tx is valid, then a unmarshalled ethereum transaction is returned. if not valid, nil is returned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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?
grpc/execution/validation.go
Outdated
bridgeAddress := string(deposit.BridgeAddress.GetInner()) | ||
bac, ok := bridgeAddresses[bridgeAddress] | ||
if !ok { | ||
log.Debug("ignoring deposit tx from unknown bridge", "bridgeAddress", bridgeAddress) |
There was a problem hiding this comment.
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
grpc/execution/test_utils.go
Outdated
if err := n.Start(); err != nil { | ||
t.Fatal("can't start node:", err) | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
grpc/execution/server_test.go
Outdated
conn, err := grpc.Dial(GrpcEndpointWithoutPrefix(n), grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
if err != nil { | ||
t.Fatalf("Failed to dial gRPC: %v", err) | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
grpc/execution/server_test.go
Outdated
if err != nil { | ||
t.Fatalf("GetGenesisInfo failed: %v", err) | ||
} |
There was a problem hiding this comment.
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:
if err != nil { | |
t.Fatalf("GetGenesisInfo failed: %v", err) | |
} | |
if err != nil { | |
t.Fatalf("GetGenesisInfo failed: %v", err) | |
} |
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)
aa5dd01
to
2273524
Compare
grpc/execution/server.go
Outdated
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Error("failed to validate sequencer tx, ignoring", "tx", tx, "err", err) | |
log.Debug("failed to validate sequencer tx, ignoring", "tx", tx, "err", err) |
grpc/execution/server_test.go
Outdated
ethservice, serviceV1Alpha1 := setupExecutionService(t, 10) | ||
|
||
genesisInfo, err := serviceV1Alpha1.GetGenesisInfo(context.Background(), &astriaPb.GetGenesisInfoRequest{}) | ||
require.Nil(t, err, "GetGenesisInfo failed: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't know that!
grpc/execution/server_test.go
Outdated
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) |
There was a problem hiding this comment.
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
grpc/execution/server_test.go
Outdated
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
grpc/execution/test_utils.go
Outdated
Config: &config, | ||
Alloc: core.GenesisAlloc{ | ||
testAddr: {Balance: testBalance}, | ||
params.BeaconRootsStorageAddress: {Balance: common.Big0, Code: common.Hex2Bytes("3373fffffffffffffffffffffffffffffffffffffffe14604457602036146024575f5ffd5b620180005f350680545f35146037575f5ffd5b6201800001545f5260205ff35b6201800042064281555f359062018000015500")}, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
grpc/execution/test_utils.go
Outdated
n, err := node.New(&node.Config{ | ||
P2P: p2p.Config{ | ||
ListenAddr: "0.0.0.0:0", | ||
NoDiscovery: true, | ||
MaxPeers: 25, | ||
}, | ||
}) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed it!
grpc/execution/test_utils.go
Outdated
if err != nil { | ||
t.Fatal("can't create node:", err) | ||
} |
There was a problem hiding this comment.
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
grpc/execution/test_utils.go
Outdated
|
||
} | ||
|
||
func GrpcEndpointWithoutPrefix(n *node.Node) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove (unused?)
grpc/execution/validation_test.go
Outdated
"testing" | ||
) | ||
|
||
func randomBlobTx() *types.Transaction { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func randomBlobTx() *types.Transaction { | |
func testBlobTx() *types.Transaction { |
since it isn't random, same with randomDepositTx
below
There was a problem hiding this 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 :)
This PR adds the following: