@@ -20,32 +20,25 @@ import (
2020 "context"
2121 "errors"
2222 "fmt"
23+ "math/big"
2324 "os"
2425 "testing"
2526
26- "github.com/ipfs/go-cid"
2727 "github.com/jmoiron/sqlx"
28- "github.com/multiformats/go-multihash"
2928 "github.com/stretchr/testify/require"
3029
3130 "github.com/ethereum/go-ethereum/core/types"
3231 "github.com/ethereum/go-ethereum/params"
33- "github.com/ethereum/go-ethereum/rlp"
3432 "github.com/ethereum/go-ethereum/statediff/indexer/database/file"
3533 "github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
3634 "github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
37- "github.com/ethereum/go-ethereum/statediff/indexer/ipld"
3835 "github.com/ethereum/go-ethereum/statediff/indexer/mocks"
3936 "github.com/ethereum/go-ethereum/statediff/indexer/test_helpers"
4037)
4138
4239var (
43- testBlock * types.Block
44- testReceipts types.Receipts
45- testHeaderCID cid.Cid
46- sqlxdb * sqlx.DB
47- err error
48- chainConf = params .MainnetChainConfig
40+ sqlxdb * sqlx.DB
41+ chainConf = params .MainnetChainConfig
4942)
5043
5144func init () {
@@ -55,13 +48,35 @@ func init() {
5548 }
5649}
5750
58- func setup (t * testing.T ) {
59- testBlock , testReceipts , err = TestBlocksAndReceiptsFromEnv ()
60- require .NoError (t , err )
61- headerRLP , err := rlp .EncodeToBytes (testBlock .Header ())
51+ func TestPushBlockAndState (t * testing.T ) {
52+ conf := DefaultTestConfig
53+ rawURL := os .Getenv (TEST_RAW_URL )
54+ if rawURL == "" {
55+ fmt .Printf ("Warning: no raw url configured for statediffing mainnet tests, will look for local file and" +
56+ "then try default endpoint (%s)\r \n " , DefaultTestConfig .RawURL )
57+ } else {
58+ conf .RawURL = rawURL
59+ }
60+ for _ , blockNumber := range problemBlocks {
61+ conf .BlockNumber = big .NewInt (blockNumber )
62+ tb , trs , err := TestBlockAndReceipts (conf )
63+ require .NoError (t , err )
64+ testPushBlockAndState (t , tb , trs )
65+ }
66+ testBlock , testReceipts , err := TestBlockAndReceiptsFromEnv (conf )
6267 require .NoError (t , err )
68+ testPushBlockAndState (t , testBlock , testReceipts )
69+ }
6370
64- testHeaderCID , _ = ipld .RawdataToCid (ipld .MEthHeader , headerRLP , multihash .KECCAK_256 )
71+ func testPushBlockAndState (t * testing.T , block * types.Block , receipts types.Receipts ) {
72+ t .Run ("Test PushBlock and PushStateNode" , func (t * testing.T ) {
73+ setup (t , block , receipts )
74+ dumpData (t )
75+ tearDown (t )
76+ })
77+ }
78+
79+ func setup (t * testing.T , testBlock * types.Block , testReceipts types.Receipts ) {
6580 if _ , err := os .Stat (file .TestConfig .FilePath ); ! errors .Is (err , os .ErrNotExist ) {
6681 err := os .Remove (file .TestConfig .FilePath )
6782 require .NoError (t , err )
@@ -113,11 +128,3 @@ func tearDown(t *testing.T) {
113128 err = sqlxdb .Close ()
114129 require .NoError (t , err )
115130}
116-
117- func TestPushBlockAndState (t * testing.T ) {
118- t .Run ("Test PushBlock and PushStateNode" , func (t * testing.T ) {
119- setup (t )
120- dumpData (t )
121- tearDown (t )
122- })
123- }
0 commit comments