@alephium/web3-test
Version:
Utility functions for Alephium test
56 lines (52 loc) • 2.66 kB
JavaScript
;
/*
Copyright 2018 - 2022 The Alephium Authors
This file is part of the alephium project.
The library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the library. If not, see <http://www.gnu.org/licenses/>.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.testPrivateKeyWallet = exports.testPassword = exports.testPrivateKey = exports.testAddress = exports.testWalletName = exports.testMnemonic = exports.testPrivateKeys = void 0;
exports.tryGetDevnetNodeProvider = tryGetDevnetNodeProvider;
const web3_1 = require("@alephium/web3");
const web3_wallet_1 = require("@alephium/web3-wallet");
exports.testPrivateKeys = [
'a642942e67258589cd2b1822c631506632db5a12aabcf413604e785300d762a5',
'ec8c4e863e4027d5217c382bfc67bd2638f21d6f956653505229f1d242123a9a',
'bd7dd0c4abd3cf8ba2d169c8320a2cc8bc8ab583b0db9a32d4352d6f5b15d037',
'93ae1392f36a592aca154ea14e51b791c248beaea1b63117c57cc46d56e5f482'
];
exports.testMnemonic = 'vault alarm sad mass witness property virus style good flower rice alpha viable evidence run glare pretty scout evil judge enroll refuse another lava';
exports.testWalletName = 'alephium-web3-test-only-wallet';
exports.testAddress = '1DrDyTr9RpRsQnDnXo2YRiPzPW4ooHX5LLoqXrqfMrpQH';
exports.testPrivateKey = exports.testPrivateKeys[0];
exports.testPassword = 'alph';
exports.testPrivateKeyWallet = new web3_wallet_1.PrivateKeyWallet({ privateKey: exports.testPrivateKey });
async function tryGetDevnetNodeProvider() {
const currentNodeProvider = (() => {
try {
return web3_1.web3.getCurrentNodeProvider();
}
catch (err) {
return undefined;
}
})();
if (currentNodeProvider === undefined) {
const nodeProvider = new web3_1.NodeProvider('http://127.0.0.1:22973');
web3_1.web3.setCurrentNodeProvider(nodeProvider);
return nodeProvider;
}
const chainParams = await currentNodeProvider.infos.getInfosChainParams();
if (chainParams.networkId === 0 || chainParams.networkId === 1) {
throw new Error('Invalid network, expect devnet');
}
return currentNodeProvider;
}