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

Tests for invalid transaction handling #18

Merged
merged 1 commit into from
Dec 6, 2023
Merged

Conversation

sveitser
Copy link

@sveitser sveitser commented Nov 30, 2023

  • 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

@ImJeremyHe ImJeremyHe force-pushed the jh/tests branch 11 times, most recently from 0b311b7 to fc8a1f5 Compare December 5, 2023 08:49
@ImJeremyHe ImJeremyHe marked this pull request as ready for review December 5, 2023 08:51
@ImJeremyHe ImJeremyHe force-pushed the jh/tests branch 3 times, most recently from 89816cc to 735bbb5 Compare December 5, 2023 09:15

func espresso_block_txs_generators(t *testing.T, l2Info *BlockchainTestInfo) map[int][][]byte {
return map[int][][]byte{
5: onlyMalformedTxs(t),
Copy link

@nomaxg nomaxg Dec 5, 2023

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

Copy link
Member

@ImJeremyHe ImJeremyHe Dec 6, 2023

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.

Copy link
Author

@sveitser sveitser Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func(req *http.Request) (*http.Response, error) {
log.Info("GET", "url", req.URL)
block := uint64(httpmock.MustGetSubmatchAsUint(req, 1))
// todo
Copy link

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These todos 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now todos are removed and a comment is left.

"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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this log necessary?

Copy link
Member

@ImJeremyHe ImJeremyHe Dec 6, 2023

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.

})

generators := espresso_block_txs_generators(t, l2Info)
dummyProof := func(n int) []byte {
Copy link

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

log.Info("GET", "url", req.URL)
if !ok {
r := espresso.NamespaceResponse{
Proof: (*json.RawMessage)(&proof), // todo
Copy link

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 {
Copy link

@nomaxg nomaxg Dec 5, 2023

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

@sveitser
Copy link
Author

sveitser commented Dec 6, 2023

@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

NFO [12-06|12:34:06.788] Got expected messages                    count=2 need=4
INFO [12-06|12:34:07.789] Got expected messages                    count=2 need=4
INFO [12-06|12:34:08.349] GET                                      url=http://127.0.0.1:50000/availability/header/101
INFO [12-06|12:34:08.350] Fetching tx, block: 101, namespace: 100
ERROR[12-06|12:34:08.350] request failed                           err=nil                              url=http://127.0.0.1:50000/availability/block/101/namespace/100 status=404 response=0
ERROR[12-06|12:34:08.350] Error fetching transactions              err="request failed with status 404"
INFO [12-06|12:34:08.789] Got expected messages                    count=2 need=4
    espresso_test.go:254:  [] context deadline exceeded
ERROR[12-06|12:34:09.774] Failed to write trie to disk             err="pebble: closed"
ERROR[12-06|12:34:09.774] failed writing latest valid block state to DB err="pebble: closed"
INFO [12-06|12:34:13.350] GET                                      url=http://127.0.0.1:50000/availability/header/101
INFO [12-06|12:34:13.350] Fetching tx, block: 101, namespace: 100

log.txt

Any ideas?

@sveitser
Copy link
Author

sveitser commented Dec 6, 2023

I'm running go test -v -run TestEspresso ./system_tests/

@sveitser
Copy link
Author

sveitser commented Dec 6, 2023

ERROR[12-06|12:36:31.065] Error during validation                  err="validation failed: expected {0x7854bc708e7a4e54b7fd6b0a69a5a558c50d132c27404927cbb76bd06f3eb353 0x0000000000000000000000000000000000000000000000000000000000000000 1 2} got {0xd57c5b5a1264a69882f2e5316eb61ba5f62754765d266cb41c42651f2afb0e94 0x0000000000000000000000000000000000000000000000000000000000000000 1 2}"
common_test.go:859: error occurred: validation failed: expected {0x7854bc708e7a4e54b7fd6b0a69a5a558c50d132c27404927cbb76bd06f3eb353 0x0000000000000000000000000000000000000000000000000000000000000000 1 2} got {0xd57c5b5a1264a69882f2e5316eb61ba5f62754765d266cb41c42651f2afb0e94 0x0000000000000000000000000000000000000000000000000000000000000000 1 2}

@ImJeremyHe
Copy link
Member

ImJeremyHe commented Dec 6, 2023

@sveitser Have you tried to rebuild the replay wasm?

@sveitser
Copy link
Author

sveitser commented Dec 6, 2023

@ImJeremyHe That was it thanks!

@sveitser
Copy link
Author

sveitser commented Dec 6, 2023

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 waitFor looks like it has a 30 seconds timeout but that doesn't seem to be the case.

@sveitser
Copy link
Author

sveitser commented Dec 6, 2023

@ImJeremyHe Nevermind. I works as intended now 😕

@sveitser
Copy link
Author

sveitser commented Dec 6, 2023

LGTM. But I can't approve the PR because I opened it.

@ImJeremyHe ImJeremyHe merged commit 618eb65 into integration Dec 6, 2023
5 checks passed
@ImJeremyHe ImJeremyHe deleted the jh/tests branch December 6, 2023 12:40
zacshowa pushed a commit that referenced this pull request Nov 26, 2024
chore: merge from main to develop
zacshowa pushed a commit that referenced this pull request Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants