summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Paulos <jasonpaulos@users.noreply.github.com>2024-01-03 10:59:58 -0500
committerGitHub <noreply@github.com>2024-01-03 10:59:58 -0500
commite7aa0d4a785ee52f0194355912a1d9eae32a10fc (patch)
tree5c6af870c9de1fe8974c8b7c82a156e7de82eed2
parenteceed7c0d3df0f412ede27c1aa2b68e0fa21ccab (diff)
Dryrun: Improve assembler error reporting (#5889)
-rw-r--r--daemon/algod/api/server/v2/dryrun.go7
-rw-r--r--daemon/algod/api/server/v2/dryrun_test.go42
2 files changed, 48 insertions, 1 deletions
diff --git a/daemon/algod/api/server/v2/dryrun.go b/daemon/algod/api/server/v2/dryrun.go
index 7ce7c6abb..9c3355cd1 100644
--- a/daemon/algod/api/server/v2/dryrun.go
+++ b/daemon/algod/api/server/v2/dryrun.go
@@ -89,7 +89,12 @@ func (dr *DryrunRequest) ExpandSources() error {
for i, s := range dr.Sources {
ops, err := logic.AssembleString(s.Source)
if err != nil {
- return fmt.Errorf("dryrun Source[%d]: %v", i, err)
+ if len(ops.Errors) <= 1 {
+ return fmt.Errorf("dryrun Source[%d]: %w", i, err)
+ }
+ var sb strings.Builder
+ ops.ReportMultipleErrors("", &sb)
+ return fmt.Errorf("dryrun Source[%d]: %d errors\n%s", i, len(ops.Errors), sb.String())
}
switch s.FieldName {
case "lsig":
diff --git a/daemon/algod/api/server/v2/dryrun_test.go b/daemon/algod/api/server/v2/dryrun_test.go
index ad0592f5f..93177e488 100644
--- a/daemon/algod/api/server/v2/dryrun_test.go
+++ b/daemon/algod/api/server/v2/dryrun_test.go
@@ -132,6 +132,48 @@ func logResponse(t *testing.T, response *model.DryrunResponse) {
var dryrunProtoVersion protocol.ConsensusVersion = protocol.ConsensusFuture
var dryrunMakeLedgerProto protocol.ConsensusVersion = "dryrunMakeLedgerProto"
+func TestDryrunSources(t *testing.T) {
+ partitiontest.PartitionTest(t)
+ t.Parallel()
+
+ goodSource := model.DryrunSource{
+ AppIndex: 1007,
+ FieldName: "approv",
+ Source: `#pragma version 10
+int 1`,
+ }
+ badSource := model.DryrunSource{
+ AppIndex: 1007,
+ FieldName: "approv",
+ Source: `#pragma version 10
+int 1
+pop
+fake_opcode
+int not_an_int`,
+ }
+
+ dr := DryrunRequest{
+ Sources: []model.DryrunSource{
+ goodSource,
+ },
+ Apps: []model.Application{
+ {
+ Id: 1007,
+ },
+ },
+ }
+ var response model.DryrunResponse
+
+ doDryrunRequest(&dr, &response)
+ require.Empty(t, response.Error)
+
+ dr.Sources[0] = badSource
+ doDryrunRequest(&dr, &response)
+ require.Contains(t, response.Error, "dryrun Source[0]: 2 errors")
+ require.Contains(t, response.Error, "4: unknown opcode: fake_opcode")
+ require.Contains(t, response.Error, "5:4: unable to parse \"not_an_int\" as integer")
+}
+
func TestDryrunLogicSig(t *testing.T) {
partitiontest.PartitionTest(t)
// {"txns":[{"lsig":{"l":"AiABASI="},"txn":{}}]}