package hr.zg.rus;

/**
 * Created by evedili on 23.8.2017..
 */
public class TxOutTest {
    public static void main(String[] args) {
        int amount;
        String script;

        TxOut out0 = new TxOut();

        amount = out0.getAmount();

        if(amount != 0){
            System.out.println("Invalid amount!");
        }

        script = out0.getScriptPubKey();

        if (!(script == null)){
            System.out.println("Invalid script!");
        }

        out0.setAmount(100_000);
        amount = out0.getAmount();

        if(amount != 100_000){
            System.out.println("Set amount not equal to stored amount!");
        }

        script = out0.getScriptPubKey();

        if (!(script == null)){
            System.out.println("Invalid script!");
        }

        out0.setScriptPubKey("76a91496c8fe3196453eb48aaad26d5e1b96a8681e93c188ac");

        if (out0.getScriptPubKey() == null){
            System.out.println("Script should not be empty after setting!");
        }

        TxOut out1 = new TxOut("76a91496c8fe3196453eb48aaad26d5e1b96a8681e93c188ac");

        if(out1.getScriptPubKey() == null){
            System.out.println("Script should not be empty!");
        }
        if(out1.getAmount() < 546){
            System.out.println("Amount should be at leas 546 satoshi!");
        }

        TxOut out2 = new TxOut(100_000, "76a91496c8fe3196453eb48aaad26d5e1b96a8681e93c188ac");

        if(out2.getScriptPubKey() == null){
            System.out.println("Script should not be empty!");
        }
        if(out2.getAmount() < 546){
            System.out.println("Amount should be at leas 546 satoshi!");
        }
    }
}

@@ -179,16 +179,101 @@
 script;%0D
+%0A        String scriptPubKey = %2276a91496c8fe3196453eb48aaad26d5e1b96a8681e93c188ac%22;%0D
 %0A%0D%0A     
@@ -942,60 +942,20 @@
 Key(
-%2276a91496c8fe3196453eb48aaad26d5e1b96a8681e93c188ac%22
+scriptPubKey
 );%0D%0A
@@ -1128,61 +1128,92 @@
 Out(
-%2276a91496c8fe3196453eb48aaad26d5e1b96a8681e93c188ac%22)
+scriptPubKey);%0D%0A        String out1_serialized = %22220200000000000019%22 + scriptPubKey
 ;%0D%0A%0D
@@ -1459,103 +1459,264 @@
  %7D%0D%0A
-%0D%0A        TxOut out2 = new TxOut(100_000, %2276a91496c8fe3196453eb48aaad26d5e1b96a8681e93c188ac%22)
+        if(!out1.toString().equals(out1_serialized))%7B%0D%0A            System.out.println(%22Wrong output serialization!%22);%0D%0A        %7D%0D%0A%0D%0A        TxOut out2 = new TxOut(100_000, scriptPubKey);%0D%0A        String out2_serialized = %22a08601000000000019%22 + scriptPubKey
 ;%0D%0A%0D
@@ -1954,22 +1954,152 @@
 %0A        %7D%0D%0A
+        if(!out2.toString().equals(out2_serialized))%7B%0D%0A            System.out.println(%22Wrong output serialization!%22);%0D%0A        %7D%0D%0A
     %7D%0D%0A%7D%0D%0A

Correct output serialization.