Skip to content

Commit

Permalink
Dryrun: Improve assembler error reporting (#5889)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonpaulos authored Jan 3, 2024
1 parent eceed7c commit e7aa0d4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
7 changes: 6 additions & 1 deletion daemon/algod/api/server/v2/dryrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
42 changes: 42 additions & 0 deletions daemon/algod/api/server/v2/dryrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":{}}]}
Expand Down

0 comments on commit e7aa0d4

Please sign in to comment.