@@ -202,8 +202,7 @@ func TestDBFT_OnReceiveRequestSendResponse(t *testing.T) {
202202 })
203203
204204 t .Run ("old height" , func (t * testing.T ) {
205- p := s .getPrepareRequest (5 , txs [0 ].Hash ())
206- p .SetHeight (3 )
205+ p := s .getPrepareRequestWithHeight (5 , 3 , txs [0 ].Hash ())
207206 service .OnReceive (p )
208207 require .Nil (t , s .tryRecv ())
209208 })
@@ -462,35 +461,35 @@ func TestDBFT_Invalid(t *testing.T) {
462461 require .Nil (t , dbft .New (opts ... ))
463462 })
464463
465- opts = append (opts , dbft.WithNewPrepareRequest [crypto.Uint256 , crypto.Uint160 ](func () dbft.PrepareRequest [crypto.Uint256 , crypto.Uint160 ] {
464+ opts = append (opts , dbft.WithNewPrepareRequest [crypto.Uint256 , crypto.Uint160 ](func (uint64 , uint64 , crypto. Uint160 , []crypto. Uint256 ) dbft.PrepareRequest [crypto.Uint256 , crypto.Uint160 ] {
466465 return nil
467466 }))
468467 t .Run ("without NewPrepareResponse" , func (t * testing.T ) {
469468 require .Nil (t , dbft .New (opts ... ))
470469 })
471470
472- opts = append (opts , dbft.WithNewPrepareResponse [crypto.Uint256 , crypto.Uint160 ](func () dbft.PrepareResponse [crypto.Uint256 ] {
471+ opts = append (opts , dbft.WithNewPrepareResponse [crypto.Uint256 , crypto.Uint160 ](func (crypto. Uint256 ) dbft.PrepareResponse [crypto.Uint256 ] {
473472 return nil
474473 }))
475474 t .Run ("without NewChangeView" , func (t * testing.T ) {
476475 require .Nil (t , dbft .New (opts ... ))
477476 })
478477
479- opts = append (opts , dbft.WithNewChangeView [crypto.Uint256 , crypto.Uint160 ](func () dbft.ChangeView {
478+ opts = append (opts , dbft.WithNewChangeView [crypto.Uint256 , crypto.Uint160 ](func (byte , dbft. ChangeViewReason , uint64 ) dbft.ChangeView {
480479 return nil
481480 }))
482481 t .Run ("without NewCommit" , func (t * testing.T ) {
483482 require .Nil (t , dbft .New (opts ... ))
484483 })
485484
486- opts = append (opts , dbft.WithNewCommit [crypto.Uint256 , crypto.Uint160 ](func () dbft.Commit {
485+ opts = append (opts , dbft.WithNewCommit [crypto.Uint256 , crypto.Uint160 ](func ([] byte ) dbft.Commit {
487486 return nil
488487 }))
489488 t .Run ("without NewRecoveryRequest" , func (t * testing.T ) {
490489 require .Nil (t , dbft .New (opts ... ))
491490 })
492491
493- opts = append (opts , dbft.WithNewRecoveryRequest [crypto.Uint256 , crypto.Uint160 ](func () dbft.RecoveryRequest {
492+ opts = append (opts , dbft.WithNewRecoveryRequest [crypto.Uint256 , crypto.Uint160 ](func (uint64 ) dbft.RecoveryRequest {
494493 return nil
495494 }))
496495 t .Run ("without NewRecoveryMessage" , func (t * testing.T ) {
@@ -732,63 +731,38 @@ func TestDBFT_FourGoodNodesDeadlock(t *testing.T) {
732731}
733732
734733func (s testState ) getChangeView (from uint16 , view byte ) Payload {
735- cv := payload .NewChangeView ()
736- cv .SetNewViewNumber (view )
737-
738- p := s .getPayload (from )
739- p .SetType (dbft .ChangeViewType )
740- p .SetPayload (cv )
734+ cv := payload .NewChangeView (view , 0 , 0 )
741735
736+ p := payload .NewConsensusPayload (dbft .ChangeViewType , s .currHeight + 1 , from , 0 , cv )
742737 return p
743738}
744739
745740func (s testState ) getRecoveryRequest (from uint16 ) Payload {
746- p := s .getPayload (from )
747- p .SetType (dbft .RecoveryRequestType )
748- p .SetPayload (payload .NewRecoveryRequest ())
749-
741+ p := payload .NewConsensusPayload (dbft .RecoveryRequestType , s .currHeight + 1 , from , 0 , payload .NewRecoveryRequest (0 ))
750742 return p
751743}
752744
753745func (s testState ) getCommit (from uint16 , sign []byte ) Payload {
754- c := payload .NewCommit ()
755- c .SetSignature (sign )
756-
757- p := s .getPayload (from )
758- p .SetType (dbft .CommitType )
759- p .SetPayload (c )
760-
746+ c := payload .NewCommit (sign )
747+ p := payload .NewConsensusPayload (dbft .CommitType , s .currHeight + 1 , from , 0 , c )
761748 return p
762749}
763750
764751func (s testState ) getPrepareResponse (from uint16 , phash crypto.Uint256 ) Payload {
765- resp := payload .NewPrepareResponse ()
766- resp .SetPreparationHash (phash )
767-
768- p := s .getPayload (from )
769- p .SetType (dbft .PrepareResponseType )
770- p .SetPayload (resp )
752+ resp := payload .NewPrepareResponse (phash )
771753
754+ p := payload .NewConsensusPayload (dbft .PrepareResponseType , s .currHeight + 1 , from , 0 , resp )
772755 return p
773756}
774757
775758func (s testState ) getPrepareRequest (from uint16 , hashes ... crypto.Uint256 ) Payload {
776- req := payload .NewPrepareRequest ()
777- req .SetTransactionHashes (hashes )
778- req .SetNextConsensus (s .nextConsensus ())
779-
780- p := s .getPayload (from )
781- p .SetType (dbft .PrepareRequestType )
782- p .SetPayload (req )
783-
784- return p
759+ return s .getPrepareRequestWithHeight (from , s .currHeight + 1 , hashes ... )
785760}
786761
787- func (s testState ) getPayload (from uint16 ) Payload {
788- p := payload .NewConsensusPayload ()
789- p .SetHeight (s .currHeight + 1 )
790- p .SetValidatorIndex (from )
762+ func (s testState ) getPrepareRequestWithHeight (from uint16 , height uint32 , hashes ... crypto.Uint256 ) Payload {
763+ req := payload .NewPrepareRequest (0 , 0 , s .nextConsensus (), hashes )
791764
765+ p := payload .NewConsensusPayload (dbft .PrepareRequestType , height , from , 0 , req )
792766 return p
793767}
794768
@@ -867,7 +841,9 @@ func (s *testState) getOptions() []func(*dbft.Config[crypto.Uint256, crypto.Uint
867841 dbft.WithNewChangeView [crypto.Uint256 , crypto.Uint160 ](payload .NewChangeView ),
868842 dbft.WithNewCommit [crypto.Uint256 , crypto.Uint160 ](payload .NewCommit ),
869843 dbft.WithNewRecoveryRequest [crypto.Uint256 , crypto.Uint160 ](payload .NewRecoveryRequest ),
870- dbft.WithNewRecoveryMessage [crypto.Uint256 , crypto.Uint160 ](payload .NewRecoveryMessage ),
844+ dbft.WithNewRecoveryMessage [crypto.Uint256 , crypto.Uint160 ](func () dbft.RecoveryMessage [crypto.Uint256 , crypto.Uint160 ] {
845+ return payload .NewRecoveryMessage (nil )
846+ }),
871847 }
872848
873849 verify := s .verify
@@ -898,13 +874,7 @@ func newBlockFromContext(ctx *dbft.Context[crypto.Uint256, crypto.Uint160]) dbft
898874// newConsensusPayload is a function for creating consensus payload of specific
899875// type.
900876func newConsensusPayload (c * dbft.Context [crypto.Uint256 , crypto.Uint160 ], t dbft.MessageType , msg any ) dbft.ConsensusPayload [crypto.Uint256 , crypto.Uint160 ] {
901- cp := payload .NewConsensusPayload ()
902- cp .SetHeight (c .BlockIndex )
903- cp .SetValidatorIndex (uint16 (c .MyIndex ))
904- cp .SetViewNumber (c .ViewNumber )
905- cp .SetType (t )
906- cp .SetPayload (msg )
907-
877+ cp := payload .NewConsensusPayload (t , c .BlockIndex , uint16 (c .MyIndex ), c .ViewNumber , msg )
908878 return cp
909879}
910880
0 commit comments