-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
9,182 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
GhostfolioSidekick.UnitTests/FileImporter/Coinbase/CoinbaseParserTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
using AutoFixture; | ||
using FluentAssertions; | ||
using GhostfolioSidekick.FileImporter.Coinbase; | ||
using GhostfolioSidekick.Ghostfolio.API; | ||
using Moq; | ||
|
||
namespace GhostfolioSidekick.UnitTests.FileImporter.Coinbase | ||
{ | ||
public class CoinbaseParserTests | ||
{ | ||
readonly Mock<IGhostfolioAPI> api; | ||
|
||
public CoinbaseParserTests() | ||
{ | ||
api = new Mock<IGhostfolioAPI>(); | ||
} | ||
|
||
[Fact] | ||
public async Task CanConvertOrders_Example1_True() | ||
{ | ||
// Arrange | ||
var parser = new CoinbaseParser(api.Object); | ||
|
||
// Act | ||
var canParse = await parser.CanConvertOrders(new[] { "./FileImporter/TestFiles/Coinbase/Example1/Example1.csv" }); | ||
|
||
// Assert | ||
canParse.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public async Task ConvertToOrders_Example1_Converted() | ||
{ | ||
// Arrange | ||
var parser = new CoinbaseParser(api.Object); | ||
var fixture = new Fixture(); | ||
|
||
var asset1 = fixture.Build<Asset>().With(x => x.Currency, "EUR").Create(); | ||
|
||
var account = fixture.Create<Account>(); | ||
|
||
api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account); | ||
api.Setup(x => x.FindSymbolByISIN("Bitcoin", It.IsAny<Func<IEnumerable<Asset>, Asset>>())).ReturnsAsync(asset1); | ||
|
||
// Act | ||
var orders = await parser.ConvertToOrders(account.Name, new[] { "./FileImporter/TestFiles/Coinbase/Example1/Example1.csv" }); | ||
|
||
// Assert | ||
orders.Should().BeEquivalentTo(new[] | ||
{ | ||
new Order { | ||
AccountId = account.Id, | ||
Asset = asset1, | ||
Comment = "Transaction Reference: [SELL_BTC_638280626190000000]", | ||
Currency = asset1.Currency, | ||
FeeCurrency = asset1.Currency, | ||
Date = new DateTime(2023,08,19,17,23,39, DateTimeKind.Utc), | ||
Fee = 0, | ||
Quantity = 0.00205323M, | ||
Type = OrderType.SELL, | ||
UnitPrice = 24073.28M, | ||
ReferenceCode = "SELL_BTC_638280626190000000" | ||
}}); | ||
} | ||
|
||
[Fact] | ||
public async Task ConvertToOrders_Example2_Converted() | ||
{ | ||
// Arrange | ||
var parser = new CoinbaseParser(api.Object); | ||
var fixture = new Fixture(); | ||
|
||
var asset1 = fixture.Build<Asset>().With(x => x.Currency, "EUR").Create(); | ||
var asset2 = fixture.Build<Asset>().With(x => x.Currency, "EUR").Create(); | ||
var asset3 = fixture.Build<Asset>().With(x => x.Currency, "EUR").Create(); | ||
|
||
var account = fixture.Create<Account>(); | ||
|
||
api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account); | ||
api.Setup(x => x.FindSymbolByISIN("Bitcoin", It.IsAny<Func<IEnumerable<Asset>, Asset>>())).ReturnsAsync(asset1); | ||
api.Setup(x => x.FindSymbolByISIN("Ethereum", It.IsAny<Func<IEnumerable<Asset>, Asset>>())).ReturnsAsync(asset2); | ||
api.Setup(x => x.FindSymbolByISIN("Cosmos", It.IsAny<Func<IEnumerable<Asset>, Asset>>())).ReturnsAsync(asset3); | ||
|
||
// Act | ||
var orders = await parser.ConvertToOrders(account.Name, new[] { "./FileImporter/TestFiles/Coinbase/Example2/Example2.csv" }); | ||
|
||
// Assert | ||
orders.Should().BeEquivalentTo(new[] | ||
{ | ||
new Order { | ||
AccountId = account.Id, | ||
Asset = asset1, // BTC | ||
Comment = "Transaction Reference: [SELL_BTC_638280626190000000]", | ||
Currency = asset1.Currency, | ||
FeeCurrency = asset1.Currency, | ||
Date = new DateTime(2023,08,19,17,23,39, DateTimeKind.Utc), | ||
Fee = 0, | ||
Quantity = 0.00205323M, | ||
Type = OrderType.SELL, | ||
UnitPrice = 24073.28M, | ||
ReferenceCode = "SELL_BTC_638280626190000000" | ||
}, | ||
new Order { | ||
AccountId = account.Id, | ||
Asset = asset2, // ETH | ||
Comment = "Transaction Reference: [BUY_ETH_638175603400000000]", | ||
Currency = asset2.Currency, | ||
FeeCurrency = asset2.Currency, | ||
Date = new DateTime(2023,04,20,4,5,40, DateTimeKind.Utc), | ||
Fee = 0.990000M, | ||
Quantity = 0.00213232M, | ||
Type = OrderType.BUY, | ||
UnitPrice =1810.23M, | ||
ReferenceCode = "BUY_ETH_638175603400000000" | ||
}, | ||
new Order { | ||
AccountId = account.Id, | ||
Asset = asset2, // ETH | ||
Comment = "Transaction Reference: [BUY_ETH_638177414840000000]", | ||
Currency = asset2.Currency, | ||
FeeCurrency = asset2.Currency, | ||
Date = new DateTime(2023,4,22,6,24,44, DateTimeKind.Utc), | ||
Fee = 0, | ||
Quantity = 1.0e-08M, | ||
Type = OrderType.BUY, | ||
UnitPrice =1689.10M, | ||
ReferenceCode = "BUY_ETH_638177414840000000" | ||
}, | ||
new Order { | ||
AccountId = account.Id, | ||
Asset = asset2, // ETH -> ATOM | ||
Comment = "Transaction Reference: [SELL_ETH_638181135820000000]", | ||
Currency = asset2.Currency, | ||
FeeCurrency = asset2.Currency, | ||
Date = new DateTime(2023,04,26,13,46,22, DateTimeKind.Utc), | ||
Fee = 0.020000M, | ||
Quantity = 0.00052203M, | ||
Type = OrderType.SELL, | ||
UnitPrice = 1762.35M, | ||
ReferenceCode = "SELL_ETH_638181135820000000" | ||
}, | ||
new Order { | ||
AccountId = account.Id, | ||
Asset = asset3, // ETH -> ATOM | ||
Comment = "Transaction Reference: [BUY_ATOM_638181135820000000]", | ||
Currency = asset3.Currency, | ||
FeeCurrency = asset3.Currency, | ||
Date = new DateTime(2023,04,26,13,46,22, DateTimeKind.Utc), | ||
Fee = 0, | ||
Quantity = 0.087842M, | ||
Type = OrderType.BUY, | ||
UnitPrice = 10.473344988729764804990778898M, | ||
ReferenceCode = "BUY_ATOM_638181135820000000" | ||
}}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
GhostfolioSidekick.UnitTests/FileImporter/TestFiles/Coinbase/Example1/Example1.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"You can use this transaction report to inform your likely tax obligations. For US customers, Sells, Converts, Rewards Income, Learning Rewards, and Donations are taxable events. For final tax obligations, please consult your tax advisor." | ||
|
||
|
||
|
||
Transactions | ||
User,some@email.com,0000000000000000000000 | ||
|
||
Timestamp,Transaction Type,Asset,Quantity Transacted,Spot Price Currency,Spot Price at Transaction,Subtotal,Total (inclusive of fees and/or spread),Fees and/or Spread,Notes | ||
2023-08-19T17:23:39Z,Sell,BTC,0.00205323,EUR,24073.28,"","","",Sent 0.00205323 BTC to 39ADd6pNpeuwjcweLLS5JiJPFjNPJnf4xY |
12 changes: 12 additions & 0 deletions
12
GhostfolioSidekick.UnitTests/FileImporter/TestFiles/Coinbase/Example2/Example2.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"You can use this transaction report to inform your likely tax obligations. For US customers, Sells, Converts, Rewards Income, Learning Rewards, and Donations are taxable events. For final tax obligations, please consult your tax advisor." | ||
|
||
|
||
|
||
Transactions | ||
User,some@email.com,0000000000000000000000 | ||
|
||
Timestamp,Transaction Type,Asset,Quantity Transacted,Spot Price Currency,Spot Price at Transaction,Subtotal,Total (inclusive of fees and/or spread),Fees and/or Spread,Notes | ||
2023-08-19T17:23:39Z,Send,BTC,0.00205323,EUR,24073.28,"","","",Sent 0.00205323 BTC to 39ADd6pNpeuwjcweLLS5JiJPFjNPJnf4xY | ||
2023-04-20T04:05:40Z,Buy,ETH,0.00213232,EUR,1810.23,3.86,4.85,0.990000,Bought 0.00213232 ETH for €4.85 EUR | ||
2023-04-22T06:24:44Z,Receive,ETH,1.0e-08,EUR,1689.10,"","","",Received 0.00000001 ETH from Vweeter Limited | ||
2023-04-26T13:46:22Z,Convert,ETH,0.00052203,EUR,1762.35,0.900000,0.920000,0.020000,Converted 0.00052203 ETH to 0.087842 ATOM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.