diff --git a/graphenej/src/test/java/cy/agorise/graphenej/TransactionTest.java b/graphenej/src/test/java/cy/agorise/graphenej/TransactionTest.java index 6b9b1ad..d4dd064 100644 --- a/graphenej/src/test/java/cy/agorise/graphenej/TransactionTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/TransactionTest.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.math.BigInteger; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import javax.net.ssl.SSLContext; @@ -24,6 +25,7 @@ import cy.agorise.graphenej.interfaces.WitnessResponseListener; import cy.agorise.graphenej.models.BaseResponse; import cy.agorise.graphenej.models.WitnessResponse; import cy.agorise.graphenej.objects.Memo; +import cy.agorise.graphenej.operations.CustomOperation; import cy.agorise.graphenej.operations.LimitOrderCancelOperation; import cy.agorise.graphenej.operations.LimitOrderCreateOperation; import cy.agorise.graphenej.operations.TransferOperation; @@ -53,6 +55,13 @@ public class TransactionTest { private AssetAmount minToReceive = new AssetAmount(UnsignedLong.valueOf(520), BIT_USD); private long expiration; + // Custom operation transaction + private final AssetAmount fee = new AssetAmount(UnsignedLong.valueOf(100000), CORE_ASSET); + private final UserAccount payer = bilthon_7; + private final Integer operationId = 61166; + private final List requiredAuths = Collections.singletonList(payer); + private final String data = "some data"; + private final long FEE_AMOUNT = 21851; // Lock object @@ -322,4 +331,19 @@ public class TransactionTest { } }, lockObject); } + + @Test + public void testCustomOperationTransaction(){ + ECKey sourcePrivateKey = new BrainKey(BILTHON_7_BRAIN_KEY, 0).getPrivateKey(); + + // Creating custom operation + CustomOperation customOperation = new CustomOperation(fee, payer, operationId, requiredAuths, data); + + // Adding operation to the operation list + ArrayList operationList = new ArrayList<>(); + operationList.add(customOperation); + + // Broadcasting transaction + broadcastTransaction(sourcePrivateKey, operationList, listener, null); + } } \ No newline at end of file diff --git a/graphenej/src/test/java/cy/agorise/graphenej/operations/CustomOperationTest.java b/graphenej/src/test/java/cy/agorise/graphenej/operations/CustomOperationTest.java new file mode 100644 index 0000000..6196378 --- /dev/null +++ b/graphenej/src/test/java/cy/agorise/graphenej/operations/CustomOperationTest.java @@ -0,0 +1,39 @@ +package cy.agorise.graphenej.operations; + +import com.google.common.primitives.UnsignedLong; +import cy.agorise.graphenej.Asset; +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.Util; +import org.junit.Test; + +import java.util.Collections; +import java.util.List; + +import static org.junit.Assert.assertArrayEquals; + +public class CustomOperationTest { + private final Asset CORE_ASSET = new Asset("1.3.0"); + private final AssetAmount fee = new AssetAmount(UnsignedLong.valueOf(100000L), CORE_ASSET); + private final UserAccount payer = new UserAccount("1.2.20"); + private final Integer operationId = 61166; + private final List requiredAuths = Collections.singletonList(payer); + private final String shortData = "some data"; + private final String longData = "very long data, very long data, very long data, very long data, very long data, very long data, very long data, very long data, very long data, very long data, very long data, very long data, very long data, very long data..."; + + private static final byte[] EXPECTED_SERIALIZED_BYTES_1 = Util.hexToBytes("a08601000000000000140114eeee09736f6d652064617461"); + private static final byte[] EXPECTED_SERIALIZED_BYTES_2 = Util.hexToBytes("a08601000000000000140114eeeee50176657279206c6f6e6720646174612c2076657279206c6f6e6720646174612c2076657279206c6f6e6720646174612c2076657279206c6f6e6720646174612c2076657279206c6f6e6720646174612c2076657279206c6f6e6720646174612c202076657279206c6f6e6720646174612c2076657279206c6f6e6720646174612c202076657279206c6f6e6720646174612c2076657279206c6f6e6720646174612c202076657279206c6f6e6720646174612c2076657279206c6f6e6720646174612c202076657279206c6f6e6720646174612c2076657279206c6f6e6720646174612e2e2e"); + + @Test + public void testToBytes() throws Exception { + CustomOperation customOperation1 = new CustomOperation(fee, payer, operationId, requiredAuths, shortData); + byte[] serialized1 = customOperation1.toBytes(); + assertArrayEquals(EXPECTED_SERIALIZED_BYTES_1, serialized1); + + // test with some long data string to check if data length is serialized correctly + CustomOperation customOperation2 = new CustomOperation(fee, payer, operationId, requiredAuths, longData); + byte[] serialized2 = customOperation2.toBytes(); + assertArrayEquals(EXPECTED_SERIALIZED_BYTES_2, serialized2); + } +} +