When excessive amount of "missing amounts", so items in the set was missing on our side, there was a possibility for our logic to classify a good trade as bad one, because we didn't fill in enough holes, as the subtraction in the condition was calculated on each loop rather than once initially.

Since this could only worsen the neutrality score, but never improve it (as the amounts were sorted ascending), there was no abusive possibility due to that, only ignoring otherwise valid trades classifying them as worse than they were in reality.
This commit is contained in:
Łukasz Domeradzki
2024-05-13 09:29:30 +02:00
parent b438e38268
commit 3b2ca10b05
2 changed files with 27 additions and 1 deletions

View File

@@ -52,6 +52,30 @@ public sealed class Trading {
Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
} }
[TestMethod]
public void Issue3203() {
HashSet<Asset> inventory = [
CreateItem(1, amount: 2),
CreateItem(2, amount: 6),
CreateItem(3),
CreateItem(4)
];
HashSet<Asset> itemsToGive = [
CreateItem(1),
CreateItem(2, amount: 2)
];
HashSet<Asset> itemsToReceive = [
CreateItem(5),
CreateItem(6),
CreateItem(7)
];
Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
}
[TestMethod] [TestMethod]
public void MismatchRarityIsNotFair() { public void MismatchRarityIsNotFair() {
HashSet<Asset> itemsToGive = [ HashSet<Asset> itemsToGive = [

View File

@@ -178,7 +178,9 @@ public sealed class Trading : IDisposable {
} }
// Otherwise, fill the missing holes in our data if needed, since we actually had zeros there // Otherwise, fill the missing holes in our data if needed, since we actually had zeros there
for (byte i = 0; i < afterAmounts.Count - beforeAmounts.Count; i++) { byte missingAmounts = (byte) (afterAmounts.Count - beforeAmounts.Count);
for (byte i = 0; i < missingAmounts; i++) {
beforeAmounts.Insert(0, 0); beforeAmounts.Insert(0, 0);
} }