Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added WriteUnbonding transform data class #273

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apply plugin: 'java'

group = 'network.casper'
// Version number update for release
version='2.5.5'
version='2.5.6'
sourceCompatibility = 1.8
targetCompatibility = 1.8

Expand Down
36 changes: 16 additions & 20 deletions src/main/java/com/casper/sdk/model/deploy/UnbondingPurse.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
import com.casper.sdk.model.key.PublicKey;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.casper.sdk.model.uref.URef;
import lombok.AllArgsConstructor;
Expand All @@ -19,6 +18,12 @@
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*
* Changed 5/24
* @author Carl Norburn
* Refactored to match the Casper documentation
* <a href="https://docs.casper.network/concepts/serialization-standard/#unbondingpurse"></a>
*
*/
@Getter
@Setter
Expand All @@ -31,11 +36,11 @@ public class UnbondingPurse {
* Unbonding amount
*/
@JsonProperty("amount")
private BigInteger unbondingAmount;

@JsonIgnore
private BigInteger amount;

@JsonProperty("new_validator")
private BigInteger newValidator;

/**
* the bondingPurse's {@link URef}
*/
Expand All @@ -60,25 +65,16 @@ public class UnbondingPurse {
@JsonProperty("validator_public_key")
private PublicKey validatorPublicKey;

/**
* getter for unbondingAmount json serialization
*
* @return cost as expected for json serialization
*/
@JsonProperty("unbonding_amount")
@JsonProperty("amount")
@ExcludeFromJacocoGeneratedReport
protected String getJsonUnbondingAmount() {
return this.unbondingAmount.toString(10);
protected String getJsonAmount() {
return this.amount.toString(10);
}

/**
* setter for unbondingAmount from json deserialized value
*
* @param value the deserialized value
*/
@JsonProperty("unbonding_amount")
@JsonProperty("amount")
@ExcludeFromJacocoGeneratedReport
protected void setJsonUnbondingAmount(String value) {
this.unbondingAmount = new BigInteger(value, 10);
protected void setJsonAmount(String value) {
this.amount = new BigInteger(value, 10);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public enum TransformTypeData {
WRITE_DEPLOY_INFO("WriteDeployInfo", WriteDeployInfo.class),
WRITE_ERA_INFO("WriteEraInfo", WriteEraInfo.class),
WRITE_TRANSFER("WriteTransfer", WriteTransfer.class),
WRITE_WITHDRAW("WriteWithdraw", WriteWithdraw.class);
WRITE_WITHDRAW("WriteWithdraw", WriteWithdraw.class),
WRITE_UNBONDING("WriteUnbonding", WriteUnbonding.class);

private final String name;
private final Class<?> clazz;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.casper.sdk.model.deploy.transform;

import com.casper.sdk.model.deploy.UnbondingPurse;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import lombok.*;

import java.util.List;

/**
* An implementation of Transform that Writes the given Unbonding to global state.
*
* @author Carl Norburn
* @see Transform
* @since 2.5.6
*/
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@JsonTypeName("WriteUnbonding")
public class WriteUnbonding implements Transform {

@JsonProperty("WriteUnbonding")
private List<UnbondingPurse> purses;

}
16 changes: 16 additions & 0 deletions src/test/java/com/casper/sdk/model/deploy/DeployDataTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@ void validateDeployDataMapping_5() throws IOException, JSONException {

JSONAssert.assertEquals(inputJson, expectedJson, JSONCompareMode.NON_EXTENSIBLE);
}
@Test
void validateDeployDataMapping_6() throws IOException, JSONException {
final String inputJson = getPrettyJson(loadJsonFromFile("deploy-samples/deploy-v6.json"));

LOGGER.debug("Original JSON: {}", inputJson);

final DeployData dd = OBJECT_MAPPER.readValue(inputJson, DeployData.class);

assertNotNull(dd.getDeploy());

final String expectedJson = getPrettyJson(dd);

LOGGER.debug("Serialized JSON: {}", expectedJson);

JSONAssert.assertEquals(inputJson, expectedJson, JSONCompareMode.NON_EXTENSIBLE);
}

@Test
void validateDeployResultMapping() throws IOException, JSONException {
Expand Down
Loading
Loading