mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-01-26 22:37:00 -05:00
Add tradestatistics tests
This commit is contained in:
parent
9e2a466f66
commit
a6c6d64500
@ -1642,6 +1642,7 @@ test("Can complete a trade within a range", async () => {
|
|||||||
const offerAmount = HavenoUtils.xmrToAtomicUnits(2);
|
const offerAmount = HavenoUtils.xmrToAtomicUnits(2);
|
||||||
const offerMinAmount = HavenoUtils.xmrToAtomicUnits(.15);
|
const offerMinAmount = HavenoUtils.xmrToAtomicUnits(.15);
|
||||||
const tradeAmount = getRandomBigIntWithinRange(offerMinAmount, offerAmount);
|
const tradeAmount = getRandomBigIntWithinRange(offerMinAmount, offerAmount);
|
||||||
|
const tradeStatisticsPre = await arbitrator.getTradeStatistics();
|
||||||
await executeTrade({
|
await executeTrade({
|
||||||
price: 142.23,
|
price: 142.23,
|
||||||
offerAmount: offerAmount,
|
offerAmount: offerAmount,
|
||||||
@ -1653,6 +1654,9 @@ test("Can complete a trade within a range", async () => {
|
|||||||
assetCode: assetCode,
|
assetCode: assetCode,
|
||||||
testBalanceChangeEndToEnd: true
|
testBalanceChangeEndToEnd: true
|
||||||
});
|
});
|
||||||
|
const tradeStatisticsPost = await arbitrator.getTradeStatistics();
|
||||||
|
HavenoUtils.log(0, "Trade statistics size before/after trade: " + tradeStatisticsPre.length + "/" + tradeStatisticsPost.length);
|
||||||
|
assert(tradeStatisticsPost.length - tradeStatisticsPre.length === 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Can complete trades at the same time (CI, sanity check)", async () => {
|
test("Can complete trades at the same time (CI, sanity check)", async () => {
|
||||||
@ -2217,6 +2221,14 @@ test("Selects arbitrators which are online, registered, and least used", async (
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("Can get trade statistics", async () => {
|
||||||
|
const tradeStatisticsArbitrator = await arbitrator.getTradeStatistics();
|
||||||
|
const tradeStatisticsUser1 = await user1.getTradeStatistics();
|
||||||
|
const tradeStatisticsUser2 = await user2.getTradeStatistics();
|
||||||
|
HavenoUtils.log(0, "Trade statistics size (arb/u1/u2): " + tradeStatisticsArbitrator.length + "/" + tradeStatisticsUser1.length + "/" + tradeStatisticsUser2.length);
|
||||||
|
assert(tradeStatisticsArbitrator.length === tradeStatisticsUser1.length && tradeStatisticsUser1.length === tradeStatisticsUser2.length);
|
||||||
|
});
|
||||||
|
|
||||||
// ----------------------------- TEST HELPERS ---------------------------------
|
// ----------------------------- TEST HELPERS ---------------------------------
|
||||||
|
|
||||||
function getTradeContexts(numConfigs: number): TradeContext[] {
|
function getTradeContexts(numConfigs: number): TradeContext[] {
|
||||||
|
@ -20,9 +20,9 @@ import HavenoError from "./types/HavenoError";
|
|||||||
import HavenoUtils from "./utils/HavenoUtils";
|
import HavenoUtils from "./utils/HavenoUtils";
|
||||||
import TaskLooper from "./utils/TaskLooper";
|
import TaskLooper from "./utils/TaskLooper";
|
||||||
import type * as grpcWeb from "grpc-web";
|
import type * as grpcWeb from "grpc-web";
|
||||||
import { GetVersionClient, AccountClient, XmrConnectionsClient, DisputesClient, DisputeAgentsClient, NotificationsClient, WalletsClient, PriceClient, OffersClient, PaymentAccountsClient, TradesClient, ShutdownServerClient, XmrNodeClient } from './protobuf/GrpcServiceClientPb';
|
import { GetTradeStatisticsClient, GetVersionClient, AccountClient, XmrConnectionsClient, DisputesClient, DisputeAgentsClient, NotificationsClient, WalletsClient, PriceClient, OffersClient, PaymentAccountsClient, TradesClient, ShutdownServerClient, XmrNodeClient } from './protobuf/GrpcServiceClientPb';
|
||||||
import { GetVersionRequest, GetVersionReply, IsAppInitializedRequest, IsAppInitializedReply, RegisterDisputeAgentRequest, UnregisterDisputeAgentRequest, MarketPriceRequest, MarketPriceReply, MarketPricesRequest, MarketPricesReply, MarketPriceInfo, MarketDepthRequest, MarketDepthReply, MarketDepthInfo, GetBalancesRequest, GetBalancesReply, XmrBalanceInfo, GetMyOfferRequest, GetMyOfferReply, GetOffersRequest, GetOffersReply, OfferInfo, GetPaymentMethodsRequest, GetPaymentMethodsReply, GetPaymentAccountFormRequest, CreatePaymentAccountRequest, ValidateFormFieldRequest, CreatePaymentAccountReply, GetPaymentAccountFormReply, GetPaymentAccountsRequest, GetPaymentAccountsReply, CreateCryptoCurrencyPaymentAccountRequest, CreateCryptoCurrencyPaymentAccountReply, PostOfferRequest, PostOfferReply, CancelOfferRequest, TakeOfferRequest, TakeOfferReply, TradeInfo, GetTradeRequest, GetTradeReply, GetTradesRequest, GetTradesReply, GetXmrSeedRequest, GetXmrSeedReply, GetXmrPrimaryAddressRequest, GetXmrPrimaryAddressReply, GetXmrNewSubaddressRequest, GetXmrNewSubaddressReply, ConfirmPaymentSentRequest, ConfirmPaymentReceivedRequest, CompleteTradeRequest, XmrTx, GetXmrTxsRequest, GetXmrTxsReply, XmrDestination, CreateXmrTxRequest, CreateXmrTxReply, RelayXmrTxRequest, RelayXmrTxReply, CreateAccountRequest, AccountExistsRequest, AccountExistsReply, DeleteAccountRequest, OpenAccountRequest, IsAccountOpenRequest, IsAccountOpenReply, CloseAccountRequest, ChangePasswordRequest, BackupAccountRequest, BackupAccountReply, RestoreAccountRequest, StopRequest, NotificationMessage, RegisterNotificationListenerRequest, SendNotificationRequest, UrlConnection, AddConnectionRequest, RemoveConnectionRequest, GetConnectionRequest, GetConnectionsRequest, SetConnectionRequest, CheckConnectionRequest, CheckConnectionsReply, CheckConnectionsRequest, StartCheckingConnectionRequest, StopCheckingConnectionRequest, GetBestAvailableConnectionRequest, SetAutoSwitchRequest, CheckConnectionReply, GetConnectionsReply, GetConnectionReply, GetBestAvailableConnectionReply, GetDisputeRequest, GetDisputeReply, GetDisputesRequest, GetDisputesReply, OpenDisputeRequest, ResolveDisputeRequest, SendDisputeChatMessageRequest, SendChatMessageRequest, GetChatMessagesRequest, GetChatMessagesReply, StartXmrNodeRequest, StopXmrNodeRequest, IsXmrNodeOnlineRequest, IsXmrNodeOnlineReply, GetXmrNodeSettingsRequest, GetXmrNodeSettingsReply } from "./protobuf/grpc_pb";
|
import { GetTradeStatisticsRequest, GetTradeStatisticsReply, GetVersionRequest, GetVersionReply, IsAppInitializedRequest, IsAppInitializedReply, RegisterDisputeAgentRequest, UnregisterDisputeAgentRequest, MarketPriceRequest, MarketPriceReply, MarketPricesRequest, MarketPricesReply, MarketPriceInfo, MarketDepthRequest, MarketDepthReply, MarketDepthInfo, GetBalancesRequest, GetBalancesReply, XmrBalanceInfo, GetMyOfferRequest, GetMyOfferReply, GetOffersRequest, GetOffersReply, OfferInfo, GetPaymentMethodsRequest, GetPaymentMethodsReply, GetPaymentAccountFormRequest, CreatePaymentAccountRequest, ValidateFormFieldRequest, CreatePaymentAccountReply, GetPaymentAccountFormReply, GetPaymentAccountsRequest, GetPaymentAccountsReply, CreateCryptoCurrencyPaymentAccountRequest, CreateCryptoCurrencyPaymentAccountReply, PostOfferRequest, PostOfferReply, CancelOfferRequest, TakeOfferRequest, TakeOfferReply, TradeInfo, GetTradeRequest, GetTradeReply, GetTradesRequest, GetTradesReply, GetXmrSeedRequest, GetXmrSeedReply, GetXmrPrimaryAddressRequest, GetXmrPrimaryAddressReply, GetXmrNewSubaddressRequest, GetXmrNewSubaddressReply, ConfirmPaymentSentRequest, ConfirmPaymentReceivedRequest, CompleteTradeRequest, XmrTx, GetXmrTxsRequest, GetXmrTxsReply, XmrDestination, CreateXmrTxRequest, CreateXmrTxReply, RelayXmrTxRequest, RelayXmrTxReply, CreateAccountRequest, AccountExistsRequest, AccountExistsReply, DeleteAccountRequest, OpenAccountRequest, IsAccountOpenRequest, IsAccountOpenReply, CloseAccountRequest, ChangePasswordRequest, BackupAccountRequest, BackupAccountReply, RestoreAccountRequest, StopRequest, NotificationMessage, RegisterNotificationListenerRequest, SendNotificationRequest, UrlConnection, AddConnectionRequest, RemoveConnectionRequest, GetConnectionRequest, GetConnectionsRequest, SetConnectionRequest, CheckConnectionRequest, CheckConnectionsReply, CheckConnectionsRequest, StartCheckingConnectionRequest, StopCheckingConnectionRequest, GetBestAvailableConnectionRequest, SetAutoSwitchRequest, CheckConnectionReply, GetConnectionsReply, GetConnectionReply, GetBestAvailableConnectionReply, GetDisputeRequest, GetDisputeReply, GetDisputesRequest, GetDisputesReply, OpenDisputeRequest, ResolveDisputeRequest, SendDisputeChatMessageRequest, SendChatMessageRequest, GetChatMessagesRequest, GetChatMessagesReply, StartXmrNodeRequest, StopXmrNodeRequest, IsXmrNodeOnlineRequest, IsXmrNodeOnlineReply, GetXmrNodeSettingsRequest, GetXmrNodeSettingsReply } from "./protobuf/grpc_pb";
|
||||||
import { OfferDirection, PaymentMethod, PaymentAccountForm, PaymentAccountFormField, PaymentAccount, PaymentAccountPayload, AvailabilityResult, Attachment, DisputeResult, Dispute, ChatMessage, XmrNodeSettings } from "./protobuf/pb_pb";
|
import { TradeStatistics3, OfferDirection, PaymentMethod, PaymentAccountForm, PaymentAccountFormField, PaymentAccount, PaymentAccountPayload, AvailabilityResult, Attachment, DisputeResult, Dispute, ChatMessage, XmrNodeSettings } from "./protobuf/pb_pb";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Haveno daemon client.
|
* Haveno daemon client.
|
||||||
@ -31,6 +31,7 @@ export default class HavenoClient {
|
|||||||
|
|
||||||
// grpc clients
|
// grpc clients
|
||||||
/** @private */ _appName: string | undefined;
|
/** @private */ _appName: string | undefined;
|
||||||
|
/** @private */ _getTradeStatisticsClient: GetTradeStatisticsClient;
|
||||||
/** @private */ _getVersionClient: GetVersionClient;
|
/** @private */ _getVersionClient: GetVersionClient;
|
||||||
/** @private */ _disputeAgentsClient: DisputeAgentsClient;
|
/** @private */ _disputeAgentsClient: DisputeAgentsClient;
|
||||||
/** @private */ _disputesClient: DisputesClient;
|
/** @private */ _disputesClient: DisputesClient;
|
||||||
@ -74,6 +75,7 @@ export default class HavenoClient {
|
|||||||
HavenoUtils.log(2, "Creating Haveno client connected to " + url);
|
HavenoUtils.log(2, "Creating Haveno client connected to " + url);
|
||||||
this._url = url;
|
this._url = url;
|
||||||
this._password = password;
|
this._password = password;
|
||||||
|
this._getTradeStatisticsClient = new GetTradeStatisticsClient(this._url);
|
||||||
this._getVersionClient = new GetVersionClient(this._url);
|
this._getVersionClient = new GetVersionClient(this._url);
|
||||||
this._accountClient = new AccountClient(this._url);
|
this._accountClient = new AccountClient(this._url);
|
||||||
this._xmrConnectionsClient = new XmrConnectionsClient(this._url);
|
this._xmrConnectionsClient = new XmrConnectionsClient(this._url);
|
||||||
@ -1101,6 +1103,19 @@ export default class HavenoClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all trade statistics.
|
||||||
|
*
|
||||||
|
* @return {TradeStatistics3[]} all user trades
|
||||||
|
*/
|
||||||
|
async getTradeStatistics(): Promise<TradeStatistics3[]> {
|
||||||
|
try {
|
||||||
|
return (await this._getTradeStatisticsClient.getTradeStatistics(new GetTradeStatisticsRequest(), {password: this._password})).getTradeStatisticsList();
|
||||||
|
} catch (e: any) {
|
||||||
|
throw new HavenoError(e.message, e.code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all trades.
|
* Get all trades.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user