Hardcoding additional account information and thus making the tx test self-contained

This commit is contained in:
Nelson R. Perez 2017-11-02 16:09:15 -05:00
parent 2e92805234
commit 3449e97b5b
3 changed files with 26 additions and 19 deletions

View file

@ -4,7 +4,13 @@ package cy.agorise.graphenej;
* Created by nelson on 11/2/17. * Created by nelson on 11/2/17.
*/ */
public class MemoTestAccounts { public class TestAccounts {
public class Bilthon5 {
public static final String BRAINKEY = "TIGROID BUTLER GALLOWS PAKEHA MOONJAH ACARI LUPUS BAE ACRISIA ABBACY BASSOON AKUND";
public static final String WIF = "5Jr84yteNbomGgLq5nvH2Y6WYJCBTsjugPouCtggfS3RguqxDo8";
}
public class Bilthon7 { public class Bilthon7 {
public static final String BRAINKEY = "PUMPER ISOTOME SERE STAINER CLINGER MOONLIT CHAETA UPBRIM AEDILIC BERTHER NIT SHAP SAID SHADING JUNCOUS CHOUGH"; public static final String BRAINKEY = "PUMPER ISOTOME SERE STAINER CLINGER MOONLIT CHAETA UPBRIM AEDILIC BERTHER NIT SHAP SAID SHADING JUNCOUS CHOUGH";
public static final String WIF = "5J96pne45qWM1WpektoeazN6k9Mt93jQ7LyueRxFfEMTiy6yxjM"; public static final String WIF = "5J96pne45qWM1WpektoeazN6k9Mt93jQ7LyueRxFfEMTiy6yxjM";

View file

@ -33,12 +33,11 @@ import cy.agorise.graphenej.test.NaiveSSLContext;
* Created by nelson on 3/6/17. * Created by nelson on 3/6/17.
*/ */
public class TransactionTest { public class TransactionTest {
private final String BILTHON_15_BRAIN_KEY = System.getenv("BILTHON_15_BRAINKEY"); private final String BILTHON_7_BRAIN_KEY = TestAccounts.Bilthon7.BRAINKEY;
private final String BILTHON_5_BRAIN_KEY = System.getenv("BILTHON_5_BRAINKEY"); private final String BILTHON_5_BRAIN_KEY = TestAccounts.Bilthon5.BRAINKEY;
private final String BILTHON_16_BRAIN_KEY = System.getenv("BILTHON_16_BRAINKEY"); private final String BILTHON_16_BRAIN_KEY = TestAccounts.Bilthon16.BRAINKEY;
private final String BLOCK_PAY_DE = System.getenv("BLOCKPAY_DE"); private final String NODE_URL = "wss://eu.openledger.info/ws";
private final String BLOCK_PAY_FR = System.getenv("BLOCKPAY_FR");
// Transfer operation transaction // Transfer operation transaction
private final Asset CORE_ASSET = new Asset("1.3.0"); private final Asset CORE_ASSET = new Asset("1.3.0");
@ -53,6 +52,8 @@ public class TransactionTest {
private AssetAmount minToReceive = new AssetAmount(UnsignedLong.valueOf(520), BIT_USD); private AssetAmount minToReceive = new AssetAmount(UnsignedLong.valueOf(520), BIT_USD);
private long expiration; private long expiration;
private final long FEE_AMOUNT = 21851;
// Lock object // Lock object
private static final class Lock { } private static final class Lock { }
private final Object lockObject = new Lock(); private final Object lockObject = new Lock();
@ -106,7 +107,7 @@ public class TransactionTest {
// Set the custom SSL context. // Set the custom SSL context.
factory.setSSLContext(context); factory.setSSLContext(context);
WebSocket mWebSocket = factory.createSocket(BLOCK_PAY_DE); WebSocket mWebSocket = factory.createSocket(NODE_URL);
mWebSocket.addListener(new TransactionBroadcastSequence(transaction, CORE_ASSET, responseListener)); mWebSocket.addListener(new TransactionBroadcastSequence(transaction, CORE_ASSET, responseListener));
mWebSocket.connect(); mWebSocket.connect();
@ -137,7 +138,7 @@ public class TransactionTest {
@Test @Test
public void testTransferTransaction(){ public void testTransferTransaction(){
ECKey sourcePrivateKey = new BrainKey(BILTHON_15_BRAIN_KEY, 0).getPrivateKey(); ECKey sourcePrivateKey = new BrainKey(BILTHON_7_BRAIN_KEY, 0).getPrivateKey();
PublicKey to1 = new PublicKey(ECKey.fromPublicOnly(new BrainKey(BILTHON_5_BRAIN_KEY, 0).getPublicKey())); PublicKey to1 = new PublicKey(ECKey.fromPublicOnly(new BrainKey(BILTHON_5_BRAIN_KEY, 0).getPublicKey()));
PublicKey to2 = new PublicKey(ECKey.fromPublicOnly(new BrainKey(BILTHON_16_BRAIN_KEY, 0).getPublicKey())); PublicKey to2 = new PublicKey(ECKey.fromPublicOnly(new BrainKey(BILTHON_16_BRAIN_KEY, 0).getPublicKey()));
@ -151,7 +152,7 @@ public class TransactionTest {
.setTransferAmount(new AssetAmount(UnsignedLong.valueOf(1), CORE_ASSET)) .setTransferAmount(new AssetAmount(UnsignedLong.valueOf(1), CORE_ASSET))
.setSource(bilthon_15) .setSource(bilthon_15)
.setDestination(bilthon_5) // bilthon-5 .setDestination(bilthon_5) // bilthon-5
.setFee(new AssetAmount(UnsignedLong.valueOf(264174), CORE_ASSET)) .setFee(new AssetAmount(UnsignedLong.valueOf(FEE_AMOUNT), CORE_ASSET))
.build(); .build();
// Creating operation 2 // Creating operation 2
@ -159,7 +160,7 @@ public class TransactionTest {
.setTransferAmount(new AssetAmount(UnsignedLong.valueOf(1), CORE_ASSET)) .setTransferAmount(new AssetAmount(UnsignedLong.valueOf(1), CORE_ASSET))
.setSource(bilthon_15) // bilthon-15 .setSource(bilthon_15) // bilthon-15
.setDestination(bilthon_16) // bilthon-16 .setDestination(bilthon_16) // bilthon-16
.setFee(new AssetAmount(UnsignedLong.valueOf(264174), CORE_ASSET)) .setFee(new AssetAmount(UnsignedLong.valueOf(FEE_AMOUNT), CORE_ASSET))
.build(); .build();
@ -174,7 +175,7 @@ public class TransactionTest {
@Test @Test
public void testLimitOrderCreateTransaction(){ public void testLimitOrderCreateTransaction(){
ECKey privateKey = new BrainKey(BILTHON_15_BRAIN_KEY, 0).getPrivateKey(); ECKey privateKey = new BrainKey(BILTHON_7_BRAIN_KEY, 0).getPrivateKey();
expiration = (System.currentTimeMillis() / 1000) + 60 * 60; expiration = (System.currentTimeMillis() / 1000) + 60 * 60;
// Creating limit order creation operation // Creating limit order creation operation
@ -210,7 +211,7 @@ public class TransactionTest {
public void testLimitOrderCancelTransaction() throws NoSuchAlgorithmException, IOException, WebSocketException { public void testLimitOrderCancelTransaction() throws NoSuchAlgorithmException, IOException, WebSocketException {
// We first must create a limit order for this test // We first must create a limit order for this test
ECKey privateKey = new BrainKey(BILTHON_15_BRAIN_KEY, 0).getPrivateKey(); ECKey privateKey = new BrainKey(BILTHON_7_BRAIN_KEY, 0).getPrivateKey();
expiration = (System.currentTimeMillis() / 1000) + 60 * 5; expiration = (System.currentTimeMillis() / 1000) + 60 * 5;
// Creating limit order creation operation // Creating limit order creation operation
@ -237,7 +238,7 @@ public class TransactionTest {
// Set the custom SSL context. // Set the custom SSL context.
factory.setSSLContext(context); factory.setSSLContext(context);
WebSocket mWebSocket = factory.createSocket(BLOCK_PAY_DE); WebSocket mWebSocket = factory.createSocket(NODE_URL);
// Requesting limit order to cancel (Task 2) // Requesting limit order to cancel (Task 2)
mWebSocket.addListener(new GetLimitOrders(base.getObjectId(), quote.getObjectId(), 100, new WitnessResponseListener() { mWebSocket.addListener(new GetLimitOrders(base.getObjectId(), quote.getObjectId(), 100, new WitnessResponseListener() {
@ -250,7 +251,7 @@ public class TransactionTest {
if(order.getSeller().getObjectId().equals(bilthon_15.getObjectId())){ if(order.getSeller().getObjectId().equals(bilthon_15.getObjectId())){
// Instantiating a private key for bilthon-15 // Instantiating a private key for bilthon-15
ECKey privateKey = new BrainKey(BILTHON_15_BRAIN_KEY, 0).getPrivateKey(); ECKey privateKey = new BrainKey(BILTHON_7_BRAIN_KEY, 0).getPrivateKey();
// Creating limit order cancellation operation // Creating limit order cancellation operation
LimitOrderCancelOperation operation = new LimitOrderCancelOperation(order, bilthon_15); LimitOrderCancelOperation operation = new LimitOrderCancelOperation(order, bilthon_15);

View file

@ -11,7 +11,7 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import cy.agorise.graphenej.Address; import cy.agorise.graphenej.Address;
import cy.agorise.graphenej.MemoTestAccounts; import cy.agorise.graphenej.TestAccounts;
import cy.agorise.graphenej.PublicKey; import cy.agorise.graphenej.PublicKey;
import cy.agorise.graphenej.Util; import cy.agorise.graphenej.Util;
import cy.agorise.graphenej.errors.ChecksumException; import cy.agorise.graphenej.errors.ChecksumException;
@ -30,8 +30,8 @@ public class MemoTest {
private ECKey destinationPrivate; private ECKey destinationPrivate;
private Address destinationAddress; private Address destinationAddress;
private String sourceWIF = MemoTestAccounts.Bilthon16.WIF; private String sourceWIF = TestAccounts.Bilthon16.WIF;
private String destinationWIF = MemoTestAccounts.Bilthon7.WIF; private String destinationWIF = TestAccounts.Bilthon7.WIF;
private String shortMessage = "test"; private String shortMessage = "test";
private String longerMessage = "testing now longer string with some special charaters é ç o ú á í Í mMno!!"; private String longerMessage = "testing now longer string with some special charaters é ç o ú á í Í mMno!!";
@ -130,8 +130,8 @@ public class MemoTest {
Memo memo = new Memo(sourceAddress, destinationAddress, shortEncryptedMessageNonce, encrypted); Memo memo = new Memo(sourceAddress, destinationAddress, shortEncryptedMessageNonce, encrypted);
JsonElement jsonObject = memo.toJsonObject(); JsonElement jsonObject = memo.toJsonObject();
JsonObject expected = new JsonObject(); JsonObject expected = new JsonObject();
expected.addProperty("from", new Address(ECKey.fromPublicOnly(ECKey.fromPrivate(DumpedPrivateKey.fromBase58(null, MemoTestAccounts.Bilthon16.WIF).getKey().getPrivKeyBytes()).getPubKey())).toString()); expected.addProperty("from", new Address(ECKey.fromPublicOnly(ECKey.fromPrivate(DumpedPrivateKey.fromBase58(null, TestAccounts.Bilthon16.WIF).getKey().getPrivKeyBytes()).getPubKey())).toString());
expected.addProperty("to", new Address(ECKey.fromPublicOnly(ECKey.fromPrivate(DumpedPrivateKey.fromBase58(null, MemoTestAccounts.Bilthon7.WIF).getKey().getPrivKeyBytes()).getPubKey())).toString()); expected.addProperty("to", new Address(ECKey.fromPublicOnly(ECKey.fromPrivate(DumpedPrivateKey.fromBase58(null, TestAccounts.Bilthon7.WIF).getKey().getPrivKeyBytes()).getPubKey())).toString());
expected.addProperty("nonce", String.format("%d", shortEncryptedMessageNonce)); expected.addProperty("nonce", String.format("%d", shortEncryptedMessageNonce));
expected.addProperty("message", "93c398e05f2a36a535f82880032a062d"); expected.addProperty("message", "93c398e05f2a36a535f82880032a062d");
assertEquals("Memo instance should generate a valid JsonObject",expected, jsonObject); assertEquals("Memo instance should generate a valid JsonObject",expected, jsonObject);