Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
fix nil map in persistData
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechampine committed Oct 25, 2016
1 parent 3dbdad4 commit 3fc2c9f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/renter/contractor/persist.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func (c *Contractor) persistData() contractorPersist {
BlockHeight: c.blockHeight,
FinancialMetrics: c.financialMetrics,
LastChange: c.lastChange,
RenewedIDs: make(map[string]string),
}
for _, rev := range c.cachedRevisions {
data.CachedRevisions = append(data.CachedRevisions, rev)
Expand Down
21 changes: 20 additions & 1 deletion modules/renter/contractor/persist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ func (m memPersist) load(data *contractorPersist) error { *data = contractor
func TestSaveLoad(t *testing.T) {
// create contractor with mocked persist dependency
c := &Contractor{
contracts: make(map[types.FileContractID]modules.RenterContract),
contracts: make(map[types.FileContractID]modules.RenterContract),
renewedIDs: make(map[types.FileContractID]types.FileContractID),
}
c.persist = new(memPersist)

Expand All @@ -30,6 +31,12 @@ func TestSaveLoad(t *testing.T) {
{1}: {NetAddress: "bar"},
{2}: {NetAddress: "baz"},
}
c.renewedIDs = map[types.FileContractID]types.FileContractID{
{0}: {1},
{1}: {2},
{2}: {3},
}

// save and reload
err := c.save()
if err != nil {
Expand All @@ -46,6 +53,12 @@ func TestSaveLoad(t *testing.T) {
if !ok0 || !ok1 || !ok2 {
t.Fatal("contracts were not restored properly:", c.contracts)
}
_, ok0 = c.renewedIDs[types.FileContractID{0}]
_, ok1 = c.renewedIDs[types.FileContractID{1}]
_, ok2 = c.renewedIDs[types.FileContractID{2}]
if !ok0 || !ok1 || !ok2 {
t.Fatal("renewed IDs were not restored properly:", c.renewedIDs)
}

// use stdPersist instead of mock
c.persist = newPersist(build.TempDir("contractor", "TestSaveLoad"))
Expand All @@ -67,4 +80,10 @@ func TestSaveLoad(t *testing.T) {
if !ok0 || !ok1 || !ok2 {
t.Fatal("contracts were not restored properly:", c.contracts)
}
_, ok0 = c.renewedIDs[types.FileContractID{0}]
_, ok1 = c.renewedIDs[types.FileContractID{1}]
_, ok2 = c.renewedIDs[types.FileContractID{2}]
if !ok0 || !ok1 || !ok2 {
t.Fatal("renewed IDs were not restored properly:", c.renewedIDs)
}
}

0 comments on commit 3fc2c9f

Please sign in to comment.