This repository was archived by the owner on Oct 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Broadcast UserOperation batch to list of builders in searcher mode (#352
- Loading branch information
Showing
15 changed files
with
345 additions
and
139 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
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,21 @@ | ||
package testutils | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"net/http/httptest" | ||
|
||
"github.com/metachris/flashbotsrpc" | ||
) | ||
|
||
func BadBuilderRpcMock() *httptest.Server { | ||
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
res := &flashbotsrpc.RelayErrorResponse{ | ||
Error: "Mock upstream builder error", | ||
} | ||
w.WriteHeader(http.StatusOK) | ||
if err := json.NewEncoder(w).Encode(res); 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
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 |
---|---|---|
@@ -1,51 +1,44 @@ | ||
package testutils | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
) | ||
"math/big" | ||
"time" | ||
|
||
type mockReq struct { | ||
JsonRpc string `json:"jsonrpc"` | ||
ID float64 `json:"id"` | ||
Method string `json:"method"` | ||
} | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
) | ||
|
||
type mockRes struct { | ||
JsonRpc string `json:"jsonrpc"` | ||
ID float64 `json:"id"` | ||
Result any `json:"result"` | ||
func NewBlockMock() map[string]any { | ||
return map[string]any{ | ||
"parentHash": MockHash, | ||
"sha3Uncles": MockHash, | ||
"stateRoot": MockHash, | ||
"transactionsRoot": MockHash, | ||
"receiptsRoot": MockHash, | ||
"logsBloom": "0xdeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddead", | ||
"difficulty": "0x0", | ||
"number": "0x1", | ||
"gasLimit": hexutil.EncodeBig(big.NewInt(30000000)), | ||
"gasUsed": hexutil.EncodeBig(big.NewInt(5000000)), | ||
"timestamp": hexutil.EncodeUint64(uint64(time.Now().Unix())), | ||
"extraData": "0x", | ||
} | ||
} | ||
|
||
type MethodMocks map[string]any | ||
|
||
// EthMock returns a httptest.Server for mocking the return value of a JSON-RPC method call to an Ethereum node. | ||
func EthMock(mocks MethodMocks) *httptest.Server { | ||
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
var req mockReq | ||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil { | ||
panic(err) | ||
} | ||
|
||
mock, ok := mocks[req.Method] | ||
if !ok { | ||
w.WriteHeader(http.StatusBadRequest) | ||
if _, err := w.Write([]byte(fmt.Sprintf("method not in mocks: %s", req.Method))); err != nil { | ||
panic(err) | ||
} | ||
return | ||
} | ||
|
||
res := &mockRes{ | ||
JsonRpc: req.JsonRpc, | ||
ID: req.ID, | ||
Result: mock, | ||
} | ||
w.WriteHeader(http.StatusOK) | ||
if err := json.NewEncoder(w).Encode(res); err != nil { | ||
panic(err) | ||
} | ||
})) | ||
func NewTransactionReceiptMock() map[string]any { | ||
return map[string]any{ | ||
"blockHash": MockHash, | ||
"blockNumber": "0x1", | ||
"cumulativeGasUsed": "0x1", | ||
"effectiveGasPrice": "0x1", | ||
"from": common.HexToAddress("0x").Hex(), | ||
"gasUsed": "0x1", | ||
"logs": []any{}, | ||
"logsBloom": "0xdeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddead", | ||
"status": "0x1", | ||
"to": common.HexToAddress("0x").Hex(), | ||
"transactionHash": MockHash, | ||
"transactionIndex": "0x1", | ||
"type": "0x2", | ||
} | ||
} |
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,49 @@ | ||
package testutils | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
) | ||
|
||
type mockReq struct { | ||
JsonRpc string `json:"jsonrpc"` | ||
ID float64 `json:"id"` | ||
Method string `json:"method"` | ||
} | ||
|
||
type mockRes struct { | ||
JsonRpc string `json:"jsonrpc"` | ||
ID float64 `json:"id"` | ||
Result any `json:"result"` | ||
} | ||
|
||
type MethodMocks map[string]any | ||
|
||
func RpcMock(mocks MethodMocks) *httptest.Server { | ||
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
var req mockReq | ||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil { | ||
panic(err) | ||
} | ||
mock, ok := mocks[req.Method] | ||
if !ok { | ||
w.WriteHeader(http.StatusBadRequest) | ||
if _, err := w.Write([]byte(fmt.Sprintf("method not in mocks: %s", req.Method))); err != nil { | ||
panic(err) | ||
} | ||
return | ||
} | ||
|
||
res := &mockRes{ | ||
JsonRpc: req.JsonRpc, | ||
ID: req.ID, | ||
Result: mock, | ||
} | ||
w.WriteHeader(http.StatusOK) | ||
if err := json.NewEncoder(w).Encode(res); 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
Oops, something went wrong.