From 73e590a225745d64833afe5a19c3582d58145c1d Mon Sep 17 00:00:00 2001 From: Tyler Hale <7747991+t-hale@users.noreply.github.com> Date: Tue, 22 Feb 2022 21:14:28 -0500 Subject: [PATCH] fixes https://github.com/coinbase/rosetta-cli/issues/248 (#371) --- constructor/dsl/dsl_test.go | 31 +++++++++++++++++++++++ constructor/dsl/parser.go | 5 ++++ constructor/dsl/testdata/action_valid.ros | 10 ++++++++ 3 files changed, 46 insertions(+) create mode 100644 constructor/dsl/testdata/action_valid.ros diff --git a/constructor/dsl/dsl_test.go b/constructor/dsl/dsl_test.go index 3600d319..09fb4522 100644 --- a/constructor/dsl/dsl_test.go +++ b/constructor/dsl/dsl_test.go @@ -330,6 +330,37 @@ func TestParse(t *testing.T) { file: "blah_blah.txt", expectedErr: ErrIncorrectExtension, }, + "action: valid type": { + file: "action_valid.ros", + expectedWorkflows: []*job.Workflow{ + { + Name: string(job.CreateAccount), + Concurrency: job.ReservedWorkflowConcurrency, + Scenarios: []*job.Scenario{ + { + Name: "create", + Actions: []*job.Action{ + { + Type: job.SetVariable, + Input: `{"network":"chrysalis-devnet", "blockchain":"iota"}`, + OutputPath: "network", + }, + { + Type: job.GenerateKey, + Input: `{"curve_type": "edwards25519"}`, + OutputPath: "key", + }, + { + Type: job.Derive, + Input: `{"network_identifier": {{network}},"public_key": {{key.public_key}}}`, + OutputPath: "account", + }, + }, + }, + }, + }, + }, + }, } for name, test := range tests { diff --git a/constructor/dsl/parser.go b/constructor/dsl/parser.go index cef7cdf6..063560c6 100644 --- a/constructor/dsl/parser.go +++ b/constructor/dsl/parser.go @@ -17,6 +17,7 @@ package dsl import ( "bufio" "context" + "encoding/json" "errors" "fmt" "os" @@ -147,6 +148,10 @@ func parseActionType(line string) (job.ActionType, string, string, error) { divide: job.Division, } { tokens = strings.SplitN(remaining, symbol, split2) + + if json.Valid([]byte(strings.TrimSuffix(remaining, ";"))) { + break + } if len(tokens) == split2 { if len(mathOperation) == 0 { return "", "", "", ErrInvalidMathSymbol diff --git a/constructor/dsl/testdata/action_valid.ros b/constructor/dsl/testdata/action_valid.ros new file mode 100644 index 00000000..b400877b --- /dev/null +++ b/constructor/dsl/testdata/action_valid.ros @@ -0,0 +1,10 @@ +create_account(1){ + create{ + network = {"network":"chrysalis-devnet", "blockchain":"iota"}; + key = generate_key({"curve_type": "edwards25519"}); + account = derive({ + "network_identifier": {{network}}, + "public_key": {{key.public_key}} + }); + } +} \ No newline at end of file