Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async waitUntilBlock(expectedHeight, counter) {
const {
data: { height },
} = await this.call().getNodeStatus();
const pendingTrxCnt = await this.getPendingTransactionCount();
counter = counter ? (counter += 1) : 1;
output.print(
`Counter: ${counter}, Timestamp: ${new Date().toISOString()}, current height: ${height}, expected height: ${expectedHeight}, pending trxs: ${pendingTrxCnt}`
);
if (counter >= 20) {
return true;
}
if (height >= expectedHeight) {
// Remove the buffer time when network is stable
if (pendingTrxCnt >= 0) {
await this.wait(BLOCK_TIME);
}
return height;
}
await this.wait(BLOCK_TIME);
const splitDelegatesByPeers = (delegates, peers) => {
if (peers.length === 0) {
output.print(
'\n',
'***********Please run npm run tools:peers:config to generate peer list*************',
'\n'
);
process.exit(1);
}
if (peers.length > 101) {
peers.splice(101);
}
const chunkSize = Math.ceil(delegates.length / peers.length);
const delegateList = chunkArray(delegates, chunkSize);
return delegateList;
};
Scenario('List peers', async () => {
try {
const allPeers = await I.getAllPeers(100, 0);
output.print('Peers config list: ', JSON.stringify(allPeers, null, '\t'));
} catch (error) {
output.print('Failed to get peers list: ');
output.error(error);
process.exit(1);
}
})
.tag('@peers_list');
async getTransactionsByState(state, params, ipAddress) {
try {
const client = this.getClientByAddress(ipAddress);
return client.node.getTransactions(state, params);
} catch (error) {
output.print(
'API.getTransactionsByState: Error while processing request'
);
output.error(error);
await this.getTransactionsByState(state, params, ipAddress);
}
return true;
}
async getPeers(params, ipAddress) {
try {
const client = this.getClientByAddress(ipAddress);
return client.peers.get(params);
} catch (error) {
output.print('API.getPeers: Error while processing request');
output.error(error);
await this.getPeers(params, ipAddress);
}
return true;
}
async getMultisignatureMemberships(address, params, ipAddress) {
try {
const client = this.getClientByAddress(ipAddress);
return client.accounts.getMultisignatureMemberships(address, params);
} catch (error) {
output.print(
'API.getMultisignatureMemberships: Error while processing request'
);
output.error(error);
await this.getMultisignatureMemberships(address, params, ipAddress);
}
return true;
}
async broadcastSignatures(params, ipAddress) {
try {
const client = this.getClientByAddress(ipAddress);
return client.signatures.broadcast(params);
} catch (error) {
output.print('API.broadcastSignatures: Error while processing request');
output.error(error);
await this.broadcastSignatures(params, ipAddress);
}
return true;
}
async broadcastAndValidateTransaction(transaction) {
const { result, error } = await from(
this.call().broadcastTransactions(transaction)
);
if (error) {
output.print(`Failed to broadcast transaction: ${transaction.id}`);
output.error(error);
return;
}
expect(error).to.be.null;
this.helpers.ValidateHelper.expectResponseToBeValid(
result,
'GeneralStatusResponse'
);
expect(result.data.message).to.deep.equal('Transaction(s) accepted');
}
async getNodeStatus(ipAddress) {
try {
const client = this.getClientByAddress(ipAddress);
return client.node.getStatus();
} catch (error) {
output.print('API.getNodeStatus: Error while processing request');
output.error(error);
await this.getNodeStatus(ipAddress);
}
return true;
}
async getNodeConstants(ipAddress) {
try {
const client = this.getClientByAddress(ipAddress);
return client.node.getConstants();
} catch (error) {
output.print('API.getNodeConstants: Error while processing request');
output.error(error);
await this.getNodeConstants(ipAddress);
}
return true;
}