gitlab.com/jokerrs1/Sia@v1.3.2/modules/host/persist_compat_1.0.0_test.go (about) 1 package host 2 3 import ( 4 "path/filepath" 5 "testing" 6 7 "github.com/NebulousLabs/Sia/build" 8 "github.com/NebulousLabs/Sia/modules" 9 "github.com/NebulousLabs/Sia/types" 10 ) 11 12 // TestHostPersistCompat100 tests breaking changes in the host persist struct 13 // resulting from spelling errors. The test occurs by loading 14 // hostpersist_compat_1.0.0.json, a v0.6.0 host persistence file that has been 15 // pulled from the wild and adapted to have all non-zero values in its fields 16 // for the purposes of testing. 17 func TestHostPersistCompat100(t *testing.T) { 18 if testing.Short() { 19 t.SkipNow() 20 } 21 t.Parallel() 22 ht, err := newHostTester("TestHostPersistCompat100") 23 if err != nil { 24 t.Fatal(err) 25 } 26 defer ht.Close() 27 28 // Close the host and then swap out the persist file for the one that is 29 // being used for testing. 30 ht.host.Close() 31 source := filepath.Join("testdata", "v100Host.tar.gz") 32 err = build.ExtractTarGz(source, filepath.Join(ht.host.persistDir)) 33 if err != nil { 34 t.Log(filepath.Abs(source)) 35 t.Fatal(err) 36 } 37 h, err := New(ht.cs, ht.tpool, ht.wallet, "localhost:0", filepath.Join(ht.persistDir, modules.HostDir)) 38 if err != nil { 39 t.Fatal(err) 40 } 41 42 // Check that, after loading the compatibility file, all of the values are 43 // still correct. The file that was transplanted had no zero-value fields. 44 ht.host.mu.Lock() 45 if h.financialMetrics.PotentialStorageRevenue.IsZero() { 46 t.Error("potential storage revenue not loaded correctly") 47 } 48 if h.settings.MinContractPrice.IsZero() { 49 t.Error("min contract price not loaded correctly") 50 } 51 if h.settings.MinDownloadBandwidthPrice.IsZero() { 52 t.Error("min download bandwidth price not loaded correctly") 53 } 54 if h.settings.MinStoragePrice.IsZero() { 55 t.Error("min storage price not loaded correctly") 56 } 57 if h.settings.MinUploadBandwidthPrice.IsZero() { 58 t.Error("min upload bandwidth price not loaded correctly") 59 } 60 if h.revisionNumber == 0 { 61 t.Error("revision number loaded incorrectly") 62 } 63 if h.unlockHash == (types.UnlockHash{}) { 64 t.Error("unlock hash loaded incorrectly") 65 } 66 ht.host.mu.Unlock() 67 68 // Set ht.host to 'h' so that the 'ht.Close()' method will close everything 69 // cleanly. 70 ht.host = h 71 }