From acb02e18edd7a5b45d8305b58508b42c87a1dbff Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Fri, 7 Jul 2023 01:24:47 +0200 Subject: [PATCH 01/24] chore: init (thank you ChatGPT) --- .../bigint-type/implementations/go/module.go | 20 +++++++ .../implementations/go/module.go | 20 +++++++ cases/bytes-type/implementations/go/module.go | 11 ++++ cases/enum-type/implementations/go/module.go | 11 ++++ .../invalid-type/implementations/go/module.go | 23 +++++++ cases/json-type/implementations/go/module.go | 57 ++++++++++++++++++ cases/map-type/implementations/go/module.go | 26 ++++++++ cases/no-args/implementations/go/module.go | 7 +++ .../numbers-type/implementations/go/module.go | 27 +++++++++ .../object-type/implementations/go/module.go | 60 +++++++++++++++++++ defaults/go.mod | 7 +++ 11 files changed, 269 insertions(+) create mode 100644 cases/bigint-type/implementations/go/module.go create mode 100644 cases/bignumber-type/implementations/go/module.go create mode 100644 cases/bytes-type/implementations/go/module.go create mode 100644 cases/enum-type/implementations/go/module.go create mode 100644 cases/invalid-type/implementations/go/module.go create mode 100644 cases/json-type/implementations/go/module.go create mode 100644 cases/map-type/implementations/go/module.go create mode 100644 cases/no-args/implementations/go/module.go create mode 100644 cases/numbers-type/implementations/go/module.go create mode 100644 cases/object-type/implementations/go/module.go create mode 100644 defaults/go.mod diff --git a/cases/bigint-type/implementations/go/module.go b/cases/bigint-type/implementations/go/module.go new file mode 100644 index 0000000..af67082 --- /dev/null +++ b/cases/bigint-type/implementations/go/module.go @@ -0,0 +1,20 @@ +package module + +import ( + "errors" + "github.com/polywrap/wrap-test-harness/go/module/wrap/types" + "github.com/polywrap/wasm-as" +) + +func Method(args *types.ArgsMethod) (*wasm.BigInt, error) { + result := new(wasm.BigInt).Mul(args.Arg1, args.Obj.Prop1) + + if args.Arg2 != nil { + result.Mul(result, args.Arg2) + } + if args.Obj.Prop2 != nil { + result.Mul(result, args.Obj.Prop2) + } + + return result, nil +} diff --git a/cases/bignumber-type/implementations/go/module.go b/cases/bignumber-type/implementations/go/module.go new file mode 100644 index 0000000..4a889e1 --- /dev/null +++ b/cases/bignumber-type/implementations/go/module.go @@ -0,0 +1,20 @@ +package module + +import ( + "errors" + "github.com/polywrap/wrap-test-harness/go/module/wrap/types" + "math/big" +) + +func Method(args *types.ArgsMethod) (*big.Int, error) { + result := big.NewInt(0).Mul(args.Arg1, args.Obj.Prop1) + + if args.Arg2 != nil { + result.Mul(result, args.Arg2) + } + if args.Obj.Prop2 != nil { + result.Mul(result, args.Obj.Prop2) + } + + return result, nil +} diff --git a/cases/bytes-type/implementations/go/module.go b/cases/bytes-type/implementations/go/module.go new file mode 100644 index 0000000..2c95380 --- /dev/null +++ b/cases/bytes-type/implementations/go/module.go @@ -0,0 +1,11 @@ +package module + +import ( + "github.com/polywrap/wrap-test-harness/go/module/wrap/types" +) + +func BytesMethod(args *types.ArgsBytesMethod) ([]byte, error) { + s := string(args.Arg.Prop) + result := []byte(s + " Sanity!") + return result, nil +} diff --git a/cases/enum-type/implementations/go/module.go b/cases/enum-type/implementations/go/module.go new file mode 100644 index 0000000..b85eed9 --- /dev/null +++ b/cases/enum-type/implementations/go/module.go @@ -0,0 +1,11 @@ +package module + +import "github.com/polywrap/wrap-test-harness/go/module/wrap/types" + +func Method1(args *types.ArgsMethod1) types.SanityEnum { + return args.En +} + +func Method2(args *types.ArgsMethod2) []types.SanityEnum { + return args.EnumArray +} diff --git a/cases/invalid-type/implementations/go/module.go b/cases/invalid-type/implementations/go/module.go new file mode 100644 index 0000000..28d8d4e --- /dev/null +++ b/cases/invalid-type/implementations/go/module.go @@ -0,0 +1,23 @@ +package module + +import "github.com/polywrap/wrap-test-harness/go/module/wrap/types" + +func BoolMethod(args *types.ArgsBoolMethod) (bool, error) { + return args.Arg, nil +} + +func IntMethod(args *types.ArgsIntMethod) (int32, error) { + return args.Arg, nil +} + +func UIntMethod(args *types.ArgsUIntMethod) (uint32, error) { + return args.Arg, nil +} + +func BytesMethod(args *types.ArgsBytesMethod) ([]uint8, error) { + return args.Arg, nil +} + +func ArrayMethod(args *types.ArgsArrayMethod) ([]string, error) { + return args.Arg, nil +} diff --git a/cases/json-type/implementations/go/module.go b/cases/json-type/implementations/go/module.go new file mode 100644 index 0000000..212eeda --- /dev/null +++ b/cases/json-type/implementations/go/module.go @@ -0,0 +1,57 @@ +package module + +import ( + "encoding/json" + "errors" + "github.com/polywrap/wrap-test-harness/go/module/wrap/types" +) + +func Stringify(args *types.ArgsStringify) (string, error) { + var newString string + for _, object := range args.Values { + newString += object.String() + } + return newString, nil +} + +func Parse(args *types.ArgsParse) (interface{}, error) { + var value interface{} + err := json.Unmarshal([]byte(args.Value), &value) + if err != nil { + return nil, err + } + return value, nil +} + +func StringifyObject(args *types.ArgsStringifyObject) (string, error) { + var newString string + newString += args.Object.JSONA.String() + newString += args.Object.JSONB.String() + return newString, nil +} + +func MethodJSON(args *types.ArgsMethodJSON) (interface{}, error) { + value := map[string]interface{}{ + "valueA": args.ValueA, + "valueB": args.ValueB, + "valueC": args.ValueC, + } + return value, nil +} + +func ParseReserved(args *types.ArgsParseReserved) (interface{}, error) { + var reserved interface{} + err := json.Unmarshal([]byte(args.JSON), &reserved) + if err != nil { + return nil, err + } + return reserved, nil +} + +func StringifyReserved(args *types.ArgsStringifyReserved) (string, error) { + jsonString, err := json.Marshal(args.Reserved) + if err != nil { + return "", err + } + return string(jsonString), nil +} diff --git a/cases/map-type/implementations/go/module.go b/cases/map-type/implementations/go/module.go new file mode 100644 index 0000000..085d3ec --- /dev/null +++ b/cases/map-type/implementations/go/module.go @@ -0,0 +1,26 @@ +package module + +import ( + "github.com/polywrap/wrap-test-harness/go/module/wrap/types" +) + +func GetKey(args *types.ArgsGetKey) int32 { + value, exists := args.Foo.Map[args.Key] + if !exists { + // Return a default value or handle the case when the key is not found + return 0 + } + return value +} + +func ReturnMap(args *types.ArgsReturnMap) map[string]int32 { + return args.Map +} + +func ReturnCustomMap(args *types.ArgsReturnCustomMap) map[string]int32 { + return args.Foo.Map +} + +func ReturnNestedMap(args *types.ArgsReturnNestedMap) map[string]map[string]int32 { + return args.Foo +} diff --git a/cases/no-args/implementations/go/module.go b/cases/no-args/implementations/go/module.go new file mode 100644 index 0000000..469785b --- /dev/null +++ b/cases/no-args/implementations/go/module.go @@ -0,0 +1,7 @@ +package module + +import "github.com/polywrap/wrap-test-harness/go/module/wrap/types" + +func NoArgsMethod(args *types.ArgsNoArgsMethod) bool { + return true +} diff --git a/cases/numbers-type/implementations/go/module.go b/cases/numbers-type/implementations/go/module.go new file mode 100644 index 0000000..96235dd --- /dev/null +++ b/cases/numbers-type/implementations/go/module.go @@ -0,0 +1,27 @@ +package module + +import "github.com/polywrap/wrap-test-harness/go/module/wrap/types" + +func I8Method(args *types.ArgsI8Method) int8 { + return args.First + args.Second +} + +func U8Method(args *types.ArgsU8Method) uint8 { + return args.First + args.Second +} + +func I16Method(args *types.ArgsI16Method) int16 { + return args.First + args.Second +} + +func U16Method(args *types.ArgsU16Method) uint16 { + return args.First + args.Second +} + +func I32Method(args *types.ArgsI32Method) int32 { + return args.First + args.Second +} + +func U32Method(args *types.ArgsU32Method) uint32 { + return args.First + args.Second +} diff --git a/cases/object-type/implementations/go/module.go b/cases/object-type/implementations/go/module.go new file mode 100644 index 0000000..5e9d09b --- /dev/null +++ b/cases/object-type/implementations/go/module.go @@ -0,0 +1,60 @@ +package module + +import "github.com/polywrap/wrap-test-harness/go/module/wrap/types" + +func Method1(args *types.ArgsMethod1) []types.Output { + outputs := []types.Output{ + { + Prop: args.Arg1.Prop, + Nested: types.Nested{ + Prop: args.Arg1.Nested.Prop, + }, + }, + } + if args.Arg2 != nil { + arg2 := args.Arg2.(*types.Arg2) + outputs = append(outputs, types.Output{ + Prop: arg2.Prop, + Nested: types.Nested{ + Prop: arg2.Circular.Prop, + }, + }) + } + return outputs +} + +func Method2(args *types.ArgsMethod2) *types.Output { + if args.Arg.Prop == "null" { + return nil + } + return &types.Output{ + Prop: args.Arg.Prop, + Nested: types.Nested{ + Prop: args.Arg.Nested.Prop, + }, + } +} + +func Method3(args *types.ArgsMethod3) []*types.Output { + outputs := []*types.Output{ + nil, + } + if args.Arg != nil { + outputs = append(outputs, &types.Output{ + Prop: args.Arg.Prop, + Nested: types.Nested{ + Prop: args.Arg.Nested.Prop, + }, + }) + } + return outputs +} + +func Method4(args *types.ArgsMethod4) types.Output { + return types.Output{ + Prop: args.Arg.Prop, + Nested: types.Nested{ + Prop: "nested prop", + }, + } +} diff --git a/defaults/go.mod b/defaults/go.mod new file mode 100644 index 0000000..20c1d2c --- /dev/null +++ b/defaults/go.mod @@ -0,0 +1,7 @@ +module github.com/polywrap/wrap-test-harness/go + +go 1.18 + +require github.com/polywrap/go-wrap v0.0.0-20230706013513-29691688fe81 + +require github.com/valyala/fastjson v1.6.3 // indirect From a4ff235fe0a1c3b2a1df0687f4224831cfeeeed5 Mon Sep 17 00:00:00 2001 From: Niraj Kamdar Date: Tue, 11 Jul 2023 03:36:14 +0800 Subject: [PATCH 02/24] wip: go harness --- cases/asyncify/implementations/go/module.go | 80 ++++ .../bigint-type/implementations/go/module.go | 9 +- .../implementations/go/module.go | 7 +- cases/bytes-type/implementations/go/module.go | 4 +- cases/enum-type/implementations/go/module.go | 4 +- .../invalid-type/implementations/go/module.go | 20 +- cases/json-type/implementations/go/module.go | 24 +- src/constants.rs | 6 + src/engine.rs | 352 ++++++++++-------- src/generator.rs | 9 +- 10 files changed, 326 insertions(+), 189 deletions(-) create mode 100644 cases/asyncify/implementations/go/module.go diff --git a/cases/asyncify/implementations/go/module.go b/cases/asyncify/implementations/go/module.go new file mode 100644 index 0000000..e188cda --- /dev/null +++ b/cases/asyncify/implementations/go/module.go @@ -0,0 +1,80 @@ +package module + +import ( + "errors" + "github.com/polywrap/wrap-test-harness/go/module/wrap/types" + "github.com/polywrap/wrap-test-harness/go/module/wrap/storage_module" + "strconv" +) + +func GetData(args *types.ArgsGetData) (uint32, error) { + v, err := storage_module.GetData(&storage_module.ArgsGetData{}) + if err != nil { + return 0, errors.New(err.Error()) + } + return uint32(v), nil +} + +func SetDataWithLargeArgs(args *types.ArgsSetDataWithLargeArgs) (string, error) { + largeString := args.Value + _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 66}) + if err != nil { + return "", errors.New(err.Error()) + } + return largeString, nil +} + +func SetDataWithManyArgs(args *types.ArgsSetDataWithManyArgs) (string, error) { + _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 55}) + if err != nil { + return "", errors.New(err.Error()) + } + return args.ValueA + args.ValueB + args.ValueC + args.ValueD + args.ValueE + args.ValueF + args.ValueG + args.ValueH + args.ValueI + args.ValueJ + args.ValueK + args.ValueL, nil +} + +func SetDataWithManyStructuredArgs(args *types.ArgsSetDataWithManyStructuredArgs) (bool, error) { + _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 44}) + if err != nil { + return false, errors.New(err.Error()) + } + return true, nil +} + +func LocalVarMethod(args *types.ArgsLocalVarMethod) (bool, error) { + _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 88}) + if err != nil { + return false, errors.New(err.Error()) + } + return true, nil +} + +func GlobalVarMethod(args *types.ArgsGlobalVarMethod) (bool, error) { + _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 77}) + if err != nil { + return false, errors.New(err.Error()) + } + return true, nil +} + +func SubsequentInvokes(args *types.ArgsSubsequentInvokes) ([]string, error) { + var result []string + var err error + + for i := 0; i < int(args.NumberOfTimes); i++ { + _, errSet := storage_module.SetData(&storage_module.ArgsSetData{Value: i}) + if errSet != nil { + err = errSet + break + } + data, errGet := storage_module.GetData(&storage_module.ArgsGetData{}) + if errGet != nil { + err = errGet + break + } + result = append(result, strconv.Itoa(data)) + } + if err != nil { + return nil, errors.New(err.Error()) + } + return result, nil +} diff --git a/cases/bigint-type/implementations/go/module.go b/cases/bigint-type/implementations/go/module.go index af67082..03924c1 100644 --- a/cases/bigint-type/implementations/go/module.go +++ b/cases/bigint-type/implementations/go/module.go @@ -1,13 +1,12 @@ package module import ( - "errors" "github.com/polywrap/wrap-test-harness/go/module/wrap/types" - "github.com/polywrap/wasm-as" + big "github.com/polywrap/go-wrap/polywrap/msgpack/big" ) -func Method(args *types.ArgsMethod) (*wasm.BigInt, error) { - result := new(wasm.BigInt).Mul(args.Arg1, args.Obj.Prop1) +func Method(args *types.MethodArgsMethod) (*big.Int) { + result := new(big.Int).Mul(args.Arg1, args.Obj.Prop1) if args.Arg2 != nil { result.Mul(result, args.Arg2) @@ -16,5 +15,5 @@ func Method(args *types.ArgsMethod) (*wasm.BigInt, error) { result.Mul(result, args.Obj.Prop2) } - return result, nil + return result } diff --git a/cases/bignumber-type/implementations/go/module.go b/cases/bignumber-type/implementations/go/module.go index 4a889e1..813a894 100644 --- a/cases/bignumber-type/implementations/go/module.go +++ b/cases/bignumber-type/implementations/go/module.go @@ -1,12 +1,11 @@ package module import ( - "errors" "github.com/polywrap/wrap-test-harness/go/module/wrap/types" - "math/big" + big "github.com/polywrap/go-wrap/polywrap/msgpack/big" ) -func Method(args *types.ArgsMethod) (*big.Int, error) { +func Method(args *types.MethodArgsMethod) (*big.Int) { result := big.NewInt(0).Mul(args.Arg1, args.Obj.Prop1) if args.Arg2 != nil { @@ -16,5 +15,5 @@ func Method(args *types.ArgsMethod) (*big.Int, error) { result.Mul(result, args.Obj.Prop2) } - return result, nil + return result } diff --git a/cases/bytes-type/implementations/go/module.go b/cases/bytes-type/implementations/go/module.go index 2c95380..324d06e 100644 --- a/cases/bytes-type/implementations/go/module.go +++ b/cases/bytes-type/implementations/go/module.go @@ -4,8 +4,8 @@ import ( "github.com/polywrap/wrap-test-harness/go/module/wrap/types" ) -func BytesMethod(args *types.ArgsBytesMethod) ([]byte, error) { +func BytesMethod(args *types.MethodArgsBytesMethod) ([]byte) { s := string(args.Arg.Prop) result := []byte(s + " Sanity!") - return result, nil + return result } diff --git a/cases/enum-type/implementations/go/module.go b/cases/enum-type/implementations/go/module.go index b85eed9..4fdc7a1 100644 --- a/cases/enum-type/implementations/go/module.go +++ b/cases/enum-type/implementations/go/module.go @@ -2,10 +2,10 @@ package module import "github.com/polywrap/wrap-test-harness/go/module/wrap/types" -func Method1(args *types.ArgsMethod1) types.SanityEnum { +func Method1(args *types.MethodArgsMethod1) types.SanityEnum { return args.En } -func Method2(args *types.ArgsMethod2) []types.SanityEnum { +func Method2(args *types.MethodArgsMethod2) []types.SanityEnum { return args.EnumArray } diff --git a/cases/invalid-type/implementations/go/module.go b/cases/invalid-type/implementations/go/module.go index 28d8d4e..80bddf1 100644 --- a/cases/invalid-type/implementations/go/module.go +++ b/cases/invalid-type/implementations/go/module.go @@ -2,22 +2,22 @@ package module import "github.com/polywrap/wrap-test-harness/go/module/wrap/types" -func BoolMethod(args *types.ArgsBoolMethod) (bool, error) { - return args.Arg, nil +func BoolMethod(args *types.MethodArgsBoolMethod) (bool) { + return args.Arg } -func IntMethod(args *types.ArgsIntMethod) (int32, error) { - return args.Arg, nil +func IntMethod(args *types.MethodArgsIntMethod) (int32) { + return args.Arg } -func UIntMethod(args *types.ArgsUIntMethod) (uint32, error) { - return args.Arg, nil +func UIntMethod(args *types.MethodArgsUIntMethod) (uint32) { + return args.Arg } -func BytesMethod(args *types.ArgsBytesMethod) ([]uint8, error) { - return args.Arg, nil +func BytesMethod(args *types.MethodArgsBytesMethod) ([]uint8) { + return args.Arg } -func ArrayMethod(args *types.ArgsArrayMethod) ([]string, error) { - return args.Arg, nil +func ArrayMethod(args *types.MethodArgsArrayMethod) ([]string) { + return args.Arg } diff --git a/cases/json-type/implementations/go/module.go b/cases/json-type/implementations/go/module.go index 212eeda..e024051 100644 --- a/cases/json-type/implementations/go/module.go +++ b/cases/json-type/implementations/go/module.go @@ -14,44 +14,44 @@ func Stringify(args *types.ArgsStringify) (string, error) { return newString, nil } -func Parse(args *types.ArgsParse) (interface{}, error) { +func Parse(args *types.ArgsParse) (interface{}) { var value interface{} err := json.Unmarshal([]byte(args.Value), &value) if err != nil { return nil, err } - return value, nil + return value } -func StringifyObject(args *types.ArgsStringifyObject) (string, error) { +func StringifyObject(args *types.ArgsStringifyObject) (string) { var newString string newString += args.Object.JSONA.String() newString += args.Object.JSONB.String() - return newString, nil + return newString } -func MethodJSON(args *types.ArgsMethodJSON) (interface{}, error) { +func MethodJSON(args *types.ArgsMethodJSON) (interface{}) { value := map[string]interface{}{ "valueA": args.ValueA, "valueB": args.ValueB, "valueC": args.ValueC, } - return value, nil + return value } -func ParseReserved(args *types.ArgsParseReserved) (interface{}, error) { +func ParseReserved(args *types.ArgsParseReserved) (interface{}) { var reserved interface{} err := json.Unmarshal([]byte(args.JSON), &reserved) if err != nil { - return nil, err + return nil } - return reserved, nil + return reserved } -func StringifyReserved(args *types.ArgsStringifyReserved) (string, error) { +func StringifyReserved(args *types.ArgsStringifyReserved) (string) { jsonString, err := json.Marshal(args.Reserved) if err != nil { - return "", err + return "" } - return string(jsonString), nil + return string(jsonString) } diff --git a/src/constants.rs b/src/constants.rs index 4a8a4b9..892e413 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -24,6 +24,12 @@ lazy_static! { module: "./Cargo.toml", id: "rs" }); + map.insert("go", Implementation { + dependency: "go.mod", + name: "golang", + module: "./go.mod", + id: "go" + }); map }; } \ No newline at end of file diff --git a/src/engine.rs b/src/engine.rs index 257f344..8413f43 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -1,3 +1,12 @@ +use crate::error::{BuildError, ExecutionError, TestError}; +use crate::generator::Generate; +use crate::polywrap_cli::PolywrapCli; +use crate::Results; +use futures::future::try_join_all; +use futures::{future::join_all, Future, StreamExt}; +use log::debug; +use log::info; +use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::fmt::Debug; use std::fs; @@ -5,15 +14,6 @@ use std::path::{Path, PathBuf}; use std::pin::Pin; use std::sync::Arc; use std::sync::Mutex; -use futures::future::try_join_all; -use log::{debug}; -use serde::{Deserialize, Serialize}; -use futures::{Future,future::join_all,StreamExt}; -use log::{info}; -use crate::error::{ExecutionError, TestError, BuildError}; -use crate::Results; -use crate::generator::{Generate}; -use crate::polywrap_cli::PolywrapCli; #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] pub struct Engine { @@ -30,35 +30,37 @@ pub struct EnginePath { type ComplexCase = HashMap>>; -type ExecutorFuture = Pin> + Send>>; +type ExecutorFuture = Pin> + Send>>; type Executor = Box, Option) -> ExecutorFuture + Send>; #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] enum CaseType { Simple(Vec), - Complex(ComplexCase) + Complex(ComplexCase), } impl Engine { - pub fn start( - destination: &Path, - source: &Path - ) -> Self { + pub fn start(destination: &Path, source: &Path) -> Self { Self { path: EnginePath { destination: destination.to_path_buf(), source: source.to_path_buf(), }, feature: None, - implementation: None + implementation: None, } } - pub async fn execute(&self, feature: Option<&str>, implementation: Option<&str>, generate_built_cases: bool) -> Result<(), ExecutionError> { + pub async fn execute( + &self, + feature: Option<&str>, + implementation: Option<&str>, + generate_built_cases: bool, + ) -> Result<(), ExecutionError> { let generator = Generate::new( self.path.destination.to_path_buf(), self.path.source.to_path_buf(), - generate_built_cases + generate_built_cases, ); let generator = Arc::new(generator); let engine = Arc::new(self.clone()); @@ -67,64 +69,64 @@ impl Engine { fs::create_dir("./wrappers")?; } - let project_generator_executor: Executor = Box::new( - move |feature, implementation, subpath| { + let project_generator_executor: Executor = + Box::new(move |feature, implementation, subpath| { let generator = generator.clone(); Box::pin(async move { - generator.project( - feature.as_str(), - implementation.as_deref(), - subpath.as_deref() - ).await.map_err(ExecutionError::GenerateError) + generator + .project( + feature.as_str(), + implementation.as_deref(), + subpath.as_deref(), + ) + .await + .map_err(ExecutionError::GenerateError) }) - } - ); + }); info!("Running generator executor"); self.handler( project_generator_executor, feature.map(|f| f.to_string()), implementation.map(|i| i.to_string()), - ).await?; - - let build_executor: Executor = Box::new( - move |feature, implementation, subpath| { - let e = engine.clone(); - Box::pin(async move { - e.build( - feature.as_str(), - implementation.as_deref(), - subpath.as_deref(), - generate_built_cases - ).await.map_err(ExecutionError::BuildError) - }) - } - ); + ) + .await?; + + let build_executor: Executor = Box::new(move |feature, implementation, subpath| { + let e = engine.clone(); + Box::pin(async move { + e.build( + feature.as_str(), + implementation.as_deref(), + subpath.as_deref(), + generate_built_cases, + ) + .await + .map_err(ExecutionError::BuildError) + }) + }); info!("Running build executor"); self.handler( build_executor, feature.map(|f| f.to_string()), implementation.map(|i| i.to_string()), - ).await?; + ) + .await?; let engine = Arc::new(self.clone()); - let test_executor: Executor = Box::new( - move |feature, implementation, subpath| { - let e = engine.clone(); - Box::pin(async move { - if let Some(i) = implementation { - e.test( - feature.as_str(), - &i, - subpath.as_deref(), - ).await.map_err(ExecutionError::TestError) - } else { - Ok(()) - } - }) - } - ); + let test_executor: Executor = Box::new(move |feature, implementation, subpath| { + let e = engine.clone(); + Box::pin(async move { + if let Some(i) = implementation { + e.test(feature.as_str(), &i, subpath.as_deref()) + .await + .map_err(ExecutionError::TestError) + } else { + Ok(()) + } + }) + }); if !generate_built_cases { info!("Running test executor"); @@ -132,7 +134,8 @@ impl Engine { test_executor, feature.map(|f| f.to_string()), implementation.map(|i| i.to_string()), - ).await? + ) + .await? } Ok(()) } @@ -141,25 +144,28 @@ impl Engine { &self, executor: Executor, feature: Option, - implementation: Option + implementation: Option, ) -> Result<(), ExecutionError> { type FeatureImplMap = HashMap; - let mut feature_map : FeatureImplMap = HashMap::new(); + let mut feature_map: FeatureImplMap = HashMap::new(); match feature { None => { - feature_map = fs::read_dir(&self.path.source)?.fold(feature_map, |mut current, f| { - current.insert(String::from(f.unwrap().file_name().to_str().unwrap()), CaseType::Simple(vec![])); - current - }); - }, + feature_map = + fs::read_dir(&self.path.source)?.fold(feature_map, |mut current, f| { + current.insert( + String::from(f.unwrap().file_name().to_str().unwrap()), + CaseType::Simple(vec![]), + ); + current + }); + } Some(f) => { f.split(',') - .map(|feature| - feature.trim().to_string() - ).into_iter().for_each(|f| { + .map(|feature| feature.trim().to_string()) + .into_iter() + .for_each(|f| { feature_map.insert(f, CaseType::Simple(vec![])); - } - ); + }); } } @@ -169,48 +175,54 @@ impl Engine { match implementation.clone() { None => { if implementation_folder.exists() { - let implementations = fs::read_dir(implementation_folder)?.map(|i| { - i.unwrap().file_name().into_string().unwrap() - }).collect::>(); + let implementations = fs::read_dir(implementation_folder)? + .map(|i| i.unwrap().file_name().into_string().unwrap()) + .collect::>(); feature_map.insert(feature.to_string(), CaseType::Simple(implementations)); } else { let mut complex_case_map: ComplexCase = HashMap::new(); - fs::read_dir(feature_folder)?.into_iter().filter(|i| { - i.as_ref().unwrap().metadata().unwrap().is_dir() - }).for_each(|entry| { - let dir = entry.unwrap(); - let step_name = dir.file_name().into_string().unwrap(); - let step_implementations = dir.path().join("implementations"); - if step_implementations.exists() { - let implementations = fs::read_dir(step_implementations).unwrap().map(|i| { - i.unwrap().file_name().into_string().unwrap() - }).collect::>(); - complex_case_map.insert(step_name, Some(implementations)); - } else { - complex_case_map.insert(step_name, None); - } - }); - feature_map.insert(feature.to_string(), CaseType::Complex(complex_case_map)); + fs::read_dir(feature_folder)? + .into_iter() + .filter(|i| i.as_ref().unwrap().metadata().unwrap().is_dir()) + .for_each(|entry| { + let dir = entry.unwrap(); + let step_name = dir.file_name().into_string().unwrap(); + let step_implementations = dir.path().join("implementations"); + if step_implementations.exists() { + let implementations = fs::read_dir(step_implementations) + .unwrap() + .map(|i| i.unwrap().file_name().into_string().unwrap()) + .collect::>(); + complex_case_map.insert(step_name, Some(implementations)); + } else { + complex_case_map.insert(step_name, None); + } + }); + feature_map + .insert(feature.to_string(), CaseType::Complex(complex_case_map)); }; - }, + } Some(i) => { if implementation_folder.exists() { - feature_map.insert(feature.to_string(), CaseType::Simple(vec![i.to_string()])); + feature_map + .insert(feature.to_string(), CaseType::Simple(vec![i.to_string()])); } else { let mut complex_case_map: ComplexCase = HashMap::new(); - fs::read_dir(feature_folder)?.into_iter().filter(|i| { - i.as_ref().unwrap().metadata().unwrap().is_dir() - }).for_each(|entry| { - let dir = entry.unwrap(); - let step_name = dir.file_name().into_string().unwrap(); - let step_implementations = dir.path().join("implementations"); - if step_implementations.exists() { - complex_case_map.insert(step_name, Some(vec![i.to_string()])); - } else { - complex_case_map.insert(step_name, None); - } - }); - feature_map.insert(feature.to_string(), CaseType::Complex(complex_case_map)); + fs::read_dir(feature_folder)? + .into_iter() + .filter(|i| i.as_ref().unwrap().metadata().unwrap().is_dir()) + .for_each(|entry| { + let dir = entry.unwrap(); + let step_name = dir.file_name().into_string().unwrap(); + let step_implementations = dir.path().join("implementations"); + if step_implementations.exists() { + complex_case_map.insert(step_name, Some(vec![i.to_string()])); + } else { + complex_case_map.insert(step_name, None); + } + }); + feature_map + .insert(feature.to_string(), CaseType::Complex(complex_case_map)); } } } @@ -223,9 +235,11 @@ impl Engine { match f.unwrap() { CaseType::Simple(implementations) => { for implementation in implementations { - current_executions.push( - executor(feature.clone(), Some(implementation.to_string()), None) - ); + current_executions.push(executor( + feature.clone(), + Some(implementation.to_string()), + None, + )); } } CaseType::Complex(cases) => { @@ -235,14 +249,18 @@ impl Engine { let implementations = cases.get(step.as_str()).unwrap(); if let Some(implementation) = implementations { for i in implementation { - current_executions.push( - executor(feature.clone(), Some(i.to_string()), Some(step.to_string())) - ); + current_executions.push(executor( + feature.clone(), + Some(i.to_string()), + Some(step.to_string()), + )); } } else { - current_executions.push( - executor(feature.clone(), None, Some(step.to_string())) - ); + current_executions.push(executor( + feature.clone(), + None, + Some(step.to_string()), + )); } } } @@ -252,11 +270,14 @@ impl Engine { let execution_futures = features_execution_futures .into_values() - .map(|f| { - tokio::spawn(join_all(f)) - } - ); - let futures = try_join_all(futures::stream::iter(execution_futures).collect::>().await).await.unwrap(); + .map(|f| tokio::spawn(join_all(f))); + let futures = try_join_all( + futures::stream::iter(execution_futures) + .collect::>() + .await, + ) + .await + .unwrap(); for feature in futures { for result in feature { @@ -268,7 +289,13 @@ impl Engine { Ok(()) } - async fn build(&self, feature: &str, implementation: Option<&str>, subpath: Option<&str>, generate_built_cases: bool) -> Result<(), BuildError> { + async fn build( + &self, + feature: &str, + implementation: Option<&str>, + subpath: Option<&str>, + generate_built_cases: bool, + ) -> Result<(), BuildError> { let mut directory = self.path.destination.join(feature); let mut copy_dest = self.path.source.join("..").join("wrappers").join(feature); @@ -279,26 +306,37 @@ impl Engine { if let Some(i) = implementation { copy_dest = copy_dest.join("implementations").join(i); - directory = directory - .join("implementations") - .join(i); + directory = directory.join("implementations").join(i); debug!("Building wrapper in path: {}", directory.to_str().unwrap()); } else { - debug!("Building interface in path: {}", directory.to_str().unwrap()); + debug!( + "Building interface in path: {}", + directory.to_str().unwrap() + ); }; let cli = PolywrapCli::new(); let mut command = cli.command.unwrap(); - let build = command.arg("build") + let mut build = command + .arg("build") .arg("-v") .arg("-l") .arg("./log.txt") .current_dir(&directory); + if let Some(i) = implementation { + if i == "go" { + build = build.arg("-s").arg("local") + } + } + if let Ok(output) = build.output() { let message = if let Some(i) = implementation { if let Some(s) = subpath { - format!("Build of feature: {}, with implementation: {} and subpath: {}", feature, i, s) + format!( + "Build of feature: {}, with implementation: {} and subpath: {}", + feature, i, s + ) } else { format!("Build of feature: {}, with implementation: {}", feature, i) } @@ -309,7 +347,11 @@ impl Engine { if output.status.code() == Some(0) { debug!("{} succeed", message); } else { - return Err(BuildError::BuildExecutionError(format!("{} failed with error: {}", message, String::from_utf8(output.stderr).unwrap()))); + return Err(BuildError::BuildExecutionError(format!( + "{} failed with error: {}", + message, + String::from_utf8(output.stderr).unwrap() + ))); } if generate_built_cases { @@ -323,30 +365,37 @@ impl Engine { } else { let error = build.output().unwrap_err(); - return Err(BuildError::BuildExecutionError(format!("Error on polywrap cli build command: {:?}", error))); + return Err(BuildError::BuildExecutionError(format!( + "Error on polywrap cli build command: {:?}", + error + ))); } Ok(()) } - async fn test(&self, feature: &str, implementation: &str, subpath: Option<&str>) -> Result<(), TestError> { + async fn test( + &self, + feature: &str, + implementation: &str, + subpath: Option<&str>, + ) -> Result<(), TestError> { let mut directory = self.path.destination.join(feature); let cli = PolywrapCli::new(); let mut command = cli.command.unwrap(); - let test = command.arg("test") - .arg("-o") - .arg("./output.json"); + let test = command.arg("test").arg("-o").arg("./output.json"); if let Some(p) = subpath { - let mut folders = fs::read_dir(&directory)? - .filter_map(|f| { - let file = f.unwrap(); - if file.metadata().unwrap().is_dir() { + let mut folders = fs::read_dir(&directory)? + .filter_map(|f| { + let file = f.unwrap(); + if file.metadata().unwrap().is_dir() { return Some(file.file_name().into_string().unwrap()); - } + } - None - }).collect::>(); + None + }) + .collect::>(); folders.sort(); if !folders.last().eq(&Some(&String::from(p))) { @@ -362,9 +411,7 @@ impl Engine { test.arg("-c").arg("../../../client-config.ts"); }; } else { - directory = directory - .join("implementations") - .join(implementation); + directory = directory.join("implementations").join(implementation); test.arg("-m").arg("../../polywrap.test.yaml"); let custom_config = directory.join("../../client-config.ts").exists(); if custom_config { @@ -379,14 +426,14 @@ impl Engine { message_error = test.output().unwrap_err().to_string(); }; - let stderr = test.output().unwrap().stderr; + let stderr = test.output().unwrap().stderr; if !stderr.is_empty() { message_error = String::from_utf8(stderr).unwrap(); } if !message_error.is_empty() { let message = format!("Error on polywrap CLI Test command: {}", message_error); - return Err(TestError::TestExecutionError(message)) + return Err(TestError::TestExecutionError(message)); } let impl_name = directory.file_name().unwrap().to_str().unwrap(); @@ -407,17 +454,16 @@ impl Engine { if let Ok(f) = fs::read(&info_path) { let result_str = String::from_utf8_lossy(&f).parse::().unwrap(); let mut results: Results = serde_json::from_str(result_str.as_str()).unwrap(); - results.info.entry(impl_name.to_string()).or_default().insert(feature.to_string(), summary); - let results_file = fs::OpenOptions::new() - .write(true) - .open(&info_path) - .unwrap(); + results + .info + .entry(impl_name.to_string()) + .or_default() + .insert(feature.to_string(), summary); + let results_file = fs::OpenOptions::new().write(true).open(&info_path).unwrap(); serde_json::to_writer_pretty(results_file, &results).unwrap(); } else { let mut results = Results::new(); - let summaries = HashMap::from([ - (feature.to_string(), summary) - ]); + let summaries = HashMap::from([(feature.to_string(), summary)]); results.info.insert(impl_name.to_string(), summaries); let results_file = fs::OpenOptions::new() .write(true) diff --git a/src/generator.rs b/src/generator.rs index e8babe2..9fa81b0 100644 --- a/src/generator.rs +++ b/src/generator.rs @@ -151,7 +151,14 @@ impl Generate { // Generate implementation files (i.e: index.ts/lib.rs) let files = fs::read_dir(&source_path)?; for file in files { - let destination_source_folder = &destination_path.join("src"); + // HACK: fix this + let subpath: &str; + if implementation == "go" { + subpath = "module"; + } else { + subpath = "src;" + } + let destination_source_folder = &destination_path.join(subpath); fs::create_dir(destination_source_folder)?; let name = file?.file_name(); let impl_source = source_path.join(&name); From e8edc82d685fc5adc6fa13f74a730978f22416d6 Mon Sep 17 00:00:00 2001 From: Jordan Ellis <5522128+dOrgJelli@users.noreply.github.com> Date: Mon, 10 Jul 2023 22:09:27 -0400 Subject: [PATCH 03/24] Update module.go --- .../object-type/implementations/go/module.go | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/cases/object-type/implementations/go/module.go b/cases/object-type/implementations/go/module.go index 5e9d09b..c571bda 100644 --- a/cases/object-type/implementations/go/module.go +++ b/cases/object-type/implementations/go/module.go @@ -2,7 +2,7 @@ package module import "github.com/polywrap/wrap-test-harness/go/module/wrap/types" -func Method1(args *types.ArgsMethod1) []types.Output { +func Method1(args *types.MethodArgsMethod1) []types.Output { outputs := []types.Output{ { Prop: args.Arg1.Prop, @@ -12,7 +12,7 @@ func Method1(args *types.ArgsMethod1) []types.Output { }, } if args.Arg2 != nil { - arg2 := args.Arg2.(*types.Arg2) + arg2 := args.Arg2 outputs = append(outputs, types.Output{ Prop: arg2.Prop, Nested: types.Nested{ @@ -23,7 +23,7 @@ func Method1(args *types.ArgsMethod1) []types.Output { return outputs } -func Method2(args *types.ArgsMethod2) *types.Output { +func Method2(args *types.MethodArgsMethod2) *types.Output { if args.Arg.Prop == "null" { return nil } @@ -35,24 +35,22 @@ func Method2(args *types.ArgsMethod2) *types.Output { } } -func Method3(args *types.ArgsMethod3) []*types.Output { +func Method3(args *types.MethodArgsMethod3) []*types.Output { outputs := []*types.Output{ nil, } - if args.Arg != nil { - outputs = append(outputs, &types.Output{ - Prop: args.Arg.Prop, - Nested: types.Nested{ - Prop: args.Arg.Nested.Prop, - }, - }) - } + outputs = append(outputs, &types.Output{ + Prop: args.Arg.Prop, + Nested: types.Nested{ + Prop: args.Arg.Nested.Prop, + }, + }) return outputs } -func Method4(args *types.ArgsMethod4) types.Output { +func Method4(args *types.MethodArgsMethod4) types.Output { return types.Output{ - Prop: args.Arg.Prop, + Prop: string(args.Arg.Prop), Nested: types.Nested{ Prop: "nested prop", }, From 3fe32faa862c404cfae186d0e41f378f997d85cb Mon Sep 17 00:00:00 2001 From: Niraj Kamdar Date: Tue, 11 Jul 2023 20:55:17 +0800 Subject: [PATCH 04/24] fix: issues --- src/engine.rs | 8 +------- src/generator.rs | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index 8413f43..760f871 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -317,19 +317,13 @@ impl Engine { let cli = PolywrapCli::new(); let mut command = cli.command.unwrap(); - let mut build = command + let build = command .arg("build") .arg("-v") .arg("-l") .arg("./log.txt") .current_dir(&directory); - if let Some(i) = implementation { - if i == "go" { - build = build.arg("-s").arg("local") - } - } - if let Ok(output) = build.output() { let message = if let Some(i) = implementation { if let Some(s) = subpath { diff --git a/src/generator.rs b/src/generator.rs index 9fa81b0..d2e9865 100644 --- a/src/generator.rs +++ b/src/generator.rs @@ -156,7 +156,7 @@ impl Generate { if implementation == "go" { subpath = "module"; } else { - subpath = "src;" + subpath = "src"; } let destination_source_folder = &destination_path.join(subpath); fs::create_dir(destination_source_folder)?; From 514697ce59554aafe61876432025f36540d8c048 Mon Sep 17 00:00:00 2001 From: Niraj Kamdar Date: Wed, 12 Jul 2023 15:44:58 +0800 Subject: [PATCH 05/24] wip: test harness wraps --- .gitignore | 5 ++- cases/asyncify/implementations/go/module.go | 32 ++++++------- cases/json-type/implementations/go/module.go | 45 ++++++++++--------- cases/map-type/implementations/go/module.go | 14 +++--- cases/no-args/implementations/go/module.go | 4 +- .../numbers-type/implementations/go/module.go | 12 ++--- 6 files changed, 58 insertions(+), 54 deletions(-) diff --git a/.gitignore b/.gitignore index e52ae10..d626cb1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,7 @@ wrap /target results.json /wrappers -yarn.lock \ No newline at end of file +yarn.lock +.env +venv/ +pyexpr/ \ No newline at end of file diff --git a/cases/asyncify/implementations/go/module.go b/cases/asyncify/implementations/go/module.go index e188cda..04c2155 100644 --- a/cases/asyncify/implementations/go/module.go +++ b/cases/asyncify/implementations/go/module.go @@ -3,70 +3,70 @@ package module import ( "errors" "github.com/polywrap/wrap-test-harness/go/module/wrap/types" - "github.com/polywrap/wrap-test-harness/go/module/wrap/storage_module" + storage_module "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/storage" "strconv" ) -func GetData(args *types.ArgsGetData) (uint32, error) { - v, err := storage_module.GetData(&storage_module.ArgsGetData{}) +func GetData(args *types.MethodArgsGetData) (uint32, error) { + v, err := storage_module.MethodGetData(&storage_module.ArgsGetData{}) if err != nil { return 0, errors.New(err.Error()) } return uint32(v), nil } -func SetDataWithLargeArgs(args *types.ArgsSetDataWithLargeArgs) (string, error) { +func SetDataWithLargeArgs(args *types.MethodArgsSetDataWithLargeArgs) (string, error) { largeString := args.Value - _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 66}) + _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 66}) if err != nil { return "", errors.New(err.Error()) } return largeString, nil } -func SetDataWithManyArgs(args *types.ArgsSetDataWithManyArgs) (string, error) { - _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 55}) +func SetDataWithManyArgs(args *types.MethodArgsSetDataWithManyArgs) (string, error) { + _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 55}) if err != nil { return "", errors.New(err.Error()) } return args.ValueA + args.ValueB + args.ValueC + args.ValueD + args.ValueE + args.ValueF + args.ValueG + args.ValueH + args.ValueI + args.ValueJ + args.ValueK + args.ValueL, nil } -func SetDataWithManyStructuredArgs(args *types.ArgsSetDataWithManyStructuredArgs) (bool, error) { - _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 44}) +func SetDataWithManyStructuredArgs(args *types.MethodArgsSetDataWithManyStructuredArgs) (bool, error) { + _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 44}) if err != nil { return false, errors.New(err.Error()) } return true, nil } -func LocalVarMethod(args *types.ArgsLocalVarMethod) (bool, error) { - _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 88}) +func LocalVarMethod(args *types.MethodArgsLocalVarMethod) (bool, error) { + _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 88}) if err != nil { return false, errors.New(err.Error()) } return true, nil } -func GlobalVarMethod(args *types.ArgsGlobalVarMethod) (bool, error) { - _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 77}) +func GlobalVarMethod(args *types.MethodArgsGlobalVarMethod) (bool, error) { + _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 77}) if err != nil { return false, errors.New(err.Error()) } return true, nil } -func SubsequentInvokes(args *types.ArgsSubsequentInvokes) ([]string, error) { +func SubsequentInvokes(args *types.MethodArgsSubsequentInvokes) ([]string, error) { var result []string var err error for i := 0; i < int(args.NumberOfTimes); i++ { - _, errSet := storage_module.SetData(&storage_module.ArgsSetData{Value: i}) + _, errSet := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: i}) if errSet != nil { err = errSet break } - data, errGet := storage_module.GetData(&storage_module.ArgsGetData{}) + data, errGet := storage_module.MethodGetData(&storage_module.ArgsGetData{}) if errGet != nil { err = errGet break diff --git a/cases/json-type/implementations/go/module.go b/cases/json-type/implementations/go/module.go index e024051..a677973 100644 --- a/cases/json-type/implementations/go/module.go +++ b/cases/json-type/implementations/go/module.go @@ -2,56 +2,59 @@ package module import ( "encoding/json" - "errors" + "github.com/valyala/fastjson" "github.com/polywrap/wrap-test-harness/go/module/wrap/types" ) -func Stringify(args *types.ArgsStringify) (string, error) { +func Stringify(args *types.MethodArgsStringify) (string) { var newString string for _, object := range args.Values { newString += object.String() } - return newString, nil + return newString } -func Parse(args *types.ArgsParse) (interface{}) { - var value interface{} +func Parse(args *types.MethodArgsParse) *fastjson.Value { + var value fastjson.Value err := json.Unmarshal([]byte(args.Value), &value) if err != nil { - return nil, err + panic(err) } - return value + return &value } -func StringifyObject(args *types.ArgsStringifyObject) (string) { +func StringifyObject(args *types.MethodArgsStringifyObject) (string) { var newString string - newString += args.Object.JSONA.String() - newString += args.Object.JSONB.String() + newString += args.Object.JsonA.String() + newString += args.Object.JsonB.String() return newString } -func MethodJSON(args *types.ArgsMethodJSON) (interface{}) { - value := map[string]interface{}{ - "valueA": args.ValueA, - "valueB": args.ValueB, - "valueC": args.ValueC, +func MethodJSON(args *types.MethodArgsMethodJSON) *fastjson.Value { + jsonValue, jsonErr := json.Marshal(args) + if jsonErr != nil { + panic(jsonErr) + } + value, err := fastjson.ParseBytes(jsonValue) + if err != nil { + panic(err) } return value } -func ParseReserved(args *types.ArgsParseReserved) (interface{}) { - var reserved interface{} - err := json.Unmarshal([]byte(args.JSON), &reserved) +func ParseReserved(args *types.MethodArgsParseReserved) types.Reserved { + var reserved types.Reserved + err := json.Unmarshal([]byte(args.Json), &reserved) if err != nil { - return nil + panic(err) } return reserved } -func StringifyReserved(args *types.ArgsStringifyReserved) (string) { +func StringifyReserved(args *types.MethodArgsStringifyReserved) (string) { jsonString, err := json.Marshal(args.Reserved) if err != nil { - return "" + panic(err) } return string(jsonString) } diff --git a/cases/map-type/implementations/go/module.go b/cases/map-type/implementations/go/module.go index 085d3ec..278c984 100644 --- a/cases/map-type/implementations/go/module.go +++ b/cases/map-type/implementations/go/module.go @@ -4,8 +4,8 @@ import ( "github.com/polywrap/wrap-test-harness/go/module/wrap/types" ) -func GetKey(args *types.ArgsGetKey) int32 { - value, exists := args.Foo.Map[args.Key] +func GetKey(args *types.MethodArgsGetKey) int32 { + value, exists := args.Foo.M_map[args.Key] if !exists { // Return a default value or handle the case when the key is not found return 0 @@ -13,14 +13,14 @@ func GetKey(args *types.ArgsGetKey) int32 { return value } -func ReturnMap(args *types.ArgsReturnMap) map[string]int32 { - return args.Map +func ReturnMap(args *types.MethodArgsReturnMap) map[string]int32 { + return args.M_map } -func ReturnCustomMap(args *types.ArgsReturnCustomMap) map[string]int32 { - return args.Foo.Map +func ReturnCustomMap(args *types.MethodArgsReturnCustomMap) types.CustomMap { + return args.Foo } -func ReturnNestedMap(args *types.ArgsReturnNestedMap) map[string]map[string]int32 { +func ReturnNestedMap(args *types.MethodArgsReturnNestedMap) map[string]map[string]int32 { return args.Foo } diff --git a/cases/no-args/implementations/go/module.go b/cases/no-args/implementations/go/module.go index 469785b..154651a 100644 --- a/cases/no-args/implementations/go/module.go +++ b/cases/no-args/implementations/go/module.go @@ -1,7 +1,5 @@ package module -import "github.com/polywrap/wrap-test-harness/go/module/wrap/types" - -func NoArgsMethod(args *types.ArgsNoArgsMethod) bool { +func NoArgsMethod() bool { return true } diff --git a/cases/numbers-type/implementations/go/module.go b/cases/numbers-type/implementations/go/module.go index 96235dd..9b01c4a 100644 --- a/cases/numbers-type/implementations/go/module.go +++ b/cases/numbers-type/implementations/go/module.go @@ -2,26 +2,26 @@ package module import "github.com/polywrap/wrap-test-harness/go/module/wrap/types" -func I8Method(args *types.ArgsI8Method) int8 { +func I8Method(args *types.MethodArgsI8Method) int8 { return args.First + args.Second } -func U8Method(args *types.ArgsU8Method) uint8 { +func U8Method(args *types.MethodArgsU8Method) uint8 { return args.First + args.Second } -func I16Method(args *types.ArgsI16Method) int16 { +func I16Method(args *types.MethodArgsI16Method) int16 { return args.First + args.Second } -func U16Method(args *types.ArgsU16Method) uint16 { +func U16Method(args *types.MethodArgsU16Method) uint16 { return args.First + args.Second } -func I32Method(args *types.ArgsI32Method) int32 { +func I32Method(args *types.MethodArgsI32Method) int32 { return args.First + args.Second } -func U32Method(args *types.ArgsU32Method) uint32 { +func U32Method(args *types.MethodArgsU32Method) uint32 { return args.First + args.Second } From 06af361ea7ab7fae701fc28eae9590424e20cc4f Mon Sep 17 00:00:00 2001 From: Niraj Kamdar Date: Wed, 12 Jul 2023 20:08:22 +0800 Subject: [PATCH 06/24] fix: asyncify issues --- cases/asyncify/implementations/go/module.go | 47 ++++++++++----------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/cases/asyncify/implementations/go/module.go b/cases/asyncify/implementations/go/module.go index 04c2155..910d603 100644 --- a/cases/asyncify/implementations/go/module.go +++ b/cases/asyncify/implementations/go/module.go @@ -1,67 +1,66 @@ package module import ( - "errors" "github.com/polywrap/wrap-test-harness/go/module/wrap/types" storage_module "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/storage" "strconv" ) -func GetData(args *types.MethodArgsGetData) (uint32, error) { +func GetData() uint32 { v, err := storage_module.MethodGetData(&storage_module.ArgsGetData{}) if err != nil { - return 0, errors.New(err.Error()) + panic(err) } - return uint32(v), nil + return uint32(v) } -func SetDataWithLargeArgs(args *types.MethodArgsSetDataWithLargeArgs) (string, error) { +func SetDataWithLargeArgs(args *types.MethodArgsSetDataWithLargeArgs) string { largeString := args.Value _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 66}) if err != nil { - return "", errors.New(err.Error()) + panic(err) } - return largeString, nil + return largeString } -func SetDataWithManyArgs(args *types.MethodArgsSetDataWithManyArgs) (string, error) { +func SetDataWithManyArgs(args *types.MethodArgsSetDataWithManyArgs) string { _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 55}) if err != nil { - return "", errors.New(err.Error()) + panic(err) } - return args.ValueA + args.ValueB + args.ValueC + args.ValueD + args.ValueE + args.ValueF + args.ValueG + args.ValueH + args.ValueI + args.ValueJ + args.ValueK + args.ValueL, nil + return args.ValueA + args.ValueB + args.ValueC + args.ValueD + args.ValueE + args.ValueF + args.ValueG + args.ValueH + args.ValueI + args.ValueJ + args.ValueK + args.ValueL } -func SetDataWithManyStructuredArgs(args *types.MethodArgsSetDataWithManyStructuredArgs) (bool, error) { +func SetDataWithManyStructuredArgs(args *types.MethodArgsSetDataWithManyStructuredArgs) bool { _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 44}) if err != nil { - return false, errors.New(err.Error()) + panic(err) } - return true, nil + return true } -func LocalVarMethod(args *types.MethodArgsLocalVarMethod) (bool, error) { +func LocalVarMethod() bool { _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 88}) if err != nil { - return false, errors.New(err.Error()) + panic(err) } - return true, nil + return true } -func GlobalVarMethod(args *types.MethodArgsGlobalVarMethod) (bool, error) { +func GlobalVarMethod() bool { _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 77}) if err != nil { - return false, errors.New(err.Error()) + panic(err) } - return true, nil + return true } -func SubsequentInvokes(args *types.MethodArgsSubsequentInvokes) ([]string, error) { +func SubsequentInvokes(args *types.MethodArgsSubsequentInvokes) []string { var result []string var err error for i := 0; i < int(args.NumberOfTimes); i++ { - _, errSet := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: i}) + _, errSet := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: int32(i)}) if errSet != nil { err = errSet break @@ -71,10 +70,10 @@ func SubsequentInvokes(args *types.MethodArgsSubsequentInvokes) ([]string, error err = errGet break } - result = append(result, strconv.Itoa(data)) + result = append(result, strconv.Itoa(int(data))) } if err != nil { - return nil, errors.New(err.Error()) + panic(err) } - return result, nil + return result } From 8560023c8a9522e2062054b94cce793e0111219a Mon Sep 17 00:00:00 2001 From: Niraj Kamdar Date: Thu, 13 Jul 2023 00:09:05 +0800 Subject: [PATCH 07/24] feat: add subinvoke go wraps --- .../00-main/implementations/go/module.go | 17 ++++++++++ .../implementations/go/module.go | 31 +++++++++++++++++++ .../implementations/go/module.go | 10 ++++++ 3 files changed, 58 insertions(+) create mode 100644 cases/env-type/00-main/implementations/go/module.go create mode 100644 cases/env-type/01-subinvoker/implementations/go/module.go create mode 100644 cases/env-type/02-subinvoker-with-env/implementations/go/module.go diff --git a/cases/env-type/00-main/implementations/go/module.go b/cases/env-type/00-main/implementations/go/module.go new file mode 100644 index 0000000..f24d35e --- /dev/null +++ b/cases/env-type/00-main/implementations/go/module.go @@ -0,0 +1,17 @@ +package module + +import ( + "github.com/polywrap/wrap-test-harness/go/module/wrap/types" +) + +func MethodNoEnv(args *types.MethodArgsMethodNoEnv) string { + return args.Arg +} + +func MethodRequireEnv(env *types.Env) types.Env { + return *env +} + +func MethodOptionalEnv(env *types.Env) *types.Env { + return env +} diff --git a/cases/env-type/01-subinvoker/implementations/go/module.go b/cases/env-type/01-subinvoker/implementations/go/module.go new file mode 100644 index 0000000..51a0c7c --- /dev/null +++ b/cases/env-type/01-subinvoker/implementations/go/module.go @@ -0,0 +1,31 @@ +package module + +import ( + "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/subinvoked" + "github.com/polywrap/wrap-test-harness/go/module/wrap/types" +) + +func SubinvokeMethodNoEnv(args *types.MethodArgsSubinvokeMethodNoEnv) string { + value, err := subinvoked.MethodMethodNoEnv(&subinvoked.ArgsMethodNoEnv{Arg: args.Arg}) + if err != nil { + panic(err) + } + return value +} + +func SubinvokeMethodRequireEnv() subinvoked.Subinvoked_Env { + value, err := subinvoked.MethodMethodRequireEnv(&subinvoked.ArgsMethodRequireEnv{}) + if err != nil { + panic(err) + } + return value +} + +func SubinvokeMethodOptionalEnv() *subinvoked.Subinvoked_Env { + value, err := subinvoked.MethodMethodOptionalEnv(&subinvoked.ArgsMethodOptionalEnv{}) + if err != nil { + panic(err) + } + return value +} + diff --git a/cases/env-type/02-subinvoker-with-env/implementations/go/module.go b/cases/env-type/02-subinvoker-with-env/implementations/go/module.go new file mode 100644 index 0000000..88ca616 --- /dev/null +++ b/cases/env-type/02-subinvoker-with-env/implementations/go/module.go @@ -0,0 +1,10 @@ +package module + +import ( + subinvoked_module "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/subinvoked_module_wrapped" + "github.com/polywrap/wrap-test-harness/go/module/wrap/types" +) + +func SubinvokeMethodRequireEnv(_ *types.MethodArgsSubinvokeMethodRequireEnv, _ types.Env) subinvoked_module.SubinvokedEnv { + return subinvoked_module.MethodRequireEnv(&subinvoked_module.ArgsMethodRequireEnv{}) +} From 654f4f5c1ae880f02457e3d0c688879ea7743be3 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Thu, 13 Jul 2023 01:51:10 +0200 Subject: [PATCH 08/24] chore: go asyncify passing --- cases/asyncify/client-config.ts | 2 +- cases/asyncify/implementations/go/module.go | 17 +++++++------ cases/asyncify/test.ts | 25 +++++++++++++++++++ .../bigint-type/implementations/go/module.go | 2 +- .../implementations/go/module.go | 2 +- .../implementations/go/module.go | 6 ++--- defaults/go.mod | 2 +- src/engine.rs | 19 +++++++------- src/main.rs | 6 ++++- 9 files changed, 56 insertions(+), 25 deletions(-) create mode 100644 cases/asyncify/test.ts diff --git a/cases/asyncify/client-config.ts b/cases/asyncify/client-config.ts index 6391c1d..6ca5fbd 100644 --- a/cases/asyncify/client-config.ts +++ b/cases/asyncify/client-config.ts @@ -24,7 +24,7 @@ export function configure(builder: IClientConfigBuilder): IClientConfigBuilder { } class MemoryStoragePlugin extends PluginModule> { - private _value: number; + private _value: number = 0; async getData(_: {}): Promise { await this.sleep(50); diff --git a/cases/asyncify/implementations/go/module.go b/cases/asyncify/implementations/go/module.go index 910d603..d5233a9 100644 --- a/cases/asyncify/implementations/go/module.go +++ b/cases/asyncify/implementations/go/module.go @@ -9,7 +9,7 @@ import ( func GetData() uint32 { v, err := storage_module.MethodGetData(&storage_module.ArgsGetData{}) if err != nil { - panic(err) + panic(err.Error()) } return uint32(v) } @@ -18,7 +18,7 @@ func SetDataWithLargeArgs(args *types.MethodArgsSetDataWithLargeArgs) string { largeString := args.Value _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 66}) if err != nil { - panic(err) + panic(err.Error()) } return largeString } @@ -26,7 +26,7 @@ func SetDataWithLargeArgs(args *types.MethodArgsSetDataWithLargeArgs) string { func SetDataWithManyArgs(args *types.MethodArgsSetDataWithManyArgs) string { _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 55}) if err != nil { - panic(err) + panic(err.Error()) } return args.ValueA + args.ValueB + args.ValueC + args.ValueD + args.ValueE + args.ValueF + args.ValueG + args.ValueH + args.ValueI + args.ValueJ + args.ValueK + args.ValueL } @@ -34,7 +34,7 @@ func SetDataWithManyArgs(args *types.MethodArgsSetDataWithManyArgs) string { func SetDataWithManyStructuredArgs(args *types.MethodArgsSetDataWithManyStructuredArgs) bool { _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 44}) if err != nil { - panic(err) + panic(err.Error()) } return true } @@ -42,7 +42,7 @@ func SetDataWithManyStructuredArgs(args *types.MethodArgsSetDataWithManyStructur func LocalVarMethod() bool { _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 88}) if err != nil { - panic(err) + panic(err.Error()) } return true } @@ -50,7 +50,7 @@ func LocalVarMethod() bool { func GlobalVarMethod() bool { _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 77}) if err != nil { - panic(err) + panic(err.Error()) } return true } @@ -70,10 +70,11 @@ func SubsequentInvokes(args *types.MethodArgsSubsequentInvokes) []string { err = errGet break } - result = append(result, strconv.Itoa(int(data))) + str := strconv.Itoa(int(data)) + result = append(result, str) } if err != nil { - panic(err) + panic(err.Error()) } return result } diff --git a/cases/asyncify/test.ts b/cases/asyncify/test.ts new file mode 100644 index 0000000..1a32e71 --- /dev/null +++ b/cases/asyncify/test.ts @@ -0,0 +1,25 @@ +import { PolywrapClient } from "@polywrap/client-js"; +import { ClientConfigBuilder } from "@polywrap/client-config-builder-js"; +import { WasmPackage } from "@polywrap/wasm-js"; +import fs from "fs"; + +import { configure } from "./client-config"; + +const packageDir = `${__dirname}/../../build/asyncify/implementations/go/build`; +const p = WasmPackage.from( + fs.readFileSync(packageDir + "/wrap.info"), + fs.readFileSync(packageDir + "/wrap.wasm"), +); + +const builder = new ClientConfigBuilder(); +builder.addDefaults(); +builder.addPackage("my/wrap", p); +const config = configure(builder).build(); +const client = new PolywrapClient(config); +client.invoke({ + uri: "my/wrap", + method: "subsequentInvokes", + args: { + numberOfTimes: 1 + } +}).then((res) => console.log(res)) diff --git a/cases/bigint-type/implementations/go/module.go b/cases/bigint-type/implementations/go/module.go index 03924c1..e486d9e 100644 --- a/cases/bigint-type/implementations/go/module.go +++ b/cases/bigint-type/implementations/go/module.go @@ -2,7 +2,7 @@ package module import ( "github.com/polywrap/wrap-test-harness/go/module/wrap/types" - big "github.com/polywrap/go-wrap/polywrap/msgpack/big" + big "github.com/polywrap/go-wrap/msgpack/big" ) func Method(args *types.MethodArgsMethod) (*big.Int) { diff --git a/cases/bignumber-type/implementations/go/module.go b/cases/bignumber-type/implementations/go/module.go index 813a894..1e411d7 100644 --- a/cases/bignumber-type/implementations/go/module.go +++ b/cases/bignumber-type/implementations/go/module.go @@ -2,7 +2,7 @@ package module import ( "github.com/polywrap/wrap-test-harness/go/module/wrap/types" - big "github.com/polywrap/go-wrap/polywrap/msgpack/big" + big "github.com/polywrap/go-wrap/msgpack/big" ) func Method(args *types.MethodArgsMethod) (*big.Int) { diff --git a/cases/env-type/01-subinvoker/implementations/go/module.go b/cases/env-type/01-subinvoker/implementations/go/module.go index 51a0c7c..37daab4 100644 --- a/cases/env-type/01-subinvoker/implementations/go/module.go +++ b/cases/env-type/01-subinvoker/implementations/go/module.go @@ -8,7 +8,7 @@ import ( func SubinvokeMethodNoEnv(args *types.MethodArgsSubinvokeMethodNoEnv) string { value, err := subinvoked.MethodMethodNoEnv(&subinvoked.ArgsMethodNoEnv{Arg: args.Arg}) if err != nil { - panic(err) + panic(err.Error()) } return value } @@ -16,7 +16,7 @@ func SubinvokeMethodNoEnv(args *types.MethodArgsSubinvokeMethodNoEnv) string { func SubinvokeMethodRequireEnv() subinvoked.Subinvoked_Env { value, err := subinvoked.MethodMethodRequireEnv(&subinvoked.ArgsMethodRequireEnv{}) if err != nil { - panic(err) + panic(err.Error()) } return value } @@ -24,7 +24,7 @@ func SubinvokeMethodRequireEnv() subinvoked.Subinvoked_Env { func SubinvokeMethodOptionalEnv() *subinvoked.Subinvoked_Env { value, err := subinvoked.MethodMethodOptionalEnv(&subinvoked.ArgsMethodOptionalEnv{}) if err != nil { - panic(err) + panic(err.Error()) } return value } diff --git a/defaults/go.mod b/defaults/go.mod index 20c1d2c..e212331 100644 --- a/defaults/go.mod +++ b/defaults/go.mod @@ -2,6 +2,6 @@ module github.com/polywrap/wrap-test-harness/go go 1.18 -require github.com/polywrap/go-wrap v0.0.0-20230706013513-29691688fe81 +require github.com/polywrap/go-wrap wrap-0.1 require github.com/valyala/fastjson v1.6.3 // indirect diff --git a/src/engine.rs b/src/engine.rs index 760f871..ce26b41 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -415,18 +415,19 @@ impl Engine { test.current_dir(&directory); - let mut message_error = String::new(); - if test.output().is_err() { - message_error = test.output().unwrap_err().to_string(); - }; + let test_result = test.output(); - let stderr = test.output().unwrap().stderr; - if !stderr.is_empty() { - message_error = String::from_utf8(stderr).unwrap(); + if test_result.is_err() { + return Err(TestError::TestExecutionError(test_result.unwrap_err().to_string())); } - if !message_error.is_empty() { - let message = format!("Error on polywrap CLI Test command: {}", message_error); + let test_output = test.output().unwrap(); + + let stderr = test_output.stderr; + if !stderr.is_empty() { + let stdout_str = String::from_utf8(test_output.stdout).unwrap(); + let stderr_str = String::from_utf8(stderr).unwrap(); + let message = format!("Error on polywrap CLI Test command. STDOUT:\n{}\n\nSTDERR:\n{}", stdout_str, stderr_str); return Err(TestError::TestExecutionError(message)); } diff --git a/src/main.rs b/src/main.rs index 7d4497d..2a4a20d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,7 +32,11 @@ async fn main() -> Result<(), HarnessError> { Engine::start( destination_path, source_path - ).execute(feature, implementation, sanitized_args.wrappers_path.is_some()).await?; + ).execute( + feature, + implementation, + sanitized_args.wrappers_path.is_some() + ).await?; if let Some(p) = sanitized_args.wrappers_path.as_deref() { if !p.eq("./wrappers") { From 87a04f7427fb0b0553236376403b64063fbe6195 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Thu, 13 Jul 2023 03:38:39 +0200 Subject: [PATCH 09/24] fix: json-type go implmentation --- cases/json-type/implementations/go/module.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cases/json-type/implementations/go/module.go b/cases/json-type/implementations/go/module.go index a677973..f5eae8a 100644 --- a/cases/json-type/implementations/go/module.go +++ b/cases/json-type/implementations/go/module.go @@ -15,12 +15,12 @@ func Stringify(args *types.MethodArgsStringify) (string) { } func Parse(args *types.MethodArgsParse) *fastjson.Value { - var value fastjson.Value - err := json.Unmarshal([]byte(args.Value), &value) + p := fastjson.Parser{} + value, err := p.Parse(args.Value) if err != nil { panic(err) } - return &value + return value } func StringifyObject(args *types.MethodArgsStringifyObject) (string) { From 4ddd97eb52c85b508376a1c83679cde9238cff80 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Thu, 13 Jul 2023 03:45:14 +0200 Subject: [PATCH 10/24] chore: fix object-type go impl --- cases/object-type/implementations/go/module.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cases/object-type/implementations/go/module.go b/cases/object-type/implementations/go/module.go index c571bda..69e9ab4 100644 --- a/cases/object-type/implementations/go/module.go +++ b/cases/object-type/implementations/go/module.go @@ -19,6 +19,13 @@ func Method1(args *types.MethodArgsMethod1) []types.Output { Prop: arg2.Circular.Prop, }, }) + } else { + outputs = append(outputs, types.Output{ + Prop: "", + Nested: types.Nested{ + Prop: "", + }, + }) } return outputs } From 05c7d8d9d430d696cd467c6366b4deabde8ead31 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Thu, 13 Jul 2023 04:19:46 +0200 Subject: [PATCH 11/24] chore: subinvoke functional --- .../00-subinvoke/implementations/go/module.go | 13 +++++++ .../01-invoke/implementations/go/module.go | 27 ++++++++++++++ .../02-consumer/implementations/go/module.go | 37 +++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 cases/subinvoke/00-subinvoke/implementations/go/module.go create mode 100644 cases/subinvoke/01-invoke/implementations/go/module.go create mode 100644 cases/subinvoke/02-consumer/implementations/go/module.go diff --git a/cases/subinvoke/00-subinvoke/implementations/go/module.go b/cases/subinvoke/00-subinvoke/implementations/go/module.go new file mode 100644 index 0000000..c46475d --- /dev/null +++ b/cases/subinvoke/00-subinvoke/implementations/go/module.go @@ -0,0 +1,13 @@ +package module + +import ( + "github.com/polywrap/wrap-test-harness/go/module/wrap/types" +) + +func Add(args *types.ArgsAdd) int32 { + return args.A + args.B +} + +func SubinvokeThrowError(args *types.ArgsSubinvokeThrowError) bool { + panic(args.A) +} diff --git a/cases/subinvoke/01-invoke/implementations/go/module.go b/cases/subinvoke/01-invoke/implementations/go/module.go new file mode 100644 index 0000000..0b54eaa --- /dev/null +++ b/cases/subinvoke/01-invoke/implementations/go/module.go @@ -0,0 +1,27 @@ +package module + +import ( + "github.com/polywrap/wrap-test-harness/go/module/wrap/types" + imported_subinvoke "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/imported_subinvoke" +) + +func AddAndIncrement(args *types.ArgsAddAndIncrement) int32 { + value, err := imported_subinvoke.Add(&imported_subinvoke.ArgsAdd{ + A: args.A, + B: args.B, + }) + if err != nil { + panic(err.Error()) + } + return value + 1 +} + +func InvokeThrowError(args *types.ArgsInvokeThrowError) bool { + result, err := imported_subinvoke.SubinvokeThrowError(&imported_subinvoke.ArgsSubinvokeThrowError{ + A: args.A, + }) + if err != nil { + panic(err.Error()) + } + return result +} diff --git a/cases/subinvoke/02-consumer/implementations/go/module.go b/cases/subinvoke/02-consumer/implementations/go/module.go new file mode 100644 index 0000000..2d762a9 --- /dev/null +++ b/cases/subinvoke/02-consumer/implementations/go/module.go @@ -0,0 +1,37 @@ +package module + +import ( + "github.com/polywrap/wrap-test-harness/go/module/wrap/types" + imported_invoke "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/imported_invoke" +) + +func AddAndIncrement(args *types.ArgsAddAndIncrement) int32 { + value, err := imported_invoke.AddAndIncrement(&imported_invoke.ArgsAddAndIncrement{ + A: args.A, + B: args.B, + }) + if err != nil { + panic(err.Error()) + } + return value + 1 +} + +func ThrowError(args *types.ArgsThrowError) bool { + result, err := imported_invoke.InvokeThrowError(&imported_invoke.ArgsInvokeThrowError{ + A: args.A, + }) + if err != nil { + panic(err.Error()) + } + return result +} + +func RethrowError(args *types.ArgsRethrowError) bool { + result, err := imported_invoke.InvokeThrowError(&imported_invoke.ArgsInvokeThrowError{ + A: args.A, + }) + if err != nil { + panic(err.Error()) + } + return result +} From 7d3e02c28f9c381ee5c16d2982eaa97523ac0877 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Thu, 13 Jul 2023 04:59:17 +0200 Subject: [PATCH 12/24] chore: update to latest bindings --- cases/asyncify/implementations/go/module.go | 24 +++++++++---------- .../bigint-type/implementations/go/module.go | 2 +- .../implementations/go/module.go | 2 +- cases/bytes-type/implementations/go/module.go | 2 +- cases/enum-type/implementations/go/module.go | 4 ++-- .../00-main/implementations/go/module.go | 2 +- .../implementations/go/module.go | 8 +++---- .../implementations/go/module.go | 4 ++-- .../invalid-type/implementations/go/module.go | 10 ++++---- cases/json-type/implementations/go/module.go | 12 +++++----- cases/map-type/implementations/go/module.go | 8 +++---- .../numbers-type/implementations/go/module.go | 12 +++++----- .../object-type/implementations/go/module.go | 8 +++---- 13 files changed, 49 insertions(+), 49 deletions(-) diff --git a/cases/asyncify/implementations/go/module.go b/cases/asyncify/implementations/go/module.go index d5233a9..62e6240 100644 --- a/cases/asyncify/implementations/go/module.go +++ b/cases/asyncify/implementations/go/module.go @@ -7,32 +7,32 @@ import ( ) func GetData() uint32 { - v, err := storage_module.MethodGetData(&storage_module.ArgsGetData{}) + v, err := storage_module.GetData(&storage_module.ArgsGetData{}) if err != nil { panic(err.Error()) } return uint32(v) } -func SetDataWithLargeArgs(args *types.MethodArgsSetDataWithLargeArgs) string { +func SetDataWithLargeArgs(args *types.ArgsSetDataWithLargeArgs) string { largeString := args.Value - _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 66}) + _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 66}) if err != nil { panic(err.Error()) } return largeString } -func SetDataWithManyArgs(args *types.MethodArgsSetDataWithManyArgs) string { - _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 55}) +func SetDataWithManyArgs(args *types.ArgsSetDataWithManyArgs) string { + _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 55}) if err != nil { panic(err.Error()) } return args.ValueA + args.ValueB + args.ValueC + args.ValueD + args.ValueE + args.ValueF + args.ValueG + args.ValueH + args.ValueI + args.ValueJ + args.ValueK + args.ValueL } -func SetDataWithManyStructuredArgs(args *types.MethodArgsSetDataWithManyStructuredArgs) bool { - _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 44}) +func SetDataWithManyStructuredArgs(args *types.ArgsSetDataWithManyStructuredArgs) bool { + _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 44}) if err != nil { panic(err.Error()) } @@ -40,7 +40,7 @@ func SetDataWithManyStructuredArgs(args *types.MethodArgsSetDataWithManyStructur } func LocalVarMethod() bool { - _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 88}) + _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 88}) if err != nil { panic(err.Error()) } @@ -48,24 +48,24 @@ func LocalVarMethod() bool { } func GlobalVarMethod() bool { - _, err := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: 77}) + _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 77}) if err != nil { panic(err.Error()) } return true } -func SubsequentInvokes(args *types.MethodArgsSubsequentInvokes) []string { +func SubsequentInvokes(args *types.ArgsSubsequentInvokes) []string { var result []string var err error for i := 0; i < int(args.NumberOfTimes); i++ { - _, errSet := storage_module.MethodSetData(&storage_module.ArgsSetData{Value: int32(i)}) + _, errSet := storage_module.SetData(&storage_module.ArgsSetData{Value: int32(i)}) if errSet != nil { err = errSet break } - data, errGet := storage_module.MethodGetData(&storage_module.ArgsGetData{}) + data, errGet := storage_module.GetData(&storage_module.ArgsGetData{}) if errGet != nil { err = errGet break diff --git a/cases/bigint-type/implementations/go/module.go b/cases/bigint-type/implementations/go/module.go index e486d9e..c6704cd 100644 --- a/cases/bigint-type/implementations/go/module.go +++ b/cases/bigint-type/implementations/go/module.go @@ -5,7 +5,7 @@ import ( big "github.com/polywrap/go-wrap/msgpack/big" ) -func Method(args *types.MethodArgsMethod) (*big.Int) { +func Method(args *types.ArgsMethod) (*big.Int) { result := new(big.Int).Mul(args.Arg1, args.Obj.Prop1) if args.Arg2 != nil { diff --git a/cases/bignumber-type/implementations/go/module.go b/cases/bignumber-type/implementations/go/module.go index 1e411d7..1a08bef 100644 --- a/cases/bignumber-type/implementations/go/module.go +++ b/cases/bignumber-type/implementations/go/module.go @@ -5,7 +5,7 @@ import ( big "github.com/polywrap/go-wrap/msgpack/big" ) -func Method(args *types.MethodArgsMethod) (*big.Int) { +func Method(args *types.ArgsMethod) (*big.Int) { result := big.NewInt(0).Mul(args.Arg1, args.Obj.Prop1) if args.Arg2 != nil { diff --git a/cases/bytes-type/implementations/go/module.go b/cases/bytes-type/implementations/go/module.go index 324d06e..fdaaf5d 100644 --- a/cases/bytes-type/implementations/go/module.go +++ b/cases/bytes-type/implementations/go/module.go @@ -4,7 +4,7 @@ import ( "github.com/polywrap/wrap-test-harness/go/module/wrap/types" ) -func BytesMethod(args *types.MethodArgsBytesMethod) ([]byte) { +func BytesMethod(args *types.ArgsBytesMethod) ([]byte) { s := string(args.Arg.Prop) result := []byte(s + " Sanity!") return result diff --git a/cases/enum-type/implementations/go/module.go b/cases/enum-type/implementations/go/module.go index 4fdc7a1..b85eed9 100644 --- a/cases/enum-type/implementations/go/module.go +++ b/cases/enum-type/implementations/go/module.go @@ -2,10 +2,10 @@ package module import "github.com/polywrap/wrap-test-harness/go/module/wrap/types" -func Method1(args *types.MethodArgsMethod1) types.SanityEnum { +func Method1(args *types.ArgsMethod1) types.SanityEnum { return args.En } -func Method2(args *types.MethodArgsMethod2) []types.SanityEnum { +func Method2(args *types.ArgsMethod2) []types.SanityEnum { return args.EnumArray } diff --git a/cases/env-type/00-main/implementations/go/module.go b/cases/env-type/00-main/implementations/go/module.go index f24d35e..fcd0a5b 100644 --- a/cases/env-type/00-main/implementations/go/module.go +++ b/cases/env-type/00-main/implementations/go/module.go @@ -4,7 +4,7 @@ import ( "github.com/polywrap/wrap-test-harness/go/module/wrap/types" ) -func MethodNoEnv(args *types.MethodArgsMethodNoEnv) string { +func MethodNoEnv(args *types.ArgsMethodNoEnv) string { return args.Arg } diff --git a/cases/env-type/01-subinvoker/implementations/go/module.go b/cases/env-type/01-subinvoker/implementations/go/module.go index 37daab4..5ea07a8 100644 --- a/cases/env-type/01-subinvoker/implementations/go/module.go +++ b/cases/env-type/01-subinvoker/implementations/go/module.go @@ -5,8 +5,8 @@ import ( "github.com/polywrap/wrap-test-harness/go/module/wrap/types" ) -func SubinvokeMethodNoEnv(args *types.MethodArgsSubinvokeMethodNoEnv) string { - value, err := subinvoked.MethodMethodNoEnv(&subinvoked.ArgsMethodNoEnv{Arg: args.Arg}) +func SubinvokeMethodNoEnv(args *types.ArgsSubinvokeMethodNoEnv) string { + value, err := subinvoked.NoEnv(&subinvoked.ArgsMethodNoEnv{Arg: args.Arg}) if err != nil { panic(err.Error()) } @@ -14,7 +14,7 @@ func SubinvokeMethodNoEnv(args *types.MethodArgsSubinvokeMethodNoEnv) string { } func SubinvokeMethodRequireEnv() subinvoked.Subinvoked_Env { - value, err := subinvoked.MethodMethodRequireEnv(&subinvoked.ArgsMethodRequireEnv{}) + value, err := subinvoked.RequireEnv(&subinvoked.ArgsMethodRequireEnv{}) if err != nil { panic(err.Error()) } @@ -22,7 +22,7 @@ func SubinvokeMethodRequireEnv() subinvoked.Subinvoked_Env { } func SubinvokeMethodOptionalEnv() *subinvoked.Subinvoked_Env { - value, err := subinvoked.MethodMethodOptionalEnv(&subinvoked.ArgsMethodOptionalEnv{}) + value, err := subinvoked.OptionalEnv(&subinvoked.ArgsMethodOptionalEnv{}) if err != nil { panic(err.Error()) } diff --git a/cases/env-type/02-subinvoker-with-env/implementations/go/module.go b/cases/env-type/02-subinvoker-with-env/implementations/go/module.go index 88ca616..f931feb 100644 --- a/cases/env-type/02-subinvoker-with-env/implementations/go/module.go +++ b/cases/env-type/02-subinvoker-with-env/implementations/go/module.go @@ -5,6 +5,6 @@ import ( "github.com/polywrap/wrap-test-harness/go/module/wrap/types" ) -func SubinvokeMethodRequireEnv(_ *types.MethodArgsSubinvokeMethodRequireEnv, _ types.Env) subinvoked_module.SubinvokedEnv { - return subinvoked_module.MethodRequireEnv(&subinvoked_module.ArgsMethodRequireEnv{}) +func SubinvokeMethodRequireEnv(_ *types.ArgsSubinvokeMethodRequireEnv, _ types.Env) subinvoked_module.SubinvokedEnv { + return subinvoked_module.RequireEnv(&subinvoked_module.ArgsMethodRequireEnv{}) } diff --git a/cases/invalid-type/implementations/go/module.go b/cases/invalid-type/implementations/go/module.go index 80bddf1..4c5a987 100644 --- a/cases/invalid-type/implementations/go/module.go +++ b/cases/invalid-type/implementations/go/module.go @@ -2,22 +2,22 @@ package module import "github.com/polywrap/wrap-test-harness/go/module/wrap/types" -func BoolMethod(args *types.MethodArgsBoolMethod) (bool) { +func BoolMethod(args *types.ArgsBoolMethod) (bool) { return args.Arg } -func IntMethod(args *types.MethodArgsIntMethod) (int32) { +func IntMethod(args *types.ArgsIntMethod) (int32) { return args.Arg } -func UIntMethod(args *types.MethodArgsUIntMethod) (uint32) { +func UIntMethod(args *types.ArgsUIntMethod) (uint32) { return args.Arg } -func BytesMethod(args *types.MethodArgsBytesMethod) ([]uint8) { +func BytesMethod(args *types.ArgsBytesMethod) ([]uint8) { return args.Arg } -func ArrayMethod(args *types.MethodArgsArrayMethod) ([]string) { +func ArrayMethod(args *types.ArgsArrayMethod) ([]string) { return args.Arg } diff --git a/cases/json-type/implementations/go/module.go b/cases/json-type/implementations/go/module.go index f5eae8a..e184c23 100644 --- a/cases/json-type/implementations/go/module.go +++ b/cases/json-type/implementations/go/module.go @@ -6,7 +6,7 @@ import ( "github.com/polywrap/wrap-test-harness/go/module/wrap/types" ) -func Stringify(args *types.MethodArgsStringify) (string) { +func Stringify(args *types.ArgsStringify) (string) { var newString string for _, object := range args.Values { newString += object.String() @@ -14,7 +14,7 @@ func Stringify(args *types.MethodArgsStringify) (string) { return newString } -func Parse(args *types.MethodArgsParse) *fastjson.Value { +func Parse(args *types.ArgsParse) *fastjson.Value { p := fastjson.Parser{} value, err := p.Parse(args.Value) if err != nil { @@ -23,14 +23,14 @@ func Parse(args *types.MethodArgsParse) *fastjson.Value { return value } -func StringifyObject(args *types.MethodArgsStringifyObject) (string) { +func StringifyObject(args *types.ArgsStringifyObject) (string) { var newString string newString += args.Object.JsonA.String() newString += args.Object.JsonB.String() return newString } -func MethodJSON(args *types.MethodArgsMethodJSON) *fastjson.Value { +func MethodJSON(args *types.ArgsMethodJSON) *fastjson.Value { jsonValue, jsonErr := json.Marshal(args) if jsonErr != nil { panic(jsonErr) @@ -42,7 +42,7 @@ func MethodJSON(args *types.MethodArgsMethodJSON) *fastjson.Value { return value } -func ParseReserved(args *types.MethodArgsParseReserved) types.Reserved { +func ParseReserved(args *types.ArgsParseReserved) types.Reserved { var reserved types.Reserved err := json.Unmarshal([]byte(args.Json), &reserved) if err != nil { @@ -51,7 +51,7 @@ func ParseReserved(args *types.MethodArgsParseReserved) types.Reserved { return reserved } -func StringifyReserved(args *types.MethodArgsStringifyReserved) (string) { +func StringifyReserved(args *types.ArgsStringifyReserved) (string) { jsonString, err := json.Marshal(args.Reserved) if err != nil { panic(err) diff --git a/cases/map-type/implementations/go/module.go b/cases/map-type/implementations/go/module.go index 278c984..b7079d2 100644 --- a/cases/map-type/implementations/go/module.go +++ b/cases/map-type/implementations/go/module.go @@ -4,7 +4,7 @@ import ( "github.com/polywrap/wrap-test-harness/go/module/wrap/types" ) -func GetKey(args *types.MethodArgsGetKey) int32 { +func GetKey(args *types.ArgsGetKey) int32 { value, exists := args.Foo.M_map[args.Key] if !exists { // Return a default value or handle the case when the key is not found @@ -13,14 +13,14 @@ func GetKey(args *types.MethodArgsGetKey) int32 { return value } -func ReturnMap(args *types.MethodArgsReturnMap) map[string]int32 { +func ReturnMap(args *types.ArgsReturnMap) map[string]int32 { return args.M_map } -func ReturnCustomMap(args *types.MethodArgsReturnCustomMap) types.CustomMap { +func ReturnCustomMap(args *types.ArgsReturnCustomMap) types.CustomMap { return args.Foo } -func ReturnNestedMap(args *types.MethodArgsReturnNestedMap) map[string]map[string]int32 { +func ReturnNestedMap(args *types.ArgsReturnNestedMap) map[string]map[string]int32 { return args.Foo } diff --git a/cases/numbers-type/implementations/go/module.go b/cases/numbers-type/implementations/go/module.go index 9b01c4a..96235dd 100644 --- a/cases/numbers-type/implementations/go/module.go +++ b/cases/numbers-type/implementations/go/module.go @@ -2,26 +2,26 @@ package module import "github.com/polywrap/wrap-test-harness/go/module/wrap/types" -func I8Method(args *types.MethodArgsI8Method) int8 { +func I8Method(args *types.ArgsI8Method) int8 { return args.First + args.Second } -func U8Method(args *types.MethodArgsU8Method) uint8 { +func U8Method(args *types.ArgsU8Method) uint8 { return args.First + args.Second } -func I16Method(args *types.MethodArgsI16Method) int16 { +func I16Method(args *types.ArgsI16Method) int16 { return args.First + args.Second } -func U16Method(args *types.MethodArgsU16Method) uint16 { +func U16Method(args *types.ArgsU16Method) uint16 { return args.First + args.Second } -func I32Method(args *types.MethodArgsI32Method) int32 { +func I32Method(args *types.ArgsI32Method) int32 { return args.First + args.Second } -func U32Method(args *types.MethodArgsU32Method) uint32 { +func U32Method(args *types.ArgsU32Method) uint32 { return args.First + args.Second } diff --git a/cases/object-type/implementations/go/module.go b/cases/object-type/implementations/go/module.go index 69e9ab4..be2cd6a 100644 --- a/cases/object-type/implementations/go/module.go +++ b/cases/object-type/implementations/go/module.go @@ -2,7 +2,7 @@ package module import "github.com/polywrap/wrap-test-harness/go/module/wrap/types" -func Method1(args *types.MethodArgsMethod1) []types.Output { +func Method1(args *types.ArgsMethod1) []types.Output { outputs := []types.Output{ { Prop: args.Arg1.Prop, @@ -30,7 +30,7 @@ func Method1(args *types.MethodArgsMethod1) []types.Output { return outputs } -func Method2(args *types.MethodArgsMethod2) *types.Output { +func Method2(args *types.ArgsMethod2) *types.Output { if args.Arg.Prop == "null" { return nil } @@ -42,7 +42,7 @@ func Method2(args *types.MethodArgsMethod2) *types.Output { } } -func Method3(args *types.MethodArgsMethod3) []*types.Output { +func Method3(args *types.ArgsMethod3) []*types.Output { outputs := []*types.Output{ nil, } @@ -55,7 +55,7 @@ func Method3(args *types.MethodArgsMethod3) []*types.Output { return outputs } -func Method4(args *types.MethodArgsMethod4) types.Output { +func Method4(args *types.ArgsMethod4) types.Output { return types.Output{ Prop: string(args.Arg.Prop), Nested: types.Nested{ From d30a50b45b5cca28f40fefe1f996ddfdfe9496b0 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Thu, 13 Jul 2023 05:33:48 +0200 Subject: [PATCH 13/24] chore: minor updates --- cases/asyncify/test.ts | 25 ----------------- .../implementations/go/module.go | 2 +- .../implementations/go/module.go | 6 ++-- .../01-redirect/implementations/go/module.go | 28 +++++++++++++++++++ .../02-fs/implementations/go/module.go | 28 +++++++++++++++++++ run.sh | 3 ++ todo | 18 ++++++++++++ 7 files changed, 81 insertions(+), 29 deletions(-) delete mode 100644 cases/asyncify/test.ts create mode 100644 cases/resolver/01-redirect/implementations/go/module.go create mode 100644 cases/resolver/02-fs/implementations/go/module.go create mode 100755 run.sh create mode 100644 todo diff --git a/cases/asyncify/test.ts b/cases/asyncify/test.ts deleted file mode 100644 index 1a32e71..0000000 --- a/cases/asyncify/test.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { PolywrapClient } from "@polywrap/client-js"; -import { ClientConfigBuilder } from "@polywrap/client-config-builder-js"; -import { WasmPackage } from "@polywrap/wasm-js"; -import fs from "fs"; - -import { configure } from "./client-config"; - -const packageDir = `${__dirname}/../../build/asyncify/implementations/go/build`; -const p = WasmPackage.from( - fs.readFileSync(packageDir + "/wrap.info"), - fs.readFileSync(packageDir + "/wrap.wasm"), -); - -const builder = new ClientConfigBuilder(); -builder.addDefaults(); -builder.addPackage("my/wrap", p); -const config = configure(builder).build(); -const client = new PolywrapClient(config); -client.invoke({ - uri: "my/wrap", - method: "subsequentInvokes", - args: { - numberOfTimes: 1 - } -}).then((res) => console.log(res)) diff --git a/cases/env-type/01-subinvoker/implementations/go/module.go b/cases/env-type/01-subinvoker/implementations/go/module.go index 5ea07a8..2760599 100644 --- a/cases/env-type/01-subinvoker/implementations/go/module.go +++ b/cases/env-type/01-subinvoker/implementations/go/module.go @@ -1,7 +1,7 @@ package module import ( - "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/subinvoked" + subinvoked "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/subinvoked" "github.com/polywrap/wrap-test-harness/go/module/wrap/types" ) diff --git a/cases/env-type/02-subinvoker-with-env/implementations/go/module.go b/cases/env-type/02-subinvoker-with-env/implementations/go/module.go index f931feb..f717cf7 100644 --- a/cases/env-type/02-subinvoker-with-env/implementations/go/module.go +++ b/cases/env-type/02-subinvoker-with-env/implementations/go/module.go @@ -1,10 +1,10 @@ package module import ( - subinvoked_module "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/subinvoked_module_wrapped" + subinvoked "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/subinvoked" "github.com/polywrap/wrap-test-harness/go/module/wrap/types" ) -func SubinvokeMethodRequireEnv(_ *types.ArgsSubinvokeMethodRequireEnv, _ types.Env) subinvoked_module.SubinvokedEnv { - return subinvoked_module.RequireEnv(&subinvoked_module.ArgsMethodRequireEnv{}) +func SubinvokeMethodRequireEnv(_ *types.ArgsSubinvokeMethodRequireEnv, _ types.Env) subinvoked.SubinvokedEnv { + return subinvoked.RequireEnv(&subinvoked.ArgsMethodRequireEnv{}) } diff --git a/cases/resolver/01-redirect/implementations/go/module.go b/cases/resolver/01-redirect/implementations/go/module.go new file mode 100644 index 0000000..4dd0f5d --- /dev/null +++ b/cases/resolver/01-redirect/implementations/go/module.go @@ -0,0 +1,28 @@ +package module + +import ( + "github.com/polywrap/wrap-test-harness/go/module/wrap/types" + uri_resolver "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/uri_resolver" + + "fmt" +) + +func TryResolveUri(args *types.ArgsTryResolveUri) *uri_resolver.UriResolver_MaybeUriOrManifest { + if args.Authority == "custom-authority" { + uri := fmt.Sprintf("wrap://%s/%s", args.Authority, args.Path) + return &uri_resolver.UriResolver_MaybeUriOrManifest{ + Uri: &uri, + Manifest: nil, + } + } else { + uri := fmt.Sprintf("wrap://custom-fs/%s", args.Path) + return &uri_resolver.UriResolver_MaybeUriOrManifest{ + Uri: &uri, + Manifest: nil, + } + } +} + +func GetFile(args *types.ArgsGetFile) []byte { + return nil +} diff --git a/cases/resolver/02-fs/implementations/go/module.go b/cases/resolver/02-fs/implementations/go/module.go new file mode 100644 index 0000000..0a225af --- /dev/null +++ b/cases/resolver/02-fs/implementations/go/module.go @@ -0,0 +1,28 @@ +package module + +import ( + "github.com/polywrap/wrap-test-harness/go/module/wrap/types" + uri_resolver "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/uri_resolver" + + "fmt" +) + +func TryResolveUri(args *types.ArgsTryResolveUri) *uri_resolver.UriResolver_MaybeUriOrManifest { + if args.Authority == "custom-fs" { + uri := fmt.Sprintf("wrap://file/%s", args.Path) + return &uri_resolver.UriResolver_MaybeUriOrManifest{ + Uri: &uri, + Manifest: nil, + } + } else { + uri := fmt.Sprintf("wrap://%s/%s", args.Authority, args.Path) + return &uri_resolver.UriResolver_MaybeUriOrManifest{ + Uri: &uri, + manifest: nil, + } + } +} + +func GetFile(args *types.ArgsGetFile) []byte { + return nil +} diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..9937aaf --- /dev/null +++ b/run.sh @@ -0,0 +1,3 @@ +export POLYWRAP_CLI_PATH="/home/jelli/Dev/Repos/wrap/cli/packages/cli" + +cargo run -- -i=interface-invoke -f=env-type -v=1 \ No newline at end of file diff --git a/todo b/todo new file mode 100644 index 0000000..aa42a53 --- /dev/null +++ b/todo @@ -0,0 +1,18 @@ +working: +- asyncify +- bigint-type +- bignumber-type +- bytes-type +- enum-type +- invalid-type +- map-type +- numbers-type +- no-args +- json-type +- object-type +- subinvoke + +not-working: +- resolver +- env-type +- interface-invoke From 2a596b24c76eb724cb587ced57c8c23744505bb9 Mon Sep 17 00:00:00 2001 From: Cesar Date: Mon, 17 Jul 2023 14:50:46 +0200 Subject: [PATCH 14/24] chore(cases): update with latest rust wrap bindings --- cases/bigint-type/implementations/rs/lib.rs | 11 +++++------ cases/env-type/00-main/implementations/rs/lib.rs | 1 - .../01-subinvoker/implementations/rs/lib.rs | 2 -- .../implementations/rs/lib.rs | 2 -- .../01-implementation/implementations/rs/lib.rs | 1 - .../02-wrapper/implementations/rs/lib.rs | 3 +-- cases/invalid-type/implementations/rs/lib.rs | 1 - cases/json-type/implementations/rs/lib.rs | 16 ++++++++-------- defaults/Cargo.toml | 6 ++++-- 9 files changed, 18 insertions(+), 25 deletions(-) diff --git a/cases/bigint-type/implementations/rs/lib.rs b/cases/bigint-type/implementations/rs/lib.rs index efe4bf5..633b22f 100644 --- a/cases/bigint-type/implementations/rs/lib.rs +++ b/cases/bigint-type/implementations/rs/lib.rs @@ -1,19 +1,18 @@ use std::ops::Mul; -use polywrap_wasm_rs::BigInt; +use polywrap_msgpack_serde::BigIntWrapper; pub mod wrap; -use wrap::module::{Module, ModuleTrait}; pub use wrap::*; impl ModuleTrait for Module { - fn method(args: ArgsMethod) -> Result { - let mut result = args.arg1.mul(args.obj.prop1); + fn method(args: ArgsMethod) -> Result { + let mut result = args.arg1.0.mul(args.obj.prop1.0); if args.arg2.is_some() { - result = result.mul(args.arg2.unwrap()); + result = result.mul(args.arg2.unwrap().0); } if args.obj.prop2.is_some() { - result = result.mul(args.obj.prop2.unwrap()); + result = result.mul(args.obj.prop2.unwrap().0); } Ok(result) diff --git a/cases/env-type/00-main/implementations/rs/lib.rs b/cases/env-type/00-main/implementations/rs/lib.rs index 626523a..abd5896 100644 --- a/cases/env-type/00-main/implementations/rs/lib.rs +++ b/cases/env-type/00-main/implementations/rs/lib.rs @@ -1,7 +1,6 @@ pub mod wrap; pub use wrap::*; use wrap::env::Env; -use wrap::module::{ModuleTrait, Module}; impl ModuleTrait for Module { fn method_no_env(args: ArgsMethodNoEnv) -> Result { diff --git a/cases/env-type/01-subinvoker/implementations/rs/lib.rs b/cases/env-type/01-subinvoker/implementations/rs/lib.rs index 57bd9c0..777a764 100644 --- a/cases/env-type/01-subinvoker/implementations/rs/lib.rs +++ b/cases/env-type/01-subinvoker/implementations/rs/lib.rs @@ -1,8 +1,6 @@ pub mod wrap; pub use wrap::*; -use wrap::module::{ModuleTrait, Module}; - impl ModuleTrait for Module { fn subinvoke_method_no_env(args: ArgsSubinvokeMethodNoEnv) -> Result { SubinvokedModule::method_no_env(&(imported::ArgsMethodNoEnv {arg: args.arg})) diff --git a/cases/env-type/02-subinvoker-with-env/implementations/rs/lib.rs b/cases/env-type/02-subinvoker-with-env/implementations/rs/lib.rs index 5ced2aa..c18b7d4 100644 --- a/cases/env-type/02-subinvoker-with-env/implementations/rs/lib.rs +++ b/cases/env-type/02-subinvoker-with-env/implementations/rs/lib.rs @@ -2,8 +2,6 @@ pub mod wrap; pub use wrap::*; use wrap::env::Env; -use wrap::module::{ModuleTrait, Module}; - impl ModuleTrait for Module { fn subinvoke_method_require_env(_: ArgsSubinvokeMethodRequireEnv, _env: Env) -> Result { SubinvokedModule::method_require_env(&(imported::ArgsMethodRequireEnv {})) diff --git a/cases/interface-invoke/01-implementation/implementations/rs/lib.rs b/cases/interface-invoke/01-implementation/implementations/rs/lib.rs index 48c3797..dd607d3 100644 --- a/cases/interface-invoke/01-implementation/implementations/rs/lib.rs +++ b/cases/interface-invoke/01-implementation/implementations/rs/lib.rs @@ -1,6 +1,5 @@ pub mod wrap; pub use wrap::*; -use wrap::module::{ModuleTrait, Module}; impl ModuleTrait for Module { fn module_method(args: ArgsModuleMethod) -> Result { diff --git a/cases/interface-invoke/02-wrapper/implementations/rs/lib.rs b/cases/interface-invoke/02-wrapper/implementations/rs/lib.rs index 58dc8c5..0930d34 100644 --- a/cases/interface-invoke/02-wrapper/implementations/rs/lib.rs +++ b/cases/interface-invoke/02-wrapper/implementations/rs/lib.rs @@ -2,7 +2,6 @@ pub mod wrap; pub use wrap::*; pub use wrap::imported::interface_module; pub use wrap::imported::interface_argument; -use wrap::module::{ModuleTrait, Module}; impl ModuleTrait for Module { fn module_method(args: ArgsModuleMethod) -> Result { @@ -13,7 +12,7 @@ impl ModuleTrait for Module { let impls = Interface::get_implementations(); let uri: String = impls[1].to_owned(); let module = InterfaceModule::new(uri); - let method_args = interface_module::serialization::ArgsAbstractModuleMethod { + let method_args = interface_module::ArgsAbstractModuleMethod { arg: interface_argument::InterfaceArgument { str: args.arg.str } diff --git a/cases/invalid-type/implementations/rs/lib.rs b/cases/invalid-type/implementations/rs/lib.rs index b6c5508..01fc267 100644 --- a/cases/invalid-type/implementations/rs/lib.rs +++ b/cases/invalid-type/implementations/rs/lib.rs @@ -1,6 +1,5 @@ pub mod wrap; pub use wrap::*; -use wrap::module::{ModuleTrait, Module}; impl ModuleTrait for Module { fn bool_method(args: ArgsBoolMethod) -> Result { diff --git a/cases/json-type/implementations/rs/lib.rs b/cases/json-type/implementations/rs/lib.rs index 30d3b65..ad6e850 100644 --- a/cases/json-type/implementations/rs/lib.rs +++ b/cases/json-type/implementations/rs/lib.rs @@ -1,34 +1,34 @@ pub mod wrap; +use polywrap_msgpack_serde::JSONString; use polywrap_wasm_rs::JSON; use serde_json::json; -use wrap::module::{Module, ModuleTrait}; pub use wrap::*; impl ModuleTrait for Module { fn stringify(args: ArgsStringify) -> Result { let mut new_string = String::from(""); for object in &args.values { - new_string.push_str(&object.to_string()); + new_string.push_str(&object.to_json().to_string()); } Ok(new_string) } - fn parse(args: ArgsParse) -> Result { + fn parse(args: ArgsParse) -> Result { Ok(JSON::from_str(&args.value).unwrap()) } fn stringify_object(args: ArgsStringifyObject) -> Result { - let mut new_string = String::from(&args.object.json_a.to_string()); - new_string.push_str(&args.object.json_b.to_string()); + let mut new_string = String::from(&args.object.json_a.to_json().to_string()); + new_string.push_str(&args.object.json_b.to_json().to_string()); Ok(new_string) } - fn method_j_s_o_n(args: ArgsMethodJSON) -> Result { - Ok(json!({ + fn method_j_s_o_n(args: ArgsMethodJSON) -> Result { + Ok(JSONString::new(json!({ "valueA": args.value_a, "valueB": args.value_b, "valueC": args.value_c - })) + }))) } fn parse_reserved(args: ArgsParseReserved) -> Result { diff --git a/defaults/Cargo.toml b/defaults/Cargo.toml index 82e44e9..d0acb3b 100644 --- a/defaults/Cargo.toml +++ b/defaults/Cargo.toml @@ -7,9 +7,11 @@ license = "MIT" edition = "2021" [dependencies] -polywrap-wasm-rs = "0.10.3" +polywrap-wasm-rs = "0.11.0-pre.2" +polywrap_msgpack_serde = "0.0.2-beta.4" serde = { version = "1.0", features = ["derive"] } -serde_json = { version = "1.0", features = ["preserve_order"]} +serde_json = { version = "1.0", features = ["preserve_order"] } +serde_bytes = "0.11.5" [lib] crate-type = ["cdylib", "rlib"] From 96859a2ce45ae05bbca96d87411371002cd4dd7a Mon Sep 17 00:00:00 2001 From: Niraj Kamdar Date: Mon, 17 Jul 2023 23:19:25 +0800 Subject: [PATCH 15/24] fix: todo wraps are building --- .../implementations/go/module.go | 7 +++--- .../implementations/go/module.go | 5 ++-- .../implementations/go/module.go | 13 ++++++++++ .../02-wrapper/implementations/go/module.go | 24 +++++++++++++++++++ .../01-redirect/implementations/go/module.go | 8 +++---- .../02-fs/implementations/go/module.go | 11 ++++----- todo | 4 ++-- 7 files changed, 54 insertions(+), 18 deletions(-) create mode 100644 cases/interface-invoke/01-implementation/implementations/go/module.go create mode 100644 cases/interface-invoke/02-wrapper/implementations/go/module.go diff --git a/cases/env-type/01-subinvoker/implementations/go/module.go b/cases/env-type/01-subinvoker/implementations/go/module.go index 2760599..9b27b40 100644 --- a/cases/env-type/01-subinvoker/implementations/go/module.go +++ b/cases/env-type/01-subinvoker/implementations/go/module.go @@ -6,7 +6,7 @@ import ( ) func SubinvokeMethodNoEnv(args *types.ArgsSubinvokeMethodNoEnv) string { - value, err := subinvoked.NoEnv(&subinvoked.ArgsMethodNoEnv{Arg: args.Arg}) + value, err := subinvoked.MethodNoEnv(&subinvoked.ArgsMethodNoEnv{Arg: args.Arg}) if err != nil { panic(err.Error()) } @@ -14,7 +14,7 @@ func SubinvokeMethodNoEnv(args *types.ArgsSubinvokeMethodNoEnv) string { } func SubinvokeMethodRequireEnv() subinvoked.Subinvoked_Env { - value, err := subinvoked.RequireEnv(&subinvoked.ArgsMethodRequireEnv{}) + value, err := subinvoked.MethodRequireEnv(&subinvoked.ArgsMethodRequireEnv{}) if err != nil { panic(err.Error()) } @@ -22,10 +22,9 @@ func SubinvokeMethodRequireEnv() subinvoked.Subinvoked_Env { } func SubinvokeMethodOptionalEnv() *subinvoked.Subinvoked_Env { - value, err := subinvoked.OptionalEnv(&subinvoked.ArgsMethodOptionalEnv{}) + value, err := subinvoked.MethodOptionalEnv(&subinvoked.ArgsMethodOptionalEnv{}) if err != nil { panic(err.Error()) } return value } - diff --git a/cases/env-type/02-subinvoker-with-env/implementations/go/module.go b/cases/env-type/02-subinvoker-with-env/implementations/go/module.go index f717cf7..cea053b 100644 --- a/cases/env-type/02-subinvoker-with-env/implementations/go/module.go +++ b/cases/env-type/02-subinvoker-with-env/implementations/go/module.go @@ -5,6 +5,7 @@ import ( "github.com/polywrap/wrap-test-harness/go/module/wrap/types" ) -func SubinvokeMethodRequireEnv(_ *types.ArgsSubinvokeMethodRequireEnv, _ types.Env) subinvoked.SubinvokedEnv { - return subinvoked.RequireEnv(&subinvoked.ArgsMethodRequireEnv{}) +func SubinvokeMethodRequireEnv(_ *types.Env) subinvoked.Subinvoked_Env { + res, _ := subinvoked.MethodRequireEnv(&subinvoked.ArgsMethodRequireEnv{}) + return res } diff --git a/cases/interface-invoke/01-implementation/implementations/go/module.go b/cases/interface-invoke/01-implementation/implementations/go/module.go new file mode 100644 index 0000000..d0bc12d --- /dev/null +++ b/cases/interface-invoke/01-implementation/implementations/go/module.go @@ -0,0 +1,13 @@ +package module + +import ( + "github.com/polywrap/wrap-test-harness/go/module/wrap/types" +) + +func ModuleMethod(args *types.ArgsModuleMethod) types.ImplementationType { + return args.Arg +} + +func AbstractModuleMethod(args *types.ArgsAbstractModuleMethod) string { + return args.Arg.Str +} diff --git a/cases/interface-invoke/02-wrapper/implementations/go/module.go b/cases/interface-invoke/02-wrapper/implementations/go/module.go new file mode 100644 index 0000000..c572187 --- /dev/null +++ b/cases/interface-invoke/02-wrapper/implementations/go/module.go @@ -0,0 +1,24 @@ +package module + +import ( + . "github.com/polywrap/wrap-test-harness/go/module/wrap/interfaces" + . "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/pkginterface" + "github.com/polywrap/wrap-test-harness/go/module/wrap/types" +) + +func ModuleMethod(args *types.ArgsModuleMethod) types.ImplementationType { + return args.Arg +} + +func AbstractModuleMethod(args *types.ArgsAbstractModuleMethod) string { + impls := Interface_GetImplementations() + uri := impls[1] + methodArgs := &Interface_ArgsAbstractModuleMethod{ + Arg: args.Arg, + } + result, err := Interface_AbstractModuleMethod(uri, methodArgs) + if err != nil { + panic(err.Error()) + } + return result +} diff --git a/cases/resolver/01-redirect/implementations/go/module.go b/cases/resolver/01-redirect/implementations/go/module.go index 4dd0f5d..965ad11 100644 --- a/cases/resolver/01-redirect/implementations/go/module.go +++ b/cases/resolver/01-redirect/implementations/go/module.go @@ -2,21 +2,21 @@ package module import ( "github.com/polywrap/wrap-test-harness/go/module/wrap/types" - uri_resolver "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/uri_resolver" + . "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/uri_resolver" "fmt" ) -func TryResolveUri(args *types.ArgsTryResolveUri) *uri_resolver.UriResolver_MaybeUriOrManifest { +func TryResolveUri(args *types.ArgsTryResolveUri) *UriResolver_MaybeUriOrManifest { if args.Authority == "custom-authority" { uri := fmt.Sprintf("wrap://%s/%s", args.Authority, args.Path) - return &uri_resolver.UriResolver_MaybeUriOrManifest{ + return &UriResolver_MaybeUriOrManifest{ Uri: &uri, Manifest: nil, } } else { uri := fmt.Sprintf("wrap://custom-fs/%s", args.Path) - return &uri_resolver.UriResolver_MaybeUriOrManifest{ + return &UriResolver_MaybeUriOrManifest{ Uri: &uri, Manifest: nil, } diff --git a/cases/resolver/02-fs/implementations/go/module.go b/cases/resolver/02-fs/implementations/go/module.go index 0a225af..6ef5ac6 100644 --- a/cases/resolver/02-fs/implementations/go/module.go +++ b/cases/resolver/02-fs/implementations/go/module.go @@ -2,23 +2,22 @@ package module import ( "github.com/polywrap/wrap-test-harness/go/module/wrap/types" - uri_resolver "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/uri_resolver" - + . "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/uri_resolver" "fmt" ) -func TryResolveUri(args *types.ArgsTryResolveUri) *uri_resolver.UriResolver_MaybeUriOrManifest { +func TryResolveUri(args *types.ArgsTryResolveUri) *UriResolver_MaybeUriOrManifest { if args.Authority == "custom-fs" { uri := fmt.Sprintf("wrap://file/%s", args.Path) - return &uri_resolver.UriResolver_MaybeUriOrManifest{ + return &UriResolver_MaybeUriOrManifest{ Uri: &uri, Manifest: nil, } } else { uri := fmt.Sprintf("wrap://%s/%s", args.Authority, args.Path) - return &uri_resolver.UriResolver_MaybeUriOrManifest{ + return &UriResolver_MaybeUriOrManifest{ Uri: &uri, - manifest: nil, + Manifest: nil, } } } diff --git a/todo b/todo index aa42a53..f6a02b8 100644 --- a/todo +++ b/todo @@ -12,7 +12,7 @@ working: - object-type - subinvoke -not-working: -- resolver +building: - env-type +- resolver - interface-invoke From d12d793582aa381257cf7537cf739eb964745e6d Mon Sep 17 00:00:00 2001 From: Cesar Date: Tue, 18 Jul 2023 21:20:05 +0200 Subject: [PATCH 16/24] chore(ci): set rust to stable version --- .github/workflows/ci.yaml | 2 +- .github/workflows/release-pr.yaml | 2 +- .github/workflows/release-publish.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 51f5b4d..d8224a6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,7 +16,7 @@ jobs: - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: nightly + toolchain: 1.69.0 override: true - name: Install Clippy diff --git a/.github/workflows/release-pr.yaml b/.github/workflows/release-pr.yaml index f2d029d..afd0a92 100644 --- a/.github/workflows/release-pr.yaml +++ b/.github/workflows/release-pr.yaml @@ -161,7 +161,7 @@ jobs: - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: nightly + toolchain: 1.69.0 override: true - name: Apply Rust Version & Commit diff --git a/.github/workflows/release-publish.yaml b/.github/workflows/release-publish.yaml index 6d614db..7869df1 100644 --- a/.github/workflows/release-publish.yaml +++ b/.github/workflows/release-publish.yaml @@ -46,7 +46,7 @@ jobs: - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: nightly + toolchain: 1.69.0 override: true - name: Read .nvmrc into env.NVMRC From a503f164e5d64f55dbcb8f224c5842e5933a9b6a Mon Sep 17 00:00:00 2001 From: Cesar Date: Tue, 18 Jul 2023 21:43:45 +0200 Subject: [PATCH 17/24] chore: fix bigint rs --- cases/bigint-type/implementations/rs/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cases/bigint-type/implementations/rs/lib.rs b/cases/bigint-type/implementations/rs/lib.rs index 633b22f..5c82e63 100644 --- a/cases/bigint-type/implementations/rs/lib.rs +++ b/cases/bigint-type/implementations/rs/lib.rs @@ -15,6 +15,6 @@ impl ModuleTrait for Module { result = result.mul(args.obj.prop2.unwrap().0); } - Ok(result) + Ok(BigIntWrapper(result)) } } From 71d060bdc4f1bc493c355f788e1b335e21a29055 Mon Sep 17 00:00:00 2001 From: Cesar Date: Tue, 18 Jul 2023 21:45:17 +0200 Subject: [PATCH 18/24] chore(ci): add clippy without nightly --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d8224a6..4e369ee 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -20,7 +20,7 @@ jobs: override: true - name: Install Clippy - run: rustup component add clippy --toolchain nightly-x86_64-unknown-linux-gnu + run: rustup component add clippy - name: Lint run: cargo clippy @@ -34,7 +34,7 @@ jobs: - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: nightly + toolchain: 1.69.0 override: true - name: Read .nvmrc into env.NVMRC From 53b5b7a9fe9c769a99e7e7856dc1d74c41fd9cba Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Sun, 30 Jul 2023 13:24:32 -0400 Subject: [PATCH 19/24] chore: update versions --- defaults/Cargo.toml | 2 +- defaults/package.json | 2 +- package.json | 4 ++-- todo | 18 ------------------ 4 files changed, 4 insertions(+), 22 deletions(-) delete mode 100644 todo diff --git a/defaults/Cargo.toml b/defaults/Cargo.toml index 82e44e9..fba32f7 100644 --- a/defaults/Cargo.toml +++ b/defaults/Cargo.toml @@ -7,7 +7,7 @@ license = "MIT" edition = "2021" [dependencies] -polywrap-wasm-rs = "0.10.3" +polywrap-wasm-rs = "~0.11.0" serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0", features = ["preserve_order"]} diff --git a/defaults/package.json b/defaults/package.json index b00b623..c7b239f 100644 --- a/defaults/package.json +++ b/defaults/package.json @@ -2,7 +2,7 @@ "name": "test-cases-default", "private": true, "dependencies": { - "@polywrap/wasm-as": "0.10.3", + "@polywrap/wasm-as": "~0.11.0", "assemblyscript": "0.19.5" } } \ No newline at end of file diff --git a/package.json b/package.json index e3e4daf..838d0fa 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "version:apply": "yarn version --new-version $(cat VERSION) --no-git-tag-version" }, "dependencies": { - "@polywrap/plugin-js": "0.10.0", - "polywrap": "~0.11.0-pre.0" + "@polywrap/plugin-js": "~0.12.0", + "polywrap": "~0.11.0" } } diff --git a/todo b/todo deleted file mode 100644 index f6a02b8..0000000 --- a/todo +++ /dev/null @@ -1,18 +0,0 @@ -working: -- asyncify -- bigint-type -- bignumber-type -- bytes-type -- enum-type -- invalid-type -- map-type -- numbers-type -- no-args -- json-type -- object-type -- subinvoke - -building: -- env-type -- resolver -- interface-invoke From 119f94fd695d941465467d7c538b1136f175f5d5 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Thu, 17 Aug 2023 13:49:29 +0200 Subject: [PATCH 20/24] chore: update asyncify --- cases/asyncify/implementations/go/module.go | 18 +++++++++--------- run.sh | 3 --- 2 files changed, 9 insertions(+), 12 deletions(-) delete mode 100755 run.sh diff --git a/cases/asyncify/implementations/go/module.go b/cases/asyncify/implementations/go/module.go index 62e6240..2537052 100644 --- a/cases/asyncify/implementations/go/module.go +++ b/cases/asyncify/implementations/go/module.go @@ -2,12 +2,12 @@ package module import ( "github.com/polywrap/wrap-test-harness/go/module/wrap/types" - storage_module "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/storage" + storage "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/storage" "strconv" ) func GetData() uint32 { - v, err := storage_module.GetData(&storage_module.ArgsGetData{}) + v, err := storage.Storage_GetData(&storage.Storage_ArgsGetData{}) if err != nil { panic(err.Error()) } @@ -16,7 +16,7 @@ func GetData() uint32 { func SetDataWithLargeArgs(args *types.ArgsSetDataWithLargeArgs) string { largeString := args.Value - _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 66}) + _, err := storage.Storage_SetData(&storage.Storage_ArgsSetData{Value: 66}) if err != nil { panic(err.Error()) } @@ -24,7 +24,7 @@ func SetDataWithLargeArgs(args *types.ArgsSetDataWithLargeArgs) string { } func SetDataWithManyArgs(args *types.ArgsSetDataWithManyArgs) string { - _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 55}) + _, err := storage.Storage_SetData(&storage.Storage_ArgsSetData{Value: 55}) if err != nil { panic(err.Error()) } @@ -32,7 +32,7 @@ func SetDataWithManyArgs(args *types.ArgsSetDataWithManyArgs) string { } func SetDataWithManyStructuredArgs(args *types.ArgsSetDataWithManyStructuredArgs) bool { - _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 44}) + _, err := storage.Storage_SetData(&storage.Storage_ArgsSetData{Value: 44}) if err != nil { panic(err.Error()) } @@ -40,7 +40,7 @@ func SetDataWithManyStructuredArgs(args *types.ArgsSetDataWithManyStructuredArgs } func LocalVarMethod() bool { - _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 88}) + _, err := storage.Storage_SetData(&storage.Storage_ArgsSetData{Value: 88}) if err != nil { panic(err.Error()) } @@ -48,7 +48,7 @@ func LocalVarMethod() bool { } func GlobalVarMethod() bool { - _, err := storage_module.SetData(&storage_module.ArgsSetData{Value: 77}) + _, err := storage.Storage_SetData(&storage.Storage_ArgsSetData{Value: 77}) if err != nil { panic(err.Error()) } @@ -60,12 +60,12 @@ func SubsequentInvokes(args *types.ArgsSubsequentInvokes) []string { var err error for i := 0; i < int(args.NumberOfTimes); i++ { - _, errSet := storage_module.SetData(&storage_module.ArgsSetData{Value: int32(i)}) + _, errSet := storage.Storage_SetData(&storage.Storage_ArgsSetData{Value: int32(i)}) if errSet != nil { err = errSet break } - data, errGet := storage_module.GetData(&storage_module.ArgsGetData{}) + data, errGet := storage.Storage_GetData(&storage.Storage_ArgsGetData{}) if errGet != nil { err = errGet break diff --git a/run.sh b/run.sh deleted file mode 100755 index 9937aaf..0000000 --- a/run.sh +++ /dev/null @@ -1,3 +0,0 @@ -export POLYWRAP_CLI_PATH="/home/jelli/Dev/Repos/wrap/cli/packages/cli" - -cargo run -- -i=interface-invoke -f=env-type -v=1 \ No newline at end of file From 1110ac74557d1222a4c6d087fe12ada924e9ea03 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Thu, 17 Aug 2023 13:57:46 +0200 Subject: [PATCH 21/24] chore: fix subinvoke feature --- .../{00-subinvoke => 00-invoke}/implementations/go/module.go | 2 +- .../{01-invoke => 01-subinvoke}/implementations/go/module.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename cases/subinvoke/{00-subinvoke => 00-invoke}/implementations/go/module.go (71%) rename cases/subinvoke/{01-invoke => 01-subinvoke}/implementations/go/module.go (75%) diff --git a/cases/subinvoke/00-subinvoke/implementations/go/module.go b/cases/subinvoke/00-invoke/implementations/go/module.go similarity index 71% rename from cases/subinvoke/00-subinvoke/implementations/go/module.go rename to cases/subinvoke/00-invoke/implementations/go/module.go index c46475d..97d8f08 100644 --- a/cases/subinvoke/00-subinvoke/implementations/go/module.go +++ b/cases/subinvoke/00-invoke/implementations/go/module.go @@ -8,6 +8,6 @@ func Add(args *types.ArgsAdd) int32 { return args.A + args.B } -func SubinvokeThrowError(args *types.ArgsSubinvokeThrowError) bool { +func InvokeThrowError(args *types.ArgsnvokeThrowError) bool { panic(args.A) } diff --git a/cases/subinvoke/01-invoke/implementations/go/module.go b/cases/subinvoke/01-subinvoke/implementations/go/module.go similarity index 75% rename from cases/subinvoke/01-invoke/implementations/go/module.go rename to cases/subinvoke/01-subinvoke/implementations/go/module.go index 0b54eaa..62719b8 100644 --- a/cases/subinvoke/01-invoke/implementations/go/module.go +++ b/cases/subinvoke/01-subinvoke/implementations/go/module.go @@ -16,8 +16,8 @@ func AddAndIncrement(args *types.ArgsAddAndIncrement) int32 { return value + 1 } -func InvokeThrowError(args *types.ArgsInvokeThrowError) bool { - result, err := imported_subinvoke.SubinvokeThrowError(&imported_subinvoke.ArgsSubinvokeThrowError{ +func SubinvokeThrowError(args *types.ArgsSubinvokeThrowError) bool { + result, err := imported_subinvoke.InvokeThrowError(&imported_subinvoke.ArgsInvokeThrowError{ A: args.A, }) if err != nil { From 176bd0ee68e77931408da99323122a8c3b2c4c5e Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Thu, 17 Aug 2023 14:13:24 +0200 Subject: [PATCH 22/24] chore: fix env-type --- .../01-subinvoker/implementations/go/module.go | 12 ++++++------ .../implementations/go/module.go | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cases/env-type/01-subinvoker/implementations/go/module.go b/cases/env-type/01-subinvoker/implementations/go/module.go index 9b27b40..c12b96a 100644 --- a/cases/env-type/01-subinvoker/implementations/go/module.go +++ b/cases/env-type/01-subinvoker/implementations/go/module.go @@ -1,28 +1,28 @@ package module import ( - subinvoked "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/subinvoked" + . "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/subinvoked" "github.com/polywrap/wrap-test-harness/go/module/wrap/types" ) func SubinvokeMethodNoEnv(args *types.ArgsSubinvokeMethodNoEnv) string { - value, err := subinvoked.MethodNoEnv(&subinvoked.ArgsMethodNoEnv{Arg: args.Arg}) + value, err := Subinvoked_MethodNoEnv(&Subinvoked_ArgsMethodNoEnv{Arg: args.Arg}) if err != nil { panic(err.Error()) } return value } -func SubinvokeMethodRequireEnv() subinvoked.Subinvoked_Env { - value, err := subinvoked.MethodRequireEnv(&subinvoked.ArgsMethodRequireEnv{}) +func SubinvokeMethodRequireEnv() Subinvoked_Env { + value, err := Subinvoked_MethodRequireEnv(&Subinvoked_ArgsMethodRequireEnv{}) if err != nil { panic(err.Error()) } return value } -func SubinvokeMethodOptionalEnv() *subinvoked.Subinvoked_Env { - value, err := subinvoked.MethodOptionalEnv(&subinvoked.ArgsMethodOptionalEnv{}) +func SubinvokeMethodOptionalEnv() *Subinvoked_Env { + value, err := Subinvoked_MethodOptionalEnv(&Subinvoked_ArgsMethodOptionalEnv{}) if err != nil { panic(err.Error()) } diff --git a/cases/env-type/02-subinvoker-with-env/implementations/go/module.go b/cases/env-type/02-subinvoker-with-env/implementations/go/module.go index cea053b..d4cd380 100644 --- a/cases/env-type/02-subinvoker-with-env/implementations/go/module.go +++ b/cases/env-type/02-subinvoker-with-env/implementations/go/module.go @@ -1,11 +1,11 @@ package module import ( - subinvoked "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/subinvoked" + . "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/subinvoked" "github.com/polywrap/wrap-test-harness/go/module/wrap/types" ) -func SubinvokeMethodRequireEnv(_ *types.Env) subinvoked.Subinvoked_Env { - res, _ := subinvoked.MethodRequireEnv(&subinvoked.ArgsMethodRequireEnv{}) +func SubinvokeMethodRequireEnv(_ *types.Env) Subinvoked_Env { + res, _ := Subinvoked_MethodRequireEnv(&Subinvoked_ArgsMethodRequireEnv{}) return res } From 16e4b31b0c21dab8271ec843c144a3ab87c6622f Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Thu, 17 Aug 2023 14:42:08 +0200 Subject: [PATCH 23/24] chore: fix subinvoke test cases --- .../subinvoke/00-invoke/implementations/go/module.go | 4 ++-- .../01-subinvoke/implementations/go/module.go | 8 ++++---- .../02-consumer/implementations/go/module.go | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cases/subinvoke/00-invoke/implementations/go/module.go b/cases/subinvoke/00-invoke/implementations/go/module.go index 97d8f08..22a163a 100644 --- a/cases/subinvoke/00-invoke/implementations/go/module.go +++ b/cases/subinvoke/00-invoke/implementations/go/module.go @@ -8,6 +8,6 @@ func Add(args *types.ArgsAdd) int32 { return args.A + args.B } -func InvokeThrowError(args *types.ArgsnvokeThrowError) bool { - panic(args.A) +func InvokeThrowError(args *types.ArgsInvokeThrowError) bool { + panic(args.Error) } diff --git a/cases/subinvoke/01-subinvoke/implementations/go/module.go b/cases/subinvoke/01-subinvoke/implementations/go/module.go index 62719b8..ae735f0 100644 --- a/cases/subinvoke/01-subinvoke/implementations/go/module.go +++ b/cases/subinvoke/01-subinvoke/implementations/go/module.go @@ -2,11 +2,11 @@ package module import ( "github.com/polywrap/wrap-test-harness/go/module/wrap/types" - imported_subinvoke "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/imported_subinvoke" + . "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/imported_subinvoke" ) func AddAndIncrement(args *types.ArgsAddAndIncrement) int32 { - value, err := imported_subinvoke.Add(&imported_subinvoke.ArgsAdd{ + value, err := ImportedSubinvoke_Add(&ImportedSubinvoke_ArgsAdd{ A: args.A, B: args.B, }) @@ -17,8 +17,8 @@ func AddAndIncrement(args *types.ArgsAddAndIncrement) int32 { } func SubinvokeThrowError(args *types.ArgsSubinvokeThrowError) bool { - result, err := imported_subinvoke.InvokeThrowError(&imported_subinvoke.ArgsInvokeThrowError{ - A: args.A, + result, err := ImportedSubinvoke_InvokeThrowError(&ImportedSubinvoke_ArgsInvokeThrowError{ + Error: args.Error, }) if err != nil { panic(err.Error()) diff --git a/cases/subinvoke/02-consumer/implementations/go/module.go b/cases/subinvoke/02-consumer/implementations/go/module.go index 2d762a9..69d14df 100644 --- a/cases/subinvoke/02-consumer/implementations/go/module.go +++ b/cases/subinvoke/02-consumer/implementations/go/module.go @@ -2,11 +2,11 @@ package module import ( "github.com/polywrap/wrap-test-harness/go/module/wrap/types" - imported_invoke "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/imported_invoke" + . "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/imported_invoke" ) func AddAndIncrement(args *types.ArgsAddAndIncrement) int32 { - value, err := imported_invoke.AddAndIncrement(&imported_invoke.ArgsAddAndIncrement{ + value, err := ImportedInvoke_AddAndIncrement(&ImportedInvoke_ArgsAddAndIncrement{ A: args.A, B: args.B, }) @@ -17,8 +17,8 @@ func AddAndIncrement(args *types.ArgsAddAndIncrement) int32 { } func ThrowError(args *types.ArgsThrowError) bool { - result, err := imported_invoke.InvokeThrowError(&imported_invoke.ArgsInvokeThrowError{ - A: args.A, + result, err := ImportedInvoke_SubinvokeThrowError(&ImportedInvoke_ArgsSubinvokeThrowError{ + Error: args.Error, }) if err != nil { panic(err.Error()) @@ -27,8 +27,8 @@ func ThrowError(args *types.ArgsThrowError) bool { } func RethrowError(args *types.ArgsRethrowError) bool { - result, err := imported_invoke.InvokeThrowError(&imported_invoke.ArgsInvokeThrowError{ - A: args.A, + result, err := ImportedInvoke_SubinvokeThrowError(&ImportedInvoke_ArgsSubinvokeThrowError{ + Error: args.Error, }) if err != nil { panic(err.Error()) From 44afd280ab32fee2a496fab4e5fdc64d17f30908 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Thu, 7 Sep 2023 05:07:55 +0200 Subject: [PATCH 24/24] chore: fix subinvoke case --- .../01-subinvoke/implementations/go/module.go | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cases/subinvoke/01-subinvoke/implementations/go/module.go b/cases/subinvoke/01-subinvoke/implementations/go/module.go index ae735f0..c74524f 100644 --- a/cases/subinvoke/01-subinvoke/implementations/go/module.go +++ b/cases/subinvoke/01-subinvoke/implementations/go/module.go @@ -1,6 +1,7 @@ package module import ( + "github.com/polywrap/go-wrap/wrap" "github.com/polywrap/wrap-test-harness/go/module/wrap/types" . "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/imported_subinvoke" ) @@ -25,3 +26,28 @@ func SubinvokeThrowError(args *types.ArgsSubinvokeThrowError) bool { } return result } + +func SubinvokeMethodNotFound() bool { + argsAdd := &ImportedSubinvoke_ArgsAdd{ + A: 1, + B: 1, + } + argsBuf := SerializeImportedSubinvoke_AddArgs(argsAdd) + _, err := wrap.WrapSubinvoke("authority/imported-subinvoke", "methodNotFound", argsBuf) + if err != nil { + return false + } + return true +} + +func SubinvokeArgsIncorrect() bool { + wrongArgs := &ImportedSubinvoke_ArgsInvokeThrowError{ + Error: "Oops!", + } + argsBuf := SerializeImportedSubinvoke_InvokeThrowErrorArgs(wrongArgs) + _, err := wrap.WrapSubinvoke("authority/imported-subinvoke", "add", argsBuf) + if err != nil { + return false + } + return true +}