-
Notifications
You must be signed in to change notification settings - Fork 11
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
Tests for invalid transaction handling #18
Conversation
sveitser
commented
Nov 30, 2023
•
edited by ImJeremyHe
Loading
edited by ImJeremyHe
- mock the HotShot server to make sure the transactions we want are included in an espresso block
- check the message count in transaction streamer and block validator
- check the count of transactions in the l2 block
0b311b7
to
fc8a1f5
Compare
89816cc
to
735bbb5
Compare
|
||
func espresso_block_txs_generators(t *testing.T, l2Info *BlockchainTestInfo) map[int][][]byte { | ||
return map[int][][]byte{ | ||
5: onlyMalformedTxs(t), |
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 think that this might be cleaner with some sort mock Txn Interface:
type MockTxn struct {
Type MockTxnType // Valid or invalid
Amount uint64
...etc
}
Then you can build test cases with arrays of MockTxnTemplates and create a single function that parses them into the correct txn bytes
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.
Great point. But currently mocking txs is still not easy. There is no any readily available functions to mock the malformed and invalid txs and I don't have any good idea about how to implement this interface yet. I think it might be better to optimize here after we know the test system well.
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.
system_tests/espresso_test.go
Outdated
func(req *http.Request) (*http.Response, error) { | ||
log.Info("GET", "url", req.URL) | ||
block := uint64(httpmock.MustGetSubmatchAsUint(req, 1)) | ||
// todo |
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.
Do we still need these todos? If not, we should remove them, but if we do, let's comment them with a GitHub issue
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.
These todo
s are here just because we don't realize the validation of espresso. After we realize that, we need to make the proof or header correctly or the test will fail.
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.
Now todo
s are removed and a comment is left.
system_tests/espresso_test.go
Outdated
"POST", | ||
"http://127.0.0.1:50000/submit/submit", | ||
func(req *http.Request) (*http.Response, error) { | ||
log.Info("POST", "url", req.URL, "body", req.Body) |
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 this log necessary?
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.
The submit/submit
handler is removed now. There should not be any submission during the test.
system_tests/espresso_test.go
Outdated
}) | ||
|
||
generators := espresso_block_txs_generators(t, l2Info) | ||
dummyProof := func(n int) []byte { |
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.
We could even consider hardcoding this entirely, unless you think there is a benefit to encoding the block number in each proof
system_tests/espresso_test.go
Outdated
log.Info("GET", "url", req.URL) | ||
if !ok { | ||
r := espresso.NamespaceResponse{ | ||
Proof: (*json.RawMessage)(&proof), // todo |
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.
What are these todos?
} | ||
return httpmock.NewJsonResponse(200, r) | ||
} | ||
for _, rawTx := range data { |
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 think that generators (or whatever we end up using to generate txns) can do this wrapping - we can even hardcode the VM ID
@ImJeremyHe I have trouble running the new test locally. I made this change for debugging modified system_tests/espresso_test.go
@@ -248,6 +248,7 @@ func TestEspresso(t *testing.T) {
err = waitFor(t, ctx, func() bool {
cnt := node.ConsensusNode.BlockValidator.Validated(t)
expected := arbutil.MessageIndex(expectedMsgCnt)
+ log.Info("Got expected messages", "count", cnt, "need", expected)
return cnt >= expected
})
Require(t, err) At the end I just get
Any ideas? |
I'm running |
|
@sveitser Have you tried to rebuild the replay wasm? |
@ImJeremyHe That was it thanks! |
At least we know now that if validation fails the test also fails. I think we should add a timeout though so we don't wait too long. The test takes about 15 seconds on the CI and 10 seconds locally. So I think setting something like a minute should be safe. The |
@ImJeremyHe Nevermind. I works as intended now 😕 |
LGTM. But I can't approve the PR because I opened it. |
chore: merge from main to develop