mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-09-21 05:04:39 -04:00
test crypto account persistence
This commit is contained in:
parent
6235048fc5
commit
ce88deebac
2 changed files with 41 additions and 10 deletions
|
@ -227,6 +227,9 @@ test("Can manage an account", async () => {
|
||||||
assert(await charlie.accountExists());
|
assert(await charlie.accountExists());
|
||||||
assert(await charlie.isAccountOpen());
|
assert(await charlie.isAccountOpen());
|
||||||
|
|
||||||
|
// create payment account
|
||||||
|
let paymentAccount = await charlie.createCryptoPaymentAccount("My ETH account", TestConfig.cryptoAddresses[0].currencyCode, TestConfig.cryptoAddresses[0].address);
|
||||||
|
|
||||||
// close account
|
// close account
|
||||||
await charlie.closeAccount();
|
await charlie.closeAccount();
|
||||||
assert(await charlie.accountExists());
|
assert(await charlie.accountExists());
|
||||||
|
@ -298,6 +301,10 @@ test("Can manage an account", async () => {
|
||||||
assert(await charlie.accountExists());
|
assert(await charlie.accountExists());
|
||||||
await charlie.openAccount(password);
|
await charlie.openAccount(password);
|
||||||
assert(await charlie.isAccountOpen());
|
assert(await charlie.isAccountOpen());
|
||||||
|
|
||||||
|
// check the persisted payment account
|
||||||
|
let paymentAccount2 = await charlie.getPaymentAccount(paymentAccount.getId());
|
||||||
|
testCryptoPaymentAccountsEqual(paymentAccount, paymentAccount2);
|
||||||
} catch (err2) {
|
} catch (err2) {
|
||||||
console.log(err2);
|
console.log(err2);
|
||||||
err = err2;
|
err = err2;
|
||||||
|
@ -315,6 +322,8 @@ test("Can manage an account", async () => {
|
||||||
catch (err) { assert.equal(err.message, "Account not open"); }
|
catch (err) { assert.equal(err.message, "Account not open"); }
|
||||||
try { await havenod.getBalances(); throw new Error("Should have thrown"); }
|
try { await havenod.getBalances(); throw new Error("Should have thrown"); }
|
||||||
catch (err) { assert.equal(err.message, "Account not open"); }
|
catch (err) { assert.equal(err.message, "Account not open"); }
|
||||||
|
try { await havenod.createCryptoPaymentAccount("My ETH account", TestConfig.cryptoAddresses[0].currencyCode, TestConfig.cryptoAddresses[0].address); throw new Error("Should have thrown"); }
|
||||||
|
catch (err) { assert.equal(err.message, "Account not open"); }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -527,7 +536,7 @@ test("Can start and stop a local Monero node", async() => {
|
||||||
|
|
||||||
// expect settings are updated
|
// expect settings are updated
|
||||||
let settingsAfter = await alice.getMoneroNodeSettings();
|
let settingsAfter = await alice.getMoneroNodeSettings();
|
||||||
testMoneroNodeSettings(settings, settingsAfter!);
|
testMoneroNodeSettingsEqual(settings, settingsAfter!);
|
||||||
|
|
||||||
// expect connections to be unmodified by local node
|
// expect connections to be unmodified by local node
|
||||||
let connectionsAfter = await alice.getMoneroConnections();
|
let connectionsAfter = await alice.getMoneroConnections();
|
||||||
|
@ -1977,15 +1986,22 @@ function getOffer(offers: OfferInfo[], id: string): OfferInfo | undefined {
|
||||||
return offers.find(offer => offer.getId() === id);
|
return offers.find(offer => offer.getId() === id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testCryptoPaymentAccount(paymentAccount: PaymentAccount) {
|
function testCryptoPaymentAccount(acct: PaymentAccount) {
|
||||||
expect(paymentAccount.getId().length).toBeGreaterThan(0);
|
expect(acct.getId().length).toBeGreaterThan(0);
|
||||||
expect(paymentAccount.getAccountName().length).toBeGreaterThan(0);
|
expect(acct.getAccountName().length).toBeGreaterThan(0);
|
||||||
expect(paymentAccount.getPaymentAccountPayload()!.getCryptoCurrencyAccountPayload()!.getAddress().length).toBeGreaterThan(0);
|
expect(acct.getPaymentAccountPayload()!.getCryptoCurrencyAccountPayload()!.getAddress().length).toBeGreaterThan(0);
|
||||||
expect(paymentAccount.getSelectedTradeCurrency()!.getCode().length).toBeGreaterThan(0);
|
expect(acct.getSelectedTradeCurrency()!.getCode().length).toBeGreaterThan(0);
|
||||||
expect(paymentAccount.getTradeCurrenciesList().length).toEqual(1);
|
expect(acct.getTradeCurrenciesList().length).toEqual(1);
|
||||||
let tradeCurrency = paymentAccount.getTradeCurrenciesList()[0];
|
let tradeCurrency = acct.getTradeCurrenciesList()[0];
|
||||||
expect(tradeCurrency.getName().length).toBeGreaterThan(0);
|
expect(tradeCurrency.getName().length).toBeGreaterThan(0);
|
||||||
expect(tradeCurrency.getCode()).toEqual(paymentAccount.getSelectedTradeCurrency()!.getCode());
|
expect(tradeCurrency.getCode()).toEqual(acct.getSelectedTradeCurrency()!.getCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
function testCryptoPaymentAccountsEqual(acct1: PaymentAccount, acct2: PaymentAccount) {
|
||||||
|
expect(acct1.getId()).toEqual(acct2.getId());
|
||||||
|
expect(acct1.getAccountName()).toEqual(acct2.getAccountName());
|
||||||
|
expect(acct1.getSelectedTradeCurrency()!.getCode()).toEqual(acct2.getSelectedTradeCurrency()!.getCode());
|
||||||
|
expect(acct1.getPaymentAccountPayload()!.getCryptoCurrencyAccountPayload()!.getAddress()).toEqual(acct2.getPaymentAccountPayload()!.getCryptoCurrencyAccountPayload()!.getAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
function testOffer(offer: OfferInfo, config?: any) {
|
function testOffer(offer: OfferInfo, config?: any) {
|
||||||
|
@ -2076,7 +2092,7 @@ async function testTradeChat(tradeId: string, alice: HavenoClient, bob: HavenoCl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function testMoneroNodeSettings(settingsBefore: MoneroNodeSettings, settingsAfter: MoneroNodeSettings) {
|
function testMoneroNodeSettingsEqual(settingsBefore: MoneroNodeSettings, settingsAfter: MoneroNodeSettings) {
|
||||||
expect(settingsBefore.getBlockchainPath()).toEqual(settingsAfter.getBlockchainPath());
|
expect(settingsBefore.getBlockchainPath()).toEqual(settingsAfter.getBlockchainPath());
|
||||||
expect(settingsBefore.getBootstrapUrl()).toEqual(settingsAfter.getBootstrapUrl());
|
expect(settingsBefore.getBootstrapUrl()).toEqual(settingsAfter.getBootstrapUrl());
|
||||||
expect(settingsBefore.getStartupFlagsList()).toEqual(settingsAfter.getStartupFlagsList());
|
expect(settingsBefore.getStartupFlagsList()).toEqual(settingsAfter.getStartupFlagsList());
|
||||||
|
|
|
@ -837,6 +837,21 @@ class HavenoClient {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a payment account by id.
|
||||||
|
*
|
||||||
|
* @param {string} paymentAccountId - the payment account id to get
|
||||||
|
* @return {PaymentAccount} the payment account
|
||||||
|
*/
|
||||||
|
async getPaymentAccount(paymentAccountId: string): Promise<PaymentAccount> {
|
||||||
|
// TODO (woodser): implement this on the backend
|
||||||
|
let paymentAccounts = await this.getPaymentAccounts();
|
||||||
|
for (let paymentAccount of paymentAccounts) {
|
||||||
|
if (paymentAccount.getId() === paymentAccountId) return paymentAccount;
|
||||||
|
}
|
||||||
|
throw new Error("No payment account with id " + paymentAccountId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a form for the given payment method to complete and create a new payment account.
|
* Get a form for the given payment method to complete and create a new payment account.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue