Skip to content

Commit 939889d

Browse files
committed
Checkpoint before testing MBR changes to run CI
1 parent 0888c14 commit 939889d

File tree

17 files changed

+427
-133
lines changed

17 files changed

+427
-133
lines changed

data/basics/teal.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,13 @@ func (sm StateSchema) SubSchema(osm StateSchema) (out StateSchema) {
107107
}
108108

109109
// NumEntries counts the total number of values that may be stored for particular schema
110-
func (sm StateSchema) NumEntries() (tot uint64) {
111-
tot = AddSaturate(tot, sm.NumUint)
112-
tot = AddSaturate(tot, sm.NumByteSlice)
113-
return tot
110+
func (sm StateSchema) NumEntries() uint64 {
111+
return AddSaturate(sm.NumUint, sm.NumByteSlice)
112+
}
113+
114+
// Allows determines if `other` "fits" within this schema.
115+
func (sm StateSchema) Allows(other StateSchema) bool {
116+
return other.NumUint <= sm.NumUint && other.NumByteSlice <= sm.NumByteSlice
114117
}
115118

116119
// MinBalance computes the MinBalance requirements for a StateSchema based on

data/bookkeeping/block.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ type BlockHeader struct {
110110
// Each block is associated with at most one active upgrade proposal
111111
// (a new version of the protocol). An upgrade proposal can be made
112112
// by a block proposer, as long as no other upgrade proposal is active.
113-
// The upgrade proposal lasts for many rounds (UpgradeVoteRounds), and
113+
// The upgrade proposal lasts for consensus.UpgradeVoteRounds, and
114114
// in each round, that round's block proposer votes to support (or not)
115115
// the proposed upgrade.
116116
//
@@ -232,7 +232,7 @@ type UpgradeState struct {
232232
NextProtocol protocol.ConsensusVersion `codec:"nextproto"`
233233
// NextProtocolApprovals is the number of approvals for the next protocol proposal. It is expressed in basics.Round because it is a count of rounds.
234234
NextProtocolApprovals basics.Round `codec:"nextyes"`
235-
// NextProtocolVoteBefore specify the last voting round for the next protocol proposal. If there is no voting for
235+
// NextProtocolVoteBefore specifies the last voting round for the next protocol proposal. If there is no voting for
236236
// an upgrade taking place, this would be zero.
237237
NextProtocolVoteBefore basics.Round `codec:"nextbefore"`
238238
// NextProtocolSwitchOn specify the round number at which the next protocol would be adopted. If there is no upgrade taking place,

data/transactions/application.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ func (ac ApplicationCallTxnFields) wellFormed(proto config.ConsensusParams) erro
453453
effectiveEPP := ac.ExtraProgramPages
454454
// Schemas and ExtraProgramPages may only be set during application creation
455455
// and explicit attempts to change size during updates.
456-
if ac.ApplicationID != 0 && !ac.UpdatingSizes(proto.AppSizeUpdates) {
456+
if ac.ApplicationID != 0 && !(proto.AppSizeUpdates && ac.UpdatingSizes()) {
457457
if ac.GlobalStateSchema != (basics.StateSchema{}) {
458458
return fmt.Errorf("inappropriate non-zero tx.GlobalStateSchema (%v)",
459459
ac.GlobalStateSchema)
@@ -559,10 +559,9 @@ func (ac ApplicationCallTxnFields) wellFormed(proto config.ConsensusParams) erro
559559
return nil
560560
}
561561

562-
// UpdatingSizes returns true if the transaction is setting the
563-
// extra-program-pages or global schema size during an update.
564-
func (ac ApplicationCallTxnFields) UpdatingSizes(allowed bool) bool {
565-
return allowed && ac.OnCompletion == UpdateApplicationOC &&
562+
// UpdatingSizes returns true if the transaction is has non-zero sizing fields.
563+
func (ac ApplicationCallTxnFields) UpdatingSizes() bool {
564+
return ac.OnCompletion == UpdateApplicationOC &&
566565
(ac.ExtraProgramPages != 0 || ac.GlobalStateSchema != (basics.StateSchema{}))
567566
}
568567

data/transactions/logic/evalAppTxn_test.go

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,15 +1308,53 @@ func TestApplSubmission(t *testing.T) {
13081308
// Can't set epp when app id is given
13091309
tx.ForeignApps = append(tx.ForeignApps, basics.AppIndex(7))
13101310
TestApp(t, p+`int 1; itxn_field ExtraProgramPages;
1311-
int 7; itxn_field ApplicationID`+s, ep, "immutable")
1311+
int 7; itxn_field ApplicationID`+s, ep, "inappropriate non-zero tx.Extra")
1312+
// nor can global schema be set
1313+
TestApp(t, p+`int 1; itxn_field GlobalNumUint;
1314+
int 7; itxn_field ApplicationID`+s, ep, "inappropriate non-zero tx.Global")
1315+
// nor can local schema be set
1316+
TestApp(t, p+`int 1; itxn_field LocalNumUint;
1317+
int 7; itxn_field ApplicationID`+s, ep, "inappropriate non-zero tx.Local")
1318+
1319+
// When performing an update, we can set epp and (global only) schema
1320+
ledger.NewApp(tx.Receiver, 7, basics.AppParams{
1321+
ApprovalProgram: ops.Program, // which is "int 1"
1322+
})
1323+
TestApp(t, p+a+`int UpdateApplication; itxn_field OnCompletion;
1324+
int 1; itxn_field ExtraProgramPages;
1325+
int 7; itxn_field ApplicationID`+s, ep)
1326+
// global schema can be set
1327+
TestApp(t, p+a+`int UpdateApplication; itxn_field OnCompletion;
1328+
int 1; itxn_field GlobalNumUint;
1329+
int 7; itxn_field ApplicationID`+s, ep)
1330+
// but local schema still cannot be set
1331+
TestApp(t, p+a+`int UpdateApplication; itxn_field OnCompletion;
1332+
int 1; itxn_field LocalNumUint;
1333+
int 7; itxn_field ApplicationID`+s, ep, "inappropriate non-zero tx.Local")
1334+
1335+
// Even when performing an update, they cannot be set (in old consensus)
1336+
ep.Proto.AppSizeUpdates = false
1337+
TestApp(t, p+a+`int UpdateApplication; itxn_field OnCompletion;
1338+
int 1; itxn_field ExtraProgramPages;
1339+
int 7; itxn_field ApplicationID`+s, ep, "inappropriate non-zero tx.Extra")
1340+
// global schema can be set
1341+
TestApp(t, p+a+`int UpdateApplication; itxn_field OnCompletion;
1342+
int 1; itxn_field GlobalNumUint;
1343+
int 7; itxn_field ApplicationID`+s, ep, "inappropriate non-zero tx.Global")
1344+
// but local schema still cannot be set
1345+
TestApp(t, p+a+`int UpdateApplication; itxn_field OnCompletion;
1346+
int 1; itxn_field LocalNumUint;
1347+
int 7; itxn_field ApplicationID`+s, ep, "inappropriate non-zero tx.Local")
13121348

13131349
TestApp(t, p+a+"int 20; itxn_field GlobalNumUint; int 11; itxn_field GlobalNumByteSlice"+s,
13141350
ep, "too large")
13151351
TestApp(t, p+a+"int 7; itxn_field LocalNumUint; int 7; itxn_field LocalNumByteSlice"+s,
13161352
ep, "too large")
13171353
}
13181354

1319-
func TestInnerApplCreate(t *testing.T) {
1355+
// TestInnerApplLifecycle tests creation, update, and deletion of apps with
1356+
// inner transactions.
1357+
func TestInnerApplLifecycle(t *testing.T) {
13201358
partitiontest.PartitionTest(t)
13211359
t.Parallel()
13221360

@@ -1345,6 +1383,7 @@ itxn_submit
13451383
int 1
13461384
`)
13471385

1386+
// Can't examine it without ForeignApps
13481387
test("int 5000; app_params_get AppGlobalNumByteSlice; assert; int 0; ==; assert",
13491388
"unavailable App 5000")
13501389

@@ -1358,7 +1397,8 @@ int 1
13581397
// Can't call it either
13591398
test(call, "unavailable App 5000")
13601399

1361-
tx.ForeignApps = []basics.AppIndex{basics.AppIndex(5000)}
1400+
// Add to ForeignApps, then we can examine and call it.
1401+
tx.ForeignApps = []basics.AppIndex{5000}
13621402
test(`
13631403
int 5000; app_params_get AppGlobalNumByteSlice; assert; int 0; ==; assert
13641404
int 5000; app_params_get AppGlobalNumUint; assert; int 1; ==; assert
@@ -1387,10 +1427,33 @@ int 1
13871427
test(update)
13881428

13891429
if v >= 12 {
1390-
// Version starts at 0
1430+
// Version is up to 1
13911431
test(`int 5000; app_params_get AppVersion; assert; int 1; ==`)
13921432
}
13931433

1434+
updateSchema := `
1435+
itxn_begin
1436+
int appl; itxn_field TypeEnum
1437+
int 5000; itxn_field ApplicationID
1438+
` + approve + `; itxn_field ApprovalProgram
1439+
` + approve + `; itxn_field ClearStateProgram
1440+
int 2; itxn_field GlobalNumUint
1441+
int UpdateApplication; itxn_field OnCompletion
1442+
itxn_submit
1443+
int 1
1444+
`
1445+
test(updateSchema)
1446+
if v >= 12 {
1447+
// Version is up to 2
1448+
test(`int 5000; app_params_get AppVersion; assert; int 2; ==`)
1449+
}
1450+
1451+
test(`
1452+
int 5000; app_params_get AppGlobalNumUint; assert; int 2; ==; assert
1453+
int 1
1454+
`)
1455+
1456+
// Delete it
13941457
test(`
13951458
itxn_begin
13961459
int appl; itxn_field TypeEnum
@@ -1405,7 +1468,6 @@ int 1
14051468

14061469
// Can't call it either
14071470
test(call, "no app 5000")
1408-
14091471
})
14101472
}
14111473

0 commit comments

Comments
 (0)