Skip to content

Commit 449c097

Browse files
committed
Merge branch 'ryan/fix-test' into 'main'
Fix broken test See merge request flarenetwork/FSP/flare-system-c-chain-indexer!76
2 parents a22fd80 + 8cc0759 commit 449c097

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/ethereum/go-ethereum v1.13.8
1111
github.com/go-sql-driver/mysql v1.9.3
1212
github.com/gorilla/mux v1.8.1
13+
github.com/joho/godotenv v1.5.1
1314
github.com/pkg/errors v0.9.1
1415
github.com/stretchr/testify v1.11.1
1516
go.uber.org/zap v1.27.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
132132
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
133133
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
134134
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
135+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
136+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
135137
github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw=
136138
github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4=
137139
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=

main_test.go

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ package main_test
22

33
import (
44
"context"
5-
"flare-ftso-indexer/chain"
6-
"flare-ftso-indexer/config"
7-
"flare-ftso-indexer/database"
8-
"flare-ftso-indexer/indexer"
95
"os"
106
"strconv"
117
"strings"
128
"testing"
9+
"time"
10+
11+
"flare-ftso-indexer/chain"
12+
"flare-ftso-indexer/config"
13+
"flare-ftso-indexer/database"
14+
"flare-ftso-indexer/indexer"
1315

1416
"github.com/BurntSushi/toml"
1517
"github.com/bradleyjkemp/cupaloy/v2"
1618
"github.com/ethereum/go-ethereum/common"
19+
_ "github.com/joho/godotenv/autoload"
1720
"github.com/pkg/errors"
1821
"github.com/stretchr/testify/require"
1922
"github.com/stretchr/testify/suite"
@@ -25,6 +28,7 @@ const (
2528
startBlock = 6446256
2629
endBlockHistory = 6447813
2730
endBlockContinuous = 6446306
31+
testTimeout = 10 * time.Second
2832
)
2933

3034
type testConfig struct {
@@ -55,35 +59,44 @@ type IntegrationIndexHistorySuite struct {
5559
}
5660

5761
func TestIntegrationIndexContinuous(t *testing.T) {
62+
ctx := context.Background()
5863
testSuite := new(IntegrationIndexContinuousSuite)
59-
err := testSuite.prepareSuite(false)
64+
err := testSuite.prepareSuite(ctx, false)
6065
if err != nil {
6166
t.Fatal("Could not prepare the test suite:", err)
6267
}
6368
suite.Run(t, testSuite)
6469
}
6570

6671
func TestIntegrationIndexHistory(t *testing.T) {
72+
ctx := context.Background()
6773
testSuite := new(IntegrationIndexHistorySuite)
68-
err := testSuite.prepareSuite(true)
74+
err := testSuite.prepareSuite(ctx, true)
6975
if err != nil {
7076
t.Fatal("Could not prepare the test suite")
7177
}
7278
suite.Run(t, testSuite)
7379
}
7480

75-
func (suite *IntegrationIndexContinuousSuite) SetupSuite(ctx context.Context) {
81+
func (suite *IntegrationIndexContinuousSuite) SetupSuite() {
82+
ctx := context.Background()
83+
7684
err := suite.indexer.IndexContinuous(ctx, startBlock)
7785
require.NoError(suite.T(), err, "Could not run the indexer")
7886
}
7987

80-
func (suite *IntegrationIndexHistorySuite) SetupSuite(ctx context.Context) {
88+
func (suite *IntegrationIndexHistorySuite) SetupSuite() {
89+
ctx := context.Background()
90+
8191
lastIndex, err := suite.indexer.IndexHistory(ctx)
8292
require.NoError(suite.T(), err, "Could not run the indexer")
8393
require.Equal(suite.T(), uint64(endBlockHistory), lastIndex, "Last indexed block does not match expected value")
8494
}
8595

86-
func (suite *IntegrationIndex) TestCheckBlocks(ctx context.Context) {
96+
func (suite *IntegrationIndex) TestCheckBlocks() {
97+
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
98+
defer cancel()
99+
87100
var blocks []database.Block
88101
result := suite.db.WithContext(ctx).Order("hash ASC").Find(&blocks)
89102
require.NoError(suite.T(), result.Error, "Could not find blocks")
@@ -96,7 +109,10 @@ func (suite *IntegrationIndex) TestCheckBlocks(ctx context.Context) {
96109
cupaloy.SnapshotT(suite.T(), blocks)
97110
}
98111

99-
func (suite *IntegrationIndex) TestCheckTransactions(ctx context.Context) {
112+
func (suite *IntegrationIndex) TestCheckTransactions() {
113+
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
114+
defer cancel()
115+
100116
var transactions []database.Transaction
101117
result := suite.db.WithContext(ctx).Order("hash ASC").Find(&transactions)
102118
require.NoError(suite.T(), result.Error, "Could not find transactions")
@@ -109,7 +125,10 @@ func (suite *IntegrationIndex) TestCheckTransactions(ctx context.Context) {
109125
cupaloy.SnapshotT(suite.T(), transactions)
110126
}
111127

112-
func (suite *IntegrationIndex) TestCheckLogs(ctx context.Context) {
128+
func (suite *IntegrationIndex) TestCheckLogs() {
129+
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
130+
defer cancel()
131+
113132
var logs []database.Log
114133
result := suite.db.WithContext(ctx).
115134
Preload("Transaction").
@@ -125,8 +144,7 @@ func (suite *IntegrationIndex) TestCheckLogs(ctx context.Context) {
125144
cupaloy.SnapshotT(suite.T(), logs)
126145
}
127146

128-
func (suite *IntegrationIndex) prepareSuite(isHistory bool) error {
129-
ctx := context.Background()
147+
func (suite *IntegrationIndex) prepareSuite(ctx context.Context, isHistory bool) error {
130148
tCfg := testConfig{}
131149

132150
_, err := toml.DecodeFile("testing/config_test.toml", &tCfg)

0 commit comments

Comments
 (0)