Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions cmd/opdoc/opdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,22 +235,25 @@ func opToMarkdown(out io.Writer, op *logic.OpSpec) (err error) {
if !op.Modes.Any() {
fmt.Fprintf(out, "- Mode: %s\n", op.Modes.String())
}
if op.Name == "global" {
switch op.Name {
case "global":
globalFieldsMarkdown(out)
} else if op.Name == "txn" {
case "txn":
transactionFieldsMarkdown(out)
fmt.Fprintf(out, "\nTypeEnum mapping:\n\n")
typeEnumTableMarkdown(out)
} else if op.Name == "asset_holding_get" {
case "asset_holding_get":
assetHoldingFieldsMarkdown(out)
} else if op.Name == "asset_params_get" {
case "asset_params_get":
assetParamsFieldsMarkdown(out)
} else if op.Name == "app_params_get" {
case "app_params_get":
appParamsFieldsMarkdown(out)
} else if op.Name == "acct_params_get" {
case "acct_params_get":
acctParamsFieldsMarkdown(out)
} else if strings.HasPrefix(op.Name, "ecdsa") {
ecDsaCurvesMarkdown(out)
default:
if strings.HasPrefix(op.Name, "ecdsa") {
ecDsaCurvesMarkdown(out)
}
}
ode := logic.OpDocExtra(op.Name)
if ode != "" {
Expand Down Expand Up @@ -369,55 +372,64 @@ func buildLanguageSpec(opGroups map[string][]string) *LanguageSpec {
}
}

func create(file string) *os.File {
f, err := os.Create(file)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to create '%s': %v", file, err)
os.Exit(1)
}
return f
}

func main() {
opcodesMd, _ := os.Create("TEAL_opcodes.md")
opcodesMd := create("TEAL_opcodes.md")
opsToMarkdown(opcodesMd)
opcodesMd.Close()
opGroups := make(map[string][]string, len(logic.OpSpecs))
for grp, names := range logic.OpGroups {
fname := fmt.Sprintf("%s.md", grp)
fname = strings.ReplaceAll(fname, " ", "_")
fout, _ := os.Create(fname)
fout := create(fname)
opGroupMarkdownTable(names, fout)
fout.Close()
for _, opname := range names {
opGroups[opname] = append(opGroups[opname], grp)
}
}
constants, _ := os.Create("named_integer_constants.md")
constants := create("named_integer_constants.md")
integerConstantsTableMarkdown(constants)
constants.Close()

txnfields, _ := os.Create("txn_fields.md")
txnfields := create("txn_fields.md")
fieldSpecsMarkdown(txnfields, logic.TxnFieldNames, logic.TxnFieldSpecByName)
txnfields.Close()

globalfields, _ := os.Create("global_fields.md")
globalfields := create("global_fields.md")
fieldSpecsMarkdown(globalfields, logic.GlobalFieldNames, logic.GlobalFieldSpecByName)
globalfields.Close()

assetholding, _ := os.Create("asset_holding_fields.md")
assetholding := create("asset_holding_fields.md")
fieldSpecsMarkdown(assetholding, logic.AssetHoldingFieldNames, logic.AssetHoldingFieldSpecByName)
assetholding.Close()

assetparams, _ := os.Create("asset_params_fields.md")
assetparams := create("asset_params_fields.md")
fieldSpecsMarkdown(assetparams, logic.AssetParamsFieldNames, logic.AssetParamsFieldSpecByName)
assetparams.Close()

appparams, _ := os.Create("app_params_fields.md")
appparams := create("app_params_fields.md")
fieldSpecsMarkdown(appparams, logic.AppParamsFieldNames, logic.AppParamsFieldSpecByName)
appparams.Close()

acctparams, _ := os.Create("acct_params_fields.md")
fieldSpecsMarkdown(acctparams, logic.AcctParamsFieldNames, logic.AcctParamsFieldSpecByName)
acctparams.Close()

langspecjs, _ := os.Create("langspec.json")
langspecjs := create("langspec.json")
enc := json.NewEncoder(langspecjs)
enc.Encode(buildLanguageSpec(opGroups))
langspecjs.Close()

tealtm, _ := os.Create("teal.tmLanguage.json")
tealtm := create("teal.tmLanguage.json")
enc = json.NewEncoder(tealtm)
enc.SetIndent("", " ")
enc.Encode(buildSyntaxHighlight())
Expand Down
3 changes: 2 additions & 1 deletion cmd/tealdbg/cdtState.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ func prepareTxn(txn *transactions.Transaction, groupIndex int) []fieldDesc {
field == int(logic.CreatedApplicationID) ||
field == int(logic.CreatedAssetID) ||
field == int(logic.Logs) ||
field == int(logic.NumLogs) {
field == int(logic.NumLogs) ||
field == int(logic.LastLog) {
continue
}
var value string
Expand Down
82 changes: 82 additions & 0 deletions data/transactions/blackbox_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

package transactions_test

import (
"testing"

"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/data/txntest"
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/go-algorand/test/partitiontest"
"github.com/stretchr/testify/require"
)

func TestFeeCredit(t *testing.T) {
partitiontest.PartitionTest(t)

c, err := transactions.FeeCredit([]transactions.SignedTxnWithAD{
txntest.Txn{Fee: 5}.SignedTxnWithAD(),
}, 5)
require.NoError(t, err)
require.Equal(t, c, uint64(0))

c, err = transactions.FeeCredit([]transactions.SignedTxnWithAD{
txntest.Txn{Fee: 4}.SignedTxnWithAD(),
}, 5)
require.Error(t, err)

c, err = transactions.FeeCredit([]transactions.SignedTxnWithAD{
txntest.Txn{Fee: 5}.SignedTxnWithAD(),
}, 4)
require.NoError(t, err)
require.Equal(t, c, uint64(1))

c, err = transactions.FeeCredit([]transactions.SignedTxnWithAD{
txntest.Txn{Fee: 5}.SignedTxnWithAD(),
txntest.Txn{Fee: 5}.SignedTxnWithAD(),
}, 5)
require.NoError(t, err)
require.Equal(t, c, uint64(0))

c, err = transactions.FeeCredit([]transactions.SignedTxnWithAD{
txntest.Txn{Fee: 5}.SignedTxnWithAD(),
txntest.Txn{Type: protocol.CompactCertTx, Fee: 0}.SignedTxnWithAD(),
}, 5)
require.NoError(t, err)
require.Equal(t, c, uint64(0))

c, err = transactions.FeeCredit([]transactions.SignedTxnWithAD{
txntest.Txn{Fee: 5}.SignedTxnWithAD(),
txntest.Txn{Fee: 5}.SignedTxnWithAD(),
txntest.Txn{Fee: 5}.SignedTxnWithAD(),
}, 5)
require.NoError(t, err)
require.Equal(t, c, uint64(0))

c, err = transactions.FeeCredit([]transactions.SignedTxnWithAD{}, 5)
require.NoError(t, err)
require.Equal(t, c, uint64(0))

c, err = transactions.FeeCredit([]transactions.SignedTxnWithAD{
txntest.Txn{Fee: 5}.SignedTxnWithAD(),
txntest.Txn{Fee: 25}.SignedTxnWithAD(),
txntest.Txn{Fee: 5}.SignedTxnWithAD(),
}, 5)
require.NoError(t, err)
require.Equal(t, c, uint64(20))
}
9 changes: 5 additions & 4 deletions data/transactions/logic/assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,14 +823,15 @@ func asmTxn(ops *OpStream, spec *OpSpec, args []string) error {

// asmTxn2 delegates to asmTxn or asmTxna depending on number of operands
func asmTxn2(ops *OpStream, spec *OpSpec, args []string) error {
if len(args) == 1 {
switch len(args) {
case 1:
return asmTxn(ops, spec, args)
}
if len(args) == 2 {
case 2:
txna := OpsByName[ops.Version]["txna"]
return asmTxna(ops, &txna, args)
default:
return ops.error("txn expects one or two arguments")
}
return ops.error("txn expects one or two arguments")
}

// asmTxna also assemble asmItxna
Expand Down
1 change: 0 additions & 1 deletion data/transactions/logic/backwardCompat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ func TestBackwardCompatTEALv1(t *testing.T) {
// Costs for v2 should be higher because of hash opcode cost changes
ep2, tx, _ := makeSampleEnvWithVersion(2)
ep2.Proto.LogicSigMaxCost = 2307
// ep2.TxnGroup[0].Lsig.Logic = opsV2.Program
ep2.TxnGroup[0].Lsig.Args = [][]byte{data[:], sig[:], pk[:], tx.Sender[:], tx.Note}
// Eval doesn't fail, but it would be ok (better?) if it did
testLogicBytes(t, opsV2.Program, ep2, "static cost", "")
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestNewAppEvalParams(t *testing.T) {
require.NotNil(t, ep)
require.Equal(t, ep.TxnGroup, testCase.group)
require.Equal(t, *ep.Proto, param)
if reflect.DeepEqual(param, config.Consensus[protocol.ConsensusV29]) {
if reflect.DeepEqual(param, config.Consensus[protocol.ConsensusV29]) || testCase.numAppCalls == 0 {
require.Nil(t, ep.PooledApplicationBudget)
} else if reflect.DeepEqual(param, config.Consensus[protocol.ConsensusFuture]) {
require.Equal(t, *ep.PooledApplicationBudget, param.MaxAppProgramCost*testCase.numAppCalls)
Expand Down
Loading