Skip to content

Commit

Permalink
Merge pull request #273 from /issues/272
Browse files Browse the repository at this point in the history
Added WriteUnbonding transform data class
  • Loading branch information
meywood authored May 17, 2024
2 parents ebebb52 + a22b97f commit 67be93d
Show file tree
Hide file tree
Showing 6 changed files with 1,846 additions and 22 deletions.
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

0 comments on commit 67be93d

Please sign in to comment.