github.com/johnathanhowell/sia@v0.5.1-beta.0.20160524050156-83dcc3d37c94/modules/host/persist_test.go (about) 1 package host 2 3 /* 4 import ( 5 "testing" 6 7 "github.com/NebulousLabs/Sia/crypto" 8 "github.com/NebulousLabs/Sia/types" 9 ) 10 11 // TestEarlySaving checks that the early host is correctly saving values to 12 // disk. 13 func TestEarlySaving(t *testing.T) { 14 if testing.Short() { 15 t.SkipNow() 16 } 17 ht, err := blankHostTester("TestEarlySaving") 18 if err != nil { 19 t.Fatal(err) 20 } 21 22 // Store a few of the important fields. 23 var oldSK crypto.SecretKey 24 copy(oldSK[:], ht.host.secretKey[:]) 25 oldSpaceRemaining := ht.host.spaceRemaining 26 oldRevenue := ht.host.revenue 27 28 // Corrupt the fields. 29 ht.host.secretKey[0]++ 30 ht.host.spaceRemaining += 25e9 31 ht.host.revenue = ht.host.revenue.Add(types.NewCurrency64(91e3)) 32 33 // Load the host and see that the fields are reset correctly. 34 ht.host.mu.Lock() 35 err = ht.host.load() 36 ht.host.mu.Unlock() 37 if err != nil { 38 t.Fatal(err) 39 } 40 if ht.host.secretKey != oldSK { 41 t.Error("secret key not loaded correctly") 42 } 43 if ht.host.spaceRemaining != oldSpaceRemaining { 44 t.Error("space remaining not loaded correctly") 45 } 46 if ht.host.revenue.Cmp(oldRevenue) != 0 { 47 t.Error("profit not loaded correctly") 48 } 49 } 50 51 // TestIntegrationValuePersistence verifies that changes made to the host persist between 52 // loads. 53 func TestIntegrationValuePersistence(t *testing.T) { 54 if testing.Short() { 55 t.SkipNow() 56 } 57 ht, err := blankHostTester("TestIntegrationValuePersistence") 58 if err != nil { 59 t.Fatal(err) 60 } 61 62 // Change one of the features of the host persistence and save. 63 ht.host.fileCounter += 1500 64 oldFileCounter := ht.host.fileCounter 65 err = ht.host.save() 66 if err != nil { 67 t.Fatal(err) 68 } 69 70 // Close the current host and create a new host pointing to the same file. 71 err = ht.host.Close() 72 if err != nil { 73 t.Fatal(err) 74 } 75 newHost, err := New(ht.cs, ht.tpool, ht.wallet, "localhost:0", filepath.Join(ht.persistDir, modules.HostDir)) 76 if err != nil { 77 t.Fatal(err) 78 } 79 // Check that the adjusted value has persisted. 80 if newHost.fileCounter != oldFileCounter { 81 t.Fatal(err) 82 } 83 } 84 */