Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lots of testing convenience improvements, including e2e python #2936

Merged
merged 4 commits into from
Sep 27, 2021
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
14 changes: 8 additions & 6 deletions data/transactions/logic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ The stack starts empty and contains values of either uint64 or bytes
4096 bytes in length). Most operations act on the stack, popping
arguments from it and pushing results to it.

The maximum stack depth is currently 1000.
The maximum stack depth is currently 1000. If the stack depth is
exceed or if a `bytes` element exceed 4096 bytes, the program fails.

## Scratch Space

Expand All @@ -36,11 +37,12 @@ TEAL LogicSigs run in Algorand nodes as part of testing a proposed transaction t

If an authorized program executes and finishes with a single non-zero uint64 value on the stack then that program has validated the transaction it is attached to.

The TEAL program has access to data from the transaction it is attached to (`txn` op), any transactions in a transaction group it is part of (`gtxn` op), and a few global values like consensus parameters (`global` op). Some "Args" may be attached to a transaction being validated by a TEAL program. Args are an array of byte strings. A common pattern would be to have the key to unlock some contract as an Arg. Args are recorded on the blockchain and publicly visible when the transaction is submitted to the network. These LogicSig Args are _not_ signed.
The TEAL program has access to data from the transaction it is attached to (`txn` op), any transactions in a transaction group it is part of (`gtxn` op), and a few global values like consensus parameters (`global` op). Some "Args" may be attached to a transaction being validated by a TEAL program. Args are an array of byte strings. A common pattern would be to have the key to unlock some contract as an Arg. Args are recorded on the blockchain and publicly visible when the transaction is submitted to the network. These LogicSig Args are _not_ part of the transaction ID nor of the TxGroup hash. They also cannot be read from other TEAL programs in the group of transactions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mb leave something like "efficiently leaving them not signed" for better clarity?


A program can either authorize some delegated action on a normal private key signed or multisig account or be wholly in charge of a contract account.

* If the account has signed the program (an ed25519 signature on "Program" concatenated with the program bytes) then if the program returns true the transaction is authorized as if the account had signed it. This allows an account to hand out a signed program so that other users can carry out delegated actions which are approved by the program.
* If the account has signed the program (an ed25519 signature on "Program" concatenated with the program bytes) then if the program returns true the transaction is authorized as if the account had signed it. This allows an account to hand out a signed program so that other users can carry out delegated actions which are approved by the program. Note that LogicSig Args are _not_ signed.

* If the SHA512_256 hash of the program (prefixed by "Program") is equal to the transaction Sender address then this is a contract account wholly controlled by the program. No other signature is necessary or possible. The only way to execute a transaction against the contract account is for the program to approve it.

The TEAL bytecode plus the length of all Args must add up to no more than 1000 bytes (consensus parameter LogicSigMaxSize). Each TEAL op has an associated cost and the program cost must total no more than 20000 (consensus parameter LogicSigMaxCost). Most ops have a cost of 1, but a few slow crypto ops are much higher. Prior to v4, the program's cost was estimated as the static sum of all the opcode costs in the program (whether they were actually executed or not). Beginning with v4, the program's cost is tracked dynamically, while being evaluated. If the program exceeds its budget, it fails.
Expand Down Expand Up @@ -464,9 +466,9 @@ transaction types, are rejected by `itxn_submit`.

| Op | Description |
| --- | --- |
| `itxn_begin` | Begin preparation of a new inner transaction |
| `itxn_field f` | Set field F of the current inner transaction to X |
| `itxn_submit` | Execute the current inner transaction. Fail if 16 inner transactions have already been executed, or if the transaction itself fails. |
| `itxn_begin` | begin preparation of a new inner transaction |
| `itxn_field f` | set field F of the current inner transaction to X |
| `itxn_submit` | execute the current inner transaction. Fail if 16 inner transactions have already been executed, or if the transaction itself fails. |
| `itxn f` | push field F of the last inner transaction to stack |
| `itxna f i` | push Ith value of the array field F of the last inner transaction to stack |

Expand Down
8 changes: 5 additions & 3 deletions data/transactions/logic/README_in.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ The stack starts empty and contains values of either uint64 or bytes
4096 bytes in length). Most operations act on the stack, popping
arguments from it and pushing results to it.

The maximum stack depth is currently 1000.
The maximum stack depth is currently 1000. If the stack depth is
exceed or if a `bytes` element exceed 4096 bytes, the program fails.

## Scratch Space

Expand All @@ -36,11 +37,12 @@ TEAL LogicSigs run in Algorand nodes as part of testing a proposed transaction t

If an authorized program executes and finishes with a single non-zero uint64 value on the stack then that program has validated the transaction it is attached to.

