@@ -28,19 +28,6 @@ func Equal[T any](t *testing.T, desc string, expected, got T) {
2828 }
2929}
3030
31- // CheckBalance checks that an address has the balances we expect.
32- func CheckBalance (t * testing.T , db explorer.Store , addr types.Address , expectSC , expectImmatureSC types.Currency , expectSF uint64 ) {
33- t .Helper ()
34-
35- sc , immatureSC , sf , err := db .Balance (addr )
36- if err != nil {
37- t .Fatal (err )
38- }
39- Equal (t , "siacoins" , expectSC , sc )
40- Equal (t , "immature siacoins" , expectImmatureSC , immatureSC )
41- Equal (t , "siafunds" , expectSF , sf )
42- }
43-
4431// CheckTransaction checks the inputs and outputs of the retrieved transaction
4532// with the source transaction.
4633func CheckTransaction (t * testing.T , expectTxn types.Transaction , gotTxn explorer.Transaction ) {
@@ -150,6 +137,29 @@ func CheckTransaction(t *testing.T, expectTxn types.Transaction, gotTxn explorer
150137func CheckV2Transaction (t * testing.T , expectTxn types.V2Transaction , gotTxn explorer.V2Transaction ) {
151138 t .Helper ()
152139
140+ // checkV2FC checks the retrieved file contract with the source file contract
141+ // in addition to checking the resolved and valid fields.
142+ checkV2FC := func (expected types.V2FileContract , got explorer.V2FileContract ) {
143+ t .Helper ()
144+
145+ gotFC := got .V2FileContractElement .V2FileContract
146+ Equal (t , "capacity" , expected .Capacity , gotFC .Capacity )
147+ Equal (t , "filesize" , expected .Filesize , gotFC .Filesize )
148+ Equal (t , "proof height" , expected .ProofHeight , gotFC .ProofHeight )
149+ Equal (t , "expiration height" , expected .ExpirationHeight , gotFC .ExpirationHeight )
150+ Equal (t , "renter output address" , expected .RenterOutput .Address , gotFC .RenterOutput .Address )
151+ Equal (t , "renter output value" , expected .RenterOutput .Address , gotFC .RenterOutput .Address )
152+ Equal (t , "host output address" , expected .HostOutput .Address , gotFC .HostOutput .Address )
153+ Equal (t , "host output value" , expected .HostOutput .Address , gotFC .HostOutput .Address )
154+ Equal (t , "missed host value" , expected .MissedHostValue , gotFC .MissedHostValue )
155+ Equal (t , "total collateral" , expected .TotalCollateral , gotFC .TotalCollateral )
156+ Equal (t , "renter public key" , expected .RenterPublicKey , gotFC .RenterPublicKey )
157+ Equal (t , "host public key" , expected .HostPublicKey , gotFC .HostPublicKey )
158+ Equal (t , "revision number" , expected .RevisionNumber , gotFC .RevisionNumber )
159+ Equal (t , "renter signature" , expected .RenterSignature , gotFC .RenterSignature )
160+ Equal (t , "host signature" , expected .HostSignature , gotFC .HostSignature )
161+ }
162+
153163 txnID := expectTxn .ID ()
154164 Equal (t , "id" , txnID , gotTxn .ID )
155165 Equal (t , "new foundation address" , expectTxn .NewFoundationAddress , gotTxn .NewFoundationAddress )
@@ -217,7 +227,7 @@ func CheckV2Transaction(t *testing.T, expectTxn types.V2Transaction, gotTxn expl
217227 expected := expectTxn .FileContracts [i ]
218228 got := gotTxn .FileContracts [i ]
219229
220- CheckV2FC ( t , expected , got )
230+ checkV2FC ( expected , got )
221231 Equal (t , "id" , expectTxn .V2FileContractID (txnID , i ), got .ID )
222232 }
223233
@@ -228,23 +238,23 @@ func CheckV2Transaction(t *testing.T, expectTxn types.V2Transaction, gotTxn expl
228238
229239 Equal (t , "parent ID" , expected .Parent .ID , got .Parent .ID )
230240 Equal (t , "revision ID" , expected .Parent .ID , got .Revision .ID )
231- CheckV2FC ( t , expected .Parent .V2FileContract , got .Parent )
232- CheckV2FC ( t , expected .Revision , got .Revision )
241+ checkV2FC ( expected .Parent .V2FileContract , got .Parent )
242+ checkV2FC ( expected .Revision , got .Revision )
233243 }
234244
235245 Equal (t , "file contract resolutions" , len (expectTxn .FileContractResolutions ), len (gotTxn .FileContractResolutions ))
236246 for i := range expectTxn .FileContractResolutions {
237247 expected := expectTxn .FileContractResolutions [i ]
238248 got := gotTxn .FileContractResolutions [i ]
239249
240- CheckV2FC ( t , expected .Parent .V2FileContract , got .Parent )
250+ checkV2FC ( expected .Parent .V2FileContract , got .Parent )
241251
242252 switch v := expected .Resolution .(type ) {
243253 case * types.V2FileContractRenewal :
244254 if gotV , ok := got .Resolution .(* explorer.V2FileContractRenewal ); ! ok {
245255 t .Fatalf ("expected V2FileContractRenewal, got %v" , reflect .TypeOf (got .Resolution ))
246256 } else {
247- CheckV2FC ( t , v .NewContract , gotV .NewContract )
257+ checkV2FC ( v .NewContract , gotV .NewContract )
248258
249259 Equal (t , "type" , explorer .V2ResolutionRenewal , got .Type )
250260 Equal (t , "final renter output address" , v .FinalRenterOutput .Address , gotV .FinalRenterOutput .Address )
@@ -314,72 +324,3 @@ func CheckV2Transaction(t *testing.T, expectTxn types.V2Transaction, gotTxn expl
314324 Equal (t , "arbitrary data value" , expectTxn .ArbitraryData [i ], gotTxn .ArbitraryData [i ])
315325 }
316326}
317-
318- // CheckV2ChainIndices checks that the chain indices that a v2 transaction was
319- // in from the explorer match the expected chain indices.
320- func CheckV2ChainIndices (t * testing.T , db explorer.Store , txnID types.TransactionID , expected []types.ChainIndex ) {
321- t .Helper ()
322-
323- indices , err := db .V2TransactionChainIndices (txnID , 0 , 100 )
324- switch {
325- case err != nil :
326- t .Fatal (err )
327- case len (indices ) != len (expected ):
328- t .Fatalf ("expected %d indices, got %d" , len (expected ), len (indices ))
329- }
330- for i := range indices {
331- Equal (t , "index" , expected [i ], indices [i ])
332- }
333- }
334-
335- // CheckFC checks the retrieved file contract with the source file contract in
336- // addition to checking the resolved and valid fields.
337- func CheckFC (t * testing.T , revision , resolved , valid bool , expected types.FileContract , got explorer.ExtendedFileContract ) {
338- t .Helper ()
339-
340- Equal (t , "resolved state" , resolved , got .Resolved )
341- Equal (t , "valid state" , valid , got .Valid )
342-
343- Equal (t , "filesize" , expected .Filesize , got .Filesize )
344- Equal (t , "file merkle root" , expected .FileMerkleRoot , got .FileMerkleRoot )
345- Equal (t , "window start" , expected .WindowStart , got .WindowStart )
346- Equal (t , "window end" , expected .WindowEnd , got .WindowEnd )
347- if ! revision {
348- Equal (t , "payout" , expected .Payout , got .Payout )
349- }
350- Equal (t , "unlock hash" , expected .UnlockHash , got .UnlockHash )
351- Equal (t , "revision number" , expected .RevisionNumber , got .RevisionNumber )
352- Equal (t , "valid proof outputs" , len (expected .ValidProofOutputs ), len (got .ValidProofOutputs ))
353- for i := range expected .ValidProofOutputs {
354- Equal (t , "valid proof output address" , expected .ValidProofOutputs [i ].Address , got .ValidProofOutputs [i ].Address )
355- Equal (t , "valid proof output value" , expected .ValidProofOutputs [i ].Value , got .ValidProofOutputs [i ].Value )
356- }
357- Equal (t , "missed proof outputs" , len (expected .MissedProofOutputs ), len (got .MissedProofOutputs ))
358- for i := range expected .MissedProofOutputs {
359- Equal (t , "missed proof output address" , expected .MissedProofOutputs [i ].Address , got .MissedProofOutputs [i ].Address )
360- Equal (t , "missed proof output value" , expected .MissedProofOutputs [i ].Value , got .MissedProofOutputs [i ].Value )
361- }
362- }
363-
364- // CheckV2FC checks the retrieved file contract with the source file contract
365- // in addition to checking the resolved and valid fields.
366- func CheckV2FC (t * testing.T , expected types.V2FileContract , got explorer.V2FileContract ) {
367- t .Helper ()
368-
369- gotFC := got .V2FileContractElement .V2FileContract
370- Equal (t , "capacity" , expected .Capacity , gotFC .Capacity )
371- Equal (t , "filesize" , expected .Filesize , gotFC .Filesize )
372- Equal (t , "proof height" , expected .ProofHeight , gotFC .ProofHeight )
373- Equal (t , "expiration height" , expected .ExpirationHeight , gotFC .ExpirationHeight )
374- Equal (t , "renter output address" , expected .RenterOutput .Address , gotFC .RenterOutput .Address )
375- Equal (t , "renter output value" , expected .RenterOutput .Address , gotFC .RenterOutput .Address )
376- Equal (t , "host output address" , expected .HostOutput .Address , gotFC .HostOutput .Address )
377- Equal (t , "host output value" , expected .HostOutput .Address , gotFC .HostOutput .Address )
378- Equal (t , "missed host value" , expected .MissedHostValue , gotFC .MissedHostValue )
379- Equal (t , "total collateral" , expected .TotalCollateral , gotFC .TotalCollateral )
380- Equal (t , "renter public key" , expected .RenterPublicKey , gotFC .RenterPublicKey )
381- Equal (t , "host public key" , expected .HostPublicKey , gotFC .HostPublicKey )
382- Equal (t , "revision number" , expected .RevisionNumber , gotFC .RevisionNumber )
383- Equal (t , "renter signature" , expected .RenterSignature , gotFC .RenterSignature )
384- Equal (t , "host signature" , expected .HostSignature , gotFC .HostSignature )
385- }
0 commit comments