Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/js-dash-sdk/src/SDK/Client/Client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Dash - Client', function suite() {

beforeEach(async function beforeEach() {
testMnemonic = 'agree country attract master mimic ball load beauty join gentle turtle hover';
testHDKey = "xprv9s21ZrQH143K4PgfRZPuYjYUWRZkGfEPuWTEUESMoEZLC274ntC4G49qxgZJEPgmujsmY52eVggtwZgJPrWTMXmbYgqDVySWg46XzbGXrSZ";
testHDKey = "tprv8ZgxMBicQKsPeGi4CikhacVPz6UmErenu1PoD3S4XcEDSPP8auRaS8hG3DQtsQ2i9HACgohHwF5sgMVJNksoKqYoZbis8o75Pp1koCme2Yo";

client = new Client({
wallet: {
Expand Down Expand Up @@ -145,7 +145,7 @@ describe('Dash - Client', function suite() {
const importedIdentityIds = account.identities.getIdentityIds();
// Check that we've imported identities properly
expect(importedIdentityIds.length).to.be.equal(accountIdentitiesCountBeforeTest + 1);
expect(importedIdentityIds[0]).to.be.equal(interceptedIdentityStateTransition.getIdentityId().toString());
expect(importedIdentityIds[1]).to.be.equal(interceptedIdentityStateTransition.getIdentityId().toString());
});

it('should throw TransitionBroadcastError when transport resolves error', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,20 @@ export default async function register(
await broadcastStateTransition(this, identityCreateTransition);

// If state transition was broadcast without any errors, import identity to the account
account.storage.insertIdentityIdAtIndex(
account.walletId,
identity.getId().toString(),
identityIndex,
account.storage
.getWalletStore(account.walletId)
.insertIdentityIdAtIndex(
identity.getId().toString(),
identityIndex,
);

// Current identity object will not have metadata or balance information
const registeredIdentity = await this.identities.get(identity.getId().toString());

// We cannot just return registeredIdentity as we want to
// keep additional information (assetLockProof and transaction) instance
identity.setMetadata(registeredIdentity.metadata);
identity.setBalance(registeredIdentity.balance);

return identity;
}
2 changes: 1 addition & 1 deletion packages/js-dash-sdk/src/SDK/SDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { default as _DAPIClient } from '@dashevo/dapi-client';
import {
Wallet as _Wallet,
Account as _Account,
KeyChain as _KeyChain,
DerivableKeyChain as _KeyChain,
CONSTANTS as _WalletLibCONSTANTS,
EVENTS as _WalletLibEVENTS,
utils as _WalletLibUtils,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const getIdentityFixture = require('@dashevo/dpp/lib/test/fixtures/getIdentityFi

export function createIdentityFixtureInAccount(account) {
const identityFixture = getIdentityFixture();
const identityFixtureIndex = 10000;
const identityFixtureIndex = 0;
const { privateKey: identityPrivateKey } = account.identities.getIdentityHDKeyByIndex(identityFixtureIndex, 0);

identityFixture.publicKeys[0] = new IdentityPublicKey({
Expand All @@ -15,8 +15,9 @@ export function createIdentityFixtureInAccount(account) {
securityLevel: IdentityPublicKey.SECURITY_LEVELS.MASTER
});

account.storage.insertIdentityIdAtIndex(
account.walletId,
account.storage
.getWalletStore(account.walletId)
.insertIdentityIdAtIndex(
identityFixture.getId().toString(),
identityFixtureIndex,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function createTransactionInAccount(account) {
}])
.to(account.getAddress(10).address, 100000);

await account.importTransactions([walletTransaction.serialize(true)]);
await account.importTransactions([[walletTransaction.serialize(true)]]);

return walletTransaction;
}
}
3 changes: 3 additions & 0 deletions packages/platform-test-suite/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ DASHPAY_OWNER_PRIVATE_KEY=
# MASTERNODE_REWARD_SHARES_OWNER_PRO_REG_TX_HASH=
# MASTERNODE_REWARD_SHARES_OWNER_PRIVATE_KEY=
# MASTERNODE_REWARD_SHARES_MN_OWNER_PRIVATE_KEY=

# Enable storage for faucet wallet
# FAUCET_WALLET_USE_STORAGE=true
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ const getDAPISeeds = require('./getDAPISeeds');

const createFaucetClient = require('./createFaucetClient');

let faucetClient;

/**
* Create and fund DashJS client
* @param {string} [HDPrivateKey]
*
* @param {number} [amount] - amount of Duffs to fund wallet with
* @returns {Promise<Client>}
*/
async function createClientWithFundedWallet(HDPrivateKey = undefined) {
async function createClientWithFundedWallet(HDPrivateKey = undefined, amount = 40000) {
const useFaucetWalletStorage = process.env.FAUCET_WALLET_USE_STORAGE === "true"
const seeds = getDAPISeeds();

const clientOpts = {
Expand All @@ -29,7 +32,9 @@ async function createClientWithFundedWallet(HDPrivateKey = undefined) {
},
};

const faucetClient = createFaucetClient();
if (!faucetClient || (faucetClient && useFaucetWalletStorage)) {
faucetClient = createFaucetClient();
}

const walletOptions = {
waitForInstantLockTimeout: 120000,
Expand All @@ -52,10 +57,12 @@ async function createClientWithFundedWallet(HDPrivateKey = undefined) {
wallet: walletOptions,
});

const amount = 40000;

await fundWallet(faucetClient.wallet, client.wallet, amount);

if (useFaucetWalletStorage) {
await faucetClient.wallet.disconnect();
}

return client;
}

Expand Down
19 changes: 15 additions & 4 deletions packages/platform-test-suite/lib/test/createFaucetClient.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
const Dash = require('dash');

let storageAdapter;

if (typeof window === 'undefined') {
// eslint-disable-next-line global-require
const { NodeForage } = require('nodeforage');
storageAdapter = new NodeForage({ name: `faucet-wallet-${process.env.FAUCET_ADDRESS}` });
} else {
// eslint-disable-next-line global-require
storageAdapter = require('localforage');
}

const { contractId } = require('@dashevo/dpns-contract/lib/systemIds');

const getDAPISeeds = require('./getDAPISeeds');

let faucetClient;

function createFaucetClient() {
if (faucetClient) {
return faucetClient;
}

const seeds = getDAPISeeds();

const clientOpts = {
Expand All @@ -27,6 +34,10 @@ function createFaucetClient() {
privateKey: process.env.FAUCET_PRIVATE_KEY,
};

if (process.env.FAUCET_WALLET_USE_STORAGE === "true") {
walletOptions.adapter = storageAdapter;
}

if (process.env.SKIP_SYNC_BEFORE_HEIGHT) {
walletOptions.unsafeOptions = {
skipSynchronizationBeforeHeight: process.env.SKIP_SYNC_BEFORE_HEIGHT,
Expand Down
2 changes: 2 additions & 0 deletions packages/platform-test-suite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@
"karma-mocha-reporter": "^2.2.5",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^5.0.0",
"localforage": "^1.10.0",
"mocha": "^9.1.2",
"net": "^1.0.2",
"nodeforage": "^1.1.1",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"process": "^0.11.10",
Expand Down
2 changes: 1 addition & 1 deletion packages/platform-test-suite/test/e2e/wallet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('e2e', () => {

mnemonic = emptyWallet.wallet.exportWallet();
const { storage } = fundedWallet.wallet;
emptyWalletHeight = storage.store.chains[storage.network].blockHeight;
emptyWalletHeight = storage.getChainStore(storage.application.network).state.blockHeight;
});

// Skip test if any prior test in this describe failed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@ const {
PrivateKey,
} = require('@dashevo/dashcore-lib');

const createFaucetClient = require('../../../lib/test/createFaucetClient');
const createClientWithFundedWallet = require('../../../lib/test/createClientWithFundedWallet');

describe('Core', () => {
describe('broadcastTransaction', () => {
let faucetClient;
let client;

before(() => {
faucetClient = createFaucetClient();
before(async () => {
client = await createClientWithFundedWallet();
});

after(async () => {
await client.disconnect();
});

it('should sent transaction and return transaction ID', async () => {
const faucetWalletAccount = await faucetClient.getWalletAccount();
const account = await client.getWalletAccount();

const transaction = faucetWalletAccount.createTransaction({
const transaction = account.createTransaction({
recipient: new PrivateKey().toAddress(process.env.NETWORK),
satoshis: 10000,
});

const dapiClient = faucetClient.getDAPIClient();
const dapiClient = client.getDAPIClient();

const transactionId = await dapiClient.core.broadcastTransaction(transaction.toBuffer());

Expand Down
Loading