Files
ArchiSteamFarm/ArchiSteamFarm.Tests/Trading.cs

393 lines
11 KiB
C#
Raw Normal View History

2019-02-16 17:34:17 +01:00
// _ _ _ ____ _ _____
2017-11-18 17:27:06 +01:00
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
2019-01-14 19:11:17 +01:00
// |
// Copyright 2015-2021 Łukasz "JustArchi" Domeradzki
2018-07-27 04:52:14 +02:00
// Contact: JustArchi@JustArchi.net
2019-01-14 19:11:17 +01:00
// |
2018-07-27 04:52:14 +02:00
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
2019-01-14 19:11:17 +01:00
// |
2018-07-27 04:52:14 +02:00
// http://www.apache.org/licenses/LICENSE-2.0
2019-01-14 19:11:17 +01:00
// |
2018-07-27 04:52:14 +02:00
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2017-07-10 08:52:59 +02:00
using System.Collections.Generic;
using ArchiSteamFarm.Steam.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static ArchiSteamFarm.Steam.Exchange.Trading;
namespace ArchiSteamFarm.Tests {
[TestClass]
public sealed class Trading {
2019-02-02 22:54:23 +01:00
[TestMethod]
public void MismatchRarityIsNotFair() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToGive = new() { CreateItem(1, rarity: Asset.ERarity.Rare) };
HashSet<Asset> itemsToReceive = new() { CreateItem(2) };
2019-02-02 22:54:23 +01:00
Assert.IsFalse(IsFairExchange(itemsToGive, itemsToReceive));
}
[TestMethod]
public void MismatchRealAppIDsIsNotFair() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToGive = new() { CreateItem(1, realAppID: 570) };
HashSet<Asset> itemsToReceive = new() { CreateItem(2) };
2019-02-02 22:54:23 +01:00
Assert.IsFalse(IsFairExchange(itemsToGive, itemsToReceive));
}
[TestMethod]
public void MismatchTypesIsNotFair() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToGive = new() { CreateItem(1, type: Asset.EType.Emoticon) };
HashSet<Asset> itemsToReceive = new() { CreateItem(2) };
2019-02-02 22:54:23 +01:00
Assert.IsFalse(IsFairExchange(itemsToGive, itemsToReceive));
}
[TestMethod]
2017-09-27 04:19:10 +02:00
public void MultiGameMultiTypeBadReject() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> inventory = new() {
CreateItem(1, 9),
2021-05-06 20:16:06 +02:00
CreateItem(3, 9, 730, Asset.EType.Emoticon),
CreateItem(4, realAppID: 730, type: Asset.EType.Emoticon)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToGive = new() {
2018-10-05 04:26:57 +02:00
CreateItem(1),
2021-05-06 20:16:06 +02:00
CreateItem(4, realAppID: 730, type: Asset.EType.Emoticon)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToReceive = new() {
2018-10-05 04:26:57 +02:00
CreateItem(2),
2021-05-06 20:16:06 +02:00
CreateItem(3, realAppID: 730, type: Asset.EType.Emoticon)
2018-09-08 00:46:40 +02:00
};
2019-02-02 22:54:23 +01:00
Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
2019-01-26 18:14:07 +01:00
Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
}
[TestMethod]
2017-09-27 04:19:10 +02:00
public void MultiGameMultiTypeNeutralAccept() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> inventory = new() {
CreateItem(1, 9),
2021-05-06 20:16:06 +02:00
CreateItem(3, realAppID: 730, type: Asset.EType.Emoticon)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToGive = new() {
2018-10-05 04:26:57 +02:00
CreateItem(1),
2021-05-06 20:16:06 +02:00
CreateItem(3, realAppID: 730, type: Asset.EType.Emoticon)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToReceive = new() {
2018-10-05 04:26:57 +02:00
CreateItem(2),
2021-05-06 20:16:06 +02:00
CreateItem(4, realAppID: 730, type: Asset.EType.Emoticon)
2018-09-08 00:46:40 +02:00
};
2019-02-02 22:54:23 +01:00
Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
2019-01-26 18:14:07 +01:00
Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
}
[TestMethod]
2017-09-27 04:19:10 +02:00
public void MultiGameSingleTypeBadReject() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> inventory = new() {
CreateItem(1, 9),
2018-10-05 04:26:57 +02:00
CreateItem(3, realAppID: 730),
CreateItem(4, realAppID: 730)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToGive = new() {
2018-10-05 04:26:57 +02:00
CreateItem(1),
CreateItem(3, realAppID: 730)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToReceive = new() {
2018-10-05 04:26:57 +02:00
CreateItem(2),
CreateItem(4, realAppID: 730)
2018-09-08 00:46:40 +02:00
};
2019-02-02 22:54:23 +01:00
Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
2019-01-26 18:14:07 +01:00
Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
}
[TestMethod]
2017-09-27 04:19:10 +02:00
public void MultiGameSingleTypeNeutralAccept() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> inventory = new() {
CreateItem(1, 2),
2018-10-05 04:26:57 +02:00
CreateItem(3, realAppID: 730)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToGive = new() {
2018-10-05 04:26:57 +02:00
CreateItem(1),
CreateItem(3, realAppID: 730)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToReceive = new() {
2018-10-05 04:26:57 +02:00
CreateItem(2),
CreateItem(4, realAppID: 730)
2018-09-08 00:46:40 +02:00
};
2019-02-02 22:54:23 +01:00
Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
2019-01-26 18:14:07 +01:00
Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
}
2020-08-11 11:34:32 +02:00
[TestMethod]
public void SingleGameAbrynosWasWrongNeutralAccept() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> inventory = new() {
2020-08-11 11:34:32 +02:00
CreateItem(1),
CreateItem(2, 2),
CreateItem(3),
CreateItem(4),
CreateItem(5)
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToGive = new() {
2020-08-11 11:34:32 +02:00
CreateItem(2)
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToReceive = new() {
2020-08-11 11:34:32 +02:00
CreateItem(3)
};
Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
}
2019-01-26 18:14:07 +01:00
[TestMethod]
public void SingleGameDonationAccept() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> inventory = new() {
2019-01-26 18:14:07 +01:00
CreateItem(1)
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToGive = new() {
2019-01-26 18:14:07 +01:00
CreateItem(1)
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToReceive = new() {
2019-01-26 18:14:07 +01:00
CreateItem(2),
2021-05-06 20:16:06 +02:00
CreateItem(3, type: Asset.EType.SteamGems)
2019-01-26 18:14:07 +01:00
};
2019-02-02 22:54:23 +01:00
Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
2019-01-26 18:14:07 +01:00
Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
}
[TestMethod]
2017-09-27 04:19:10 +02:00
public void SingleGameMultiTypeBadReject() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> inventory = new() {
CreateItem(1, 9),
2021-05-06 20:16:06 +02:00
CreateItem(3, 9, type: Asset.EType.Emoticon),
CreateItem(4, type: Asset.EType.Emoticon)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToGive = new() {
2018-10-05 04:26:57 +02:00
CreateItem(1),
2021-05-06 20:16:06 +02:00
CreateItem(4, type: Asset.EType.Emoticon)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToReceive = new() {
2018-10-05 04:26:57 +02:00
CreateItem(2),
2021-05-06 20:16:06 +02:00
CreateItem(3, type: Asset.EType.Emoticon)
2018-09-08 00:46:40 +02:00
};
2019-02-02 22:54:23 +01:00
Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
2019-01-26 18:14:07 +01:00
Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
}
[TestMethod]
2017-09-27 04:19:10 +02:00
public void SingleGameMultiTypeNeutralAccept() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> inventory = new() {
CreateItem(1, 9),
2021-05-06 20:16:06 +02:00
CreateItem(3, type: Asset.EType.Emoticon)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToGive = new() {
2018-10-05 04:26:57 +02:00
CreateItem(1),
2021-05-06 20:16:06 +02:00
CreateItem(3, type: Asset.EType.Emoticon)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToReceive = new() {
2018-10-05 04:26:57 +02:00
CreateItem(2),
2021-05-06 20:16:06 +02:00
CreateItem(4, type: Asset.EType.Emoticon)
2018-09-08 00:46:40 +02:00
};
2019-02-02 22:54:23 +01:00
Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
2019-01-26 18:14:07 +01:00
Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
}
[TestMethod]
2017-09-27 04:19:10 +02:00
public void SingleGameQuantityBadReject() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> inventory = new() {
2018-10-05 04:26:57 +02:00
CreateItem(1),
CreateItem(2),
CreateItem(3)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToGive = new() {
2018-10-05 04:26:57 +02:00
CreateItem(1),
CreateItem(2),
CreateItem(3)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToReceive = new() { CreateItem(4, 3) };
2017-09-27 04:19:10 +02:00
2019-02-02 22:54:23 +01:00
Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
2019-01-26 18:14:07 +01:00
Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
2017-09-27 04:19:10 +02:00
}
[TestMethod]
public void SingleGameQuantityBadReject2() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> inventory = new() {
2018-10-05 04:26:57 +02:00
CreateItem(1),
CreateItem(2, 2)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToGive = new() {
2018-10-05 04:26:57 +02:00
CreateItem(1),
CreateItem(2, 2)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToReceive = new() { CreateItem(3, 3) };
2019-02-02 22:54:23 +01:00
Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
2019-01-26 18:14:07 +01:00
Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
}
2017-09-27 04:19:10 +02:00
[TestMethod]
public void SingleGameQuantityNeutralAccept() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> inventory = new() {
CreateItem(1, 2),
2018-10-05 04:26:57 +02:00
CreateItem(2)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToGive = new() {
2018-10-05 04:26:57 +02:00
CreateItem(1),
CreateItem(2)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToReceive = new() { CreateItem(3, 2) };
2017-09-27 04:19:10 +02:00
2019-02-02 22:54:23 +01:00
Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
2019-01-26 18:14:07 +01:00
Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
2017-09-27 04:19:10 +02:00
}
[TestMethod]
public void SingleGameSingleTypeBadReject() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> inventory = new() {
2018-10-05 04:26:57 +02:00
CreateItem(1),
CreateItem(2)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToGive = new() { CreateItem(1) };
HashSet<Asset> itemsToReceive = new() { CreateItem(2) };
2017-09-27 04:19:10 +02:00
2019-02-02 22:54:23 +01:00
Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
2019-01-26 18:14:07 +01:00
Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
2017-09-27 04:19:10 +02:00
}
2018-08-01 23:11:15 +02:00
[TestMethod]
public void SingleGameSingleTypeBadWithOverpayingReject() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> inventory = new() {
CreateItem(1, 2),
CreateItem(2, 2),
CreateItem(3, 2)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToGive = new() { CreateItem(2) };
2018-09-08 00:46:40 +02:00
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToReceive = new() {
2018-10-05 04:26:57 +02:00
CreateItem(1),
CreateItem(3)
2018-09-08 00:46:40 +02:00
};
2018-08-01 23:11:15 +02:00
2019-02-02 22:54:23 +01:00
Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
2019-01-26 18:14:07 +01:00
Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
2018-08-01 23:11:15 +02:00
}
2018-10-05 03:37:49 +02:00
[TestMethod]
public void SingleGameSingleTypeBigDifferenceAccept() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> inventory = new() {
2018-10-05 04:26:57 +02:00
CreateItem(1),
CreateItem(2, 5),
2018-10-05 04:26:57 +02:00
CreateItem(3)
2018-10-05 03:37:49 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToGive = new() { CreateItem(2) };
HashSet<Asset> itemsToReceive = new() { CreateItem(3) };
2018-10-05 03:37:49 +02:00
2019-02-02 22:54:23 +01:00
Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
2019-01-26 18:14:07 +01:00
Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
2018-10-05 03:37:49 +02:00
}
2018-10-05 15:54:22 +02:00
[TestMethod]
public void SingleGameSingleTypeBigDifferenceReject() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> inventory = new() {
2018-10-05 15:54:22 +02:00
CreateItem(1),
CreateItem(2, 2),
CreateItem(3, 2),
CreateItem(4, 3),
CreateItem(5, 10)
2018-10-05 15:54:22 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToGive = new() {
2018-10-05 15:54:22 +02:00
CreateItem(2),
CreateItem(5)
};
2018-12-15 00:27:15 +01:00
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToReceive = new() {
2018-10-05 15:54:22 +02:00
CreateItem(3),
CreateItem(4)
};
2019-02-02 22:54:23 +01:00
Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
2019-01-26 18:14:07 +01:00
Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
2018-10-05 15:54:22 +02:00
}
2017-09-27 04:19:10 +02:00
[TestMethod]
public void SingleGameSingleTypeGoodAccept() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> inventory = new() { CreateItem(1, 2) };
HashSet<Asset> itemsToGive = new() { CreateItem(1) };
HashSet<Asset> itemsToReceive = new() { CreateItem(2) };
2017-09-27 04:19:10 +02:00
2019-02-02 22:54:23 +01:00
Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
2019-01-26 18:14:07 +01:00
Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
2017-09-27 04:19:10 +02:00
}
[TestMethod]
public void SingleGameSingleTypeNeutralAccept() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> inventory = new() { CreateItem(1) };
HashSet<Asset> itemsToGive = new() { CreateItem(1) };
HashSet<Asset> itemsToReceive = new() { CreateItem(2) };
2019-02-02 22:54:23 +01:00
Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
2019-01-26 18:14:07 +01:00
Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
}
2018-08-01 23:11:15 +02:00
[TestMethod]
public void SingleGameSingleTypeNeutralWithOverpayingAccept() {
2021-05-06 20:16:06 +02:00
HashSet<Asset> inventory = new() {
CreateItem(1, 2),
CreateItem(2, 2)
2018-09-08 00:46:40 +02:00
};
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToGive = new() { CreateItem(2) };
2018-09-08 00:46:40 +02:00
2021-05-06 20:16:06 +02:00
HashSet<Asset> itemsToReceive = new() {
2018-10-05 04:26:57 +02:00
CreateItem(1),
CreateItem(3)
2018-09-08 00:46:40 +02:00
};
2018-08-01 23:11:15 +02:00
2019-02-02 22:54:23 +01:00
Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
2019-01-26 18:14:07 +01:00
Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
}
2017-09-27 04:19:10 +02:00
2021-05-06 20:16:06 +02:00
private static Asset CreateItem(ulong classID, uint amount = 1, uint realAppID = Asset.SteamAppID, Asset.EType type = Asset.EType.TradingCard, Asset.ERarity rarity = Asset.ERarity.Common) => new(Asset.SteamAppID, Asset.SteamCommunityContextID, classID, amount, realAppID: realAppID, type: type, rarity: rarity);
}
2018-07-27 04:52:14 +02:00
}