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
2 changes: 2 additions & 0 deletions ledger/acctonline_expired_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/crypto/merklesignature"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/data/txntest"
Expand Down Expand Up @@ -320,6 +321,7 @@ func (m *doubleLedgerAcctModel) goOnline(addr basics.Address, firstvalid, lastva
// meaningless non-zero voting data
VotePK: crypto.OneTimeSignatureVerifier(addr),
SelectionPK: crypto.VRFVerifier(addr),
StateProofPK: merklesignature.Commitment{1},
VoteKeyDilution: 1024,
})
m.accts[addr] = m.ops.Sub(m.accts[addr], basics.MicroAlgos{Raw: minFee})
Expand Down
31 changes: 22 additions & 9 deletions ledger/apptxn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,24 @@ func TestPayAction(t *testing.T) {

// We're going to test some payout effects here too, so that we have an inner transaction example.
proposer := basics.Address{0x01, 0x02, 0x03}
stateProofPK := merklesignature.Commitment{0x03}
if ver < 31 { // no state proof support
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these consensus version numbers getting spread across the codebase so I wonder if we need to name them

stateProofPK = merklesignature.Commitment{}
}
dl.txns(&txntest.Txn{
Type: "pay",
Sender: addrs[7],
Receiver: proposer,
Amount: 1_000_000 * 1_000_000, // 1 million algos is surely an eligible amount
}, &txntest.Txn{
Type: "keyreg",
Sender: proposer,
Fee: 3_000_000,
VotePK: crypto.OneTimeSignatureVerifier{0x01},
SelectionPK: crypto.VRFVerifier{0x02},
StateProofPK: merklesignature.Commitment{0x03},
VoteFirst: 1, VoteLast: 1000,
Type: "keyreg",
Sender: proposer,
Fee: 3_000_000,
VotePK: crypto.OneTimeSignatureVerifier{0x01},
SelectionPK: crypto.VRFVerifier{0x02},
VoteKeyDilution: 1000,
StateProofPK: stateProofPK,
VoteFirst: 1, VoteLast: 1000,
})

payout1 := txntest.Txn{
Expand Down Expand Up @@ -1818,6 +1823,9 @@ func TestSelfCheckHoldingNewApp(t *testing.T) {
ForeignAssets: []basics.AssetIndex{assetID},
}
selfcheck.ApplicationID = dl.txn(&selfcheck).ApplicationID
// remove programs to just call the app
selfcheck.ApprovalProgram = nil
selfcheck.ClearStateProgram = nil

dl.txn(&selfcheck)

Expand Down Expand Up @@ -1867,6 +1875,9 @@ func TestCheckHoldingNewApp(t *testing.T) {
ForeignAssets: []basics.AssetIndex{assetID},
}
check.ApplicationID = dl.txn(&check).ApplyData.ApplicationID
// remove the programs to just call the app
check.ApprovalProgram = nil
check.ClearStateProgram = nil

create := txntest.Txn{
Type: "appl",
Expand Down Expand Up @@ -3703,8 +3714,10 @@ func TestUnfundedSenders(t *testing.T) {

// v34 enabled UnfundedSenders
var problem string
if ver < 34 {
// In the old days, balances.Move would try to increase the rewardsState on the unfunded account
// In the old days, balances.Move would try to increase the rewardsState on the unfunded account
if ver < 28 {
problem = "transaction had fee 0, which is less than the minimum 1000"
} else if ver < 34 {
problem = "balance 0 below min"
}
for i, e := range ephemeral {
Expand Down
74 changes: 59 additions & 15 deletions ledger/boxtxn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,33 @@ func TestBoxIOBudgets(t *testing.T) {
dl.txn(call.Args("check", "x", "\x00"), "box read budget")

// Give a budget over 32768, confirm failure anyway
empties := [32]transactions.BoxRef{}
// These tests skip WellFormed, so the huge Boxes is ok
call.Boxes = append(call.Boxes, empties[:]...)
dl.txn(call.Args("create", "x", "\x80\x01"), "box size too large") // 32769
// Use a transaction group with 5 txns, each with 8 box refs (except the last one)
// to accumulate enough box references (33 total) for the quota test
txns := make([]*txntest.Txn, 5)
for i := 0; i < 4; i++ {
// Create 8 valid box references to the existing box "x"
boxes := make([]transactions.BoxRef, 8)
for j := 0; j < 8; j++ {
boxes[j] = transactions.BoxRef{Index: 0, Name: []byte("x")}
}
Comment thread
cce marked this conversation as resolved.
txns[i] = &txntest.Txn{
Type: "appl",
Sender: addrs[0],
ApplicationID: appID,
Boxes: boxes,
ApplicationArgs: [][]byte{[]byte("check"), []byte("x"), []byte("\x00")}, // box contains zeros
Note: []byte{byte(i)}, // vary the note to make txns unique
}
}
// Last transaction tries to create a box > 32K, which should fail even with enough quota
txns[4] = &txntest.Txn{
Type: "appl",
Sender: addrs[0],
ApplicationID: appID,
Boxes: []transactions.BoxRef{{Index: 0, Name: []byte("y")}}, // 1 ref, total 33 refs in group
ApplicationArgs: [][]byte{[]byte("create"), []byte("y"), []byte("\x80\x01")}, // 32769 bytes
}
dl.txgroup("box size too large", txns...)
})
}

Expand Down Expand Up @@ -718,8 +741,26 @@ func TestNewAppBoxCreate(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

t.Run("current", func(t *testing.T) { testNewAppBoxCreate(t, 0) })
t.Run("tealv9", func(t *testing.T) { testNewAppBoxCreate(t, 9) })
t.Run("tealv12", func(t *testing.T) { testNewAppBoxCreate(t, 12) })
}

func testNewAppBoxCreate(t *testing.T, requestedTealVersion int) {
genBalances, addrs, _ := ledgertesting.NewTestGenesis()
ledgertesting.TestConsensusRange(t, boxVersion, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) {
proto := config.Consensus[cv]

tealVersion := requestedTealVersion
if tealVersion == 0 {
tealVersion = int(proto.LogicSigVersion)
}

// Skip for combinations of tealVersion and cv that aren't possible
if uint64(tealVersion) > proto.LogicSigVersion {
t.Skipf("TEAL v%d not available in %s (LogicSigVersion=%d)", tealVersion, cv, proto.LogicSigVersion)
}

dl := NewDoubleLedger(t, genBalances, cv, cfg)
defer dl.Close()

Expand Down Expand Up @@ -753,8 +794,11 @@ func TestNewAppBoxCreate(t *testing.T) {
boxPut := "txn ApplicationArgs 0; int 24; bzero; box_put; int 1;"

for _, createSrc := range []string{boxCreate, boxPut} {
// createSrcVer is the versioned source for the current test's TEAL version
createSrcVer := fmt.Sprintf("#pragma version %d\n%s", tealVersion, createSrc)

// doubleSrc tries to create TWO boxes. The second is always named by ApplicationArgs 1
doubleSrc := createSrc + `txn ApplicationArgs 1; int 24; box_create; pop;` // return result of FIRST box_create
doubleSrc := createSrcVer + `txn ApplicationArgs 1; int 24; box_create; pop;` // return result of FIRST box_create
// need to call one inner txn, and have have mbr for itself and inner created app
passID := dl.fundedApp(addrs[0], 201_000, passThruCreator) // Will be used to show inners have same power

Expand All @@ -769,33 +813,33 @@ func TestNewAppBoxCreate(t *testing.T) {

// Try to create it. It will fail because there's no box ref. (does not increment txncounter)
dl.txn(&txntest.Txn{Type: "appl", Sender: addrs[0],
ApprovalProgram: createSrc, ApplicationArgs: [][]byte{{0x01}}},
ApprovalProgram: createSrcVer, ApplicationArgs: [][]byte{{0x01}}},
"invalid Box reference 0x01")

// 2a. Create it with a box ref of the predicted appID
dl.txn(&txntest.Txn{Type: "appl", Sender: addrs[0],
ApprovalProgram: createSrc, ApplicationArgs: [][]byte{{0x01}},
ApprovalProgram: createSrcVer, ApplicationArgs: [][]byte{{0x01}},
ForeignApps: []basics.AppIndex{passID + testTxns + 2},
Boxes: []transactions.BoxRef{{Index: 1, Name: []byte{0x01}}}})

// 2a. Create it with a box ref of the predicted appID (Access list)
if ver >= accessVersion {
if proto.MaxAppAccess > 0 {
dl.txn(&txntest.Txn{Type: "appl", Sender: addrs[0],
ApprovalProgram: createSrc, ApplicationArgs: [][]byte{{0x01}},
ApprovalProgram: createSrcVer, ApplicationArgs: [][]byte{{0x01}},
Access: []transactions.ResourceRef{
{App: passID + testTxns + 3},
{Box: transactions.BoxRef{Index: 1, Name: []byte{0x01}}}}})
}

// 2b. Create it with a box ref of 0, which means "this app"
dl.txn(&txntest.Txn{Type: "appl", Sender: addrs[0],
ApprovalProgram: createSrc, ApplicationArgs: [][]byte{{0x01}},
ApprovalProgram: createSrcVer, ApplicationArgs: [][]byte{{0x01}},
Boxes: []transactions.BoxRef{{Index: 0, Name: []byte{0x01}}}})

// 2b. Create it with a box ref of 0, which means "this app" (Access List)
if ver >= accessVersion {
if proto.MaxAppAccess > 0 {
dl.txn(&txntest.Txn{Type: "appl", Sender: addrs[0],
ApprovalProgram: createSrc, ApplicationArgs: [][]byte{{0x01}},
ApprovalProgram: createSrcVer, ApplicationArgs: [][]byte{{0x01}},
Access: []transactions.ResourceRef{
{Box: transactions.BoxRef{Index: 0, Name: []byte{0x01}}}}})
}
Expand All @@ -822,12 +866,12 @@ func TestNewAppBoxCreate(t *testing.T) {
if ver >= newAppCreateVersion {
// 2c. Create it with an empty box ref
dl.txn(&txntest.Txn{Type: "appl", Sender: addrs[0],
ApprovalProgram: createSrc, ApplicationArgs: [][]byte{{0x01}},
ApprovalProgram: createSrcVer, ApplicationArgs: [][]byte{{0x01}},
Boxes: []transactions.BoxRef{{}}})

// 2c. Create it with an empty box ref
dl.txn(&txntest.Txn{Type: "appl", Sender: addrs[0],
ApprovalProgram: createSrc, ApplicationArgs: [][]byte{{0x01}},
ApprovalProgram: createSrcVer, ApplicationArgs: [][]byte{{0x01}},
Access: []transactions.ResourceRef{{Box: transactions.BoxRef{}}}})

// but you can't do a second create
Expand Down Expand Up @@ -861,7 +905,7 @@ func TestNewAppBoxCreate(t *testing.T) {
} else {
// 2c. Doesn't work yet until `newAppCreateVersion`
dl.txn(&txntest.Txn{Type: "appl", Sender: addrs[0],
ApprovalProgram: createSrc, ApplicationArgs: [][]byte{{0x01}},
ApprovalProgram: createSrcVer, ApplicationArgs: [][]byte{{0x01}},
Boxes: []transactions.BoxRef{{}}},
"invalid Box reference 0x01")
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/double_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func (dl *DoubleLedger) beginBlock() *eval.BlockEvaluator {
return dl.eval
}

// txn will add a transaction to the current block. If no block is
// currently being built, it will start one, and end it after the
// transaction is added. If a problem is specified, it will be
// expected to fail, and the block will not be ended.
func (dl *DoubleLedger) txn(tx *txntest.Txn, problem ...string) (stib *transactions.SignedTxnInBlock) {
dl.t.Helper()
if dl.eval == nil {
Expand Down
6 changes: 6 additions & 0 deletions ledger/eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,12 @@ func (eval *BlockEvaluator) transaction(txn transactions.SignedTxn, evalParams *
return err
}

err = txn.Txn.WellFormed(eval.specials, eval.proto)
if err != nil {
txnErr := ledgercore.TxnNotWellFormedError(fmt.Sprintf("transaction %v: malformed: %v", txn.ID(), err))
return &txnErr
}

// Transaction already in the ledger?
err = cow.checkDup(txn.Txn.FirstValid, txn.Txn.LastValid, txid, ledgercore.Txlease{Sender: txn.Txn.Sender, Lease: txn.Txn.Lease})
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions ledger/eval/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,7 @@ func TestAbsenteeChecks(t *testing.T) {
Header: transactions.Header{
Sender: addrs[i],
Fee: minFee,
FirstValid: blkEval.Round().SubSaturate(1000),
LastValid: blkEval.Round(),
GenesisHash: l.GenesisHash(),
},
Expand Down
Loading
Loading