Skip to content

Commit

Permalink
Merge pull request #115 from /issues/113
Browse files Browse the repository at this point in the history
Issues/113
  • Loading branch information
cnorburn authored Jul 13, 2022
2 parents cff4c8e + 5885625 commit a15acc5
Show file tree
Hide file tree
Showing 47 changed files with 4,237 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>network.casper</groupId>
<artifactId>casper-java-sdk</artifactId>
<version>0.3.7</version>
<version>0.3.8</version>
<name>Casper Java SDK</name>
<description>Casper Java SDK</description>
<url>https://casperlabs.io/</url>
Expand Down
72 changes: 72 additions & 0 deletions src/test/java/com/casper/sdk/Batch6Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.casper.sdk;

import com.casper.sdk.service.serialization.cltypes.CLValueBuilder;
import com.casper.sdk.service.serialization.util.CollectionUtils;
import com.casper.sdk.types.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.math.BigInteger;
import java.security.PublicKey;
import java.time.Instant;

import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

public class Batch6Test {

private CasperSdk casperSdk;

@BeforeEach
void setUp() {
casperSdk = new CasperSdk("http://localhost", 11101);
}

/**
* Tests that a StoredContractByHash can be made with CLMap parameters
*/
@Test
void testMakeDeployWithCLMap() throws IOException {

final PublicKey platformPublicKey = casperSdk.loadKey(CasperSdkIntegrationTest.class.getResourceAsStream("/track-4/assets/keys/wm/public_key.pem"));

final String contractHash = "D5f63F80B885B849443Ef758FdC97f69910B84440Ff41463B4ab3F4bE02Ad16a";
final String contractuuid = "ISIN:DE000XXB2UL2";

final CLValue key1 = CLValueBuilder.byteArray("e07cA98F1b5C15bC9ce75e8adB8a3b4D334A1B1Fa14DD16CfD3320bf77Cc3aAb");
final CLValue value = CLValueBuilder.u256(0.4e6);
final CLValue key2 = CLValueBuilder.byteArray("e3D394334Ce46C6043BCd33E4686D2B7a369C606BfCce4C26ca14d2C73Fac824");

final Deploy deploy = casperSdk.makeDeploy(
new DeployParams(
platformPublicKey,
"integration-test",
1,
Instant.now().toEpochMilli(),
DeployParams.DEFAULT_TTL,
null),
new StoredContractByHash(
new ContractHash(contractHash),
"set_state",
new DeployNamedArgBuilder()
.add("token_id", CLValueBuilder.string("token-id"))
.add("instrument_id", CLValueBuilder.string(contractuuid))
.add("asset_decimals", CLValueBuilder.u256(1))
.add("asset_units", CLValueBuilder.u256(50000))
.add("asset_holders", CLValueBuilder.map(CollectionUtils.Map.of(key1, value)))
.add("liability_decimals", CLValueBuilder.u256(1))
.add("liability_units", CLValueBuilder.u256(40000))
.add("liability_holders", CLValueBuilder.map(CollectionUtils.Map.of(key2, value)))
.build()),
casperSdk.standardPayment(new BigInteger("10000000000"))
);

assertThat(deploy, is(notNullValue()));

final String jsonDeploy = casperSdk.deployToJson(deploy);

assertThat(jsonDeploy, is(notNullValue()));
}
}
11 changes: 9 additions & 2 deletions src/test/java/com/casper/sdk/CasperSdkIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.casper.sdk.how_to.HowToUtils;
import com.casper.sdk.service.hash.HashService;
import com.casper.sdk.service.serialization.cltypes.CLValueBuilder;
import com.casper.sdk.service.serialization.util.CollectionUtils;
import com.casper.sdk.types.*;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
Expand All @@ -15,6 +17,7 @@
import java.io.IOException;
import java.math.BigInteger;
import java.security.KeyPair;
import java.security.PublicKey;
import java.time.Instant;

