File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed
Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change 66
77namespace AElf . Contracts . RandomContract ;
88
9- public class RandomContract : RandomContractContainer . RandomContractBase
9+ public partial class RandomContract : RandomContractContainer . RandomContractBase
1010{
1111 // Initializes the contract
1212 public override Empty Initialize ( InitializeInput input )
@@ -61,6 +61,8 @@ public override Empty GenerateRandomNumber(GenerateRandomNumberInput input)
6161 {
6262 // Check if the random number is already generated
6363 Assert ( State . RandomNumbers [ input . Hash ] == null , "Random number already generated." ) ;
64+ // Check if the hash length is valid
65+ Assert ( input . Hash . Length <= MaxHashLength , "Invalid hash length." ) ;
6466 // Check if the maxValue is valid
6567 Assert ( input . MaxValue > 0 && input . MaxValue <= State . MaxValueLimit . Value , "Invalid max value." ) ;
6668 // Check if the random number count is valid
Original file line number Diff line number Diff line change 1+ namespace AElf . Contracts . RandomContract ;
2+
3+ public partial class RandomContract
4+ {
5+ private const long MaxHashLength = 100 ;
6+ }
Original file line number Diff line number Diff line change @@ -224,6 +224,17 @@ public async Task GenerateRandomNumberTest()
224224 result . TransactionResult . Status . ShouldBe ( TransactionResultStatus . Failed ) ;
225225 result . TransactionResult . Error . ShouldContain ( "Random number already generated" ) ;
226226
227+ var invalidHash = "cdd6b38b763d929355c47fb6f7be5107cdd6b38b763d929355c47fb6f7be5107cdd6b38b763d929355c47fb6f7be510712345" ;
228+ // Generate random number with invalid hash length and expect an exception
229+ result = await RandomContractStub . GenerateRandomNumber . SendWithExceptionAsync ( new GenerateRandomNumberInput
230+ {
231+ Hash = invalidHash ,
232+ RandomNumberCount = randomNumberCount ,
233+ MaxValue = maxValue
234+ } ) ;
235+ result . TransactionResult . Status . ShouldBe ( TransactionResultStatus . Failed ) ;
236+ result . TransactionResult . Error . ShouldContain ( "Invalid hash length" ) ;
237+
227238 hash = "OtherHash" ;
228239 // Generate random number with invalid max value and expect an exception
229240 result = await RandomContractStub . GenerateRandomNumber . SendWithExceptionAsync ( new GenerateRandomNumberInput
You can’t perform that action at this time.
0 commit comments