Created
August 19, 2022 12:54
-
-
Save rithvikvibhu/9f891202a430a50af3a1cc6375f0dfe3 to your computer and use it in GitHub Desktop.
Bob setup chain for testing
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
// Based on hsd/test/wallet-auction-test.js (hsd 686, #764) | |
// Opens 800 names and places 2 bids per name | |
// After running this, refresh Bob and try other bulk actions (reveal all, etc.) | |
const { WalletClient, NodeClient } = require('hs-client'); | |
const { Address, Network } = require('hsd'); | |
// Edit these: | |
const NETWORK = 'regtest'; | |
const API_KEY = 'apikey'; | |
const WALLET_NAME = 'walletname'; | |
const WALLET_PASSPHRASE = 'walletpass'; | |
/** @type {import('hsd/lib/protocol/network')} */ | |
const network = Network.get(NETWORK); | |
const nodeClient = new NodeClient({ | |
network: network.type, | |
port: network.rpcPort, | |
apiKey: API_KEY, | |
}); | |
const walletClient = new WalletClient({ | |
network: network.type, | |
port: network.walletPort, | |
apiKey: API_KEY, | |
}); | |
const wallet = walletClient.wallet(WALLET_NAME); | |
async function printInfo() { | |
const { chain } = await nodeClient.getInfo(); | |
// console.log(chain); | |
const account = await wallet.getAccount('default'); | |
// console.log(account); | |
console.log(`chain: `, `height=${chain.height}`) | |
console.log(`wallet:`, `receive=${account.receiveDepth}`, `change=${account.changeDepth}`, `txs=${account.balance.tx}`, `coins=${account.balance.coin}`) | |
} | |
async function mineBlocks(num, own = false) { | |
const address = own ? (await wallet.createAddress('default')).address : new Address().toString(network); | |
await nodeClient.execute('generatetoaddress', [num, address]); | |
} | |
(async () => { | |
const names = []; | |
for (let i = 0; i < 800; i++) { | |
names.push(`name_${i}`); | |
} | |
await nodeClient.open(); | |
await walletClient.open(); | |
// // Create wallet | |
// console.log(await walletClient.createWallet(WALLET_NAME, {passphrase: WALLET_PASSPHRASE})) | |
await walletClient.execute('selectwallet', [WALLET_NAME]); | |
await wallet.unlock(WALLET_PASSPHRASE, 60); | |
await printInfo(); | |
// Mine blocks past rollout | |
await mineBlocks(104, true); | |
await printInfo(); | |
// Open max auctions | |
{ | |
let count = 0; | |
for (let i = 0; i < 8; i++) { | |
const batch = []; | |
for (let j = 0; j < 100; j++) { | |
batch.push(['OPEN', names[count++]]); | |
} | |
// console.log(await walletClient.execute('createbatch', [batch])); | |
console.log(await walletClient.execute('sendbatch', [batch])); | |
if (i % 2 == 1) await mineBlocks(1); | |
} | |
} | |
// Mine blocks to bidding period | |
await mineBlocks(7-4); | |
await printInfo(); | |
// Bid on all names | |
{ | |
let count = 0; | |
for (let i = 0; i < 8; i++) { | |
const batch = []; | |
for (let j = 0; j < 100; j++) { | |
batch.push( | |
['BID', names[count], 1, 1], | |
['BID', names[count], 1, 1] | |
); | |
count++; | |
} | |
// console.log(await walletClient.execute('createbatch', [batch])); | |
console.log(await walletClient.execute('sendbatch', [batch])); | |
if (i % 2 == 1) await mineBlocks(1); | |
} | |
} | |
// // Mine blocks to reveal period | |
// await mineBlocks(7-4); | |
// await printInfo(); | |
await nodeClient.close(); | |
await walletClient.close(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment