File tree Expand file tree Collapse file tree 2 files changed +44
-3
lines changed
Expand file tree Collapse file tree 2 files changed +44
-3
lines changed Original file line number Diff line number Diff line change @@ -1037,6 +1037,37 @@ public void Execute_ValidateDuplicateTicketPurchaseException()
10371037 } ) ) ;
10381038 }
10391039
1040+ [ Theory ]
1041+ [ InlineData ( 8 , null ) ]
1042+ [ InlineData ( 100 , null ) ]
1043+ [ InlineData ( 0 , typeof ( ArgumentException ) ) ]
1044+ [ InlineData ( - 1 , typeof ( ArgumentException ) ) ]
1045+ public void PlainValue ( int ticket , Type exc )
1046+ {
1047+ BattleArena action = new BattleArena
1048+ {
1049+ myAvatarAddress = _avatar1Address ,
1050+ enemyAvatarAddress = _avatar2Address ,
1051+ championshipId = 1 ,
1052+ round = 1 ,
1053+ ticket = ticket ,
1054+ costumes = new List < Guid > ( ) ,
1055+ equipments = new List < Guid > ( ) ,
1056+ runeInfos = new List < RuneSlotInfo > ( ) ,
1057+ } ;
1058+ IValue plainValue = action . PlainValue ;
1059+ BattleArena des = new BattleArena ( ) ;
1060+ if ( exc is null )
1061+ {
1062+ des . LoadPlainValue ( plainValue ) ;
1063+ Assert . Equal ( plainValue , des . PlainValue ) ;
1064+ }
1065+ else
1066+ {
1067+ Assert . Throws ( exc , ( ) => des . LoadPlainValue ( plainValue ) ) ;
1068+ }
1069+ }
1070+
10401071 private static ( AgentState AgentState , AvatarState AvatarState ) GetAgentStateWithAvatarState (
10411072 IReadOnlyDictionary < string , string > sheets ,
10421073 TableSheets tableSheets ,
Original file line number Diff line number Diff line change @@ -83,14 +83,16 @@ protected override void LoadPlainValueInternal(
8383 championshipId = plainValue [ ChampionshipIdKey ] . ToInteger ( ) ;
8484 round = plainValue [ RoundKey ] . ToInteger ( ) ;
8585 ticket = plainValue [ TicketKey ] . ToInteger ( ) ;
86- costumes = ( ( List ) plainValue [ CostumesKey ] ) . Select ( e => e . ToGuid ( ) ) . ToList ( ) ;
87- equipments = ( ( List ) plainValue [ EquipmentsKey ] ) . Select ( e => e . ToGuid ( ) ) . ToList ( ) ;
88- runeInfos = plainValue [ RuneInfos ] . ToList ( x => new RuneSlotInfo ( ( List ) x ) ) ;
86+ costumes = ( ( List ) plainValue [ CostumesKey ] ) . Select ( e => e . ToGuid ( ) ) . ToList ( ) ;
87+ equipments = ( ( List ) plainValue [ EquipmentsKey ] ) . Select ( e => e . ToGuid ( ) ) . ToList ( ) ;
88+ runeInfos = plainValue [ RuneInfos ] . ToList ( x => new RuneSlotInfo ( ( List ) x ) ) ;
89+ ValidateTicket ( ) ;
8990 }
9091
9192 public override IAccount Execute ( IActionContext context )
9293 {
9394 context . UseGas ( 1 ) ;
95+ ValidateTicket ( ) ;
9496 var states = context . PreviousState ;
9597 var addressesHex = GetSignerAndOtherAddressesHex (
9698 context ,
@@ -446,5 +448,13 @@ public override IAccount Execute(IActionContext context)
446448 myAvatarAddress . Derive ( LegacyInventoryKey ) ,
447449 avatarState . inventory . Serialize ( ) ) ;
448450 }
451+
452+ private void ValidateTicket ( )
453+ {
454+ if ( ticket <= 0 )
455+ {
456+ throw new ArgumentException ( "ticket must be greater than 0" ) ;
457+ }
458+ }
449459 }
450460}
You can’t perform that action at this time.
0 commit comments