Add API functions to register arbitrator and mediator keys

This commit is contained in:
duriancrepe 2022-01-02 13:47:43 -08:00
parent 8272484c3e
commit 34a76819bd
3 changed files with 65 additions and 5 deletions

View File

@ -28,7 +28,7 @@ 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.
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`
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`.

View File

@ -88,7 +88,9 @@ const TestConfig = {
["8084", ["10003", "7779"]],
["8085", ["10004", "7780"]],
["8086", ["10005", "7781"]],
])
]),
// from DEV_PRIVILEGE_PRIV_KEY
devPrivPrivateKey: "6ac43ea1df2a290c1c8391736aa42e4339c5cb4f110ff0257a13b63211977b7a"
};
interface TxContext {
@ -162,6 +164,43 @@ 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 () => {
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);
} catch (err) {
console.log("Error registering dispute agent:", err.message);
}
console.log("Dispute agent registration complete");
try {
console.log("Registering dispute agent with bad key");
await arbitrator.registerDisputeAgent("mediator", "bad key");
throw Error("unexpected")
} catch (err) {
if (err.message === "unexpected") throw Error("Unexpected error: registered dispute agent with bad key");
expect(err.message).toEqual("invalid registration key");
}
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 () => {
// get all market prices

View File

@ -1,7 +1,7 @@
import {HavenoUtils} from "./HavenoUtils";
import * as grpcWeb from 'grpc-web';
import {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} from './protobuf/grpc_pb';
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 {PaymentAccount, AvailabilityResult} from './protobuf/pb_pb';
const console = require('console');
@ -22,6 +22,7 @@ class HavenoDaemon {
_paymentAccountsClient: PaymentAccountsClient;
_offersClient: OffersClient;
_tradesClient: TradesClient;
_disputeAgentsClient: DisputeAgentsClient;
/**
* Construct a client connected to a Haveno daemon.
@ -41,6 +42,7 @@ class HavenoDaemon {
this._paymentAccountsClient = new PaymentAccountsClient(this._url);
this._offersClient = new OffersClient(this._url);
this._tradesClient = new TradesClient(this._url);
this._disputeAgentsClient = new DisputeAgentsClient(this._url);
}
/**
@ -229,7 +231,6 @@ class HavenoDaemon {
});
});
}
/**
* Get the user's balances.
*
@ -547,6 +548,26 @@ 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};