From 5dfd052a78cc5ed7257dd4562dfdafcf4fad9dab Mon Sep 17 00:00:00 2001 From: Jeff Rifwald Date: Fri, 29 Aug 2025 15:51:58 -0400 Subject: [PATCH] feat(DAPP-7236): add ability to import pre-compiled wasm in standard tests --- pkg/workflows/wasm/host/standard_test.go | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pkg/workflows/wasm/host/standard_test.go b/pkg/workflows/wasm/host/standard_test.go index 61996ce402..33c9049234 100644 --- a/pkg/workflows/wasm/host/standard_test.go +++ b/pkg/workflows/wasm/host/standard_test.go @@ -40,9 +40,11 @@ var anyTestConfig = []byte("config") var anyTestTriggerValue = "test value" var testPath string +var importWasmFileName string func init() { flag.StringVar(&testPath, "path", "./standard_tests", "Path to the standard tests") + flag.StringVar(&importWasmFileName, "importWasmFileName", "", "File name to import WASM instead of compiling") } func TestStandardConfig(t *testing.T) { @@ -461,11 +463,21 @@ func runWithBasicTrigger(t *testing.T, executor ExecutionHelper) *sdk.ExecutionR // When subtests have their own binaries, those binaries are expected to be nested in a subfolder. func makeTestModule(t *testing.T) *module { testName := strcase.ToSnake(t.Name()[len("TestStandard"):]) + + if importWasmFileName != "" { + return importTestModuleByName(t, testName, nil) + } + return makeTestModuleByName(t, testName, nil) } func makeTestModuleWithCfg(t *testing.T, cfg *ModuleConfig) *module { testName := strcase.ToSnake(t.Name()[len("TestStandard"):]) + + if importWasmFileName != "" { + return importTestModuleByName(t, testName, nil) + } + return makeTestModuleByName(t, testName, cfg) } @@ -490,6 +502,25 @@ func makeTestModuleByName(t *testing.T, testName string, cfg *ModuleConfig) *mod return mod } +// importTestModuleByName imports pre-compiled test modules in the testPath directory +// The test to import and run is determined by the test name. +func importTestModuleByName(t *testing.T, testName string, cfg *ModuleConfig) *module { + wasmName := path.Join(testName, importWasmFileName) + absPath, err := filepath.Abs(testPath) + require.NoError(t, err, "Failed to get absolute path for test directory") + + wasmPath := filepath.Join(absPath, wasmName) + binary, err := os.ReadFile(wasmPath) + require.NoError(t, err, "Failed to read WASM file at %s", wasmPath) + + if cfg == nil { + cfg = defaultNoDAGModCfg(t) + } + mod, err := NewModule(cfg, binary) + require.NoError(t, err) + return mod +} + func setupNodeCallAndConsensusCall(t *testing.T, output int32) func(_ context.Context, request *sdk.CapabilityRequest) (*sdk.CapabilityResponse, error) { return func(_ context.Context, request *sdk.CapabilityRequest) (*sdk.CapabilityResponse, error) { nodeResponse := &nodeaction.NodeOutputs{OutputThing: output}