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

Add a onchain execution on forked network with Hardcoded values. #54

Merged
merged 19 commits into from
Aug 30, 2024

Conversation

Ethnical
Copy link
Collaborator

@Ethnical Ethnical commented Aug 19, 2024

Description

A PR to execute a hard-coded transaction (sent 1wei to 0x4141414142424242414141414242424241414141 with data=0x414243) on forked L1 on Sepolia using a well known privatekey.

9ec733437aca03061ec4bdf188b23c401b126cf60752d6988deb0f015a1b55e2

From a simple cURL will trigger the onchain execution.

CleanShot 2024-08-29 at 13 33 16@2x

We can see that the transaction on tenderly is a simple movemement of 1 wei to 0x4141414142424242414141414242424241414141 with calldata=0x414243.
image

Tests

I made some tests using the HTTP API directly using:

curl -X POST http://localhost:8080/api/psp_execution \-H "Content-Type: application/json" \-d '{"pause": true, "timestamp": 1719432011, "operator": "Tom"}'

To make better testing, I had to create a mocking interface:

type SimpleExecutor struct{}

func (e *SimpleExecutor) FetchAndExecute(d *Defender) {
	// Do nothing for now, for mocking purposes
}

To achieve this, I have added a executor to the defender object for helping us in the future for mocking the results.

I haved added multiples unit tests in the file api_test.go for the new created functions.

  • TestHTTPServerHasOnlyPSPExecutionRoute(): This ensure the API HTTP is not listenning on another methods or other routes. To make sure no undesired HTTP requests can be crafted on unknown method or path.
  • TestDefenderInitialization(): This ensure we can create a defender with a mock FetchAndExecute() method.
  • TestCheckAndReturnRPC(): This make sure that the RPC ur is correct and valid RPC. This is particular useful for during the development part to not send transaction accidentally on undesired network.
  • TestHandlePostMockFetch(): This test the HTTP status code result to ensure malformed HTTP request return the correct status code.
=== RUN   TestHTTPServerHasOnlyPSPExecutionRoute
--- PASS: TestHTTPServerHasOnlyPSPExecutionRoute (0.00s)
=== RUN   TestDefenderInitialization
--- PASS: TestDefenderInitialization (0.00s)
=== RUN   TestHandlePostMockFetch
=== RUN   TestHandlePostMockFetch/Valid_Request
=== RUN   TestHandlePostMockFetch/Invalid_JSON
=== RUN   TestHandlePostMockFetch/Missing_Fields
=== RUN   TestHandlePostMockFetch/Incorrect_Path_Fields
--- PASS: TestHandlePostMockFetch (0.00s)
    --- PASS: TestHandlePostMockFetch/Valid_Request (0.00s)
    --- PASS: TestHandlePostMockFetch/Invalid_JSON (0.00s)
    --- PASS: TestHandlePostMockFetch/Missing_Fields (0.00s)
    --- PASS: TestHandlePostMockFetch/Incorrect_Path_Fields (0.00s)
=== RUN   TestCheckAndReturnRPC
=== RUN   TestCheckAndReturnRPC/Empty_URL
=== RUN   TestCheckAndReturnRPC/Production_URL
=== RUN   TestCheckAndReturnRPC/Valid_Tenderly_Fork_URL
--- PASS: TestCheckAndReturnRPC (0.00s)
    --- PASS: TestCheckAndReturnRPC/Empty_URL (0.00s)
    --- PASS: TestCheckAndReturnRPC/Production_URL (0.00s)
    --- PASS: TestCheckAndReturnRPC/Valid_Tenderly_Fork_URL (0.00s)
PASS
ok      github.com/ethereum-optimism/monitorism/op-defender/psp_executor        0.924s

Additional context
This is the PR N°3, after this one will make 2 PRs again to complete the psp_executor.
Worth noting there is multiples @todo tags that would be fixed in the future PRs.

I have also improve the current README with the current features.

@Ethnical Ethnical added the enhancement New feature or request label Aug 19, 2024
@Ethnical Ethnical self-assigned this Aug 19, 2024
@Ethnical Ethnical changed the title Add a OnChain Execution on forked Env with Hardcoded values. WIP: Add a OnChain Execution on forked Env with Hardcoded values. Aug 19, 2024
@Ethnical Ethnical marked this pull request as ready for review August 29, 2024 12:48
@Ethnical Ethnical requested a review from a team as a code owner August 29, 2024 12:48
@Ethnical Ethnical requested review from blmalone and zchn August 29, 2024 12:48
@Ethnical Ethnical changed the title WIP: Add a OnChain Execution on forked Env with Hardcoded values. Add a onchain execution on forked network with Hardcoded values. Aug 29, 2024
@zchn zchn assigned zchn and unassigned Ethnical Aug 29, 2024
@zchn zchn removed request for zchn and blmalone August 29, 2024 14:35
op-defender/psp_executor/api_test.go Outdated Show resolved Hide resolved
op-defender/psp_executor/api_test.go Outdated Show resolved Hide resolved
op-defender/psp_executor/defender.go Outdated Show resolved Hide resolved
@Ethnical Ethnical requested a review from zchn August 30, 2024 11:52
op-defender/psp_executor/api_test.go Outdated Show resolved Hide resolved
op-defender/psp_executor/api_test.go Outdated Show resolved Hide resolved
op-defender/psp_executor/api_test.go Outdated Show resolved Hide resolved
op-defender/psp_executor/api_test.go Outdated Show resolved Hide resolved
op-defender/psp_executor/defender.go Outdated Show resolved Hide resolved
Ethnical and others added 3 commits August 30, 2024 16:14
Co-authored-by: Kevin Z Chen <kevin.zchn@gmail.com>
Co-authored-by: Kevin Z Chen <kevin.zchn@gmail.com>
@Ethnical Ethnical merged commit 6d99605 into main Aug 30, 2024
4 checks passed
@Ethnical Ethnical deleted the ethni/hardcoded_transaction_execution branch August 30, 2024 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants