Skip to content

Commit

Permalink
test: add in simulate tag and a few more test steps
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltchuang committed Oct 3, 2024
1 parent f39ea1d commit 9281c78
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- run: mvn test
integration-test:
machine:
image: "ubuntu-2204:2022.04.2"
image: default
resource_class: medium
steps:
- checkout
Expand Down
1 change: 1 addition & 0 deletions src/test/integration.tags
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
@rekey_v1
@send
@send.keyregtxn
@simulate
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.Map;
import java.util.regex.Pattern;

import static com.algorand.algosdk.util.ConversionUtils.convertBoxes;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNull;

Expand Down Expand Up @@ -437,6 +438,28 @@ public void i_add_a_method_call_with_the_transient_account_the_current_applicati
atc.addMethodCall(optionBuild);
}

@And("I add a method call with the transient account, the current application, suggested params, on complete {string}, current transaction signer, current method arguments, boxes {string}.")
public void iAddAMethodCallWithTheTransientAccountTheCurrentApplicationSuggestedParamsOnCompleteCurrentTransactionSignerCurrentMethodArgumentsBoxes(String onCompleteString, String boxesString) throws Exception {
Address senderAddress = applications.transientAccount.transientAccount.getAddress();

optionBuilder
.onComplete(Transaction.OnCompletion.String(onCompleteString))
.sender(senderAddress)
.signer(transSigner)
.applicationId(applications.appId)
.method(method)
.note(("I should be unique thanks to this nonce: " + nonce).getBytes(StandardCharsets.UTF_8))
.firstValid(transSteps.fv)
.lastValid(transSteps.lv)
.genesisHash(transSteps.genesisHash)
.genesisID(transSteps.genesisID)
.fee(transSteps.fee)
.flatFee(transSteps.flatFee)
.boxReferences(convertBoxes(boxesString));
MethodCallParams optionBuild = optionBuilder.build();
atc.addMethodCall(optionBuild);
}

@When("I build the transaction group with the composer. If there is an error it is {string}.")
public void i_build_the_transaction_group_with_the_composer_if_there_is_an_error_it_is(String errStr) {
String inferredError = "";
Expand Down Expand Up @@ -478,7 +501,6 @@ public void theSimulationShouldReportAFailureAtGroupPathWithMessage(String txnGr
throw new Exception("Invalid transaction group index", e);
}

// Parse the path ("0,0") into a list of numbers ([0, 0])
String[] path = failAt.split(",");
List<Long> expectedPath = new ArrayList<>();
for (String pathStr : path) {
Expand All @@ -489,7 +511,6 @@ public void theSimulationShouldReportAFailureAtGroupPathWithMessage(String txnGr
}
}

// Retrieve the actual failure message
String actualFailureMsg = null;
if (base.simulateResponse != null) {
actualFailureMsg = base.simulateResponse.body().txnGroups.get(groupIndex).failureMessage;
Expand All @@ -503,7 +524,6 @@ public void theSimulationShouldReportAFailureAtGroupPathWithMessage(String txnGr
throw new Exception("Expected failure message '" + expectedFailureMsg + "', but got: '" + actualFailureMsg + "'");
}

// Retrieve the actual failure path
List<Long> actualPath = null;
if (base.simulateResponse != null) {
actualPath = base.simulateResponse.body().txnGroups.get(groupIndex).failedAt;
Expand Down
38 changes: 24 additions & 14 deletions src/test/java/com/algorand/algosdk/integration/Stepdefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import com.algorand.algosdk.v2.client.model.SimulateRequest;
import com.algorand.algosdk.v2.client.model.SimulateRequestTransactionGroup;
import com.algorand.algosdk.v2.client.model.SimulateResponse;
import com.algorand.algosdk.v2.client.model.SimulateTraceConfig;
import com.algorand.algosdk.v2.client.model.TransactionParametersResponse;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.cucumber.java.en.And;
Expand Down Expand Up @@ -1249,12 +1250,14 @@ public void iSimulateTheTransaction() throws Exception {

@When("I make a new simulate request.")
public void iMakeANewSimulateRequest() {

if (simulateRequest == null) {
simulateRequest = new SimulateRequest();
}
}

@Then("I allow {int} more budget on that simulate request.")
public void iAllowMoreBudgetOnThatSimulateRequest(int arg0) {

public void iAllowMoreBudgetOnThatSimulateRequest(int extraOpcodeBudget) {
simulateRequest.extraOpcodeBudget = Long.parseLong(extraOpcodeBudget + "");
}

@Then("I simulate the transaction group with the simulate request.")
Expand All @@ -1263,7 +1266,7 @@ public void iSimulateTheTransactionGroupWithTheSimulateRequest() {
}

@Then("I check the simulation result has power packs extra-opcode-budget with extra budget {int}.")
public void iCheckTheSimulationResultHasPowerPacksExtraOpcodeBudgetWithExtraBudget(int arg0) {
public void iCheckTheSimulationResultHasPowerPacksExtraOpcodeBudgetWithExtraBudget(int budget) {

}

Expand All @@ -1274,27 +1277,34 @@ public void iCheckTheSimulationResultHasPowerPacksAllowMoreLogging() {

@Then("I allow more logs on that simulate request.")
public void iAllowMoreLogsOnThatSimulateRequest() {
if (simulateRequest == null) {
simulateRequest = new SimulateRequest();
}
simulateRequest.allowMoreLogging = true;
}

@Then("I allow exec trace options {string} on that simulate request.")
public void iAllowExecTraceOptionsOnThatSimulateRequest(String arg0) {

public void iAllowExecTraceOptionsOnThatSimulateRequest(String stcString) {
SimulateTraceConfig stc = new SimulateTraceConfig();
String[] stcArray = stcString.split(",");
for (String stcValue : stcArray) {
switch (stcValue) {
case "stack": stc.stackChange = true;
break;
case "scratch": stc.scratchChange = true;
break;
case "state": stc.stateChange = true;
break;
default:
break;
}
}
stc.enable = true;
simulateRequest.execTraceConfig = stc;
}

@Then("{int}th unit in the {string} trace at txn-groups path {string} should add value {string} to stack, pop {int} values from stack, write value {string} to scratch slot {string}.")
public void thUnitInTheTraceAtTxnGroupsPathShouldAddValueToStackPopValuesFromStackWriteValueToScratchSlot(int arg0, String arg1, String arg2, String arg3, int arg4, String arg5, String arg6) {

}

@And("I add a method call with the transient account, the current application, suggested params, on complete {string}, current transaction signer, current method arguments, boxes {string}.")
public void iAddAMethodCallWithTheTransientAccountTheCurrentApplicationSuggestedParamsOnCompleteCurrentTransactionSignerCurrentMethodArgumentsBoxes(String arg0, String arg1) {

}

@Then("the current application initial {string} state should be empty.")
public void theCurrentApplicationInitialStateShouldBeEmpty(String arg0) {

Expand Down

0 comments on commit 9281c78

Please sign in to comment.