@@ -775,6 +775,20 @@ func TestTransactionJSONMarshalling(t *testing.T) {
775
775
},
776
776
},
777
777
},
778
+ SiafundInputs : []SiafundInput {
779
+ {
780
+ ParentID : frand .Entropy256 (),
781
+ UnlockConditions : UnlockConditions {
782
+ PublicKeys : []UnlockKey {
783
+ PublicKey (frand .Entropy256 ()).UnlockKey (),
784
+ },
785
+ SignaturesRequired : 1 ,
786
+ },
787
+ },
788
+ },
789
+ SiafundOutputs : []SiafundOutput {
790
+ {Address : frand .Entropy256 (), Value : frand .Uint64n (10000 )},
791
+ },
778
792
}
779
793
expectedID := txn .ID ()
780
794
@@ -790,11 +804,43 @@ func TestTransactionJSONMarshalling(t *testing.T) {
790
804
t .Fatalf ("expected ID %q, got %q" , expectedID .String (), txnMap ["id" ].(string ))
791
805
}
792
806
807
+ expectedSiacoinID := txn .SiacoinOutputID (0 )
808
+ siacoinOutputID := txnMap ["siacoinOutputs" ].([]any )[0 ].(map [string ]any )["id" ].(string )
809
+ if siacoinOutputID != expectedSiacoinID .String () {
810
+ t .Fatalf ("expected siacoin output id %q, got %q" , expectedSiacoinID .String (), siacoinOutputID )
811
+ }
812
+
813
+ expectedSiafundID := txn .SiafundOutputID (0 )
814
+ siafundOutputID := txnMap ["siafundOutputs" ].([]any )[0 ].(map [string ]any )["id" ].(string )
815
+ if siafundOutputID != expectedSiafundID .String () {
816
+ t .Fatalf ("expected siafund output id %q, got %q" , expectedSiafundID .String (), siafundOutputID )
817
+ }
818
+
819
+ expectedSiacoinInputAddress := txn .SiacoinInputs [0 ].UnlockConditions .UnlockHash ()
820
+ siacoinInputAddress := txnMap ["siacoinInputs" ].([]any )[0 ].(map [string ]any )["address" ].(string )
821
+ if siacoinInputAddress != expectedSiacoinInputAddress .String () {
822
+ t .Fatalf ("expected siacoin input address %q, got %q" , expectedSiacoinInputAddress .String (), siacoinInputAddress )
823
+ }
824
+
825
+ expectedSiafundInputAddress := txn .SiafundInputs [0 ].UnlockConditions .UnlockHash ()
826
+ siafundInputAddress := txnMap ["siafundInputs" ].([]any )[0 ].(map [string ]any )["address" ].(string )
827
+ if siafundInputAddress != expectedSiafundInputAddress .String () {
828
+ t .Fatalf ("expected siafund input address %q, got %q" , expectedSiafundInputAddress .String (), siafundInputAddress )
829
+ }
830
+
793
831
var txn2 Transaction
794
832
if err := json .Unmarshal (buf , & txn2 ); err != nil {
795
833
t .Fatal (err )
796
834
} else if txn2 .ID () != expectedID {
797
835
t .Fatalf ("expected unmarshalled ID to be %q, got %q" , expectedID , txn2 .ID ())
836
+ } else if txn2 .SiacoinOutputID (0 ) != expectedSiacoinID {
837
+ t .Fatalf ("expected unmarshalled siacoin output id to be %q, got %q" , expectedSiacoinID , txn2 .SiacoinOutputID (0 ))
838
+ } else if txn2 .SiafundOutputID (0 ) != expectedSiafundID {
839
+ t .Fatalf ("expected unmarshalled siafund output id to be %q, got %q" , expectedSiafundID , txn2 .SiafundOutputID (0 ))
840
+ } else if txn2 .SiacoinInputs [0 ].UnlockConditions .UnlockHash () != expectedSiacoinInputAddress {
841
+ t .Fatalf ("expected unmarshalled siacoin input address to be %q, got %q" , expectedSiacoinInputAddress , txn2 .SiacoinInputs [0 ].UnlockConditions .UnlockHash ())
842
+ } else if txn2 .SiafundInputs [0 ].UnlockConditions .UnlockHash () != expectedSiafundInputAddress {
843
+ t .Fatalf ("expected unmarshalled siafund input address to be %q, got %q" , expectedSiafundInputAddress , txn2 .SiafundInputs [0 ].UnlockConditions .UnlockHash ())
798
844
}
799
845
}
800
846
0 commit comments