Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJeremyHe committed Dec 1, 2023
1 parent 6006cb2 commit 190a002
Showing 1 changed file with 58 additions and 10 deletions.
68 changes: 58 additions & 10 deletions system_tests/espresso_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package arbtest

import (
"context"
"encoding/json"
"net/http"
"testing"
"time"
Expand All @@ -14,7 +15,7 @@ import (

func block_txs_generators() map[int](func() [][]byte) {
return map[int](func() [][]byte){
// 4: onlyMalformedTxs,
4: onlyMalformedTxs,
}
}

Expand Down Expand Up @@ -50,18 +51,23 @@ func createMockHotShot(ctx context.Context) func() {
})

generators := block_txs_generators()
dummyProof, _ := json.Marshal(map[int]int{0: 0})

httpmock.RegisterResponder(
"GET",
`=~http://127.0.0.1:50000/availability/block/(\d+)/namespace/100`,
func(req *http.Request) (*http.Response, error) {
log.Info("GET", "url", req.URL)
txes := []espresso.Transaction{}
block := int(httpmock.MustGetSubmatchAsInt(req, 1))
getData, ok := generators[block]
if block > 100 {
// make the debug message more cleaner
return httpmock.NewJsonResponse(404, 0)
}
log.Info("GET", "url", req.URL)
if !ok {
r := espresso.NamespaceResponse{
Proof: nil, // todo
Proof: (*json.RawMessage)(&dummyProof), // todo
Transactions: &[]espresso.Transaction{},
}
return httpmock.NewJsonResponse(200, r)
Expand All @@ -74,7 +80,7 @@ func createMockHotShot(ctx context.Context) func() {
txes = append(txes, tx)
}
resp := espresso.NamespaceResponse{
Proof: nil, // todo
Proof: (*json.RawMessage)(&dummyProof), // todo
Transactions: &txes,
}
return httpmock.NewJsonResponse(200, resp)
Expand All @@ -85,6 +91,7 @@ func createMockHotShot(ctx context.Context) func() {

func createL2Node(ctx context.Context, t *testing.T, hotshot_url string) (*TestClient, func()) {
builder := NewNodeBuilder(ctx).DefaultConfig(t, false)
builder.takeOwnership = false
builder.nodeConfig.DelayedSequencer.Enable = true
builder.nodeConfig.Sequencer = true
builder.nodeConfig.Espresso = true
Expand All @@ -99,7 +106,20 @@ func createL2Node(ctx context.Context, t *testing.T, hotshot_url string) (*TestC
}

func createPosterNode(ctx context.Context, t *testing.T) (*TestClient, func()) {
return nil, nil
builder := NewNodeBuilder(ctx).DefaultConfig(t, true)
builder.nodeConfig.Feed.Input.URL = []string{"ws://127.0.0.1:9642"}
builder.nodeConfig.BatchPoster.Enable = true

cleanup := builder.Build(t)
return builder.L2, cleanup
}

func createValidatorNode(ctx context.Context, t *testing.T) (*TestClient, func()) {
builder := NewNodeBuilder(ctx).DefaultConfig(t, false)
builder.nodeConfig.BlockValidator.Enable = true

cleanup := builder.Build(t)
return builder.L2, cleanup
}

func waitForMsgCnt(
Expand All @@ -108,13 +128,11 @@ func waitForMsgCnt(
expectedCnt int,
client *TestClient,
) error {
t.Log("????")
ctx, cancel := context.WithTimeout(ctxinput, 3000*time.Second)
defer cancel()

for {
cnt, _ := client.ConsensusNode.TxStreamer.GetMessageCount()
t.Log(cnt)
expected := arbutil.MessageIndex(expectedCnt)
if cnt >= expected {
return nil
Expand All @@ -127,19 +145,49 @@ func waitForMsgCnt(
}
}

func waitForBatchCnt(
t *testing.T,
ctxinput context.Context,
expected uint64,
client *TestClient,
) error {
ctx, cancel := context.WithTimeout(ctxinput, 3000*time.Second)
defer cancel()

for {
cnt, _ := client.ConsensusNode.InboxTracker.GetBatchCount()
if cnt >= expected {
return nil
}
select {
case <-time.After(time.Second):
case <-ctx.Done():
return ctx.Err()
}
}
}

func TestEspresso(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

t.Log("creating hotshot node")
cleanHotShot := createMockHotShot(ctx)
defer cleanHotShot()

t.Log("creating l2 node")
l2Node, cleanL2Node := createL2Node(ctx, t, "http://127.0.0.1:50000")
defer cleanL2Node()

err := waitForMsgCnt(t, ctx, 4, l2Node)
// An initial message and message should be produced per block containing txs
expectedMsgCnt := 1 + len(block_txs_generators())
err := waitForMsgCnt(t, ctx, expectedMsgCnt, l2Node)
Require(t, err)

poster, cleanPoster := createPosterNode(ctx, t)
defer cleanPoster()
err = waitForBatchCnt(t, ctx, uint64(expectedMsgCnt), poster)
Require(t, err)

_, cleanValidator := createValidatorNode(ctx, t)
defer cleanValidator()

}

0 comments on commit 190a002

Please sign in to comment.