Last active
February 8, 2022 23:03
-
-
Save rauljordan/dd5aef5c35a98ae67989601c83aafde1 to your computer and use it in GitHub Desktop.
New Engine API Spec Tests, Informal
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
{ | |
"forkchoiceState": { | |
"headBlockHash": "0x3b8fb240d288781d4aac94d3fd16809ee413bc99294a085798a589dae51ddd4a", | |
"safeBlockHash": "0x3b8fb240d288781d4aac94d3fd16809ee413bc99294a085798a589dae51ddd4a", | |
"finalizedBlockHash": "0x0000000000000000000000000000000000000000000000000000000000000000" | |
}, | |
"payloadAttributes": { | |
"timestamp": "0x5", | |
"random": "0x0000000000000000000000000000000000000000000000000000000000000000", | |
"suggestedFeeRecipient": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" | |
} | |
} |
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
{ | |
"payloadStatus": { | |
"status": "VALID", | |
"latestValidHash": "0x0000000000000000000000000000000000000000000000000000000000000000", | |
"validationError": "" | |
}, | |
"payloadId": "0xa247243752eb10b4" | |
} |
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
{ | |
"forkchoiceState": { | |
"headBlockHash": "0x3559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858", | |
"safeBlockHash": "0x3559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858", | |
"finalizedBlockHash": "0x3b8fb240d288781d4aac94d3fd16809ee413bc99294a085798a589dae51ddd4a" | |
}, | |
"payloadAttributes": null | |
} |
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
{ | |
"payloadStatus": { | |
"status": "VALID", | |
"latestValidHash": "0x0000000000000000000000000000000000000000000000000000000000000000", | |
"validationError": "" | |
} | |
} |
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
{ | |
"parentHash": "0x3b8fb240d288781d4aac94d3fd16809ee413bc99294a085798a589dae51ddd4a", | |
"feeRecipient": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", | |
"stateRoot": "0xca3149fa9e37db08d1cd49c9061db1002ef1cd58db2210f2115c8c989b2bdf45", | |
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", | |
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", | |
"random": "0x0000000000000000000000000000000000000000000000000000000000000000", | |
"blockNumber": "0x1", | |
"gasLimit": "0x1c95111", | |
"gasUsed": "0x0", | |
"timestamp": "0x5", | |
"extraData": "0x", | |
"baseFeePerGas": "0x7", | |
"blockHash": "0x6359b8381a370e2f54072a5784ddd78b6ed024991558c511d4452eb4f6ac898c", | |
"transactions": [] | |
} |
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
// Runs the test fixtures prepared by Marius as defined here: https://notes.ethereum.org/rmVErCfCRPKGqGkUe89-Kg?both | |
// and ensures that Prysm passes. This requires running geth in catalyst mode. | |
// Place all the JSON files in this gist inside of a `data/` folder in the same directory as this test. | |
package main | |
import ( | |
"context" | |
"encoding/json" | |
"testing" | |
v1 "github.com/prysmaticlabs/prysm/beacon-chain/powchain/engine-api-client/v1" | |
"github.com/prysmaticlabs/prysm/io/file" | |
enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1" | |
"github.com/prysmaticlabs/prysm/testing/require" | |
) | |
func TestEngineAPICompliance(t *testing.T) { | |
ctx := context.Background() | |
client, err := v1.New(ctx, "http://localhost:8550") | |
require.NoError(t, err) | |
// First, prepare a payload for forkchoice updates. | |
type args struct { | |
ForkchoiceState *enginev1.ForkchoiceState `json:"forkchoiceState"` | |
PayloadAttributes *enginev1.PayloadAttributes `json:"payloadAttributes"` | |
} | |
req := args{} | |
readDataFile("forkchoice_updated_request", &req) | |
// engine_forkchoiceUpdatedV1. | |
resp, err := client.ForkchoiceUpdated(ctx, req.ForkchoiceState, req.PayloadAttributes) | |
require.NoError(t, err) | |
want := &v1.ForkchoiceUpdatedResponse{} | |
readDataFile("forkchoice_updated_response", want) | |
require.DeepEqual(t, want, resp) | |
// This will create a payload under payload id 0xa247243752eb10b4. | |
// All subsequent calls with the same parameters should create a | |
// payload under the same id. | |
// engine_getPayloadV1. | |
var getPayloadReq enginev1.PayloadIDBytes | |
require.NoError(t, json.Unmarshal([]byte("\"0xa247243752eb10b4\""), &getPayloadReq)) | |
getPayloadResp, err := client.GetPayload(ctx, getPayloadReq) | |
require.NoError(t, err) | |
wantGetPayloadResp := &enginev1.ExecutionPayload{} | |
readDataFile("get_payload_response", &wantGetPayloadResp) | |
require.DeepEqual(t, wantGetPayloadResp, getPayloadResp) | |
// engine_newPayloadV1. | |
var newPayloadReq *enginev1.ExecutionPayload | |
readDataFile("new_payload_request", &newPayloadReq) | |
newPayloadResp, err := client.NewPayload(ctx, newPayloadReq) | |
require.NoError(t, err) | |
wantNewPayloadResp := &enginev1.PayloadStatus{} | |
readDataFile("new_payload_response", &wantNewPayloadResp) | |
require.DeepEqual(t, wantNewPayloadResp, newPayloadResp) | |
updateForkChoiceSecondReq := args{} | |
readDataFile("forkchoice_updated_second_request", &updateForkChoiceSecondReq) | |
// engine_forkchoiceUpdatedV1. | |
updateForkChoiceSecondResp, err := client.ForkchoiceUpdated( | |
ctx, | |
updateForkChoiceSecondReq.ForkchoiceState, | |
updateForkChoiceSecondReq.PayloadAttributes, | |
) | |
require.NoError(t, err) | |
wantForkChoiceSecondResp := &v1.ForkchoiceUpdatedResponse{} | |
readDataFile("forkchoice_updated_second_response", wantForkChoiceSecondResp) | |
require.DeepEqual(t, wantForkChoiceSecondResp, updateForkChoiceSecondResp) | |
} | |
func readDataFile(fileName string, target interface{}) { | |
enc, err := file.ReadFileAsBytes("data/" + fileName + ".json") | |
if err != nil { | |
panic(err) | |
} | |
if err := json.Unmarshal(enc, target); err != nil { | |
panic(err) | |
} | |
} |
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
{ | |
"parentHash": "0x3b8fb240d288781d4aac94d3fd16809ee413bc99294a085798a589dae51ddd4a", | |
"feeRecipient": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", | |
"stateRoot": "0xca3149fa9e37db08d1cd49c9061db1002ef1cd58db2210f2115c8c989b2bdf45", | |
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", | |
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", | |
"random": "0x0000000000000000000000000000000000000000000000000000000000000000", | |
"blockNumber": "0x1", | |
"gasLimit": "0x1c9c380", | |
"gasUsed": "0x0", | |
"timestamp": "0x5", | |
"extraData": "0x", | |
"baseFeePerGas": "0x7", | |
"blockHash": "0x3559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858", | |
"transactions": [] | |
} |
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
{ | |
"status": "VALID", | |
"latestValidHash": "0x3559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858", | |
"validationError": "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment