mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2025-12-16 06:20:34 +00:00
Closes #3203
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:
@@ -52,6 +52,30 @@ public sealed class Trading {
|
||||
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]
|
||||
public void MismatchRarityIsNotFair() {
|
||||
HashSet<Asset> itemsToGive = [
|
||||
|
||||
@@ -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
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user