Skip to content

Commit

Permalink
feat(wallet-lib)!: storage layer refactoring (#232)
Browse files Browse the repository at this point in the history
Co-authored-by: Igor Markin <[email protected]>
  • Loading branch information
Alex-Werner and markin-io authored Mar 8, 2022
1 parent a6acd1a commit 2643791
Show file tree
Hide file tree
Showing 200 changed files with 2,967 additions and 5,165 deletions.
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,10 +36,11 @@ 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,
);

return identity;
Expand Down
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;
}
}
14 changes: 9 additions & 5 deletions packages/platform-test-suite/test/e2e/wallet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,17 @@ describe('e2e', () => {

restoredAccount = await restoredWallet.getWalletAccount();

// Due to the limitations of DAPI, we need to wait for a block to be mined if we connected
// in the moment when transaction already entered the mempool, but haven't been mined yet
await new Promise((resolve) => restoredAccount.once(EVENTS.BLOCKHEADER, resolve));

let transactions = restoredAccount.getTransactions();

if (Object.keys(transactions).length === 0) {
// Due to the limitations of DAPI, we need to wait for a block to be mined if we connected
// in the moment when transaction already entered the mempool, but haven't been mined yet
await new Promise((resolve) => restoredAccount.once(EVENTS.BLOCKHEADER, resolve));
transactions = restoredAccount.getTransactions();
}
await waitForBalanceToChange(restoredAccount);

const transactionIds = Object.keys(restoredAccount.getTransactions());
const transactionIds = Object.keys(transactions);

expect(transactionIds).to.have.lengthOf(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const BalanceIsNotEnoughError = require('@dashevo/dpp/lib/errors/consensus/fee/B
const DAPIClient = require('@dashevo/dapi-client/lib/DAPIClient');
const { hash } = require('@dashevo/dpp/lib/util/hash');
const Identifier = require('@dashevo/dpp/lib/identifier/Identifier');
const Transaction = require('@dashevo/dashcore-lib/lib/transaction');
const createClientWithFundedWallet = require('../../../lib/test/createClientWithFundedWallet');
const wait = require('../../../lib/wait');
const getDAPISeeds = require('../../../lib/test/getDAPISeeds');
const Transaction = require('@dashevo/dashcore-lib/lib/transaction');

describe('Platform', () => {
describe('Identity', () => {
Expand Down Expand Up @@ -114,11 +114,12 @@ describe('Platform', () => {
await wait(5000);
}

walletAccount.storage.insertIdentityIdAtIndex(
walletAccount.walletId,
identityOne.getId().toString(),
identityOneIndex,
);
walletAccount.storage
.getWalletStore(walletAccount.walletId)
.insertIdentityIdAtIndex(
identityOne.getId().toString(),
identityOneIndex,
);

// Creating transition that tries to spend the same transaction
const {
Expand Down
Loading

0 comments on commit 2643791

Please sign in to comment.