rename to HavenoDaemon.ts and HavenoDaemon.test.ts

This commit is contained in:
woodser 2021-11-11 13:48:31 -05:00
parent 6f94a51a59
commit 36a007a667
6 changed files with 7223 additions and 7684 deletions

View File

@ -22,7 +22,7 @@ This application is a lightly modified [create-react-app](https://github.com/fac
Running the [top-level API tests](./src/HavenoDaemon.test.tsx) is a great way to develop and test Haveno end-to-end.
[`HavenoDaemon`](./src/HavenoDaemon.tsx) provides the interface to the Haveno daemon's gRPC API.
[`HavenoDaemon`](./src/HavenoDaemon.ts) provides the interface to the Haveno daemon's gRPC API.
1. [Run a local Haveno test network](https://github.com/haveno-dex/haveno/blob/master/docs/installing.md), running Alice and Bob as daemons with `make alice-daemon` and `make bob-daemon`.
2. `git clone https://github.com/haveno-dex/haveno-ui-poc`

14845
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,7 @@
"grpc-web": "^1.2.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"react-scripts": "^4.0.3",
"typescript": "^4.2.4",
"web-vitals": "^1.1.1"
},
@ -43,6 +43,6 @@
]
},
"devDependencies": {
"monero-javascript": "^0.5.6"
"monero-javascript": "^0.5.8"
}
}

View File

