-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: persistent storage with leveldb * tests: leveldb store tests * chore: temporary add ci on base feat/new-storage-scheme * chore: update typescript * use rmdirSync on node < v14.14.0 * chore: remove node version 8 and 10 from ci * chore: remove v16 from ci * tests(integration): persistent storage * chore: review changes * feat: await rmdir * chore: remove blank line * chore: review changes * chore: remove unused generic db access * chore: add htr to tokens on constructor * chore: split nft creation fee from mint deposit * chore: await async methods * feat: process history using the storage util * feat: save address and history count on storage instead of calculating every call * chore: add delays * feat: only process walletData if there is something to process * chore: integration test delay funds * feat: actually increment counter when adding addresses * feat: save the index size on memory * chore: remove changes to force CI * chore: rename editToken and editAddress methods for leveldb store
- Loading branch information
Showing
26 changed files
with
2,317 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,6 @@ lib | |
*.swo | ||
|
||
tsconfig.tsbuildinfo | ||
|
||
// Generated test database files | ||
*.leveldb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { precalculationHelpers } from '../helpers/wallet-precalculation.helper'; | ||
import { GenesisWalletHelper } from '../helpers/genesis-wallet.helper'; | ||
import { | ||
createTokenHelper, | ||
DEFAULT_PASSWORD, | ||
DEFAULT_PIN_CODE, | ||
generateConnection, | ||
generateMultisigWalletHelper, | ||
generateWalletHelper, | ||
stopAllWallets, | ||
waitForTxReceived, | ||
waitForWalletReady, | ||
waitUntilNextTimestamp | ||
} from '../helpers/wallet.helper'; | ||
import { delay } from '../utils/core.util'; | ||
|
||
import { LevelDBStore, Storage } from '../../../src/storage'; | ||
import walletUtils from '../../../src/utils/wallet'; | ||
import HathorWallet from '../../../src/new/wallet'; | ||
import { loggers } from '../utils/logger.util'; | ||
|
||
const startedWallets = []; | ||
|
||
/** | ||
* Helper to stop wallets started manually in this test file. | ||
*/ | ||
async function stopWallets() { | ||
let hWallet; | ||
while (hWallet = startedWallets.pop()) { | ||
try { | ||
await hWallet.stop({ cleanStorage: true, cleanAddresses: true }); | ||
} catch (e) { | ||
loggers.test.error(e.stack); | ||
} | ||
} | ||
} | ||
|
||
describe('LevelDB persistent store', () => { | ||
afterEach(async () => { | ||
await stopWallets(); | ||
await stopAllWallets(); | ||
await GenesisWalletHelper.clearListeners(); | ||
}); | ||
|
||
it('should receive and send tokens', async () => { | ||
const DATA_DIR = './testdata.leveldb'; | ||
const walletData = precalculationHelpers.test.getPrecalculatedWallet(); | ||
const xpubkey = walletUtils.getXPubKeyFromSeed(walletData.words, { accountDerivationIndex: '0\'/0' }); | ||
const store = new LevelDBStore(DATA_DIR, xpubkey); | ||
const storage = new Storage(store); | ||
|
||
// Start the wallet | ||
const walletConfig = { | ||
seed: walletData.words, | ||
connection: generateConnection(), | ||
password: DEFAULT_PASSWORD, | ||
pinCode: DEFAULT_PIN_CODE, | ||
preCalculatedAddresses: walletData.addresses, | ||
storage, | ||
}; | ||
const hWallet = new HathorWallet(walletConfig); | ||
await hWallet.start(); | ||
startedWallets.push(hWallet); | ||
await waitForWalletReady(hWallet); | ||
|
||
// Expect to have an empty list for the full history | ||
expect(Object.keys(hWallet.getFullHistory())).toHaveLength(0); | ||
|
||
// Injecting some funds on this wallet | ||
await GenesisWalletHelper.injectFunds(await hWallet.getAddressAtIndex(1), 10); | ||
|
||
await delay(100); | ||
// Validating the full history increased in one | ||
expect(Object.keys(await hWallet.getFullHistory())).toHaveLength(1); | ||
|
||
const tx1 = await hWallet.sendTransaction(await hWallet.getAddressAtIndex(3), 5); | ||
await waitForTxReceived(hWallet, tx1.hash); | ||
expect(Object.keys(await hWallet.getFullHistory())).toHaveLength(2); | ||
|
||
await expect(store.getTx(tx1.hash)).resolves.not.toBeNull(); | ||
}); | ||
}); |
Oops, something went wrong.