gitlab.com/SkynetLabs/skyd@v1.6.9/skymodules/renter/proto/contractpersist_compat_test.go (about) 1 package proto 2 3 import ( 4 "os" 5 "path/filepath" 6 "testing" 7 8 "gitlab.com/NebulousLabs/encoding" 9 ) 10 11 var ( 12 v1412ContractLocation = filepath.Join("testdata", "v1412.contract") 13 v1420ContractLocation = filepath.Join("testdata", "v1420.header") 14 ) 15 16 // TestLoadV1412Contract will test that loading a v1412 legacy contract is 17 // successful. 18 func TestLoadV1412Contract(t *testing.T) { 19 f, err := os.Open(v1412ContractLocation) 20 if err != nil { 21 t.Fatal(err) 22 } 23 stat, err := f.Stat() 24 if err != nil { 25 t.Fatal(err) 26 } 27 decodeMaxSize := int(stat.Size() * decodeMaxSizeMultiplier) 28 29 _, err = loadSafeContractHeader(f, decodeMaxSize) 30 if err != nil { 31 t.Fatal(err) 32 } 33 } 34 35 // TestLoadV160Contract will test that loading a v160 legacy contract is 36 // successful. 37 func TestLoadV160Contract(t *testing.T) { 38 f, err := os.Open(v1420ContractLocation) 39 if err != nil { 40 t.Fatal(err) 41 } 42 stat, err := f.Stat() 43 if err != nil { 44 t.Fatal(err) 45 } 46 decodeMaxSize := int(stat.Size() * decodeMaxSizeMultiplier) 47 48 _, err = loadSafeContractHeader(f, decodeMaxSize) 49 if err != nil { 50 t.Fatal(err) 51 } 52 } 53 54 // TestLoadV1420SetHeaderUpdate will test that loading a v1420 legacy header 55 // update is successful. 56 func TestLoadV1420SetHeaderUpdate(t *testing.T) { 57 var update v160UpdateSetHeader 58 update.Header.Utility.GoodForRenew = true 59 b := encoding.Marshal(update) 60 61 var newUpdate updateSetHeader 62 err := updateSetHeaderUnmarshalV1420ToV160(b, &newUpdate) 63 if err != nil { 64 t.Fatal(err) 65 } 66 if newUpdate.Header.Utility.GoodForRefresh != true { 67 t.Fatal("goodForRefresh should be true") 68 } 69 }