The TEAL program has access to data from the transaction it is attached to (`txn` op), any transactions in a transaction group it is part of (`gtxn` op), and a few global values like consensus parameters (`global` op). Some "Args" may be attached to a transaction being validated by a TEAL program. Args are an array of byte strings. A common pattern would be to have the key to unlock some contract as an Arg. Args are recorded on the blockchain and publicly visible when the transaction is submitted to the network. These LogicSig Args are _not_ signed.
The TEAL program has access to data from the transaction it is attached to (`txn` op), any transactions in a transaction group it is part of (`gtxn` op), and a few global values like consensus parameters (`global` op). Some "Args" may be attached to a transaction being validated by a TEAL program. Args are an array of byte strings. A common pattern would be to have the key to unlock some contract as an Arg. Args are recorded on the blockchain and publicly visible when the transaction is submitted to the network. These LogicSig Args are _not_ part of the transaction ID nor of the TxGroup hash. They also cannot be read from other TEAL programs in the group of transactions.

A program can either authorize some delegated action on a normal private key signed or multisig account or be wholly in charge of a contract account.

* If the account has signed the program (an ed25519 signature on "Program" concatenated with the program bytes) then if the program returns true the transaction is authorized as if the account had signed it. This allows an account to hand out a signed program so that other users can carry out delegated actions which are approved by the program.
* If the account has signed the program (an ed25519 signature on "Program" concatenated with the program bytes) then if the program returns true the transaction is authorized as if the account had signed it. This allows an account to hand out a signed program so that other users can carry out delegated actions which are approved by the program. Note that LogicSig Args are _not_ signed.

* If the SHA512_256 hash of the program (prefixed by "Program") is equal to the transaction Sender address then this is a contract account wholly controlled by the program. No other signature is necessary or possible. The only way to execute a transaction against the contract account is for the program to approve it.

The TEAL bytecode plus the length of all Args must add up to no more than 1000 bytes (consensus parameter LogicSigMaxSize). Each TEAL op has an associated cost and the program cost must total no more than 20000 (consensus parameter LogicSigMaxCost). Most ops have a cost of 1, but a few slow crypto ops are much higher. Prior to v4, the program's cost was estimated as the static sum of all the opcode costs in the program (whether they were actually executed or not). Beginning with v4, the program's cost is tracked dynamically, while being evaluated. If the program exceeds its budget, it fails.
Expand Down
8 changes: 5 additions & 3 deletions data/transactions/logic/TEAL_opcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ bitlen interprets arrays as big-endian integers, unlike setbit/getbit
- Opcode: 0xb1
- Pops: _None_
- Pushes: _None_
- Begin preparation of a new inner transaction
- begin preparation of a new inner transaction
- LogicSigVersion >= 5
- Mode: Application

Expand All @@ -1307,7 +1307,7 @@ bitlen interprets arrays as big-endian integers, unlike setbit/getbit
- Opcode: 0xb2 {uint8 transaction field index}
- Pops: *... stack*, any
- Pushes: _None_
- Set field F of the current inner transaction to X
- set field F of the current inner transaction to X
- LogicSigVersion >= 5
- Mode: Application

Expand All @@ -1318,10 +1318,12 @@ bitlen interprets arrays as big-endian integers, unlike setbit/getbit
- Opcode: 0xb3
- Pops: _None_
- Pushes: _None_
- Execute the current inner transaction. Fail if 16 inner transactions have already been executed, or if the transaction itself fails.
- execute the current inner transaction. Fail if 16 inner transactions have already been executed, or if the transaction itself fails.
- LogicSigVersion >= 5
- Mode: Application

`itxn_submit` resets the current transaction so that it can not be resubmitted. A new `itxn_begin` is required to prepare another inner transaction.

## itxn f

- Opcode: 0xb4 {uint8 transaction field index}
Expand Down
7 changes: 4 additions & 3 deletions data/transactions/logic/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ var opDocByName = map[string]string{
"b~": "X with all bits inverted",

"log": "write bytes to log state of the current application",
"itxn_begin": "Begin preparation of a new inner transaction",
"itxn_field": "Set field F of the current inner transaction to X",
"itxn_submit": "Execute the current inner transaction. Fail if 16 inner transactions have already been executed, or if the transaction itself fails.",
"itxn_begin": "begin preparation of a new inner transaction",
"itxn_field": "set field F of the current inner transaction to X",
"itxn_submit": "execute the current inner transaction. Fail if 16 inner transactions have already been executed, or if the transaction itself fails.",
}

// OpDoc returns a description of the op
Expand Down Expand Up @@ -281,6 +281,7 @@ var opDocExtras = map[string]string{
"log": "`log` fails if called more than MaxLogCalls times in a program, or if the sum of logged bytes exceeds 1024 bytes.",
"itxn_begin": "`itxn_begin` initializes Sender to the application address; Fee to the minimum allowable, taking into account MinTxnFee and credit from overpaying in earlier transactions; FirstValid/LastValid to the values in the top-level transaction, and all other fields to zero values.",
"itxn_field": "`itxn_field` fails if X is of the wrong type for F, including a byte array of the wrong size for use as an address when F is an address field. `itxn_field` also fails if X is an account or asset that does not appear in `txn.Accounts` or `txn.ForeignAssets` of the top-level transaction. (Setting addresses in asset creation are exempted from this requirement.)",
"itxn_submit": "`itxn_submit` resets the current transaction so that it can not be resubmitted. A new `itxn_begin` is required to prepare another inner transaction.",
}

