Skip to content

Commit

Permalink
remove unnecessary code in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
algoidurovic committed May 23, 2022
1 parent 10aa9df commit 2166891
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 63 deletions.
2 changes: 1 addition & 1 deletion data/transactions/logic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ _available_.
group is _available_.

* Since v7, the account associated with any contract present in the
`txn.ForeignApplications` is _available_.
`txn.ForeignApplications` field is _available_.

## Constants

Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/README_in.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ _available_.
group is _available_.

* Since v7, the account associated with any contract present in the
`txn.ForeignApplications` is _available_.
`txn.ForeignApplications` field is _available_.

## Constants

Expand Down
5 changes: 2 additions & 3 deletions data/transactions/logic/evalAppTxn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2913,10 +2913,9 @@ func TestForeignAppAccountAccess(t *testing.T) {

ep, tx, ledger := MakeSampleEnv()
ledger.NewAccount(appAddr(888), 50_000)
tx.ForeignApps = []basics.AppIndex{basics.AppIndex(2)}
tx.ForeignApps = []basics.AppIndex{basics.AppIndex(111)}

// This app looks itself up in the ledger, so we need to put it in there.
ledger.NewApp(tx.Sender, 2, basics.AppParams{
ledger.NewApp(tx.Sender, 111, basics.AppParams{
ApprovalProgram: TestProg(t, "int 1", AssemblerMaxVersion).Program,
ClearStateProgram: TestProg(t, "int 1", AssemblerMaxVersion).Program,
})
Expand Down
96 changes: 38 additions & 58 deletions ledger/internal/apptxn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3070,12 +3070,6 @@ func TestForeignAppAccountsAccessible(t *testing.T) {
appA := txntest.Txn{
Type: "appl",
Sender: addrs[0],
ApprovalProgram: main(`
int 3
int 3
==
assert
`),
}

appB := txntest.Txn{
Expand All @@ -3093,9 +3087,7 @@ itxn_submit
`),
}

dl.beginBlock()
dl.txgroup("", &appA, &appB)
vb := dl.endBlock()
vb := dl.fullBlock(&appA, &appB)
index0 := vb.Block().Payset[0].ApplicationID
index1 := vb.Block().Payset[1].ApplicationID

Expand All @@ -3107,7 +3099,6 @@ itxn_submit
}
fund0 := fund1
fund0.Receiver = index0.Address()
fund1.Receiver = index1.Address()

callTx := txntest.Txn{
Type: "appl",
Expand All @@ -3131,66 +3122,59 @@ itxn_submit
})
}

// While accounts of foreign apps are available in most context, they still
// While accounts of foreign apps are available in most contexts, they still
// cannot be used as mutable references; ie the accounts cannot be used by
// opcodes that modify local storage.
func TestForeignAppAccountsImmutable(t *testing.T) {
partitiontest.PartitionTest(t)

genBalances, addrs, _ := ledgertesting.NewTestGenesis()
l := newTestLedger(t, genBalances)
defer l.Close()
testConsensusRange(t, 32, 0, func(t *testing.T, ver int) {
dl := NewDoubleLedger(t, genBalances, consensusByNumber[ver])
defer dl.Close()

appA := txntest.Txn{
Type: "appl",
Sender: addrs[0],
ApprovalProgram: main(`
int 3
int 3
==
assert
`),
}
appA := txntest.Txn{
Type: "appl",
Sender: addrs[0],
}

appB := txntest.Txn{
Type: "appl",
Sender: addrs[0],
ApprovalProgram: main(`
appB := txntest.Txn{
Type: "appl",
Sender: addrs[0],
ApprovalProgram: main(`
txn Applications 1
app_params_get AppAddress
byte "X"
byte "ABC"
app_local_put
int 1
`),
}
}

eval := nextBlock(t, l)
txns(t, l, eval, &appA, &appB)
vb := endBlock(t, l, eval)
index0 := vb.Block().Payset[0].ApplicationID
index1 := vb.Block().Payset[1].ApplicationID
vb := dl.fullBlock(&appA, &appB)
index0 := vb.Block().Payset[0].ApplicationID
index1 := vb.Block().Payset[1].ApplicationID

fund1 := txntest.Txn{
Type: "pay",
Sender: addrs[0],
Receiver: index1.Address(),
Amount: 1_000_000_000,
}
fund0 := fund1
fund0.Receiver = index0.Address()
fund1.Receiver = index1.Address()
fund1 := txntest.Txn{
Type: "pay",
Sender: addrs[0],
Receiver: index1.Address(),
Amount: 1_000_000_000,
}
fund0 := fund1
fund0.Receiver = index0.Address()

callTx := txntest.Txn{
Type: "appl",
Sender: addrs[2],
ApplicationID: index1,
ForeignApps: []basics.AppIndex{index0},
}
eval = nextBlock(t, l)
txns(t, l, eval, &fund0, &fund1)
txn(t, l, eval, &callTx, "invalid Account reference")
endBlock(t, l, eval)
callTx := txntest.Txn{
Type: "appl",
Sender: addrs[2],
ApplicationID: index1,
ForeignApps: []basics.AppIndex{index0},
}

dl.beginBlock()
dl.txgroup("invalid Account reference", &fund0, &fund1, &callTx)
dl.endBlock()
})
}

// In the case where the foreign app account is also provided in the
Expand Down Expand Up @@ -3239,9 +3223,7 @@ done:
},
}

dl.beginBlock()
dl.txgroup("", &appA, &appB)
vb := dl.endBlock()
vb := dl.fullBlock(&appA, &appB)
index0 := vb.Block().Payset[0].ApplicationID
index1 := vb.Block().Payset[1].ApplicationID

Expand Down Expand Up @@ -3270,9 +3252,7 @@ done:
Accounts: []basics.Address{index0.Address()},
}

dl.beginBlock()
dl.txgroup("", &fund0, &fund1, &callA, &callB)
vb = dl.endBlock()
vb = dl.fullBlock(&fund0, &fund1, &callA, &callB)

require.Equal(t, "Y", vb.Block().Payset[3].EvalDelta.LocalDeltas[1]["X"].Bytes)
})
Expand Down

0 comments on commit 2166891

Please sign in to comment.