-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
228 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//go:build wasip1 | ||
|
||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/workflows/wasm" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/capabilities/cli/cmd/testdata/fixtures/capabilities/basictrigger" | ||
"github.com/smartcontractkit/chainlink-common/pkg/workflows/sdk" | ||
) | ||
|
||
func BuildWorkflow(config []byte) *sdk.WorkflowSpecFactory { | ||
params := sdk.NewWorkflowParams{} | ||
if err := json.Unmarshal(config, ¶ms); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
workflow := sdk.NewWorkflowSpecFactory(params) | ||
|
||
triggerCfg := basictrigger.TriggerConfig{Name: "trigger", Number: 100} | ||
_ = triggerCfg.New(workflow) | ||
|
||
return workflow | ||
} | ||
|
||
func main() { | ||
runner := wasm.NewRunner() | ||
workflow := BuildWorkflow(runner.Config()) | ||
runner.Run(workflow) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package job | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"os" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/workflows/sdk" | ||
"github.com/smartcontractkit/chainlink-common/pkg/workflows/wasm/host" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/core/logger" | ||
) | ||
|
||
type WasmFileSpecFactory struct{} | ||
|
||
func (w WasmFileSpecFactory) Spec(ctx context.Context, lggr logger.Logger, rawSpec, config []byte) (sdk.WorkflowSpec, error) { | ||
moduleConfig := &host.ModuleConfig{Logger: lggr} | ||
spec, err := host.GetWorkflowSpec(moduleConfig, rawSpec, config) | ||
if err != nil { | ||
return sdk.WorkflowSpec{}, err | ||
} else if spec == nil { | ||
return sdk.WorkflowSpec{}, errors.New("workflow spec not found when running wasm") | ||
} | ||
|
||
return *spec, nil | ||
} | ||
|
||
func (w WasmFileSpecFactory) RawSpec(_ context.Context, wf string) ([]byte, error) { | ||
return os.ReadFile(wf) | ||
} | ||
|
||
var _ SDKWorkflowSpecFactory = (*WasmFileSpecFactory)(nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package job_test | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/workflows/sdk" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/workflows/wasm/host" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils" | ||
"github.com/smartcontractkit/chainlink/v2/core/logger" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/job" | ||
) | ||
|
||
func TestWasmFileSpecFactory(t *testing.T) { | ||
binaryLocation := createTestBinary(t) | ||
config, err := json.Marshal(sdk.NewWorkflowParams{ | ||
Owner: "owner", | ||
Name: "name", | ||
}) | ||
|
||
factory := job.WasmFileSpecFactory{} | ||
rawSpec, err := factory.RawSpec(testutils.Context(t), binaryLocation) | ||
require.NoError(t, err) | ||
actual, err := factory.Spec(testutils.Context(t), logger.NullLogger, rawSpec, config) | ||
|
||
rawBinary, err := os.ReadFile(binaryLocation) | ||
require.NoError(t, err) | ||
expected, err := host.GetWorkflowSpec(&host.ModuleConfig{Logger: logger.NullLogger}, rawBinary, config) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, *expected, actual) | ||
} | ||
|
||
func createTestBinary(t *testing.T) string { | ||
const testBinaryLocation = "testdata/wasm/testmodule.wasm" | ||
|
||
cmd := exec.Command("go", "build", "-o", testBinaryLocation, "github.com/smartcontractkit/chainlink/v2/core/services/job/testdata/wasm") | ||
cmd.Env = append(os.Environ(), "GOOS=wasip1", "GOARCH=wasm") | ||
|
||
output, err := cmd.CombinedOutput() | ||
require.NoError(t, err, string(output)) | ||
|
||
return testBinaryLocation | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.