-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathexecutor_test.go
More file actions
744 lines (661 loc) · 20.5 KB
/
executor_test.go
File metadata and controls
744 lines (661 loc) · 20.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
package taskengine
import (
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/AvaProtocol/EigenLayer-AVS/core/testutil"
"github.com/AvaProtocol/EigenLayer-AVS/model"
"github.com/AvaProtocol/EigenLayer-AVS/pkg/gow"
avsproto "github.com/AvaProtocol/EigenLayer-AVS/protobuf"
"github.com/AvaProtocol/EigenLayer-AVS/storage"
"google.golang.org/protobuf/types/known/structpb"
)
func TestExecutorRunTaskSucess(t *testing.T) {
SetRpc(testutil.GetTestRPCURL())
SetCache(testutil.GetDefaultCache())
db := testutil.TestMustDB()
defer storage.Destroy(db.(*storage.BadgerStorage))
// Set up a test HTTP server
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Simulate a response with "I'm hit"
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"message": "I'm hit"}`))
}))
defer server.Close()
nodes := []*avsproto.TaskNode{
{
Id: "branch1",
Name: "branch",
TaskType: &avsproto.TaskNode_Branch{
Branch: &avsproto.BranchNode{
Config: &avsproto.BranchNode_Config{
Conditions: []*avsproto.BranchNode_Condition{
{
Id: "a1",
Type: "if",
// The test data is of this transaction https://sepolia.etherscan.io/tx/0x53beb2163994510e0984b436ebc828dc57e480ee671cfbe7ed52776c2a4830c8 which is 3.45 token
Expression: "Number(triggertest.data.valueFormatted) >= 3",
},
},
},
},
},
},
{
Id: "notification1",
Name: "httpnode",
TaskType: &avsproto.TaskNode_RestApi{
RestApi: &avsproto.RestAPINode{
Config: &avsproto.RestAPINode_Config{
Url: server.URL, // Use the test server URL
Method: "POST",
Body: "hit=notification1",
},
},
},
},
}
trigger := &avsproto.TaskTrigger{
Id: "triggertest",
Name: "triggertest",
}
edges := []*avsproto.TaskEdge{
{
Id: "e1",
Source: trigger.Id,
Target: "branch1",
},
{
Id: "e2",
Source: "branch1.a1",
Target: "notification1",
},
}
task := &model.Task{
Task: &avsproto.Task{
Id: "TaskID123",
Nodes: nodes,
Edges: edges,
Trigger: trigger,
},
}
executor := NewExecutorForTesting(testutil.GetTestSmartWalletConfig(), db, testutil.GetLogger())
triggerData := testutil.GetTestEventTriggerDataWithTransferData()
execution, err := executor.RunTask(task, &QueueExecutionData{
TriggerType: triggerData.Type,
TriggerOutput: triggerData.Output,
ExecutionID: "exec123",
})
if err != nil {
t.Errorf("expect no error but got %v", err)
}
if execution.Status != avsproto.ExecutionStatus_EXECUTION_STATUS_SUCCESS {
t.Errorf("Expect success status but got failure")
}
if execution.Error != "" {
t.Errorf("Expect no error but got: %s", execution.Error)
}
// Validate by IDs instead of fixed indices to be robust to scheduler ordering
hasBranch := false
hasNotification := false
for _, s := range execution.Steps {
if s.Id == "branch1" {
hasBranch = true
}
if s.Id == "notification1" {
hasNotification = true
}
}
if !hasBranch || !hasNotification {
t.Fatalf("Expected both branch1 and notification1 steps; gotBranch=%v gotNotification=%v (total=%d)", hasBranch, hasNotification, len(execution.Steps))
}
// Find the notification1 step to inspect its output
var notifStep *avsproto.Execution_Step
for i := range execution.Steps {
if execution.Steps[i].Id == "notification1" {
notifStep = execution.Steps[i]
break
}
}
if notifStep == nil {
t.Fatalf("notification1 step not found in execution steps")
}
outputData := gow.ValueToMap(notifStep.GetRestApi().Data)
bodyData := outputData["data"].(map[string]interface{})
if bodyData["message"].(string) != "I'm hit" {
t.Errorf("expect message to be 'I'm hit' but got %s", bodyData["message"])
}
}
func TestExecutorRunTaskWithBranchSilentFailureBehavior(t *testing.T) {
SetRpc(testutil.GetTestRPCURL())
SetCache(testutil.GetDefaultCache())
db := testutil.TestMustDB()
defer storage.Destroy(db.(*storage.BadgerStorage))
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"message":"ok"}`))
}))
defer ts.Close()
nodes := []*avsproto.TaskNode{
{
Id: "branch1",
Name: "branch",
TaskType: &avsproto.TaskNode_Branch{
Branch: &avsproto.BranchNode{
Config: &avsproto.BranchNode_Config{
Conditions: []*avsproto.BranchNode_Condition{
{
Id: "a1",
Type: "if",
Expression: "a >= 5", // Variable 'a' doesn't exist - should be treated as false
},
},
},
},
},
},
{
Id: "notification1",
Name: "httpnode",
TaskType: &avsproto.TaskNode_RestApi{
RestApi: &avsproto.RestAPINode{
Config: &avsproto.RestAPINode_Config{
Url: ts.URL,
Method: "POST",
Body: "hit=notification1",
},
},
},
},
}
trigger := &avsproto.TaskTrigger{
Id: "triggertest",
Name: "triggertest",
}
edges := []*avsproto.TaskEdge{
{
Id: "e1",
Source: trigger.Id,
Target: "branch1",
},
{
Id: "e2",
Source: "branch1.a1",
Target: "notification1",
},
}
task := &model.Task{
Task: &avsproto.Task{
Id: "TaskID123",
Nodes: nodes,
Edges: edges,
Trigger: trigger,
},
}
executor := NewExecutorForTesting(testutil.GetTestSmartWalletConfig(), db, testutil.GetLogger())
triggerData := testutil.GetTestEventTriggerData()
execution, err := executor.RunTask(task, &QueueExecutionData{
TriggerType: triggerData.Type,
TriggerOutput: triggerData.Output,
ExecutionID: "exec123",
})
// With silent failure behavior, branch nodes no longer hard fail - they succeed but no condition matches
if err != nil {
t.Errorf("Expected no error with silent failure behavior, but got: %v", err)
}
// Branch workflows with skipped nodes are SUCCESS — the workflow executed its
// chosen path correctly; skipping nodes due to branching is expected behavior.
if execution.Status != avsproto.ExecutionStatus_EXECUTION_STATUS_SUCCESS {
t.Errorf("Expected success status (branch path with skipped nodes is normal), but got: %v with error: %s", execution.Status, execution.Error)
}
// No error when all executed steps succeeded
if execution.Error != "" {
t.Errorf("Expected empty error for successful branch execution, but got: %s", execution.Error)
}
// Find the branch step regardless of ordering
var branchStep *avsproto.Execution_Step
for _, s := range execution.Steps {
if s.Id == "branch1" {
branchStep = s
break
}
}
if branchStep == nil {
t.Fatalf("branch1 step not found; steps=%d", len(execution.Steps))
}
// Branch should succeed but no condition should be matched
if !branchStep.Success {
t.Errorf("Expected branch to succeed with silent failure behavior, but got failure: %s", branchStep.Error)
}
// The output should be nil since no condition was matched
if branchStep.OutputData != nil {
t.Errorf("Expected no branch output since no condition matched, but got output")
}
}
func TestExecutorRunTaskComputeSuccessFalseWhenANodeFailedToRun(t *testing.T) {
// Set up a test HTTP server that returns a 503 status code
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusServiceUnavailable)
}))
defer server.Close()
SetRpc(testutil.GetTestRPCURL())
SetCache(testutil.GetDefaultCache())
db := testutil.TestMustDB()
defer storage.Destroy(db.(*storage.BadgerStorage))
nodes := []*avsproto.TaskNode{
{
Id: "branch1",
Name: "branch",
TaskType: &avsproto.TaskNode_Branch{
Branch: &avsproto.BranchNode{
Config: &avsproto.BranchNode_Config{
Conditions: []*avsproto.BranchNode_Condition{
{
Id: "condition1",
Type: "if",
Expression: "true",
},
},
},
},
},
},
{
Id: "rest1",
Name: "httpnode",
TaskType: &avsproto.TaskNode_RestApi{
RestApi: &avsproto.RestAPINode{
Config: &avsproto.RestAPINode_Config{
Url: server.URL, // Use the test server URL
Method: "POST",
Body: "hit=notification1",
},
},
},
},
}
trigger := &avsproto.TaskTrigger{
Id: "triggertest",
Name: "triggertest",
}
edges := []*avsproto.TaskEdge{
{
Id: "e1",
Source: trigger.Id,
Target: "branch1",
},
{
Id: "e2",
Source: "branch1.condition1",
Target: "rest1",
},
}
task := &model.Task{
Task: &avsproto.Task{
Id: "TaskID123",
Nodes: nodes,
Edges: edges,
Trigger: trigger,
},
}
executor := NewExecutorForTesting(testutil.GetTestSmartWalletConfig(), db, testutil.GetLogger())
triggerData := testutil.GetTestEventTriggerData()
execution, err := executor.RunTask(task, &QueueExecutionData{
TriggerType: triggerData.Type,
TriggerOutput: triggerData.Output,
ExecutionID: "exec123",
})
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if execution.Status == avsproto.ExecutionStatus_EXECUTION_STATUS_SUCCESS {
t.Errorf("Expected failure status when a node fails (HTTP 503), but got success")
}
if len(execution.Steps) != 3 {
t.Errorf("Expect evaluate 3 nodes (trigger + 2 workflow nodes) but got: %d", len(execution.Steps))
}
// Check branch1 step at index 0 (no trigger step in regular executions)
if execution.Steps[1].Id != "branch1" {
t.Errorf("step id doesn't match, expect branch1 but got: %s", execution.Steps[1].Id)
}
// Check rest1 step at index 1
// if execution.Steps[1].Id != "rest1" {
// t.Errorf("step id doesn't match, expect rest1 but got: %s", execution.Steps[2].Id)
// }
// Verify that the REST API step correctly failed with 503 status code
if execution.Steps[2].Success {
t.Errorf("REST API step should fail with 503 status (HTTP errors are failures), but got success")
}
// The 503 status code should be available in the step's output data for workflow logic to handle
if execution.Steps[1].OutputData == nil {
t.Error("Expected REST API step to have output data")
}
}
// TestExecutorRunTaskReturnAllExecutionData to test the happy path and return all the relevant data a task needed
func TestExecutorRunTaskReturnAllExecutionData(t *testing.T) {
SetRpc(testutil.GetTestRPCURL())
SetCache(testutil.GetDefaultCache())
db := testutil.TestMustDB()
defer storage.Destroy(db.(*storage.BadgerStorage))
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Simulate a response with "I'm hit"
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"message": "I'm hit"}`))
}))
defer server.Close()
nodes := []*avsproto.TaskNode{
{
Id: "spacex",
Name: "spacex",
TaskType: &avsproto.TaskNode_GraphqlQuery{
GraphqlQuery: &avsproto.GraphQLQueryNode{
Config: &avsproto.GraphQLQueryNode_Config{
Url: "https://spacex-production.up.railway.app/",
Query: `
query Launch {
company {
ceo
}
launches(limit: 2, sort: "launch_date_unix", order: "ASC") {
id
mission_name
}
}
`,
},
},
},
},
{
Id: "branch1",
Name: "branch",
TaskType: &avsproto.TaskNode_Branch{
Branch: &avsproto.BranchNode{
Config: &avsproto.BranchNode_Config{
Conditions: []*avsproto.BranchNode_Condition{
{
Id: "condition1",
Type: "if",
Expression: "Number(triggertest.data.valueFormatted) >= 3",
},
},
},
},
},
},
{
Id: "customcode1",
Name: "dummy",
TaskType: &avsproto.TaskNode_CustomCode{
CustomCode: &avsproto.CustomCodeNode{
Config: &avsproto.CustomCodeNode_Config{
// Just logout the data so we can assert from the output
Source: "JSON.stringify(triggertest.data)",
},
},
},
},
{
Id: "rest1",
Name: "http",
TaskType: &avsproto.TaskNode_RestApi{
RestApi: &avsproto.RestAPINode{
Config: &avsproto.RestAPINode_Config{
Url: server.URL, // Use the test server URL
Method: "POST",
Body: "hit=notification1",
},
},
},
},
}
trigger := &avsproto.TaskTrigger{
Id: "triggertest",
Name: "triggertest",
}
edges := []*avsproto.TaskEdge{
{
Id: "e0",
Source: trigger.Id,
Target: "spacex",
},
{
Id: "e1",
Source: "spacex",
Target: "branch1",
},
{
Id: "e3",
Source: "branch1.condition1",
Target: "customcode1",
},
{
Id: "e2",
Source: "customcode1",
Target: "rest1",
},
}
task := &model.Task{
Task: &avsproto.Task{
Id: "TaskID123",
Nodes: nodes,
Edges: edges,
Trigger: trigger,
},
}
// Create executor
executor := NewExecutorForTesting(testutil.GetTestSmartWalletConfig(), db, testutil.GetLogger())
// Get the event trigger data with EvmLog data
testTriggerData := testutil.GetTestEventTriggerData()
// Convert to taskengine.TriggerData
triggerData := &TriggerData{
Type: testTriggerData.Type,
Output: testTriggerData.Output,
}
// Get the mock transfer log data for testing
transferTriggerData := testutil.GetTestEventTriggerDataWithTransferData()
// For this test, we need to test the execution with transfer log data
// So we'll override the RunTask method behavior by calling the VM directly
secrets, _ := LoadSecretForTask(executor.db, task)
// Extract the Data field from EventTrigger_Output
var transferLog *structpb.Value
if eventOutput, ok := transferTriggerData.Output.(*avsproto.EventTrigger_Output); ok {
transferLog = eventOutput.Data
}
vm, err := NewVMWithDataAndTransferLog(task, triggerData, executor.smartWalletConfig, secrets, transferLog)
if err != nil {
t.Fatalf("error creating VM: %v", err)
}
vm.WithLogger(executor.logger).WithDb(executor.db)
// Execute the task
err = vm.Compile()
if err != nil {
t.Fatalf("error compiling task: %v", err)
}
runErr := vm.Run()
if runErr != nil {
t.Fatalf("error running task: %v", runErr)
}
// Create execution result similar to what RunTask would create
t0 := time.Now()
t1 := time.Now()
execution := &avsproto.Execution{
Id: "test_exec123",
StartAt: t0.UnixMilli(),
EndAt: t1.UnixMilli(),
Status: avsproto.ExecutionStatus_EXECUTION_STATUS_SUCCESS,
Error: "",
Steps: vm.ExecutionLogs,
Index: 0, // Test execution
}
if runErr != nil {
execution.Error = runErr.Error()
execution.Status = avsproto.ExecutionStatus_EXECUTION_STATUS_FAILED
}
if execution.Id != "test_exec123" {
t.Errorf("expect execution id is test_exec123 but got: %s", execution.Id)
}
if execution.Status != avsproto.ExecutionStatus_EXECUTION_STATUS_SUCCESS {
t.Errorf("expect success status but got failure")
}
if err != nil || execution.Error != "" {
t.Errorf("expect no error but got: %s", execution.Error)
}
if execution.StartAt <= 0 {
t.Errorf("expect start at is set but got: %d", execution.StartAt)
}
if execution.EndAt <= 0 {
t.Errorf("expect end at is set but got: %d", execution.EndAt)
}
}
// TestBlockTriggerOutputDataStructure tests that block trigger output data is properly structured
// This replaces the expensive integration test that tried to do real ETH transfers
func TestBlockTriggerOutputDataStructure(t *testing.T) {
// Test the actual trigger output data structure conversion - what the original test should have been testing
rawTriggerOutput := map[string]interface{}{
"blockNumber": uint64(12345),
"blockHash": "0xabcdef123456",
"timestamp": uint64(1672531200),
"parentHash": "0x123456abcdef",
"difficulty": "1000000",
"gasLimit": uint64(30000000),
"gasUsed": uint64(21000),
}
// Test buildBlockTriggerOutput function (the actual logic being tested)
blockOutput := buildBlockTriggerOutput(rawTriggerOutput)
// Verify the output structure
if blockOutput == nil {
t.Fatal("buildBlockTriggerOutput should not return nil")
}
if blockOutput.Data == nil {
t.Fatal("BlockTrigger output Data should not be nil")
}
// Verify data can be converted back
dataMap := blockOutput.Data.AsInterface().(map[string]interface{})
if dataMap == nil {
t.Fatal("BlockTrigger output Data should convert to map")
}
// Test specific fields and the known uint64->float64 conversion
if blockNumber, exists := dataMap["blockNumber"]; exists {
// Due to protobuf conversion, uint64 becomes float64
if blockNumFloat, ok := blockNumber.(float64); ok {
if blockNumFloat != 12345.0 {
t.Errorf("Expected blockNumber 12345.0, got %v", blockNumFloat)
}
} else {
t.Errorf("Expected blockNumber to be float64 after protobuf conversion, got %T", blockNumber)
}
} else {
t.Error("blockNumber field missing from output")
}
// Test string fields remain unchanged
if blockHash, exists := dataMap["blockHash"]; exists {
if hashStr, ok := blockHash.(string); ok {
if hashStr != "0xabcdef123456" {
t.Errorf("Expected blockHash '0xabcdef123456', got %v", hashStr)
}
} else {
t.Errorf("Expected blockHash to be string, got %T", blockHash)
}
} else {
t.Error("blockHash field missing from output")
}
t.Log("✅ Block trigger output data structure test passed")
}
// TestFixedTimeTriggerOutputDataStructure tests that fixed time trigger output data is properly structured
func TestFixedTimeTriggerOutputDataStructure(t *testing.T) {
// Test the actual trigger output data structure conversion
rawTriggerOutput := map[string]interface{}{
"timestamp": uint64(1672531200),
"timestamp_iso": "2023-01-01T00:00:00Z",
}
// Test buildFixedTimeTriggerOutput function
fixedTimeOutput := buildFixedTimeTriggerOutput(rawTriggerOutput)
// Verify the output structure
if fixedTimeOutput == nil {
t.Fatal("buildFixedTimeTriggerOutput should not return nil")
}
if fixedTimeOutput.Data == nil {
t.Fatal("FixedTimeTrigger output Data should not be nil")
}
// Verify data can be converted back
dataMap := fixedTimeOutput.Data.AsInterface().(map[string]interface{})
if dataMap == nil {
t.Fatal("FixedTimeTrigger output Data should convert to map")
}
// Test timestamp field and the known uint64->float64 conversion
if timestamp, exists := dataMap["timestamp"]; exists {
// Due to protobuf conversion, uint64 becomes float64
if timestampFloat, ok := timestamp.(float64); ok {
if timestampFloat != 1672531200.0 {
t.Errorf("Expected timestamp 1672531200.0, got %v", timestampFloat)
}
} else {
t.Errorf("Expected timestamp to be float64 after protobuf conversion, got %T", timestamp)
}
} else {
t.Error("timestamp field missing from output")
}
// Test timestampIso field remains string
if timestampIso, exists := dataMap["timestampIso"]; exists {
if isoStr, ok := timestampIso.(string); ok {
if isoStr != "2023-01-01T00:00:00Z" {
t.Errorf("Expected timestampIso '2023-01-01T00:00:00Z', got %v", isoStr)
}
} else {
t.Errorf("Expected timestampIso to be string, got %T", timestampIso)
}
} else {
t.Error("timestampIso field missing from output")
}
t.Log("✅ Fixed time trigger output data structure test passed")
}
// TestCronTriggerOutputDataStructure tests that cron trigger output data is properly structured
func TestCronTriggerOutputDataStructure(t *testing.T) {
// Test the actual trigger output data structure conversion
rawTriggerOutput := map[string]interface{}{
"timestamp": uint64(1672531200),
"timestamp_iso": "2023-01-01T00:00:00Z",
}
// Test buildCronTriggerOutput function
cronOutput := buildCronTriggerOutput(rawTriggerOutput)
// Verify the output structure
if cronOutput == nil {
t.Fatal("buildCronTriggerOutput should not return nil")
}
if cronOutput.Data == nil {
t.Fatal("CronTrigger output Data should not be nil")
}
// Verify data can be converted back
dataMap := cronOutput.Data.AsInterface().(map[string]interface{})
if dataMap == nil {
t.Fatal("CronTrigger output Data should convert to map")
}
// Test timestamp field and the known uint64->float64 conversion
if timestamp, exists := dataMap["timestamp"]; exists {
// Due to protobuf conversion, uint64 becomes float64
if timestampFloat, ok := timestamp.(float64); ok {
if timestampFloat != 1672531200.0 {
t.Errorf("Expected timestamp 1672531200.0, got %v", timestampFloat)
}
} else {
t.Errorf("Expected timestamp to be float64 after protobuf conversion, got %T", timestamp)
}
} else {
t.Error("timestamp field missing from output")
}
// Test timestampIso field remains string
if timestampIso, exists := dataMap["timestampIso"]; exists {
if isoStr, ok := timestampIso.(string); ok {
if isoStr != "2023-01-01T00:00:00Z" {
t.Errorf("Expected timestampIso '2023-01-01T00:00:00Z', got %v", isoStr)
}
} else {
t.Errorf("Expected timestampIso to be string, got %T", timestampIso)
}
} else {
t.Error("timestampIso field missing from output")
}
t.Log("✅ Cron trigger output data structure test passed")
}