@@ -188,8 +188,7 @@ type validatorRange struct {
188188
189189// createSnowCtx creates a snow.Context instance with a validator state specified by the given validatorRanges 
190190func  createSnowCtx (tb  testing.TB , validatorRanges  []validatorRange ) * snow.Context  {
191- 	getValidatorsOutput  :=  make (map [ids.NodeID ]* validators.GetValidatorOutput )
192- 
191+ 	validatorSet  :=  make (map [ids.NodeID ]* validators.GetValidatorOutput )
193192	for  _ , validatorRange  :=  range  validatorRanges  {
194193		for  i  :=  validatorRange .start ; i  <  validatorRange .end ; i ++  {
195194			validatorOutput  :=  & validators.GetValidatorOutput {
@@ -199,20 +198,19 @@ func createSnowCtx(tb testing.TB, validatorRanges []validatorRange) *snow.Contex
199198			if  validatorRange .publicKey  {
200199				validatorOutput .PublicKey  =  testVdrs [i ].vdr .PublicKey 
201200			}
202- 			getValidatorsOutput [testVdrs [i ].nodeID ] =  validatorOutput 
201+ 			validatorSet [testVdrs [i ].nodeID ] =  validatorOutput 
203202		}
204203	}
205204
206205	snowCtx  :=  snowtest .Context (tb , snowtest .CChainID )
207- 	state   : =  & validatorstest.State {
206+ 	snowCtx . ValidatorState   =  & validatorstest.State {
208207		GetSubnetIDF : func (context.Context , ids.ID ) (ids.ID , error ) {
209208			return  sourceSubnetID , nil 
210209		},
211- 		GetValidatorSetF : func (context.Context , uint64 , ids.ID ) (map [ids. NodeID ] * validators.GetValidatorOutput , error ) {
212- 			return  getValidatorsOutput ,  nil 
210+ 		GetWarpValidatorSetF : func (context.Context , uint64 , ids.ID ) (validators.WarpSet , error ) {
211+ 			return  validators . FlattenValidatorSet ( validatorSet ) 
213212		},
214213	}
215- 	snowCtx .ValidatorState  =  state 
216214	return  snowCtx 
217215}
218216
@@ -247,20 +245,29 @@ func testWarpMessageFromPrimaryNetwork(t *testing.T, requirePrimaryNetworkSigner
247245	unsignedMsg , err  :=  avalancheWarp .NewUnsignedMessage (constants .UnitTestID , cChainID , addressedCall .Bytes ())
248246	require .NoError (err )
249247
250- 	getValidatorsOutput  :=  make (map [ids.NodeID ]* validators.GetValidatorOutput )
251- 	blsSignatures  :=  make ([]* bls.Signature , 0 , numKeys )
248+ 	var  (
249+ 		warpValidators  =  validators.WarpSet {
250+ 			Validators :  make ([]* validators.Warp , 0 , numKeys ),
251+ 			TotalWeight : 20  *  uint64 (numKeys ),
252+ 		}
253+ 		blsSignatures  =  make ([]* bls.Signature , 0 , numKeys )
254+ 	)
252255	for  i  :=  0 ; i  <  numKeys ; i ++  {
253- 		sig , err  :=  testVdrs [i ].sk .Sign (unsignedMsg .Bytes ())
256+ 		vdr  :=  testVdrs [i ]
257+ 		sig , err  :=  vdr .sk .Sign (unsignedMsg .Bytes ())
254258		require .NoError (err )
255- 
256- 		validatorOutput  :=  & validators.GetValidatorOutput {
257- 			NodeID :    testVdrs [i ].nodeID ,
258- 			Weight :    20 ,
259- 			PublicKey : testVdrs [i ].vdr .PublicKey ,
260- 		}
261- 		getValidatorsOutput [testVdrs [i ].nodeID ] =  validatorOutput 
262259		blsSignatures  =  append (blsSignatures , sig )
260+ 
261+ 		pk  :=  vdr .sk .PublicKey ()
262+ 		warpValidators .Validators  =  append (warpValidators .Validators , & validators.Warp {
263+ 			PublicKey :      pk ,
264+ 			PublicKeyBytes : bls .PublicKeyToUncompressedBytes (pk ),
265+ 			Weight :         20 ,
266+ 			NodeIDs :        []ids.NodeID {vdr .nodeID },
267+ 		})
263268	}
269+ 	agoUtils .Sort (warpValidators .Validators )
270+ 
264271	aggregateSignature , err  :=  bls .AggregateSignatures (blsSignatures )
265272	require .NoError (err )
266273	bitSet  :=  set .NewBits ()
@@ -284,13 +291,13 @@ func testWarpMessageFromPrimaryNetwork(t *testing.T, requirePrimaryNetworkSigner
284291			require .Equal (chainID , cChainID )
285292			return  constants .PrimaryNetworkID , nil  // Return Primary Network SubnetID 
286293		},
287- 		GetValidatorSetF : func (_  context.Context , _  uint64 , subnetID  ids.ID ) (map [ids. NodeID ] * validators.GetValidatorOutput , error ) {
294+ 		GetWarpValidatorSetF : func (_  context.Context , _  uint64 , subnetID  ids.ID ) (validators.WarpSet , error ) {
288295			expectedSubnetID  :=  snowCtx .SubnetID 
289296			if  requirePrimaryNetworkSigners  {
290297				expectedSubnetID  =  constants .PrimaryNetworkID 
291298			}
292299			require .Equal (expectedSubnetID , subnetID )
293- 			return  getValidatorsOutput , nil 
300+ 			return  warpValidators , nil 
294301		},
295302	}
296303
@@ -717,25 +724,26 @@ func makeWarpPredicateTests(tb testing.TB) map[string]precompiletest.PredicateTe
717724		testName  :=  fmt .Sprintf ("%d validators w/ %d signers/repeated PublicKeys" , totalNodes , numSigners )
718725
719726		pred  :=  createPredicate (numSigners )
720- 		getValidatorsOutput  :=  make (map [ids.NodeID ]* validators.GetValidatorOutput , totalNodes )
727+ 		validatorSet  :=  make (map [ids.NodeID ]* validators.GetValidatorOutput , totalNodes )
721728		for  i  :=  0 ; i  <  totalNodes ; i ++  {
722- 			getValidatorsOutput [testVdrs [i ].nodeID ] =  & validators.GetValidatorOutput {
729+ 			validatorSet [testVdrs [i ].nodeID ] =  & validators.GetValidatorOutput {
723730				NodeID :    testVdrs [i ].nodeID ,
724731				Weight :    20 ,
725732				PublicKey : testVdrs [i % numSigners ].vdr .PublicKey ,
726733			}
727734		}
735+ 		warpValidators , err  :=  validators .FlattenValidatorSet (validatorSet )
736+ 		require .NoError (tb , err )
728737
729738		snowCtx  :=  snowtest .Context (tb , snowtest .CChainID )
730- 		state   : =  & validatorstest.State {
739+ 		snowCtx . ValidatorState   =  & validatorstest.State {
731740			GetSubnetIDF : func (context.Context , ids.ID ) (ids.ID , error ) {
732741				return  sourceSubnetID , nil 
733742			},
734- 			GetValidatorSetF : func (context.Context , uint64 , ids.ID ) (map [ids. NodeID ] * validators.GetValidatorOutput , error ) {
735- 				return  getValidatorsOutput , nil 
743+ 			GetWarpValidatorSetF : func (context.Context , uint64 , ids.ID ) (validators.WarpSet , error ) {
744+ 				return  warpValidators , nil 
736745			},
737746		}
738- 		snowCtx .ValidatorState  =  state 
739747
740748		predicateTests [testName ] =  createValidPredicateTest (snowCtx , uint64 (numSigners ), pred )
741749	}
0 commit comments