mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-04-16 14:03:19 -04:00
cleanup
This commit is contained in:
parent
db456dfadf
commit
212094fde5
@ -9,7 +9,7 @@ This application is a lightly modified [create-react-app](https://github.com/fac
|
||||
1. [Run a local Haveno test network](https://github.com/haveno-dex/haveno/blob/master/docs/installing.md), running Alice as a daemon with `make alice-daemon`.
|
||||
2. Clone this project to the same parent directory as the haveno project: `git clone https://github.com/haveno-dex/haveno-ui-poc`
|
||||
3. In a new terminal, start envoy with the config in haveno-ui-poc/config/envoy.yaml (change absolute path for your system): `docker run --rm --add-host host.docker.internal:host-gateway -it -v ~/git/haveno-ui-poc/config/envoy.yaml:/envoy.yaml -p 8080:8080 envoyproxy/envoy-dev:8a2143613d43d17d1eb35a24b4a4a4c432215606 -c /envoy.yaml`
|
||||
4. Install protobuf compiler 3.19.1 or later for your system:<br>
|
||||
4. Install protobuf compiler v3.19.1 or later for your system:<br>
|
||||
mac: `brew install protobuf`<br>
|
||||
linux: `apt install protobuf-compiler`
|
||||
NOTE: You may need to upgrade to v3.19.1 manually if your package manager installs an older version.
|
||||
@ -33,13 +33,11 @@ Running the [top-level API tests](./src/HavenoDaemon.test.ts) is a great way to
|
||||
2. Clone this project to the same parent directory as the haveno project: `git clone https://github.com/haveno-dex/haveno-ui-poc`
|
||||
3. In a new terminal, start envoy with the config in haveno-ui-poc/config/envoy.test.yaml (change absolute path for your system): `docker run --rm --add-host host.docker.internal:host-gateway -it -v ~/git/haveno-ui-poc/config/envoy.test.yaml:/envoy.test.yaml -p 8079:8079 -p 8080:8080 -p 8081:8081 -p 8082:8082 -p 8083:8083 -p 8084:8084 -p 8085:8085 -p 8086:8086 envoyproxy/envoy-dev:8a2143613d43d17d1eb35a24b4a4a4c432215606 -c /envoy.test.yaml`
|
||||
4. In a new terminal, start the funding wallet. This wallet will be automatically funded in order to fund Alice and Bob during the tests.<br>For example: `cd ~/git/haveno && make funding-wallet`.
|
||||
5. Install protobuf compiler 3.19.1 or later for your system:<br>
|
||||
5. Install protobuf compiler v3.19.1 or later for your system:<br>
|
||||
mac: `brew install protobuf`<br>
|
||||
linux: `apt install protobuf-compiler`
|
||||
NOTE: You may need to upgrade to v3.19.1 manually if your package manager installs an older version.
|
||||
6. Download `protoc-gen-grpc-web` plugin and make executable as [shown here](https://github.com/grpc/grpc-web#code-generator-plugin).
|
||||
7. `cd haveno-ui-poc`
|
||||
8. `npm install`
|
||||
9. `npm test` to run all tests or `npm run test -- -t 'my test'` to run tests by name.
|
||||
|
||||
|
||||
9. `npm test` to run all tests or `npm run test -- -t 'my test'` to run tests by name.
|
@ -89,8 +89,7 @@ const TestConfig = {
|
||||
["8085", ["10004", "7780"]],
|
||||
["8086", ["10005", "7781"]],
|
||||
]),
|
||||
// from DEV_PRIVILEGE_PRIV_KEY
|
||||
devPrivPrivateKey: "6ac43ea1df2a290c1c8391736aa42e4339c5cb4f110ff0257a13b63211977b7a"
|
||||
devPrivilegePrivKey: "6ac43ea1df2a290c1c8391736aa42e4339c5cb4f110ff0257a13b63211977b7a" // from DEV_PRIVILEGE_PRIV_KEY
|
||||
};
|
||||
|
||||
interface TxContext {
|
||||
@ -129,6 +128,10 @@ beforeAll(async () => {
|
||||
if (daemons[2].status === "fulfilled") bob = (daemons[2] as PromiseFulfilledResult<HavenoDaemon>).value;
|
||||
else throw new Error((daemons[2] as PromiseRejectedResult).reason);
|
||||
|
||||
// register arbitrator as dispute agents
|
||||
await arbitrator.registerDisputeAgent("mediator", TestConfig.devPrivilegePrivKey);
|
||||
await arbitrator.registerDisputeAgent("refundagent", TestConfig.devPrivilegePrivKey);
|
||||
|
||||
// connect monero clients
|
||||
monerod = await monerojs.connectToDaemonRpc(TestConfig.monerod.url, TestConfig.monerod.username, TestConfig.monerod.password);
|
||||
aliceWallet = await monerojs.connectToWalletRpc(TestConfig.alice.walletUrl, TestConfig.alice.walletUsername, TestConfig.alice.walletPassword);
|
||||
@ -150,8 +153,8 @@ beforeEach(async() => {
|
||||
afterAll(async () => {
|
||||
let stopPromises = [];
|
||||
if (arbitrator && arbitrator.getProcess()) stopPromises.push(stopHavenoProcess(arbitrator));
|
||||
if (alice && alice.getProcess())stopPromises.push(stopHavenoProcess(alice));
|
||||
if (bob && bob.getProcess())stopPromises.push(stopHavenoProcess(bob));
|
||||
if (alice && alice.getProcess()) stopPromises.push(stopHavenoProcess(alice));
|
||||
if (bob && bob.getProcess()) stopPromises.push(stopHavenoProcess(bob));
|
||||
return Promise.all(stopPromises);
|
||||
});
|
||||
|
||||
@ -164,41 +167,25 @@ test("Can get the version", async () => {
|
||||
expect(version).toEqual(TestConfig.haveno.version);
|
||||
});
|
||||
|
||||
// Current implementation of required arbitor roles is implemented in GrpcDisputeAgentsService.
|
||||
// The arbitration agent role has not yet been implemented since the dispute agent registers as `MEDIATON` and `REFUND` SupportTypes,
|
||||
// which are parsed from the disputeAgentType strings.
|
||||
// Haveno does not provide any UI to enable the `ARBITRATION` type yet.
|
||||
test("Can register arbitrator as dispute agent types", async () => {
|
||||
test("Can register as dispute agents", async () => {
|
||||
await arbitrator.registerDisputeAgent("mediator", TestConfig.devPrivilegePrivKey); // TODO: bisq mediator = haveno arbitrator
|
||||
await arbitrator.registerDisputeAgent("refundagent", TestConfig.devPrivilegePrivKey); // TODO: no refund agent in haveno
|
||||
|
||||
// test bad dispute agent type
|
||||
try {
|
||||
console.log("Registering arbitrator as mediation agent");
|
||||
// DEV_PRIVILEGE_PRIV_KEY is expected by the service.
|
||||
await arbitrator.registerDisputeAgent("mediator", TestConfig.devPrivPrivateKey);
|
||||
console.log("Registering arbitrator as refund agent");
|
||||
await arbitrator.registerDisputeAgent("refundagent", TestConfig.devPrivPrivateKey);
|
||||
await arbitrator.registerDisputeAgent("unsupported type", TestConfig.devPrivilegePrivKey);
|
||||
throw new Error("should have thrown error registering bad type");
|
||||
} catch (err) {
|
||||
console.log("Error registering dispute agent:", err.message);
|
||||
if (err.message !== "unknown dispute agent type 'unsupported type'") throw new Error("Unexpected error: " + err.message);
|
||||
}
|
||||
console.log("Dispute agent registration complete");
|
||||
|
||||
|
||||
// test bad key
|
||||
try {
|
||||
console.log("Registering dispute agent with bad key");
|
||||
await arbitrator.registerDisputeAgent("mediator", "bad key");
|
||||
throw Error("unexpected")
|
||||
throw new Error("should have thrown error registering bad key");
|
||||
} catch (err) {
|
||||
if (err.message === "unexpected") throw Error("Unexpected error: registered dispute agent with bad key");
|
||||
expect(err.message).toEqual("invalid registration key");
|
||||
if (err.message !== "invalid registration key") throw new Error("Unexpected error: " + err.message);
|
||||
}
|
||||
|
||||
try {
|
||||
console.log("Registering dispute agent with bad type");
|
||||
await arbitrator.registerDisputeAgent("unsupported type", TestConfig.devPrivPrivateKey);
|
||||
throw Error("unexpected")
|
||||
} catch (err) {
|
||||
if (err.message === "unexpected") throw Error("Unexpected error: registered dispute agent with bad type");
|
||||
expect(err.message).toEqual("unknown dispute agent type 'unsupported type'");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
test("Can get market prices", async () => {
|
||||
@ -464,7 +451,7 @@ test("Handles unexpected errors during trade initialization", async () => {
|
||||
offer = await traders[0].getMyOffer(offer.getId());
|
||||
assert.equal(offer.getState(), "AVAILABLE");
|
||||
|
||||
// wait for offer for offer to be seen
|
||||
// wait for offer to be seen
|
||||
await wait(TestConfig.walletSyncPeriodMs * 2);
|
||||
|
||||
// trader 1 spends trade funds after initializing trade
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {HavenoUtils} from "./HavenoUtils";
|
||||
import * as grpcWeb from 'grpc-web';
|
||||
import {DisputeAgentsClient, GetVersionClient, PriceClient, WalletsClient, OffersClient, PaymentAccountsClient, TradesClient} from './protobuf/GrpcServiceClientPb';
|
||||
import {GetVersionRequest, GetVersionReply, MarketPriceRequest, MarketPriceReply, MarketPricesRequest, MarketPricesReply, MarketPriceInfo, GetBalancesRequest, GetBalancesReply, XmrBalanceInfo, GetOffersRequest, GetOffersReply, OfferInfo, GetPaymentAccountsRequest, GetPaymentAccountsReply, CreateCryptoCurrencyPaymentAccountRequest, CreateCryptoCurrencyPaymentAccountReply, CreateOfferRequest, CreateOfferReply, CancelOfferRequest, TakeOfferRequest, TakeOfferReply, TradeInfo, GetTradeRequest, GetTradeReply, GetTradesRequest, GetTradesReply, GetNewDepositSubaddressRequest, GetNewDepositSubaddressReply, ConfirmPaymentStartedRequest, ConfirmPaymentReceivedRequest, XmrTx, GetXmrTxsRequest, GetXmrTxsReply, XmrDestination, CreateXmrTxRequest, CreateXmrTxReply, RelayXmrTxRequest, RelayXmrTxReply, RegisterDisputeAgentRequest} from './protobuf/grpc_pb';
|
||||
import {GetVersionClient, DisputeAgentsClient, PriceClient, WalletsClient, OffersClient, PaymentAccountsClient, TradesClient} from './protobuf/GrpcServiceClientPb';
|
||||
import {GetVersionRequest, GetVersionReply, RegisterDisputeAgentRequest, MarketPriceRequest, MarketPriceReply, MarketPricesRequest, MarketPricesReply, MarketPriceInfo, GetBalancesRequest, GetBalancesReply, XmrBalanceInfo, GetOffersRequest, GetOffersReply, OfferInfo, GetPaymentAccountsRequest, GetPaymentAccountsReply, CreateCryptoCurrencyPaymentAccountRequest, CreateCryptoCurrencyPaymentAccountReply, CreateOfferRequest, CreateOfferReply, CancelOfferRequest, TakeOfferRequest, TakeOfferReply, TradeInfo, GetTradeRequest, GetTradeReply, GetTradesRequest, GetTradesReply, GetNewDepositSubaddressRequest, GetNewDepositSubaddressReply, ConfirmPaymentStartedRequest, ConfirmPaymentReceivedRequest, XmrTx, GetXmrTxsRequest, GetXmrTxsReply, XmrDestination, CreateXmrTxRequest, CreateXmrTxReply, RelayXmrTxRequest, RelayXmrTxReply} from './protobuf/grpc_pb';
|
||||
import {PaymentAccount, AvailabilityResult} from './protobuf/pb_pb';
|
||||
const console = require('console');
|
||||
|
||||
@ -17,12 +17,12 @@ class HavenoDaemon {
|
||||
_processLogging: boolean = false;
|
||||
_walletRpcPort: number|undefined;
|
||||
_getVersionClient: GetVersionClient;
|
||||
_disputeAgentsClient: DisputeAgentsClient;
|
||||
_priceClient: PriceClient;
|
||||
_walletsClient: WalletsClient;
|
||||
_paymentAccountsClient: PaymentAccountsClient;
|
||||
_offersClient: OffersClient;
|
||||
_tradesClient: TradesClient;
|
||||
_disputeAgentsClient: DisputeAgentsClient;
|
||||
|
||||
/**
|
||||
* Construct a client connected to a Haveno daemon.
|
||||
@ -37,12 +37,12 @@ class HavenoDaemon {
|
||||
this._url = url;
|
||||
this._password = password;
|
||||
this._getVersionClient = new GetVersionClient(this._url);
|
||||
this._disputeAgentsClient = new DisputeAgentsClient(this._url);
|
||||
this._priceClient = new PriceClient(this._url);
|
||||
this._walletsClient = new WalletsClient(this._url);
|
||||
this._paymentAccountsClient = new PaymentAccountsClient(this._url);
|
||||
this._offersClient = new OffersClient(this._url);
|
||||
this._tradesClient = new TradesClient(this._url);
|
||||
this._disputeAgentsClient = new DisputeAgentsClient(this._url);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -201,6 +201,25 @@ class HavenoDaemon {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register as a dispute agent.
|
||||
*
|
||||
* @param {string} disputeAgentType - type of dispute agent to register, e.g. mediator, refundagent
|
||||
* @param {string} registrationKey - registration key
|
||||
*/
|
||||
async registerDisputeAgent(disputeAgentType: string, registrationKey: string): Promise<void> {
|
||||
let that = this;
|
||||
let request = new RegisterDisputeAgentRequest()
|
||||
.setDisputeAgentType(disputeAgentType)
|
||||
.setRegistrationKey(registrationKey);
|
||||
return new Promise(function(resolve, reject) {
|
||||
that._disputeAgentsClient.registerDisputeAgent(request, {password: that._password}, function(err: grpcWeb.RpcError) {
|
||||
if (err) reject(err);
|
||||
else resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current market price per 1 XMR in the given currency.
|
||||
*
|
||||
@ -231,6 +250,7 @@ class HavenoDaemon {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's balances.
|
||||
*
|
||||
@ -548,26 +568,6 @@ class HavenoDaemon {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register as a dispute agent.
|
||||
*
|
||||
* @param {string} disputeAgentType - type of the dispute agent, E.G. mediator, refundagent
|
||||
* @param {string} registrationKey - registration key, must be DEV_PRIVILEGE_PRIV_KEY
|
||||
*/
|
||||
async registerDisputeAgent(disputeAgentType: string, registrationKey: string): Promise<void> {
|
||||
let that = this;
|
||||
let request = new RegisterDisputeAgentRequest()
|
||||
.setDisputeAgentType(disputeAgentType)
|
||||
.setRegistrationKey(registrationKey);
|
||||
return new Promise(function(resolve, reject) {
|
||||
that._disputeAgentsClient.registerDisputeAgent(request, {password: that._password}, function(err: grpcWeb.RpcError) {
|
||||
if (err) reject(err);
|
||||
else resolve();
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export {HavenoDaemon};
|
||||
|
Loading…
x
Reference in New Issue
Block a user