@@ -2,18 +2,21 @@ package main_test
22
33import (
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
3034type testConfig struct {
@@ -55,35 +59,44 @@ type IntegrationIndexHistorySuite struct {
5559}
5660
5761func 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
6671func 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