Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BD-4597 onNetAccount Update #379

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions tools/perform-vote-audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { readBufferWithDetectedEncoding } = require('tslint/lib/utils');
const testType = getTestType();

let calling_account;

/*
This test tool will invoke auditvote on the target environment.
the tool will call audit vote until phase 4 is completed by the audit vote engine.
Expand All @@ -25,24 +26,22 @@ let calling_account;
is used to create and fund the account used to call auditvote.

test net account that may be used (NOTE please verify account balance before running)
account: 'v2lgwcdkb5gn',
publicKey: 'FIO8k7N7jU9eyj57AfazGxMuvPGZG5hvXNUyxt9pBchnkXXx9KUuD',
privateKey: '5Jw78NzS2QMvjcyemCgJ9XQv8SMSEvTEuLxF8TcKf27xWcX5fmw'
account: 'wxrm1xzulbpy',
publicKey: 'FIO57FuR9isLbaPemXopbh5oUxqgPGXr7k9wyinuwF6ZCDM1woB9H',
privateKey: '5K2rhwLJptp1ycvJz58tzMUvVf2FHPCxBbSu5ejrRZBNLWqxRSH'

for main net account info please contact the FIO release manager.

*/
*/
const onNetAccount = {
account: 'v2lgwcdkb5gn',
publicKey: 'FIO8k7N7jU9eyj57AfazGxMuvPGZG5hvXNUyxt9pBchnkXXx9KUuD',
privateKey: '5Jw78NzS2QMvjcyemCgJ9XQv8SMSEvTEuLxF8TcKf27xWcX5fmw'
account: 'wxrm1xzulbpy',
publicKey: 'FIO57FuR9isLbaPemXopbh5oUxqgPGXr7k9wyinuwF6ZCDM1woB9H',
privateKey: '5K2rhwLJptp1ycvJz58tzMUvVf2FHPCxBbSu5ejrRZBNLWqxRSH'
}
const sdkAcc = {
sdk: 'undefined',
account: 'undefined'
}


/* SETUP
for private test net use the following block

Expand All @@ -61,17 +60,12 @@ const sdkAcc = {
*/
before(async () => {
faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson);

calling_account = await newUser(faucet);
})




