Skip to content

Commit

Permalink
Merge branch 'development' into chore/add-unity-meta-files
Browse files Browse the repository at this point in the history
  • Loading branch information
boscohyun authored Jan 5, 2024
2 parents 1102c63 + a63821e commit 7dd64a6
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 18 deletions.
31 changes: 31 additions & 0 deletions .Lib9c.Tests/Action/BattleArenaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Guid>(),
equipments = new List<Guid>(),
runeInfos = new List<RuneSlotInfo>(),
};
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<string, string> sheets,
TableSheets tableSheets,
Expand Down
40 changes: 25 additions & 15 deletions Lib9c.Policy/NCStagePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,39 @@ public IEnumerable<Transaction> 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)
Expand Down
16 changes: 13 additions & 3 deletions Lib9c/Action/BattleArena.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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");
}
}
}
}

0 comments on commit 7dd64a6

Please sign in to comment.