@ -17,7 +17,7 @@ const havenoVersion = "1.6.2";
const aliceDaemonUrl = "http://localhost:8080";
const aliceDaemonPassword = "apitest";
const alice: HavenoDaemon = new HavenoDaemon(aliceDaemonUrl, aliceDaemonPassword);
const aliceWalletUrl = "http://127.0.0.1:51743"; // alice's internal haveno wallet for direct testing // TODO (woodser): make configurable rather than randomly generated
const aliceWalletUrl = "http://127.0.0.1:63773"; // alice's internal haveno wallet for direct testing // TODO (woodser): make configurable rather than randomly generated
const aliceWalletUsername = "rpc_user";
const aliceWalletPassword = "abc123";
let aliceWallet: any;
@ -92,10 +92,10 @@ test("Can get market prices", async () => {
test("Can get balances", async () => {
let balances: XmrBalanceInfo = await alice.getBalances();
expect(balances.getUnlockedBalance());
expect(balances.getLockedBalance());
expect(balances.getReservedOfferBalance());
expect(balances.getReservedTradeBalance());
expect(BigInt(balances.getUnlockedBalance())).toBeGreaterThanOrEqual(0);
expect(BigInt(balances.getLockedBalance())).toBeGreaterThanOrEqual(0);
expect(BigInt(balances.getReservedOfferBalance())).toBeGreaterThanOrEqual(0);
expect(BigInt(balances.getReservedTradeBalance())).toBeGreaterThanOrEqual(0);
});
test("Can get offers", async () => {
@ -368,18 +368,18 @@ function getOffer(offers: OfferInfo[], id: string): OfferInfo | undefined {
}
function testCryptoPaymentAccount(paymentAccount: PaymentAccount) {
expect(paymentAccount.getId()).toHaveLength;
expect(paymentAccount.getAccountName()).toHaveLength;
expect(paymentAccount.getPaymentAccountPayload()!.getCryptoCurrencyAccountPayload()!.getAddress()).toHaveLength;
expect(paymentAccount.getSelectedTradeCurrency()!.getCode()).toHaveLength;
expect(paymentAccount.getId().length).toBeGreaterThan(0);
expect(paymentAccount.getAccountName().length).toBeGreaterThan(0);
expect(paymentAccount.getPaymentAccountPayload()!.getCryptoCurrencyAccountPayload()!.getAddress().length).toBeGreaterThan(0);
expect(paymentAccount.getSelectedTradeCurrency()!.getCode().length).toBeGreaterThan(0);
expect(paymentAccount.getTradeCurrenciesList().length).toEqual(1);
let tradeCurrency = paymentAccount.getTradeCurrenciesList()[0];
expect(tradeCurrency.getName()).toHaveLength;
expect(tradeCurrency.getName().length).toBeGreaterThan(0);
expect(tradeCurrency.getCode()).toEqual(paymentAccount.getSelectedTradeCurrency()!.getCode());
}
function testOffer(offer: OfferInfo) {
expect(offer.getId()).toHaveLength;
expect(offer.getId().length).toBeGreaterThan(0);
// TODO: test rest of offer
}

View File

@ -43,7 +43,7 @@ class HavenoDaemon {
async getVersion(): Promise<string> {
let that = this;
return new Promise(function(resolve, reject) {
that._getVersionClient.getVersion(new GetVersionRequest(), {password: that._password}, function(err: grpcWeb.Error, response: GetVersionReply) {
that._getVersionClient.getVersion(new GetVersionRequest(), {password: that._password}, function(err: grpcWeb.RpcError, response: GetVersionReply) {
if (err) reject(err);
else resolve(response.getVersion());
});
@ -59,7 +59,7 @@ class HavenoDaemon {
async getPrice(currencyCode: string): Promise<number> {
let that = this;
return new Promise(function(resolve, reject) {
that._priceClient.getMarketPrice(new MarketPriceRequest().setCurrencyCode(currencyCode), {password: that._password}, function(err: grpcWeb.Error, response: MarketPriceReply) {
that._priceClient.getMarketPrice(new MarketPriceRequest().setCurrencyCode(currencyCode), {password: that._password}, function(err: grpcWeb.RpcError, response: MarketPriceReply) {
if (err) reject(err);
else resolve(response.getPrice());
});
@ -74,7 +74,7 @@ class HavenoDaemon {
async getBalances(): Promise<XmrBalanceInfo> {
let that = this;
return new Promise(function(resolve, reject) {
that._walletsClient.getBalances(new GetBalancesRequest(), {password: that._password}, function(err: grpcWeb.Error, response: GetBalancesReply) {
that._walletsClient.getBalances(new GetBalancesRequest(), {password: that._password}, function(err: grpcWeb.RpcError, response: GetBalancesReply) {
if (err) reject(err);
else resolve(response.getBalances()!.getXmr()!);
});
@ -89,7 +89,7 @@ class HavenoDaemon {
async getNewDepositSubaddress(): Promise<string> {
let that = this;
return new Promise(function(resolve, reject) {
that._walletsClient.getNewDepositSubaddress(new GetNewDepositSubaddressRequest(), {password: that._password}, function(err: grpcWeb.Error, response: GetNewDepositSubaddressReply) {
that._walletsClient.getNewDepositSubaddress(new GetNewDepositSubaddressRequest(), {password: that._password}, function(err: grpcWeb.RpcError, response: GetNewDepositSubaddressReply) {
if (err) reject(err);
else resolve(response.getSubaddress());
});
@ -104,7 +104,7 @@ class HavenoDaemon {
async getPaymentAccounts(): Promise<PaymentAccount[]> {
let that = this;
return new Promise(function(resolve, reject) {
that._paymentAccountsClient.getPaymentAccounts(new GetPaymentAccountsRequest(), {password: that._password}, function(err: grpcWeb.Error, response: GetPaymentAccountsReply) {
that._paymentAccountsClient.getPaymentAccounts(new GetPaymentAccountsRequest(), {password: that._password}, function(err: grpcWeb.RpcError, response: GetPaymentAccountsReply) {
if (err) reject(err);
else resolve(response.getPaymentAccountsList());
});
@ -129,7 +129,7 @@ class HavenoDaemon {
.setAddress(address)
.setTradeInstant(false); // not using instant trades
return new Promise(function(resolve, reject) {
that._paymentAccountsClient.createCryptoCurrencyPaymentAccount(request, {password: that._password}, function(err: grpcWeb.Error, response: CreateCryptoCurrencyPaymentAccountReply) {
that._paymentAccountsClient.createCryptoCurrencyPaymentAccount(request, {password: that._password}, function(err: grpcWeb.RpcError, response: CreateCryptoCurrencyPaymentAccountReply) {
if (err) reject(err);
else resolve(response.getPaymentAccount()!);
});
@ -146,7 +146,7 @@ class HavenoDaemon {
async getOffers(direction: string): Promise<OfferInfo[]> {
let that = this;
return new Promise(function(resolve, reject) {
that._offersClient.getOffers(new GetOffersRequest().setDirection(direction).setCurrencyCode("XMR"), {password: that._password}, function(err: grpcWeb.Error, response: GetOffersReply) {
that._offersClient.getOffers(new GetOffersRequest().setDirection(direction).setCurrencyCode("XMR"), {password: that._password}, function(err: grpcWeb.RpcError, response: GetOffersReply) {
if (err) reject(err);
else resolve(response.getOffersList());
});
@ -163,7 +163,7 @@ class HavenoDaemon {
async getMyOffers(direction: string): Promise<OfferInfo[]> {
let that = this;
return new Promise(function(resolve, reject) {
that._offersClient.getMyOffers(new GetOffersRequest().setDirection(direction).setCurrencyCode("XMR"), {password: that._password}, function(err: grpcWeb.Error, response: GetOffersReply) {
that._offersClient.getMyOffers(new GetOffersRequest().setDirection(direction).setCurrencyCode("XMR"), {password: that._password}, function(err: grpcWeb.RpcError, response: GetOffersReply) {
if (err) reject(err);
else resolve(response.getOffersList());
});
@ -208,7 +208,7 @@ class HavenoDaemon {
.setPaymentAccountId(paymentAccountId);
if (triggerPrice) request.setTriggerPrice(BigInt(triggerPrice.toString()).toString());
return new Promise(function(resolve, reject) {
that._offersClient.createOffer(request, {password: that._password}, function(err: grpcWeb.Error, response: CreateOfferReply) {
that._offersClient.createOffer(request, {password: that._password}, function(err: grpcWeb.RpcError, response: CreateOfferReply) {
if (err) reject(err);
else resolve(response.getOffer()!);
});
@ -223,7 +223,7 @@ class HavenoDaemon {
async removeOffer(offerId: string): Promise<void> {
let that = this;
return new Promise(function(resolve, reject) {
that._offersClient.cancelOffer(new CancelOfferRequest().setId(offerId), {password: that._password}, function(err: grpcWeb.Error) {
that._offersClient.cancelOffer(new CancelOfferRequest().setId(offerId), {password: that._password}, function(err: grpcWeb.RpcError) {
if (err) reject(err);
else resolve();
});
@ -243,10 +243,10 @@ class HavenoDaemon {
.setOfferId(offerId)
.setPaymentAccountId(paymentAccountId);
return new Promise(function(resolve, reject) {
that._tradesClient.takeOffer(request, {password: that._password}, function(err: grpcWeb.Error, response: TakeOfferReply) {
that._tradesClient.takeOffer(request, {password: that._password}, function(err: grpcWeb.RpcError, response: TakeOfferReply) {
if (err) reject(err);
else if (response.getFailureReason() && response.getFailureReason()!.getAvailabilityResult() !== AvailabilityResult.AVAILABLE) reject(response.getFailureReason()!.getDescription());
else resolve(response.getTrade());
else resolve(response.getTrade()!);
});
});
}
@ -260,9 +260,9 @@ class HavenoDaemon {
async getTrade(tradeId: string): Promise<TradeInfo> {
let that = this;
return new Promise(function(resolve, reject) {
that._tradesClient.getTrade(new GetTradeRequest().setTradeId(tradeId), {password: that._password}, function(err: grpcWeb.Error, response: GetTradeReply) {
that._tradesClient.getTrade(new GetTradeRequest().setTradeId(tradeId), {password: that._password}, function(err: grpcWeb.RpcError, response: GetTradeReply) {
if (err) reject(err);
else resolve(response.getTrade());
else resolve(response.getTrade()!);
});
});
}
@ -275,7 +275,7 @@ class HavenoDaemon {
async confirmPaymentStarted(tradeId: string): Promise<void> {
let that = this;
return new Promise(function(resolve, reject) {
that._tradesClient.confirmPaymentStarted(new ConfirmPaymentStartedRequest().setTradeId(tradeId), {password: that._password}, function(err: grpcWeb.Error) {
that._tradesClient.confirmPaymentStarted(new ConfirmPaymentStartedRequest().setTradeId(tradeId), {password: that._password}, function(err: grpcWeb.RpcError) {
if (err) reject(err);
else resolve();
});
@ -290,7 +290,7 @@ class HavenoDaemon {
async confirmPaymentReceived(tradeId: string): Promise<void> {
let that = this;
return new Promise(function(resolve, reject) {
that._tradesClient.confirmPaymentReceived(new ConfirmPaymentReceivedRequest().setTradeId(tradeId), {password: that._password}, function(err: grpcWeb.Error) {
that._tradesClient.confirmPaymentReceived(new ConfirmPaymentReceivedRequest().setTradeId(tradeId), {password: that._password}, function(err: grpcWeb.RpcError) {
if (err) reject(err);
else resolve();
});

View File

@ -18,7 +18,7 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
"jsx": "react-jsx"
},
"include": [
"src"