diff --git a/vochain/process_test.go b/vochain/process_test.go index db28bcfa1..357a34692 100644 --- a/vochain/process_test.go +++ b/vochain/process_test.go @@ -509,7 +509,7 @@ func TestSetProcessCensusSize(t *testing.T) { process := &models.Process{ StartBlock: 1, EnvelopeType: &models.EnvelopeType{EncryptedVotes: false}, - Mode: &models.ProcessMode{Interruptible: true, DynamicCensus: true}, + Mode: &models.ProcessMode{Interruptible: true, DynamicCensus: false}, VoteOptions: &models.ProcessVoteOptions{MaxCount: 16, MaxValue: 16}, Status: models.ProcessStatus_READY, EntityId: accounts[0].Address().Bytes(), @@ -528,8 +528,12 @@ func TestSetProcessCensusSize(t *testing.T) { qt.Assert(t, err, qt.IsNil) qt.Assert(t, proc.MaxCensusSize, qt.Equals, uint64(2)) - // Set census size and new root (should work) - qt.Assert(t, testSetProcessCensus(t, pid, accounts[0], app, util.RandomBytes(32), &censusURI, 5), qt.IsNil) + // Set census size with root (should failg since dynamicCensus=false) + qt.Assert(t, testSetProcessCensus(t, pid, accounts[0], app, util.RandomBytes(32), nil, 5), qt.IsNotNil) + app.AdvanceTestBlock() + + // Set census size (should work) + qt.Assert(t, testSetProcessCensus(t, pid, accounts[0], app, nil, nil, 5), qt.IsNil) app.AdvanceTestBlock() proc, err = app.State.Process(pid, true) diff --git a/vochain/state/process.go b/vochain/state/process.go index 00dad9951..efc299c79 100644 --- a/vochain/state/process.go +++ b/vochain/state/process.go @@ -318,16 +318,17 @@ func (v *State) SetProcessCensus(pid, censusRoot []byte, censusURI string, censu if err != nil { return err } - // check valid state transition - // dynamic census - if !process.Mode.DynamicCensus { - return fmt.Errorf( - "cannot update census, only processes with dynamic census can update their census") - } - // census origin - if !CensusOrigins[process.CensusOrigin].AllowCensusUpdate { - return fmt.Errorf( - "cannot update census, invalid census origin: %s", process.CensusOrigin) + // check dynamic census only if root is being updated + if censusRoot != nil { + if !process.Mode.DynamicCensus { + return fmt.Errorf( + "cannot update census, only processes with dynamic census can update their root") + } + // census origin + if !CensusOrigins[process.CensusOrigin].AllowCensusUpdate { + return fmt.Errorf( + "cannot update census, census origin %s does not allow update", process.CensusOrigin) + } } // status if !(process.Status == models.ProcessStatus_READY) && @@ -352,8 +353,6 @@ func (v *State) SetProcessCensus(pid, censusRoot []byte, censusURI string, censu if commit { if censusRoot != nil { process.CensusRoot = censusRoot - } - if censusURI != "" { process.CensusURI = &censusURI } if censusSize > 0 {