11package streams
22
33import (
4+ "bytes"
45 "context"
56 "encoding/json"
67 "fmt"
@@ -10,11 +11,53 @@ import (
1011 "strconv"
1112 "strings"
1213 "testing"
14+ "time"
1315
1416 "github.com/ethereum/go-ethereum/common/hexutil"
15- "github.com/smartcontractkit/data-streams-sdk/go/feed"
17+ "github.com/smartcontractkit/data-streams-sdk/go/v2/ feed"
1618)
1719
20+ // reportResponseEqual compares two ReportResponse structs, handling time.Time comparison properly
21+ func reportResponseEqual (a , b * ReportResponse ) bool {
22+ if a .FeedID != b .FeedID {
23+ return false
24+ }
25+ if ! bytes .Equal (a .FullReport , b .FullReport ) {
26+ return false
27+ }
28+ if ! a .ObservationsTimestamp .Equal (b .ObservationsTimestamp ) {
29+ return false
30+ }
31+ if ! a .ValidFromTimestamp .Equal (b .ValidFromTimestamp ) {
32+ return false
33+ }
34+ return true
35+ }
36+
37+ // reportResponsesEqual compares slices of ReportResponse
38+ func reportResponsesEqual (a , b []* ReportResponse ) bool {
39+ if len (a ) != len (b ) {
40+ return false
41+ }
42+ for i := range a {
43+ if ! reportResponseEqual (a [i ], b [i ]) {
44+ return false
45+ }
46+ }
47+ return true
48+ }
49+
50+ // reportPageEqual compares two ReportPage structs
51+ func reportPageEqual (a , b * ReportPage ) bool {
52+ if ! reportResponsesEqual (a .Reports , b .Reports ) {
53+ return false
54+ }
55+ if a .NextPageTS != b .NextPageTS {
56+ return false
57+ }
58+ return true
59+ }
60+
1861func mustFeedIDfromString (s string ) (f feed.ID ) {
1962 err := f .FromString (s )
2063 if err != nil {
@@ -68,8 +111,8 @@ func TestClient_GetFeeds(t *testing.T) {
68111
69112func TestClient_GetReports (t * testing.T ) {
70113 expectedReports := []* ReportResponse {
71- {FeedID : feed1 , ObservationsTimestamp : 12344 },
72- {FeedID : feed2 , ObservationsTimestamp : 12344 },
114+ {FeedID : feed1 , ObservationsTimestamp : time . Unix ( 12344 , 0 ) },
115+ {FeedID : feed2 , ObservationsTimestamp : time . Unix ( 12344 , 0 ) },
73116 }
74117 expectedFeedIdListStr := fmt .Sprintf ("%s,%s" , feed1 .String (), feed2 .String ())
75118
@@ -111,7 +154,7 @@ func TestClient_GetReports(t *testing.T) {
111154
112155 fmt .Println (expectedReports [0 ], reports [0 ])
113156
114- if ! reflect . DeepEqual (reports , expectedReports ) {
157+ if ! reportResponsesEqual (reports , expectedReports ) {
115158 t .Errorf ("GetFeeds() = %v, want %v" , reports , expectedReports )
116159 }
117160}
@@ -155,7 +198,7 @@ func TestClient_GetLatestReport(t *testing.T) {
155198 t .Fatalf ("GetLatestReport() error = %v" , err )
156199 }
157200
158- if ! reflect . DeepEqual (report , expectedReport ) {
201+ if ! reportResponseEqual (report , expectedReport ) {
159202 t .Errorf ("GetLatestReport() = %v, want %v" , report , expectedReport )
160203 }
161204}
@@ -165,18 +208,18 @@ func TestClient_GetReportPage(t *testing.T) {
165208
166209 expectedReportPage1 := & ReportPage {
167210 Reports : []* ReportResponse {
168- {FeedID : feed1 , ObservationsTimestamp : 1234567890 , FullReport : hexutil .Bytes (`report1 payload` )},
169- {FeedID : feed1 , ObservationsTimestamp : 1234567891 , FullReport : hexutil .Bytes (`report2 payload` )},
211+ {FeedID : feed1 , FullReport : hexutil .Bytes (`report1 payload` ), ObservationsTimestamp : time . Unix ( 1234567897 , 0 )},
212+ {FeedID : feed1 , FullReport : hexutil .Bytes (`report2 payload` ), ObservationsTimestamp : time . Unix ( 1234567898 , 0 )},
170213 },
171- NextPageTS : 1234567892 ,
214+ NextPageTS : 1234567899 , // Last ObservationsTimestamp (1234567898) + 1
172215 }
173216
174217 expectedReportPage2 := & ReportPage {
175218 Reports : []* ReportResponse {
176- {FeedID : feed1 , ObservationsTimestamp : 1234567892 , FullReport : hexutil .Bytes (`report3 payload` )},
177- {FeedID : feed1 , ObservationsTimestamp : 1234567893 , FullReport : hexutil .Bytes (`report4 payload` )},
219+ {FeedID : feed1 , FullReport : hexutil .Bytes (`report3 payload` ), ObservationsTimestamp : time . Unix ( 1234567997 , 0 )},
220+ {FeedID : feed1 , FullReport : hexutil .Bytes (`report4 payload` ), ObservationsTimestamp : time . Unix ( 1234567998 , 0 )},
178221 },
179- NextPageTS : 1234567894 ,
222+ NextPageTS : 1234567999 , // Last ObservationsTimestamp (1234567998) + 1
180223 }
181224
182225 ms := newMockServer (func (w http.ResponseWriter , r * http.Request ) {
@@ -230,7 +273,7 @@ func TestClient_GetReportPage(t *testing.T) {
230273 t .Fatalf ("GetReportPage() error = %v" , err )
231274 }
232275
233- if ! reflect . DeepEqual (reportPage , expectedReportPage1 ) {
276+ if ! reportPageEqual (reportPage , expectedReportPage1 ) {
234277 t .Errorf ("GetReportPage() = %v, want %v" , reportPage , expectedReportPage1 )
235278 }
236279
@@ -239,7 +282,7 @@ func TestClient_GetReportPage(t *testing.T) {
239282 t .Fatalf ("GetReportPage() error = %v" , err )
240283 }
241284
242- if ! reflect . DeepEqual (reportPage , expectedReportPage2 ) {
285+ if ! reportPageEqual (reportPage , expectedReportPage2 ) {
243286 t .Errorf ("GetReportPage() = %v, want %v" , reportPage , expectedReportPage2 )
244287 }
245288}
0 commit comments