From bcf8df1dd434f89225fe8fd49547f9674c72af41 Mon Sep 17 00:00:00 2001 From: meywood <105049338+meywood@users.noreply.github.com> Date: Mon, 6 Nov 2023 16:16:26 +0000 Subject: [PATCH] issues/235 - Option type values --- .../e2e/steps/OptionValuesStepDefinitin.java | 62 ++++++++++++++++--- .../casper/sdk/e2e/utils/CLValueFactory.java | 30 ++++----- 2 files changed, 70 insertions(+), 22 deletions(-) diff --git a/src/test/java/com/casper/sdk/e2e/steps/OptionValuesStepDefinitin.java b/src/test/java/com/casper/sdk/e2e/steps/OptionValuesStepDefinitin.java index adc9f7ea3..5f9b6a38a 100644 --- a/src/test/java/com/casper/sdk/e2e/steps/OptionValuesStepDefinitin.java +++ b/src/test/java/com/casper/sdk/e2e/steps/OptionValuesStepDefinitin.java @@ -1,52 +1,100 @@ package com.casper.sdk.e2e.steps; import com.casper.sdk.e2e.utils.CLValueFactory; +import com.casper.sdk.e2e.utils.CasperClientProvider; +import com.casper.sdk.e2e.utils.DeployUtils; import com.casper.sdk.model.clvalue.CLValueOption; import com.casper.sdk.model.clvalue.cltype.CLTypeData; +import com.casper.sdk.model.deploy.Deploy; +import com.casper.sdk.model.deploy.DeployData; +import com.casper.sdk.model.deploy.DeployResult; +import com.casper.sdk.model.deploy.NamedArg; import dev.oak3.sbs4j.exception.ValueSerializationException; import io.cucumber.java.en.And; import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import java.util.LinkedList; +import java.util.List; import java.util.Optional; +import static com.casper.sdk.e2e.utils.DeployUtils.buildStandardTransferDeploy; +import static com.casper.sdk.e2e.utils.DeployUtils.getNamedArgValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsNull.notNullValue; /** + * Step definitions for the Option value feature. * @author ian@meywood.com */ public class OptionValuesStepDefinitin { private CLValueOption clValueOption; private final CLValueFactory clValueFactory = new CLValueFactory(); + private DeployResult deployResult; + private DeployData deployData; - @Given("^that an option value has an empty value$") + @Given("^that an Option value has an empty value$") public void thatAnOptionValueHasAnEmptyValue() throws ValueSerializationException { - clValueOption = new CLValueOption(Optional.empty()); } - @Then("^the option value is not present$") + @Then("^the Option value is not present$") public void theOptionValueShouldBeInvalid() { assertThat(clValueOption.getValue().isPresent(), is(false)); } - @And("the option value bytes are {string}") + @And("the Option value's bytes are {string}") public void theOptionValueBytesAre(final String hexBytes) { assertThat(clValueOption.getBytes(), is(hexBytes)); } - @Given("that an option value has a {string} value of {string}") + @Given("an Option value contains a {string} value of {string}") public void thatAnOptionValuesHasAValueOf(final String typeName, final String strValue) throws Exception { - clValueOption = new CLValueOption( Optional.of(clValueFactory.createValue(CLTypeData.getTypeByName(typeName), strValue)) ); } - @Then("the option value is present") + @Then("the Option value is present") public void theOptionValueIsPresent() { assertThat(clValueOption.getValue().isPresent(), is(true)); } + + @Given("that the Option value is deployed in a transfer as a named argument") + public void thatTheOptionValueIsDeployedInATransferAsANamedArgument() throws Exception { + final List> transferArgs = new LinkedList<>(); + transferArgs.add(new NamedArg<>("OPTION", clValueOption)); + + final Deploy deploy = buildStandardTransferDeploy(transferArgs); + + clValueOption = null; + + deployResult = CasperClientProvider.getInstance().getCasperService().putDeploy(deploy); + } + + @And("the transfer containing the Option value is successfully executed" + ) + public void theTransferContainingTheOptionValueIsSuccessfullyExecuted() { + deployData = DeployUtils.waitForDeploy( + deployResult.getDeployHash(), + 300, + CasperClientProvider.getInstance().getCasperService() + ); + } + + @When("the Option is read from the deploy") + public void theOptionIsReadFromTheDeploy() { + clValueOption = (CLValueOption) getNamedArgValue(deployData.getDeploy().getSession().getArgs(), "OPTION"); + assertThat(clValueOption, is(notNullValue())); + } + + @And("the type of the Option is {string} with a value of {string}") + public void theTypeOfTheOptionIsWithAValueOf(final String typeName, final String strValue) throws Exception { + assertThat(clValueOption.getClType().getTypeName(), is("Option")); + assertThat(clValueOption.getValue(), is(notNullValue())); + assertThat(clValueOption.getValue().get().getValue(), is(this.clValueFactory.createValue(CLTypeData.getTypeByName(typeName), strValue).getValue())); + } } diff --git a/src/test/java/com/casper/sdk/e2e/utils/CLValueFactory.java b/src/test/java/com/casper/sdk/e2e/utils/CLValueFactory.java index 0d4f16156..73448ef42 100644 --- a/src/test/java/com/casper/sdk/e2e/utils/CLValueFactory.java +++ b/src/test/java/com/casper/sdk/e2e/utils/CLValueFactory.java @@ -32,6 +32,21 @@ public class CLValueFactory { case BOOL: return new CLValueBool(Boolean.TRUE.toString().equalsIgnoreCase(strValue)); + case BYTE_ARRAY: + return new CLValueByteArray(Hex.decode(strValue)); + + case I32: + return new CLValueI32(Integer.valueOf(strValue)); + + case I64: + return new CLValueI64(Long.valueOf(strValue)); + + case KEY: + return new CLValueKey(Key.fromTaggedHexString(strValue)); + + case PUBLIC_KEY: + return new CLValuePublicKey(PublicKey.fromTaggedHexString(strValue)); + case U8: return new CLValueU8(Byte.valueOf(strValue)); @@ -50,21 +65,6 @@ public class CLValueFactory { case U512: return new CLValueU512(new BigInteger(strValue)); - case I32: - return new CLValueI32(Integer.valueOf(strValue)); - - case I64: - return new CLValueI64(Long.valueOf(strValue)); - - case BYTE_ARRAY: - return new CLValueByteArray(Hex.decode(strValue)); - - case KEY: - return new CLValueKey(Key.fromTaggedHexString(strValue)); - - case PUBLIC_KEY: - return new CLValuePublicKey(PublicKey.fromTaggedHexString(strValue)); - case UREF: return new CLValueURef(new URef(Hex.decode(strValue), URefAccessRight.READ_ADD_WRITE));