github.com/avahowell/sia@v0.5.1-beta.0.20160524050156-83dcc3d37c94/types/transactions_test.go (about) 1 package types 2 3 import ( 4 "testing" 5 6 "github.com/NebulousLabs/Sia/crypto" 7 ) 8 9 // TestTransactionIDs probes all of the ID functions of the Transaction type. 10 func TestIDs(t *testing.T) { 11 // Create every type of ID using empty fields. 12 txn := Transaction{ 13 SiacoinOutputs: []SiacoinOutput{{}}, 14 FileContracts: []FileContract{{}}, 15 SiafundOutputs: []SiafundOutput{{}}, 16 } 17 tid := txn.ID() 18 scoid := txn.SiacoinOutputID(0) 19 fcid := txn.FileContractID(0) 20 spidT := fcid.StorageProofOutputID(ProofValid, 0) 21 spidF := fcid.StorageProofOutputID(ProofMissed, 0) 22 sfoid := txn.SiafundOutputID(0) 23 scloid := sfoid.SiaClaimOutputID() 24 25 // Put all of the ids into a slice. 26 var ids []crypto.Hash 27 ids = append(ids, 28 crypto.Hash(tid), 29 crypto.Hash(scoid), 30 crypto.Hash(fcid), 31 crypto.Hash(spidT), 32 crypto.Hash(spidF), 33 crypto.Hash(sfoid), 34 crypto.Hash(scloid), 35 ) 36 37 // Check that each id is unique. 38 knownIDs := make(map[crypto.Hash]struct{}) 39 for i, id := range ids { 40 _, exists := knownIDs[id] 41 if exists { 42 t.Error("id repeat for index", i) 43 } 44 knownIDs[id] = struct{}{} 45 } 46 } 47 48 // TestTransactionSiacoinOutputSum probes the SiacoinOutputSum method of the 49 // Transaction type. 50 func TestTransactionSiacoinOutputSum(t *testing.T) { 51 // Create a transaction with all types of siacoin outputs. 52 txn := Transaction{ 53 SiacoinOutputs: []SiacoinOutput{ 54 {Value: NewCurrency64(1)}, 55 {Value: NewCurrency64(20)}, 56 }, 57 FileContracts: []FileContract{ 58 {Payout: NewCurrency64(300)}, 59 {Payout: NewCurrency64(4000)}, 60 }, 61 MinerFees: []Currency{ 62 NewCurrency64(50000), 63 NewCurrency64(600000), 64 }, 65 } 66 if txn.SiacoinOutputSum().Cmp(NewCurrency64(654321)) != 0 { 67 t.Error("wrong siacoin output sum was calculated, got:", txn.SiacoinOutputSum()) 68 } 69 }