-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsource_txresults_test.go
More file actions
52 lines (42 loc) · 1.5 KB
/
source_txresults_test.go
File metadata and controls
52 lines (42 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package monitoring
import (
"context"
"encoding/json"
"os"
"testing"
"time"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring"
"github.com/smartcontractkit/chainlink-cosmos/pkg/monitoring/fcdclient"
fcdclientmocks "github.com/smartcontractkit/chainlink-cosmos/pkg/monitoring/fcdclient/mocks"
)
func TestTxResultsSource(t *testing.T) {
t.Run("should correcly count failed and succeeded transactions", func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
chainConfig := generateChainConfig(t)
feedConfig := generateFeedConfig(t)
fcdClient := new(fcdclientmocks.Client)
factory := NewTxResultsSourceFactory(fcdClient)
source, err := factory.NewSource(chainConfig, feedConfig)
require.NoError(t, err)
// Setup mocks
getTxsRaw, err := os.ReadFile("./fixtures/txs.json")
require.NoError(t, err)
getTxsRes := fcdclient.Response{}
require.NoError(t, json.Unmarshal(getTxsRaw, &getTxsRes))
fcdClient.On("GetTxList",
mock.Anything, // context
fcdclient.GetTxListParams{Account: feedConfig.ContractAddress, Limit: 10},
).Return(getTxsRes, nil).Once()
// Execute Fetch()
data, err := source.Fetch(ctx)
require.NoError(t, err)
// Assertions
txResults, ok := data.(relayMonitoring.TxResults)
require.True(t, ok)
require.Equal(t, uint64(94), txResults.NumSucceeded)
require.Equal(t, uint64(6), txResults.NumFailed)
})
}