Skip to content

Commit

Permalink
disable wip test
Browse files Browse the repository at this point in the history
  • Loading branch information
v9n committed Dec 27, 2024
1 parent b31ab79 commit ed4aa3e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 39 deletions.
7 changes: 4 additions & 3 deletions core/taskengine/macros/exp.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ func (bi *Builtin) ParseUnit(val string, decimal uint) *big.Int {

var (
exprEnv = map[string]any{
"fetch": Fetch,
"request": Fetch,
// bind and simular JS fetch api
"fetch": Fetch,

// macro to do IO from JS
"readContractData": readContractData,

"priceChainlink": chainlinkLatestAnswer,
Expand Down Expand Up @@ -193,7 +195,6 @@ type FetchOptions struct {
func Fetch(url string) *FetchResponse {
options := FetchOptions{}

fmt.Println("FETCH", url)
client := resty.New()
// Create request
request := client.R()
Expand Down
3 changes: 2 additions & 1 deletion core/taskengine/vm_runner_customcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ func NewJSProcessor(vm *VM) *JSProcessor {
jsvm: goja.New(),
}

// These are built-in func
for key, value := range macros.GetEnvs(nil) {
fmt.Println("Set", key)
r.jsvm.Set(key, value)
}
/// Binding the data from previous step into jsvm
for key, value := range vm.vars {
r.jsvm.Set(key, map[string]any{
"data": value,
Expand Down
70 changes: 35 additions & 35 deletions core/taskengine/vm_runner_customcode_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package taskengine

import (
"fmt"
"strings"
"testing"

Expand Down Expand Up @@ -89,37 +88,38 @@ func TestRunJavaScriptComplex(t *testing.T) {
}
}

func TestRunJavaScriptHTTP(t *testing.T) {
node := &avsproto.CustomCodeNode{
Source: `
toBigInt("1234442")
`,
}
nodes := []*avsproto.TaskNode{
&avsproto.TaskNode{
Id: "123abc",
Name: "customJs",
TaskType: &avsproto.TaskNode_CustomCode{
CustomCode: node,
},
},
}

edges := []*avsproto.TaskEdge{
&avsproto.TaskEdge{
Id: "e1",
Source: "__TRIGGER__",
Target: "123abc",
},
}

vm, _ := NewVMWithData("123abc", nil, nodes, edges)
n := NewJSProcessor(vm)

step, err := n.Execute("123abc", node)
fmt.Println("error", err, step.OutputData)

if step.OutputData != "[2,3]" {
t.Errorf("wrong JS code evaluation result, expect [2,3] got %s", step.OutputData)
}
}
// Temp disable until we figured out the event loop
// func TestRunJavaScriptHTTP(t *testing.T) {
// node := &avsproto.CustomCodeNode{
// Source: `
// toBigInt("1234442")
// `,
// }
// nodes := []*avsproto.TaskNode{
// &avsproto.TaskNode{
// Id: "123abc",
// Name: "customJs",
// TaskType: &avsproto.TaskNode_CustomCode{
// CustomCode: node,
// },
// },
// }
//
// edges := []*avsproto.TaskEdge{
// &avsproto.TaskEdge{
// Id: "e1",
// Source: "__TRIGGER__",
// Target: "123abc",
// },
// }
//
// vm, _ := NewVMWithData("123abc", nil, nodes, edges)
// n := NewJSProcessor(vm)
//
// step, err := n.Execute("123abc", node)
// fmt.Println("error", err, step.OutputData)
//
// if step.OutputData != "[2,3]" {
// t.Errorf("wrong JS code evaluation result, expect [2,3] got %s", step.OutputData)
// }
// }

0 comments on commit ed4aa3e

Please sign in to comment.