From 9281c7875c35f41bdc6906fdb96abad192e023f1 Mon Sep 17 00:00:00 2001 From: Michael T Chuang Date: Wed, 2 Oct 2024 19:55:23 -0700 Subject: [PATCH] test: add in simulate tag and a few more test steps --- .circleci/config.yml | 2 +- src/test/integration.tags | 1 + .../integration/AtomicTxnComposer.java | 26 +++++++++++-- .../algosdk/integration/Stepdefs.java | 38 ++++++++++++------- 4 files changed, 49 insertions(+), 18 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 511cac25f..968f1a0d7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,7 +24,7 @@ jobs: - run: mvn test integration-test: machine: - image: "ubuntu-2204:2022.04.2" + image: default resource_class: medium steps: - checkout diff --git a/src/test/integration.tags b/src/test/integration.tags index f8b49f9fc..d73c5c749 100644 --- a/src/test/integration.tags +++ b/src/test/integration.tags @@ -13,3 +13,4 @@ @rekey_v1 @send @send.keyregtxn +@simulate diff --git a/src/test/java/com/algorand/algosdk/integration/AtomicTxnComposer.java b/src/test/java/com/algorand/algosdk/integration/AtomicTxnComposer.java index 6ae4e092e..93a269976 100644 --- a/src/test/java/com/algorand/algosdk/integration/AtomicTxnComposer.java +++ b/src/test/java/com/algorand/algosdk/integration/AtomicTxnComposer.java @@ -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; @@ -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 = ""; @@ -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 expectedPath = new ArrayList<>(); for (String pathStr : path) { @@ -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; @@ -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 actualPath = null; if (base.simulateResponse != null) { actualPath = base.simulateResponse.body().txnGroups.get(groupIndex).failedAt; diff --git a/src/test/java/com/algorand/algosdk/integration/Stepdefs.java b/src/test/java/com/algorand/algosdk/integration/Stepdefs.java index 1a64b6853..d2c3ddd8f 100644 --- a/src/test/java/com/algorand/algosdk/integration/Stepdefs.java +++ b/src/test/java/com/algorand/algosdk/integration/Stepdefs.java @@ -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; @@ -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.") @@ -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) { } @@ -1274,15 +1277,27 @@ 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}.") @@ -1290,11 +1305,6 @@ public void thUnitInTheTraceAtTxnGroupsPathShouldAddValueToStackPopValuesFromSta } - @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) {