Skip to content

Commit 44aa75a

Browse files
committed
what i have so far
1 parent bf7a0b2 commit 44aa75a

5 files changed

Lines changed: 96 additions & 209 deletions

File tree

src/test/java/com/algorand/algosdk/integration/Applications.java

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@
1515
import io.cucumber.java.en.Then;
1616
import org.apache.commons.lang3.StringUtils;
1717
import org.assertj.core.api.Assertions;
18-
import org.assertj.core.util.Lists;
1918
import org.bouncycastle.util.Strings;
2019
import org.junit.Assert;
2120

2221
import java.io.ByteArrayOutputStream;
2322
import java.io.IOException;
2423
import java.security.NoSuchAlgorithmException;
2524
import java.util.ArrayList;
26-
import java.util.Arrays;
27-
import java.util.Comparator;
2825
import java.util.HashSet;
2926
import java.util.List;
3027
import java.util.Set;
@@ -35,7 +32,6 @@
3532
import static org.assertj.core.api.Assertions.assertThat;
3633

3734
public class Applications {
38-
public Clients clients;
3935
public Stepdefs base;
4036
public TransientAccount transientAccount;
4137

@@ -44,9 +40,8 @@ public class Applications {
4440
public Long appId = 0L;
4541
public List<Long> rememberedAppIds = new ArrayList<>();
4642

47-
public Applications(TransientAccount transientAccount, Clients clients, Stepdefs base) {
43+
public Applications(TransientAccount transientAccount, Stepdefs base) {
4844
this.transientAccount = transientAccount;
49-
this.clients = clients;
5045
this.base = base;
5146
}
5247

@@ -58,24 +53,24 @@ public void buildAnApplicationTransactions(String operation, String approvalProg
5853
switch (operation) {
5954
case "create":
6055
builder = Transaction.ApplicationCreateTransactionBuilder()
61-
.approvalProgram(loadTEALProgramFromFile(approvalProgramFile, this.clients.v2Client))
62-
.clearStateProgram(loadTEALProgramFromFile(clearProgramFile, this.clients.v2Client))
56+
.approvalProgram(loadTEALProgramFromFile(approvalProgramFile, this.base.aclv2))
57+
.clearStateProgram(loadTEALProgramFromFile(clearProgramFile, this.base.aclv2))
6358
.globalStateSchema(new StateSchema(globalInts, globalBytes))
6459
.localStateSchema(new StateSchema(localInts, localBytes))
6560
.extraPages(extraPages);
6661
break;
6762
case "create_optin":
6863
builder = Transaction.ApplicationCreateTransactionBuilder()
69-
.approvalProgram(loadTEALProgramFromFile(approvalProgramFile, this.clients.v2Client))
70-
.clearStateProgram(loadTEALProgramFromFile(clearProgramFile, this.clients.v2Client))
64+
.approvalProgram(loadTEALProgramFromFile(approvalProgramFile, this.base.aclv2))
65+
.clearStateProgram(loadTEALProgramFromFile(clearProgramFile, this.base.aclv2))
7166
.globalStateSchema(new StateSchema(globalInts, globalBytes))
7267
.localStateSchema(new StateSchema(localInts, localBytes))
7368
.optIn(true);
7469
break;
7570
case "update":
7671
builder = Transaction.ApplicationUpdateTransactionBuilder()
77-
.approvalProgram(loadTEALProgramFromFile(approvalProgramFile, this.clients.v2Client))
78-
.clearStateProgram(loadTEALProgramFromFile(clearProgramFile, this.clients.v2Client));
72+
.approvalProgram(loadTEALProgramFromFile(approvalProgramFile, this.base.aclv2))
73+
.clearStateProgram(loadTEALProgramFromFile(clearProgramFile, this.base.aclv2));
7974
break;
8075
case "call":
8176
builder = Transaction.ApplicationCallTransactionBuilder();
@@ -115,7 +110,7 @@ public void buildAnApplicationTransactions(String operation, String approvalProg
115110

116111
// Send with transient account, suggested params and current application
117112
builder.sender(this.transientAccount.transientAccount.getAddress());
118-
builder.lookupParams(this.clients.v2Client);
113+
builder.lookupParams(this.base.aclv2);
119114
if (this.appId != 0 && !operation.equals("create")) {
120115
builder.applicationId(appId);
121116
}
@@ -128,7 +123,7 @@ public void sendTransactionWithTransientAccountAndCheckForError(String error) th
128123
SignedTransaction stx = this.transientAccount.transientAccount.signTransaction(this.transaction);
129124

130125
// Submit
131-
Response<PostTransactionsResponse> rPost = clients.v2Client.RawTransaction().rawtxn(Encoder.encodeToMsgPack(stx)).execute();
126+
Response<PostTransactionsResponse> rPost = base.aclv2.RawTransaction().rawtxn(Encoder.encodeToMsgPack(stx)).execute();
132127

133128
// If an error was expected, make sure it is set correctly.
134129
if (StringUtils.isNotEmpty(error)) {
@@ -142,18 +137,19 @@ public void sendTransactionWithTransientAccountAndCheckForError(String error) th
142137

143138
// And save the txId for later
144139
this.txId = rPost.body().txId;
140+
base.txid = this.txId;
145141
}
146142

147143
@Given("I wait for the transaction to be confirmed.")
148144
public void waitForTransactionToBeConfirmed() throws Exception {
149-
Utils.waitForConfirmation(clients.v2Client, txId, 1);
145+
Utils.waitForConfirmation(base.aclv2, base.txid, 1);
150146
}
151147

152148
// TODO: Use V2 Pending Transaction endpoint when it is available.
153149
// The initial implementation hacks into the v1 endpoint to manually extract the new data.
154150
@Given("I remember the new application ID.")
155151
public void rememberTheNewApplicatoinId() throws Exception {
156-
PendingTransactionResponse r = clients.v2Client.PendingTransactionInformation(txId).execute().body();
152+
PendingTransactionResponse r = base.aclv2.PendingTransactionInformation(txId).execute().body();
157153
this.appId = r.applicationIndex;
158154
this.rememberedAppIds.add(this.appId);
159155
}
@@ -171,12 +167,12 @@ public void fundAppAccount(Integer amount) throws Exception {
171167
.sender(sender)
172168
.receiver(appAddress)
173169
.amount(amount)
174-
.lookupParams(clients.v2Client)
170+
.lookupParams(base.aclv2)
175171
.build();
176172
SignedTransaction stx = base.signWithAddress(tx, sender);
177173

178-
Response<PostTransactionsResponse> rPost = clients.v2Client.RawTransaction().rawtxn(Encoder.encodeToMsgPack(stx)).execute();
179-
Utils.waitForConfirmation(clients.v2Client, rPost.body().txId, 1);
174+
Response<PostTransactionsResponse> rPost = base.aclv2.RawTransaction().rawtxn(Encoder.encodeToMsgPack(stx)).execute();
175+
Utils.waitForConfirmation(base.aclv2, rPost.body().txId, 1);
180176
}
181177

182178
@Then("I get the account address for the current application and see that it matches the app id's hash")
@@ -198,7 +194,7 @@ public void checkAccountData(
198194
String hasKey,
199195
String keyValue
200196
) throws Exception {
201-
Response<com.algorand.algosdk.v2.client.model.Account> acctResponse = clients.v2Client.AccountInformation(transientAccount.transientAccount.getAddress()).execute();
197+
Response<com.algorand.algosdk.v2.client.model.Account> acctResponse = base.aclv2.AccountInformation(this.transientAccount.transientAccount.getAddress()).execute();
202198

203199
com.algorand.algosdk.v2.client.model.Account acct = acctResponse.body();
204200

@@ -263,9 +259,9 @@ public void checkAccountData(
263259
public void contentsOfBoxShouldBe(String fromClient, String encodedBoxName, String boxContents, String errStr) throws Exception {
264260
Response<Box> boxResp;
265261
if (fromClient.equals("algod"))
266-
boxResp = clients.v2Client.GetApplicationBoxByName(this.appId).name(encodedBoxName).execute();
262+
boxResp = base.aclv2.GetApplicationBoxByName(this.appId).name(encodedBoxName).execute();
267263
else if (fromClient.equals("indexer"))
268-
boxResp = clients.v2IndexerClient.lookupApplicationBoxByIDAndName(this.appId).name(encodedBoxName).execute();
264+
boxResp = base.v2IndexerClient.lookupApplicationBoxByIDAndName(this.appId).name(encodedBoxName).execute();
269265
else
270266
throw new IllegalArgumentException("expecting algod or indexer, got " + fromClient);
271267

@@ -297,9 +293,9 @@ private static void assertSetOfByteArraysEqual(Set<byte[]> expected, Set<byte[]>
297293
public void checkAppBoxes(String fromClient, String encodedBoxesRaw) throws Exception {
298294
Response<BoxesResponse> r;
299295
if (fromClient.equals("algod"))
300-
r = clients.v2Client.GetApplicationBoxes(this.appId).execute();
296+
r = base.aclv2.GetApplicationBoxes(this.appId).execute();
301297
else if (fromClient.equals("indexer"))
302-
r = clients.v2IndexerClient.searchForApplicationBoxes(this.appId).execute();
298+
r = base.v2IndexerClient.searchForApplicationBoxes(this.appId).execute();
303299
else
304300
throw new IllegalArgumentException("expecting algod or indexer, got " + fromClient);
305301

@@ -324,9 +320,9 @@ else if (fromClient.equals("indexer"))
324320
public void checkAppBoxesNum(String fromClient, Long limit, int expected_num) throws Exception {
325321
Response<BoxesResponse> r;
326322
if (fromClient.equals("algod"))
327-
r = clients.v2Client.GetApplicationBoxes(this.appId).max(limit).execute();
323+
r = base.aclv2.GetApplicationBoxes(this.appId).max(limit).execute();
328324
else if (fromClient.equals("indexer"))
329-
r = clients.v2IndexerClient.searchForApplicationBoxes(this.appId).limit(limit).execute();
325+
r = base.v2IndexerClient.searchForApplicationBoxes(this.appId).limit(limit).execute();
330326
else
331327
throw new IllegalArgumentException("expecting algod or indexer, got " + fromClient);
332328

@@ -337,7 +333,7 @@ else if (fromClient.equals("indexer"))
337333

338334
@Then("according to indexer, with {long} being the parameter that limits results, and {string} being the parameter that sets the next result, the current application should have the following boxes {string}.")
339335
public void indexerCheckAppBoxesWithParams(Long limit, String next, String encodedBoxesRaw) throws Exception {
340-
Response<BoxesResponse> r = clients.v2IndexerClient.searchForApplicationBoxes(this.appId).limit(limit).next(next).execute();
336+
Response<BoxesResponse> r = base.v2IndexerClient.searchForApplicationBoxes(this.appId).limit(limit).next(next).execute();
341337
final Set<byte[]> expectedNames = new HashSet<>();
342338
if (!encodedBoxesRaw.isEmpty()) {
343339
for (String s : Strings.split(encodedBoxesRaw, ':')) {

src/test/java/com/algorand/algosdk/integration/AtomicTxnComposer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class AtomicTxnComposer {
4747
public AtomicTxnComposer(Stepdefs stepdefs, Applications apps, TransactionSteps steps) {
4848
base = stepdefs;
4949
applications = apps;
50-
applications.transientAccount.clients.v2Client = base.aclv2;
50+
applications.base.aclv2 = base.aclv2;
5151
applications.transientAccount.base = base;
5252
transSteps = steps;
5353
transSteps.transAcc = apps.transientAccount;

src/test/java/com/algorand/algosdk/integration/Clients.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)