diff --git a/internal/machine/vm/run.go b/internal/machine/vm/run.go index a437806b8..d9fd4dad8 100644 --- a/internal/machine/vm/run.go +++ b/internal/machine/vm/run.go @@ -35,7 +35,12 @@ func (s ScriptV1) ToCore() Script { case string: s.Script.Vars[k] = v case map[string]any: - s.Script.Vars[k] = fmt.Sprintf("%s %v", v["asset"], v["amount"]) + switch amount := v["amount"].(type) { + case string: + s.Script.Vars[k] = fmt.Sprintf("%s %s", v["asset"], amount) + case float64: + s.Script.Vars[k] = fmt.Sprintf("%s %d", v["asset"], int(amount)) + } default: s.Script.Vars[k] = fmt.Sprint(v) } diff --git a/internal/machine/vm/run_test.go b/internal/machine/vm/run_test.go index f74b6b756..0ef310460 100644 --- a/internal/machine/vm/run_test.go +++ b/internal/machine/vm/run_test.go @@ -451,3 +451,59 @@ func TestRun(t *testing.T) { }) } } + +func TestConvertScriptV1(t *testing.T) { + t.Parallel() + + type testCase struct { + name string + inputVars map[string]any + expected map[string]string + } + + testCases := []testCase{ + { + name: "float64 conversion", + inputVars: map[string]any{ + "amount": map[string]any{ + "asset": "USD", + "amount": float64(999999999999999), + }, + }, + expected: map[string]string{ + "amount": "USD 999999999999999", + }, + }, + { + name: "big int conversion", + inputVars: map[string]any{ + "amount": map[string]any{ + "asset": "USD", + "amount": func() string { + ret, _ := big.NewInt(0).SetString("9999999999999999999999999999999999999999", 10) + return ret.String() + }(), + }, + }, + expected: map[string]string{ + "amount": "USD 9999999999999999999999999999999999999999", + }, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + script := ScriptV1{ + Script: Script{ + Plain: ``, + }, + Vars: tc.inputVars, + } + + converted := script.ToCore() + require.Equal(t, tc.expected, converted.Vars) + }) + } +}