Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
feat!: update plugin injection and additional test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Werner committed Nov 29, 2021
1 parent 0349d5a commit f9eb15d
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 42 deletions.
1 change: 0 additions & 1 deletion src/CONSTANTS.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ const CONSTANTS = {
],
UNSAFE_PROPERTIES: [
'storage',
'keyChain',
'identities',
],
SAFE_PROPERTIES: [
Expand Down
11 changes: 6 additions & 5 deletions src/plugins/Workers/IdentitySyncWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ class IdentitySyncWorker extends Worker {
logger.silly(`IdentitySyncWorker - got ${Identifier.from(fetchedId)} at ${index}`);

// eslint-disable-next-line no-await-in-loop
await this.storage.insertIdentityIdAtIndex(
this.walletId,
Identifier.from(fetchedId).toString(),
index,
);
await this.storage
.getWalletStore(this.walletId)
.insertIdentityIdAtIndex(
Identifier.from(fetchedId).toString(),
index,
);
}

logger.silly('IdentitySyncWorker - sync finished');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ describe('transports - DAPIClientTransport .getTransaction', function suite() {
expect(res.transaction.hash).to.equal('2c0ee853b91b23d881f96f0128bbb5ebb90c9ef7e7bdb4eda360b0e5abf97239');
expect(res.blockHash).to.equal('4f46066bd50cc2684484407696b7949e82bd906ea92c040f59a97cba47ed8176');
expect(res.height).to.equal(42);
expect(res.instantLocked).to.equal(true);
expect(res.chainLocked).to.equal(false);
expect(res.isInstantLocked).to.equal(true);
expect(res.isChainLocked).to.equal(false);
});

it('should return null if transaction if not found', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/types/Account/Account.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,10 @@ class Account extends EventEmitter {
*/
waitForInstantLock(transactionHash, timeout = this.waitForInstantLockTimeout) {
let rejectTimeout;

const chainStore = this.storage.getChainStore(this.network);
return Promise.race([
new Promise((resolve) => {
const instantLock = this.storage.getInstantLock(transactionHash);
const instantLock = chainStore.getInstantLock(transactionHash);
if (instantLock != null) {
clearTimeout(rejectTimeout);
resolve(instantLock);
Expand Down
15 changes: 12 additions & 3 deletions src/types/Account/Account.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const { WALLET_TYPES } = require('../../CONSTANTS');
const { Account, EVENTS } = require('../../index');
const EventEmitter = require('events');
const inMem = require('../../adapters/InMem');
const Storage = require('../Storage/Storage');
const {mock} = require("sinon");
const KeyChainStore = require("../KeyChainStore/KeyChainStore");
const KeyChain = require("../KeyChain/KeyChain");
const blockHeader = new Dashcore.BlockHeader.fromObject({
hash: '00000ac3a0c9df709260e41290d6902e5a4a073099f11fe8c1ce80aadc4bb331',
version: 2,
Expand All @@ -29,7 +33,7 @@ describe('Account - class', function suite() {
const mockStorage = {
on: emitter.on,
emit: emitter.emit,
store: {},
storage: new Storage(),
getStore: () => {},
saveState: () => {},
stopWorker: () => {},
Expand All @@ -43,8 +47,13 @@ describe('Account - class', function suite() {
this.walletType = WALLET_TYPES.HDWALLET;
this.accounts = [];
this.network = Dashcore.Networks.testnet;
this.storage = mockStorage;
this.storage = new Storage();
})());
mocks.wallet.storage.application.network = mocks.wallet.network;
mocks.wallet.storage.createWalletStore(mocks.wallet.walletId);
mocks.wallet.storage.createChainStore(mocks.wallet.network);
mocks.wallet.keyChainStore = new KeyChainStore()
mocks.wallet.keyChainStore.addKeyChain(new KeyChain({mnemonic: fluidMnemonic.mnemonic}), { isMasterKeyChain: true })
});
it('should be specify on missing params', () => {
const expectedException1 = 'Expected wallet to be passed as param';
Expand Down Expand Up @@ -96,7 +105,7 @@ describe('Account - class', function suite() {
await account.on(EVENTS.BLOCKHEADER, ()=>{
done();
});
account.storage.importBlockHeader(blockHeader);
account.storage.getChainStore(account.network).importBlockHeader(blockHeader);
})

});
Expand Down
2 changes: 1 addition & 1 deletion src/types/Account/methods/broadcastTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function impactAffectedInputs({ transaction }) {
*/
async function broadcastTransaction(transaction, options = {}) {
const { network, storage } = this;
// if (!this.transport) throw new ValidTransportLayerRequired('broadcast');
if (!this.transport) throw new ValidTransportLayerRequired('broadcast');

// We still support having in rawtransaction, if this is the case
// we first need to reform our object
Expand Down
38 changes: 12 additions & 26 deletions src/types/Account/methods/broadcastTransaction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const broadcastTransaction = require('./broadcastTransaction');
const validRawTxs = require('../../../../fixtures/rawtx').valid;
const invalidRawTxs = require('../../../../fixtures/rawtx').invalid;
const expectThrowsAsync = require('../../../utils/expectThrowsAsync');

const ChainStore = require('../../ChainStore/ChainStore');
const { PrivateKey } = Dashcore;

describe('Account - broadcastTransaction', function suite() {
Expand All @@ -14,12 +14,14 @@ describe('Account - broadcastTransaction', function suite() {
let keysToSign;
let oneToOneTx;
let fee;
// const storage = new Storage();
// storage.createChainStore('testnet')
// storage.getChainStore('testnet').state.fees.minRelay = 888;
const chainStore = new ChainStore('testnet');
chainStore.state.fees.minRelay = 888;
chainStore.importAddress('yTBXsrcGw74yMUsK34fBKAWJx3RNCq97Aq');
const storage = {
getStore: ()=>({
chains:{
"testnet": { fees: { minRelay: 888 }}
}
})
getChainStore:()=> chainStore
}
beforeEach(() => {
utxos = [
Expand Down Expand Up @@ -87,11 +89,7 @@ describe('Account - broadcastTransaction', function suite() {
sendTransaction: () => sendCalled = +1,
},
network: 'testnet',
storage: {
getStore: storage.getStore,
searchAddress: () => { searchCalled = +1; return { found: false }; },
searchAddressesWithTx: () => { searchCalled = +1; return { results: [] }; },
},
storage
};

const tx = oneToOneTx;
Expand All @@ -109,11 +107,7 @@ describe('Account - broadcastTransaction', function suite() {
sendTransaction: () => sendCalled = +1,
},
network: 'testnet',
storage: {
getStore: storage.getStore,
searchAddress: () => { searchCalled = +1; return { found: false }; },
searchAddressesWithTx: (affectedTxId) => { searchCalled = +1; return { results: [] }; },
},
storage
};

return broadcastTransaction
Expand All @@ -132,11 +126,7 @@ describe('Account - broadcastTransaction', function suite() {
sendTransaction: () => sendCalled = +1,
},
network: 'testnet',
storage: {
getStore: storage.getStore,
searchAddress: () => { searchCalled = +1; return { found: false }; },
searchAddressesWithTx: () => { searchCalled = +1; return { results: [] }; },
},
storage
};

const tx = oneToOneTx;
Expand All @@ -151,11 +141,7 @@ describe('Account - broadcastTransaction', function suite() {
sendTransaction: () => sendCalled = +1,
},
network: 'testnet',
storage: {
getStore: storage.getStore,
searchAddress: () => { searchCalled = +1; return { found: false }; },
searchAddressesWithTx: () => { searchCalled = +1; return { results: [] }; },
},
storage
};

const tx = oneToOneTx;
Expand Down
2 changes: 1 addition & 1 deletion src/types/Account/methods/getUnusedIdentityIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async function getUnusedIdentityIndex() {
// Force identities sync before return unused index
await this.getWorker('IdentitySyncWorker').execWorker();

const identityIds = this.storage.getIndexedIdentityIds(this.walletId);
const identityIds = this.storage.getWalletStore(this.walletId).getIndexedIdentityIds();

const firstMissingIndex = identityIds.findIndex((identityId) => !identityId);

Expand Down
1 change: 1 addition & 0 deletions src/types/ChainStore/methods/importInstantLock.spec.js

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

2 changes: 2 additions & 0 deletions src/types/Storage/Storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ Storage.prototype.createChainStore = require('./methods/createChainStore');
Storage.prototype.createWalletStore = require('./methods/createWalletStore');
Storage.prototype.getChainStore = require('./methods/getChainStore');
Storage.prototype.getWalletStore = require('./methods/getWalletStore');
Storage.prototype.rehydrateState = require('./methods/rehydrateState');
Storage.prototype.saveState = require('./methods/saveState');

module.exports = Storage;
2 changes: 1 addition & 1 deletion src/types/WalletStore/WalletStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class WalletStore {
return this.state.identities.get(identityIndex);
}

insertIdentityAtIndex(identityId, identityIndex) {
insertIdentityIdAtIndex(identityId, identityIndex) {
const existingId = this.getIdentityIdByIndex(identityIndex);

if (Boolean(existingId) && existingId !== identityId) {
Expand Down

0 comments on commit f9eb15d

Please sign in to comment.