@@ -2,12 +2,13 @@ package watcher
22
33import (
44 "context"
5+ "os"
56 "testing"
67
78 "gorm.io/gorm"
89
910 "github.com/scroll-tech/go-ethereum/common"
10- "github.com/scroll-tech/go-ethereum/ethclient "
11+ "github.com/scroll-tech/go-ethereum/core/types "
1112 "github.com/scroll-tech/go-ethereum/rpc"
1213 "github.com/stretchr/testify/assert"
1314
@@ -20,7 +21,7 @@ import (
2021func setupL2Watcher (t * testing.T ) (* L2WatcherClient , * gorm.DB ) {
2122 db := setupDB (t )
2223 l2cfg := cfg .L2Config
23- watcher := NewL2WatcherClient (context .Background (), l2Cli , l2cfg .Confirmations , l2cfg .L2MessageQueueAddress , l2cfg .WithdrawTrieRootSlot , nil , db , nil )
24+ watcher := NewL2WatcherClient (context .Background (), l2Rpc , l2cfg .Confirmations , l2cfg .L2MessageQueueAddress , l2cfg .WithdrawTrieRootSlot , nil , db , false , nil )
2425 return watcher , db
2526}
2627
@@ -34,15 +35,40 @@ func testFetchRunningMissingBlocks(t *testing.T) {
3435 if err != nil {
3536 return false
3637 }
37- wc := prepareWatcherClient (l2Cli , db )
38+ wc := prepareWatcherClient (l2Rpc , db )
3839 wc .TryFetchRunningMissingBlocks (latestHeight )
3940 fetchedHeight , err := l2BlockOrm .GetL2BlocksLatestHeight (context .Background ())
4041 return err == nil && fetchedHeight == latestHeight
4142 })
4243 assert .True (t , ok )
4344}
4445
45- func prepareWatcherClient (l2Cli * ethclient .Client , db * gorm.DB ) * L2WatcherClient {
46+ func prepareWatcherClient (l2Cli * rpc .Client , db * gorm.DB ) * L2WatcherClient {
4647 confirmations := rpc .LatestBlockNumber
47- return NewL2WatcherClient (context .Background (), l2Cli , confirmations , common.Address {}, common.Hash {}, nil , db , nil )
48+ return NewL2WatcherClient (context .Background (), l2Cli , confirmations , common.Address {}, common.Hash {}, nil , db , false , nil )
49+ }
50+
51+ // New test for raw RPC GetBlockByHash from an endpoint URL in env.
52+ func TestRawRPCGetBlockByHash (t * testing.T ) {
53+ url := os .Getenv ("RPC_ENDPOINT_URL" )
54+ if url == "" {
55+ t .Log ("warn: RPC_ENDPOINT_URL not set, skipping raw RPC test" )
56+ t .Skip ("missing RPC_ENDPOINT_URL" )
57+ }
58+
59+ ctx := context .Background ()
60+ cli , err := rpc .DialContext (ctx , url )
61+ if err != nil {
62+ t .Fatalf ("failed to dial RPC endpoint %s: %v" , url , err )
63+ }
64+ defer cli .Close ()
65+
66+ var txs []* types.Transaction
67+ blkHash := common .HexToHash ("0xc80cf12883341827d71c08f734ba9a9d6da7e59eb16921d26e6706887e552c74" )
68+ err = cli .CallContext (ctx , & txs , "scroll_getL1MessagesInBlock" , blkHash , "synced" )
69+ if err != nil {
70+ t .Logf ("scroll_getL1MessagesInBlock failed: err=%v" , err )
71+ t .Fail ()
72+ }
73+ t .Log (txs , txs [0 ].Hash ())
4874}
0 commit comments