// OpDocExtra returns extra documentation text about an op
Expand Down
18 changes: 15 additions & 3 deletions data/txntest/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type Txn struct {
Type protocol.TxType

Sender basics.Address
Fee uint64
Fee interface{} // basics.MicroAlgos, uint64, int, or nil
FirstValid basics.Round
LastValid basics.Round
Note []byte
Expand Down Expand Up @@ -113,7 +113,7 @@ func (tx *Txn) Noted(note string) *Txn {
// FillDefaults populates some obvious defaults from config params,
// unless they have already been set.
func (tx *Txn) FillDefaults(params config.ConsensusParams) {
if tx.Fee == 0 {
if tx.Fee == nil {
tx.Fee = params.MinTxnFee
}
if tx.LastValid == 0 {
Expand Down Expand Up @@ -146,11 +146,23 @@ func assemble(source string) []byte {

// Txn produces a transactions.Transaction from the fields in this Txn
func (tx Txn) Txn() transactions.Transaction {
switch fee := tx.Fee.(type) {
case basics.MicroAlgos:
// nothing, already have MicroAlgos
case uint64:
tx.Fee = basics.MicroAlgos{Raw: fee}
case int:
if fee >= 0 {
tx.Fee = basics.MicroAlgos{Raw: uint64(fee)}
}
case nil:
tx.Fee = basics.MicroAlgos{}
}
return transactions.Transaction{
Type: tx.Type,
Header: transactions.Header{
Sender: tx.Sender,
Fee: basics.MicroAlgos{Raw: tx.Fee},
Fee: tx.Fee.(basics.MicroAlgos),
FirstValid: tx.FirstValid,
LastValid: tx.LastValid,
Note: tx.Note,
Expand Down
80 changes: 76 additions & 4 deletions ledger/apptxn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,33 +786,78 @@ func TestAcfgAction(t *testing.T) {
itxn_field ConfigAssetName
byte "https://gold.rush/"
itxn_field ConfigAssetURL
global CurrentApplicationAddress

global CurrentApplicationAddress
dup
dup2
itxn_field ConfigAssetManager
itxn_field ConfigAssetReserve
itxn_field ConfigAssetFreeze
itxn_field ConfigAssetClawback
b submit
manager:
// Put the current values in the itxn
txn Assets 0
asset_params_get AssetManager
assert // exists
itxn_field ConfigAssetManager

txn Assets 0
asset_params_get AssetReserve
assert // exists
itxn_field ConfigAssetReserve

txn Assets 0
asset_params_get AssetFreeze
assert // exists
itxn_field ConfigAssetFreeze

txn Assets 0
asset_params_get AssetClawback
assert // exists
itxn_field ConfigAssetClawback
b submit
manager:


txn ApplicationArgs 0
byte "manager"
==
bz reserve
txn Assets 0
itxn_field ConfigAsset
txn ApplicationArgs 1
itxn_field ConfigAssetManager
b submit
reserve:
txn ApplicationArgs 0
byte "reserve"
==
bz freeze
txn Assets 0
itxn_field ConfigAsset
txn ApplicationArgs 1
itxn_field ConfigAssetReserve
b submit
freeze:
txn ApplicationArgs 0
byte "freeze"
==
bz clawback
txn Assets 0
itxn_field ConfigAsset
txn ApplicationArgs 1
itxn_field ConfigAssetFreeze
b submit
clawback:
txn ApplicationArgs 0
byte "manager"
byte "clawback"
==
bz error
txn Assets 0
itxn_field ConfigAsset
txn ApplicationArgs 1
itxn_field ConfigAssetClawback
b submit
error: err
submit: itxn_submit
`),
}
Expand Down Expand Up @@ -854,6 +899,33 @@ submit: itxn_submit
require.Equal(t, "Gold", asaParams.AssetName)
require.Equal(t, "https://gold.rush/", asaParams.URL)

require.Equal(t, appIndex.Address(), asaParams.Manager)

for _, a := range []string{"reserve", "freeze", "clawback", "manager"} {
check := txntest.Txn{
Type: "appl",
Sender: addrs[1],
ApplicationID: appIndex,
ApplicationArgs: [][]byte{[]byte(a), []byte("junkjunkjunkjunkjunkjunkjunkjunk")},
ForeignAssets: []basics.AssetIndex{asaIndex},
}
eval = l.nextBlock(t)
t.Log(a)
eval.txn(t, &check)
l.endBlock(t, eval)
}
// Not the manager anymore so this won't work
nodice := txntest.Txn{
Type: "appl",
Sender: addrs[1],
ApplicationID: appIndex,
ApplicationArgs: [][]byte{[]byte("freeze"), []byte("junkjunkjunkjunkjunkjunkjunkjunk")},
ForeignAssets: []basics.AssetIndex{asaIndex},
}
eval = l.nextBlock(t)
eval.txn(t, &nodice, "this transaction should be issued by the manager")
l.endBlock(t, eval)

}

// TestAsaDuringInit ensures an ASA can be made while initilizing an
Expand Down
Loading