import static com.casper.sdk.how_to.HowToUtils.getUserKeyPairStreams;
Expand All @@ -29,7 +32,9 @@
@Disabled // Remove this comment to test against a network
class CasperSdkIntegrationTest {

/** Path the nctl folder can be overridden with -Dnctl.home=some-path */
/**
* Path the nctl folder can be overridden with -Dnctl.home=some-path
*/

private final Logger logger = LoggerFactory.getLogger(CasperSdkIntegrationTest.class);
private final byte[] expectedSerializedBody = {
Expand All @@ -54,7 +59,9 @@ class CasperSdkIntegrationTest {
(byte) 135, (byte) 250, (byte) 107, (byte) 113, (byte) 237, (byte) 101, (byte) 127, (byte) 51,
(byte) 144, (byte) 81, (byte) 19, (byte) 196, (byte) 35, (byte) 39
};
/** The SDK under test the NCTL test nodes must be running for these tests to execute */
/**
* The SDK under test the NCTL test nodes must be running for these tests to execute
*/
private CasperSdk casperSdk;

@BeforeEach
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/casper/sdk/types/DeployServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.casper.sdk.service.hash.HashService;
import com.casper.sdk.service.json.JsonConversionService;
import com.casper.sdk.service.serialization.cltypes.CLValueBuilder;
import com.casper.sdk.service.serialization.cltypes.TypesFactory;
import com.casper.sdk.service.serialization.types.ByteSerializerFactory;
import com.casper.sdk.service.serialization.util.CollectionUtils;
Expand Down
124 changes: 124 additions & 0 deletions src/test/resources/track-4/assets/batch6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"hash" : "a84aabff106f9d5c606e62d5f4d5f1db715e3d02bdc09c94470d96658d983bee",
"header" : {
"account" : "01f56e258a89bd12cea9d1d77cd2dd367f5134da564572e1c330fcae5579ad0613",
"timestamp" : "2022-07-13T12:51:13.483Z",
"ttl" : "30m",
"gas_price" : 1,
"body_hash" : "b8f30d7a5d17458831de0bdbe4feae5d93e40bba8513dfdfb4165862c85b96c8",
"dependencies" : [ ],
"chain_name" : "integration-test"
},
"payment" : {
"ModuleBytes" : {
"module_bytes" : "",
"args" : [
[
"amount",
{
"cl_type" : "U512",
"bytes" : "0500e40b5402",
"parsed" : 10000000000
}
]
]
}
},
"session" : {
"StoredContractByHash" : {
"hash" : "d5f63f80b885b849443ef758fdc97f69910b84440ff41463b4ab3f4be02ad16a",
"entry_point" : "set_state",
"args" : [
[
"token_id",
{
"cl_type" : "String",
"bytes" : "08000000746f6b656e2d6964",
"parsed" : "token-id"
}
],
[
"instrument_id",
{
"cl_type" : "String",
"bytes" : "110000004953494e3a444530303058584232554c32",
"parsed" : "ISIN:DE000XXB2UL2"
}
],
[
"asset_decimals",
{
"cl_type" : "U256",
"bytes" : "0101",
"parsed" : 1
}
],
[
"asset_units",
{
"cl_type" : "U256",
"bytes" : "0250c3",
"parsed" : 50000
}
],
[
"asset_holders",
{
"cl_type" : {
"Map" : {
"key" : {
"ByteArray" : 32
},
"value" : "U256"
}
},
"bytes" : "0100000020000000e07ca98f1b5c15bc9ce75e8adb8a3b4d334a1b1fa14dd16cfd3320bf77cc3aab03801a06",
"parsed" : [
{
"key" : "e07cA98F1b5C15bC9ce75e8adB8a3b4D334A1B1Fa14DD16CfD3320bf77Cc3aAb",
"value" : 400000.0
}
]
}
],
[
"liability_decimals",
{
"cl_type" : "U256",
"bytes" : "0101",
"parsed" : 1
}
],
[
"liability_units",
{
"cl_type" : "U256",
"bytes" : "02409c",
"parsed" : 40000
}
],
[
"liability_holders",
{
"cl_type" : {
"Map" : {
"key" : {
"ByteArray" : 32
},
"value" : "U256"
}
},
"bytes" : "0100000020000000e3d394334ce46c6043bcd33e4686d2b7a369c606bfcce4c26ca14d2c73fac82403801a06",
"parsed" : [
{
"key" : "e3D394334Ce46C6043BCd33E4686D2B7a369C606BfCce4C26ca14d2C73Fac824",
"value" : 400000.0
}
]
}
]
]
}
},
"approvals" : [ ]
}
3 changes: 3 additions & 0 deletions src/test/resources/track-4/assets/keys/faucet/public_key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAyPi9bJbGm82rh149G92e/PlEJJ4ib9csZ4NwxzNJ9Jo=
-----END PUBLIC KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
01c8f8bd6c96c69bcdab875e3d1bdd9efcf944249e226fd72c678370c73349f49a
3 changes: 3 additions & 0 deletions src/test/resources/track-4/assets/keys/faucet/secret_key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIBAcRxgcggkvRKgseYBEnaZ4njdBobuAkksDgxuwTKmE
-----END PRIVATE KEY-----
1 change: 1 addition & 0 deletions src/test/resources/track-4/assets/keys/nf/account_hash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
account-hash-51da5ae5c39880bfe4f94b0898332d1bd37e647f72f79cf23475df1bb1f85bea
3 changes: 3 additions & 0 deletions src/test/resources/track-4/assets/keys/nf/public_key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEABXPVLfoDJxb9wq5Tlph/KAMEEG/BH2rGzPKHuB3Antc=
-----END PUBLIC KEY-----
1 change: 1 addition & 0 deletions src/test/resources/track-4/assets/keys/nf/public_key_hex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
010573d52dfa032716fdc2ae5396987f280304106fc11f6ac6ccf287b81dc09ed7
3 changes: 3 additions & 0 deletions src/test/resources/track-4/assets/keys/nf/secret_key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIPt0wz7HEdCxzNgXixw7t+SgAYvnnz0CxeeVRbtgMH2z
-----END PRIVATE KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEA51CI/a0aN58sxKDGUAxZ6XOnWJUJmS6DYLYbl4E14aw=
-----END PUBLIC KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
01e75088fdad1a379f2cc4a0c6500c59e973a7589509992e8360b61b978135e1ac
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIFEX5glq6++MEBA5+WqGPGBsxAlODEXH8VvPAwSVOMKG
-----END PRIVATE KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAIl4885Cia8eGNIhqpjsTshSFa7w9tfy5b5WEBg1Pa70=
-----END PUBLIC KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
01225e3cf390a26bc78634886aa63b13b214856bbc3db5fcb96f9584060d4f6bbd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIKJd7yy+8o5Vyq6rjs5XidIA7Djws2ckQWkeFqrB2u5C
-----END PRIVATE KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEA/9cAOBw0Mn/a3t2cq0L41GVEiG8GtKeog6s2Xq23+J8=
-----END PUBLIC KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
01ffd700381c34327fdadedd9cab42f8d46544886f06b4a7a883ab365eadb7f89f
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIO+ZjhVktNCDue22EItXLE9ybqa7DGtrglhJhKeprPNT
-----END PRIVATE KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEA7CTKjV5tzWkfF0SMuAl+jJVylSmoleYXxteevruxHEc=
-----END PUBLIC KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
01ec24ca8d5e6dcd691f17448cb8097e8c95729529a895e617c6d79ebebbb11c47
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIBctKrJebIOeDk/UA4j1eZWHPoI6B0h41KRe5PxtePPy
-----END PRIVATE KEY-----
1 change: 1 addition & 0 deletions src/test/resources/track-4/assets/keys/wm/account_hash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
account-hash-f96fdd87998e35e7e9d080154a3bc1cba9a580610c1eb843a1438754e499c589
3 changes: 3 additions & 0 deletions src/test/resources/track-4/assets/keys/wm/public_key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEA9W4liom9Es6p0dd80t02f1E02lZFcuHDMPyuVXmtBhM=
-----END PUBLIC KEY-----
1 change: 1 addition & 0 deletions src/test/resources/track-4/assets/keys/wm/public_key_hex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
01f56e258a89bd12cea9d1d77cd2dd367f5134da564572e1c330fcae5579ad0613
3 changes: 3 additions & 0 deletions src/test/resources/track-4/assets/keys/wm/secret_key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIGatJC8m3E0IJuWl0MqfG9Eem110NIdBRvFB16jnkmPo
-----END PRIVATE KEY-----
51 changes: 51 additions & 0 deletions src/test/resources/track-4/assets/sfc-PAM-01.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"contract_type": "PAM",
"identifiers": [
{
"value": "DE000XXB2UL2",
"scheme": "ISIN"
},
{
"value": "XXB2UL",
"scheme": "WKN"
}
],
"fields": [
{
"name": "currency",
"value": "EUR"
},
{
"name": "cycleAnchorDateOfInterestPayment",
"value": "2021-06-10T00:00:00"
},
{
"name": "cycleOfInterestPayment",
"value": "P1YL0"
},
{
"name": "dayCountConvention",
"value": "AA"
},
{
"name": "initialExchangeDate",
"value": "2020-06-10T00:00:00"
},
{
"name": "maturityDate",
"value": "2022-06-10T00:00:00"
},
{
"name": "nominalInterestRate",
"value": 0.0012
},
{
"name": "notionalPrincipal",
"value": 100000000.0
},
{
"name": "statusDate",
"value": "2020-05-05T23:59:59"
}
]
}
Loading

0 comments on commit a15acc5

Please sign in to comment.