diff --git a/.Lib9c.Tests/Action/BattleArenaTest.cs b/.Lib9c.Tests/Action/BattleArenaTest.cs index 693a0a42c2..f331236e25 100644 --- a/.Lib9c.Tests/Action/BattleArenaTest.cs +++ b/.Lib9c.Tests/Action/BattleArenaTest.cs @@ -1037,6 +1037,37 @@ public void Execute_ValidateDuplicateTicketPurchaseException() })); } + [Theory] + [InlineData(8, null)] + [InlineData(100, null)] + [InlineData(0, typeof(ArgumentException))] + [InlineData(-1, typeof(ArgumentException))] + public void PlainValue(int ticket, Type exc) + { + BattleArena action = new BattleArena + { + myAvatarAddress = _avatar1Address, + enemyAvatarAddress = _avatar2Address, + championshipId = 1, + round = 1, + ticket = ticket, + costumes = new List(), + equipments = new List(), + runeInfos = new List(), + }; + IValue plainValue = action.PlainValue; + BattleArena des = new BattleArena(); + if (exc is null) + { + des.LoadPlainValue(plainValue); + Assert.Equal(plainValue, des.PlainValue); + } + else + { + Assert.Throws(exc, () => des.LoadPlainValue(plainValue)); + } + } + private static (AgentState AgentState, AvatarState AvatarState) GetAgentStateWithAvatarState( IReadOnlyDictionary sheets, TableSheets tableSheets, diff --git a/Lib9c.Policy/NCStagePolicy.cs b/Lib9c.Policy/NCStagePolicy.cs index 0a6c181703..b10bea1630 100644 --- a/Lib9c.Policy/NCStagePolicy.cs +++ b/Lib9c.Policy/NCStagePolicy.cs @@ -88,29 +88,39 @@ public IEnumerable Iterate(BlockChain blockChain, bool filtered = t public bool Stage(BlockChain blockChain, Transaction transaction) { - if (_accessControlService?.GetTxQuota(transaction.Signer) is { } acsTxQuota) + try { - _quotaPerSignerList[transaction.Signer] = acsTxQuota; + if (_accessControlService?.GetTxQuota(transaction.Signer) is { } acsTxQuota) + { + _quotaPerSignerList[transaction.Signer] = acsTxQuota; + + if (acsTxQuota == 0) + { + return false; + } + } - if (acsTxQuota == 0) + var deniedTxs = new[] + { + // CreatePledge Transaction with 50000 addresses + TxId.FromHex( + "300826da62b595d8cd663dadf04995a7411534d1cdc17dac75ce88754472f774"), + // CreatePledge Transaction with 5000 addresses + TxId.FromHex( + "210d1374d8f068de657de6b991e63888da9cadbc68e505ac917b35568b5340f8"), + }; + if (deniedTxs.Contains(transaction.Id)) { return false; } - } - var deniedTxs = new[] - { - // CreatePledge Transaction with 50000 addresses - TxId.FromHex("300826da62b595d8cd663dadf04995a7411534d1cdc17dac75ce88754472f774"), - // CreatePledge Transaction with 5000 addresses - TxId.FromHex("210d1374d8f068de657de6b991e63888da9cadbc68e505ac917b35568b5340f8"), - }; - if (deniedTxs.Contains(transaction.Id)) + return _impl.Stage(blockChain, transaction); + } + catch (Exception ex) { - return false; + Console.WriteLine("[NCStagePolicy-ACS] {0} {1}", ex.Message, ex.StackTrace); + return _impl.Stage(blockChain, transaction); } - - return _impl.Stage(blockChain, transaction); } public bool Unstage(BlockChain blockChain, TxId id) diff --git a/Lib9c/Action/BattleArena.cs b/Lib9c/Action/BattleArena.cs index 11f7d2fe51..f4b5fc6970 100644 --- a/Lib9c/Action/BattleArena.cs +++ b/Lib9c/Action/BattleArena.cs @@ -83,14 +83,16 @@ protected override void LoadPlainValueInternal( championshipId = plainValue[ChampionshipIdKey].ToInteger(); round = plainValue[RoundKey].ToInteger(); ticket = plainValue[TicketKey].ToInteger(); - costumes = ((List)plainValue[CostumesKey]).Select(e => e.ToGuid()).ToList(); - equipments = ((List)plainValue[EquipmentsKey]).Select(e => e.ToGuid()).ToList(); - runeInfos = plainValue[RuneInfos].ToList(x => new RuneSlotInfo((List)x)); + costumes = ((List) plainValue[CostumesKey]).Select(e => e.ToGuid()).ToList(); + equipments = ((List) plainValue[EquipmentsKey]).Select(e => e.ToGuid()).ToList(); + runeInfos = plainValue[RuneInfos].ToList(x => new RuneSlotInfo((List) x)); + ValidateTicket(); } public override IAccount Execute(IActionContext context) { context.UseGas(1); + ValidateTicket(); var states = context.PreviousState; var addressesHex = GetSignerAndOtherAddressesHex( context, @@ -446,5 +448,13 @@ public override IAccount Execute(IActionContext context) myAvatarAddress.Derive(LegacyInventoryKey), avatarState.inventory.Serialize()); } + + private void ValidateTicket() + { + if (ticket <= 0) + { + throw new ArgumentException("ticket must be greater than 0"); + } + } } }