Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into require-make-msgp
Browse files Browse the repository at this point in the history
  • Loading branch information
cce committed May 17, 2022
2 parents b6fdf67 + 91095fa commit 5c0a6b5
Show file tree
Hide file tree
Showing 22 changed files with 1,327 additions and 349 deletions.
2 changes: 1 addition & 1 deletion cmd/goal/clerk.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ var groupCmd = &cobra.Command{
}

stxns = append(stxns, stxn)
group.TxGroupHashes = append(group.TxGroupHashes, crypto.HashObj(stxn.Txn))
group.TxGroupHashes = append(group.TxGroupHashes, crypto.Digest(stxn.ID()))
transactionIdx++
}

Expand Down
2 changes: 1 addition & 1 deletion config/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const VersionMajor = 3

// VersionMinor is the Minor semantic version number (x.#.z) - changed when backwards-compatible features are introduced.
// Not enforced until after initial public release (x > 0).
const VersionMinor = 6
const VersionMinor = 7

// Version is the type holding our full version information.
type Version struct {
Expand Down
12 changes: 11 additions & 1 deletion daemon/algod/api/algod.oas2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,12 @@
"type": "string",
"format": "binary"
}
},
{
"name": "sourcemap",
"description": "When set to `true`, returns the source map of the program as a JSON. Defaults to `false`.",
"in": "query",
"type": "boolean"
}
],
"responses": {
Expand Down Expand Up @@ -1432,7 +1438,7 @@
},
"/v2/teal/disassemble": {
"post": {
"description": "Given the base64 encoded program bytes, return the TEAL source code in plain text. This endpoint is only enabled when a node's configuration file sets EnableDeveloperAPI to true.",
"description": "Given the program bytes, return the TEAL source code in plain text. This endpoint is only enabled when a node's configuration file sets EnableDeveloperAPI to true.",
"consumes": [
"application/x-binary"
],
Expand Down Expand Up @@ -3105,6 +3111,10 @@
"result": {
"description": "base64 encoded program bytes",
"type": "string"
},
"sourcemap": {
"description": "JSON of the source map",
"type": "object"
}
}
}
Expand Down
22 changes: 21 additions & 1 deletion daemon/algod/api/algod.oas3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@
"result": {
"description": "base64 encoded program bytes",
"type": "string"
},
"sourcemap": {
"description": "JSON of the source map",
"properties": {},
"type": "object"
}
},
"required": [
Expand Down Expand Up @@ -3646,6 +3651,16 @@
"post": {
"description": "Given TEAL source code in plain text, return base64 encoded program bytes and base32 SHA512_256 hash of program bytes (Address style). This endpoint is only enabled when a node's configuration file sets EnableDeveloperAPI to true.",
"operationId": "TealCompile",
"parameters": [
{
"description": "When set to `true`, returns the source map of the program as a JSON. Defaults to `false`.",
"in": "query",
"name": "sourcemap",
"schema": {
"type": "boolean"
}
}
],
"requestBody": {
"content": {
"text/plain": {
Expand All @@ -3671,6 +3686,11 @@
"result": {
"description": "base64 encoded program bytes",
"type": "string"
},
"sourcemap": {
"description": "JSON of the source map",
"properties": {},
"type": "object"
}
},
"required": [
Expand Down Expand Up @@ -3728,7 +3748,7 @@
},
"/v2/teal/disassemble": {
"post": {
"description": "Given the base64 encoded program bytes, return the TEAL source code in plain text. This endpoint is only enabled when a node's configuration file sets EnableDeveloperAPI to true.",
"description": "Given the program bytes, return the TEAL source code in plain text. This endpoint is only enabled when a node's configuration file sets EnableDeveloperAPI to true.",
"operationId": "TealDisassemble",
"requestBody": {
"content": {
Expand Down
3 changes: 3 additions & 0 deletions daemon/algod/api/server/v2/dryrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,9 @@ func doDryrunRequest(dr *DryrunRequest, response *generated.DryrunResponse) {
messages[0] = "ApprovalProgram"
}
pass, delta, err := ba.StatefulEval(ti, ep, appIdx, program)
if !pass {
delta = ep.TxnGroup[ti].EvalDelta
}
result.Disassembly = debug.lines
result.AppCallTrace = &debug.history
result.GlobalDelta = StateDeltaToStateDelta(delta.GlobalDelta)
Expand Down
134 changes: 132 additions & 2 deletions daemon/algod/api/server/v2/dryrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -374,7 +375,7 @@ func checkLogicSigPass(t *testing.T, response *generated.DryrunResponse) {
}
}

func checkAppCallPass(t *testing.T, response *generated.DryrunResponse) {
func checkAppCallResponse(t *testing.T, response *generated.DryrunResponse, msg string) {
if len(response.Txns) < 1 {
t.Error("no response txns")
} else if len(response.Txns) == 0 {
Expand All @@ -387,12 +388,20 @@ func checkAppCallPass(t *testing.T, response *generated.DryrunResponse) {
if response.Txns[idx].AppCallMessages != nil {
messages := *response.Txns[idx].AppCallMessages
assert.GreaterOrEqual(t, len(messages), 1)
assert.Equal(t, "PASS", messages[len(messages)-1])
assert.Equal(t, msg, messages[len(messages)-1])
}
}
}
}

func checkAppCallPass(t *testing.T, response *generated.DryrunResponse) {
checkAppCallResponse(t, response, "PASS")
}

func checkAppCallReject(t *testing.T, response *generated.DryrunResponse) {
checkAppCallResponse(t, response, "REJECT")
}

type expectedSlotType struct {
slot int
tt basics.TealType
Expand Down Expand Up @@ -1634,3 +1643,124 @@ int 1`)
logResponse(t, &response)
}
}

func checkEvalDelta(t *testing.T,
response generated.DryrunResponse,
expectedGlobalDelta generated.StateDelta,
expectedLocalDelta generated.AccountStateDelta,
) {
for _, rt := range response.Txns {
if rt.GlobalDelta != nil && len(*rt.GlobalDelta) > 0 {
assert.Equal(t, expectedGlobalDelta, *rt.GlobalDelta)
} else {
assert.Nil(t, expectedGlobalDelta)
}

if rt.LocalDeltas != nil {
for _, ld := range *rt.LocalDeltas {
assert.Equal(t, expectedLocalDelta.Address, ld.Address)
assert.Equal(t, expectedLocalDelta.Delta, ld.Delta)
}
} else {
assert.Nil(t, expectedLocalDelta)
}
}
}

func TestDryrunCheckEvalDeltasReturned(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

var dr DryrunRequest
var response generated.DryrunResponse

// Expected responses.
expectedByte := b64("val")
expectedUint := uint64(1)
expectedGlobalDelta := generated.StateDelta{
{
Key: b64("key"),
Value: generated.EvalDelta{
Action: uint64(basics.SetBytesAction),
Bytes: &expectedByte,
},
},
}
expectedLocalDelta := generated.AccountStateDelta{
Address: basics.Address{}.String(),
Delta: generated.StateDelta{
{
Key: b64("key"),
Value: generated.EvalDelta{
Action: uint64(basics.SetUintAction),
Uint: &expectedUint,
},
},
},
}

// Test that a PASS and REJECT dryrun both return the dryrun evaldelta.
for i := range []int{0, 1} {
ops, _ := logic.AssembleString(fmt.Sprintf(`
#pragma version 6
txna ApplicationArgs 0
txna ApplicationArgs 1
app_global_put
int 0
txna ApplicationArgs 0
int %d
app_local_put
int %d`, expectedUint, i))
dr.ProtocolVersion = string(dryrunProtoVersion)

dr.Txns = []transactions.SignedTxn{
{
Txn: transactions.Transaction{
Type: protocol.ApplicationCallTx,
ApplicationCallTxnFields: transactions.ApplicationCallTxnFields{
ApplicationID: 1,
ApplicationArgs: [][]byte{
[]byte("key"),
[]byte("val"),
},
},
},
},
}
dr.Apps = []generated.Application{
{
Id: 1,
Params: generated.ApplicationParams{
ApprovalProgram: ops.Program,
GlobalStateSchema: &generated.ApplicationStateSchema{
NumByteSlice: 1,
NumUint: 1,
},
LocalStateSchema: &generated.ApplicationStateSchema{
NumByteSlice: 1,
NumUint: 1,
},
},
},
}
dr.Accounts = []generated.Account{
{
Status: "Online",
Address: basics.Address{}.String(),
AppsLocalState: &[]generated.ApplicationLocalState{{Id: 1}},
},
}

doDryrunRequest(&dr, &response)
if i == 0 {
checkAppCallReject(t, &response)
} else {
checkAppCallPass(t, &response)
}
checkEvalDelta(t, response, expectedGlobalDelta, expectedLocalDelta)
if t.Failed() {
logResponse(t, &response)
}
}

}
1 change: 1 addition & 0 deletions daemon/algod/api/server/v2/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
errFailedToParseTransaction = "failed to parse transaction"
errFailedToParseBlock = "failed to parse block"
errFailedToParseCert = "failed to parse cert"
errFailedToParseSourcemap = "failed to parse sourcemap"
errFailedToEncodeResponse = "failed to encode response"
errInternalFailure = "internal failure"
errNoTxnSpecified = "no transaction ID was specified"
Expand Down
Loading

0 comments on commit 5c0a6b5

Please sign in to comment.