describe(' A. call audit vote until phase 4 completes or max calls exceeded', () => {
let phase_change = 0


it(`call audit vote until it has completed phase 4, max number of calls to audit vote is 100`, async () => {
try {
let audit_phase = '10' //init to phase number not used by audit
Expand Down Expand Up @@ -126,5 +120,4 @@ describe(' A. call audit vote until phase 4 completes or max calls exceeded', ()
}
})


})
149 changes: 149 additions & 0 deletions tools/perform-voter-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
require('mocha')
const {expect} = require('chai')
const {newUser, existingUser, getTestType, getProdVoteTotal, timeout, getBundleCount, getAccountVoteWeight, getTotalVotedFio, callFioApi, fetchJson} = require('../utils.js');
const {FIOSDK } = require('@fioprotocol/fiosdk');
const config = require('../config.js');
const { readBufferWithDetectedEncoding } = require('tslint/lib/utils');
const testType = getTestType();

let calling_account;

/*
This test tool will seed the voters in the voters table with 1 fio; a pre-req for
performing the auditvote on the target environment.
*/

/* SETUP --
onNetAccount is used when running on test net or main net, it should contain the
keys and account for an account on the chain that is funded with enough
FIO to cover the addition of 1 fio per voter in the voters table.

onNetAccout is NOT used when running on a private test net, instead the faucet
is used to create and fund the account used to call trnsfiopubky

test net account that may be used (NOTE please verify account balance before running)
account: 'wxrm1xzulbpy',
publicKey: 'FIO57FuR9isLbaPemXopbh5oUxqgPGXr7k9wyinuwF6ZCDM1woB9H',
privateKey: '5K2rhwLJptp1ycvJz58tzMUvVf2FHPCxBbSu5ejrRZBNLWqxRSH'

for main net account info please contact the FIO release manager.
*/
const onNetAccount = {
account: 'wxrm1xzulbpy',
publicKey: 'FIO57FuR9isLbaPemXopbh5oUxqgPGXr7k9wyinuwF6ZCDM1woB9H',
privateKey: '5K2rhwLJptp1ycvJz58tzMUvVf2FHPCxBbSu5ejrRZBNLWqxRSH'
}
const sdkAcc = {
sdk: 'undefined',
account: 'undefined'
}

/* SETUP
for private test net use the following block

//local private network setup
faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson);
calling_account = await newUser(faucet);

for test net main net use use the following block

//testnet main net setup
let analysis_sdk = new FIOSDK(onNetAccount.privateKey, onNetAccount.publicKey, config.BASE_URL, fetchJson);
let tacc = sdkAcc
tacc.sdk = analysis_sdk
calling_account = tacc;
calling_account.account = onNetAccount.account;
*/
before(async () => {
let analysis_sdk = new FIOSDK(onNetAccount.privateKey, onNetAccount.publicKey, config.BASE_URL, fetchJson);
let tacc = sdkAcc
tacc.sdk = analysis_sdk
calling_account = tacc;
calling_account.account = onNetAccount.account;
})

async function get_voters(start,limit) {
try {
const json = {
json: true,
code: 'eosio',
scope: 'eosio',
table: 'voters',
upper_bound: start + limit - 1,
lower_bound: start,
reverse: false,
show_payer: false
}
let voters = await callFioApi("get_table_rows", json);
return voters;
}catch(error) {
console.log("unexpected error getting voters " + error);
}
}

async function get_pub_key(acc) {
try {
const json = {
json: true,
code: 'fio.address',
scope: 'fio.address',
table: 'accountmap',
upper_bound: acc,
lower_bound: acc,
limit: 1,
reverse: false,
show_payer: false
}
let res = await callFioApi("get_table_rows", json);
if (res.rows[0]) {
return res.rows[0].clientkey;
} else return 0;

}catch(error) {
console.log("unexpected error getting voters " + error);
}
}

describe(' A. Send 1 FIO to all voters...', () => {
it(`Sending...`, async () => {
let voter_rows = Array();

// Establish Voters
console.log("Fetching voters and computing power...");
let limit = 900;
let start = 0;
let ix = 0;

let voters = await get_voters(start,limit);
console.log("Fetched voters start limit,"+start+" "+limit);
while (voters.rows.length > 0) {
console.log("the number of rows is " + voters.rows.length);
for (let i=0;i<voters.rows.length;i++) {
let voter = voters.rows[i]
ix++;
try {
let voter_pub_key = await get_pub_key(voter.owner)
console.log("Sending funds to ", voter.owner);
await calling_account.sdk.genericAction('pushTransaction', {
action: 'trnsfiopubky',
account: 'fio.token',
data: {
payee_public_key: voter_pub_key,
amount: 1000000000,
max_fee: config.maxFee,
actor: calling_account.account,
tpid: ''
}
});
} catch (error) {
console.log("unexpected error processing funding for voter " + voter.owner + " " + error)
}
}

start = start + voters.rows.length;
voters = await get_voters(start, limit);
console.log("Fetched voters start limit," + start + " " + limit);
}
})
})

21 changes: 7 additions & 14 deletions tools/perform_vote_power_analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const config = require('../config.js');
const { readBufferWithDetectedEncoding } = require('tslint/lib/utils');
const testType = getTestType();


/*
NOTE -- output files are removed and replaced every run....
This test will perform a comprehensive voting analysis and output files that
Expand Down Expand Up @@ -35,16 +34,16 @@ the before also needs changed for local or (testnet mainnet) uses, see comments
for the required setup in the before.
*/
/* testnet account key that may be used
privateKey = '5Jw78NzS2QMvjcyemCgJ9XQv8SMSEvTEuLxF8TcKf27xWcX5fmw',
publicKey = 'FIO8k7N7jU9eyj57AfazGxMuvPGZG5hvXNUyxt9pBchnkXXx9KUuD',
account = 'v2lgwcdkb5gn',
*/
account: 'wxrm1xzulbpy',
publicKey: 'FIO57FuR9isLbaPemXopbh5oUxqgPGXr7k9wyinuwF6ZCDM1woB9H',
privateKey: '5K2rhwLJptp1ycvJz58tzMUvVf2FHPCxBbSu5ejrRZBNLWqxRSH'
*/
//SETUP edit the account private and pub key for the pre existing account on main net or test net
//This is NOT USED if running local private network.
const onNetAccount = {
account: 'v2lgwcdkb5gn',
publicKey: 'FIO8k7N7jU9eyj57AfazGxMuvPGZG5hvXNUyxt9pBchnkXXx9KUuD',
privateKey: '5Jw78NzS2QMvjcyemCgJ9XQv8SMSEvTEuLxF8TcKf27xWcX5fmw'
account: 'wxrm1xzulbpy',
publicKey: 'FIO57FuR9isLbaPemXopbh5oUxqgPGXr7k9wyinuwF6ZCDM1woB9H',
privateKey: '5K2rhwLJptp1ycvJz58tzMUvVf2FHPCxBbSu5ejrRZBNLWqxRSH'
}
const sdkAcc = {
sdk: 'somefin'
Expand Down Expand Up @@ -242,10 +241,6 @@ async function get_csv_obj(t1) {
return tp;
}





describe(`************************** perform_vote_analysis.js ************************** \n A. (this takes a while) analyze voters table, bp vote, and global vote and report results to csv`, () => {

it(`Wait a few seconds.`, async () => { await timeout(3000) })
Expand Down Expand Up @@ -484,6 +479,4 @@ it will output several csv files, it will remove and overwrite the files if they

})



})