Skip to content

Commit 696c34e

Browse files
jasonpaulosalgorandskiy
authored andcommitted
Add e2e test for extra pages
1 parent 42e260b commit 696c34e

File tree

3 files changed

+204
-0
lines changed

3 files changed

+204
-0
lines changed

daemon/algod/api/client/restClient.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,14 @@ func (client RestClient) PendingTransactionInformation(transactionID string) (re
434434
return
435435
}
436436

437+
// PendingTransactionInformationV2 gets information about a recently issued
438+
// transaction. See PendingTransactionInformation for more details.
439+
func (client RestClient) PendingTransactionInformationV2(transactionID string) (response generatedV2.PendingTransactionResponse, err error) {
440+
transactionID = stripTransaction(transactionID)
441+
err = client.get(&response, fmt.Sprintf("/v2/transactions/pending/%s", transactionID), nil)
442+
return
443+
}
444+
437445
// SuggestedFee gets the recommended transaction fee from the node
438446
func (client RestClient) SuggestedFee() (response v1.TransactionFee, err error) {
439447
err = client.get(&response, "/v1/transactions/fee", nil)

libgoal/libgoal.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,16 @@ func (c *Client) PendingTransactionInformation(txid string) (resp v1.Transaction
746746
return
747747
}
748748

749+
// PendingTransactionInformation returns information about a recently issued
750+
// transaction based on its txid.
751+
func (c *Client) PendingTransactionInformationV2(txid string) (resp generatedV2.PendingTransactionResponse, err error) {
752+
algod, err := c.ensureAlgodClient()
753+
if err == nil {
754+
resp, err = algod.PendingTransactionInformationV2(txid)
755+
}
756+
return
757+
}
758+
749759
// Block takes a round and returns its block
750760
func (c *Client) Block(round uint64) (resp v1.Block, err error) {
751761
algod, err := c.ensureAlgodClient()
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
// Copyright (C) 2019-2021 Algorand, Inc.
2+
// This file is part of go-algorand
3+
//
4+
// go-algorand is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as
6+
// published by the Free Software Foundation, either version 3 of the
7+
// License, or (at your option) any later version.
8+
//
9+
// go-algorand is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.
16+
17+
package transactions
18+
19+
import (
20+
"encoding/base64"
21+
"fmt"
22+
"path/filepath"
23+
"testing"
24+
25+
"github.com/stretchr/testify/require"
26+
27+
"github.com/algorand/go-algorand/data/basics"
28+
"github.com/algorand/go-algorand/data/transactions"
29+
"github.com/algorand/go-algorand/data/transactions/logic"
30+
"github.com/algorand/go-algorand/test/framework/fixtures"
31+
"github.com/algorand/go-algorand/test/partitiontest"
32+
)
33+
34+
func TestExtraProgramPages(t *testing.T) {
35+
partitiontest.PartitionTest(t)
36+
37+
t.Parallel()
38+
a := require.New(fixtures.SynchronizedTest(t))
39+
40+
var fixture fixtures.RestClientFixture
41+
fixture.Setup(t, filepath.Join("nettemplates", "TwoNodes50EachFuture.json"))
42+
defer fixture.Shutdown()
43+
client := fixture.LibGoalClient
44+
45+
accountList, err := fixture.GetWalletsSortedByBalance()
46+
a.NoError(err)
47+
baseAcct := accountList[0].Address
48+
49+
walletHandle, err := client.GetUnencryptedWalletHandle()
50+
a.NoError(err)
51+
52+
accountInfo, err := client.AccountInformationV2(baseAcct)
53+
a.NoError(err)
54+
if accountInfo.AppsTotalExtraPages != nil {
55+
a.Equal(*accountInfo.AppsTotalExtraPages, uint64(0))
56+
}
57+
58+
var inconsequentialBytes [2048]byte
59+
srcBigProgram := fmt.Sprintf(`#pragma version 4
60+
byte base64(%s)
61+
pop
62+
int 1
63+
return
64+
`, base64.StdEncoding.EncodeToString(inconsequentialBytes[:]))
65+
66+
srcSmallProgram := `#pragma version 4
67+
int 1
68+
return
69+
`
70+
71+
bigProgramOps, err := logic.AssembleString(srcBigProgram)
72+
a.NoError(err)
73+
bigProgram := bigProgramOps.Program
74+
75+
smallProgramOps, err := logic.AssembleString(srcSmallProgram)
76+
a.NoError(err)
77+
smallProgram := smallProgramOps.Program
78+
79+
globalSchema := basics.StateSchema{
80+
NumByteSlice: 1,
81+
}
82+
localSchema := basics.StateSchema{
83+
NumByteSlice: 1,
84+
}
85+
86+
status, err := client.Status()
87+
a.NoError(err)
88+
89+
// create app 1 with 1 extra page
90+
app1ExtraPages := uint32(1)
91+
tx, err := client.MakeUnsignedAppCreateTx(transactions.NoOpOC, smallProgram, smallProgram, globalSchema, localSchema, nil, nil, nil, nil, app1ExtraPages)
92+
a.NoError(err)
93+
tx, err = client.FillUnsignedTxTemplate(baseAcct, 0, 0, 0, tx)
94+
a.NoError(err)
95+
txid, err := client.SignAndBroadcastTransaction(walletHandle, nil, tx)
96+
a.NoError(err)
97+
_, err = fixture.WaitForConfirmedTxn(status.LastRound+5, baseAcct, txid)
98+
a.NoError(err)
99+
100+
app1CreateTxn, err := client.PendingTransactionInformationV2(txid)
101+
a.NoError(err)
102+
a.NotNil(app1CreateTxn.ConfirmedRound)
103+
a.NotNil(app1CreateTxn.ApplicationIndex)
104+
app1ID := *app1CreateTxn.ApplicationIndex
105+
106+
accountInfo, err = client.AccountInformationV2(baseAcct)
107+
a.NoError(err)
108+
a.NotNil(accountInfo.AppsTotalExtraPages)
109+
a.Equal(*accountInfo.AppsTotalExtraPages, uint64(app1ExtraPages))
110+
111+
// update app 1 and ensure the extra page still works
112+
tx, err = client.MakeUnsignedAppUpdateTx(app1ID, nil, nil, nil, nil, bigProgram, smallProgram)
113+
a.NoError(err)
114+
tx, err = client.FillUnsignedTxTemplate(baseAcct, 0, 0, 0, tx)
115+
a.NoError(err)
116+
txid, err = client.SignAndBroadcastTransaction(walletHandle, nil, tx)
117+
a.NoError(err)
118+
_, err = fixture.WaitForConfirmedTxn(*app1CreateTxn.ConfirmedRound+5, baseAcct, txid)
119+
a.NoError(err)
120+
121+
app1UpdateTxn, err := client.PendingTransactionInformationV2(txid)
122+
a.NoError(err)
123+
a.NotNil(app1CreateTxn.ConfirmedRound)
124+
125+
accountInfo, err = client.AccountInformationV2(baseAcct)
126+
a.NoError(err)
127+
a.NotNil(accountInfo.AppsTotalExtraPages)
128+
a.Equal(*accountInfo.AppsTotalExtraPages, uint64(app1ExtraPages))
129+
130+
// create app 2 with 2 extra pages
131+
app2ExtraPages := uint32(2)
132+
tx, err = client.MakeUnsignedAppCreateTx(transactions.NoOpOC, bigProgram, smallProgram, globalSchema, localSchema, nil, nil, nil, nil, app2ExtraPages)
133+
a.NoError(err)
134+
tx, err = client.FillUnsignedTxTemplate(baseAcct, 0, 0, 0, tx)
135+
a.NoError(err)
136+
txid, err = client.SignAndBroadcastTransaction(walletHandle, nil, tx)
137+
a.NoError(err)
138+
_, err = fixture.WaitForConfirmedTxn(*app1UpdateTxn.ConfirmedRound+5, baseAcct, txid)
139+
a.NoError(err)
140+
141+
app2CreateTxn, err := client.PendingTransactionInformationV2(txid)
142+
a.NoError(err)
143+
a.NotNil(app2CreateTxn.ConfirmedRound)
144+
a.NotNil(app2CreateTxn.ApplicationIndex)
145+
app2ID := *app2CreateTxn.ApplicationIndex
146+
147+
accountInfo, err = client.AccountInformationV2(baseAcct)
148+
a.NoError(err)
149+
a.NotNil(accountInfo.AppsTotalExtraPages)
150+
a.Equal(*accountInfo.AppsTotalExtraPages, uint64(app1ExtraPages+app2ExtraPages))
151+
152+
// delete app 1
153+
tx, err = client.MakeUnsignedAppDeleteTx(app1ID, nil, nil, nil, nil)
154+
a.NoError(err)
155+
tx, err = client.FillUnsignedTxTemplate(baseAcct, 0, 0, 0, tx)
156+
a.NoError(err)
157+
txid, err = client.SignAndBroadcastTransaction(walletHandle, nil, tx)
158+
a.NoError(err)
159+
_, err = fixture.WaitForConfirmedTxn(*app2CreateTxn.ConfirmedRound+5, baseAcct, txid)
160+
a.NoError(err)
161+
162+
app1DeleteTxn, err := client.PendingTransactionInformationV2(txid)
163+
a.NoError(err)
164+
a.NotNil(app1DeleteTxn.ConfirmedRound)
165+
166+
accountInfo, err = client.AccountInformationV2(baseAcct)
167+
a.NoError(err)
168+
a.NotNil(accountInfo.AppsTotalExtraPages)
169+
a.Equal(*accountInfo.AppsTotalExtraPages, uint64(app2ExtraPages))
170+
171+
// delete app 2
172+
tx, err = client.MakeUnsignedAppDeleteTx(app2ID, nil, nil, nil, nil)
173+
a.NoError(err)
174+
tx, err = client.FillUnsignedTxTemplate(baseAcct, 0, 0, 0, tx)
175+
a.NoError(err)
176+
txid, err = client.SignAndBroadcastTransaction(walletHandle, nil, tx)
177+
a.NoError(err)
178+
_, err = fixture.WaitForConfirmedTxn(*app1DeleteTxn.ConfirmedRound+5, baseAcct, txid)
179+
a.NoError(err)
180+
181+
accountInfo, err = client.AccountInformationV2(baseAcct)
182+
a.NoError(err)
183+
if accountInfo.AppsTotalExtraPages != nil {
184+
a.Equal(*accountInfo.AppsTotalExtraPages, uint64(0))
185+
}
186+
}

0 commit comments

Comments
 (0)