mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-02-24 08:29:54 -05:00
Add API functions to register arbitrator and mediator keys (#58)
* Add API functions to register arbitrator and mediator keys
This commit is contained in:
parent
d7150453ee
commit
640c89aa87
10
README.md
10
README.md
@ -9,9 +9,10 @@ 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`.
|
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`
|
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`
|
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>
|
mac: `brew install protobuf`<br>
|
||||||
linux: `apt install protobuf-compiler`
|
linux: `apt install protobuf-compiler`
|
||||||
|
NOTE: You may need to upgrade to v3.19.1 manually if your package manager installs an older version.
|
||||||
5. Download `protoc-gen-grpc-web` plugin and make executable as [shown here](https://github.com/grpc/grpc-web#code-generator-plugin).
|
5. Download `protoc-gen-grpc-web` plugin and make executable as [shown here](https://github.com/grpc/grpc-web#code-generator-plugin).
|
||||||
6. `cd haveno-ui-poc`
|
6. `cd haveno-ui-poc`
|
||||||
7. `npm install`
|
7. `npm install`
|
||||||
@ -28,14 +29,15 @@ Running the [top-level API tests](./src/HavenoDaemon.test.ts) is a great way to
|
|||||||
|
|
||||||
[`HavenoDaemon`](./src/HavenoDaemon.ts) 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) and then shut down the arbitrator, Alice, and Bob or run them as daemons, e.g. `make alice-daemon`.
|
1. [Run a local Haveno test network](https://github.com/haveno-dex/haveno/blob/master/docs/installing.md) and then shut down the arbitrator, Alice, and Bob or run them as daemons, e.g. `make alice-daemon`. You may omit the arbitrator registration steps since it is done automatically in the tests.
|
||||||
2. Clone this project to the same parent directory as the haveno project: `git clone https://github.com/haveno-dex/haveno-ui-poc`
|
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`
|
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`.
|
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>
|
mac: `brew install protobuf`<br>
|
||||||
linux: `apt install protobuf-compiler`
|
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).
|
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`
|
7. `cd haveno-ui-poc`
|
||||||
8. `npm install`
|
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.
|
@ -88,7 +88,8 @@ const TestConfig = {
|
|||||||
["8084", ["10003", "7779"]],
|
["8084", ["10003", "7779"]],
|
||||||
["8085", ["10004", "7780"]],
|
["8085", ["10004", "7780"]],
|
||||||
["8086", ["10005", "7781"]],
|
["8086", ["10005", "7781"]],
|
||||||
])
|
]),
|
||||||
|
devPrivilegePrivKey: "6ac43ea1df2a290c1c8391736aa42e4339c5cb4f110ff0257a13b63211977b7a" // from DEV_PRIVILEGE_PRIV_KEY
|
||||||
};
|
};
|
||||||
|
|
||||||
interface TxContext {
|
interface TxContext {
|
||||||
@ -127,6 +128,10 @@ beforeAll(async () => {
|
|||||||
if (daemons[2].status === "fulfilled") bob = (daemons[2] as PromiseFulfilledResult<HavenoDaemon>).value;
|
if (daemons[2].status === "fulfilled") bob = (daemons[2] as PromiseFulfilledResult<HavenoDaemon>).value;
|
||||||
else throw new Error((daemons[2] as PromiseRejectedResult).reason);
|
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
|
// connect monero clients
|
||||||
monerod = await monerojs.connectToDaemonRpc(TestConfig.monerod.url, TestConfig.monerod.username, TestConfig.monerod.password);
|
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);
|
aliceWallet = await monerojs.connectToWalletRpc(TestConfig.alice.walletUrl, TestConfig.alice.walletUsername, TestConfig.alice.walletPassword);
|
||||||
@ -148,8 +153,8 @@ beforeEach(async() => {
|
|||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
let stopPromises = [];
|
let stopPromises = [];
|
||||||
if (arbitrator && arbitrator.getProcess()) stopPromises.push(stopHavenoProcess(arbitrator));
|
if (arbitrator && arbitrator.getProcess()) stopPromises.push(stopHavenoProcess(arbitrator));
|
||||||
if (alice && alice.getProcess())stopPromises.push(stopHavenoProcess(alice));
|
if (alice && alice.getProcess()) stopPromises.push(stopHavenoProcess(alice));
|
||||||
if (bob && bob.getProcess())stopPromises.push(stopHavenoProcess(bob));
|
if (bob && bob.getProcess()) stopPromises.push(stopHavenoProcess(bob));
|
||||||
return Promise.all(stopPromises);
|
return Promise.all(stopPromises);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -162,6 +167,27 @@ test("Can get the version", async () => {
|
|||||||
expect(version).toEqual(TestConfig.haveno.version);
|
expect(version).toEqual(TestConfig.haveno.version);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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 {
|
||||||
|
await arbitrator.registerDisputeAgent("unsupported type", TestConfig.devPrivilegePrivKey);
|
||||||
|
throw new Error("should have thrown error registering bad type");
|
||||||
|
} catch (err) {
|
||||||
|
if (err.message !== "unknown dispute agent type 'unsupported type'") throw new Error("Unexpected error: " + err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// test bad key
|
||||||
|
try {
|
||||||
|
await arbitrator.registerDisputeAgent("mediator", "bad key");
|
||||||
|
throw new Error("should have thrown error registering bad key");
|
||||||
|
} catch (err) {
|
||||||
|
if (err.message !== "invalid registration key") throw new Error("Unexpected error: " + err.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test("Can get market prices", async () => {
|
test("Can get market prices", async () => {
|
||||||
|
|
||||||
// get all market prices
|
// get all market prices
|
||||||
@ -425,7 +451,7 @@ test("Handles unexpected errors during trade initialization", async () => {
|
|||||||
offer = await traders[0].getMyOffer(offer.getId());
|
offer = await traders[0].getMyOffer(offer.getId());
|
||||||
assert.equal(offer.getState(), "AVAILABLE");
|
assert.equal(offer.getState(), "AVAILABLE");
|
||||||
|
|
||||||
// wait for offer for offer to be seen
|
// wait for offer to be seen
|
||||||
await wait(TestConfig.walletSyncPeriodMs * 2);
|
await wait(TestConfig.walletSyncPeriodMs * 2);
|
||||||
|
|
||||||
// trader 1 spends trade funds after initializing trade
|
// trader 1 spends trade funds after initializing trade
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import {HavenoUtils} from "./HavenoUtils";
|
import {HavenoUtils} from "./HavenoUtils";
|
||||||
import * as grpcWeb from 'grpc-web';
|
import * as grpcWeb from 'grpc-web';
|
||||||
import {GetVersionClient, PriceClient, WalletsClient, OffersClient, PaymentAccountsClient, TradesClient} from './protobuf/GrpcServiceClientPb';
|
import {GetVersionClient, DisputeAgentsClient, 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} from './protobuf/grpc_pb';
|
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';
|
import {PaymentAccount, AvailabilityResult} from './protobuf/pb_pb';
|
||||||
const console = require('console');
|
const console = require('console');
|
||||||
|
|
||||||
@ -17,6 +17,7 @@ class HavenoDaemon {
|
|||||||
_processLogging: boolean = false;
|
_processLogging: boolean = false;
|
||||||
_walletRpcPort: number|undefined;
|
_walletRpcPort: number|undefined;
|
||||||
_getVersionClient: GetVersionClient;
|
_getVersionClient: GetVersionClient;
|
||||||
|
_disputeAgentsClient: DisputeAgentsClient;
|
||||||
_priceClient: PriceClient;
|
_priceClient: PriceClient;
|
||||||
_walletsClient: WalletsClient;
|
_walletsClient: WalletsClient;
|
||||||
_paymentAccountsClient: PaymentAccountsClient;
|
_paymentAccountsClient: PaymentAccountsClient;
|
||||||
@ -36,6 +37,7 @@ class HavenoDaemon {
|
|||||||
this._url = url;
|
this._url = url;
|
||||||
this._password = password;
|
this._password = password;
|
||||||
this._getVersionClient = new GetVersionClient(this._url);
|
this._getVersionClient = new GetVersionClient(this._url);
|
||||||
|
this._disputeAgentsClient = new DisputeAgentsClient(this._url);
|
||||||
this._priceClient = new PriceClient(this._url);
|
this._priceClient = new PriceClient(this._url);
|
||||||
this._walletsClient = new WalletsClient(this._url);
|
this._walletsClient = new WalletsClient(this._url);
|
||||||
this._paymentAccountsClient = new PaymentAccountsClient(this._url);
|
this._paymentAccountsClient = new PaymentAccountsClient(this._url);
|
||||||
@ -199,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.
|
* Get the current market price per 1 XMR in the given currency.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user