@@ -262,13 +262,71 @@ func TestClaimDepositNilAggregate(t *testing.T) {
262262 sdkCtx := sdk .UnwrapSDKContext (ctx )
263263 k .SetValsetCheckpointDomainSeparator (sdkCtx )
264264
265- queryId , _ := k .GetDepositQueryId (0 )
265+ queryIdV2 , _ := k .GetDepositQueryId (0 )
266+ queryIdV1 , _ := k .GetDepositQueryIdByType (0 , "TRBBridge" )
266267 currentTime := time .Now ()
267- ok .On ("GetAggregateByTimestamp" , sdkCtx , queryId , uint64 (currentTime .UnixMilli ())).Return (oracletypes.Aggregate {}, collections .ErrNotFound )
268+ ok .On ("GetAggregateByTimestamp" , sdkCtx , queryIdV2 , uint64 (currentTime .UnixMilli ())).Return (oracletypes.Aggregate {}, collections .ErrNotFound )
269+ ok .On ("GetAggregateByTimestamp" , sdkCtx , queryIdV1 , uint64 (currentTime .UnixMilli ())).Return (oracletypes.Aggregate {}, collections .ErrNotFound )
268270 err := k .ClaimDeposit (ctx , 0 , uint64 (currentTime .UnixMilli ()))
269271 require .ErrorContains (t , err , "not found" )
270272}
271273
274+ func TestClaimDepositFallsBackToLegacyTRBBridgeQueryId (t * testing.T ) {
275+ k , _ , bk , ok , _ , _ , _ , ctx := setupKeeper (t )
276+ require .NotNil (t , k )
277+ require .NotNil (t , ctx )
278+ sdkCtx := sdk .UnwrapSDKContext (ctx )
279+ k .SetValsetCheckpointDomainSeparator (sdkCtx )
280+
281+ aggregateTimestamp := sdkCtx .BlockTime ()
282+ AddressType , err := abi .NewType ("address" , "" , nil )
283+ require .NoError (t , err )
284+ Uint256Type , err := abi .NewType ("uint256" , "" , nil )
285+ require .NoError (t , err )
286+ StringType , err := abi .NewType ("string" , "" , nil )
287+ require .NoError (t , err )
288+ reportValueArgs := abi.Arguments {
289+ {Type : AddressType },
290+ {Type : StringType },
291+ {Type : Uint256Type },
292+ }
293+ ethAddress := common .HexToAddress ("0x3386518F7ab3eb51591571adBE62CF94540EAd29" )
294+ layerAddressString := simtestutil .CreateIncrementalAccounts (1 )[0 ].String ()
295+ amountUint64 := big .NewInt (100 * 1e12 )
296+ reportValueArgsEncoded , err := reportValueArgs .Pack (ethAddress , layerAddressString , amountUint64 )
297+ require .NoError (t , err )
298+ reportValueString := hex .EncodeToString (reportValueArgsEncoded )
299+
300+ queryIdV2 , err := k .GetDepositQueryId (0 )
301+ require .NoError (t , err )
302+ queryIdV1 , err := k .GetDepositQueryIdByType (0 , "TRBBridge" )
303+ require .NoError (t , err )
304+
305+ aggregate := oracletypes.Aggregate {
306+ QueryId : queryIdV1 ,
307+ AggregateValue : reportValueString ,
308+ AggregatePower : uint64 (68 ),
309+ }
310+ powerThreshold := uint64 (67 )
311+ validatorTimestamp := uint64 (aggregateTimestamp .UnixMilli () - 1 )
312+ valSetHash := []byte ("valSetHash" )
313+ _ , err = k .CalculateValidatorSetCheckpoint (ctx , powerThreshold , validatorTimestamp , valSetHash )
314+ require .NoError (t , err )
315+
316+ sdkCtx = sdkCtx .WithBlockTime (sdkCtx .BlockTime ().Add (13 * time .Hour ))
317+ recipient , amount , _ , err := k .DecodeDepositReportValue (ctx , reportValueString )
318+ require .NoError (t , err )
319+
320+ // First lookup (V2) misses, second lookup (legacy V1) succeeds.
321+ ok .On ("GetAggregateByTimestamp" , sdkCtx , queryIdV2 , uint64 (aggregateTimestamp .UnixMilli ())).Return (oracletypes.Aggregate {}, collections .ErrNotFound )
322+ ok .On ("GetAggregateByTimestamp" , sdkCtx , queryIdV1 , uint64 (aggregateTimestamp .UnixMilli ())).Return (aggregate , nil )
323+ bk .On ("MintCoins" , sdkCtx , bridgetypes .ModuleName , amount ).Return (nil )
324+ bk .On ("SendCoinsFromModuleToAccount" , sdkCtx , bridgetypes .ModuleName , recipient , amount ).Return (nil )
325+
326+ err = k .ClaimDeposit (sdkCtx , 0 , uint64 (aggregateTimestamp .UnixMilli ()))
327+ require .NoError (t , err )
328+ }
329+
272330func TestClaimDepositFlaggedAggregate (t * testing.T ) {
273331 k , _ , bk , ok , rk , _ , _ , ctx := setupKeeper (t )
274332 require .NotNil (t , k )
0 commit comments