Skip to content

Commit 2643791

Browse files
Alex-WernerIgor Markin
andauthored
feat(wallet-lib)!: storage layer refactoring (#232)
Co-authored-by: Igor Markin <igor.markin@dash.org>
1 parent a6acd1a commit 2643791

200 files changed

Lines changed: 2967 additions & 5165 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/js-dash-sdk/src/SDK/Client/Client.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('Dash - Client', function suite() {
3737

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

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

151151
it('should throw TransitionBroadcastError when transport resolves error', async () => {

packages/js-dash-sdk/src/SDK/Client/Platform/methods/identities/register.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ export default async function register(
3636
await broadcastStateTransition(this, identityCreateTransition);
3737

3838
// If state transition was broadcast without any errors, import identity to the account
39-
account.storage.insertIdentityIdAtIndex(
40-
account.walletId,
41-
identity.getId().toString(),
42-
identityIndex,
39+
account.storage
40+
.getWalletStore(account.walletId)
41+
.insertIdentityIdAtIndex(
42+
identity.getId().toString(),
43+
identityIndex,
4344
);
4445

4546
return identity;

packages/js-dash-sdk/src/SDK/SDK.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { default as _DAPIClient } from '@dashevo/dapi-client';
66
import {
77
Wallet as _Wallet,
88
Account as _Account,
9-
KeyChain as _KeyChain,
9+
DerivableKeyChain as _KeyChain,
1010
CONSTANTS as _WalletLibCONSTANTS,
1111
EVENTS as _WalletLibEVENTS,
1212
utils as _WalletLibUtils,

packages/js-dash-sdk/src/test/fixtures/createIdentityFixtureInAccount.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const getIdentityFixture = require('@dashevo/dpp/lib/test/fixtures/getIdentityFi
44

55
export function createIdentityFixtureInAccount(account) {
66
const identityFixture = getIdentityFixture();
7-
const identityFixtureIndex = 10000;
7+
const identityFixtureIndex = 0;
88
const { privateKey: identityPrivateKey } = account.identities.getIdentityHDKeyByIndex(identityFixtureIndex, 0);
99

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

18-
account.storage.insertIdentityIdAtIndex(
19-
account.walletId,
18+
account.storage
19+
.getWalletStore(account.walletId)
20+
.insertIdentityIdAtIndex(
2021
identityFixture.getId().toString(),
2122
identityFixtureIndex,
2223
);

packages/js-dash-sdk/src/test/fixtures/createTransactionFixtureInAccount.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export async function createTransactionInAccount(account) {
1111
}])
1212
.to(account.getAddress(10).address, 100000);
1313

14-
await account.importTransactions([walletTransaction.serialize(true)]);
14+
await account.importTransactions([[walletTransaction.serialize(true)]]);
1515

1616
return walletTransaction;
17-
}
17+
}

packages/platform-test-suite/test/e2e/wallet.spec.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,17 @@ describe('e2e', () => {
105105

106106
restoredAccount = await restoredWallet.getWalletAccount();
107107

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

114-
const transactionIds = Object.keys(restoredAccount.getTransactions());
118+
const transactionIds = Object.keys(transactions);
115119

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

packages/platform-test-suite/test/functional/platform/Identity.spec.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ const BalanceIsNotEnoughError = require('@dashevo/dpp/lib/errors/consensus/fee/B
1515
const DAPIClient = require('@dashevo/dapi-client/lib/DAPIClient');
1616
const { hash } = require('@dashevo/dpp/lib/util/hash');
1717
const Identifier = require('@dashevo/dpp/lib/identifier/Identifier');
18+
const Transaction = require('@dashevo/dashcore-lib/lib/transaction');
1819
const createClientWithFundedWallet = require('../../../lib/test/createClientWithFundedWallet');
1920
const wait = require('../../../lib/wait');
2021
const getDAPISeeds = require('../../../lib/test/getDAPISeeds');
21-
const Transaction = require('@dashevo/dashcore-lib/lib/transaction');
2222

2323
describe('Platform', () => {
2424
describe('Identity', () => {
@@ -114,11 +114,12 @@ describe('Platform', () => {
114114
await wait(5000);
115115
}
116116

117-
walletAccount.storage.insertIdentityIdAtIndex(
118-
walletAccount.walletId,
119-
identityOne.getId().toString(),
120-
identityOneIndex,
121-
);
117+
walletAccount.storage
118+
.getWalletStore(walletAccount.walletId)
119+
.insertIdentityIdAtIndex(
120+
identityOne.getId().toString(),
121+
identityOneIndex,
122+
);
122123

123124
// Creating transition that tries to spend the same transaction
124125
const {

0 commit comments

Comments
 (0)