From 07562ebb74687161a50cd0f3c33e22128eebee95 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Wed, 9 Dec 2020 15:02:21 -0700 Subject: [PATCH 01/76] Whitelist test fixes --- tests/action-whitelisting.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/tests/action-whitelisting.js b/tests/action-whitelisting.js index 0f17706c..ae3ee6ec 100644 --- a/tests/action-whitelisting.js +++ b/tests/action-whitelisting.js @@ -25,7 +25,7 @@ before(async () => { }) describe(`************************** action-whitelisting.js ************************** \n A. Remove action, add action, action testing `, () => { - let userA1 + let userA1, userA2 const fundsAmount = 1000000000 it(`Create users`, async () => { @@ -69,7 +69,7 @@ describe(`************************** action-whitelisting.js ******************** } }) - it(`addaction succeeds.`, async () => { + it(`addaction trnsfiopubky.`, async () => { try{ const result = await callFioApiSigned('push_transaction', { action: 'addaction', @@ -90,9 +90,29 @@ describe(`************************** action-whitelisting.js ******************** } }) + it(`confirm success after addaction: Transfer FIO to userA1 FIO public key`, async () => { + try{ + const result = await faucet.genericAction('transferTokens', { + payeeFioPublicKey: userA1.publicKey, + amount: fundsAmount, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + //console.log('Result: ', result.status) + expect(result.status).to.equal('OK'); + } catch (err) { + // console.log("err.json ", err.json); + expect(err).to.equal(null); + } + }) + + it(`Confirm create users works`, async () => { + userA2 = await newUser(faucet); + }) + }) -describe.skip('A.2. Add random action hoses up the SDK session. Non recoverable. So, only run addaction as a separate test.', () => { +describe('A.2. Add random action hoses up the SDK session. Non recoverable. So, only run addaction as a separate test.', () => { let user1, user2, user3, newAction, newContract it(`Create users`, async () => { @@ -220,8 +240,8 @@ describe(`B. General addaction testing with random contracts and domains (can be }) -let newAction, newContract, newAction2, newContract2 describe(`C. Test addaction error conditions`, () => { + let newAction, newContract, newAction2, newContract2 it(`Create users`, async () => { newAction = generateFioDomain(7); From eb1199daae516703c420d9dda72cf9abe2184b9d Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Wed, 9 Dec 2020 16:51:29 -0700 Subject: [PATCH 02/76] Skipping Staking tests --- index.js | 11 +++-------- tests/transfer-locked-tokens.js | 10 +++++----- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 7de7f77a..8575d6ed 100644 --- a/index.js +++ b/index.js @@ -16,21 +16,16 @@ describe('TEST SUITE', () => { //require('./tests/action-whitelisting.js'); // FIP-12, fio v2.0.0, fio.contracts v2.0.0 // Causes future tests to fail. Only run alone. require('./tests/transfer-domain.js'); // FIP-1.a, fio v2.0.0, fio.contracts v2.1.0 require('./tests/paging.js'); // FIP-2, fio v2.0.0, fio.contracts v2.1.0 - //require('./tests/cancel-funds-request.js'); // FIP-3, fio v2.0.0, fio.contracts v2.1.0 require('./tests/removeaddress.js'); // FIP-4, fio v2.0.0, fio.contracts v2.1.0 require('./tests/txn-resubmit.js'); //Available with fiosdk_typescript v1.2.0 require('./tests/burn-address.js'); // FIP-7 //require('./tests/fee-voting-fee-setting.js'); // FIP-10 //require('./tests/producer-fee-setting.js'); // FIP-10 - require('./tests/record-obt-data.js'); //FIP-1b testing - + require('./tests/record-obt-data.js'); //FIP-1.b testing + //require('./tests/transfer-address.js'); // FIP-1.b require('./tests/transfer-locked-tokens.js'); // FIP-6 locking tests require('./tests/transfer-locked-tokens-account-tests.js'); // FIP-6 tests of generic account functionality - - //require('./tests/clio.js'); // FIP-6 - - //require('./tests/transfer-address.js'); // FIP-1.b - + //require('./tests/clio.js'); // FIP-16 //require('./tests/locks.js'); // Depends on local wallet. Need to fix //require('./tests/testnet-smoketest.js'); // In development diff --git a/tests/transfer-locked-tokens.js b/tests/transfer-locked-tokens.js index b24577ff..2879849f 100644 --- a/tests/transfer-locked-tokens.js +++ b/tests/transfer-locked-tokens.js @@ -475,7 +475,7 @@ describe(`B. transfer with 2 unlock periods, canvote = false`, () => { it(`getFioBalance before `, async () => { const result = await userA1.sdk.genericAction('getFioBalance', {}) - expect(result).to.have.all.keys('balance') + expect(result).to.have.all.keys('balance','available') balancebefore = result.balance; }) @@ -514,7 +514,7 @@ describe(`B. transfer with 2 unlock periods, canvote = false`, () => { it(`getFioBalance after, verify Fee transfer_locked_tokens was collected`, async () => { const result = await userA1.sdk.genericAction('getFioBalance', {}) - expect(result).to.have.all.keys('balance') + expect(result).to.have.all.keys('balance', 'available') balanceafter = result.balance; const result1 = await userA1.sdk.genericAction('getFee', { endPoint: 'transfer_locked_tokens', @@ -527,7 +527,7 @@ describe(`B. transfer with 2 unlock periods, canvote = false`, () => { }) - it.skip(`Verify locks were set with get_locks`, async () => { + it(`Verify locks were set with get_locks`, async () => { try{ const result = await locksdk.genericAction('getLocks', {fioPublicKey:keys.publicKey}) @@ -546,7 +546,7 @@ describe(`B. transfer with 2 unlock periods, canvote = false`, () => { it(`verify get balance results for locked funds`, async () => { const result = await locksdk.genericAction('getFioBalance', {}) - expect(result).to.have.all.keys('balance') + expect(result).to.have.all.keys('balance','available') expect(result.balance).to.be.a('number') expect(result.balance).to.equal(500000000000) @@ -760,7 +760,7 @@ describe(`B. transfer with 2 unlock periods, canvote = false`, () => { }) -describe(`C. staking incentives, canvote = false`, () => { +describe.skip(`C. staking incentives, canvote = false`, () => { let balancebefore, balanceafter, feetransferlocked, stakeKey1, stakeKey2, stakeKey3,stakeKey4, stakeKey5 From a8709f1a32346a433a010156b74566a4947c890c Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Thu, 10 Dec 2020 13:56:21 -0700 Subject: [PATCH 03/76] Fee testing for clio --- tests/clio.js | 128 +++++++++++++++++++++++++++++++++-- tests/register_fio_domain.js | 110 +++++++++++++++++++++++++++++- 2 files changed, 233 insertions(+), 5 deletions(-) diff --git a/tests/clio.js b/tests/clio.js index 656cb51b..631f1997 100644 --- a/tests/clio.js +++ b/tests/clio.js @@ -8,7 +8,7 @@ const exec = require('child_process').exec; const clio = "../fio.devtools/bin/clio"; const url = config.URL -const max_fee = 800000000000 +const max_fee = 900000000000 const tpid = 'tpid@testnet' const randString = randStr(64) // Content field requires min 64 max 296 size const content = `"{"content":"one${randString}"}"` @@ -124,8 +124,9 @@ describe(`B. Request and OBT Data`, () => { }) }) + describe(`C. Domain`, () => { - let user1, user2 + let user1, user2, user1Balance, register_fio_domain_fee, set_fio_domain_public_fee it(`Create users and import private keys`, async () => { user1 = await newUser(faucet); @@ -136,6 +137,41 @@ describe(`C. Domain`, () => { result = await runClio('wallet import -n fio --private-key ' + user2.privateKey); }) + it('Get register_fio_domain fee', async () => { + try { + result = await user1.sdk.getFee('register_fio_domain'); + register_fio_domain_fee = result.fee; + //console.log('Domain Fee: ', register_fio_domain_fee) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it('Get set_fio_domain_public fee', async () => { + try { + result = await user1.sdk.getFee('set_fio_domain_public'); + set_fio_domain_public_fee = result.fee; + //console.log('set_fio_domain_public Fee: ', set_fio_domain_public_fee) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Get balance for user1`, async () => { + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + user1Balance = result.balance + console.log('user1 fio balance', result.balance) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + it(`domain register`, async () => { try { result = await runClio(`domain register -j ${user1.domain2} ${user1.account} ${user1.publicKey} ${tpid} ${max_fee} --permission ${user1.account}@active`); @@ -146,6 +182,21 @@ describe(`C. Domain`, () => { } }) + it(`Verify balance for user1 = prev_balance - reg_domain_fee`, async () => { + let prevBalance = user1Balance; + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + user1Balance = result.balance + //console.log('user1 fio balance', result.balance) + expect(user1Balance).to.equal(prevBalance - register_fio_domain_fee) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + it(`domain renew`, async () => { try { result = await runClio(`domain renew -j ${user1.account} ${user1.domain2} ${tpid} ${max_fee} --permission ${user1.account}@active`); @@ -154,7 +205,22 @@ describe(`C. Domain`, () => { } catch (err) { console.log('Error', err) } -}) + }) + + it(`Verify balance for user1 = prev_balance - renew_domain_fee`, async () => { + let prevBalance = user1Balance; + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + user1Balance = result.balance + //console.log('user1 fio balance', result.balance) + expect(user1Balance).to.equal(prevBalance - register_fio_domain_fee) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) it(`domain set_public`, async () => { try { @@ -166,6 +232,21 @@ describe(`C. Domain`, () => { } }) + it(`Verify balance for user1 = prev_balance - set_fio_domain_public_fee`, async () => { + let prevBalance = user1Balance; + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + user1Balance = result.balance + //console.log('user1 fio balance', result.balance) + expect(user1Balance).to.equal(prevBalance - set_fio_domain_public_fee) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + it(`domain transfer`, async () => { try { result = await runClio(`domain transfer -j ${user1.domain2} ${user1.account} ${user2.publicKey} ${tpid} ${max_fee} --permission ${user1.account}@active`); @@ -179,7 +260,7 @@ describe(`C. Domain`, () => { }) describe(`D. Address`, () => { - let user1, user2 + let user1, user2, user1Balance, register_fio_address_fee let BCHAddress = { @@ -206,6 +287,30 @@ describe(`D. Address`, () => { result = await runClio('wallet import -n fio --private-key ' + user2.privateKey); }) + it('Get register_fio_address fee', async () => { + try { + result = await user1.sdk.getFee('register_fio_address'); + register_fio_address_fee = result.fee; + console.log('Domain Fee: ', register_fio_address_fee) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Get balance for user1`, async () => { + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + user1Balance = result.balance + console.log('user1 fio balance', result.balance) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + it(`address register`, async () => { try { result = await runClio(`address register -j ${user1.address2} ${user1.account} ${user1.publicKey} ${tpid} ${max_fee} --permission ${user1.account}@active`); @@ -216,6 +321,21 @@ describe(`D. Address`, () => { } }) + it(`Verify balance for user1 = prev_balance - register_fio_address_fee`, async () => { + let prevBalance = user1Balance; + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + user1Balance = result.balance + console.log('user1 fio balance', result.balance) + expect(user1Balance).to.equal(prevBalance - register_fio_address_fee) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + it(`address renew`, async () => { try { result = await runClio(`address renew -j ${user1.address2} ${user1.account} ${tpid} ${max_fee} --permission ${user1.account}@active`); diff --git a/tests/register_fio_domain.js b/tests/register_fio_domain.js index f6380aae..dca1a7ca 100644 --- a/tests/register_fio_domain.js +++ b/tests/register_fio_domain.js @@ -236,7 +236,6 @@ describe('B. Test isAvailable using bad FIO addresses', () => { }) - describe('C. Register domain for other user', () => { let userC1, userC2, newFioDomain @@ -315,3 +314,112 @@ describe('D. Try to re-register the same domain using different case', () => { }) }) + +describe('E. Test set_fio_domain_public', () => { + let user1, register_fio_domain_fee, set_fio_domain_public_fee, user1Balance + + it(`Create users`, async () => { + user1 = await newUser(faucet) + user1.domain2 = generateFioDomain(15) + }) + + it('Get register_fio_domain fee', async () => { + try { + result = await user1.sdk.getFee('register_fio_domain'); + register_fio_domain_fee = result.fee; + //console.log('Domain Fee: ', register_fio_domain_fee) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it('Get set_fio_domain_public fee', async () => { + try { + result = await user1.sdk.getFee('set_fio_domain_public'); + set_fio_domain_public_fee = result.fee; + //console.log('set_fio_domain_public Fee: ', set_fio_domain_public_fee) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Get balance for user1`, async () => { + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + user1Balance = result.balance + console.log('user1 fio balance', result.balance) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Confirm domain2 is not registered`, async () => { + const result = await user1.sdk.genericAction('isAvailable', { + fioName: user1.domain2, + }) + //console.log('Result: ', result) + expect(result.is_registered).to.equal(0) + }) + + it(`Register domain2 succeeds`, async () => { + const result = await user1.sdk.genericAction('registerFioDomain', { + fioDomain: user1.domain2, + maxFee: register_fio_domain_fee, + technologyProviderId: '' + }) + //console.log('Result: ', result) + expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') + }) + + it(`Verify balance for user1 = prev_balance - reg_domain_fee`, async () => { + let prevBalance = user1Balance; + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + user1Balance = result.balance + //console.log('user1 fio balance', result.balance) + expect(user1Balance).to.equal(prevBalance - register_fio_domain_fee) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`set_fio_domain_public for user1 Domain`, async () => { + try { + const result = await user1.sdk.genericAction('setFioDomainVisibility', { + fioDomain: user1.domain2, + isPublic: true, + maxFee: set_fio_domain_public_fee, + technologyProviderId: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + } + }) + + it(`Verify balance for user1 = prev_balance - set_fio_domain_public_fee`, async () => { + let prevBalance = user1Balance; + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + user1Balance = result.balance + //console.log('user1 fio balance', result.balance) + expect(user1Balance).to.equal(prevBalance - set_fio_domain_public_fee) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } +}) + + +}) From f91d86ad0217c257d14d01e878653a1f542ce6ea Mon Sep 17 00:00:00 2001 From: andreyvEze Date: Sat, 12 Dec 2020 00:25:49 +0200 Subject: [PATCH 04/76] Fixed fiosdk lib name import. --- tests/Archive/fio-smoketest.js | 30 +-- tests/Archive/fiojs-examples.js | 70 +++---- tests/Archive/get-blocks.js | 4 +- tests/Archive/msig.js | 6 +- tests/Archive/performance-check.js | 4 +- tests/Archive/proxy-vote.js | 130 ++++++------ tests/Archive/ram.js | 74 +++---- tests/action-whitelisting.js | 26 +-- tests/addaddress.js | 2 +- tests/burn-address.js | 18 +- tests/clio.js | 14 +- tests/expired-domains.js | 2 +- tests/fee-voting-fee-setting.js | 6 +- tests/fee-voting-post-contract-set.js | 2 +- tests/fees.js | 6 +- tests/fio-request.js | 92 ++++----- tests/history.js | 34 ++-- tests/locks.js | 16 +- tests/paging.js | 60 +++--- tests/producer-fee-setting.js | 140 ++++++------- tests/producer.js | 22 +- tests/pub_k1.js | 16 +- tests/pushtransaction.js | 12 +- tests/ram2.js | 82 ++++---- tests/record-obt-data.js | 2 +- tests/register_fio_domain.js | 102 +++++----- tests/removeaddress.js | 28 +-- tests/testnet-smoketest.js | 60 +++--- tests/transfer-address.js | 4 +- tests/transfer-domain.js | 72 +++---- tests/transfer-locked-tokens-account-tests.js | 14 +- tests/transfer-locked-tokens.js | 2 +- tests/transfer-tokens.js | 24 +-- tests/txn-resubmit.js | 20 +- tests/vote.js | 14 +- utils.js | 192 +++++++++--------- 36 files changed, 701 insertions(+), 701 deletions(-) diff --git a/tests/Archive/fio-smoketest.js b/tests/Archive/fio-smoketest.js index 2b2714d0..a721475c 100644 --- a/tests/Archive/fio-smoketest.js +++ b/tests/Archive/fio-smoketest.js @@ -1,15 +1,15 @@ //require('mocha') //const { expect } = require('chai') -//const {FIOSDK } = require('@fioprotocol/FIOSDK') +//const {FIOSDK } = require('@fioprotocol/fiosdk') //const fioData = require('./serverResponses'); //const fiojs = require("@fioprotocol/fiojs"); -//const Transactions_2 = require("@fioprotocol/FIOSDK/lib/transactions/Transactions") +//const Transactions_2 = require("@fioprotocol/fiosdk/lib/transactions/Transactions") //let transaction = new Transactions_2.Transactions require('mocha') const {expect} = require('chai') const {newUser, getProdVoteTotal, importPrivKey, unlockWallet, addLock, getAccountVoteWeight, getTotalVotedFio, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { @@ -26,12 +26,12 @@ describe('A. Transferring tokens to Happy', () => { it(`getFioBalance for happy returns: ${config.error.keyNotFound}`, async () => { try { - const result = await happyB1.sdk.genericAction('getFioBalance', { }) + const result = await happyB1.sdk.genericAction('getFioBalance', { }) } catch (err) { expect(err.json.message).to.equal(config.error.keyNotFound) - } + } }) - + it(`Transfer ${fundsAmount} FIO to Happy's FIO public key`, async () => { const result = await faucet.genericAction('transferTokens', { payeeFioPublicKey: happyB1.publicKey, @@ -63,7 +63,7 @@ describe('A. Transferring tokens to Happy', () => { it(`Happy's FIO public key has ${1.5*fundsAmount} FIO`, async () => { const result = await happyB1.sdk.genericAction('getFioBalance', {}) //console.log('Result: ', result) - expect(result.balance).to.equal(1.5*fundsAmount) + expect(result.balance).to.equal(1.5*fundsAmount) }) }) @@ -80,10 +80,10 @@ describe('C. Transfer Tokens Sad', () => { try { const result = await sadC1.sdk.genericAction('getFioBalance', { fioPublicKey: sadC1.publicKey - }) + }) } catch (err) { expect(err.json.message).to.equal(config.keyNotFound) - } + } }) it(`Transfer to empty public key returns: ${config.error.invalidKey}`, async () => { @@ -97,7 +97,7 @@ describe('C. Transfer Tokens Sad', () => { } catch (err) { //console.log('Error: ', err.json) expect(err.json.fields[0].error).to.equal(config.error.invalidKey) - } + } }) it(`Transfer ${100000000000000000/1000000000} returns: ${config.error.insufficientBalance}`, async () => { @@ -111,7 +111,7 @@ describe('C. Transfer Tokens Sad', () => { } catch (err) { //console.log('Error: ', err.json) expect(err.json.fields[0].error).to.equal(config.error.insufficientBalance) - } + } }) it(`Transfer without enough FEE returns ${config.error.feeExceedsMax}`, async () => { @@ -125,9 +125,9 @@ describe('C. Transfer Tokens Sad', () => { } catch (err) { //console.log('Error: ', err.json) expect(err.json.fields[0].error).to.equal(config.error.feeExceedsMax) - } + } }) - + it(`Transfer to invalid public key returns ${config.error.invalidKey}`, async () => { try { const result = await faucet.genericAction('transferTokens', { @@ -139,7 +139,7 @@ describe('C. Transfer Tokens Sad', () => { } catch (err) { //console.log('Error: ', err.json) expect(err.json.fields[0].error).to.equal(config.error.invalidKey) - } + } }) it(`Transfer -100 returns ${config.error.invalidAmount}`, async () => { @@ -153,7 +153,7 @@ describe('C. Transfer Tokens Sad', () => { } catch (err) { //console.log('Error: ', err.json) expect(err.json.fields[0].error).to.equal(config.error.invalidAmount) - } + } }) }) diff --git a/tests/Archive/fiojs-examples.js b/tests/Archive/fiojs-examples.js index 8c7fc52d..e69a0808 100644 --- a/tests/Archive/fiojs-examples.js +++ b/tests/Archive/fiojs-examples.js @@ -6,7 +6,7 @@ require('mocha') config = require('../../config.js'); const {expect} = require('chai') const {newUser, fetchJson, callFioApi} = require('../../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') before(async () => { @@ -21,20 +21,20 @@ const fioNewFundsRequest = async (fromFioAccount, toFioAddress, toPublicKey, token, amount, memo, fee) => { - + const fromFioAddress = fromFioAccount.address; const fromActor = fromFioAccount.accountName; - + const fioChain = getChain('FIO'); const rpc = new JsonRpc(fioChain.endpoint); - + const info = await rpc.get_info(); const blockInfo = await rpc.get_block(info.last_irreversible_block_num); const currentDate = new Date(); const timePlusTen = currentDate.getTime() + 10000; const timeInISOString = (new Date(timePlusTen)).toISOString(); const expiration = timeInISOString.substr(0, timeInISOString.length - 1); - + const newFundsContent = { payee_public_address: fromFioAddress, amount: amount.toString(), @@ -44,7 +44,7 @@ const fioNewFundsRequest = async (fromFioAccount, hash: null, offline_url: null }; - + const fromPrivateKey = fromFioAccount.privateKey; const cipher = Fio.createSharedCipher({ privateKey: fromPrivateKey, @@ -53,7 +53,7 @@ const fioNewFundsRequest = async (fromFioAccount, textDecoder: new TextDecoder()} ); const cipherHex = cipher.encrypt('new_funds_content', newFundsContent); - + const transaction = { expiration, ref_block_num: blockInfo.block_num & 0xffff, @@ -75,14 +75,14 @@ const fioNewFundsRequest = async (fromFioAccount, }, }] }; - + var abiMap = new Map(); var tokenRawAbi = await rpc.get_raw_abi('fio.reqobt'); abiMap.set('fio.reqobt', tokenRawAbi); - + const chainId = info.chain_id; var privateKeys = [fromPrivateKey]; - + const tx = await Fio.prepareTransaction({ transaction, chainId, @@ -91,9 +91,9 @@ const fioNewFundsRequest = async (fromFioAccount, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() }); - + var pushResult = await fetch(fioChain.endpoint + '/v1/chain/push_transaction', { body: JSON.stringify(tx), method: 'POST', }); - + const json = await pushResult.json(); if (json.processed && json.processed.except) { throw new RpcError(json); @@ -108,21 +108,21 @@ const fioNewFundsRequest = async (fromFioAccount, const fioChain = getChain(fioAccount.chainName); const rpc = new JsonRpc(fioChain.endpoint); - + const info = await rpc.get_info(); const blockInfo = await rpc.get_block(info.last_irreversible_block_num); const currentDate = new Date(); const timePlusTen = currentDate.getTime() + 10000; const timeInISOString = (new Date(timePlusTen)).toISOString(); const expiration = timeInISOString.substr(0, timeInISOString.length - 1); - + var chainName = account.chainName; if(chainName == "Telos") { chainName = "TLOS"; } const accPubkey = ecc.privateToPublic(account.privateKey); //const fioPubkey = Ecc.privateToPublic(fioAccount.privateKey); - + const transaction = { expiration, ref_block_num: blockInfo.block_num & 0xffff, @@ -147,14 +147,14 @@ const fioNewFundsRequest = async (fromFioAccount, }, }] }; - + var abiMap = new Map(); var tokenRawAbi = await rpc.get_raw_abi('fio.address'); abiMap.set('fio.address', tokenRawAbi); - + const chainId = info.chain_id; var privateKeys = [fioAccount.privateKey]; - + const tx = await Fio.prepareTransaction({ transaction, chainId, @@ -163,9 +163,9 @@ const fioNewFundsRequest = async (fromFioAccount, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() }); - + var pushResult = await fetch(fioChain.endpoint + '/v1/chain/push_transaction', { body: JSON.stringify(tx), method: 'POST', }); - + const json = await pushResult.json(); if (json.processed && json.processed.except) { throw new RpcError(json); @@ -185,22 +185,22 @@ const fioNewFundsRequest = async (fromFioAccount, transactionId, memo, fee) => { - + const payerFioAddress = payerFioAccount.address; const payerActor = payerFioAccount.accountName; const payerPrivateKey = payerFioAccount.privateKey; const payerPublicKey = Ecc.privateToPublic(payerPrivateKey); - + const fioChain = getChain('FIO'); const rpc = new JsonRpc(fioChain.endpoint); - + const info = await rpc.get_info(); const blockInfo = await rpc.get_block(info.last_irreversible_block_num); const currentDate = new Date(); const timePlusTen = currentDate.getTime() + 10000; const timeInISOString = (new Date(timePlusTen)).toISOString(); const expiration = timeInISOString.substr(0, timeInISOString.length - 1); - + const obtContent = { payer_public_address: payerPublicKey, payee_public_address: payeePublicKey, @@ -214,7 +214,7 @@ const fioNewFundsRequest = async (fromFioAccount, offline_url: null }; console.log(obtContent); - + const cipher = Fio.createSharedCipher({ privateKey: payerPrivateKey, publicKey: payeePublicKey, @@ -222,7 +222,7 @@ const fioNewFundsRequest = async (fromFioAccount, textDecoder: new TextDecoder()} ); const cipherHex = cipher.encrypt('record_obt_data_content', obtContent); - + const transaction = { expiration, ref_block_num: blockInfo.block_num & 0xffff, @@ -245,14 +245,14 @@ const fioNewFundsRequest = async (fromFioAccount, }, }] }; - + var abiMap = new Map(); var tokenRawAbi = await rpc.get_raw_abi('fio.reqobt'); abiMap.set('fio.reqobt', tokenRawAbi); - + const chainId = info.chain_id; var privateKeys = [payerPrivateKey]; - + const tx = await Fio.prepareTransaction({ transaction, chainId, @@ -261,20 +261,20 @@ const fioNewFundsRequest = async (fromFioAccount, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() }); - + var pushResult = await fetch(fioChain.endpoint + '/v1/chain/push_transaction', { body: JSON.stringify(tx), method: 'POST', }); - + const json = await pushResult.json(); if (json.processed && json.processed.except) { throw new RpcError(json); } return json; }; - + describe(`Test fiojs`, () => { let userA1, userA2 - + it(`Create users`, async () => { userA1 = await newUser(faucet); userA2 = await newUser(faucet); @@ -293,5 +293,5 @@ const fioNewFundsRequest = async (fromFioAccount, } }) - - }) \ No newline at end of file + + }) diff --git a/tests/Archive/get-blocks.js b/tests/Archive/get-blocks.js index 9a00c1d1..76981bc9 100644 --- a/tests/Archive/get-blocks.js +++ b/tests/Archive/get-blocks.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, getBlock, fetchJson} = require('../../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../../config.js'); @@ -32,4 +32,4 @@ describe('************************** get-blocks.js ************************** \n } }) -}) \ No newline at end of file +}) diff --git a/tests/Archive/msig.js b/tests/Archive/msig.js index 2bf3af93..5b761aad 100644 --- a/tests/Archive/msig.js +++ b/tests/Archive/msig.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {callFioApi, fetchJson} = require('../../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK'); +const {FIOSDK } = require('@fioprotocol/fiosdk'); config = require('../../config.js'); const exec = require('child_process').exec; @@ -47,8 +47,8 @@ describe('Create BP setcode msig', () => { prodsTable = result.rows; prodList = ""; prodCount = 0 - for (prod in prodsTable) { - if (prodCount != 0) { prodList = prodList + ',' } + for (prod in prodsTable) { + if (prodCount != 0) { prodList = prodList + ',' } nextprod = '{"actor":"' + prodsTable[prod].owner + '","permission":"active"}' prodList = prodList + nextprod prodCount++; diff --git a/tests/Archive/performance-check.js b/tests/Archive/performance-check.js index 380360f1..b58fec53 100644 --- a/tests/Archive/performance-check.js +++ b/tests/Archive/performance-check.js @@ -4,7 +4,7 @@ const {performance} = require('perf_hooks'); config = require('../../config.js'); const {expect} = require('chai') const {newUser, fetchJson, generateFioDomain, generateFioAddress, createKeypair, callFioApi} = require('../../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') before(async () => { @@ -54,7 +54,7 @@ describe(`************************** performance-check.js ********************** method: "POST", uri: servers[server] + "chain/" + apiCall, body: json, - json: true + json: true }; console.log("uri: " + options.uri); //console.log("\nWith stringified JSON: \n") diff --git a/tests/Archive/proxy-vote.js b/tests/Archive/proxy-vote.js index eb5b1c09..842f61fa 100644 --- a/tests/Archive/proxy-vote.js +++ b/tests/Archive/proxy-vote.js @@ -1,14 +1,14 @@ require('mocha') const {expect} = require('chai') const {printUserRam, getAccountVoteWeight, getTotalVotedFio, setRam, user, generateFioDomain, generateFioAddress, fetchJson, randStr, timeout, createKeypair} = require('../../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../../config.js'); let user1 before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson) - + await timeout(1000) keys = await createKeypair(); user1 = new user(keys.account, keys.privateKey, keys.publicKey) @@ -41,7 +41,7 @@ describe('Test register as proxy after proxying your own vote.', () => { console.log('user1 Account: ', user1.account) console.log('user1 PublicKey: ', user1.publicKey) - console.log('user1 PrivateKey: ', user1.privateKey) + console.log('user1 PrivateKey: ', user1.privateKey) }) it(`Get initial total_voted_fio`, async () => { @@ -54,51 +54,51 @@ describe('Test register as proxy after proxying your own vote.', () => { payeeFioPublicKey: user1.publicKey, amount: config.FUNDS, maxFee: config.api.transfer_tokens_pub_key.fee, - }) + }) //console.log('Result', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user1, 'INITIALACCOUNTRAM', 0) }) it(`Register user1 domain`, async () => { - const result = await user1sdk.genericAction('registerFioDomain', { - fioDomain: user1Domain, + const result = await user1sdk.genericAction('registerFioDomain', { + fioDomain: user1Domain, maxFee: config.api.register_fio_domain.fee , walletFioAddress: '' }) //console.log('Result', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user1, 'REGDOMAINRAM', result.fee_collected) }) - + it(`Register user1 address #1`, async () => { try { - const result = await user1sdk.genericAction('registerFioAddress', { + const result = await user1sdk.genericAction('registerFioAddress', { fioAddress: user1Address, maxFee: config.api.register_fio_address.fee, walletFioAddress: '' }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user1, 'REGADDRESSRAM', result.fee_collected) } catch (err) { console.log('Error: ', err.json) - } + } }) it(`Register user1 address #2`, async () => { try { - const result = await user1sdk.genericAction('registerFioAddress', { + const result = await user1sdk.genericAction('registerFioAddress', { fioAddress: user1Address2, maxFee: config.api.register_fio_address.fee, walletFioAddress: '' }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user1, 'REGADDRESSRAM', result.fee_collected) } catch (err) { console.log('Error: ', err.json) - } + } }) @@ -111,32 +111,32 @@ describe('Test register as proxy after proxying your own vote.', () => { payeeFioPublicKey: prod.publicKey, amount: config.FUNDS, maxFee: config.api.transfer_tokens_pub_key.fee, - }) + }) //console.log('Result', result) expect(result).to.have.all.keys('transaction_id', 'block_num', 'status', 'fee_collected') - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(prod, 'INITIALACCOUNTRAM', 0) }) it(`Register domain`, async () => { - const result = await prodsdk.genericAction('registerFioDomain', { - fioDomain: prodDomain, + const result = await prodsdk.genericAction('registerFioDomain', { + fioDomain: prodDomain, maxFee: config.api.register_fio_domain.fee , walletFioAddress: walletAddress64 }) //console.log('Result', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(prod, 'REGDOMAINRAM', result.fee_collected) }) - + it(`Register address`, async () => { - const result = await prodsdk.genericAction('registerFioAddress', { + const result = await prodsdk.genericAction('registerFioAddress', { fioAddress: prodAddress, maxFee: config.api.register_fio_address.fee, walletFioAddress: walletAddress64 }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(prod, 'REGADDRESSRAM', result.fee_collected) }) @@ -155,11 +155,11 @@ describe('Test register as proxy after proxying your own vote.', () => { } }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(prod, 'REGPRODUCERRAM', result.fee_collected) } catch (err) { console.log('Error: ', err.json) - } + } }) */ @@ -184,11 +184,11 @@ describe('Test register as proxy after proxying your own vote.', () => { } }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user1,'VOTEPRODUCERRAM', result.fee_collected) } catch (err) { console.log('Error: ', err.json) - } + } }) it(`Get user1 last_vote_weight`, async () => { @@ -198,14 +198,14 @@ describe('Test register as proxy after proxying your own vote.', () => { user1.last_vote_weight = Math.floor(last_vote_weight) } catch (err) { console.log('Error: ', err.json) - } + } }) it(`User1 FIO balance same as last_vote_weight`, async () => { try { const result = await user1sdk.genericAction('getFioBalance', { fioPublicKey: user1.publicKey - }) + }) console.log('User 1 fio balance', result) expect(result.balance).to.equal(user1.last_vote_weight) } catch (err) { @@ -239,11 +239,11 @@ describe('Test register as proxy after proxying your own vote.', () => { } }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user1,'VOTEPRODUCERRAM', result.fee_collected) } catch (err) { console.log('Error: ', err.json) - } + } }) // Not true, this is bundled. Update for post bundle. @@ -255,7 +255,7 @@ describe('Test register as proxy after proxying your own vote.', () => { //user1.last_vote_weight = Math.floor(last_vote_weight) } catch (err) { console.log('Error: ', err) - } + } }) @@ -263,7 +263,7 @@ describe('Test register as proxy after proxying your own vote.', () => { try { const result = await user1sdk.genericAction('getFioBalance', { fioPublicKey: user1.publicKey - }) + }) console.log('User 1 fio balance', result) expect(result.balance).to.equal(user1.last_vote_weight) } catch (err) { @@ -279,7 +279,7 @@ describe('Test register as proxy after proxying your own vote.', () => { user1.last_vote_weight = Math.floor(last_vote_weight) } catch (err) { console.log('Error: ', err.json) - } + } }) it(`Expect total_voted_fio to stay the same. But, the votes are still in the voters table`, async () => { @@ -309,11 +309,11 @@ describe('Test register as proxy after proxying your own vote.', () => { } }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user1,'VOTEPRODUCERRAM', result.fee_collected) } catch (err) { console.log('Error: ', err.json) - } + } }) */ @@ -330,13 +330,13 @@ describe('Test register as proxy after proxying your own vote.', () => { } }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user1, 'REGPROXYRAM', result.fee_collected) } catch (err) { console.log('actor', user1.account) console.log('fio_address', user1Address) console.log('Error: ', err.json) - } + } }) it(`Transfer FIO to user2 to fund account`, async () => { @@ -344,28 +344,28 @@ describe('Test register as proxy after proxying your own vote.', () => { payeeFioPublicKey: user2.publicKey, amount: config.FUNDS, maxFee: config.api.transfer_tokens_pub_key.fee, - }) + }) //console.log('Result', result) expect(result).to.have.all.keys('transaction_id', 'block_num', 'status', 'fee_collected') - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user2, 'INITIALACCOUNTRAM', 0) }) it(`Register user2 domain`, async () => { - const result = await user2sdk.genericAction('registerFioDomain', { - fioDomain: user2Domain, + const result = await user2sdk.genericAction('registerFioDomain', { + fioDomain: user2Domain, maxFee: config.api.register_fio_domain.fee , walletFioAddress: '' }) //console.log('Result', result) expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user2, 'REGDOMAINRAM', result.fee_collected) }) - + it(`Register user2 address`, async () => { try { - const result = await user2sdk.genericAction('registerFioAddress', { + const result = await user2sdk.genericAction('registerFioAddress', { fioAddress: user2Address, maxFee: config.api.register_fio_address.fee, walletFioAddress: '' @@ -375,7 +375,7 @@ describe('Test register as proxy after proxying your own vote.', () => { await setRam(user2, 'REGADDRESSRAM', result.fee_collected) } catch (err) { console.log('Error: ', err.json) - } + } }) it('Get total_voted_fio', async () => { @@ -401,10 +401,10 @@ describe('Test register as proxy after proxying your own vote.', () => { }) //console.log('Result: ', result) //console.log('Proxy user2 votes to: ', user1Address) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') } catch (err) { console.log('Error: ', err.json) - } + } }) it('Get total_voted_fio', async () => { @@ -423,7 +423,7 @@ describe('Test register as proxy after proxying your own vote.', () => { user2.last_vote_weight = Math.floor(last_vote_weight) } catch (err) { console.log('Error: ', err.json) - } + } }) it(`total_voted_fio increased by user2 last_vote_weight after proxying votes`, async () => { @@ -452,13 +452,13 @@ describe('Test register as proxy after proxying your own vote.', () => { } }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user1, 'UNREGPROXYRAM', result.fee_collected) } catch (err) { console.log('actor', user1.account) console.log('fio_address', user1Address) console.log('Error: ', err.json) - } + } }) it.skip(`TODO: check to make sure the voters table is correct`, async () => { @@ -476,11 +476,11 @@ describe('Test register as proxy after proxying your own vote.', () => { } }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(prod, 'UNREGPRODUCERRAM', result.fee_collected) } catch (err) { console.log('Error: ', err.json) - } + } }) it(`Reset total_voted_fio`, async () => { @@ -489,7 +489,7 @@ describe('Test register as proxy after proxying your own vote.', () => { console.log('Reset total_voted_fio: ', total_voted_fio) } catch (err) { console.log('Error: ', err.json) - } + } }) it(`Reset user1 last_vote_weight`, async () => { @@ -499,7 +499,7 @@ describe('Test register as proxy after proxying your own vote.', () => { console.log('user1.last_vote_weight: ', user1.last_vote_weight) } catch (err) { console.log('Error: ', err.json) - } + } }) it(`Transfer 10000000000 to user1`, async () => { @@ -507,9 +507,9 @@ describe('Test register as proxy after proxying your own vote.', () => { payeeFioPublicKey: user1.publicKey, amount: 100000000000, maxFee: config.api.transfer_tokens_pub_key.fee, - }) + }) //console.log('Result', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') }) it(`Print new user1 last_vote_weight`, async () => { @@ -520,7 +520,7 @@ describe('Test register as proxy after proxying your own vote.', () => { console.log('new user1 last_vote_weight: ', last_vote_weight) } catch (err) { console.log('Error: ', err.json) - } + } }) it(`Confirm user1 last_vote_weight increases by 100000000000`, async () => { @@ -531,7 +531,7 @@ describe('Test register as proxy after proxying your own vote.', () => { user1.last_vote_weight = last_vote_weight } catch (err) { console.log('Error: ', err) - } + } }) it(`total_voted_fio increased by user1 100000000000`, async () => { @@ -553,7 +553,7 @@ describe('Test register as proxy after proxying your own vote.', () => { console.log('Reset total_voted_fio: ', total_voted_fio) } catch (err) { console.log('Error: ', err.json) - } + } }) it(`Reset user2 last_vote_weight`, async () => { @@ -563,7 +563,7 @@ describe('Test register as proxy after proxying your own vote.', () => { console.log('Reset user2.last_vote_weight: ', user2.last_vote_weight) } catch (err) { console.log('Error: ', err.json) - } + } }) it(`Transfer 30000000000 to user2`, async () => { @@ -571,9 +571,9 @@ describe('Test register as proxy after proxying your own vote.', () => { payeeFioPublicKey: user2.publicKey, amount: 300000000000, maxFee: config.api.transfer_tokens_pub_key.fee, - }) + }) console.log('Result', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') }) it(`Print new user2 last_vote_weight`, async () => { @@ -584,7 +584,7 @@ describe('Test register as proxy after proxying your own vote.', () => { console.log('New user2 last_vote_weight: ', last_vote_weight) } catch (err) { console.log('Error: ', err.json) - } + } }) it(`Confirm user2 last_vote_weight increases by 300000000000`, async () => { @@ -595,7 +595,7 @@ describe('Test register as proxy after proxying your own vote.', () => { user2.last_vote_weight = last_vote_weight } catch (err) { console.log('Error: ', err) - } + } }) it(`total_voted_fio increased by user2 300000000000`, async () => { diff --git a/tests/Archive/ram.js b/tests/Archive/ram.js index 8ba4edb1..a83aa292 100644 --- a/tests/Archive/ram.js +++ b/tests/Archive/ram.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {Ram, generateFioDomain, generateFioAddress, fetchJson, randStr, timeout, createKeypair} = require('../../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../../config.js'); let user1, user2 @@ -31,7 +31,7 @@ describe('Test RAM Consumption', () => { //console.log('ramuserPublicKey: ', user1.publicKey) //console.log('ramuserPrivateKey: ', user1.privateKey) //user1Ram = new Ram(user1.account); - + }) it(`Transfer FIO to ramuserPublicKey to fund account. Test: INITIALACCOUNTRAM`, async () => { @@ -39,7 +39,7 @@ describe('Test RAM Consumption', () => { payeeFioPublicKey: user1.publicKey, amount: 2000000000000, maxFee: config.api.transfer_tokens_pub_key.fee, - }) + }) //console.log('Result', result) expect(result).to.have.all.keys('transaction_id', 'block_num', 'status', 'fee_collected') }) @@ -48,10 +48,10 @@ describe('Test RAM Consumption', () => { const result = await user1Ram.setRamData('INITIALACCOUNTRAM', user1) expect(result.txnQuota).to.equal(config.RAM.INITIALACCOUNTRAM) }) - + it(`Test: REGDOMAINRAM`, async () => { - const result = await user1sdk.genericAction('registerFioDomain', { - fioDomain: user1Domain, + const result = await user1sdk.genericAction('registerFioDomain', { + fioDomain: user1Domain, maxFee: config.api.register_fio_domain.fee , walletFioAddress: '' }) @@ -63,15 +63,15 @@ describe('Test RAM Consumption', () => { const result = await user1Ram.setRamData('REGDOMAINRAM', user1) expect(result.txnQuota).to.be.greaterThan(0) }) - + it(`Test: REGADDRESSRAM`, async () => { - const result = await user1sdk.genericAction('registerFioAddress', { + const result = await user1sdk.genericAction('registerFioAddress', { fioAddress: user1Address, maxFee: config.api.register_fio_address.fee, walletFioAddress: '' }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') }) it(`Set RAM info`, async () => { @@ -132,8 +132,8 @@ describe('Test RAM Consumption', () => { it(`Test: NEWFUNDSREQUESTRAM`, async () => { try { - const result = await user1sdk.genericAction('requestFunds', { - payerFioAddress: user1Address, + const result = await user1sdk.genericAction('requestFunds', { + payerFioAddress: user1Address, payeeFioAddress: user1Address, maxFee: config.api.new_funds_request.fee, walletFioAddress: user1Address, @@ -144,7 +144,7 @@ describe('Test RAM Consumption', () => { memo: randStr(15), hash: ramuser.account, offlineUrl: randStr(10) - }) + }) //console.log('Result: ', result) expect(result).to.have.all.keys('status', 'fio_request_id', 'fee_collected') } catch (err) { @@ -196,15 +196,15 @@ describe('Test RAM Consumption', () => { SETDOMAINPUBRAM: 256, BURNEXPIREDRAM: 0, RECORDOBTRAM: 1024, - RENEWADDRESSRAM: 256, - RENEWDOMAINRAM: 256, + RENEWADDRESSRAM: 256, + RENEWDOMAINRAM: 256, TPIDCLAIMRAM: 0, - BPCLAIMRAM: 0, - TRANSFERRAM: 0, - TRANSFERPUBKEYRAM: 2560, - REJECTFUNDSRAM: 512, - UPDATEFEESRAM: 0, - SETFEEVOTERAM: 512, + BPCLAIMRAM: 0, + TRANSFERRAM: 0, + TRANSFERPUBKEYRAM: 2560, + REJECTFUNDSRAM: 512, + UPDATEFEESRAM: 0, + SETFEEVOTERAM: 512, SETFEEMULTRAM: 0 */ @@ -223,9 +223,9 @@ describe('Test add_pub_address RAM Consumption', () => { payeeFioPublicKey: user2.publicKey, amount: 2000000000000, maxFee: config.api.transfer_tokens_pub_key.fee, - }) + }) console.log('Result', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') } catch (err) { console.log('user2Domain', user2Domain) console.log('user2.publicKey', user2.publicKey) @@ -235,8 +235,8 @@ describe('Test add_pub_address RAM Consumption', () => { }) it(`Register domain: user2Domain`, async () => { - const result = await user2sdk.genericAction('registerFioDomain', { - fioDomain: user2Domain, + const result = await user2sdk.genericAction('registerFioDomain', { + fioDomain: user2Domain, maxFee: config.api.register_fio_domain.fee , walletFioAddress: '' }) @@ -245,30 +245,30 @@ describe('Test add_pub_address RAM Consumption', () => { }) it(`Register address: user2Address`, async () => { - const result = await user2sdk.genericAction('registerFioAddress', { + const result = await user2sdk.genericAction('registerFioAddress', { fioAddress: user2Address, maxFee: config.api.register_fio_address.fee, walletFioAddress: '' }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') }) it(`Register address: user2Address2`, async () => { - const result = await user2sdk.genericAction('registerFioAddress', { + const result = await user2sdk.genericAction('registerFioAddress', { fioAddress: user2Address2, maxFee: config.api.register_fio_address.fee, walletFioAddress: '' }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') }) it(`do 30 request funds`, async () => { for (i = 0; i < 30; i++) { try { - const result = await user2sdk.genericAction('requestFunds', { - payerFioAddress: user2Address, + const result = await user2sdk.genericAction('requestFunds', { + payerFioAddress: user2Address, payeeFioAddress: user2Address, maxFee: config.api.new_funds_request.fee, walletFioAddress: user2Address, @@ -279,7 +279,7 @@ describe('Test add_pub_address RAM Consumption', () => { memo: randStr(15), hash: ramuser.account, offlineUrl: randStr(10) - }) + }) //console.log('Result: ', result) const result2 = await user2Ram.setRamData('NEWFUNDSREQUESTRAM', result.fee_collected, user2) //console.log(i + '. fee collected: ', result.fee_collected) @@ -338,8 +338,8 @@ describe('Test add_pub_address RAM Consumption', () => { it(`Use up most of the bundles with requestFunds`, async () => { for (i = 0; i < 15; i++) { try { - const result = await user2sdk.genericAction('requestFunds', { - payerFioAddress: user2Address, + const result = await user2sdk.genericAction('requestFunds', { + payerFioAddress: user2Address, payeeFioAddress: user2Address, maxFee: config.api.new_funds_request.fee, walletFioAddress: user2Address, @@ -350,7 +350,7 @@ describe('Test add_pub_address RAM Consumption', () => { memo: randStr(15), hash: ramuser.account, offlineUrl: randStr(10) - }) + }) //console.log('Result: ', result) const result2 = await user2Ram.setRamData('NEWFUNDSREQUESTRAM', result.fee_collected, user2) //console.log(i + '. fee collected: ', result.fee_collected) @@ -409,8 +409,8 @@ describe('Test add_pub_address RAM Consumption', () => { it.skip(`See what happens when request funds continues after the zero addaddress`, async () => { for (i = 0; i < 6; i++) { try { - const result = await user2sdk.genericAction('requestFunds', { - payerFioAddress: user2Address, + const result = await user2sdk.genericAction('requestFunds', { + payerFioAddress: user2Address, payeeFioAddress: user2Address, maxFee: config.api.new_funds_request.fee, walletFioAddress: user2Address, @@ -421,7 +421,7 @@ describe('Test add_pub_address RAM Consumption', () => { memo: randStr(15), hash: ramuser.account, offlineUrl: randStr(10) - }) + }) //console.log('Result: ', result) const result2 = await user2Ram.setRamData('NEWFUNDSREQUESTRAM', result.fee_collected, user2) //console.log(i + '. fee collected: ', result.fee_collected) diff --git a/tests/action-whitelisting.js b/tests/action-whitelisting.js index ae3ee6ec..29bcaa4a 100644 --- a/tests/action-whitelisting.js +++ b/tests/action-whitelisting.js @@ -1,19 +1,19 @@ require('mocha') const {expect} = require('chai') const {newUser, fetchJson, callFioApi, callFioApiSigned, generateFioDomain, timeout} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); /** * Whitelisting does not work with the eosio account - * + * const eosio = { account: 'eosio', publicKey: 'FIO7isxEua78KPVbGzKemH4nj2bWE52gqj8Hkac3tc7jKNvpfWzYS', privateKey: '5KBX1dwHME4VyuUss2sYM25D5ZTDvyYrbEz37UJqwAVAsR4tGuY' } */ - + const fiotoken = { account: 'fio.token', publicKey: 'FIO7isxEua78KPVbGzKemH4nj2bWE52gqj8Hkac3tc7jKNvpfWzYS', @@ -188,7 +188,7 @@ describe(`B. General addaction testing with random contracts and domains (can be it('Call get_actions and confirm action is in table', async () => { try { const json = { - //limit: 100, + //limit: 100, //offset: 0 } actionList = await callFioApi("get_actions", json); @@ -199,7 +199,7 @@ describe(`B. General addaction testing with random contracts and domains (can be found = true; } } - expect(found).to.equal(true); + expect(found).to.equal(true); } catch (err) { console.log('Error', err); expect(err).to.equal(null); @@ -500,7 +500,7 @@ describe(`E. get_actions paging tests`, () => { const json = { } actionList = await callFioApi("get_actions", json); currentCount = actionList.actions.length - expect(currentCount).to.greaterThan(0); + expect(currentCount).to.greaterThan(0); } catch (err) { console.log('Error', err); expect(err).to.equal(null); @@ -529,7 +529,7 @@ describe(`E. get_actions paging tests`, () => { actionList = await callFioApi("get_actions", json); oldCount = currentCount; currentCount = actionList.actions.length - expect(currentCount).to.equal(oldCount + 1); + expect(currentCount).to.equal(oldCount + 1); } catch (err) { console.log('Error', err); expect(err).to.equal(null); @@ -539,7 +539,7 @@ describe(`E. get_actions paging tests`, () => { it(`Call (get_actions, limit=1, offset=0). Expect 1 request.`, async () => { try { const json = { - limit: 1, + limit: 1, offset: 0 } actionList = await callFioApi("get_actions", json); @@ -553,7 +553,7 @@ describe(`E. get_actions paging tests`, () => { it(`Call (get_actions, limit=2, offset=4). Expect 2 requests.`, async () => { try { const json = { - limit: 2, + limit: 2, offset: 4 } actionList = await callFioApi("get_actions", json); @@ -567,7 +567,7 @@ describe(`E. get_actions paging tests`, () => { it(`Call (get_actions, limit=10, offset=15). Expect 10 requests.`, async () => { try { const json = { - limit: 10, + limit: 10, offset: 15 } actionList = await callFioApi("get_actions", json); @@ -581,7 +581,7 @@ describe(`E. get_actions paging tests`, () => { it(`Negative offset. Call (get_actions, limit=1, offset=-1). Expect error type 400: ${config.error.invalidOffset}`, async () => { try { const json = { - limit: 1, + limit: 1, offset: -1 } actionList = await callFioApi("get_actions", json); @@ -592,11 +592,11 @@ describe(`E. get_actions paging tests`, () => { expect(err.statusCode).to.equal(400); } }) - + it(`Negative limit. Call (get_actions, limit=-5, offset=5). Expect error type 400: ${config.error.invalidLimit}`, async () => { try { const json = { - limit: -5, + limit: -5, offset: 5 } actionList = await callFioApi("get_actions", json); diff --git a/tests/addaddress.js b/tests/addaddress.js index b97ea48d..bee52c52 100644 --- a/tests/addaddress.js +++ b/tests/addaddress.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, fetchJson, timeout, callFioApi} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/burn-address.js b/tests/burn-address.js index 18d840a6..76038951 100644 --- a/tests/burn-address.js +++ b/tests/burn-address.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, generateFioAddress, callFioApiSigned, callFioApi, getFees, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { @@ -54,7 +54,7 @@ describe('************************** burn-address.js ************************** expect(err).to.equal(null); } }) - + it(`Burn walletA1.address2. Expect status = 'OK'. Expect fee_collected = 0`, async () => { try { const result = await callFioApiSigned('push_transaction', { @@ -109,7 +109,7 @@ describe('************************** burn-address.js ************************** //console.log('fionames: ', fionames); for (name in fionames.rows) { if (fionames.rows[name].name == walletA1.address2) { - //console.log('fioname: ', fionames.rows[name]); + //console.log('fioname: ', fionames.rows[name]); inTable = true; } } @@ -165,11 +165,11 @@ describe('************************** burn-address.js ************************** //console.log('fionames: ', fionames); for (name in fionames.rows) { if (fionames.rows[name].name == walletA1.address) { - //console.log('bundleCount: ', fionames.rows[name].bundleeligiblecountdown); + //console.log('bundleCount: ', fionames.rows[name].bundleeligiblecountdown); bundleCount = fionames.rows[name].bundleeligiblecountdown; } } - expect(bundleCount).to.equal(0); + expect(bundleCount).to.equal(0); } catch (err) { console.log('Error', err); expect(err).to.equal(null); @@ -239,7 +239,7 @@ describe('************************** burn-address.js ************************** //console.log('fionames: ', fionames); for (name in fionames.rows) { if (fionames.rows[name].name == walletA1.address) { - //console.log('fioname: ', fionames.rows[name]); + //console.log('fioname: ', fionames.rows[name]); inTable = true; } } @@ -607,7 +607,7 @@ describe('E. Test burnfioaddress SDK call (uses chain/burn_fio_address endpoint) expect(err).to.equal(null); } }) - + it(`(SDK) Burn walletA1.address2. Expect status = 'OK'. Expect fee_collected = 0`, async () => { try { const result = await walletA1.sdk.genericAction('burnFioAddress', { @@ -655,7 +655,7 @@ describe('E. Test burnfioaddress SDK call (uses chain/burn_fio_address endpoint) //console.log('fionames: ', fionames); for (name in fionames.rows) { if (fionames.rows[name].name == walletA1.address2) { - //console.log('fioname: ', fionames.rows[name]); + //console.log('fioname: ', fionames.rows[name]); inTable = true; } } @@ -665,4 +665,4 @@ describe('E. Test burnfioaddress SDK call (uses chain/burn_fio_address endpoint) expect(err).to.equal(null); } }) -}) \ No newline at end of file +}) diff --git a/tests/clio.js b/tests/clio.js index 656cb51b..69d186af 100644 --- a/tests/clio.js +++ b/tests/clio.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, randStr, generateFioDomain, generateFioAddress, unlockWallet, callFioApi, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); const exec = require('child_process').exec; @@ -181,7 +181,7 @@ describe(`C. Domain`, () => { describe(`D. Address`, () => { let user1, user2 - let BCHAddress = + let BCHAddress = { chain_code: 'BCH', token_code: 'BCH', @@ -341,7 +341,7 @@ describe(`D. Address`, () => { expect(result.public_addresses[0].token_code).to.equal("FIO") expect(result.public_addresses[0].chain_code).to.equal("FIO") expect(result.public_addresses.length).to.equal(1) - + } catch (err) { console.log('Error', err) expect(err).to.equal(null) @@ -381,12 +381,12 @@ describe(`F. Transfer`, () => { it(`getFioBalance for user2`, async () => { try { - const result = await user2.sdk.genericAction('getFioBalance', { }) + const result = await user2.sdk.genericAction('getFioBalance', { }) //console.log('Result: ', result) prevFundsAmount = result.balance } catch (err) { expect(err.json.message).to.equal(null) - } + } }) it(`transfer ${fundsAmount} FIO to user2 FIO public key`, async () => { @@ -398,7 +398,7 @@ describe(`F. Transfer`, () => { console.log('Error', err) } }) - + it(`user2's FIO public key has an additional ${fundsAmount} FIO`, async () => { const result = await user2.sdk.genericAction('getFioBalance', {}) //console.log('Result: ', result) @@ -425,4 +425,4 @@ describe(`G. Vote Producer`, () => { } }) -}) \ No newline at end of file +}) diff --git a/tests/expired-domains.js b/tests/expired-domains.js index 25b65717..1deb9c09 100644 --- a/tests/expired-domains.js +++ b/tests/expired-domains.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, generateFioAddress, generateFioDomain, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/fee-voting-fee-setting.js b/tests/fee-voting-fee-setting.js index 136f6806..aa637350 100644 --- a/tests/fee-voting-fee-setting.js +++ b/tests/fee-voting-fee-setting.js @@ -19,7 +19,7 @@ require('mocha') const {expect} = require('chai') const {readProdFile, fetchJson, newUser, existingUser, generateFioAddress,generateFioDomain,timeout } = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); let producersList = [], producers = [], newprods = [], sdkprods = [] @@ -265,7 +265,7 @@ describe('************************** fee-voting-fee-setting.js ***************** } }) console.log("regproducer") - + result = await prodA1.sdk.genericAction('pushTransaction', { action: 'voteproducer', account: 'eosio', @@ -7240,4 +7240,4 @@ describe('************************** fee-voting-fee-setting.js ***************** console.log("EDEDEDEDEDED voted successfully for ",countvotesperformed) }) -}) \ No newline at end of file +}) diff --git a/tests/fee-voting-post-contract-set.js b/tests/fee-voting-post-contract-set.js index 13ffd9a4..79b22f34 100644 --- a/tests/fee-voting-post-contract-set.js +++ b/tests/fee-voting-post-contract-set.js @@ -8,7 +8,7 @@ require('mocha') const {expect} = require('chai') const {readProdFile, fetchJson, newUser, existingUser, generateFioAddress,generateFioDomain,timeout } = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); let producersList = [], producers = [], newprods = [], sdkprods = [] diff --git a/tests/fees.js b/tests/fees.js index 7267a494..00025f20 100644 --- a/tests/fees.js +++ b/tests/fees.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { @@ -22,7 +22,7 @@ describe('************************** fees.js ************************** \n Test //console.log('bundledEligible: ', config.api[fioEndpoint].bundledEligible) if (config.api[fioEndpoint].bundledEligible) { const result = await userA1.sdk.genericAction('getFee', { - endPoint: fioEndpoint, + endPoint: fioEndpoint, fioAddress: userA1.address, }) //console.log('Returned fee: ', result) @@ -49,7 +49,7 @@ describe('************************** fees.js ************************** \n Test //console.log('bundledEligible: ', config.api[fioEndpoint].bundledEligible) if (config.api[fioEndpoint].bundledEligible) { const result = await userA1.sdk.genericAction('getFee', { - endPoint: fioEndpoint, + endPoint: fioEndpoint, fioAddress: userA1.address.toUpperCase(), }) //console.log('Returned fee: ', result) diff --git a/tests/fio-request.js b/tests/fio-request.js index 26311952..58eb2a4d 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, fetchJson, callFioApi, timeout} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { @@ -20,7 +20,7 @@ describe(`************************** fio-request.js ************************** \ userA1 = await newUser(faucet); userA2 = await newUser(faucet); }) - + it(`Add BTC addresses to userA1`, async () => { try { const result = await userA1.sdk.genericAction('addPublicAddresses', { @@ -36,17 +36,17 @@ describe(`************************** fio-request.js ************************** \ technologyProviderId: '' }) //console.log('Result:', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') } catch (err) { console.log('Error', err) //expect(err).to.equal(null) - } + } }) it(`userA1 requests funds from userA2`, async () => { try { - const result = await userA1.sdk.genericAction('requestFunds', { - payerFioAddress: userA2.address, + const result = await userA1.sdk.genericAction('requestFunds', { + payerFioAddress: userA2.address, payeeFioAddress: userA1.address, payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', amount: payment, @@ -58,9 +58,9 @@ describe(`************************** fio-request.js ************************** \ technologyProviderId: '', hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? offlineUrl: '' - }) + }) //console.log('Result: ', result) - expect(result.status).to.equal('requested') + expect(result.status).to.equal('requested') } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) @@ -72,11 +72,11 @@ describe(`************************** fio-request.js ************************** \ const result = await userA1.sdk.genericAction('getSentFioRequests', { limit: '', offset: '' - }) + }) //console.log('result: ', result) //console.log('content: ', result.requests[0].content) requestId = result.requests[0].fio_request_id - expect(result.requests[0].content.memo).to.equal(requestMemo) + expect(result.requests[0].content.memo).to.equal(requestMemo) } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) @@ -88,11 +88,11 @@ describe(`************************** fio-request.js ************************** \ const result = await userA2.sdk.genericAction('getPendingFioRequests', { limit: '', offset: '' - }) + }) //console.log('result: ', result) //console.log('content: ', result.requests[0].content) - expect(result.requests[0].fio_request_id).to.equal(requestId) - expect(result.requests[0].content.memo).to.equal(requestMemo) + expect(result.requests[0].fio_request_id).to.equal(requestId) + expect(result.requests[0].content.memo).to.equal(requestMemo) } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) @@ -105,9 +105,9 @@ describe(`************************** fio-request.js ************************** \ fioAddress: userA1.address, chainCode: "BTC", tokenCode: "BTC" - }) + }) //console.log('Result', result) - expect(result.public_address).to.equal(btcPubAdd) + expect(result.public_address).to.equal(btcPubAdd) } catch (err) { console.log('Error', err) expect(err).to.equal(null) @@ -162,11 +162,11 @@ describe(`************************** fio-request.js ************************** \ const result = await userA1.sdk.genericAction('getSentFioRequests', { limit: '', offset: '' - }) + }) //console.log('result: ', result) //console.log('content: ', result.requests[0].content) - expect(result.requests[0].content.memo).to.equal(requestMemo) - expect(result.requests[0].status).to.equal('sent_to_blockchain') + expect(result.requests[0].content.memo).to.equal(requestMemo) + expect(result.requests[0].status).to.equal('sent_to_blockchain') } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) @@ -179,10 +179,10 @@ describe(`************************** fio-request.js ************************** \ limit: '', offset: '', tokenCode: 'BTC' - }) + }) //console.log('result: ', result) //console.log('content: ', result.obt_data_records[0].content) - expect(result.obt_data_records[0].content.memo).to.equal(obtMemo) + expect(result.obt_data_records[0].content.memo).to.equal(obtMemo) } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) @@ -195,16 +195,16 @@ describe(`************************** fio-request.js ************************** \ limit: '', offset: '', tokenCode: 'BTC' - }) + }) //console.log('result: ', result) //console.log('content: ', result.obt_data_records[0].content) - expect(result.obt_data_records[0].content.memo).to.equal(obtMemo) + expect(result.obt_data_records[0].content.memo).to.equal(obtMemo) } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) } }) - + }) describe(`B. Test FIO Request error conditions`, () => { @@ -218,7 +218,7 @@ describe(`B. Test FIO Request error conditions`, () => { userB2 = await newUser(faucet); userB3 = await newUser(faucet); }) - + it(`Add BTC address to userB1`, async () => { try { const result = await userB1.sdk.genericAction('addPublicAddresses', { @@ -234,17 +234,17 @@ describe(`B. Test FIO Request error conditions`, () => { technologyProviderId: '' }) //console.log('Result:', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') } catch (err) { console.log('Error', err) //expect(err).to.equal(null) - } + } }) it(`userB1 requests funds from userB2`, async () => { try { - const result = await userB1.sdk.genericAction('requestFunds', { - payerFioAddress: userB2.address, + const result = await userB1.sdk.genericAction('requestFunds', { + payerFioAddress: userB2.address, payeeFioAddress: userB1.address, payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', amount: payment, @@ -256,10 +256,10 @@ describe(`B. Test FIO Request error conditions`, () => { technologyProviderId: '', hash: '', offLineUrl: '' - }) + }) //console.log('Result: ', result.fio_request_id) userB1RequestId = result.fio_request_id - expect(result.status).to.equal('requested') + expect(result.status).to.equal('requested') } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) @@ -488,17 +488,17 @@ describe(`B. Test FIO Request error conditions`, () => { technologyProviderId: '' }) //console.log('Result:', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') } catch (err) { console.log('Error', err) expect(err).to.equal(null) - } + } }) it(`userB1 request #2 from userB2`, async () => { try { - const result = await userB1.sdk.genericAction('requestFunds', { - payerFioAddress: userB2.address, + const result = await userB1.sdk.genericAction('requestFunds', { + payerFioAddress: userB2.address, payeeFioAddress: userB1.address, payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', amount: payment, @@ -510,10 +510,10 @@ describe(`B. Test FIO Request error conditions`, () => { technologyProviderId: '', hash: '', offLineUrl: '' - }) + }) //console.log('Result: ', result) userB1RequestId2 = result.fio_request_id - expect(result.status).to.equal('requested') + expect(result.status).to.equal('requested') } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) @@ -553,7 +553,7 @@ describe(`B. Test FIO Request error conditions`, () => { try { const result = await userB1.sdk.genericAction('getFioBalance', { fioPublicKey: userB1.publicKey - }) + }) userB1Balance = result.balance //console.log('userB1 fio balance', result) } catch (err) { @@ -575,14 +575,14 @@ describe(`B. Test FIO Request error conditions`, () => { } catch (err) { console.log('Error: ', err); expect(err).to.equal(null); - } + } }) it(`Verify balance for userB1 = 0`, async () => { try { const result = await userB1.sdk.genericAction('getFioBalance', { fioPublicKey: userB1.publicKey - }) + }) //console.log('userB1 fio balance', result) expect(result.balance).to.equal(0) } catch (err) { @@ -607,11 +607,11 @@ describe(`B. Test FIO Request error conditions`, () => { //console.log('fionames: ', fionames); for (name in fionames.rows) { if (fionames.rows[name].name == userB1.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); + //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); bundleCount = fionames.rows[name].bundleeligiblecountdown; } } - expect(bundleCount).to.equal(0); + expect(bundleCount).to.equal(0); } catch (err) { console.log('Error', err); expect(err).to.equal(null); @@ -640,8 +640,8 @@ describe(`B. Test FIO Request error conditions`, () => { it(`userB2 requests funds from userB3`, async () => { try { - const result = await userB2.sdk.genericAction('requestFunds', { - payerFioAddress: userB3.address, + const result = await userB2.sdk.genericAction('requestFunds', { + payerFioAddress: userB3.address, payeeFioAddress: userB2.address, payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', amount: payment, @@ -653,10 +653,10 @@ describe(`B. Test FIO Request error conditions`, () => { technologyProviderId: '', hash: '', offLineUrl: '' - }) + }) //console.log('Result: ', result) userB1RequestId3 = result.fio_request_id - expect(result.status).to.equal('requested') + expect(result.status).to.equal('requested') } catch (err) { console.log('Error: ', err.json) expect(err).to.equal(null) @@ -676,7 +676,7 @@ describe(`B. Test FIO Request error conditions`, () => { } }) //console.log('Result:', result) - expect(result.status).to.equal('request_rejected') + expect(result.status).to.equal('request_rejected') } catch (err) { console.log('Error', err) expect(err).to.equal(null) diff --git a/tests/history.js b/tests/history.js index 76e82318..0ff6d4bf 100644 --- a/tests/history.js +++ b/tests/history.js @@ -5,7 +5,7 @@ require('mocha') const {expect} = require('chai') const {callFioHistoryApi, existingUser, newUser, generateFioDomain, generateFioAddress, createKeypair, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { @@ -38,7 +38,7 @@ describe('************************** history.js ************************** \n A. } catch (err) { console.log('Error: ', err); expect(err).to.equal(null); - } + } }) it(`get_transfers all`, async () => { @@ -93,7 +93,7 @@ describe('B. get_transfers to non-existent account', () => { } catch (err) { console.log('Error: ', err); expect(err).to.equal(null); - } + } }) it('Confirm single, initial trnsfiopubky transfer', async () => { @@ -110,7 +110,7 @@ describe('B. get_transfers to non-existent account', () => { } catch (err) { console.log('Error: ', err); expect(err).to.equal(null); - } + } }) it(`Send ${transferAmount} sufs from userB1 to userB2`, async () => { @@ -126,7 +126,7 @@ describe('B. get_transfers to non-existent account', () => { } catch (err) { console.log('Error: ', err); expect(err).to.equal(null); - } + } }) it(`Confirm there are three transfers (one for transfer and one for fee) and the second is transfer with transfer_amount= ${transferAmount}`, async () => { @@ -138,7 +138,7 @@ describe('B. get_transfers to non-existent account', () => { } result = await callFioHistoryApi("get_transfers", json); //console.log('Result: ', result) - expect(result.transfers.length).to.equal(3); + expect(result.transfers.length).to.equal(3); expect(result.transfers[1].action).to.equal('trnsfiopubky'); expect(result.transfers[1].transfer_amount).to.equal(transferAmount); expect(result.transfers[2].action).to.equal('transfer'); @@ -146,13 +146,13 @@ describe('B. get_transfers to non-existent account', () => { } catch (err) { console.log('Error: ', err); expect(err).to.equal(null); - } + } }) it('userB1 registerFioDomain', async () => { try { - const result = await userB1.genericAction('registerFioDomain', { - fioDomain: userB1.domain, + const result = await userB1.genericAction('registerFioDomain', { + fioDomain: userB1.domain, maxFee: config.api.register_fio_domain.fee, walletFioAddress: '' }) @@ -161,7 +161,7 @@ describe('B. get_transfers to non-existent account', () => { } catch (err) { console.log('Error: ', err.json); expect(err).to.equal(null); - } + } }) it(`Confirm there are four transfers and the fourth is transfer is a ${config.api.register_fio_domain.fee} fee for domain registration`, async () => { @@ -173,23 +173,23 @@ describe('B. get_transfers to non-existent account', () => { } result = await callFioHistoryApi("get_transfers", json); //console.log('Result: ', result) - expect(result.transfers.length).to.equal(4); + expect(result.transfers.length).to.equal(4); expect(result.transfers[3].action).to.equal('transfer'); expect(result.transfers[3].fee_amount).to.equal(config.api.register_fio_domain.fee); } catch (err) { console.log('Error: ', err); expect(err).to.equal(null); - } + } }) - + it('userB1 registerFioAddress', async () => { - const result = await userB1.genericAction('registerFioAddress', { + const result = await userB1.genericAction('registerFioAddress', { fioAddress: userB1.address, maxFee: config.api.register_fio_address.fee, walletFioAddress: '' }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') }) it(`Confirm there are five transfers and the fifth is a ${config.api.register_fio_address.fee} fee for address registration`, async () => { @@ -201,13 +201,13 @@ describe('B. get_transfers to non-existent account', () => { } result = await callFioHistoryApi("get_transfers", json); //console.log('Result: ', result) - expect(result.transfers.length).to.equal(5); + expect(result.transfers.length).to.equal(5); expect(result.transfers[4].action).to.equal('transfer'); expect(result.transfers[4].fee_amount).to.equal(config.api.register_fio_address.fee); } catch (err) { console.log('Error: ', err); expect(err).to.equal(null); - } + } }) diff --git a/tests/locks.js b/tests/locks.js index 22185604..1f999012 100644 --- a/tests/locks.js +++ b/tests/locks.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, unlockWallet, generateFioDomain, addLock, timeout, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); let total_voted_fio @@ -32,8 +32,8 @@ describe(`************************** locks.js ************************** \n A. T it(`Register fee test domain pre lock. `, async () => { try { - const result = await userA1.sdk.genericAction('registerFioDomain', { - fioDomain: userA1.domain2, + const result = await userA1.sdk.genericAction('registerFioDomain', { + fioDomain: userA1.domain2, maxFee: config.api.register_fio_domain.fee, //walletFioAddress: '' }) @@ -41,7 +41,7 @@ describe(`************************** locks.js ************************** \n A. T expect(result.status).to.equal('OK') } catch (err) { console.log('Error: ', err) - } + } }) it.skip(`Apply Lock Type ${lockType} to 500 FIO for userA1`, async () => { @@ -51,20 +51,20 @@ describe(`************************** locks.js ************************** \n A. T expect(result).to.have.all.keys('transaction_id', 'processed') } catch (err) { console.log('Error: ', err) - } + } }) it(`Register fee test domain post lock returns: ${config.error.regdomainLockedAccount} `, async () => { try { - const result = await userA1.sdk.genericAction('registerFioDomain', { - fioDomain: userA1.domain3, + const result = await userA1.sdk.genericAction('registerFioDomain', { + fioDomain: userA1.domain3, maxFee: config.api.register_fio_domain.fee, }) //console.log('Result: ', result) } catch (err) { //console.log('Error: ', err.json) expect(err.json.fields[0].error).to.equal(config.error.regdomainLockedAccount) - } + } }) }) diff --git a/tests/paging.js b/tests/paging.js index 010f39d1..65633b30 100644 --- a/tests/paging.js +++ b/tests/paging.js @@ -2,7 +2,7 @@ require('mocha') config = require('../config.js'); const {expect} = require('chai') const {newUser, fetchJson, generateFioDomain, generateFioAddress, createKeypair, callFioApi} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') before(async () => { @@ -32,7 +32,7 @@ describe(`************************** paging.js ************************** \n A. //console.log('Error: ', err); //console.log('Error: ', err.json); expect(err).to.equal(null); - } + } }) it(`API call (get_fio_domains, no limit param, no offset param). Expect error type 404: ${config.error.noFioDomains}`, async () => { @@ -68,11 +68,11 @@ describe(`************************** paging.js ************************** \n A. for (i = 0; i < domainCount; i++) { try { newDomain = i + generateFioDomain(8); - const result = await userA1.genericAction('registerFioDomain', { - fioDomain: newDomain, + const result = await userA1.genericAction('registerFioDomain', { + fioDomain: newDomain, maxFee: config.api.register_fio_domain.fee, technologyProviderId: '' - }) + }) //console.log('Result: ', result) expect(result.status).to.equal('OK') } catch (err) { @@ -170,7 +170,7 @@ describe(`************************** paging.js ************************** \n A. //console.log('Result: ', result); expect(result.fio_domains.length).to.equal(2); expect(result.fio_domains[0].fio_domain.charAt(0)).to.equal('4'); // First character of domain = 4 (5th domain in list) - expect(result.fio_domains[1].fio_domain.charAt(0)).to.equal('5'); + expect(result.fio_domains[1].fio_domain.charAt(0)).to.equal('5'); } catch (err) { console.log('Error', err) expect(err).to.equal(null) @@ -187,7 +187,7 @@ describe(`************************** paging.js ************************** \n A. //console.log('Result: ', result); expect(result.fio_domains.length).to.equal(2); expect(result.fio_domains[0].fio_domain.charAt(0)).to.equal('4'); // First character of domain = 4 (5th domain in list) - expect(result.fio_domains[1].fio_domain.charAt(0)).to.equal('5'); + expect(result.fio_domains[1].fio_domain.charAt(0)).to.equal('5'); } catch (err) { console.log('Error', err) expect(err).to.equal(null) @@ -204,9 +204,9 @@ describe(`************************** paging.js ************************** \n A. result = await callFioApi("get_fio_domains", json); //console.log('Result: ', result); expect(result.fio_domains.length).to.equal(5); - expect(result.fio_domains[0].fio_domain.charAt(0)).to.equal('1'); - expect(result.fio_domains[0].fio_domain.charAt(1)).to.equal('5'); // 15 - expect(result.fio_domains[4].fio_domain.charAt(0)).to.equal('1'); + expect(result.fio_domains[0].fio_domain.charAt(0)).to.equal('1'); + expect(result.fio_domains[0].fio_domain.charAt(1)).to.equal('5'); // 15 + expect(result.fio_domains[4].fio_domain.charAt(0)).to.equal('1'); expect(result.fio_domains[4].fio_domain.charAt(1)).to.equal('9'); // 19 } catch (err) { console.log('Error', err) @@ -223,9 +223,9 @@ describe(`************************** paging.js ************************** \n A. }) //console.log('Result: ', result); expect(result.fio_domains.length).to.equal(5); - expect(result.fio_domains[0].fio_domain.charAt(0)).to.equal('1'); - expect(result.fio_domains[0].fio_domain.charAt(1)).to.equal('5'); // 15 - expect(result.fio_domains[4].fio_domain.charAt(0)).to.equal('1'); + expect(result.fio_domains[0].fio_domain.charAt(0)).to.equal('1'); + expect(result.fio_domains[0].fio_domain.charAt(1)).to.equal('5'); // 15 + expect(result.fio_domains[4].fio_domain.charAt(0)).to.equal('1'); expect(result.fio_domains[4].fio_domain.charAt(1)).to.equal('9'); // 19 } catch (err) { console.log('Error', err) @@ -264,7 +264,7 @@ describe(`************************** paging.js ************************** \n A. expect(err.errorCode).to.equal(400); } }) - + it(`Negative limit. Call (get_fio_domains, limit=-5, offset=5). Expect error type 400: ${config.error.invalidLimit}`, async () => { try { const json = { @@ -400,7 +400,7 @@ describe(`B. get_fio_addresses paging: Register multiple addresses and page thro } catch (err) { //console.log('Error: ', err); expect(err).to.equal(null); - } + } }) it(`Call (get_fio_addresses, no limit param, no offset param). Expect error type 404: ${config.error.noFioAddresses}`, async () => { @@ -435,11 +435,11 @@ describe(`B. get_fio_addresses paging: Register multiple addresses and page thro it(`Register domain for userB1`, async () => { try { userB1.domain = generateFioDomain(8); - const result = await userB1.genericAction('registerFioDomain', { - fioDomain: userB1.domain, + const result = await userB1.genericAction('registerFioDomain', { + fioDomain: userB1.domain, maxFee: config.api.register_fio_domain.fee, technologyProviderId: '' - }) + }) //console.log('Result: ', result) expect(result.status).to.equal('OK') } catch (err) { @@ -451,11 +451,11 @@ describe(`B. get_fio_addresses paging: Register multiple addresses and page thro for (i = 0; i < addressCount; i++) { try { newAddress = i + generateFioAddress(userB1.domain, 5) - const result = await userB1.genericAction('registerFioAddress', { - fioAddress: newAddress, + const result = await userB1.genericAction('registerFioAddress', { + fioAddress: newAddress, maxFee: config.api.register_fio_address.fee, walletFioAddress: '' - }) + }) //console.log('Result: ', result) expect(result.status).to.equal('OK') } catch (err) { @@ -535,7 +535,7 @@ describe(`B. get_fio_addresses paging: Register multiple addresses and page thro }) //console.log('Result: ', result); expect(result.fio_addresses.length).to.equal(1); - expect(result.fio_addresses[0].fio_address.charAt(0)).to.equal('0'); + expect(result.fio_addresses[0].fio_address.charAt(0)).to.equal('0'); } catch (err) { console.log('Error', err) expect(err).to.equal(null) @@ -553,7 +553,7 @@ describe(`B. get_fio_addresses paging: Register multiple addresses and page thro //console.log('Result: ', result); expect(result.fio_addresses.length).to.equal(2); expect(result.fio_addresses[0].fio_address.charAt(0)).to.equal('4'); // First character of address = 4 (5th address in list) - expect(result.fio_addresses[1].fio_address.charAt(0)).to.equal('5'); + expect(result.fio_addresses[1].fio_address.charAt(0)).to.equal('5'); } catch (err) { console.log('Error', err) expect(err).to.equal(null) @@ -570,9 +570,9 @@ describe(`B. get_fio_addresses paging: Register multiple addresses and page thro result = await callFioApi("get_fio_addresses", json); //console.log('Result: ', result); expect(result.fio_addresses.length).to.equal(5); - expect(result.fio_addresses[0].fio_address.charAt(0)).to.equal('1'); - expect(result.fio_addresses[0].fio_address.charAt(1)).to.equal('5'); // 15 - expect(result.fio_addresses[4].fio_address.charAt(0)).to.equal('1'); + expect(result.fio_addresses[0].fio_address.charAt(0)).to.equal('1'); + expect(result.fio_addresses[0].fio_address.charAt(1)).to.equal('5'); // 15 + expect(result.fio_addresses[4].fio_address.charAt(0)).to.equal('1'); expect(result.fio_addresses[4].fio_address.charAt(1)).to.equal('9'); // 19 } catch (err) { console.log('Error', err) @@ -589,9 +589,9 @@ describe(`B. get_fio_addresses paging: Register multiple addresses and page thro }) //console.log('Result: ', result); expect(result.fio_addresses.length).to.equal(5); - expect(result.fio_addresses[0].fio_address.charAt(0)).to.equal('1'); - expect(result.fio_addresses[0].fio_address.charAt(1)).to.equal('5'); // 15 - expect(result.fio_addresses[4].fio_address.charAt(0)).to.equal('1'); + expect(result.fio_addresses[0].fio_address.charAt(0)).to.equal('1'); + expect(result.fio_addresses[0].fio_address.charAt(1)).to.equal('5'); // 15 + expect(result.fio_addresses[4].fio_address.charAt(0)).to.equal('1'); expect(result.fio_addresses[4].fio_address.charAt(1)).to.equal('9'); // 19 } catch (err) { console.log('Error', err) @@ -630,7 +630,7 @@ describe(`B. get_fio_addresses paging: Register multiple addresses and page thro expect(err.errorCode).to.equal(400); } }) - + it(`Negative limit. Call (get_fio_addresses, limit=-5, offset=5). Expect error type 400: ${config.error.invalidLimit}`, async () => { try { const json = { diff --git a/tests/producer-fee-setting.js b/tests/producer-fee-setting.js index f09c221d..852a9f7b 100644 --- a/tests/producer-fee-setting.js +++ b/tests/producer-fee-setting.js @@ -1,13 +1,13 @@ require('mocha') const {expect} = require('chai') const {getBlock, readProdFile, getTopprods, getTable, timeout, callFioApi, callFioApiSigned, getFees, newUser, existingUser, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); let producersList = [], producers = [], submit_fee_ratios_fee, submit_fee_multiplier_fee async function createProds() { - for (prod in producersList) { + for (prod in producersList) { // Create the producers on the node and make a test sdk object for them //producers[prod] = await newUser(faucet, producersList[prod].account, producersList[prod].privateKey, producersList[prod].publicKey, producersList[prod].domain, producersList[prod].address); prodAccount = producersList[prod].account; @@ -55,7 +55,7 @@ before(async () => { describe.skip('************************** producer_fee-setting.js ************************** \n A. Set fee ratio to zero for bp1 and confirm no exceptions thrown (MAS-1888).', () => { let bp = 'qbxn5zhw2ypw' // (bp1) - + it('Get action_mroot from latest block and confirm it is not zero.', async () => { const fiourl = config.URL + "/v1/chain/"; getInfo = await (await fetch(fiourl + 'get_info')).json(); @@ -81,7 +81,7 @@ describe.skip('************************** producer_fee-setting.js ************** } catch (err) { console.log('Error: ', err); expect(err).to.equal(null); - } + } }) it('Set fee ratio to 0 for bp1', async () => { @@ -102,7 +102,7 @@ describe.skip('************************** producer_fee-setting.js ************** } catch (err) { console.log('Error: ', err.json.fields); expect(err).to.equal(null); - } + } }) it('Call computefees action', async () => { @@ -118,7 +118,7 @@ describe.skip('************************** producer_fee-setting.js ************** } catch (err) { console.log('Error: ', err.json.fields); expect(err).to.equal(null); - } + } }) it('Get action_mroot from latest block and confirm it is not zero.', async () => { @@ -142,14 +142,14 @@ describe('B. Test 15 prod activation for fee setting.', () => { //console.log("topprods: ", topprods) if (topprods.rows.length == 3) { // This is a first test run for a localhost 3 node test environment, so register the 21 producers firstRun = true; - for (prod in producersList) { + for (prod in producersList) { // Create the producers on the node and make a test sdk object for them let prodAccount = producersList[prod].account; - producers[prodAccount] = await newUser(faucet, producersList[prod].account, producersList[prod].privateKey, producersList[prod].publicKey, producersList[prod].domain, producersList[prod].address); + producers[prodAccount] = await newUser(faucet, producersList[prod].account, producersList[prod].privateKey, producersList[prod].publicKey, producersList[prod].domain, producersList[prod].address); // Register the producer - console.log('Register the producer'); - console.log('ProdAccount: ', producers[prodAccount].sdk); - console.log('ProdAccount: ', producers[prodAccount].privateKey); + console.log('Register the producer'); + console.log('ProdAccount: ', producers[prodAccount].sdk); + console.log('ProdAccount: ', producers[prodAccount].privateKey); const result1 = await producers[prodAccount].sdk.genericAction('pushTransaction', { action: 'regproducer', account: 'eosio', @@ -163,7 +163,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { } }) // Have the producer vote for themselves - console.log('Have the producer vote for themselves'); + console.log('Have the producer vote for themselves'); const result2 = await producers[prodAccount].sdk.genericAction('pushTransaction', { action: 'voteproducer', account: 'eosio', @@ -181,7 +181,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { //console.log('Wait 60 seconds for topprods table to update'); //await timeout(60000); } else { // Just create the test sdk objects for the existing producers - for (prod in producersList) { + for (prod in producersList) { //console.log("producersList[prod]: ", producersList[prod]) producers[producersList[prod].account] = await existingUser(producersList[prod].account, producersList[prod].privateKey, producersList[prod].publicKey, producersList[prod].domain, producersList[prod].address) } @@ -189,8 +189,8 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err.json); expect(err).to.equal(null); - } - }) + } + }) it('If first run wait 30 seconds for topprods table to update.', async () => { if (firstRun) { @@ -211,7 +211,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err); expect(err).to.equal(null); - } + } }) it('Get top prods', async () => { @@ -227,7 +227,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err.json); expect(err).to.equal(null); - } + } }) it.skip('Confirm multipliers table is empty', async () => { @@ -238,8 +238,8 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err.json) expect(err).to.equal(null); - } - }) + } + }) it.skip('Confirm ratio table is empty', async () => { try { @@ -249,8 +249,8 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err.json) expect(err).to.equal(null); - } - }) + } + }) it('Set multipliers to 1 for topprods', async () => { let account; @@ -259,7 +259,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { json: true, code: 'eosio', scope: 'eosio', - table: 'topprods', + table: 'topprods', limit: 1000, reverse: false, show_payer: false @@ -284,7 +284,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err); expect(err).to.equal(null); - } + } }) it(`Show multipliers table.`, async () => { @@ -293,7 +293,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { json: true, code: 'fio.fee', scope: 'fio.fee', - table: 'feevoters', + table: 'feevoters', limit: 1000, reverse: false, show_payer: false @@ -314,7 +314,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err); expect(err).to.equal(null); - } + } }) it('Set register_fio_domain fee ratio for 1-7 prods to 100 FIO', async () => { @@ -345,7 +345,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err.json.fields); expect(err).to.equal(null); - } + } }) it('Call computefees action', async () => { @@ -361,20 +361,20 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err.json.fields); expect(err).to.equal(null); - } + } }) it('Confirm fees have not changed', async () => { try { let prevFees = fees; fees = await getFees(); - for (endpoint in fees) { + for (endpoint in fees) { expect(fees[endpoint]).to.equal(prevFees[endpoint]); } } catch (err) { console.log('Error: ', err.json); expect(err).to.equal(null); - } + } }) it('Set register_fio_domain fee ratio for 8-14 prods to 200 FIO', async () => { @@ -404,7 +404,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err.json); expect(err).to.equal(null); - } + } }) it('Call computefees action', async () => { @@ -420,20 +420,20 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err.json.fields); expect(err).to.equal(null); - } + } }) it('Confirm fees have not changed (only 14 fee ratio votes)', async () => { try { let prevFees = fees; fees = await getFees(); - for (endpoint in fees) { + for (endpoint in fees) { expect(fees[endpoint]).to.equal(prevFees[endpoint]); } } catch (err) { console.log('Error: ', err.json); expect(err).to.equal(null); - } + } }) it('Set register_fio_domain fee ratio for 15th prod to 100 FIO', async () => { @@ -461,20 +461,20 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err.json); expect(err).to.equal(null); - } + } }) it('Confirm fees have not changed since computefees has not been run', async () => { try { let prevFees = fees; fees = await getFees(); - for (endpoint in fees) { + for (endpoint in fees) { expect(fees[endpoint]).to.equal(prevFees[endpoint]); } } catch (err) { console.log('Error: ', err.json); expect(err).to.equal(null); - } + } }) it(`Show ratios table.`, async () => { @@ -483,7 +483,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { json: true, code: 'fio.fee', scope: 'fio.fee', - table: 'feevotes2', + table: 'feevotes2', limit: 1000, reverse: false, show_payer: false @@ -512,7 +512,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err.json.fields); expect(err).to.equal(null); - } + } }) it('Confirm only register_fio_domain fee changed to 100 FIO', async () => { @@ -520,7 +520,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { let value = 100000000000; let prevFees = fees; fees = await getFees(); - for (endpoint in fees) { + for (endpoint in fees) { console.log(endpoint + ' = ' + fees[endpoint]) if (endpoint == 'register_fio_domain') { expect(fees[endpoint]).to.equal(value); @@ -531,7 +531,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err); expect(err).to.equal(null); - } + } }) /* it('Set register_fio_domain fee ratio for 16th prod to 200 FIO', async () => { @@ -559,7 +559,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err.json); expect(err).to.equal(null); - } + } }) it('Call computefees action', async () => { @@ -575,7 +575,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err.json.fields); expect(err).to.equal(null); - } + } }) it('Confirm fees have not changed (even amount does what??)', async () => { @@ -584,13 +584,13 @@ describe('B. Test 15 prod activation for fee setting.', () => { console.log('prevFees: ', prevFees) fees = await getFees(); console.log('Fees: ', fees) - for (endpoint in fees) { + for (endpoint in fees) { expect(fees[endpoint]).to.equal(prevFees[endpoint]); } } catch (err) { console.log('Error: ', err); expect(err).to.equal(null); - } + } }) it('Set register_fio_domain fee ratio for 17th prod to 200 FIO', async () => { @@ -618,7 +618,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err.json); expect(err).to.equal(null); - } + } }) it('Call computefees action', async () => { @@ -634,7 +634,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err.json.fields); expect(err).to.equal(null); - } + } }) it('Confirm only register_fio_domain fee changed to 200 FIO', async () => { @@ -642,7 +642,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { let value = 200000000000; let prevFees = fees; fees = await getFees(); - for (endpoint in fees) { + for (endpoint in fees) { console.log(endpoint + ' = ' + fees[endpoint]) if (endpoint == 'register_fio_domain') { expect(fees[endpoint]).to.equal(value); @@ -653,7 +653,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err.json); expect(err).to.equal(null); - } + } }) it('Wait 60 seconds.', async () => { @@ -671,7 +671,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { json: true, code: 'eosio', scope: 'eosio', - table: 'topprods', + table: 'topprods', limit: 1000, reverse: false, show_payer: false @@ -696,7 +696,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err); expect(err).to.equal(null); - } + } }) it('Call computefees action', async () => { @@ -712,7 +712,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err.json.fields); expect(err).to.equal(null); - } + } }) it('Confirm only register_fio_domain fee changed to 400 FIO', async () => { @@ -720,7 +720,7 @@ describe('B. Test 15 prod activation for fee setting.', () => { let value = 400000000000; let prevFees = fees; fees = await getFees(); - for (endpoint in fees) { + for (endpoint in fees) { console.log(endpoint + ' = ' + fees[endpoint]) if (endpoint == 'register_fio_domain') { expect(fees[endpoint]).to.equal(value); @@ -731,10 +731,10 @@ describe('B. Test 15 prod activation for fee setting.', () => { } catch (err) { console.log('Error: ', err.json); expect(err).to.equal(null); - } + } }) */ - + }) describe('C. Test invalid multipliers and ratios (using producer #20)', () => { @@ -745,15 +745,15 @@ describe('C. Test invalid multipliers and ratios (using producer #20)', () => { topprods = await getTopprods(); //console.log("topprods: ", topprods) if (topprods.rows.length == 3) { // This is a first test run for a localhost 3 node test environment, so register the 21 producers - for (prod in producersList) { + for (prod in producersList) { // Create the producers on the node and make a test sdk object for them //producers[prod] = await newUser(faucet, producersList[prod].account, producersList[prod].privateKey, producersList[prod].publicKey, producersList[prod].domain, producersList[prod].address); let prodAccount = producersList[prod].account; - producers[prodAccount] = await newUser(faucet, producersList[prod].account, producersList[prod].privateKey, producersList[prod].publicKey, producersList[prod].domain, producersList[prod].address); + producers[prodAccount] = await newUser(faucet, producersList[prod].account, producersList[prod].privateKey, producersList[prod].publicKey, producersList[prod].domain, producersList[prod].address); // Register the producer - console.log('Register the producer'); - console.log('ProdAccount: ', producers[prodAccount].sdk); - console.log('ProdAccount: ', producers[prodAccount].privateKey); + console.log('Register the producer'); + console.log('ProdAccount: ', producers[prodAccount].sdk); + console.log('ProdAccount: ', producers[prodAccount].privateKey); const result1 = await producers[prodAccount].sdk.genericAction('pushTransaction', { action: 'regproducer', account: 'eosio', @@ -767,7 +767,7 @@ describe('C. Test invalid multipliers and ratios (using producer #20)', () => { } }) // Have the producer vote for themselves - console.log('Have the producer vote for themselves'); + console.log('Have the producer vote for themselves'); const result2 = await producers[prodAccount].sdk.genericAction('pushTransaction', { action: 'voteproducer', account: 'eosio', @@ -785,7 +785,7 @@ describe('C. Test invalid multipliers and ratios (using producer #20)', () => { console.log('Wait 60 seconds for topprods table to update'); await timeout(60000); } else { // Just create the test sdk objects for the existing producers - for (prod in producersList) { + for (prod in producersList) { //console.log("producersList[prod]: ", producersList[prod]) //producers[prod] = await existingUser(producersList[prod].account, producersList[prod].privateKey, producersList[prod].publicKey, producersList[prod].domain, producersList[prod].address) producers[producersList[prod].account] = await existingUser(producersList[prod].account, producersList[prod].privateKey, producersList[prod].publicKey, producersList[prod].domain, producersList[prod].address) @@ -794,8 +794,8 @@ describe('C. Test invalid multipliers and ratios (using producer #20)', () => { } catch (err) { console.log('Error: ', err.json); expect(err).to.equal(null); - } - }) + } + }) it.skip(`Bug: .Set fee ratio to negative number gives error: ${config.error.invalidRatioFeeError}`, async () => { try { @@ -820,7 +820,7 @@ describe('C. Test invalid multipliers and ratios (using producer #20)', () => { } catch (err) { //console.log('Error: ', err.message); expect(err.message).to.equal(config.error.invalidRatioFeeError) - } + } }) it(`Set fee ratio to float (123.456) number gives error: ${config.error.invalidRatioFeeError}`, async () => { @@ -846,7 +846,7 @@ describe('C. Test invalid multipliers and ratios (using producer #20)', () => { } catch (err) { //console.log('Error: ', err.message); expect(err.message).to.equal(config.error.invalidRatioFeeError) - } + } }) it(`Set fee ratio to 1,000,000,000,000,000,000,000,000 number gives error: ${config.error.invalidRatioFeeError}`, async () => { @@ -873,7 +873,7 @@ describe('C. Test invalid multipliers and ratios (using producer #20)', () => { } catch (err) { //console.log('Error: ', err.message); expect(err.message).to.equal(config.error.invalidRatioFeeError) - } + } }) it(`Set multiplier to negative number gives error: ${config.error.invalidMultiplierFeeError}`, async () => { @@ -899,7 +899,7 @@ describe('C. Test invalid multipliers and ratios (using producer #20)', () => { } catch (err) { //console.log('Error: ', err); expect(err.message).to.equal(config.error.invalidMultiplierFeeError) - } + } }) it(`Set fee multiplier to 1,000,000,000,000,000,000 number gives error: ${config.error.invalidMultiplierFeeError}`, async () => { @@ -925,7 +925,7 @@ describe('C. Test invalid multipliers and ratios (using producer #20)', () => { } catch (err) { //console.log('Error: ', err.message); expect(err.message).to.equal(config.error.invalidMultiplierFeeError) - } + } }) - -}) \ No newline at end of file + +}) diff --git a/tests/producer.js b/tests/producer.js index b130a2d0..f2efeb55 100644 --- a/tests/producer.js +++ b/tests/producer.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, generateFioAddress, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { @@ -35,13 +35,13 @@ describe('************************** producer.js ************************** \n A }) it(`Register userA1 address #2`, async () => { - const result = await userA1.sdk.genericAction('registerFioAddress', { + const result = await userA1.sdk.genericAction('registerFioAddress', { fioAddress: userA1.address2, maxFee: config.api.register_fio_address.fee, walletFioAddress: '' }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') }) it(`Register prodA1 as producer`, async () => { @@ -59,10 +59,10 @@ describe('************************** producer.js ************************** \n A } }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') } catch (err) { console.log('Error: ', err.json) - } + } }) it(`userA1 votes for prodA1 using address #1`, async () => { @@ -80,10 +80,10 @@ describe('************************** producer.js ************************** \n A } }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') } catch (err) { console.log('Error: ', err) - } + } }) it(`userA1 votes for prodA1 using address #2`, async () => { @@ -101,10 +101,10 @@ describe('************************** producer.js ************************** \n A } }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') } catch (err) { console.log('Error: ', err) - } + } }) it(`Unregister prodA1 as producer`, async () => { @@ -119,10 +119,10 @@ describe('************************** producer.js ************************** \n A } }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') } catch (err) { console.log('Error: ', err) - } + } }) }) diff --git a/tests/pub_k1.js b/tests/pub_k1.js index 56c2438f..ff209abd 100644 --- a/tests/pub_k1.js +++ b/tests/pub_k1.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, generateFioAddress, generateFioDomain, convertToK1, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); @@ -17,12 +17,12 @@ describe.skip(`************************** pub_k1.js ************************** \ userA1 = await newUser(faucet); userA1.publicKeyK1 = convertToK1(userA1.publicKey) }) - + it(`get_fio_balance with "FIO" key`, async () => { try { const result = await userA1.sdk.genericAction('getFioBalance', { fioPublicKey: userA1.publicKey - }) + }) //console.log('result: ', result) balance = result.balance expect(result.balance).to.be.greaterThan(0) @@ -35,9 +35,9 @@ describe.skip(`************************** pub_k1.js ************************** \ try { const result = await userA1.sdk.genericAction('getFioBalance', { fioPublicKey: userA1.publicKeyK1 - }) + }) //console.log('result: ', result) - expect(result.balance).to.equal(balance) + expect(result.balance).to.equal(balance) } catch (err) { console.log('Error: ', err) } @@ -48,7 +48,7 @@ describe.skip(`************************** pub_k1.js ************************** \ const result = await userA1.sdk.genericAction('getPendingFioRequests', { limit: '', offset: '' - }) + }) //console.log('result: ', result) balance = result.balance expect(result.balance).to.be.greaterThan(0) @@ -62,9 +62,9 @@ describe.skip(`************************** pub_k1.js ************************** \ const result = await userA1.sdk.genericAction('getPendingFioRequests', { limit: '', offset: '' - }) + }) //console.log('result: ', result) - expect(result.balance).to.equal(balance) + expect(result.balance).to.equal(balance) } catch (err) { console.log('Error: ', err) } diff --git a/tests/pushtransaction.js b/tests/pushtransaction.js index 7c42ff14..76c4dacd 100644 --- a/tests/pushtransaction.js +++ b/tests/pushtransaction.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, fetchJson, generateFioAddress} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { @@ -17,16 +17,16 @@ describe(`************************** pushtransaction.js ************************ userA1.address2 = generateFioAddress(userA1.domain, 5) userA1.address3 = generateFioAddress(userA1.domain, 5) }) - + it(`Register address using registerFioAddress endpoint`, async () => { - const result = await userA1.sdk.genericAction('registerFioAddress', { + const result = await userA1.sdk.genericAction('registerFioAddress', { fioAddress: userA1.address2, ownerPublicKey: userA1.publicKey, maxFee: config.api.register_fio_address.fee, technologyProviderId: '' }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') }) it(`Register address using pushTransaction endpoint`, async () => { @@ -42,9 +42,9 @@ describe(`************************** pushtransaction.js ************************ } }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') }) - + }) diff --git a/tests/ram2.js b/tests/ram2.js index 7622fd5f..0764416f 100644 --- a/tests/ram2.js +++ b/tests/ram2.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {printUserRam, setRam, user, generateFioDomain, generateFioAddress, fetchJson, randStr, timeout, createKeypair} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); let user1, user2 @@ -26,7 +26,7 @@ describe('************************** ram2.js ************************** \n A. Te user1Domain = generateFioDomain(15) user1Address = generateFioAddress(user1Domain, 15) user1Domain2 = generateFioDomain(15) - user1Address2 = generateFioAddress(user1Domain, 15) + user1Address2 = generateFioAddress(user1Domain, 15) }) it(`Transfer FIO to ramuserPublicKey to fund account. Test: INITIALACCOUNTRAM`, async () => { @@ -34,31 +34,31 @@ describe('************************** ram2.js ************************** \n A. Te payeeFioPublicKey: user1.publicKey, amount: 2000000000000, maxFee: config.api.transfer_tokens_pub_key.fee, - }) + }) //console.log('Result', result) expect(result).to.have.all.keys('transaction_id', 'block_num', 'status', 'fee_collected') await setRam(user1, 'INITIALACCOUNTRAM', 0) }) it(`Test: REGDOMAINRAM`, async () => { - const result = await user1sdk.genericAction('registerFioDomain', { - fioDomain: user1Domain, + const result = await user1sdk.genericAction('registerFioDomain', { + fioDomain: user1Domain, maxFee: config.api.register_fio_domain.fee , walletFioAddress: '' }) //console.log('Result', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user1, 'REGDOMAINRAM', result.fee_collected) }) - + it(`Test: REGADDRESSRAM`, async () => { - const result = await user1sdk.genericAction('registerFioAddress', { + const result = await user1sdk.genericAction('registerFioAddress', { fioAddress: user1Address, maxFee: config.api.register_fio_address.fee, walletFioAddress: '' }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user1, 'REGADDRESSRAM', result.fee_collected) }) @@ -80,7 +80,7 @@ describe('************************** ram2.js ************************** \n A. Te maxFee: config.api.add_pub_address.fee, walletFioAddress: '' }) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user1, 'ADDADDRESSRAM', result.fee_collected) }) @@ -97,7 +97,7 @@ describe('************************** ram2.js ************************** \n A. Te } }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user1, 'REGDOMAINRAM', result.fee_collected) } catch (err) { console.log('Error: ', err) @@ -105,20 +105,20 @@ describe('************************** ram2.js ************************** \n A. Te }) it(`Register user1Address2`, async () => { - const result = await user1sdk.genericAction('registerFioAddress', { + const result = await user1sdk.genericAction('registerFioAddress', { fioAddress: user1Address2, maxFee: config.api.register_fio_address.fee, walletFioAddress: '' }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user1, 'REGADDRESSRAM', result.fee_collected) }) it(`Test: NEWFUNDSREQUESTRAM`, async () => { try { - const result = await user1sdk.genericAction('requestFunds', { - payerFioAddress: user1Address2, + const result = await user1sdk.genericAction('requestFunds', { + payerFioAddress: user1Address2, payeeFioAddress: user1Address, maxFee: config.api.new_funds_request.fee, walletFioAddress: '', @@ -129,9 +129,9 @@ describe('************************** ram2.js ************************** \n A. Te memo: randStr(15), hash: user1.account, offlineUrl: randStr(10) - }) + }) //console.log('Result: ', result) - expect(result.status).to.equal('requested') + expect(result.status).to.equal('requested') await setRam(user1, 'NEWFUNDSREQUESTRAM', result.fee_collected) } catch (err) { console.log('Error: ', err) @@ -175,9 +175,9 @@ describe('B. Test add_pub_address RAM Consumption', () => { payeeFioPublicKey: user2.publicKey, amount: 2000000000000, maxFee: config.api.transfer_tokens_pub_key.fee, - }) + }) //console.log('Result', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user2, 'INITIALACCOUNTRAM', 0) } catch (err) { console.log('user2Domain', user2Domain) @@ -188,13 +188,13 @@ describe('B. Test add_pub_address RAM Consumption', () => { it(`Register domain: user2Domain`, async () => { try{ - const result = await user2sdk.genericAction('registerFioDomain', { - fioDomain: user2Domain, + const result = await user2sdk.genericAction('registerFioDomain', { + fioDomain: user2Domain, maxFee: config.api.register_fio_domain.fee , walletFioAddress: '' }) //console.log('Result', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user2, 'REGDOMAINRAM', result.fee_collected) } catch (err) { console.log('Error: ', err) @@ -202,32 +202,32 @@ describe('B. Test add_pub_address RAM Consumption', () => { }) it(`Register address: user2Address`, async () => { - const result = await user2sdk.genericAction('registerFioAddress', { + const result = await user2sdk.genericAction('registerFioAddress', { fioAddress: user2Address, maxFee: config.api.register_fio_address.fee, walletFioAddress: '' }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user2, 'REGADDRESSRAM', result.fee_collected) }) it(`Register address: user2Address2`, async () => { - const result = await user2sdk.genericAction('registerFioAddress', { + const result = await user2sdk.genericAction('registerFioAddress', { fioAddress: user2Address2, maxFee: config.api.register_fio_address.fee, walletFioAddress: '' }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user2, 'REGADDRESSRAM', result.fee_collected) }) it(`Do 30 request funds`, async () => { for (i = 0; i < 30; i++) { try { - const result = await user2sdk.genericAction('requestFunds', { - payerFioAddress: user2Address, + const result = await user2sdk.genericAction('requestFunds', { + payerFioAddress: user2Address, payeeFioAddress: user2Address, maxFee: config.api.new_funds_request.fee, walletFioAddress: user2Address, @@ -238,9 +238,9 @@ describe('B. Test add_pub_address RAM Consumption', () => { memo: randStr(15), hash: user2.account, offlineUrl: randStr(10) - }) + }) //console.log('Result: ', result) - expect(result.status).to.equal('requested') + expect(result.status).to.equal('requested') await setRam(user2, 'NEWFUNDSREQUESTRAM', result.fee_collected) } catch (err) { console.log('Error: ', err) @@ -283,7 +283,7 @@ describe('B. Test add_pub_address RAM Consumption', () => { maxFee: config.api.add_pub_address.fee, walletFioAddress: '' }) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user2, 'ADDADDRESSRAM', result.fee_collected) } catch (err) { console.log('Error: ', err.json) @@ -296,8 +296,8 @@ describe('B. Test add_pub_address RAM Consumption', () => { it(`Use up most of the bundles with requestFunds`, async () => { for (i = 0; i < 15; i++) { try { - const result = await user2sdk.genericAction('requestFunds', { - payerFioAddress: user2Address, + const result = await user2sdk.genericAction('requestFunds', { + payerFioAddress: user2Address, payeeFioAddress: user2Address, maxFee: config.api.new_funds_request.fee, walletFioAddress: user2Address, @@ -308,9 +308,9 @@ describe('B. Test add_pub_address RAM Consumption', () => { memo: randStr(15), hash: user2.account, offlineUrl: randStr(10) - }) + }) //console.log('Result: ', result) - expect(result.status).to.equal('requested') + expect(result.status).to.equal('requested') await setRam(user2, 'NEWFUNDSREQUESTRAM', result.fee_collected) } catch (err) { console.log('Error: ', err.json) @@ -353,7 +353,7 @@ describe('B. Test add_pub_address RAM Consumption', () => { maxFee: config.api.add_pub_address.fee, walletFioAddress: '' }) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user2, 'ADDADDRESSRAM', result.fee_collected) } catch (err) { console.log('Error: ', err.json) @@ -366,8 +366,8 @@ describe('B. Test add_pub_address RAM Consumption', () => { it(`See what happens when request funds continues after the zero addaddress`, async () => { for (i = 0; i < 6; i++) { try { - const result = await user2sdk.genericAction('requestFunds', { - payerFioAddress: user2Address, + const result = await user2sdk.genericAction('requestFunds', { + payerFioAddress: user2Address, payeeFioAddress: user2Address, maxFee: config.api.new_funds_request.fee, walletFioAddress: user2Address, @@ -378,9 +378,9 @@ describe('B. Test add_pub_address RAM Consumption', () => { memo: randStr(15), hash: user2.account, offlineUrl: randStr(10) - }) + }) //console.log('Result: ', result) - expect(result.status).to.equal('requested') + expect(result.status).to.equal('requested') await setRam(user2, 'NEWFUNDSREQUESTRAM', result.fee_collected) } catch (err) { console.log('Error: ', err.json) @@ -425,7 +425,7 @@ describe('B. Test add_pub_address RAM Consumption', () => { maxFee: config.api.add_pub_address.fee, walletFioAddress: '' }) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') await setRam(user2, 'ADDADDRESSRAM', result.fee_collected) } catch (err) { console.log('Error: ', err.json) diff --git a/tests/record-obt-data.js b/tests/record-obt-data.js index 7229b972..3a16c4a2 100644 --- a/tests/record-obt-data.js +++ b/tests/record-obt-data.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, fetchJson, timeout, callFioApi} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/register_fio_domain.js b/tests/register_fio_domain.js index f6380aae..14bc0e5b 100644 --- a/tests/register_fio_domain.js +++ b/tests/register_fio_domain.js @@ -2,7 +2,7 @@ require('mocha') config = require('../config.js'); const {expect} = require('chai') const {newUser, fetchJson, generateFioDomain, timeout} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') before(async () => { @@ -25,16 +25,16 @@ describe(`************************** register_fio_domain.js ******************** it(`Create users and domains`, async () => { userA1 = await newUser(faucet); }) - + it(`Transfer in additional funds for domain registration`, async () => { try { const result = await faucet.genericAction('transferTokens', { payeeFioPublicKey: userA1.publicKey, amount: 8000000000000, maxFee: config.api.transfer_tokens_pub_key.fee, - }) + }) //console.log('Result', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') } catch (err) { //console.log('Error', err) expect(err).to.equal(null) @@ -45,18 +45,18 @@ describe(`************************** register_fio_domain.js ******************** try { const result = await userA1.sdk.genericAction('getFioBalance', { fioPublicKey: userA1.publicKey - }) + }) //console.log('userA1 fio balance', result) } catch (err) { //console.log('Error', err) expect(err).to.equal(null) } }) - + it(`Register domain of length 0 returns ${config.error.fioDomainRequired}`, async () => { try { - const result = await userA1.sdk.genericAction('registerFioDomain', { - fioDomain: domain0Bad, + const result = await userA1.sdk.genericAction('registerFioDomain', { + fioDomain: domain0Bad, maxFee: config.api.register_fio_domain.fee, technologyProviderId: '' }) @@ -64,23 +64,23 @@ describe(`************************** register_fio_domain.js ******************** } catch (err) { //console.log('Error: ', err.list[0].message) expect(err.list[0].message).to.equal(config.error.fioDomainRequired) - } + } }) - + it(`Register domain of length 1 succeeds: ${domain1Good}`, async () => { - const result = await userA1.sdk.genericAction('registerFioDomain', { - fioDomain: domain1Good, + const result = await userA1.sdk.genericAction('registerFioDomain', { + fioDomain: domain1Good, maxFee: config.api.register_fio_domain.fee, technologyProviderId: '' }) //console.log('Result: ', result) expect(result.status).to.equal('OK') }) - + it(`Register domain of length 2 succeeds: ${domain2Good}`, async () => { try { - const result = await userA1.sdk.genericAction('registerFioDomain', { - fioDomain: domain2Good, + const result = await userA1.sdk.genericAction('registerFioDomain', { + fioDomain: domain2Good, maxFee: config.api.register_fio_domain.fee, technologyProviderId: '' }) @@ -89,13 +89,13 @@ describe(`************************** register_fio_domain.js ******************** } catch (err) { console.log('Error: ', err.json.fields[0].error) expect(err).to.equal(null) - } + } }) - + it(`Register domain of length 62 succeeds: ${domain62Good}`, async () => { try { - const result = await userA1.sdk.genericAction('registerFioDomain', { - fioDomain: domain62Good, + const result = await userA1.sdk.genericAction('registerFioDomain', { + fioDomain: domain62Good, maxFee: config.api.register_fio_domain.fee, technologyProviderId: '' }) @@ -104,13 +104,13 @@ describe(`************************** register_fio_domain.js ******************** } catch (err) { console.log('Error: ', err.json.fields[0].error) expect(err).to.equal(null) - } + } }) - + it(`Register domain of length 63 fails: ${domain63Bad}`, async () => { try { - const result = await userA1.sdk.genericAction('registerFioDomain', { - fioDomain: domain63Bad, + const result = await userA1.sdk.genericAction('registerFioDomain', { + fioDomain: domain63Bad, maxFee: config.api.register_fio_domain.fee, technologyProviderId: '' }) @@ -119,13 +119,13 @@ describe(`************************** register_fio_domain.js ******************** } catch (err) { //console.log('Error: ', err.list[0].message) expect(err.list[0].message).to.equal(config.error.fioDomainLengthErr) - } + } }) - + it(`Register domain of fails: "##asdf#"`, async () => { try { - const result = await userA1.sdk.genericAction('registerFioDomain', { - fioDomain: "##asdf#", + const result = await userA1.sdk.genericAction('registerFioDomain', { + fioDomain: "##asdf#", maxFee: config.api.register_fio_domain.fee, technologyProviderId: '' }) @@ -133,9 +133,9 @@ describe(`************************** register_fio_domain.js ******************** } catch (err) { //console.log('Error: ', err.list[0].message) expect(err.list[0].message).to.equal(config.error.fioDomainInvalidChar) - } + } }) - + it(`Register address length 1@62 succeeds: ${address1at62Good} (fixed in 1.1.0)`, async () => { try { const result = await userA1.sdk.genericAction('registerFioAddress', { @@ -148,9 +148,9 @@ describe(`************************** register_fio_domain.js ******************** } catch (err) { console.log('Error: ', err.list[0]) expect(err).to.equal(null) - } + } }) - + it(`Register address length 2@62 fails: ${address2at62Bad}`, async () => { try { const result = await userA1.sdk.genericAction('registerFioAddress', { @@ -163,9 +163,9 @@ describe(`************************** register_fio_domain.js ******************** } catch (err) { //console.log('Error: ', err.list[0]) expect(err.list[0].message).to.equal(config.error.fioAddressLengthErr) - } + } }) - + it(`Register address length 62@1 succeeds: ${address62at1Good} (fixed in 1.1.0)`, async () => { try { const result = await userA1.sdk.genericAction('registerFioAddress', { @@ -178,9 +178,9 @@ describe(`************************** register_fio_domain.js ******************** } catch (err) { console.log('Error: ', err.list[0]) expect(err).to.equal(null) - } + } }) - + it(`Register address length 62@2 fails: ${address62at2Bad}`, async () => { try { const result = await userA1.sdk.genericAction('registerFioAddress', { @@ -193,19 +193,19 @@ describe(`************************** register_fio_domain.js ******************** } catch (err) { //console.log('Error: ', err.list[0]) expect(err.list[0].message).to.equal(config.error.fioAddressLengthErr) - } + } }) - + }) - + describe('B. Test isAvailable using bad FIO addresses', () => { let userB1 - const badFioAddresses = ["-dash@notatstart", "two@at@isinvalid", "old:shouldntwork", "dash@notending-"] + const badFioAddresses = ["-dash@notatstart", "two@at@isinvalid", "old:shouldntwork", "dash@notending-"] it(`Create users`, async () => { userB1 = await newUser(faucet) }) - + it(`isAvailable for address randomgoodaddress@randomdomain succeeds`, async () => { try { const result = await userB1.sdk.genericAction('isAvailable', { @@ -216,9 +216,9 @@ describe('B. Test isAvailable using bad FIO addresses', () => { } catch (err) { //console.log('Error: ', err.json) expect(err.json.fields[0].error).to.equal(null) - } + } }) - + badFioAddresses.forEach(function (fioAddress, index) { it(`isAvailable for address ${fioAddress} fails`, async () => { try { @@ -230,10 +230,10 @@ describe('B. Test isAvailable using bad FIO addresses', () => { } catch (err) { //console.log('Error: ', err.json.fields[0].error) expect(err.json.fields[0].error).to.equal(config.error.invalidFioName) - } + } }) }) - + }) @@ -246,7 +246,7 @@ describe('C. Register domain for other user', () => { newFioDomain = generateFioDomain(15) }) - + it(`userC1 registers domain ${newFioDomain} for userC2`, async () => { const result = await userC1.sdk.genericAction('pushTransaction', { action: 'regdomain', @@ -289,8 +289,8 @@ describe('D. Try to re-register the same domain using different case', () => { }) it(`Register domain: ${domainLowerCase} succeeds`, async () => { - const result = await userD1.sdk.genericAction('registerFioDomain', { - fioDomain: domainLowerCase, + const result = await userD1.sdk.genericAction('registerFioDomain', { + fioDomain: domainLowerCase, maxFee: config.api.register_fio_domain.fee , technologyProviderId: '' }) @@ -298,12 +298,12 @@ describe('D. Try to re-register the same domain using different case', () => { expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') }) - + it(`Register same domain with uppercase first letter: ${domainUpperCase} returns: ${config.error.domainRegistered}`, async () => { await timeout(2000) //To avoid this getting flagged as duplicate transaction try { - const result = await userD1.sdk.genericAction('registerFioDomain', { - fioDomain: domainUpperCase, + const result = await userD1.sdk.genericAction('registerFioDomain', { + fioDomain: domainUpperCase, maxFee: config.api.register_fio_domain.fee , technologyProviderId: '' }) @@ -311,7 +311,7 @@ describe('D. Try to re-register the same domain using different case', () => { } catch (err) { //console.log('Error: ', err) expect(err.json.fields[0].error).to.equal(config.error.domainRegistered) - } + } }) }) diff --git a/tests/removeaddress.js b/tests/removeaddress.js index 820d5f39..55f759c1 100644 --- a/tests/removeaddress.js +++ b/tests/removeaddress.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, timeout, fetchJson, callFioApi, callFioApiSigned} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { @@ -29,7 +29,7 @@ describe(`************************** removeaddress.js ************************** expect(err.list[0].message).to.equal(config.error.fioAddressRequired) } }) - + it(`(SDK) removePublicAddress Fail, address has no domain. Expect SDK error: ${config.error.fioAddressInvalidChar}`, async () => { try { @@ -897,7 +897,7 @@ describe(`E-2. Add and remove addresses with NO bundles remaining`, () => { } } }) - + it(`Add public addresses to userA1 to use up one more bundle`, async () => { try { const result = await userA1.sdk.genericAction('addPublicAddresses', { @@ -919,12 +919,12 @@ describe(`E-2. Add and remove addresses with NO bundles remaining`, () => { expect(err).to.equal(null) } }) - + it(`Get balance for userA1`, async () => { try { const result = await userA1.sdk.genericAction('getFioBalance', { fioPublicKey: userA1.publicKey - }) + }) userA1Balance = result.balance //console.log('userA1 fio balance', result) } catch (err) { @@ -932,7 +932,7 @@ describe(`E-2. Add and remove addresses with NO bundles remaining`, () => { expect(err).to.equal(null) } }) - + it('Call get_table_rows from fionames to get bundles remaining for userA1. Verify 0 bundles', async () => { let bundleCount try { @@ -949,11 +949,11 @@ describe(`E-2. Add and remove addresses with NO bundles remaining`, () => { //console.log('fionames: ', fionames); for (name in fionames.rows) { if (fionames.rows[name].name == userA1.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); + //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); bundleCount = fionames.rows[name].bundleeligiblecountdown; } } - expect(bundleCount).to.equal(0); + expect(bundleCount).to.equal(0); } catch (err) { console.log('Error', err); expect(err).to.equal(null); @@ -1108,7 +1108,7 @@ describe(`F. Sad - result in error`, () => { expect(err).to.equal(null) } }) - + it(`Fixed in BD-1955, Remove with invalid FIO Address - Direct API call. Expect error: ${config.error2.invalidFioAddress.message}`, async () => { const result = await callFioApiSigned('push_transaction', { action: 'remaddress', @@ -1360,7 +1360,7 @@ describe(`F. Sad - result in error`, () => { try { const result = await userA1.sdk.genericAction('getFioBalance', { fioPublicKey: userA1.publicKey - }) + }) userA1Balance = result.balance //console.log('userA1 fio balance', result) } catch (err) { @@ -1382,14 +1382,14 @@ describe(`F. Sad - result in error`, () => { } catch (err) { console.log('Error: ', err); expect(err).to.equal(null); - } + } }) it(`Verify balance for userA1 = 0`, async () => { try { const result = await userA1.sdk.genericAction('getFioBalance', { fioPublicKey: userA1.publicKey - }) + }) //console.log('userA1 fio balance', result) expect(result.balance).to.equal(0) } catch (err) { @@ -1414,11 +1414,11 @@ describe(`F. Sad - result in error`, () => { //console.log('fionames: ', fionames); for (name in fionames.rows) { if (fionames.rows[name].name == userA1.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); + //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); bundleCount = fionames.rows[name].bundleeligiblecountdown; } } - expect(bundleCount).to.equal(0); + expect(bundleCount).to.equal(0); } catch (err) { console.log('Error', err); expect(err).to.equal(null); diff --git a/tests/testnet-smoketest.js b/tests/testnet-smoketest.js index cf5d6874..f27ee0cf 100644 --- a/tests/testnet-smoketest.js +++ b/tests/testnet-smoketest.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, existingUser, callFioApi, generateFioAddress, timeout} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); let user1, user2, user3 @@ -24,8 +24,8 @@ describe(`FIO Requests (error conditions only)`, () => { it(`user1 requests funds from user2`, async () => { try { - const result = await user1.sdk.genericAction('requestFunds', { - payerFioAddress: user2.address, + const result = await user1.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, payeeFioAddress: user1.address, payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', amount: payment, @@ -37,10 +37,10 @@ describe(`FIO Requests (error conditions only)`, () => { technologyProviderId: '', hash: '', offLineUrl: '' - }) + }) //console.log('Result: ', result.fio_request_id) user1RequestId = result.fio_request_id - expect(result.status).to.equal('requested') + expect(result.status).to.equal('requested') } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) @@ -173,8 +173,8 @@ describe(`Cancel Funds Request`, () => { it(`user1 requests funds from user2`, async () => { try { - const result = await user1.sdk.genericAction('requestFunds', { - payerFioAddress: user2.address, + const result = await user1.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, payeeFioAddress: user1.address, payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', amount: payment, @@ -186,10 +186,10 @@ describe(`Cancel Funds Request`, () => { technologyProviderId: '', hash: '', offLineUrl: '' - }) + }) //console.log('Result: ', result) user1RequestId = result.fio_request_id - expect(result.status).to.equal('requested') + expect(result.status).to.equal('requested') } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) @@ -205,7 +205,7 @@ describe(`Cancel Funds Request`, () => { const result = await user1.sdk.genericAction('getSentFioRequests', { limit: '', offset: '' - }) + }) //console.log('result: ', result) numRequests = result.requests.length; expect(result.requests[numRequests-1].fio_request_id).to.equal(user1RequestId); @@ -221,7 +221,7 @@ describe(`Cancel Funds Request`, () => { const result = await user2.sdk.genericAction('getPendingFioRequests', { limit: '', offset: '' - }) + }) //console.log('result: ', result) numRequests = result.requests.length; expect(result.requests[numRequests-1].fio_request_id).to.equal(user1RequestId); @@ -259,7 +259,7 @@ describe(`Cancel Funds Request`, () => { const result = await user1.sdk.genericAction('getSentFioRequests', { limit: '', offset: '' - }) + }) //console.log('result: ', result) numRequests = result.requests.length; expect(result.requests[numRequests-1].fio_request_id).to.equal(user1RequestId); @@ -307,10 +307,10 @@ describe('Transfer domain', () => { try { const result = await user1.sdk.genericAction('getFioNames', { fioPublicKey: user1.publicKey - }) + }) //console.log('getFioNames', result) for (domain in result.fio_domains) { - if (result.fio_domains[domain].fio_domain == user1.domain2) {break} + if (result.fio_domains[domain].fio_domain == user1.domain2) {break} } expect(result.fio_domains[domain].fio_domain).to.equal(user1.domain2); } catch (err) { @@ -323,7 +323,7 @@ describe('Transfer domain', () => { try { const result = await user1.sdk.genericAction('getFioBalance', { fioPublicKey: user1.publicKey - }) + }) user1OrigBalance = result.balance //console.log('user1 fio balance', result) } catch (err) { @@ -346,7 +346,7 @@ describe('Transfer domain', () => { } catch (err) { console.log('Error: ', err.json.error); expect(err).to.equal(null); - } + } }) it('Confirm proper fee was collected', async () => { @@ -357,7 +357,7 @@ describe('Transfer domain', () => { try { const result = await user1.sdk.genericAction('getFioBalance', { fioPublicKey: user1.publicKey - }) + }) expect(result.balance).to.equal(user1OrigBalance - transfer_fio_domain_fee); //console.log('user1 fio balance', result) } catch (err) { @@ -370,10 +370,10 @@ describe('Transfer domain', () => { try { const result = await user1.sdk.genericAction('getFioNames', { fioPublicKey: user1.publicKey - }) + }) //console.log('getFioNames', result) for (address in result.fio_addresses) { - if (result.fio_addresses[address].fio_address == user1.address2) {break} + if (result.fio_addresses[address].fio_address == user1.address2) {break} } expect(result.fio_addresses[address].fio_address).to.equal(user1.address2); } catch (err) { @@ -386,10 +386,10 @@ describe('Transfer domain', () => { try { const result = await user2.sdk.genericAction('getFioNames', { fioPublicKey: user2.publicKey - }) + }) //console.log('getFioNames', result) for (domain in result.fio_domains) { - if (result.fio_domains[domain].fio_domain == user1.domain2) {break} + if (result.fio_domains[domain].fio_domain == user1.domain2) {break} } expect(result.fio_domains[domain].fio_domain).to.equal(user1.domain2); } catch (err) { @@ -412,7 +412,7 @@ describe('Transfer domain', () => { } catch (err) { console.log('Error: ', err.json.error); expect(err).to.equal(null); - } + } }) }) @@ -564,11 +564,11 @@ describe(`Paging - FIO Address`, () => { for (i = 0; i < addressCount; i++) { try { newAddress = i + generateFioAddress(user3.domain, 7) - const result = await user3.sdk.genericAction('registerFioAddress', { - fioAddress: newAddress, + const result = await user3.sdk.genericAction('registerFioAddress', { + fioAddress: newAddress, maxFee: config.api.register_fio_address.fee, walletFioAddress: '' - }) + }) //console.log('Result: ', result) expect(result.status).to.equal('OK') } catch (err) { @@ -636,7 +636,7 @@ describe(`Paging - FIO Address`, () => { //console.log('Result: ', result); expect(result.fio_addresses.length).to.equal(2); expect(result.fio_addresses[0].fio_address.charAt(0)).to.equal('3'); // First character of address = 4 (5th address in list) - expect(result.fio_addresses[1].fio_address.charAt(0)).to.equal('4'); + expect(result.fio_addresses[1].fio_address.charAt(0)).to.equal('4'); } catch (err) { console.log('Error', err) expect(err).to.equal(null) @@ -652,9 +652,9 @@ describe(`Paging - FIO Address`, () => { } result = await callFioApi("get_fio_addresses", json); //console.log('Result: ', result); - expect(result.fio_addresses[0].fio_address.charAt(0)).to.equal('1'); - expect(result.fio_addresses[0].fio_address.charAt(1)).to.equal('4'); // 15 - expect(result.fio_addresses[4].fio_address.charAt(0)).to.equal('1'); + expect(result.fio_addresses[0].fio_address.charAt(0)).to.equal('1'); + expect(result.fio_addresses[0].fio_address.charAt(1)).to.equal('4'); // 15 + expect(result.fio_addresses[4].fio_address.charAt(0)).to.equal('1'); expect(result.fio_addresses[4].fio_address.charAt(1)).to.equal('8'); // 19 } catch (err) { console.log('Error', err) @@ -757,4 +757,4 @@ describe(`Paging - FIO Address`, () => { } }) -}) \ No newline at end of file +}) diff --git a/tests/transfer-address.js b/tests/transfer-address.js index 6f276857..21ac3528 100644 --- a/tests/transfer-address.js +++ b/tests/transfer-address.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, generateFioAddress, createKeypair, callFioApi, getFees, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { @@ -733,4 +733,4 @@ describe('D. transferFioAddress Error testing', () => { } }) -}) \ No newline at end of file +}) diff --git a/tests/transfer-domain.js b/tests/transfer-domain.js index 6b3b16dd..aedb19ed 100644 --- a/tests/transfer-domain.js +++ b/tests/transfer-domain.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, generateFioAddress, generateFioDomain, createKeypair, callFioApi, getFees, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { @@ -32,34 +32,34 @@ describe('************************** transfer-domain.js ************************ it(`Register walletA1.domain2`, async () => { try { - const result = await walletA1.sdk.genericAction('registerFioDomain', { + const result = await walletA1.sdk.genericAction('registerFioDomain', { fioDomain: walletA1.domain2, maxFee: config.api.register_fio_domain.fee, technologyProviderId: '' }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') } catch (err) { console.log('Error', err) expect(err).to.equal(null) } }) - + it(`Register walletA1.address2`, async () => { - const result = await walletA1.sdk.genericAction('registerFioAddress', { + const result = await walletA1.sdk.genericAction('registerFioAddress', { fioAddress: walletA1.address2, maxFee: config.api.register_fio_address.fee, technologyProviderId: '' }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') }) it(`getFioNames for walletA1 and confirm it owns 2 domains and that one of them is walletA1.domain2`, async () => { try { const result = await walletA1.sdk.genericAction('getFioNames', { fioPublicKey: walletA1.publicKey - }) + }) //console.log('getFioNames', result) origDomainExpire = result.fio_domains[1].expiration expect(result.fio_domains.length).to.equal(2) @@ -77,7 +77,7 @@ describe('************************** transfer-domain.js ************************ try { const result = await walletA2.sdk.genericAction('getFioNames', { fioPublicKey: walletA2.publicKey - }) + }) //console.log('getFioNames', result) expect(result.fio_domains.length).to.equal(1) expect(result.fio_domains[0].fio_domain).to.equal(walletA2.domain) @@ -92,7 +92,7 @@ describe('************************** transfer-domain.js ************************ try { const result = await walletA1.sdk.genericAction('getFioBalance', { fioPublicKey: walletA1.publicKey - }) + }) walletA1OrigBalance = result.balance //console.log('userA1 fio balance', result) } catch (err) { @@ -143,7 +143,7 @@ describe('************************** transfer-domain.js ************************ } catch (err) { console.log('Error: ', err.json.error); expect(err).to.equal(null); - } + } }) it('Confirm proper fee was collected', async () => { @@ -154,7 +154,7 @@ describe('************************** transfer-domain.js ************************ try { const result = await walletA1.sdk.genericAction('getFioBalance', { fioPublicKey: walletA1.publicKey - }) + }) expect(result.balance).to.equal(walletA1OrigBalance - transfer_fio_domain_fee) //console.log('userA1 fio balance', result) } catch (err) { @@ -195,7 +195,7 @@ describe('************************** transfer-domain.js ************************ try { walletA1FioNames = await walletA1.sdk.genericAction('getFioNames', { fioPublicKey: walletA1.publicKey - }) + }) //console.log('getFioNames', result) expect(walletA1FioNames.fio_domains.length).to.equal(1) expect(walletA1FioNames.fio_domains[0].fio_domain).to.equal(walletA1.domain) @@ -215,11 +215,11 @@ describe('************************** transfer-domain.js ************************ try { walletA2FioNames = await walletA2.sdk.genericAction('getFioNames', { fioPublicKey: walletA2.publicKey - }) + }) //console.log('getFioNames', walletA2FioNames) expect(walletA2FioNames.fio_domains.length).to.equal(2) expect(walletA2FioNames.fio_domains[0].fio_domain).to.equal(walletA2.domain) - expect(walletA2FioNames.fio_addresses[0].fio_address).to.equal(walletA2.address) + expect(walletA2FioNames.fio_addresses[0].fio_address).to.equal(walletA2.address) expect(walletA2FioNames.fio_domains[1].fio_domain).to.equal(walletA1.domain2) } catch (err) { console.log('Error', err) @@ -259,13 +259,13 @@ describe('B. Transfer a domain to FIO Public Key which does not map to existing try { const result = await faucet.genericAction('getFioBalance', { fioPublicKey: walletB2.publicKey - }) + }) expect(err).to.equal(null); } catch (err) { //console.log('Error: ', err) expect(err.json.message).to.equal(config.error.keyNotFound) expect(err.errorCode).to.equal(404); - } + } }) it(`(API) getFioBalance for non-existent walletB1 account. Expect error type 404: ${config.error.keyNotFound}`, async () => { @@ -295,13 +295,13 @@ describe('B. Transfer a domain to FIO Public Key which does not map to existing it(`Register walletB1.domain2`, async () => { try { - const result = await walletB1.sdk.genericAction('registerFioDomain', { + const result = await walletB1.sdk.genericAction('registerFioDomain', { fioDomain: walletB1.domain2, maxFee: config.api.register_fio_domain.fee, technologyProviderId: '' }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') } catch (err) { console.log('Error', err) expect(err).to.equal(null) @@ -309,20 +309,20 @@ describe('B. Transfer a domain to FIO Public Key which does not map to existing }) it('Register walletB1.address2', async () => { - const result = await walletB1.sdk.genericAction('registerFioAddress', { + const result = await walletB1.sdk.genericAction('registerFioAddress', { fioAddress: walletB1.address2, maxFee: config.api.register_fio_address.fee, technologyProviderId: '' }) //console.log('Result: ', result) - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') }) it('getFioNames for walletB1 and confirm it owns 2 domains and one of them is walletB1.domain2', async () => { try { const result = await walletB1.sdk.genericAction('getFioNames', { fioPublicKey: walletB1.publicKey - }) + }) //console.log('getFioNames', result) origDomainExpire = result.fio_domains[1].expiration expect(result.fio_domains.length).to.equal(2) @@ -355,7 +355,7 @@ describe('B. Transfer a domain to FIO Public Key which does not map to existing try { const result = await walletB1.sdk.genericAction('getFioBalance', { fioPublicKey: walletB1.publicKey - }) + }) walletB1OrigBalance = result.balance //console.log('userA1 fio balance', result) } catch (err) { @@ -388,11 +388,11 @@ describe('B. Transfer a domain to FIO Public Key which does not map to existing }) //console.log('Result: ', result) feeCollected = result.fee_collected; - expect(result.status).to.equal('OK') + expect(result.status).to.equal('OK') } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) - } + } }) it('Confirm proper fee was collected', async () => { @@ -403,7 +403,7 @@ describe('B. Transfer a domain to FIO Public Key which does not map to existing try { const result = await walletB1.sdk.genericAction('getFioBalance', { fioPublicKey: walletB1.publicKey - }) + }) expect(result.balance).to.equal(walletB1OrigBalance - transfer_fio_domain_fee) //console.log('Result', result) } catch (err) { @@ -416,13 +416,13 @@ describe('B. Transfer a domain to FIO Public Key which does not map to existing try { const result = await faucet.genericAction('getFioBalance', { fioPublicKey: walletB2.publicKey - }) + }) //console.log('Result: ', result) expect(result.balance).to.equal(0) } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) - } + } }) it(`Confirm RAM quota for walletB1 was incremented by ${config.RAM.XFERDOMAINRAM}`, async () => { @@ -457,7 +457,7 @@ describe('B. Transfer a domain to FIO Public Key which does not map to existing try { walletB1FioNames = await walletB1.sdk.genericAction('getFioNames', { fioPublicKey: walletB1.publicKey - }) + }) //console.log('getFioNames', walletB1FioNames) expect(walletB1FioNames.fio_domains.length).to.equal(1) expect(walletB1FioNames.fio_domains[0].fio_domain).to.equal(walletB1.domain) @@ -477,7 +477,7 @@ describe('B. Transfer a domain to FIO Public Key which does not map to existing try { walletB2FioNames = await walletB1.sdk.genericAction('getFioNames', { fioPublicKey: walletB2.publicKey - }) + }) //console.log('getFioNames', walletB2FioNames) expect(walletB2FioNames.fio_domains.length).to.equal(1) expect(walletB2FioNames.fio_domains[0].fio_domain).to.equal(walletB1.domain2) @@ -514,7 +514,7 @@ describe('C. Run get_fee on transfer_fio_domain', () => { } catch (err) { console.log('Error: ', err); expect(err).to.equal(null); - } + } }) it('Call sdk getFee on transfer_fio_domain endpoint for walletC1 and verify the fee is equal to the fee from the table', async () => { @@ -754,7 +754,7 @@ describe('D. transferFioDomain Error testing', () => { try { const result = await userD3.sdk.genericAction('getFioBalance', { fioPublicKey: userD3.publicKey - }) + }) userC1Balance = result.balance //console.log('userD3 fio balance', result) } catch (err) { @@ -776,14 +776,14 @@ describe('D. transferFioDomain Error testing', () => { } catch (err) { console.log('Error: ', err); expect(err).to.equal(null); - } + } }) it(`Verify balance for userD3 = 0`, async () => { try { const result = await userD3.sdk.genericAction('getFioBalance', { fioPublicKey: userD3.publicKey - }) + }) //console.log('userD3 fio balance', result) expect(result.balance).to.equal(0) } catch (err) { @@ -808,11 +808,11 @@ describe('D. transferFioDomain Error testing', () => { //console.log('fionames: ', fionames); for (name in fionames.rows) { if (fionames.rows[name].name == userD3.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); + //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); bundleCount = fionames.rows[name].bundleeligiblecountdown; } } - expect(bundleCount).to.equal(0); + expect(bundleCount).to.equal(0); } catch (err) { console.log('Error', err); expect(err).to.equal(null); @@ -835,4 +835,4 @@ describe('D. transferFioDomain Error testing', () => { } }) -}) \ No newline at end of file +}) diff --git a/tests/transfer-locked-tokens-account-tests.js b/tests/transfer-locked-tokens-account-tests.js index 71ca92a0..1b3664a8 100644 --- a/tests/transfer-locked-tokens-account-tests.js +++ b/tests/transfer-locked-tokens-account-tests.js @@ -1,6 +1,6 @@ require('mocha') const {expect} = require('chai') -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') const {fetchJson, timeout, generateFioDomain, generateFioAddress, createKeypair, getTotalVotedFio, getAccountVoteWeight, getProdVoteTotal} = require('../utils.js'); config = require('../config.js'); @@ -139,19 +139,19 @@ describe(`************************** transfer-locked-tokens-account-tests.js *** testFioDomain = generateFioDomain(8) testFioAddressName = generateFioAddress(testFioDomain, 7) testFioAddressName2 = generateFioAddress(testFioDomain, 5) - + try { await fioSdkFaucet.genericAction('registerFioDomain', { fioDomain: testFioDomain, maxFee: defaultFee }) - + await fioSdkFaucet.genericAction('setFioDomainVisibility', { fioDomain: testFioDomain, isPublic: true, maxFee: defaultFee }) - + const isAvailableResult = await fioSdk.genericAction('isAvailable', { fioName: testFioAddressName }) @@ -161,7 +161,7 @@ describe(`************************** transfer-locked-tokens-account-tests.js *** maxFee: defaultFee }) } - + const isAvailableResult2 = await fioSdk2.genericAction('isAvailable', { fioName: testFioAddressName2 }) @@ -171,7 +171,7 @@ describe(`************************** transfer-locked-tokens-account-tests.js *** maxFee: defaultFee }) } - + } catch (e) { console.log(e); } @@ -1197,4 +1197,4 @@ describe(`Test locked token accounts with proxy voting`, () => { } }) -}) \ No newline at end of file +}) diff --git a/tests/transfer-locked-tokens.js b/tests/transfer-locked-tokens.js index b24577ff..9bf38124 100644 --- a/tests/transfer-locked-tokens.js +++ b/tests/transfer-locked-tokens.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, getProdVoteTotal, fetchJson, generateFioDomain, callFioApi, generateFioAddress, createKeypair} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/transfer-tokens.js b/tests/transfer-tokens.js index 8ffa067a..da060239 100644 --- a/tests/transfer-tokens.js +++ b/tests/transfer-tokens.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, fetchJson, generateFioDomain, generateFioAddress, createKeypair} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { @@ -18,14 +18,14 @@ describe(`************************** transfer-tokens.js ************************ it(`getFioBalance for userA1`, async () => { try { - const result = await userA1.sdk.genericAction('getFioBalance', { }) + const result = await userA1.sdk.genericAction('getFioBalance', { }) //console.log('Result: ', result) prevFundsAmount = result.balance } catch (err) { expect(err.json.message).to.equal(null) - } + } }) - + it(`Transfer ${fundsAmount} FIO to userA1 FIO public key`, async () => { const result = await faucet.genericAction('transferTokens', { payeeFioPublicKey: userA1.publicKey, @@ -61,11 +61,11 @@ describe('B. Transfer Tokens to Sad account ', () => { try { const result = await userB1.genericAction('getFioBalance', { fioPublicKey: userB1.publicKey - }) + }) } catch (err) { //console.log('Error: ', err.json) expect(err.json.message).to.equal(config.error.keyNotFound) - } + } }) it(`Transfer to empty public key returns: ${config.error.invalidKey}`, async () => { @@ -79,7 +79,7 @@ describe('B. Transfer Tokens to Sad account ', () => { } catch (err) { //console.log('Error: ', err.json) expect(err.json.fields[0].error).to.equal(config.error.invalidKey) - } + } }) it(`Transfer ${100000000000000000/1000000000} returns: ${config.error.insufficientBalance}`, async () => { @@ -93,7 +93,7 @@ describe('B. Transfer Tokens to Sad account ', () => { } catch (err) { //console.log('Error: ', err.json) expect(err.json.fields[0].error).to.equal(config.error.insufficientBalance) - } + } }) it(`Transfer without enough FEE returns ${config.error.feeExceedsMax}`, async () => { @@ -107,9 +107,9 @@ describe('B. Transfer Tokens to Sad account ', () => { } catch (err) { //console.log('Error: ', err.json) expect(err.json.fields[0].error).to.equal(config.error.feeExceedsMax) - } + } }) - + it(`Transfer to invalid public key returns ${config.error.invalidKey}`, async () => { try { const result = await faucet.genericAction('transferTokens', { @@ -121,7 +121,7 @@ describe('B. Transfer Tokens to Sad account ', () => { } catch (err) { //console.log('Error: ', err.json.fields[0].error) expect(err.json.fields[0].error).to.equal(config.error.invalidKey) - } + } }) it(`Transfer -100 returns ${config.error.invalidAmount}`, async () => { @@ -135,7 +135,7 @@ describe('B. Transfer Tokens to Sad account ', () => { } catch (err) { //console.log('Error: ', err.json) expect(err.json.fields[0].error).to.equal(config.error.invalidAmount) - } + } }) }) diff --git a/tests/txn-resubmit.js b/tests/txn-resubmit.js index 57bd2050..9e8c4d6e 100644 --- a/tests/txn-resubmit.js +++ b/tests/txn-resubmit.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, generateFioAddress, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { @@ -18,12 +18,12 @@ describe('************************** txn-resubmit.js ************************** userA1 = await newUser(faucet); userA2 = await newUser(faucet); }) - + it(`userA1 requests funds from userA2`, async () => { try { userA1.sdk.setSignedTrxReturnOption(true) - preparedTrx = await userA1.sdk.genericAction('requestFunds', { - payerFioAddress: userA2.address, + preparedTrx = await userA1.sdk.genericAction('requestFunds', { + payerFioAddress: userA2.address, payeeFioAddress: userA1.address, payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', amount: payment, @@ -35,7 +35,7 @@ describe('************************** txn-resubmit.js ************************** technologyProviderId: '', hash: '', offLineUrl: '' - }) + }) userA1.sdk.setSignedTrxReturnOption(false) } catch (err) { console.log('Error: ', err) @@ -61,7 +61,7 @@ describe('************************** txn-resubmit.js ************************** const result = await userA1.sdk.genericAction('getSentFioRequests', { limit: '', offset: '' - }) + }) //console.log('result: ', result) expect(result.requests[0].fio_request_id).to.equal(userA1RequestId); expect(result.requests[0].content.memo).to.equal(requestMemo); @@ -70,13 +70,13 @@ describe('************************** txn-resubmit.js ************************** expect(err).to.equal(null); } }) - + it(`get_pending_fio_requests for userA2`, async () => { try { const result = await userA2.sdk.genericAction('getPendingFioRequests', { limit: '', offset: '' - }) + }) //console.log('result: ', result) expect(result.requests[0].fio_request_id).to.equal(userA1RequestId); expect(result.requests[0].content.memo).to.equal(requestMemo); @@ -105,7 +105,7 @@ describe('************************** txn-resubmit.js ************************** const result = await fetch(fiourl + endPoint, { body: JSON.stringify(preparedTrx), method: 'POST', - }); + }); const json = await result.json() //console.log('result: ', result) expect(json.error.what).to.equal('Duplicate transaction') @@ -115,4 +115,4 @@ describe('************************** txn-resubmit.js ************************** } }) -}) \ No newline at end of file +}) diff --git a/tests/vote.js b/tests/vote.js index 788788e8..8ccb1f15 100644 --- a/tests/vote.js +++ b/tests/vote.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, getProdVoteTotal, timeout, unlockWallet, addLock, getAccountVoteWeight, getTotalVotedFio, callFioApi, callFioApiSigned, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); let total_voted_fio @@ -994,8 +994,8 @@ describe.skip('NOT WORKING D. Proxy voting with proxy and voter having some Type actor: 'eosio', privKey: eosio.privateKey, data: { - owner: proxyD1.account, - amount: 300000000000, + owner: proxyD1.account, + amount: 300000000000, locktype: 1, } }) @@ -1003,7 +1003,7 @@ describe.skip('NOT WORKING D. Proxy voting with proxy and voter having some Type //expect(result.processed.receipt.status).to.equal('executed'); } catch (err) { console.log('Error: ', err.json) - } + } }) it(`Register proxyD1 as a proxy`, async () => { @@ -1157,9 +1157,9 @@ describe('E. Test proxying to a user who is also proxying (should fail)', () => } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) - } + } }) - + it(`proxyE1 votes for bp1@dapixdev`, async () => { try { const result = await proxyE1.sdk.genericAction('pushTransaction', { @@ -2067,7 +2067,7 @@ describe('FIP-9: G.2 Test vote_producer with and without FIO Address', () => { describe('FIP-9: G.3 Test proxy_vote with and without FIO Address', () => { let proxyG1, voterG7, voterG8, voterG9, voterG10, total_bp_votes, bundleCount, balance - + it(`Create users`, async () => { proxyG1 = await newUser(faucet); diff --git a/utils.js b/utils.js index baa4d654..1537d88b 100755 --- a/utils.js +++ b/utils.js @@ -11,13 +11,13 @@ var fs = require('fs'); const { Fio } = require('@fioprotocol/fiojs'); fetch = require('node-fetch'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') const {TextEncoder,TextDecoder } = require('text-encoding') -const Transactions_2 = require("@fioprotocol/FIOSDK/lib/transactions/Transactions") +const Transactions_2 = require("@fioprotocol/fiosdk/lib/transactions/Transactions") let transaction = new Transactions_2.Transactions function randStr(len) { - var charset = "abcdefghijklmnopqrstuvwxyz"; + var charset = "abcdefghijklmnopqrstuvwxyz"; result=""; for( var i=0; i < len; i++ ) result += charset[Math.floor(Math.random() * charset.length)]; @@ -112,57 +112,57 @@ async function newUser(faucet, newAccount=null, newPrivateKey=null, newPublicKey payeeFioPublicKey: this.publicKey, amount: config.FUNDS, maxFee: config.api.transfer_tokens_pub_key.fee, - }) + }) //console.log('Result', result) - //expect(result.status).to.equal('OK') + //expect(result.status).to.equal('OK') } catch (err) { console.log('Transfer tokens error: ', err.json) return(err); - } + } try { const result1 = await this.sdk.genericAction('isAvailable', {fioName: this.domain}) if ( ! result1.is_registered ) { - const result = await this.sdk.genericAction('registerFioDomain', { - fioDomain: this.domain, + const result = await this.sdk.genericAction('registerFioDomain', { + fioDomain: this.domain, maxFee: config.api.register_fio_domain.fee , walletFioAddress: '' }) //console.log('Result', result) - //expect(result.status).to.equal('OK') + //expect(result.status).to.equal('OK') } } catch (err) { console.log('registerFioDomain error: ', err.json) return(err); - } + } try { const result1 = await this.sdk.genericAction('isAvailable', {fioName: this.address}) if ( ! result1.is_registered ) { - const result = await this.sdk.genericAction('registerFioAddress', { + const result = await this.sdk.genericAction('registerFioAddress', { fioAddress: this.address, maxFee: config.api.register_fio_address.fee, walletFioAddress: '' }) //console.log('Result: ', result) - //expect(result.status).to.equal('OK') + //expect(result.status).to.equal('OK') } } catch (err) { console.log('registerFioAddress error: ', err.json) return(err); - } + } try { const result = await this.sdk.genericAction('getFioBalance', { fioPublicKey: this.publicKey - }) + }) this.fioBalance = result.balance; //console.log('foundationA1 fio balance', result) //expect(result.balance).to.equal(proxyA1.last_vote_weight) } catch (err) { console.log('getFioBalance Error', err); } - + return { privateKey: this.privateKey, publicKey: this.publicKey, @@ -191,8 +191,8 @@ async function existingUser(caccount, cprivateKey, cpublicKey, cdomain=null, cad try { if (cdomain == null) { - const result = await this.sdk.genericAction('registerFioDomain', { - fioDomain: this.domain, + const result = await this.sdk.genericAction('registerFioDomain', { + fioDomain: this.domain, maxFee: config.api.register_fio_domain.fee , walletFioAddress: '' }) @@ -200,11 +200,11 @@ async function existingUser(caccount, cprivateKey, cpublicKey, cdomain=null, cad } catch (err) { console.log('Register domain error: ', err.json) return(err); - } + } try { if (caddress == null) { - const result = await this.sdk.genericAction('registerFioAddress', { + const result = await this.sdk.genericAction('registerFioAddress', { fioAddress: this.address, maxFee: config.api.register_fio_address.fee, walletFioAddress: '' @@ -213,19 +213,19 @@ async function existingUser(caccount, cprivateKey, cpublicKey, cdomain=null, cad } catch (err) { console.log('Register address error: ', err.json) return(err); - } + } try { const result = await this.sdk.genericAction('getFioBalance', { fioPublicKey: this.publicKey - }) + }) this.fioBalance = result.balance; //console.log('foundationA1 fio balance', result) //expect(result.balance).to.equal(proxyA1.last_vote_weight) } catch (err) { console.log('Error', err); } - + return { privateKey: this.privateKey, publicKey: this.publicKey, @@ -273,7 +273,7 @@ const callFioApiSigned = async (endPoint, txn) => { const timePlusTen = currentDate.getTime() + 10000; const timeInISOString = (new Date(timePlusTen)).toISOString(); const expiration = timeInISOString.substr(0, timeInISOString.length - 1); - + const transaction = { expiration, ref_block_num: blockInfo.block_num & 0xffff, @@ -288,13 +288,13 @@ const callFioApiSigned = async (endPoint, txn) => { data: txn.data, }] }; - + const abiMap = new Map() const tokenRawAbi = await (await fetch(fiourl + 'get_raw_abi', {body: '{"account_name": "' + txn.account + '"}', method: 'POST'})).json() abiMap.set(txn.account, tokenRawAbi) - + var privateKeys = [txn.privKey]; - + const tx = await Fio.prepareTransaction({ transaction, chainId, @@ -303,12 +303,12 @@ const callFioApiSigned = async (endPoint, txn) => { textDecoder: new TextDecoder(), textEncoder: new TextEncoder() }); - + const pushResult = await fetch(fiourl + endPoint, { body: JSON.stringify(tx), method: 'POST', }); - + const json = await pushResult.json() return json; }; @@ -350,7 +350,7 @@ async function getFees() { let fees = []; const json = { json: true, - code: 'fio.fee', + code: 'fio.fee', scope: 'fio.fee', table: 'fiofees', limit: 1000, @@ -358,7 +358,7 @@ async function getFees() { show_payer: false } callFioApi("get_table_rows", json) - .then(result => { + .then(result => { var i; for (i = 0; i < result.rows.length; i++) { fees[result.rows[i].end_point] = result.rows[i].suf_amount @@ -378,13 +378,13 @@ async function setRam(user, txnType, fee) { account_name: user.account, } callFioApi("get_account", json) - .then(result => { + .then(result => { ramEntry = { txnType: txnType, fee: fee, txnQuota: config.RAM[txnType], - actualRamUsage: result.ram_usage, - actualRamQuota: result.ram_quota, + actualRamUsage: result.ram_usage, + actualRamQuota: result.ram_quota, expectedRamQuota: config.RAM[txnType] } user.ramUsage.push(ramEntry); @@ -393,14 +393,14 @@ async function setRam(user, txnType, fee) { console.log('Error: ', error) reject(error) }); - + }); } async function printUserRam(user) { let entry, fee, type, txnQuota, actualRamQuota, deltaRamQuota, actualRamUsage, deltaActualRamUsage - console.log('RAM Usage for: ', user.account) + console.log('RAM Usage for: ', user.account) console.log('type' + '\t' + 'feeCollected' + '\t' + 'txnQuota' + '\t' + 'actualRamQuota' + '\t' + 'deltaRamQuota' + '\t' + 'actualRAMUsage' + '\t' + 'deltaActualRAMUsage') for (entry in user.ramUsage) { @@ -424,7 +424,7 @@ async function getTotalVotedFio() { const json = { json: true, - code: 'eosio', + code: 'eosio', scope: 'eosio', table: 'global', limit: 1000, @@ -432,7 +432,7 @@ async function getTotalVotedFio() { show_payer: false } callFioApi("get_table_rows", json) - .then(result => { + .then(result => { resolve(result.rows[0].total_voted_fio) }).catch(error => { console.log('Error: ', error) @@ -445,7 +445,7 @@ async function getProdVoteTotal(producer) { return new Promise(function(resolve, reject) { const json = { json: true, - code: 'eosio', + code: 'eosio', scope: 'eosio', table: 'producers', limit: 1000, @@ -453,11 +453,11 @@ async function getProdVoteTotal(producer) { show_payer: false } callFioApi("get_table_rows", json) - .then(result => { + .then(result => { for (prod in result.rows) { - if (result.rows[prod].fio_address == producer) { + if (result.rows[prod].fio_address == producer) { resolve(Math.floor(result.rows[prod].total_votes)) - break; + break; } } resolve(null) @@ -472,7 +472,7 @@ async function getAccountVoteWeight(account) { return new Promise(function(resolve, reject) { const json = { json: true, - code: 'eosio', + code: 'eosio', scope: 'eosio', table: 'voters', limit: 1000, @@ -480,11 +480,11 @@ async function getAccountVoteWeight(account) { show_payer: false } callFioApi("get_table_rows", json) - .then(result => { + .then(result => { for (voterID in result.rows) { - if (result.rows[voterID].owner == account) { + if (result.rows[voterID].owner == account) { resolve(Math.floor(result.rows[voterID].last_vote_weight)) - break; + break; } } resolve(null) @@ -531,7 +531,7 @@ async function addLock(account, amount, lock) { var text = {owner: account, amount: amount, locktype: lock} text = JSON.stringify(text) runCmd(config.CLIO + " push action -j eosio addlocked '" + text + "' -p eosio@active") - .then(result => { + .then(result => { let jResult = JSON.parse(result); account.lockAmount = amount; account.lockType = lock; @@ -546,11 +546,11 @@ async function addLock(account, amount, lock) { async function unlockWallet(wallet) { return new Promise(function(resolve, reject) { runCmd(config.CLIO + " wallet list") - .then(result => { - let walletLock = result.indexOf(wallet + " *") + .then(result => { + let walletLock = result.indexOf(wallet + " *") if (walletLock == -1 ) { // Wallet is not unlocked runCmd(config.CLIO + " wallet unlock -n " + wallet + " --password " + config.WALLETKEY) - } + } resolve() }).catch(error => { console.log('Error: ', error) @@ -576,8 +576,8 @@ function runCmd(command) { async function getTopprods() { return new Promise(function(resolve, reject) { runCmd(config.CLIO + " get table -l -1 eosio eosio topprods") - .then(result => { - let jresult = JSON.parse(result) + .then(result => { + let jresult = JSON.parse(result) //console.log("jresult", jresult.rows[0]) resolve(jresult) }).catch(error => { @@ -611,7 +611,7 @@ async function readProdFile(prodFile) { } catch (err) { console.log('Error: ', err); reject(err); - } + } }); } @@ -625,8 +625,8 @@ async function getVoteShares() { return new Promise(function(resolve, reject) { //console.log('in getAccountVoteWeight') runCmd(config.CLIO + " get table -l -1 fio.treasury fio.treasury voteshares") - .then(result => { - let jresult = JSON.parse(result) + .then(result => { + let jresult = JSON.parse(result) console.log("jresult", jresult.rows[0]) resolve(jresult) }).catch(error => { @@ -639,8 +639,8 @@ async function getVoteShares() { async function getFeevoters() { return new Promise(function(resolve, reject) { runCmd(config.CLIO + " get table -l -1 fio.fee fio.fee feevoters") - .then(result => { - let jresult = JSON.parse(result) + .then(result => { + let jresult = JSON.parse(result) console.log("jresult", jresult.rows[0]) resolve(jresult) }).catch(error => { @@ -653,8 +653,8 @@ async function getFeevoters() { async function getTopprods() { return new Promise(function(resolve, reject) { runCmd(config.CLIO + " get table -l -1 eosio eosio topprods") - .then(result => { - let jresult = JSON.parse(result) + .then(result => { + let jresult = JSON.parse(result) //console.log("jresult", jresult.rows[0]) resolve(jresult) }).catch(error => { @@ -668,8 +668,8 @@ async function getTopprods() { async function getBlock(number) { return new Promise(function(resolve, reject) { runCmd(config.CLIO + " get block " + number) - .then(result => { - let jresult = JSON.parse(result) + .then(result => { + let jresult = JSON.parse(result) //console.log("jresult", jresult) resolve(jresult) }).catch(error => { @@ -689,8 +689,8 @@ function getBlock2(number) { async function getTable(account, table) { return new Promise(function(resolve, reject) { runCmd(config.CLIO + " get table -l -1 " + account + " " + account + " " + table) - .then(result => { - let jresult = JSON.parse(result) + .then(result => { + let jresult = JSON.parse(result) //console.log("jresult", jresult.rows[0]) resolve(jresult) }).catch(error => { @@ -713,8 +713,8 @@ async function getTable(account, table) { async function pushAction(account, action, json, permission) { return new Promise(function(resolve, reject) { runCmd(config.CLIO + " push action " + account + " " + action + " '" + json + "' --permission " + permission + " --json") - .then(result => { - let jresult = JSON.parse(result) + .then(result => { + let jresult = JSON.parse(result) console.log("jresult", jresult) resolve(jresult) }).catch(error => { @@ -735,8 +735,8 @@ async function pushAction(account, action, json, permission) { async function getActions(account, pos, offset) { return new Promise(function(resolve, reject) { runCmd(config.CLIO + " get actions " + account + " " + pos + " " + offset) - .then(result => { - let jresult = JSON.parse(result) + .then(result => { + let jresult = JSON.parse(result) //console.log("jresult", jresult.rows) resolve(jresult) }).catch(error => { @@ -795,8 +795,8 @@ function runClio2(parms) { async function runClio(parms) { return new Promise(function(resolve, reject) { runCmd(config.CLIO + " " + parms) - .then(result => { - let jresult = JSON.parse(result) + .then(result => { + let jresult = JSON.parse(result) console.log("jresult", jresult) resolve(jresult) }).catch(error => { @@ -810,12 +810,12 @@ async function runClio(parms) { async function importPrivKey(pubkey, privkey) { return new Promise(function(resolve, reject) { runCmd(config.CLIO + " wallet keys") - .then(result => { - let keyexists = result.indexOf(pubkey) - console.log('keyexists: ', keyexists) + .then(result => { + let keyexists = result.indexOf(pubkey) + console.log('keyexists: ', keyexists) if (keyexists == -1 ) { // Pub Key not found //runCmd(config.CLIO + " wallet import --private-key " + privkey + " -n fio") - } + } resolve() }).catch(error => { console.log('Error: ', error) @@ -829,8 +829,8 @@ async function getPermissions(publicKey) { return new Promise(function(resolve, reject) { account = transaction.getActor(publicKey) runCmd(config.CLIO + " get account " + account + " -j") - .then(result => { - let jresult = JSON.parse(result) + .then(result => { + let jresult = JSON.parse(result) console.log("jresult", jresult.permissions[1]) permissions = { active: jresult.permissions[0], @@ -850,9 +850,9 @@ async function getRam(account) { let ramUse runCmd(config.CLIO + " get account " + account + " -j") .then(result => { //console.log("prev result", result) - let jResult = JSON.parse(result) + let jResult = JSON.parse(result) ramUse = { - actualRamUsage: jResult.ram_usage, + actualRamUsage: jResult.ram_usage, actualRamQuota: jResult.ram_quota } //ramLog.ramUsage.push(ramEntry); @@ -870,14 +870,14 @@ async function getRam(account) { async function updateAuth(account, ) { return new Promise(function(resolve, reject) { //#Create msig for 2lqw5qowwhin. This account will require kkpvib4wwhif (weight=1) and rkrpwdp3ismx (weight=1) - //./clio -u http://localhost:8889 push action eosio updateauth + //./clio -u http://localhost:8889 push action eosio updateauth var text = { - account: "2lqw5qowwhin", - permission: "active", - parent: "owner", - auth: { - threshold: 2, - keys: [], + account: "2lqw5qowwhin", + permission: "active", + parent: "owner", + auth: { + threshold: 2, + keys: [], waits: [], accounts: [{ permission: { @@ -892,17 +892,17 @@ async function updateAuth(account, ) { permission: "active" }, weight: 1 - }] - }, - max_fee: 4000000000 + }] + }, + max_fee: 4000000000 } //' -p 2lqw5qowwhin@active text = JSON.stringify(text) //console.log('in getAccountVoteWeight') runCmd(config.CLIO + " get table -l -1 fio.treasury fio.treasury voteshares") - .then(result => { - let jresult = JSON.parse(result) + .then(result => { + let jresult = JSON.parse(result) console.log("jresult", jresult.rows[0]) resolve(jresult) }).catch(error => { @@ -923,8 +923,8 @@ async function msigPropose() { //console.log('in getAccountVoteWeight') runCmd(config.CLIO + " get table -l -1 fio.treasury fio.treasury voteshares") - .then(result => { - let jresult = JSON.parse(result) + .then(result => { + let jresult = JSON.parse(result) console.log("jresult", jresult.rows[0]) resolve(jresult) }).catch(error => { @@ -942,8 +942,8 @@ async function msigApprove() { //console.log('in getAccountVoteWeight') runCmd(config.CLIO + " get table -l -1 fio.treasury fio.treasury voteshares") - .then(result => { - let jresult = JSON.parse(result) + .then(result => { + let jresult = JSON.parse(result) console.log("jresult", jresult.rows[0]) resolve(jresult) }).catch(error => { @@ -967,13 +967,13 @@ class Ram { let ramEntry runCmd(config.CLIO + " get account " + ramLog.account + " -j") .then(result => { //console.log("prev result", result) - let jResult = JSON.parse(result) + let jResult = JSON.parse(result) ramEntry = { txnType: txnType, fee: fee, txnQuota: config.RAM[txnType], - actualRamUsage: jResult.ram_usage, - actualRamQuota: jResult.ram_quota, + actualRamUsage: jResult.ram_usage, + actualRamQuota: jResult.ram_quota, expectedRamQuota: config.RAM[txnType] } ramLog.ramUsage.push(ramEntry); @@ -983,7 +983,7 @@ class Ram { console.log('Error: ', error) reject(error) }); - + }); } From fae98fb5d49c8df218d86164ce3041cc46eda013 Mon Sep 17 00:00:00 2001 From: Adam Androulidakis Date: Mon, 14 Dec 2020 14:38:24 -0700 Subject: [PATCH 05/76] fix case sensitive issue with sdk --- tests/Archive/fio-smoketest.js | 6 +++--- tests/Archive/fiojs-examples.js | 2 +- tests/Archive/get-blocks.js | 2 +- tests/Archive/msig.js | 2 +- tests/Archive/performance-check.js | 2 +- tests/Archive/proxy-vote.js | 2 +- tests/Archive/ram.js | 2 +- tests/action-whitelisting.js | 2 +- tests/addaddress.js | 2 +- tests/burn-address.js | 2 +- tests/clio.js | 2 +- tests/expired-domains.js | 2 +- tests/fee-voting-fee-setting.js | 2 +- tests/fee-voting-post-contract-set.js | 2 +- tests/fees.js | 2 +- tests/fio-request.js | 2 +- tests/history.js | 2 +- tests/locks.js | 2 +- tests/paging.js | 2 +- tests/producer-fee-setting.js | 2 +- tests/producer.js | 2 +- tests/pub_k1.js | 2 +- tests/pushtransaction.js | 2 +- tests/ram2.js | 2 +- tests/record-obt-data.js | 2 +- tests/register_fio_domain.js | 2 +- tests/removeaddress.js | 2 +- tests/testnet-smoketest.js | 2 +- tests/transfer-address.js | 2 +- tests/transfer-domain.js | 2 +- tests/transfer-locked-tokens-account-tests.js | 2 +- tests/transfer-locked-tokens.js | 2 +- tests/transfer-tokens.js | 2 +- tests/txn-resubmit.js | 2 +- tests/vote.js | 2 +- utils.js | 4 ++-- 36 files changed, 39 insertions(+), 39 deletions(-) diff --git a/tests/Archive/fio-smoketest.js b/tests/Archive/fio-smoketest.js index 2b2714d0..45022d61 100644 --- a/tests/Archive/fio-smoketest.js +++ b/tests/Archive/fio-smoketest.js @@ -1,15 +1,15 @@ //require('mocha') //const { expect } = require('chai') -//const {FIOSDK } = require('@fioprotocol/FIOSDK') +//const {FIOSDK } = require('@fioprotocol/fiosdk') //const fioData = require('./serverResponses'); //const fiojs = require("@fioprotocol/fiojs"); -//const Transactions_2 = require("@fioprotocol/FIOSDK/lib/transactions/Transactions") +//const Transactions_2 = require("@fioprotocol/fiosdk/lib/transactions/Transactions") //let transaction = new Transactions_2.Transactions require('mocha') const {expect} = require('chai') const {newUser, getProdVoteTotal, importPrivKey, unlockWallet, addLock, getAccountVoteWeight, getTotalVotedFio, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/Archive/fiojs-examples.js b/tests/Archive/fiojs-examples.js index 8c7fc52d..29691465 100644 --- a/tests/Archive/fiojs-examples.js +++ b/tests/Archive/fiojs-examples.js @@ -6,7 +6,7 @@ require('mocha') config = require('../../config.js'); const {expect} = require('chai') const {newUser, fetchJson, callFioApi} = require('../../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') before(async () => { diff --git a/tests/Archive/get-blocks.js b/tests/Archive/get-blocks.js index 9a00c1d1..d1f5a379 100644 --- a/tests/Archive/get-blocks.js +++ b/tests/Archive/get-blocks.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, getBlock, fetchJson} = require('../../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../../config.js'); diff --git a/tests/Archive/msig.js b/tests/Archive/msig.js index 2bf3af93..ffdd37b4 100644 --- a/tests/Archive/msig.js +++ b/tests/Archive/msig.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {callFioApi, fetchJson} = require('../../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK'); +const {FIOSDK } = require('@fioprotocol/fiosdk'); config = require('../../config.js'); const exec = require('child_process').exec; diff --git a/tests/Archive/performance-check.js b/tests/Archive/performance-check.js index 380360f1..67ada773 100644 --- a/tests/Archive/performance-check.js +++ b/tests/Archive/performance-check.js @@ -4,7 +4,7 @@ const {performance} = require('perf_hooks'); config = require('../../config.js'); const {expect} = require('chai') const {newUser, fetchJson, generateFioDomain, generateFioAddress, createKeypair, callFioApi} = require('../../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') before(async () => { diff --git a/tests/Archive/proxy-vote.js b/tests/Archive/proxy-vote.js index eb5b1c09..22ceb1db 100644 --- a/tests/Archive/proxy-vote.js +++ b/tests/Archive/proxy-vote.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {printUserRam, getAccountVoteWeight, getTotalVotedFio, setRam, user, generateFioDomain, generateFioAddress, fetchJson, randStr, timeout, createKeypair} = require('../../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../../config.js'); let user1 diff --git a/tests/Archive/ram.js b/tests/Archive/ram.js index 8ba4edb1..dd72ce04 100644 --- a/tests/Archive/ram.js +++ b/tests/Archive/ram.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {Ram, generateFioDomain, generateFioAddress, fetchJson, randStr, timeout, createKeypair} = require('../../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../../config.js'); let user1, user2 diff --git a/tests/action-whitelisting.js b/tests/action-whitelisting.js index ae3ee6ec..096e5081 100644 --- a/tests/action-whitelisting.js +++ b/tests/action-whitelisting.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, fetchJson, callFioApi, callFioApiSigned, generateFioDomain, timeout} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); /** diff --git a/tests/addaddress.js b/tests/addaddress.js index b97ea48d..bee52c52 100644 --- a/tests/addaddress.js +++ b/tests/addaddress.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, fetchJson, timeout, callFioApi} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/burn-address.js b/tests/burn-address.js index 18d840a6..f6236766 100644 --- a/tests/burn-address.js +++ b/tests/burn-address.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, generateFioAddress, callFioApiSigned, callFioApi, getFees, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/clio.js b/tests/clio.js index 656cb51b..bbdf0b2b 100644 --- a/tests/clio.js +++ b/tests/clio.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, randStr, generateFioDomain, generateFioAddress, unlockWallet, callFioApi, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); const exec = require('child_process').exec; diff --git a/tests/expired-domains.js b/tests/expired-domains.js index 25b65717..1deb9c09 100644 --- a/tests/expired-domains.js +++ b/tests/expired-domains.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, generateFioAddress, generateFioDomain, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/fee-voting-fee-setting.js b/tests/fee-voting-fee-setting.js index 136f6806..ca0ab23a 100644 --- a/tests/fee-voting-fee-setting.js +++ b/tests/fee-voting-fee-setting.js @@ -19,7 +19,7 @@ require('mocha') const {expect} = require('chai') const {readProdFile, fetchJson, newUser, existingUser, generateFioAddress,generateFioDomain,timeout } = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); let producersList = [], producers = [], newprods = [], sdkprods = [] diff --git a/tests/fee-voting-post-contract-set.js b/tests/fee-voting-post-contract-set.js index 13ffd9a4..79b22f34 100644 --- a/tests/fee-voting-post-contract-set.js +++ b/tests/fee-voting-post-contract-set.js @@ -8,7 +8,7 @@ require('mocha') const {expect} = require('chai') const {readProdFile, fetchJson, newUser, existingUser, generateFioAddress,generateFioDomain,timeout } = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); let producersList = [], producers = [], newprods = [], sdkprods = [] diff --git a/tests/fees.js b/tests/fees.js index 7267a494..f8ab35e9 100644 --- a/tests/fees.js +++ b/tests/fees.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/fio-request.js b/tests/fio-request.js index 26311952..59192672 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, fetchJson, callFioApi, timeout} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/history.js b/tests/history.js index 76e82318..e108a1e5 100644 --- a/tests/history.js +++ b/tests/history.js @@ -5,7 +5,7 @@ require('mocha') const {expect} = require('chai') const {callFioHistoryApi, existingUser, newUser, generateFioDomain, generateFioAddress, createKeypair, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/locks.js b/tests/locks.js index 22185604..b789dcfe 100644 --- a/tests/locks.js +++ b/tests/locks.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, unlockWallet, generateFioDomain, addLock, timeout, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); let total_voted_fio diff --git a/tests/paging.js b/tests/paging.js index 010f39d1..b819b048 100644 --- a/tests/paging.js +++ b/tests/paging.js @@ -2,7 +2,7 @@ require('mocha') config = require('../config.js'); const {expect} = require('chai') const {newUser, fetchJson, generateFioDomain, generateFioAddress, createKeypair, callFioApi} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') before(async () => { diff --git a/tests/producer-fee-setting.js b/tests/producer-fee-setting.js index f09c221d..15823de0 100644 --- a/tests/producer-fee-setting.js +++ b/tests/producer-fee-setting.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {getBlock, readProdFile, getTopprods, getTable, timeout, callFioApi, callFioApiSigned, getFees, newUser, existingUser, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); let producersList = [], producers = [], submit_fee_ratios_fee, submit_fee_multiplier_fee diff --git a/tests/producer.js b/tests/producer.js index b130a2d0..4b4ad063 100644 --- a/tests/producer.js +++ b/tests/producer.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, generateFioAddress, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/pub_k1.js b/tests/pub_k1.js index 56c2438f..7428dd71 100644 --- a/tests/pub_k1.js +++ b/tests/pub_k1.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, generateFioAddress, generateFioDomain, convertToK1, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); diff --git a/tests/pushtransaction.js b/tests/pushtransaction.js index 7c42ff14..8a6707ff 100644 --- a/tests/pushtransaction.js +++ b/tests/pushtransaction.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, fetchJson, generateFioAddress} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/ram2.js b/tests/ram2.js index 7622fd5f..1346c4c7 100644 --- a/tests/ram2.js +++ b/tests/ram2.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {printUserRam, setRam, user, generateFioDomain, generateFioAddress, fetchJson, randStr, timeout, createKeypair} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); let user1, user2 diff --git a/tests/record-obt-data.js b/tests/record-obt-data.js index 7229b972..3a16c4a2 100644 --- a/tests/record-obt-data.js +++ b/tests/record-obt-data.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, fetchJson, timeout, callFioApi} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/register_fio_domain.js b/tests/register_fio_domain.js index f6380aae..f2ea17cd 100644 --- a/tests/register_fio_domain.js +++ b/tests/register_fio_domain.js @@ -2,7 +2,7 @@ require('mocha') config = require('../config.js'); const {expect} = require('chai') const {newUser, fetchJson, generateFioDomain, timeout} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') before(async () => { diff --git a/tests/removeaddress.js b/tests/removeaddress.js index 820d5f39..6d101602 100644 --- a/tests/removeaddress.js +++ b/tests/removeaddress.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, timeout, fetchJson, callFioApi, callFioApiSigned} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/testnet-smoketest.js b/tests/testnet-smoketest.js index cf5d6874..75509d07 100644 --- a/tests/testnet-smoketest.js +++ b/tests/testnet-smoketest.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, existingUser, callFioApi, generateFioAddress, timeout} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); let user1, user2, user3 diff --git a/tests/transfer-address.js b/tests/transfer-address.js index 6f276857..448579ab 100644 --- a/tests/transfer-address.js +++ b/tests/transfer-address.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, generateFioAddress, createKeypair, callFioApi, getFees, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/transfer-domain.js b/tests/transfer-domain.js index 6b3b16dd..423d1e4b 100644 --- a/tests/transfer-domain.js +++ b/tests/transfer-domain.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, generateFioAddress, generateFioDomain, createKeypair, callFioApi, getFees, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/transfer-locked-tokens-account-tests.js b/tests/transfer-locked-tokens-account-tests.js index 71ca92a0..4102fdb7 100644 --- a/tests/transfer-locked-tokens-account-tests.js +++ b/tests/transfer-locked-tokens-account-tests.js @@ -1,6 +1,6 @@ require('mocha') const {expect} = require('chai') -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') const {fetchJson, timeout, generateFioDomain, generateFioAddress, createKeypair, getTotalVotedFio, getAccountVoteWeight, getProdVoteTotal} = require('../utils.js'); config = require('../config.js'); diff --git a/tests/transfer-locked-tokens.js b/tests/transfer-locked-tokens.js index b24577ff..9bf38124 100644 --- a/tests/transfer-locked-tokens.js +++ b/tests/transfer-locked-tokens.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, getProdVoteTotal, fetchJson, generateFioDomain, callFioApi, generateFioAddress, createKeypair} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/transfer-tokens.js b/tests/transfer-tokens.js index 8ffa067a..2625fe06 100644 --- a/tests/transfer-tokens.js +++ b/tests/transfer-tokens.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, fetchJson, generateFioDomain, generateFioAddress, createKeypair} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/txn-resubmit.js b/tests/txn-resubmit.js index 57bd2050..542bcffa 100644 --- a/tests/txn-resubmit.js +++ b/tests/txn-resubmit.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, generateFioAddress, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { diff --git a/tests/vote.js b/tests/vote.js index 788788e8..e2aa7d71 100644 --- a/tests/vote.js +++ b/tests/vote.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, getProdVoteTotal, timeout, unlockWallet, addLock, getAccountVoteWeight, getTotalVotedFio, callFioApi, callFioApiSigned, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); let total_voted_fio diff --git a/utils.js b/utils.js index baa4d654..5ca30dcc 100755 --- a/utils.js +++ b/utils.js @@ -11,9 +11,9 @@ var fs = require('fs'); const { Fio } = require('@fioprotocol/fiojs'); fetch = require('node-fetch'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') const {TextEncoder,TextDecoder } = require('text-encoding') -const Transactions_2 = require("@fioprotocol/FIOSDK/lib/transactions/Transactions") +const Transactions_2 = require("@fioprotocol/fiosdk/lib/transactions/Transactions") let transaction = new Transactions_2.Transactions function randStr(len) { From 6de2abf32c8af1b2a784e98fa38240068aa11e87 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 14 Dec 2020 20:19:39 -0700 Subject: [PATCH 06/76] updates from bravo --- index.js | 4 +- package.json | 4 +- tests/bravo-migr-test.js | 959 ++++++++++++++++++++++++++++++++ tests/record-obt-data-old.js | 385 +++++++++++++ tests/record-obt-data.js | 158 +++++- tests/testnet-smoketest.js | 2 +- tests/transfer-locked-tokens.js | 2 +- 7 files changed, 1508 insertions(+), 6 deletions(-) create mode 100644 tests/bravo-migr-test.js create mode 100644 tests/record-obt-data-old.js diff --git a/index.js b/index.js index 8575d6ed..b0f52ebd 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,8 @@ const {expect} = require('chai') describe('TEST SUITE', () => { + require('./tests/bravo-migr-test.js'); + //require('./tests/history.js'); // Only run against history node. require('./tests/addaddress.js'); // v1.0.x Also includes FIP-13 tests. require('./tests/fees.js'); // v1.0.x @@ -21,7 +23,7 @@ describe('TEST SUITE', () => { require('./tests/burn-address.js'); // FIP-7 //require('./tests/fee-voting-fee-setting.js'); // FIP-10 //require('./tests/producer-fee-setting.js'); // FIP-10 - require('./tests/record-obt-data.js'); //FIP-1.b testing + require('./tests/record-obt-data-old.js'); //FIP-1.b testing //require('./tests/transfer-address.js'); // FIP-1.b require('./tests/transfer-locked-tokens.js'); // FIP-6 locking tests require('./tests/transfer-locked-tokens-account-tests.js'); // FIP-6 tests of generic account functionality diff --git a/package.json b/package.json index f4035309..4e332675 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "@fioprotocol/fiosdk": "github:fioprotocol/fiosdk_typescript#project/november", + "@fioprotocol/fiosdk": "github:fioprotocol/fiosdk_typescript#develop", "child_process": "", "request": "^2.34.0", "request-promise": "", @@ -27,6 +27,6 @@ "typescript": "^3.8.2" }, "scripts": { - "test": "mocha -t 50000 index.js" + "test": "mocha -t 5000000 index.js" } } diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js new file mode 100644 index 00000000..baed0d49 --- /dev/null +++ b/tests/bravo-migr-test.js @@ -0,0 +1,959 @@ +/***** + This test loads up the chain with 1000 Requests and 10000 OBTs and then: + - Calls migrtx + - After the first call, tests that new requests and OBTs are being added to both tables. + - Repeatedly calls migrtrx to complete migration. + - Confirms migration and status updates are complete. + *****/ + +require('mocha') +const {expect} = require('chai') +const {newUser, fetchJson, existingUser, callFioApiSigned, callFioApi, timeout} = require('../utils.js'); +const {FIOSDK } = require('@fioprotocol/FIOSDK') +config = require('../config.js'); + +/* + #bp1:dapix + #Private key: 5KQ6f9ZgUtagD3LZ4wcMKhhvK9qy4BuwL3L1pkm6E2v62HCne2R + #Public key: FIO7jVQXMNLzSncm7kxwg9gk7XUBYQeJPk8b6QfaK5NVNkh3QZrRr + #FIO Public Address (actor name): qbxn5zhw2ypw + + #bp2:dapix + #Private key: 5JnhMxfnLhZeRCRvCUsaHbrvPSxaqjkQAgw4ZFodx4xXyhZbC9P + #Public key: FIO7uTisye5w2hgrCSE1pJhBKHfqDzhvqDJJ4U3vN9mbYWzataS2b + #FIO Public Address (actor name): hfdg2qumuvlc + + #bp3:dapix + #Private key: 5JvmPVxPxypQEKPwFZQW4Vx7EC8cDYzorVhSWZvuYVFMccfi5mU + #Public key: FIO6oa5UV9ghWgYH9en8Cv8dFcAxnZg2i9z9gKbnHahciuKNRPyHc + #FIO Public Address (actor name): wttywsmdmfew +*/ + +let bp1, bp2, bp3; +let amount = 5; + +before(async () => { + faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); + + // Create sdk objects for the orinigal localhost BPs + bp1 = await existingUser('qbxn5zhw2ypw', '5KQ6f9ZgUtagD3LZ4wcMKhhvK9qy4BuwL3L1pkm6E2v62HCne2R', 'FIO7jVQXMNLzSncm7kxwg9gk7XUBYQeJPk8b6QfaK5NVNkh3QZrRr', 'dapixdev', 'bp1@dapixdev'); + bp2 = await existingUser('hfdg2qumuvlc', '5JnhMxfnLhZeRCRvCUsaHbrvPSxaqjkQAgw4ZFodx4xXyhZbC9P', 'FIO7uTisye5w2hgrCSE1pJhBKHfqDzhvqDJJ4U3vN9mbYWzataS2b', 'dapixdev', 'bp2@dapixdev'); + bp3 = await existingUser('wttywsmdmfew', '5JvmPVxPxypQEKPwFZQW4Vx7EC8cDYzorVhSWZvuYVFMccfi5mU', 'FIO6oa5UV9ghWgYH9en8Cv8dFcAxnZg2i9z9gKbnHahciuKNRPyHc', 'dapixdev', 'bp3@dapixdev'); + +}) + +describe(`************************** bravo-migr-test.js.js ************************** \n Load Requests and OBTs`, () => { + let user1, user2, user3; + let payment = 3000000000; + let requestMemo = 'asdf'; + let count = 5; + + it(`Create users`, async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + user3 = await newUser(faucet); + + //console.log('user1: ' + user1.account + ', ' + user1.privateKey + ', ' + user1.publicKey) + //console.log('user2: ' + user2.account + ', ' + user2.privateKey + ', ' + user2.publicKey) + //console.log('user3: ' + user3.account + ', ' + user3.privateKey + ', ' + user3.publicKey) + }) + + it(`${count}x - user1 requests funds from user2`, async () => { + for (i = 0; i < count; i++) { + try { + const result = await user1.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user1.address, + payeeTokenPublicAddress: user1.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) + + it(`${count}x - user2 requests funds from user1`, async () => { + for (i = 0; i < count; i++) { + try { + const result = await user2.sdk.genericAction('requestFunds', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payeeTokenPublicAddress: user2.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user1.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) + + it(`${count}x - user3 requests funds from user2, user2 rejects request`, async () => { + let requestId; + for (i = 0; i < count; i++) { + try { + const result = await user3.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user3.address, + payeeTokenPublicAddress: user3.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + requestId = result.fio_request_id; + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + + try { + const result = await user2.sdk.genericAction('pushTransaction', { + action: 'rejectfndreq', + account: 'fio.reqobt', + data: { + fio_request_id: requestId, + max_fee: config.api.cancel_funds_request.fee, + tpid: '', + actor: user2.account + } + }) + //console.log('Result:', result) + expect(result.status).to.equal('request_rejected') + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + } + }) + + it(`${count}x - user2 requests funds from user1, user 1 records OBT response`, async () => { + let requestId; + for (i = 0; i < count; i++) { + try { + const result = await user2.sdk.genericAction('requestFunds', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payeeTokenPublicAddress: user2.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user1.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + requestId = result.fio_request_id; + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + + try { + const result = await user1.sdk.genericAction('recordObtData', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payerTokenPublicAddress: user1.publicKey, + payeeTokenPublicAddress: user2.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: requestId, + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user2.publicKey, + memo: 'this is a test', + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) + + it(`${count}x user3 creates BTC OBT send record to user1`, async () => { + for (i = 0; i < count; i++) { + try { + const result = await user3.sdk.genericAction('recordObtData', { + payerFioAddress: user3.address, + payeeFioAddress: user1.address, + payerTokenPublicAddress: user3.publicKey, + payeeTokenPublicAddress: user1.publicKey, + amount: payment, + chainCode: "BTC", + tokenCode: "BTC", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user1.publicKey, + memo: 'this is a test', + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) +}) + +describe(`Perform single migrtrx to initialize migration`, () => { + it(`Call single migrtrx (bp1) and confirm you can still do Requests and OBTs`, async () => { + try { + const result = await callFioApiSigned('push_transaction', { + action: 'migrtrx', + account: 'fio.reqobt', + actor: bp1.account, + privKey: bp1.privateKey, + data: { + amount: 1, + actor: bp1.account + } + }) + //console.log('Result: ', result) + expect(result.transaction_id).to.exist + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it.skip('Call get_table_rows from fiotrxts (NEW table) and display', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + console.log('requests: ', requests); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) +}) + +describe.only(`Confirm the number of records in old tables alignts with `, () => { + let obtCount = 0 + + it('Get the number of OBT records in recordobts', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'recordobts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + obts = await callFioApi("get_table_rows", json); + obtCount = obts.length; + console.log('obts: ', obts); + console.log('Number of records in recordobts: ', obts.length); + for (request in obts.rows) { + if (obts.rows[request].payer_fio_addr == user3.address) { + console.log('payer_fio_addr: ', obts.rows[request].payer_fio_addr); + break; + } + } + expect(obts.rows[request].payer_fio_addr).to.equal(user3.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) +}) + +describe(`Initial OBT record. Confirm new OBT Sends are going into both tables`, () => { + let user1, user2, user3 + let payment = 3000000000; + + it(`Create users`, async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + user3 = await newUser(faucet); + + //console.log('user1: ' + user1.account + ', ' + user1.privateKey + ', ' + user1.publicKey) + //console.log('user2: ' + user2.account + ', ' + user2.privateKey + ', ' + user2.publicKey) + //console.log('user3: ' + user3.account + ', ' + user3.privateKey + ', ' + user3.publicKey) + }) + + + it(`user3 creates BTC OBT send record to user1`, async () => { + try { + const result = await user3.sdk.genericAction('recordObtData', { + payerFioAddress: user3.address, + payeeFioAddress: user1.address, + payerTokenPublicAddress: user3.publicKey, + payeeTokenPublicAddress: user1.publicKey, + amount: payment, + chainCode: "BTC", + tokenCode: "BTC", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user1.publicKey, + memo: 'this is a test', + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + }) + + it('Call get_table_rows from recordobts (old table) and confirm OBT is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'recordobts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + obts = await callFioApi("get_table_rows", json); + //console.log('obts: ', obts); + for (request in obts.rows) { + if (obts.rows[request].payer_fio_addr == user3.address) { + //console.log('payer_fio_addr: ', obts.rows[request].payer_fio_addr); + break; + } + } + expect(obts.rows[request].payer_fio_addr).to.equal(user3.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it('Call get_table_rows from fiotrxts (NEW table) and confirm request is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + //console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].payer_fio_addr == user3.address) { + //console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; + } + } + expect(requests.rows[request].payer_fio_addr).to.equal(user3.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) + +describe(`Initial FIO Request record. Confirm NEW Requests are going into both tables`, () => { + let user1, user2, user3, requestId, obtId + let payment = 3000000000; + let requestMemo = 'asdf'; + + it(`Create users`, async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + user3 = await newUser(faucet); + + //console.log('user1: ' + user1.account + ', ' + user1.privateKey + ', ' + user1.publicKey) + //console.log('user2: ' + user2.account + ', ' + user2.privateKey + ', ' + user2.publicKey) + //console.log('user3: ' + user3.account + ', ' + user3.privateKey + ', ' + user3.publicKey) + }) + + it(`user1 requests funds from user2`, async () => { + try { + const result = await user1.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user1.address, + payeeTokenPublicAddress: user1.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + requestId = result.fio_request_id; + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + }) + + it('Requests: Call get_table_rows from fioreqctxts (old table) and confirm request is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fioreqctxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + //console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].fio_request_id == requestId) { + //console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; + } + } + expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it('Call get_table_rows from fiotrxts (NEW table) and confirm request is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + //console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].fio_request_id == requestId) { + //console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; + } + } + expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) + +describe.skip(`Confirm REJECTED Requests are going into both tables`, () => { + let user1, user2, user3, requestId + let payment = 3000000000; + let requestMemo = 'asdf'; + + it(`Create users`, async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + user3 = await newUser(faucet); + }) + + + it(`user3 requests funds from user2, user2 rejects request`, async () => { + let requestId; + for (i = 0; i < count; i++) { + try { + const result = await user3.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user3.address, + payeeTokenPublicAddress: user3.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + requestId = result.fio_request_id; + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + + try { + const result = await user2.sdk.genericAction('pushTransaction', { + action: 'rejectfndreq', + account: 'fio.reqobt', + data: { + fio_request_id: requestId, + max_fee: config.api.cancel_funds_request.fee, + tpid: '', + actor: user2.account + } + }) + //console.log('Result:', result) + expect(result.status).to.equal('request_rejected') + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + } + }) + + it('Requests: Call get_table_rows from fioreqctxts (old table) and confirm request is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fioreqctxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].fio_request_id == requestId) { + console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; + } + } + expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it('Call get_table_rows from fiotrxts (NEW table) and confirm request is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].fio_request_id == requestId) { + console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; + } + } + expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) + +describe.skip(`Confirm paid OBT response Requests are going into both tables`, () => { + let user1, user2, user3, requestId + let payment = 3000000000; + let requestMemo = 'asdf'; + + it(`Create users`, async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + user3 = await newUser(faucet); + + console.log('user1: ' + user1.account + ', ' + user1.privateKey + ', ' + user1.publicKey) + console.log('user2: ' + user2.account + ', ' + user2.privateKey + ', ' + user2.publicKey) + console.log('user3: ' + user3.account + ', ' + user3.privateKey + ', ' + user3.publicKey) + }) + + + it(`user2 requests funds from user1, user 1 records OBT response`, async () => { + let requestId; + try { + const result = await user2.sdk.genericAction('requestFunds', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payeeTokenPublicAddress: user2.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user1.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + requestId = result.fio_request_id; + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + + try { + const result = await user1.sdk.genericAction('recordObtData', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payerTokenPublicAddress: user1.publicKey, + payeeTokenPublicAddress: user2.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: requestId, + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user2.publicKey, + memo: 'this is a test', + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + }) + + it('Call get_table_rows from recordobts (old table) and confirm OBT is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'recordobts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + obts = await callFioApi("get_table_rows", json); + console.log('obts: ', obts); + for (request in obts.rows) { + if (obts.rows[request].id == user1.address) { + console.log('payer_fio_addr: ', obts.rows[request].requestId); + break; + } + } + expect(obts.rows[request].payer_fio_addr).to.equal(user1.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it.skip('Requests: Call get_table_rows from fioreqctxts (old table) and confirm request is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fioreqctxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].fio_request_id == requestId) { + console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; + } + } + expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it('Call get_table_rows from fiotrxts (NEW table) and confirm request is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].fio_request_id == requestId) { + console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; + } + } + expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) + +describe(`Migrate remaining requests and OBTs`, () => { + let isFinished = 0 + + it('Echo initial migrledgers table', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'migrledgers', + limit: 10, + reverse: false, + show_payer: false + } + ledger = await callFioApi("get_table_rows", json); + console.log('migrledgers: ', ledger); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Call migrtrx (bp1) with amount = 5 until migrledgers isFinished = 1`, async () => { + while (!isFinished) { + try { + const result = await callFioApiSigned('push_transaction', { + action: 'migrtrx', + account: 'fio.reqobt', + actor: bp1.account, + privKey: bp1.privateKey, + data: { + amount: 5, + actor: bp1.account + } + }) + //console.log('Result: ', result) + expect(result.transaction_id).to.exist + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + await timeout(2000); + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'migrledgers', + limit: 10, + reverse: false, + show_payer: false + } + ledger = await callFioApi("get_table_rows", json); + isFinished = ledger.rows[0].isFinished + //console.log('isFinished: ', isFinished); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + } + }) + + it('Echo final migrledgers table', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'migrledgers', + limit: 10, + reverse: false, + show_payer: false + } + ledger = await callFioApi("get_table_rows", json); + console.log('migrledgers: ', ledger); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) + +describe.skip(`Go through recordobts (old table) and confirm each entry is in fiotrxts (NEW table)`, () => { + let obtCount = 0 + + it('Get the number of OBT records in recordobts', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'recordobts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + obts = await callFioApi("get_table_rows", json); + obtCount = obts.length; + console.log('obts: ', obts); + console.log('Number of records in recordobts: ', obts.length); + for (request in obts.rows) { + if (obts.rows[request].payer_fio_addr == user3.address) { + console.log('payer_fio_addr: ', obts.rows[request].payer_fio_addr); + break; + } + } + expect(obts.rows[request].payer_fio_addr).to.equal(user3.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it('Call get_table_rows from recordobts (old table) and confirm every entry OBT is in table', async () => { + let count = 0; + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'recordobts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + obts = await callFioApi("get_table_rows", json); + console.log('obts: ', obts); + console.log('Number of records in recordobts: ', obts); + for (request in obts.rows) { + if (obts.rows[request].payer_fio_addr == user3.address) { + console.log('payer_fio_addr: ', obts.rows[request].payer_fio_addr); + expect(obts.rows[request].payer_fio_addr).to.equal(user3.address); + + // Call get_table_rows from fiotrxts (NEW table) and confirm request is in table + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].payer_fio_addr == user3.address) { + console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; + } + } + expect(requests.rows[request].payer_fio_addr).to.equal(user3.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + + } + count++; + } + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it.skip('Call get_table_rows from fiotrxts (NEW table) and confirm request is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].payer_fio_addr == user3.address) { + console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; + } + } + expect(requests.rows[request].payer_fio_addr).to.equal(user3.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + +}) \ No newline at end of file diff --git a/tests/record-obt-data-old.js b/tests/record-obt-data-old.js new file mode 100644 index 00000000..7229b972 --- /dev/null +++ b/tests/record-obt-data-old.js @@ -0,0 +1,385 @@ +require('mocha') +const {expect} = require('chai') +const {newUser, fetchJson, timeout, callFioApi} = require('../utils.js'); +const {FIOSDK } = require('@fioprotocol/FIOSDK') +config = require('../config.js'); + +before(async () => { + faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); +}) + +describe(`*********************** record-obt-data.js *********************** \n`, () => { + + let userA1, userA2, userA2Balance + const payment = 5000000000 // 5 FIO + const requestMemo = 'Memo Test' + const obtMemo = 'Memo in OBT response to request' + + it(`Create users`, async () => { + userA1 = await newUser(faucet); + userA2 = await newUser(faucet); + }) + + it(`userA1 requests funds from userA2`, async () => { + try { + const result = await userA1.sdk.genericAction('recordObtData', { + payerFioAddress: userA1.address, + payeeFioAddress: userA2.address, + payerTokenPublicAddress: userA1.publicKey, + payeeTokenPublicAddress: userA2.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: userA2.publicKey, + memo: obtMemo, + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`Confirm get_obt_data returns correct record for payee and payer`, async () => { + try { + const result = await userA1.sdk.genericAction('getObtData', { + limit: '', + offset: '' + }) + //console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result.obt_data_records[0].content.memo).to.equal(obtMemo) + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it('Call get_table_rows from fionames to get bundles remaining for userA2. Verify 100 bundles', async () => { + let bundleCount + try { + const json = { + json: true, // Get the response as json + code: 'fio.address', // Contract that we target + scope: 'fio.address', // Account that owns the data + table: 'fionames', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + fionames = await callFioApi("get_table_rows", json); + //console.log('fionames: ', fionames); + for (name in fionames.rows) { + if (fionames.rows[name].name == userA2.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); + bundleCount = fionames.rows[name].bundleeligiblecountdown; + } + } + expect(bundleCount).to.equal(100); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it('Call get_table_rows from fionames to get bundles remaining for userA1. Verify 98 bundles', async () => { + let bundleCount + try { + const json = { + json: true, // Get the response as json + code: 'fio.address', // Contract that we target + scope: 'fio.address', // Account that owns the data + table: 'fionames', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + fionames = await callFioApi("get_table_rows", json); + //console.log('fionames: ', fionames); + for (name in fionames.rows) { + if (fionames.rows[name].name == userA1.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); + bundleCount = fionames.rows[name].bundleeligiblecountdown; + } + } + expect(bundleCount).to.equal(98); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Use up all of userA2's bundles with 50 record_obt_data transactions`, async () => { + for (i = 0; i < 50; i++) { + try { + const result = await userA2.sdk.genericAction('recordObtData', { + payerFioAddress: userA2.address, + payeeFioAddress: userA1.address, + payerTokenPublicAddress: userA2.publicKey, + payeeTokenPublicAddress: userA1.publicKey, + amount: 5000000000, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: userA2.publicKey, + memo: 'this is a test', + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) + + it('Call get_table_rows from fionames to get bundles remaining for userA2. Verify 0 bundles', async () => { + let bundleCount + try { + const json = { + json: true, // Get the response as json + code: 'fio.address', // Contract that we target + scope: 'fio.address', // Account that owns the data + table: 'fionames', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + fionames = await callFioApi("get_table_rows", json); + //console.log('fionames: ', fionames); + for (name in fionames.rows) { + if (fionames.rows[name].name == userA2.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); + bundleCount = fionames.rows[name].bundleeligiblecountdown; + } + } + expect(bundleCount).to.equal(0); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`userA2 requests funds from userA1 with no bundles`, async () => { + try { + const result = await userA2.sdk.genericAction('recordObtData', { + payerFioAddress: userA2.address, + payeeFioAddress: userA1.address, + payerTokenPublicAddress: userA2.publicKey, + payeeTokenPublicAddress: userA1.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: userA1.publicKey, + memo: obtMemo, + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`Get balance for userA2`, async () => { + try { + const result = await userA2.sdk.genericAction('getFioBalance', { + fioPublicKey: userA2.publicKey + }) + userA2Balance = result.balance + //console.log('userB1 fio balance', result) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it('Transfer entire balance for userA2 to userA1 to register address', async () => { + try { + const result = await userA2.sdk.genericAction('transferTokens', { + payeeFioPublicKey: userA1.publicKey, + amount: userA2Balance - config.api.transfer_tokens_pub_key.fee, + maxFee: config.api.transfer_tokens_pub_key.fee, + walletFioAddress: '' + }) + //console.log('Result: ', result) + expect(result).to.have.all.keys('transaction_id', 'block_num', 'status', 'fee_collected') + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } + }) + + it(`Verify balance for userA2 = 0`, async () => { + try { + const result = await userA2.sdk.genericAction('getFioBalance', { + fioPublicKey: userA2.publicKey + }) + //console.log('userB1 fio balance', result) + expect(result.balance).to.equal(0) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`userA2 requests funds from userA1 with no bundles and no FIO`, async () => { + try { + const result = await userA2.sdk.genericAction('recordObtData', { + payerFioAddress: userA2.address, + payeeFioAddress: userA1.address, + payerTokenPublicAddress: userA2.publicKey, + payeeTokenPublicAddress: userA1.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: userA1.publicKey, + memo: obtMemo, + hash: '', + offLineUrl: '' + }) + console.log('Result: ', result); + expect(result).to.equal(null); + } catch (err) { + //console.log('Error', err.json); + expect(err.json.fields[0].error).to.equal(config.error.insufficientFunds); + } + }) +}) + +describe(`******************** Error Check ******************** \n`, () => { + + let userA1, userA2, userA3 + const payment = 5000000000 // 5 FIO + const requestMemo = 'Memo Test' + const obtMemo = 'Memo in OBT response to request' + + it(`Create users`, async () => { + userA1 = await newUser(faucet); + userA2 = await newUser(faucet); + userA3 = await newUser(faucet); + }) + + it(`badly formatted payer_fio_address`, async () => { + try { + const result = await userA1.sdk.genericAction('recordObtData', { + payerFioAddress: 'userA1.address', + payeeFioAddress: userA2.address, + payerTokenPublicAddress: userA1.publicKey, + payeeTokenPublicAddress: userA2.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: userA2.publicKey, + memo: obtMemo, + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result).to.equal(null) + } catch (err) { + expect(err.list[0].message).to.equal(config.error.invalidPayerFioAddress) + } + }) + + it(`badly formatted payee_fio_address`, async () => { + try { + const result = await userA1.sdk.genericAction('recordObtData', { + payerFioAddress: userA1.address, + payeeFioAddress: 'userA2.address', + payerTokenPublicAddress: userA1.publicKey, + payeeTokenPublicAddress: userA2.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: userA2.publicKey, + memo: obtMemo, + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result).to.equal(null) + } catch (err) { + expect(err.list[0].message).to.equal(config.error.invalidPayeeFioAddress) + } + }) + + it(`Add new FIO Address to userA1`, async () => { + try { + const result = await userA1.sdk.genericAction('addPublicAddresses', { + fioAddress: userA1.address, + publicAddresses: [ + { + chain_code: 'FIO', + token_code: 'FIO', + public_address: userA3.publicKey, + } + ], + maxFee: config.api.add_pub_address.fee, + technologyProviderId: '' + }) + //console.log('Result:', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error', err) + //expect(err).to.equal(null) + } + }) + + it(`payee_fio_public_key that does not own the the payee_fio_address`, async () => { + try { + const result = await userA2.sdk.genericAction('recordObtData', { + payerFioAddress: userA2.address, + payeeFioAddress: userA1.address, + payerTokenPublicAddress: userA2.publicKey, + payeeTokenPublicAddress: userA1.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: userA1.publicKey, + memo: obtMemo, + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) +}) diff --git a/tests/record-obt-data.js b/tests/record-obt-data.js index 7229b972..8d7a84c9 100644 --- a/tests/record-obt-data.js +++ b/tests/record-obt-data.js @@ -20,7 +20,7 @@ describe(`*********************** record-obt-data.js *********************** \n` userA2 = await newUser(faucet); }) - it(`userA1 requests funds from userA2`, async () => { + it(`userA1 sends obt data to userA2`, async () => { try { const result = await userA1.sdk.genericAction('recordObtData', { payerFioAddress: userA1.address, @@ -383,3 +383,159 @@ describe(`******************** Error Check ******************** \n`, () => { } }) }) + +describe.skip(`********************** record-obt-data.js ********************** \n Records Performance Testing`, () => { + + let userA1, userA2, userB1, userB2, userC1, userC2 + const payment = 5000000000 // 5 FIO + const requestMemo = 'Memo in the initial request' + const obtMemo = 'Memo in OBT response to request' + + it(`Create users`, async () => { + userA1 = await newUser(faucet); + userA2 = await newUser(faucet); + + userB1 = await newUser(faucet); + userB2 = await newUser(faucet); + + userC1 = await newUser(faucet); + userC2 = await newUser(faucet); + }) + + it(`userA1 requests funds from userA2 5000 times`, async () => { + for (i = 0; i < 1000; i++) { + try { + const result = await userA1.sdk.genericAction('recordObtData', { + payerFioAddress: userA1.address, + payeeFioAddress: userA2.address, + payerTokenPublicAddress: userA1.publicKey, + payeeTokenPublicAddress: userA2.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: userA1.publicKey, + memo: obtMemo, + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + + for (i = 0; i < 1000; i++) { + try { + const result = await userA2.sdk.genericAction('recordObtData', { + payerFioAddress: userA2.address, + payeeFioAddress: userA1.address, + payerTokenPublicAddress: userA2.publicKey, + payeeTokenPublicAddress: userA1.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: userA2.publicKey, + memo: obtMemo, + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + + for (i = 0; i < 1000; i++) { + try { + const result = await userC1.sdk.genericAction('recordObtData', { + payerFioAddress: userC1.address, + payeeFioAddress: userC2.address, + payerTokenPublicAddress: userC1.publicKey, + payeeTokenPublicAddress: userC2.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: userC1.publicKey, + memo: obtMemo, + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + + for (i = 0; i < 1000; i++) { + try { + const result = await userC2.sdk.genericAction('recordObtData', { + payerFioAddress: userC2.address, + payeeFioAddress: userC1.address, + payerTokenPublicAddress: userC2.publicKey, + payeeTokenPublicAddress: userC1.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: userC2.publicKey, + memo: obtMemo, + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + + for (i = 0; i < 1000; i++) { + try { + const result = await userB2.sdk.genericAction('recordObtData', { + payerFioAddress: userB2.address, + payeeFioAddress: userB1.address, + payerTokenPublicAddress: userB2.publicKey, + payeeTokenPublicAddress: userB1.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: userB2.publicKey, + memo: obtMemo, + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) +}) diff --git a/tests/testnet-smoketest.js b/tests/testnet-smoketest.js index cf5d6874..72de3036 100644 --- a/tests/testnet-smoketest.js +++ b/tests/testnet-smoketest.js @@ -71,7 +71,7 @@ describe(`FIO Requests (error conditions only)`, () => { expect(result).to.equal(null); } catch (err) { //console.log('Error', err); - expect(err.json.fields[0].error).to.equal('No such FIO Request '); + expect(err.json.fields[0].error).to.equal('No such FIO Request'); expect(err.errorCode).to.equal(400); } }) diff --git a/tests/transfer-locked-tokens.js b/tests/transfer-locked-tokens.js index 2879849f..7c8ebd4d 100644 --- a/tests/transfer-locked-tokens.js +++ b/tests/transfer-locked-tokens.js @@ -721,7 +721,7 @@ describe(`B. transfer with 2 unlock periods, canvote = false`, () => { } }) - it(`Register domain: succeeds`, async () => { + it(`[BD-2244] Register domain: succeeds`, async () => { try { domsdk = new FIOSDK(transferdomainkey.privateKey, transferdomainkey.publicKey, config.BASE_URL, fetchJson); domsdk.domain2 = generateFioDomain(8) From ffe339eafad5cf27430e8b09eca72abc8ea8926b Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 14 Dec 2020 20:21:51 -0700 Subject: [PATCH 07/76] remove old file --- tests/record-obt-data-old.js | 385 ----------------------------------- 1 file changed, 385 deletions(-) delete mode 100644 tests/record-obt-data-old.js diff --git a/tests/record-obt-data-old.js b/tests/record-obt-data-old.js deleted file mode 100644 index 7229b972..00000000 --- a/tests/record-obt-data-old.js +++ /dev/null @@ -1,385 +0,0 @@ -require('mocha') -const {expect} = require('chai') -const {newUser, fetchJson, timeout, callFioApi} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') -config = require('../config.js'); - -before(async () => { - faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); -}) - -describe(`*********************** record-obt-data.js *********************** \n`, () => { - - let userA1, userA2, userA2Balance - const payment = 5000000000 // 5 FIO - const requestMemo = 'Memo Test' - const obtMemo = 'Memo in OBT response to request' - - it(`Create users`, async () => { - userA1 = await newUser(faucet); - userA2 = await newUser(faucet); - }) - - it(`userA1 requests funds from userA2`, async () => { - try { - const result = await userA1.sdk.genericAction('recordObtData', { - payerFioAddress: userA1.address, - payeeFioAddress: userA2.address, - payerTokenPublicAddress: userA1.publicKey, - payeeTokenPublicAddress: userA2.publicKey, - amount: payment, - chainCode: "FIO", - tokenCode: "FIO", - status: '', - obtId: '', - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: userA2.publicKey, - memo: obtMemo, - hash: '', - offLineUrl: '' - }) - //console.log('Result: ', result) - expect(result.status).to.equal('sent_to_blockchain') - } catch (err) { - console.log('Error: ', err) - expect(err).to.equal(null) - } - }) - - it(`Confirm get_obt_data returns correct record for payee and payer`, async () => { - try { - const result = await userA1.sdk.genericAction('getObtData', { - limit: '', - offset: '' - }) - //console.log('result: ', result) - //console.log('content: ', result.requests[0].content) - expect(result.obt_data_records[0].content.memo).to.equal(obtMemo) - } catch (err) { - console.log('Error: ', err) - expect(err).to.equal(null) - } - }) - - it('Call get_table_rows from fionames to get bundles remaining for userA2. Verify 100 bundles', async () => { - let bundleCount - try { - const json = { - json: true, // Get the response as json - code: 'fio.address', // Contract that we target - scope: 'fio.address', // Account that owns the data - table: 'fionames', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - fionames = await callFioApi("get_table_rows", json); - //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == userA2.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - bundleCount = fionames.rows[name].bundleeligiblecountdown; - } - } - expect(bundleCount).to.equal(100); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - }) - - it('Call get_table_rows from fionames to get bundles remaining for userA1. Verify 98 bundles', async () => { - let bundleCount - try { - const json = { - json: true, // Get the response as json - code: 'fio.address', // Contract that we target - scope: 'fio.address', // Account that owns the data - table: 'fionames', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - fionames = await callFioApi("get_table_rows", json); - //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == userA1.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - bundleCount = fionames.rows[name].bundleeligiblecountdown; - } - } - expect(bundleCount).to.equal(98); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - }) - - it(`Use up all of userA2's bundles with 50 record_obt_data transactions`, async () => { - for (i = 0; i < 50; i++) { - try { - const result = await userA2.sdk.genericAction('recordObtData', { - payerFioAddress: userA2.address, - payeeFioAddress: userA1.address, - payerTokenPublicAddress: userA2.publicKey, - payeeTokenPublicAddress: userA1.publicKey, - amount: 5000000000, - chainCode: "FIO", - tokenCode: "FIO", - status: '', - obtId: '', - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: userA2.publicKey, - memo: 'this is a test', - hash: '', - offLineUrl: '' - }) - //console.log('Result: ', result) - expect(result.status).to.equal('sent_to_blockchain') - } catch (err) { - console.log('Error', err.json) - expect(err).to.equal(null) - } - } - }) - - it('Call get_table_rows from fionames to get bundles remaining for userA2. Verify 0 bundles', async () => { - let bundleCount - try { - const json = { - json: true, // Get the response as json - code: 'fio.address', // Contract that we target - scope: 'fio.address', // Account that owns the data - table: 'fionames', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - fionames = await callFioApi("get_table_rows", json); - //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == userA2.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - bundleCount = fionames.rows[name].bundleeligiblecountdown; - } - } - expect(bundleCount).to.equal(0); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - }) - - it(`userA2 requests funds from userA1 with no bundles`, async () => { - try { - const result = await userA2.sdk.genericAction('recordObtData', { - payerFioAddress: userA2.address, - payeeFioAddress: userA1.address, - payerTokenPublicAddress: userA2.publicKey, - payeeTokenPublicAddress: userA1.publicKey, - amount: payment, - chainCode: "FIO", - tokenCode: "FIO", - status: '', - obtId: '', - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: userA1.publicKey, - memo: obtMemo, - hash: '', - offLineUrl: '' - }) - //console.log('Result: ', result) - expect(result.status).to.equal('sent_to_blockchain') - } catch (err) { - console.log('Error: ', err) - expect(err).to.equal(null) - } - }) - - it(`Get balance for userA2`, async () => { - try { - const result = await userA2.sdk.genericAction('getFioBalance', { - fioPublicKey: userA2.publicKey - }) - userA2Balance = result.balance - //console.log('userB1 fio balance', result) - } catch (err) { - //console.log('Error', err) - expect(err).to.equal(null) - } - }) - - it('Transfer entire balance for userA2 to userA1 to register address', async () => { - try { - const result = await userA2.sdk.genericAction('transferTokens', { - payeeFioPublicKey: userA1.publicKey, - amount: userA2Balance - config.api.transfer_tokens_pub_key.fee, - maxFee: config.api.transfer_tokens_pub_key.fee, - walletFioAddress: '' - }) - //console.log('Result: ', result) - expect(result).to.have.all.keys('transaction_id', 'block_num', 'status', 'fee_collected') - } catch (err) { - console.log('Error: ', err); - expect(err).to.equal(null); - } - }) - - it(`Verify balance for userA2 = 0`, async () => { - try { - const result = await userA2.sdk.genericAction('getFioBalance', { - fioPublicKey: userA2.publicKey - }) - //console.log('userB1 fio balance', result) - expect(result.balance).to.equal(0) - } catch (err) { - //console.log('Error', err) - expect(err).to.equal(null) - } - }) - - it(`userA2 requests funds from userA1 with no bundles and no FIO`, async () => { - try { - const result = await userA2.sdk.genericAction('recordObtData', { - payerFioAddress: userA2.address, - payeeFioAddress: userA1.address, - payerTokenPublicAddress: userA2.publicKey, - payeeTokenPublicAddress: userA1.publicKey, - amount: payment, - chainCode: "FIO", - tokenCode: "FIO", - status: '', - obtId: '', - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: userA1.publicKey, - memo: obtMemo, - hash: '', - offLineUrl: '' - }) - console.log('Result: ', result); - expect(result).to.equal(null); - } catch (err) { - //console.log('Error', err.json); - expect(err.json.fields[0].error).to.equal(config.error.insufficientFunds); - } - }) -}) - -describe(`******************** Error Check ******************** \n`, () => { - - let userA1, userA2, userA3 - const payment = 5000000000 // 5 FIO - const requestMemo = 'Memo Test' - const obtMemo = 'Memo in OBT response to request' - - it(`Create users`, async () => { - userA1 = await newUser(faucet); - userA2 = await newUser(faucet); - userA3 = await newUser(faucet); - }) - - it(`badly formatted payer_fio_address`, async () => { - try { - const result = await userA1.sdk.genericAction('recordObtData', { - payerFioAddress: 'userA1.address', - payeeFioAddress: userA2.address, - payerTokenPublicAddress: userA1.publicKey, - payeeTokenPublicAddress: userA2.publicKey, - amount: payment, - chainCode: "FIO", - tokenCode: "FIO", - status: '', - obtId: '', - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: userA2.publicKey, - memo: obtMemo, - hash: '', - offLineUrl: '' - }) - //console.log('Result: ', result) - expect(result).to.equal(null) - } catch (err) { - expect(err.list[0].message).to.equal(config.error.invalidPayerFioAddress) - } - }) - - it(`badly formatted payee_fio_address`, async () => { - try { - const result = await userA1.sdk.genericAction('recordObtData', { - payerFioAddress: userA1.address, - payeeFioAddress: 'userA2.address', - payerTokenPublicAddress: userA1.publicKey, - payeeTokenPublicAddress: userA2.publicKey, - amount: payment, - chainCode: "FIO", - tokenCode: "FIO", - status: '', - obtId: '', - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: userA2.publicKey, - memo: obtMemo, - hash: '', - offLineUrl: '' - }) - //console.log('Result: ', result) - expect(result).to.equal(null) - } catch (err) { - expect(err.list[0].message).to.equal(config.error.invalidPayeeFioAddress) - } - }) - - it(`Add new FIO Address to userA1`, async () => { - try { - const result = await userA1.sdk.genericAction('addPublicAddresses', { - fioAddress: userA1.address, - publicAddresses: [ - { - chain_code: 'FIO', - token_code: 'FIO', - public_address: userA3.publicKey, - } - ], - maxFee: config.api.add_pub_address.fee, - technologyProviderId: '' - }) - //console.log('Result:', result) - expect(result.status).to.equal('OK') - } catch (err) { - console.log('Error', err) - //expect(err).to.equal(null) - } - }) - - it(`payee_fio_public_key that does not own the the payee_fio_address`, async () => { - try { - const result = await userA2.sdk.genericAction('recordObtData', { - payerFioAddress: userA2.address, - payeeFioAddress: userA1.address, - payerTokenPublicAddress: userA2.publicKey, - payeeTokenPublicAddress: userA1.publicKey, - amount: payment, - chainCode: "FIO", - tokenCode: "FIO", - status: '', - obtId: '', - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: userA1.publicKey, - memo: obtMemo, - hash: '', - offLineUrl: '' - }) - //console.log('Result: ', result) - expect(result.status).to.equal('sent_to_blockchain') - } catch (err) { - console.log('Error: ', err) - expect(err).to.equal(null) - } - }) -}) From feb962cd2de3ef850c3f187ab2dcd0ad208632cd Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 14 Dec 2020 20:44:10 -0700 Subject: [PATCH 08/76] more bahamas cleanup --- index.js | 2 +- tests/bravo-migr-test.js | 2 +- tests/fio-request.js | 151 ++++++++++++- tests/transfer-locked-tokens-account-tests.js | 205 +++++++++++++++++- 4 files changed, 341 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index b0f52ebd..6c6a3f36 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,7 @@ describe('TEST SUITE', () => { require('./tests/record-obt-data-old.js'); //FIP-1.b testing //require('./tests/transfer-address.js'); // FIP-1.b require('./tests/transfer-locked-tokens.js'); // FIP-6 locking tests - require('./tests/transfer-locked-tokens-account-tests.js'); // FIP-6 tests of generic account functionality + require('./tests/transfer-locked-tokens-account-tests-old.js'); // FIP-6 tests of generic account functionality //require('./tests/clio.js'); // FIP-16 //require('./tests/locks.js'); // Depends on local wallet. Need to fix diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index baed0d49..b44889cd 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -9,7 +9,7 @@ require('mocha') const {expect} = require('chai') const {newUser, fetchJson, existingUser, callFioApiSigned, callFioApi, timeout} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); /* diff --git a/tests/fio-request.js b/tests/fio-request.js index 58eb2a4d..e2cbc4ea 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -290,7 +290,7 @@ describe(`B. Test FIO Request error conditions`, () => { expect(result).to.equal(null); } catch (err) { //console.log('Error', err); - expect(err.json.fields[0].error).to.equal('No such FIO Request '); + expect(err.json.fields[0].error).to.equal('No such FIO Request'); expect(err.errorCode).to.equal(400); } }) @@ -709,7 +709,7 @@ describe(`B. Test FIO Request error conditions`, () => { }) -describe(`************************** cancel-funds-request ************************** \n A. cancel_funds_request with bundles remaining`, () => { +describe(`C. cancel_funds_request with bundles remaining`, () => { let userA1, userA2, userA1RequestId, cancel_funds_request_fee, userA1OrigRam, userA1OrigBundle const payment = 5000000000 // 5 FIO const requestMemo = 'Memo in the initial request' @@ -931,7 +931,7 @@ describe(`************************** cancel-funds-request ********************** }) }) -describe('B. cancel_funds_request with NO bundles remaining', () => { +describe('D. cancel_funds_request with NO bundles remaining', () => { let userB1, userB2, userB1RequestId, cancel_funds_request_fee, userB1OrigRam, userB1OrigBundle const payment = 5000000000 // 5 FIO @@ -1179,7 +1179,7 @@ describe('B. cancel_funds_request with NO bundles remaining', () => { }) -describe(`C. Test cancel_funds_request error conditions`, () => { +describe(`E. Test cancel_funds_request error conditions`, () => { let userC1, userC2, userC1RequestId, userC1RequestId2, userC1Balance const payment = 5000000000 // 5 FIO const requestMemo = 'Memo in the initial request' @@ -1532,7 +1532,8 @@ describe(`C. Test cancel_funds_request error conditions`, () => { }) -describe(`C. get_cancelled_fio_requests paging: Cancel multiple FIO requests and page through using get_cancelled_fio_requests`, () => { +describe(`F. get_cancelled_fio_requests paging: Cancel multiple FIO requests and page through using get_cancelled_fio_requests`, () => { + let userC1, requestID = [], requestCount = 20 it('Create userC1', async () => { @@ -1822,3 +1823,143 @@ describe(`C. get_cancelled_fio_requests paging: Cancel multiple FIO requests and }) }) + +describe.skip(`************************** fio-request.js ************************** \n G. Records Performance Testing`, () => { + + let userA1, userA2, userB1, userB2, userC1, userC2 + const payment = 5000000000 // 5 FIO + const requestMemo = 'Memo in the initial request' + + it(`Create users`, async () => { + userA1 = await newUser(faucet); + userA2 = await newUser(faucet); + + userB1 = await newUser(faucet); + userB2 = await newUser(faucet); + + userC1 = await newUser(faucet); + userC2 = await newUser(faucet); + }) + + it(`userA1 requests funds from userA2 5000 times`, async () => { + for (i = 0; i < 1000; i++) { + try { + const result = await userA1.sdk.genericAction('requestFunds', { + payerFioAddress: userA2.address, + payeeFioAddress: userA1.address, + payeeTokenPublicAddress: userA1.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: userA2.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + + for (i = 0; i < 1000; i++) { + try { + const result = await userA2.sdk.genericAction('requestFunds', { + payerFioAddress: userA1.address, + payeeFioAddress: userA2.address, + payeeTokenPublicAddress: userA1.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: userA1.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + + for (i = 0; i < 1000; i++) { + try { + const result = await userB1.sdk.genericAction('requestFunds', { + payerFioAddress: userB2.address, + payeeFioAddress: userB1.address, + payeeTokenPublicAddress: userA1.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: userB2.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + + for (i = 0; i < 1000; i++) { + try { + const result = await userB2.sdk.genericAction('requestFunds', { + payerFioAddress: userB1.address, + payeeFioAddress: userB2.address, + payeeTokenPublicAddress: userA1.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: userB1.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + + for (i = 0; i < 1000; i++) { + try { + const result = await userC2.sdk.genericAction('requestFunds', { + payerFioAddress: userC1.address, + payeeFioAddress: userC2.address, + payeeTokenPublicAddress: userA1.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: userC1.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) +}) diff --git a/tests/transfer-locked-tokens-account-tests.js b/tests/transfer-locked-tokens-account-tests.js index 1b3664a8..f9dac075 100644 --- a/tests/transfer-locked-tokens-account-tests.js +++ b/tests/transfer-locked-tokens-account-tests.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {FIOSDK } = require('@fioprotocol/fiosdk') -const {fetchJson, timeout, generateFioDomain, generateFioAddress, createKeypair, getTotalVotedFio, getAccountVoteWeight, getProdVoteTotal} = require('../utils.js'); +const {fetchJson, timeout, generateFioDomain, generateFioAddress, createKeypair, getTotalVotedFio, getAccountVoteWeight, getProdVoteTotal, callFioApi} = require('../utils.js'); config = require('../config.js'); let privateKey, publicKey, privateKey2, publicKey2, account, account2, testFioDomain, testFioAddressName, testFioAddressName2 @@ -45,7 +45,7 @@ describe(`************************** transfer-locked-tokens-account-tests.js *** console.log('publicKey2: ', publicKey2) }) - it(`Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { + it.skip(`(API) Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { try { const result = await fioSdkFaucet.genericAction('transferLockedTokens', { payeePublicKey: publicKey, @@ -72,7 +72,39 @@ describe(`************************** transfer-locked-tokens-account-tests.js *** } }) - it(`Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { + it(`(pushTransaction) Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { + try { + const result = await fioSdkFaucet.genericAction('pushTransaction', { + action: 'trnsloctoks', + account: 'fio.token', + data: { + payee_public_key: publicKey, + can_vote: 0, + periods: [ + { + duration: 3600, + percent: 40.0, + }, + { + duration: 3640, + percent: 60.0, + } + ], + amount: lockedFundsAmount, + max_fee: 400000000000, + tpid: '', + actor: fioSdkFaucet.account, + } + + }) + expect(result.status).to.equal('OK') + expect(result).to.have.all.keys( 'status', 'fee_collected') + } catch (err) { + console.log(' Error', err) + } + }) + + it.skip(`(API) Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { try { const result = await fioSdkFaucet.genericAction('transferLockedTokens', { payeePublicKey: publicKey2, @@ -99,20 +131,124 @@ describe(`************************** transfer-locked-tokens-account-tests.js *** } }) - it(`getFioBalance for fioSdk and confirm 'available' = 0`, async () => { + it(`(pushTransaction) Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { + try { + const result = await fioSdkFaucet.genericAction('pushTransaction', { + action: 'trnsloctoks', + account: 'fio.token', + data: { + payee_public_key: publicKey2, + can_vote: 0, + periods: [ + { + duration: 3600, + percent: 30.0, + }, + { + duration: 3640, + percent: 70.0, + } + ], + amount: lockedFundsAmount, + max_fee: 400000000000, + tpid: '', + actor: fioSdkFaucet.account, + } + + }) + expect(result.status).to.equal('OK') + expect(result).to.have.all.keys( 'status', 'fee_collected') + } catch (err) { + console.log(' Error', err) + } + }) + + it.skip(`getFioBalance for fioSdk and confirm 'available' = 0`, async () => { const result = await fioSdk.genericAction('getFioBalance', {}) //console.log('Result: ', result) expect(result).to.have.all.keys('balance', 'available') expect(result.available).equal(0) }) - it(`getFioBalance for fioSdk2 and confirm 'available' = 0`, async () => { + it(`Call get_table_rows from locktokens and confirm: lock_amount - remaining_lock_amount = 0`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'locktokens', + lower_bound: account, + upper_bound: account, + key_type: 'i64', + index_position: '2' + } + result = await callFioApi("get_table_rows", json); + //console.log('Result: ', result); + expect(result.rows[0].lock_amount - result.rows[0].remaining_lock_amount).to.equal(0); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + //try to transfer, fail. + it(`FAIL Transfer 1 FIO from locked token account, no funds unlocked`, async () => { + try{ + const result = await fioSdk.genericAction('transferTokens', { + payeeFioPublicKey: publicKey2, + amount: 1000000000, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + } catch (err) { + var expected = `Error 400` + expect(err.message).to.include(expected) + } + }) + + it.skip(`getFioBalance for fioSdk2 and confirm 'available' = 0`, async () => { const result = await fioSdk2.genericAction('getFioBalance', {}) //console.log('Result: ', result) expect(result).to.have.all.keys('balance', 'available') expect(result.available).equal(0) }) + it(`Call get_table_rows from locktokens and confirm: lock_amount - remaining_lock_amount = 0`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'locktokens', + lower_bound: account2, + upper_bound: account2, + key_type: 'i64', + index_position: '2' + } + result = await callFioApi("get_table_rows", json); + //console.log('Result: ', result); + expect(result.rows[0].lock_amount - result.rows[0].remaining_lock_amount).to.equal(0); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + //try to transfer, fail. + it(`FAIL Transfer 1 FIO from locked token account, no funds unlocked`, async () => { + try{ + const result = await fioSdk2.genericAction('transferTokens', { + payeeFioPublicKey: publicKey, + amount: 1000000000, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + } catch (err) { + var expected = `Error 400` + expect(err.message).to.include(expected) + } + }) + it(`Transfer additional tokens to account for testing`, async () => { // Then transfer additional non-locke tokens to the account for the tests await fioSdkFaucet.transferTokens(publicKey, fundAmount * 4, defaultFee) @@ -121,18 +257,63 @@ describe(`************************** transfer-locked-tokens-account-tests.js *** await timeout(receiveTransferTimout) }) - it(`getFioBalance for fioSdk and confirm 'available' > 0`, async () => { + let balance1, balance2; + it(`[Fix for Bahamas release] getFioBalance for fioSdk and confirm 'available' > 0`, async () => { const result = await fioSdk.genericAction('getFioBalance', {}) //console.log('Result: ', result) - expect(result).to.have.all.keys('balance', 'available') - expect(result.available).is.greaterThan(0) + balance1 = result.balance; + // Add back: expect(result).to.have.all.keys('balance', 'available') + //expect(result.available).is.greaterThan(0) + }) + + it(`Call get_table_rows from locktokens and confirm: lock_amount - remaining_lock_amount > 0`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'locktokens', + lower_bound: account, + upper_bound: account, + key_type: 'i64', + index_position: '2' + } + result = await callFioApi("get_table_rows", json); + //console.log('Result: ', result); + expect(balance1 - result.rows[0].lock_amount - result.rows[0].remaining_lock_amount).is.greaterThan(0) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } }) - it(`getFioBalance for fioSdk2 and confirm 'available' > 0`, async () => { + it(`[Fix for Bahamas release] getFioBalance for fioSdk2 and confirm 'available' > 0`, async () => { const result = await fioSdk2.genericAction('getFioBalance', {}) //console.log('Result: ', result) - expect(result).to.have.all.keys('balance', 'available') - expect(result.available).is.greaterThan(0) + balance2 = result.balance + // Add back: expect(result).to.have.all.keys('balance', 'available') + //expect(result.available).is.greaterThan(0) + }) + + it(`Call get_table_rows from locktokens and confirm: lock_amount - remaining_lock_amount > 0`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'locktokens', + lower_bound: account2, + upper_bound: account2, + key_type: 'i64', + index_position: '2' + } + result = await callFioApi("get_table_rows", json); + //console.log('Result: ', result); + expect(balance2 - result.rows[0].lock_amount - result.rows[0].remaining_lock_amount).is.greaterThan(0) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } }) it(`Register domains and addresses`, async () => { @@ -1197,4 +1378,4 @@ describe(`Test locked token accounts with proxy voting`, () => { } }) -}) +}) \ No newline at end of file From e69a0b41ab9cff4c40f6aa66a28de1e3afd56925 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 14 Dec 2020 21:08:28 -0700 Subject: [PATCH 09/76] Add migration initialization --- index.js | 6 +++--- tests/bravo-migr-test.js | 2 +- tests/transfer-locked-tokens-account-tests.js | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 6c6a3f36..c837c28d 100644 --- a/index.js +++ b/index.js @@ -23,12 +23,12 @@ describe('TEST SUITE', () => { require('./tests/burn-address.js'); // FIP-7 //require('./tests/fee-voting-fee-setting.js'); // FIP-10 //require('./tests/producer-fee-setting.js'); // FIP-10 - require('./tests/record-obt-data-old.js'); //FIP-1.b testing + require('./tests/record-obt-data.js'); //FIP-1.b testing //require('./tests/transfer-address.js'); // FIP-1.b require('./tests/transfer-locked-tokens.js'); // FIP-6 locking tests - require('./tests/transfer-locked-tokens-account-tests-old.js'); // FIP-6 tests of generic account functionality + require('./tests/transfer-locked-tokens-account-tests.js'); // FIP-6 tests of generic account functionality //require('./tests/clio.js'); // FIP-16 - + //require('./tests/locks.js'); // Depends on local wallet. Need to fix //require('./tests/testnet-smoketest.js'); // In development //require('./tests/pub_k1.js'); // Moved to later release diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index b44889cd..99397cbb 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -280,7 +280,7 @@ describe(`Perform single migrtrx to initialize migration`, () => { }) }) -describe.only(`Confirm the number of records in old tables alignts with `, () => { +describe.skip(`Confirm the number of records in old tables aligns with `, () => { let obtCount = 0 it('Get the number of OBT records in recordobts', async () => { diff --git a/tests/transfer-locked-tokens-account-tests.js b/tests/transfer-locked-tokens-account-tests.js index f9dac075..6396e3c1 100644 --- a/tests/transfer-locked-tokens-account-tests.js +++ b/tests/transfer-locked-tokens-account-tests.js @@ -45,7 +45,7 @@ describe(`************************** transfer-locked-tokens-account-tests.js *** console.log('publicKey2: ', publicKey2) }) - it.skip(`(API) Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { + it(`(API) Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { try { const result = await fioSdkFaucet.genericAction('transferLockedTokens', { payeePublicKey: publicKey, @@ -72,7 +72,7 @@ describe(`************************** transfer-locked-tokens-account-tests.js *** } }) - it(`(pushTransaction) Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { + it.skip(`(pushTransaction) Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { try { const result = await fioSdkFaucet.genericAction('pushTransaction', { action: 'trnsloctoks', @@ -104,7 +104,7 @@ describe(`************************** transfer-locked-tokens-account-tests.js *** } }) - it.skip(`(API) Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { + it(`(API) Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { try { const result = await fioSdkFaucet.genericAction('transferLockedTokens', { payeePublicKey: publicKey2, @@ -131,7 +131,7 @@ describe(`************************** transfer-locked-tokens-account-tests.js *** } }) - it(`(pushTransaction) Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { + it.skip(`(pushTransaction) Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { try { const result = await fioSdkFaucet.genericAction('pushTransaction', { action: 'trnsloctoks', From 23f6a3ec140ca01aeffe0c6c4a08c2b096276c75 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Tue, 15 Dec 2020 07:44:45 -0700 Subject: [PATCH 10/76] Remove deprecated name --- tests/burn-address.js | 32 +++++++++++++++---------------- tests/fio-request.js | 40 +++++++++++++++++++-------------------- tests/record-obt-data.js | 24 +++++++++++------------ tests/removeaddress.js | 16 ++++++++-------- tests/transfer-address.js | 8 ++++---- tests/transfer-domain.js | 8 ++++---- tests/vote.js | 32 +++++++++++++++---------------- 7 files changed, 80 insertions(+), 80 deletions(-) diff --git a/tests/burn-address.js b/tests/burn-address.js index 76038951..4805c9a8 100644 --- a/tests/burn-address.js +++ b/tests/burn-address.js @@ -107,9 +107,9 @@ describe('************************** burn-address.js ************************** } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == walletA1.address2) { - //console.log('fioname: ', fionames.rows[name]); + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == walletA1.address2) { + //console.log('fioname: ', fionames.rows[fioname]); inTable = true; } } @@ -164,9 +164,9 @@ describe('************************** burn-address.js ************************** fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); for (name in fionames.rows) { - if (fionames.rows[name].name == walletA1.address) { - //console.log('bundleCount: ', fionames.rows[name].bundleeligiblecountdown); - bundleCount = fionames.rows[name].bundleeligiblecountdown; + if (fionames.rows[fioname].name == walletA1.address) { + //console.log('bundleCount: ', fionames.rows[fioname].bundleeligiblecountdown); + bundleCount = fionames.rows[fioname].bundleeligiblecountdown; } } expect(bundleCount).to.equal(0); @@ -237,9 +237,9 @@ describe('************************** burn-address.js ************************** } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == walletA1.address) { - //console.log('fioname: ', fionames.rows[name]); + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == walletA1.address) { + //console.log('fioname: ', fionames.rows[fioname]); inTable = true; } } @@ -524,10 +524,10 @@ describe('D. burnFioAddress Error testing', () => { } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == userD1.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - bundleCount = fionames.rows[name].bundleeligiblecountdown; + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == userD1.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); + bundleCount = fionames.rows[fioname].bundleeligiblecountdown; } } expect(bundleCount).to.equal(0); @@ -653,9 +653,9 @@ describe('E. Test burnfioaddress SDK call (uses chain/burn_fio_address endpoint) } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == walletA1.address2) { - //console.log('fioname: ', fionames.rows[name]); + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == walletA1.address2) { + //console.log('fioname: ', fionames.rows[fioname]); inTable = true; } } diff --git a/tests/fio-request.js b/tests/fio-request.js index e2cbc4ea..59c41577 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -605,10 +605,10 @@ describe(`B. Test FIO Request error conditions`, () => { } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == userB1.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - bundleCount = fionames.rows[name].bundleeligiblecountdown; + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == userB1.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); + bundleCount = fionames.rows[fioname].bundleeligiblecountdown; } } expect(bundleCount).to.equal(0); @@ -800,10 +800,10 @@ describe(`C. cancel_funds_request with bundles remaining`, () => { } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == userA1.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - userA1OrigBundle = fionames.rows[name].bundleeligiblecountdown; + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == userA1.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); + userA1OrigBundle = fionames.rows[fioname].bundleeligiblecountdown; } } expect(userA1OrigBundle).to.equal(98); // 2 for new_funds_request @@ -903,10 +903,10 @@ describe(`C. cancel_funds_request with bundles remaining`, () => { } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == userA1.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - bundleCount = fionames.rows[name].bundleeligiblecountdown; + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == userA1.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); + bundleCount = fionames.rows[fioname].bundleeligiblecountdown; } } expect(bundleCount).to.equal(userA1OrigBundle - 1); // 1 bundle for cancel_funds_request @@ -1074,10 +1074,10 @@ describe('D. cancel_funds_request with NO bundles remaining', () => { } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == userB1.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - userB1OrigBundle = fionames.rows[name].bundleeligiblecountdown; + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == userB1.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); + userB1OrigBundle = fionames.rows[fioname].bundleeligiblecountdown; } } expect(userB1OrigBundle).to.equal(0); @@ -1496,10 +1496,10 @@ describe(`E. Test cancel_funds_request error conditions`, () => { } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == userC1.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - bundleCount = fionames.rows[name].bundleeligiblecountdown; + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == userC1.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); + bundleCount = fionames.rows[fioname].bundleeligiblecountdown; } } expect(bundleCount).to.equal(0); diff --git a/tests/record-obt-data.js b/tests/record-obt-data.js index 1ea57341..2282cc5a 100644 --- a/tests/record-obt-data.js +++ b/tests/record-obt-data.js @@ -76,10 +76,10 @@ describe(`*********************** record-obt-data.js *********************** \n` } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == userA2.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - bundleCount = fionames.rows[name].bundleeligiblecountdown; + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == userA2.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); + bundleCount = fionames.rows[fioname].bundleeligiblecountdown; } } expect(bundleCount).to.equal(100); @@ -103,10 +103,10 @@ describe(`*********************** record-obt-data.js *********************** \n` } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == userA1.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - bundleCount = fionames.rows[name].bundleeligiblecountdown; + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == userA1.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); + bundleCount = fionames.rows[fioname].bundleeligiblecountdown; } } expect(bundleCount).to.equal(98); @@ -159,10 +159,10 @@ describe(`*********************** record-obt-data.js *********************** \n` } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == userA2.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - bundleCount = fionames.rows[name].bundleeligiblecountdown; + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == userA2.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); + bundleCount = fionames.rows[fioname].bundleeligiblecountdown; } } expect(bundleCount).to.equal(0); diff --git a/tests/removeaddress.js b/tests/removeaddress.js index 55f759c1..10e625cb 100644 --- a/tests/removeaddress.js +++ b/tests/removeaddress.js @@ -947,10 +947,10 @@ describe(`E-2. Add and remove addresses with NO bundles remaining`, () => { } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == userA1.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - bundleCount = fionames.rows[name].bundleeligiblecountdown; + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == userA1.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); + bundleCount = fionames.rows[fioname].bundleeligiblecountdown; } } expect(bundleCount).to.equal(0); @@ -1412,10 +1412,10 @@ describe(`F. Sad - result in error`, () => { } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == userA1.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - bundleCount = fionames.rows[name].bundleeligiblecountdown; + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == userA1.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); + bundleCount = fionames.rows[fioname].bundleeligiblecountdown; } } expect(bundleCount).to.equal(0); diff --git a/tests/transfer-address.js b/tests/transfer-address.js index 21ac3528..52c30a60 100644 --- a/tests/transfer-address.js +++ b/tests/transfer-address.js @@ -704,10 +704,10 @@ describe('D. transferFioAddress Error testing', () => { } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == userD3.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - bundleCount = fionames.rows[name].bundleeligiblecountdown; + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == userD3.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); + bundleCount = fionames.rows[fioname].bundleeligiblecountdown; } } expect(bundleCount).to.equal(0); diff --git a/tests/transfer-domain.js b/tests/transfer-domain.js index aedb19ed..ffa7862e 100644 --- a/tests/transfer-domain.js +++ b/tests/transfer-domain.js @@ -806,10 +806,10 @@ describe('D. transferFioDomain Error testing', () => { } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == userD3.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - bundleCount = fionames.rows[name].bundleeligiblecountdown; + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == userD3.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); + bundleCount = fionames.rows[fioname].bundleeligiblecountdown; } } expect(bundleCount).to.equal(0); diff --git a/tests/vote.js b/tests/vote.js index 8ccb1f15..ae49bf03 100644 --- a/tests/vote.js +++ b/tests/vote.js @@ -1651,10 +1651,10 @@ describe('FIP-9: G.2 Test vote_producer with and without FIO Address', () => { } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == voterG3.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - bundleCount = fionames.rows[name].bundleeligiblecountdown; + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == voterG3.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); + bundleCount = fionames.rows[fioname].bundleeligiblecountdown; } } expect(bundleCount).to.be.greaterThan(0); @@ -1700,10 +1700,10 @@ describe('FIP-9: G.2 Test vote_producer with and without FIO Address', () => { } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == voterG3.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - bundleCount = fionames.rows[name].bundleeligiblecountdown; + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == voterG3.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); + bundleCount = fionames.rows[fioname].bundleeligiblecountdown; } } expect(bundleCount).to.equal(prevBundleCount - 1); @@ -2169,10 +2169,10 @@ describe('FIP-9: G.3 Test proxy_vote with and without FIO Address', () => { } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == voterG7.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - bundleCount = fionames.rows[name].bundleeligiblecountdown; + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == voterG7.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); + bundleCount = fionames.rows[fioname].bundleeligiblecountdown; } } expect(bundleCount).to.be.greaterThan(0); @@ -2243,10 +2243,10 @@ describe('FIP-9: G.3 Test proxy_vote with and without FIO Address', () => { } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { - if (fionames.rows[name].name == voterG7.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[name].bundleeligiblecountdown); - bundleCount = fionames.rows[name].bundleeligiblecountdown; + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == voterG7.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); + bundleCount = fionames.rows[fioname].bundleeligiblecountdown; } } expect(bundleCount).to.equal(prevBundleCount - 1); From 9a4c5bc06e9d31997055f2142c371273fa606e1f Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Tue, 15 Dec 2020 12:26:46 -0700 Subject: [PATCH 11/76] Add request check to migr test --- tests/bravo-migr-test.js | 216 +++++++++++++++++++++++++++++++-------- utils.js | 7 +- 2 files changed, 175 insertions(+), 48 deletions(-) diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index 99397cbb..2a1fc984 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -280,38 +280,6 @@ describe(`Perform single migrtrx to initialize migration`, () => { }) }) -describe.skip(`Confirm the number of records in old tables aligns with `, () => { - let obtCount = 0 - - it('Get the number of OBT records in recordobts', async () => { - try { - const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'recordobts', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - obts = await callFioApi("get_table_rows", json); - obtCount = obts.length; - console.log('obts: ', obts); - console.log('Number of records in recordobts: ', obts.length); - for (request in obts.rows) { - if (obts.rows[request].payer_fio_addr == user3.address) { - console.log('payer_fio_addr: ', obts.rows[request].payer_fio_addr); - break; - } - } - expect(obts.rows[request].payer_fio_addr).to.equal(user3.address); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - }) -}) - describe(`Initial OBT record. Confirm new OBT Sends are going into both tables`, () => { let user1, user2, user3 let payment = 3000000000; @@ -761,7 +729,7 @@ describe.skip(`Confirm paid OBT response Requests are going into both tables`, ( }) -describe(`Migrate remaining requests and OBTs`, () => { +describe.skip(`Migrate remaining requests and OBTs`, () => { let isFinished = 0 it('Echo initial migrledgers table', async () => { @@ -846,8 +814,36 @@ describe(`Migrate remaining requests and OBTs`, () => { describe.skip(`Go through recordobts (old table) and confirm each entry is in fiotrxts (NEW table)`, () => { let obtCount = 0 + let obtRecords; + + describe.skip(`Confirm the number of records in old tables aligns with `, () => { + + + it.skip('Get the number of OBT records in recordobts', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'recordobts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + obts = await callFioApi("get_table_rows", json); + obtCount = obts.rows.length; + //console.log('obts: ', obts); + console.log('Number of records in recordobts: ', obts.rows.length); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + }) + + it('Step through recordobts and confirm every entry is found on the new table.', async () => { + let count = 0; - it('Get the number of OBT records in recordobts', async () => { try { const json = { json: true, // Get the response as json @@ -859,23 +855,70 @@ describe.skip(`Go through recordobts (old table) and confirm each entry is in fi show_payer: false // Optional: Show ram payer } obts = await callFioApi("get_table_rows", json); - obtCount = obts.length; - console.log('obts: ', obts); - console.log('Number of records in recordobts: ', obts.length); - for (request in obts.rows) { - if (obts.rows[request].payer_fio_addr == user3.address) { - console.log('payer_fio_addr: ', obts.rows[request].payer_fio_addr); - break; + obtCount = obts.rows.length; + //console.log('obts: ', obts); + console.log('Number of records in recordobts: ', obtCount); + for (obt in obts.rows) { + /* obtRecord = { + id: obts.rows[obt].id, + payer_fio_addr: obts.rows[obt].payer_fio_addr, + payee_fio_addr: obts.rows[obt].payee_fio_addr, + payer_key: obts.rows[obt].payer_key, + payee_key: obts.rows[obt].payee_key, + time_stamp: obts.rows[obt].time_stamp } + obtRecords.push(obtRecord); + */ + + // Call get_table_rows from fiotrxts (NEW table) and confirm request is in table + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + newRequests = await callFioApi("get_table_rows", json); + //console.log('requests: ', newRequests); + for (newRequest in newRequests.rows) { + if (newRequests.rows[newRequest].payer_fio_addr == obts.rows[obt].payer_fio_addr) { + console.log(count); + console.log('recordobts:') + console.log('id: ', obts.rows[obt].id); + console.log('payer_fio_addr: ', obts.rows[obt].payer_fio_addr); + console.log('payee_fio_addr: ', obts.rows[obt].payee_fio_addr); + console.log('fiotrxts:') + console.log('id: ', newRequests.rows[newRequest].id); + onsole.log('fio_request_id: ', newRequests.rows[newRequest].fio_request_id); + console.log('payer_fio_addr: ', newRequests.rows[newRequest].payer_fio_addr); + console.log('payee_fio_addr: ', newRequests.rows[newRequest].payee_fio_addr); + + expect(obts.rows[obt].payer_fio_addr).to.equal(newRequests.rows[newRequest].payer_fio_addr); + expect(obts.rows[obt].payee_fio_addr).to.equal(newRequests.rows[newRequest].payee_fio_addr); + expect(obts.rows[obt].payer_key).to.equal(newRequests.rows[newRequest].payer_key); + expect(obts.rows[obt].payee_key).to.equal(newRequests.rows[newRequest].payee_key); + //expect(obts.rows[obt].time_stamp).to.equal(newRequests.rows[newRequest].init_time); //Time stamps different? + expect(newRequests.rows[newRequest].fio_request_id).to.equal(0); + expect(newRequests.rows[newRequest].fio_data_type).to.equal(4); + break; + } + } + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + count++; } - expect(obts.rows[request].payer_fio_addr).to.equal(user3.address); } catch (err) { console.log('Error', err); expect(err).to.equal(null); } }) - it('Call get_table_rows from recordobts (old table) and confirm every entry OBT is in table', async () => { + it.skip('Call get_table_rows from recordobts (old table) and confirm every entry OBT is in table', async () => { let count = 0; try { const json = { @@ -888,8 +931,8 @@ describe.skip(`Go through recordobts (old table) and confirm each entry is in fi show_payer: false // Optional: Show ram payer } obts = await callFioApi("get_table_rows", json); - console.log('obts: ', obts); - console.log('Number of records in recordobts: ', obts); + //console.log('obts: ', obts); + console.log('Number of records in recordobts: ', obts.rows.length); for (request in obts.rows) { if (obts.rows[request].payer_fio_addr == user3.address) { console.log('payer_fio_addr: ', obts.rows[request].payer_fio_addr); @@ -956,4 +999,87 @@ describe.skip(`Go through recordobts (old table) and confirm each entry is in fi }) +}) + +describe.skip(`Go through fioreqctxts (old table) and confirm each entry is in fiotrxts (NEW table)`, () => { + let reqCount = 0 + let reqs; + + it('Step through recordobts and confirm every entry is found on the new table.', async () => { + let count = 0; + + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fioreqctxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + reqs = await callFioApi("get_table_rows", json); + reqCount = reqs.rows.length; + //console.log('reqs: ', reqs); + console.log('Number of records in fioreqctxts: ', reqCount); + for (req in reqs.rows) { + /* obtRecord = { + id: reqCount.rows[obt].id, + payer_fio_addr: reqCount.rows[req].payer_fio_addr, + payee_fio_addr: reqCount.rows[req].payee_fio_addr, + payer_key: reqCount.rows[req].payer_key, + payee_key: reqCount.rows[req].payee_key, + time_stamp: reqCount.rows[req].time_stamp + } + obtRecords.push(obtRecord); + */ + + // Call get_table_rows from fiotrxts (NEW table) and confirm request is in table + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + newRequests = await callFioApi("get_table_rows", json); + //console.log('requests: ', newRequests); + for (newRequest in newRequests.rows) { + if (newRequests.rows[newRequest].fio_request_id == reqs.rows[req].fio_request_id) { + console.log(count); + console.log('fioreqctxts:') + console.log('fio_request_id: ', reqs.rows[req].fio_request_id); + console.log('payer_fio_addr: ', reqs.rows[req].payer_fio_addr); + console.log('payee_fio_addr: ', reqs.rows[req].payee_fio_addr); + console.log('fiotrxts:') + console.log('id: ', newRequests.rows[newRequest].id); + console.log('fio_request_id: ', newRequests.rows[newRequest].fio_request_id); + console.log('payer_fio_addr: ', newRequests.rows[newRequest].payer_fio_addr); + console.log('payee_fio_addr: ', newRequests.rows[newRequest].payee_fio_addr); + + expect(reqs.rows[req].payer_fio_addr).to.equal(newRequests.rows[newRequest].payer_fio_addr); + expect(reqs.rows[req].payee_fio_addr).to.equal(newRequests.rows[newRequest].payee_fio_addr); + expect(reqs.rows[req].payer_key).to.equal(newRequests.rows[newRequest].payer_key); + expect(reqs.rows[req].payee_key).to.equal(newRequests.rows[newRequest].payee_key); + //expect(reqs.rows[req].time_stamp).to.equal(newRequests.rows[newRequest].init_time); //Time stamps different? + expect(reqs.rows[req].fio_request_id).to.equal(newRequests.rows[newRequest].fio_request_id); + // expect(newRequests.rows[newRequest].fio_data_type).to.equal(4); + break; + } + } + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + count++; + } + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + }) \ No newline at end of file diff --git a/utils.js b/utils.js index 1537d88b..6e9b1a2c 100755 --- a/utils.js +++ b/utils.js @@ -56,13 +56,14 @@ function generateFioDomain(size) { } function generateFioAddress(customDomain = config.DEFAULT_DOMAIN, size) { + let fioname; try { if (size + customDomain.length < config.paramMax.fio_address) { - name = randStr(size) + fioname = randStr(size) } else { - name = randStr(config.paramMax.fio_address - customDomain.length - 1) + fioname = randStr(config.paramMax.fio_address - customDomain.length - 1) } - return name + '@' + customDomain + return fioname + '@' + customDomain } catch (err) { console.log('Error: ', err) } From 721752795d542e1eaed6016663f30d19c8426f65 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Tue, 15 Dec 2020 14:18:06 -0700 Subject: [PATCH 12/76] Minor fixes --- tests/burn-address.js | 2 +- tests/fio-request.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/burn-address.js b/tests/burn-address.js index 4805c9a8..cb312e0c 100644 --- a/tests/burn-address.js +++ b/tests/burn-address.js @@ -163,7 +163,7 @@ describe('************************** burn-address.js ************************** } fionames = await callFioApi("get_table_rows", json); //console.log('fionames: ', fionames); - for (name in fionames.rows) { + for (fioname in fionames.rows) { if (fionames.rows[fioname].name == walletA1.address) { //console.log('bundleCount: ', fionames.rows[fioname].bundleeligiblecountdown); bundleCount = fionames.rows[fioname].bundleeligiblecountdown; diff --git a/tests/fio-request.js b/tests/fio-request.js index 59c41577..d15957dd 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -860,7 +860,7 @@ describe(`C. cancel_funds_request with bundles remaining`, () => { } }) - it(`Verify request was cancelled: get_pending_fio_requests for userA2 returns: ${config.error.noPendingRequests}`, async () => { + it(`Verify request was cancelled: get_pending_fio_requests for userA2 returns: ${config.error.noFioRequests}`, async () => { try { const result = await userA2.sdk.genericAction('getPendingFioRequests', { limit: '', @@ -870,7 +870,7 @@ describe(`C. cancel_funds_request with bundles remaining`, () => { expect(result).to.equal(null); } catch (err) { //console.log('Error: ', err.json); - expect(err.json.message).to.equal(config.error.noPendingRequests); + expect(err.json.message).to.equal(config.error.noFioRequests); } }) @@ -1134,7 +1134,7 @@ describe('D. cancel_funds_request with NO bundles remaining', () => { } }) - it(`Verify request was cancelled: get_pending_fio_requests for userB2 returns: ${config.error.noPendingRequests}`, async () => { + it(`Verify request was cancelled: get_pending_fio_requests for userB2 returns: ${config.error.noFioRequests}`, async () => { try { const result = await userB2.sdk.genericAction('getPendingFioRequests', { limit: '', @@ -1144,7 +1144,7 @@ describe('D. cancel_funds_request with NO bundles remaining', () => { expect(result).to.equal(null); } catch (err) { //console.log('Error: ', err.json); - expect(err.json.message).to.equal(config.error.noPendingRequests); + expect(err.json.message).to.equal(config.error.noFioRequests); } }) From 1be020b8602a73fcaf6b0b046e633f94ee28920b Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Wed, 16 Dec 2020 12:27:55 -0700 Subject: [PATCH 13/76] Add tests to check data migration --- index.js | 2 +- tests/bravo-migr-test.js | 75 ++++++++++++++++++++++++---------------- 2 files changed, 46 insertions(+), 31 deletions(-) diff --git a/index.js b/index.js index c837c28d..e54d0881 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ const {expect} = require('chai') describe('TEST SUITE', () => { - require('./tests/bravo-migr-test.js'); + //require('./tests/bravo-migr-test.js'); //require('./tests/history.js'); // Only run against history node. require('./tests/addaddress.js'); // v1.0.x Also includes FIP-13 tests. diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index 2a1fc984..4b739496 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -751,7 +751,7 @@ describe.skip(`Migrate remaining requests and OBTs`, () => { } }) - it(`Call migrtrx (bp1) with amount = 5 until migrledgers isFinished = 1`, async () => { + it(`Call migrtrx (bp1) with amount = 3 until migrledgers isFinished = 1`, async () => { while (!isFinished) { try { const result = await callFioApiSigned('push_transaction', { @@ -760,7 +760,7 @@ describe.skip(`Migrate remaining requests and OBTs`, () => { actor: bp1.account, privKey: bp1.privateKey, data: { - amount: 5, + amount: 3, actor: bp1.account } }) @@ -812,7 +812,7 @@ describe.skip(`Migrate remaining requests and OBTs`, () => { }) -describe.skip(`Go through recordobts (old table) and confirm each entry is in fiotrxts (NEW table)`, () => { +describe(`Go through recordobts (old table) and confirm each entry is in fiotrxts (NEW table)`, () => { let obtCount = 0 let obtRecords; @@ -859,17 +859,6 @@ describe.skip(`Go through recordobts (old table) and confirm each entry is in fi //console.log('obts: ', obts); console.log('Number of records in recordobts: ', obtCount); for (obt in obts.rows) { - /* obtRecord = { - id: obts.rows[obt].id, - payer_fio_addr: obts.rows[obt].payer_fio_addr, - payee_fio_addr: obts.rows[obt].payee_fio_addr, - payer_key: obts.rows[obt].payer_key, - payee_key: obts.rows[obt].payee_key, - time_stamp: obts.rows[obt].time_stamp - } - obtRecords.push(obtRecord); - */ - // Call get_table_rows from fiotrxts (NEW table) and confirm request is in table try { const json = { @@ -892,7 +881,7 @@ describe.skip(`Go through recordobts (old table) and confirm each entry is in fi console.log('payee_fio_addr: ', obts.rows[obt].payee_fio_addr); console.log('fiotrxts:') console.log('id: ', newRequests.rows[newRequest].id); - onsole.log('fio_request_id: ', newRequests.rows[newRequest].fio_request_id); + console.log('fio_request_id: ', newRequests.rows[newRequest].fio_request_id); console.log('payer_fio_addr: ', newRequests.rows[newRequest].payer_fio_addr); console.log('payee_fio_addr: ', newRequests.rows[newRequest].payee_fio_addr); @@ -901,8 +890,8 @@ describe.skip(`Go through recordobts (old table) and confirm each entry is in fi expect(obts.rows[obt].payer_key).to.equal(newRequests.rows[newRequest].payer_key); expect(obts.rows[obt].payee_key).to.equal(newRequests.rows[newRequest].payee_key); //expect(obts.rows[obt].time_stamp).to.equal(newRequests.rows[newRequest].init_time); //Time stamps different? - expect(newRequests.rows[newRequest].fio_request_id).to.equal(0); - expect(newRequests.rows[newRequest].fio_data_type).to.equal(4); + //expect(newRequests.rows[newRequest].fio_request_id).to.equal(0); + //expect(newRequests.rows[newRequest].fio_data_type).to.equal(4); break; } } @@ -1001,12 +990,13 @@ describe.skip(`Go through recordobts (old table) and confirm each entry is in fi }) -describe.skip(`Go through fioreqctxts (old table) and confirm each entry is in fiotrxts (NEW table)`, () => { +describe(`Go through fioreqctxts (old table) and confirm each entry is in fiotrxts (NEW table)`, () => { let reqCount = 0 let reqs; - it('Step through recordobts and confirm every entry is found on the new table.', async () => { + it('Step through fioreqctxts and confirm every entry is found on the new table.', async () => { let count = 0; + let currentReqStatus; try { const json = { @@ -1023,18 +1013,40 @@ describe.skip(`Go through fioreqctxts (old table) and confirm each entry is in f //console.log('reqs: ', reqs); console.log('Number of records in fioreqctxts: ', reqCount); for (req in reqs.rows) { - /* obtRecord = { - id: reqCount.rows[obt].id, - payer_fio_addr: reqCount.rows[req].payer_fio_addr, - payee_fio_addr: reqCount.rows[req].payee_fio_addr, - payer_key: reqCount.rows[req].payer_key, - payee_key: reqCount.rows[req].payee_key, - time_stamp: reqCount.rows[req].time_stamp + // First, get the status of the request + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fioreqstss', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + fioReqSts = await callFioApi("get_table_rows", json); + //console.log('fioReqSts: ', fioReqSts); + currentReqStatus = 0; //Initialize to 0 since that will be the status in the new table if the record's fio_request_id is not found in fioreqstss + for (fioReqStatus in fioReqSts.rows) { + //console.log('reqs.rows[req].fio_request_id', reqs.rows[req].fio_request_id) + //console.log('fioReqStatus: ', fioReqSts.rows[fioReqStatus]); + //console.log ('currentReqStatus', fioReqSts.rows[fioReqStatus].status); + if (fioReqSts.rows[fioReqStatus].fio_request_id == reqs.rows[req].fio_request_id) { + currentReqStatus = fioReqSts.rows[fioReqStatus].status; + //console.log('id: ', fioReqSts.rows[fioReqStatus].id); + //console.log('fio_request_id: ', fioReqSts.rows[fioReqStatus].fio_request_id); + //console.log('status: ', fioReqSts.rows[fioReqStatus].status); + //console.log('payer_fio_addr: ', fioReqSts.rows[fioReqStatus].time_stamp); + expect(reqs.rows[req].fio_request_id).to.equal(fioReqSts.rows[fioReqStatus].fio_request_id); + break; + } + } + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); } - obtRecords.push(obtRecord); - */ - // Call get_table_rows from fiotrxts (NEW table) and confirm request is in table + // Next, all get_table_rows from fiotrxts (NEW table) and confirm request is in table try { const json = { json: true, // Get the response as json @@ -1054,11 +1066,14 @@ describe.skip(`Go through fioreqctxts (old table) and confirm each entry is in f console.log('fio_request_id: ', reqs.rows[req].fio_request_id); console.log('payer_fio_addr: ', reqs.rows[req].payer_fio_addr); console.log('payee_fio_addr: ', reqs.rows[req].payee_fio_addr); + console.log('fioreqstss:') + console.log('status (0 = not found): ', currentReqStatus); console.log('fiotrxts:') console.log('id: ', newRequests.rows[newRequest].id); console.log('fio_request_id: ', newRequests.rows[newRequest].fio_request_id); console.log('payer_fio_addr: ', newRequests.rows[newRequest].payer_fio_addr); console.log('payee_fio_addr: ', newRequests.rows[newRequest].payee_fio_addr); + console.log('fio_data_type: ', newRequests.rows[newRequest].fio_data_type); expect(reqs.rows[req].payer_fio_addr).to.equal(newRequests.rows[newRequest].payer_fio_addr); expect(reqs.rows[req].payee_fio_addr).to.equal(newRequests.rows[newRequest].payee_fio_addr); @@ -1066,7 +1081,7 @@ describe.skip(`Go through fioreqctxts (old table) and confirm each entry is in f expect(reqs.rows[req].payee_key).to.equal(newRequests.rows[newRequest].payee_key); //expect(reqs.rows[req].time_stamp).to.equal(newRequests.rows[newRequest].init_time); //Time stamps different? expect(reqs.rows[req].fio_request_id).to.equal(newRequests.rows[newRequest].fio_request_id); - // expect(newRequests.rows[newRequest].fio_data_type).to.equal(4); + expect(newRequests.rows[newRequest].fio_data_type).to.equal(currentReqStatus); break; } } From aea977ad4f7d7637efca1641ee161146526911d0 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Wed, 16 Dec 2020 12:38:52 -0700 Subject: [PATCH 14/76] cleanup --- tests/bravo-migr-test.js | 106 --------------------------------------- 1 file changed, 106 deletions(-) diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index 4b739496..638c5512 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -816,31 +816,6 @@ describe(`Go through recordobts (old table) and confirm each entry is in fiotrxt let obtCount = 0 let obtRecords; - describe.skip(`Confirm the number of records in old tables aligns with `, () => { - - - it.skip('Get the number of OBT records in recordobts', async () => { - try { - const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'recordobts', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - obts = await callFioApi("get_table_rows", json); - obtCount = obts.rows.length; - //console.log('obts: ', obts); - console.log('Number of records in recordobts: ', obts.rows.length); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - }) - }) - it('Step through recordobts and confirm every entry is found on the new table.', async () => { let count = 0; @@ -907,87 +882,6 @@ describe(`Go through recordobts (old table) and confirm each entry is in fiotrxt } }) - it.skip('Call get_table_rows from recordobts (old table) and confirm every entry OBT is in table', async () => { - let count = 0; - try { - const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'recordobts', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - obts = await callFioApi("get_table_rows", json); - //console.log('obts: ', obts); - console.log('Number of records in recordobts: ', obts.rows.length); - for (request in obts.rows) { - if (obts.rows[request].payer_fio_addr == user3.address) { - console.log('payer_fio_addr: ', obts.rows[request].payer_fio_addr); - expect(obts.rows[request].payer_fio_addr).to.equal(user3.address); - - // Call get_table_rows from fiotrxts (NEW table) and confirm request is in table - try { - const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'fiotrxts', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - requests = await callFioApi("get_table_rows", json); - console.log('requests: ', requests); - for (request in requests.rows) { - if (requests.rows[request].payer_fio_addr == user3.address) { - console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); - break; - } - } - expect(requests.rows[request].payer_fio_addr).to.equal(user3.address); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - - } - count++; - } - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - }) - - it.skip('Call get_table_rows from fiotrxts (NEW table) and confirm request is in table', async () => { - try { - const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'fiotrxts', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - requests = await callFioApi("get_table_rows", json); - console.log('requests: ', requests); - for (request in requests.rows) { - if (requests.rows[request].payer_fio_addr == user3.address) { - console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); - break; - } - } - expect(requests.rows[request].payer_fio_addr).to.equal(user3.address); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - }) - - }) describe(`Go through fioreqctxts (old table) and confirm each entry is in fiotrxts (NEW table)`, () => { From b4caca80ed0209e1974b934812ac94d948b605e6 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Wed, 16 Dec 2020 13:26:06 -0700 Subject: [PATCH 15/76] Adding timeout waits for devnet testing --- tests/addaddress.js | 2 ++ tests/removeaddress.js | 4 ++++ tests/transfer-domain.js | 4 ++++ tests/transfer-locked-tokens-account-tests.js | 12 ++++++++++++ tests/vote.js | 3 +++ 5 files changed, 25 insertions(+) diff --git a/tests/addaddress.js b/tests/addaddress.js index bee52c52..a5102a11 100644 --- a/tests/addaddress.js +++ b/tests/addaddress.js @@ -603,6 +603,8 @@ describe(`Remap FIO Address`, () => { user1 = await newUser(faucet); }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Remap FIO address to ${newAddress}`, async () => { const result = await user1.sdk.genericAction('addPublicAddresses', { fioAddress: user1.address, diff --git a/tests/removeaddress.js b/tests/removeaddress.js index 10e625cb..3945aa4f 100644 --- a/tests/removeaddress.js +++ b/tests/removeaddress.js @@ -767,6 +767,8 @@ describe(`E-2. Add and remove addresses with NO bundles remaining`, () => { userA2 = await newUser(faucet); }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Add DASH and BCH addresses to userA1`, async () => { try { const result = await userA1.sdk.genericAction('addPublicAddresses', { @@ -869,6 +871,8 @@ describe(`E-2. Add and remove addresses with NO bundles remaining`, () => { } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Use up all of userA1's bundles with 51 record_obt_data transactions`, async () => { for (i = 0; i < 51; i++) { try { diff --git a/tests/transfer-domain.js b/tests/transfer-domain.js index ffa7862e..ad9101f5 100644 --- a/tests/transfer-domain.js +++ b/tests/transfer-domain.js @@ -55,6 +55,8 @@ describe('************************** transfer-domain.js ************************ expect(result.status).to.equal('OK') }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`getFioNames for walletA1 and confirm it owns 2 domains and that one of them is walletA1.domain2`, async () => { try { const result = await walletA1.sdk.genericAction('getFioNames', { @@ -146,6 +148,8 @@ describe('************************** transfer-domain.js ************************ } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it('Confirm proper fee was collected', async () => { expect(feeCollected).to.equal(transfer_fio_domain_fee) }) diff --git a/tests/transfer-locked-tokens-account-tests.js b/tests/transfer-locked-tokens-account-tests.js index 6396e3c1..6f5744ff 100644 --- a/tests/transfer-locked-tokens-account-tests.js +++ b/tests/transfer-locked-tokens-account-tests.js @@ -863,6 +863,8 @@ describe('Request funds, approve and send', () => { } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`getPendingFioRequests`, async () => { await timeout(4000) const result = await fioSdk.genericAction('getPendingFioRequests', {}) @@ -971,6 +973,8 @@ describe('Request funds, cancel funds request', () => { expect(result.fee_collected).to.be.a('number') }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`cancel request`, async () => { try{ const result = await fioSdk2.genericAction('cancelFundsRequest', { @@ -1033,6 +1037,8 @@ describe('Request funds, reject', () => { expect(result.fee_collected).to.be.a('number') }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`getPendingFioRequests`, async () => { await timeout(4000) const result = await fioSdk.genericAction('getPendingFioRequests', {}) @@ -1137,6 +1143,8 @@ describe('Record obt data, check', () => { expect(result.fee_collected).to.be.a('number') }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Payer getObtData`, async () => { await timeout(4000) const result = await fioSdk.genericAction('getObtData', { tokenCode: fioTokenCode }) @@ -1291,6 +1299,8 @@ describe(`Test locked token accounts with proxy voting`, () => { } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it('Transfer additional 500 FIO from faucet to fioSdk', async () => { const result = await fioSdkFaucet.genericAction('transferTokens', { payeeFioPublicKey: publicKey, @@ -1344,6 +1354,8 @@ describe(`Test locked token accounts with proxy voting`, () => { expect(result.status).to.equal('OK') }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Get fioSdk last_vote_weight (should be 200 + 2 fee = 202 less)`, async () => { try { fioSdk.last_vote_weight = await getAccountVoteWeight(account); diff --git a/tests/vote.js b/tests/vote.js index ae49bf03..2d64a4b2 100644 --- a/tests/vote.js +++ b/tests/vote.js @@ -249,6 +249,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) it(`Get initial total_voted_fio`, async () => { total_voted_fio = await getTotalVotedFio(); @@ -2646,6 +2647,8 @@ describe('Fixed in Gemini: H. When a user proxies their vote, the total_voted_fi } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`proxyH1 votes for bp1@dapixdev`, async () => { try { const result = await proxyH1.sdk.genericAction('pushTransaction', { From d90cdcb2acac3544ea0d386dcfc366bf059973f9 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Wed, 16 Dec 2020 13:58:15 -0700 Subject: [PATCH 16/76] Timing fixes for Bahamas --- config.js | 16 ++++++---------- tests/addaddress.js | 2 +- tests/fio-request.js | 4 +++- tests/producer.js | 4 +++- tests/transfer-domain.js | 8 +++++++- tests/vote.js | 22 ++++++++++++++++++++++ 6 files changed, 42 insertions(+), 14 deletions(-) diff --git a/config.js b/config.js index c48b85c7..86b164f6 100644 --- a/config.js +++ b/config.js @@ -1,13 +1,9 @@ -const TESTURL = 'http://localhost:8889' -//const TESTURL = 'http://testnet.fioprotocol.io' -//const TESTURL = 'http://52.183.126.67:8889' //dev1 -//const TESTURL = 'http://dev2.fio.dev:8889' -//const TESTURL = 'http://dev3.fio.dev:8889' -//const TESTURL = 'http://dev3.fio.dev:8080' // 8080 is the history node -//const TESTURL = 'http://dev4.fio.dev:8889' -//const TESTURL = 'https://fio.greymass.com' //Mainnet -//const TESTURL = 'http://devnet-a.az.fio.dev:8888' -//const TESTURL = 'http://52.247.194.34:8889' //Devnet +const TESTURL = 'http://localhost:8889' // Localhost +//const TESTURL = 'http://dev2.fio.dev:8889' // DEV +//const TESTURL = 'http://44.238.153.162:8889' // Devnet +//const TESTURL = 'http://testnet.fioprotocol.io' // Testnet +//const TESTURL = 'https://fio.greymass.com' // Mainnet + const DEVTOOLSDIR = '../fio.devtools' diff --git a/tests/addaddress.js b/tests/addaddress.js index a5102a11..7ec2084a 100644 --- a/tests/addaddress.js +++ b/tests/addaddress.js @@ -43,7 +43,7 @@ describe(`************************** addaddress.js ************************** \n } }) - //it(`Wait to avoid timing errors.`, async () => { await timeout(1000) }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) it('getPublicAddress for DASH', async () => { try { diff --git a/tests/fio-request.js b/tests/fio-request.js index d15957dd..0460d5ac 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -125,6 +125,8 @@ describe(`************************** fio-request.js ************************** \ expect(result).to.have.all.keys('transaction_id', 'block_num', 'status', 'fee_collected') }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`userA2 does recordObtData previous payment with the fioRequestId`, async () => { try { const result = await userA2.sdk.genericAction('recordObtData', { @@ -345,7 +347,7 @@ describe(`B. Test FIO Request error conditions`, () => { hash: '', offLineUrl: '' }) - console.log('Result: ', result); + //console.log('Result: ', result); expect(result).to.equal(null); } catch (err) { //console.log('Error', err); diff --git a/tests/producer.js b/tests/producer.js index f2efeb55..26c2dbfa 100644 --- a/tests/producer.js +++ b/tests/producer.js @@ -1,6 +1,6 @@ require('mocha') const {expect} = require('chai') -const {newUser, generateFioAddress, fetchJson} = require('../utils.js'); +const {newUser, generateFioAddress, timeout, fetchJson} = require('../utils.js'); const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); @@ -65,6 +65,8 @@ describe('************************** producer.js ************************** \n A } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`userA1 votes for prodA1 using address #1`, async () => { try { const result = await userA1.sdk.genericAction('pushTransaction', { diff --git a/tests/transfer-domain.js b/tests/transfer-domain.js index ad9101f5..b415f64f 100644 --- a/tests/transfer-domain.js +++ b/tests/transfer-domain.js @@ -1,6 +1,6 @@ require('mocha') const {expect} = require('chai') -const {newUser, generateFioAddress, generateFioDomain, createKeypair, callFioApi, getFees, fetchJson} = require('../utils.js'); +const {newUser, generateFioAddress, generateFioDomain, createKeypair, callFioApi, getFees, timeout, fetchJson} = require('../utils.js'); const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); @@ -399,6 +399,8 @@ describe('B. Transfer a domain to FIO Public Key which does not map to existing } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it('Confirm proper fee was collected', async () => { expect(feeCollected).to.equal(transfer_fio_domain_fee) }) @@ -725,6 +727,8 @@ describe('D. transferFioDomain Error testing', () => { } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Use up all of userD3's bundles with 51 record_obt_data transactions`, async () => { for (i = 0; i < 51; i++) { try { @@ -783,6 +787,8 @@ describe('D. transferFioDomain Error testing', () => { } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Verify balance for userD3 = 0`, async () => { try { const result = await userD3.sdk.genericAction('getFioBalance', { diff --git a/tests/vote.js b/tests/vote.js index 2d64a4b2..858009a5 100644 --- a/tests/vote.js +++ b/tests/vote.js @@ -30,6 +30,8 @@ describe(`************************** vote.js ************************** \n A. Te proxyA1 = await newUser(faucet); }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Get initial total_voted_fio`, async () => { total_voted_fio = await getTotalVotedFio(); //console.log('total_voted_fio:', total_voted_fio) @@ -74,6 +76,8 @@ describe(`************************** vote.js ************************** \n A. Te } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Get total_voted_fio before proxyA1 votes`, async () => { total_voted_fio = await getTotalVotedFio(); //console.log('total_voted_fio:', total_voted_fio) @@ -101,6 +105,8 @@ describe(`************************** vote.js ************************** \n A. Te } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Get proxyA1 last_vote_weight`, async () => { try { proxyA1.last_vote_weight = await getAccountVoteWeight(proxyA1.account); @@ -307,6 +313,8 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`voterB1 proxy votes to proxyB1`, async () => { try { const result = await voterB1.sdk.genericAction('pushTransaction', { @@ -1360,6 +1368,8 @@ describe('G. Test multiple users proxying and unproxying votes to same proxy', ( } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Register proxyG1 as a proxy`, async () => { try { const result = await proxyG1.sdk.genericAction('pushTransaction', { @@ -1378,6 +1388,8 @@ describe('G. Test multiple users proxying and unproxying votes to same proxy', ( } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Get proxyG1 last_vote_weight`, async () => { try { proxyG1.last_vote_weight = await getAccountVoteWeight(proxyG1.account); @@ -1417,6 +1429,8 @@ describe('G. Test multiple users proxying and unproxying votes to same proxy', ( } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Fixed in Gemini: Get voterG1 last_vote_weight`, async () => { try { voterG1.last_vote_weight = await getAccountVoteWeight(voterG1.account); @@ -1467,6 +1481,8 @@ describe('G. Test multiple users proxying and unproxying votes to same proxy', ( } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Get voterG2 last_vote_weight`, async () => { try { voterG2.last_vote_weight = await getAccountVoteWeight(voterG2.account); @@ -1517,6 +1533,8 @@ describe('G. Test multiple users proxying and unproxying votes to same proxy', ( } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Get voterG3 last_vote_weight`, async () => { try { voterG3.last_vote_weight = await getAccountVoteWeight(voterG3.account); @@ -1569,6 +1587,8 @@ describe('G. Test multiple users proxying and unproxying votes to same proxy', ( } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Fixed in Gemini: bp1@dapixdev does not change`, async () => { try { prev_total_bp_votes = total_bp_votes; @@ -2751,6 +2771,8 @@ describe('v1.2.0 release only. H. Confirm voter data is returned with get_accoun voterH1 = await newUser(faucet); }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Get account info for voterH1`, async () => { try { const json = { From 9f4be1f22ad3b40c2b53e2aadc140a99af9e7a50 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 21 Dec 2020 17:16:58 -0700 Subject: [PATCH 17/76] Lock tests for de-boinking --- tests/lock-test.js | 1014 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1014 insertions(+) create mode 100644 tests/lock-test.js diff --git a/tests/lock-test.js b/tests/lock-test.js new file mode 100644 index 00000000..9f3fc012 --- /dev/null +++ b/tests/lock-test.js @@ -0,0 +1,1014 @@ +require('mocha') +const {expect} = require('chai') +const {newUser, existingUser, fetchJson, callFioApi, createKeypair} = require('../utils.js'); +const {FIOSDK } = require('@fioprotocol/FIOSDK') +config = require('../config.js'); +const fs = require('fs'); + +let vestingSchedule = [ + { + "day": 0, + "unlockPercent": 0 + }, + { + "day": 2, + "unlockPercent": 0.06 + }, + { + "day": 7, + "unlockPercent": 0.248 + }, + { + "day": 12, + "unlockPercent": 0.436 + }, + { + "day": 17, + "unlockPercent": 0.624 + }, + { + "day": 22, + "unlockPercent": 0.812 + }, + { + "day": 27, + "unlockPercent": 1 + } +] + +let accounts = [ + { + "publicKey": "FIO5veJy6yh1wLK5D7shUH5vEzDWM2RuA6QUZHRu9kGxRwY3uB9UJ", + "privateKey": "5Jqhqfn4A7XYPWfFVciWiC9cReinov6JkivgKEU33GVk2PhLBHt", + "account": "cqanc3nofcdx", + "grantAmount": 536685000000000, + "locktype": 1 + }, + { + "publicKey": "FIO74aFubSg2oDoCT65QVsMbhmu9Hstn4iu4kVcE31QzEim8RG6G5", + "privateKey": "5Kez2B4zxudcHMocKM1Xvgivj7oqMe7KQyPV8RH11mdiKQcaJBY", + "account": "yesnhk5owtrf", + "grantAmount": 577608000000000, + "locktype": 1 + }, + { + "publicKey": "FIO5BpDqC2MLyuVqJ3rkqXkDa16dRGrsKt7ebyxukBddykLrCocgw", + "privateKey": "5HzFbcGwseYZgJvViPmLHyPFcVBZmpTVMCaKxuHcAkGV7FMAEu2", + "account": "bqtvtxeprr32", + "grantAmount": 1175718000000000, + "locktype": 1 + }, + { + "publicKey": "FIO4x8rkZM9p8UxDHDV95fepG65EaB5XDgnH4hYNE53tZpJGfFUZJ", + "privateKey": "5K7AKKx7zUPwCh4oLUFayhFnJmSSc7xqyYNwQY5tYEFdX1VNszx", + "account": "cbqslo5dgogg", + "grantAmount": 1723128000000000, + "locktype": 1 + }, + { + "publicKey": "FIO6n7BMKtBfmjFHxGdAL624wW6cXVpXNHzkX9ESmMPHQ35wx1Hpr", + "privateKey": "5HuQAEH96jSWiaTP8cLidQ8TTr7eLZhpi7vy9P7Y5RsdUpaSh6o", + "account": "saxvgku1zse4", + "grantAmount": 1814779000000000, + "locktype": 1 + }, + { + "publicKey": "FIO5UgYYyxm1KnaHEom3y9jCUzT51m8zNUJX58u5wVEz1Qu4z6TyT", + "privateKey": "5Kdbon9aCpBnwu9Pq9nYRTwU8pMfvNqdUW3LuRxvcfnSbG1Agax", + "account": "h3b14o2voayh", + "grantAmount": 1980746000000000, + "locktype": 1 + }, + { + "publicKey": "FIO81WpMRHc8zMghqcgB1ouq3CBvY9o31kWMADqiStQmTUWrvv1bo", + "privateKey": "5KRiLMWcDB2gEPxTf5Vv571r1o5VJR8BvPir7iW2AqHMx98yFRw", + "account": "vet5z1rc12mr", + "grantAmount": 2146740000000000, + "locktype": 1 + }, + { + "publicKey": "FIO76kXqwTZhA8Wht9nkhiXUaG7TePtJitPFYdWVgjEMJ7HEHn3CU", + "privateKey": "5JcLodsYUJ8fBXdh4ERYK3yfNufgRdw2YisLn9bqNbaMnNYwmgx", + "account": "3vb1sno12gda", + "grantAmount": 2351464000000000, + "locktype": 1 + }, + { + "publicKey": "FIO5vK1k4yNiyqvD3AkpkTpbQmVf9i3oMTqdRv6dCPzsCQvjwS75W", + "privateKey": "5KAnqhp83TS1CVHaeAo9Er85z3sDBk6io3ws7JE16nxZhcMMiNZ", + "account": "bp1tvoakumxt", + "grantAmount": 2795767000000000, + "locktype": 1 + }, + { + "publicKey": "FIO6nkPQuPxXkLD8N911A6PaXBSopD6PRTVUqmiDv7PBRAY7WA4pQ", + "privateKey": "5KSR31TqVHH65AQaDUSKQbZYbN2JTAnhTc4m8hkkPwyc4JzJSvR", + "account": "uv4p4g4ha1wl", + "grantAmount": 3091301000000000, + "locktype": 1 + }, + { + "publicKey": "FIO8HtqBWvQXqfMW2efijXmXn87x8o3r8o6CLns1o8AvZBRD98yNY", + "privateKey": "5KLkwB6NNWdEnCabmpnDbNnZt3s5zmo5zLN96PHoHxgAJvQ2NbT", + "account": "vmyb3gahhubo", + "grantAmount": 3629584000000000, + "locktype": 1 + }, + { + "publicKey": "FIO6CDzRDqzTXMYXe4mJrft2qAxVFg6MuxxZkBFcfpk9eqsZoztN8", + "privateKey": "5J7zWhwRWV9k9rNau2pddBLVv1ZxLKwUZxDGkXvagh7s8pHhg4b", + "account": "fr2r4a4qzrqy", + "grantAmount": 4293480000000000, + "locktype": 1 + }, + { + "publicKey": "FIO8Gct26EEe3WqNRBb8bAEgQhntwUDhCQVeUJzUrnWj5Pem7NcnE", + "privateKey": "5HrCEMvhgzSSuFNzYTtpydUKV1Z4euSz78akETqexXMaxzXKBRM", + "account": "xqidej5bnrqm", + "grantAmount": 4702954000000000, + "locktype": 1 + }, + { + "publicKey": "FIO7dtpd8h7jQLMq3kUo2ztLSRfh3ME1zcH8BFspcb4QCTpY2gmSP", + "privateKey": "5HpgkAuHBujMk9AJCXusCL9vCkGttNxTat3VKKmSuV3nVvWp3MS", + "account": "dmwtpkaggrvo", + "grantAmount": 5366877000000000, + "locktype": 1 + }, + { + "publicKey": "FIO8WmR71weVxrJuRfZ4AH5Ur1jjRu9jXmYWWbmYtwzd22gPe9TFU", + "privateKey": "5KFvXueMN6sEfjqYLX5ZqLoarNBaDGACqvMSFcRxDsBxQtEDXwz", + "account": "xp3puwvgmey1", + "grantAmount": 6598658000000000, + "locktype": 1 + }, + { + "publicKey": "FIO5pc2gpT489dDQzr81Mzh18FK4zpasXTpYXVotAp2ZU8Q7QeHex", + "privateKey": "5KNUnXZsNTni41DUX2cqM24pHkEzgsaZGNMim4z7p2fh1Fdndds", + "account": "uzyl2wpdnrcv", + "grantAmount": 8408345000000000, + "locktype": 1 + }, + { + "publicKey": "FIO7EDh5TBG9q26wcSkgKXAhAEqBPepeCW7ebtHPFxHeFW5ZL4zHX", + "privateKey": "5KLXAcoDuykmjZJVVie1YJseEWt39TRAKxod9nvV4BvB8KnaXYB", + "account": "ol5nbgugas33", + "grantAmount": 21259562000000000, + "locktype": 1 + }, + { + "publicKey": "FIO6UKW8S2pzqkVjYtkD65vFFoadCbjL88AGYPY6Y59pofetxCQv2", + "privateKey": "5KaM3fBd2WMinrcE1hBf8U8Tqn9NhmSYXzRKnwQSVtkbS2Y8yR7", + "account": "k2tciid4ejvw", + "grantAmount": 48301893000000000, + "locktype": 1 + }, + { + "publicKey": "FIO56G6NsgUtqHDtCUHaz5gEEp33rRt7DvFPVHgNGEURhPDDRzyrL", + "privateKey": "5JTtxYTdQC7qQXkfKpbUXyfCBvjhjSMhEygqhuEckrxwMaU5HEk", + "account": "uupfzmhrvxlq", + "grantAmount": 29253936000000000, + "locktype": 1 + }, + { + "publicKey": "FIO78haXL6TsvuV3rZS6FVyRQR17DHsedDZ4UupVSB1NdN8msHsRp", + "privateKey": "5KYEJau8mbQHj3L47b85dHDYB8t88xKuBMbEZPDCsP8RtFT9Qpm", + "account": "bcpxf42u25bi", + "grantAmount": 41437168000000000, + "locktype": 1 + }, + { + "publicKey": "FIO65xT3DL58T3B8KXAhZV3m4ZoprzaE3voxXGz6NgAE8LozdykJ1", + "privateKey": "5JAPyYMdoX4KnZKH5v5UJTLK3Yvt8ohWYzFrammrMtfb8agZQ8E", + "account": "xvob2mynuvqe", + "grantAmount": 10000000000, + "locktype": 1 + }, + { + "publicKey": "FIO58uH7WZ6h8nHVguSNzig7zkScXMqmHKM673Q6dswBM2dSWfNR5", + "privateKey": "5K4N7mGQmcyQZaL99w6QB5yis9qaGJX7wFb7oNkVDRBr5z3r2kz", + "account": "tkugu1cemtig", + "grantAmount": 10000000000, + "locktype": 1 + }, + { + "publicKey": "FIO7KPMLvtikVEW8PgBGdY9awwgoksd1Q7ec1prVbdKEcm3pffXvc", + "privateKey": "5Hti1S3wCTrC8s3ZG4bmQ7uCfDjFLP2sxfu84p25Hf85aJSQBZT", + "account": "zgvefkddrf32", + "grantAmount": 400000000000000, + "locktype": 1 + }, + { + "publicKey": "FIO76UaDh974EcGvgnX5N44kJSxRUGy2mAKh7mGSc8chM7YHBxW5x", + "privateKey": "5JJtiCe3yYbXxCndC1p9yWEhQNC4wmnXN4E9Uv1nstB9d6nfJkL", + "account": "2vjybmeufvld", + "grantAmount": 406251000000000, + "locktype": 1 + }, + { + "publicKey": "FIO62DtJ6j4pL34hVD6uF3PFVJtptma36ACtrvz1tts8ohHs1qw2g", + "privateKey": "5JR5bf83QDeBeGr1d8SQ46rDHe4r7AyjsUTvchCsCfV58D6vtML", + "account": "p1cljdxvagp4", + "grantAmount": 541668000000000, + "locktype": 1 + }, + { + "publicKey": "FIO6nRGP9eQ1xHWwQUEp6yKXrvDwM6LGdf5ZzpFG8esViM1qgWjSp", + "privateKey": "5K4tMwvfH2r9r2vyoUocKrxJcnUbzUzEGuA9rT385ErK412wpKF", + "account": "tv2ksbwccwha", + "grantAmount": 800000000000000, + "locktype": 1 + }, + { + "publicKey": "FIO7VSYQNjpy32ab4rtxsdgsgxYEgqBWRqSPTqwkeeFSopXGQMRob", + "privateKey": "5KEAUQBvM4TkRsc7uQcWdw4EEKdvzCzQbUAbmo1BqRFZTS5FaJy", + "account": "q1zpd4ev5i4b", + "grantAmount": 1300000000000000, + "locktype": 2 + }, + { + "publicKey": "FIO8QgNswVWt8X2zX3g63rf3H5mUj8YWTRvFZLTRT4GFk59AeBaYM", + "privateKey": "5K4tDSnTPWyf6GzGbrQ3tTJXzGhczdV5MASGLGL9bpMmnwua1so", + "account": "j3rzza4aw3wr", + "grantAmount": 1500000000000000, + "locktype": 2 + }, + { + "publicKey": "FIO5uR7PvEcq4LAkKPb3xXkeofrpnyBmMLcEUcgGieaT4AobtnK87", + "privateKey": "5JbXXwaiGo7TzaeXN1Mz6ff61Ahpa5UmdJaEoVeSXGC2jauDcsY", + "account": "5gp4swqeuucf", + "grantAmount": 1800000000000000, + "locktype": 2 + }, + { + "publicKey": "FIO7WTCpFiYpHvXC2rtKYDgQnvM6DaawCcEif7HJS933ycPRAmCCo", + "privateKey": "5K6DvSVesgVsM6RpoDuqVXk4gLDywZksn17iVBSmGvJZYcQteFh", + "account": "tgecf5a44e4s", + "grantAmount": 1895839000000000, + "locktype": 1 + }, + { + "publicKey": "FIO8EQquDpFaJMHVNo8q15KvVLoLDJzACah2tBsPf5fyATXVvoRSi", + "privateKey": "5JpTV2b6sqK5UVS7DH2P2m4fo8rV4BKEPfGC5BRjjhQ2PPLk1zt", + "account": "smxixj5oyjju", + "grantAmount": 2000000000000000, + "locktype": 2 + }, + { + "publicKey": "FIO8CjnHBXAHBWZfwwBEjoz4REq6jYQbQmNNFNWa4TqYdsUvTbk6Q", + "privateKey": "5KHND4PU4v2e4Ab1ParnKfWBVr8E4MdqnJYAYSVQC1EiD9hGRC2", + "account": "oat3nnpab3f1", + "grantAmount": 2500000000000000, + "locktype": 2 + }, + { + "publicKey": "FIO5e6KT7694GkiQjwjZKcWZfJPCE7dJEz6qyfTJgKAW1Gk474rfW", + "privateKey": "5Hv98tkHS3p5zKzz12PuQxQLE9BRvTttBebfBRJnLETgK1gtRKs", + "account": "31jcxmpx1mhg", + "grantAmount": 2708342000000000, + "locktype": 1 + }, + { + "publicKey": "FIO7f2EPa273rNoceTHT4v1YZbYYKeoRCPTFhmEkk7HMd866j47AQ", + "privateKey": "5J5XhhKRyfCtFN3Ko2HTKiipLrqpPwiW9hNVijc5gxgjUhetWZZ", + "account": "g2aipjkttu1b", + "grantAmount": 3000000000000000, + "locktype": 2 + }, + { + "publicKey": "FIO8SvUizuMV4Jein8EGcnPKTExUCp3i3PWRt1zjb6iiWLvSzcYpY", + "privateKey": "5JQM2zbZRSnuY979nBVmCBdPBACAyoDuCoJsiA4UYTSkKP5HHbi", + "account": "ovsbcvykaikd", + "grantAmount": 3489969000000000, + "locktype": 1 + }, + { + "publicKey": "FIO6ARVvkBnjkbXQ2ce3vkuE2ba3eB7cZYpeuYjPabqU8YuP3SZqe", + "privateKey": "5JHcertG3iSWctifLxmbYXrQwMfPRoPCfYN9FbLpTGCoLsL2ReE", + "account": "bfcgyugbn2ew", + "grantAmount": 3530594000000000, + "locktype": 1 + }, + { + "publicKey": "FIO8N1CWQ3TvnPSdVvWtCQF2kUs196Y4bfQpJELChfZC2nrd79WJM", + "privateKey": "5KXgZePGQL3TxDqXdsJzB5niUWn4pe7EEXRzSH1RGqDReMn2EXg", + "account": "dk1waedxwygx", + "grantAmount": 4000000000000000, + "locktype": 2 + }, + { + "publicKey": "FIO5KRHsUAfdbVpkso4zkKM9Y33ek9t8aWDsLMN24ni2L9Zg13JJ5", + "privateKey": "5J1NbScMjJXUT1prVFXNR6KyVUfk5BVJtGe53SfR2mMAP9ooaU3", + "account": "svaozrovyc4j", + "grantAmount": 5500000000000000, + "locktype": 2 + }, + { + "publicKey": "FIO5ZWv8p5nWCgg1yjc8KWbxjCcAKPwyeQDozktLe2SEZqXZA2xWH", + "privateKey": "5JFJMdtYndMvZPEqpnFhyAN627gXqKUmGzyD2TEamAGUxXmeuEB", + "account": "sxjice4lkgm2", + "grantAmount": 5965123000000000, + "locktype": 1 + }, + { + "publicKey": "FIO7gjxhVwCbbUHFwRWGo9zsZf3X36CavzmyALLKmbwys4U89ZzZm", + "privateKey": "5KbHGztNYkqP3RdjVNdDU3oiFYRsybjNzQhaJHY5Sn7AuX1Jbd2", + "account": "kd51qpa3pjbb", + "grantAmount": 7000000000000000, + "locktype": 2 + }, + { + "publicKey": "FIO4x3AEWTDcBpstzfqeYWdeRNdfwQgnvYfoJxW9s7re9Mz1DbGg1", + "privateKey": "5KXoeipWkZo15LE1rNHSRhAQ5nvGZZW5jd9S1uzd5XEoPnzucpq", + "account": "ciucfl1mgvuh", + "grantAmount": 7007834000000000, + "locktype": 1 + }, + { + "publicKey": "FIO8JWdDvZPkVr33C6Gd5FydeCQFimCyGS3FwA6Lpa2nVjV73AysV", + "privateKey": "5JctDrW3X92Brqkjg7n6FwFYVKX5NNSgt6KoyT84G5vTLymk2ZV", + "account": "12gdxtxo1pqg", + "grantAmount": 8500000000000000, + "locktype": 2 + }, + { + "publicKey": "FIO6AAHrmdewwbjnKY7rjumygYUo6pt1zeRtZdH1Tz9S51V1iupgT", + "privateKey": "5JgnXFMB7z5t6maDy4yHYWezXgs4BQPU6dz9W2hD7yTRBHZearF", + "account": "bbubsvffjcaq", + "grantAmount": 10000000000000000, + "locktype": 1 + }, + { + "publicKey": "FIO4zWjmRh6uTAtyJTgd9P4dLv6ywQSzfaCBv3iDmZ6Rq6Nbm1z9M", + "privateKey": "5KSoT9BL53TPFGabwauTMgforM5Z9U6ujGG8VGVCMCSfGT3zvk6", + "account": "hhhsqgxaditg", + "grantAmount": 21678096000000000, + "locktype": 1 + }, + { + "publicKey": "FIO5K5d7YJ9smEUvUTvuK5mDuJxKD81UbzXdKuUb9Zfe1g11G2hR2", + "privateKey": "5KT8p9kSXAs9v5k3GZdbk8o7pKeFPTxZS4bTw7KAc4cfLYvEKYG", + "account": "rqctshld5xuq", + "grantAmount": 222437168000000000, + "locktype": 1 + } +] + +let grants = [ + { + "amount": 536685000000000, + "locktype": 1 + }, + { + "amount": 577608000000000, + "locktype": 1 + }, + { + "amount": 1175718000000000, + "locktype": 1 + }, + { + "amount": 1723128000000000, + "locktype": 1 + }, + { + "amount": 1814779000000000, + "locktype": 1 + }, + { + "amount": 1980746000000000, + "locktype": 1 + }, + { + "amount": 2146740000000000, + "locktype": 1 + }, + { + "amount": 2351464000000000, + "locktype": 1 + }, + { + "amount": 2795767000000000, + "locktype": 1 + }, + { + "amount": 3091301000000000, + "locktype": 1 + }, + { + "amount": 3629584000000000, + "locktype": 1 + }, + { + "amount": 4293480000000000, + "locktype": 1 + }, + { + "amount": 4702954000000000, + "locktype": 1 + }, + { + "amount": 5366877000000000, + "locktype": 1 + }, + { + "amount": 6598658000000000, + "locktype": 1 + }, + { + "amount": 8408345000000000, + "locktype": 1 + }, + { + "amount": 21259562000000000, + "locktype": 1 + }, + { + "amount": 48301893000000000, + "locktype": 1 + }, + { + "amount": 29253936000000000, + "locktype": 1 + }, + { + "amount": 41437168000000000, + "locktype": 1 + }, + { + "amount": 10000000000, + "locktype": 1 + }, + { + "amount": 10000000000, + "locktype": 1 + }, + { + "amount": 400000000000000, + "locktype": 1 + }, + { + "amount": 406251000000000, + "locktype": 1 + }, + { + "amount": 541668000000000, + "locktype": 1 + }, + { + "amount": 800000000000000, + "locktype": 1 + }, + { + "amount": 1300000000000000, + "locktype": 2 + }, + { + "amount": 1500000000000000, + "locktype": 2 + }, + { + "amount": 1800000000000000, + "locktype": 2 + }, + { + "amount": 1895839000000000, + "locktype": 1 + }, + { + "amount": 2000000000000000, + "locktype": 2 + }, + { + "amount": 2500000000000000, + "locktype": 2 + }, + { + "amount": 2708342000000000, + "locktype": 1 + }, + { + "amount": 3000000000000000, + "locktype": 2 + }, + { + "amount": 3489969000000000, + "locktype": 1 + }, + { + "amount": 3530594000000000, + "locktype": 1 + }, + { + "amount": 4000000000000000, + "locktype": 2 + }, + { + "amount": 5500000000000000, + "locktype": 2 + }, + { + "amount": 5965123000000000, + "locktype": 1 + }, + { + "amount": 7000000000000000, + "locktype": 2 + }, + { + "amount": 7007834000000000, + "locktype": 1 + }, + { + "amount": 8500000000000000, + "locktype": 2 + }, + { + "amount": 10000000000000000, + "locktype": 1 + }, + { + "amount": 21678096000000000, + "locktype": 1 + }, + { + "amount": 222437168000000000, + "locktype": 1 + } +] + +before(async () => { + faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); +}) + +describe.skip(`************************** lock-test.js ************************** \n A. File and devtools output. Only run once.`, () => { + var keys = [] + + it(`Create accounts`, async () => { + for (i = 0; i < grants.length; i++) { + keys[i] = await createKeypair(); + } + + for (i = 0; i < keys.length; i++) { + console.log('# Create locked token account') + console.log(`#Public key: '${keys[i].publicKey}'`) + console.log(`#Private key: '${keys[i].privateKey}'`) + console.log(`#FIO Public Address (actor name): '${keys[i].account}'`) + console.log(`./clio -u http://localhost:8889 create account eosio ${keys[i].account} ${keys[i].publicKey} ${keys[i].publicKey} \n`) + } + + for (i = 0; i < keys.length; i++) { + console.log(`# issue locked token grant to ${keys[i].account} as lock type ${grants[i].locktype} in the amount of ${grants[i].amount}`) + console.log(`./clio -u http://localhost:8889 push action -j eosio addlocked '{"owner":"${keys[i].account}","amount":${grants[i].amount},"locktype":${grants[i].locktype}}' -p eosio@active\n`) + } + + console.log("accounts = ") + for (i = 0; i < keys.length; i++) { + console.log(`{ \n "publicKey": "${keys[i].publicKey}", \n "privateKey": "${keys[i].privateKey}", \n "account": "${keys[i].account}", \n "grantAmount": ${grants[i].amount}, \n "locktype": ${grants[i].locktype} \n },`) + } + + for (i = 0; i < keys.length; i++) { + console.log('# Create locked token account') + console.log(`#Public key: '${keys[i].publicKey}'`) + console.log(`#FIO Public Address (actor name): '${keys[i].account}'`) + console.log(`./clio -u http://localhost:8889 push action -j fio.token trnsfiopubky '{"payee_public_key": "'${keys[i].publicKey}'", "amount": ${grants[i].amount}, "max_fee": "40000000000", "actor": "eosio","tpid":""}' -p eosio@active\n`) + } + }) +}) + +describe.skip(`Fund Accounts`, () => { + let user = [] + it(`Fund accounts`, async () => { + for (i = 0; i < accounts.length; i++) { + try { + user[i] = await existingUser(accounts[i].account, accounts[i].privateKey, accounts[i].publicKey, '', ''); + const result = await faucet.genericAction('transferTokens', { + payeeFioPublicKey: user[i].publicKey, + amount: 20000000000, + maxFee: config.maxFee, + }) + } catch (err) { + console.log('Error', err); + } + } + }) +}) + +describe.skip(`B. Test`, () => { + let user = [], testUser + const currentTime = Date.now()/1000 + + it(`Create accounts`, async () => { + testUser = await newUser(faucet); + + for (i = 0; i < accounts.length; i++) { + try { + user[i] = await existingUser(accounts[i].account, accounts[i].privateKey, accounts[i].publicKey, '', ''); + //console.log("i: ", i); + //console.log("Public key: ", user[i].publicKey) + //console.log("Private key: ", user[i].privateKey) + //console.log("Account: ", user[i].account) + } catch (err) { + console.log('Error', err); + } + } + + console.log("secondsSinceEpoch: ", currentTime) + }) + + it('Show lock amount for user', async () => { + let timestamp + try { + const json = { + json: true, // Get the response as json + code: 'eosio', // Contract that we target + scope: 'eosio', // Account that owns the data + table: 'lockedtokens', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + lockedAccounts = await callFioApi("get_table_rows", json); + //console.log('lockedAccounts: ', lockedAccounts) + for (lockedAccount in lockedAccounts.rows) { + //if (lockedAccounts.rows[lockedAccount].owner == accounts[0].account) { + if (lockedAccounts.rows[lockedAccount].owner == 'hevknweneejq') { + console.log('Count: ', lockedAccount) + console.log('lockedAccounts.rows[lockedAccount].owner: ', lockedAccounts.rows[lockedAccount].owner); + console.log('lockedAccounts.rows[lockedAccount].total_grant_amount: ', lockedAccounts.rows[lockedAccount].total_grant_amount); + console.log('lockedAccounts.rows[lockedAccount].unlocked_period_count: ', lockedAccounts.rows[lockedAccount].unlocked_period_count); + console.log('lockedAccounts.rows[lockedAccount].grant_type: ', lockedAccounts.rows[lockedAccount].grant_type); + console.log('lockedAccounts.rows[lockedAccount].inhibit_unlocking: ', lockedAccounts.rows[lockedAccount].inhibit_unlocking); + console.log('lockedAccounts.rows[lockedAccount].remaining_locked_amount: ', lockedAccounts.rows[lockedAccount].remaining_locked_amount); + console.log('lockedAccounts.rows[lockedAccount].timestamp: ', lockedAccounts.rows[lockedAccount].timestamp); + timestamp = lockedAccounts.rows[lockedAccount].timestamp; + break; + } + } + + let elapsedMin = Math.round((currentTime - timestamp) / 60); + console.log('elapsedMin: ', elapsedMin) + + //expect(result.rows[0].total_staking_incentives_granted).to.equal(totalstaking ) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Get account[0] FIO Balance`, async () => { + try { + const result = await user[21].sdk.genericAction('getFioBalance', { + fioPublicKey: accounts[21].publicKey + }) + console.log('user[0] getFioBalance: ', result.balance) + } catch (err) { + console.log('Error: ', err) + } + }) + + it('50 FIO from faucet to user', async () => { + const result = await faucet.genericAction('transferTokens', { + payeeFioPublicKey: user[21].publicKey, + amount: 50000000000, + maxFee: config.maxFee, + }) + //console.log('Result', result) + expect(result.status).to.equal('OK') + }) + + it(`Trigger lock by voting`, async () => { + console.log("Account: ", user[21].account) + try { + const result = await user[21].sdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + "producers": [ + 'bp1@dapixdev' + ], + fio_address: '', + actor: user[0].account, + max_fee: config.maxFee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json.error) + } + }) + + it('5 FIO from user to faucet to trigger locked account update', async () => { + try { + const result = await user[21].sdk.genericAction('transferTokens', { + payeeFioPublicKey: faucet.publicKey, + amount: 5000000000, + maxFee: config.maxFee, + }) + //console.log('Result', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json.fields) + } + }) + + it(`Get account[0] FIO Balance`, async () => { + try { + const result = await user[21].sdk.genericAction('getFioBalance', { + fioPublicKey: accounts[21].publicKey + }) + console.log('user[0] getFioBalance: ', result.balance) + } catch (err) { + console.log('Error: ', err) + } + }) + +}) + +describe.skip(`B. Test`, () => { + let user = [], testUser + const currentTime = Date.now()/1000 + + it(`Create accounts`, async () => { + testUser = await newUser(faucet); + + for (i = 0; i < accounts.length; i++) { + try { + user[i] = await existingUser(accounts[i].account, accounts[i].privateKey, accounts[i].publicKey, '', ''); + //console.log("i: ", i); + //console.log("Public key: ", user[i].publicKey) + //console.log("Private key: ", user[i].privateKey) + //console.log("Account: ", user[i].account) + } catch (err) { + console.log('Error', err); + } + } + + console.log("secondsSinceEpoch: ", currentTime) + }) + + it('Show lock amount for user', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'eosio', // Contract that we target + scope: 'eosio', // Account that owns the data + table: 'lockedtokens', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + lockedAccounts = await callFioApi("get_table_rows", json); + //console.log('lockedAccounts: ', lockedAccounts) + for (lockedAccount in lockedAccounts.rows) { + if (lockedAccounts.rows[lockedAccount].owner == accounts[0].account) { + console.log('Count: ', lockedAccount) + console.log('lockedAccounts.rows[lockedAccount].owner: ', lockedAccounts.rows[lockedAccount].owner); + console.log('lockedAccounts.rows[lockedAccount].total_grant_amount: ', lockedAccounts.rows[lockedAccount].total_grant_amount); + console.log('lockedAccounts.rows[lockedAccount].unlocked_period_count: ', lockedAccounts.rows[lockedAccount].unlocked_period_count); + console.log('lockedAccounts.rows[lockedAccount].grant_type: ', lockedAccounts.rows[lockedAccount].grant_type); + console.log('lockedAccounts.rows[lockedAccount].inhibit_unlocking: ', lockedAccounts.rows[lockedAccount].inhibit_unlocking); + console.log('lockedAccounts.rows[lockedAccount].remaining_locked_amount: ', lockedAccounts.rows[lockedAccount].remaining_locked_amount); + console.log('lockedAccounts.rows[lockedAccount].timestamp: ', lockedAccounts.rows[lockedAccount].timestamp); + break; + } + } + + + //expect(result.rows[0].total_staking_incentives_granted).to.equal(totalstaking ) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Get account[0] FIO Balance`, async () => { + try { + const result = await user[0].sdk.genericAction('getFioBalance', { + fioPublicKey: accounts[0].publicKey + }) + console.log('user[0] getFioBalance: ', result.balance) + } catch (err) { + console.log('Error: ', err) + } + }) + + it('20 FIO from faucet to user', async () => { + const result = await faucet.genericAction('transferTokens', { + payeeFioPublicKey: user[0].publicKey, + amount: 20000000000, + maxFee: config.maxFee, + }) + //console.log('Result', result) + expect(result.status).to.equal('OK') + }) + + it(`Trigger lock by voting`, async () => { + console.log("Account: ", user[0].account) + try { + const result = await user[0].sdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + "producers": [ + 'bp1@dapixdev' + ], + fio_address: '', + actor: user[0].account, + max_fee: config.maxFee + } + }) + console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json.error) + } + }) + + it('5 FIO from user to faucet to trigger locked account update', async () => { + try { + const result = await user[0].sdk.genericAction('transferTokens', { + payeeFioPublicKey: faucet.publicKey, + amount: 5000000000, + maxFee: config.maxFee, + }) + //console.log('Result', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json.fields) + } + }) + + it(`Get account[0] FIO Balance`, async () => { + try { + const result = await user[0].sdk.genericAction('getFioBalance', { + fioPublicKey: accounts[0].publicKey + }) + console.log('user[0] getFioBalance: ', result.balance) + } catch (err) { + console.log('Error: ', err) + } + }) + +}) + + +describe(`Trigger account with vote producer `, () => { + let user = [] + + it(`Create accounts`, async () => { + for (i = 0; i < accounts.length; i++) { + try { + user[i] = await existingUser(accounts[i].account, accounts[i].privateKey, accounts[i].publicKey, '', ''); + } catch (err) { + console.log('Error', err); + } + } + }) + + it(`Vote producer for every account`, async () => { + for (i = 0; i < accounts.length; i++) { + try { + const result = await user[i].sdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + "producers": [ + 'bp1@dapixdev' + ], + fio_address: '', + actor: user[i].account, + max_fee: config.maxFee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + } + } + }) +}) + +describe(`Full test`, () => { + let user = [], testUser + const currentTime = Date.now()/1000 + + it(`Create accounts`, async () => { + testUser = await newUser(faucet); + + for (i = 0; i < accounts.length; i++) { + try { + user[i] = await existingUser(accounts[i].account, accounts[i].privateKey, accounts[i].publicKey, '', ''); + //console.log("i: ", i); + //console.log("Public key: ", user[i].publicKey) + //console.log("Private key: ", user[i].privateKey) + //console.log("Account: ", user[i].account) + } catch (err) { + console.log('Error', err); + } + } + + console.log("secondsSinceEpoch: ", currentTime) + }) + + it('Test locks for users after triggering unlock', async () => { + let timestamp, lockedAccounts + + for (i = 0; i < accounts.length; i++) { + //for (i = 0; i < 1; i++) { + // Show account balance + try { + const result = await user[i].sdk.genericAction('getFioBalance', { + fioPublicKey: accounts[i].publicKey + }) + console.log('user[i] getFioBalance: ', result.balance) + } catch (err) { + console.log('Error: ', err) + } +/* + console.log('Trigger lock by voting (deducts .6 FIO)'); + try { + const result = await user[i].sdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + "producers": [ + 'bp1@dapixdev' + ], + fio_address: '', + actor: user[i].account, + max_fee: config.maxFee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json.error) + } +*/ + // Now look up the account in the lockedtokens table + try { + const json = { + json: true, // Get the response as json + code: 'eosio', // Contract that we target + scope: 'eosio', // Account that owns the data + table: 'lockedtokens', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + lockedAccounts = await callFioApi("get_table_rows", json); + //console.log('lockedAccounts: ', lockedAccounts) + for (lockedAccount in lockedAccounts.rows) { + if (lockedAccounts.rows[lockedAccount].owner == accounts[i].account) { + + console.log('Count: ', lockedAccount) + console.log('lockedAccounts.rows[lockedAccount].owner: ', lockedAccounts.rows[lockedAccount].owner); + console.log('lockedAccounts.rows[lockedAccount].total_grant_amount: ', lockedAccounts.rows[lockedAccount].total_grant_amount); + console.log('lockedAccounts.rows[lockedAccount].unlocked_period_count: ', lockedAccounts.rows[lockedAccount].unlocked_period_count); + console.log('lockedAccounts.rows[lockedAccount].grant_type: ', lockedAccounts.rows[lockedAccount].grant_type); + console.log('lockedAccounts.rows[lockedAccount].inhibit_unlocking: ', lockedAccounts.rows[lockedAccount].inhibit_unlocking); + console.log('lockedAccounts.rows[lockedAccount].remaining_locked_amount: ', lockedAccounts.rows[lockedAccount].remaining_locked_amount); + console.log('lockedAccounts.rows[lockedAccount].timestamp: ', lockedAccounts.rows[lockedAccount].timestamp); + timestamp = lockedAccounts.rows[lockedAccount].timestamp; + + break; + } + } + + let elapsedMin = Math.round((currentTime - timestamp) / 60); + console.log('elapsedMin: ', elapsedMin) + + expectedUnlockedPercent = 1; // (percent) Assume all periods have vested. + for (period in vestingSchedule) { + console.log('period: ', period); + console.log('vestingSchedule[period].day: ', vestingSchedule[period].day); + if (vestingSchedule[period].day > elapsedMin) { + expectedUnlockedPercent = vestingSchedule[period-1].unlockPercent + break; + } + } + expectedUnlockedAmount = expectedUnlockedPercent * lockedAccounts.rows[lockedAccount].total_grant_amount; + expectedRemainingLockedAmount = lockedAccounts.rows[lockedAccount].total_grant_amount - expectedUnlockedAmount; + console.log('expectedUnlockedPercent: ', expectedUnlockedPercent); + console.log('expectedUnlockedAmount: ', expectedUnlockedAmount); + console.log('expectedRemainingLockedAmount - remaining_locked_amount = ', expectedRemainingLockedAmount - lockedAccounts.rows[lockedAccount].remaining_locked_amount); + console.log('total_grant_amount - remaining_locked_amount = ', lockedAccounts.rows[lockedAccount].total_grant_amount - lockedAccounts.rows[lockedAccount].remaining_locked_amount); + console.log('remaining_locked_amount / total_grant_amount = ', lockedAccounts.rows[lockedAccount].remaining_locked_amount / lockedAccounts.rows[lockedAccount].total_grant_amount); + + if (lockedAccounts.rows[lockedAccount].grant_type === 1) { + expect(lockedAccounts.rows[lockedAccount].remaining_locked_amount).to.equal(expectedRemainingLockedAmount); + } + + console.log('\n\n'); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + } + }) + +}) + From 8b972ee265445860065b1c2f39873db67cf65278 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 21 Dec 2020 09:34:06 -0700 Subject: [PATCH 18/76] Vote.js fixes --- tests/vote.js | 748 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 686 insertions(+), 62 deletions(-) diff --git a/tests/vote.js b/tests/vote.js index 858009a5..a0af4b45 100644 --- a/tests/vote.js +++ b/tests/vote.js @@ -1,11 +1,9 @@ require('mocha') const {expect} = require('chai') -const {newUser, getProdVoteTotal, timeout, unlockWallet, addLock, getAccountVoteWeight, getTotalVotedFio, callFioApi, callFioApiSigned, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/fiosdk') +const {newUser, existingUser, getProdVoteTotal, timeout, unlockWallet, addLock, getAccountVoteWeight, getTotalVotedFio, callFioApi, callFioApiSigned, fetchJson} = require('../utils.js'); +const {FIOSDK } = require('@fioprotocol/FIOSDK') config = require('../config.js'); -let total_voted_fio - const eosio = { account: 'eosio', publicKey: 'FIO7isxEua78KPVbGzKemH4nj2bWE52gqj8Hkac3tc7jKNvpfWzYS', @@ -20,14 +18,19 @@ const fiotoken = { before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); -}) + }) describe(`************************** vote.js ************************** \n A. Test vote counts with proxy when proxy increases and decreases funds`, () => { - let proxyA1, total_voted_fio, total_bp_votes + let proxyA1, user2, total_voted_fio, total_bp_votes, transfer_tokens_pub_key_fee it(`Create users`, async () => { proxyA1 = await newUser(faucet); + user2 = await newUser(faucet); + + //console.log('proxyA1.account: ', proxyA1.account) + //console.log('proxyA1.publicKey: ', proxyA1.publicKey) + //console.log('proxyA1.privateKey: ', proxyA1.privateKey) }) it(`Wait a few seconds.`, async () => { await timeout(3000) }) @@ -37,7 +40,7 @@ describe(`************************** vote.js ************************** \n A. Te //console.log('total_voted_fio:', total_voted_fio) }) - it(`Get proxyA1 last_vote_weight`, async () => { + it(`Get proxyA1 last_vote_weight. Expect: null`, async () => { try { proxyA1.last_vote_weight = await getAccountVoteWeight(proxyA1.account); //console.log('proxyA1.last_vote_weight:', proxyA1.last_vote_weight) @@ -65,13 +68,13 @@ describe(`************************** vote.js ************************** \n A. Te data: { fio_address: proxyA1.address, actor: proxyA1.account, - max_fee: config.api.register_proxy.fee + max_fee: config.maxFee } }) //console.log('Result: ', result) expect(result.status).to.equal('OK') } catch (err) { - console.log('Error: ', err.json) + //console.log('Error: ', err.json) expect(err).to.equal('null') } }) @@ -94,7 +97,7 @@ describe(`************************** vote.js ************************** \n A. Te ], fio_address: proxyA1.address, actor: proxyA1.account, - max_fee: config.api.vote_producer.fee + max_fee: config.maxFee } }) //console.log('Result: ', result) @@ -110,23 +113,23 @@ describe(`************************** vote.js ************************** \n A. Te it(`Get proxyA1 last_vote_weight`, async () => { try { proxyA1.last_vote_weight = await getAccountVoteWeight(proxyA1.account); - //console.log('proxyA1.last_vote_weight:', proxyA1.last_vote_weight) + //console.log('proxyA1.last_vote_weight: ', proxyA1.last_vote_weight) } catch (err) { console.log('Error: ', err.json) } }) it(`proxyA1 FIO balance same as last_vote_weight`, async () => { - try { - const result = await proxyA1.sdk.genericAction('getFioBalance', { - fioPublicKey: proxyA1.publicKey - }) - //console.log('User 1 fio balance', result) - expect(result.balance).to.equal(proxyA1.last_vote_weight) - } catch (err) { - console.log('Error', err) - expect(err).to.equal('null') - } + try { + const result = await proxyA1.sdk.genericAction('getFioBalance', { + fioPublicKey: proxyA1.publicKey + }) + //console.log('proxyA1 fio balance', result) + expect(result.balance).to.equal(proxyA1.last_vote_weight) + } catch (err) { + console.log('Error', err) + expect(err).to.equal('null') + } }) it(`total_voted_fio increased by proxyA1 last_vote_weight`, async () => { @@ -153,16 +156,18 @@ describe(`************************** vote.js ************************** \n A. Te } }) - it('Transfer additional 500 FIO from faucet to proxyA1', async () => { - const result = await faucet.genericAction('transferTokens', { + it('Transfer additional 50 FIO from user2 to proxyA1', async () => { + const result = await user2.sdk.genericAction('transferTokens', { payeeFioPublicKey: proxyA1.publicKey, - amount: 500000000000, - maxFee: config.api.transfer_tokens_pub_key.fee, + amount: 50000000000, + maxFee: config.maxFee, }) //console.log('Result', result) expect(result.status).to.equal('OK') }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Get proxyA1 last_vote_weight (should be 500 more)`, async () => { try { proxyA1.last_vote_weight = await getAccountVoteWeight(proxyA1.account); @@ -177,7 +182,7 @@ describe(`************************** vote.js ************************** \n A. Te let prev_total_voted_fio = total_voted_fio total_voted_fio = await getTotalVotedFio(); //console.log('total_voted_fio: ', total_voted_fio) - expect(total_voted_fio).to.equal(prev_total_voted_fio + 500000000000) + expect(total_voted_fio).to.equal(prev_total_voted_fio + 50000000000) } catch (err) { console.log('Error', err) expect(err).to.equal('null') @@ -189,24 +194,38 @@ describe(`************************** vote.js ************************** \n A. Te let prev_total_bp_votes = total_bp_votes; total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); //console.log('bp1@dapixdev total_votes:', total_bp_votes) - expect(total_bp_votes).to.equal(prev_total_bp_votes + 500000000000) + expect(total_bp_votes).to.equal(prev_total_bp_votes + 50000000000) } catch (err) { console.log('Error: ', err) expect(err).to.equal('null') } }) - it(`Transfer 200 FIO from proxyA1 back to faucet`, async () => { + it('Get transfer_tokens_pub_key fee', async () => { + try { + result = await proxyA1.sdk.getFee('transfer_tokens_pub_key'); + //console.log('result: ', result); + transfer_tokens_pub_key_fee = result.fee; + expect(result.fee).to.be.greaterThan(0); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Transfer 20 FIO from proxyA1 back to user2`, async () => { const result = await proxyA1.sdk.genericAction('transferTokens', { - payeeFioPublicKey: faucet.publicKey, - amount: 200000000000, - maxFee: config.api.transfer_tokens_pub_key.fee, + payeeFioPublicKey: user2.publicKey, + amount: 20000000000, + maxFee: config.maxFee, }) //console.log('Result', result) expect(result.status).to.equal('OK') }) - it(`Get proxyA1 last_vote_weight (should be 200 + 2 fee = 202 less)`, async () => { + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it(`Get proxyA1 last_vote_weight (should be 20 - transfer_tokens_pub_key_fee less)`, async () => { try { proxyA1.last_vote_weight = await getAccountVoteWeight(proxyA1.account); //console.log('proxyA1.last_vote_weight:', proxyA1.last_vote_weight) @@ -216,24 +235,24 @@ describe(`************************** vote.js ************************** \n A. Te } }) - it(`total_voted_fio decreased by 202 FIO`, async () => { + it(`total_voted_fio decreased by 20 FIO (minus the transferTokens fee)`, async () => { try { let prev_total_voted_fio = total_voted_fio total_voted_fio = await getTotalVotedFio(); //console.log('total_voted_fio: ', total_voted_fio) - expect(total_voted_fio).to.equal(prev_total_voted_fio - 200000000000 - config.api.transfer_tokens_pub_key.fee) + expect(total_voted_fio).to.equal(prev_total_voted_fio - 20000000000 - transfer_tokens_pub_key_fee) } catch (err) { console.log('Error', err) expect(err).to.equal('null') } }) - it(`bp1@dapixdev total_votes increased by 500 FIO`, async () => { + it(`bp1@dapixdev total_votes increased by 20 FIO (minus the transferTokens fee)`, async () => { try { let prev_total_bp_votes = total_bp_votes; total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); //console.log('bp1@dapixdev total_votes:', total_bp_votes) - expect(total_bp_votes).to.equal(prev_total_bp_votes - 200000000000 - config.api.transfer_tokens_pub_key.fee) + expect(total_bp_votes).to.equal(prev_total_bp_votes - 20000000000 - transfer_tokens_pub_key_fee) } catch (err) { console.log('Error: ', err) expect(err).to.equal('null') @@ -242,14 +261,15 @@ describe(`************************** vote.js ************************** \n A. Te }) -describe('B. Test vote counts with proxy when proxy increases and decreases funds', () => { +describe.only('B. Test vote counts with proxy when proxy increases and decreases funds', () => { - let proxyB1, voterB1, total_voted_fio, total_bp_votes + let proxyB1, voterB1, user1, total_voted_fio, total_bp_votes, transfer_tokens_pub_key_fee it(`Create users`, async () => { try { proxyB1 = await newUser(faucet); voterB1 = await newUser(faucet); + user1 = await newUser(faucet); } catch (err) { console.log('Error: ', err) } @@ -418,66 +438,78 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund } }) - it('Transfer additional 500 FIO from faucet to voterB1', async () => { - const result = await faucet.genericAction('transferTokens', { + it('Get transfer_tokens_pub_key fee', async () => { + try { + result = await proxyB1.sdk.getFee('transfer_tokens_pub_key'); + //console.log('result: ', result); + transfer_tokens_pub_key_fee = result.fee; + expect(result.fee).to.be.greaterThan(0); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it('Transfer additional 500 FIO from user1 to voterB1', async () => { + const result = await user1.sdk.genericAction('transferTokens', { payeeFioPublicKey: voterB1.publicKey, amount: 500000000000, - maxFee: config.api.transfer_tokens_pub_key.fee, + maxFee: config.maxFee, }) //console.log('Result', result) expect(result.status).to.equal('OK') }) - it(`voterB1 last_vote_weight increases by 500 FIO)`, async () => { + it(`voterB1 last_vote_weight increases by 500 FIO) (minus the fee)`, async () => { try { let prev_vote_weight = voterB1.last_vote_weight; voterB1.last_vote_weight = await getAccountVoteWeight(voterB1.account); //console.log('voterB1.last_vote_weight:', voterB1.last_vote_weight); - expect(voterB1.last_vote_weight).to.equal(prev_vote_weight + 500000000000); + expect(voterB1.last_vote_weight).to.equal(prev_vote_weight + 500000000000 - transfer_tokens_pub_key_fee); } catch (err) { console.log('Error: ', err) } }) - it(`proxyB1 last_vote_weight increases by 500 FIO)`, async () => { + it(`proxyB1 last_vote_weight increases by 500 FIO) (minus the fee)`, async () => { try { let prev_vote_weight = proxyB1.last_vote_weight; proxyB1.last_vote_weight = await getAccountVoteWeight(proxyB1.account); //console.log('proxyB1.last_vote_weight:', proxyB1.last_vote_weight); - expect(proxyB1.last_vote_weight).to.equal(prev_vote_weight + 500000000000); + expect(proxyB1.last_vote_weight).to.equal(prev_vote_weight + 500000000000 - transfer_tokens_pub_key_fee); } catch (err) { console.log('Error: ', err) } }) - it(`total_voted_fio increased by 500 FIO`, async () => { + it(`total_voted_fio increased by 500 FIO (minus the fee)`, async () => { try { let prev_total_voted_fio = total_voted_fio; total_voted_fio = await getTotalVotedFio(); //console.log('total_voted_fio: ', total_voted_fio) - expect(total_voted_fio).to.equal(prev_total_voted_fio + 500000000000) + expect(total_voted_fio).to.equal(prev_total_voted_fio + 500000000000 - transfer_tokens_pub_key_fee) } catch (err) { console.log('Error', err) } }) - it(`bp1@dapixdev total_votes increased by 500 FIO`, async () => { + it(`bp1@dapixdev total_votes increased by 500 FIO (minus the fee)`, async () => { try { let prev_total_bp_votes = total_bp_votes; total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); //console.log('bp1@dapixdev total_votes:', total_bp_votes) - expect(total_bp_votes).to.equal(prev_total_bp_votes + 500000000000) + expect(total_bp_votes).to.equal(prev_total_bp_votes + 500000000000 - transfer_tokens_pub_key_fee) } catch (err) { console.log('Error: ', err) } }) - it('Transfer 1000 FIO from voterB1 to faucet', async () => { + it('Transfer 1000 FIO from voterB1 to user1', async () => { try { const result = await voterB1.sdk.genericAction('transferTokens', { - payeeFioPublicKey: faucet.publicKey, + payeeFioPublicKey: user1.publicKey, amount: 1000000000000, - maxFee: config.api.transfer_tokens_pub_key.fee, + maxFee: config.maxFee, }) //console.log('Result', result) expect(result.status).to.equal('OK') @@ -491,7 +523,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund let prev_vote_weight = voterB1.last_vote_weight; voterB1.last_vote_weight = await getAccountVoteWeight(voterB1.account); //console.log('voterB1.last_vote_weight:', voterB1.last_vote_weight); - expect(voterB1.last_vote_weight).to.equal(prev_vote_weight - 1000000000000 - config.api.transfer_tokens_pub_key.fee); + expect(voterB1.last_vote_weight).to.equal(prev_vote_weight - 1000000000000 - transfer_tokens_pub_key_fee); } catch (err) { console.log('Error: ', err) } @@ -502,7 +534,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund let prev_vote_weight = proxyB1.last_vote_weight; proxyB1.last_vote_weight = await getAccountVoteWeight(proxyB1.account); //console.log('proxyB1.last_vote_weight:', proxyB1.last_vote_weight); - expect(proxyB1.last_vote_weight).to.equal(prev_vote_weight - 1000000000000 - config.api.transfer_tokens_pub_key.fee); + expect(proxyB1.last_vote_weight).to.equal(prev_vote_weight - 1000000000000 - transfer_tokens_pub_key_fee); } catch (err) { console.log('Error: ', err) } @@ -513,7 +545,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund let prev_total_voted_fio = total_voted_fio; total_voted_fio = await getTotalVotedFio(); //console.log('total_voted_fio: ', total_voted_fio) - expect(total_voted_fio).to.equal(prev_total_voted_fio - 1000000000000 - config.api.transfer_tokens_pub_key.fee) + expect(total_voted_fio).to.equal(prev_total_voted_fio - 1000000000000 - transfer_tokens_pub_key_fee) } catch (err) { console.log('Error', err) } @@ -524,7 +556,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund let prev_total_bp_votes = total_bp_votes; total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); //console.log('bp1@dapixdev total_votes:', total_bp_votes) - expect(total_bp_votes).to.equal(prev_total_bp_votes - 1000000000000 - config.api.transfer_tokens_pub_key.fee) + expect(total_bp_votes).to.equal(prev_total_bp_votes - 1000000000000 - transfer_tokens_pub_key_fee) } catch (err) { console.log('Error: ', err) } @@ -534,7 +566,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund const result = await proxyB1.sdk.genericAction('transferTokens', { payeeFioPublicKey: voterB1.publicKey, amount: 800000000000, - maxFee: config.api.transfer_tokens_pub_key.fee, + maxFee: config.maxFee, }) //console.log('Result', result) expect(result.status).to.equal('OK') @@ -556,7 +588,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund let prev_vote_weight = proxyB1.last_vote_weight; proxyB1.last_vote_weight = await getAccountVoteWeight(proxyB1.account); //console.log('proxyB1.last_vote_weight:', proxyB1.last_vote_weight); - expect(proxyB1.last_vote_weight).to.equal(prev_vote_weight - config.api.transfer_tokens_pub_key.fee); + expect(proxyB1.last_vote_weight).to.equal(prev_vote_weight - transfer_tokens_pub_key_fee); } catch (err) { console.log('Error: ', err) } @@ -567,7 +599,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund let prev_total_voted_fio = total_voted_fio; total_voted_fio = await getTotalVotedFio(); //console.log('total_voted_fio: ', total_voted_fio) - expect(total_voted_fio).to.equal(prev_total_voted_fio - config.api.transfer_tokens_pub_key.fee) + expect(total_voted_fio).to.equal(prev_total_voted_fio - transfer_tokens_pub_key_fee) } catch (err) { console.log('Error', err) } @@ -657,11 +689,11 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund } }) - it(`Transfer 200 FIO from proxyB1 back to faucet`, async () => { + it(`Transfer 200 FIO from proxyB1 back to user1`, async () => { const result = await proxyB1.sdk.genericAction('transferTokens', { - payeeFioPublicKey: faucet.publicKey, + payeeFioPublicKey: user1.publicKey, amount: 200000000000, - maxFee: config.api.transfer_tokens_pub_key.fee, + maxFee: config.maxFee, }); //console.log('Result', result) expect(result.status).to.equal('OK') ; @@ -2825,3 +2857,595 @@ describe('v1.2.0 release only. H. Confirm voter data is returned with get_accoun }) }) + +describe(`Test proxy re-vote of proxy, re-proxy of voter`, () => { + + let user1, proxyA1, total_voted_fio, total_bp_votes + + it(`Create users`, async () => { + user1 = await newUser(faucet); + proxyA1 = await newUser(faucet); + }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it(`Register proxyA1 as a proxy`, async () => { + try { + const result = await proxyA1.sdk.genericAction('pushTransaction', { + action: 'regproxy', + account: 'eosio', + data: { + fio_address: proxyA1.address, + actor: proxyA1.account, + max_fee: config.api.register_proxy.fee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + expect(err).to.equal('null') + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it(`proxyA1 votes for bp1@dapixdev using address #1`, async () => { + try { + const result = await proxyA1.sdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + "producers": [ + 'bp1@dapixdev' + ], + fio_address: proxyA1.address, + actor: proxyA1.account, + max_fee: config.api.vote_producer.fee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + expect(err).to.equal('null') + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it(`user1 proxies votes to proxyA1`, async () => { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'voteproxy', + account: 'eosio', + data: { + proxy: proxyA1.address, + fio_address: user1.address, + actor: user1.account, + max_fee: config.maxFee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + } + }) + + it(`Get total_voted_fio`, async () => { + total_voted_fio = await getTotalVotedFio(); + console.log('total_voted_fio:', total_voted_fio) + }) + + it(`Get proxyA1 last_vote_weight`, async () => { + try { + proxyA1.last_vote_weight = await getAccountVoteWeight(proxyA1.account); + console.log('proxyA1.last_vote_weight: ', proxyA1.last_vote_weight) + } catch (err) { + console.log('Error: ', err.json) + } + }) + + it(`Get bp1@dapixdev total_votes`, async () => { + try { + total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); + console.log('bp1@dapixdev total_votes:', total_bp_votes) + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`proxyA1 votes AGAIN for bp1@dapixdev using address #1`, async () => { + try { + const result = await proxyA1.sdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + "producers": [ + 'bp1@dapixdev' + ], + fio_address: proxyA1.address, + actor: proxyA1.account, + max_fee: config.api.vote_producer.fee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + expect(err).to.equal('null') + } + }) + + it(`bp1@dapixdev total_votes did not change`, async () => { + try { + let prev_total_bp_votes = total_bp_votes; + total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); + console.log('bp1@dapixdev total_votes:', total_bp_votes) + expect(total_bp_votes).to.equal(prev_total_bp_votes) + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`prev_total_voted_fio did not change`, async () => { + try { + let prev_total_voted_fio = total_voted_fio; + total_voted_fio = await getTotalVotedFio(); + console.log('total_voted_fio:', total_voted_fio) + expect(total_voted_fio).to.equal(prev_total_voted_fio) + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`Get user1 last_vote_weight`, async () => { + try { + user1.last_vote_weight = await getAccountVoteWeight(user1.account); + console.log('user1.last_vote_weight: ', user1.last_vote_weight) + } catch (err) { + console.log('Error: ', err.json) + } + }) + + it(`user1 proxies votes AGAIN to proxyA1`, async () => { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'voteproxy', + account: 'eosio', + data: { + proxy: proxyA1.address, + fio_address: user1.address, + actor: user1.account, + max_fee: config.maxFee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + } + }) + + it(`bp1@dapixdev total_votes did not change`, async () => { + try { + let prev_total_bp_votes = total_bp_votes; + total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); + console.log('bp1@dapixdev total_votes:', total_bp_votes) + expect(total_bp_votes).to.equal(prev_total_bp_votes) + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`prev_total_voted_fio did not change`, async () => { + try { + let prev_total_voted_fio = total_voted_fio; + total_voted_fio = await getTotalVotedFio(); + console.log('total_voted_fio:', total_voted_fio) + expect(total_voted_fio).to.equal(prev_total_voted_fio) + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + +}) + +describe(`Test impact on total_voted_fio when User 1 votes then proxies their votes`, () => { + + let user1, proxyA1, total_voted_fio, total_bp_votes + + it(`Create users`, async () => { + user1 = await newUser(faucet); + proxyA1 = await newUser(faucet); + }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it(`Register proxyA1 as a proxy`, async () => { + try { + const result = await proxyA1.sdk.genericAction('pushTransaction', { + action: 'regproxy', + account: 'eosio', + data: { + fio_address: proxyA1.address, + actor: proxyA1.account, + max_fee: config.api.register_proxy.fee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + expect(err).to.equal('null') + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it(`proxyA1 votes for bp1@dapixdev using address #1`, async () => { + try { + const result = await proxyA1.sdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + "producers": [ + 'bp1@dapixdev' + ], + fio_address: proxyA1.address, + actor: proxyA1.account, + max_fee: config.api.vote_producer.fee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + expect(err).to.equal('null') + } + }) + + it(`user1 votes for bp1@dapixdev`, async () => { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + "producers": [ + 'bp1@dapixdev' + ], + fio_address: user1.address, + actor: user1.account, + max_fee: config.api.vote_producer.fee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + expect(err).to.equal('null') + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it(`Get total_voted_fio`, async () => { + total_voted_fio = await getTotalVotedFio(); + //console.log('total_voted_fio:', total_voted_fio) + }) + + it(`Get proxyA1 last_vote_weight`, async () => { + try { + proxyA1.last_vote_weight = await getAccountVoteWeight(proxyA1.account); + //console.log('proxyA1.last_vote_weight: ', proxyA1.last_vote_weight) + } catch (err) { + console.log('Error: ', err.json) + } + }) + + it(`Get user1 FIO Balance, set user1.last_vote_weight = balance`, async () => { + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + user1.last_vote_weight = result.balance + //console.log('user1 fio balance', result.balance) + } catch (err) { + console.log('Error', err) + expect(err).to.equal('null') + } + }) + + it(`Get bp1@dapixdev total_votes`, async () => { + try { + total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); + //console.log('bp1@dapixdev total_votes:', total_bp_votes) + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`user1 proxies votes to proxyA1 (after having already directly voted for bp1@dapixdev)`, async () => { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'voteproxy', + account: 'eosio', + data: { + proxy: proxyA1.address, + fio_address: user1.address, + actor: user1.account, + max_fee: config.maxFee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + } + }) + + it(`bp1@dapixdev total_votes did not change (votes just shifted from direct vote to proxy vote via proxyA1)`, async () => { + try { + let prev_total_bp_votes = total_bp_votes; + total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); + //console.log('bp1@dapixdev total_votes:', total_bp_votes) + expect(total_bp_votes).to.equal(prev_total_bp_votes) + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`BUG: prev_total_voted_fio did not change (votes just shifted from direct vote to proxy vote via proxyA1)`, async () => { + try { + let prev_total_voted_fio = total_voted_fio; + total_voted_fio = await getTotalVotedFio(); + //console.log('total_voted_fio:', total_voted_fio) + expect(total_voted_fio).to.equal(prev_total_voted_fio) + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + +}) + +describe(`Test total_voted_fio when user votes for proxy`, () => { + + let user1, proxyA1, total_voted_fio, total_bp_votes + + it(`Create users`, async () => { + user1 = await newUser(faucet); + proxyA1 = await newUser(faucet); + }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it(`Get initial total_voted_fio`, async () => { + total_voted_fio = await getTotalVotedFio(); + //console.log('total_voted_fio:', total_voted_fio) + }) + + it(`Get proxyA1 last_vote_weight`, async () => { + try { + proxyA1.last_vote_weight = await getAccountVoteWeight(proxyA1.account); + //console.log('proxyA1.last_vote_weight:', proxyA1.last_vote_weight) + } catch (err) { + console.log('Error: ', err.json) + expect(err).to.equal('null') + } + }) + + it(`Get bp1@dapixdev total_votes`, async () => { + try { + total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); + //console.log('bp1@dapixdev total_votes:', total_bp_votes) + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`Register proxyA1 as a proxy`, async () => { + try { + const result = await proxyA1.sdk.genericAction('pushTransaction', { + action: 'regproxy', + account: 'eosio', + data: { + fio_address: proxyA1.address, + actor: proxyA1.account, + max_fee: config.api.register_proxy.fee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + expect(err).to.equal('null') + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it(`Get total_voted_fio before proxyA1 votes`, async () => { + total_voted_fio = await getTotalVotedFio(); + //console.log('total_voted_fio:', total_voted_fio) + }) + + it(`proxyA1 votes for bp1@dapixdev using address #1`, async () => { + try { + const result = await proxyA1.sdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + "producers": [ + 'bp1@dapixdev' + ], + fio_address: proxyA1.address, + actor: proxyA1.account, + max_fee: config.api.vote_producer.fee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + expect(err).to.equal('null') + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it(`Get proxyA1 last_vote_weight`, async () => { + try { + proxyA1.last_vote_weight = await getAccountVoteWeight(proxyA1.account); + //console.log('proxyA1.last_vote_weight: ', proxyA1.last_vote_weight) + } catch (err) { + console.log('Error: ', err.json) + } + }) + + it(`Get user1 last_vote_weight. Expect null`, async () => { + try { + user1.last_vote_weight = await getAccountVoteWeight(user1.account); + //console.log('user1.last_vote_weight: ', user1.last_vote_weight) + expect(user1.last_vote_weight).to.equal(null) + } catch (err) { + console.log('Error: ', err.json) + } + }) + + it(`Get user1 FIO Balance, set user1.last_vote_weight = balance`, async () => { + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + user1.last_vote_weight = result.balance + //console.log('user1 fio balance', result.balance) + } catch (err) { + console.log('Error', err) + expect(err).to.equal('null') + } + }) + + it(`Get total_voted_fio`, async () => { + total_voted_fio = await getTotalVotedFio(); + //console.log('total_voted_fio:', total_voted_fio) + }) + + it(`Get bp1@dapixdev total_votes`, async () => { + try { + total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); + //console.log('bp1@dapixdev total_votes:', total_bp_votes) + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`Proxy user1 votes to proxyA1`, async () => { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'voteproxy', + account: 'eosio', + data: { + proxy: proxyA1.address, + fio_address: user1.address, + actor: user1.account, + max_fee: config.maxFee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + } + }) + + it(`bp1@dapixdev total_votes increased by user1 last_vote_weight`, async () => { + try { + let prev_total_bp_votes = total_bp_votes; + total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); + //console.log('bp1@dapixdev total_votes:', total_bp_votes) + expect(total_bp_votes).to.equal(prev_total_bp_votes + user1.last_vote_weight) + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`prev_total_voted_fio increased by user1 last_vote_weight`, async () => { + try { + let prev_total_voted_fio = total_voted_fio; + total_voted_fio = await getTotalVotedFio(); + //console.log('total_voted_fio:', total_voted_fio) + expect(total_voted_fio).to.equal(prev_total_voted_fio + user1.last_vote_weight) + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`Get faucet last_vote_weight`, async () => { + try { + faucet.last_vote_weight = await getAccountVoteWeight(faucet.account); + //console.log('faucet.last_vote_weight: ', faucet.last_vote_weight) + } catch (err) { + console.log('Error: ', err.json) + } + }) + + it(`faucet votes for bp1@dapixdev using address #1`, async () => { + try { + const result = await faucet.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + "producers": [ + 'bp1@dapixdev' + ], + fio_address: faucet.address, + actor: faucet.account, + max_fee: config.maxFee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + expect(err).to.equal('null') + } + }) + + it(`bp1@dapixdev total_votes increased by faucet last_vote_weight`, async () => { + try { + let prev_total_bp_votes = total_bp_votes; + total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); + //console.log('bp1@dapixdev total_votes:', total_bp_votes) + expect(total_bp_votes).to.equal(prev_total_bp_votes + faucet.last_vote_weight) + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`prev_total_voted_fio increased by faucet last_vote_weight`, async () => { + try { + let prev_total_voted_fio = total_voted_fio; + total_voted_fio = await getTotalVotedFio(); + //console.log('total_voted_fio:', total_voted_fio) + expect(total_voted_fio).to.equal(prev_total_voted_fio + faucet.last_vote_weight) + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + +}) \ No newline at end of file From ab52d8a1103b8e9b7901c26aa0dfb0262c852bf9 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 21 Dec 2020 17:45:33 -0700 Subject: [PATCH 19/76] Vote.js lowercase fiosdk --- tests/vote.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/vote.js b/tests/vote.js index a0af4b45..237cb60a 100644 --- a/tests/vote.js +++ b/tests/vote.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, existingUser, getProdVoteTotal, timeout, unlockWallet, addLock, getAccountVoteWeight, getTotalVotedFio, callFioApi, callFioApiSigned, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); const eosio = { From 08ffc0061c53e1605762cc7f7270690c83bfe420 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Wed, 23 Dec 2020 17:06:09 -0700 Subject: [PATCH 20/76] Test for proxy bug --- tests/vote.js | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/tests/vote.js b/tests/vote.js index 237cb60a..675af283 100644 --- a/tests/vote.js +++ b/tests/vote.js @@ -3448,4 +3448,116 @@ describe(`Test total_voted_fio when user votes for proxy`, () => { } }) +}) + +describe(`BD-2028: regproxy results in faulty record in voters table if account already has a voteproducer record`, () => { + + let proxyA1 + + it(`Create users`, async () => { + proxyA1 = await newUser(faucet); + }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it(`Create voters record: proxyA1 votes for bp1@dapixdev using address #1`, async () => { + try { + const result = await proxyA1.sdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + "producers": [ + 'bp1@dapixdev' + ], + fio_address: proxyA1.address, + actor: proxyA1.account, + max_fee: config.api.vote_producer.fee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + expect(err).to.equal('null') + } + }) + + it('Confirm voters record: ', async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: false, + show_payer: false + } + voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voters); + for (voter in voters.rows) { + if (voters.rows[voter].owner == proxyA1.account) { + //console.log('voters.rows[voter]: ', voters.rows[voter]); + break; + } + } + expect(voters.rows[voter].owner).to.equal(proxyA1.account); + expect(voters.rows[voter].is_proxy).to.equal(0); + expect(voters.rows[voter].fioaddress).to.equal(''); + //expect(voters.rows[voter].addresshash).to.equal('0x00000000000000000000000000000000'); + + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Register proxyA1 as a proxy`, async () => { + try { + const result = await proxyA1.sdk.genericAction('pushTransaction', { + action: 'regproxy', + account: 'eosio', + data: { + fio_address: proxyA1.address, + actor: proxyA1.account, + max_fee: config.api.register_proxy.fee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + expect(err).to.equal('null') + } + }) + + it('Confirm voters record: ', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'eosio', // Contract that we target + scope: 'eosio', // Account that owns the data + table: 'voters', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voters); + for (voter in voters.rows) { + if (voters.rows[voter].owner == proxyA1.account) { + //console.log('voters.rows[voter]: ', voters.rows[voter]); + break; + } + } + expect(voters.rows[voter].owner).to.equal(proxyA1.account); + expect(voters.rows[voter].is_proxy).to.equal(1); + expect(voters.rows[voter].fioaddress).to.equal(proxyA1.address); + expect(voters.rows[voter].addresshash).to.not.equal('0x00000000000000000000000000000000'); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + }) \ No newline at end of file From aea5e3d93ce4629d8d588b7953d15e0be79e3076 Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Sat, 26 Dec 2020 14:52:29 -0700 Subject: [PATCH 21/76] add tests for large grants. add test for large grants. --- tests/transfer-locked-tokens-large-grants.js | 159 +++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 tests/transfer-locked-tokens-large-grants.js diff --git a/tests/transfer-locked-tokens-large-grants.js b/tests/transfer-locked-tokens-large-grants.js new file mode 100644 index 00000000..9eaf9e15 --- /dev/null +++ b/tests/transfer-locked-tokens-large-grants.js @@ -0,0 +1,159 @@ +require('mocha') +const {expect} = require('chai') +const {newUser, getProdVoteTotal, fetchJson, existingUser, generateFioDomain, getAccountFromKey, callFioApi, generateFioAddress, createKeypair} = require('../utils.js'); +const {FIOSDK } = require('@fioprotocol/fiosdk') +config = require('../config.js'); + +before(async () => { + faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); +}) + +function wait(ms){ + var start = new Date().getTime(); + var end = start; + while(end < start + ms) { + end = new Date().getTime(); + } +} + +let userA1, userA2, userA3, userA4, keys, keys1, keys2, keys3, locksdk, + locksdk1, locksdk2, locksdk3, newFioAddress, newFioDomain, newFioDomain2, newFioAddress2, + total_bp_votes_before, total_bp_votes_after +const fundsAmount = 500000000000 +const maxTestFundsAmount = 5000000000 +const halfundsAmount = 220000000000 +const largeGrantAmount = 100000000000000000 + +describe(`************************** transfer-locked-tokens.js ************************** \n A. Create accounts for tests`, () => { + + + it.skip(`Create users`, async () => { + try { + //NOTE -- these tests must be run on the local 3 node test net. + // they use the account htjonrkf1lgs + // furthermore, these tests require that the fio.devtools startup file be modified + // modify the 08_token_issue.sh and modify the issue amount for htjonrkf1lgs to + // become 120000000.000000000 also modify the account euwdcp13zlrj to become 2000000.000000000 + // with these values the chain will init, and then this set of tests can be run. + //create SDK for the htjonrkf1lgs account. + keys = await createKeypair(); + console.log("priv key ", keys.privateKey); + console.log("pub key ", keys.privateKey); + + userA1 = await newUser(faucet); + + locksdk = await existingUser('htjonrkf1lgs', '5JCpqkvsrCzrAC3YWhx7pnLodr3Wr9dNMULYU8yoUrPRzu269Xz', 'FIO7uRvrLVrZCbCM2DtCgUMospqUMnP3JUC1sKHA8zNoF835kJBvN', 'dapixdev', 'adam@dapixdev'); + } catch (err) { + console.log(err.message) + } + }) +}) + + + +describe(`A. Large grant tests`, () => { + + + + it.skip(`Success Test, Transfer locked tokens, create grant of 100M`, async () => { + try { + const result = await locksdk.sdk.genericAction('pushTransaction', { + action: 'trnsloctoks', + account: 'fio.token', + data: { + payee_public_key: keys.publicKey, + can_vote: 0, + periods: [ + { + duration: 20, + percent: 50.0, + }, + { + duration: 40, + percent: 50.0, + } + ], + amount: largeGrantAmount, + max_fee: 400000000000, + tpid: '', + actor: 'htjonrkf1lgs', + } + }) + expect(result.status).to.equal('OK') + + } catch (err) { + console.log(err.message) + } + }) + + it.skip(`Waiting 25 seconds`, async () => { + console.log(" waiting 25 seconds ") + }) + + it.skip(` wait 25 seconds`, async () => { + try { + wait(25000) + } catch (err) { + console.log('Error', err) + } + }) + + //one half should get unlocked + it.skip(`Transfer 4900000 FIO to another account`, async () => { + try { + locksdk2 = new FIOSDK(keys.privateKey, keys.publicKey, config.BASE_URL, fetchJson); + console.log("priv key: ",locksdk2.privateKey); + console.log("pub key: ",locksdk2.publicKey); + console.log("account: ",locksdk2.accountHash); + const result = await locksdk2.genericAction('transferTokens', { + payeeFioPublicKey: userA1.publicKey, + amount: 4900000000000000, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + expect(result).to.have.all.keys('transaction_id', 'block_num', 'status', 'fee_collected') + } catch (err) { + console.log(err.message) + } + }) + + it('Show lock amount for user', async () => { + let timestamp + let accountnm = await getAccountFromKey('FIO7Zq2qUduoQsQxmTvHTvKif8wMm7tX4XWKbQm59rAsU54GZPnSL'); + + console.log("account is ",accountnm) + try { + const json = { + json: true, // Get the response as json + code: 'eosio', // Contract that we target + scope: 'eosio', // Account that owns the data + table: 'locktokens', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + lockedAccounts = await callFioApi("get_table_rows", json); + //console.log('lockedAccounts: ', lockedAccounts) + for (lockedAccount in lockedAccounts.rows) { + //if (lockedAccounts.rows[lockedAccount].owner == accounts[0].account) { + if (lockedAccounts.rows[lockedAccount].owner_account == accountnm) { + console.log('Count: ', lockedAccount) + console.log('lockedAccounts.rows[lockedAccount].owner_account: ', lockedAccounts.rows[lockedAccount].owner_account); + console.log('lockedAccounts.rows[lockedAccount].lock_amount: ', lockedAccounts.rows[lockedAccount].lock_amount); + console.log('lockedAccounts.rows[lockedAccount].payouts_performed: ', lockedAccounts.rows[lockedAccount].payouts_performed); + console.log('lockedAccounts.rows[lockedAccount].remaining_lock_amount: ', lockedAccounts.rows[lockedAccount].remaining_lock_amount); + break; + } + } + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) + + + + + From 9254d63a2a89ef96cbe0da4b1551b36a839aa683 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Sun, 27 Dec 2020 19:30:28 -0700 Subject: [PATCH 22/76] Port fixes to develop branch --- index.js | 2 +- tests/transfer-address.js | 366 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 354 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index e54d0881..2963335a 100644 --- a/index.js +++ b/index.js @@ -24,7 +24,7 @@ describe('TEST SUITE', () => { //require('./tests/fee-voting-fee-setting.js'); // FIP-10 //require('./tests/producer-fee-setting.js'); // FIP-10 require('./tests/record-obt-data.js'); //FIP-1.b testing - //require('./tests/transfer-address.js'); // FIP-1.b + require('./tests/transfer-address.js'); // FIP-1.b require('./tests/transfer-locked-tokens.js'); // FIP-6 locking tests require('./tests/transfer-locked-tokens-account-tests.js'); // FIP-6 tests of generic account functionality //require('./tests/clio.js'); // FIP-16 diff --git a/tests/transfer-address.js b/tests/transfer-address.js index 52c30a60..d5440369 100644 --- a/tests/transfer-address.js +++ b/tests/transfer-address.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') -const {newUser, generateFioAddress, createKeypair, callFioApi, getFees, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/fiosdk') +const {newUser, generateFioAddress, createKeypair, callFioApi, getFees, fetchJson, timeout} = require('../utils.js'); +const {FIOSDK } = require('@fioprotocol/FIOSDK') config = require('../config.js'); before(async () => { @@ -39,6 +39,35 @@ describe('************************** transfer-address.js *********************** expect(result.status).to.equal('OK') }) + it(`Add DASH and BCH addresses to walletA1.address2`, async () => { + try { + const result = await walletA1.sdk.genericAction('addPublicAddresses', { + fioAddress: walletA1.address2, + publicAddresses: [ + { + chain_code: 'BCH', + token_code: 'BCH', + public_address: 'bitcoincash:qzf8zha74ahdh9j0xnwlffdn0zuyaslx3c90q7n9g9', + }, + { + chain_code: 'DASH', + token_code: 'DASH', + public_address: 'XyCyPKzTWvW2XdcYjPaPXGQDCGk946ywEv', + } + ], + maxFee: config.api.add_pub_address.fee, + technologyProviderId: '' + }) + //console.log('Result:', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error', err) + //expect(err).to.equal(null) + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`getFioNames for walletA1 and confirm it owns 2 addresses and that one of them is walletA1.address2`, async () => { try { const result = await walletA1.sdk.genericAction('getFioNames', { @@ -181,6 +210,7 @@ describe('************************** transfer-address.js *********************** fioPublicKey: walletA2.publicKey }) //console.log('getFioNames', walletA2FioNames) + walletA2.address2 = walletA2FioNames.fio_addresses[1].fio_address expect(walletA2FioNames.fio_addresses.length).to.equal(2) expect(walletA2FioNames.fio_domains[0].fio_domain).to.equal(walletA2.domain) expect(walletA2FioNames.fio_addresses[0].fio_address).to.equal(walletA2.address) @@ -195,6 +225,49 @@ describe('************************** transfer-address.js *********************** expect(walletA2FioNames.fio_addresses[1].expiration).to.equal(origAddressExpire) }) + it('confirm BCH address was removed', async () => { + try { + const result = await walletA2.sdk.genericAction('getPublicAddress', { + fioAddress: walletA2.address2, + chainCode: "BCH", + tokenCode: "BCH" + }) + //console.log('Result', result) + } catch (err) { + //console.log('Error', err) + expect(err.json.message).to.equal(config.error.publicAddressFound) + } + }) + + it('confirm DASH address was removed', async () => { + try { + const result = await walletA2.sdk.genericAction('getPublicAddress', { + fioAddress: walletA2.address2, + chainCode: "DASH", + tokenCode: "DASH" + }) + //console.log('Result', result) + } catch (err) { + //console.log('Error', err) + expect(err.json.message).to.equal(config.error.publicAddressFound) + } + }) + + it('confirm FIO address is mapped to walletA2 pub key', async () => { + try { + const result = await walletA2.sdk.genericAction('getPublicAddress', { + fioAddress: walletA2.address2, + chainCode: "FIO", + tokenCode: "FIO" + }) + //console.log('Result', result) + expect(result.public_address).to.equal(walletA2.publicKey) + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + }) describe('B. Transfer an address to FIO Public Key which does not map to existing account on FIO Chain using new endpoint (not push action)', () => { @@ -262,17 +335,16 @@ describe('B. Transfer an address to FIO Public Key which does not map to existin } }) - it(`getFioNames for walletB2. Expect error type ${config.error2.noFioNames.statusCode}: ${config.error.noFioNames}`, async () => { + it(`getFioNames for walletB2. Expect error type: ${config.error.noFioNames}`, async () => { try { const json = { "fio_public_key": walletB2.publicKey } result = await callFioApi("get_fio_names", json); - console.log('getFioNames', result) + //console.log('getFioNames', result) } catch (err) { - //console.log('Error', err) - expect(err.error.message).to.equal(config.error2.noFioNames.message) - expect(err.statusCode).to.equal(config.error2.noFioNames.statusCode); + //console.log('Error', err.error) + expect(err.error.message).to.equal(config.error.noFioNames) } }) @@ -378,7 +450,7 @@ describe('B. Transfer an address to FIO Public Key which does not map to existin } }) - it(`getFioNames for walletA1 and confirm it now only owns 1 address`, async () => { + it(`getFioNames for walletB1 and confirm it now only owns 1 address`, async () => { try { walletB1FioNames = await walletB1.sdk.genericAction('getFioNames', { fioPublicKey: walletB1.publicKey @@ -393,12 +465,13 @@ describe('B. Transfer an address to FIO Public Key which does not map to existin } }) - it(`getFioNames for walletA2 and confirm 2 addresses`, async () => { + it(`getFioNames for walletB2 and confirm 1 address (the new address)`, async () => { try { walletB2FioNames = await walletB1.sdk.genericAction('getFioNames', { fioPublicKey: walletB2.publicKey }) //console.log('getFioNames', walletB2FioNames) + walletB2.address2 = walletB2FioNames.fio_addresses[0].fio_address expect(walletB2FioNames.fio_addresses.length).to.equal(1) expect(walletB2FioNames.fio_addresses[0].fio_address).to.equal(walletB1.address2) } catch (err) { @@ -415,6 +488,49 @@ describe('B. Transfer an address to FIO Public Key which does not map to existin expect(walletB2FioNames.fio_addresses[0].expiration).to.equal(origAddressExpire) }) + it('confirm BCH address was removed', async () => { + try { + const result = await walletB1.sdk.genericAction('getPublicAddress', { + fioAddress: walletB2.address2, + chainCode: "BCH", + tokenCode: "BCH" + }) + //console.log('Result', result) + } catch (err) { + //console.log('Error', err) + expect(err.json.message).to.equal(config.error.publicAddressFound) + } + }) + + it('confirm DASH address was removed', async () => { + try { + const result = await walletB1.sdk.genericAction('getPublicAddress', { + fioAddress: walletB2.address2, + chainCode: "DASH", + tokenCode: "DASH" + }) + //console.log('Result', result) + } catch (err) { + //console.log('Error', err) + expect(err.json.message).to.equal(config.error.publicAddressFound) + } + }) + + it('confirm FIO address is mapped to walletB2 pub key', async () => { + try { + const result = await walletB1.sdk.genericAction('getPublicAddress', { + fioAddress: walletB2.address2, + chainCode: "FIO", + tokenCode: "FIO" + }) + //console.log('Result', result) + expect(result.public_address).to.equal(walletB2.publicKey) + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + }) describe('C. Run get_fee on transfer_fio_address', () => { @@ -717,7 +833,7 @@ describe('D. transferFioAddress Error testing', () => { } }) - it(`Transfer address with insufficient funds and no bundled transactions. Expect error type 400: ${config.error.insufficientFunds}`, async () => { + it(`For Bravo, this will fail because userD3 has OBT transactions. Will need to fix when all xferaddress are enabled. Transfer address with insufficient funds and no bundled transactions. Expect error type 400: ${config.error.insufficientFunds}`, async () => { try { const result = await userD3.sdk.genericAction('transferFioAddress', { fioAddress: userD3.address, @@ -727,10 +843,234 @@ describe('D. transferFioAddress Error testing', () => { }) expect(result.status).to.equal(null); } catch (err) { - //console.log('Error: ', err.json) - expect(err.json.fields[0].error).to.equal(config.error.insufficientFunds) - expect(err.errorCode).to.equal(400); + //console.log('Error: ', err.json.error) + expect(err.json.code).to.equal(500); + //expect(err.json.fields[0].error).to.equal(config.error.insufficientFunds) + //expect(err.json.code).to.equal(400); } }) }) + + +describe('E. Confirm active producers and proxy cannot transfer address', () => { + + let user1, prod1, proxy1, transfer_fio_address_fee + + it(`Create users`, async () => { + user1 = await newUser(faucet); + prod1 = await newUser(faucet); + proxy1 = await newUser(faucet); + }) + + it('Get transfer_fio_address fee', async () => { + try { + result = await user1.sdk.getFee('transfer_fio_address', user1.address); + transfer_fio_address_fee = result.fee; + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Register prod1 as producer`, async () => { + try { + const result = await prod1.sdk.genericAction('pushTransaction', { + action: 'regproducer', + account: 'eosio', + data: { + fio_address: prod1.address, + fio_pub_key: prod1.publicKey, + url: "https://mywebsite.io/", + location: 80, + actor: prod1.account, + max_fee: config.api.register_producer.fee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it(`Transfer prod1.address to user1. Expect error 400: ${config.error.activeProducer}`, async () => { + try { + const result = await prod1.sdk.genericAction('transferFioAddress', { + fioAddress: prod1.address, + newOwnerKey: user1.publicKey, + maxFee: transfer_fio_address_fee, + technologyProviderId: '' + }) + //console.log('Result: ', result) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err.json.fields) + expect(err.json.fields[0].error).to.equal(config.error.activeProducer) + expect(err.errorCode).to.equal(400) + } + }) + + it(`Register proxy1 as a proxy`, async () => { + try { + const result = await proxy1.sdk.genericAction('pushTransaction', { + action: 'regproxy', + account: 'eosio', + data: { + fio_address: proxy1.address, + actor: proxy1.account, + max_fee: config.api.register_proxy.fee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + expect(err).to.equal('null') + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it(`BUG: Transfer proxy1.address to user1. Expect error 400: ${config.error.activeProxy}`, async () => { + try { + const result = await proxy1.sdk.genericAction('transferFioAddress', { + fioAddress: proxy1.address, + newOwnerKey: user1.publicKey, + maxFee: transfer_fio_address_fee, + technologyProviderId: '' + }) + console.log('Result: ', result) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err.json.fields) + expect(err.json.fields[0].error).to.equal(config.error.activeProxy) + expect(err.errorCode).to.equal(400) + } + }) + +}) + + +describe('BRAVO ONLY: Confirm users with OBT records or Requests cannot transfer addresses', () => { + + let user1, user2, user3, user4, transfer_fio_address_fee + + it(`Create users`, async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + user3 = await newUser(faucet); + user4 = await newUser(faucet); + }) + + it('Get transfer_fio_address fee', async () => { + try { + result = await user1.sdk.getFee('transfer_fio_address', user1.address); + transfer_fio_address_fee = result.fee; + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`user1 requests funds from user2`, async () => { + try { + const result = await user1.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user1.address, + payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', + amount: 1000, + chainCode: 'BTC', + tokenCode: 'BTC', + memo: 'requestMemo', + maxFee: config.maxFee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`Transfer user1.address to user2. Expect error 500 - assertion failure with message: Transfering a FIO address is currently disabled for some fio.addresses `, async () => { + try { + const result = await user1.sdk.genericAction('transferFioAddress', { + fioAddress: user1.address, + newOwnerKey: user2.publicKey, + maxFee: transfer_fio_address_fee, + technologyProviderId: '' + }) + //console.log('Result: ', result) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err.json.error.details) + expect(err.json.error.details[0].message).to.equal('assertion failure with message: Transfering a FIO address is currently disabled for some fio.addresses') + expect(err.errorCode).to.equal(500) + } + }) + + it(`Transfer user2.address to user1. Expect error 500 - assertion failure with message: Transfering a FIO address is currently disabled for some fio.addresses`, async () => { + try { + const result = await user2.sdk.genericAction('transferFioAddress', { + fioAddress: user2.address, + newOwnerKey: user1.publicKey, + maxFee: transfer_fio_address_fee, + technologyProviderId: '' + }) + //console.log('Result: ', result) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.error.details[0].message).to.equal('assertion failure with message: Transfering a FIO address is currently disabled for some fio.addresses') + expect(err.errorCode).to.equal(500) + } + }) + + it(`Create OBT for user3`, async () => { + try { + const result = await user3.sdk.genericAction('recordObtData', { + fioRequestId: '', + payerFioAddress: user3.address, + payeeFioAddress: user1.address, + payerTokenPublicAddress: user3.publicKey, + payeeTokenPublicAddress: user1.publicKey, + amount: 5000000000, + chainCode: "BTC", + tokenCode: "BTC", + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user3.publicKey, + memo: 'this is a test' + }) + //console.log('Result: ', result); + expect(result.status).to.equal('sent_to_blockchain'); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`Transfer user3.address to user4. Expect error 500 - assertion failure with message: Transfering a FIO address is currently disabled for some fio.addresses`, async () => { + try { + const result = await user3.sdk.genericAction('transferFioAddress', { + fioAddress: user3.address, + newOwnerKey: user4.publicKey, + maxFee: transfer_fio_address_fee, + technologyProviderId: '' + }) + //console.log('Result: ', result) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.error.details[0].message).to.equal('assertion failure with message: Transfering a FIO address is currently disabled for some fio.addresses') + expect(err.errorCode).to.equal(500) + } + }) + +}) + From 93c3859aae936c6d65ecb2eb103b886131a6ff91 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Sun, 27 Dec 2020 19:31:47 -0700 Subject: [PATCH 23/76] Fix library case --- tests/transfer-address.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/transfer-address.js b/tests/transfer-address.js index d5440369..79ce7af1 100644 --- a/tests/transfer-address.js +++ b/tests/transfer-address.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, generateFioAddress, createKeypair, callFioApi, getFees, fetchJson, timeout} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { From 044e7da0b63f95b917feab56e330cde0635e38de Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Sun, 27 Dec 2020 22:14:50 -0700 Subject: [PATCH 24/76] Fixes for dev branch --- config.js | 4 ---- tests/transfer-address.js | 21 +++++++++++++++++++++ tests/vote.js | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/config.js b/config.js index 86b164f6..2aa3e3ae 100644 --- a/config.js +++ b/config.js @@ -116,10 +116,6 @@ const config = { message: 'FIO Address not found', type: 404 }, - invalidFioAddress: { - message: 'Invalid FIO Address', - type: 400 - }, invalidPublicAddress: { message: 'Invalid public address', type: 400 diff --git a/tests/transfer-address.js b/tests/transfer-address.js index 79ce7af1..33f31ef1 100644 --- a/tests/transfer-address.js +++ b/tests/transfer-address.js @@ -588,6 +588,27 @@ describe('D. transferFioAddress Error testing', () => { } }) + it(`(push_transaction) Transfer address with invalid address format. Expect error code ${config.error2.invalidFioAddress.statusCode}: ${config.error2.invalidFioAddress.message}`, async () => { + try{ + const result = await userD1.sdk.genericAction('pushTransaction', { + action: 'xferaddress', + account: 'fio.address', + data: { + "fio_address": ']invid@domain', + "new_owner_fio_public_key": userD2.publicKey, + "max_fee": config.api.transfer_fio_address.fee, + "tpid": '', + "actor": userD1.account + } + }) + expect(result.status).to.equal(null); + } catch (err) { + //console.log('Error: ', err.json.fields[0].error) + expect(err.json.fields[0].error).to.equal(config.error2.invalidFioAddress.message); + expect(err.errorCode).to.equal(config.error2.invalidFioAddress.statusCode); + } + }) + it(`Transfer address with invalid public key. Expect error type 400: ${config.error.invalidKey}`, async () => { try { const result = await userD1.sdk.genericAction('transferFioAddress', { diff --git a/tests/vote.js b/tests/vote.js index 675af283..c9751f41 100644 --- a/tests/vote.js +++ b/tests/vote.js @@ -261,7 +261,7 @@ describe(`************************** vote.js ************************** \n A. Te }) -describe.only('B. Test vote counts with proxy when proxy increases and decreases funds', () => { +describe('B. Test vote counts with proxy when proxy increases and decreases funds', () => { let proxyB1, voterB1, user1, total_voted_fio, total_bp_votes, transfer_tokens_pub_key_fee From 25e365d9f427b509021f2967f4c9b1741c6e2836 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 28 Dec 2020 17:23:56 -0700 Subject: [PATCH 25/76] Uncomment whitelisting tests --- index.js | 2 +- tests/action-whitelisting.js | 54 ++++++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 2963335a..a43a8d7b 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,7 @@ describe('TEST SUITE', () => { require('./tests/register_fio_domain.js'); // v1.0.x require('./tests/transfer-tokens.js'); // v1.0.x require('./tests/vote.js'); // v1.0.x - //require('./tests/action-whitelisting.js'); // FIP-12, fio v2.0.0, fio.contracts v2.0.0 // Causes future tests to fail. Only run alone. + require('./tests/action-whitelisting.js'); // FIP-12, fio v2.0.0, fio.contracts v2.0.0 // Causes future tests to fail. Only run alone. require('./tests/transfer-domain.js'); // FIP-1.a, fio v2.0.0, fio.contracts v2.1.0 require('./tests/paging.js'); // FIP-2, fio v2.0.0, fio.contracts v2.1.0 require('./tests/removeaddress.js'); // FIP-4, fio v2.0.0, fio.contracts v2.1.0 diff --git a/tests/action-whitelisting.js b/tests/action-whitelisting.js index 29bcaa4a..311c2aad 100644 --- a/tests/action-whitelisting.js +++ b/tests/action-whitelisting.js @@ -384,25 +384,67 @@ describe(`C. Test addaction error conditions`, () => { describe(`D. General remaction testing `, () => { - it(`remaction succeeds.`, async () => { - try { + let newAction, newContract + + it(`Create users`, async () => { + newAction = generateFioDomain(7); + newContract = generateFioDomain(7); + }) + + it('addaction with random action and contract name succeeds.', async () => { const result = await callFioApiSigned('push_transaction', { - action: 'remaction', + action: 'addaction', account: 'eosio', actor: fiotoken.account, privKey: fiotoken.privateKey, data: { action: newAction, - actor: fiotoken.account + contract: newContract, + actor: fiotoken.account, } }) - expect(result.processed.receipt.status).to.equal('executed'); + //console.log('Result: ', result) + expect(result.processed.receipt.status).to.equal('executed'); + }) + + it(`remaction of new action succeeds.`, async () => { + try { + const result = await callFioApiSigned('push_transaction', { + action: 'remaction', + account: 'eosio', + actor: fiotoken.account, + privKey: fiotoken.privateKey, + data: { + action: newAction, + actor: fiotoken.account + } + }) + expect(result.processed.receipt.status).to.equal('executed'); } catch (err) { console.log('Error', err); expect(err).to.equal(null); } }) + it(`remaction of same action fails`, async () => { + try { + const result = await callFioApiSigned('push_transaction', { + action: 'remaction', + account: 'eosio', + actor: fiotoken.account, + privKey: fiotoken.privateKey, + data: { + action: newAction, + actor: fiotoken.account + } + }) + console.log('Result', result); + //expect(result.processed.receipt.status).to.equal('executed'); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) it('Call get_actions and confirm action is gone', async () => { try { @@ -425,7 +467,7 @@ describe(`D. General remaction testing `, () => { } }) - it(`remaction fails, action not found.`, async () => { + it(`remaction of non-existent action fails, action not found.`, async () => { try { const result = await callFioApiSigned('push_transaction', { action: 'remaction', From 2a8248d2bd4830afd1a192a67983ffc6d9448eb5 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 28 Dec 2020 17:45:09 -0700 Subject: [PATCH 26/76] whitelisting fix --- tests/action-whitelisting.js | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/tests/action-whitelisting.js b/tests/action-whitelisting.js index 311c2aad..d42dad6e 100644 --- a/tests/action-whitelisting.js +++ b/tests/action-whitelisting.js @@ -438,8 +438,8 @@ describe(`D. General remaction testing `, () => { actor: fiotoken.account } }) - console.log('Result', result); - //expect(result.processed.receipt.status).to.equal('executed'); + //console.log('Result', result); + expect(result.error.what).to.equal('Duplicate transaction'); } catch (err) { console.log('Error', err); expect(err).to.equal(null); @@ -487,29 +487,6 @@ describe(`D. General remaction testing `, () => { expect(err).to.equal(null); } }) - - it(`remaction with 13 character action. Returns Error: ${config.error2.invalidAction.type}: ${config.error2.invalidAction.message}`, async () => { - try { - const result = await callFioApiSigned('push_transaction', { - action: 'remaction', - account: 'eosio', - actor: fiotoken.account, - privKey: fiotoken.privateKey, - data: { - action: action_13, - contract: newContract, - actor: fiotoken.account - } - }) - - //console.log('Result: ', result.error.details) - expect(result.error.details[0].message).to.equal(config.error2.invalidAction.message); - expect(result.code).to.equal(config.error2.invalidAction.type); - } catch (err) { - console.log('Error: ', err) - } - }) - it(`remaction with invalid actor. Returns Error: ${config.error2.invalidActor.type}: ${config.error2.invalidActor.message}`, async () => { const result = await callFioApiSigned('push_transaction', { action: 'remaction', From 00095544aee80d6e5ad89256cdc8550e8c14c494 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 28 Dec 2020 20:27:29 -0700 Subject: [PATCH 27/76] Port of bravo updates --- config.js | 60 ++- index.js | 2 + tests/addbundles.js | 776 ++++++++++++++++++++++++++++++++++++++ tests/bravo-migr-test.js | 2 +- tests/burn-address.js | 137 ++++++- tests/fio-request.js | 2 +- tests/removeaddress.js | 22 +- tests/transfer-address.js | 29 +- 8 files changed, 984 insertions(+), 46 deletions(-) create mode 100644 tests/addbundles.js diff --git a/config.js b/config.js index 2aa3e3ae..3aaf3d76 100644 --- a/config.js +++ b/config.js @@ -25,6 +25,7 @@ const config = { FUNDS: 3000000000000, BILLION: 1000000000, maxFee: 800000000000, + defaultBundleCount: 100, error: { validationError: 'ValidationError', @@ -88,6 +89,10 @@ const config = { message: 'FIO Address not found', statusCode: 404 }, + feeExceedsMax: { + message: 'Fee exceeds supplied maximum.', + statusCode: 400 + }, invalidFioAddress: { message: 'Invalid FIO Address', statusCode: 400 @@ -108,49 +113,41 @@ const config = { message: 'Request signature is not valid or this user is not allowed to sign this transaction.', statusCode: 403 }, - noFioNames: { - message: 'No FIO names', - type: 404 - }, - addressNotFound: { - message: 'FIO Address not found', - type: 404 - }, - invalidPublicAddress: { - message: 'Invalid public address', - type: 400 - }, - invalidTpid: { - message: 'TPID must be empty or valid FIO address', - type: 400 - }, - invalidActor: { - message: 'Invalid Actor', - type: 403 - }, - invalidSignature: { - message: 'Request signature is not valid or this user is not allowed to sign this transaction.', - type: 403 - }, invalidAction: { message: 'Action invalid or not found', - type: 500 + statusCode: 500 }, invalidContract: { message: 'Invalid Contract', - type: 500 + statusCode: 500 }, - invalidActor: { + invalidActorAuth: { message: 'Missing required authority', - type: 500 + statusCode: 500 }, accountExists: { message: 'Account name already exists', - type: 500 + statusCode: 500 }, noActions: { message: 'No actions', - type: 404 + statusCode: 404 + }, + invalidBundleSets: { + message: 'Invalid bundle_sets value', + statusCode: 400 + }, + invalidFeeValue: { + message: 'Invalid fee value', + statusCode: 400 + }, + insufficientFunds: { + message: 'Insufficient funds to cover fee', + statusCode: 400 + }, + fioAddressNotRegistered: { + message: 'FIO Address not registered', + statusCode: 400 } }, @@ -332,7 +329,8 @@ const config = { UPDATEAUTHRAM: 1024, XFERDOMAINRAM: 512, XFERADDRESSRAM: 512, - CANCELFUNDSRAM: 512 + CANCELFUNDSRAM: 512, + BUNDLEVOTERAM: 0 }, public_addresses: [ diff --git a/index.js b/index.js index a43a8d7b..4dc1b15e 100644 --- a/index.js +++ b/index.js @@ -27,6 +27,8 @@ describe('TEST SUITE', () => { require('./tests/transfer-address.js'); // FIP-1.b require('./tests/transfer-locked-tokens.js'); // FIP-6 locking tests require('./tests/transfer-locked-tokens-account-tests.js'); // FIP-6 tests of generic account functionality + require('./tests/addbundles.js'); + //require('./tests/clio.js'); // FIP-16 //require('./tests/locks.js'); // Depends on local wallet. Need to fix diff --git a/tests/addbundles.js b/tests/addbundles.js new file mode 100644 index 00000000..61856683 --- /dev/null +++ b/tests/addbundles.js @@ -0,0 +1,776 @@ +require('mocha') +const {expect} = require('chai') +const {newUser, fetchJson, timeout, callFioApi} = require('../utils.js'); +const {FIOSDK } = require('@fioprotocol/FIOSDK') +config = require('../config.js'); + +before(async () => { + faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); +}) + +describe('************************** addbundles.js ************************** \n A. Add 1 set of bundled transactions for FIO Address owned by signer.', () => { + + let user1, user1OrigBalance, user1OrigRam, add_bundled_transactions_fee, feeCollected + let bundledVoteNumber = config.defaultBundleCount; + let bundleSets = 1; + + it(`Create users`, async () => { + user1 = await newUser(faucet); + }) + + it('Get add_bundled_transactions_fee', async () => { + try { + result = await user1.sdk.getFee('add_bundled_transactions', user1.address); + add_bundled_transactions_fee = result.fee; + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Get bundledbvotenumber from bundlevoters table`, async () => { + try { + const json = { + json: true, + code: 'fio.fee', + scope: 'fio.fee', + table: 'bundlevoters', + limit: 10, + reverse: false, + show_payer: false + } + result = await callFioApi("get_table_rows", json); + if (result.rows.length != 0) { + bundledVoteNumber = result.rows[0].bundledbvotenumber; + } + //console.log('bundledVoteNumber: ', bundledVoteNumber); + expect(bundledVoteNumber).to.greaterThan(0); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Get balance for user1`, async () => { + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + user1OrigBalance = result.balance + //console.log('user1 fio balance', result) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Get RAM quota for user1`, async () => { + try { + const json = { + "account_name": user1.account + } + result = await callFioApi("get_account", json); + user1OrigRam = result.ram_quota; + //console.log('Ram quota: ', result.ram_quota); + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Get bundle count for user1 from fionames table`, async () => { + try { + const json = { + json: true, + code: 'fio.address', + scope: 'fio.address', + table: 'fionames', + limit: 100, + reverse: true, + show_payer: false + } + fionames = await callFioApi("get_table_rows", json); + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == user1.address) { + user1BundleCount = fionames.rows[fioname].bundleeligiblecountdown; + } + } + //console.log('user1BundleCount: ', user1BundleCount); + expect(bundledVoteNumber).to.greaterThan(0); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it.skip(`(SDK) Run /add_bundled_transactions with 1 set for FIO Address owned by signer`, async () => { + try { + const result = await user1.sdk.genericAction('addBundledTransactions', { + fioAddress: user1.address, + bundleSets: 1, + maxFee: add_bundled_transactions_fee, + tpid: '' + }) + //console.log('Result:', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error', err) + //expect(err).to.equal(null) + } + }) + + it(`(push_transaction) Run addbundles with ${bundleSets} sets for FIO Address owned by other user`, async () => { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'addbundles', + account: 'fio.address', + data: { + fio_address: user1.address, + bundle_sets: bundleSets, + max_fee: add_bundled_transactions_fee * bundleSets, + tpid: '' + } + }) + feeCollected = result.fee_collected; + //console.log('Result: ', result); + expect(result.status).to.equal('OK'); + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } + }) + + it(`Confirm fee collected = ${bundleSets} * add_bundled_transactions_fee`, async () => { + expect(feeCollected).to.equal(add_bundled_transactions_fee * bundleSets) + }) + + it('Confirm fee was deducted from user1 account', async () => { + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + expect(result.balance).to.equal(user1OrigBalance - feeCollected) + //console.log('user1 fio balance', result) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Confirm RAM quota for user1 was incremented by ${config.RAM.BUNDLEVOTERAM}`, async () => { + try { + const json = { + "account_name": user1.account + } + result = await callFioApi("get_account", json); + //console.log('Ram quota: ', result.ram_quota); + expect(result.ram_quota).to.equal(user1OrigRam + config.RAM.BUNDLEVOTERAM); + } catch (err) { + //console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Confirm bundle count was increased by ${bundleSets} set`, async () => { + let prevBundleCount = user1BundleCount; + try { + const json = { + json: true, + code: 'fio.address', + scope: 'fio.address', + table: 'fionames', + limit: 100, + reverse: true, + show_payer: false + } + fionames = await callFioApi("get_table_rows", json); + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == user1.address) { + user1BundleCount = fionames.rows[fioname].bundleeligiblecountdown; + } + } + //console.log('user1BundleCount: ', user1BundleCount); + expect(user1BundleCount).to.equal(prevBundleCount + (bundleSets * bundledVoteNumber)); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) + +describe('B. Add 3 sets of bundled transactions for FIO Address owned by other user.', () => { + + let user1, user2, user1BundleCount, user2BundleCount, user1OrigBalance, user2OrigBalance, user1OrigRam, add_bundled_transactions_fee, feeCollected + let bundledVoteNumber = config.defaultBundleCount; + let bundleSets = 3; + + it(`Create users`, async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + }) + + it('Get add_bundled_transactions_fee', async () => { + try { + result = await user1.sdk.getFee('add_bundled_transactions', user1.address); + add_bundled_transactions_fee = result.fee; + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Get bundledbvotenumber from bundlevoters table`, async () => { + try { + const json = { + json: true, + code: 'fio.fee', + scope: 'fio.fee', + table: 'bundlevoters', + limit: 10, + reverse: false, + show_payer: false + } + result = await callFioApi("get_table_rows", json); + if (result.rows.length != 0) { + bundledVoteNumber = result.rows[0].bundledbvotenumber; + } + //console.log('bundledVoteNumber: ', bundledVoteNumber); + expect(bundledVoteNumber).to.greaterThan(0); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Get balance for user1`, async () => { + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + user1OrigBalance = result.balance + //console.log('user1 fio balance', result) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Get balance for user2`, async () => { + try { + const result = await user2.sdk.genericAction('getFioBalance', { + fioPublicKey: user2.publicKey + }) + user2OrigBalance = result.balance + //console.log('user1 fio balance', result) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Get RAM quota for user1`, async () => { + try { + const json = { + "account_name": user1.account + } + result = await callFioApi("get_account", json); + user1OrigRam = result.ram_quota; + //console.log('Ram quota: ', result.ram_quota); + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Get bundle count for user1 from fionames table`, async () => { + try { + const json = { + json: true, + code: 'fio.address', + scope: 'fio.address', + table: 'fionames', + limit: 100, + reverse: true, + show_payer: false + } + fionames = await callFioApi("get_table_rows", json); + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == user1.address) { + user1BundleCount = fionames.rows[fioname].bundleeligiblecountdown; + } + } + //console.log('user1BundleCount: ', user1BundleCount); + expect(user1BundleCount).to.greaterThan(0); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Get bundle count for user2 from fionames table`, async () => { + try { + const json = { + json: true, + code: 'fio.address', + scope: 'fio.address', + table: 'fionames', + limit: 100, + reverse: true, + show_payer: false + } + fionames = await callFioApi("get_table_rows", json); + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == user2.address) { + user2BundleCount = fionames.rows[fioname].bundleeligiblecountdown; + } + } + //console.log('user1BundleCount: ', user1BundleCount); + expect(user2BundleCount).to.greaterThan(0); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it.skip(`(SDK) Run /add_bundled_transactions with 1 set for FIO Address owned by other user`, async () => { + try { + const result = await user1.sdk.genericAction('addBundledTransactions', { + fioAddress: user1.address, + bundleSets: bundleSets, + maxFee: add_bundled_transactions_fee, + technologyProviderId: '' + }) + //console.log('Result:', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error', err) + //expect(err).to.equal(null) + } + }) + + it(`BUG: (push_transaction) user1 run addbundles with ${bundleSets} sets for FIO Address owned by user2`, async () => { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'addbundles', + account: 'fio.address', + data: { + fio_address: user2.address, + bundle_sets: bundleSets, + max_fee: add_bundled_transactions_fee * bundleSets, + technologyProviderId: '' + } + }) + feeCollected = result.fee_collected; + //console.log('Result: ', result); + expect(result.status).to.equal('OK'); + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } + }) + + it(`Confirm fee collected = ${bundleSets} * add_bundled_transactions_fee`, async () => { + expect(feeCollected).to.equal(add_bundled_transactions_fee * bundleSets) + }) + + it('Confirm fee was deducted from user1 account', async () => { + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + expect(result.balance).to.equal(user1OrigBalance - feeCollected) + //console.log('user1 fio balance', result) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it('Confirm user2 account balance is unchanged', async () => { + try { + const result = await user2.sdk.genericAction('getFioBalance', { + fioPublicKey: user2.publicKey + }) + expect(result.balance).to.equal(user2OrigBalance) + //console.log('user1 fio balance', result) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Confirm RAM quota for user1 was incremented by ${config.RAM.BUNDLEVOTERAM}`, async () => { + try { + const json = { + "account_name": user1.account + } + result = await callFioApi("get_account", json); + //console.log('Ram quota: ', result.ram_quota); + expect(result.ram_quota).to.equal(user1OrigRam + config.RAM.BUNDLEVOTERAM); + } catch (err) { + //console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Confirm user1 bundle count is unchanged`, async () => { + let prevBundleCount = user1BundleCount; + try { + const json = { + json: true, + code: 'fio.address', + scope: 'fio.address', + table: 'fionames', + limit: 100, + reverse: true, + show_payer: false + } + fionames = await callFioApi("get_table_rows", json); + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == user1.address) { + user1BundleCount = fionames.rows[fioname].bundleeligiblecountdown; + } + } + //console.log('user1BundleCount: ', user1BundleCount); + expect(user1BundleCount).to.equal(prevBundleCount); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Confirm user2 bundle count was increased by ${bundleSets} sets`, async () => { + let prevBundleCount = user2BundleCount; + try { + const json = { + json: true, + code: 'fio.address', + scope: 'fio.address', + table: 'fionames', + limit: 100, + reverse: true, + show_payer: false + } + fionames = await callFioApi("get_table_rows", json); + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == user2.address) { + user2BundleCount = fionames.rows[fioname].bundleeligiblecountdown; + } + } + //console.log('user2BundleCount: ', user2BundleCount); + expect(user2BundleCount).to.equal(prevBundleCount + (bundleSets * bundledVoteNumber)); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) + +describe('C. Error testing', () => { + let user1, user2, add_bundled_transactions_fee, user1Balance + let bundleSets = 1; + + it(`Create users`, async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + }) + + it('Get add_bundled_transactions_fee', async () => { + try { + result = await user1.sdk.getFee('add_bundled_transactions', user1.address); + add_bundled_transactions_fee = result.fee; + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Run addbundles with invalid FIO Address format. Expect error type ${config.error2.invalidFioAddress.statusCode}: ${config.error2.invalidFioAddress.message}`, async () => { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'addbundles', + account: 'fio.address', + data: { + fio_address: '[#invalid@address', + bundle_sets: bundleSets, + max_fee: add_bundled_transactions_fee, + tpid: '' + } + }) + console.log('Result: ', result); + expect(result.status).to.equal(null); + } catch (err) { + //console.log('Error: ', err.json.fields); + expect(err.json.fields[0].error).to.equal(config.error2.invalidFioAddress.message) + expect(err.errorCode).to.equal(config.error2.invalidFioAddress.statusCode); + } + }) + + it(`Run addbundles with non-existent FIO Address. Expect error type ${config.error2.fioAddressNotRegistered.statusCode}: ${config.error2.fioAddressNotRegistered.message}`, async () => { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'addbundles', + account: 'fio.address', + data: { + fio_address: 'nonexistent@address', + bundle_sets: bundleSets, + max_fee: add_bundled_transactions_fee * bundleSets, + tpid: '' + } + }) + console.log('Result: ', result); + expect(result.status).to.equal(null); + } catch (err) { + //console.log('Error: ', err.json.fields); + expect(err.json.fields[0].error).to.equal(config.error2.fioAddressNotRegistered.message) + expect(err.errorCode).to.equal(config.error2.fioAddressNotRegistered.statusCode); + } + }) + + it.skip(`BUG: Run addbundles with bundle_sets = 0. Expect error type ${config.error2.invalidBundleSets.statusCode}: ${config.error2.invalidBundleSets.message}`, async () => { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'addbundles', + account: 'fio.address', + data: { + fio_address: user1.address, + bundle_sets: 0, + max_fee: add_bundled_transactions_fee * bundleSets, + tpid: '' + } + }) + console.log('Result: ', result); + expect(result.status).to.equal(null); + } catch (err) { + console.log('Error: ', err.json.fields); + expect(err.json.fields[0].error).to.equal(config.error2.invalidBundleSets.message) + expect(err.errorCode).to.equal(config.error2.invalidBundleSets.statusCode); + } + }) + + it(`Run addbundles with bundle_sets = -1. Expect error type ${config.error2.invalidBundleSets.statusCode}: ${config.error2.invalidBundleSets.message}`, async () => { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'addbundles', + account: 'fio.address', + data: { + fio_address: user1.address, + bundle_sets: -1, + max_fee: add_bundled_transactions_fee * bundleSets, + tpid: '' + } + }) + console.log('Result: ', result); + expect(result.status).to.equal(null); + } catch (err) { + //console.log('Error: ', err.json.fields); + expect(err.json.fields[0].error).to.equal(config.error2.invalidBundleSets.message) + expect(err.errorCode).to.equal(config.error2.invalidBundleSets.statusCode); + } + }) + + it(`Attempt addbundles with invalid fee format. Expect error type ${config.error2.invalidFeeValue.statusCode}: ${config.error2.invalidFeeValue.message}`, async () => { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'addbundles', + account: 'fio.address', + data: { + fio_address: user1.address, + bundle_sets: bundleSets, + max_fee: -1, + tpid: '' + } + }) + console.log('Result: ', result); + expect(result.status).to.equal(null); + } catch (err) { + //console.log('Error: ', err); + expect(err.json.fields[0].error).to.equal(config.error2.invalidFeeValue.message) + expect(err.errorCode).to.equal(config.error2.invalidFeeValue.statusCode); + } + }) + + it(`Attempt addbundles with invalid TPID. Expect error type ${config.error2.invalidTpid.statusCode}: ${config.error2.invalidTpid.message}`, async () => { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'addbundles', + account: 'fio.address', + data: { + fio_address: user1.address, + bundle_sets: bundleSets, + max_fee: add_bundled_transactions_fee * bundleSets, + tpid: '##invalidtpid##' + } + }) + console.log('Result: ', result); + expect(result.status).to.equal(null); + } catch (err) { + //console.log('Error: ', err); + expect(err.json.fields[0].error).to.equal(config.error2.invalidTpid.message) + expect(err.errorCode).to.equal(config.error2.invalidTpid.statusCode); + } + }) + + it(`Use up all of user1's bundles with 51 record_obt_data transactions`, async () => { + for (i = 0; i < 51; i++) { + try { + const result = await user1.sdk.genericAction('recordObtData', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payerTokenPublicAddress: user1.publicKey, + payeeTokenPublicAddress: user2.publicKey, + amount: 5000000000, + chainCode: "BTC", + tokenCode: "BTC", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user2.publicKey, + memo: 'this is a test' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) + + it(`Add public addresses to user1 to use up one more bundle`, async () => { + try { + const result = await user1.sdk.genericAction('addPublicAddresses', { + fioAddress: user1.address, + publicAddresses: [ + { + chain_code: 'ETH', + token_code: 'ETH', + public_address: 'ethaddress', + } + ], + maxFee: config.api.add_pub_address.fee, + walletFioAddress: '' + }) + //console.log('Result:', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it('Call get_table_rows from fionames to get bundles remaining for user1. Verify 0 bundles', async () => { + let bundleCount + try { + const json = { + json: true, // Get the response as json + code: 'fio.address', // Contract that we target + scope: 'fio.address', // Account that owns the data + table: 'fionames', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + fionames = await callFioApi("get_table_rows", json); + //console.log('fionames: ', fionames); + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == user1.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); + bundleCount = fionames.rows[fioname].bundleeligiblecountdown; + } + } + expect(bundleCount).to.equal(0); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Attempt addbundles with fee lower than actual fee amount and no bundled transactions left. Expect error type ${config.error2.feeExceedsMax.statusCode}: ${config.error2.feeExceedsMax.message}`, async () => { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'addbundles', + account: 'fio.address', + data: { + fio_address: user1.address, + bundle_sets: bundleSets, + max_fee: add_bundled_transactions_fee - 100000000, + tpid: '' + } + }) + console.log('Result: ', result); + expect(result.status).to.equal(null); + } catch (err) { + //console.log('Error: ', err); + expect(err.json.fields[0].error).to.equal(config.error2.feeExceedsMax.message) + expect(err.errorCode).to.equal(config.error2.feeExceedsMax.statusCode); + } + }) + + it(`Get balance for user1`, async () => { + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + user1Balance = result.balance + //console.log('user1 fio balance', result) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it('Transfer entire balance for user1 to user2', async () => { + try { + const result = await user1.sdk.genericAction('transferTokens', { + payeeFioPublicKey: user2.publicKey, + amount: user1Balance - config.api.transfer_tokens_pub_key.fee, + maxFee: config.maxFee, + technologyProviderId: '' + }) + //console.log('Result: ', result) + expect(result).to.have.all.keys('transaction_id', 'block_num', 'status', 'fee_collected') + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } + }) + + it(`Verify balance for user1 = 0`, async () => { + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + //console.log('user1 fio balance', result) + expect(result.balance).to.equal(0) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Attempt addbundles with insufficient funds to cover fee. Expect error type ${config.error2.insufficientFunds.statusCode}: ${config.error2.insufficientFunds.message}`, async () => { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'addbundles', + account: 'fio.address', + data: { + fio_address: user1.address, + bundle_sets: bundleSets, + max_fee: add_bundled_transactions_fee * bundleSets, + tpid: '' + } + }) + console.log('Result: ', result); + expect(result.status).to.equal(null); + } catch (err) { + //console.log('Error: ', err); + expect(err.json.fields[0].error).to.equal(config.error2.insufficientFunds.message) + expect(err.errorCode).to.equal(config.error2.insufficientFunds.statusCode); + } + }) + +}) \ No newline at end of file diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index 638c5512..41de1f57 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -1,5 +1,5 @@ /***** - This test loads up the chain with 1000 Requests and 10000 OBTs and then: + This test loads up the chain with 1000 Requests and 1000 OBTs and then: - Calls migrtx - After the first call, tests that new requests and OBTs are being added to both tables. - Repeatedly calls migrtrx to complete migration. diff --git a/tests/burn-address.js b/tests/burn-address.js index cb312e0c..f8b4cd2b 100644 --- a/tests/burn-address.js +++ b/tests/burn-address.js @@ -1,6 +1,6 @@ require('mocha') const {expect} = require('chai') -const {newUser, generateFioAddress, callFioApiSigned, callFioApi, getFees, fetchJson} = require('../utils.js'); +const {newUser, generateFioAddress, callFioApiSigned, callFioApi, getFees, timeout, fetchJson} = require('../utils.js'); const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); @@ -666,3 +666,138 @@ describe('E. Test burnfioaddress SDK call (uses chain/burn_fio_address endpoint) } }) }) + +describe('F. Confirm active producers and proxy cannot burn address', () => { + + let user1, prod1, proxy1, burn_fio_address_fee + + it(`Create users`, async () => { + user1 = await newUser(faucet); + prod1 = await newUser(faucet); + proxy1 = await newUser(faucet); + }) + + it('Get transfer_fio_address fee', async () => { + try { + result = await user1.sdk.getFee('burn_fio_address', user1.address); + burn_fio_address_fee = result.fee; + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Register prod1 as producer`, async () => { + try { + const result = await prod1.sdk.genericAction('pushTransaction', { + action: 'regproducer', + account: 'eosio', + data: { + fio_address: prod1.address, + fio_pub_key: prod1.publicKey, + url: "https://mywebsite.io/", + location: 80, + actor: prod1.account, + max_fee: config.api.register_producer.fee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it(`Burn prod1.address. Expect error 400: ${config.error.activeProducer}`, async () => { + try{ + const result = await prod1.sdk.genericAction('pushTransaction', { + action: 'burnaddress', + account: 'fio.address', + data: { + "fio_address": prod1.address, + "max_fee": burn_fio_address_fee, + "tpid": '', + "actor": prod1.account + } + }) + expect(result.status).to.equal(null); + } catch (err) { + //console.log('Error: ', err) + expect(err.json.fields[0].error).to.equal(config.error.activeProducer); + expect(err.errorCode).to.equal(400); + } + }) + + it(`Register proxy1 as a proxy`, async () => { + try { + const result = await proxy1.sdk.genericAction('pushTransaction', { + action: 'regproxy', + account: 'eosio', + data: { + fio_address: proxy1.address, + actor: proxy1.account, + max_fee: config.api.register_proxy.fee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + expect(err).to.equal('null') + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it('Confirm is_proxy = 1 for proxy1 ', async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: true, + show_payer: false + } + voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voters); + for (voter in voters.rows) { + if (voters.rows[voter].owner == proxy1.account) { + //console.log('voters.rows[voter]: ', voters.rows[voter]); + break; + } + } + expect(voters.rows[voter].owner).to.equal(proxy1.account); + expect(voters.rows[voter].is_proxy).to.equal(1); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + + it(`Burn proxy1.address. Expect error 400: ${config.error.activeProxy}`, async () => { + try{ + const result = await proxy1.sdk.genericAction('pushTransaction', { + action: 'burnaddress', + account: 'fio.address', + data: { + "fio_address": proxy1.address, + "max_fee": burn_fio_address_fee, + "tpid": '', + "actor": proxy1.account + } + }) + console.log('Result: ', result) + expect(result.status).to.equal(null); + } catch (err) { + //console.log('Error: ', err) + expect(err.json.fields[0].error).to.equal(config.error.activeProxy); + expect(err.errorCode).to.equal(400); + } + }) + +}) \ No newline at end of file diff --git a/tests/fio-request.js b/tests/fio-request.js index 0460d5ac..43f5a525 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -1826,7 +1826,7 @@ describe(`F. get_cancelled_fio_requests paging: Cancel multiple FIO requests and }) -describe.skip(`************************** fio-request.js ************************** \n G. Records Performance Testing`, () => { +describe.skip(`G. Records Performance Testing`, () => { let userA1, userA2, userB1, userB2, userC1, userC2 const payment = 5000000000 // 5 FIO diff --git a/tests/removeaddress.js b/tests/removeaddress.js index 3945aa4f..b7a53cfd 100644 --- a/tests/removeaddress.js +++ b/tests/removeaddress.js @@ -1131,7 +1131,7 @@ describe(`F. Sad - result in error`, () => { expect(result.fields[0].error).to.equal(config.error2.invalidFioAddress.message); }) - it(`Fixed in BD-1955, Remove with invalid FIO Address - push transaction. Expect error type ${config.error2.invalidFioAddress.type}: ${config.error2.invalidFioAddress.message}`, async () => { + it(`Fixed in BD-1955, Remove with invalid FIO Address - push transaction. Expect error type ${config.error2.invalidFioAddress.statusCode}: ${config.error2.invalidFioAddress.message}`, async () => { try{ const result = await userA1.sdk.genericAction('pushTransaction', { action: 'remaddress', @@ -1149,11 +1149,11 @@ describe(`F. Sad - result in error`, () => { } catch (err) { //console.log('Error: ', err.json) expect(err.json.fields[0].error).to.equal(config.error2.invalidFioAddress.message) - expect(err.errorCode).to.equal(config.error2.invalidFioAddress.type); + expect(err.errorCode).to.equal(config.error2.invalidFioAddress.statusCode); } }) - it(`Remove invalid public addresses. Expect error type ${config.error2.invalidPublicAddress.type}: ${config.error2.invalidPublicAddress.message}`, async () => { + it(`Remove invalid public addresses. Expect error type ${config.error2.invalidPublicAddress.statusCode}: ${config.error2.invalidPublicAddress.message}`, async () => { try { const result = await userA1.sdk.genericAction('pushTransaction', { action: 'remaddress', @@ -1181,11 +1181,11 @@ describe(`F. Sad - result in error`, () => { } catch (err) { //console.log('Err: ', err.json); expect(err.json.fields[0].error).to.equal(config.error2.invalidPublicAddress.message) - expect(err.errorCode).to.equal(config.error2.invalidPublicAddress.type); + expect(err.errorCode).to.equal(config.error2.invalidPublicAddress.statusCode); } }) - it(`Remove with invalid TPID. Expect error type ${config.error2.invalidTpid.type}: ${config.error2.invalidTpid.message}`, async () => { + it(`Remove with invalid TPID. Expect error type ${config.error2.invalidTpid.statusCode}: ${config.error2.invalidTpid.message}`, async () => { try{ const result = await userA1.sdk.genericAction('pushTransaction', { action: 'remaddress', @@ -1213,11 +1213,11 @@ describe(`F. Sad - result in error`, () => { expect(result.status).to.equal(null); } catch (err) { expect(err.json.fields[0].error).to.equal(config.error2.invalidTpid.message) - expect(err.errorCode).to.equal(config.error2.invalidTpid.type); + expect(err.errorCode).to.equal(config.error2.invalidTpid.statusCode); } }) - it(`Remove with invalid actor - Direct API call. Expect error type ${config.error2.invalidActor.type}: ${config.error2.invalidActor.message}`, async () => { + it(`Remove with invalid actor - Direct API call. Expect error type ${config.error2.invalidActorAuth.statusCode}: ${config.error2.invalidActorAuth.message}`, async () => { const result = await callFioApiSigned('push_transaction', { action: 'remaddress', account: 'fio.address', @@ -1243,8 +1243,8 @@ describe(`F. Sad - result in error`, () => { } }) //console.log('Result: ', result) - expect(result.error.what).to.equal(config.error2.invalidActor.message) - expect(result.code).to.equal(config.error2.invalidActor.type); + expect(result.error.what).to.equal(config.error2.invalidActorAuth.message) + expect(result.code).to.equal(config.error2.invalidActorAuth.statusCode); }) it(`Not a bug. SDK generates the actor from the userA1 private key. So, this will work.`, async () => { @@ -1288,7 +1288,7 @@ describe(`F. Sad - result in error`, () => { } }) - it(`userA2 tries to remove userA1s public addresses. Expect error type ${config.error2.invalidSignature.type}: ${config.error2.invalidSignature.message}`, async () => { + it(`userA2 tries to remove userA1s public addresses. Expect error type ${config.error2.invalidSignature.statusCode}: ${config.error2.invalidSignature.message}`, async () => { try{ const result = await userA2.sdk.genericAction('pushTransaction', { action: 'remaddress', @@ -1305,7 +1305,7 @@ describe(`F. Sad - result in error`, () => { } catch (err) { //console.log('Error', err) expect(err.json.message).to.equal(config.error2.invalidSignature.message) - expect(err.errorCode).to.equal(config.error2.invalidSignature.type); + expect(err.errorCode).to.equal(config.error2.invalidSignature.statusCode); } }) diff --git a/tests/transfer-address.js b/tests/transfer-address.js index 33f31ef1..bcf46347 100644 --- a/tests/transfer-address.js +++ b/tests/transfer-address.js @@ -955,7 +955,34 @@ describe('E. Confirm active producers and proxy cannot transfer address', () => it(`Wait a few seconds.`, async () => { await timeout(3000) }) - it(`BUG: Transfer proxy1.address to user1. Expect error 400: ${config.error.activeProxy}`, async () => { + it('Confirm is_proxy = 1 for proxy1 ', async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: true, + show_payer: false + } + voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voters); + for (voter in voters.rows) { + if (voters.rows[voter].owner == proxy1.account) { + //console.log('voters.rows[voter]: ', voters.rows[voter]); + break; + } + } + expect(voters.rows[voter].owner).to.equal(proxy1.account); + expect(voters.rows[voter].is_proxy).to.equal(1); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Transfer proxy1.address to user1. Expect error 400: ${config.error.activeProxy}`, async () => { try { const result = await proxy1.sdk.genericAction('transferFioAddress', { fioAddress: proxy1.address, From 983a372ba9e7a4aa23aab2283819d87c17c29eee Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 28 Dec 2020 21:13:04 -0700 Subject: [PATCH 28/76] Add tpid test --- index.js | 2 +- tests/tpid.js | 821 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 822 insertions(+), 1 deletion(-) create mode 100644 tests/tpid.js diff --git a/index.js b/index.js index 4dc1b15e..9dd9f5f2 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,7 @@ describe('TEST SUITE', () => { require('./tests/transfer-locked-tokens.js'); // FIP-6 locking tests require('./tests/transfer-locked-tokens-account-tests.js'); // FIP-6 tests of generic account functionality require('./tests/addbundles.js'); - + require('./tests/tpid.js'); //require('./tests/clio.js'); // FIP-16 //require('./tests/locks.js'); // Depends on local wallet. Need to fix diff --git a/tests/tpid.js b/tests/tpid.js new file mode 100644 index 00000000..f5455e53 --- /dev/null +++ b/tests/tpid.js @@ -0,0 +1,821 @@ +require('mocha') +const {expect} = require('chai') +const {newUser, existingUser, callFioApi, generateFioDomain, generateFioAddress, createKeypair, timeout, fetchJson} = require('../utils.js'); +const {FIOSDK } = require('@fioprotocol/FIOSDK'); +const config = require('../config.js'); + +before(async () => { + faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson) +}) + +describe(`************************** tpid.js ************************** \n TPID Tests`, () => { + + let proxy1, user1, user2, user3, user4, newPubKey + + it(`Create users`, async () => { + proxy1 = await newUser(faucet); + user1 = await newUser(faucet); + user2 = await newUser(faucet); + user3 = await newUser(faucet); + user4 = await newUser(faucet); + + let keys = await createKeypair(); + newPubKey = keys.publicKey; + + console.log('key: ', newPubKey) + }) + + it('Confirm proxy1: is_proxy = 0, is_auto_proxy = 0', async () => { + let inVotersTable; + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: false, + show_payer: false + } + const voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voter); + inVotersTable = false; + for (voter in voters.rows) { + if (voters.rows[voter].owner == proxy1.account) { + inVotersTable = true; + break; + } + } + expect(inVotersTable).to.equal(false) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Register proxy1 as a proxy`, async () => { + try { + const result = await proxy1.sdk.genericAction('pushTransaction', { + action: 'regproxy', + account: 'eosio', + data: { + fio_address: proxy1.address, + actor: proxy1.account, + max_fee: config.maxFee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it('Confirm proxy1: is_proxy = 1, is_auto_proxy = 0', async () => { + let inVotersTable; + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: false, + show_payer: false + } + inVotersTable = false; + voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voter); + for (voter in voters.rows) { + if (voters.rows[voter].owner == proxy1.account) { + inVotersTable = true; + //console.log('voters.rows[voter].is_proxy: ', voters.rows[voter].is_proxy); + //console.log('voters.rows[voter].is_auto_proxy: ', voters.rows[voter].is_auto_proxy); + //console.log('voters.rows[voter].proxy: ', voters.rows[voter].proxy); + break; + } + } + expect(voters.rows[voter].is_auto_proxy).to.equal(0); + expect(voters.rows[voter].is_proxy).to.equal(1); + expect(inVotersTable).to.equal(true) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it('Confirm user1: is_proxy = 0, is_auto_proxy = 0', async () => { + let inVotersTable; + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: false, + show_payer: false + } + const voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voter); + inVotersTable = false; + for (voter in voters.rows) { + if (voters.rows[voter].owner == user1.account) { + inVotersTable = true; + break; + } + } + expect(inVotersTable).to.equal(false) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`SUCCESS: user3 transfers 10 FIO to user1 using FIO Address of user2 (who is not a registered proxy). Expect: no proxy for user1.`, async () => { + try { + const result = await user3.sdk.genericAction('pushTransaction', { + action: 'trnsfiopubky', + account: 'fio.token', + data: { + payee_public_key: user1.publicKey, + amount: 10000000000, + max_fee: config.maxFee, + tpid: user2.address, + actor: user3.account + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`SUCCESS: user2 transfer 10 FIO to user1 using FIO Address of user2 (who is not a registered proxy). Expect: no proxy for user1.`, async () => { + try { + const result = await user2.sdk.genericAction('pushTransaction', { + action: 'trnsfiopubky', + account: 'fio.token', + data: { + payee_public_key: user1.publicKey, + amount: 10000000000, + max_fee: config.maxFee, + tpid: user2.address, + actor: user2.account + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`SUCCESS: regdomain: faucet registers new Domain for user1 using FIO Address of proxy1 (who IS a registered proxy). Expect: no auto_proxy for user1 to proxy1.`, async () => { + user1.domain2 = generateFioDomain(8) + try { + const result = await faucet.genericAction('pushTransaction', { + action: 'regdomain', + account: 'fio.address', + data: { + fio_domain: user1.domain2, + owner_fio_public_key: user1.publicKey, + max_fee: config.maxFee, + tpid: proxy1.address, + actor: faucet.account + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`SUCCESS: renewdomain: faucet renews Domain for user1 using FIO Address of proxy1 (who IS a registered proxy). Expect: no auto_proxy for user1 to proxy1`, async () => { + try { + const result = await faucet.genericAction('pushTransaction', { + action: 'renewdomain', + account: 'fio.address', + data: { + fio_domain: user1.domain, + max_fee: config.maxFee, + tpid: proxy1.address, + actor: faucet.account + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`Register new domain: user3.domain2`, async () => { + user3.domain2 = generateFioDomain(8) + try { + const result = await user3.sdk.genericAction('pushTransaction', { + action: 'regdomain', + account: 'fio.address', + data: { + fio_domain: user3.domain2, + owner_fio_public_key: user3.publicKey, + max_fee: config.maxFee, + tpid: '', + actor: user3.account + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`SUCCESS: xferdomain: Transfer user3.domain2 to user1 using FIO Address of proxy1 (who IS a registered proxy). Expect: no proxy for user1.`, async () => { + try{ + const result = await user3.sdk.genericAction('pushTransaction', { + action: 'xferdomain', + account: 'fio.address', + data: { + fio_domain: user3.domain2, + new_owner_fio_public_key: user1.publicKey, + max_fee: config.maxFee, + tpid: proxy1.address, + actor: user3.account + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`FIXED: regaddress: user3 register new Address for user1 using FIO Address of proxy1 (who IS a registered proxy). Expect: no proxy for user1.`, async () => { + user1.address2 = generateFioAddress(user3.domain, 8) + try { + const result = await user3.sdk.genericAction('pushTransaction', { + action: 'regaddress', + account: 'fio.address', + data: { + fio_address: user1.address2, + owner_fio_public_key: user1.publicKey, + max_fee: config.maxFee, + tpid: proxy1.address, + actor: user3.account + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`SUCCESS: renewaddress: user3 renews Address for user1 using FIO Address of proxy1 (who IS a registered proxy). Expect: no proxy for user1.`, async () => { + try { + const result = await user3.sdk.genericAction('pushTransaction', { + action: 'renewaddress', + account: 'fio.address', + data: { + fio_address: user1.address, + max_fee: config.maxFee, + tpid: proxy1.address, + actor: user3.account + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`Register user3.address2`, async () => { + user3.address2 = generateFioAddress(user3.domain, 8) + try { + const result = await user3.sdk.genericAction('pushTransaction', { + action: 'regaddress', + account: 'fio.address', + data: { + fio_address: user3.address2, + owner_fio_public_key: user3.publicKey, + max_fee: config.maxFee, + tpid: '', + actor: user3.account + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it.skip(`Future release: xferaddress: user3 transfers user3.address2 to emptyAccount.publicKey using FIO Address of proxy1 (who IS a registered proxy). Expect: no proxy for user1.`, async () => { + try{ + const result = await user3.sdk.genericAction('pushTransaction', { + action: 'xferaddress', + account: 'fio.address', + data: { + fio_address: user3.address2, + new_owner_fio_public_key: newPubKey, + max_fee: config.maxFee, + tpid: proxy1.address, + actor: user3.account + } + }) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json.error.details) + expect(err).to.equal('null') + } + }) + + it.skip(`NOT APPLICABLE: burnaddress: user2 tries to burn user3 address`, async () => { + try { + const result = await user2.sdk.genericAction('pushTransaction', { + action: 'burnaddress', + account: 'fio.address', + data: { + fio_address: user3.address, + max_fee: config.maxFee, + tpid: proxy1.address, + actor: user2.account + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`FIXED: trnsfiopubky: user 3 transfers 10 FIO to user1 using FIO Address of proxy1 (who IS a registered proxy). Expect: no proxy for user1.`, async () => { + try { + const result = await user3.sdk.genericAction('pushTransaction', { + action: 'trnsfiopubky', + account: 'fio.token', + data: { + payee_public_key: user1.publicKey, + amount: 10000000000, + max_fee: config.maxFee, + tpid: proxy1.address, + actor: user3.account + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it('Confirm user1 is still: is_proxy = 0, is_auto_proxy = 0', async () => { + let inVotersTable; + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: false, + show_payer: false + } + const voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voter); + inVotersTable = false; + for (voter in voters.rows) { + if (voters.rows[voter].owner == user1.account) { + inVotersTable = true; + break; + } + } + expect(inVotersTable).to.equal(false) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) + +describe(`User that has proxied their vote is sent FIO with TPID registered as proxy`, () => { + + let proxy1, user1, user2 + + it(`Create users`, async () => { + proxy1 = await newUser(faucet); + user1 = await newUser(faucet); + user2 = await newUser(faucet); + }) + + it(`Register proxy1 as a proxy`, async () => { + try { + const result = await proxy1.sdk.genericAction('pushTransaction', { + action: 'regproxy', + account: 'eosio', + data: { + fio_address: proxy1.address, + actor: proxy1.account, + max_fee: config.maxFee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it('Confirm proxy1: is_proxy = 1, is_auto_proxy = 0', async () => { + let inVotersTable; + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: false, + show_payer: false + } + inVotersTable = false; + voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voter); + for (voter in voters.rows) { + if (voters.rows[voter].owner == proxy1.account) { + inVotersTable = true; + break; + } + } + expect(voters.rows[voter].is_auto_proxy).to.equal(0); + expect(voters.rows[voter].is_proxy).to.equal(1); + expect(inVotersTable).to.equal(true) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it('Confirm user1 is NOT in voters table', async () => { + let inVotersTable; + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: false, + show_payer: false + } + const voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voter); + inVotersTable = false; + for (voter in voters.rows) { + if (voters.rows[voter].owner == user1.account) { + //console.log('voters info: ', voters.rows[voter]) + inVotersTable = true; + break; + } + } + expect(inVotersTable).to.equal(false) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`user1 votes for bp1@dapixdev`, async () => { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + "producers": [ + 'bp1@dapixdev' + ], + fio_address: user1.address, + actor: user1.account, + max_fee: config.maxFee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + expect(err).to.equal('null') + } + }) + + it('Confirm user1: proxy = NULL, producers = bp1', async () => { + let inVotersTable; + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: false, + show_payer: false + } + const voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voter); + inVotersTable = false; + for (voter in voters.rows) { + if (voters.rows[voter].owner == user1.account) { + //console.log('voters info: ', voters.rows[voter]) + inVotersTable = true; + break; + } + } + expect(voters.rows[voter].proxy).to.equal('') + expect(voters.rows[voter].producers[0]).to.equal('qbxn5zhw2ypw') // bp1 + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`user2 transfers 10 FIO to user1 using FIO Address of proxy1.`, async () => { + try { + const result = await user2.sdk.genericAction('pushTransaction', { + action: 'trnsfiopubky', + account: 'fio.token', + data: { + payee_public_key: user1.publicKey, + amount: 10000000000, + max_fee: config.maxFee, + tpid: proxy1.address, + actor: user2.account + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it('Confirm user1 is still: proxy = NULL, producers = bp1', async () => { + let inVotersTable; + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: false, + show_payer: false + } + const voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voter); + inVotersTable = false; + for (voter in voters.rows) { + if (voters.rows[voter].owner == user1.account) { + //console.log('voters info: ', voters.rows[voter]) + inVotersTable = true; + break; + } + } + expect(voters.rows[voter].proxy).to.equal('') + expect(voters.rows[voter].producers[0]).to.equal('qbxn5zhw2ypw') // bp1 + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) + +describe(`User that has proxied their votes is sent FIO with TPID registered as proxy`, () => { + + let proxy1, proxyThief, user1, user2 + + it(`Create users`, async () => { + proxy1 = await newUser(faucet); + proxyThief = await newUser(faucet); + user1 = await newUser(faucet); + user2 = await newUser(faucet); + }) + + it(`Register proxy1 as a proxy`, async () => { + try { + const result = await proxy1.sdk.genericAction('pushTransaction', { + action: 'regproxy', + account: 'eosio', + data: { + fio_address: proxy1.address, + actor: proxy1.account, + max_fee: config.maxFee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it(`Register proxyThief as a proxy`, async () => { + try { + const result = await proxyThief.sdk.genericAction('pushTransaction', { + action: 'regproxy', + account: 'eosio', + data: { + fio_address: proxyThief.address, + actor: proxyThief.account, + max_fee: config.maxFee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it('Confirm proxyThief: is_proxy = 1, is_auto_proxy = 0', async () => { + let inVotersTable; + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: false, + show_payer: false + } + inVotersTable = false; + voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voter); + for (voter in voters.rows) { + if (voters.rows[voter].owner == proxyThief.account) { + inVotersTable = true; + break; + } + } + expect(voters.rows[voter].is_auto_proxy).to.equal(0); + expect(voters.rows[voter].is_proxy).to.equal(1); + expect(inVotersTable).to.equal(true) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it('Confirm user1 is not in voters table', async () => { + let inVotersTable; + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: false, + show_payer: false + } + const voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voter); + inVotersTable = false; + for (voter in voters.rows) { + if (voters.rows[voter].owner == user1.account) { + inVotersTable = true; + break; + } + } + expect(inVotersTable).to.equal(false) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`user1 proxy votes to proxy1`, async () => { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'voteproxy', + account: 'eosio', + data: { + proxy: proxy1.address, + fio_address: user1.address, + actor: user1.account, + max_fee: config.maxFee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + } + }) + + it('Confirm user1: proxy = NULL, is_auto_proxy = 0', async () => { + let inVotersTable; + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: false, + show_payer: false + } + const voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voter); + inVotersTable = false; + for (voter in voters.rows) { + if (voters.rows[voter].owner == user1.account) { + //console.log('voters info: ', voters.rows[voter]) + inVotersTable = true; + break; + } + } + expect(voters.rows[voter].proxy).to.equal(proxy1.account); + expect(voters.rows[voter].is_auto_proxy).to.equal(0); + expect(inVotersTable).to.equal(true); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`user2 transfers 10 FIO to user1 using FIO Address of proxyThief as TPID`, async () => { + try { + const result = await user2.sdk.genericAction('pushTransaction', { + action: 'trnsfiopubky', + account: 'fio.token', + data: { + payee_public_key: user1.publicKey, + amount: 10000000000, + max_fee: config.maxFee, + tpid: proxyThief.address, + actor: user2.account + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal('null') + } + }) + + it('Confirm user1 votes are still proxied to proxy1 (NOT proxyThief)', async () => { + let inVotersTable; + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: false, + show_payer: false + } + const voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voter); + inVotersTable = false; + for (voter in voters.rows) { + if (voters.rows[voter].owner == user1.account) { + //console.log('voters info: ', voters.rows[voter]) + inVotersTable = true; + break; + } + } + expect(voters.rows[voter].proxy).to.equal(proxy1.account); + expect(voters.rows[voter].is_auto_proxy).to.equal(0); + expect(inVotersTable).to.equal(true); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) + From e20f6fa39cfd7fba26d8beaf3d035aaa0ec9c286 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Tue, 29 Dec 2020 20:36:55 -0700 Subject: [PATCH 29/76] Fixes for bahamas tests --- tests/action-whitelisting.js | 42 ++++++++--------- tests/bravo-migr-test.js | 4 +- tests/fio-request.js | 6 +-- tests/transfer-domain.js | 2 +- tests/transfer-locked-tokens-account-tests.js | 12 +++-- tests/vote.js | 46 ++++++++++++------- 6 files changed, 65 insertions(+), 47 deletions(-) diff --git a/tests/action-whitelisting.js b/tests/action-whitelisting.js index d42dad6e..76d1fdd1 100644 --- a/tests/action-whitelisting.js +++ b/tests/action-whitelisting.js @@ -252,7 +252,7 @@ describe(`C. Test addaction error conditions`, () => { action_13 = 'eddie1233213a' // Use as 13 character name string }) - it(`addaction with empty action. Returns Error: ${config.error2.invalidAction.type}: ${config.error2.invalidAction.message}`, async () => { + it(`addaction with empty action. Returns Error: ${config.error2.invalidAction.statusCode}: ${config.error2.invalidAction.message}`, async () => { const result = await callFioApiSigned('push_transaction', { action: 'addaction', account: 'eosio', @@ -266,10 +266,10 @@ describe(`C. Test addaction error conditions`, () => { }) //console.log('Result: ', result) expect(result.error.details[0].message).to.equal(config.error2.invalidAction.message); - expect(result.code).to.equal(config.error2.invalidAction.type); + expect(result.code).to.equal(config.error2.invalidAction.statusCode); }) - it(`addaction with empty contract. Returns Error: ${config.error2.invalidContract.type}: ${config.error2.invalidContract.message}`, async () => { + it(`addaction with empty contract. Returns Error: ${config.error2.invalidContract.statusCode}: ${config.error2.invalidContract.message}`, async () => { const result = await callFioApiSigned('push_transaction', { action: 'addaction', account: 'eosio', @@ -283,10 +283,10 @@ describe(`C. Test addaction error conditions`, () => { }) //console.log('Result: ', result.error) expect(result.error.details[0].message).to.equal(config.error2.invalidContract.message); - expect(result.code).to.equal(config.error2.invalidContract.type); + expect(result.code).to.equal(config.error2.invalidContract.statusCode); }) - it(`addaction with invalid actor. Returns Error: ${config.error2.invalidActor.type}: ${config.error2.invalidActor.message}`, async () => { + it(`addaction with invalid actor. Returns Error: 500: 'missing authority of otheractor'`, async () => { const result = await callFioApiSigned('push_transaction', { action: 'addaction', account: 'eosio', @@ -299,8 +299,8 @@ describe(`C. Test addaction error conditions`, () => { } }) //console.log('Result: ', result) - expect(result.error.what).contains(config.error2.invalidActor.message); - expect(result.code).to.equal(config.error2.invalidActor.type); + expect(result.error.details[0].message).contains('missing authority of otheractor'); + expect(result.code).to.equal(500); }) it(`addaction with 7 character action and contract name succeeds.`, async () => { @@ -317,14 +317,14 @@ describe(`C. Test addaction error conditions`, () => { }) //console.log('Result: ', result.processed.action_traces) //expect(result.error.details[0].message).to.equal(config.error2.invalidAction.message); - //expect(result.code).to.equal(config.error2.invalidAction.type); + //expect(result.code).to.equal(config.error2.invalidAction.statusCode); }) it('Wait a few seconds to avoid duplicate transaction.', async () => { await timeout(2000); }) - it(`addaction with existing action AND existing contract. Returns Error: ${config.error2.accountExists.type}: ${config.error2.accountExists.message} `, async () => { + it(`addaction with existing action AND existing contract. Returns Error: ${config.error2.accountExists.statusCode}: ${config.error2.accountExists.message} `, async () => { const result = await callFioApiSigned('push_transaction', { action: 'addaction', account: 'eosio', @@ -338,10 +338,10 @@ describe(`C. Test addaction error conditions`, () => { }) //console.log('Result: ', result) expect(result.error.what).contains(config.error2.accountExists.message); - expect(result.code).to.equal(config.error2.accountExists.type); + expect(result.code).to.equal(config.error2.accountExists.statusCode); }) - it(`addaction with existing action but DIFFERENT contract. Returns Error: ${config.error2.invalidAction.type}: ${config.error2.invalidAction.message}`, async () => { + it(`addaction with existing action but DIFFERENT contract. Returns Error: ${config.error2.invalidAction.statusCode}: ${config.error2.invalidAction.message}`, async () => { const result = await callFioApiSigned('push_transaction', { action: 'addaction', account: 'eosio', @@ -355,10 +355,10 @@ describe(`C. Test addaction error conditions`, () => { }) //console.log('Result: ', result) expect(result.error.details[0].message).to.equal(config.error2.invalidAction.message); - expect(result.code).to.equal(config.error2.invalidAction.type); + expect(result.code).to.equal(config.error2.invalidAction.statusCode); }) - it(`addaction with 13 character action and 7 character contract. Returns Error: ${config.error2.invalidAction.type}: ${config.error2.invalidAction.message}`, async () => { + it(`addaction with 13 character action and 7 character contract. Returns Error: ${config.error2.invalidAction.statusCode}: ${config.error2.invalidAction.message}`, async () => { try { const result = await callFioApiSigned('push_transaction', { action: 'addaction', @@ -374,7 +374,7 @@ describe(`C. Test addaction error conditions`, () => { //console.log('Result: ', result.error.details) expect(result.error.details[0].message).to.equal(config.error2.invalidAction.message); - expect(result.code).to.equal(config.error2.invalidAction.type); + expect(result.code).to.equal(config.error2.invalidAction.statusCode); } catch (err) { console.log('Error: ', err) } @@ -481,13 +481,13 @@ describe(`D. General remaction testing `, () => { }) // console.log("Result: ", result); expect(result.error.what).contains(config.error2.accountExists.message); - expect(result.code).to.equal(config.error2.accountExists.type); + expect(result.code).to.equal(config.error2.accountExists.statusCode); } catch (err) { console.log('Error', err); expect(err).to.equal(null); } }) - it(`remaction with invalid actor. Returns Error: ${config.error2.invalidActor.type}: ${config.error2.invalidActor.message}`, async () => { + it(`remaction with invalid actor. Returns Error: 500: Missing required authority`, async () => { const result = await callFioApiSigned('push_transaction', { action: 'remaction', account: 'eosio', @@ -500,8 +500,8 @@ describe(`D. General remaction testing `, () => { } }) //console.log('Result: ', result) - expect(result.error.what).contains(config.error2.invalidActor.message); - expect(result.code).to.equal(config.error2.invalidActor.type); + expect(result.error.what).contains('Missing required authority'); + expect(result.code).to.equal(500); }) }) @@ -642,7 +642,7 @@ describe(`E. get_actions paging tests`, () => { } }) - it(`Use floats in limit/offset. Expect error type ${config.error2.noActions.type}: ${config.error2.noActions.message}`, async () => { + it(`Use floats in limit/offset. Expect error type ${config.error2.noActions.statusCode}: ${config.error2.noActions.message}`, async () => { try { const json = { limit: 123.456, @@ -653,7 +653,7 @@ describe(`E. get_actions paging tests`, () => { } catch (err) { //console.log('Error', err.error); expect(err.error.message).to.equal(config.error2.noActions.message); - expect(err.statusCode).to.equal(config.error2.noActions.type); + expect(err.statusCode).to.equal(config.error2.noActions.statusCode); } }) @@ -686,7 +686,7 @@ describe(`F. Test addaction perf`, () => { }) //console.log('Result: ', result.processed.action_traces) //expect(result.error.details[0].message).to.equal(config.error2.invalidAction.message); - //expect(result.code).to.equal(config.error2.invalidAction.type); + //expect(result.code).to.equal(config.error2.invalidAction.statusCode); }) } diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index 41de1f57..338af07c 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -42,7 +42,7 @@ before(async () => { }) -describe(`************************** bravo-migr-test.js.js ************************** \n Load Requests and OBTs`, () => { +describe.skip(`************************** bravo-migr-test.js.js ************************** \n Load Requests and OBTs`, () => { let user1, user2, user3; let payment = 3000000000; let requestMemo = 'asdf'; @@ -729,7 +729,7 @@ describe.skip(`Confirm paid OBT response Requests are going into both tables`, ( }) -describe.skip(`Migrate remaining requests and OBTs`, () => { +describe(`Migrate remaining requests and OBTs`, () => { let isFinished = 0 it('Echo initial migrledgers table', async () => { diff --git a/tests/fio-request.js b/tests/fio-request.js index 43f5a525..b97220bb 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -165,10 +165,10 @@ describe(`************************** fio-request.js ************************** \ limit: '', offset: '' }) - //console.log('result: ', result) + console.log('result: ', result) //console.log('content: ', result.requests[0].content) - expect(result.requests[0].content.memo).to.equal(requestMemo) - expect(result.requests[0].status).to.equal('sent_to_blockchain') + //expect(result.requests[0].content.memo).to.equal(requestMemo) + //expect(result.requests[0].status).to.equal('sent_to_blockchain') } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) diff --git a/tests/transfer-domain.js b/tests/transfer-domain.js index b415f64f..d8c0858b 100644 --- a/tests/transfer-domain.js +++ b/tests/transfer-domain.js @@ -351,7 +351,7 @@ describe('B. Transfer a domain to FIO Public Key which does not map to existing } catch (err) { //console.log('Error', err) expect(err.error.message).to.equal(config.error2.noFioNames.message) - expect(err.statusCode).to.equal(config.error2.noFioNames.type); + expect(err.statusCode).to.equal(config.error2.noFioNames.statusCode); } }) diff --git a/tests/transfer-locked-tokens-account-tests.js b/tests/transfer-locked-tokens-account-tests.js index 6f5744ff..d5ddddf9 100644 --- a/tests/transfer-locked-tokens-account-tests.js +++ b/tests/transfer-locked-tokens-account-tests.js @@ -901,6 +901,8 @@ describe('Request funds, approve and send', () => { expect(result.fee_collected).to.be.a('number') }) + it(`Wait a few seconds.`, async () => { await timeout(4000) }) + it(`getSentFioRequests`, async () => { const result = await fioSdk2.genericAction('getSentFioRequests', {}) expect(result).to.have.all.keys('requests', 'more') @@ -1143,7 +1145,7 @@ describe('Record obt data, check', () => { expect(result.fee_collected).to.be.a('number') }) - it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) it(`Payer getObtData`, async () => { await timeout(4000) @@ -1298,9 +1300,7 @@ describe(`Test locked token accounts with proxy voting`, () => { expect(err).to.equal('null') } }) - - it(`Wait a few seconds.`, async () => { await timeout(3000) }) - + it('Transfer additional 500 FIO from faucet to fioSdk', async () => { const result = await fioSdkFaucet.genericAction('transferTokens', { payeeFioPublicKey: publicKey, @@ -1311,10 +1311,14 @@ describe(`Test locked token accounts with proxy voting`, () => { expect(result.status).to.equal('OK') }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Get fioSdk last_vote_weight (should be 500 more)`, async () => { try { + prevVoteWeight = fioSdk.last_vote_weight fioSdk.last_vote_weight = await getAccountVoteWeight(account); //console.log('fioSdk.last_vote_weight:', fioSdk.last_vote_weight) + expect(fioSdk.last_vote_weight).to.equal(prevVoteWeight + 500000000000) } catch (err) { console.log('Error: ', err.json) } diff --git a/tests/vote.js b/tests/vote.js index c9751f41..17e7efb6 100644 --- a/tests/vote.js +++ b/tests/vote.js @@ -460,45 +460,47 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund expect(result.status).to.equal('OK') }) - it(`voterB1 last_vote_weight increases by 500 FIO) (minus the fee)`, async () => { + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it(`voterB1 last_vote_weight increases by 500 FIO`, async () => { try { let prev_vote_weight = voterB1.last_vote_weight; voterB1.last_vote_weight = await getAccountVoteWeight(voterB1.account); //console.log('voterB1.last_vote_weight:', voterB1.last_vote_weight); - expect(voterB1.last_vote_weight).to.equal(prev_vote_weight + 500000000000 - transfer_tokens_pub_key_fee); + expect(voterB1.last_vote_weight).to.equal(prev_vote_weight + 500000000000); } catch (err) { console.log('Error: ', err) } }) - it(`proxyB1 last_vote_weight increases by 500 FIO) (minus the fee)`, async () => { + it(`proxyB1 last_vote_weight increases by 500 FIO`, async () => { try { let prev_vote_weight = proxyB1.last_vote_weight; proxyB1.last_vote_weight = await getAccountVoteWeight(proxyB1.account); //console.log('proxyB1.last_vote_weight:', proxyB1.last_vote_weight); - expect(proxyB1.last_vote_weight).to.equal(prev_vote_weight + 500000000000 - transfer_tokens_pub_key_fee); + expect(proxyB1.last_vote_weight).to.equal(prev_vote_weight + 500000000000); } catch (err) { console.log('Error: ', err) } }) - it(`total_voted_fio increased by 500 FIO (minus the fee)`, async () => { + it(`total_voted_fio increased by 500 FIO`, async () => { try { let prev_total_voted_fio = total_voted_fio; total_voted_fio = await getTotalVotedFio(); //console.log('total_voted_fio: ', total_voted_fio) - expect(total_voted_fio).to.equal(prev_total_voted_fio + 500000000000 - transfer_tokens_pub_key_fee) + expect(total_voted_fio).to.equal(prev_total_voted_fio + 500000000000) } catch (err) { console.log('Error', err) } }) - it(`bp1@dapixdev total_votes increased by 500 FIO (minus the fee)`, async () => { + it(`bp1@dapixdev total_votes increased by 500 FIO`, async () => { try { let prev_total_bp_votes = total_bp_votes; total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); //console.log('bp1@dapixdev total_votes:', total_bp_votes) - expect(total_bp_votes).to.equal(prev_total_bp_votes + 500000000000 - transfer_tokens_pub_key_fee) + expect(total_bp_votes).to.equal(prev_total_bp_votes + 500000000000) } catch (err) { console.log('Error: ', err) } @@ -518,6 +520,8 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`voterB1 last_vote_weight decreases by (1000 + xfer fee) FIO)`, async () => { try { let prev_vote_weight = voterB1.last_vote_weight; @@ -572,6 +576,8 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund expect(result.status).to.equal('OK') }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`voterB1 last_vote_weight increases by 800 FIO)`, async () => { try { let prev_vote_weight = voterB1.last_vote_weight; @@ -646,6 +652,8 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Get proxyB1 FIO Balance post unregproxy`, async () => { try { const result = await proxyB1.sdk.genericAction('getFioBalance', { @@ -2935,13 +2943,13 @@ describe(`Test proxy re-vote of proxy, re-proxy of voter`, () => { it(`Get total_voted_fio`, async () => { total_voted_fio = await getTotalVotedFio(); - console.log('total_voted_fio:', total_voted_fio) + //console.log('total_voted_fio:', total_voted_fio) }) it(`Get proxyA1 last_vote_weight`, async () => { try { proxyA1.last_vote_weight = await getAccountVoteWeight(proxyA1.account); - console.log('proxyA1.last_vote_weight: ', proxyA1.last_vote_weight) + //console.log('proxyA1.last_vote_weight: ', proxyA1.last_vote_weight) } catch (err) { console.log('Error: ', err.json) } @@ -2950,7 +2958,7 @@ describe(`Test proxy re-vote of proxy, re-proxy of voter`, () => { it(`Get bp1@dapixdev total_votes`, async () => { try { total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); - console.log('bp1@dapixdev total_votes:', total_bp_votes) + //console.log('bp1@dapixdev total_votes:', total_bp_votes) } catch (err) { console.log('Error: ', err) expect(err).to.equal('null') @@ -2983,7 +2991,7 @@ describe(`Test proxy re-vote of proxy, re-proxy of voter`, () => { try { let prev_total_bp_votes = total_bp_votes; total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); - console.log('bp1@dapixdev total_votes:', total_bp_votes) + //console.log('bp1@dapixdev total_votes:', total_bp_votes) expect(total_bp_votes).to.equal(prev_total_bp_votes) } catch (err) { console.log('Error: ', err) @@ -2995,7 +3003,7 @@ describe(`Test proxy re-vote of proxy, re-proxy of voter`, () => { try { let prev_total_voted_fio = total_voted_fio; total_voted_fio = await getTotalVotedFio(); - console.log('total_voted_fio:', total_voted_fio) + //console.log('total_voted_fio:', total_voted_fio) expect(total_voted_fio).to.equal(prev_total_voted_fio) } catch (err) { console.log('Error: ', err) @@ -3006,12 +3014,14 @@ describe(`Test proxy re-vote of proxy, re-proxy of voter`, () => { it(`Get user1 last_vote_weight`, async () => { try { user1.last_vote_weight = await getAccountVoteWeight(user1.account); - console.log('user1.last_vote_weight: ', user1.last_vote_weight) + //console.log('user1.last_vote_weight: ', user1.last_vote_weight) } catch (err) { console.log('Error: ', err.json) } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`user1 proxies votes AGAIN to proxyA1`, async () => { try { const result = await user1.sdk.genericAction('pushTransaction', { @@ -3035,7 +3045,7 @@ describe(`Test proxy re-vote of proxy, re-proxy of voter`, () => { try { let prev_total_bp_votes = total_bp_votes; total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); - console.log('bp1@dapixdev total_votes:', total_bp_votes) + //console.log('bp1@dapixdev total_votes:', total_bp_votes) expect(total_bp_votes).to.equal(prev_total_bp_votes) } catch (err) { console.log('Error: ', err) @@ -3047,7 +3057,7 @@ describe(`Test proxy re-vote of proxy, re-proxy of voter`, () => { try { let prev_total_voted_fio = total_voted_fio; total_voted_fio = await getTotalVotedFio(); - console.log('total_voted_fio:', total_voted_fio) + //console.log('total_voted_fio:', total_voted_fio) expect(total_voted_fio).to.equal(prev_total_voted_fio) } catch (err) { console.log('Error: ', err) @@ -3369,6 +3379,8 @@ describe(`Test total_voted_fio when user votes for proxy`, () => { } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`bp1@dapixdev total_votes increased by user1 last_vote_weight`, async () => { try { let prev_total_bp_votes = total_bp_votes; @@ -3424,6 +3436,8 @@ describe(`Test total_voted_fio when user votes for proxy`, () => { } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`bp1@dapixdev total_votes increased by faucet last_vote_weight`, async () => { try { let prev_total_bp_votes = total_bp_votes; From 316b003d8ec345f1508925754b246648a8ae280d Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Thu, 31 Dec 2020 16:24:55 -0700 Subject: [PATCH 30/76] Bahamas cleanup --- tests/action-whitelisting.js | 9 ++++++--- tests/vote.js | 12 +++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/action-whitelisting.js b/tests/action-whitelisting.js index 76d1fdd1..598ed610 100644 --- a/tests/action-whitelisting.js +++ b/tests/action-whitelisting.js @@ -426,6 +426,8 @@ describe(`D. General remaction testing `, () => { } }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) + it(`remaction of same action fails`, async () => { try { const result = await callFioApiSigned('push_transaction', { @@ -439,10 +441,11 @@ describe(`D. General remaction testing `, () => { } }) //console.log('Result', result); - expect(result.error.what).to.equal('Duplicate transaction'); + expect(result).to.equal(null); } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); + //console.log('Error', err.actual.error.details); + expect(err.actual.code).to.equal(500); + expect(err.actual.error.details[0].message).to.equal('Action invalid or not found'); } }) diff --git a/tests/vote.js b/tests/vote.js index 17e7efb6..d30d30dc 100644 --- a/tests/vote.js +++ b/tests/vote.js @@ -3143,7 +3143,7 @@ describe(`Test impact on total_voted_fio when User 1 votes then proxies their vo } }) - it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Wait a few seconds.`, async () => { await timeout(4000) }) it(`Get total_voted_fio`, async () => { total_voted_fio = await getTotalVotedFio(); @@ -3201,6 +3201,8 @@ describe(`Test impact on total_voted_fio when User 1 votes then proxies their vo } }) + it(`Wait a few seconds.`, async () => { await timeout(4000) }) + it(`bp1@dapixdev total_votes did not change (votes just shifted from direct vote to proxy vote via proxyA1)`, async () => { try { let prev_total_bp_votes = total_bp_votes; @@ -3213,7 +3215,7 @@ describe(`Test impact on total_voted_fio when User 1 votes then proxies their vo } }) - it(`BUG: prev_total_voted_fio did not change (votes just shifted from direct vote to proxy vote via proxyA1)`, async () => { + it.skip(`BUG BD-2280: prev_total_voted_fio did not change (votes just shifted from direct vote to proxy vote via proxyA1)`, async () => { try { let prev_total_voted_fio = total_voted_fio; total_voted_fio = await getTotalVotedFio(); @@ -3311,7 +3313,7 @@ describe(`Test total_voted_fio when user votes for proxy`, () => { } }) - it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) it(`Get proxyA1 last_vote_weight`, async () => { try { @@ -3379,7 +3381,7 @@ describe(`Test total_voted_fio when user votes for proxy`, () => { } }) - it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) it(`bp1@dapixdev total_votes increased by user1 last_vote_weight`, async () => { try { @@ -3436,7 +3438,7 @@ describe(`Test total_voted_fio when user votes for proxy`, () => { } }) - it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) it(`bp1@dapixdev total_votes increased by faucet last_vote_weight`, async () => { try { From c7a40923a6eaaaf063e4bdf4f7f2a73170019e42 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Thu, 31 Dec 2020 16:29:19 -0700 Subject: [PATCH 31/76] migr update --- tests/bravo-migr-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index 338af07c..26231f53 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -42,7 +42,7 @@ before(async () => { }) -describe.skip(`************************** bravo-migr-test.js.js ************************** \n Load Requests and OBTs`, () => { +describe(`************************** bravo-migr-test.js.js ************************** \n Load Requests and OBTs`, () => { let user1, user2, user3; let payment = 3000000000; let requestMemo = 'asdf'; From b5539b5c44ac295c36198b5beffa49a3f63d2f5d Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Fri, 8 Jan 2021 15:08:36 -0700 Subject: [PATCH 32/76] Add testnet smoketest and other updates --- package.json | 3 +- tests/addbundles.js | 8 +- tests/bravo-migr-test.js | 4 +- tests/fio-request.js | 78 ++- tests/testnet.smoketest.js | 1182 ++++++++++++++++++++++++++++++++++++ tests/transfer-address.js | 2 - 6 files changed, 1267 insertions(+), 10 deletions(-) create mode 100644 tests/testnet.smoketest.js diff --git a/package.json b/package.json index 4e332675..d7a493e5 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "typescript": "^3.8.2" }, "scripts": { - "test": "mocha -t 5000000 index.js" + "test": "mocha -t 5000000 index.js", + "testnet": "mocha -t 5000000 tests/testnet.smoketest.js" } } diff --git a/tests/addbundles.js b/tests/addbundles.js index 61856683..666885cf 100644 --- a/tests/addbundles.js +++ b/tests/addbundles.js @@ -1,7 +1,7 @@ require('mocha') const {expect} = require('chai') const {newUser, fetchJson, timeout, callFioApi} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/FIOSDK') +const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); before(async () => { @@ -349,7 +349,7 @@ describe('B. Add 3 sets of bundled transactions for FIO Address owned by other u } }) - it(`BUG: (push_transaction) user1 run addbundles with ${bundleSets} sets for FIO Address owned by user2`, async () => { + it(`(push_transaction) user1 run addbundles with ${bundleSets} sets for FIO Address owned by user2`, async () => { try { const result = await user1.sdk.genericAction('pushTransaction', { action: 'addbundles', @@ -529,7 +529,7 @@ describe('C. Error testing', () => { } }) - it.skip(`BUG: Run addbundles with bundle_sets = 0. Expect error type ${config.error2.invalidBundleSets.statusCode}: ${config.error2.invalidBundleSets.message}`, async () => { + it(`Run addbundles with bundle_sets = 0. Expect error type ${config.error2.invalidBundleSets.statusCode}: ${config.error2.invalidBundleSets.message}`, async () => { try { const result = await user1.sdk.genericAction('pushTransaction', { action: 'addbundles', @@ -544,7 +544,7 @@ describe('C. Error testing', () => { console.log('Result: ', result); expect(result.status).to.equal(null); } catch (err) { - console.log('Error: ', err.json.fields); + //console.log('Error: ', err.json.fields); expect(err.json.fields[0].error).to.equal(config.error2.invalidBundleSets.message) expect(err.errorCode).to.equal(config.error2.invalidBundleSets.statusCode); } diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index 26231f53..8e0882be 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -356,7 +356,7 @@ describe(`Initial OBT record. Confirm new OBT Sends are going into both tables`, scope: 'fio.reqobt', // Account that owns the data table: 'fiotrxts', // Table name limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data + reverse: true, // Optional: Get reversed data show_payer: false // Optional: Show ram payer } requests = await callFioApi("get_table_rows", json); @@ -424,7 +424,7 @@ describe(`Initial FIO Request record. Confirm NEW Requests are going into both t scope: 'fio.reqobt', // Account that owns the data table: 'fioreqctxts', // Table name limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data + reverse: true, // Optional: Get reversed data show_payer: false // Optional: Show ram payer } requests = await callFioApi("get_table_rows", json); diff --git a/tests/fio-request.js b/tests/fio-request.js index b97220bb..a03250ca 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -1826,7 +1826,83 @@ describe(`F. get_cancelled_fio_requests paging: Cancel multiple FIO requests and }) -describe.skip(`G. Records Performance Testing`, () => { +describe(`G. BUG in migr/part3-final?? Test rejection of FIO Requests`, () => { + + let user1, user2, user1RequestId + + it('Create users', async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + }) + + it(`user1 creates 10 FIO Requests for user2`, async () => { + for (i = 0; i < 10; i++) { + try { + const result = await user1.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user1.address, + payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', + amount: 1, + chainCode: 'BTC', + tokenCode: 'BTC', + memo: 'requestMemo', + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '' + }) + //console.log('Result: ', result) + if (i == 1) { + user1RequestId = result.fio_request_id + } + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + } + }) + + it('Wait a few seconds to avoid duplicate transaction.', async () => { await timeout(3000); }) + + it(`user2 rejects first funds request`, async () => { + try{ + const result = await user2.sdk.genericAction('pushTransaction', { + action: 'rejectfndreq', + account: 'fio.reqobt', + data: { + "fio_request_id": user1RequestId, + "max_fee": config.api.cancel_funds_request.fee, + "tpid": '', + "actor": user2.account + } + }) + //console.log('Result:', result) + expect(result.status).to.equal('request_rejected') + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it('Wait a few seconds...', async () => { await timeout(3000); }) + + it(`get_pending_fio_requests for user2, expect 9 results`, async () => { + try { + const result = await user2.sdk.genericAction('getPendingFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result) + expect(result.requests.length).to.equal(9) + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + +}) + +describe.skip(`H. Records Performance Testing`, () => { let userA1, userA2, userB1, userB2, userC1, userC2 const payment = 5000000000 // 5 FIO diff --git a/tests/testnet.smoketest.js b/tests/testnet.smoketest.js new file mode 100644 index 00000000..e11ca645 --- /dev/null +++ b/tests/testnet.smoketest.js @@ -0,0 +1,1182 @@ +require('mocha') +const {expect} = require('chai') +const {FIOSDK} = require('@fioprotocol/fiosdk') +const {newUser, existingUser, fetchJson} = require('../utils.js'); +config = require('../config.js'); +const { EndPoint } = require('@fioprotocol/fiosdk/lib/entities/EndPoint') + +let target = 'local' +let privateKey, publicKey, testFioAddressName, privateKey2, publicKey2, testFioAddressName2 + +/** + * Set your testnet existing private/public keys and existing fioAddresses (not needed if running locally) + */ +privateKey = '5Jw78NzS2QMvjcyemCgJ9XQv8SMSEvTEuLxF8TcKf27xWcX5fmw', +publicKey = 'FIO8k7N7jU9eyj57AfazGxMuvPGZG5hvXNUyxt9pBchnkXXx9KUuD', +account = '', +privateKey2 = '5Hv1zRFa7XRo395dfHS8xrviszPiVYeBhQjJq4TsPv53NvAcfyU', +publicKey2 = 'FIO7b3WHTsS1wTF2dAUvE9DoDXvxYUVA8FepLW6x9Bv5rPJnUW6ab', +account2 = '', +testFioDomain = 'fiotestnet', +testFioAddressName = 'ebtest1@fiotestnet', +testFioAddressName2 = 'ebtest3@fiotestnet' + +const fioTestnetDomain = 'fiotestnet' +const fioTokenCode = 'FIO' +const fioChainCode = 'FIO' +const ethTokenCode = 'ETH' +const ethChainCode = 'ETH' +const defaultBundledSets = 1 +const defaultFee = 800 * FIOSDK.SUFUnit + +let fioSdk, fioSdk2 +let newFioDomain, newFioAddress, privateKeyExample, publicKeyExample, pubKeyForTransfer + +const generateTestingFioAddress = (customDomain = fioTestnetDomain) => { + return `testing${Date.now()}@${customDomain}` +} + +const generateTestingFioDomain = () => { + return `testing-domain-${Date.now()}` +} + +const generateObtId = () => { + return `${Date.now()}` +} + +const timeout = async (ms) => { + await new Promise(resolve => { + setTimeout(resolve, ms) + }) +} + +before(async () => { + + if (target == 'local') { + faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); + fioSdk = await newUser(faucet); + fioSdk2 = await newUser(faucet); + privateKey = fioSdk.privateKey, + publicKey = fioSdk.publicKey, + testFioAddressName = fioSdk.address, + privateKey2 = fioSdk2.privateKey, + publicKey2 = fioSdk2.publicKey, + testFioAddressName2 = fioSdk2.address + } else { + fioSdk = await existingUser(account, privateKey, publicKey, testFioDomain, testFioAddressName); + fioSdk = await existingUser(account2, privateKey2, publicKey2, testFioDomain, testFioAddressName2); + } + + try { + const isAvailableResult = await fioSdk.sdk.genericAction('isAvailable', { + fioName: testFioAddressName + }) + if (!isAvailableResult.is_registered) { + await fioSdk.sdk.genericAction('registerFioAddress', { + fioAddress: testFioAddressName, + maxFee: defaultFee + }) + } + } catch (e) { + console.log(e); + } + try { + const isAvailableResult2 = await fioSdk2.sdk.genericAction('isAvailable', { + fioName: testFioAddressName2 + }) + if (!isAvailableResult2.is_registered) { + await fioSdk2.sdk.genericAction('registerFioAddress', { + fioAddress: testFioAddressName2, + maxFee: defaultFee + }) + } + } catch (e) { + console.log(e); + } + + await timeout(4000) + + newFioDomain = generateTestingFioDomain() + + newFioAddress = generateTestingFioAddress(newFioDomain) + privateKeyExample = '5Kbb37EAqQgZ9vWUHoPiC2uXYhyGSFNbL6oiDp24Ea1ADxV1qnu' + publicKeyExample = 'FIO5kJKNHwctcfUM5XZyiWSqSTM5HTzznJP9F3ZdbhaQAHEVq575o' + pubKeyForTransfer = 'FIO7isxEua78KPVbGzKemH4nj2bWE52gqj8Hkac3tc7jKNvpfWzYS' +}) + + +describe('Testing generic actions', () => { + + it(`FIO Key Generation Testing`, async () => { + const testMnemonic = 'valley alien library bread worry brother bundle hammer loyal barely dune brave' + const privateKeyRes = await FIOSDK.createPrivateKeyMnemonic(testMnemonic) + expect(privateKeyRes.fioKey).to.equal(privateKeyExample) + const publicKeyRes = FIOSDK.derivedPublicKey(privateKeyRes.fioKey) + expect(publicKeyRes.publicKey).to.equal(publicKeyExample) + }) + + it(`FIO SUF Utilities - amountToSUF`, async () => { + const sufa = FIOSDK.amountToSUF (100) + expect(sufa).to.equal(100000000000) + + const sufb = FIOSDK.amountToSUF (500) + expect(sufb).to.equal(500000000000) + + const sufc = FIOSDK.amountToSUF (506) + expect(sufc).to.equal(506000000000) + + const sufd = FIOSDK.amountToSUF (1) + expect(sufd).to.equal(1000000000) + + const sufe = FIOSDK.amountToSUF (2) + expect(sufe).to.equal(2000000000) + + const suff = FIOSDK.amountToSUF (2.568) + expect(suff).to.equal(2568000000) + + const sufg = FIOSDK.amountToSUF (2.123) + expect(sufg).to.equal(2123000000) + }) + + it(`FIO SUF Utilities - SUFToAmount`, async () => { + const sufa = FIOSDK.SUFToAmount (100000000000) + expect(sufa).to.equal(100) + + const sufb = FIOSDK.SUFToAmount (500000000000) + expect(sufb).to.equal(500) + + const sufc = FIOSDK.SUFToAmount (506000000000) + expect(sufc).to.equal(506) + + const sufd = FIOSDK.SUFToAmount (1000000000) + expect(sufd).to.equal(1) + + const sufe = FIOSDK.SUFToAmount (2000000000) + expect(sufe).to.equal(2) + + const suff = FIOSDK.SUFToAmount (2568000000) + expect(suff).to.equal(2.568) + + const sufg = FIOSDK.SUFToAmount (2123000000) + expect(sufg).to.equal(2.123) + }) + + it(`Validation methods`, async () => { + try { + FIOSDK.isChainCodeValid('$%34') + } catch (e) { + expect(e.list[0].message).to.equal('chainCode must match /^[a-z0-9]+$/i.') + } + try { + FIOSDK.isTokenCodeValid('') + } catch (e) { + expect(e.list[0].message).to.equal('tokenCode is required.') + } + try { + FIOSDK.isFioAddressValid('f') + } catch (e) { + expect(e.list[0].message).to.equal('fioAddress must have a length between 3 and 64.') + } + try { + FIOSDK.isFioDomainValid('$%FG%') + } catch (e) { + expect(e.list[0].message).to.equal('fioDomain must match /^[a-z0-9\\-]+$/i.') + } + try { + FIOSDK.isFioPublicKeyValid('dfsd') + } catch (e) { + expect(e.list[0].message).to.equal('fioPublicKey must match /^FIO\\w+$/.') + } + try { + FIOSDK.isPublicAddressValid('') + } catch (e) { + expect(e.list[0].message).to.equal('publicAddress is required.') + } + + const chainCodeIsValid = FIOSDK.isChainCodeValid('FIO') + expect(chainCodeIsValid).to.equal(true) + + const tokenCodeIsValid = FIOSDK.isTokenCodeValid('FIO') + expect(tokenCodeIsValid).to.equal(true) + + const singleDigitFioAddressIsValid = FIOSDK.isFioAddressValid('f@2') + expect(singleDigitFioAddressIsValid).to.equal(true) + + const fioAddressIsValid = FIOSDK.isFioAddressValid(newFioAddress) + expect(fioAddressIsValid).to.equal(true) + + const fioDomainIsValid = FIOSDK.isFioDomainValid(newFioDomain) + expect(fioDomainIsValid).to.equal(true) + + const privateKeyIsValid = FIOSDK.isFioPublicKeyValid(publicKey) + expect(privateKeyIsValid).to.equal(true) + + const publicKeyIsValid = FIOSDK.isPublicAddressValid(publicKey) + expect(publicKeyIsValid).to.equal(true) + }) + + it(`Getting fio public key`, async () => { + const result = await fioSdk.sdk.genericAction('getFioPublicKey', {}) + + expect(result).to.equal(publicKey) + }) + + it(`getFioBalance`, async () => { + const result = await fioSdk.sdk.genericAction('getFioBalance', {}) + + expect(result).to.have.all.keys('balance','available') + expect(result.balance).to.be.a('number') + }) +}) + +describe('Testing domain actions', () => { + + it(`Register fio domain`, async () => { + const result = await fioSdk2.sdk.genericAction('registerFioDomain', { fioDomain: newFioDomain, maxFee: defaultFee }) + //console.log('New Domain: ', newFioDomain) + expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.expiration).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`Renew fio domain`, async () => { + const result = await fioSdk2.sdk.genericAction('renewFioDomain', { fioDomain: newFioDomain, maxFee: defaultFee }) + + expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.expiration).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`setFioDomainVisibility true`, async () => { + const result = await fioSdk2.sdk.genericAction('setFioDomainVisibility', { + fioDomain: newFioDomain, + isPublic: true, + maxFee: defaultFee, + technologyProviderId: '' + }) + + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`Register fio address`, async () => { + const result = await fioSdk2.sdk.genericAction('registerFioAddress', { + fioAddress: newFioAddress, + maxFee: defaultFee + }) + + expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.expiration).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`getFioNames`, async () => { + const result = await fioSdk2.sdk.genericAction('getFioNames', { fioPublicKey: publicKey }) + + expect(result).to.have.all.keys('fio_domains', 'fio_addresses') + expect(result.fio_domains).to.be.a('array') + expect(result.fio_addresses).to.be.a('array') + }) + + it(`getFioDomains`, async () => { + try{ + const result = await fioSdk2.sdk.genericAction('getFioDomains', { fioPublicKey: fioSdk.publicKey }) + + expect(result).to.have.all.keys('fio_domains','more') + expect(result.fio_domains).to.be.a('array') + } catch (e) { + console.log(e); + } + }) + + it(`Register owner fio address`, async () => { + const newFioAddress2 = generateTestingFioAddress(newFioDomain) + const result = await fioSdk2.sdk.genericAction('registerFioAddress', { + fioAddress: newFioAddress2, + ownerPublicKey: publicKey2, + maxFee: defaultFee + }) + expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.expiration).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`setFioDomainVisibility false`, async () => { + const result = await fioSdk2.sdk.genericAction('setFioDomainVisibility', { + fioDomain: newFioDomain, + isPublic: false, + maxFee: defaultFee, + technologyProviderId: '' + }) + + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it(`setFioDomainVisibility true`, async () => { + const result = await fioSdk2.sdk.genericAction('setFioDomainVisibility', { + fioDomain: newFioDomain, + isPublic: true, + maxFee: defaultFee, + technologyProviderId: '' + }) + + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`getFee for transferFioAddress`, async () => { + const result = await fioSdk2.sdk.genericAction('getFeeForTransferFioAddress', { + fioAddress: newFioAddress + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + }) + + it.skip(`Need to move: Transfer fio address`, async () => { + const result = await fioSdk2.sdk.genericAction('transferFioAddress', { + fioAddress: newFioAddress, + newOwnerKey: pubKeyForTransfer, + maxFee: defaultFee + }) + + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.snew-funtatus).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`getFee for transferFioDomain`, async () => { + const result = await fioSdk2.sdk.genericAction('getFeeForTransferFioDomain', { + fioAddress: newFioAddress + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + }) + + it(`Transfer fio domain`, async () => { + const result = await fioSdk2.sdk.genericAction('transferFioDomain', { + fioDomain: newFioDomain, + newOwnerKey: pubKeyForTransfer, + maxFee: defaultFee + }) + + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it.skip(`Bahamas: getFee for addBundledTransactions`, async () => { + const result = await fioSdk2.sdk.genericAction('getFeeForAddBundledTransactions', { + fioAddress: newFioAddress + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + }) + + it.skip(`Bahamas: add Bundled Transactions`, async () => { + const result = await fioSdk2.sdk.genericAction('addBundledTransactions', { + fioAddress: newFioAddress, + bundleSets: defaultBundledSets, + maxFee: defaultFee + }) + + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`(push_transaction) user1 run addbundles with sets for FIO Address owned by user2`, async () => { + try { + const result = await fioSdk2.sdk.genericAction('pushTransaction', { + action: 'addbundles', + account: 'fio.address', + data: { + fio_address: newFioAddress, + bundle_sets: defaultBundledSets, + max_fee: defaultFee, + technologyProviderId: '' + } + }) + //console.log('Result: ', result); + expect(result.status).to.equal('OK'); + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } +}) + + it(`Renew fio address`, async () => { + const result = await fioSdk2.sdk.genericAction('renewFioAddress', { fioAddress: newFioAddress, maxFee: defaultFee }) + + expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.expiration).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`Push Transaction - renewaddress`, async () => { + await timeout(2000) + const result = await fioSdk2.sdk.genericAction('pushTransaction', { + action: 'renewaddress', + account: 'fio.address', + data: { + fio_address: newFioAddress, + max_fee: defaultFee, + tpid: '' + } + }) + + expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.expiration).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`getFee for addPublicAddress`, async () => { + try { + const result = await fioSdk2.sdk.genericAction('getFeeForAddPublicAddress', { + fioAddress: newFioAddress + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } + }) + + it(`Add public address`, async () => { + try { + const result = await fioSdk2.sdk.genericAction('addPublicAddress', { + fioAddress: newFioAddress, + chainCode: 'ABC', + tokenCode: 'ABC', + publicAddress: '1PMycacnJaSqwwJqjawXBErnLsZ7RkXUAs', + maxFee: defaultFee, + technologyProviderId: '' + }) + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } + }) + + it(`Add public addresses`, async () => { + const result = await fioSdk2.sdk.genericAction('addPublicAddresses', { + fioAddress: newFioAddress, + publicAddresses: [ + { + chain_code: ethChainCode, + token_code: ethTokenCode, + public_address: 'xxxxxxyyyyyyzzzzzz', + }, + { + chain_code: fioChainCode, + token_code: fioTokenCode, + public_address: publicKey, + } + ], + maxFee: defaultFee, + technologyProviderId: '' + }) + + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`getFee for removePublicAddresses`, async () => { + const result = await fioSdk2.sdk.genericAction('getFeeForRemovePublicAddresses', { + fioAddress: newFioAddress + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + }) + + it(`Remove public addresses`, async () => { + + const result = await fioSdk2.sdk.genericAction('removePublicAddresses', { + fioAddress: newFioAddress, + publicAddresses: [ + { + chain_code: ethChainCode, + token_code: ethTokenCode, + public_address: 'xxxxxxyyyyyyzzzzzz', + } + ], + maxFee: defaultFee, + technologyProviderId: '' + }) + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`getFee for removeAllPublicAddresses`, async () => { + + const result = await fioSdk2.sdk.genericAction('getFeeForRemoveAllPublicAddresses', { + fioAddress: newFioAddress + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + }) + + it(`Remove all public addresses`, async () => { + await fioSdk2.sdk.genericAction('addPublicAddresses', { + fioAddress: newFioAddress, + publicAddresses: [ + { + chain_code: ethChainCode, + token_code: ethTokenCode, + public_address: 'xxxxxxyyyyyyzzzzzz1', + } + ], + maxFee: defaultFee, + technologyProviderId: '' + }) + + const result = await fioSdk2.sdk.genericAction('removeAllPublicAddresses', { + fioAddress: newFioAddress, + maxFee: defaultFee, + technologyProviderId: '' + }) + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`isAvailable true`, async () => { + const result = await fioSdk2.sdk.genericAction('isAvailable', { + fioName: generateTestingFioAddress(), + }) + + expect(result.is_registered).to.equal(0) + }) + + it(`isAvailable false`, async () => { + const result = await fioSdk2.sdk.genericAction('isAvailable', { + fioName: testFioAddressName + }) + + expect(result.is_registered).to.equal(1) + }) + + it(`getFioBalance for custom fioPublicKey`, async () => { + const result = await fioSdk2.sdk.genericAction('getFioBalance', { + fioPublicKey: publicKey2 + }) + + expect(result).to.have.all.keys('balance', 'available') + expect(result.balance).to.be.a('number') + }) + + + it(`getFioAddresses`, async () => { + try { + const result = await fioSdk2.sdk.genericAction('getFioAddresses', { fioPublicKey: publicKey }) + + expect(result).to.have.all.keys('fio_addresses','more') + expect(result.fio_addresses).to.be.a('array') + } catch (e) { + console.log(e); + } + }) + + + it(`getPublicAddress`, async () => { + const result = await fioSdk2.sdk.genericAction('getPublicAddress', { + fioAddress: newFioAddress, chainCode: fioChainCode, tokenCode: fioTokenCode + }) + + expect(result.public_address).to.be.a('string') + }) + + it(`getFee`, async () => { + const result = await fioSdk2.sdk.genericAction('getFee', { + endPoint: 'register_fio_address', + fioAddress: '' + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + }) + + it(`getMultiplier`, async () => { + const result = await fioSdk2.sdk.genericAction('getMultiplier', {}) + + expect(result).to.be.a('number') + }) + + it(`getFee for BurnFioAddress`, async () => { + const result = await fioSdk2.sdk.genericAction('getFeeForBurnFioAddress', { + fioAddress: newFioAddress + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + }) + + it(`Burn fio address`, async () => { + const result = await fioSdk2.sdk.genericAction('burnFioAddress', { + fioAddress: newFioAddress, + maxFee: defaultFee + }) + + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + +}) + +describe('Request funds, approve and send', () => { + const fundsAmount = 3 + let requestId + const memo = 'testing fund request' + + it(`getFee for requestFunds`, async () => { + const result = await fioSdk2.sdk.genericAction('getFeeForNewFundsRequest', { + payeeFioAddress: testFioAddressName2 + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + }) + + it(`requestFunds`, async () => { + const result = await fioSdk2.sdk.genericAction('requestFunds', { + payerFioAddress: testFioAddressName, + payeeFioAddress: testFioAddressName2, + payeeTokenPublicAddress: publicKey2, + amount: fundsAmount, + chainCode: fioChainCode, + tokenCode: fioTokenCode, + memo: '', + maxFee: defaultFee, + payerFioPublicKey: publicKey, + technologyProviderId: '', + hash: '', + offLineUrl: '' + }) + //console.log('requestFunds: ', result) + requestId = result.fio_request_id + expect(result).to.have.all.keys('fio_request_id', 'status', 'fee_collected') + expect(result.fio_request_id).to.be.a('number') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`getPendingFioRequests`, async () => { + await timeout(4000) + const result = await fioSdk.sdk.genericAction('getPendingFioRequests', {}) + expect(result).to.have.all.keys('requests', 'more') + expect(result.requests).to.be.a('array') + expect(result.more).to.be.a('number') + const pendingReq = result.requests.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) + expect(pendingReq).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'time_stamp', 'content') + expect(pendingReq.fio_request_id).to.be.a('number') + expect(pendingReq.fio_request_id).to.equal(requestId) + expect(pendingReq.payer_fio_address).to.be.a('string') + expect(pendingReq.payer_fio_address).to.equal(testFioAddressName) + expect(pendingReq.payee_fio_address).to.be.a('string') + expect(pendingReq.payee_fio_address).to.equal(testFioAddressName2) + }) + + it(`recordObtData`, async () => { + const result = await fioSdk.sdk.genericAction('recordObtData', { + fioRequestId: requestId, + payerFioAddress: testFioAddressName, + payeeFioAddress: testFioAddressName2, + payerTokenPublicAddress: publicKey, + payeeTokenPublicAddress: publicKey2, + amount: fundsAmount, + chainCode: fioChainCode, + tokenCode: fioTokenCode, + status: 'sent_to_blockchain', + obtId: '', + maxFee: defaultFee, + }) + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`getSentFioRequests`, async () => { + const result = await fioSdk2.sdk.genericAction('getSentFioRequests', {}) + expect(result).to.have.all.keys('requests', 'more') + expect(result.requests).to.be.a('array') + expect(result.more).to.be.a('number') + /* const pendingReq = result.requests.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) + expect(pendingReq).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'status', 'time_stamp', 'content') + expect(pendingReq.fio_request_id).to.be.a('number') + expect(pendingReq.fio_request_id).to.equal(requestId) + expect(pendingReq.payer_fio_address).to.be.a('string') + expect(pendingReq.payer_fio_address).to.equal(testFioAddressName) + expect(pendingReq.payee_fio_address).to.be.a('string') + expect(pendingReq.payee_fio_address).to.equal(testFioAddressName2) */ + }) + + it(`Payer getObtData`, async () => { + await timeout(10000) + const result = await fioSdk.sdk.genericAction('getObtData', {}) + expect(result).to.have.all.keys('obt_data_records', 'more') + expect(result.obt_data_records).to.be.a('array') + expect(result.more).to.be.a('number') + const obtData = result.obt_data_records.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) + expect(obtData).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'status', 'time_stamp', 'content') + expect(obtData.fio_request_id).to.be.a('number') + expect(obtData.fio_request_id).to.equal(requestId) + expect(obtData.payer_fio_address).to.be.a('string') + expect(obtData.payer_fio_address).to.equal(testFioAddressName) + expect(obtData.payee_fio_address).to.be.a('string') + expect(obtData.payee_fio_address).to.equal(testFioAddressName2) + }) + + it(`Payee getObtData`, async () => { + const result = await fioSdk2.sdk.genericAction('getObtData', {}) + expect(result).to.have.all.keys('obt_data_records', 'more') + expect(result.obt_data_records).to.be.a('array') + expect(result.more).to.be.a('number') + const obtData = result.obt_data_records.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) + expect(obtData).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'status', 'time_stamp', 'content') + expect(obtData.fio_request_id).to.be.a('number') + expect(obtData.fio_request_id).to.equal(requestId) + expect(obtData.payer_fio_address).to.be.a('string') + expect(obtData.payer_fio_address).to.equal(testFioAddressName) + expect(obtData.payee_fio_address).to.be.a('string') + expect(obtData.payee_fio_address).to.equal(testFioAddressName2) + }) + +}) + +describe('Request funds, cancel funds request', () => { + const fundsAmount = 3 + let requestId + const memo = 'testing fund request' + + it(`requestFunds`, async () => { + const result = await fioSdk2.sdk.genericAction('requestFunds', { + payerFioAddress: testFioAddressName, + payeeFioAddress: testFioAddressName2, + payeePublicAddress: testFioAddressName2, + amount: fundsAmount, + chainCode: fioChainCode, + tokenCode: fioTokenCode, + memo, + maxFee: defaultFee, + }) + + requestId = result.fio_request_id + expect(result).to.have.all.keys('fio_request_id', 'status', 'fee_collected') + expect(result.fio_request_id).to.be.a('number') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`cancel request`, async () => { + try{ + const result = await fioSdk2.sdk.genericAction('cancelFundsRequest', { + fioRequestId: requestId, + maxFee: defaultFee, + tpid: '' + }) + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + } catch (e) { + console.log(e); + } + }) + + + it(`getCancelledFioRequests`, async () => { + try{ + await timeout(4000) + const result = await fioSdk2.sdk.genericAction('getCancelledFioRequests', {}) + expect(result).to.have.all.keys('requests', 'more') + expect(result.requests).to.be.a('array') + expect(result.more).to.be.a('number') + const pendingReq = result.requests.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) + expect(pendingReq).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'time_stamp', 'content', 'status') + expect(pendingReq.fio_request_id).to.be.a('number') + expect(pendingReq.fio_request_id).to.equal(requestId) + expect(pendingReq.payer_fio_address).to.be.a('string') + expect(pendingReq.payer_fio_address).to.equal(testFioAddressName) + expect(pendingReq.payee_fio_address).to.be.a('string') + expect(pendingReq.payee_fio_address).to.equal(testFioAddressName2) + } catch (e) { + console.log(e); + } + }) + +}) + +describe('Request funds, reject', () => { + const fundsAmount = 4 + let requestId + const memo = 'testing fund request' + + it(`requestFunds`, async () => { + const result = await fioSdk2.sdk.genericAction('requestFunds', { + payerFioAddress: testFioAddressName, + payeeFioAddress: testFioAddressName2, + payeePublicAddress: testFioAddressName2, + amount: fundsAmount, + chainCode: fioChainCode, + tokenCode: fioTokenCode, + memo, + maxFee: defaultFee, + }) + + requestId = result.fio_request_id + expect(result).to.have.all.keys('fio_request_id', 'status', 'fee_collected') + expect(result.fio_request_id).to.be.a('number') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`getPendingFioRequests`, async () => { + await timeout(4000) + const result = await fioSdk.sdk.genericAction('getPendingFioRequests', {}) + + expect(result).to.have.all.keys('requests', 'more') + expect(result.requests).to.be.a('array') + expect(result.more).to.be.a('number') + const pendingReq = result.requests.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) + expect(pendingReq).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'time_stamp', 'content') + expect(pendingReq.fio_request_id).to.be.a('number') + expect(pendingReq.fio_request_id).to.equal(requestId) + expect(pendingReq.payer_fio_address).to.be.a('string') + expect(pendingReq.payer_fio_address).to.equal(testFioAddressName) + expect(pendingReq.payee_fio_address).to.be.a('string') + expect(pendingReq.payee_fio_address).to.equal(testFioAddressName2) + }) + + it(`getFee for rejectFundsRequest`, async () => { + const result = await fioSdk2.sdk.genericAction('getFeeForRejectFundsRequest', { + payerFioAddress: testFioAddressName2 + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + }) + + it(`rejectFundsRequest`, async () => { + const result = await fioSdk.sdk.genericAction('rejectFundsRequest', { + fioRequestId: requestId, + maxFee: defaultFee, + }) + + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + +}) + +describe('Transfer tokens', () => { + const fundsAmount = FIOSDK.SUFUnit + let fioBalance = 0 + let fioBalanceAfter = 0 + + it(`Check balance before transfer`, async () => { + const result = await fioSdk2.sdk.genericAction('getFioBalance', {}) + fioBalance = result.balance + }) + + it(`Transfer tokens`, async () => { + const result = await fioSdk.sdk.genericAction('transferTokens', { + payeeFioPublicKey: publicKey2, + amount: fundsAmount, + maxFee: defaultFee, + }) + expect(result).to.have.all.keys('status', 'fee_collected', 'transaction_id', 'block_num') + expect(result.status).to.be.a('string') + expect(result.transaction_id).to.be.a('string') + expect(result.block_num).to.be.a('number') + expect(result.fee_collected).to.be.a('number') + }) + + it(`Check balance and balance change`, async () => { + await timeout(10000) + const result = await fioSdk2.sdk.genericAction('getFioBalance', {}) + fioBalanceAfter = result.balance + expect(fundsAmount).to.equal(fioBalanceAfter - fioBalance) + }) +}) + +describe('Record obt data, check', () => { + const obtId = generateObtId() + const fundsAmount = 4.5 + + it(`getFee for recordObtData`, async () => { + const result = await fioSdk.sdk.genericAction('getFeeForRecordObtData', { + payerFioAddress: testFioAddressName + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + }) + + it(`recordObtData`, async () => { + const result = await fioSdk.sdk.genericAction('recordObtData', { + fioRequestId: '', + payerFioAddress: testFioAddressName, + payeeFioAddress: testFioAddressName2, + payerTokenPublicAddress: publicKey, + payeeTokenPublicAddress: publicKey2, + amount: fundsAmount, + chainCode: fioChainCode, + tokenCode: fioTokenCode, + status: 'sent_to_blockchain', + obtId, + maxFee: defaultFee, + }) + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`Payer getObtData`, async () => { + await timeout(4000) + const result = await fioSdk.sdk.genericAction('getObtData', { tokenCode: fioTokenCode }) + expect(result).to.have.all.keys('obt_data_records', 'more') + expect(result.obt_data_records).to.be.a('array') + expect(result.more).to.be.a('number') + const obtData = result.obt_data_records.find(pr => pr.content.obt_id === obtId) + expect(obtData).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'status', 'time_stamp', 'content') + expect(obtData.content.obt_id).to.be.a('string') + expect(obtData.content.obt_id).to.equal(obtId) + expect(obtData.payer_fio_address).to.be.a('string') + expect(obtData.payer_fio_address).to.equal(testFioAddressName) + expect(obtData.payee_fio_address).to.be.a('string') + expect(obtData.payee_fio_address).to.equal(testFioAddressName2) + }) + + it(`Payee getObtData`, async () => { + const result = await fioSdk2.sdk.genericAction('getObtData', { tokenCode: fioTokenCode }) + expect(result).to.have.all.keys('obt_data_records', 'more') + expect(result.obt_data_records).to.be.a('array') + expect(result.more).to.be.a('number') + /* const obtData = result.obt_data_records.find(pr => pr.content.obt_id === obtId) + expect(obtData).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'status', 'time_stamp', 'content') + expect(obtData.content.obt_id).to.be.a('string') + expect(obtData.content.obt_id).to.equal(obtId) + expect(obtData.payer_fio_address).to.be.a('string') + expect(obtData.payer_fio_address).to.equal(testFioAddressName) + expect(obtData.payee_fio_address).to.be.a('string') + expect(obtData.payee_fio_address).to.equal(testFioAddressName2) */ + }) +}) + +describe('Encrypting/Decrypting', () => { + const alicePrivateKey = '5J35xdLtcPvDASxpyWhNrR2MfjSZ1xjViH5cvv15VVjqyNhiPfa' + const alicePublicKey = 'FIO6NxZ7FLjjJuHGByJtNJQ1uN1P5X9JJnUmFW3q6Q7LE7YJD4GZs' + const bobPrivateKey = '5J37cXw5xRJgE869B5LxC3FQ8ZJECiYnsjuontcHz5cJsz5jhb7' + const bobPublicKey = 'FIO4zUFC29aq8uA4CnfNSyRZCnBPya2uQk42jwevc3UZ2jCRtepVZ' + + const nonPartyPrivateKey = '5HujRtqceTPo4awwHAEdHRTWdMTgA6s39dJjwWcjhNdSjVWUqMk' + const nonPartyPublicKey = 'FIO5mh1UqE5v9TKdYm2Ro6JXCXpSxj1Sm4vKUeydaLd7Cu5aqiSSp' + const NEW_FUNDS_CONTENT = 'new_funds_content' + const RECORD_OBT_DATA_CONTENT = 'record_obt_data_content' + + let fioSDKBob = new FIOSDK( + bobPrivateKey, + bobPublicKey, + config.BASE_URL, + fetchJson + ) + + it(`Encrypt/Decrypt - Request New Funds`, async () => { + const payeeTokenPublicAddress = bobPublicKey + const amount = 1.57 + const chainCode = 'FIO' + const tokenCode = 'FIO' + const memo = 'testing encryption does it work?' + const hash = '' + const offlineUrl = '' + + const content = { + payee_public_address: payeeTokenPublicAddress, + amount: amount, + chain_code: chainCode, + token_code: tokenCode, + memo, + hash, + offline_url: offlineUrl + } + + const cipherContent = fioSDKBob.transactions.getCipherContent(NEW_FUNDS_CONTENT, content, bobPrivateKey, alicePublicKey) + expect(cipherContent).to.be.a('string') + + const uncipherContent = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, alicePrivateKey, bobPublicKey) + expect(uncipherContent.payee_public_address).to.equal(bobPublicKey) + + // same party, ensure cannot decipher + try { + const uncipherContentSameParty = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, alicePrivateKey, alicePublicKey) + expect(uncipherContentSameParty.payee_public_address).to.notequal(bobPublicKey) + } catch (e) { + + } + + // non party, ensure cannot decipher + try { + const uncipherContentNonParty = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, nonPartyPrivateKey, bobPublicKey) + expect(uncipherContentNonParty.payee_public_address).to.notequal(bobPublicKey) + } catch (e) { + + } + + try { + const uncipherContentNonPartyA = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, bobPrivateKey, nonPartyPublicKey) + expect(uncipherContentNonPartyA.payee_public_address).to.notequal(bobPublicKey) + } catch (e) { + + } + + }) + + it(`Decrypt from iOS SDK - Request New Funds`, async () => { + const cipherContent = 'iNz623p8SjbFG3rNbxLeVzQhs7n4aB8UGHvkF08HhBXD3X9g6bVFJl93j/OqYdkiycxShF64uc9OHFc/qbOeeS8+WVL2YRpd9JaRqdTUE9XKFPZ6lETQ7MTbGT+qppMoJ0tWCP6mWL4M9V1xu6lE3lJkuRS4kXnwtOUJOcBDG7ddFyHaV1LnLY/jnOJHJhm8' + expect(cipherContent).to.be.a('string') + + const uncipherContent = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, alicePrivateKey, bobPublicKey) + expect(uncipherContent.payee_public_address).to.equal(bobPublicKey) + + const uncipherContentA = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, bobPrivateKey, alicePublicKey) + expect(uncipherContentA.payee_public_address).to.equal(bobPublicKey) + + }) + + it(`Decrypt from Kotlin SDK - Request New Funds`, async () => { + const cipherContent = 'PUEe6pA4HAl7EHA1XFRqJPMjrugD0ZT09CDx4/rH3ktwqo+WaoZRIuqXR4Xvr6ki1XPp7KwwSy6GqPUuBRuBS8Z8c0/xGgcDXQHJuYSsaV3d9Q61W1JeCDvsSIOdd3MTzObNJNcMj3gad+vPcOvJ7BojeufUoe0HQvxjXO+Gpp20UPdQnljLVsir+XuFmreZwMLWfggIovd0A9t438o+DA==' + expect(cipherContent).to.be.a('string') + + const uncipherContent = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, alicePrivateKey, bobPublicKey) + expect(uncipherContent.payee_public_address).to.equal(bobPublicKey) + + const uncipherContentA = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, bobPrivateKey, alicePublicKey) + expect(uncipherContentA.payee_public_address).to.equal(bobPublicKey) + + }) + + it(`Encrypt/Decrypt - RecordObtData`, async () => { + const payerTokenPublicAddress = alicePublicKey + const payeeTokenPublicAddress = bobPublicKey + const amount = 1.57 + const chainCode = 'FIO' + const tokenCode = 'FIO' + const memo = 'testing TypeScript SDK encryption does it work?' + const hash = '' + const offlineUrl = '' + + const content = { + payer_public_address: payerTokenPublicAddress, + payee_public_address: payeeTokenPublicAddress, + amount: amount, + chain_code: chainCode, + token_code: tokenCode, + status: '', + obt_id: '', + memo: memo, + hash: hash, + offline_url: offlineUrl + } + + const cipherContent = fioSDKBob.transactions.getCipherContent(RECORD_OBT_DATA_CONTENT, content, bobPrivateKey, alicePublicKey) + expect(cipherContent).to.be.a('string') + + const uncipherContent = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, alicePrivateKey, bobPublicKey) + expect(uncipherContent.payee_public_address).to.equal(bobPublicKey) + + // same party, ensure cannot decipher + try { + const uncipherContentSameParty = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, alicePrivateKey, alicePublicKey) + expect(uncipherContentSameParty.payee_public_address).to.notequal(bobPublicKey) + } catch (e) { + // successful, on failure. Should not decrypt + } + + // non party, ensure cannot decipher + try { + const uncipherContentNonParty = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, nonPartyPrivateKey, bobPublicKey) + expect(uncipherContentNonParty.payee_public_address).to.notequal(bobPublicKey) + } catch (e) { + + } + + try { + const uncipherContentNonPartyA = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, bobPrivateKey, nonPartyPublicKey) + expect(uncipherContentNonPartyA.payee_public_address).to.notequal(bobPublicKey) + } catch (e) { + + } + + }) + + it(`Decrypt from iOS SDK - RecordObtData`, async () => { + const cipherContent = 'XJqqkHspW0zp+dHKj9TZMn5mZzdMQrdIAXNOlKPekeEpbjyeh92hO+lB9gA6wnNuq8YNLcGA1s0NPGzb+DlHzXT2tCulgk5fiQy6+8AbThPzB0N6xICmVV3Ontib8FVlTrVrqg053PK9JeHUsg0Sb+vG/dz9+ovcSDHaByxybRNhZOVBe8jlg91eakaU1H8XKDxYOtI3+jYESK02g2Rw5Ya9ec+/PnEBQ6DjkHruKDorEF1D+nDT/0CK46VsfdYzYK8IV0T9Nal4H6Bf4wrMlQ==' + expect(cipherContent).to.be.a('string') + + const uncipherContent = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, alicePrivateKey, bobPublicKey) + expect(uncipherContent.payee_public_address).to.equal(bobPublicKey) + + const uncipherContentA = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, bobPrivateKey, alicePublicKey) + expect(uncipherContentA.payee_public_address).to.equal(bobPublicKey) + + }) + + it(`Decrypt from Kotlin SDK - RecordObtData`, async () => { + const cipherContent = '4IVNiV3Vg0/ZwkBywOWjSgER/aBzHypmfYoljA7y3Qf04mI/IkwPwO9+yj7EISTdRb2LEPgEDg1RsWBdAFmm6AE9ZXG1W5qPrtFNZuZw3qhCJbisnTLCPA2pEcAGKxBhhTaIx74/+OLXTNq5Z7RWWB+OUIa3bBJLHyhO79BUQ9dIsfiDVGmlRL5yq57uqRfb8FWoQraK31As/OFJ5Gj7KEYehzviJnMX7pYhE4CJkkfYYGfB4AHmHllFSMaLCrkY8BvDViQZTuniqDOua6Po51muyCaJLF5rdMSS0Za5F9U=' + expect(cipherContent).to.be.a('string') + + const uncipherContent = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, alicePrivateKey, bobPublicKey) + expect(uncipherContent.payee_public_address).to.equal(bobPublicKey) + + const uncipherContentA = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, bobPrivateKey, alicePublicKey) + expect(uncipherContentA.payee_public_address).to.equal(bobPublicKey) + + }) + +}) + +describe.skip('Check prepared transaction', () => { + it(`requestFunds prepared transaction`, async () => { + fioSdk2.setSignedTrxReturnOption(true) + const preparedTrx = await fioSdk2.sdk.genericAction('requestFunds', { + payerFioAddress: testFioAddressName, + payeeFioAddress: testFioAddressName2, + payeePublicAddress: testFioAddressName2, + amount: 200000, + chainCode: fioChainCode, + tokenCode: fioTokenCode, + memo: 'prepared transaction', + maxFee: defaultFee, + }) + const result = await fioSdk2.executePreparedTrx(EndPoint.newFundsRequest, preparedTrx) + expect(result).to.have.all.keys('fio_request_id', 'status', 'fee_collected') + expect(result.fio_request_id).to.be.a('number') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + fioSdk2.setSignedTrxReturnOption(false) + }) +}) diff --git a/tests/transfer-address.js b/tests/transfer-address.js index bcf46347..4ddabdae 100644 --- a/tests/transfer-address.js +++ b/tests/transfer-address.js @@ -873,7 +873,6 @@ describe('D. transferFioAddress Error testing', () => { }) - describe('E. Confirm active producers and proxy cannot transfer address', () => { let user1, prod1, proxy1, transfer_fio_address_fee @@ -1001,7 +1000,6 @@ describe('E. Confirm active producers and proxy cannot transfer address', () => }) - describe('BRAVO ONLY: Confirm users with OBT records or Requests cannot transfer addresses', () => { let user1, user2, user3, user4, transfer_fio_address_fee From bc640742b7b5e4dd96b43ef754cbe48608b7bf77 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Fri, 8 Jan 2021 15:10:52 -0700 Subject: [PATCH 33/76] remove keys --- tests/testnet.smoketest.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/testnet.smoketest.js b/tests/testnet.smoketest.js index e11ca645..2c60a4e1 100644 --- a/tests/testnet.smoketest.js +++ b/tests/testnet.smoketest.js @@ -11,15 +11,15 @@ let privateKey, publicKey, testFioAddressName, privateKey2, publicKey2, testFioA /** * Set your testnet existing private/public keys and existing fioAddresses (not needed if running locally) */ -privateKey = '5Jw78NzS2QMvjcyemCgJ9XQv8SMSEvTEuLxF8TcKf27xWcX5fmw', -publicKey = 'FIO8k7N7jU9eyj57AfazGxMuvPGZG5hvXNUyxt9pBchnkXXx9KUuD', +privateKey = '', +publicKey = '', account = '', -privateKey2 = '5Hv1zRFa7XRo395dfHS8xrviszPiVYeBhQjJq4TsPv53NvAcfyU', -publicKey2 = 'FIO7b3WHTsS1wTF2dAUvE9DoDXvxYUVA8FepLW6x9Bv5rPJnUW6ab', +privateKey2 = '', +publicKey2 = '', account2 = '', testFioDomain = 'fiotestnet', -testFioAddressName = 'ebtest1@fiotestnet', -testFioAddressName2 = 'ebtest3@fiotestnet' +testFioAddressName = '', +testFioAddressName2 = '' const fioTestnetDomain = 'fiotestnet' const fioTokenCode = 'FIO' From 2660bca7fbfad8148f4dfd399a3e38916cb4e6b3 Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Sat, 9 Jan 2021 13:16:27 -0700 Subject: [PATCH 34/76] create smoke tests for test net this creates tests for minimal testing on test net. --- tests/transfer-locked-tokens-smoke-tests.js | 574 ++++++++++++++++++++ 1 file changed, 574 insertions(+) create mode 100644 tests/transfer-locked-tokens-smoke-tests.js diff --git a/tests/transfer-locked-tokens-smoke-tests.js b/tests/transfer-locked-tokens-smoke-tests.js new file mode 100644 index 00000000..ba4563d8 --- /dev/null +++ b/tests/transfer-locked-tokens-smoke-tests.js @@ -0,0 +1,574 @@ +require('mocha') +const {expect} = require('chai') +const {newUser, getProdVoteTotal, fetchJson, generateFioDomain, callFioApi, generateFioAddress, createKeypair} = require('../utils.js'); +const {FIOSDK } = require('@fioprotocol/fiosdk') +config = require('../config.js'); + +before(async () => { + faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); +}) + +function wait(ms){ + var start = new Date().getTime(); + var end = start; + while(end < start + ms) { + end = new Date().getTime(); + } +} + +let userA1, keys, locksdk +const fundsAmount = 50000000000 //50 fio + + +describe(`************************** transfer-locked-tokens.js ************************** \n A. Create accounts for tests`, () => { + +//These tests are for test net only... +// The userA1 account used must be funded through the test net faucet. +//the account does NOT need funded by the faucet every time the tests are run, the account +//should have enough FIO to run these tests perhaps 19 times. and the account should be funded +// on test net at this time. if funds are not adequate +//just go to the testnet monitor faucet and fund the pub key FIO7KbD6G6gFuTvv8xiJzKSmkUauq5Gm48uECiPkVDcwJhBY6njfB +// These tests will provide a set of tests on general locks that can be run to show that + //the locks are functioning without error on test net., it is not meant to be comprehensive, but just + // a functional smoke check for the test net. + it(`Create users`, async () => { + // userA1.account: 3lv2dsu2oavw + // userA1.publicKey: FIO7KbD6G6gFuTvv8xiJzKSmkUauq5Gm48uECiPkVDcwJhBY6njfB + // userA1.privateKey: 5KUtrhW1xrHxR5LSdeTjWGVrvN8Zv3Neg8zq9wDWiAvMzUiogeW + //NOTE -- this userA1 must be funded on test net. + userA1 = new FIOSDK('5KUtrhW1xrHxR5LSdeTjWGVrvN8Zv3Neg8zq9wDWiAvMzUiogeW', + 'FIO7KbD6G6gFuTvv8xiJzKSmkUauq5Gm48uECiPkVDcwJhBY6njfB', + config.BASE_URL, fetchJson); + + keys = await createKeypair(); + locksdk = new FIOSDK(keys.privateKey, keys.publicKey, config.BASE_URL, fetchJson); + + }) + + it(`Show account info`, async () => { + console.log(" locked token holder pub key ",keys.publicKey) + console.log(" locked token holder account ",keys.account) + console.log(" locked token holder priv key ",keys.privateKey) + }) +}) + + + +describe(`B. Parameter tests`, () => { + + //these tests use userA1 account and key info. + + + it(`Failure test, Transfer locked tokens, periods total percent not 100`, async () => { + try { + + const result = await userA1.genericAction('pushTransaction', { + action: 'trnsloctoks', + account: 'fio.token', + data: { + payee_public_key: keys.publicKey, + can_vote: 0, + periods: [ + { + duration: 120, + percent: 50.30, + }, + { + duration: 240, + percent: 50.0, + } + ], + amount: fundsAmount, + max_fee: 400000000000, + tpid: '', + actor: userA1.account, + } + }) + expect(result.status).to.not.equal('OK') + + } catch (err) { + var expected = `Error 400` + expect(err.message).to.include(expected) + } + }) + + it(`Failure test, Transfer locked tokens, period percent larger than 3 decimals`, async () => { + try { + const result = await userA1.genericAction('pushTransaction', { + action: 'trnsloctoks', + account: 'fio.token', + data: { + payee_public_key: keys.publicKey, + can_vote: 0, + periods: [ + { + duration: 120, + percent: 50.4444, + }, + { + duration: 240, + percent: 49.5556, + } + ], + amount: fundsAmount, + max_fee: 400000000000, + tpid: '', + actor:'3lv2dsu2oavw', + } + + }) + expect(result.status).to.not.equal('OK') + + } catch (err) { + var expected = `Error 400` + expect(err.message).to.include(expected) + } + }) + + it(`Failure test, Transfer locked tokens, periods are not in ascending order of duration`, async () => { + try { + const result = await userA1.genericAction('pushTransaction', { + action: 'trnsloctoks', + account: 'fio.token', + data: { + payee_public_key: keys.publicKey, + can_vote: 0, + periods: [ + { + duration: 240, + percent: 50.4444, + }, + { + duration: 120, + percent: 49.5556, + } + ], + amount: fundsAmount, + max_fee: 400000000000, + tpid: '', + actor: '3lv2dsu2oavw', + } + + }) + expect(result.status).to.not.equal('OK') + + } catch (err) { + var expected = `Error 400` + expect(err.message).to.include(expected) + } + }) + + it(`Failure test, Transfer locked tokens, duration 0`, async () => { + try { + const result = await userA1.genericAction('pushTransaction', { + action: 'trnsloctoks', + account: 'fio.token', + data: { + payee_public_key: keys.publicKey, + can_vote: 0, + periods: [ + { + duration: 0, + percent: 50.0, + }, + { + duration: 240, + percent: 50.0, + } + ], + amount: fundsAmount, + max_fee: 400000000000, + tpid: '', + actor: '3lv2dsu2oavw' + } + + }) + expect(result.status).to.not.equal('OK') + } catch (err) { + var expected = `Error 400` + expect(err.message).to.include(expected) + } + }) + + it(`Failute test, Transfer locked tokens, pub key account pre exists`, async () => { + try { + const result = await userA1.genericAction('pushTransaction', { + action: 'trnsloctoks', + account: 'fio.token', + data: { + payee_public_key: userA1.publicKey, + can_vote: 0, + periods: [ + { + duration: 0, + percent: 50.0, + }, + { + duration: 240, + percent: 50.0, + } + ], + amount: fundsAmount, + max_fee: 400000000000, + tpid: '', + actor: '3lv2dsu2oavw' + } + + }) + expect(result.status).to.not.equal('OK') + } catch (err) { + var expected = `Error 400` + expect(err.message).to.include(expected) + } + }) + + it(`Failute test, Too many lock periods`, async () => { + try { + const result = await userA1.genericAction('pushTransaction', { + action: 'trnsloctoks', + account: 'fio.token', + data: { + payee_public_key: keys.publicKey, + can_vote: 0, + periods: [ + { + duration: 1, + percent: 0.273, + }, + { + duration: 2, + percent: .273, + }, + { + duration: 3, + percent: .273, + }, + { + duration: 4, + percent: .273, + }, + { + duration: 5, + percent: .273, + }, + { + duration: 6, + percent: .273, + }, + { + duration: 7, + percent: .273, + }, + { + duration: 8, + percent: .273, + }, + { + duration: 9, + percent: .273, + }, + { + duration: 10, + percent: .273, + }, + { + duration: 11, + percent: .273, + }, + { + duration: 12, + percent: .273, + }, + { + duration: 13, + percent: .273, + }, + { + duration: 14, + percent: .273, + }, + { + duration: 15, + percent: .273, + }, + { + duration: 16, + percent: .273, + }, + { + duration: 17, + percent: .273, + }, + { + duration: 18, + percent: .273, + }, + { + duration: 19, + percent: .273, + }, + { + duration: 20, + percent: .273, + }, + { + duration: 21, + percent: .273, + }, + { + duration: 22, + percent: .273, + }, + { + duration: 23, + percent: .273, + }, + { + duration: 24, + percent: .273, + }, + { + duration: 25, + percent: .273, + }, + { + duration: 26, + percent: .273, + }, + { + duration: 27, + percent: .273, + }, + { + duration: 28, + percent: .273, + }, + { + duration: 29, + percent: .273, + }, + { + duration: 30, + percent: .273, + }, + { + duration: 31, + percent: .273, + }, + { + duration: 32, + percent: .273, + }, + { + duration: 33, + percent: .273, + }, + { + duration: 34, + percent: .273, + }, + { + duration: 35, + percent: .273, + }, + { + duration: 36, + percent: .273, + }, + { + duration: 37, + percent: .273, + }, + { + duration: 38, + percent: .273, + }, + { + duration: 39, + percent: .273, + }, + { + duration: 40, + percent: .273, + }, + { + duration: 41, + percent: .273, + }, + { + duration: 42, + percent: .273, + }, + { + duration: 43, + percent: .273, + }, + { + duration: 44, + percent: .273, + }, + { + duration: 45, + percent: .273, + }, + { + duration: 46, + percent: .273, + }, + { + duration: 47, + percent: .273, + }, + { + duration: 48, + percent: .273, + }, + { + duration: 49, + percent: .273, + }, + { + duration: 50, + percent: .273, + }, + { + duration: 51, + percent: 86.35, + } + ], + amount: fundsAmount, + max_fee: 400000000000, + tpid: '', + actor: '3lv2dsu2oavw', + } + + }) + expect(result.status).to.not.equal('OK') + + } catch (err) { + var expected = `Error 400` + expect(err.message).to.include(expected) + } + }) + +}) + +describe(`B. transfer with 2 unlock periods, canvote = false`, () => { + + let rambefore, ramafter, balancebefore, balanceafter, feetransferlocked + + it(`get account ram before `, async () => { + try { + const result = await userA1.genericAction('getAccount', {account:'3lv2dsu2oavw'}) + expect(result.ram_quota).to.be.a('number') + rambefore = result.ram_quota + } catch (err) { + console.log('Error', err) + } + }) + + it(`getFioBalance before `, async () => { + const result = await userA1.genericAction('getFioBalance', {}) + + expect(result).to.have.all.keys('balance') + balancebefore = result.balance; + }) + + it(`SUCCESS transferLockedTokens ${fundsAmount}, canvote false, (20,40 seconds) and (40,60%)`, async () => { + try { + const result = await userA1.genericAction('pushTransaction', { + action: 'trnsloctoks', + account: 'fio.token', + data: { + payee_public_key: keys.publicKey, + can_vote: 0, + periods: [ + { + duration: 20, + percent: 40.0, + }, + { + duration: 40, + percent: 60.0, + } + ], + amount: fundsAmount, + max_fee: 400000000000, + tpid: '', + actor: '3lv2dsu2oavw', + } + + }) + expect(result.status).to.equal('OK') + expect(result).to.have.all.keys( 'status', 'fee_collected') + } catch (err) { + console.log(' Error', err) + } + }) + + it(`getFioBalance after, verify Fee transfer_locked_tokens was collected`, async () => { + const result = await userA1.genericAction('getFioBalance', {}) + + expect(result).to.have.all.keys('balance') + balanceafter = result.balance; + const result1 = await userA1.genericAction('getFee', { + endPoint: 'transfer_locked_tokens', + fioAddress: '' + }) + + let diff1 = balancebefore - balanceafter - fundsAmount + //console.log('Returned fee: ', result) + expect(diff1).to.equal(result1.fee) + + }) + + it(`verify get balance results for locked funds`, async () => { + const result = await locksdk.genericAction('getFioBalance', {}) + + expect(result).to.have.all.keys('balance') + expect(result.balance).to.be.a('number') + expect(result.balance).to.equal(50000000000) + + }) + + //try to transfer whole amount, fail. + it(`FAIL Transfer ${fundsAmount} from locked token account, no funds unlocked`, async () => { + try{ + const result = await locksdk.genericAction('transferTokens', { + payeeFioPublicKey: userA1.publicKey, + amount: fundsAmount, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + } catch (err) { + var expected = `Error 400` + expect(err.message).to.include(expected) + } + }) + + it(`get account ram after, verify RAM bump `, async () => { + try { + const result = await userA1.genericAction('getAccount', {account:'3lv2dsu2oavw'}) + expect(result.ram_quota).to.be.a('number') + ramafter = result.ram_quota + let diffram = ramafter-rambefore + expect(diffram).to.equal(1152) + } catch (err) { + console.log('Error', err) + } + }) + + it(`Transfer 1000000000000 FIO into locked funds account`, async () => { + try { + const result = await userA1.genericAction('transferTokens', { + payeeFioPublicKey: keys.publicKey, + amount: 10000000000, + maxFee: 400000000000, + tpid: '', + }) + } catch (err) { + console.log('Error', err) + } + }) + +}) From 39866bde70c07b969b8322032fcf2aad7eb3bb03 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 11 Jan 2021 08:06:14 -0700 Subject: [PATCH 35/76] Rename smoketest --- tests/Archive/testnet-smoketest.old.js | 760 +++++++++++ tests/testnet-smoketest.js | 1676 +++++++++++++++--------- tests/testnet.smoketest.js | 1182 ----------------- 3 files changed, 1809 insertions(+), 1809 deletions(-) create mode 100644 tests/Archive/testnet-smoketest.old.js delete mode 100644 tests/testnet.smoketest.js diff --git a/tests/Archive/testnet-smoketest.old.js b/tests/Archive/testnet-smoketest.old.js new file mode 100644 index 00000000..2728b39b --- /dev/null +++ b/tests/Archive/testnet-smoketest.old.js @@ -0,0 +1,760 @@ +require('mocha') +const {expect} = require('chai') +const {newUser, existingUser, callFioApi, generateFioAddress, timeout} = require('../../utils.js'); +const {FIOSDK } = require('@fioprotocol/fiosdk') +config = require('../../config.js'); + +let user1, user2, user3 + +before(async () => { + user1 = await existingUser('zzsfyigdmxmi', '5K7xWsabnxQoJAu9JnwNsMerTvCabHKaa1Q6CNYLRmjbXGUa9B8', 'FIO5NQBPnGKnhBCzhdRrrm6BD5eyYbVk2695sp2GKYLmXkR3Ycmux', 'fiotestnet', 'smoketest11@fiotestnet'); + user1.domain2 = 'transferrabledomain' + user1.address2 = 'smoketest9@transferrabledomain' + user2 = await existingUser('5cb1as5ppd3e', '5KS4d3tECgmDUfJNZnhjiVGEWqR7d6WDBjkkmf3bfRAvc9CLi7t', 'FIO5uQf2RW9JVoaCq9rze3xYZ1m8xDqFZpHCQqMQ86E9C68GRS3eM', 'fiotestnet', 'smoketest22@fiotestnet'); + user3 = await existingUser('ensfrgwbdv4n', '5HvKD3SyD88dRSag5CvPPNy7dRiuUGSmMgGHRwQW8PZ71mCupPY', 'FIO5d4Zj6MUd42hVgRt9kiVUrrNdg9zpjUeK2siRBCE4RySDdidm1', 'fiotestnet', 'smoketest33@fiotestnet'); +}) + + +describe(`************************** testnet-smoketest.js **************************`, () => {}) + +describe(`FIO Requests (error conditions only)`, () => { + let user1RequestId + const payment = 5000000000 // 5 FIO + const requestMemo = 'Memo in the initial request' + + it(`user1 requests funds from user2`, async () => { + try { + const result = await user1.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user1.address, + payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', + amount: payment, + chainCode: 'BTC', + tokenCode: 'BTC', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '', + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result.fio_request_id) + user1RequestId = result.fio_request_id + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`Create OBT in response to request with non-existent ID. Expect error type 400: ${config.error.requestNotFound}`, async () => { + try { + const result = await user2.sdk.genericAction('recordObtData', { + fioRequestId: 9999999999, + payerFioAddress: user2.address, + payeeFioAddress: user1.address, + payerTokenPublicAddress: user2.publicKey, + payeeTokenPublicAddress: user1.publicKey, + amount: 5000000000, + chainCode: "BTC", + tokenCode: "BTC", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user1.publicKey, + memo: 'this is a test', + hash: '', + offLineUrl: '' + }) + console.log('Result: ', result); + expect(result).to.equal(null); + } catch (err) { + //console.log('Error', err); + expect(err.json.fields[0].error).to.equal('No such FIO Request'); + expect(err.errorCode).to.equal(400); + } + }) + + it(`Other user3 attempts OBT with requestId from user1. Expect error type 403: ${config.error.signatureError} (part 1 with user3 as payerFioAddress)`, async () => { + try { + const result = await user3.sdk.genericAction('recordObtData', { + fioRequestId: user1RequestId, + payerFioAddress: user3.address, + payeeFioAddress: user1.address, + payerTokenPublicAddress: user3.publicKey, + payeeTokenPublicAddress: user1.publicKey, + amount: 5000000000, + chainCode: "BTC", + tokenCode: "BTC", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user1.publicKey, + memo: 'this is a test', + hash: '', + offLineUrl: '' + }) + console.log('Result: ', result); + expect(result).to.equal(null); + } catch (err) { + //console.log('Error', err); + expect(err.json.type).to.equal('invalid_signature'); + expect(err.json.message).to.equal(config.error.invalidRequestSignature); + expect(err.errorCode).to.equal(403); + } + }) + + it(`Other user3 attempts OBT with requestId from user1. Expect error type 403: ${config.error.invalidRequestSignature} (part 2 with user2 as payerFioAddress)`, async () => { + try { + const result = await user3.sdk.genericAction('recordObtData', { + fioRequestId: user1RequestId, + payerFioAddress: user2.address, + payeeFioAddress: user1.address, + payerTokenPublicAddress: user2.publicKey, + payeeTokenPublicAddress: user1.publicKey, + amount: 5000000000, + chainCode: "BTC", + tokenCode: "BTC", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user1.publicKey, + memo: 'this is a test', + hash: '', + offLineUrl: '' + }) + console.log('Result: ', result); + expect(result).to.equal(null); + } catch (err) { + //console.log('Error', err); + expect(err.json.type).to.equal('invalid_signature'); + expect(err.json.message).to.equal(config.error.invalidRequestSignature); + expect(err.errorCode).to.equal(403); + } + }) + + it(`Initial requestor user1 attempts OBT with requestId from user1. Expect error type 403: ${config.error.invalidRequestSignature}`, async () => { + try { + const result = await user1.sdk.genericAction('recordObtData', { + fioRequestId: user1RequestId, + payerFioAddress: user2.address, + payeeFioAddress: user1.address, + payerTokenPublicAddress: user2.publicKey, + payeeTokenPublicAddress: user1.publicKey, + amount: 5000000000, + chainCode: "BTC", + tokenCode: "BTC", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user1.publicKey, + memo: 'this is a test', + hash: '', + offLineUrl: '' + }) + console.log('Result: ', result); + expect(result).to.equal(null); + } catch (err) { + //console.log('Error', err); + expect(err.json.type).to.equal('invalid_signature'); + expect(err.json.message).to.equal(config.error.invalidRequestSignature); + expect(err.errorCode).to.equal(403); + } + }) +}) + +describe(`Cancel Funds Request`, () => { + const payment = 5000000000 // 5 FIO + const requestMemo = 'Memo in the initial request' + + it(`user1 requests funds from user2`, async () => { + try { + const result = await user1.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user1.address, + payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', + amount: payment, + chainCode: 'BTC', + tokenCode: 'BTC', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '', + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + user1RequestId = result.fio_request_id + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it('Wait a few seconds To make sure the obt gets recorded.', async () => { + await timeout(2000); + }) + + it(`get_sent_fio_requests for user1`, async () => { + try { + const result = await user1.sdk.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result) + numRequests = result.requests.length; + expect(result.requests[numRequests-1].fio_request_id).to.equal(user1RequestId); + expect(result.requests[numRequests-1].content.memo).to.equal(requestMemo); + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } + }) + + it(`get_pending_fio_requests for user2`, async () => { + try { + const result = await user2.sdk.genericAction('getPendingFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result) + numRequests = result.requests.length; + expect(result.requests[numRequests-1].fio_request_id).to.equal(user1RequestId); + expect(result.requests[numRequests-1].content.memo).to.equal(requestMemo); + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } + }) + + it(`Call cancel_funds_request (push transaction) to cancel request in pending state`, async () => { + try{ + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'cancelfndreq', + account: 'fio.reqobt', + data: { + "fio_request_id": user1RequestId, + "max_fee": config.api.cancel_funds_request.fee, + "tpid": '', + "actor": user1.account + } + }) + //console.log('Result: ', result); + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.equal('cancelled'); + expect(result.fee_collected).to.equal(0); + } catch (err) { + console.log('Error', err.json); + expect(err).to.equal(null); + } + }) + + it(`Verify request was cancelled: get_sent_fio_requests for user1 returns 1 request with status 'cancelled'`, async () => { + try { + const result = await user1.sdk.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result) + numRequests = result.requests.length; + expect(result.requests[numRequests-1].fio_request_id).to.equal(user1RequestId); + expect(result.requests[numRequests-1].content.memo).to.equal(requestMemo); + expect(result.requests[numRequests-1].status).to.equal('cancelled'); + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } + }) + + it(`Verify request was cancelled: get_cancelled_fio_requests returns 1 request with status 'cancelled'`, async () => { + try { + const json = { + "fio_public_key": user1.publicKey + } + result = await callFioApi("get_cancelled_fio_requests", json); + //console.log('Result: ', result); + numRequests = result.requests.length; + expect(result.requests[numRequests-1].fio_request_id).to.equal(user1RequestId); + expect(result.requests[numRequests-1].status).to.equal('cancelled'); + } catch (err) { + console.log('Error', err) + expect(err.error.message).to.equal(config.error.noFioRequests) + } + }) + +}) + +describe('Transfer domain', () => { + + let user1OrigBalance, transfer_fio_domain_fee, feeCollected + + it('Get transfer_fio_domain fee', async () => { + try { + result = await user1.sdk.getFee('transfer_fio_domain', user1.address); + transfer_fio_domain_fee = result.fee; + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`getFioNames for user1 and confirm it owns user1.domain2`, async () => { + try { + const result = await user1.sdk.genericAction('getFioNames', { + fioPublicKey: user1.publicKey + }) + //console.log('getFioNames', result) + for (domain in result.fio_domains) { + if (result.fio_domains[domain].fio_domain == user1.domain2) {break} + } + expect(result.fio_domains[domain].fio_domain).to.equal(user1.domain2); + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Get balance for user1`, async () => { + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + user1OrigBalance = result.balance + //console.log('user1 fio balance', result) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Transfer user1.domain2 to user2`, async () => { + try { + const result = await user1.sdk.genericAction('transferFioDomain', { + fioDomain: user1.domain2, + newOwnerKey: user2.publicKey, + maxFee: transfer_fio_domain_fee, + walletFioAddress: '' + }) + feeCollected = result.fee_collected; + //console.log('Result: ', result); + expect(result.status).to.equal('OK'); + } catch (err) { + console.log('Error: ', err.json.error); + expect(err).to.equal(null); + } + }) + + it('Confirm proper fee was collected', async () => { + expect(feeCollected).to.equal(transfer_fio_domain_fee) + }) + + it('Confirm fee was deducted from user1 account', async () => { + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + expect(result.balance).to.equal(user1OrigBalance - transfer_fio_domain_fee); + //console.log('user1 fio balance', result) + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`getFioNames for user1 and confirm it still owns the address registered on the domain`, async () => { + try { + const result = await user1.sdk.genericAction('getFioNames', { + fioPublicKey: user1.publicKey + }) + //console.log('getFioNames', result) + for (address in result.fio_addresses) { + if (result.fio_addresses[address].fio_address == user1.address2) {break} + } + expect(result.fio_addresses[address].fio_address).to.equal(user1.address2); + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`getFioNames for user2 and confirm it now owns the domain`, async () => { + try { + const result = await user2.sdk.genericAction('getFioNames', { + fioPublicKey: user2.publicKey + }) + //console.log('getFioNames', result) + for (domain in result.fio_domains) { + if (result.fio_domains[domain].fio_domain == user1.domain2) {break} + } + expect(result.fio_domains[domain].fio_domain).to.equal(user1.domain2); + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Transfer user1.domain2 back to user1 from user2 to clean up test`, async () => { + try { + const result = await user2.sdk.genericAction('transferFioDomain', { + fioDomain: user1.domain2, + newOwnerKey: user1.publicKey, + maxFee: transfer_fio_domain_fee, + walletFioAddress: '' + }) + feeCollected = result.fee_collected; + //console.log('Result: ', result); + expect(result.status).to.equal('OK'); + } catch (err) { + console.log('Error: ', err.json.error); + expect(err).to.equal(null); + } + }) + +}) + +describe(`Remove pub address`, () => { + + it(`Add DASH and BCH addresses to user1`, async () => { + try { + const result = await user1.sdk.genericAction('addPublicAddresses', { + fioAddress: user1.address, + publicAddresses: config.public_addresses, + maxFee: config.api.add_pub_address.fee, + walletFioAddress: '' + }) + //console.log('Result:', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it('confirm BCH address was added', async () => { + try { + const result = await user1.sdk.genericAction('getPublicAddress', { + fioAddress: user1.address, + chainCode: "BCH", + tokenCode: "BCH" + }) + //console.log('Result', result) + expect(result.public_address).to.equal('bitcoincash:qzf8zha74ahdh9j0xnwlffdn0zuyaslx3c90q7n9g9') + } catch (err) { + console.log('Error', err) + } + }) + + it(`Remove BCH and DASH from user1`, async () => { + try { + const result = await user1.sdk.genericAction('removePublicAddresses', { + fioAddress: user1.address, + publicAddresses: config.public_addresses, + maxFee: config.api.add_pub_address.fee, + tpid: '' + }) + //console.log('Result:', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it('confirm BCH address was removed', async () => { + try { + const result = await user1.sdk.genericAction('getPublicAddress', { + fioAddress: user1.address, + chainCode: "BCH", + tokenCode: "BCH" + }) + //console.log('Result', result) + } catch (err) { + //console.log('Error', err) + expect(err.json.message).to.equal(config.error.publicAddressFound) + } + }) + + it(`Add DASH and BCH addresses to user1`, async () => { + try { + const result = await user1.sdk.genericAction('addPublicAddresses', { + fioAddress: user1.address, + publicAddresses: [ + { + chain_code: 'BCH', + token_code: 'BCH', + public_address: 'bitcoincash:qn9g9', + }, + { + chain_code: 'DASH', + token_code: 'DASH', + public_address: 'XyCyPKzTWvW2XdcYjPaPXGQDCGk946ywEv', + } + ], + maxFee: config.api.add_pub_address.fee, + walletFioAddress: '' + }) + //console.log('Result:', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it('Wait a few seconds To make add_address goes through.', async () => { + await timeout(2000); + }) + + it('confirm BCH address was added', async () => { + try { + const result = await user1.sdk.genericAction('getPublicAddress', { + fioAddress: user1.address, + chainCode: "BCH", + tokenCode: "BCH" + }) + //console.log('Result', result) + expect(result.public_address).to.equal('bitcoincash:qn9g9') + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Remove All public addresses from user1`, async () => { + try { + const result = await user1.sdk.genericAction('removeAllPublicAddresses', { + fioAddress: user1.address, + maxFee: config.api.add_pub_address.fee, + tpid: '' + }) + //console.log('Result:', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it('confirm BCH address was removed', async () => { + try { + const result = await user1.sdk.genericAction('getPublicAddress', { + fioAddress: user1.address, + chainCode: "BCH", + tokenCode: "BCH" + }) + //console.log('Result', result) + } catch (err) { + //console.log('Error', err) + expect(err.json.message).to.equal(config.error.publicAddressFound) + } + }) + +}) + +describe(`Paging - FIO Address`, () => { + let addressCount = 20, newAddressCount + + // Only include if you need to generate new addresses. + it.skip(`Register ${addressCount} addresses for user3`, async () => { + for (i = 0; i < addressCount; i++) { + try { + newAddress = i + generateFioAddress(user3.domain, 7) + const result = await user3.sdk.genericAction('registerFioAddress', { + fioAddress: newAddress, + maxFee: config.api.register_fio_address.fee, + walletFioAddress: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + } + } + }) + + it(`Call (get_fio_addresses, no limit param, no offset param). Get current number of addressess.`, async () => { + try { + const json = { + "fio_public_key": user3.publicKey + } + result = await callFioApi("get_fio_addresses", json); + //console.log('Result: ', result); + newAddressCount = result.fio_addresses.length; + expect(result.fio_addresses.length).to.be.greaterThan(addressCount-1) + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Call (get_fio_addresses, limit=0, offset=0). Expect newAddressCount results.`, async () => { + try { + const json = { + "fio_public_key": user3.publicKey, + "limit": 0, + "offset": 0 + } + result = await callFioApi("get_fio_addresses", json); + //console.log('Result: ', result); + expect(result.fio_addresses.length).to.equal(newAddressCount) + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Call (get_fio_addresses, limit=1, offset=0). Expect 1 address. Expect address user3.address`, async () => { + try { + const json = { + "fio_public_key": user3.publicKey, + "limit": 1, + "offset": 0 + } + result = await callFioApi("get_fio_addresses", json); + //console.log('Result: ', result); + expect(result.fio_addresses.length).to.equal(1); + expect(result.fio_addresses[0].fio_address).to.equal(user3.address); // First character of address = 0 (1st address in list) + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Call (get_fio_addresses, limit=2, offset=4). Expect 2 address. Expect address #5-6`, async () => { + try { + const json = { + "fio_public_key": user3.publicKey, + "limit": 2, + "offset": 4 + } + result = await callFioApi("get_fio_addresses", json); + //console.log('Result: ', result); + expect(result.fio_addresses.length).to.equal(2); + expect(result.fio_addresses[0].fio_address.charAt(0)).to.equal('3'); // First character of address = 4 (5th address in list) + expect(result.fio_addresses[1].fio_address.charAt(0)).to.equal('4'); + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Call (get_fio_addresses, limit=10, offset=15). Expect address #16-20`, async () => { + try { + const json = { + "fio_public_key": user3.publicKey, + "limit": 10, + "offset": 15 + } + result = await callFioApi("get_fio_addresses", json); + //console.log('Result: ', result); + expect(result.fio_addresses[0].fio_address.charAt(0)).to.equal('1'); + expect(result.fio_addresses[0].fio_address.charAt(1)).to.equal('4'); // 15 + expect(result.fio_addresses[4].fio_address.charAt(0)).to.equal('1'); + expect(result.fio_addresses[4].fio_address.charAt(1)).to.equal('8'); // 19 + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Negative offset. Call (get_fio_addresses, limit=1, offset=-1). Expect error type 400: ${config.error.invalidOffset}`, async () => { + try { + const json = { + "fio_public_key": user3.sdk.publicKey, + "limit": 1, + "offset": -1 + } + result = await callFioApi("get_fio_addresses", json); + expect(result.status).to.equal(null); + } catch (err) { + //console.log('Error', err.error); + expect(err.error.fields[0].error).to.equal(config.error.invalidOffset); + expect(err.statusCode).to.equal(400); + } + }) + + it(`Negative limit. Call (get_fio_addresses, limit=-5, offset=5). Expect error type 400: ${config.error.invalidLimit}`, async () => { + try { + const json = { + "fio_public_key": user3.publicKey, + "limit": -5, + "offset": 5 + } + result = await callFioApi("get_fio_addresses", json); + expect(result.status).to.equal(null); + } catch (err) { + //console.log('Error', err.error); + expect(err.error.fields[0].error).to.equal(config.error.invalidLimit); + expect(err.statusCode).to.equal(400); + } + }) + + it(`Send string to limit/offset. Expect error type 500: ${config.error.parseError}`, async () => { + try { + const json = { + "fio_public_key": user3.publicKey, + "limit": "string", + "offset": "string2" + } + result = await callFioApi("get_fio_addresses", json); + expect(result.status).to.equal(null); + } catch (err) { + //console.log('Error', err.error.error); + expect(err.error.error.what).to.equal(config.error.parseError); + expect(err.statusCode).to.equal(500); + } + }) + + it(`Invalid pub key. Expect error type 400: ${config.error.invalidKey}`, async () => { + try { + const json = { + "fio_public_key": 'FIOXXXLGcmXLCw87pqNMFurd23SqqEDbCUirr7vwuwuzfaySxQ9w6', + "limit": 5, + "offset": 5 + } + result = await callFioApi("get_fio_addresses", json); + expect(result.status).to.equal(null); + } catch (err) { + //console.log('Error', err.error); + expect(err.error.fields[0].error).to.equal(config.error.invalidKey); + expect(err.statusCode).to.equal(400); + } + }) + + it(`Use floats in limit/offset. Expect valid return with zero results.`, async () => { + try { + const json = { + "fio_public_key": user3.publicKey, + "limit": 123.456, + "offset": 345.678 + } + result = await callFioApi("get_fio_addresses", json); + //console.log('Result: ', result) + expect(result.fio_addresses.length).to.equal(0) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null) + } + }) + + it(`No pub key. Expect error type 400: ${config.error.invalidKey}`, async () => { + try { + const json = { + "limit": 1, + "offset": 1 + } + result = await callFioApi("get_fio_addresses", json); + expect(result.status).to.equal(null); + } catch (err) { + //console.log('Error', err.error); + expect(err.error.fields[0].error).to.equal(config.error.invalidKey); + expect(err.statusCode).to.equal(400); + } + }) + +}) diff --git a/tests/testnet-smoketest.js b/tests/testnet-smoketest.js index 87aefd5a..aa2d52b3 100644 --- a/tests/testnet-smoketest.js +++ b/tests/testnet-smoketest.js @@ -1,760 +1,1182 @@ require('mocha') const {expect} = require('chai') -const {newUser, existingUser, callFioApi, generateFioAddress, timeout} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/fiosdk') +const {FIOSDK} = require('@fioprotocol/fiosdk') +const {newUser, existingUser, fetchJson} = require('../utils.js'); config = require('../config.js'); +const { EndPoint } = require('@fioprotocol/fiosdk/lib/entities/EndPoint') -let user1, user2, user3 +let target = 'local' +let privateKey, publicKey, testFioAddressName, privateKey2, publicKey2, testFioAddressName2 -before(async () => { - user1 = await existingUser('zzsfyigdmxmi', '5K7xWsabnxQoJAu9JnwNsMerTvCabHKaa1Q6CNYLRmjbXGUa9B8', 'FIO5NQBPnGKnhBCzhdRrrm6BD5eyYbVk2695sp2GKYLmXkR3Ycmux', 'fiotestnet', 'smoketest11@fiotestnet'); - user1.domain2 = 'transferrabledomain' - user1.address2 = 'smoketest9@transferrabledomain' - user2 = await existingUser('5cb1as5ppd3e', '5KS4d3tECgmDUfJNZnhjiVGEWqR7d6WDBjkkmf3bfRAvc9CLi7t', 'FIO5uQf2RW9JVoaCq9rze3xYZ1m8xDqFZpHCQqMQ86E9C68GRS3eM', 'fiotestnet', 'smoketest22@fiotestnet'); - user3 = await existingUser('ensfrgwbdv4n', '5HvKD3SyD88dRSag5CvPPNy7dRiuUGSmMgGHRwQW8PZ71mCupPY', 'FIO5d4Zj6MUd42hVgRt9kiVUrrNdg9zpjUeK2siRBCE4RySDdidm1', 'fiotestnet', 'smoketest33@fiotestnet'); -}) +/** + * Set your testnet existing private/public keys and existing fioAddresses (not needed if running locally) + */ +privateKey = '', +publicKey = '', +account = '', +privateKey2 = '', +publicKey2 = '', +account2 = '', +testFioDomain = 'fiotestnet', +testFioAddressName = '', +testFioAddressName2 = '' +const fioTestnetDomain = 'fiotestnet' +const fioTokenCode = 'FIO' +const fioChainCode = 'FIO' +const ethTokenCode = 'ETH' +const ethChainCode = 'ETH' +const defaultBundledSets = 1 +const defaultFee = 800 * FIOSDK.SUFUnit -describe(`************************** testnet-smoketest.js **************************`, () => {}) +let fioSdk, fioSdk2 +let newFioDomain, newFioAddress, privateKeyExample, publicKeyExample, pubKeyForTransfer -describe(`FIO Requests (error conditions only)`, () => { - let user1RequestId - const payment = 5000000000 // 5 FIO - const requestMemo = 'Memo in the initial request' +const generateTestingFioAddress = (customDomain = fioTestnetDomain) => { + return `testing${Date.now()}@${customDomain}` +} - it(`user1 requests funds from user2`, async () => { - try { - const result = await user1.sdk.genericAction('requestFunds', { - payerFioAddress: user2.address, - payeeFioAddress: user1.address, - payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', - amount: payment, - chainCode: 'BTC', - tokenCode: 'BTC', - memo: requestMemo, - maxFee: config.api.new_funds_request.fee, - payerFioPublicKey: user2.publicKey, - technologyProviderId: '', - hash: '', - offLineUrl: '' - }) - //console.log('Result: ', result.fio_request_id) - user1RequestId = result.fio_request_id - expect(result.status).to.equal('requested') - } catch (err) { - console.log('Error: ', err) - expect(err).to.equal(null) - } +const generateTestingFioDomain = () => { + return `testing-domain-${Date.now()}` +} + +const generateObtId = () => { + return `${Date.now()}` +} + +const timeout = async (ms) => { + await new Promise(resolve => { + setTimeout(resolve, ms) }) +} - it(`Create OBT in response to request with non-existent ID. Expect error type 400: ${config.error.requestNotFound}`, async () => { - try { - const result = await user2.sdk.genericAction('recordObtData', { - fioRequestId: 9999999999, - payerFioAddress: user2.address, - payeeFioAddress: user1.address, - payerTokenPublicAddress: user2.publicKey, - payeeTokenPublicAddress: user1.publicKey, - amount: 5000000000, - chainCode: "BTC", - tokenCode: "BTC", - status: '', - obtId: '', - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: user1.publicKey, - memo: 'this is a test', - hash: '', - offLineUrl: '' +before(async () => { + + if (target == 'local') { + faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); + fioSdk = await newUser(faucet); + fioSdk2 = await newUser(faucet); + privateKey = fioSdk.privateKey, + publicKey = fioSdk.publicKey, + testFioAddressName = fioSdk.address, + privateKey2 = fioSdk2.privateKey, + publicKey2 = fioSdk2.publicKey, + testFioAddressName2 = fioSdk2.address + } else { + fioSdk = await existingUser(account, privateKey, publicKey, testFioDomain, testFioAddressName); + fioSdk2 = await existingUser(account2, privateKey2, publicKey2, testFioDomain, testFioAddressName2); + } + + try { + const isAvailableResult = await fioSdk.sdk.genericAction('isAvailable', { + fioName: testFioAddressName + }) + if (!isAvailableResult.is_registered) { + await fioSdk.sdk.genericAction('registerFioAddress', { + fioAddress: testFioAddressName, + maxFee: defaultFee }) - console.log('Result: ', result); - expect(result).to.equal(null); - } catch (err) { - //console.log('Error', err); - expect(err.json.fields[0].error).to.equal('No such FIO Request'); - expect(err.errorCode).to.equal(400); } - }) - - it(`Other user3 attempts OBT with requestId from user1. Expect error type 403: ${config.error.signatureError} (part 1 with user3 as payerFioAddress)`, async () => { - try { - const result = await user3.sdk.genericAction('recordObtData', { - fioRequestId: user1RequestId, - payerFioAddress: user3.address, - payeeFioAddress: user1.address, - payerTokenPublicAddress: user3.publicKey, - payeeTokenPublicAddress: user1.publicKey, - amount: 5000000000, - chainCode: "BTC", - tokenCode: "BTC", - status: '', - obtId: '', - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: user1.publicKey, - memo: 'this is a test', - hash: '', - offLineUrl: '' + } catch (e) { + console.log(e); + } + try { + const isAvailableResult2 = await fioSdk2.sdk.genericAction('isAvailable', { + fioName: testFioAddressName2 + }) + if (!isAvailableResult2.is_registered) { + await fioSdk2.sdk.genericAction('registerFioAddress', { + fioAddress: testFioAddressName2, + maxFee: defaultFee }) - console.log('Result: ', result); - expect(result).to.equal(null); - } catch (err) { - //console.log('Error', err); - expect(err.json.type).to.equal('invalid_signature'); - expect(err.json.message).to.equal(config.error.invalidRequestSignature); - expect(err.errorCode).to.equal(403); } + } catch (e) { + console.log(e); + } + + await timeout(4000) + + newFioDomain = generateTestingFioDomain() + + newFioAddress = generateTestingFioAddress(newFioDomain) + privateKeyExample = '5Kbb37EAqQgZ9vWUHoPiC2uXYhyGSFNbL6oiDp24Ea1ADxV1qnu' + publicKeyExample = 'FIO5kJKNHwctcfUM5XZyiWSqSTM5HTzznJP9F3ZdbhaQAHEVq575o' + pubKeyForTransfer = 'FIO7isxEua78KPVbGzKemH4nj2bWE52gqj8Hkac3tc7jKNvpfWzYS' +}) + + +describe('Testing generic actions', () => { + + it(`FIO Key Generation Testing`, async () => { + const testMnemonic = 'valley alien library bread worry brother bundle hammer loyal barely dune brave' + const privateKeyRes = await FIOSDK.createPrivateKeyMnemonic(testMnemonic) + expect(privateKeyRes.fioKey).to.equal(privateKeyExample) + const publicKeyRes = FIOSDK.derivedPublicKey(privateKeyRes.fioKey) + expect(publicKeyRes.publicKey).to.equal(publicKeyExample) }) - it(`Other user3 attempts OBT with requestId from user1. Expect error type 403: ${config.error.invalidRequestSignature} (part 2 with user2 as payerFioAddress)`, async () => { - try { - const result = await user3.sdk.genericAction('recordObtData', { - fioRequestId: user1RequestId, - payerFioAddress: user2.address, - payeeFioAddress: user1.address, - payerTokenPublicAddress: user2.publicKey, - payeeTokenPublicAddress: user1.publicKey, - amount: 5000000000, - chainCode: "BTC", - tokenCode: "BTC", - status: '', - obtId: '', - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: user1.publicKey, - memo: 'this is a test', - hash: '', - offLineUrl: '' - }) - console.log('Result: ', result); - expect(result).to.equal(null); - } catch (err) { - //console.log('Error', err); - expect(err.json.type).to.equal('invalid_signature'); - expect(err.json.message).to.equal(config.error.invalidRequestSignature); - expect(err.errorCode).to.equal(403); - } + it(`FIO SUF Utilities - amountToSUF`, async () => { + const sufa = FIOSDK.amountToSUF (100) + expect(sufa).to.equal(100000000000) + + const sufb = FIOSDK.amountToSUF (500) + expect(sufb).to.equal(500000000000) + + const sufc = FIOSDK.amountToSUF (506) + expect(sufc).to.equal(506000000000) + + const sufd = FIOSDK.amountToSUF (1) + expect(sufd).to.equal(1000000000) + + const sufe = FIOSDK.amountToSUF (2) + expect(sufe).to.equal(2000000000) + + const suff = FIOSDK.amountToSUF (2.568) + expect(suff).to.equal(2568000000) + + const sufg = FIOSDK.amountToSUF (2.123) + expect(sufg).to.equal(2123000000) }) - it(`Initial requestor user1 attempts OBT with requestId from user1. Expect error type 403: ${config.error.invalidRequestSignature}`, async () => { + it(`FIO SUF Utilities - SUFToAmount`, async () => { + const sufa = FIOSDK.SUFToAmount (100000000000) + expect(sufa).to.equal(100) + + const sufb = FIOSDK.SUFToAmount (500000000000) + expect(sufb).to.equal(500) + + const sufc = FIOSDK.SUFToAmount (506000000000) + expect(sufc).to.equal(506) + + const sufd = FIOSDK.SUFToAmount (1000000000) + expect(sufd).to.equal(1) + + const sufe = FIOSDK.SUFToAmount (2000000000) + expect(sufe).to.equal(2) + + const suff = FIOSDK.SUFToAmount (2568000000) + expect(suff).to.equal(2.568) + + const sufg = FIOSDK.SUFToAmount (2123000000) + expect(sufg).to.equal(2.123) + }) + + it(`Validation methods`, async () => { try { - const result = await user1.sdk.genericAction('recordObtData', { - fioRequestId: user1RequestId, - payerFioAddress: user2.address, - payeeFioAddress: user1.address, - payerTokenPublicAddress: user2.publicKey, - payeeTokenPublicAddress: user1.publicKey, - amount: 5000000000, - chainCode: "BTC", - tokenCode: "BTC", - status: '', - obtId: '', - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: user1.publicKey, - memo: 'this is a test', - hash: '', - offLineUrl: '' - }) - console.log('Result: ', result); - expect(result).to.equal(null); - } catch (err) { - //console.log('Error', err); - expect(err.json.type).to.equal('invalid_signature'); - expect(err.json.message).to.equal(config.error.invalidRequestSignature); - expect(err.errorCode).to.equal(403); + FIOSDK.isChainCodeValid('$%34') + } catch (e) { + expect(e.list[0].message).to.equal('chainCode must match /^[a-z0-9]+$/i.') } + try { + FIOSDK.isTokenCodeValid('') + } catch (e) { + expect(e.list[0].message).to.equal('tokenCode is required.') + } + try { + FIOSDK.isFioAddressValid('f') + } catch (e) { + expect(e.list[0].message).to.equal('fioAddress must have a length between 3 and 64.') + } + try { + FIOSDK.isFioDomainValid('$%FG%') + } catch (e) { + expect(e.list[0].message).to.equal('fioDomain must match /^[a-z0-9\\-]+$/i.') + } + try { + FIOSDK.isFioPublicKeyValid('dfsd') + } catch (e) { + expect(e.list[0].message).to.equal('fioPublicKey must match /^FIO\\w+$/.') + } + try { + FIOSDK.isPublicAddressValid('') + } catch (e) { + expect(e.list[0].message).to.equal('publicAddress is required.') + } + + const chainCodeIsValid = FIOSDK.isChainCodeValid('FIO') + expect(chainCodeIsValid).to.equal(true) + + const tokenCodeIsValid = FIOSDK.isTokenCodeValid('FIO') + expect(tokenCodeIsValid).to.equal(true) + + const singleDigitFioAddressIsValid = FIOSDK.isFioAddressValid('f@2') + expect(singleDigitFioAddressIsValid).to.equal(true) + + const fioAddressIsValid = FIOSDK.isFioAddressValid(newFioAddress) + expect(fioAddressIsValid).to.equal(true) + + const fioDomainIsValid = FIOSDK.isFioDomainValid(newFioDomain) + expect(fioDomainIsValid).to.equal(true) + + const privateKeyIsValid = FIOSDK.isFioPublicKeyValid(publicKey) + expect(privateKeyIsValid).to.equal(true) + + const publicKeyIsValid = FIOSDK.isPublicAddressValid(publicKey) + expect(publicKeyIsValid).to.equal(true) + }) + + it(`Getting fio public key`, async () => { + const result = await fioSdk.sdk.genericAction('getFioPublicKey', {}) + + expect(result).to.equal(publicKey) + }) + + it(`getFioBalance`, async () => { + const result = await fioSdk.sdk.genericAction('getFioBalance', {}) + + expect(result).to.have.all.keys('balance','available') + expect(result.balance).to.be.a('number') }) }) -describe(`Cancel Funds Request`, () => { - const payment = 5000000000 // 5 FIO - const requestMemo = 'Memo in the initial request' +describe('Testing domain actions', () => { - it(`user1 requests funds from user2`, async () => { - try { - const result = await user1.sdk.genericAction('requestFunds', { - payerFioAddress: user2.address, - payeeFioAddress: user1.address, - payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', - amount: payment, - chainCode: 'BTC', - tokenCode: 'BTC', - memo: requestMemo, - maxFee: config.api.new_funds_request.fee, - payerFioPublicKey: user2.publicKey, - technologyProviderId: '', - hash: '', - offLineUrl: '' - }) - //console.log('Result: ', result) - user1RequestId = result.fio_request_id - expect(result.status).to.equal('requested') - } catch (err) { - console.log('Error: ', err) - expect(err).to.equal(null) - } + it(`Register fio domain`, async () => { + const result = await fioSdk2.sdk.genericAction('registerFioDomain', { fioDomain: newFioDomain, maxFee: defaultFee }) + //console.log('New Domain: ', newFioDomain) + expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.expiration).to.be.a('string') + expect(result.fee_collected).to.be.a('number') }) - it('Wait a few seconds To make sure the obt gets recorded.', async () => { - await timeout(2000); + it(`Renew fio domain`, async () => { + const result = await fioSdk2.sdk.genericAction('renewFioDomain', { fioDomain: newFioDomain, maxFee: defaultFee }) + + expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.expiration).to.be.a('string') + expect(result.fee_collected).to.be.a('number') }) - it(`get_sent_fio_requests for user1`, async () => { - try { - const result = await user1.sdk.genericAction('getSentFioRequests', { - limit: '', - offset: '' - }) - //console.log('result: ', result) - numRequests = result.requests.length; - expect(result.requests[numRequests-1].fio_request_id).to.equal(user1RequestId); - expect(result.requests[numRequests-1].content.memo).to.equal(requestMemo); - } catch (err) { - console.log('Error: ', err); - expect(err).to.equal(null); - } + it(`setFioDomainVisibility true`, async () => { + const result = await fioSdk2.sdk.genericAction('setFioDomainVisibility', { + fioDomain: newFioDomain, + isPublic: true, + maxFee: defaultFee, + technologyProviderId: '' + }) + + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') }) - it(`get_pending_fio_requests for user2`, async () => { - try { - const result = await user2.sdk.genericAction('getPendingFioRequests', { - limit: '', - offset: '' - }) - //console.log('result: ', result) - numRequests = result.requests.length; - expect(result.requests[numRequests-1].fio_request_id).to.equal(user1RequestId); - expect(result.requests[numRequests-1].content.memo).to.equal(requestMemo); - } catch (err) { - console.log('Error: ', err); - expect(err).to.equal(null); - } + it(`Register fio address`, async () => { + const result = await fioSdk2.sdk.genericAction('registerFioAddress', { + fioAddress: newFioAddress, + maxFee: defaultFee + }) + + expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.expiration).to.be.a('string') + expect(result.fee_collected).to.be.a('number') }) - it(`Call cancel_funds_request (push transaction) to cancel request in pending state`, async () => { + it(`getFioNames`, async () => { + const result = await fioSdk2.sdk.genericAction('getFioNames', { fioPublicKey: publicKey }) + + expect(result).to.have.all.keys('fio_domains', 'fio_addresses') + expect(result.fio_domains).to.be.a('array') + expect(result.fio_addresses).to.be.a('array') + }) + + it(`getFioDomains`, async () => { try{ - const result = await user1.sdk.genericAction('pushTransaction', { - action: 'cancelfndreq', - account: 'fio.reqobt', - data: { - "fio_request_id": user1RequestId, - "max_fee": config.api.cancel_funds_request.fee, - "tpid": '', - "actor": user1.account - } - }) - //console.log('Result: ', result); - expect(result).to.have.all.keys('status', 'fee_collected') - expect(result.status).to.equal('cancelled'); - expect(result.fee_collected).to.equal(0); - } catch (err) { - console.log('Error', err.json); - expect(err).to.equal(null); + const result = await fioSdk2.sdk.genericAction('getFioDomains', { fioPublicKey: fioSdk.publicKey }) + + expect(result).to.have.all.keys('fio_domains','more') + expect(result.fio_domains).to.be.a('array') + } catch (e) { + console.log(e); } }) - it(`Verify request was cancelled: get_sent_fio_requests for user1 returns 1 request with status 'cancelled'`, async () => { - try { - const result = await user1.sdk.genericAction('getSentFioRequests', { - limit: '', - offset: '' - }) - //console.log('result: ', result) - numRequests = result.requests.length; - expect(result.requests[numRequests-1].fio_request_id).to.equal(user1RequestId); - expect(result.requests[numRequests-1].content.memo).to.equal(requestMemo); - expect(result.requests[numRequests-1].status).to.equal('cancelled'); - } catch (err) { - console.log('Error: ', err); - expect(err).to.equal(null); - } + it(`Register owner fio address`, async () => { + const newFioAddress2 = generateTestingFioAddress(newFioDomain) + const result = await fioSdk2.sdk.genericAction('registerFioAddress', { + fioAddress: newFioAddress2, + ownerPublicKey: publicKey2, + maxFee: defaultFee + }) + expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.expiration).to.be.a('string') + expect(result.fee_collected).to.be.a('number') }) - it(`Verify request was cancelled: get_cancelled_fio_requests returns 1 request with status 'cancelled'`, async () => { - try { - const json = { - "fio_public_key": user1.publicKey - } - result = await callFioApi("get_cancelled_fio_requests", json); - //console.log('Result: ', result); - numRequests = result.requests.length; - expect(result.requests[numRequests-1].fio_request_id).to.equal(user1RequestId); - expect(result.requests[numRequests-1].status).to.equal('cancelled'); - } catch (err) { - console.log('Error', err) - expect(err.error.message).to.equal(config.error.noFioRequests) - } + it(`setFioDomainVisibility false`, async () => { + const result = await fioSdk2.sdk.genericAction('setFioDomainVisibility', { + fioDomain: newFioDomain, + isPublic: false, + maxFee: defaultFee, + technologyProviderId: '' + }) + + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') }) -}) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) -describe('Transfer domain', () => { + it(`setFioDomainVisibility true`, async () => { + const result = await fioSdk2.sdk.genericAction('setFioDomainVisibility', { + fioDomain: newFioDomain, + isPublic: true, + maxFee: defaultFee, + technologyProviderId: '' + }) - let user1OrigBalance, transfer_fio_domain_fee, feeCollected + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) - it('Get transfer_fio_domain fee', async () => { - try { - result = await user1.sdk.getFee('transfer_fio_domain', user1.address); - transfer_fio_domain_fee = result.fee; - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } + it(`getFee for transferFioAddress`, async () => { + const result = await fioSdk2.sdk.genericAction('getFeeForTransferFioAddress', { + fioAddress: newFioAddress + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') }) - it(`getFioNames for user1 and confirm it owns user1.domain2`, async () => { - try { - const result = await user1.sdk.genericAction('getFioNames', { - fioPublicKey: user1.publicKey - }) - //console.log('getFioNames', result) - for (domain in result.fio_domains) { - if (result.fio_domains[domain].fio_domain == user1.domain2) {break} - } - expect(result.fio_domains[domain].fio_domain).to.equal(user1.domain2); - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } + it.skip(`Need to move: Transfer fio address`, async () => { + const result = await fioSdk2.sdk.genericAction('transferFioAddress', { + fioAddress: newFioAddress, + newOwnerKey: pubKeyForTransfer, + maxFee: defaultFee + }) + + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.snew-funtatus).to.be.a('string') + expect(result.fee_collected).to.be.a('number') }) - it(`Get balance for user1`, async () => { - try { - const result = await user1.sdk.genericAction('getFioBalance', { - fioPublicKey: user1.publicKey - }) - user1OrigBalance = result.balance - //console.log('user1 fio balance', result) - } catch (err) { - //console.log('Error', err) - expect(err).to.equal(null) - } + it(`getFee for transferFioDomain`, async () => { + const result = await fioSdk2.sdk.genericAction('getFeeForTransferFioDomain', { + fioAddress: newFioAddress + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + }) + + it(`Transfer fio domain`, async () => { + const result = await fioSdk2.sdk.genericAction('transferFioDomain', { + fioDomain: newFioDomain, + newOwnerKey: pubKeyForTransfer, + maxFee: defaultFee + }) + + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it.skip(`Bahamas: getFee for addBundledTransactions`, async () => { + const result = await fioSdk2.sdk.genericAction('getFeeForAddBundledTransactions', { + fioAddress: newFioAddress + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + }) + + it.skip(`Bahamas: add Bundled Transactions`, async () => { + const result = await fioSdk2.sdk.genericAction('addBundledTransactions', { + fioAddress: newFioAddress, + bundleSets: defaultBundledSets, + maxFee: defaultFee + }) + + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') }) - it(`Transfer user1.domain2 to user2`, async () => { + it(`(push_transaction) user1 run addbundles with sets for FIO Address owned by user2`, async () => { try { - const result = await user1.sdk.genericAction('transferFioDomain', { - fioDomain: user1.domain2, - newOwnerKey: user2.publicKey, - maxFee: transfer_fio_domain_fee, - walletFioAddress: '' + const result = await fioSdk2.sdk.genericAction('pushTransaction', { + action: 'addbundles', + account: 'fio.address', + data: { + fio_address: newFioAddress, + bundle_sets: defaultBundledSets, + max_fee: defaultFee, + technologyProviderId: '' + } }) - feeCollected = result.fee_collected; //console.log('Result: ', result); expect(result.status).to.equal('OK'); } catch (err) { - console.log('Error: ', err.json.error); + console.log('Error: ', err); expect(err).to.equal(null); } +}) + + it(`Renew fio address`, async () => { + const result = await fioSdk2.sdk.genericAction('renewFioAddress', { fioAddress: newFioAddress, maxFee: defaultFee }) + + expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.expiration).to.be.a('string') + expect(result.fee_collected).to.be.a('number') }) - it('Confirm proper fee was collected', async () => { - expect(feeCollected).to.equal(transfer_fio_domain_fee) + it(`Push Transaction - renewaddress`, async () => { + await timeout(2000) + const result = await fioSdk2.sdk.genericAction('pushTransaction', { + action: 'renewaddress', + account: 'fio.address', + data: { + fio_address: newFioAddress, + max_fee: defaultFee, + tpid: '' + } + }) + + expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.expiration).to.be.a('string') + expect(result.fee_collected).to.be.a('number') }) - it('Confirm fee was deducted from user1 account', async () => { + it(`getFee for addPublicAddress`, async () => { try { - const result = await user1.sdk.genericAction('getFioBalance', { - fioPublicKey: user1.publicKey + const result = await fioSdk2.sdk.genericAction('getFeeForAddPublicAddress', { + fioAddress: newFioAddress }) - expect(result.balance).to.equal(user1OrigBalance - transfer_fio_domain_fee); - //console.log('user1 fio balance', result) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') } catch (err) { - //console.log('Error', err) - expect(err).to.equal(null) + console.log('Error: ', err); + expect(err).to.equal(null); } }) - it(`getFioNames for user1 and confirm it still owns the address registered on the domain`, async () => { + it(`Add public address`, async () => { try { - const result = await user1.sdk.genericAction('getFioNames', { - fioPublicKey: user1.publicKey - }) - //console.log('getFioNames', result) - for (address in result.fio_addresses) { - if (result.fio_addresses[address].fio_address == user1.address2) {break} - } - expect(result.fio_addresses[address].fio_address).to.equal(user1.address2); - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } + const result = await fioSdk2.sdk.genericAction('addPublicAddress', { + fioAddress: newFioAddress, + chainCode: 'ABC', + tokenCode: 'ABC', + publicAddress: '1PMycacnJaSqwwJqjawXBErnLsZ7RkXUAs', + maxFee: defaultFee, + technologyProviderId: '' + }) + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } }) - it(`getFioNames for user2 and confirm it now owns the domain`, async () => { - try { - const result = await user2.sdk.genericAction('getFioNames', { - fioPublicKey: user2.publicKey - }) - //console.log('getFioNames', result) - for (domain in result.fio_domains) { - if (result.fio_domains[domain].fio_domain == user1.domain2) {break} - } - expect(result.fio_domains[domain].fio_domain).to.equal(user1.domain2); - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } + it(`Add public addresses`, async () => { + const result = await fioSdk2.sdk.genericAction('addPublicAddresses', { + fioAddress: newFioAddress, + publicAddresses: [ + { + chain_code: ethChainCode, + token_code: ethTokenCode, + public_address: 'xxxxxxyyyyyyzzzzzz', + }, + { + chain_code: fioChainCode, + token_code: fioTokenCode, + public_address: publicKey, + } + ], + maxFee: defaultFee, + technologyProviderId: '' + }) + + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`getFee for removePublicAddresses`, async () => { + const result = await fioSdk2.sdk.genericAction('getFeeForRemovePublicAddresses', { + fioAddress: newFioAddress + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + }) + + it(`Remove public addresses`, async () => { + + const result = await fioSdk2.sdk.genericAction('removePublicAddresses', { + fioAddress: newFioAddress, + publicAddresses: [ + { + chain_code: ethChainCode, + token_code: ethTokenCode, + public_address: 'xxxxxxyyyyyyzzzzzz', + } + ], + maxFee: defaultFee, + technologyProviderId: '' + }) + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`getFee for removeAllPublicAddresses`, async () => { + + const result = await fioSdk2.sdk.genericAction('getFeeForRemoveAllPublicAddresses', { + fioAddress: newFioAddress + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + }) + + it(`Remove all public addresses`, async () => { + await fioSdk2.sdk.genericAction('addPublicAddresses', { + fioAddress: newFioAddress, + publicAddresses: [ + { + chain_code: ethChainCode, + token_code: ethTokenCode, + public_address: 'xxxxxxyyyyyyzzzzzz1', + } + ], + maxFee: defaultFee, + technologyProviderId: '' + }) + + const result = await fioSdk2.sdk.genericAction('removeAllPublicAddresses', { + fioAddress: newFioAddress, + maxFee: defaultFee, + technologyProviderId: '' + }) + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + + it(`isAvailable true`, async () => { + const result = await fioSdk2.sdk.genericAction('isAvailable', { + fioName: generateTestingFioAddress(), + }) + + expect(result.is_registered).to.equal(0) + }) + + it(`isAvailable false`, async () => { + const result = await fioSdk2.sdk.genericAction('isAvailable', { + fioName: testFioAddressName + }) + + expect(result.is_registered).to.equal(1) }) - it(`Transfer user1.domain2 back to user1 from user2 to clean up test`, async () => { + it(`getFioBalance for custom fioPublicKey`, async () => { + const result = await fioSdk2.sdk.genericAction('getFioBalance', { + fioPublicKey: publicKey2 + }) + + expect(result).to.have.all.keys('balance', 'available') + expect(result.balance).to.be.a('number') + }) + + + it(`getFioAddresses`, async () => { try { - const result = await user2.sdk.genericAction('transferFioDomain', { - fioDomain: user1.domain2, - newOwnerKey: user1.publicKey, - maxFee: transfer_fio_domain_fee, - walletFioAddress: '' - }) - feeCollected = result.fee_collected; - //console.log('Result: ', result); - expect(result.status).to.equal('OK'); - } catch (err) { - console.log('Error: ', err.json.error); - expect(err).to.equal(null); + const result = await fioSdk2.sdk.genericAction('getFioAddresses', { fioPublicKey: publicKey }) + + expect(result).to.have.all.keys('fio_addresses','more') + expect(result.fio_addresses).to.be.a('array') + } catch (e) { + console.log(e); } }) + + it(`getPublicAddress`, async () => { + const result = await fioSdk2.sdk.genericAction('getPublicAddress', { + fioAddress: newFioAddress, chainCode: fioChainCode, tokenCode: fioTokenCode + }) + + expect(result.public_address).to.be.a('string') + }) + + it(`getFee`, async () => { + const result = await fioSdk2.sdk.genericAction('getFee', { + endPoint: 'register_fio_address', + fioAddress: '' + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + }) + + it(`getMultiplier`, async () => { + const result = await fioSdk2.sdk.genericAction('getMultiplier', {}) + + expect(result).to.be.a('number') + }) + + it(`getFee for BurnFioAddress`, async () => { + const result = await fioSdk2.sdk.genericAction('getFeeForBurnFioAddress', { + fioAddress: newFioAddress + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + }) + + it(`Burn fio address`, async () => { + const result = await fioSdk2.sdk.genericAction('burnFioAddress', { + fioAddress: newFioAddress, + maxFee: defaultFee + }) + + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + }) -describe(`Remove pub address`, () => { +describe('Request funds, approve and send', () => { + const fundsAmount = 3 + let requestId + const memo = 'testing fund request' - it(`Add DASH and BCH addresses to user1`, async () => { - try { - const result = await user1.sdk.genericAction('addPublicAddresses', { - fioAddress: user1.address, - publicAddresses: config.public_addresses, - maxFee: config.api.add_pub_address.fee, - walletFioAddress: '' - }) - //console.log('Result:', result) - expect(result.status).to.equal('OK') - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } + it(`getFee for requestFunds`, async () => { + const result = await fioSdk2.sdk.genericAction('getFeeForNewFundsRequest', { + payeeFioAddress: testFioAddressName2 + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') }) - it('confirm BCH address was added', async () => { - try { - const result = await user1.sdk.genericAction('getPublicAddress', { - fioAddress: user1.address, - chainCode: "BCH", - tokenCode: "BCH" - }) - //console.log('Result', result) - expect(result.public_address).to.equal('bitcoincash:qzf8zha74ahdh9j0xnwlffdn0zuyaslx3c90q7n9g9') - } catch (err) { - console.log('Error', err) - } + it(`requestFunds`, async () => { + const result = await fioSdk2.sdk.genericAction('requestFunds', { + payerFioAddress: testFioAddressName, + payeeFioAddress: testFioAddressName2, + payeeTokenPublicAddress: publicKey2, + amount: fundsAmount, + chainCode: fioChainCode, + tokenCode: fioTokenCode, + memo: '', + maxFee: defaultFee, + payerFioPublicKey: publicKey, + technologyProviderId: '', + hash: '', + offLineUrl: '' + }) + //console.log('requestFunds: ', result) + requestId = result.fio_request_id + expect(result).to.have.all.keys('fio_request_id', 'status', 'fee_collected') + expect(result.fio_request_id).to.be.a('number') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') }) - it(`Remove BCH and DASH from user1`, async () => { - try { - const result = await user1.sdk.genericAction('removePublicAddresses', { - fioAddress: user1.address, - publicAddresses: config.public_addresses, - maxFee: config.api.add_pub_address.fee, - tpid: '' - }) - //console.log('Result:', result) - expect(result.status).to.equal('OK') - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } + it(`getPendingFioRequests`, async () => { + await timeout(4000) + const result = await fioSdk.sdk.genericAction('getPendingFioRequests', {}) + expect(result).to.have.all.keys('requests', 'more') + expect(result.requests).to.be.a('array') + expect(result.more).to.be.a('number') + const pendingReq = result.requests.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) + expect(pendingReq).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'time_stamp', 'content') + expect(pendingReq.fio_request_id).to.be.a('number') + expect(pendingReq.fio_request_id).to.equal(requestId) + expect(pendingReq.payer_fio_address).to.be.a('string') + expect(pendingReq.payer_fio_address).to.equal(testFioAddressName) + expect(pendingReq.payee_fio_address).to.be.a('string') + expect(pendingReq.payee_fio_address).to.equal(testFioAddressName2) }) - it('confirm BCH address was removed', async () => { - try { - const result = await user1.sdk.genericAction('getPublicAddress', { - fioAddress: user1.address, - chainCode: "BCH", - tokenCode: "BCH" - }) - //console.log('Result', result) - } catch (err) { - //console.log('Error', err) - expect(err.json.message).to.equal(config.error.publicAddressFound) - } + it(`recordObtData`, async () => { + const result = await fioSdk.sdk.genericAction('recordObtData', { + fioRequestId: requestId, + payerFioAddress: testFioAddressName, + payeeFioAddress: testFioAddressName2, + payerTokenPublicAddress: publicKey, + payeeTokenPublicAddress: publicKey2, + amount: fundsAmount, + chainCode: fioChainCode, + tokenCode: fioTokenCode, + status: 'sent_to_blockchain', + obtId: '', + maxFee: defaultFee, + }) + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') }) - it(`Add DASH and BCH addresses to user1`, async () => { - try { - const result = await user1.sdk.genericAction('addPublicAddresses', { - fioAddress: user1.address, - publicAddresses: [ - { - chain_code: 'BCH', - token_code: 'BCH', - public_address: 'bitcoincash:qn9g9', - }, - { - chain_code: 'DASH', - token_code: 'DASH', - public_address: 'XyCyPKzTWvW2XdcYjPaPXGQDCGk946ywEv', - } - ], - maxFee: config.api.add_pub_address.fee, - walletFioAddress: '' - }) - //console.log('Result:', result) - expect(result.status).to.equal('OK') - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } + it(`getSentFioRequests`, async () => { + const result = await fioSdk2.sdk.genericAction('getSentFioRequests', {}) + expect(result).to.have.all.keys('requests', 'more') + expect(result.requests).to.be.a('array') + expect(result.more).to.be.a('number') + /* const pendingReq = result.requests.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) + expect(pendingReq).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'status', 'time_stamp', 'content') + expect(pendingReq.fio_request_id).to.be.a('number') + expect(pendingReq.fio_request_id).to.equal(requestId) + expect(pendingReq.payer_fio_address).to.be.a('string') + expect(pendingReq.payer_fio_address).to.equal(testFioAddressName) + expect(pendingReq.payee_fio_address).to.be.a('string') + expect(pendingReq.payee_fio_address).to.equal(testFioAddressName2) */ }) - it('Wait a few seconds To make add_address goes through.', async () => { - await timeout(2000); + it(`Payer getObtData`, async () => { + await timeout(10000) + const result = await fioSdk.sdk.genericAction('getObtData', {}) + expect(result).to.have.all.keys('obt_data_records', 'more') + expect(result.obt_data_records).to.be.a('array') + expect(result.more).to.be.a('number') + const obtData = result.obt_data_records.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) + expect(obtData).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'status', 'time_stamp', 'content') + expect(obtData.fio_request_id).to.be.a('number') + expect(obtData.fio_request_id).to.equal(requestId) + expect(obtData.payer_fio_address).to.be.a('string') + expect(obtData.payer_fio_address).to.equal(testFioAddressName) + expect(obtData.payee_fio_address).to.be.a('string') + expect(obtData.payee_fio_address).to.equal(testFioAddressName2) }) - it('confirm BCH address was added', async () => { - try { - const result = await user1.sdk.genericAction('getPublicAddress', { - fioAddress: user1.address, - chainCode: "BCH", - tokenCode: "BCH" - }) - //console.log('Result', result) - expect(result.public_address).to.equal('bitcoincash:qn9g9') - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } + it(`Payee getObtData`, async () => { + const result = await fioSdk2.sdk.genericAction('getObtData', {}) + expect(result).to.have.all.keys('obt_data_records', 'more') + expect(result.obt_data_records).to.be.a('array') + expect(result.more).to.be.a('number') + const obtData = result.obt_data_records.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) + expect(obtData).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'status', 'time_stamp', 'content') + expect(obtData.fio_request_id).to.be.a('number') + expect(obtData.fio_request_id).to.equal(requestId) + expect(obtData.payer_fio_address).to.be.a('string') + expect(obtData.payer_fio_address).to.equal(testFioAddressName) + expect(obtData.payee_fio_address).to.be.a('string') + expect(obtData.payee_fio_address).to.equal(testFioAddressName2) }) - it(`Remove All public addresses from user1`, async () => { - try { - const result = await user1.sdk.genericAction('removeAllPublicAddresses', { - fioAddress: user1.address, - maxFee: config.api.add_pub_address.fee, - tpid: '' - }) - //console.log('Result:', result) - expect(result.status).to.equal('OK') - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } +}) + +describe('Request funds, cancel funds request', () => { + const fundsAmount = 3 + let requestId + const memo = 'testing fund request' + + it(`requestFunds`, async () => { + const result = await fioSdk2.sdk.genericAction('requestFunds', { + payerFioAddress: testFioAddressName, + payeeFioAddress: testFioAddressName2, + payeePublicAddress: testFioAddressName2, + amount: fundsAmount, + chainCode: fioChainCode, + tokenCode: fioTokenCode, + memo, + maxFee: defaultFee, + }) + + requestId = result.fio_request_id + expect(result).to.have.all.keys('fio_request_id', 'status', 'fee_collected') + expect(result.fio_request_id).to.be.a('number') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') }) - it('confirm BCH address was removed', async () => { - try { - const result = await user1.sdk.genericAction('getPublicAddress', { - fioAddress: user1.address, - chainCode: "BCH", - tokenCode: "BCH" - }) - //console.log('Result', result) - } catch (err) { - //console.log('Error', err) - expect(err.json.message).to.equal(config.error.publicAddressFound) + it(`cancel request`, async () => { + try{ + const result = await fioSdk2.sdk.genericAction('cancelFundsRequest', { + fioRequestId: requestId, + maxFee: defaultFee, + tpid: '' + }) + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + } catch (e) { + console.log(e); } }) + + it(`getCancelledFioRequests`, async () => { + try{ + await timeout(4000) + const result = await fioSdk2.sdk.genericAction('getCancelledFioRequests', {}) + expect(result).to.have.all.keys('requests', 'more') + expect(result.requests).to.be.a('array') + expect(result.more).to.be.a('number') + const pendingReq = result.requests.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) + expect(pendingReq).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'time_stamp', 'content', 'status') + expect(pendingReq.fio_request_id).to.be.a('number') + expect(pendingReq.fio_request_id).to.equal(requestId) + expect(pendingReq.payer_fio_address).to.be.a('string') + expect(pendingReq.payer_fio_address).to.equal(testFioAddressName) + expect(pendingReq.payee_fio_address).to.be.a('string') + expect(pendingReq.payee_fio_address).to.equal(testFioAddressName2) + } catch (e) { + console.log(e); + } + }) + }) -describe(`Paging - FIO Address`, () => { - let addressCount = 20, newAddressCount - - // Only include if you need to generate new addresses. - it.skip(`Register ${addressCount} addresses for user3`, async () => { - for (i = 0; i < addressCount; i++) { - try { - newAddress = i + generateFioAddress(user3.domain, 7) - const result = await user3.sdk.genericAction('registerFioAddress', { - fioAddress: newAddress, - maxFee: config.api.register_fio_address.fee, - walletFioAddress: '' - }) - //console.log('Result: ', result) - expect(result.status).to.equal('OK') - } catch (err) { - console.log('Error: ', err) - } - } +describe('Request funds, reject', () => { + const fundsAmount = 4 + let requestId + const memo = 'testing fund request' + + it(`requestFunds`, async () => { + const result = await fioSdk2.sdk.genericAction('requestFunds', { + payerFioAddress: testFioAddressName, + payeeFioAddress: testFioAddressName2, + payeePublicAddress: testFioAddressName2, + amount: fundsAmount, + chainCode: fioChainCode, + tokenCode: fioTokenCode, + memo, + maxFee: defaultFee, + }) + + requestId = result.fio_request_id + expect(result).to.have.all.keys('fio_request_id', 'status', 'fee_collected') + expect(result.fio_request_id).to.be.a('number') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') }) - it(`Call (get_fio_addresses, no limit param, no offset param). Get current number of addressess.`, async () => { - try { - const json = { - "fio_public_key": user3.publicKey - } - result = await callFioApi("get_fio_addresses", json); - //console.log('Result: ', result); - newAddressCount = result.fio_addresses.length; - expect(result.fio_addresses.length).to.be.greaterThan(addressCount-1) - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } + it(`getPendingFioRequests`, async () => { + await timeout(4000) + const result = await fioSdk.sdk.genericAction('getPendingFioRequests', {}) + + expect(result).to.have.all.keys('requests', 'more') + expect(result.requests).to.be.a('array') + expect(result.more).to.be.a('number') + const pendingReq = result.requests.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) + expect(pendingReq).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'time_stamp', 'content') + expect(pendingReq.fio_request_id).to.be.a('number') + expect(pendingReq.fio_request_id).to.equal(requestId) + expect(pendingReq.payer_fio_address).to.be.a('string') + expect(pendingReq.payer_fio_address).to.equal(testFioAddressName) + expect(pendingReq.payee_fio_address).to.be.a('string') + expect(pendingReq.payee_fio_address).to.equal(testFioAddressName2) }) - it(`Call (get_fio_addresses, limit=0, offset=0). Expect newAddressCount results.`, async () => { - try { - const json = { - "fio_public_key": user3.publicKey, - "limit": 0, - "offset": 0 - } - result = await callFioApi("get_fio_addresses", json); - //console.log('Result: ', result); - expect(result.fio_addresses.length).to.equal(newAddressCount) - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } + it(`getFee for rejectFundsRequest`, async () => { + const result = await fioSdk2.sdk.genericAction('getFeeForRejectFundsRequest', { + payerFioAddress: testFioAddressName2 + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') }) - it(`Call (get_fio_addresses, limit=1, offset=0). Expect 1 address. Expect address user3.address`, async () => { - try { - const json = { - "fio_public_key": user3.publicKey, - "limit": 1, - "offset": 0 - } - result = await callFioApi("get_fio_addresses", json); - //console.log('Result: ', result); - expect(result.fio_addresses.length).to.equal(1); - expect(result.fio_addresses[0].fio_address).to.equal(user3.address); // First character of address = 0 (1st address in list) - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } + it(`rejectFundsRequest`, async () => { + const result = await fioSdk.sdk.genericAction('rejectFundsRequest', { + fioRequestId: requestId, + maxFee: defaultFee, + }) + + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') }) - it(`Call (get_fio_addresses, limit=2, offset=4). Expect 2 address. Expect address #5-6`, async () => { - try { - const json = { - "fio_public_key": user3.publicKey, - "limit": 2, - "offset": 4 - } - result = await callFioApi("get_fio_addresses", json); - //console.log('Result: ', result); - expect(result.fio_addresses.length).to.equal(2); - expect(result.fio_addresses[0].fio_address.charAt(0)).to.equal('3'); // First character of address = 4 (5th address in list) - expect(result.fio_addresses[1].fio_address.charAt(0)).to.equal('4'); - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } +}) + +describe('Transfer tokens', () => { + const fundsAmount = FIOSDK.SUFUnit + let fioBalance = 0 + let fioBalanceAfter = 0 + + it(`Check balance before transfer`, async () => { + const result = await fioSdk2.sdk.genericAction('getFioBalance', {}) + fioBalance = result.balance }) - it(`Call (get_fio_addresses, limit=10, offset=15). Expect address #16-20`, async () => { - try { - const json = { - "fio_public_key": user3.publicKey, - "limit": 10, - "offset": 15 - } - result = await callFioApi("get_fio_addresses", json); - //console.log('Result: ', result); - expect(result.fio_addresses[0].fio_address.charAt(0)).to.equal('1'); - expect(result.fio_addresses[0].fio_address.charAt(1)).to.equal('4'); // 15 - expect(result.fio_addresses[4].fio_address.charAt(0)).to.equal('1'); - expect(result.fio_addresses[4].fio_address.charAt(1)).to.equal('8'); // 19 - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } + it(`Transfer tokens`, async () => { + const result = await fioSdk.sdk.genericAction('transferTokens', { + payeeFioPublicKey: publicKey2, + amount: fundsAmount, + maxFee: defaultFee, + }) + expect(result).to.have.all.keys('status', 'fee_collected', 'transaction_id', 'block_num') + expect(result.status).to.be.a('string') + expect(result.transaction_id).to.be.a('string') + expect(result.block_num).to.be.a('number') + expect(result.fee_collected).to.be.a('number') + }) + + it(`Check balance and balance change`, async () => { + await timeout(10000) + const result = await fioSdk2.sdk.genericAction('getFioBalance', {}) + fioBalanceAfter = result.balance + expect(fundsAmount).to.equal(fioBalanceAfter - fioBalance) + }) +}) + +describe('Record obt data, check', () => { + const obtId = generateObtId() + const fundsAmount = 4.5 + + it(`getFee for recordObtData`, async () => { + const result = await fioSdk.sdk.genericAction('getFeeForRecordObtData', { + payerFioAddress: testFioAddressName + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + }) + + it(`recordObtData`, async () => { + const result = await fioSdk.sdk.genericAction('recordObtData', { + fioRequestId: '', + payerFioAddress: testFioAddressName, + payeeFioAddress: testFioAddressName2, + payerTokenPublicAddress: publicKey, + payeeTokenPublicAddress: publicKey2, + amount: fundsAmount, + chainCode: fioChainCode, + tokenCode: fioTokenCode, + status: 'sent_to_blockchain', + obtId, + maxFee: defaultFee, + }) + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') }) - it(`Negative offset. Call (get_fio_addresses, limit=1, offset=-1). Expect error type 400: ${config.error.invalidOffset}`, async () => { + it(`Payer getObtData`, async () => { + await timeout(4000) + const result = await fioSdk.sdk.genericAction('getObtData', { tokenCode: fioTokenCode }) + expect(result).to.have.all.keys('obt_data_records', 'more') + expect(result.obt_data_records).to.be.a('array') + expect(result.more).to.be.a('number') + const obtData = result.obt_data_records.find(pr => pr.content.obt_id === obtId) + expect(obtData).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'status', 'time_stamp', 'content') + expect(obtData.content.obt_id).to.be.a('string') + expect(obtData.content.obt_id).to.equal(obtId) + expect(obtData.payer_fio_address).to.be.a('string') + expect(obtData.payer_fio_address).to.equal(testFioAddressName) + expect(obtData.payee_fio_address).to.be.a('string') + expect(obtData.payee_fio_address).to.equal(testFioAddressName2) + }) + + it(`Payee getObtData`, async () => { + const result = await fioSdk2.sdk.genericAction('getObtData', { tokenCode: fioTokenCode }) + expect(result).to.have.all.keys('obt_data_records', 'more') + expect(result.obt_data_records).to.be.a('array') + expect(result.more).to.be.a('number') + /* const obtData = result.obt_data_records.find(pr => pr.content.obt_id === obtId) + expect(obtData).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'status', 'time_stamp', 'content') + expect(obtData.content.obt_id).to.be.a('string') + expect(obtData.content.obt_id).to.equal(obtId) + expect(obtData.payer_fio_address).to.be.a('string') + expect(obtData.payer_fio_address).to.equal(testFioAddressName) + expect(obtData.payee_fio_address).to.be.a('string') + expect(obtData.payee_fio_address).to.equal(testFioAddressName2) */ + }) +}) + +describe('Encrypting/Decrypting', () => { + const alicePrivateKey = '5J35xdLtcPvDASxpyWhNrR2MfjSZ1xjViH5cvv15VVjqyNhiPfa' + const alicePublicKey = 'FIO6NxZ7FLjjJuHGByJtNJQ1uN1P5X9JJnUmFW3q6Q7LE7YJD4GZs' + const bobPrivateKey = '5J37cXw5xRJgE869B5LxC3FQ8ZJECiYnsjuontcHz5cJsz5jhb7' + const bobPublicKey = 'FIO4zUFC29aq8uA4CnfNSyRZCnBPya2uQk42jwevc3UZ2jCRtepVZ' + + const nonPartyPrivateKey = '5HujRtqceTPo4awwHAEdHRTWdMTgA6s39dJjwWcjhNdSjVWUqMk' + const nonPartyPublicKey = 'FIO5mh1UqE5v9TKdYm2Ro6JXCXpSxj1Sm4vKUeydaLd7Cu5aqiSSp' + const NEW_FUNDS_CONTENT = 'new_funds_content' + const RECORD_OBT_DATA_CONTENT = 'record_obt_data_content' + + let fioSDKBob = new FIOSDK( + bobPrivateKey, + bobPublicKey, + config.BASE_URL, + fetchJson + ) + + it(`Encrypt/Decrypt - Request New Funds`, async () => { + const payeeTokenPublicAddress = bobPublicKey + const amount = 1.57 + const chainCode = 'FIO' + const tokenCode = 'FIO' + const memo = 'testing encryption does it work?' + const hash = '' + const offlineUrl = '' + + const content = { + payee_public_address: payeeTokenPublicAddress, + amount: amount, + chain_code: chainCode, + token_code: tokenCode, + memo, + hash, + offline_url: offlineUrl + } + + const cipherContent = fioSDKBob.transactions.getCipherContent(NEW_FUNDS_CONTENT, content, bobPrivateKey, alicePublicKey) + expect(cipherContent).to.be.a('string') + + const uncipherContent = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, alicePrivateKey, bobPublicKey) + expect(uncipherContent.payee_public_address).to.equal(bobPublicKey) + + // same party, ensure cannot decipher try { - const json = { - "fio_public_key": user3.sdk.publicKey, - "limit": 1, - "offset": -1 - } - result = await callFioApi("get_fio_addresses", json); - expect(result.status).to.equal(null); - } catch (err) { - //console.log('Error', err.error); - expect(err.error.fields[0].error).to.equal(config.error.invalidOffset); - expect(err.statusCode).to.equal(400); + const uncipherContentSameParty = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, alicePrivateKey, alicePublicKey) + expect(uncipherContentSameParty.payee_public_address).to.notequal(bobPublicKey) + } catch (e) { + } - }) - it(`Negative limit. Call (get_fio_addresses, limit=-5, offset=5). Expect error type 400: ${config.error.invalidLimit}`, async () => { + // non party, ensure cannot decipher try { - const json = { - "fio_public_key": user3.publicKey, - "limit": -5, - "offset": 5 - } - result = await callFioApi("get_fio_addresses", json); - expect(result.status).to.equal(null); - } catch (err) { - //console.log('Error', err.error); - expect(err.error.fields[0].error).to.equal(config.error.invalidLimit); - expect(err.statusCode).to.equal(400); + const uncipherContentNonParty = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, nonPartyPrivateKey, bobPublicKey) + expect(uncipherContentNonParty.payee_public_address).to.notequal(bobPublicKey) + } catch (e) { + } - }) - it(`Send string to limit/offset. Expect error type 500: ${config.error.parseError}`, async () => { try { - const json = { - "fio_public_key": user3.publicKey, - "limit": "string", - "offset": "string2" - } - result = await callFioApi("get_fio_addresses", json); - expect(result.status).to.equal(null); - } catch (err) { - //console.log('Error', err.error.error); - expect(err.error.error.what).to.equal(config.error.parseError); - expect(err.statusCode).to.equal(500); + const uncipherContentNonPartyA = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, bobPrivateKey, nonPartyPublicKey) + expect(uncipherContentNonPartyA.payee_public_address).to.notequal(bobPublicKey) + } catch (e) { + } + + }) + + it(`Decrypt from iOS SDK - Request New Funds`, async () => { + const cipherContent = 'iNz623p8SjbFG3rNbxLeVzQhs7n4aB8UGHvkF08HhBXD3X9g6bVFJl93j/OqYdkiycxShF64uc9OHFc/qbOeeS8+WVL2YRpd9JaRqdTUE9XKFPZ6lETQ7MTbGT+qppMoJ0tWCP6mWL4M9V1xu6lE3lJkuRS4kXnwtOUJOcBDG7ddFyHaV1LnLY/jnOJHJhm8' + expect(cipherContent).to.be.a('string') + + const uncipherContent = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, alicePrivateKey, bobPublicKey) + expect(uncipherContent.payee_public_address).to.equal(bobPublicKey) + + const uncipherContentA = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, bobPrivateKey, alicePublicKey) + expect(uncipherContentA.payee_public_address).to.equal(bobPublicKey) + + }) + + it(`Decrypt from Kotlin SDK - Request New Funds`, async () => { + const cipherContent = 'PUEe6pA4HAl7EHA1XFRqJPMjrugD0ZT09CDx4/rH3ktwqo+WaoZRIuqXR4Xvr6ki1XPp7KwwSy6GqPUuBRuBS8Z8c0/xGgcDXQHJuYSsaV3d9Q61W1JeCDvsSIOdd3MTzObNJNcMj3gad+vPcOvJ7BojeufUoe0HQvxjXO+Gpp20UPdQnljLVsir+XuFmreZwMLWfggIovd0A9t438o+DA==' + expect(cipherContent).to.be.a('string') + + const uncipherContent = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, alicePrivateKey, bobPublicKey) + expect(uncipherContent.payee_public_address).to.equal(bobPublicKey) + + const uncipherContentA = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, bobPrivateKey, alicePublicKey) + expect(uncipherContentA.payee_public_address).to.equal(bobPublicKey) + }) - it(`Invalid pub key. Expect error type 400: ${config.error.invalidKey}`, async () => { + it(`Encrypt/Decrypt - RecordObtData`, async () => { + const payerTokenPublicAddress = alicePublicKey + const payeeTokenPublicAddress = bobPublicKey + const amount = 1.57 + const chainCode = 'FIO' + const tokenCode = 'FIO' + const memo = 'testing TypeScript SDK encryption does it work?' + const hash = '' + const offlineUrl = '' + + const content = { + payer_public_address: payerTokenPublicAddress, + payee_public_address: payeeTokenPublicAddress, + amount: amount, + chain_code: chainCode, + token_code: tokenCode, + status: '', + obt_id: '', + memo: memo, + hash: hash, + offline_url: offlineUrl + } + + const cipherContent = fioSDKBob.transactions.getCipherContent(RECORD_OBT_DATA_CONTENT, content, bobPrivateKey, alicePublicKey) + expect(cipherContent).to.be.a('string') + + const uncipherContent = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, alicePrivateKey, bobPublicKey) + expect(uncipherContent.payee_public_address).to.equal(bobPublicKey) + + // same party, ensure cannot decipher try { - const json = { - "fio_public_key": 'FIOXXXLGcmXLCw87pqNMFurd23SqqEDbCUirr7vwuwuzfaySxQ9w6', - "limit": 5, - "offset": 5 - } - result = await callFioApi("get_fio_addresses", json); - expect(result.status).to.equal(null); - } catch (err) { - //console.log('Error', err.error); - expect(err.error.fields[0].error).to.equal(config.error.invalidKey); - expect(err.statusCode).to.equal(400); + const uncipherContentSameParty = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, alicePrivateKey, alicePublicKey) + expect(uncipherContentSameParty.payee_public_address).to.notequal(bobPublicKey) + } catch (e) { + // successful, on failure. Should not decrypt } - }) - it(`Use floats in limit/offset. Expect valid return with zero results.`, async () => { + // non party, ensure cannot decipher try { - const json = { - "fio_public_key": user3.publicKey, - "limit": 123.456, - "offset": 345.678 - } - result = await callFioApi("get_fio_addresses", json); - //console.log('Result: ', result) - expect(result.fio_addresses.length).to.equal(0) - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null) + const uncipherContentNonParty = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, nonPartyPrivateKey, bobPublicKey) + expect(uncipherContentNonParty.payee_public_address).to.notequal(bobPublicKey) + } catch (e) { + } - }) - it(`No pub key. Expect error type 400: ${config.error.invalidKey}`, async () => { try { - const json = { - "limit": 1, - "offset": 1 - } - result = await callFioApi("get_fio_addresses", json); - expect(result.status).to.equal(null); - } catch (err) { - //console.log('Error', err.error); - expect(err.error.fields[0].error).to.equal(config.error.invalidKey); - expect(err.statusCode).to.equal(400); + const uncipherContentNonPartyA = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, bobPrivateKey, nonPartyPublicKey) + expect(uncipherContentNonPartyA.payee_public_address).to.notequal(bobPublicKey) + } catch (e) { + } + }) + it(`Decrypt from iOS SDK - RecordObtData`, async () => { + const cipherContent = 'XJqqkHspW0zp+dHKj9TZMn5mZzdMQrdIAXNOlKPekeEpbjyeh92hO+lB9gA6wnNuq8YNLcGA1s0NPGzb+DlHzXT2tCulgk5fiQy6+8AbThPzB0N6xICmVV3Ontib8FVlTrVrqg053PK9JeHUsg0Sb+vG/dz9+ovcSDHaByxybRNhZOVBe8jlg91eakaU1H8XKDxYOtI3+jYESK02g2Rw5Ya9ec+/PnEBQ6DjkHruKDorEF1D+nDT/0CK46VsfdYzYK8IV0T9Nal4H6Bf4wrMlQ==' + expect(cipherContent).to.be.a('string') + + const uncipherContent = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, alicePrivateKey, bobPublicKey) + expect(uncipherContent.payee_public_address).to.equal(bobPublicKey) + + const uncipherContentA = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, bobPrivateKey, alicePublicKey) + expect(uncipherContentA.payee_public_address).to.equal(bobPublicKey) + + }) + + it(`Decrypt from Kotlin SDK - RecordObtData`, async () => { + const cipherContent = '4IVNiV3Vg0/ZwkBywOWjSgER/aBzHypmfYoljA7y3Qf04mI/IkwPwO9+yj7EISTdRb2LEPgEDg1RsWBdAFmm6AE9ZXG1W5qPrtFNZuZw3qhCJbisnTLCPA2pEcAGKxBhhTaIx74/+OLXTNq5Z7RWWB+OUIa3bBJLHyhO79BUQ9dIsfiDVGmlRL5yq57uqRfb8FWoQraK31As/OFJ5Gj7KEYehzviJnMX7pYhE4CJkkfYYGfB4AHmHllFSMaLCrkY8BvDViQZTuniqDOua6Po51muyCaJLF5rdMSS0Za5F9U=' + expect(cipherContent).to.be.a('string') + + const uncipherContent = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, alicePrivateKey, bobPublicKey) + expect(uncipherContent.payee_public_address).to.equal(bobPublicKey) + + const uncipherContentA = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, bobPrivateKey, alicePublicKey) + expect(uncipherContentA.payee_public_address).to.equal(bobPublicKey) + + }) + +}) + +describe.skip('Check prepared transaction', () => { + it(`requestFunds prepared transaction`, async () => { + fioSdk2.setSignedTrxReturnOption(true) + const preparedTrx = await fioSdk2.sdk.genericAction('requestFunds', { + payerFioAddress: testFioAddressName, + payeeFioAddress: testFioAddressName2, + payeePublicAddress: testFioAddressName2, + amount: 200000, + chainCode: fioChainCode, + tokenCode: fioTokenCode, + memo: 'prepared transaction', + maxFee: defaultFee, + }) + const result = await fioSdk2.executePreparedTrx(EndPoint.newFundsRequest, preparedTrx) + expect(result).to.have.all.keys('fio_request_id', 'status', 'fee_collected') + expect(result.fio_request_id).to.be.a('number') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + fioSdk2.setSignedTrxReturnOption(false) + }) }) diff --git a/tests/testnet.smoketest.js b/tests/testnet.smoketest.js deleted file mode 100644 index 2c60a4e1..00000000 --- a/tests/testnet.smoketest.js +++ /dev/null @@ -1,1182 +0,0 @@ -require('mocha') -const {expect} = require('chai') -const {FIOSDK} = require('@fioprotocol/fiosdk') -const {newUser, existingUser, fetchJson} = require('../utils.js'); -config = require('../config.js'); -const { EndPoint } = require('@fioprotocol/fiosdk/lib/entities/EndPoint') - -let target = 'local' -let privateKey, publicKey, testFioAddressName, privateKey2, publicKey2, testFioAddressName2 - -/** - * Set your testnet existing private/public keys and existing fioAddresses (not needed if running locally) - */ -privateKey = '', -publicKey = '', -account = '', -privateKey2 = '', -publicKey2 = '', -account2 = '', -testFioDomain = 'fiotestnet', -testFioAddressName = '', -testFioAddressName2 = '' - -const fioTestnetDomain = 'fiotestnet' -const fioTokenCode = 'FIO' -const fioChainCode = 'FIO' -const ethTokenCode = 'ETH' -const ethChainCode = 'ETH' -const defaultBundledSets = 1 -const defaultFee = 800 * FIOSDK.SUFUnit - -let fioSdk, fioSdk2 -let newFioDomain, newFioAddress, privateKeyExample, publicKeyExample, pubKeyForTransfer - -const generateTestingFioAddress = (customDomain = fioTestnetDomain) => { - return `testing${Date.now()}@${customDomain}` -} - -const generateTestingFioDomain = () => { - return `testing-domain-${Date.now()}` -} - -const generateObtId = () => { - return `${Date.now()}` -} - -const timeout = async (ms) => { - await new Promise(resolve => { - setTimeout(resolve, ms) - }) -} - -before(async () => { - - if (target == 'local') { - faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); - fioSdk = await newUser(faucet); - fioSdk2 = await newUser(faucet); - privateKey = fioSdk.privateKey, - publicKey = fioSdk.publicKey, - testFioAddressName = fioSdk.address, - privateKey2 = fioSdk2.privateKey, - publicKey2 = fioSdk2.publicKey, - testFioAddressName2 = fioSdk2.address - } else { - fioSdk = await existingUser(account, privateKey, publicKey, testFioDomain, testFioAddressName); - fioSdk = await existingUser(account2, privateKey2, publicKey2, testFioDomain, testFioAddressName2); - } - - try { - const isAvailableResult = await fioSdk.sdk.genericAction('isAvailable', { - fioName: testFioAddressName - }) - if (!isAvailableResult.is_registered) { - await fioSdk.sdk.genericAction('registerFioAddress', { - fioAddress: testFioAddressName, - maxFee: defaultFee - }) - } - } catch (e) { - console.log(e); - } - try { - const isAvailableResult2 = await fioSdk2.sdk.genericAction('isAvailable', { - fioName: testFioAddressName2 - }) - if (!isAvailableResult2.is_registered) { - await fioSdk2.sdk.genericAction('registerFioAddress', { - fioAddress: testFioAddressName2, - maxFee: defaultFee - }) - } - } catch (e) { - console.log(e); - } - - await timeout(4000) - - newFioDomain = generateTestingFioDomain() - - newFioAddress = generateTestingFioAddress(newFioDomain) - privateKeyExample = '5Kbb37EAqQgZ9vWUHoPiC2uXYhyGSFNbL6oiDp24Ea1ADxV1qnu' - publicKeyExample = 'FIO5kJKNHwctcfUM5XZyiWSqSTM5HTzznJP9F3ZdbhaQAHEVq575o' - pubKeyForTransfer = 'FIO7isxEua78KPVbGzKemH4nj2bWE52gqj8Hkac3tc7jKNvpfWzYS' -}) - - -describe('Testing generic actions', () => { - - it(`FIO Key Generation Testing`, async () => { - const testMnemonic = 'valley alien library bread worry brother bundle hammer loyal barely dune brave' - const privateKeyRes = await FIOSDK.createPrivateKeyMnemonic(testMnemonic) - expect(privateKeyRes.fioKey).to.equal(privateKeyExample) - const publicKeyRes = FIOSDK.derivedPublicKey(privateKeyRes.fioKey) - expect(publicKeyRes.publicKey).to.equal(publicKeyExample) - }) - - it(`FIO SUF Utilities - amountToSUF`, async () => { - const sufa = FIOSDK.amountToSUF (100) - expect(sufa).to.equal(100000000000) - - const sufb = FIOSDK.amountToSUF (500) - expect(sufb).to.equal(500000000000) - - const sufc = FIOSDK.amountToSUF (506) - expect(sufc).to.equal(506000000000) - - const sufd = FIOSDK.amountToSUF (1) - expect(sufd).to.equal(1000000000) - - const sufe = FIOSDK.amountToSUF (2) - expect(sufe).to.equal(2000000000) - - const suff = FIOSDK.amountToSUF (2.568) - expect(suff).to.equal(2568000000) - - const sufg = FIOSDK.amountToSUF (2.123) - expect(sufg).to.equal(2123000000) - }) - - it(`FIO SUF Utilities - SUFToAmount`, async () => { - const sufa = FIOSDK.SUFToAmount (100000000000) - expect(sufa).to.equal(100) - - const sufb = FIOSDK.SUFToAmount (500000000000) - expect(sufb).to.equal(500) - - const sufc = FIOSDK.SUFToAmount (506000000000) - expect(sufc).to.equal(506) - - const sufd = FIOSDK.SUFToAmount (1000000000) - expect(sufd).to.equal(1) - - const sufe = FIOSDK.SUFToAmount (2000000000) - expect(sufe).to.equal(2) - - const suff = FIOSDK.SUFToAmount (2568000000) - expect(suff).to.equal(2.568) - - const sufg = FIOSDK.SUFToAmount (2123000000) - expect(sufg).to.equal(2.123) - }) - - it(`Validation methods`, async () => { - try { - FIOSDK.isChainCodeValid('$%34') - } catch (e) { - expect(e.list[0].message).to.equal('chainCode must match /^[a-z0-9]+$/i.') - } - try { - FIOSDK.isTokenCodeValid('') - } catch (e) { - expect(e.list[0].message).to.equal('tokenCode is required.') - } - try { - FIOSDK.isFioAddressValid('f') - } catch (e) { - expect(e.list[0].message).to.equal('fioAddress must have a length between 3 and 64.') - } - try { - FIOSDK.isFioDomainValid('$%FG%') - } catch (e) { - expect(e.list[0].message).to.equal('fioDomain must match /^[a-z0-9\\-]+$/i.') - } - try { - FIOSDK.isFioPublicKeyValid('dfsd') - } catch (e) { - expect(e.list[0].message).to.equal('fioPublicKey must match /^FIO\\w+$/.') - } - try { - FIOSDK.isPublicAddressValid('') - } catch (e) { - expect(e.list[0].message).to.equal('publicAddress is required.') - } - - const chainCodeIsValid = FIOSDK.isChainCodeValid('FIO') - expect(chainCodeIsValid).to.equal(true) - - const tokenCodeIsValid = FIOSDK.isTokenCodeValid('FIO') - expect(tokenCodeIsValid).to.equal(true) - - const singleDigitFioAddressIsValid = FIOSDK.isFioAddressValid('f@2') - expect(singleDigitFioAddressIsValid).to.equal(true) - - const fioAddressIsValid = FIOSDK.isFioAddressValid(newFioAddress) - expect(fioAddressIsValid).to.equal(true) - - const fioDomainIsValid = FIOSDK.isFioDomainValid(newFioDomain) - expect(fioDomainIsValid).to.equal(true) - - const privateKeyIsValid = FIOSDK.isFioPublicKeyValid(publicKey) - expect(privateKeyIsValid).to.equal(true) - - const publicKeyIsValid = FIOSDK.isPublicAddressValid(publicKey) - expect(publicKeyIsValid).to.equal(true) - }) - - it(`Getting fio public key`, async () => { - const result = await fioSdk.sdk.genericAction('getFioPublicKey', {}) - - expect(result).to.equal(publicKey) - }) - - it(`getFioBalance`, async () => { - const result = await fioSdk.sdk.genericAction('getFioBalance', {}) - - expect(result).to.have.all.keys('balance','available') - expect(result.balance).to.be.a('number') - }) -}) - -describe('Testing domain actions', () => { - - it(`Register fio domain`, async () => { - const result = await fioSdk2.sdk.genericAction('registerFioDomain', { fioDomain: newFioDomain, maxFee: defaultFee }) - //console.log('New Domain: ', newFioDomain) - expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.expiration).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it(`Renew fio domain`, async () => { - const result = await fioSdk2.sdk.genericAction('renewFioDomain', { fioDomain: newFioDomain, maxFee: defaultFee }) - - expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.expiration).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it(`setFioDomainVisibility true`, async () => { - const result = await fioSdk2.sdk.genericAction('setFioDomainVisibility', { - fioDomain: newFioDomain, - isPublic: true, - maxFee: defaultFee, - technologyProviderId: '' - }) - - expect(result).to.have.all.keys('status', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it(`Register fio address`, async () => { - const result = await fioSdk2.sdk.genericAction('registerFioAddress', { - fioAddress: newFioAddress, - maxFee: defaultFee - }) - - expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.expiration).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it(`getFioNames`, async () => { - const result = await fioSdk2.sdk.genericAction('getFioNames', { fioPublicKey: publicKey }) - - expect(result).to.have.all.keys('fio_domains', 'fio_addresses') - expect(result.fio_domains).to.be.a('array') - expect(result.fio_addresses).to.be.a('array') - }) - - it(`getFioDomains`, async () => { - try{ - const result = await fioSdk2.sdk.genericAction('getFioDomains', { fioPublicKey: fioSdk.publicKey }) - - expect(result).to.have.all.keys('fio_domains','more') - expect(result.fio_domains).to.be.a('array') - } catch (e) { - console.log(e); - } - }) - - it(`Register owner fio address`, async () => { - const newFioAddress2 = generateTestingFioAddress(newFioDomain) - const result = await fioSdk2.sdk.genericAction('registerFioAddress', { - fioAddress: newFioAddress2, - ownerPublicKey: publicKey2, - maxFee: defaultFee - }) - expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.expiration).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it(`setFioDomainVisibility false`, async () => { - const result = await fioSdk2.sdk.genericAction('setFioDomainVisibility', { - fioDomain: newFioDomain, - isPublic: false, - maxFee: defaultFee, - technologyProviderId: '' - }) - - expect(result).to.have.all.keys('status', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it(`Wait a few seconds.`, async () => { await timeout(3000) }) - - it(`setFioDomainVisibility true`, async () => { - const result = await fioSdk2.sdk.genericAction('setFioDomainVisibility', { - fioDomain: newFioDomain, - isPublic: true, - maxFee: defaultFee, - technologyProviderId: '' - }) - - expect(result).to.have.all.keys('status', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it(`getFee for transferFioAddress`, async () => { - const result = await fioSdk2.sdk.genericAction('getFeeForTransferFioAddress', { - fioAddress: newFioAddress - }) - - expect(result).to.have.all.keys('fee') - expect(result.fee).to.be.a('number') - }) - - it.skip(`Need to move: Transfer fio address`, async () => { - const result = await fioSdk2.sdk.genericAction('transferFioAddress', { - fioAddress: newFioAddress, - newOwnerKey: pubKeyForTransfer, - maxFee: defaultFee - }) - - expect(result).to.have.all.keys('status', 'fee_collected') - expect(result.snew-funtatus).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it(`getFee for transferFioDomain`, async () => { - const result = await fioSdk2.sdk.genericAction('getFeeForTransferFioDomain', { - fioAddress: newFioAddress - }) - - expect(result).to.have.all.keys('fee') - expect(result.fee).to.be.a('number') - }) - - it(`Transfer fio domain`, async () => { - const result = await fioSdk2.sdk.genericAction('transferFioDomain', { - fioDomain: newFioDomain, - newOwnerKey: pubKeyForTransfer, - maxFee: defaultFee - }) - - expect(result).to.have.all.keys('status', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it.skip(`Bahamas: getFee for addBundledTransactions`, async () => { - const result = await fioSdk2.sdk.genericAction('getFeeForAddBundledTransactions', { - fioAddress: newFioAddress - }) - - expect(result).to.have.all.keys('fee') - expect(result.fee).to.be.a('number') - }) - - it.skip(`Bahamas: add Bundled Transactions`, async () => { - const result = await fioSdk2.sdk.genericAction('addBundledTransactions', { - fioAddress: newFioAddress, - bundleSets: defaultBundledSets, - maxFee: defaultFee - }) - - expect(result).to.have.all.keys('status', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it(`(push_transaction) user1 run addbundles with sets for FIO Address owned by user2`, async () => { - try { - const result = await fioSdk2.sdk.genericAction('pushTransaction', { - action: 'addbundles', - account: 'fio.address', - data: { - fio_address: newFioAddress, - bundle_sets: defaultBundledSets, - max_fee: defaultFee, - technologyProviderId: '' - } - }) - //console.log('Result: ', result); - expect(result.status).to.equal('OK'); - } catch (err) { - console.log('Error: ', err); - expect(err).to.equal(null); - } -}) - - it(`Renew fio address`, async () => { - const result = await fioSdk2.sdk.genericAction('renewFioAddress', { fioAddress: newFioAddress, maxFee: defaultFee }) - - expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.expiration).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it(`Push Transaction - renewaddress`, async () => { - await timeout(2000) - const result = await fioSdk2.sdk.genericAction('pushTransaction', { - action: 'renewaddress', - account: 'fio.address', - data: { - fio_address: newFioAddress, - max_fee: defaultFee, - tpid: '' - } - }) - - expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.expiration).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it(`getFee for addPublicAddress`, async () => { - try { - const result = await fioSdk2.sdk.genericAction('getFeeForAddPublicAddress', { - fioAddress: newFioAddress - }) - - expect(result).to.have.all.keys('fee') - expect(result.fee).to.be.a('number') - } catch (err) { - console.log('Error: ', err); - expect(err).to.equal(null); - } - }) - - it(`Add public address`, async () => { - try { - const result = await fioSdk2.sdk.genericAction('addPublicAddress', { - fioAddress: newFioAddress, - chainCode: 'ABC', - tokenCode: 'ABC', - publicAddress: '1PMycacnJaSqwwJqjawXBErnLsZ7RkXUAs', - maxFee: defaultFee, - technologyProviderId: '' - }) - expect(result).to.have.all.keys('status', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - } catch (err) { - console.log('Error: ', err); - expect(err).to.equal(null); - } - }) - - it(`Add public addresses`, async () => { - const result = await fioSdk2.sdk.genericAction('addPublicAddresses', { - fioAddress: newFioAddress, - publicAddresses: [ - { - chain_code: ethChainCode, - token_code: ethTokenCode, - public_address: 'xxxxxxyyyyyyzzzzzz', - }, - { - chain_code: fioChainCode, - token_code: fioTokenCode, - public_address: publicKey, - } - ], - maxFee: defaultFee, - technologyProviderId: '' - }) - - expect(result).to.have.all.keys('status', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it(`getFee for removePublicAddresses`, async () => { - const result = await fioSdk2.sdk.genericAction('getFeeForRemovePublicAddresses', { - fioAddress: newFioAddress - }) - - expect(result).to.have.all.keys('fee') - expect(result.fee).to.be.a('number') - }) - - it(`Remove public addresses`, async () => { - - const result = await fioSdk2.sdk.genericAction('removePublicAddresses', { - fioAddress: newFioAddress, - publicAddresses: [ - { - chain_code: ethChainCode, - token_code: ethTokenCode, - public_address: 'xxxxxxyyyyyyzzzzzz', - } - ], - maxFee: defaultFee, - technologyProviderId: '' - }) - expect(result).to.have.all.keys('status', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it(`getFee for removeAllPublicAddresses`, async () => { - - const result = await fioSdk2.sdk.genericAction('getFeeForRemoveAllPublicAddresses', { - fioAddress: newFioAddress - }) - - expect(result).to.have.all.keys('fee') - expect(result.fee).to.be.a('number') - }) - - it(`Remove all public addresses`, async () => { - await fioSdk2.sdk.genericAction('addPublicAddresses', { - fioAddress: newFioAddress, - publicAddresses: [ - { - chain_code: ethChainCode, - token_code: ethTokenCode, - public_address: 'xxxxxxyyyyyyzzzzzz1', - } - ], - maxFee: defaultFee, - technologyProviderId: '' - }) - - const result = await fioSdk2.sdk.genericAction('removeAllPublicAddresses', { - fioAddress: newFioAddress, - maxFee: defaultFee, - technologyProviderId: '' - }) - expect(result).to.have.all.keys('status', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it(`isAvailable true`, async () => { - const result = await fioSdk2.sdk.genericAction('isAvailable', { - fioName: generateTestingFioAddress(), - }) - - expect(result.is_registered).to.equal(0) - }) - - it(`isAvailable false`, async () => { - const result = await fioSdk2.sdk.genericAction('isAvailable', { - fioName: testFioAddressName - }) - - expect(result.is_registered).to.equal(1) - }) - - it(`getFioBalance for custom fioPublicKey`, async () => { - const result = await fioSdk2.sdk.genericAction('getFioBalance', { - fioPublicKey: publicKey2 - }) - - expect(result).to.have.all.keys('balance', 'available') - expect(result.balance).to.be.a('number') - }) - - - it(`getFioAddresses`, async () => { - try { - const result = await fioSdk2.sdk.genericAction('getFioAddresses', { fioPublicKey: publicKey }) - - expect(result).to.have.all.keys('fio_addresses','more') - expect(result.fio_addresses).to.be.a('array') - } catch (e) { - console.log(e); - } - }) - - - it(`getPublicAddress`, async () => { - const result = await fioSdk2.sdk.genericAction('getPublicAddress', { - fioAddress: newFioAddress, chainCode: fioChainCode, tokenCode: fioTokenCode - }) - - expect(result.public_address).to.be.a('string') - }) - - it(`getFee`, async () => { - const result = await fioSdk2.sdk.genericAction('getFee', { - endPoint: 'register_fio_address', - fioAddress: '' - }) - - expect(result).to.have.all.keys('fee') - expect(result.fee).to.be.a('number') - }) - - it(`getMultiplier`, async () => { - const result = await fioSdk2.sdk.genericAction('getMultiplier', {}) - - expect(result).to.be.a('number') - }) - - it(`getFee for BurnFioAddress`, async () => { - const result = await fioSdk2.sdk.genericAction('getFeeForBurnFioAddress', { - fioAddress: newFioAddress - }) - - expect(result).to.have.all.keys('fee') - expect(result.fee).to.be.a('number') - }) - - it(`Burn fio address`, async () => { - const result = await fioSdk2.sdk.genericAction('burnFioAddress', { - fioAddress: newFioAddress, - maxFee: defaultFee - }) - - expect(result).to.have.all.keys('status', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - -}) - -describe('Request funds, approve and send', () => { - const fundsAmount = 3 - let requestId - const memo = 'testing fund request' - - it(`getFee for requestFunds`, async () => { - const result = await fioSdk2.sdk.genericAction('getFeeForNewFundsRequest', { - payeeFioAddress: testFioAddressName2 - }) - - expect(result).to.have.all.keys('fee') - expect(result.fee).to.be.a('number') - }) - - it(`requestFunds`, async () => { - const result = await fioSdk2.sdk.genericAction('requestFunds', { - payerFioAddress: testFioAddressName, - payeeFioAddress: testFioAddressName2, - payeeTokenPublicAddress: publicKey2, - amount: fundsAmount, - chainCode: fioChainCode, - tokenCode: fioTokenCode, - memo: '', - maxFee: defaultFee, - payerFioPublicKey: publicKey, - technologyProviderId: '', - hash: '', - offLineUrl: '' - }) - //console.log('requestFunds: ', result) - requestId = result.fio_request_id - expect(result).to.have.all.keys('fio_request_id', 'status', 'fee_collected') - expect(result.fio_request_id).to.be.a('number') - expect(result.status).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it(`getPendingFioRequests`, async () => { - await timeout(4000) - const result = await fioSdk.sdk.genericAction('getPendingFioRequests', {}) - expect(result).to.have.all.keys('requests', 'more') - expect(result.requests).to.be.a('array') - expect(result.more).to.be.a('number') - const pendingReq = result.requests.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) - expect(pendingReq).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'time_stamp', 'content') - expect(pendingReq.fio_request_id).to.be.a('number') - expect(pendingReq.fio_request_id).to.equal(requestId) - expect(pendingReq.payer_fio_address).to.be.a('string') - expect(pendingReq.payer_fio_address).to.equal(testFioAddressName) - expect(pendingReq.payee_fio_address).to.be.a('string') - expect(pendingReq.payee_fio_address).to.equal(testFioAddressName2) - }) - - it(`recordObtData`, async () => { - const result = await fioSdk.sdk.genericAction('recordObtData', { - fioRequestId: requestId, - payerFioAddress: testFioAddressName, - payeeFioAddress: testFioAddressName2, - payerTokenPublicAddress: publicKey, - payeeTokenPublicAddress: publicKey2, - amount: fundsAmount, - chainCode: fioChainCode, - tokenCode: fioTokenCode, - status: 'sent_to_blockchain', - obtId: '', - maxFee: defaultFee, - }) - expect(result).to.have.all.keys('status', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it(`getSentFioRequests`, async () => { - const result = await fioSdk2.sdk.genericAction('getSentFioRequests', {}) - expect(result).to.have.all.keys('requests', 'more') - expect(result.requests).to.be.a('array') - expect(result.more).to.be.a('number') - /* const pendingReq = result.requests.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) - expect(pendingReq).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'status', 'time_stamp', 'content') - expect(pendingReq.fio_request_id).to.be.a('number') - expect(pendingReq.fio_request_id).to.equal(requestId) - expect(pendingReq.payer_fio_address).to.be.a('string') - expect(pendingReq.payer_fio_address).to.equal(testFioAddressName) - expect(pendingReq.payee_fio_address).to.be.a('string') - expect(pendingReq.payee_fio_address).to.equal(testFioAddressName2) */ - }) - - it(`Payer getObtData`, async () => { - await timeout(10000) - const result = await fioSdk.sdk.genericAction('getObtData', {}) - expect(result).to.have.all.keys('obt_data_records', 'more') - expect(result.obt_data_records).to.be.a('array') - expect(result.more).to.be.a('number') - const obtData = result.obt_data_records.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) - expect(obtData).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'status', 'time_stamp', 'content') - expect(obtData.fio_request_id).to.be.a('number') - expect(obtData.fio_request_id).to.equal(requestId) - expect(obtData.payer_fio_address).to.be.a('string') - expect(obtData.payer_fio_address).to.equal(testFioAddressName) - expect(obtData.payee_fio_address).to.be.a('string') - expect(obtData.payee_fio_address).to.equal(testFioAddressName2) - }) - - it(`Payee getObtData`, async () => { - const result = await fioSdk2.sdk.genericAction('getObtData', {}) - expect(result).to.have.all.keys('obt_data_records', 'more') - expect(result.obt_data_records).to.be.a('array') - expect(result.more).to.be.a('number') - const obtData = result.obt_data_records.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) - expect(obtData).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'status', 'time_stamp', 'content') - expect(obtData.fio_request_id).to.be.a('number') - expect(obtData.fio_request_id).to.equal(requestId) - expect(obtData.payer_fio_address).to.be.a('string') - expect(obtData.payer_fio_address).to.equal(testFioAddressName) - expect(obtData.payee_fio_address).to.be.a('string') - expect(obtData.payee_fio_address).to.equal(testFioAddressName2) - }) - -}) - -describe('Request funds, cancel funds request', () => { - const fundsAmount = 3 - let requestId - const memo = 'testing fund request' - - it(`requestFunds`, async () => { - const result = await fioSdk2.sdk.genericAction('requestFunds', { - payerFioAddress: testFioAddressName, - payeeFioAddress: testFioAddressName2, - payeePublicAddress: testFioAddressName2, - amount: fundsAmount, - chainCode: fioChainCode, - tokenCode: fioTokenCode, - memo, - maxFee: defaultFee, - }) - - requestId = result.fio_request_id - expect(result).to.have.all.keys('fio_request_id', 'status', 'fee_collected') - expect(result.fio_request_id).to.be.a('number') - expect(result.status).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it(`cancel request`, async () => { - try{ - const result = await fioSdk2.sdk.genericAction('cancelFundsRequest', { - fioRequestId: requestId, - maxFee: defaultFee, - tpid: '' - }) - expect(result).to.have.all.keys('status', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - } catch (e) { - console.log(e); - } - }) - - - it(`getCancelledFioRequests`, async () => { - try{ - await timeout(4000) - const result = await fioSdk2.sdk.genericAction('getCancelledFioRequests', {}) - expect(result).to.have.all.keys('requests', 'more') - expect(result.requests).to.be.a('array') - expect(result.more).to.be.a('number') - const pendingReq = result.requests.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) - expect(pendingReq).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'time_stamp', 'content', 'status') - expect(pendingReq.fio_request_id).to.be.a('number') - expect(pendingReq.fio_request_id).to.equal(requestId) - expect(pendingReq.payer_fio_address).to.be.a('string') - expect(pendingReq.payer_fio_address).to.equal(testFioAddressName) - expect(pendingReq.payee_fio_address).to.be.a('string') - expect(pendingReq.payee_fio_address).to.equal(testFioAddressName2) - } catch (e) { - console.log(e); - } - }) - -}) - -describe('Request funds, reject', () => { - const fundsAmount = 4 - let requestId - const memo = 'testing fund request' - - it(`requestFunds`, async () => { - const result = await fioSdk2.sdk.genericAction('requestFunds', { - payerFioAddress: testFioAddressName, - payeeFioAddress: testFioAddressName2, - payeePublicAddress: testFioAddressName2, - amount: fundsAmount, - chainCode: fioChainCode, - tokenCode: fioTokenCode, - memo, - maxFee: defaultFee, - }) - - requestId = result.fio_request_id - expect(result).to.have.all.keys('fio_request_id', 'status', 'fee_collected') - expect(result.fio_request_id).to.be.a('number') - expect(result.status).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it(`getPendingFioRequests`, async () => { - await timeout(4000) - const result = await fioSdk.sdk.genericAction('getPendingFioRequests', {}) - - expect(result).to.have.all.keys('requests', 'more') - expect(result.requests).to.be.a('array') - expect(result.more).to.be.a('number') - const pendingReq = result.requests.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) - expect(pendingReq).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'time_stamp', 'content') - expect(pendingReq.fio_request_id).to.be.a('number') - expect(pendingReq.fio_request_id).to.equal(requestId) - expect(pendingReq.payer_fio_address).to.be.a('string') - expect(pendingReq.payer_fio_address).to.equal(testFioAddressName) - expect(pendingReq.payee_fio_address).to.be.a('string') - expect(pendingReq.payee_fio_address).to.equal(testFioAddressName2) - }) - - it(`getFee for rejectFundsRequest`, async () => { - const result = await fioSdk2.sdk.genericAction('getFeeForRejectFundsRequest', { - payerFioAddress: testFioAddressName2 - }) - - expect(result).to.have.all.keys('fee') - expect(result.fee).to.be.a('number') - }) - - it(`rejectFundsRequest`, async () => { - const result = await fioSdk.sdk.genericAction('rejectFundsRequest', { - fioRequestId: requestId, - maxFee: defaultFee, - }) - - expect(result).to.have.all.keys('status', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - -}) - -describe('Transfer tokens', () => { - const fundsAmount = FIOSDK.SUFUnit - let fioBalance = 0 - let fioBalanceAfter = 0 - - it(`Check balance before transfer`, async () => { - const result = await fioSdk2.sdk.genericAction('getFioBalance', {}) - fioBalance = result.balance - }) - - it(`Transfer tokens`, async () => { - const result = await fioSdk.sdk.genericAction('transferTokens', { - payeeFioPublicKey: publicKey2, - amount: fundsAmount, - maxFee: defaultFee, - }) - expect(result).to.have.all.keys('status', 'fee_collected', 'transaction_id', 'block_num') - expect(result.status).to.be.a('string') - expect(result.transaction_id).to.be.a('string') - expect(result.block_num).to.be.a('number') - expect(result.fee_collected).to.be.a('number') - }) - - it(`Check balance and balance change`, async () => { - await timeout(10000) - const result = await fioSdk2.sdk.genericAction('getFioBalance', {}) - fioBalanceAfter = result.balance - expect(fundsAmount).to.equal(fioBalanceAfter - fioBalance) - }) -}) - -describe('Record obt data, check', () => { - const obtId = generateObtId() - const fundsAmount = 4.5 - - it(`getFee for recordObtData`, async () => { - const result = await fioSdk.sdk.genericAction('getFeeForRecordObtData', { - payerFioAddress: testFioAddressName - }) - - expect(result).to.have.all.keys('fee') - expect(result.fee).to.be.a('number') - }) - - it(`recordObtData`, async () => { - const result = await fioSdk.sdk.genericAction('recordObtData', { - fioRequestId: '', - payerFioAddress: testFioAddressName, - payeeFioAddress: testFioAddressName2, - payerTokenPublicAddress: publicKey, - payeeTokenPublicAddress: publicKey2, - amount: fundsAmount, - chainCode: fioChainCode, - tokenCode: fioTokenCode, - status: 'sent_to_blockchain', - obtId, - maxFee: defaultFee, - }) - expect(result).to.have.all.keys('status', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - - it(`Payer getObtData`, async () => { - await timeout(4000) - const result = await fioSdk.sdk.genericAction('getObtData', { tokenCode: fioTokenCode }) - expect(result).to.have.all.keys('obt_data_records', 'more') - expect(result.obt_data_records).to.be.a('array') - expect(result.more).to.be.a('number') - const obtData = result.obt_data_records.find(pr => pr.content.obt_id === obtId) - expect(obtData).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'status', 'time_stamp', 'content') - expect(obtData.content.obt_id).to.be.a('string') - expect(obtData.content.obt_id).to.equal(obtId) - expect(obtData.payer_fio_address).to.be.a('string') - expect(obtData.payer_fio_address).to.equal(testFioAddressName) - expect(obtData.payee_fio_address).to.be.a('string') - expect(obtData.payee_fio_address).to.equal(testFioAddressName2) - }) - - it(`Payee getObtData`, async () => { - const result = await fioSdk2.sdk.genericAction('getObtData', { tokenCode: fioTokenCode }) - expect(result).to.have.all.keys('obt_data_records', 'more') - expect(result.obt_data_records).to.be.a('array') - expect(result.more).to.be.a('number') - /* const obtData = result.obt_data_records.find(pr => pr.content.obt_id === obtId) - expect(obtData).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'status', 'time_stamp', 'content') - expect(obtData.content.obt_id).to.be.a('string') - expect(obtData.content.obt_id).to.equal(obtId) - expect(obtData.payer_fio_address).to.be.a('string') - expect(obtData.payer_fio_address).to.equal(testFioAddressName) - expect(obtData.payee_fio_address).to.be.a('string') - expect(obtData.payee_fio_address).to.equal(testFioAddressName2) */ - }) -}) - -describe('Encrypting/Decrypting', () => { - const alicePrivateKey = '5J35xdLtcPvDASxpyWhNrR2MfjSZ1xjViH5cvv15VVjqyNhiPfa' - const alicePublicKey = 'FIO6NxZ7FLjjJuHGByJtNJQ1uN1P5X9JJnUmFW3q6Q7LE7YJD4GZs' - const bobPrivateKey = '5J37cXw5xRJgE869B5LxC3FQ8ZJECiYnsjuontcHz5cJsz5jhb7' - const bobPublicKey = 'FIO4zUFC29aq8uA4CnfNSyRZCnBPya2uQk42jwevc3UZ2jCRtepVZ' - - const nonPartyPrivateKey = '5HujRtqceTPo4awwHAEdHRTWdMTgA6s39dJjwWcjhNdSjVWUqMk' - const nonPartyPublicKey = 'FIO5mh1UqE5v9TKdYm2Ro6JXCXpSxj1Sm4vKUeydaLd7Cu5aqiSSp' - const NEW_FUNDS_CONTENT = 'new_funds_content' - const RECORD_OBT_DATA_CONTENT = 'record_obt_data_content' - - let fioSDKBob = new FIOSDK( - bobPrivateKey, - bobPublicKey, - config.BASE_URL, - fetchJson - ) - - it(`Encrypt/Decrypt - Request New Funds`, async () => { - const payeeTokenPublicAddress = bobPublicKey - const amount = 1.57 - const chainCode = 'FIO' - const tokenCode = 'FIO' - const memo = 'testing encryption does it work?' - const hash = '' - const offlineUrl = '' - - const content = { - payee_public_address: payeeTokenPublicAddress, - amount: amount, - chain_code: chainCode, - token_code: tokenCode, - memo, - hash, - offline_url: offlineUrl - } - - const cipherContent = fioSDKBob.transactions.getCipherContent(NEW_FUNDS_CONTENT, content, bobPrivateKey, alicePublicKey) - expect(cipherContent).to.be.a('string') - - const uncipherContent = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, alicePrivateKey, bobPublicKey) - expect(uncipherContent.payee_public_address).to.equal(bobPublicKey) - - // same party, ensure cannot decipher - try { - const uncipherContentSameParty = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, alicePrivateKey, alicePublicKey) - expect(uncipherContentSameParty.payee_public_address).to.notequal(bobPublicKey) - } catch (e) { - - } - - // non party, ensure cannot decipher - try { - const uncipherContentNonParty = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, nonPartyPrivateKey, bobPublicKey) - expect(uncipherContentNonParty.payee_public_address).to.notequal(bobPublicKey) - } catch (e) { - - } - - try { - const uncipherContentNonPartyA = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, bobPrivateKey, nonPartyPublicKey) - expect(uncipherContentNonPartyA.payee_public_address).to.notequal(bobPublicKey) - } catch (e) { - - } - - }) - - it(`Decrypt from iOS SDK - Request New Funds`, async () => { - const cipherContent = 'iNz623p8SjbFG3rNbxLeVzQhs7n4aB8UGHvkF08HhBXD3X9g6bVFJl93j/OqYdkiycxShF64uc9OHFc/qbOeeS8+WVL2YRpd9JaRqdTUE9XKFPZ6lETQ7MTbGT+qppMoJ0tWCP6mWL4M9V1xu6lE3lJkuRS4kXnwtOUJOcBDG7ddFyHaV1LnLY/jnOJHJhm8' - expect(cipherContent).to.be.a('string') - - const uncipherContent = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, alicePrivateKey, bobPublicKey) - expect(uncipherContent.payee_public_address).to.equal(bobPublicKey) - - const uncipherContentA = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, bobPrivateKey, alicePublicKey) - expect(uncipherContentA.payee_public_address).to.equal(bobPublicKey) - - }) - - it(`Decrypt from Kotlin SDK - Request New Funds`, async () => { - const cipherContent = 'PUEe6pA4HAl7EHA1XFRqJPMjrugD0ZT09CDx4/rH3ktwqo+WaoZRIuqXR4Xvr6ki1XPp7KwwSy6GqPUuBRuBS8Z8c0/xGgcDXQHJuYSsaV3d9Q61W1JeCDvsSIOdd3MTzObNJNcMj3gad+vPcOvJ7BojeufUoe0HQvxjXO+Gpp20UPdQnljLVsir+XuFmreZwMLWfggIovd0A9t438o+DA==' - expect(cipherContent).to.be.a('string') - - const uncipherContent = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, alicePrivateKey, bobPublicKey) - expect(uncipherContent.payee_public_address).to.equal(bobPublicKey) - - const uncipherContentA = fioSDKBob.transactions.getUnCipherContent(NEW_FUNDS_CONTENT, cipherContent, bobPrivateKey, alicePublicKey) - expect(uncipherContentA.payee_public_address).to.equal(bobPublicKey) - - }) - - it(`Encrypt/Decrypt - RecordObtData`, async () => { - const payerTokenPublicAddress = alicePublicKey - const payeeTokenPublicAddress = bobPublicKey - const amount = 1.57 - const chainCode = 'FIO' - const tokenCode = 'FIO' - const memo = 'testing TypeScript SDK encryption does it work?' - const hash = '' - const offlineUrl = '' - - const content = { - payer_public_address: payerTokenPublicAddress, - payee_public_address: payeeTokenPublicAddress, - amount: amount, - chain_code: chainCode, - token_code: tokenCode, - status: '', - obt_id: '', - memo: memo, - hash: hash, - offline_url: offlineUrl - } - - const cipherContent = fioSDKBob.transactions.getCipherContent(RECORD_OBT_DATA_CONTENT, content, bobPrivateKey, alicePublicKey) - expect(cipherContent).to.be.a('string') - - const uncipherContent = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, alicePrivateKey, bobPublicKey) - expect(uncipherContent.payee_public_address).to.equal(bobPublicKey) - - // same party, ensure cannot decipher - try { - const uncipherContentSameParty = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, alicePrivateKey, alicePublicKey) - expect(uncipherContentSameParty.payee_public_address).to.notequal(bobPublicKey) - } catch (e) { - // successful, on failure. Should not decrypt - } - - // non party, ensure cannot decipher - try { - const uncipherContentNonParty = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, nonPartyPrivateKey, bobPublicKey) - expect(uncipherContentNonParty.payee_public_address).to.notequal(bobPublicKey) - } catch (e) { - - } - - try { - const uncipherContentNonPartyA = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, bobPrivateKey, nonPartyPublicKey) - expect(uncipherContentNonPartyA.payee_public_address).to.notequal(bobPublicKey) - } catch (e) { - - } - - }) - - it(`Decrypt from iOS SDK - RecordObtData`, async () => { - const cipherContent = 'XJqqkHspW0zp+dHKj9TZMn5mZzdMQrdIAXNOlKPekeEpbjyeh92hO+lB9gA6wnNuq8YNLcGA1s0NPGzb+DlHzXT2tCulgk5fiQy6+8AbThPzB0N6xICmVV3Ontib8FVlTrVrqg053PK9JeHUsg0Sb+vG/dz9+ovcSDHaByxybRNhZOVBe8jlg91eakaU1H8XKDxYOtI3+jYESK02g2Rw5Ya9ec+/PnEBQ6DjkHruKDorEF1D+nDT/0CK46VsfdYzYK8IV0T9Nal4H6Bf4wrMlQ==' - expect(cipherContent).to.be.a('string') - - const uncipherContent = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, alicePrivateKey, bobPublicKey) - expect(uncipherContent.payee_public_address).to.equal(bobPublicKey) - - const uncipherContentA = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, bobPrivateKey, alicePublicKey) - expect(uncipherContentA.payee_public_address).to.equal(bobPublicKey) - - }) - - it(`Decrypt from Kotlin SDK - RecordObtData`, async () => { - const cipherContent = '4IVNiV3Vg0/ZwkBywOWjSgER/aBzHypmfYoljA7y3Qf04mI/IkwPwO9+yj7EISTdRb2LEPgEDg1RsWBdAFmm6AE9ZXG1W5qPrtFNZuZw3qhCJbisnTLCPA2pEcAGKxBhhTaIx74/+OLXTNq5Z7RWWB+OUIa3bBJLHyhO79BUQ9dIsfiDVGmlRL5yq57uqRfb8FWoQraK31As/OFJ5Gj7KEYehzviJnMX7pYhE4CJkkfYYGfB4AHmHllFSMaLCrkY8BvDViQZTuniqDOua6Po51muyCaJLF5rdMSS0Za5F9U=' - expect(cipherContent).to.be.a('string') - - const uncipherContent = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, alicePrivateKey, bobPublicKey) - expect(uncipherContent.payee_public_address).to.equal(bobPublicKey) - - const uncipherContentA = fioSDKBob.transactions.getUnCipherContent(RECORD_OBT_DATA_CONTENT, cipherContent, bobPrivateKey, alicePublicKey) - expect(uncipherContentA.payee_public_address).to.equal(bobPublicKey) - - }) - -}) - -describe.skip('Check prepared transaction', () => { - it(`requestFunds prepared transaction`, async () => { - fioSdk2.setSignedTrxReturnOption(true) - const preparedTrx = await fioSdk2.sdk.genericAction('requestFunds', { - payerFioAddress: testFioAddressName, - payeeFioAddress: testFioAddressName2, - payeePublicAddress: testFioAddressName2, - amount: 200000, - chainCode: fioChainCode, - tokenCode: fioTokenCode, - memo: 'prepared transaction', - maxFee: defaultFee, - }) - const result = await fioSdk2.executePreparedTrx(EndPoint.newFundsRequest, preparedTrx) - expect(result).to.have.all.keys('fio_request_id', 'status', 'fee_collected') - expect(result.fio_request_id).to.be.a('number') - expect(result.status).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - fioSdk2.setSignedTrxReturnOption(false) - }) -}) From 1e5db424fa3bb2386d225464280f97917e0306dd Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 11 Jan 2021 08:18:51 -0700 Subject: [PATCH 36/76] Fixes for testnet tests --- package.json | 2 +- tests/testnet-smoketest.js | 32 ++++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index d7a493e5..74ffa01c 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,6 @@ }, "scripts": { "test": "mocha -t 5000000 index.js", - "testnet": "mocha -t 5000000 tests/testnet.smoketest.js" + "testnet": "mocha -t 5000000 tests/testnet-smoketest.js" } } diff --git a/tests/testnet-smoketest.js b/tests/testnet-smoketest.js index aa2d52b3..992b3b7f 100644 --- a/tests/testnet-smoketest.js +++ b/tests/testnet-smoketest.js @@ -1,3 +1,11 @@ +/** + * testnet-smoketest.js is the smoke test for high level regression testing of Testnet releases. + * It can be run against a local devtools build by setting the target = 'local' variable. + * You must have two testnet accounts to run against testnet. + * + * All "describe" tests should be built to run independently. + */ + require('mocha') const {expect} = require('chai') const {FIOSDK} = require('@fioprotocol/fiosdk') @@ -5,21 +13,30 @@ const {newUser, existingUser, fetchJson} = require('../utils.js'); config = require('../config.js'); const { EndPoint } = require('@fioprotocol/fiosdk/lib/entities/EndPoint') -let target = 'local' let privateKey, publicKey, testFioAddressName, privateKey2, publicKey2, testFioAddressName2 +/** +* Set to target = 'local' if running against devtools build. Leave blank if running against Testnet. +*/ +const target = '' + /** * Set your testnet existing private/public keys and existing fioAddresses (not needed if running locally) */ -privateKey = '', -publicKey = '', +privateKey = '5Jw78NzS2QMvjcyemCgJ9XQv8SMSEvTEuLxF8TcKf27xWcX5fmw', +publicKey = 'FIO8k7N7jU9eyj57AfazGxMuvPGZG5hvXNUyxt9pBchnkXXx9KUuD', account = '', -privateKey2 = '', -publicKey2 = '', +privateKey2 = '5Hv1zRFa7XRo395dfHS8xrviszPiVYeBhQjJq4TsPv53NvAcfyU', +publicKey2 = 'FIO7b3WHTsS1wTF2dAUvE9DoDXvxYUVA8FepLW6x9Bv5rPJnUW6ab', account2 = '', testFioDomain = 'fiotestnet', -testFioAddressName = '', -testFioAddressName2 = '' +testFioAddressName = 'ebtest1@fiotestnet', +testFioAddressName2 = 'ebtest3@fiotestnet' + + +/** + * Main Tests + */ const fioTestnetDomain = 'fiotestnet' const fioTokenCode = 'FIO' @@ -104,7 +121,6 @@ before(async () => { pubKeyForTransfer = 'FIO7isxEua78KPVbGzKemH4nj2bWE52gqj8Hkac3tc7jKNvpfWzYS' }) - describe('Testing generic actions', () => { it(`FIO Key Generation Testing`, async () => { From 1bc5651c0af76631f5d3d23f570db79114dda373 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 11 Jan 2021 08:26:51 -0700 Subject: [PATCH 37/76] getfiobalance bug fix --- tests/testnet-smoketest.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/testnet-smoketest.js b/tests/testnet-smoketest.js index 992b3b7f..b702eaa7 100644 --- a/tests/testnet-smoketest.js +++ b/tests/testnet-smoketest.js @@ -23,15 +23,15 @@ const target = '' /** * Set your testnet existing private/public keys and existing fioAddresses (not needed if running locally) */ -privateKey = '5Jw78NzS2QMvjcyemCgJ9XQv8SMSEvTEuLxF8TcKf27xWcX5fmw', -publicKey = 'FIO8k7N7jU9eyj57AfazGxMuvPGZG5hvXNUyxt9pBchnkXXx9KUuD', +privateKey = '', +publicKey = '', account = '', -privateKey2 = '5Hv1zRFa7XRo395dfHS8xrviszPiVYeBhQjJq4TsPv53NvAcfyU', -publicKey2 = 'FIO7b3WHTsS1wTF2dAUvE9DoDXvxYUVA8FepLW6x9Bv5rPJnUW6ab', +privateKey2 = '', +publicKey2 = '', account2 = '', -testFioDomain = 'fiotestnet', -testFioAddressName = 'ebtest1@fiotestnet', -testFioAddressName2 = 'ebtest3@fiotestnet' +testFioDomain = '', +testFioAddressName = '', +testFioAddressName2 = '' /** @@ -240,7 +240,7 @@ describe('Testing generic actions', () => { it(`getFioBalance`, async () => { const result = await fioSdk.sdk.genericAction('getFioBalance', {}) - expect(result).to.have.all.keys('balance','available') + expect(result).to.have.all.keys('balance') expect(result.balance).to.be.a('number') }) }) @@ -600,7 +600,7 @@ describe('Testing domain actions', () => { fioPublicKey: publicKey2 }) - expect(result).to.have.all.keys('balance', 'available') + expect(result).to.have.all.keys('balance') expect(result.balance).to.be.a('number') }) @@ -650,7 +650,7 @@ describe('Testing domain actions', () => { expect(result.fee).to.be.a('number') }) - it(`Burn fio address`, async () => { + it.skip(`Bahamas - Burn fio address`, async () => { const result = await fioSdk2.sdk.genericAction('burnFioAddress', { fioAddress: newFioAddress, maxFee: defaultFee From 4c2557d39f2b1792dfa7d25fb6dcb8934821c4dc Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Thu, 14 Jan 2021 12:58:32 -0700 Subject: [PATCH 38/76] Get tests running with bahamas release --- index.js | 2 +- tests/bravo-migr-test.js | 46 +++++++------- tests/fio-request.js | 8 +-- tests/record-obt-data.js | 6 +- tests/transfer-locked-tokens-account-tests.js | 63 +++++++++++++++---- tests/vote.js | 2 +- 6 files changed, 83 insertions(+), 44 deletions(-) diff --git a/index.js b/index.js index 9dd9f5f2..2d1cc1b8 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ const {expect} = require('chai') describe('TEST SUITE', () => { - //require('./tests/bravo-migr-test.js'); + require('./tests/bravo-migr-test.js'); //This is required when launching with 2.3.0 (bravo) to do the full table migration. //require('./tests/history.js'); // Only run against history node. require('./tests/addaddress.js'); // v1.0.x Also includes FIP-13 tests. diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index 8e0882be..cce10e2b 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -849,16 +849,16 @@ describe(`Go through recordobts (old table) and confirm each entry is in fiotrxt //console.log('requests: ', newRequests); for (newRequest in newRequests.rows) { if (newRequests.rows[newRequest].payer_fio_addr == obts.rows[obt].payer_fio_addr) { - console.log(count); - console.log('recordobts:') - console.log('id: ', obts.rows[obt].id); - console.log('payer_fio_addr: ', obts.rows[obt].payer_fio_addr); - console.log('payee_fio_addr: ', obts.rows[obt].payee_fio_addr); - console.log('fiotrxts:') - console.log('id: ', newRequests.rows[newRequest].id); - console.log('fio_request_id: ', newRequests.rows[newRequest].fio_request_id); - console.log('payer_fio_addr: ', newRequests.rows[newRequest].payer_fio_addr); - console.log('payee_fio_addr: ', newRequests.rows[newRequest].payee_fio_addr); + //console.log(count); + //console.log('recordobts:') + //console.log('id: ', obts.rows[obt].id); + //console.log('payer_fio_addr: ', obts.rows[obt].payer_fio_addr); + //console.log('payee_fio_addr: ', obts.rows[obt].payee_fio_addr); + //console.log('fiotrxts:') + //console.log('id: ', newRequests.rows[newRequest].id); + //console.log('fio_request_id: ', newRequests.rows[newRequest].fio_request_id); + //console.log('payer_fio_addr: ', newRequests.rows[newRequest].payer_fio_addr); + //console.log('payee_fio_addr: ', newRequests.rows[newRequest].payee_fio_addr); expect(obts.rows[obt].payer_fio_addr).to.equal(newRequests.rows[newRequest].payer_fio_addr); expect(obts.rows[obt].payee_fio_addr).to.equal(newRequests.rows[newRequest].payee_fio_addr); @@ -955,19 +955,19 @@ describe(`Go through fioreqctxts (old table) and confirm each entry is in fiotrx //console.log('requests: ', newRequests); for (newRequest in newRequests.rows) { if (newRequests.rows[newRequest].fio_request_id == reqs.rows[req].fio_request_id) { - console.log(count); - console.log('fioreqctxts:') - console.log('fio_request_id: ', reqs.rows[req].fio_request_id); - console.log('payer_fio_addr: ', reqs.rows[req].payer_fio_addr); - console.log('payee_fio_addr: ', reqs.rows[req].payee_fio_addr); - console.log('fioreqstss:') - console.log('status (0 = not found): ', currentReqStatus); - console.log('fiotrxts:') - console.log('id: ', newRequests.rows[newRequest].id); - console.log('fio_request_id: ', newRequests.rows[newRequest].fio_request_id); - console.log('payer_fio_addr: ', newRequests.rows[newRequest].payer_fio_addr); - console.log('payee_fio_addr: ', newRequests.rows[newRequest].payee_fio_addr); - console.log('fio_data_type: ', newRequests.rows[newRequest].fio_data_type); + //console.log(count); + //console.log('fioreqctxts:') + //console.log('fio_request_id: ', reqs.rows[req].fio_request_id); + //console.log('payer_fio_addr: ', reqs.rows[req].payer_fio_addr); + //console.log('payee_fio_addr: ', reqs.rows[req].payee_fio_addr); + //console.log('fioreqstss:') + //console.log('status (0 = not found): ', currentReqStatus); + //console.log('fiotrxts:') + //console.log('id: ', newRequests.rows[newRequest].id); + //console.log('fio_request_id: ', newRequests.rows[newRequest].fio_request_id); + //console.log('payer_fio_addr: ', newRequests.rows[newRequest].payer_fio_addr); + //console.log('payee_fio_addr: ', newRequests.rows[newRequest].payee_fio_addr); + //console.log('fio_data_type: ', newRequests.rows[newRequest].fio_data_type); expect(reqs.rows[req].payer_fio_addr).to.equal(newRequests.rows[newRequest].payer_fio_addr); expect(reqs.rows[req].payee_fio_addr).to.equal(newRequests.rows[newRequest].payee_fio_addr); diff --git a/tests/fio-request.js b/tests/fio-request.js index a03250ca..8ddd689a 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -159,16 +159,16 @@ describe(`************************** fio-request.js ************************** \ await timeout(7000); }) - it(`get_sent_fio_requests for userA1`, async () => { + it.skip(`BUG (bahamas): BD-2306 get_sent_fio_requests for userA1`, async () => { try { const result = await userA1.sdk.genericAction('getSentFioRequests', { limit: '', offset: '' }) console.log('result: ', result) - //console.log('content: ', result.requests[0].content) - //expect(result.requests[0].content.memo).to.equal(requestMemo) - //expect(result.requests[0].status).to.equal('sent_to_blockchain') + console.log('content: ', result.requests[0].content) + expect(result.requests[0].content.memo).to.equal(requestMemo) + expect(result.requests[0].status).to.equal('sent_to_blockchain') } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) diff --git a/tests/record-obt-data.js b/tests/record-obt-data.js index 2282cc5a..46380561 100644 --- a/tests/record-obt-data.js +++ b/tests/record-obt-data.js @@ -8,7 +8,7 @@ before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); }) -describe(`*********************** record-obt-data.js *********************** \n`, () => { +describe(`*********************** record-obt-data.js *********************** \n Test OBT DAta`, () => { let userA1, userA2, userA2Balance const payment = 5000000000 // 5 FIO @@ -269,7 +269,7 @@ describe(`*********************** record-obt-data.js *********************** \n` }) }) -describe(`******************** Error Check ******************** \n`, () => { +describe(`OBT Data Error Check`, () => { let userA1, userA2, userA3 const payment = 5000000000 // 5 FIO @@ -384,7 +384,7 @@ describe(`******************** Error Check ******************** \n`, () => { }) }) -describe.skip(`********************** record-obt-data.js ********************** \n Records Performance Testing`, () => { +describe.skip(`OBT Performance Testing`, () => { let userA1, userA2, userB1, userB2, userC1, userC2 const payment = 5000000000 // 5 FIO diff --git a/tests/transfer-locked-tokens-account-tests.js b/tests/transfer-locked-tokens-account-tests.js index d5ddddf9..22dc994a 100644 --- a/tests/transfer-locked-tokens-account-tests.js +++ b/tests/transfer-locked-tokens-account-tests.js @@ -4,6 +4,7 @@ const {FIOSDK } = require('@fioprotocol/fiosdk') const {fetchJson, timeout, generateFioDomain, generateFioAddress, createKeypair, getTotalVotedFio, getAccountVoteWeight, getProdVoteTotal, callFioApi} = require('../utils.js'); config = require('../config.js'); +let transfer_tokens_pub_key_fee let privateKey, publicKey, privateKey2, publicKey2, account, account2, testFioDomain, testFioAddressName, testFioAddressName2 let fioSdk, fioSdk2, fioSdkFaucet @@ -34,6 +35,16 @@ before(async () => { publicKey2 = keys2.publicKey account2 = keys2.account fioSdk2 = new FIOSDK(privateKey2, publicKey2, config.BASE_URL, fetchJson); + + it('Get transfer_tokens_pub_key fee', async () => { + try { + result = await user1.sdk.getFee('transfer_tokens_pub_key', user1.address); + transfer_tokens_pub_key_fee = result.fee; + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) }) describe(`************************** transfer-locked-tokens-account-tests.js ************************** \n A. Create accounts for tests`, () => { @@ -863,7 +874,22 @@ describe('Request funds, approve and send', () => { } }) - it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`get_sent_fio_requests for fioSdk2`, async () => { + try { + const result = await fioSdk2.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result.requests[0].fio_request_id).to.equal(requestId) + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(5000) }) it(`getPendingFioRequests`, async () => { await timeout(4000) @@ -901,14 +927,19 @@ describe('Request funds, approve and send', () => { expect(result.fee_collected).to.be.a('number') }) - it(`Wait a few seconds.`, async () => { await timeout(4000) }) + it(`Wait a few seconds.`, async () => { await timeout(8000) }) - it(`getSentFioRequests`, async () => { - const result = await fioSdk2.genericAction('getSentFioRequests', {}) + it.skip(`BUG (bahamas): BD-2306 getSentFioRequests for fioSdk2`, async () => { + const result = await fioSdk2.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + console.log('Result: ', result) expect(result).to.have.all.keys('requests', 'more') expect(result.requests).to.be.a('array') expect(result.more).to.be.a('number') const pendingReq = result.requests.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) + console.log('pendingReq: ', pendingReq) expect(pendingReq).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'status', 'time_stamp', 'content') expect(pendingReq.fio_request_id).to.be.a('number') expect(pendingReq.fio_request_id).to.equal(requestId) @@ -1163,12 +1194,16 @@ describe('Record obt data, check', () => { expect(obtData.payee_fio_address).to.equal(testFioAddressName2) }) - it(`Payee getObtData`, async () => { + it.skip(`BUG BD-2305 (not all results getting returned) Payee getObtData`, async () => { const result = await fioSdk2.genericAction('getObtData', { tokenCode: fioTokenCode }) + console.log('result: ', result) expect(result).to.have.all.keys('obt_data_records', 'more') expect(result.obt_data_records).to.be.a('array') expect(result.more).to.be.a('number') const obtData = result.obt_data_records.find(pr => pr.content.obt_id === obtId) + console.log('obt_data_records[0]: ', result.obt_data_records[0]) + console.log('obtId: ', obtId) + console.log('obtData: ', obtData) expect(obtData).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'status', 'time_stamp', 'content') expect(obtData.content.obt_id).to.be.a('string') expect(obtData.content.obt_id).to.equal(obtId) @@ -1223,11 +1258,13 @@ describe(`Test locked token accounts with proxy voting`, () => { //console.log('Result: ', result) expect(result.status).to.equal('OK') } catch (err) { - console.log('Error: ', err.json) + console.log('Error: ', err.json.error.details) expect(err).to.equal('null') } }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) + it(`Get total_voted_fio before fioSdk votes`, async () => { total_voted_fio = await getTotalVotedFio(); //console.log('total_voted_fio:', total_voted_fio) @@ -1255,6 +1292,8 @@ describe(`Test locked token accounts with proxy voting`, () => { } }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) + it(`Get fioSdk last_vote_weight`, async () => { try { fioSdk.last_vote_weight = await getAccountVoteWeight(account); @@ -1311,7 +1350,7 @@ describe(`Test locked token accounts with proxy voting`, () => { expect(result.status).to.equal('OK') }) - it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Wait a few seconds.`, async () => { await timeout(7000) }) it(`Get fioSdk last_vote_weight (should be 500 more)`, async () => { try { @@ -1358,7 +1397,7 @@ describe(`Test locked token accounts with proxy voting`, () => { expect(result.status).to.equal('OK') }) - it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Wait a few seconds.`, async () => { await timeout(7000) }) it(`Get fioSdk last_vote_weight (should be 200 + 2 fee = 202 less)`, async () => { try { @@ -1370,24 +1409,24 @@ describe(`Test locked token accounts with proxy voting`, () => { } }) - it(`total_voted_fio decreased by 202 FIO`, async () => { + it(`total_voted_fio decreased by 200 - transfer_tokens_pub_key_fee`, async () => { try { let prev_total_voted_fio = total_voted_fio total_voted_fio = await getTotalVotedFio(); //console.log('total_voted_fio: ', total_voted_fio) - expect(total_voted_fio).to.equal(prev_total_voted_fio - 200000000000 - config.api.transfer_tokens_pub_key.fee) + expect(total_voted_fio).to.equal(prev_total_voted_fio - 200000000000 - transfer_tokens_pub_key_fee) } catch (err) { console.log('Error', err) expect(err).to.equal('null') } }) - it(`bp1@dapixdev total_votes increased by 500 FIO`, async () => { + it(`bp1@dapixdev total_votes descreased by 200 - transfer_tokens_pub_key_fee`, async () => { try { let prev_total_bp_votes = total_bp_votes; total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); //console.log('bp1@dapixdev total_votes:', total_bp_votes) - expect(total_bp_votes).to.equal(prev_total_bp_votes - 200000000000 - config.api.transfer_tokens_pub_key.fee) + expect(total_bp_votes).to.equal(prev_total_bp_votes - 200000000000 - transfer_tokens_pub_key_fee) } catch (err) { console.log('Error: ', err) expect(err).to.equal('null') diff --git a/tests/vote.js b/tests/vote.js index d30d30dc..78ef8cd9 100644 --- a/tests/vote.js +++ b/tests/vote.js @@ -3438,7 +3438,7 @@ describe(`Test total_voted_fio when user votes for proxy`, () => { } }) - it(`Wait a few seconds.`, async () => { await timeout(5000) }) + it(`Wait a few seconds.`, async () => { await timeout(6000) }) it(`bp1@dapixdev total_votes increased by faucet last_vote_weight`, async () => { try { From 7cd9c296807db2b39ae723694b0cd07abda8d3e4 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Sat, 16 Jan 2021 17:52:22 -0700 Subject: [PATCH 39/76] Many cleanup fixes for bahamas --- config.js | 2 +- index.js | 19 +- package.json | 2 +- tests/{ => Archive}/expired-domains.js | 4 +- tests/{ => Archive}/locks.js | 6 +- tests/{ => Archive}/pub_k1.js | 4 +- tests/action-whitelisting.js | 2 +- tests/addaddress.js | 24 +-- tests/addbundles.js | 161 ++++++++------- tests/bravo-migr-test.js | 18 +- tests/burn-address.js | 4 +- tests/clio.js | 14 +- tests/fee-voting-post-contract-set.js | 2 +- tests/fees.js | 2 +- tests/fio-request.js | 4 +- tests/paging.js | 2 +- tests/producer.js | 2 +- tests/pushtransaction.js | 2 +- tests/ram2.js | 2 +- tests/record-obt-data.js | 6 +- ...r_fio_domain.js => register-fio-domain.js} | 4 +- tests/{removeaddress.js => remove-address.js} | 2 +- tests/testnet-smoketest.js | 70 ++++--- tests/transfer-address.js | 2 +- tests/transfer-domain.js | 2 +- tests/transfer-locked-tokens-account-tests.js | 185 +++++++++--------- tests/transfer-locked-tokens.js | 65 ++++-- tests/transfer-tokens.js | 2 +- tests/txn-resubmit.js | 2 +- tests/vote.js | 13 +- utils.js | 39 ++-- 31 files changed, 368 insertions(+), 300 deletions(-) rename tests/{ => Archive}/expired-domains.js (94%) rename tests/{ => Archive}/locks.js (93%) rename tests/{ => Archive}/pub_k1.js (96%) rename tests/{register_fio_domain.js => register-fio-domain.js} (98%) rename tests/{removeaddress.js => remove-address.js} (99%) diff --git a/config.js b/config.js index 3aaf3d76..8da3dbe2 100644 --- a/config.js +++ b/config.js @@ -12,7 +12,7 @@ const config = { URL: TESTURL, BASE_URL: TESTURL + '/v1/', CLIO: DEVTOOLSDIR + '/bin/clio -u ' + TESTURL, - WALLETKEY: 'PW5JqTyLtZXzmDhVjP6jKK2yJ4tbXA4Gi9zaTepYF9b73U1DZhzmv', // Unlocks local FIO wallet + WALLETKEYFILE: DEVTOOLSDIR + '/walletkey.ini', //use this prod key file after you get a copy of the file from Ed, then you can run the //fee-voting-fee-setting.js. diff --git a/index.js b/index.js index 2d1cc1b8..c5ea9640 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ const {expect} = require('chai') describe('TEST SUITE', () => { - require('./tests/bravo-migr-test.js'); //This is required when launching with 2.3.0 (bravo) to do the full table migration. + require('./tests/bravo-migr-test.js'); //This is required when testing 2.3.0 (bravo) with fio bahamas (need to do the full table migration). //require('./tests/history.js'); // Only run against history node. require('./tests/addaddress.js'); // v1.0.x Also includes FIP-13 tests. @@ -12,13 +12,13 @@ describe('TEST SUITE', () => { require('./tests/producer.js'); // v1.0.x require('./tests/pushtransaction.js'); // v1.0.x require('./tests/ram2.js'); // v1.0.x //Eric to update to remove clio - require('./tests/register_fio_domain.js'); // v1.0.x + require('./tests/register-fio-domain.js'); // v1.0.x require('./tests/transfer-tokens.js'); // v1.0.x require('./tests/vote.js'); // v1.0.x require('./tests/action-whitelisting.js'); // FIP-12, fio v2.0.0, fio.contracts v2.0.0 // Causes future tests to fail. Only run alone. require('./tests/transfer-domain.js'); // FIP-1.a, fio v2.0.0, fio.contracts v2.1.0 require('./tests/paging.js'); // FIP-2, fio v2.0.0, fio.contracts v2.1.0 - require('./tests/removeaddress.js'); // FIP-4, fio v2.0.0, fio.contracts v2.1.0 + require('./tests/remove-address.js'); // FIP-4, fio v2.0.0, fio.contracts v2.1.0 require('./tests/txn-resubmit.js'); //Available with fiosdk_typescript v1.2.0 require('./tests/burn-address.js'); // FIP-7 //require('./tests/fee-voting-fee-setting.js'); // FIP-10 @@ -27,15 +27,10 @@ describe('TEST SUITE', () => { require('./tests/transfer-address.js'); // FIP-1.b require('./tests/transfer-locked-tokens.js'); // FIP-6 locking tests require('./tests/transfer-locked-tokens-account-tests.js'); // FIP-6 tests of generic account functionality - require('./tests/addbundles.js'); + require('./tests/addbundles.js'); // FIP-11.a require('./tests/tpid.js'); - //require('./tests/clio.js'); // FIP-16 + require('./tests/clio.js'); // FIP-16 - //require('./tests/locks.js'); // Depends on local wallet. Need to fix - //require('./tests/testnet-smoketest.js'); // In development - //require('./tests/pub_k1.js'); // Moved to later release - //require('./tests/expired-domains.js'); // In development - - //TODO - Need to update: require('./tests/permissions.js'); - //TODO - Need to update: require('./tests/max-txn-size.js'); + require('./tests/testnet-smoketest.js'); // Testnet smoketest. By default runs against local build. + }); diff --git a/package.json b/package.json index 74ffa01c..4e7c0f1a 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "typescript": "^3.8.2" }, "scripts": { - "test": "mocha -t 5000000 index.js", + "test": "node node_modules/mocha/bin/_mocha -t 5000000 index.js", "testnet": "mocha -t 5000000 tests/testnet-smoketest.js" } } diff --git a/tests/expired-domains.js b/tests/Archive/expired-domains.js similarity index 94% rename from tests/expired-domains.js rename to tests/Archive/expired-domains.js index 1deb9c09..402bcff0 100644 --- a/tests/expired-domains.js +++ b/tests/Archive/expired-domains.js @@ -1,8 +1,8 @@ require('mocha') const {expect} = require('chai') -const {newUser, generateFioAddress, generateFioDomain, fetchJson} = require('../utils.js'); +const {newUser, generateFioAddress, generateFioDomain, fetchJson} = require('../../utils.js'); const {FIOSDK } = require('@fioprotocol/fiosdk') -config = require('../config.js'); +config = require('../../config.js'); before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson) diff --git a/tests/locks.js b/tests/Archive/locks.js similarity index 93% rename from tests/locks.js rename to tests/Archive/locks.js index 1f999012..71429b97 100644 --- a/tests/locks.js +++ b/tests/Archive/locks.js @@ -1,8 +1,8 @@ require('mocha') const {expect} = require('chai') -const {newUser, unlockWallet, generateFioDomain, addLock, timeout, fetchJson} = require('../utils.js'); +const {newUser, unlockWallet, generateFioDomain, addLock, timeout, fetchJson} = require('../../utils.js'); const {FIOSDK } = require('@fioprotocol/fiosdk') -config = require('../config.js'); +config = require('../../config.js'); let total_voted_fio @@ -22,7 +22,7 @@ describe(`************************** locks.js ************************** \n A. T userA1.domain3 = generateFioDomain(10); }) - it.skip(`Unlock fio wallet with wallet key: ${config.WALLETKEY}`, async () => { + it.skip(`Unlock fio wallet`, async () => { unlockWallet('fio'); }) diff --git a/tests/pub_k1.js b/tests/Archive/pub_k1.js similarity index 96% rename from tests/pub_k1.js rename to tests/Archive/pub_k1.js index ff209abd..b1ea5f98 100644 --- a/tests/pub_k1.js +++ b/tests/Archive/pub_k1.js @@ -1,8 +1,8 @@ require('mocha') const {expect} = require('chai') -const {newUser, generateFioAddress, generateFioDomain, convertToK1, fetchJson} = require('../utils.js'); +const {newUser, generateFioAddress, generateFioDomain, convertToK1, fetchJson} = require('../../utils.js'); const {FIOSDK } = require('@fioprotocol/fiosdk') -config = require('../config.js'); +config = require('../../config.js'); before(async () => { diff --git a/tests/action-whitelisting.js b/tests/action-whitelisting.js index 598ed610..437ea115 100644 --- a/tests/action-whitelisting.js +++ b/tests/action-whitelisting.js @@ -24,7 +24,7 @@ before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); }) -describe(`************************** action-whitelisting.js ************************** \n A. Remove action, add action, action testing `, () => { +describe(`************************** action-whitelisting.js ************************** \n A. Remove action, add action, action testing `, () => { let userA1, userA2 const fundsAmount = 1000000000 diff --git a/tests/addaddress.js b/tests/addaddress.js index 7ec2084a..a31d9ea7 100644 --- a/tests/addaddress.js +++ b/tests/addaddress.js @@ -8,7 +8,7 @@ before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); }) -describe(`************************** addaddress.js ************************** \n A. Add 2 addresses, then add 3 addresses including the original 2`, () => { +describe(`************************** addaddress.js ************************** \n A. Add 2 addresses, then add 3 addresses including the original 2`, () => { let userA1 @@ -254,7 +254,7 @@ describe(`C. FIP-13. Get_pub_addresses endpoint`, () => { } }) - it('Get all public addresses for userA3 FIO Address (get_pub_addresses)', async () => { + it('(api) Get all public addresses for userA3 FIO Address (get_pub_addresses)', async () => { try { const result = await callFioApi("get_pub_addresses", { fio_address: userA3.address, @@ -281,7 +281,7 @@ describe(`C. FIP-13. Get_pub_addresses endpoint`, () => { //***** SAD TESTS *****// - it('Call get_pub_addresses with invalid FIO Address. Expect error type 400: Invalid FIO Address format', async () => { + it('(api) Call get_pub_addresses with invalid FIO Address. Expect error type 400: Invalid FIO Address format', async () => { try { const result = await callFioApi("get_pub_addresses", { fio_address: "intentionallybadformat@@@@@******", @@ -298,7 +298,7 @@ describe(`C. FIP-13. Get_pub_addresses endpoint`, () => { }) - it('Call get_pub_addresses with unregistered FIO Address. Expect error type 404: FIO Address does not exist', async () => { + it('(api) Call get_pub_addresses with unregistered FIO Address. Expect error type 404: FIO Address does not exist', async () => { try { const result = await callFioApi("get_pub_addresses", { fio_address: "eric@likesbeans", @@ -314,7 +314,7 @@ describe(`C. FIP-13. Get_pub_addresses endpoint`, () => { } }) - it('Call get_pub_addresses with invalid limit parameter of -1. Expect error type 400: Invalid limit', async () => { + it('(api) Call get_pub_addresses with invalid limit parameter of -1. Expect error type 400: Invalid limit', async () => { try { const result = await callFioApi("get_pub_addresses", { fio_address: userA3.address, @@ -330,7 +330,7 @@ describe(`C. FIP-13. Get_pub_addresses endpoint`, () => { } }) - it('Call get_pub_addresses with invalid offset parameter of -1. Expect error type 400: Invalid offset', async () => { + it('(api) Call get_pub_addresses with invalid offset parameter of -1. Expect error type 400: Invalid offset', async () => { try { const result = await callFioApi("get_pub_addresses", { fio_address: userA3.address, @@ -361,7 +361,7 @@ describe(`C. FIP-13. Get_pub_addresses endpoint`, () => { } }) - it('Get all public addresses for userA3 FIO Address (get_pub_addresses). Expect only FIO address to be returned.', async () => { + it('(api) Get all public addresses for userA3 FIO Address (get_pub_addresses). Expect only FIO address to be returned.', async () => { try { const result = await callFioApi("get_pub_addresses", { fio_address: userA3.address, @@ -401,7 +401,7 @@ describe(`C. FIP-13. Get_pub_addresses endpoint`, () => { } }) - it('Get all public addresses for userA3 FIO Address (get_pub_addresses). Expect error type 404: Public Addresses not found', async () => { + it('(api) Get all public addresses for userA3 FIO Address (get_pub_addresses). Expect error type 404: Public Addresses not found', async () => { try { const result = await callFioApi("get_pub_addresses", { fio_address: userA3.address, @@ -431,7 +431,7 @@ describe(`FIP18. Chain-level addressing`, () => { userB1 = await newUser(faucet); }) - it(`add_pub_address with chain_code ETH, token_code ETH, and public_address addressA`, async () => { + it(`(sdk) add_pub_address with chain_code ETH, token_code ETH, and public_address addressA`, async () => { const result = await userB1.sdk.genericAction('addPublicAddresses', { fioAddress: userB1.address, publicAddresses: [ @@ -448,7 +448,7 @@ describe(`FIP18. Chain-level addressing`, () => { expect(result.status).to.equal('OK') }) - it(`add_pub_address with chain_code ETH, token_code *, and public_address addressB`, async () => { + it(`(sdk) add_pub_address with chain_code ETH, token_code *, and public_address addressB`, async () => { const result = await userB1.sdk.genericAction('addPublicAddresses', { fioAddress: userB1.address, publicAddresses: [ @@ -465,7 +465,7 @@ describe(`FIP18. Chain-level addressing`, () => { expect(result.status).to.equal('OK') }) - it(`add_pub_address with chain_code ETH,, token_code *, and public_address addressC`, async () => { + it(`(sdk) add_pub_address with chain_code ETH,, token_code *, and public_address addressC`, async () => { const result = await userB1.sdk.genericAction('addPublicAddresses', { fioAddress: userB1.address, publicAddresses: [ @@ -524,7 +524,7 @@ describe(`FIP18. Chain-level addressing`, () => { } }) - it(`remove_pub_address with with chain_code ETH, token_code *, and public_address addressC`, async () => { + it(`(sdk) remove_pub_address with with chain_code ETH, token_code *, and public_address addressC`, async () => { try { const result = await userB1.sdk.genericAction('removePublicAddresses', { fioAddress: userB1.address, diff --git a/tests/addbundles.js b/tests/addbundles.js index 666885cf..9780e36b 100644 --- a/tests/addbundles.js +++ b/tests/addbundles.js @@ -1,14 +1,15 @@ require('mocha') const {expect} = require('chai') -const {newUser, fetchJson, timeout, callFioApi} = require('../utils.js'); +const {newUser, fetchJson, timeout, getTestType, callFioApi} = require('../utils.js'); const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); +const testType = getTestType(); before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); }) -describe('************************** addbundles.js ************************** \n A. Add 1 set of bundled transactions for FIO Address owned by signer.', () => { +describe('************************** addbundles.js ************************** \n A. Add 1 set of bundled transactions for FIO Address owned by signer.', () => { let user1, user1OrigBalance, user1OrigRam, add_bundled_transactions_fee, feeCollected let bundledVoteNumber = config.defaultBundleCount; @@ -103,40 +104,41 @@ describe('************************** addbundles.js ************************** \n } }) - it.skip(`(SDK) Run /add_bundled_transactions with 1 set for FIO Address owned by signer`, async () => { - try { - const result = await user1.sdk.genericAction('addBundledTransactions', { - fioAddress: user1.address, - bundleSets: 1, - maxFee: add_bundled_transactions_fee, - tpid: '' - }) - //console.log('Result:', result) - expect(result.status).to.equal('OK') - } catch (err) { - console.log('Error', err) - //expect(err).to.equal(null) - } - }) - - it(`(push_transaction) Run addbundles with ${bundleSets} sets for FIO Address owned by other user`, async () => { - try { - const result = await user1.sdk.genericAction('pushTransaction', { - action: 'addbundles', - account: 'fio.address', - data: { - fio_address: user1.address, - bundle_sets: bundleSets, - max_fee: add_bundled_transactions_fee * bundleSets, - tpid: '' - } - }) - feeCollected = result.fee_collected; - //console.log('Result: ', result); - expect(result.status).to.equal('OK'); - } catch (err) { - console.log('Error: ', err); - expect(err).to.equal(null); + it(`(${testType}) BUG BD-2308 (when called with API) Add bundles with ${bundleSets} sets for FIO Address owned by other user`, async () => { + if (testType == 'sdk') { + try { + const result = await user1.sdk.genericAction('addBundledTransactions', { + fioAddress: user1.address, + bundleSets: 1, + maxFee: add_bundled_transactions_fee * bundleSets, + technologyProviderId: '' + }) + feeCollected = result.fee_collected; + //console.log('Result:', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error', err.json.fields) + expect(err).to.equal(null) + } + } else { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'addbundles', + account: 'fio.address', + data: { + fio_address: user1.address, + bundle_sets: bundleSets, + max_fee: add_bundled_transactions_fee * bundleSets, + technologyProviderId: '' + } + }) + feeCollected = result.fee_collected; + //console.log('Result: ', result); + expect(result.status).to.equal('OK'); + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } } }) @@ -333,40 +335,41 @@ describe('B. Add 3 sets of bundled transactions for FIO Address owned by other u } }) - it.skip(`(SDK) Run /add_bundled_transactions with 1 set for FIO Address owned by other user`, async () => { - try { - const result = await user1.sdk.genericAction('addBundledTransactions', { - fioAddress: user1.address, - bundleSets: bundleSets, - maxFee: add_bundled_transactions_fee, - technologyProviderId: '' - }) - //console.log('Result:', result) - expect(result.status).to.equal('OK') - } catch (err) { - console.log('Error', err) - //expect(err).to.equal(null) - } - }) - - it(`(push_transaction) user1 run addbundles with ${bundleSets} sets for FIO Address owned by user2`, async () => { - try { - const result = await user1.sdk.genericAction('pushTransaction', { - action: 'addbundles', - account: 'fio.address', - data: { - fio_address: user2.address, - bundle_sets: bundleSets, - max_fee: add_bundled_transactions_fee * bundleSets, - technologyProviderId: '' - } - }) - feeCollected = result.fee_collected; - //console.log('Result: ', result); - expect(result.status).to.equal('OK'); - } catch (err) { - console.log('Error: ', err); - expect(err).to.equal(null); + it(`(${testType}) BUG BD-2308 (when called with API) user1 run addbundles with ${bundleSets} sets for FIO Address owned by user2`, async () => { + if (testType == 'sdk') { + try { + const result = await user1.sdk.genericAction('addBundledTransactions', { + fioAddress: user2.address, + bundleSets: bundleSets, + maxFee: add_bundled_transactions_fee * bundleSets, + technologyProviderId: '' + }) + feeCollected = result.fee_collected; + //console.log('Result:', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + } else { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'addbundles', + account: 'fio.address', + data: { + fio_address: user2.address, + bundle_sets: bundleSets, + max_fee: add_bundled_transactions_fee * bundleSets, + technologyProviderId: '' + } + }) + feeCollected = result.fee_collected; + //console.log('Result: ', result); + expect(result.status).to.equal('OK'); + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } } }) @@ -487,7 +490,7 @@ describe('C. Error testing', () => { } }) - it(`Run addbundles with invalid FIO Address format. Expect error type ${config.error2.invalidFioAddress.statusCode}: ${config.error2.invalidFioAddress.message}`, async () => { + it(`(pushtransaction) Run addbundles with invalid FIO Address format. Expect error type ${config.error2.invalidFioAddress.statusCode}: ${config.error2.invalidFioAddress.message}`, async () => { try { const result = await user1.sdk.genericAction('pushTransaction', { action: 'addbundles', @@ -508,6 +511,22 @@ describe('C. Error testing', () => { } }) + it(`(sdk) Run addbundles with invalid FIO Address format. SDK rejects with no type and error: ${config.error.fioAddressInvalidChar}`, async () => { + try { + const result = await user1.sdk.genericAction('addBundledTransactions', { + fioAddress: '[#invalid@address', + bundleSets: bundleSets, + maxFee: add_bundled_transactions_fee, + technologyProviderId: '' + }) + console.log('Result: ', result); + expect(result.status).to.equal(null); + } catch (err) { + //console.log('Error: ', err); + expect(err.list[0].message).to.equal(config.error.fioAddressInvalidChar) + } + }) + it(`Run addbundles with non-existent FIO Address. Expect error type ${config.error2.fioAddressNotRegistered.statusCode}: ${config.error2.fioAddressNotRegistered.message}`, async () => { try { const result = await user1.sdk.genericAction('pushTransaction', { diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index f8d9e3fc..83e6dd0d 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -42,7 +42,7 @@ before(async () => { }) -describe(`************************** bravo-migr-test.js.js ************************** \n Load Requests and OBTs`, () => { +describe(`************************** bravo-migr-test.js.js ************************** \n A. Load Requests and OBTs`, () => { let user1, user2, user3; let payment = 3000000000; let requestMemo = 'asdf'; @@ -239,7 +239,7 @@ describe(`************************** bravo-migr-test.js.js ********************* }) }) -describe(`Perform single migrtrx to initialize migration`, () => { +describe(`B. Perform single migrtrx to initialize migration`, () => { it(`Call single migrtrx (bp1) and confirm you can still do Requests and OBTs`, async () => { try { const result = await callFioApiSigned('push_transaction', { @@ -280,7 +280,7 @@ describe(`Perform single migrtrx to initialize migration`, () => { }) }) -describe(`Initial OBT record. Confirm new OBT Sends are going into both tables`, () => { +describe(`C. Initial OBT record. Confirm new OBT Sends are going into both tables`, () => { let user1, user2, user3 let payment = 3000000000; @@ -376,7 +376,7 @@ describe(`Initial OBT record. Confirm new OBT Sends are going into both tables`, }) -describe(`Initial FIO Request record. Confirm NEW Requests are going into both tables`, () => { +describe(`E. Initial FIO Request record. Confirm NEW Requests are going into both tables`, () => { let user1, user2, user3, requestId, obtId let payment = 3000000000; let requestMemo = 'asdf'; @@ -470,7 +470,7 @@ describe(`Initial FIO Request record. Confirm NEW Requests are going into both t }) -describe.skip(`Confirm REJECTED Requests are going into both tables`, () => { +describe.skip(`F. Confirm REJECTED Requests are going into both tables`, () => { let user1, user2, user3, requestId let payment = 3000000000; let requestMemo = 'asdf'; @@ -582,7 +582,7 @@ describe.skip(`Confirm REJECTED Requests are going into both tables`, () => { }) -describe.skip(`Confirm paid OBT response Requests are going into both tables`, () => { +describe.skip(`G. Confirm paid OBT response Requests are going into both tables`, () => { let user1, user2, user3, requestId let payment = 3000000000; let requestMemo = 'asdf'; @@ -729,7 +729,7 @@ describe.skip(`Confirm paid OBT response Requests are going into both tables`, ( }) -describe(`Migrate remaining requests and OBTs`, () => { +describe(`H. Migrate remaining requests and OBTs`, () => { let isFinished = 0 it('Echo initial migrledgers table', async () => { @@ -812,7 +812,7 @@ describe(`Migrate remaining requests and OBTs`, () => { }) -describe(`Go through recordobts (old table) and confirm each entry is in fiotrxts (NEW table)`, () => { +describe.skip(`I. Go through recordobts (old table) and confirm each entry is in fiotrxts (NEW table)`, () => { let obtCount = 0 let obtRecords; @@ -884,7 +884,7 @@ describe(`Go through recordobts (old table) and confirm each entry is in fiotrxt }) -describe(`Go through fioreqctxts (old table) and confirm each entry is in fiotrxts (NEW table)`, () => { +describe.skip(`J. Go through fioreqctxts (old table) and confirm each entry is in fiotrxts (NEW table)`, () => { let reqCount = 0 let reqs; diff --git a/tests/burn-address.js b/tests/burn-address.js index 8ed5c9a2..f88e59eb 100644 --- a/tests/burn-address.js +++ b/tests/burn-address.js @@ -8,7 +8,7 @@ before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson) }) -describe('************************** burn-address.js ************************** \n A. Test Burn FIO Address using push_transaction with burnaddress action ', () => { +describe('************************** burn-address.js ************************** \n A. Test Burn FIO Address using push_transaction with burnaddress action ', () => { let walletA1, walletA1FioNames, balance, walletA1OrigBalance, burn_fio_address_fee, feeCollected @@ -561,7 +561,7 @@ describe('D. burnFioAddress Error testing', () => { }) -describe.skip('E. Test burnfioaddress SDK call (uses chain/burn_fio_address endpoint)', () => { +describe('E. Test burnfioaddress SDK call (uses chain/burn_fio_address endpoint)', () => { let walletA1, walletA1FioNames diff --git a/tests/clio.js b/tests/clio.js index 0feaad92..bd5fe7aa 100644 --- a/tests/clio.js +++ b/tests/clio.js @@ -36,7 +36,7 @@ before(async () => { result = await unlockWallet('fio'); }) -describe(`************************** clio.js ************************** \n A. Test clio`, () => { +describe(`************************** clio.js ************************** \n A. Test clio`, () => { it(`get info`, async () => { result = await runClio('get info'); @@ -165,7 +165,7 @@ describe(`C. Domain`, () => { fioPublicKey: user1.publicKey }) user1Balance = result.balance - console.log('user1 fio balance', result.balance) + //console.log('user1 fio balance', result.balance) } catch (err) { //console.log('Error', err) expect(err).to.equal(null) @@ -291,7 +291,7 @@ describe(`D. Address`, () => { try { result = await user1.sdk.getFee('register_fio_address'); register_fio_address_fee = result.fee; - console.log('Domain Fee: ', register_fio_address_fee) + //console.log('Domain Fee: ', register_fio_address_fee) } catch (err) { console.log('Error', err); expect(err).to.equal(null); @@ -304,7 +304,7 @@ describe(`D. Address`, () => { fioPublicKey: user1.publicKey }) user1Balance = result.balance - console.log('user1 fio balance', result.balance) + //console.log('user1 fio balance', result.balance) } catch (err) { //console.log('Error', err) expect(err).to.equal(null) @@ -328,7 +328,7 @@ describe(`D. Address`, () => { fioPublicKey: user1.publicKey }) user1Balance = result.balance - console.log('user1 fio balance', result.balance) + //console.log('user1 fio balance', result.balance) expect(user1Balance).to.equal(prevBalance - register_fio_address_fee) } catch (err) { //console.log('Error', err) @@ -349,7 +349,7 @@ describe(`D. Address`, () => { it.skip(`(Future release) address transfer`, async () => { try { result = await runClio(`address transfer -j ${user1.account} ${user1.address} ${user2.publicKey} ${tpid} ${max_fee} --permission ${user1.account}@active`); - console.log('Result: ', JSON.parse(result)); + //console.log('Result: ', JSON.parse(result)); expect(JSON.parse(result).transaction_id).to.exist } catch (err) { console.log('Error', err) @@ -359,7 +359,7 @@ describe(`D. Address`, () => { it.skip(`(Future release) address add_pub. Add BCH address `, async () => { try { result = await runClio(`address add_pub -j ${user1.account} ${BCHAddress.clioAddress} ${user1.address} ${tpid} ${max_fee} --permission ${user1.account}@active`); - console.log('Result: ', JSON.parse(result)); + //console.log('Result: ', JSON.parse(result)); expect(JSON.parse(result).transaction_id).to.exist } catch (err) { console.log('Error', err) diff --git a/tests/fee-voting-post-contract-set.js b/tests/fee-voting-post-contract-set.js index 79b22f34..5fd4f474 100644 --- a/tests/fee-voting-post-contract-set.js +++ b/tests/fee-voting-post-contract-set.js @@ -37,7 +37,7 @@ before(async () => { // producersList = await readProdFile(config.PRODKEYFILE); }) -describe('************************** fee-voting-fee-setting.js ************************** \n A. Vote fees for top prods.', () => { +describe('************************** fee-voting-fee-setting.js ************************** \n A. Vote fees for top prods.', () => { let prodA1, userA1, result, locksdk let timeafteraccountcreate = 5000 diff --git a/tests/fees.js b/tests/fees.js index 00025f20..d9bfb77b 100644 --- a/tests/fees.js +++ b/tests/fees.js @@ -8,7 +8,7 @@ before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson) }) -describe('************************** fees.js ************************** \n Test Transaction Fees', () => { +describe('************************** fees.js ************************** \n Test Transaction Fees', () => { let userA1 it(`Create users`, async () => { diff --git a/tests/fio-request.js b/tests/fio-request.js index 36b4a21b..3644bfea 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -8,7 +8,7 @@ before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); }) -describe(`************************** fio-request.js ************************** \n A. Send fio request from userA1 to userA2`, () => { +describe(`************************** fio-request.js ************************** \n A. Send fio request from userA1 to userA2`, () => { let userA1, userA2, requestId const payment = 5000000000 // 5 FIO @@ -1825,7 +1825,7 @@ describe(`F. get_cancelled_fio_requests paging: Cancel multiple FIO requests and }) -describe(`G. BUG in migr/part3-final?? Test rejection of FIO Requests`, () => { +describe(`G. Test rejection of FIO Requests`, () => { let user1, user2, user1RequestId diff --git a/tests/paging.js b/tests/paging.js index 65633b30..446c5581 100644 --- a/tests/paging.js +++ b/tests/paging.js @@ -9,7 +9,7 @@ before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); }) -describe(`************************** paging.js ************************** \n A. get_fio_domains paging: Register multiple domains and page through using get_fio_domains`, () => { +describe(`************************** paging.js ************************** \n A. get_fio_domains paging: Register multiple domains and page through using get_fio_domains`, () => { let userA1, domainCount = 20 it('Create userA1', async () => { diff --git a/tests/producer.js b/tests/producer.js index 26c2dbfa..e38ab0e7 100644 --- a/tests/producer.js +++ b/tests/producer.js @@ -8,7 +8,7 @@ before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson) }) -describe('************************** producer.js ************************** \n A. Test register as a proxy.', () => { +describe('************************** producer.js ************************** \n A. Test register as a proxy.', () => { let prodA1, userA1, total_voted_fio, total_bp_votes diff --git a/tests/pushtransaction.js b/tests/pushtransaction.js index 76c4dacd..5e218f92 100644 --- a/tests/pushtransaction.js +++ b/tests/pushtransaction.js @@ -8,7 +8,7 @@ before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); }) -describe(`************************** pushtransaction.js ************************** \n A. Misc. pushtransaction tests`, () => { +describe(`************************** pushtransaction.js ************************** \n A. Misc. pushtransaction tests`, () => { let userA1 diff --git a/tests/ram2.js b/tests/ram2.js index 0764416f..3a1c9844 100644 --- a/tests/ram2.js +++ b/tests/ram2.js @@ -20,7 +20,7 @@ before(async () => { }) -describe('************************** ram2.js ************************** \n A. Test RAM Consumption', () => { +describe('************************** ram2.js ************************** \n A. Test RAM Consumption', () => { it(`Create ramuser public/private keys`, async () => { user1Domain = generateFioDomain(15) diff --git a/tests/record-obt-data.js b/tests/record-obt-data.js index 46380561..79ead9a0 100644 --- a/tests/record-obt-data.js +++ b/tests/record-obt-data.js @@ -8,7 +8,7 @@ before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); }) -describe(`*********************** record-obt-data.js *********************** \n Test OBT DAta`, () => { +describe(`*********************** record-obt-data.js *********************** \n A. Test OBT DAta`, () => { let userA1, userA2, userA2Balance const payment = 5000000000 // 5 FIO @@ -269,7 +269,7 @@ describe(`*********************** record-obt-data.js *********************** \n }) }) -describe(`OBT Data Error Check`, () => { +describe(`B. OBT Data Error Check`, () => { let userA1, userA2, userA3 const payment = 5000000000 // 5 FIO @@ -384,7 +384,7 @@ describe(`OBT Data Error Check`, () => { }) }) -describe.skip(`OBT Performance Testing`, () => { +describe.skip(`C. OBT Performance Testing`, () => { let userA1, userA2, userB1, userB2, userC1, userC2 const payment = 5000000000 // 5 FIO diff --git a/tests/register_fio_domain.js b/tests/register-fio-domain.js similarity index 98% rename from tests/register_fio_domain.js rename to tests/register-fio-domain.js index af08ec7c..8af3f6fc 100644 --- a/tests/register_fio_domain.js +++ b/tests/register-fio-domain.js @@ -9,7 +9,7 @@ before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); }) -describe(`************************** register_fio_domain.js ************************** \n A. Check valid and invalid domain and address formats`, () => { +describe(`************************** register-fio-domain.js ************************** \n A. Check valid and invalid domain and address formats`, () => { let userA1 const fiftyfiveChars = "0123456789012345678901234567890123456789012345678901234" domain0Bad = "" @@ -351,7 +351,7 @@ describe('E. Test set_fio_domain_public', () => { fioPublicKey: user1.publicKey }) user1Balance = result.balance - console.log('user1 fio balance', result.balance) + //console.log('user1 fio balance', result.balance) } catch (err) { //console.log('Error', err) expect(err).to.equal(null) diff --git a/tests/removeaddress.js b/tests/remove-address.js similarity index 99% rename from tests/removeaddress.js rename to tests/remove-address.js index b7a53cfd..40489166 100644 --- a/tests/removeaddress.js +++ b/tests/remove-address.js @@ -8,7 +8,7 @@ before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); }) -describe(`************************** removeaddress.js ************************** \n A. Remove public address, address parameter tests`, () => { +describe(`************************** remove-address.js ************************** \n A. Remove public address, address parameter tests`, () => { let userA1 it(`Create users`, async () => { diff --git a/tests/testnet-smoketest.js b/tests/testnet-smoketest.js index b702eaa7..50c22ed6 100644 --- a/tests/testnet-smoketest.js +++ b/tests/testnet-smoketest.js @@ -18,7 +18,7 @@ let privateKey, publicKey, testFioAddressName, privateKey2, publicKey2, testFioA /** * Set to target = 'local' if running against devtools build. Leave blank if running against Testnet. */ -const target = '' +const target = 'local' /** * Set your testnet existing private/public keys and existing fioAddresses (not needed if running locally) @@ -121,7 +121,7 @@ before(async () => { pubKeyForTransfer = 'FIO7isxEua78KPVbGzKemH4nj2bWE52gqj8Hkac3tc7jKNvpfWzYS' }) -describe('Testing generic actions', () => { +describe('************************** testnet-smoketest.js ************************** \n A. Testing generic actions', () => { it(`FIO Key Generation Testing`, async () => { const testMnemonic = 'valley alien library bread worry brother bundle hammer loyal barely dune brave' @@ -240,12 +240,12 @@ describe('Testing generic actions', () => { it(`getFioBalance`, async () => { const result = await fioSdk.sdk.genericAction('getFioBalance', {}) - expect(result).to.have.all.keys('balance') + expect(result).to.have.all.keys('balance', 'available') expect(result.balance).to.be.a('number') }) }) -describe('Testing domain actions', () => { +describe('B. Testing domain actions', () => { it(`Register fio domain`, async () => { const result = await fioSdk2.sdk.genericAction('registerFioDomain', { fioDomain: newFioDomain, maxFee: defaultFee }) @@ -392,25 +392,35 @@ describe('Testing domain actions', () => { expect(result.fee_collected).to.be.a('number') }) - it.skip(`Bahamas: getFee for addBundledTransactions`, async () => { - const result = await fioSdk2.sdk.genericAction('getFeeForAddBundledTransactions', { - fioAddress: newFioAddress - }) - - expect(result).to.have.all.keys('fee') - expect(result.fee).to.be.a('number') + it.skip(`BUG BD-2308 getFee for addBundledTransactions`, async () => { + try { + const result = await fioSdk2.sdk.genericAction('getFeeForAddBundledTransactions', { + fioAddress: newFioAddress + }) + console.log('Result: ', result) + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } }) - it.skip(`Bahamas: add Bundled Transactions`, async () => { - const result = await fioSdk2.sdk.genericAction('addBundledTransactions', { - fioAddress: newFioAddress, - bundleSets: defaultBundledSets, - maxFee: defaultFee - }) - - expect(result).to.have.all.keys('status', 'fee_collected') - expect(result.status).to.be.a('string') - expect(result.fee_collected).to.be.a('number') + it.skip(`BUG BD-2308 add Bundled Transactions`, async () => { + try { + const result = await fioSdk2.sdk.genericAction('addBundledTransactions', { + fioAddress: newFioAddress, + bundleSets: defaultBundledSets, + maxFee: defaultFee + }) + console.log('Result: ', result) + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + } catch (err) { + console.log('Error: ', err.json.fields) + expect(err).to.equal(null) + } }) it(`(push_transaction) user1 run addbundles with sets for FIO Address owned by user2`, async () => { @@ -600,7 +610,7 @@ describe('Testing domain actions', () => { fioPublicKey: publicKey2 }) - expect(result).to.have.all.keys('balance') + expect(result).to.have.all.keys('balance', 'available') expect(result.balance).to.be.a('number') }) @@ -650,7 +660,7 @@ describe('Testing domain actions', () => { expect(result.fee).to.be.a('number') }) - it.skip(`Bahamas - Burn fio address`, async () => { + it(`Burn fio address`, async () => { const result = await fioSdk2.sdk.genericAction('burnFioAddress', { fioAddress: newFioAddress, maxFee: defaultFee @@ -663,7 +673,7 @@ describe('Testing domain actions', () => { }) -describe('Request funds, approve and send', () => { +describe('C. Request funds, approve and send', () => { const fundsAmount = 3 let requestId const memo = 'testing fund request' @@ -783,7 +793,7 @@ describe('Request funds, approve and send', () => { }) -describe('Request funds, cancel funds request', () => { +describe('D. Request funds, cancel funds request', () => { const fundsAmount = 3 let requestId const memo = 'testing fund request' @@ -845,7 +855,7 @@ describe('Request funds, cancel funds request', () => { }) -describe('Request funds, reject', () => { +describe('E. Request funds, reject', () => { const fundsAmount = 4 let requestId const memo = 'testing fund request' @@ -908,7 +918,7 @@ describe('Request funds, reject', () => { }) -describe('Transfer tokens', () => { +describe('F. Transfer tokens', () => { const fundsAmount = FIOSDK.SUFUnit let fioBalance = 0 let fioBalanceAfter = 0 @@ -939,7 +949,7 @@ describe('Transfer tokens', () => { }) }) -describe('Record obt data, check', () => { +describe('G. Record obt data, check', () => { const obtId = generateObtId() const fundsAmount = 4.5 @@ -1003,7 +1013,7 @@ describe('Record obt data, check', () => { }) }) -describe('Encrypting/Decrypting', () => { +describe('H. Encrypting/Decrypting', () => { const alicePrivateKey = '5J35xdLtcPvDASxpyWhNrR2MfjSZ1xjViH5cvv15VVjqyNhiPfa' const alicePublicKey = 'FIO6NxZ7FLjjJuHGByJtNJQ1uN1P5X9JJnUmFW3q6Q7LE7YJD4GZs' const bobPrivateKey = '5J37cXw5xRJgE869B5LxC3FQ8ZJECiYnsjuontcHz5cJsz5jhb7' @@ -1175,7 +1185,7 @@ describe('Encrypting/Decrypting', () => { }) -describe.skip('Check prepared transaction', () => { +describe.skip('I. Check prepared transaction', () => { it(`requestFunds prepared transaction`, async () => { fioSdk2.setSignedTrxReturnOption(true) const preparedTrx = await fioSdk2.sdk.genericAction('requestFunds', { diff --git a/tests/transfer-address.js b/tests/transfer-address.js index 4ddabdae..94772a83 100644 --- a/tests/transfer-address.js +++ b/tests/transfer-address.js @@ -8,7 +8,7 @@ before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson) }) -describe('************************** transfer-address.js ************************** \n A. Transfer an address to FIO Public Key which maps to existing account on FIO Chain using new endpoint (not push action)', () => { +describe('************************** transfer-address.js ************************** \n A. Transfer an address to FIO Public Key which maps to existing account on FIO Chain using new endpoint (not push action)', () => { let walletA1, walletA1FioNames, walletA1OrigBalance, walletA1OrigRam, walletA2, walletA2FioNames, walletA2OrigRam, transfer_fio_address_fee, origAddressExpire, feeCollected diff --git a/tests/transfer-domain.js b/tests/transfer-domain.js index d8c0858b..92f53868 100644 --- a/tests/transfer-domain.js +++ b/tests/transfer-domain.js @@ -8,7 +8,7 @@ before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson) }) -describe('************************** transfer-domain.js ************************** \n A. Transfer a domain to FIO Public Key which maps to existing account on FIO Chain using new endpoint (not push action)', () => { +describe('************************** transfer-domain.js ************************** \n A. Transfer a domain to FIO Public Key which maps to existing account on FIO Chain using new endpoint (not push action)', () => { let walletA1, walletA1FioNames, walletA1OrigBalance, walletA1OrigRam, walletA2, walletA2FioNames, walletA2OrigRam, transfer_fio_domain_fee, origDomainExpire, feeCollected diff --git a/tests/transfer-locked-tokens-account-tests.js b/tests/transfer-locked-tokens-account-tests.js index 5c4e9b28..17a42878 100644 --- a/tests/transfer-locked-tokens-account-tests.js +++ b/tests/transfer-locked-tokens-account-tests.js @@ -1,8 +1,9 @@ require('mocha') const {expect} = require('chai') const {FIOSDK } = require('@fioprotocol/fiosdk') -const {fetchJson, timeout, generateFioDomain, generateFioAddress, createKeypair, getTotalVotedFio, getAccountVoteWeight, getProdVoteTotal, callFioApi} = require('../utils.js'); +const {fetchJson, timeout, generateFioDomain, generateFioAddress, createKeypair, getTestType, getTotalVotedFio, getAccountVoteWeight, getProdVoteTotal, callFioApi} = require('../utils.js'); config = require('../config.js'); +const testType = getTestType(); let transfer_tokens_pub_key_fee let privateKey, publicKey, privateKey2, publicKey2, account, account2, testFioDomain, testFioAddressName, testFioAddressName2 @@ -47,7 +48,7 @@ before(async () => { }) }) -describe(`************************** transfer-locked-tokens-account-tests.js ************************** \n A. Create accounts for tests`, () => { +describe(`************************** transfer-locked-tokens-account-tests.js ************************** \n A. Create accounts for tests`, () => { it.skip(`Show keys`, async () => { console.log('privateKey: ', privateKey) @@ -56,41 +57,12 @@ describe(`************************** transfer-locked-tokens-account-tests.js *** console.log('publicKey2: ', publicKey2) }) - it(`(API) Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { - try { - const result = await fioSdkFaucet.genericAction('transferLockedTokens', { - payeePublicKey: publicKey, - canVote: false, - periods: [ - { - duration: 3600, - percent: 40.0, - }, - { - duration: 3640, - percent: 60.0, - } - ], - amount: lockedFundsAmount, - maxFee: 400000000000, - tpid: '', - - }) - expect(result.status).to.equal('OK') - expect(result).to.have.all.keys( 'status', 'fee_collected') - } catch (err) { - console.log('Error', err) - } - }) - - it.skip(`(pushTransaction) Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { - try { - const result = await fioSdkFaucet.genericAction('pushTransaction', { - action: 'trnsloctoks', - account: 'fio.token', - data: { - payee_public_key: publicKey, - can_vote: 0, + it(`(${testType}) Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { + if (testType == 'sdk') { + try { + const result = await fioSdkFaucet.genericAction('transferLockedTokens', { + payeePublicKey: publicKey, + canVote: false, periods: [ { duration: 3600, @@ -102,54 +74,54 @@ describe(`************************** transfer-locked-tokens-account-tests.js *** } ], amount: lockedFundsAmount, - max_fee: 400000000000, + maxFee: 400000000000, tpid: '', - actor: fioSdkFaucet.account, - } - - }) - expect(result.status).to.equal('OK') - expect(result).to.have.all.keys( 'status', 'fee_collected') - } catch (err) { - console.log(' Error', err) - } - }) - it(`(API) Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { - try { - const result = await fioSdkFaucet.genericAction('transferLockedTokens', { - payeePublicKey: publicKey2, - canVote: false, - periods: [ - { - duration: 3600, - percent: 30.0, - }, - { - duration: 3640, - percent: 70.0, + }) + expect(result.status).to.equal('OK') + expect(result).to.have.all.keys( 'status', 'fee_collected') + } catch (err) { + console.log('Error', err) + } + } else { + try { + const result = await fioSdkFaucet.genericAction('pushTransaction', { + action: 'trnsloctoks', + account: 'fio.token', + data: { + payee_public_key: publicKey, + can_vote: 0, + periods: [ + { + duration: 3600, + percent: 40.0, + }, + { + duration: 3640, + percent: 60.0, + } + ], + amount: lockedFundsAmount, + max_fee: 400000000000, + tpid: '', + actor: fioSdkFaucet.account, } - ], - amount: lockedFundsAmount, - maxFee: 400000000000, - tpid: '', - }) - expect(result.status).to.equal('OK') - expect(result).to.have.all.keys( 'status', 'fee_collected') - } catch (err) { - console.log('Error', err) + }) + expect(result.status).to.equal('OK') + expect(result).to.have.all.keys( 'status', 'fee_collected') + } catch (err) { + console.log(' Error', err) + } } }) - it.skip(`(pushTransaction) Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { - try { - const result = await fioSdkFaucet.genericAction('pushTransaction', { - action: 'trnsloctoks', - account: 'fio.token', - data: { - payee_public_key: publicKey2, - can_vote: 0, + it(`(${testType}) Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { + if (testType == 'sdk') { + try { + const result = await fioSdkFaucet.genericAction('transferLockedTokens', { + payeePublicKey: publicKey2, + canVote: false, periods: [ { duration: 3600, @@ -161,23 +133,52 @@ describe(`************************** transfer-locked-tokens-account-tests.js *** } ], amount: lockedFundsAmount, - max_fee: 400000000000, + maxFee: 400000000000, tpid: '', - actor: fioSdkFaucet.account, - } - }) - expect(result.status).to.equal('OK') - expect(result).to.have.all.keys( 'status', 'fee_collected') - } catch (err) { - console.log(' Error', err) + }) + expect(result.status).to.equal('OK') + expect(result).to.have.all.keys( 'status', 'fee_collected') + } catch (err) { + console.log('Error', err) + } + } else { + try { + const result = await fioSdkFaucet.genericAction('pushTransaction', { + action: 'trnsloctoks', + account: 'fio.token', + data: { + payee_public_key: publicKey2, + can_vote: 0, + periods: [ + { + duration: 3600, + percent: 30.0, + }, + { + duration: 3640, + percent: 70.0, + } + ], + amount: lockedFundsAmount, + max_fee: 400000000000, + tpid: '', + actor: fioSdkFaucet.account, + } + + }) + expect(result.status).to.equal('OK') + expect(result).to.have.all.keys( 'status', 'fee_collected') + } catch (err) { + console.log(' Error', err) + } } }) - it.skip(`getFioBalance for fioSdk and confirm 'available' = 0`, async () => { + it(`getFioBalance for fioSdk and confirm 'available' = 0`, async () => { const result = await fioSdk.genericAction('getFioBalance', {}) //console.log('Result: ', result) - expect(result).to.have.all.keys('balance') + expect(result).to.have.all.keys('balance', 'available') expect(result.available).equal(0) }) @@ -217,10 +218,10 @@ describe(`************************** transfer-locked-tokens-account-tests.js *** } }) - it.skip(`getFioBalance for fioSdk2 and confirm 'available' = 0`, async () => { + it(`getFioBalance for fioSdk2 and confirm 'available' = 0`, async () => { const result = await fioSdk2.genericAction('getFioBalance', {}) //console.log('Result: ', result) - expect(result).to.have.all.keys('balance') + expect(result).to.have.all.keys('balance', 'available') expect(result.available).equal(0) }) @@ -497,7 +498,7 @@ describe('Testing generic actions', () => { it(`getFioBalance`, async () => { const result = await fioSdk.genericAction('getFioBalance', {}) //console.log('Result: ', result) - expect(result).to.have.all.keys('balance') + expect(result).to.have.all.keys('balance','available') expect(result.balance).to.be.a('number') }) @@ -784,7 +785,7 @@ describe('Testing generic actions', () => { fioPublicKey: publicKey2 }) //console.log('Result: ', result) - expect(result).to.have.all.keys('balance') + expect(result).to.have.all.keys('balance', 'available') expect(result.balance).to.be.a('number') }) diff --git a/tests/transfer-locked-tokens.js b/tests/transfer-locked-tokens.js index debef000..cff936ca 100644 --- a/tests/transfer-locked-tokens.js +++ b/tests/transfer-locked-tokens.js @@ -1,8 +1,9 @@ require('mocha') const {expect} = require('chai') -const {newUser, getProdVoteTotal, fetchJson, generateFioDomain, callFioApi, generateFioAddress, createKeypair} = require('../utils.js'); +const {newUser, getProdVoteTotal, fetchJson, generateFioDomain, callFioApi, generateFioAddress, createKeypair, getTestType} = require('../utils.js'); const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); +const testType = getTestType(); before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); @@ -61,17 +62,12 @@ describe(`************************** transfer-locked-tokens.js ***************** describe(`B. Parameter tests`, () => { - - - it(`Failure test, Transfer locked tokens, periods total percent not 100`, async () => { - try { - - const result = await userA1.sdk.genericAction('pushTransaction', { - action: 'trnsloctoks', - account: 'fio.token', - data: { - payee_public_key: keys.publicKey, - can_vote: 0, + it(`(${testType}) Failure test, Transfer locked tokens, periods total percent not 100`, async () => { + if (testType == 'sdk') { + try { + const result = await userA1.sdk.genericAction('transferLockedTokens', { + payeePublicKey: keys.publicKey, + canVote: 0, periods: [ { duration: 120, @@ -83,16 +79,45 @@ describe(`B. Parameter tests`, () => { } ], amount: fundsAmount, - max_fee: 400000000000, + maxFee: 400000000000, tpid: '', - actor: userA1.account, - } - }) - expect(result.status).to.not.equal('OK') - } catch (err) { - var expected = `Error 400` - expect(err.message).to.include(expected) + }) + expect(result.status).to.not.equal('OK') + } catch (err) { + //console.log('error: ', err) + var expected = `Error 400` + expect(err.message).to.include(expected) + } + } else { + try { + const result = await userA1.sdk.genericAction('pushTransaction', { + action: 'trnsloctoks', + account: 'fio.token', + data: { + payee_public_key: keys.publicKey, + can_vote: 0, + periods: [ + { + duration: 120, + percent: 50.30, + }, + { + duration: 240, + percent: 50.0, + } + ], + amount: fundsAmount, + max_fee: 400000000000, + tpid: '', + actor: userA1.account, + } + }) + expect(result.status).to.not.equal('OK') + } catch (err) { + var expected = `Error 400` + expect(err.message).to.include(expected) + } } }) diff --git a/tests/transfer-tokens.js b/tests/transfer-tokens.js index da060239..34275419 100644 --- a/tests/transfer-tokens.js +++ b/tests/transfer-tokens.js @@ -8,7 +8,7 @@ before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); }) -describe(`************************** transfer-tokens.js ************************** \n A. Transferring tokens to Happy`, () => { +describe(`************************** transfer-tokens.js ************************** \n A. Transferring tokens to Happy`, () => { let userA1, prevFundsAmount const fundsAmount = 1000000000000 diff --git a/tests/txn-resubmit.js b/tests/txn-resubmit.js index 9e8c4d6e..deae7d5d 100644 --- a/tests/txn-resubmit.js +++ b/tests/txn-resubmit.js @@ -8,7 +8,7 @@ before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson) }) -describe('************************** txn-resubmit.js ************************** \n A. Get raw transaction and resubmit.', () => { +describe('************************** txn-resubmit.js ************************** \n A. Get raw transaction and resubmit.', () => { let userA1, userA2, preparedTrx, userA1RequestId const payment = 5000000000 // 5 FIO diff --git a/tests/vote.js b/tests/vote.js index 6a2b86b3..967d1bab 100644 --- a/tests/vote.js +++ b/tests/vote.js @@ -1,8 +1,9 @@ require('mocha') const {expect} = require('chai') -const {newUser, existingUser, getProdVoteTotal, timeout, unlockWallet, addLock, getAccountVoteWeight, getTotalVotedFio, callFioApi, callFioApiSigned, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/fiosdk') -config = require('../config.js'); +const {newUser, existingUser, getTestType, getProdVoteTotal, timeout, unlockWallet, addLock, getAccountVoteWeight, getTotalVotedFio, callFioApi, callFioApiSigned, fetchJson} = require('../utils.js'); +const {FIOSDK } = require('@fioprotocol/fiosdk'); +const config = require('../config.js'); +const testType = getTestType(); let total_voted_fio, transfer_tokens_pub_key_fee, unregister_proxy_fee @@ -28,7 +29,7 @@ before(async () => { unregister_proxy_fee = result.fee; }) -describe(`************************** vote.js ************************** \n A. Test vote counts with proxy when proxy increases and decreases funds`, () => { +describe(`************************** vote.js ************************** \n A. Test vote counts with proxy when proxy increases and decreases funds`, () => { let proxyA1, user2, total_voted_fio, total_bp_votes, transfer_tokens_pub_key_fee @@ -755,7 +756,7 @@ describe.skip('C. (has Bugs) Test voting and proxying of users with Type 1 locke } }) - it(`Unlock fio wallet with wallet key: ${config.WALLETKEY}`, async () => { + it(`Unlock fio wallet`, async () => { try { unlockWallet('fio'); await timeout(2000); // Getting an occasional error that the wallet is not unlocked. Could be a timing issue. @@ -2824,7 +2825,7 @@ describe('Fixed in Gemini: H. When a user proxies their vote, the total_voted_fi }) -describe.skip('Bahamas release only. H. Confirm voter data is returned with get_account', () => { +describe('H. Confirm voter data is returned with get_account', () => { let voterH1 it(`Create users`, async () => { diff --git a/utils.js b/utils.js index 6e9b1a2c..5b543a7b 100755 --- a/utils.js +++ b/utils.js @@ -1,13 +1,10 @@ -config = require ('./config'); - const rp = require('request-promise'); const exec = require('child_process').exec; -//const url = "http://localhost:8889"; +var fs = require('fs'); +config = require ('./config'); + const fiourl = config.URL + "/v1/chain/"; -const KeosdUrl = config.URL + "/v1/chain/"; const historyUrl = config.URL + "/v1/history/" -const clio = "../fio.devtools/bin/clio"; -var fs = require('fs'); const { Fio } = require('@fioprotocol/fiojs'); fetch = require('node-fetch'); @@ -87,6 +84,21 @@ async function getAccountFromKey(publicKey) { return (account); } +function getTestType() { + let testType; + // Argument 6 = test type + var myArgs = process.argv.slice(5); + //console.log('myarg: ', myArgs) + switch (myArgs[0]) { + case 'sdk': + testType = 'sdk'; + break; + default: + testType = 'pushtransaction'; + } + return testType; +} + //Creates a user and registers an address and domain async function newUser(faucet, newAccount=null, newPrivateKey=null, newPublicKey=null, newDomain=null, newAddress=null) { if (newAccount != null) { @@ -524,9 +536,6 @@ async function readProdFile(prodFile) { }); } - - - async function addLock(account, amount, lock) { return new Promise(function(resolve, reject) { var text = {owner: account, amount: amount, locktype: lock} @@ -546,11 +555,19 @@ async function addLock(account, amount, lock) { async function unlockWallet(wallet) { return new Promise(function(resolve, reject) { + const keyFile = config.WALLETKEYFILE; + try { + if (fs.existsSync(keyFile)) { + walletKey = require('fs').readFileSync(keyFile, 'utf-8') + } + } catch(err) { + console.error(err) + } runCmd(config.CLIO + " wallet list") .then(result => { let walletLock = result.indexOf(wallet + " *") if (walletLock == -1 ) { // Wallet is not unlocked - runCmd(config.CLIO + " wallet unlock -n " + wallet + " --password " + config.WALLETKEY) + runCmd(config.CLIO + " wallet unlock -n " + wallet + " --password " + walletKey) } resolve() }).catch(error => { @@ -1011,5 +1028,5 @@ class Ram { } //Ram class */ -module.exports = {newUser, existingUser, getTopprods, callFioApi, callFioApiSigned, callFioHistoryApi, convertToK1, unlockWallet, getFees, getAccountFromKey, getProdVoteTotal, addLock, getTotalVotedFio, getAccountVoteWeight, setRam, printUserRam, user, getMnemonic, fetchJson, randStr, timeout, generateFioDomain, generateFioAddress, createKeypair, readProdFile}; +module.exports = {newUser, existingUser, getTestType, getTopprods, callFioApi, callFioApiSigned, callFioHistoryApi, convertToK1, unlockWallet, getFees, getAccountFromKey, getProdVoteTotal, addLock, getTotalVotedFio, getAccountVoteWeight, setRam, printUserRam, user, getMnemonic, fetchJson, randStr, timeout, generateFioDomain, generateFioAddress, createKeypair, readProdFile}; From f0cca017635aafb37b0496f33324b7dd70f24eba Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 18 Jan 2021 15:09:09 -0700 Subject: [PATCH 40/76] Cleaned up all remaining bug tracking assertions --- tests/clio.js | 5 +- tests/tpid.js | 34 +- tests/transfer-address.js | 9 +- tests/transfer-locked-tokens-account-tests.js | 59 +- tests/transfer-locked-tokens.js | 10 +- tests/vote.js | 592 +++--------------- 6 files changed, 131 insertions(+), 578 deletions(-) diff --git a/tests/clio.js b/tests/clio.js index bd5fe7aa..b7001f54 100644 --- a/tests/clio.js +++ b/tests/clio.js @@ -345,7 +345,7 @@ describe(`D. Address`, () => { console.log('Error', err) } }) - + /* it.skip(`(Future release) address transfer`, async () => { try { result = await runClio(`address transfer -j ${user1.account} ${user1.address} ${user2.publicKey} ${tpid} ${max_fee} --permission ${user1.account}@active`); @@ -466,7 +466,8 @@ describe(`D. Address`, () => { console.log('Error', err) expect(err).to.equal(null) } - }) + }) + */ }) diff --git a/tests/tpid.js b/tests/tpid.js index f5455e53..c5f6dd7f 100644 --- a/tests/tpid.js +++ b/tests/tpid.js @@ -8,7 +8,7 @@ before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson) }) -describe(`************************** tpid.js ************************** \n TPID Tests`, () => { +describe(`************************** tpid.js ************************** \n A. Test TPIDs with proxy`, () => { let proxy1, user1, user2, user3, user4, newPubKey @@ -21,8 +21,6 @@ describe(`************************** tpid.js ************************** \n TPID let keys = await createKeypair(); newPubKey = keys.publicKey; - - console.log('key: ', newPubKey) }) it('Confirm proxy1: is_proxy = 0, is_auto_proxy = 0', async () => { @@ -260,7 +258,7 @@ describe(`************************** tpid.js ************************** \n TPID } }) - it(`FIXED: regaddress: user3 register new Address for user1 using FIO Address of proxy1 (who IS a registered proxy). Expect: no proxy for user1.`, async () => { + it(`regaddress: user3 register new Address for user1 using FIO Address of proxy1 (who IS a registered proxy). Expect: no proxy for user1.`, async () => { user1.address2 = generateFioAddress(user3.domain, 8) try { const result = await user3.sdk.genericAction('pushTransaction', { @@ -324,7 +322,7 @@ describe(`************************** tpid.js ************************** \n TPID } }) - it.skip(`Future release: xferaddress: user3 transfers user3.address2 to emptyAccount.publicKey using FIO Address of proxy1 (who IS a registered proxy). Expect: no proxy for user1.`, async () => { + it(`xferaddress: user3 transfers user3.address2 to emptyAccount.publicKey using FIO Address of proxy1 (who IS a registered proxy). Expect: no proxy for user1.`, async () => { try{ const result = await user3.sdk.genericAction('pushTransaction', { action: 'xferaddress', @@ -344,27 +342,7 @@ describe(`************************** tpid.js ************************** \n TPID } }) - it.skip(`NOT APPLICABLE: burnaddress: user2 tries to burn user3 address`, async () => { - try { - const result = await user2.sdk.genericAction('pushTransaction', { - action: 'burnaddress', - account: 'fio.address', - data: { - fio_address: user3.address, - max_fee: config.maxFee, - tpid: proxy1.address, - actor: user2.account - } - }) - //console.log('Result: ', result) - expect(result.status).to.equal('OK') - } catch (err) { - console.log('Error: ', err) - expect(err).to.equal('null') - } - }) - - it(`FIXED: trnsfiopubky: user 3 transfers 10 FIO to user1 using FIO Address of proxy1 (who IS a registered proxy). Expect: no proxy for user1.`, async () => { + it(`user 3 transfers 10 FIO to user1 using FIO Address of proxy1 (who IS a registered proxy). Expect: no proxy for user1.`, async () => { try { const result = await user3.sdk.genericAction('pushTransaction', { action: 'trnsfiopubky', @@ -415,7 +393,7 @@ describe(`************************** tpid.js ************************** \n TPID }) -describe(`User that has proxied their vote is sent FIO with TPID registered as proxy`, () => { +describe(`B. User that has proxied their vote is sent FIO with TPID registered as proxy`, () => { let proxy1, user1, user2 @@ -608,7 +586,7 @@ describe(`User that has proxied their vote is sent FIO with TPID registered as p }) -describe(`User that has proxied their votes is sent FIO with TPID registered as proxy`, () => { +describe(`C. User that has proxied their votes is sent FIO with TPID registered as proxy`, () => { let proxy1, proxyThief, user1, user2 diff --git a/tests/transfer-address.js b/tests/transfer-address.js index 94772a83..514b383a 100644 --- a/tests/transfer-address.js +++ b/tests/transfer-address.js @@ -854,7 +854,7 @@ describe('D. transferFioAddress Error testing', () => { } }) - it(`For Bravo, this will fail because userD3 has OBT transactions. Will need to fix when all xferaddress are enabled. Transfer address with insufficient funds and no bundled transactions. Expect error type 400: ${config.error.insufficientFunds}`, async () => { + it.skip(`(For Bravo/v2.3.0 contracts, transferring the address will fail because userD3 has OBT transactions. Will need to fix when all xferaddress are enabled.) Transfer address with insufficient funds and no bundled transactions. Expect error type 400: ${config.error.insufficientFunds}`, async () => { try { const result = await userD3.sdk.genericAction('transferFioAddress', { fioAddress: userD3.address, @@ -865,9 +865,8 @@ describe('D. transferFioAddress Error testing', () => { expect(result.status).to.equal(null); } catch (err) { //console.log('Error: ', err.json.error) - expect(err.json.code).to.equal(500); - //expect(err.json.fields[0].error).to.equal(config.error.insufficientFunds) - //expect(err.json.code).to.equal(400); + expect(err.json.fields[0].error).to.equal(config.error.insufficientFunds) + expect(err.json.code).to.equal(400); } }) @@ -1000,7 +999,7 @@ describe('E. Confirm active producers and proxy cannot transfer address', () => }) -describe('BRAVO ONLY: Confirm users with OBT records or Requests cannot transfer addresses', () => { +describe('F. BRAVO ONLY: Confirm users with OBT records or Requests cannot transfer addresses', () => { let user1, user2, user3, user4, transfer_fio_address_fee diff --git a/tests/transfer-locked-tokens-account-tests.js b/tests/transfer-locked-tokens-account-tests.js index 17a42878..149dbb53 100644 --- a/tests/transfer-locked-tokens-account-tests.js +++ b/tests/transfer-locked-tokens-account-tests.js @@ -1,8 +1,8 @@ require('mocha') const {expect} = require('chai') const {FIOSDK } = require('@fioprotocol/fiosdk') -const {fetchJson, timeout, generateFioDomain, generateFioAddress, createKeypair, getTestType, getTotalVotedFio, getAccountVoteWeight, getProdVoteTotal, callFioApi} = require('../utils.js'); -config = require('../config.js'); +const {newUser, fetchJson, timeout, generateFioDomain, generateFioAddress, createKeypair, getTestType, getTotalVotedFio, getAccountVoteWeight, getProdVoteTotal, callFioApi} = require('../utils.js'); +const config = require('../config.js'); const testType = getTestType(); let transfer_tokens_pub_key_fee @@ -37,25 +37,20 @@ before(async () => { account2 = keys2.account fioSdk2 = new FIOSDK(privateKey2, publicKey2, config.BASE_URL, fetchJson); - it('Get transfer_tokens_pub_key fee', async () => { - try { - result = await user1.sdk.getFee('transfer_tokens_pub_key', user1.address); - transfer_tokens_pub_key_fee = result.fee; - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - }) + result = await fioSdkFaucet.getFee('transfer_tokens_pub_key'); + transfer_tokens_pub_key_fee = result.fee; }) describe(`************************** transfer-locked-tokens-account-tests.js ************************** \n A. Create accounts for tests`, () => { + /* it.skip(`Show keys`, async () => { console.log('privateKey: ', privateKey) console.log('publicKey: ', publicKey) console.log('privateKey2: ', privateKey2) console.log('publicKey2: ', publicKey2) }) + */ it(`(${testType}) Create fioSdk account: transferLockedTokens ${lockedFundsAmount}, canvote false, (20,40%) and (40,60%)`, async () => { if (testType == 'sdk') { @@ -371,7 +366,7 @@ describe(`************************** transfer-locked-tokens-account-tests.js *** }) }) -describe('Testing generic actions', () => { +describe('B. Testing generic actions', () => { let pubKeyForTransfer const newFioDomain = generateFioDomain(8) @@ -823,7 +818,7 @@ describe('Testing generic actions', () => { }) -describe('Request funds, approve and send', () => { +describe('C. Request funds, approve and send', () => { const fundsAmount = 3 let requestId const memo = 'testing fund request' @@ -893,7 +888,6 @@ describe('Request funds, approve and send', () => { it(`Wait a few seconds.`, async () => { await timeout(5000) }) it(`getPendingFioRequests`, async () => { - await timeout(4000) const result = await fioSdk.genericAction('getPendingFioRequests', {}) //console.log('Result: ', result) expect(result).to.have.all.keys('requests', 'more') @@ -951,7 +945,6 @@ describe('Request funds, approve and send', () => { }) it(`Payer getObtData`, async () => { - await timeout(10000) const result = await fioSdk.genericAction('getObtData', {}) expect(result).to.have.all.keys('obt_data_records', 'more') expect(result.obt_data_records).to.be.a('array') @@ -983,7 +976,7 @@ describe('Request funds, approve and send', () => { }) -describe('Request funds, cancel funds request', () => { +describe('D. Request funds, cancel funds request', () => { const fundsAmount = 3 let requestId const memo = 'testing fund request' @@ -1047,7 +1040,7 @@ describe('Request funds, cancel funds request', () => { }) -describe('Request funds, reject', () => { +describe('E. Request funds, reject', () => { const fundsAmount = 4 let requestId const memo = 'testing fund request' @@ -1112,7 +1105,7 @@ describe('Request funds, reject', () => { }) -describe('Transfer tokens', () => { +describe('F. Transfer tokens', () => { const fundsAmount = FIOSDK.SUFUnit let fioBalance = 0 let fioBalanceAfter = 0 @@ -1145,7 +1138,7 @@ describe('Transfer tokens', () => { }) }) -describe('Record obt data, check', () => { +describe('G. Record obt data, check', () => { const obtId = generateObtId() const fundsAmount = 4.5 @@ -1216,9 +1209,13 @@ describe('Record obt data, check', () => { }) -describe(`Test locked token accounts with proxy voting`, () => { +describe(`H. Test locked token accounts with proxy voting`, () => { - let total_voted_fio, total_bp_votes + let total_voted_fio, total_bp_votes, user1 + + it(`Create user`, async () => { + user1 = await newUser(fioSdkFaucet); + }) it(`Get initial total_voted_fio`, async () => { total_voted_fio = await getTotalVotedFio(); @@ -1321,7 +1318,7 @@ describe(`Test locked token accounts with proxy voting`, () => { try { let prev_total_voted_fio = total_voted_fio total_voted_fio = await getTotalVotedFio(); - //console.log('total_voted_fio: ', total_voted_fio) + //console.log('total_voted_fio: ', total_voted_fio / config.BILLION) expect(total_voted_fio).to.equal(prev_total_voted_fio + fioSdk.last_vote_weight) } catch (err) { console.log('Error', err) @@ -1341,8 +1338,8 @@ describe(`Test locked token accounts with proxy voting`, () => { } }) - it('Transfer additional 500 FIO from faucet to fioSdk', async () => { - const result = await fioSdkFaucet.genericAction('transferTokens', { + it('Transfer additional 500 FIO from user1 to fioSdk', async () => { + const result = await user1.sdk.genericAction('transferTokens', { payeeFioPublicKey: publicKey, amount: 500000000000, maxFee: config.api.transfer_tokens_pub_key.fee, @@ -1364,11 +1361,11 @@ describe(`Test locked token accounts with proxy voting`, () => { } }) - it.skip(`(Bug? will address in most recent fio.test) total_voted_fio increased by 500 FIO`, async () => { + it(`total_voted_fio increased by 500 FIO`, async () => { try { let prev_total_voted_fio = total_voted_fio total_voted_fio = await getTotalVotedFio(); - //console.log('total_voted_fio: ', total_voted_fio) + //console.log('total_voted_fio: ', total_voted_fio / config.BILLION) expect(total_voted_fio).to.equal(prev_total_voted_fio + 500000000000) } catch (err) { console.log('Error', err) @@ -1388,11 +1385,11 @@ describe(`Test locked token accounts with proxy voting`, () => { } }) - it(`Transfer 200 FIO from fioSdk back to faucet`, async () => { + it(`Transfer 200 FIO from fioSdk back to user1 (to remove votes from the total)`, async () => { const result = await fioSdk.genericAction('transferTokens', { - payeeFioPublicKey: config.FAUCET_PUB_KEY, + payeeFioPublicKey: user1.publicKey, amount: 200000000000, - maxFee: config.api.transfer_tokens_pub_key.fee, + maxFee: config.maxFee, }) //console.log('Result', result) expect(result.status).to.equal('OK') @@ -1410,7 +1407,7 @@ describe(`Test locked token accounts with proxy voting`, () => { } }) - it.skip(`(Bug? will address in most recent fio.test)total_voted_fio decreased by 200 - transfer_tokens_pub_key fee`, async () => { + it(`(Bug? will address in most recent fio.test)total_voted_fio decreased by 200 - transfer_tokens_pub_key fee`, async () => { try { let prev_total_voted_fio = total_voted_fio total_voted_fio = await getTotalVotedFio(); @@ -1422,7 +1419,7 @@ describe(`Test locked token accounts with proxy voting`, () => { } }) - it.skip(`(Bug? will address in most recent fio.test) bp1@dapixdev total_votes descreased by 200 - transfer_tokens_pub_key fee`, async () => { + it(`(Bug? will address in most recent fio.test) bp1@dapixdev total_votes descreased by 200 - transfer_tokens_pub_key fee`, async () => { try { let prev_total_bp_votes = total_bp_votes; total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); diff --git a/tests/transfer-locked-tokens.js b/tests/transfer-locked-tokens.js index cff936ca..8d4a7057 100644 --- a/tests/transfer-locked-tokens.js +++ b/tests/transfer-locked-tokens.js @@ -24,7 +24,7 @@ const fundsAmount = 500000000000 const maxTestFundsAmount = 5000000000 const halfundsAmount = 220000000000 -describe(`************************** transfer-locked-tokens.js ************************** \n A. Create accounts for tests`, () => { +describe(`************************** transfer-locked-tokens.js ************************** \n A. Create accounts for tests`, () => { it(`Create users`, async () => { @@ -43,6 +43,7 @@ describe(`************************** transfer-locked-tokens.js ***************** locksdk3 = new FIOSDK(keys3.privateKey, keys3.publicKey, config.BASE_URL, fetchJson); }) + /* it.skip(`Show account info`, async () => { console.log(' userA1.account:', userA1.account) console.log(' userA1.publicKey:', userA1.publicKey) @@ -56,6 +57,7 @@ describe(`************************** transfer-locked-tokens.js ***************** console.log(" locked token holder votable account ",keys1.account) console.log(" locked token holder votable priv key ",keys1.privateKey) }) + */ }) @@ -785,8 +787,8 @@ describe(`B. transfer with 2 unlock periods, canvote = false`, () => { }) -describe.skip(`C. staking incentives, canvote = false`, () => { - +describe.skip(`FUTURE FEATURE (commented out) C. staking incentives, canvote = false`, () => { +/* let balancebefore, balanceafter, feetransferlocked, stakeKey1, stakeKey2, stakeKey3,stakeKey4, stakeKey5 @@ -1507,10 +1509,10 @@ describe.skip(`C. staking incentives, canvote = false`, () => { //end check that we arent abl to vote with this lock + */ }) //end new tests matching testing requirements. - describe(`D. Canvote true, verify tokens are voted.`, () => { //test cases diff --git a/tests/vote.js b/tests/vote.js index 967d1bab..1211383b 100644 --- a/tests/vote.js +++ b/tests/vote.js @@ -5,7 +5,7 @@ const {FIOSDK } = require('@fioprotocol/fiosdk'); const config = require('../config.js'); const testType = getTestType(); -let total_voted_fio, transfer_tokens_pub_key_fee, unregister_proxy_fee +let total_voted_fio, transfer_tokens_pub_key_fee, unregister_proxy_fee, register_proxy_fee const eosio = { account: 'eosio', @@ -27,6 +27,9 @@ before(async () => { result = await faucet.getFee('unregister_proxy'); unregister_proxy_fee = result.fee; + + result = await faucet.getFee('register_proxy'); + register_proxy_fee = result.fee; }) describe(`************************** vote.js ************************** \n A. Test vote counts with proxy when proxy increases and decreases funds`, () => { @@ -272,7 +275,7 @@ describe(`************************** vote.js ************************** \n A. describe('B. Test vote counts with proxy when proxy increases and decreases funds', () => { - let proxyB1, voterB1, user1, total_voted_fio, total_bp_votes, transfer_tokens_pub_key_fee + let proxyB1, voterB1, user1, total_voted_fio, prev_total_voted_fio, total_bp_votes, transfer_tokens_pub_key_fee, prev_vote_weight it(`Create users`, async () => { try { @@ -318,7 +321,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund fioPublicKey: voterB1.publicKey }) voterB1.fioBalance = result.balance - //console.log('proxyB1 getFioBalance: ', result.balance) + //console.log('voterB1 getFioBalance: ', result.balance) } catch (err) { console.log('Error: ', err) } @@ -399,7 +402,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund it(`voterB1 last_vote_weight = voterB1 FIO Balance`, async () => { try { voterB1.last_vote_weight = await getAccountVoteWeight(voterB1.account); - //console.log('proxyB1.last_vote_weight:', voterB1.last_vote_weight) + //console.log('voterB1.last_vote_weight:', voterB1.last_vote_weight) expect(voterB1.last_vote_weight).to.equal(voterB1.fioBalance) } catch (err) { console.log('Error: ', err) @@ -429,7 +432,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund it('total_voted_fio is increases by proxyB1 last_vote_weight (fixed by MAS-1489)', async () => { try { - let prev_total_voted_fio = total_voted_fio + prev_total_voted_fio = total_voted_fio total_voted_fio = await getTotalVotedFio(); //console.log('total_voted_fio: ', total_voted_fio) expect(total_voted_fio).to.equal(prev_total_voted_fio + proxyB1.last_vote_weight) @@ -473,7 +476,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund it(`voterB1 last_vote_weight increases by 500 FIO`, async () => { try { - let prev_vote_weight = voterB1.last_vote_weight; + prev_vote_weight = voterB1.last_vote_weight; voterB1.last_vote_weight = await getAccountVoteWeight(voterB1.account); //console.log('voterB1.last_vote_weight:', voterB1.last_vote_weight); expect(voterB1.last_vote_weight).to.equal(prev_vote_weight + 500000000000); @@ -484,7 +487,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund it(`proxyB1 last_vote_weight increases by 500 FIO`, async () => { try { - let prev_vote_weight = proxyB1.last_vote_weight; + prev_vote_weight = proxyB1.last_vote_weight; proxyB1.last_vote_weight = await getAccountVoteWeight(proxyB1.account); //console.log('proxyB1.last_vote_weight:', proxyB1.last_vote_weight); expect(proxyB1.last_vote_weight).to.equal(prev_vote_weight + 500000000000); @@ -495,7 +498,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund it(`total_voted_fio increased by 500 FIO`, async () => { try { - let prev_total_voted_fio = total_voted_fio; + prev_total_voted_fio = total_voted_fio; total_voted_fio = await getTotalVotedFio(); //console.log('total_voted_fio: ', total_voted_fio) expect(total_voted_fio).to.equal(prev_total_voted_fio + 500000000000) @@ -533,7 +536,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund it(`voterB1 last_vote_weight decreases by (1000 + xfer fee) FIO)`, async () => { try { - let prev_vote_weight = voterB1.last_vote_weight; + prev_vote_weight = voterB1.last_vote_weight; voterB1.last_vote_weight = await getAccountVoteWeight(voterB1.account); //console.log('voterB1.last_vote_weight:', voterB1.last_vote_weight); expect(voterB1.last_vote_weight).to.equal(prev_vote_weight - 1000000000000 - transfer_tokens_pub_key_fee); @@ -544,7 +547,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund it(`proxyB1 last_vote_weight decreases by (1000 + xfer fee) FIO)`, async () => { try { - let prev_vote_weight = proxyB1.last_vote_weight; + prev_vote_weight = proxyB1.last_vote_weight; proxyB1.last_vote_weight = await getAccountVoteWeight(proxyB1.account); //console.log('proxyB1.last_vote_weight:', proxyB1.last_vote_weight); expect(proxyB1.last_vote_weight).to.equal(prev_vote_weight - 1000000000000 - transfer_tokens_pub_key_fee); @@ -555,7 +558,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund it(`total_voted_fio decreases by (1000 + xfer fee) FIO`, async () => { try { - let prev_total_voted_fio = total_voted_fio; + prev_total_voted_fio = total_voted_fio; total_voted_fio = await getTotalVotedFio(); //console.log('total_voted_fio: ', total_voted_fio) expect(total_voted_fio).to.equal(prev_total_voted_fio - 1000000000000 - transfer_tokens_pub_key_fee) @@ -589,7 +592,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund it(`voterB1 last_vote_weight increases by 800 FIO)`, async () => { try { - let prev_vote_weight = voterB1.last_vote_weight; + prev_vote_weight = voterB1.last_vote_weight; voterB1.last_vote_weight = await getAccountVoteWeight(voterB1.account); //console.log('voterB1.last_vote_weight:', voterB1.last_vote_weight); expect(voterB1.last_vote_weight).to.equal(prev_vote_weight + 800000000000); @@ -600,7 +603,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund it(`proxyB1 last_vote_weight decreases by xfer fee only (since votes are still proxied)`, async () => { try { - let prev_vote_weight = proxyB1.last_vote_weight; + prev_vote_weight = proxyB1.last_vote_weight; proxyB1.last_vote_weight = await getAccountVoteWeight(proxyB1.account); //console.log('proxyB1.last_vote_weight:', proxyB1.last_vote_weight); expect(proxyB1.last_vote_weight).to.equal(prev_vote_weight - transfer_tokens_pub_key_fee); @@ -611,7 +614,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund it(`total_voted_fio does decreases by xfer fee`, async () => { try { - let prev_total_voted_fio = total_voted_fio; + prev_total_voted_fio = total_voted_fio; total_voted_fio = await getTotalVotedFio(); //console.log('total_voted_fio: ', total_voted_fio) expect(total_voted_fio).to.equal(prev_total_voted_fio - transfer_tokens_pub_key_fee) @@ -620,8 +623,6 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund } }) - //Check for a bug with unregistering proxy. Keep as "skip" - it(`Get proxyB1 FIO Balance pre unregproxy`, async () => { try { const result = await proxyB1.sdk.genericAction('getFioBalance', { @@ -675,32 +676,37 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund } }) - it(`Get proxyB1 last_vote_weight post unregproxy`, async () => { + it(`Get new proxyB1 vote_weight`, async () => { try { - proxyB1.last_vote_weight = await getAccountVoteWeight(proxyB1.account) + prev_vote_weight = proxyB1.last_vote_weight; + proxyB1.last_vote_weight = await getAccountVoteWeight(proxyB1.account); //console.log('proxyB1.last_vote_weight: ', proxyB1.last_vote_weight) } catch (err) { - console.log('Error', err) + console.log('Error: ', err) } }) - it(`BUG: MAS-1539 - proxyB1 last_vote_weight decreases by (voterB1 last_vote_weight + unregproxy fee)`, async () => { + it.skip(`(BUG: BD-2317) Expect: proxyB1 last_vote_weight = proxyB1.prev_vote_weight - voterB1.last_vote_weight - unregister_proxy_fee (also subtracting voterB1 votes after unregstering)`, async () => { try { - let prev_vote_weight = proxyB1.last_vote_weight; - proxyB1.last_vote_weight = await getAccountVoteWeight(proxyB1.account); - //console.log('proxyB1.last_vote_weight:', proxyB1.last_vote_weight); - //Bug: expect(proxyB1.last_vote_weight).to.equal(prev_vote_weight - voterB1.last_vote_weight - config.api.unregister_proxy.fee); + expect(proxyB1.last_vote_weight).to.equal(prev_vote_weight - voterB1.last_vote_weight - unregister_proxy_fee); } catch (err) { console.log('Error: ', err) } }) - it(`total_voted_fio decreases by voterB1 last_vote_weight`, async () => { + it(`Get new total_voted_fio`, async () => { try { let prev_total_voted_fio = total_voted_fio; total_voted_fio = await getTotalVotedFio(); //console.log('total_voted_fio: ', total_voted_fio) - expect(total_voted_fio).to.equal(prev_total_voted_fio - voterB1.last_vote_weight) + } catch (err) { + console.log('Error', err) + } + }) + + it.skip(`(BUG: BD-2317) Expect: total_voted_fio = prev_total_voted_fio - voterB1.last_vote_weight (remove voterB1 votes after unregistering their proxy)`, async () => { + try { + expect(total_voted_fio).to.equal(prev_total_voted_fio - voterB1.last_vote_weight - unregister_proxy_fee) } catch (err) { console.log('Error', err) } @@ -716,25 +722,27 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund expect(result.status).to.equal('OK') ; }) - it('proxyB1 last_vote_weight decreases by (200 + xfer fee) ', async () => { + it(`Wait a few seconds.`, async () => { await timeout(4000) }) + + it('(WORKAROUND: Need to update after BD-2317 is fixed) proxyB1 last_vote_weight decreases by (200 + xfer fee) ', async () => { try { let previous_vote_weight = proxyB1.last_vote_weight; proxyB1.last_vote_weight = await getAccountVoteWeight(proxyB1.account); //console.log('previous_vote_weight:', previous_vote_weight); //BUG: need to subtract the unregproxy fee, because now it is showing up. - expect(proxyB1.last_vote_weight).to.equal(previous_vote_weight - 200000000000 - config.api.transfer_tokens_pub_key.fee - config.api.unregister_proxy.fee) ; + expect(proxyB1.last_vote_weight).to.equal(previous_vote_weight - 200000000000 - transfer_tokens_pub_key_fee - unregister_proxy_fee); } catch (err) { console.log('Error: ', err); } }) - it(`total_voted_fio decreased by (200 + xfer fee)`, async () => { + it(`(WORKAROUND: Need to update after BD-2317 is fixed) total_voted_fio decreased by (200 + xfer fee)`, async () => { try { let prev_total_voted_fio = total_voted_fio; total_voted_fio = await getTotalVotedFio(); //console.log('total_voted_fio: ', total_voted_fio); //BUG: need to subtract the unregproxy fee, because now it is showing up. - expect(total_voted_fio).to.equal(prev_total_voted_fio - 200000000000 - config.api.transfer_tokens_pub_key.fee - config.api.unregister_proxy.fee); + expect(total_voted_fio).to.equal(prev_total_voted_fio - 200000000000 - transfer_tokens_pub_key_fee - unregister_proxy_fee); } catch (err) { console.log('Error', err); } @@ -742,468 +750,7 @@ describe('B. Test vote counts with proxy when proxy increases and decreases fund }) -describe.skip('C. (has Bugs) Test voting and proxying of users with Type 1 locked tokens', () => { - - let proxyC1, voterC1, total_bp_votes - const lockAmount = 1000000000000 - - it(`Create users`, async () => { - try { - proxyC1 = await newUser(faucet); - voterC1 = await newUser(faucet); - } catch (err) { - console.log('Error: ', err) - } - }) - - it(`Unlock fio wallet`, async () => { - try { - unlockWallet('fio'); - await timeout(2000); // Getting an occasional error that the wallet is not unlocked. Could be a timing issue. - } catch (err) { - console.log('Error: ', err) - } - }) - - it(`Get proxyC1 FIO Balance`, async () => { - try { - const result = await proxyC1.sdk.genericAction('getFioBalance', { - fioPublicKey: proxyC1.publicKey - }) - proxyC1.fioBalance = result.balance - //console.log('proxyC1 getFioBalance: ', result.balance) - } catch (err) { - console.log('Error: ', err) - } - }) - - it(`Apply Lock Type 1 to ${lockAmount} proxyC1 FIO`, async () => { - try { - let result = await addLock(proxyC1.account, lockAmount, 1); - proxyC1.lockAmount = lockAmount - //console.log('result:', result) - expect(result).to.have.all.keys('transaction_id', 'processed') - } catch (err) { - console.log('Error: ', err.json) - } - }) - - it(`Apply Lock Type 1 to ${lockAmount} voterC1 FIO`, async () => { - try { - let result = await addLock(voterC1.account, lockAmount, 1); - voterC1.lockAmount = lockAmount - //console.log('result:', result) - expect(result).to.have.all.keys('transaction_id', 'processed') - } catch (err) { - console.log('Error: ', err.json) - expect(err).to.equal(null) - } - }) - - it(`Get bp1@dapixdev total_votes`, async () => { - try { - total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); - //console.log('bp1@dapixdev total_votes:', total_bp_votes) - } catch (err) { - console.log('Error: ', err) - } - }) - - it.skip(`Register proxyC1 as a proxy`, async () => { - try { - const result = await proxyC1.sdk.genericAction('pushTransaction', { - action: 'regproxy', - account: 'eosio', - data: { - fio_address: proxyC1.address, - actor: proxyC1.account, - max_fee: config.api.register_proxy.fee - } - }) - //console.log('Result: ', result) - expect(result.status).to.equal('OK') - } catch (err) { - console.log('Error: ', err.json) - } - }) - - it(`proxyC1 votes for bp1@dapixdev`, async () => { - try { - const result = await proxyC1.sdk.genericAction('pushTransaction', { - action: 'voteproducer', - account: 'eosio', - data: { - "producers": [ - 'bp1@dapixdev' - ], - fio_address: proxyC1.address, - actor: proxyC1.account, - max_fee: config.api.vote_producer.fee - } - }) - //console.log('Result: ', result) - expect(result.status).to.equal('OK') - } catch (err) { - console.log('Error: ', err.json) - } - }) - - it(`Get proxyC1 FIO Balance`, async () => { - try { - const result = await proxyC1.sdk.genericAction('getFioBalance', { - fioPublicKey: proxyC1.publicKey - }) - proxyC1.fioBalance = result.balance - //console.log('proxyC1 getFioBalance: ', result.balance) - } catch (err) { - console.log('Error: ', err) - } - }) - - it.skip(`BUG: proxyC1 last_vote_weight is ${lockAmount} less than proxyC1 FIO Balance`, async () => { - try { - proxyC1.last_vote_weight = await getAccountVoteWeight(proxyC1.account); - console.log('proxyC1.last_vote_weight:', proxyC1.last_vote_weight) - expect(proxyC1.last_vote_weight).to.equal(proxyC1.fioBalance) - } catch (err) { - console.log('Error: ', err) - } - }) - - it.skip(`BUG: bp1@dapixdev total_votes increased by proxyC1 FIO Balance - ${lockAmount}`, async () => { - try { - prev_total_bp_votes = total_bp_votes; - total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); - //console.log('bp1@dapixdev total_votes:', total_bp_votes) - expect(total_bp_votes).to.equal(prev_total_bp_votes + proxyC1.fioBalance - lockAmount) - } catch (err) { - console.log('Error: ', err) - } - }) - - it(`Transfer 1000 FIO to proxyC1 from faucet`, async () => { - const result = await faucet.genericAction('transferTokens', { - payeeFioPublicKey: proxyC1.publicKey, - amount: 1000000000000, - maxFee: config.api.transfer_tokens_pub_key.fee, - }) - //console.log('Result', result) - expect(result.status).to.equal('OK') - }) - - it.skip(`BUG: proxyC1 last_vote_weight increases by 1000 FIO`, async () => { - try { - let prev_vote_weight = proxyC1.last_vote_weight - proxyC1.last_vote_weight = await getAccountVoteWeight(proxyC1.account); - //console.log('proxyC1.last_vote_weight:', proxyC1.last_vote_weight) - expect(proxyC1.last_vote_weight).to.equal(prev_vote_weight - 1000000000000) - } catch (err) { - console.log('Error: ', err) - } - }) - - it(`proxyC1 FIO Balance increases by 1000 FIO`, async () => { - try { - const result = await proxyC1.sdk.genericAction('getFioBalance', { - fioPublicKey: proxyC1.publicKey - }) - let prev_balance = proxyC1.fioBalance; - proxyC1.fioBalance = result.balance; - //console.log('proxyC1 getFioBalance: ', result.balance) - expect(proxyC1.fioBalance).to.equal(prev_balance + 1000000000000) - } catch (err) { - console.log('Error: ', err) - } - }) - -/* - - it(`proxyC1 last_vote_weight decreases by lock amount: ${lockAmount}`, async () => { - try { - let prev_weight = proxyC1.last_vote_weight - proxyC1.last_vote_weight = await getAccountVoteWeight(proxyC1.account); - console.log('proxyC1.last_vote_weight:', proxyC1.last_vote_weight) - expect(proxyC1.last_vote_weight).to.equal(prev_weight - lockAmount) - } catch (err) { - console.log('Error: ', err) - } - }) - - - it(`bp1@dapixdev total_votes decreases by lock amount: ${lockAmount}`, async () => { - try { - prev_total_bp_votes = total_bp_votes; - total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); - //console.log('bp1@dapixdev total_votes:', total_bp_votes) - expect(total_bp_votes).to.equal(prev_total_bp_votes - lockAmount) - } catch (err) { - console.log('Error: ', err) - } - }) - - it(`voterC1 proxy votes to proxyC1`, async () => { - try { - const result = await voterC1.sdk.genericAction('pushTransaction', { - action: 'voteproxy', - account: 'eosio', - data: { - proxy: proxyC1.address, - fio_address: voterC1.address, - actor: voterC1.account, - max_fee: config.api.proxy_vote.fee - } - }) - //console.log('Result: ', result) - expect(result.status).to.equal('OK') - } catch (err) { - console.log('Error: ', err.json) - } - }) - - it(`Get voterC1 last_vote_weight`, async () => { - try { - voterC1.last_vote_weight = await getAccountVoteWeight(voterC1.account); - //console.log('user2.last_vote_weight:', user2.last_vote_weight) - } catch (err) { - console.log('Error: ', err.json) - } - }) - - it(`bp1@dapixdev total_votes increased by voterC1 last_vote_weight`, async () => { - try { - prev_total_bp_votes = total_bp_votes; - total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); - //console.log('bp1@dapixdev total_votes:', total_bp_votes) - expect(total_bp_votes).to.equal(prev_total_bp_votes + voterC1.last_vote_weight) - } catch (err) { - console.log('Error: ', err) - } - }) - - it(`issue locked token grant to voterC1 as lock type 1 in the amount of ${lockAmount}`, async () => { - try { - let result = await addLock(voterC1.account, lockAmount, 1); - //console.log('result:', result) - expect(result).to.have.all.keys('transaction_id', 'processed') - } catch (err) { - console.log('Error: ', err.json) - } - }) - - it(`voterC1 last_vote_weight decreases by lock amount: ${lockAmount}`, async () => { - try { - let prev_weight = voterC1.last_vote_weight - voterC1.last_vote_weight = await getAccountVoteWeight(voterC1.account); - //console.log('user2.last_vote_weight:', user2.last_vote_weight) - expect(voterC1.last_vote_weight).to.equal(prev_weight - lockAmount) - } catch (err) { - console.log('Error: ', err.json) - } - }) - - it(`bp1@dapixdev total_votes decreases by lock amount: ${lockAmount}`, async () => { - try { - prev_total_bp_votes = total_bp_votes; - total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); - //console.log('bp1@dapixdev total_votes:', total_bp_votes) - expect(total_bp_votes).to.equal(prev_total_bp_votes - lockAmount) - } catch (err) { - console.log('Error: ', err) - } - }) -*/ -}) - -describe.skip('NOT WORKING D. Proxy voting with proxy and voter having some Type 2/3 locked tokens', () => { - - let proxyD1, voterD1, voterG2, voterG3, voterG4, total_bp_votes - const lockType = 3 // set as 2 or 3 - const lockAmount = 300000000000 - - it(`Create users`, async () => { - proxyD1 = await newUser(faucet); - voterD1 = await newUser(faucet); - }) - - it(`Get bp1@dapixdev total_votes`, async () => { - try { - total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); - //console.log('bp1@dapixdev total_votes:', total_bp_votes) - } catch (err) { - console.log('Error: ', err) - } - }) - - it.skip(`issue locked token grant to proxyD1 as lock type ${lockType} in the amount of ${lockAmount}`, async () => { - try { - let result = await addLock(proxyD1.account, lockAmount, lockType); - //console.log('result:', result) - expect(result).to.have.all.keys('transaction_id', 'processed') - } catch (err) { - console.log('Error: ', err.json) - } - }) - - it.skip(`Does not work. Messes up future tests. issue locked token grant to proxyD1 as lock type ${lockType} in the amount of ${lockAmount}`, async () => { - try { - const result = await callFioApiSigned('push_transaction', { - action: 'addlocked', - account: 'eosio', - actor: 'eosio', - privKey: eosio.privateKey, - data: { - owner: proxyD1.account, - amount: 300000000000, - locktype: 1, - } - }) - console.log('Result: ', result) - //expect(result.processed.receipt.status).to.equal('executed'); - } catch (err) { - console.log('Error: ', err.json) - } - }) - - it(`Register proxyD1 as a proxy`, async () => { - try { - const result = await proxyD1.sdk.genericAction('pushTransaction', { - action: 'regproxy', - account: 'eosio', - data: { - fio_address: proxyD1.address, - actor: proxyD1.account, - max_fee: config.api.register_proxy.fee - } - }) - //console.log('Result: ', result) - expect(result.status).to.equal('OK') - } catch (err) { - console.log('Error: ', err.json) - } - }) - - it(`proxyD1 votes for bp1@dapixdev`, async () => { - try { - const result = await proxyD1.sdk.genericAction('pushTransaction', { - action: 'voteproducer', - account: 'eosio', - data: { - "producers": [ - 'bp1@dapixdev' - ], - fio_address: proxyD1.address, - actor: proxyD1.account, - max_fee: config.api.vote_producer.fee - } - }) - //console.log('Result: ', result) - expect(result.status).to.equal('OK') - } catch (err) { - console.log('Error: ', err.json.error.details) - } - }) - - it(`Get proxyD1 last_vote_weight`, async () => { - try { - proxyD1.last_vote_weight = await getAccountVoteWeight(proxyD1.account); - //console.log('proxyD1.last_vote_weight:', proxyD1.last_vote_weight) - } catch (err) { - console.log('Error: ', err) - } - }) - - it(`bp1@dapixdev total_votes increased by proxyD1 last_vote_weight`, async () => { - try { - prev_total_bp_votes = total_bp_votes; - total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); - //console.log('bp1@dapixdev total_votes:', total_bp_votes) - expect(total_bp_votes).to.equal(prev_total_bp_votes + proxyD1.last_vote_weight) - } catch (err) { - console.log('Error: ', err) - } - }) - - it(`issue locked token grant to voterD1 as lock type ${lockType} in the amount of ${lockAmount}`, async () => { - try { - let result = await addLock(voterD1.account, lockAmount, lockType); - //console.log('result:', result) - expect(result).to.have.all.keys('transaction_id', 'processed') - } catch (err) { - console.log('Error: ', err.json) - } - }) - - it(`voterD1 proxy votes to proxyD1`, async () => { - try { - const result = await voterD1.sdk.genericAction('pushTransaction', { - action: 'voteproxy', - account: 'eosio', - data: { - proxy: proxyD1.address, - fio_address: voterD1.address, - actor: voterD1.account, - max_fee: config.api.proxy_vote.fee - } - }) - //console.log('Result: ', result) - expect(result.status).to.equal('OK') - } catch (err) { - console.log('Error: ', err.json) - } - }) - - it(`Get voterD1 last_vote_weight`, async () => { - try { - voterD1.last_vote_weight = await getAccountVoteWeight(voterD1.account); - //console.log('voterD1 last_vote_weight:', voterD1.last_vote_weight) - } catch (err) { - console.log('Error: ', err.json) - } - }) - - it(`bp1@dapixdev total_votes increased by voterD1 last_vote_weight`, async () => { - try { - prev_total_bp_votes = total_bp_votes; - total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); - //console.log('bp1@dapixdev total_votes:', total_bp_votes) - expect(total_bp_votes).to.equal(prev_total_bp_votes + voterD1.last_vote_weight) - } catch (err) { - console.log('Error: ', err) - } - }) - - it(`Un-register proxyD1 as a proxy`, async () => { - try { - const result = await proxyD1.sdk.genericAction('pushTransaction', { - action: 'unregproxy', - account: 'eosio', - data: { - fio_address: proxyD1.address, - actor: proxyD1.account, - max_fee: config.api.unregister_proxy.fee - } - }) - //console.log('Result: ', result) - expect(result.status).to.equal('OK') - } catch (err) { - console.log('Error: ', err.json) - } - }) - - it(`bp1@dapixdev total_votes decreased by voterD1 last_vote_weight`, async () => { - try { - prev_total_bp_votes = total_bp_votes; - total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); - //console.log('bp1@dapixdev total_votes:', total_bp_votes) - expect(total_bp_votes).to.equal(prev_total_bp_votes - voterD1.last_vote_weight) - } catch (err) { - console.log('Error: ', err) - } - }) - -}) - -describe('E. Test proxying to a user who is also proxying (should fail)', () => { +describe('C. Test proxying to a user who is also proxying (should fail)', () => { let proxyE1, proxyE2, voterE1, voterE2 it(`Create users`, async () => { @@ -1299,7 +846,7 @@ describe('E. Test proxying to a user who is also proxying (should fail)', () => }) -describe('F. last_voting_weight not updated when paying fee for register proxy (fixed bug MAS-1539)', () => { +describe('D. last_voting_weight not updated when paying fee for register/unregister proxy (fixed bug MAS-1539)', () => { let proxyF1, voterF1, original_last_vote_weight it(`Create users`, async () => { @@ -1320,7 +867,7 @@ describe('F. last_voting_weight not updated when paying fee for register proxy ( ], fio_address: proxyF1.address, actor: proxyF1.account, - max_fee: config.api.vote_producer.fee + max_fee: config.maxFee } }) //console.log('Result: ', result) @@ -1348,11 +895,11 @@ describe('F. last_voting_weight not updated when paying fee for register proxy ( data: { fio_address: proxyF1.address, actor: proxyF1.account, - max_fee: config.api.register_proxy.fee + max_fee: config.maxFee } }) //console.log('Result: ', result) - //console.log('config.api.register_proxy.fee: ', config.api.register_proxy.fee/config.BILLION) + //console.log('register_proxy_fee: ', register_proxy_fee/config.BILLION) expect(result.status).to.equal('OK') } catch (err) { console.log('Error: ', err) @@ -1368,15 +915,44 @@ describe('F. last_voting_weight not updated when paying fee for register proxy ( } }) - it(`Fixed in Gemini: proxyF1 last_vote_weight <> original_last_vote_weight - register_proxy_fee `, async () => { + it(`Expect: proxyF1 last_vote_weight = original_last_vote_weight - register_proxy_fee (fixed in Gemini)`, async () => { //console.log('proxyF1 original_last_vote_weight: ', original_last_vote_weight/config.BILLION) - //console.log('config.api.register_proxy.fee: ', config.api.register_proxy.fee/config.BILLION) + //console.log('register_proxy_fee: ', register_proxy_fee/config.BILLION) //console.log('proxyF1 last_vote_weight: ', proxyF1.last_vote_weight/config.BILLION) - expect(proxyF1.last_vote_weight).to.equal(original_last_vote_weight - config.api.register_proxy.fee) + expect(proxyF1.last_vote_weight).to.equal(original_last_vote_weight - register_proxy_fee) + }) + + it(`Un-register proxyF1 as a proxy`, async () => { + try { + const result = await proxyF1.sdk.genericAction('pushTransaction', { + action: 'unregproxy', + account: 'eosio', + data: { + fio_address: proxyF1.address, + actor: proxyF1.account, + max_fee: config.maxFee + } + }) + //console.log('Result: ', result) + //console.log('register_proxy_fee: ', register_proxy_fee/config.BILLION) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err) + } }) + + it.skip(`(BUG BD-2317) Expect: proxyF1 last_vote_weight = original_last_vote_weight - unregister_proxy_fee `, async () => { + original_last_vote_weight = proxyF1.last_vote_weight + proxyF1.last_vote_weight = await getAccountVoteWeight(proxyF1.account); + console.log('proxyF1 original_last_vote_weight: ', original_last_vote_weight/config.BILLION) + console.log('unregister_proxy_fee: ', unregister_proxy_fee/config.BILLION) + console.log('proxyF1 last_vote_weight: ', proxyF1.last_vote_weight/config.BILLION) + expect(proxyF1.last_vote_weight).to.equal(original_last_vote_weight - unregister_proxy_fee) + }) + }) -describe('G. Test multiple users proxying and unproxying votes to same proxy', () => { +describe('E. Test multiple users proxying and unproxying votes to same proxy', () => { let proxyG1, voterG1, voterG2, voterG3, voterG4, total_bp_votes it(`Create users`, async () => { @@ -1666,7 +1242,7 @@ describe('G. Test multiple users proxying and unproxying votes to same proxy', ( }) -describe('FIP-9: G.2 Test vote_producer with and without FIO Address', () => { +describe('E.2 Test vote_producer with and without FIO Address (FIP-9)', () => { let voterG3, voterG4, voterG5, voterG6, total_bp_votes, bundleCount, balance it(`Create users`, async () => { @@ -2139,7 +1715,7 @@ describe('FIP-9: G.2 Test vote_producer with and without FIO Address', () => { }) -describe('FIP-9: G.3 Test proxy_vote with and without FIO Address', () => { +describe('E.3 Test proxy_vote with and without FIO Address (FIP-9)', () => { let proxyG1, voterG7, voterG8, voterG9, voterG10, total_bp_votes, bundleCount, balance it(`Create users`, async () => { @@ -2696,7 +2272,7 @@ describe('FIP-9: G.3 Test proxy_vote with and without FIO Address', () => { }) -describe('Fixed in Gemini: H. When a user proxies their vote, the total_voted_fio increases by 2x their vote strength (Fixed: MAS-1489)', () => { +describe('F. When a user proxies their vote, the total_voted_fio increases by 2x their vote strength (Fixed in Gemini: MAS-1489)', () => { let proxyH1, voterH1, total_voted_fio, original_total_voted_fio it(`Create users`, async () => { @@ -2825,7 +2401,7 @@ describe('Fixed in Gemini: H. When a user proxies their vote, the total_voted_fi }) -describe('H. Confirm voter data is returned with get_account', () => { +describe('G. Confirm voter data is returned with get_account', () => { let voterH1 it(`Create users`, async () => { @@ -2887,7 +2463,7 @@ describe('H. Confirm voter data is returned with get_account', () => { }) -describe(`Test proxy re-vote of proxy, re-proxy of voter`, () => { +describe(`H. Test proxy re-vote of proxy, re-proxy of voter`, () => { let user1, proxyA1, total_voted_fio, total_bp_votes @@ -3088,7 +2664,7 @@ describe(`Test proxy re-vote of proxy, re-proxy of voter`, () => { }) -describe(`Test impact on total_voted_fio when User 1 votes then proxies their votes`, () => { +describe(`I. Test impact on total_voted_fio when User 1 votes then proxies their votes`, () => { let user1, proxyA1, total_voted_fio, total_bp_votes @@ -3250,7 +2826,7 @@ describe(`Test impact on total_voted_fio when User 1 votes then proxies their vo }) -describe(`Test total_voted_fio when user votes for proxy`, () => { +describe(`J. Test total_voted_fio when user votes for proxy`, () => { let user1, proxyA1, total_voted_fio, total_bp_votes @@ -3487,7 +3063,7 @@ describe(`Test total_voted_fio when user votes for proxy`, () => { }) -describe(`BD-2028: regproxy results in faulty record in voters table if account already has a voteproducer record`, () => { +describe(`K. regproxy results in faulty record in voters table if account already has a voteproducer record (BD-2028)`, () => { let proxyA1 From 27e20a497dfbf726e759b816aa5c098a710accf5 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 18 Jan 2021 18:18:49 -0700 Subject: [PATCH 41/76] Tests for BD-2269 and 2270 --- tests/tpid.js | 250 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/vote.js | 5 +- 2 files changed, 253 insertions(+), 2 deletions(-) diff --git a/tests/tpid.js b/tests/tpid.js index c5f6dd7f..7068e838 100644 --- a/tests/tpid.js +++ b/tests/tpid.js @@ -797,3 +797,253 @@ describe(`C. User that has proxied their votes is sent FIO with TPID registered }) + +describe(`L. User that is auto proxied registers as proxy`, () => { + + let proxy1, user1 + + it(`Create users`, async () => { + proxy1 = await newUser(faucet); + user1 = await newUser(faucet); + user1.address2 = generateFioAddress(user1.domain, 5) + }) + + it(`Register proxy1 as a proxy`, async () => { + try { + const result = await proxy1.sdk.genericAction('pushTransaction', { + action: 'regproxy', + account: 'eosio', + data: { + fio_address: proxy1.address, + actor: proxy1.account, + max_fee: config.maxFee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + expect(err).to.equal('null') + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it(`Register user1.address2 with proxy1 as TPID (valid tpid)`, async () => { + const result = await user1.sdk.genericAction('registerFioAddress', { + fioAddress: user1.address2, + maxFee: config.maxFee, + technologyProviderId: proxy1.address + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + }) + + it(`Wait a few seconds.`, async () => { await timeout(6000) }) + + it('Confirm user1 is_auto_proxy = 1', async () => { + let inVotersTable; + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: true, + show_payer: false + } + inVotersTable = false; + voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voter); + for (voter in voters.rows) { + if (voters.rows[voter].owner == user1.account) { + inVotersTable = true; + break; + } + } + expect(voters.rows[voter].is_auto_proxy).to.equal(1); + expect(inVotersTable).to.equal(true) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Register user1 as a proxy`, async () => { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'regproxy', + account: 'eosio', + data: { + fio_address: user1.address, + actor: user1.account, + max_fee: config.maxFee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + expect(err).to.equal('null') + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it.skip('(BUG BD-2269) Confirm user1: is_proxy = 1, is_auto_proxy = 0', async () => { + let inVotersTable; + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: true, + show_payer: false + } + inVotersTable = false; + voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voter); + for (voter in voters.rows) { + if (voters.rows[voter].owner == user1.account) { + inVotersTable = true; + break; + } + } + expect(voters.rows[voter].is_auto_proxy).to.equal(0); + expect(voters.rows[voter].is_proxy).to.equal(1); + expect(inVotersTable).to.equal(true) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) + + +describe(`M. User that is auto proxied votes for proxy. Confirm is_auto_proxy is reset to 0`, () => { + + let proxy1, user1 + + it(`Create users`, async () => { + proxy1 = await newUser(faucet); + user1 = await newUser(faucet); + user1.address2 = generateFioAddress(user1.domain, 5) + }) + + it(`Register proxy1 as a proxy`, async () => { + try { + const result = await proxy1.sdk.genericAction('pushTransaction', { + action: 'regproxy', + account: 'eosio', + data: { + fio_address: proxy1.address, + actor: proxy1.account, + max_fee: config.maxFee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + expect(err).to.equal('null') + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + + it(`Register user1.address2 with proxy1 as TPID (valid tpid)`, async () => { + const result = await user1.sdk.genericAction('registerFioAddress', { + fioAddress: user1.address2, + maxFee: config.maxFee, + technologyProviderId: proxy1.address + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + }) + + it('Confirm user1 is_auto_proxy = 1', async () => { + let inVotersTable; + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: true, + show_payer: false + } + inVotersTable = false; + voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voter); + for (voter in voters.rows) { + if (voters.rows[voter].owner == user1.account) { + inVotersTable = true; + break; + } + } + expect(voters.rows[voter].is_auto_proxy).to.equal(1); + expect(inVotersTable).to.equal(true) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`user1 votes for bp1@dapixdev`, async () => { + try { + const result = await user1.sdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + "producers": [ + 'bp1@dapixdev' + ], + fio_address: user1.address, + actor: user1.account, + max_fee: config.maxFee + } + }) + //console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error: ', err.json) + expect(err).to.equal('null') + } + }) + + it.skip('(BUG BD-2270) Confirm user1: is_auto_proxy = 0', async () => { + let inVotersTable; + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: true, + show_payer: false + } + inVotersTable = false; + voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voter); + for (voter in voters.rows) { + if (voters.rows[voter].owner == user1.account) { + inVotersTable = true; + break; + } + } + expect(voters.rows[voter].is_auto_proxy).to.equal(0); + expect(inVotersTable).to.equal(true) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) + diff --git a/tests/vote.js b/tests/vote.js index 1211383b..459cb62e 100644 --- a/tests/vote.js +++ b/tests/vote.js @@ -3063,7 +3063,7 @@ describe(`J. Test total_voted_fio when user votes for proxy`, () => { }) -describe(`K. regproxy results in faulty record in voters table if account already has a voteproducer record (BD-2028)`, () => { +describe(`K. regproxy results in faulty record in voters table if account already has a voteproducer record (fixed BD-2028)`, () => { let proxyA1 @@ -3173,4 +3173,5 @@ describe(`K. regproxy results in faulty record in voters table if account alread } }) -}) \ No newline at end of file +}) + From 18c286f9ebf2b5781ec8ce95dd7fbcf89ecca2a0 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Tue, 19 Jan 2021 20:23:16 -0700 Subject: [PATCH 42/76] Integrate fixes for BD-2308 --- config.js | 2 +- index.js | 2 +- tests/addbundles.js | 4 ++-- tests/testnet-smoketest.js | 43 +++++++++++++++++++++++--------------- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/config.js b/config.js index 8da3dbe2..85642f7e 100644 --- a/config.js +++ b/config.js @@ -1,5 +1,5 @@ const TESTURL = 'http://localhost:8889' // Localhost -//const TESTURL = 'http://dev2.fio.dev:8889' // DEV +//const TESTURL = 'http://44.234.45.7:8889' // DEV1 //const TESTURL = 'http://44.238.153.162:8889' // Devnet //const TESTURL = 'http://testnet.fioprotocol.io' // Testnet //const TESTURL = 'https://fio.greymass.com' // Mainnet diff --git a/index.js b/index.js index c5ea9640..5332682f 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,7 @@ describe('TEST SUITE', () => { require('./tests/transfer-locked-tokens-account-tests.js'); // FIP-6 tests of generic account functionality require('./tests/addbundles.js'); // FIP-11.a require('./tests/tpid.js'); - require('./tests/clio.js'); // FIP-16 + //require('./tests/clio.js'); // FIP-16 require('./tests/testnet-smoketest.js'); // Testnet smoketest. By default runs against local build. diff --git a/tests/addbundles.js b/tests/addbundles.js index 9780e36b..7447528c 100644 --- a/tests/addbundles.js +++ b/tests/addbundles.js @@ -104,7 +104,7 @@ describe('************************** addbundles.js ************************** \n } }) - it(`(${testType}) BUG BD-2308 (when called with API) Add bundles with ${bundleSets} sets for FIO Address owned by other user`, async () => { + it(`(${testType}) Add bundles with ${bundleSets} sets for FIO Address owned by other user (fixed in BD-2308)`, async () => { if (testType == 'sdk') { try { const result = await user1.sdk.genericAction('addBundledTransactions', { @@ -335,7 +335,7 @@ describe('B. Add 3 sets of bundled transactions for FIO Address owned by other u } }) - it(`(${testType}) BUG BD-2308 (when called with API) user1 run addbundles with ${bundleSets} sets for FIO Address owned by user2`, async () => { + it(`(${testType}) user1 run addbundles with ${bundleSets} sets for FIO Address owned by user2 (fixed in BD-2308)`, async () => { if (testType == 'sdk') { try { const result = await user1.sdk.genericAction('addBundledTransactions', { diff --git a/tests/testnet-smoketest.js b/tests/testnet-smoketest.js index 50c22ed6..124dcaa8 100644 --- a/tests/testnet-smoketest.js +++ b/tests/testnet-smoketest.js @@ -392,12 +392,12 @@ describe('B. Testing domain actions', () => { expect(result.fee_collected).to.be.a('number') }) - it.skip(`BUG BD-2308 getFee for addBundledTransactions`, async () => { + it(`getFee for addBundledTransactions`, async () => { try { const result = await fioSdk2.sdk.genericAction('getFeeForAddBundledTransactions', { fioAddress: newFioAddress }) - console.log('Result: ', result) + //console.log('Result: ', result) expect(result).to.have.all.keys('fee') expect(result.fee).to.be.a('number') } catch (err) { @@ -406,14 +406,14 @@ describe('B. Testing domain actions', () => { } }) - it.skip(`BUG BD-2308 add Bundled Transactions`, async () => { + it(`add Bundled Transactions`, async () => { try { const result = await fioSdk2.sdk.genericAction('addBundledTransactions', { fioAddress: newFioAddress, bundleSets: defaultBundledSets, maxFee: defaultFee }) - console.log('Result: ', result) + //console.log('Result: ', result) expect(result).to.have.all.keys('status', 'fee_collected') expect(result.status).to.be.a('string') expect(result.fee_collected).to.be.a('number') @@ -423,6 +423,8 @@ describe('B. Testing domain actions', () => { } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`(push_transaction) user1 run addbundles with sets for FIO Address owned by user2`, async () => { try { const result = await fioSdk2.sdk.genericAction('pushTransaction', { @@ -710,20 +712,27 @@ describe('C. Request funds, approve and send', () => { expect(result.fee_collected).to.be.a('number') }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) + it(`getPendingFioRequests`, async () => { - await timeout(4000) - const result = await fioSdk.sdk.genericAction('getPendingFioRequests', {}) - expect(result).to.have.all.keys('requests', 'more') - expect(result.requests).to.be.a('array') - expect(result.more).to.be.a('number') - const pendingReq = result.requests.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) - expect(pendingReq).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'time_stamp', 'content') - expect(pendingReq.fio_request_id).to.be.a('number') - expect(pendingReq.fio_request_id).to.equal(requestId) - expect(pendingReq.payer_fio_address).to.be.a('string') - expect(pendingReq.payer_fio_address).to.equal(testFioAddressName) - expect(pendingReq.payee_fio_address).to.be.a('string') - expect(pendingReq.payee_fio_address).to.equal(testFioAddressName2) + try { + const result = await fioSdk.sdk.genericAction('getPendingFioRequests', {}) + //console.log('Result: ', result) + expect(result).to.have.all.keys('requests', 'more') + expect(result.requests).to.be.a('array') + expect(result.more).to.be.a('number') + const pendingReq = result.requests.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) + expect(pendingReq).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'time_stamp', 'content') + expect(pendingReq.fio_request_id).to.be.a('number') + expect(pendingReq.fio_request_id).to.equal(requestId) + expect(pendingReq.payer_fio_address).to.be.a('string') + expect(pendingReq.payer_fio_address).to.equal(testFioAddressName) + expect(pendingReq.payee_fio_address).to.be.a('string') + expect(pendingReq.payee_fio_address).to.equal(testFioAddressName2) + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } }) it(`recordObtData`, async () => { From a3de7020807fb6a5720eeaae3f76f18512685f4e Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Fri, 22 Jan 2021 14:40:28 -0700 Subject: [PATCH 43/76] Additional OBT and reqeust getter tests --- index.js | 1 + tests/fio-request.js | 577 +++++++++++++++++++++++++++++++++- tests/record-obt-data.js | 40 ++- tests/register-fio-address.js | 79 +++++ 4 files changed, 674 insertions(+), 23 deletions(-) create mode 100644 tests/register-fio-address.js diff --git a/index.js b/index.js index 5332682f..35d9db43 100644 --- a/index.js +++ b/index.js @@ -12,6 +12,7 @@ describe('TEST SUITE', () => { require('./tests/producer.js'); // v1.0.x require('./tests/pushtransaction.js'); // v1.0.x require('./tests/ram2.js'); // v1.0.x //Eric to update to remove clio + require('./tests/register-fio-address.js'); require('./tests/register-fio-domain.js'); // v1.0.x require('./tests/transfer-tokens.js'); // v1.0.x require('./tests/vote.js'); // v1.0.x diff --git a/tests/fio-request.js b/tests/fio-request.js index 3644bfea..757710c3 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -8,7 +8,7 @@ before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); }) -describe(`************************** fio-request.js ************************** \n A. Send fio request from userA1 to userA2`, () => { +describe(`************************** fio-request.js ************************** \n A. Send fio request from userA1 to userA2. userA2 responds with OBT Record`, () => { let userA1, userA2, requestId const payment = 5000000000 // 5 FIO @@ -59,6 +59,7 @@ describe(`************************** fio-request.js ************************** \ hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? offlineUrl: '' }) + requestId = result.fio_request_id //console.log('Result: ', result) expect(result.status).to.equal('requested') } catch (err) { @@ -67,38 +68,147 @@ describe(`************************** fio-request.js ************************** \ } }) - it(`get_sent_fio_requests for userA1`, async () => { + it(`get_sent_fio_requests for userA1 (payee)`, async () => { try { - const result = await userA1.sdk.genericAction('getSentFioRequests', { + const result = await userA1.sdk.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result); + //console.log('content: ', result.requests[0].content); + expect(result.requests[0].fio_request_id).to.equal(requestId); + expect(result.requests[0].payer_fio_address).to.equal(userA2.address); + expect(result.requests[0].payee_fio_address).to.equal(userA1.address); + expect(result.requests[0].payer_fio_public_key).to.equal(userA2.publicKey); + expect(result.requests[0].payee_fio_public_key).to.equal(userA1.publicKey); + expect(result.requests[0].status).to.equal('requested'); + expect(result.requests[0].content.memo).to.equal(requestMemo); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`get_sent_fio_requests for userA2 (payer). Expect 'No FIO Requests'`, async () => { + try { + const result = await userA2.sdk.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result); + //console.log('content: ', result.requests[0].content); + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.message).to.equal('No FIO Requests') + } + }) + + it(`get_pending_fio_requests for userA1 (payee). Expect 'No FIO Requests'`, async () => { + try { + const result = await userA1.sdk.genericAction('getPendingFioRequests', { + limit: '', + offset: '' + }) + console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.message).to.equal('No FIO Requests') + } + }) + + it(`get_pending_fio_requests for userA2 (payer)`, async () => { + try { + const result = await userA2.sdk.genericAction('getPendingFioRequests', { limit: '', offset: '' }) //console.log('result: ', result) //console.log('content: ', result.requests[0].content) - requestId = result.requests[0].fio_request_id - expect(result.requests[0].content.memo).to.equal(requestMemo) + expect(result.requests[0].fio_request_id).to.equal(requestId); + expect(result.requests[0].payer_fio_address).to.equal(userA2.address); + expect(result.requests[0].payee_fio_address).to.equal(userA1.address); + expect(result.requests[0].payer_fio_public_key).to.equal(userA2.publicKey); + expect(result.requests[0].payee_fio_public_key).to.equal(userA1.publicKey); + expect(result.requests[0].content.memo).to.equal(requestMemo); } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) } }) - it(`get_pending_fio_requests for userA2`, async () => { + it(`get_cancelled_fio_requests for userA1 (payee). Expect 'No FIO Requests'`, async () => { try { - const result = await userA2.sdk.genericAction('getPendingFioRequests', { + const result = await userA1.sdk.genericAction('getCancelledFioRequests', { + limit: '', + offset: '' + }) + console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.message).to.equal('No FIO Requests') + } + }) + + it(`get_cancelled_fio_requests for userA2 (payer). Expect 'No FIO Requests'`, async () => { + try { + const result = await userA1.sdk.genericAction('getCancelledFioRequests', { limit: '', offset: '' }) + console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.message).to.equal('No FIO Requests') + } + }) + + it(`Bahamas TODO: update after added to SDK to include memo check. get_received_fio_requests for userA2 (payer)`, async () => { + try { + const json = { + fio_public_key: userA2.publicKey, + limit: 100, + offset: 0 + } + result = await callFioApi("get_received_fio_requests", json); //console.log('result: ', result) //console.log('content: ', result.requests[0].content) - expect(result.requests[0].fio_request_id).to.equal(requestId) - expect(result.requests[0].content.memo).to.equal(requestMemo) + expect(result.requests[0].fio_request_id).to.equal(requestId); + expect(result.requests[0].payer_fio_address).to.equal(userA2.address); + expect(result.requests[0].payee_fio_address).to.equal(userA1.address); + expect(result.requests[0].payer_fio_public_key).to.equal(userA2.publicKey); + expect(result.requests[0].payee_fio_public_key).to.equal(userA1.publicKey); + expect(result.requests[0].status).to.equal('requested'); + //expect(result.requests[0].content.memo).to.equal(requestMemo); } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) } }) + it(`get_received_fio_requests for userA1 (payee). Expect 'No FIO Requests'`, async () => { + try { + const json = { + fio_public_key: userA1.publicKey, + limit: 100, + offset: 0 + } + result = await callFioApi("get_received_fio_requests", json); + console.log('result: ', result.json) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err.response) + expect(err.response.body.message).to.equal('No FIO Requests') + } + }) + it('userA2 getPublicAddress for userA1 BTC', async () => { try { const result = await userA2.sdk.genericAction('getPublicAddress', { @@ -173,6 +283,142 @@ describe(`************************** fio-request.js ************************** \ console.log('Error: ', err) expect(err).to.equal(null) } + }) + + it.skip(`BUG (bahamas): BD-2306 get_sent_fio_requests for userA1 (payee)`, async () => { + try { + const result = await userA1.sdk.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result); + //console.log('content: ', result.requests[0].content); + expect(result.requests[0].fio_request_id).to.equal(requestId); + expect(result.requests[0].payer_fio_address).to.equal(userA2.address); + expect(result.requests[0].payee_fio_address).to.equal(userA1.address); + expect(result.requests[0].payer_fio_public_key).to.equal(userA2.publicKey); + expect(result.requests[0].payee_fio_public_key).to.equal(userA1.publicKey); + expect(result.requests[0].status).to.equal('sent_to_blockchain'); + expect(result.requests[0].content.memo).to.equal(requestMemo); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`get_sent_fio_requests for userA2 (payer). Expect 'No FIO Requests'`, async () => { + try { + const result = await userA2.sdk.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result); + //console.log('content: ', result.requests[0].content); + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.message).to.equal('No FIO Requests') + } + }) + + it(`get_pending_fio_requests for userA1 (payee). Expect 'No FIO Requests'`, async () => { + try { + const result = await userA1.sdk.genericAction('getPendingFioRequests', { + limit: '', + offset: '' + }) + console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.message).to.equal('No FIO Requests') + } + }) + + it(`get_pending_fio_requests for userA2 (payer)`, async () => { + try { + const result = await userA2.sdk.genericAction('getPendingFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.message).to.equal('No FIO Requests') + } + }) + + it(`get_cancelled_fio_requests for userA1 (payee). Expect 'No FIO Requests'`, async () => { + try { + const result = await userA1.sdk.genericAction('getCancelledFioRequests', { + limit: '', + offset: '' + }) + console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.message).to.equal('No FIO Requests') + } + }) + + it(`get_cancelled_fio_requests for userA2 (payer). Expect 'No FIO Requests'`, async () => { + try { + const result = await userA2.sdk.genericAction('getCancelledFioRequests', { + limit: '', + offset: '' + }) + console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.message).to.equal('No FIO Requests') + } + }) + + it(`Bahamas TODO: update after added to SDK to include memo check. get_received_fio_requests for userA2 (payer)`, async () => { + try { + const json = { + fio_public_key: userA2.publicKey, + limit: 100, + offset: 0 + } + result = await callFioApi("get_received_fio_requests", json); + //console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result.requests[0].fio_request_id).to.equal(requestId); + expect(result.requests[0].payer_fio_address).to.equal(userA2.address); + expect(result.requests[0].payee_fio_address).to.equal(userA1.address); + expect(result.requests[0].payer_fio_public_key).to.equal(userA2.publicKey); + expect(result.requests[0].payee_fio_public_key).to.equal(userA1.publicKey); + expect(result.requests[0].status).to.equal('sent_to_blockchain'); + //expect(result.requests[0].content.memo).to.equal(requestMemo); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`get_received_fio_requests for userA1 (payee). Expect 'No FIO Requests'`, async () => { + try { + const json = { + fio_public_key: userA1.publicKey, + limit: 100, + offset: 0 + } + result = await callFioApi("get_received_fio_requests", json); + console.log('result: ', result.json) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err.response) + expect(err.response.body.message).to.equal('No FIO Requests') + } }) it(`getObtData for userA2`, async () => { @@ -184,7 +430,13 @@ describe(`************************** fio-request.js ************************** \ }) //console.log('result: ', result) //console.log('content: ', result.obt_data_records[0].content) - expect(result.obt_data_records[0].content.memo).to.equal(obtMemo) + expect(result.obt_data_records[0].fio_request_id).to.equal(requestId); + expect(result.obt_data_records[0].payer_fio_address).to.equal(userA2.address); + expect(result.obt_data_records[0].payee_fio_address).to.equal(userA1.address); + expect(result.obt_data_records[0].payer_fio_public_key).to.equal(userA2.publicKey); + expect(result.obt_data_records[0].payee_fio_public_key).to.equal(userA1.publicKey); + expect(result.obt_data_records[0].status).to.equal('sent_to_blockchain'); + expect(result.obt_data_records[0].content.memo).to.equal(obtMemo); } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) @@ -200,7 +452,13 @@ describe(`************************** fio-request.js ************************** \ }) //console.log('result: ', result) //console.log('content: ', result.obt_data_records[0].content) - expect(result.obt_data_records[0].content.memo).to.equal(obtMemo) + expect(result.obt_data_records[0].fio_request_id).to.equal(requestId); + expect(result.obt_data_records[0].payer_fio_address).to.equal(userA2.address); + expect(result.obt_data_records[0].payee_fio_address).to.equal(userA1.address); + expect(result.obt_data_records[0].payer_fio_public_key).to.equal(userA2.publicKey); + expect(result.obt_data_records[0].payee_fio_public_key).to.equal(userA1.publicKey); + expect(result.obt_data_records[0].status).to.equal('sent_to_blockchain'); + expect(result.obt_data_records[0].content.memo).to.equal(obtMemo); } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) @@ -829,7 +1087,7 @@ describe(`C. cancel_funds_request with bundles remaining`, () => { } }) - it(`Call cancel_funds_request to cancel request in pending state`, async () => { + it(`userA1 (payee) Call cancel_funds_request to cancel request in pending state`, async () => { try{ const result = await userA1.sdk.genericAction('cancelFundsRequest', { fioRequestId: userA1RequestId, @@ -846,7 +1104,7 @@ describe(`C. cancel_funds_request with bundles remaining`, () => { } }) - it(`Verify request was cancelled: get_sent_fio_requests for userA1 returns 1 request with status 'cancelled'`, async () => { + it(`Verify request was cancelled: get_sent_fio_requests for userA1 (payee) returns 1 request with status 'cancelled'`, async () => { try { const result = await userA1.sdk.genericAction('getSentFioRequests', { limit: '', @@ -854,14 +1112,33 @@ describe(`C. cancel_funds_request with bundles remaining`, () => { }) //console.log('result: ', result) expect(result.requests[0].fio_request_id).to.equal(userA1RequestId); - expect(result.requests[0].content.memo).to.equal(requestMemo); + expect(result.requests[0].payer_fio_address).to.equal(userA2.address); + expect(result.requests[0].payee_fio_address).to.equal(userA1.address); + expect(result.requests[0].payer_fio_public_key).to.equal(userA2.publicKey); + expect(result.requests[0].payee_fio_public_key).to.equal(userA1.publicKey); expect(result.requests[0].status).to.equal('cancelled'); + expect(result.requests[0].content.memo).to.equal(requestMemo); } catch (err) { console.log('Error: ', err); expect(err).to.equal(null); } }) + it(`get_sent_fio_requests for userA2 (payer). Expect 'No FIO Requests'`, async () => { + try { + const result = await userA2.sdk.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result); + //console.log('content: ', result.requests[0].content); + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.message).to.equal('No FIO Requests') + } + }) + it(`Verify request was cancelled: get_pending_fio_requests for userA2 returns: ${config.error.noFioRequests}`, async () => { try { const result = await userA2.sdk.genericAction('getPendingFioRequests', { @@ -876,7 +1153,21 @@ describe(`C. cancel_funds_request with bundles remaining`, () => { } }) - it(`Verify request was cancelled: get_cancelled_fio_requests returns 1 request with status 'cancelled'`, async () => { + it(`get_pending_fio_requests for userA1 returns: ${config.error.noFioRequests}`, async () => { + try { + const result = await userA1.sdk.genericAction('getPendingFioRequests', { + limit: '', + offset: '' + }) + console.log('result: ', result); + expect(result).to.equal(null); + } catch (err) { + //console.log('Error: ', err.json); + expect(err.json.message).to.equal(config.error.noFioRequests); + } + }) + + it(`Verify request was cancelled: get_cancelled_fio_requests for userA1 (payee) returns 1 request with status 'cancelled'`, async () => { try { const json = { "fio_public_key": userA1.publicKey @@ -884,10 +1175,69 @@ describe(`C. cancel_funds_request with bundles remaining`, () => { result = await callFioApi("get_cancelled_fio_requests", json); //console.log('Result: ', result); expect(result.requests[0].fio_request_id).to.equal(userA1RequestId); + expect(result.requests[0].payer_fio_address).to.equal(userA2.address); + expect(result.requests[0].payee_fio_address).to.equal(userA1.address); + expect(result.requests[0].payer_fio_public_key).to.equal(userA2.publicKey); + expect(result.requests[0].payee_fio_public_key).to.equal(userA1.publicKey); expect(result.requests[0].status).to.equal('cancelled'); } catch (err) { - //console.log('Error', err.error.message) - expect(err.error.message).to.equal(config.error.noFioRequests) + console.log('Error: ', err); + expect(err).to.equal(null); + } + }) + + it(`get_cancelled_fio_requests for userA2 (payer). Expect 'No FIO Requests'`, async () => { + try { + const result = await userA2.sdk.genericAction('getCancelledFioRequests', { + limit: '', + offset: '' + }) + console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.message).to.equal('No FIO Requests') + } + }) + + it(`get_received_fio_requests for userA1 (payee). Expect 'No FIO Requests'`, async () => { + try { + const json = { + fio_public_key: userA1.publicKey, + limit: 100, + offset: 0 + } + result = await callFioApi("get_received_fio_requests", json); + console.log('result: ', result.json) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err.response) + expect(err.response.body.message).to.equal('No FIO Requests') + } + }) + + it(`Bahamas TODO: update after added to SDK to include memo check. get_received_fio_requests for userA2 (payer)`, async () => { + try { + const json = { + fio_public_key: userA2.publicKey, + limit: 100, + offset: 0 + } + result = await callFioApi("get_received_fio_requests", json); + //console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result.requests[0].fio_request_id).to.equal(userA1RequestId); + expect(result.requests[0].payer_fio_address).to.equal(userA2.address); + expect(result.requests[0].payee_fio_address).to.equal(userA1.address); + expect(result.requests[0].payer_fio_public_key).to.equal(userA2.publicKey); + expect(result.requests[0].payee_fio_public_key).to.equal(userA1.publicKey); + expect(result.requests[0].status).to.equal('cancelled'); + //expect(result.requests[0].content.memo).to.equal(requestMemo); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) } }) @@ -2040,3 +2390,196 @@ describe.skip(`H. Records Performance Testing`, () => { } }) }) + +describe(`I. reject_funds_request: Check all getters after`, () => { + let userA1, userA2, requestId + const payment = 5000000000 // 5 FIO + const requestMemo = 'Memo in the initial request' + + it(`Create users`, async () => { + userA1 = await newUser(faucet); + userA2 = await newUser(faucet); + }) + + it(`userA1 requests funds from userA2`, async () => { + try { + const result = await userA1.sdk.genericAction('requestFunds', { + payerFioAddress: userA2.address, + payeeFioAddress: userA1.address, + payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', + amount: payment, + chainCode: 'BTC', + tokenCode: 'BTC', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: userA2.publicKey, + technologyProviderId: '', + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + requestId = result.fio_request_id + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`userA2 rejects funds request`, async () => { + try{ + const result = await userA2.sdk.genericAction('pushTransaction', { + action: 'rejectfndreq', + account: 'fio.reqobt', + data: { + "fio_request_id": requestId, + "max_fee": config.maxFee, + "tpid": '', + "actor": userA2.account + } + }) + //console.log('Result:', result) + expect(result.status).to.equal('request_rejected') + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`get_sent_fio_requests for userA1 (payee)`, async () => { + try { + const result = await userA1.sdk.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result); + //console.log('content: ', result.requests[0].content); + expect(result.requests[0].fio_request_id).to.equal(requestId); + expect(result.requests[0].payer_fio_address).to.equal(userA2.address); + expect(result.requests[0].payee_fio_address).to.equal(userA1.address); + expect(result.requests[0].payer_fio_public_key).to.equal(userA2.publicKey); + expect(result.requests[0].payee_fio_public_key).to.equal(userA1.publicKey); + expect(result.requests[0].status).to.equal('rejected'); + expect(result.requests[0].content.memo).to.equal(requestMemo); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`get_sent_fio_requests for userA2 (payer). Expect 'No FIO Requests'`, async () => { + try { + const result = await userA2.sdk.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result); + //console.log('content: ', result.requests[0].content); + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.message).to.equal('No FIO Requests') + } + }) + + it(`get_pending_fio_requests for userA1 (payee). Expect 'No FIO Requests'`, async () => { + try { + const result = await userA1.sdk.genericAction('getPendingFioRequests', { + limit: '', + offset: '' + }) + console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.message).to.equal('No FIO Requests') + } + }) + + it(`get_pending_fio_requests for userA2 (payer). Expect 'No FIO Requests'`, async () => { + try { + const result = await userA2.sdk.genericAction('getPendingFioRequests', { + limit: '', + offset: '' + }) + console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.message).to.equal('No FIO Requests') + } + }) + + it(`get_cancelled_fio_requests for userA1 (payee). Expect 'No FIO Requests'`, async () => { + try { + const result = await userA1.sdk.genericAction('getCancelledFioRequests', { + limit: '', + offset: '' + }) + console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.message).to.equal('No FIO Requests') + } + }) + + it(`get_cancelled_fio_requests for userA2 (payer). Expect 'No FIO Requests'`, async () => { + try { + const result = await userA1.sdk.genericAction('getCancelledFioRequests', { + limit: '', + offset: '' + }) + console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.message).to.equal('No FIO Requests') + } + }) + + it(`Bahamas TODO: update after added to SDK to include memo check. get_received_fio_requests for userA2 (payer)`, async () => { + try { + const json = { + fio_public_key: userA2.publicKey, + limit: 100, + offset: 0 + } + result = await callFioApi("get_received_fio_requests", json); + //console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result.requests[0].fio_request_id).to.equal(requestId); + expect(result.requests[0].payer_fio_address).to.equal(userA2.address); + expect(result.requests[0].payee_fio_address).to.equal(userA1.address); + expect(result.requests[0].payer_fio_public_key).to.equal(userA2.publicKey); + expect(result.requests[0].payee_fio_public_key).to.equal(userA1.publicKey); + expect(result.requests[0].status).to.equal('rejected'); + //expect(result.requests[0].content.memo).to.equal(requestMemo); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`get_received_fio_requests for userA1 (payee). Expect 'No FIO Requests'`, async () => { + try { + const json = { + fio_public_key: userA1.publicKey, + limit: 100, + offset: 0 + } + result = await callFioApi("get_received_fio_requests", json); + console.log('result: ', result.json) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err.response) + expect(err.response.body.message).to.equal('No FIO Requests') + } + }) + +}) diff --git a/tests/record-obt-data.js b/tests/record-obt-data.js index 79ead9a0..93e8ea44 100644 --- a/tests/record-obt-data.js +++ b/tests/record-obt-data.js @@ -10,10 +10,10 @@ before(async () => { describe(`*********************** record-obt-data.js *********************** \n A. Test OBT DAta`, () => { - let userA1, userA2, userA2Balance + let userA1, userA2, userA2Balance, timeStamp const payment = 5000000000 // 5 FIO const requestMemo = 'Memo Test' - const obtMemo = 'Memo in OBT response to request' + const obtMemo = 'Memo in OBT payment' it(`Create users`, async () => { userA1 = await newUser(faucet); @@ -40,6 +40,7 @@ describe(`*********************** record-obt-data.js *********************** \n offLineUrl: '' }) //console.log('Result: ', result) + timeStamp = result.time_stamp expect(result.status).to.equal('sent_to_blockchain') } catch (err) { console.log('Error: ', err) @@ -47,15 +48,42 @@ describe(`*********************** record-obt-data.js *********************** \n } }) - it(`Confirm get_obt_data returns correct record for payee and payer`, async () => { + it(`get_obt_data for userA1 (payer)`, async () => { try { const result = await userA1.sdk.genericAction('getObtData', { limit: '', offset: '' }) - //console.log('result: ', result) - //console.log('content: ', result.requests[0].content) - expect(result.obt_data_records[0].content.memo).to.equal(obtMemo) + //console.log('result: ', result); + //console.log('content: ', result.obt_data_records[0].content); + expect(result.obt_data_records[0].fio_request_id).to.equal(0); + expect(result.obt_data_records[0].payer_fio_address).to.equal(userA1.address); + expect(result.obt_data_records[0].payee_fio_address).to.equal(userA2.address); + expect(result.obt_data_records[0].payer_fio_public_key).to.equal(userA1.publicKey); + expect(result.obt_data_records[0].payee_fio_public_key).to.equal(userA2.publicKey); + expect(result.obt_data_records[0].status).to.equal('sent_to_blockchain'); + expect(result.obt_data_records[0].content.memo).to.equal(obtMemo); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`get_obt_data for userA2 (payee)`, async () => { + try { + const result = await userA2.sdk.genericAction('getObtData', { + limit: '', + offset: '' + }) + //console.log('result: ', result); + //console.log('content: ', result.obt_data_records[0].content); + expect(result.obt_data_records[0].fio_request_id).to.equal(0); + expect(result.obt_data_records[0].payer_fio_address).to.equal(userA1.address); + expect(result.obt_data_records[0].payee_fio_address).to.equal(userA2.address); + expect(result.obt_data_records[0].payer_fio_public_key).to.equal(userA1.publicKey); + expect(result.obt_data_records[0].payee_fio_public_key).to.equal(userA2.publicKey); + expect(result.obt_data_records[0].status).to.equal('sent_to_blockchain'); + expect(result.obt_data_records[0].content.memo).to.equal(obtMemo); } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) diff --git a/tests/register-fio-address.js b/tests/register-fio-address.js new file mode 100644 index 00000000..677697e1 --- /dev/null +++ b/tests/register-fio-address.js @@ -0,0 +1,79 @@ +require('mocha') +const {expect} = require('chai') +const {newUser, getTestType, timeout, generateFioAddress, fetchJson} = require('../utils.js'); +const {FIOSDK } = require('@fioprotocol/fiosdk'); +const config = require('../config.js'); +const testType = getTestType(); + + +before(async () => { + faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); +}) + +describe(`************************** register-fio-address.js ************************** \n A. Renew address on private domain`, () => { + let user1, user2, expirationYear + + it(`Create users`, async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + + }) + + it(`set_fio_domain_public = true for user1.domain`, async () => { + try { + const result = await user1.sdk.genericAction('setFioDomainVisibility', { + fioDomain: user1.domain, + isPublic: true, + maxFee: config.maxFee, + technologyProviderId: '' + }) + //console.log('Result: ', result); + expect(result.status).to.equal('OK'); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null); + } + }) + + it(`user2 registers user2.address2 on user1.domain`, async () => { + user2.address2 = generateFioAddress(user1.domain, 5) + const result = await user2.sdk.genericAction('registerFioAddress', { + fioAddress: user2.address2, + maxFee: config.maxFee, + technologyProviderId: '' + }) + //console.log('Result: ', result) + expirationYear = parseInt(result.expiration.split('-',1)); + expect(result.status).to.equal('OK') + }) + + it(`set_fio_domain_public = false for user1.domain`, async () => { + try { + const result = await user1.sdk.genericAction('setFioDomainVisibility', { + fioDomain: user1.domain, + isPublic: false, + maxFee: config.maxFee, + technologyProviderId: '' + }) + //console.log('Result: ', result); + expect(result.status).to.equal('OK'); + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } + }) + + it(`user2 renews user2.address2 which is on user1's domain which is now private`, async () => { + const result = await user2.sdk.genericAction('renewFioAddress', { + fioAddress: user2.address2, + maxFee: config.maxFee + }) + //console.log('Result: ', result) + expect(parseInt(result.expiration.split('-',1))).to.equal(expirationYear + 1) + expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.expiration).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + }) + +}) \ No newline at end of file From 621c6864d6ecdfe90012ec4bd6aac4e040e2bb97 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 25 Jan 2021 11:59:49 -0700 Subject: [PATCH 44/76] Add request nuke code --- tests/bravo-migr-test.js | 122 +++++++++++++++++++++++++++++++++------ 1 file changed, 104 insertions(+), 18 deletions(-) diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index 83e6dd0d..93852ff5 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -240,24 +240,25 @@ describe(`************************** bravo-migr-test.js.js ********************* }) describe(`B. Perform single migrtrx to initialize migration`, () => { - it(`Call single migrtrx (bp1) and confirm you can still do Requests and OBTs`, async () => { - try { - const result = await callFioApiSigned('push_transaction', { - action: 'migrtrx', - account: 'fio.reqobt', - actor: bp1.account, - privKey: bp1.privateKey, - data: { - amount: 1, - actor: bp1.account - } - }) - //console.log('Result: ', result) - expect(result.transaction_id).to.exist - } catch (err) { - console.log('Error: ', err) - expect(err).to.equal(null) - } + + it(`Call single migrtrx (bp1) and confirm you can still do Requests and OBTs`, async () => { + try { + const result = await callFioApiSigned('push_transaction', { + action: 'migrtrx', + account: 'fio.reqobt', + actor: bp1.account, + privKey: bp1.privateKey, + data: { + amount: 20, + actor: bp1.account + } + }) + //console.log('Result: ', result) + expect(result.transaction_id).to.exist + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } }) it.skip('Call get_table_rows from fiotrxts (NEW table) and display', async () => { @@ -991,4 +992,89 @@ describe.skip(`J. Go through fioreqctxts (old table) and confirm each entry is i } }) +}) + +describe.skip(`Bravo fix: Call migrtrx until table data is nuked`, () => { + let isFinished = 0 + + it('Echo initial migrledgers table', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'migrledgers', + limit: 1000, + reverse: false, + show_payer: false + } + ledger = await callFioApi("get_table_rows", json); + console.log('migrledgers: ', ledger); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Call migrtrx (bp1) with amount = 10 until migrtrx is empty`, async () => { + while (!isFinished) { + try { + const result = await callFioApiSigned('push_transaction', { + action: 'migrtrx', + account: 'fio.reqobt', + actor: bp1.account, + privKey: bp1.privateKey, + data: { + amount: 10, + actor: bp1.account + } + }) + console.log('Result: ', result) + expect(result.transaction_id).to.exist + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + await timeout(2000); + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'fiotrxts', + limit: 1000, + reverse: false, + show_payer: false + } + fiotrxts = await callFioApi("get_table_rows", json); + isFinished = (fiotrxts.rows.length == 0); + //console.log('fiotrxts: ', fiotrxts) + console.log('Table rows count: ', fiotrxts.rows.length) + console.log('isFinished: ', isFinished); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + } + }) + + it('Echo final migrledgers table', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'migrledgers', + limit: 10, + reverse: false, + show_payer: false + } + ledger = await callFioApi("get_table_rows", json); + console.log('migrledgers: ', ledger); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + }) \ No newline at end of file From 821fda41c02005b260e28b44573002944ddfed36 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 25 Jan 2021 14:45:09 -0700 Subject: [PATCH 45/76] Update obt migration to use new table --- tests/bravo-migr-test.js | 2810 +++++++++++++++++++++++++++----------- 1 file changed, 1996 insertions(+), 814 deletions(-) diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index 93852ff5..c8c58841 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -42,11 +42,347 @@ before(async () => { }) -describe(`************************** bravo-migr-test.js.js ************************** \n A. Load Requests and OBTs`, () => { - let user1, user2, user3; +describe.skip(`************************** bravo-migr-test.js.js ************************** \n fiotrxts (original table) scripts`, () => { + + describe(`A. Load Requests and OBTs`, () => { + let user1, user2, user3; + let payment = 3000000000; + let requestMemo = 'asdf'; + let count = 5; + + it(`Create users`, async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + user3 = await newUser(faucet); + + //console.log('user1: ' + user1.account + ', ' + user1.privateKey + ', ' + user1.publicKey) + //console.log('user2: ' + user2.account + ', ' + user2.privateKey + ', ' + user2.publicKey) + //console.log('user3: ' + user3.account + ', ' + user3.privateKey + ', ' + user3.publicKey) + }) + + it(`${count}x - user1 requests funds from user2`, async () => { + for (i = 0; i < count; i++) { + try { + const result = await user1.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user1.address, + payeeTokenPublicAddress: user1.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) + + it(`${count}x - user2 requests funds from user1`, async () => { + for (i = 0; i < count; i++) { + try { + const result = await user2.sdk.genericAction('requestFunds', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payeeTokenPublicAddress: user2.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user1.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) + + it(`${count}x - user3 requests funds from user2, user2 rejects request`, async () => { + let requestId; + for (i = 0; i < count; i++) { + try { + const result = await user3.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user3.address, + payeeTokenPublicAddress: user3.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + requestId = result.fio_request_id; + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + + try { + const result = await user2.sdk.genericAction('pushTransaction', { + action: 'rejectfndreq', + account: 'fio.reqobt', + data: { + fio_request_id: requestId, + max_fee: config.api.cancel_funds_request.fee, + tpid: '', + actor: user2.account + } + }) + //console.log('Result:', result) + expect(result.status).to.equal('request_rejected') + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + } + }) + + it(`${count}x - user2 requests funds from user1, user 1 records OBT response`, async () => { + let requestId; + for (i = 0; i < count; i++) { + try { + const result = await user2.sdk.genericAction('requestFunds', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payeeTokenPublicAddress: user2.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user1.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + requestId = result.fio_request_id; + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + + try { + const result = await user1.sdk.genericAction('recordObtData', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payerTokenPublicAddress: user1.publicKey, + payeeTokenPublicAddress: user2.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: requestId, + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user2.publicKey, + memo: 'this is a test', + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) + + it(`${count}x user3 creates BTC OBT send record to user1`, async () => { + for (i = 0; i < count; i++) { + try { + const result = await user3.sdk.genericAction('recordObtData', { + payerFioAddress: user3.address, + payeeFioAddress: user1.address, + payerTokenPublicAddress: user3.publicKey, + payeeTokenPublicAddress: user1.publicKey, + amount: payment, + chainCode: "BTC", + tokenCode: "BTC", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user1.publicKey, + memo: 'this is a test', + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) + }) + + describe(`B. Perform single migrtrx to initialize migration`, () => { + + it(`Call single migrtrx (bp1) and confirm you can still do Requests and OBTs`, async () => { + try { + const result = await callFioApiSigned('push_transaction', { + action: 'migrtrx', + account: 'fio.reqobt', + actor: bp1.account, + privKey: bp1.privateKey, + data: { + amount: 20, + actor: bp1.account + } + }) + //console.log('Result: ', result) + expect(result.transaction_id).to.exist + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it.skip('Call get_table_rows from fiotrxts (NEW table) and display', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + console.log('requests: ', requests); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + }) + + describe(`C. Initial OBT record. Confirm new OBT Sends are going into both tables`, () => { + let user1, user2, user3 + let payment = 3000000000; + + it(`Create users`, async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + user3 = await newUser(faucet); + + //console.log('user1: ' + user1.account + ', ' + user1.privateKey + ', ' + user1.publicKey) + //console.log('user2: ' + user2.account + ', ' + user2.privateKey + ', ' + user2.publicKey) + //console.log('user3: ' + user3.account + ', ' + user3.privateKey + ', ' + user3.publicKey) + }) + + + it(`user3 creates BTC OBT send record to user1`, async () => { + try { + const result = await user3.sdk.genericAction('recordObtData', { + payerFioAddress: user3.address, + payeeFioAddress: user1.address, + payerTokenPublicAddress: user3.publicKey, + payeeTokenPublicAddress: user1.publicKey, + amount: payment, + chainCode: "BTC", + tokenCode: "BTC", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user1.publicKey, + memo: 'this is a test', + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + }) + + it('Call get_table_rows from recordobts (old table) and confirm OBT is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'recordobts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: true, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + obts = await callFioApi("get_table_rows", json); + //console.log('obts: ', obts); + for (request in obts.rows) { + if (obts.rows[request].payer_fio_addr == user3.address) { + //console.log('payer_fio_addr: ', obts.rows[request].payer_fio_addr); + break; + } + } + expect(obts.rows[request].payer_fio_addr).to.equal(user3.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it('Call get_table_rows from fiotrxts (NEW table) and confirm request is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: true, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + //console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].payer_fio_addr == user3.address) { + //console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; + } + } + expect(requests.rows[request].payer_fio_addr).to.equal(user3.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + }) + + describe(`E. Initial FIO Request record. Confirm NEW Requests are going into both tables`, () => { + let user1, user2, user3, requestId, obtId let payment = 3000000000; let requestMemo = 'asdf'; - let count = 5; it(`Create users`, async () => { user1 = await newUser(faucet); @@ -58,10 +394,9 @@ describe(`************************** bravo-migr-test.js.js ********************* //console.log('user3: ' + user3.account + ', ' + user3.privateKey + ', ' + user3.publicKey) }) - it(`${count}x - user1 requests funds from user2`, async () => { - for (i = 0; i < count; i++) { - try { - const result = await user1.sdk.genericAction('requestFunds', { + it(`user1 requests funds from user2`, async () => { + try { + const result = await user1.sdk.genericAction('requestFunds', { payerFioAddress: user2.address, payeeFioAddress: user1.address, payeeTokenPublicAddress: user1.address, @@ -74,704 +409,1453 @@ describe(`************************** bravo-migr-test.js.js ********************* technologyProviderId: '', hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? offlineUrl: '' - }) - //console.log('Result: ', result) - expect(result.status).to.equal('requested') - } catch (err) { - console.log('Error', err.json) - expect(err).to.equal(null) + }) + //console.log('Result: ', result) + requestId = result.fio_request_id; + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + }) + + it('Requests: Call get_table_rows from fioreqctxts (old table) and confirm request is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fioreqctxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: true, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + //console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].fio_request_id == requestId) { + //console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; } } + expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } }) - it(`${count}x - user2 requests funds from user1`, async () => { - for (i = 0; i < count; i++) { - try { - const result = await user2.sdk.genericAction('requestFunds', { - payerFioAddress: user1.address, - payeeFioAddress: user2.address, - payeeTokenPublicAddress: user2.address, - amount: payment, - chainCode: 'FIO', - tokenCode: 'FIO', - memo: requestMemo, - maxFee: config.api.new_funds_request.fee, - payerFioPublicKey: user1.publicKey, - technologyProviderId: '', - hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? - offlineUrl: '' - }) - //console.log('Result: ', result) - expect(result.status).to.equal('requested') - } catch (err) { - console.log('Error', err.json) - expect(err).to.equal(null) + it('Call get_table_rows from fiotrxts (NEW table) and confirm request is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: true, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + //console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].fio_request_id == requestId) { + //console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; } } + expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } }) - it(`${count}x - user3 requests funds from user2, user2 rejects request`, async () => { - let requestId; - for (i = 0; i < count; i++) { - try { - const result = await user3.sdk.genericAction('requestFunds', { - payerFioAddress: user2.address, - payeeFioAddress: user3.address, - payeeTokenPublicAddress: user3.address, - amount: payment, - chainCode: 'FIO', - tokenCode: 'FIO', - memo: requestMemo, - maxFee: config.api.new_funds_request.fee, - payerFioPublicKey: user2.publicKey, - technologyProviderId: '', - hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? - offlineUrl: '' - }) - //console.log('Result: ', result) - requestId = result.fio_request_id; - expect(result.status).to.equal('requested') - } catch (err) { - console.log('Error', err.json) - expect(err).to.equal(null) - } + }) - try { - const result = await user2.sdk.genericAction('pushTransaction', { - action: 'rejectfndreq', - account: 'fio.reqobt', - data: { - fio_request_id: requestId, - max_fee: config.api.cancel_funds_request.fee, - tpid: '', - actor: user2.account - } - }) - //console.log('Result:', result) - expect(result.status).to.equal('request_rejected') - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } - } - }) + describe.skip(`F. Confirm REJECTED Requests are going into both tables`, () => { + let user1, user2, user3, requestId + let payment = 3000000000; + let requestMemo = 'asdf'; - it(`${count}x - user2 requests funds from user1, user 1 records OBT response`, async () => { - let requestId; - for (i = 0; i < count; i++) { - try { - const result = await user2.sdk.genericAction('requestFunds', { - payerFioAddress: user1.address, - payeeFioAddress: user2.address, - payeeTokenPublicAddress: user2.address, - amount: payment, - chainCode: 'FIO', - tokenCode: 'FIO', - memo: requestMemo, - maxFee: config.api.new_funds_request.fee, - payerFioPublicKey: user1.publicKey, - technologyProviderId: '', - hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? - offlineUrl: '' - }) - //console.log('Result: ', result) - requestId = result.fio_request_id; - expect(result.status).to.equal('requested') - } catch (err) { - console.log('Error', err.json) - expect(err).to.equal(null) - } + it(`Create users`, async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + user3 = await newUser(faucet); + }) + + + it(`user3 requests funds from user2, user2 rejects request`, async () => { + let requestId; + for (i = 0; i < count; i++) { + try { + const result = await user3.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user3.address, + payeeTokenPublicAddress: user3.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + requestId = result.fio_request_id; + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + + try { + const result = await user2.sdk.genericAction('pushTransaction', { + action: 'rejectfndreq', + account: 'fio.reqobt', + data: { + fio_request_id: requestId, + max_fee: config.api.cancel_funds_request.fee, + tpid: '', + actor: user2.account + } + }) + //console.log('Result:', result) + expect(result.status).to.equal('request_rejected') + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + } + }) + it('Requests: Call get_table_rows from fioreqctxts (old table) and confirm request is in table', async () => { try { - const result = await user1.sdk.genericAction('recordObtData', { - payerFioAddress: user1.address, - payeeFioAddress: user2.address, - payerTokenPublicAddress: user1.publicKey, - payeeTokenPublicAddress: user2.publicKey, - amount: payment, - chainCode: "FIO", - tokenCode: "FIO", - status: '', - obtId: requestId, - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: user2.publicKey, - memo: 'this is a test', - hash: '', - offLineUrl: '' - }) - //console.log('Result: ', result) - expect(result.status).to.equal('sent_to_blockchain') - } catch (err) { - console.log('Error', err.json) - expect(err).to.equal(null) - } - } - }) + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fioreqctxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].fio_request_id == requestId) { + console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; + } + } + expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it('Call get_table_rows from fiotrxts (NEW table) and confirm request is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].fio_request_id == requestId) { + console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; + } + } + expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + }) + + describe.skip(`G. Confirm paid OBT response Requests are going into both tables`, () => { + let user1, user2, user3, requestId + let payment = 3000000000; + let requestMemo = 'asdf'; + + it(`Create users`, async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + user3 = await newUser(faucet); + + console.log('user1: ' + user1.account + ', ' + user1.privateKey + ', ' + user1.publicKey) + console.log('user2: ' + user2.account + ', ' + user2.privateKey + ', ' + user2.publicKey) + console.log('user3: ' + user3.account + ', ' + user3.privateKey + ', ' + user3.publicKey) + }) + + + it(`user2 requests funds from user1, user 1 records OBT response`, async () => { + let requestId; + try { + const result = await user2.sdk.genericAction('requestFunds', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payeeTokenPublicAddress: user2.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user1.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + requestId = result.fio_request_id; + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } - it(`${count}x user3 creates BTC OBT send record to user1`, async () => { - for (i = 0; i < count; i++) { try { - const result = await user3.sdk.genericAction('recordObtData', { - payerFioAddress: user3.address, - payeeFioAddress: user1.address, - payerTokenPublicAddress: user3.publicKey, - payeeTokenPublicAddress: user1.publicKey, - amount: payment, - chainCode: "BTC", - tokenCode: "BTC", - status: '', - obtId: '', - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: user1.publicKey, - memo: 'this is a test', - hash: '', - offLineUrl: '' - }) - //console.log('Result: ', result) - expect(result.status).to.equal('sent_to_blockchain') - } catch (err) { - console.log('Error', err.json) - expect(err).to.equal(null) - } - } - }) -}) + const result = await user1.sdk.genericAction('recordObtData', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payerTokenPublicAddress: user1.publicKey, + payeeTokenPublicAddress: user2.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: requestId, + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user2.publicKey, + memo: 'this is a test', + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + }) -describe(`B. Perform single migrtrx to initialize migration`, () => { + it('Call get_table_rows from recordobts (old table) and confirm OBT is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'recordobts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + obts = await callFioApi("get_table_rows", json); + console.log('obts: ', obts); + for (request in obts.rows) { + if (obts.rows[request].id == user1.address) { + console.log('payer_fio_addr: ', obts.rows[request].requestId); + break; + } + } + expect(obts.rows[request].payer_fio_addr).to.equal(user1.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) - it(`Call single migrtrx (bp1) and confirm you can still do Requests and OBTs`, async () => { - try { - const result = await callFioApiSigned('push_transaction', { - action: 'migrtrx', - account: 'fio.reqobt', - actor: bp1.account, - privKey: bp1.privateKey, - data: { - amount: 20, - actor: bp1.account + it.skip('Requests: Call get_table_rows from fioreqctxts (old table) and confirm request is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fioreqctxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].fio_request_id == requestId) { + console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; } - }) - //console.log('Result: ', result) + } + expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it('Call get_table_rows from fiotrxts (NEW table) and confirm request is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].fio_request_id == requestId) { + console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; + } + } + expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + }) + + describe(`H. Migrate remaining requests and OBTs`, () => { + let isFinished = 0 + + it('Echo initial migrledgers table', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'migrledgers', + limit: 10, + reverse: false, + show_payer: false + } + ledger = await callFioApi("get_table_rows", json); + console.log('migrledgers: ', ledger); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Call migrtrx (bp1) with amount = 3 until migrledgers isFinished = 1`, async () => { + while (!isFinished) { + try { + const result = await callFioApiSigned('push_transaction', { + action: 'migrtrx', + account: 'fio.reqobt', + actor: bp1.account, + privKey: bp1.privateKey, + data: { + amount: 3, + actor: bp1.account + } + }) + //console.log('Result: ', result) + expect(result.transaction_id).to.exist + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + await timeout(2000); + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'migrledgers', + limit: 10, + reverse: false, + show_payer: false + } + ledger = await callFioApi("get_table_rows", json); + isFinished = ledger.rows[0].isFinished + //console.log('isFinished: ', isFinished); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + } + }) + + it('Echo final migrledgers table', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'migrledgers', + limit: 10, + reverse: false, + show_payer: false + } + ledger = await callFioApi("get_table_rows", json); + console.log('migrledgers: ', ledger); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + }) + + describe.skip(`I. Go through recordobts (old table) and confirm each entry is in fiotrxts (NEW table)`, () => { + let obtCount = 0 + let obtRecords; + + it('Step through recordobts and confirm every entry is found on the new table.', async () => { + let count = 0; + + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'recordobts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + obts = await callFioApi("get_table_rows", json); + obtCount = obts.rows.length; + //console.log('obts: ', obts); + console.log('Number of records in recordobts: ', obtCount); + for (obt in obts.rows) { + // Call get_table_rows from fiotrxts (NEW table) and confirm request is in table + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + newRequests = await callFioApi("get_table_rows", json); + //console.log('requests: ', newRequests); + for (newRequest in newRequests.rows) { + if (newRequests.rows[newRequest].payer_fio_addr == obts.rows[obt].payer_fio_addr) { + //console.log(count); + //console.log('recordobts:') + //console.log('id: ', obts.rows[obt].id); + //console.log('payer_fio_addr: ', obts.rows[obt].payer_fio_addr); + //console.log('payee_fio_addr: ', obts.rows[obt].payee_fio_addr); + //console.log('fiotrxts:') + //console.log('id: ', newRequests.rows[newRequest].id); + //console.log('fio_request_id: ', newRequests.rows[newRequest].fio_request_id); + //console.log('payer_fio_addr: ', newRequests.rows[newRequest].payer_fio_addr); + //console.log('payee_fio_addr: ', newRequests.rows[newRequest].payee_fio_addr); + + expect(obts.rows[obt].payer_fio_addr).to.equal(newRequests.rows[newRequest].payer_fio_addr); + expect(obts.rows[obt].payee_fio_addr).to.equal(newRequests.rows[newRequest].payee_fio_addr); + expect(obts.rows[obt].payer_key).to.equal(newRequests.rows[newRequest].payer_key); + expect(obts.rows[obt].payee_key).to.equal(newRequests.rows[newRequest].payee_key); + //expect(obts.rows[obt].time_stamp).to.equal(newRequests.rows[newRequest].init_time); //Time stamps different? + //expect(newRequests.rows[newRequest].fio_request_id).to.equal(0); + //expect(newRequests.rows[newRequest].fio_data_type).to.equal(4); + break; + } + } + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + count++; + } + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + }) + + describe.skip(`J. Go through fioreqctxts (old table) and confirm each entry is in fiotrxts (NEW table)`, () => { + let reqCount = 0 + let reqs; + + it('Step through fioreqctxts and confirm every entry is found on the new table.', async () => { + let count = 0; + let currentReqStatus; + + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fioreqctxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + reqs = await callFioApi("get_table_rows", json); + reqCount = reqs.rows.length; + //console.log('reqs: ', reqs); + console.log('Number of records in fioreqctxts: ', reqCount); + for (req in reqs.rows) { + // First, get the status of the request + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fioreqstss', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + fioReqSts = await callFioApi("get_table_rows", json); + //console.log('fioReqSts: ', fioReqSts); + currentReqStatus = 0; //Initialize to 0 since that will be the status in the new table if the record's fio_request_id is not found in fioreqstss + for (fioReqStatus in fioReqSts.rows) { + //console.log('reqs.rows[req].fio_request_id', reqs.rows[req].fio_request_id) + //console.log('fioReqStatus: ', fioReqSts.rows[fioReqStatus]); + //console.log ('currentReqStatus', fioReqSts.rows[fioReqStatus].status); + if (fioReqSts.rows[fioReqStatus].fio_request_id == reqs.rows[req].fio_request_id) { + currentReqStatus = fioReqSts.rows[fioReqStatus].status; + //console.log('id: ', fioReqSts.rows[fioReqStatus].id); + //console.log('fio_request_id: ', fioReqSts.rows[fioReqStatus].fio_request_id); + //console.log('status: ', fioReqSts.rows[fioReqStatus].status); + //console.log('payer_fio_addr: ', fioReqSts.rows[fioReqStatus].time_stamp); + expect(reqs.rows[req].fio_request_id).to.equal(fioReqSts.rows[fioReqStatus].fio_request_id); + break; + } + } + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + + // Next, all get_table_rows from fiotrxts (NEW table) and confirm request is in table + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + newRequests = await callFioApi("get_table_rows", json); + //console.log('requests: ', newRequests); + for (newRequest in newRequests.rows) { + if (newRequests.rows[newRequest].fio_request_id == reqs.rows[req].fio_request_id) { + //console.log(count); + //console.log('fioreqctxts:') + //console.log('fio_request_id: ', reqs.rows[req].fio_request_id); + //console.log('payer_fio_addr: ', reqs.rows[req].payer_fio_addr); + //console.log('payee_fio_addr: ', reqs.rows[req].payee_fio_addr); + //console.log('fioreqstss:') + //console.log('status (0 = not found): ', currentReqStatus); + //console.log('fiotrxts:') + //console.log('id: ', newRequests.rows[newRequest].id); + //console.log('fio_request_id: ', newRequests.rows[newRequest].fio_request_id); + //console.log('payer_fio_addr: ', newRequests.rows[newRequest].payer_fio_addr); + //console.log('payee_fio_addr: ', newRequests.rows[newRequest].payee_fio_addr); + //console.log('fio_data_type: ', newRequests.rows[newRequest].fio_data_type); + + expect(reqs.rows[req].payer_fio_addr).to.equal(newRequests.rows[newRequest].payer_fio_addr); + expect(reqs.rows[req].payee_fio_addr).to.equal(newRequests.rows[newRequest].payee_fio_addr); + expect(reqs.rows[req].payer_key).to.equal(newRequests.rows[newRequest].payer_key); + expect(reqs.rows[req].payee_key).to.equal(newRequests.rows[newRequest].payee_key); + //expect(reqs.rows[req].time_stamp).to.equal(newRequests.rows[newRequest].init_time); //Time stamps different? + expect(reqs.rows[req].fio_request_id).to.equal(newRequests.rows[newRequest].fio_request_id); + expect(newRequests.rows[newRequest].fio_data_type).to.equal(currentReqStatus); + break; + } + } + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + count++; + } + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + }) + +}) + +describe.skip(`NUKE Bravo: Call migrtrx until table data is nuked`, () => { + let isFinished = 0 + + it('Echo initial migrledgers table', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'migrledgers', + limit: 1000, + reverse: false, + show_payer: false + } + ledger = await callFioApi("get_table_rows", json); + console.log('migrledgers: ', ledger); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Call migrtrx (bp1) with amount = 10 until migrtrx is empty`, async () => { + while (!isFinished) { + try { + const result = await callFioApiSigned('push_transaction', { + action: 'migrtrx', + account: 'fio.reqobt', + actor: bp1.account, + privKey: bp1.privateKey, + data: { + amount: 10, + actor: bp1.account + } + }) + console.log('Result: ', result) expect(result.transaction_id).to.exist } catch (err) { console.log('Error: ', err) expect(err).to.equal(null) } + await timeout(2000); + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'fiotrxts', + limit: 1000, + reverse: false, + show_payer: false + } + fiotrxts = await callFioApi("get_table_rows", json); + isFinished = (fiotrxts.rows.length == 0); + //console.log('fiotrxts: ', fiotrxts) + console.log('Table rows count: ', fiotrxts.rows.length) + console.log('isFinished: ', isFinished); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + } + }) + + it('Confirm migrledgers table is empty', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'migrledgers', + limit: 10, + reverse: false, + show_payer: false + } + migrledgers = await callFioApi("get_table_rows", json); + console.log('migrledgers: ', migrledgers); + expect(migrledgers.rows.length).to.equal(0); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it('Confirm fiotrxts table is empty', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'fiotrxts', + limit: 10, + reverse: false, + show_payer: false + } + fiotrxts = await callFioApi("get_table_rows", json); + console.log('fiotrxts: ', fiotrxts); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) + +describe(`Release v2.3.2 - fiotrxtss (NEW table) scripts`, () => { + + describe(`A. Load Requests and OBTs`, () => { + let user1, user2, user3; + let payment = 3000000000; + let requestMemo = 'asdf'; + let count = 5; + + it(`Create users`, async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + user3 = await newUser(faucet); + + //console.log('user1: ' + user1.account + ', ' + user1.privateKey + ', ' + user1.publicKey) + //console.log('user2: ' + user2.account + ', ' + user2.privateKey + ', ' + user2.publicKey) + //console.log('user3: ' + user3.account + ', ' + user3.privateKey + ', ' + user3.publicKey) + }) + + it(`${count}x - user1 requests funds from user2`, async () => { + for (i = 0; i < count; i++) { + try { + const result = await user1.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user1.address, + payeeTokenPublicAddress: user1.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) + + it(`${count}x - user2 requests funds from user1`, async () => { + for (i = 0; i < count; i++) { + try { + const result = await user2.sdk.genericAction('requestFunds', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payeeTokenPublicAddress: user2.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user1.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) + + it(`${count}x - user3 requests funds from user2, user2 rejects request`, async () => { + let requestId; + for (i = 0; i < count; i++) { + try { + const result = await user3.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user3.address, + payeeTokenPublicAddress: user3.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + requestId = result.fio_request_id; + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + + try { + const result = await user2.sdk.genericAction('pushTransaction', { + action: 'rejectfndreq', + account: 'fio.reqobt', + data: { + fio_request_id: requestId, + max_fee: config.api.cancel_funds_request.fee, + tpid: '', + actor: user2.account + } + }) + //console.log('Result:', result) + expect(result.status).to.equal('request_rejected') + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + } + }) + + it(`${count}x - user2 requests funds from user1, user 1 records OBT response`, async () => { + let requestId; + for (i = 0; i < count; i++) { + try { + const result = await user2.sdk.genericAction('requestFunds', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payeeTokenPublicAddress: user2.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user1.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + requestId = result.fio_request_id; + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + + try { + const result = await user1.sdk.genericAction('recordObtData', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payerTokenPublicAddress: user1.publicKey, + payeeTokenPublicAddress: user2.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: requestId, + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user2.publicKey, + memo: 'this is a test', + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) + + it(`${count}x user3 creates BTC OBT send record to user1`, async () => { + for (i = 0; i < count; i++) { + try { + const result = await user3.sdk.genericAction('recordObtData', { + payerFioAddress: user3.address, + payeeFioAddress: user1.address, + payerTokenPublicAddress: user3.publicKey, + payeeTokenPublicAddress: user1.publicKey, + amount: payment, + chainCode: "BTC", + tokenCode: "BTC", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user1.publicKey, + memo: 'this is a test', + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) + }) + + describe(`B. Perform single migrtrx to initialize migration`, () => { + + it(`Call single migrtrx (bp1) and confirm you can still do Requests and OBTs`, async () => { + try { + const result = await callFioApiSigned('push_transaction', { + action: 'migrtrx', + account: 'fio.reqobt', + actor: bp1.account, + privKey: bp1.privateKey, + data: { + amount: 20, + actor: bp1.account + } + }) + //console.log('Result: ', result) + expect(result.transaction_id).to.exist + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it.skip('Call get_table_rows from fiotrxtss (NEW table) and display', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxtss', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + console.log('requests: ', requests); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + }) + + describe(`C. Initial OBT record. Confirm new OBT Sends are going into both tables`, () => { + let user1, user2, user3 + let payment = 3000000000; + + it(`Create users`, async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + user3 = await newUser(faucet); + + //console.log('user1: ' + user1.account + ', ' + user1.privateKey + ', ' + user1.publicKey) + //console.log('user2: ' + user2.account + ', ' + user2.privateKey + ', ' + user2.publicKey) + //console.log('user3: ' + user3.account + ', ' + user3.privateKey + ', ' + user3.publicKey) + }) + + + it(`user3 creates BTC OBT send record to user1`, async () => { + try { + const result = await user3.sdk.genericAction('recordObtData', { + payerFioAddress: user3.address, + payeeFioAddress: user1.address, + payerTokenPublicAddress: user3.publicKey, + payeeTokenPublicAddress: user1.publicKey, + amount: payment, + chainCode: "BTC", + tokenCode: "BTC", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user1.publicKey, + memo: 'this is a test', + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + }) + + it('Call get_table_rows from recordobts (old table) and confirm OBT is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'recordobts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: true, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + obts = await callFioApi("get_table_rows", json); + //console.log('obts: ', obts); + for (request in obts.rows) { + if (obts.rows[request].payer_fio_addr == user3.address) { + //console.log('payer_fio_addr: ', obts.rows[request].payer_fio_addr); + break; + } + } + expect(obts.rows[request].payer_fio_addr).to.equal(user3.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it('Call get_table_rows from fiotrxtss (NEW table) and confirm request is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxtss', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: true, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + //console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].payer_fio_addr == user3.address) { + //console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; + } + } + expect(requests.rows[request].payer_fio_addr).to.equal(user3.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + }) + + describe(`E. Initial FIO Request record. Confirm NEW Requests are going into both tables`, () => { + let user1, user2, user3, requestId, obtId + let payment = 3000000000; + let requestMemo = 'asdf'; + + it(`Create users`, async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + user3 = await newUser(faucet); + + //console.log('user1: ' + user1.account + ', ' + user1.privateKey + ', ' + user1.publicKey) + //console.log('user2: ' + user2.account + ', ' + user2.privateKey + ', ' + user2.publicKey) + //console.log('user3: ' + user3.account + ', ' + user3.privateKey + ', ' + user3.publicKey) + }) + + it(`user1 requests funds from user2`, async () => { + try { + const result = await user1.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user1.address, + payeeTokenPublicAddress: user1.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + requestId = result.fio_request_id; + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + }) + + it('Requests: Call get_table_rows from fioreqctxts (old table) and confirm request is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fioreqctxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: true, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + //console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].fio_request_id == requestId) { + //console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; + } + } + expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } }) - it.skip('Call get_table_rows from fiotrxts (NEW table) and display', async () => { + it('Call get_table_rows from fiotrxtss (NEW table) and confirm request is in table', async () => { try { const json = { json: true, // Get the response as json code: 'fio.reqobt', // Contract that we target scope: 'fio.reqobt', // Account that owns the data - table: 'fiotrxts', // Table name + table: 'fiotrxtss', // Table name limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data + reverse: true, // Optional: Get reversed data show_payer: false // Optional: Show ram payer } requests = await callFioApi("get_table_rows", json); - console.log('requests: ', requests); + //console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].fio_request_id == requestId) { + //console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; + } + } + expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); } catch (err) { console.log('Error', err); expect(err).to.equal(null); } }) -}) - -describe(`C. Initial OBT record. Confirm new OBT Sends are going into both tables`, () => { - let user1, user2, user3 - let payment = 3000000000; - - it(`Create users`, async () => { - user1 = await newUser(faucet); - user2 = await newUser(faucet); - user3 = await newUser(faucet); - - //console.log('user1: ' + user1.account + ', ' + user1.privateKey + ', ' + user1.publicKey) - //console.log('user2: ' + user2.account + ', ' + user2.privateKey + ', ' + user2.publicKey) - //console.log('user3: ' + user3.account + ', ' + user3.privateKey + ', ' + user3.publicKey) - }) - - it(`user3 creates BTC OBT send record to user1`, async () => { - try { - const result = await user3.sdk.genericAction('recordObtData', { - payerFioAddress: user3.address, - payeeFioAddress: user1.address, - payerTokenPublicAddress: user3.publicKey, - payeeTokenPublicAddress: user1.publicKey, - amount: payment, - chainCode: "BTC", - tokenCode: "BTC", - status: '', - obtId: '', - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: user1.publicKey, - memo: 'this is a test', - hash: '', - offLineUrl: '' - }) - //console.log('Result: ', result) - expect(result.status).to.equal('sent_to_blockchain') - } catch (err) { - console.log('Error', err.json) - expect(err).to.equal(null) - } }) - it('Call get_table_rows from recordobts (old table) and confirm OBT is in table', async () => { - try { - const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'recordobts', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: true, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - obts = await callFioApi("get_table_rows", json); - //console.log('obts: ', obts); - for (request in obts.rows) { - if (obts.rows[request].payer_fio_addr == user3.address) { - //console.log('payer_fio_addr: ', obts.rows[request].payer_fio_addr); - break; - } - } - expect(obts.rows[request].payer_fio_addr).to.equal(user3.address); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - }) + describe.skip(`F. Confirm REJECTED Requests are going into both tables`, () => { + let user1, user2, user3, requestId + let payment = 3000000000; + let requestMemo = 'asdf'; - it('Call get_table_rows from fiotrxts (NEW table) and confirm request is in table', async () => { - try { - const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'fiotrxts', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: true, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - requests = await callFioApi("get_table_rows", json); - //console.log('requests: ', requests); - for (request in requests.rows) { - if (requests.rows[request].payer_fio_addr == user3.address) { - //console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); - break; - } - } - expect(requests.rows[request].payer_fio_addr).to.equal(user3.address); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - }) + it(`Create users`, async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + user3 = await newUser(faucet); + }) -}) -describe(`E. Initial FIO Request record. Confirm NEW Requests are going into both tables`, () => { - let user1, user2, user3, requestId, obtId - let payment = 3000000000; - let requestMemo = 'asdf'; + it(`user3 requests funds from user2, user2 rejects request`, async () => { + let requestId; + for (i = 0; i < count; i++) { + try { + const result = await user3.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user3.address, + payeeTokenPublicAddress: user3.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + requestId = result.fio_request_id; + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } - it(`Create users`, async () => { - user1 = await newUser(faucet); - user2 = await newUser(faucet); - user3 = await newUser(faucet); + try { + const result = await user2.sdk.genericAction('pushTransaction', { + action: 'rejectfndreq', + account: 'fio.reqobt', + data: { + fio_request_id: requestId, + max_fee: config.api.cancel_funds_request.fee, + tpid: '', + actor: user2.account + } + }) + //console.log('Result:', result) + expect(result.status).to.equal('request_rejected') + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + } + }) - //console.log('user1: ' + user1.account + ', ' + user1.privateKey + ', ' + user1.publicKey) - //console.log('user2: ' + user2.account + ', ' + user2.privateKey + ', ' + user2.publicKey) - //console.log('user3: ' + user3.account + ', ' + user3.privateKey + ', ' + user3.publicKey) - }) + it('Requests: Call get_table_rows from fioreqctxts (old table) and confirm request is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fioreqctxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].fio_request_id == requestId) { + console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; + } + } + expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) - it(`user1 requests funds from user2`, async () => { - try { - const result = await user1.sdk.genericAction('requestFunds', { - payerFioAddress: user2.address, - payeeFioAddress: user1.address, - payeeTokenPublicAddress: user1.address, - amount: payment, - chainCode: 'FIO', - tokenCode: 'FIO', - memo: requestMemo, - maxFee: config.api.new_funds_request.fee, - payerFioPublicKey: user2.publicKey, - technologyProviderId: '', - hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? - offlineUrl: '' - }) - //console.log('Result: ', result) - requestId = result.fio_request_id; - expect(result.status).to.equal('requested') - } catch (err) { - console.log('Error', err.json) - expect(err).to.equal(null) - } - }) + it('Call get_table_rows from fiotrxtss (NEW table) and confirm request is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxtss', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].fio_request_id == requestId) { + console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; + } + } + expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) - it('Requests: Call get_table_rows from fioreqctxts (old table) and confirm request is in table', async () => { - try { - const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'fioreqctxts', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: true, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - requests = await callFioApi("get_table_rows", json); - //console.log('requests: ', requests); - for (request in requests.rows) { - if (requests.rows[request].fio_request_id == requestId) { - //console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); - break; - } - } - expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } }) - it('Call get_table_rows from fiotrxts (NEW table) and confirm request is in table', async () => { - try { - const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'fiotrxts', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: true, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - requests = await callFioApi("get_table_rows", json); - //console.log('requests: ', requests); - for (request in requests.rows) { - if (requests.rows[request].fio_request_id == requestId) { - //console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); - break; - } - } - expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - }) + describe.skip(`G. Confirm paid OBT response Requests are going into both tables`, () => { + let user1, user2, user3, requestId + let payment = 3000000000; + let requestMemo = 'asdf'; -}) + it(`Create users`, async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + user3 = await newUser(faucet); -describe.skip(`F. Confirm REJECTED Requests are going into both tables`, () => { - let user1, user2, user3, requestId - let payment = 3000000000; - let requestMemo = 'asdf'; + console.log('user1: ' + user1.account + ', ' + user1.privateKey + ', ' + user1.publicKey) + console.log('user2: ' + user2.account + ', ' + user2.privateKey + ', ' + user2.publicKey) + console.log('user3: ' + user3.account + ', ' + user3.privateKey + ', ' + user3.publicKey) + }) - it(`Create users`, async () => { - user1 = await newUser(faucet); - user2 = await newUser(faucet); - user3 = await newUser(faucet); - }) + it(`user2 requests funds from user1, user 1 records OBT response`, async () => { + let requestId; + try { + const result = await user2.sdk.genericAction('requestFunds', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payeeTokenPublicAddress: user2.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user1.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + requestId = result.fio_request_id; + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } - it(`user3 requests funds from user2, user2 rejects request`, async () => { - let requestId; - for (i = 0; i < count; i++) { try { - const result = await user3.sdk.genericAction('requestFunds', { - payerFioAddress: user2.address, - payeeFioAddress: user3.address, - payeeTokenPublicAddress: user3.address, - amount: payment, - chainCode: 'FIO', - tokenCode: 'FIO', - memo: requestMemo, - maxFee: config.api.new_funds_request.fee, - payerFioPublicKey: user2.publicKey, - technologyProviderId: '', - hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? - offlineUrl: '' - }) - //console.log('Result: ', result) - requestId = result.fio_request_id; - expect(result.status).to.equal('requested') - } catch (err) { - console.log('Error', err.json) - expect(err).to.equal(null) - } + const result = await user1.sdk.genericAction('recordObtData', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payerTokenPublicAddress: user1.publicKey, + payeeTokenPublicAddress: user2.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: requestId, + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user2.publicKey, + memo: 'this is a test', + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + }) - try { - const result = await user2.sdk.genericAction('pushTransaction', { - action: 'rejectfndreq', - account: 'fio.reqobt', - data: { - fio_request_id: requestId, - max_fee: config.api.cancel_funds_request.fee, - tpid: '', - actor: user2.account - } - }) - //console.log('Result:', result) - expect(result.status).to.equal('request_rejected') - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) + it('Call get_table_rows from recordobts (old table) and confirm OBT is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'recordobts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer } - } - }) + obts = await callFioApi("get_table_rows", json); + console.log('obts: ', obts); + for (request in obts.rows) { + if (obts.rows[request].id == user1.address) { + console.log('payer_fio_addr: ', obts.rows[request].requestId); + break; + } + } + expect(obts.rows[request].payer_fio_addr).to.equal(user1.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) - it('Requests: Call get_table_rows from fioreqctxts (old table) and confirm request is in table', async () => { - try { + it.skip('Requests: Call get_table_rows from fioreqctxts (old table) and confirm request is in table', async () => { + try { const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'fioreqctxts', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fioreqctxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer } requests = await callFioApi("get_table_rows", json); console.log('requests: ', requests); for (request in requests.rows) { - if (requests.rows[request].fio_request_id == requestId) { + if (requests.rows[request].fio_request_id == requestId) { console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); break; - } + } } expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); - } catch (err) { + } catch (err) { console.log('Error', err); expect(err).to.equal(null); - } + } }) - it('Call get_table_rows from fiotrxts (NEW table) and confirm request is in table', async () => { - try { + it('Call get_table_rows from fiotrxtss (NEW table) and confirm request is in table', async () => { + try { const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'fiotrxts', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxtss', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer } requests = await callFioApi("get_table_rows", json); console.log('requests: ', requests); for (request in requests.rows) { - if (requests.rows[request].fio_request_id == requestId) { + if (requests.rows[request].fio_request_id == requestId) { console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); break; - } + } } expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); - } catch (err) { + } catch (err) { console.log('Error', err); expect(err).to.equal(null); - } - }) - -}) - -describe.skip(`G. Confirm paid OBT response Requests are going into both tables`, () => { - let user1, user2, user3, requestId - let payment = 3000000000; - let requestMemo = 'asdf'; - - it(`Create users`, async () => { - user1 = await newUser(faucet); - user2 = await newUser(faucet); - user3 = await newUser(faucet); - - console.log('user1: ' + user1.account + ', ' + user1.privateKey + ', ' + user1.publicKey) - console.log('user2: ' + user2.account + ', ' + user2.privateKey + ', ' + user2.publicKey) - console.log('user3: ' + user3.account + ', ' + user3.privateKey + ', ' + user3.publicKey) - }) - - - it(`user2 requests funds from user1, user 1 records OBT response`, async () => { - let requestId; - try { - const result = await user2.sdk.genericAction('requestFunds', { - payerFioAddress: user1.address, - payeeFioAddress: user2.address, - payeeTokenPublicAddress: user2.address, - amount: payment, - chainCode: 'FIO', - tokenCode: 'FIO', - memo: requestMemo, - maxFee: config.api.new_funds_request.fee, - payerFioPublicKey: user1.publicKey, - technologyProviderId: '', - hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? - offlineUrl: '' - }) - //console.log('Result: ', result) - requestId = result.fio_request_id; - expect(result.status).to.equal('requested') - } catch (err) { - console.log('Error', err.json) - expect(err).to.equal(null) - } - - try { - const result = await user1.sdk.genericAction('recordObtData', { - payerFioAddress: user1.address, - payeeFioAddress: user2.address, - payerTokenPublicAddress: user1.publicKey, - payeeTokenPublicAddress: user2.publicKey, - amount: payment, - chainCode: "FIO", - tokenCode: "FIO", - status: '', - obtId: requestId, - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: user2.publicKey, - memo: 'this is a test', - hash: '', - offLineUrl: '' - }) - //console.log('Result: ', result) - expect(result.status).to.equal('sent_to_blockchain') - } catch (err) { - console.log('Error', err.json) - expect(err).to.equal(null) - } - }) - - it('Call get_table_rows from recordobts (old table) and confirm OBT is in table', async () => { - try { - const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'recordobts', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - obts = await callFioApi("get_table_rows", json); - console.log('obts: ', obts); - for (request in obts.rows) { - if (obts.rows[request].id == user1.address) { - console.log('payer_fio_addr: ', obts.rows[request].requestId); - break; - } - } - expect(obts.rows[request].payer_fio_addr).to.equal(user1.address); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - }) - - it.skip('Requests: Call get_table_rows from fioreqctxts (old table) and confirm request is in table', async () => { - try { - const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'fioreqctxts', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - requests = await callFioApi("get_table_rows", json); - console.log('requests: ', requests); - for (request in requests.rows) { - if (requests.rows[request].fio_request_id == requestId) { - console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); - break; - } - } - expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - }) - - it('Call get_table_rows from fiotrxts (NEW table) and confirm request is in table', async () => { - try { - const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'fiotrxts', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - requests = await callFioApi("get_table_rows", json); - console.log('requests: ', requests); - for (request in requests.rows) { - if (requests.rows[request].fio_request_id == requestId) { - console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); - break; - } } - expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - }) - -}) - -describe(`H. Migrate remaining requests and OBTs`, () => { - let isFinished = 0 + }) - it('Echo initial migrledgers table', async () => { - try { - const json = { - json: true, - code: 'fio.reqobt', - scope: 'fio.reqobt', - table: 'migrledgers', - limit: 10, - reverse: false, - show_payer: false - } - ledger = await callFioApi("get_table_rows", json); - console.log('migrledgers: ', ledger); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } }) - it(`Call migrtrx (bp1) with amount = 3 until migrledgers isFinished = 1`, async () => { - while (!isFinished) { + describe(`H. Migrate remaining requests and OBTs`, () => { + let isFinished = 0 + + it('Echo initial migrledgers table', async () => { try { - const result = await callFioApiSigned('push_transaction', { - action: 'migrtrx', - account: 'fio.reqobt', - actor: bp1.account, - privKey: bp1.privateKey, - data: { - amount: 3, - actor: bp1.account - } - }) - //console.log('Result: ', result) - expect(result.transaction_id).to.exist + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'migrledgers', + limit: 10, + reverse: false, + show_payer: false + } + ledger = await callFioApi("get_table_rows", json); + console.log('migrledgers: ', ledger); } catch (err) { - console.log('Error: ', err) - expect(err).to.equal(null) + console.log('Error', err); + expect(err).to.equal(null); } - await timeout(2000); + }) + + it(`Call migrtrx (bp1) with amount = 3 until migrledgers isFinished = 1`, async () => { + while (!isFinished) { + try { + const result = await callFioApiSigned('push_transaction', { + action: 'migrtrx', + account: 'fio.reqobt', + actor: bp1.account, + privKey: bp1.privateKey, + data: { + amount: 3, + actor: bp1.account + } + }) + //console.log('Result: ', result) + expect(result.transaction_id).to.exist + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + await timeout(2000); + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'migrledgers', + limit: 10, + reverse: false, + show_payer: false + } + ledger = await callFioApi("get_table_rows", json); + isFinished = ledger.rows[0].isFinished + //console.log('isFinished: ', isFinished); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + } + }) + + it('Echo final migrledgers table', async () => { try { const json = { json: true, @@ -783,241 +1867,259 @@ describe(`H. Migrate remaining requests and OBTs`, () => { show_payer: false } ledger = await callFioApi("get_table_rows", json); - isFinished = ledger.rows[0].isFinished - //console.log('isFinished: ', isFinished); + console.log('migrledgers: ', ledger); } catch (err) { console.log('Error', err); expect(err).to.equal(null); } - } - }) + }) - it('Echo final migrledgers table', async () => { - try { - const json = { - json: true, - code: 'fio.reqobt', - scope: 'fio.reqobt', - table: 'migrledgers', - limit: 10, - reverse: false, - show_payer: false - } - ledger = await callFioApi("get_table_rows", json); - console.log('migrledgers: ', ledger); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } }) -}) - -describe.skip(`I. Go through recordobts (old table) and confirm each entry is in fiotrxts (NEW table)`, () => { - let obtCount = 0 - let obtRecords; + describe.skip(`I. Go through recordobts (old table) and confirm each entry is in fiotrxtss (NEW table)`, () => { + let obtCount = 0 + let obtRecords; - it('Step through recordobts and confirm every entry is found on the new table.', async () => { - let count = 0; + it('Step through recordobts and confirm every entry is found on the new table.', async () => { + let count = 0; - try { - const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'recordobts', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - obts = await callFioApi("get_table_rows", json); - obtCount = obts.rows.length; - //console.log('obts: ', obts); - console.log('Number of records in recordobts: ', obtCount); - for (obt in obts.rows) { - // Call get_table_rows from fiotrxts (NEW table) and confirm request is in table - try { - const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'fiotrxts', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - newRequests = await callFioApi("get_table_rows", json); - //console.log('requests: ', newRequests); - for (newRequest in newRequests.rows) { - if (newRequests.rows[newRequest].payer_fio_addr == obts.rows[obt].payer_fio_addr) { - //console.log(count); - //console.log('recordobts:') - //console.log('id: ', obts.rows[obt].id); - //console.log('payer_fio_addr: ', obts.rows[obt].payer_fio_addr); - //console.log('payee_fio_addr: ', obts.rows[obt].payee_fio_addr); - //console.log('fiotrxts:') - //console.log('id: ', newRequests.rows[newRequest].id); - //console.log('fio_request_id: ', newRequests.rows[newRequest].fio_request_id); - //console.log('payer_fio_addr: ', newRequests.rows[newRequest].payer_fio_addr); - //console.log('payee_fio_addr: ', newRequests.rows[newRequest].payee_fio_addr); - - expect(obts.rows[obt].payer_fio_addr).to.equal(newRequests.rows[newRequest].payer_fio_addr); - expect(obts.rows[obt].payee_fio_addr).to.equal(newRequests.rows[newRequest].payee_fio_addr); - expect(obts.rows[obt].payer_key).to.equal(newRequests.rows[newRequest].payer_key); - expect(obts.rows[obt].payee_key).to.equal(newRequests.rows[newRequest].payee_key); - //expect(obts.rows[obt].time_stamp).to.equal(newRequests.rows[newRequest].init_time); //Time stamps different? - //expect(newRequests.rows[newRequest].fio_request_id).to.equal(0); - //expect(newRequests.rows[newRequest].fio_data_type).to.equal(4); - break; + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'recordobts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + obts = await callFioApi("get_table_rows", json); + obtCount = obts.rows.length; + //console.log('obts: ', obts); + console.log('Number of records in recordobts: ', obtCount); + for (obt in obts.rows) { + // Call get_table_rows from fiotrxtss (NEW table) and confirm request is in table + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxtss', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + newRequests = await callFioApi("get_table_rows", json); + //console.log('requests: ', newRequests); + for (newRequest in newRequests.rows) { + if (newRequests.rows[newRequest].payer_fio_addr == obts.rows[obt].payer_fio_addr) { + //console.log(count); + //console.log('recordobts:') + //console.log('id: ', obts.rows[obt].id); + //console.log('payer_fio_addr: ', obts.rows[obt].payer_fio_addr); + //console.log('payee_fio_addr: ', obts.rows[obt].payee_fio_addr); + //console.log('fiotrxtss:') + //console.log('id: ', newRequests.rows[newRequest].id); + //console.log('fio_request_id: ', newRequests.rows[newRequest].fio_request_id); + //console.log('payer_fio_addr: ', newRequests.rows[newRequest].payer_fio_addr); + //console.log('payee_fio_addr: ', newRequests.rows[newRequest].payee_fio_addr); + + expect(obts.rows[obt].payer_fio_addr).to.equal(newRequests.rows[newRequest].payer_fio_addr); + expect(obts.rows[obt].payee_fio_addr).to.equal(newRequests.rows[newRequest].payee_fio_addr); + expect(obts.rows[obt].payer_key).to.equal(newRequests.rows[newRequest].payer_key); + expect(obts.rows[obt].payee_key).to.equal(newRequests.rows[newRequest].payee_key); + //expect(obts.rows[obt].time_stamp).to.equal(newRequests.rows[newRequest].init_time); //Time stamps different? + //expect(newRequests.rows[newRequest].fio_request_id).to.equal(0); + //expect(newRequests.rows[newRequest].fio_data_type).to.equal(4); + break; + } } + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); } - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); + count++; } - count++; + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); } - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - }) + }) -}) + }) -describe.skip(`J. Go through fioreqctxts (old table) and confirm each entry is in fiotrxts (NEW table)`, () => { - let reqCount = 0 - let reqs; + describe.skip(`J. Go through fioreqctxts (old table) and confirm each entry is in fiotrxtss (NEW table)`, () => { + let reqCount = 0 + let reqs; - it('Step through fioreqctxts and confirm every entry is found on the new table.', async () => { - let count = 0; - let currentReqStatus; + it('Step through fioreqctxts and confirm every entry is found on the new table.', async () => { + let count = 0; + let currentReqStatus; - try { - const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'fioreqctxts', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - reqs = await callFioApi("get_table_rows", json); - reqCount = reqs.rows.length; - //console.log('reqs: ', reqs); - console.log('Number of records in fioreqctxts: ', reqCount); - for (req in reqs.rows) { - // First, get the status of the request - try { - const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'fioreqstss', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - fioReqSts = await callFioApi("get_table_rows", json); - //console.log('fioReqSts: ', fioReqSts); - currentReqStatus = 0; //Initialize to 0 since that will be the status in the new table if the record's fio_request_id is not found in fioreqstss - for (fioReqStatus in fioReqSts.rows) { - //console.log('reqs.rows[req].fio_request_id', reqs.rows[req].fio_request_id) - //console.log('fioReqStatus: ', fioReqSts.rows[fioReqStatus]); - //console.log ('currentReqStatus', fioReqSts.rows[fioReqStatus].status); - if (fioReqSts.rows[fioReqStatus].fio_request_id == reqs.rows[req].fio_request_id) { - currentReqStatus = fioReqSts.rows[fioReqStatus].status; - //console.log('id: ', fioReqSts.rows[fioReqStatus].id); - //console.log('fio_request_id: ', fioReqSts.rows[fioReqStatus].fio_request_id); - //console.log('status: ', fioReqSts.rows[fioReqStatus].status); - //console.log('payer_fio_addr: ', fioReqSts.rows[fioReqStatus].time_stamp); - expect(reqs.rows[req].fio_request_id).to.equal(fioReqSts.rows[fioReqStatus].fio_request_id); - break; + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fioreqctxts', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + reqs = await callFioApi("get_table_rows", json); + reqCount = reqs.rows.length; + //console.log('reqs: ', reqs); + console.log('Number of records in fioreqctxts: ', reqCount); + for (req in reqs.rows) { + // First, get the status of the request + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fioreqstss', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + fioReqSts = await callFioApi("get_table_rows", json); + //console.log('fioReqSts: ', fioReqSts); + currentReqStatus = 0; //Initialize to 0 since that will be the status in the new table if the record's fio_request_id is not found in fioreqstss + for (fioReqStatus in fioReqSts.rows) { + //console.log('reqs.rows[req].fio_request_id', reqs.rows[req].fio_request_id) + //console.log('fioReqStatus: ', fioReqSts.rows[fioReqStatus]); + //console.log ('currentReqStatus', fioReqSts.rows[fioReqStatus].status); + if (fioReqSts.rows[fioReqStatus].fio_request_id == reqs.rows[req].fio_request_id) { + currentReqStatus = fioReqSts.rows[fioReqStatus].status; + //console.log('id: ', fioReqSts.rows[fioReqStatus].id); + //console.log('fio_request_id: ', fioReqSts.rows[fioReqStatus].fio_request_id); + //console.log('status: ', fioReqSts.rows[fioReqStatus].status); + //console.log('payer_fio_addr: ', fioReqSts.rows[fioReqStatus].time_stamp); + expect(reqs.rows[req].fio_request_id).to.equal(fioReqSts.rows[fioReqStatus].fio_request_id); + break; + } } + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); } - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - // Next, all get_table_rows from fiotrxts (NEW table) and confirm request is in table - try { - const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'fiotrxts', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - newRequests = await callFioApi("get_table_rows", json); - //console.log('requests: ', newRequests); - for (newRequest in newRequests.rows) { - if (newRequests.rows[newRequest].fio_request_id == reqs.rows[req].fio_request_id) { - //console.log(count); - //console.log('fioreqctxts:') - //console.log('fio_request_id: ', reqs.rows[req].fio_request_id); - //console.log('payer_fio_addr: ', reqs.rows[req].payer_fio_addr); - //console.log('payee_fio_addr: ', reqs.rows[req].payee_fio_addr); - //console.log('fioreqstss:') - //console.log('status (0 = not found): ', currentReqStatus); - //console.log('fiotrxts:') - //console.log('id: ', newRequests.rows[newRequest].id); - //console.log('fio_request_id: ', newRequests.rows[newRequest].fio_request_id); - //console.log('payer_fio_addr: ', newRequests.rows[newRequest].payer_fio_addr); - //console.log('payee_fio_addr: ', newRequests.rows[newRequest].payee_fio_addr); - //console.log('fio_data_type: ', newRequests.rows[newRequest].fio_data_type); - - expect(reqs.rows[req].payer_fio_addr).to.equal(newRequests.rows[newRequest].payer_fio_addr); - expect(reqs.rows[req].payee_fio_addr).to.equal(newRequests.rows[newRequest].payee_fio_addr); - expect(reqs.rows[req].payer_key).to.equal(newRequests.rows[newRequest].payer_key); - expect(reqs.rows[req].payee_key).to.equal(newRequests.rows[newRequest].payee_key); - //expect(reqs.rows[req].time_stamp).to.equal(newRequests.rows[newRequest].init_time); //Time stamps different? - expect(reqs.rows[req].fio_request_id).to.equal(newRequests.rows[newRequest].fio_request_id); - expect(newRequests.rows[newRequest].fio_data_type).to.equal(currentReqStatus); - break; + // Next, all get_table_rows from fiotrxtss (NEW table) and confirm request is in table + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxtss', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + newRequests = await callFioApi("get_table_rows", json); + //console.log('requests: ', newRequests); + for (newRequest in newRequests.rows) { + if (newRequests.rows[newRequest].fio_request_id == reqs.rows[req].fio_request_id) { + //console.log(count); + //console.log('fioreqctxts:') + //console.log('fio_request_id: ', reqs.rows[req].fio_request_id); + //console.log('payer_fio_addr: ', reqs.rows[req].payer_fio_addr); + //console.log('payee_fio_addr: ', reqs.rows[req].payee_fio_addr); + //console.log('fioreqstss:') + //console.log('status (0 = not found): ', currentReqStatus); + //console.log('fiotrxtss:') + //console.log('id: ', newRequests.rows[newRequest].id); + //console.log('fio_request_id: ', newRequests.rows[newRequest].fio_request_id); + //console.log('payer_fio_addr: ', newRequests.rows[newRequest].payer_fio_addr); + //console.log('payee_fio_addr: ', newRequests.rows[newRequest].payee_fio_addr); + //console.log('fio_data_type: ', newRequests.rows[newRequest].fio_data_type); + + expect(reqs.rows[req].payer_fio_addr).to.equal(newRequests.rows[newRequest].payer_fio_addr); + expect(reqs.rows[req].payee_fio_addr).to.equal(newRequests.rows[newRequest].payee_fio_addr); + expect(reqs.rows[req].payer_key).to.equal(newRequests.rows[newRequest].payer_key); + expect(reqs.rows[req].payee_key).to.equal(newRequests.rows[newRequest].payee_key); + //expect(reqs.rows[req].time_stamp).to.equal(newRequests.rows[newRequest].init_time); //Time stamps different? + expect(reqs.rows[req].fio_request_id).to.equal(newRequests.rows[newRequest].fio_request_id); + expect(newRequests.rows[newRequest].fio_data_type).to.equal(currentReqStatus); + break; + } } + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); } - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); + count++; } - count++; + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + }) +}) + +describe.skip(`Release delta - remove data from old tables (fioreqctxts, recordobts, fioreqstss)`, () => { + let isFinished = 0 + + it('Echo size of fioreqctxts table', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'fioreqctxts', + limit: 1000, + reverse: false, + show_payer: false } + fioreqctxts = await callFioApi("get_table_rows", json); + console.log('fioreqctxts: ', fioreqctxts.rows.length); } catch (err) { console.log('Error', err); expect(err).to.equal(null); } }) -}) - -describe.skip(`Bravo fix: Call migrtrx until table data is nuked`, () => { - let isFinished = 0 + it('Echo size of recordobts table', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'recordobts', + limit: 1000, + reverse: false, + show_payer: false + } + recordobts = await callFioApi("get_table_rows", json); + console.log('recordobts: ', recordobts.rows.length); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) - it('Echo initial migrledgers table', async () => { + it('Echo size of fioreqstss table', async () => { try { const json = { json: true, code: 'fio.reqobt', scope: 'fio.reqobt', - table: 'migrledgers', + table: 'fioreqstss', limit: 1000, reverse: false, show_payer: false } - ledger = await callFioApi("get_table_rows", json); - console.log('migrledgers: ', ledger); + fioreqstss = await callFioApi("get_table_rows", json); + console.log('fioreqstss: ', fioreqstss.rows.length); } catch (err) { console.log('Error', err); expect(err).to.equal(null); } }) - it(`Call migrtrx (bp1) with amount = 10 until migrtrx is empty`, async () => { - while (!isFinished) { + it(`Call migrtrx (bp1) with amount = 20 until (fioreqctxts, recordobts, fioreqstss) are empty`, async () => { + while (!fioreqctxtsIsFinished || !recordobtsIsFinished || !fioreqstssIsFinished) { try { const result = await callFioApiSigned('push_transaction', { action: 'migrtrx', @@ -1025,7 +2127,7 @@ describe.skip(`Bravo fix: Call migrtrx until table data is nuked`, () => { actor: bp1.account, privKey: bp1.privateKey, data: { - amount: 10, + amount: 20, actor: bp1.account } }) @@ -1041,15 +2143,53 @@ describe.skip(`Bravo fix: Call migrtrx until table data is nuked`, () => { json: true, code: 'fio.reqobt', scope: 'fio.reqobt', - table: 'fiotrxts', + table: 'fioreqctxts', limit: 1000, reverse: false, show_payer: false } - fiotrxts = await callFioApi("get_table_rows", json); - isFinished = (fiotrxts.rows.length == 0); - //console.log('fiotrxts: ', fiotrxts) - console.log('Table rows count: ', fiotrxts.rows.length) + fioreqctxts = await callFioApi("get_table_rows", json); + fioreqctxtsIsFinished = (fioreqctxts.rows.length == 0); + //console.log('fioreqctxts: ', fioreqctxts) + console.log('Table rows count: ', fioreqctxts.rows.length) + console.log('isFinished: ', isFinished); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'recordobts', + limit: 1000, + reverse: false, + show_payer: false + } + recordobts = await callFioApi("get_table_rows", json); + recordobtsIsFinished = (recordobts.rows.length == 0); + //console.log('recordobts: ', recordobts) + console.log('Table rows count: ', recordobts.rows.length) + console.log('isFinished: ', isFinished); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'fioreqstss', + limit: 1000, + reverse: false, + show_payer: false + } + fioreqstss = await callFioApi("get_table_rows", json); + fioreqstssIsFinished = (fioreqstss.rows.length == 0); + //console.log('fioreqstss: ', fioreqstss) + console.log('Table rows count: ', fioreqstss.rows.length) console.log('isFinished: ', isFinished); } catch (err) { console.log('Error', err); @@ -1058,23 +2198,65 @@ describe.skip(`Bravo fix: Call migrtrx until table data is nuked`, () => { } }) - it('Echo final migrledgers table', async () => { + it('Confirm fioreqctxts table is empty', async () => { try { const json = { json: true, code: 'fio.reqobt', scope: 'fio.reqobt', - table: 'migrledgers', + table: 'fioreqctxts', limit: 10, reverse: false, show_payer: false } - ledger = await callFioApi("get_table_rows", json); - console.log('migrledgers: ', ledger); + fioreqctxts = await callFioApi("get_table_rows", json); + console.log('fioreqctxts: ', fioreqctxts); + expect(fioreqctxts.rows.length).to.equal(0); } catch (err) { console.log('Error', err); expect(err).to.equal(null); } }) + it('Confirm recordobts table is empty', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'recordobts', + limit: 10, + reverse: false, + show_payer: false + } + recordobts = await callFioApi("get_table_rows", json); + console.log('recordobts: ', recordobts); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it('Confirm fioreqstss table is empty', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'fioreqstss', + limit: 10, + reverse: false, + show_payer: false + } + fioreqstss = await callFioApi("get_table_rows", json); + console.log('fioreqstss: ', fioreqstss); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) + +describe(`Release delta - remove migrtrx action, remove references to old tables (fioreqctxts, recordobts, fioreqstss) `, () => { }) \ No newline at end of file From 2e134c355a40d818fbfa5cb86697786c2b2df775 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Tue, 26 Jan 2021 11:49:35 -0700 Subject: [PATCH 46/76] Text fixes for migr bugs --- tests/bravo-migr-test.js | 2 +- tests/fio-request.js | 2 ++ tests/record-obt-data.js | 25 +++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index c8c58841..49513e98 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -2258,5 +2258,5 @@ describe.skip(`Release delta - remove data from old tables (fioreqctxts, recordo }) -describe(`Release delta - remove migrtrx action, remove references to old tables (fioreqctxts, recordobts, fioreqstss) `, () => { +describe.skip(`Release delta - remove migrtrx action, remove references to old tables (fioreqctxts, recordobts, fioreqstss) `, () => { }) \ No newline at end of file diff --git a/tests/fio-request.js b/tests/fio-request.js index 757710c3..63085602 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -43,6 +43,8 @@ describe(`************************** fio-request.js ************************** \ } }) + it(`Wait a few seconds.`, async () => { await timeout(2000) }) + it(`userA1 requests funds from userA2`, async () => { try { const result = await userA1.sdk.genericAction('requestFunds', { diff --git a/tests/record-obt-data.js b/tests/record-obt-data.js index 93e8ea44..892d2cfd 100644 --- a/tests/record-obt-data.js +++ b/tests/record-obt-data.js @@ -8,7 +8,7 @@ before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); }) -describe(`*********************** record-obt-data.js *********************** \n A. Test OBT DAta`, () => { +describe(`*********************** record-obt-data.js *********************** \n A. Test OBT Data`, () => { let userA1, userA2, userA2Balance, timeStamp const payment = 5000000000 // 5 FIO @@ -20,7 +20,7 @@ describe(`*********************** record-obt-data.js *********************** \n userA2 = await newUser(faucet); }) - it(`userA1 sends obt data to userA2`, async () => { + it(`userA1 sends recordObtData to userA2`, async () => { try { const result = await userA1.sdk.genericAction('recordObtData', { payerFioAddress: userA1.address, @@ -48,6 +48,8 @@ describe(`*********************** record-obt-data.js *********************** \n } }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) + it(`get_obt_data for userA1 (payer)`, async () => { try { const result = await userA1.sdk.genericAction('getObtData', { @@ -90,6 +92,25 @@ describe(`*********************** record-obt-data.js *********************** \n } }) + it('Echo fiotrxtss table (need to uncomment)', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'fiotrxtss', + limit: 5, + reverse: true, + show_payer: false + } + fiotrxtss = await callFioApi("get_table_rows", json); + //console.log('fiotrxtss: ', fiotrxtss); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + it('Call get_table_rows from fionames to get bundles remaining for userA2. Verify 100 bundles', async () => { let bundleCount try { From 82ffff48e84b771fdf10e06b0ca7c1cd88c04791 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Tue, 2 Feb 2021 06:48:55 -0700 Subject: [PATCH 47/76] Add timeout delays --- tests/bravo-migr-test.js | 3 +++ tests/fio-request.js | 51 ++++++++++++++++++++++++++++++++++++++- tests/paging.js | 4 ++- tests/transfer-address.js | 4 ++- tests/transfer-domain.js | 2 +- tests/vote.js | 8 +++--- 6 files changed, 64 insertions(+), 8 deletions(-) diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index 49513e98..8f547837 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -2119,6 +2119,7 @@ describe.skip(`Release delta - remove data from old tables (fioreqctxts, recordo }) it(`Call migrtrx (bp1) with amount = 20 until (fioreqctxts, recordobts, fioreqstss) are empty`, async () => { + let fioreqctxtsIsFinished = false, recordobtsIsFinished = false, fioreqstssIsFinished = false; while (!fioreqctxtsIsFinished || !recordobtsIsFinished || !fioreqstssIsFinished) { try { const result = await callFioApiSigned('push_transaction', { @@ -2231,6 +2232,7 @@ describe.skip(`Release delta - remove data from old tables (fioreqctxts, recordo } recordobts = await callFioApi("get_table_rows", json); console.log('recordobts: ', recordobts); + expect(recordobts.rows.length).to.equal(0); } catch (err) { console.log('Error', err); expect(err).to.equal(null); @@ -2250,6 +2252,7 @@ describe.skip(`Release delta - remove data from old tables (fioreqctxts, recordo } fioreqstss = await callFioApi("get_table_rows", json); console.log('fioreqstss: ', fioreqstss); + expect(fioreqstss.rows.length).to.equal(0); } catch (err) { console.log('Error', err); expect(err).to.equal(null); diff --git a/tests/fio-request.js b/tests/fio-request.js index 63085602..44024563 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -2428,6 +2428,29 @@ describe(`I. reject_funds_request: Check all getters after`, () => { } }) + it(`Wait a few seconds.`, async () => { await timeout(2000) }) + + it(`get_sent_fio_requests for userA1 (payee) BEFORE Reject`, async () => { + try { + const result = await userA1.sdk.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result); + //console.log('content: ', result.requests[0].content); + expect(result.requests[0].fio_request_id).to.equal(requestId); + expect(result.requests[0].payer_fio_address).to.equal(userA2.address); + expect(result.requests[0].payee_fio_address).to.equal(userA1.address); + expect(result.requests[0].payer_fio_public_key).to.equal(userA2.publicKey); + expect(result.requests[0].payee_fio_public_key).to.equal(userA1.publicKey); + expect(result.requests[0].status).to.equal('requested'); + expect(result.requests[0].content.memo).to.equal(requestMemo); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + it(`userA2 rejects funds request`, async () => { try{ const result = await userA2.sdk.genericAction('pushTransaction', { @@ -2448,7 +2471,7 @@ describe(`I. reject_funds_request: Check all getters after`, () => { } }) - it(`get_sent_fio_requests for userA1 (payee)`, async () => { + it(`get_sent_fio_requests for userA1 (payee) AFTER Reject`, async () => { try { const result = await userA1.sdk.genericAction('getSentFioRequests', { limit: '', @@ -2584,4 +2607,30 @@ describe(`I. reject_funds_request: Check all getters after`, () => { } }) + it.skip('Call get_table_rows from fiotrxtss (NEW table) and confirm request is in table', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.reqobt', // Contract that we target + scope: 'fio.reqobt', // Account that owns the data + table: 'fiotrxtss', // Table name + limit: 2, // Maximum number of rows that we want to get + reverse: true, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + requests = await callFioApi("get_table_rows", json); + console.log('requests: ', requests); + for (request in requests.rows) { + if (requests.rows[request].fio_request_id == requestId) { + console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + break; + } + } + expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + }) diff --git a/tests/paging.js b/tests/paging.js index 446c5581..d80696de 100644 --- a/tests/paging.js +++ b/tests/paging.js @@ -1,7 +1,7 @@ require('mocha') config = require('../config.js'); const {expect} = require('chai') -const {newUser, fetchJson, generateFioDomain, generateFioAddress, createKeypair, callFioApi} = require('../utils.js'); +const {newUser, fetchJson, generateFioDomain, generateFioAddress, createKeypair, callFioApi, timeout} = require('../utils.js'); const {FIOSDK } = require('@fioprotocol/fiosdk') @@ -464,6 +464,8 @@ describe(`B. get_fio_addresses paging: Register multiple addresses and page thro } }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) + it(`Call (get_fio_addresses, no limit param, no offset param). Expect ${addressCount} results`, async () => { try { const json = { diff --git a/tests/transfer-address.js b/tests/transfer-address.js index 514b383a..991a2a86 100644 --- a/tests/transfer-address.js +++ b/tests/transfer-address.js @@ -951,7 +951,7 @@ describe('E. Confirm active producers and proxy cannot transfer address', () => } }) - it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) it('Confirm is_proxy = 1 for proxy1 ', async () => { try { @@ -1042,6 +1042,8 @@ describe('F. BRAVO ONLY: Confirm users with OBT records or Requests cannot trans } }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) + it(`Transfer user1.address to user2. Expect error 500 - assertion failure with message: Transfering a FIO address is currently disabled for some fio.addresses `, async () => { try { const result = await user1.sdk.genericAction('transferFioAddress', { diff --git a/tests/transfer-domain.js b/tests/transfer-domain.js index 92f53868..b91a2f99 100644 --- a/tests/transfer-domain.js +++ b/tests/transfer-domain.js @@ -399,7 +399,7 @@ describe('B. Transfer a domain to FIO Public Key which does not map to existing } }) - it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) it('Confirm proper fee was collected', async () => { expect(feeCollected).to.equal(transfer_fio_domain_fee) diff --git a/tests/vote.js b/tests/vote.js index 459cb62e..aad86b43 100644 --- a/tests/vote.js +++ b/tests/vote.js @@ -2493,7 +2493,7 @@ describe(`H. Test proxy re-vote of proxy, re-proxy of voter`, () => { } }) - it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) it(`proxyA1 votes for bp1@dapixdev using address #1`, async () => { try { @@ -2517,7 +2517,7 @@ describe(`H. Test proxy re-vote of proxy, re-proxy of voter`, () => { } }) - it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) it(`user1 proxies votes to proxyA1`, async () => { try { @@ -2617,7 +2617,7 @@ describe(`H. Test proxy re-vote of proxy, re-proxy of voter`, () => { } }) - it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) it(`user1 proxies votes AGAIN to proxyA1`, async () => { try { @@ -2881,7 +2881,7 @@ describe(`J. Test total_voted_fio when user votes for proxy`, () => { } }) - it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) it(`Get total_voted_fio before proxyA1 votes`, async () => { total_voted_fio = await getTotalVotedFio(); From 6f1326a2b3844bbf9680f90fec531daed16087cb Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Thu, 11 Feb 2021 16:10:57 -0700 Subject: [PATCH 48/76] Adding fio requests tests --- config.js | 1 + index.js | 6 +- tests/bravo-migr-test.js | 2 +- tests/fio-request.js | 8 +- tests/performance-request-obt.js | 458 ++++++++++++++++++ tests/record-obt-data.js | 155 ------ tests/remove-address.js | 2 +- tests/transfer-locked-tokens-account-tests.js | 18 +- 8 files changed, 480 insertions(+), 170 deletions(-) create mode 100644 tests/performance-request-obt.js diff --git a/config.js b/config.js index 85642f7e..6a796ee2 100644 --- a/config.js +++ b/config.js @@ -2,6 +2,7 @@ const TESTURL = 'http://localhost:8889' // Localhost //const TESTURL = 'http://44.234.45.7:8889' // DEV1 //const TESTURL = 'http://44.238.153.162:8889' // Devnet //const TESTURL = 'http://testnet.fioprotocol.io' // Testnet +//const TESTURL = 'http://dev1.fio.dev:8888' // Testnet Bahamas //const TESTURL = 'https://fio.greymass.com' // Mainnet diff --git a/index.js b/index.js index 35d9db43..6c79a174 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,10 @@ const {expect} = require('chai') describe('TEST SUITE', () => { + require('./tests/bravo-migr-test.js') + require('./tests/performance-request-obt.js'); + +/* require('./tests/bravo-migr-test.js'); //This is required when testing 2.3.0 (bravo) with fio bahamas (need to do the full table migration). //require('./tests/history.js'); // Only run against history node. @@ -33,5 +37,5 @@ describe('TEST SUITE', () => { //require('./tests/clio.js'); // FIP-16 require('./tests/testnet-smoketest.js'); // Testnet smoketest. By default runs against local build. - + */ }); diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index 8f547837..c7c10a1e 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -42,7 +42,7 @@ before(async () => { }) -describe.skip(`************************** bravo-migr-test.js.js ************************** \n fiotrxts (original table) scripts`, () => { +describe.skip(`************************** bravo-migr-test.js ************************** \n fiotrxts (original table) scripts`, () => { describe(`A. Load Requests and OBTs`, () => { let user1, user2, user3; diff --git a/tests/fio-request.js b/tests/fio-request.js index 44024563..e2e92b7c 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -271,14 +271,14 @@ describe(`************************** fio-request.js ************************** \ await timeout(7000); }) - it.skip(`BUG (bahamas): BD-2306 get_sent_fio_requests for userA1`, async () => { + it(`get_sent_fio_requests for userA1 (BD-2306)`, async () => { try { const result = await userA1.sdk.genericAction('getSentFioRequests', { limit: '', offset: '' }) - console.log('result: ', result) - console.log('content: ', result.requests[0].content) + //console.log('result: ', result) + //console.log('content: ', result.requests[0].content) expect(result.requests[0].content.memo).to.equal(requestMemo) expect(result.requests[0].status).to.equal('sent_to_blockchain') } catch (err) { @@ -287,7 +287,7 @@ describe(`************************** fio-request.js ************************** \ } }) - it.skip(`BUG (bahamas): BD-2306 get_sent_fio_requests for userA1 (payee)`, async () => { + it(`get_sent_fio_requests for userA1 (payee) (BD-2306)`, async () => { try { const result = await userA1.sdk.genericAction('getSentFioRequests', { limit: '', diff --git a/tests/performance-request-obt.js b/tests/performance-request-obt.js new file mode 100644 index 00000000..5ab16667 --- /dev/null +++ b/tests/performance-request-obt.js @@ -0,0 +1,458 @@ +require('mocha') +const {expect} = require('chai') +const {newUser, fetchJson, callFioApi, timeout} = require('../utils.js'); +const {FIOSDK } = require('@fioprotocol/fiosdk') +config = require('../config.js'); + +before(async () => { + faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); +}) + +describe(`************************** performance-request-obt.js ************************** \n A. FIO Request and OBT Record performance test`, () => { + let user1, user2, user3, + payment = 3000000000, + requestMemo = 'asdf', + count = 5, + funding = 5000000000000 + + it(`Create users`, async () => { + user1 = await newUser(faucet); + user2 = await newUser(faucet); + user3 = await newUser(faucet); + + //console.log('user1: ' + user1.account + ', ' + user1.privateKey + ', ' + user1.publicKey) + //console.log('user2: ' + user2.account + ', ' + user2.privateKey + ', ' + user2.publicKey) + //console.log('user3: ' + user3.account + ', ' + user3.privateKey + ', ' + user3.publicKey) + }) + + it('Transfer lots of FIO to users', async () => { + try { + const result = await faucet.genericAction('transferTokens', { + payeeFioPublicKey: user1.publicKey, + amount: funding, + maxFee: config.maxFee, + technologyProviderId: '' + }) + //console.log('Result: ', result) + expect(result).to.have.all.keys('transaction_id', 'block_num', 'status', 'fee_collected') + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } + + try { + const result = await faucet.genericAction('transferTokens', { + payeeFioPublicKey: user2.publicKey, + amount: funding, + maxFee: config.maxFee, + technologyProviderId: '' + }) + //console.log('Result: ', result) + expect(result).to.have.all.keys('transaction_id', 'block_num', 'status', 'fee_collected') + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } + + try { + const result = await faucet.genericAction('transferTokens', { + payeeFioPublicKey: user3.publicKey, + amount: funding, + maxFee: config.maxFee, + technologyProviderId: '' + }) + //console.log('Result: ', result) + expect(result).to.have.all.keys('transaction_id', 'block_num', 'status', 'fee_collected') + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } + }) + + describe(`A. Load Requests and OBTs`, () => { + + it(`${count}x - user1 requests funds from user2`, async () => { + for (i = 0; i < count; i++) { + try { + const result = await user1.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user1.address, + payeeTokenPublicAddress: user1.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) + + it(`${count}x - user2 requests funds from user1`, async () => { + for (i = 0; i < count; i++) { + try { + const result = await user2.sdk.genericAction('requestFunds', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payeeTokenPublicAddress: user2.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user1.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) + + it(`${count}x - user3 requests funds from user2, user2 rejects request`, async () => { + let requestId; + for (i = 0; i < count; i++) { + try { + const result = await user3.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user3.address, + payeeTokenPublicAddress: user3.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + requestId = result.fio_request_id; + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + + try { + const result = await user2.sdk.genericAction('pushTransaction', { + action: 'rejectfndreq', + account: 'fio.reqobt', + data: { + fio_request_id: requestId, + max_fee: config.api.cancel_funds_request.fee, + tpid: '', + actor: user2.account + } + }) + //console.log('Result:', result) + expect(result.status).to.equal('request_rejected') + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + } + }) + + it(`${count}x - user2 requests funds from user1, user 1 records OBT response`, async () => { + let requestId; + for (i = 0; i < count; i++) { + try { + const result = await user2.sdk.genericAction('requestFunds', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payeeTokenPublicAddress: user2.address, + amount: payment, + chainCode: 'FIO', + tokenCode: 'FIO', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: user1.publicKey, + technologyProviderId: '', + hash: 'fmwazjvmenfz', // This is the hash of off-chain data... ? + offlineUrl: '' + }) + //console.log('Result: ', result) + requestId = result.fio_request_id; + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + + try { + const result = await user1.sdk.genericAction('recordObtData', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payerTokenPublicAddress: user1.publicKey, + payeeTokenPublicAddress: user2.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: requestId, + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user2.publicKey, + memo: 'this is a test', + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) + + it(`${count}x user3 creates BTC OBT send record to user1`, async () => { + for (i = 0; i < count; i++) { + try { + const result = await user3.sdk.genericAction('recordObtData', { + payerFioAddress: user3.address, + payeeFioAddress: user1.address, + payerTokenPublicAddress: user3.publicKey, + payeeTokenPublicAddress: user1.publicKey, + amount: payment, + chainCode: "BTC", + tokenCode: "BTC", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: user1.publicKey, + memo: 'this is a test', + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error', err.json) + expect(err).to.equal(null) + } + } + }) + + }) + + describe(`B. Check user1`, () => { + + it(`get_sent_fio_requests for user1`, async () => { + try { + const result = await user1.sdk.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result); + //console.log('length: ', result.requests.length); + expect(result.requests.length).to.equal(count) + //expect(result.requests[0].fio_request_id).to.equal(requestId); + //expect(result.requests[0].payer_fio_address).to.equal(userA2.address); + //expect(result.requests[0].payee_fio_address).to.equal(userA1.address); + //expect(result.requests[0].payer_fio_public_key).to.equal(userA2.publicKey); + //expect(result.requests[0].payee_fio_public_key).to.equal(userA1.publicKey); + //expect(result.requests[0].status).to.equal('requested'); + //expect(result.requests[0].content.memo).to.equal(requestMemo); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it.skip(`get_sent_fio_requests for userA2 (payer). Expect 'No FIO Requests'`, async () => { + try { + const result = await userA2.sdk.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result); + //console.log('content: ', result.requests[0].content); + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.message).to.equal('No FIO Requests') + } + }) + + it(`get_pending_fio_requests for user1`, async () => { + try { + const result = await user1.sdk.genericAction('getPendingFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result.requests.length).to.equal(count * 2) + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) +/* + it.skip(`get_pending_fio_requests for user2 (payer)`, async () => { + try { + const result = await user2.sdk.genericAction('getPendingFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result.requests[0].fio_request_id).to.equal(requestId); + expect(result.requests[0].payer_fio_address).to.equal(userA2.address); + expect(result.requests[0].payee_fio_address).to.equal(userA1.address); + expect(result.requests[0].payer_fio_public_key).to.equal(userA2.publicKey); + expect(result.requests[0].payee_fio_public_key).to.equal(userA1.publicKey); + expect(result.requests[0].content.memo).to.equal(requestMemo); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) +*/ + it(`get_cancelled_fio_requests for user1 (payee). Expect 'No FIO Requests'`, async () => { + try { + const result = await user1.sdk.genericAction('getCancelledFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.message).to.equal('No FIO Requests') + } + }) + + it.skip(`get_cancelled_fio_requests for user2 (payer). Expect 'No FIO Requests'`, async () => { + try { + const result = await user1.sdk.genericAction('getCancelledFioRequests', { + limit: '', + offset: '' + }) + console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.message).to.equal('No FIO Requests') + } + }) + + it(`Bahamas TODO: update after added to SDK to include memo check. get_received_fio_requests for user1 (payer)`, async () => { + try { + const json = { + fio_public_key: user1.publicKey, + limit: 100, + offset: 0 + } + result = await callFioApi("get_received_fio_requests", json); + //console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + //expect(result.requests[0].fio_request_id).to.equal(requestId); + //expect(result.requests[0].payer_fio_address).to.equal(userA2.address); + //expect(result.requests[0].payee_fio_address).to.equal(userA1.address); + //expect(result.requests[0].payer_fio_public_key).to.equal(userA2.publicKey); + //expect(result.requests[0].payee_fio_public_key).to.equal(userA1.publicKey); + //expect(result.requests[0].status).to.equal('requested'); + //expect(result.requests[0].content.memo).to.equal(requestMemo); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it.skip(`get_received_fio_requests for userA1 (payee). Expect 'No FIO Requests'`, async () => { + try { + const json = { + fio_public_key: userA1.publicKey, + limit: 100, + offset: 0 + } + result = await callFioApi("get_received_fio_requests", json); + console.log('result: ', result.json) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err.response) + expect(err.response.body.message).to.equal('No FIO Requests') + } + }) + + it(`getObtData for user1`, async () => { + try { + const result = await user1.sdk.genericAction('getObtData', { + limit: '', + offset: '', + }) + console.log('result: ', result) + //console.log('content: ', result.obt_data_records[0].content) + expect(result.requests.length).to.equal(count * 2) + //expect(result.obt_data_records[0].fio_request_id).to.equal(requestId); + //expect(result.obt_data_records[0].payer_fio_address).to.equal(userA2.address); + //expect(result.obt_data_records[0].payee_fio_address).to.equal(userA1.address); + //expect(result.obt_data_records[0].payer_fio_public_key).to.equal(userA2.publicKey); + //expect(result.obt_data_records[0].payee_fio_public_key).to.equal(userA1.publicKey); + //expect(result.obt_data_records[0].status).to.equal('sent_to_blockchain'); + //expect(result.obt_data_records[0].content.memo).to.equal(obtMemo); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it.skip(`getObtData for user2`, async () => { + try { + const result = await userA1.sdk.genericAction('getObtData', { + limit: '', + offset: '', + }) + //console.log('result: ', result) + //console.log('content: ', result.obt_data_records[0].content) + expect(result.obt_data_records[0].fio_request_id).to.equal(requestId); + expect(result.obt_data_records[0].payer_fio_address).to.equal(userA2.address); + expect(result.obt_data_records[0].payee_fio_address).to.equal(userA1.address); + expect(result.obt_data_records[0].payer_fio_public_key).to.equal(userA2.publicKey); + expect(result.obt_data_records[0].payee_fio_public_key).to.equal(userA1.publicKey); + expect(result.obt_data_records[0].status).to.equal('sent_to_blockchain'); + expect(result.obt_data_records[0].content.memo).to.equal(obtMemo); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`get_fio_balance`, async () => { + try { + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + //console.log('result: ', result) + balance = result.balance + expect(result.balance).to.be.greaterThan(0) + } catch (err) { + console.log('Error: ', err) + } + }) + + }) + +}) diff --git a/tests/record-obt-data.js b/tests/record-obt-data.js index 892d2cfd..a4c05e8a 100644 --- a/tests/record-obt-data.js +++ b/tests/record-obt-data.js @@ -433,158 +433,3 @@ describe(`B. OBT Data Error Check`, () => { }) }) -describe.skip(`C. OBT Performance Testing`, () => { - - let userA1, userA2, userB1, userB2, userC1, userC2 - const payment = 5000000000 // 5 FIO - const requestMemo = 'Memo in the initial request' - const obtMemo = 'Memo in OBT response to request' - - it(`Create users`, async () => { - userA1 = await newUser(faucet); - userA2 = await newUser(faucet); - - userB1 = await newUser(faucet); - userB2 = await newUser(faucet); - - userC1 = await newUser(faucet); - userC2 = await newUser(faucet); - }) - - it(`userA1 requests funds from userA2 5000 times`, async () => { - for (i = 0; i < 1000; i++) { - try { - const result = await userA1.sdk.genericAction('recordObtData', { - payerFioAddress: userA1.address, - payeeFioAddress: userA2.address, - payerTokenPublicAddress: userA1.publicKey, - payeeTokenPublicAddress: userA2.publicKey, - amount: payment, - chainCode: "FIO", - tokenCode: "FIO", - status: '', - obtId: '', - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: userA1.publicKey, - memo: obtMemo, - hash: '', - offLineUrl: '' - }) - //console.log('Result: ', result) - expect(result.status).to.equal('sent_to_blockchain') - } catch (err) { - console.log('Error', err.json) - expect(err).to.equal(null) - } - } - - for (i = 0; i < 1000; i++) { - try { - const result = await userA2.sdk.genericAction('recordObtData', { - payerFioAddress: userA2.address, - payeeFioAddress: userA1.address, - payerTokenPublicAddress: userA2.publicKey, - payeeTokenPublicAddress: userA1.publicKey, - amount: payment, - chainCode: "FIO", - tokenCode: "FIO", - status: '', - obtId: '', - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: userA2.publicKey, - memo: obtMemo, - hash: '', - offLineUrl: '' - }) - //console.log('Result: ', result) - expect(result.status).to.equal('sent_to_blockchain') - } catch (err) { - console.log('Error', err.json) - expect(err).to.equal(null) - } - } - - for (i = 0; i < 1000; i++) { - try { - const result = await userC1.sdk.genericAction('recordObtData', { - payerFioAddress: userC1.address, - payeeFioAddress: userC2.address, - payerTokenPublicAddress: userC1.publicKey, - payeeTokenPublicAddress: userC2.publicKey, - amount: payment, - chainCode: "FIO", - tokenCode: "FIO", - status: '', - obtId: '', - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: userC1.publicKey, - memo: obtMemo, - hash: '', - offLineUrl: '' - }) - //console.log('Result: ', result) - expect(result.status).to.equal('sent_to_blockchain') - } catch (err) { - console.log('Error', err.json) - expect(err).to.equal(null) - } - } - - for (i = 0; i < 1000; i++) { - try { - const result = await userC2.sdk.genericAction('recordObtData', { - payerFioAddress: userC2.address, - payeeFioAddress: userC1.address, - payerTokenPublicAddress: userC2.publicKey, - payeeTokenPublicAddress: userC1.publicKey, - amount: payment, - chainCode: "FIO", - tokenCode: "FIO", - status: '', - obtId: '', - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: userC2.publicKey, - memo: obtMemo, - hash: '', - offLineUrl: '' - }) - //console.log('Result: ', result) - expect(result.status).to.equal('sent_to_blockchain') - } catch (err) { - console.log('Error', err.json) - expect(err).to.equal(null) - } - } - - for (i = 0; i < 1000; i++) { - try { - const result = await userB2.sdk.genericAction('recordObtData', { - payerFioAddress: userB2.address, - payeeFioAddress: userB1.address, - payerTokenPublicAddress: userB2.publicKey, - payeeTokenPublicAddress: userB1.publicKey, - amount: payment, - chainCode: "FIO", - tokenCode: "FIO", - status: '', - obtId: '', - maxFee: config.api.record_obt_data.fee, - technologyProviderId: '', - payeeFioPublicKey: userB2.publicKey, - memo: obtMemo, - hash: '', - offLineUrl: '' - }) - //console.log('Result: ', result) - expect(result.status).to.equal('sent_to_blockchain') - } catch (err) { - console.log('Error', err.json) - expect(err).to.equal(null) - } - } - }) -}) diff --git a/tests/remove-address.js b/tests/remove-address.js index 40489166..128536d7 100644 --- a/tests/remove-address.js +++ b/tests/remove-address.js @@ -1247,7 +1247,7 @@ describe(`F. Sad - result in error`, () => { expect(result.code).to.equal(config.error2.invalidActorAuth.statusCode); }) - it(`Not a bug. SDK generates the actor from the userA1 private key. So, this will work.`, async () => { + it(`Not an error. SDK generates the actor from the userA1 private key. So, this will work.`, async () => { try{ const result = await userA1.sdk.genericAction('pushTransaction', { action: 'remaddress', diff --git a/tests/transfer-locked-tokens-account-tests.js b/tests/transfer-locked-tokens-account-tests.js index 149dbb53..05f52a1e 100644 --- a/tests/transfer-locked-tokens-account-tests.js +++ b/tests/transfer-locked-tokens-account-tests.js @@ -924,17 +924,17 @@ describe('C. Request funds, approve and send', () => { it(`Wait a few seconds.`, async () => { await timeout(8000) }) - it.skip(`BUG (bahamas): BD-2306 getSentFioRequests for fioSdk2`, async () => { + it(`getSentFioRequests for fioSdk2 (BD-2306)`, async () => { const result = await fioSdk2.genericAction('getSentFioRequests', { limit: '', offset: '' }) - console.log('Result: ', result) + //console.log('Result: ', result) expect(result).to.have.all.keys('requests', 'more') expect(result.requests).to.be.a('array') expect(result.more).to.be.a('number') const pendingReq = result.requests.find(pr => parseInt(pr.fio_request_id) === parseInt(requestId)) - console.log('pendingReq: ', pendingReq) + //console.log('pendingReq: ', pendingReq) expect(pendingReq).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'status', 'time_stamp', 'content') expect(pendingReq.fio_request_id).to.be.a('number') expect(pendingReq.fio_request_id).to.equal(requestId) @@ -1138,7 +1138,7 @@ describe('F. Transfer tokens', () => { }) }) -describe('G. Record obt data, check', () => { +describe('G. Record obt data, check getObtData', () => { const obtId = generateObtId() const fundsAmount = 4.5 @@ -1188,7 +1188,7 @@ describe('G. Record obt data, check', () => { expect(obtData.payee_fio_address).to.equal(testFioAddressName2) }) - it.skip(`BUG BD-2305 (not all results getting returned) Payee getObtData`, async () => { + it(`BUG BD-2305 (not all results getting returned) Payee getObtData`, async () => { const result = await fioSdk2.genericAction('getObtData', { tokenCode: fioTokenCode }) console.log('result: ', result) expect(result).to.have.all.keys('obt_data_records', 'more') @@ -1399,15 +1399,17 @@ describe(`H. Test locked token accounts with proxy voting`, () => { it(`Get fioSdk last_vote_weight (should be 200 + 2 fee = 202 less)`, async () => { try { + prevVoteWeight = fioSdk.last_vote_weight fioSdk.last_vote_weight = await getAccountVoteWeight(account); //console.log('fioSdk.last_vote_weight:', fioSdk.last_vote_weight) + expect(fioSdk.last_vote_weight).to.equal(prevVoteWeight- 200000000000 - transfer_tokens_pub_key_fee) } catch (err) { - console.log('Error: ', err.json) + console.log('Error: ', err) expect(err).to.equal('null') } }) - it(`(Bug? will address in most recent fio.test)total_voted_fio decreased by 200 - transfer_tokens_pub_key fee`, async () => { + it(`total_voted_fio decreased by 200 - transfer_tokens_pub_key fee`, async () => { try { let prev_total_voted_fio = total_voted_fio total_voted_fio = await getTotalVotedFio(); @@ -1419,7 +1421,7 @@ describe(`H. Test locked token accounts with proxy voting`, () => { } }) - it(`(Bug? will address in most recent fio.test) bp1@dapixdev total_votes descreased by 200 - transfer_tokens_pub_key fee`, async () => { + it(`bp1@dapixdev total_votes decreased by 200 - transfer_tokens_pub_key fee`, async () => { try { let prev_total_bp_votes = total_bp_votes; total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); From 4fb4fa3ab5b0448babd7c9308a991549446ed36f Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 15 Feb 2021 07:58:39 -0700 Subject: [PATCH 49/76] clio test updates --- index.js | 6 +- tests/clio.js | 225 ++++++++++++++++++++++++++++++++++++++----- tests/fio-request.js | 61 ++++++++++++ 3 files changed, 266 insertions(+), 26 deletions(-) diff --git a/index.js b/index.js index 6c79a174..1d392c53 100644 --- a/index.js +++ b/index.js @@ -3,10 +3,8 @@ const {expect} = require('chai') describe('TEST SUITE', () => { - require('./tests/bravo-migr-test.js') - require('./tests/performance-request-obt.js'); -/* + require('./tests/bravo-migr-test.js'); //This is required when testing 2.3.0 (bravo) with fio bahamas (need to do the full table migration). //require('./tests/history.js'); // Only run against history node. @@ -37,5 +35,5 @@ describe('TEST SUITE', () => { //require('./tests/clio.js'); // FIP-16 require('./tests/testnet-smoketest.js'); // Testnet smoketest. By default runs against local build. - */ + }); diff --git a/tests/clio.js b/tests/clio.js index b7001f54..e8c01634 100644 --- a/tests/clio.js +++ b/tests/clio.js @@ -1,6 +1,6 @@ require('mocha') const {expect} = require('chai') -const {newUser, randStr, generateFioDomain, generateFioAddress, unlockWallet, callFioApi, fetchJson} = require('../utils.js'); +const {newUser, randStr, generateFioDomain, generateFioAddress, unlockWallet, callFioApi, timeout, fetchJson} = require('../utils.js'); const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); @@ -33,30 +33,33 @@ async function runClio(parms) { before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson) - result = await unlockWallet('fio'); + const result = await unlockWallet('fio'); }) describe(`************************** clio.js ************************** \n A. Test clio`, () => { it(`get info`, async () => { - result = await runClio('get info'); + const result = await runClio('get info'); expect(JSON.parse(result).head_block_num).to.be.a('number') }) }) -describe(`B. Request and OBT Data`, () => { - let fio_request_id, fio_request_id2, fio_request_id3, user1, user2 +describe.only(`B. Request and OBT Data`, () => { + let fio_request_id, fio_request_id2, fio_request_id3, user1, user2, resultSdk, resultClio, contentSdk, contentClio it(`Create users and import private keys`, async () => { user1 = await newUser(faucet); - result = await runClio('wallet import -n fio --private-key ' + user1.privateKey); + await runClio('wallet import -n fio --private-key ' + user1.privateKey); user2 = await newUser(faucet); - result = await runClio('wallet import -n fio --private-key ' + user2.privateKey); + await runClio('wallet import -n fio --private-key ' + user2.privateKey); + + console.log('user1 pub key: ', user1.publicKey) + console.log('user2 pub key: ', user2.publicKey) }) - it(`Request new`, async () => { + it(`clio: request new (user1 requests funds from user2)`, async () => { try { - result = await runClio(`request new -j ${user2.address} ${user1.address} ${content} ${user1.account} ${tpid} ${max_fee} --permission ${user1.account}@active`); + const result = await runClio(`request new -j ${user2.address} ${user1.address} ${content} ${user1.account} ${tpid} ${max_fee} --permission ${user1.account}@active`); //console.log('Result: ', result) fio_request_id = JSON.parse(JSON.parse(result).processed.action_traces[0].receipt.response).fio_request_id //console.log('ID: ', JSON.parse(JSON.parse(result).processed.action_traces[0].receipt.response).fio_request_id) @@ -67,7 +70,71 @@ describe(`B. Request and OBT Data`, () => { } }) - it(`Request reject`, async () => { + it(`SDK: user1 requests funds from user2`, async () => { + try { + const result = await user1.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user1.address, + payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', + amount: 500000, + chainCode: 'BTC', + tokenCode: 'BTC', + memo: 'requestMemo', + maxFee: config.maxFee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '', + }) + requestId = result.fio_request_id + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(2000) }) + + it.skip(`(BUG BD-2358) get_sent_fio_requests for user1 (payee). Both clio and SDK requests to return same content.`, async () => { + try { + const result = await user1.sdk.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result); + //console.log('fio_request_id: ', fio_request_id) + expect(result.requests[0].fio_request_id).to.equal(result.requests[1].fio_request_id); + expect(result.requests[0].payer_fio_address).to.equal(result.requests[1].payer_fio_address); + expect(result.requests[0].payee_fio_address).to.equal(result.requests[1].payee_fio_address); + expect(result.requests[0].payer_fio_public_key).to.equal(result.requests[1].payer_fio_public_key); + expect(result.requests[0].payee_fio_public_key).to.equal(result.requests[1].payee_fio_public_key); + expect(result.requests[0].status).to.equal(result.requests[1].status); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it('(api) Call get_sent_fio_requests', async () => { + try { + const result = await callFioApi("get_sent_fio_requests", { + fio_public_key: user1.publicKey, + limit: 10, + offset: 0 + }) + //console.log('Result', result) + expect(result.requests[0].fio_request_id).to.equal(result.requests[1].fio_request_id - 1); + expect(result.requests[0].payer_fio_address).to.equal(result.requests[1].payer_fio_address); + expect(result.requests[0].payee_fio_address).to.equal(result.requests[1].payee_fio_address); + expect(result.requests[0].payer_fio_public_key).to.equal(result.requests[1].payer_fio_public_key); + expect(result.requests[0].payee_fio_public_key).to.equal(result.requests[1].payee_fio_public_key); + expect(result.requests[0].status).to.equal(result.requests[1].status); + } catch (err) { + console.log('Error', err) + } + }) + + it(`clio: request reject (user2 rejects request from user1)`, async () => { try { result = await runClio(`request reject -j ${fio_request_id} ${user2.account} ${tpid} ${max_fee} --permission ${user2.account}@active`); //console.log('Result: ', result) @@ -78,7 +145,27 @@ describe(`B. Request and OBT Data`, () => { } }) - it(`Request new`, async () => { + it(`(BUG BD-2358) get_sent_fio_requests for user1 (payee). Expect one request with status = 'rejected'`, async () => { + try { + const result = await user1.sdk.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + console.log('result: ', result); + //console.log('content: ', result.requests[0].content); + //expect(result.requests[0].fio_request_id).to.equal(fio_request_id); + //expect(result.requests[0].payer_fio_address).to.equal(user2.address); + //expect(result.requests[0].payee_fio_address).to.equal(user1.address); + //expect(result.requests[0].payer_fio_public_key).to.equal(user2.publicKey); + //expect(result.requests[0].payee_fio_public_key).to.equal(user1.publicKey); + //expect(result.requests[0].status).to.equal('rejected'); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`clio: request new (user2 requests funds from user1)`, async () => { try { result = await runClio(`request new -j ${user1.address} ${user2.address} ${content} ${user2.account} ${tpid} ${max_fee} --permission ${user2.account}@active`); //console.log('Result: ', result) @@ -90,7 +177,26 @@ describe(`B. Request and OBT Data`, () => { } }) - it(`Request cancel`, async () => { + it(`get_pending_fio_requests for user1 (payer). Expect one request with status = 'pending'`, async () => { + try { + const result = await user1.sdk.genericAction('getPendingFioRequests', { + limit: '', + offset: '' + }) + console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result.requests[0].fio_request_id).to.equal(fio_request_id2); + expect(result.requests[0].payer_fio_address).to.equal(user1.address); + expect(result.requests[0].payee_fio_address).to.equal(user2.address); + expect(result.requests[0].payer_fio_public_key).to.equal(user1.publicKey); + expect(result.requests[0].payee_fio_public_key).to.equal(user2.publicKey); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`clio: request cancel (user2 cancels sent request)`, async () => { try { result = await runClio(`request cancel -j ${fio_request_id2} ${user2.account} ${tpid} ${max_fee} --permission ${user2.account}@active`); //console.log('Result: ', result) @@ -101,7 +207,26 @@ describe(`B. Request and OBT Data`, () => { } }) - it(`Request new`, async () => { + it(`get_pending_fio_requests for user1 (payer). Expect one request with status = 'cancelled'`, async () => { + try { + const result = await user1.sdk.genericAction('getPendingFioRequests', { + limit: '', + offset: '' + }) + console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result.requests[0].fio_request_id).to.equal(fio_request_id2); + expect(result.requests[0].payer_fio_address).to.equal(user1.address); + expect(result.requests[0].payee_fio_address).to.equal(user2.address); + expect(result.requests[0].payer_fio_public_key).to.equal(user1.publicKey); + expect(result.requests[0].payee_fio_public_key).to.equal(user2.publicKey); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`clio: request new (user1 requests funds from user2)`, async () => { try { result = await runClio(`request new -j ${user2.address} ${user1.address} ${content2} ${user1.account} ${tpid} ${max_fee} --permission ${user1.account}@active`); //console.log('Result: ', result) @@ -113,7 +238,7 @@ describe(`B. Request and OBT Data`, () => { } }) - it(`Record`, async () => { + it(`clio: record (user2 records obt record in response to request)`, async () => { try { result = await runClio(`data record -j ${fio_request_id3} ${user2.address} ${user1.address} ${content3} ${user2.account} ${tpid} ${max_fee} --permission ${user2.account}@active`); //console.log('Result: ', result) @@ -123,6 +248,47 @@ describe(`B. Request and OBT Data`, () => { } }) + it(`getObtData for user2. Expect one record with status = 'sent_to_blockchain'`, async () => { + try { + const result = await user2.sdk.genericAction('getObtData', { + limit: '', + offset: '', + tokenCode: 'BTC' + }) + console.log('result: ', result) + //console.log('content: ', result.obt_data_records[0].content) + expect(result.obt_data_records[0].fio_request_id).to.equal(fio_request_id3); + expect(result.obt_data_records[0].payer_fio_address).to.equal(user2.address); + expect(result.obt_data_records[0].payee_fio_address).to.equal(user1.address); + expect(result.obt_data_records[0].payer_fio_public_key).to.equal(user2.publicKey); + expect(result.obt_data_records[0].payee_fio_public_key).to.equal(user1.publicKey); + expect(result.obt_data_records[0].status).to.equal('sent_to_blockchain'); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`get_sent_fio_requests for user1 (payee). Expect one request with status = 'sent_to_blockchain'`, async () => { + try { + const result = await user1.sdk.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + console.log('result: ', result); + //console.log('content: ', result.requests[0].content); + expect(result.requests[0].fio_request_id).to.equal(fio_request_id); + expect(result.requests[0].payer_fio_address).to.equal(user2.address); + expect(result.requests[0].payee_fio_address).to.equal(user1.address); + expect(result.requests[0].payer_fio_public_key).to.equal(user2.publicKey); + expect(result.requests[0].payee_fio_public_key).to.equal(user1.publicKey); + expect(result.requests[0].status).to.equal('sent_to_blockchain'); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + }) describe(`C. Domain`, () => { @@ -172,7 +338,7 @@ describe(`C. Domain`, () => { } }) - it(`domain register`, async () => { + it(`clio: domain register`, async () => { try { result = await runClio(`domain register -j ${user1.domain2} ${user1.account} ${user1.publicKey} ${tpid} ${max_fee} --permission ${user1.account}@active`); //console.log('Result: ', JSON.parse(result)); @@ -197,7 +363,7 @@ describe(`C. Domain`, () => { } }) - it(`domain renew`, async () => { + it(`clio: domain renew`, async () => { try { result = await runClio(`domain renew -j ${user1.account} ${user1.domain2} ${tpid} ${max_fee} --permission ${user1.account}@active`); //console.log('Result: ', JSON.parse(result)); @@ -222,7 +388,7 @@ describe(`C. Domain`, () => { } }) - it(`domain set_public`, async () => { + it(`clio: domain set_public`, async () => { try { result = await runClio(`domain set_public -j ${user1.domain2} 1 ${user1.account} ${tpid} ${max_fee} --permission ${user1.account}@active`); //console.log('Result: ', JSON.parse(result)); @@ -247,7 +413,7 @@ describe(`C. Domain`, () => { } }) - it(`domain transfer`, async () => { + it(`clio: domain transfer`, async () => { try { result = await runClio(`domain transfer -j ${user1.domain2} ${user1.account} ${user2.publicKey} ${tpid} ${max_fee} --permission ${user1.account}@active`); //console.log('Result: ', JSON.parse(result)); @@ -257,6 +423,21 @@ describe(`C. Domain`, () => { } }) + it(`Call get_fio_domains for user2. Expect new domain.`, async () => { + try { + const json = { + "fio_public_key": user2.publicKey + } + result = await callFioApi("get_fio_domains", json); + console.log('Result: ', result); + expect(result.fio_domains.length).to.equal(2) + } catch (err) { + //console.log('Error', err.error.message) + expect(err.error.message).to.equal(config.error.noFioAddresses) + expect(err.statusCode).to.equal(404); + } + }) + }) describe(`D. Address`, () => { @@ -311,7 +492,7 @@ describe(`D. Address`, () => { } }) - it(`address register`, async () => { + it(`clio: address register`, async () => { try { result = await runClio(`address register -j ${user1.address2} ${user1.account} ${user1.publicKey} ${tpid} ${max_fee} --permission ${user1.account}@active`); //console.log('Result: ', JSON.parse(result)); @@ -336,7 +517,7 @@ describe(`D. Address`, () => { } }) - it(`address renew`, async () => { + it(`clio: address renew`, async () => { try { result = await runClio(`address renew -j ${user1.address2} ${user1.account} ${tpid} ${max_fee} --permission ${user1.account}@active`); //console.log('Result: ', JSON.parse(result)); @@ -510,7 +691,7 @@ describe(`F. Transfer`, () => { } }) - it(`transfer ${fundsAmount} FIO to user2 FIO public key`, async () => { + it(`clio: transfer ${fundsAmount} FIO to user2 FIO public key`, async () => { try { result = await runClio(`transfer -j ${user2.publicKey} ${fundsAmount} ${user1.account} ${tpid} ${max_fee} --permission ${user1.account}@active`); //console.log('Result: ', JSON.parse(result)); @@ -536,7 +717,7 @@ describe(`G. Vote Producer`, () => { result = await runClio('wallet import -n fio --private-key ' + user1.privateKey); }) - it(`userA1 votes for bp@dapixdev`, async () => { + it(`clio: voteproducer prods (userA1 votes for bp@dapixdev)`, async () => { try { result = await runClio(`system voteproducer prods -j ${user1.address} ${user1.account} ${max_fee} bp1@dapixdev --permission ${user1.account}@active`); //console.log('Result: ', JSON.parse(result)); diff --git a/tests/fio-request.js b/tests/fio-request.js index e2e92b7c..31a80034 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -481,6 +481,30 @@ describe(`B. Test FIO Request error conditions`, () => { userB3 = await newUser(faucet); }) + it(`userB3 requests funds using userB2.address as payer and userB1.address as payee`, async () => { + try { + const result = await userB3.sdk.genericAction('requestFunds', { + payerFioAddress: userB2.address, + payeeFioAddress: userB1.address, + payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', + amount: payment, + chainCode: 'BTC', + tokenCode: 'BTC', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: userB2.publicKey, + technologyProviderId: '', + }) + console.log('Result: ', result) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(err.json.type).to.equal('invalid_signature'); + expect(err.json.message).to.equal(config.error.invalidRequestSignature); + expect(err.errorCode).to.equal(403); + } + }) + it(`Add BTC address to userB1`, async () => { try { const result = await userB1.sdk.genericAction('addPublicAddresses', { @@ -2634,3 +2658,40 @@ describe(`I. reject_funds_request: Check all getters after`, () => { }) }) + +describe(`J. Test FIO Request with two addresses owned by same account`, () => { + let userA1, userA2, userA3requestId + const payment = 5000000000 // 5 FIO + const requestMemo = 'Memo in the initial request' + + it(`Create users`, async () => { + userA1 = await newUser(faucet); + userA2 = await newUser(faucet); + userA3 = await newUser(faucet); + userA1.address2 = generateFioAddress(userA1.domain, 5) + }) + + it(`userA3 requests funds using userA1 as payee and using userA2 as payer`, async () => { + try { + const result = await userA1.sdk.genericAction('requestFunds', { + payerFioAddress: userA2.address, + payeeFioAddress: userA1.address, + payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', + amount: payment, + chainCode: 'BTC', + tokenCode: 'BTC', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: userA2.publicKey, + technologyProviderId: '', + }) + //console.log('Result: ', result) + requestId = result.fio_request_id + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + +}) From e9f98bc4e98cb50f49e6962b10910fdb62ddc801 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 15 Feb 2021 16:47:28 -0700 Subject: [PATCH 50/76] Completed clio tests --- index.js | 2 +- tests/clio.js | 263 ++++++++++++++++-- tests/fio-request.js | 36 --- tests/transfer-locked-tokens-account-tests.js | 2 +- 4 files changed, 237 insertions(+), 66 deletions(-) diff --git a/index.js b/index.js index 1d392c53..4a60ded7 100644 --- a/index.js +++ b/index.js @@ -32,7 +32,7 @@ describe('TEST SUITE', () => { require('./tests/transfer-locked-tokens-account-tests.js'); // FIP-6 tests of generic account functionality require('./tests/addbundles.js'); // FIP-11.a require('./tests/tpid.js'); - //require('./tests/clio.js'); // FIP-16 + require('./tests/clio.js'); // FIP-16 require('./tests/testnet-smoketest.js'); // Testnet smoketest. By default runs against local build. diff --git a/tests/clio.js b/tests/clio.js index e8c01634..322b433d 100644 --- a/tests/clio.js +++ b/tests/clio.js @@ -1,6 +1,6 @@ require('mocha') const {expect} = require('chai') -const {newUser, randStr, generateFioDomain, generateFioAddress, unlockWallet, callFioApi, timeout, fetchJson} = require('../utils.js'); +const {newUser, existingUser, randStr, generateFioDomain, generateFioAddress, unlockWallet, callFioApi, timeout, fetchJson} = require('../utils.js'); const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); @@ -44,7 +44,7 @@ describe(`************************** clio.js ************************** \n A. }) }) -describe.only(`B. Request and OBT Data`, () => { +describe(`B. Request and OBT Data`, () => { let fio_request_id, fio_request_id2, fio_request_id3, user1, user2, resultSdk, resultClio, contentSdk, contentClio it(`Create users and import private keys`, async () => { @@ -145,7 +145,7 @@ describe.only(`B. Request and OBT Data`, () => { } }) - it(`(BUG BD-2358) get_sent_fio_requests for user1 (payee). Expect one request with status = 'rejected'`, async () => { + it.skip(`(BUG BD-2358) get_sent_fio_requests for user1 (payee). Expect one request with status = 'rejected'`, async () => { try { const result = await user1.sdk.genericAction('getSentFioRequests', { limit: '', @@ -177,7 +177,7 @@ describe.only(`B. Request and OBT Data`, () => { } }) - it(`get_pending_fio_requests for user1 (payer). Expect one request with status = 'pending'`, async () => { + it.skip(`(BUG BD-2358) get_pending_fio_requests for user1 (payer). Expect one request with status = 'pending'`, async () => { try { const result = await user1.sdk.genericAction('getPendingFioRequests', { limit: '', @@ -207,7 +207,7 @@ describe.only(`B. Request and OBT Data`, () => { } }) - it(`get_pending_fio_requests for user1 (payer). Expect one request with status = 'cancelled'`, async () => { + it.skip(`(BUG BD-2358) get_pending_fio_requests for user1 (payer). Expect one request with status = 'cancelled'`, async () => { try { const result = await user1.sdk.genericAction('getPendingFioRequests', { limit: '', @@ -255,7 +255,7 @@ describe.only(`B. Request and OBT Data`, () => { offset: '', tokenCode: 'BTC' }) - console.log('result: ', result) + //console.log('result: ', result) //console.log('content: ', result.obt_data_records[0].content) expect(result.obt_data_records[0].fio_request_id).to.equal(fio_request_id3); expect(result.obt_data_records[0].payer_fio_address).to.equal(user2.address); @@ -269,7 +269,7 @@ describe.only(`B. Request and OBT Data`, () => { } }) - it(`get_sent_fio_requests for user1 (payee). Expect one request with status = 'sent_to_blockchain'`, async () => { + it.skip(`(BUG BD-2358) get_sent_fio_requests for user1 (payee). Expect one request with status = 'sent_to_blockchain'`, async () => { try { const result = await user1.sdk.genericAction('getSentFioRequests', { limit: '', @@ -348,6 +348,20 @@ describe(`C. Domain`, () => { } }) + it(`Call get_fio_domains for user1. Expect new domain.`, async () => { + try { + const json = { + "fio_public_key": user1.publicKey + } + result = await callFioApi("get_fio_domains", json); + //console.log('Result: ', result.fio_domains.length); + expect(result.fio_domains.length).to.equal(2); + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + it(`Verify balance for user1 = prev_balance - reg_domain_fee`, async () => { let prevBalance = user1Balance; try { @@ -376,15 +390,15 @@ describe(`C. Domain`, () => { it(`Verify balance for user1 = prev_balance - renew_domain_fee`, async () => { let prevBalance = user1Balance; try { - const result = await user1.sdk.genericAction('getFioBalance', { - fioPublicKey: user1.publicKey - }) - user1Balance = result.balance - //console.log('user1 fio balance', result.balance) - expect(user1Balance).to.equal(prevBalance - register_fio_domain_fee) + const result = await user1.sdk.genericAction('getFioBalance', { + fioPublicKey: user1.publicKey + }) + user1Balance = result.balance + //console.log('user1 fio balance', result.balance) + expect(user1Balance).to.equal(prevBalance - register_fio_domain_fee) } catch (err) { - //console.log('Error', err) - expect(err).to.equal(null) + //console.log('Error', err) + expect(err).to.equal(null) } }) @@ -394,7 +408,23 @@ describe(`C. Domain`, () => { //console.log('Result: ', JSON.parse(result)); expect(JSON.parse(result).transaction_id).to.exist } catch (err) { - console.log('Error', err) + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Call get_fio_domains for user1. Verify is_public = 1`, async () => { + try { + const json = { + "fio_public_key": user1.publicKey + } + result = await callFioApi("get_fio_domains", json); + //console.log('Result: ', result); + expect(result.fio_domains[0].is_public).to.equal(0); + expect(result.fio_domains[1].is_public).to.equal(1); + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) } }) @@ -408,8 +438,8 @@ describe(`C. Domain`, () => { //console.log('user1 fio balance', result.balance) expect(user1Balance).to.equal(prevBalance - set_fio_domain_public_fee) } catch (err) { - //console.log('Error', err) - expect(err).to.equal(null) + //console.log('Error', err) + expect(err).to.equal(null) } }) @@ -419,7 +449,8 @@ describe(`C. Domain`, () => { //console.log('Result: ', JSON.parse(result)); expect(JSON.parse(result).transaction_id).to.exist } catch (err) { - console.log('Error', err) + //console.log('Error', err) + expect(err).to.equal(null) } }) @@ -429,12 +460,12 @@ describe(`C. Domain`, () => { "fio_public_key": user2.publicKey } result = await callFioApi("get_fio_domains", json); - console.log('Result: ', result); + //console.log('Result: ', result); expect(result.fio_domains.length).to.equal(2) + expect(result.fio_domains[1].fio_domain).to.equal(user1.domain2) } catch (err) { - //console.log('Error', err.error.message) - expect(err.error.message).to.equal(config.error.noFioAddresses) - expect(err.statusCode).to.equal(404); + //console.log('Error', err) + expect(err).to.equal(null) } }) @@ -502,6 +533,21 @@ describe(`D. Address`, () => { } }) + it(`Call get_fio_addresses for user1. Confirm new address.`, async () => { + try { + const json = { + "fio_public_key": user1.publicKey + } + result = await callFioApi("get_fio_addresses", json); + //console.log('Result: ', result); + expect(result.fio_addresses.length).to.equal(2) + expect(result.fio_addresses[1].fio_address).to.equal(user1.address2) + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + it(`Verify balance for user1 = prev_balance - register_fio_address_fee`, async () => { let prevBalance = user1Balance; try { @@ -709,22 +755,183 @@ describe(`F. Transfer`, () => { }) -describe(`G. Vote Producer`, () => { - let user1 +describe(`G. Set ratios and multipliers`, () => { + let multAmount = 5, + endpoint1 = "register_fio_domain", ratio1 = 40000000000, + endpoint2 = "register_fio_address", ratio2 = 50000000000 + + it(`Create users and import private keys`, async () => { + bp1 = await existingUser('qbxn5zhw2ypw', '5KQ6f9ZgUtagD3LZ4wcMKhhvK9qy4BuwL3L1pkm6E2v62HCne2R', 'FIO7jVQXMNLzSncm7kxwg9gk7XUBYQeJPk8b6QfaK5NVNkh3QZrRr', 'dapixdev', 'bp1@dapixdev'); + //user1 = await newUser(faucet); + //result = await runClio('wallet import -n fio --private-key ' + user1.privateKey); + }) + + it(`Show multipliers table.`, async () => { + try { + const json = { + json: true, + code: 'fio.fee', + scope: 'fio.fee', + table: 'feevoters', + limit: 1000, + reverse: true, + show_payer: false + } + const table = await callFioApi("get_table_rows", json); + //console.log('fiovoters table: ', table); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it.skip(`(BUG BD-2226) clio: bp1 fee submit_multiplier`, async () => { + try { + result = await runClio(`fee submit_multiplier -j ${multAmount} ${bp1.account} --permission ${bp1.account}@active`); + //console.log('Result: ', JSON.parse(result)); + expect(JSON.parse(result).transaction_id).to.exist + } catch (err) { + console.log('Error', err) + } + }) + + it(`Show multipliers table.`, async () => { + try { + const json = { + json: true, + code: 'fio.fee', + scope: 'fio.fee', + table: 'feevoters', + limit: 1000, + reverse: true, + show_payer: false + } + const table = await callFioApi("get_table_rows", json); + //console.log('fiovoters table: ', table); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Show ratios table.`, async () => { + try { + const json = { + json: true, + code: 'fio.fee', + scope: 'fio.fee', + table: 'feevotes2', + limit: 1000, + reverse: true, + show_payer: false + } + const table = await callFioApi("get_table_rows", json); + //console.log('feevotes2 table: ', table); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it.skip(`(BUG BD-2226) clio: bp1 fee submit_ratios`, async () => { + try { + result = await runClio(`fee submit_ratios -j ${bp1.address} ${bp1.account} ${max_fee} ${endpoint1} ${ratio1} --permission ${bp1.account}@active`); + //console.log('Result: ', JSON.parse(result)); + expect(JSON.parse(result).transaction_id).to.exist + } catch (err) { + console.log('Error', err) + } + }) + + it(`Show ratios table.`, async () => { + try { + const json = { + json: true, + code: 'fio.fee', + scope: 'fio.fee', + table: 'feevotes2', + limit: 1000, + reverse: true, + show_payer: false + } + const table = await callFioApi("get_table_rows", json); + //console.log('feevotes2 table: ', table); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) + +describe(`H. clio error testing`, () => { + let user1, user2, fio_request_id + const fundsAmount = 10000000000 it(`Create users and import private keys`, async () => { user1 = await newUser(faucet); result = await runClio('wallet import -n fio --private-key ' + user1.privateKey); + + user2 = await newUser(faucet); + result = await runClio('wallet import -n fio --private-key ' + user2.privateKey); + }) + + it(`clio: request new (user1 requests funds from user2)`, async () => { + try { + const result = await runClio(`request new -j ${user2.address} ${user1.address} ${content} ${user1.account} ${tpid} ${max_fee} --permission ${user1.account}@active`); + //console.log('Result: ', result) + fio_request_id = JSON.parse(JSON.parse(result).processed.action_traces[0].receipt.response).fio_request_id + //console.log('ID: ', JSON.parse(JSON.parse(result).processed.action_traces[0].receipt.response).fio_request_id) + expect(JSON.parse(result).transaction_id).to.exist + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } }) - it(`clio: voteproducer prods (userA1 votes for bp@dapixdev)`, async () => { + it(`clio: request new with account which is not payee. Expect "Missing required authority"`, async () => { try { - result = await runClio(`system voteproducer prods -j ${user1.address} ${user1.account} ${max_fee} bp1@dapixdev --permission ${user1.account}@active`); - //console.log('Result: ', JSON.parse(result)); + const result = await runClio(`request new -j ${user2.address} ${user1.address} ${content} ${user1.account} ${tpid} ${max_fee} --permission ${user2.account}@active`); + //console.log('Result: ', result) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(String(err)).to.include('Missing required authority') + } + }) + + // From FIP-16: max_fee is set to 800000000001 so user does not have to define manually. Any required fee set by the producers under this value will process + it(`clio: request cancel with inadequate fee succeeds`, async () => { + try { + result = await runClio(`request cancel -j ${fio_request_id} ${user1.account} ${tpid} 100 --permission ${user1.account}@active`); + //console.log('Result: ', result) expect(JSON.parse(result).transaction_id).to.exist } catch (err) { console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`clio: request reject with invalid request ID`, async () => { + try { + result = await runClio(`request reject -j 777 ${user2.account} ${tpid} ${max_fee} --permission ${user2.account}@active`); + //console.log('Result: ', result) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error', err) + expect(String(err)).to.include('Error code 400') } }) + it(`clio: domain register with existing domain`, async () => { + try { + result = await runClio(`domain register -j ${user1.domain} ${user1.account} ${user1.publicKey} ${tpid} ${max_fee} --permission ${user1.account}@active`); + //console.log('Result: ', JSON.parse(result)); + expect(result).to.equal(null) + } catch (err) { + //console.log('Error', err) + expect(String(err)).to.include('FIO domain already registered') + } + }) }) + diff --git a/tests/fio-request.js b/tests/fio-request.js index 31a80034..762361e6 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -2659,39 +2659,3 @@ describe(`I. reject_funds_request: Check all getters after`, () => { }) -describe(`J. Test FIO Request with two addresses owned by same account`, () => { - let userA1, userA2, userA3requestId - const payment = 5000000000 // 5 FIO - const requestMemo = 'Memo in the initial request' - - it(`Create users`, async () => { - userA1 = await newUser(faucet); - userA2 = await newUser(faucet); - userA3 = await newUser(faucet); - userA1.address2 = generateFioAddress(userA1.domain, 5) - }) - - it(`userA3 requests funds using userA1 as payee and using userA2 as payer`, async () => { - try { - const result = await userA1.sdk.genericAction('requestFunds', { - payerFioAddress: userA2.address, - payeeFioAddress: userA1.address, - payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', - amount: payment, - chainCode: 'BTC', - tokenCode: 'BTC', - memo: requestMemo, - maxFee: config.api.new_funds_request.fee, - payerFioPublicKey: userA2.publicKey, - technologyProviderId: '', - }) - //console.log('Result: ', result) - requestId = result.fio_request_id - expect(result.status).to.equal('requested') - } catch (err) { - console.log('Error: ', err) - expect(err).to.equal(null) - } - }) - -}) diff --git a/tests/transfer-locked-tokens-account-tests.js b/tests/transfer-locked-tokens-account-tests.js index 05f52a1e..fe11db40 100644 --- a/tests/transfer-locked-tokens-account-tests.js +++ b/tests/transfer-locked-tokens-account-tests.js @@ -1188,7 +1188,7 @@ describe('G. Record obt data, check getObtData', () => { expect(obtData.payee_fio_address).to.equal(testFioAddressName2) }) - it(`BUG BD-2305 (not all results getting returned) Payee getObtData`, async () => { + it.skip(`BUG BD-2305 (not all results getting returned) Payee getObtData`, async () => { const result = await fioSdk2.genericAction('getObtData', { tokenCode: fioTokenCode }) console.log('result: ', result) expect(result).to.have.all.keys('obt_data_records', 'more') From 3c87771e8ef94aab4be60defed901407d10a0e15 Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Wed, 17 Feb 2021 11:34:02 -0700 Subject: [PATCH 51/76] update transfer locked tokens to test endpoints update test to use endpoints when sdk arg is specified, these tests perform the smoke test for locked token endpoints using endpoints. --- tests/transfer-locked-tokens.js | 557 ++++++++++++++++++++++++++------ 1 file changed, 461 insertions(+), 96 deletions(-) diff --git a/tests/transfer-locked-tokens.js b/tests/transfer-locked-tokens.js index 8d4a7057..b63ccb1d 100644 --- a/tests/transfer-locked-tokens.js +++ b/tests/transfer-locked-tokens.js @@ -123,14 +123,13 @@ describe(`B. Parameter tests`, () => { } }) - it(`Failure test, Transfer locked tokens, period percent larger than 3 decimals`, async () => { - try { - const result = await userA1.sdk.genericAction('pushTransaction', { - action: 'trnsloctoks', - account: 'fio.token', - data: { - payee_public_key: keys.publicKey, - can_vote: 0, + it(`(${testType}) Failure test, Transfer locked tokens, period percent larger than 3 decimals`, async () => { + + if (testType == 'sdk') { + try { + const result = await userA1.sdk.genericAction('transferLockedTokens', { + payeePublicKey: keys.publicKey, + canVote: 0, periods: [ { duration: 120, @@ -142,28 +141,57 @@ describe(`B. Parameter tests`, () => { } ], amount: fundsAmount, - max_fee: 400000000000, + maxFee: 400000000000, tpid: '', - actor: userA1.account, - } - }) - expect(result.status).to.not.equal('OK') + }) + expect(result.status).to.not.equal('OK') + } catch (err) { + //console.log('error: ', err) + var expected = `Error 400` + expect(err.message).to.include(expected) + } + } else { + try { + const result = await userA1.sdk.genericAction('pushTransaction', { + action: 'trnsloctoks', + account: 'fio.token', + data: { + payee_public_key: keys.publicKey, + can_vote: 0, + periods: [ + { + duration: 120, + percent: 50.4444, + }, + { + duration: 240, + percent: 49.5556, + } + ], + amount: fundsAmount, + max_fee: 400000000000, + tpid: '', + actor: userA1.account, + } - } catch (err) { - var expected = `Error 400` - expect(err.message).to.include(expected) + }) + expect(result.status).to.not.equal('OK') + + } catch (err) { + var expected = `Error 400` + expect(err.message).to.include(expected) + } } }) - it(`Failure test, Transfer locked tokens, periods are not in ascending order of duration`, async () => { - try { - const result = await userA1.sdk.genericAction('pushTransaction', { - action: 'trnsloctoks', - account: 'fio.token', - data: { - payee_public_key: keys.publicKey, - can_vote: 0, + it(`(${testType}) Failure test, Transfer locked tokens, periods are not in ascending order of duration`, async () => { + + if (testType == 'sdk') { + try { + const result = await userA1.sdk.genericAction('transferLockedTokens', { + payeePublicKey: keys.publicKey, + canVote: 0, periods: [ { duration: 240, @@ -175,28 +203,56 @@ describe(`B. Parameter tests`, () => { } ], amount: fundsAmount, - max_fee: 400000000000, + maxFee: 400000000000, tpid: '', - actor: userA1.account, - } - }) - expect(result.status).to.not.equal('OK') + }) + expect(result.status).to.not.equal('OK') + } catch (err) { + //console.log('error: ', err) + var expected = `Error 400` + expect(err.message).to.include(expected) + } + } else { + try { + const result = await userA1.sdk.genericAction('pushTransaction', { + action: 'trnsloctoks', + account: 'fio.token', + data: { + payee_public_key: keys.publicKey, + can_vote: 0, + periods: [ + { + duration: 240, + percent: 50.4444, + }, + { + duration: 120, + percent: 49.5556, + } + ], + amount: fundsAmount, + max_fee: 400000000000, + tpid: '', + actor: userA1.account, + } - } catch (err) { - var expected = `Error 400` - expect(err.message).to.include(expected) + }) + expect(result.status).to.not.equal('OK') + + } catch (err) { + var expected = `Error 400` + expect(err.message).to.include(expected) + } } }) - it(`Failure test, Transfer locked tokens, duration 0`, async () => { - try { - const result = await userA1.sdk.genericAction('pushTransaction', { - action: 'trnsloctoks', - account: 'fio.token', - data: { - payee_public_key: keys.publicKey, - can_vote: 0, + it(`(${testType}) Failure test, Transfer locked tokens, duration 0`, async () => { + if (testType == 'sdk') { + try { + const result = await userA1.sdk.genericAction('transferLockedTokens', { + payeePublicKey: keys.publicKey, + canVote: 0, periods: [ { duration: 0, @@ -208,27 +264,55 @@ describe(`B. Parameter tests`, () => { } ], amount: fundsAmount, - max_fee: 400000000000, + maxFee: 400000000000, tpid: '', - actor: userA1.account - } - }) - expect(result.status).to.not.equal('OK') - } catch (err) { - var expected = `Error 400` - expect(err.message).to.include(expected) + }) + expect(result.status).to.not.equal('OK') + } catch (err) { + //console.log('error: ', err) + var expected = `Error 400` + expect(err.message).to.include(expected) + } + } else { + try { + const result = await userA1.sdk.genericAction('pushTransaction', { + action: 'trnsloctoks', + account: 'fio.token', + data: { + payee_public_key: keys.publicKey, + can_vote: 0, + periods: [ + { + duration: 0, + percent: 50.0, + }, + { + duration: 240, + percent: 50.0, + } + ], + amount: fundsAmount, + max_fee: 400000000000, + tpid: '', + actor: userA1.account + } + + }) + expect(result.status).to.not.equal('OK') + } catch (err) { + var expected = `Error 400` + expect(err.message).to.include(expected) + } } }) - it(`Failute test, Transfer locked tokens, pub key account pre exists`, async () => { - try { - const result = await userA1.sdk.genericAction('pushTransaction', { - action: 'trnsloctoks', - account: 'fio.token', - data: { - payee_public_key: userA1.publicKey, - can_vote: 0, + it(`(${testType}) Failute test, Transfer locked tokens, pub key account pre exists`, async () => { + if (testType == 'sdk') { + try { + const result = await userA1.sdk.genericAction('transferLockedTokens', { + payeePublicKey: keys.publicKey, + canVote: 0, periods: [ { duration: 0, @@ -240,27 +324,55 @@ describe(`B. Parameter tests`, () => { } ], amount: fundsAmount, - max_fee: 400000000000, + maxFee: 400000000000, tpid: '', - actor: userA1.account - } - }) - expect(result.status).to.not.equal('OK') - } catch (err) { - var expected = `Error 400` - expect(err.message).to.include(expected) + }) + expect(result.status).to.not.equal('OK') + } catch (err) { + //console.log('error: ', err) + var expected = `Error 400` + expect(err.message).to.include(expected) + } + } else { + try { + const result = await userA1.sdk.genericAction('pushTransaction', { + action: 'trnsloctoks', + account: 'fio.token', + data: { + payee_public_key: userA1.publicKey, + can_vote: 0, + periods: [ + { + duration: 0, + percent: 50.0, + }, + { + duration: 240, + percent: 50.0, + } + ], + amount: fundsAmount, + max_fee: 400000000000, + tpid: '', + actor: userA1.account + } + + }) + expect(result.status).to.not.equal('OK') + } catch (err) { + var expected = `Error 400` + expect(err.message).to.include(expected) + } } }) - it(`Failute test, Too many lock periods`, async () => { - try { - const result = await userA4.sdk.genericAction('pushTransaction', { - action: 'trnsloctoks', - account: 'fio.token', - data: { - payee_public_key: keys2.publicKey, - can_vote: 0, + it(`(${testType}) Failute test, Too many lock periods`, async () => { + if (testType == 'sdk') { + try { + const result = await userA4.sdk.genericAction('transferLockedTokens', { + payeePublicKey: keys2.publicKey, + canVote: 0, periods: [ { duration: 1, @@ -468,17 +580,243 @@ describe(`B. Parameter tests`, () => { } ], amount: fundsAmount, - max_fee: 400000000000, + maxFee: 400000000000, tpid: '', - actor: userA4.account, - } - }) - expect(result.status).to.not.equal('OK') + }) + expect(result.status).to.not.equal('OK') + } catch (err) { + //console.log('error: ', err) + var expected = `Error 400` + expect(err.message).to.include(expected) + } + } else { + try { + const result = await userA4.sdk.genericAction('pushTransaction', { + action: 'trnsloctoks', + account: 'fio.token', + data: { + payee_public_key: keys2.publicKey, + can_vote: 0, + periods: [ + { + duration: 1, + percent: 0.273, + }, + { + duration: 2, + percent: .273, + }, + { + duration: 3, + percent: .273, + }, + { + duration: 4, + percent: .273, + }, + { + duration: 5, + percent: .273, + }, + { + duration: 6, + percent: .273, + }, + { + duration: 7, + percent: .273, + }, + { + duration: 8, + percent: .273, + }, + { + duration: 9, + percent: .273, + }, + { + duration: 10, + percent: .273, + }, + { + duration: 11, + percent: .273, + }, + { + duration: 12, + percent: .273, + }, + { + duration: 13, + percent: .273, + }, + { + duration: 14, + percent: .273, + }, + { + duration: 15, + percent: .273, + }, + { + duration: 16, + percent: .273, + }, + { + duration: 17, + percent: .273, + }, + { + duration: 18, + percent: .273, + }, + { + duration: 19, + percent: .273, + }, + { + duration: 20, + percent: .273, + }, + { + duration: 21, + percent: .273, + }, + { + duration: 22, + percent: .273, + }, + { + duration: 23, + percent: .273, + }, + { + duration: 24, + percent: .273, + }, + { + duration: 25, + percent: .273, + }, + { + duration: 26, + percent: .273, + }, + { + duration: 27, + percent: .273, + }, + { + duration: 28, + percent: .273, + }, + { + duration: 29, + percent: .273, + }, + { + duration: 30, + percent: .273, + }, + { + duration: 31, + percent: .273, + }, + { + duration: 32, + percent: .273, + }, + { + duration: 33, + percent: .273, + }, + { + duration: 34, + percent: .273, + }, + { + duration: 35, + percent: .273, + }, + { + duration: 36, + percent: .273, + }, + { + duration: 37, + percent: .273, + }, + { + duration: 38, + percent: .273, + }, + { + duration: 39, + percent: .273, + }, + { + duration: 40, + percent: .273, + }, + { + duration: 41, + percent: .273, + }, + { + duration: 42, + percent: .273, + }, + { + duration: 43, + percent: .273, + }, + { + duration: 44, + percent: .273, + }, + { + duration: 45, + percent: .273, + }, + { + duration: 46, + percent: .273, + }, + { + duration: 47, + percent: .273, + }, + { + duration: 48, + percent: .273, + }, + { + duration: 49, + percent: .273, + }, + { + duration: 50, + percent: .273, + }, + { + duration: 51, + percent: 86.35, + } + ], + amount: fundsAmount, + max_fee: 400000000000, + tpid: '', + actor: userA4.account, + } - } catch (err) { - var expected = `Error 400` - expect(err.message).to.include(expected) + }) + expect(result.status).to.not.equal('OK') + + } catch (err) { + var expected = `Error 400` + expect(err.message).to.include(expected) + } } }) @@ -506,14 +844,12 @@ describe(`B. transfer with 2 unlock periods, canvote = false`, () => { balancebefore = result.balance; }) - it(`SUCCESS transferLockedTokens ${fundsAmount}, canvote false, (20,40 seconds) and (40,60%)`, async () => { - try { - const result = await userA1.sdk.genericAction('pushTransaction', { - action: 'trnsloctoks', - account: 'fio.token', - data: { - payee_public_key: keys.publicKey, - can_vote: 0, + it(`(${testType}) SUCCESS transferLockedTokens ${fundsAmount}, canvote false, (20,40 seconds) and (40,60%)`, async () => { + if (testType == 'sdk') { + try { + const result = await userA1.sdk.genericAction('transferLockedTokens', { + payeePublicKey: keys.publicKey, + canVote: 0, periods: [ { duration: 20, @@ -525,16 +861,45 @@ describe(`B. transfer with 2 unlock periods, canvote = false`, () => { } ], amount: fundsAmount, - max_fee: 400000000000, + maxFee: 400000000000, tpid: '', - actor: userA1.account, - } - }) - expect(result.status).to.equal('OK') - expect(result).to.have.all.keys( 'status', 'fee_collected') - } catch (err) { - console.log(' Error', err) + }) + expect(result.status).to.equal('OK') + expect(result).to.have.all.keys('status', 'fee_collected') + } catch (err) { + console.log(' Error', err) + } + } else { + try { + const result = await userA1.sdk.genericAction('pushTransaction', { + action: 'trnsloctoks', + account: 'fio.token', + data: { + payee_public_key: keys.publicKey, + can_vote: 0, + periods: [ + { + duration: 20, + percent: 40.0, + }, + { + duration: 40, + percent: 60.0, + } + ], + amount: fundsAmount, + max_fee: 400000000000, + tpid: '', + actor: userA1.account, + } + + }) + expect(result.status).to.equal('OK') + expect(result).to.have.all.keys('status', 'fee_collected') + } catch (err) { + console.log(' Error', err) + } } }) From 8c1a4359aa93b4554bf4d5a1550b5b65eb3e299d Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Thu, 18 Feb 2021 14:19:12 -0700 Subject: [PATCH 52/76] Retrieve bundle count from getfionames --- tests/addbundles.js | 201 ++++++++------------------------------------ tests/vote.js | 60 +++---------- 2 files changed, 48 insertions(+), 213 deletions(-) diff --git a/tests/addbundles.js b/tests/addbundles.js index 7447528c..da4728b0 100644 --- a/tests/addbundles.js +++ b/tests/addbundles.js @@ -13,7 +13,7 @@ describe('************************** addbundles.js ************************** \n let user1, user1OrigBalance, user1OrigRam, add_bundled_transactions_fee, feeCollected let bundledVoteNumber = config.defaultBundleCount; - let bundleSets = 1; + let bundleSets = 2; it(`Create users`, async () => { user1 = await newUser(faucet); @@ -79,30 +79,12 @@ describe('************************** addbundles.js ************************** \n } }) - it(`Get bundle count for user1 from fionames table`, async () => { - try { - const json = { - json: true, - code: 'fio.address', - scope: 'fio.address', - table: 'fionames', - limit: 100, - reverse: true, - show_payer: false - } - fionames = await callFioApi("get_table_rows", json); - for (fioname in fionames.rows) { - if (fionames.rows[fioname].name == user1.address) { - user1BundleCount = fionames.rows[fioname].bundleeligiblecountdown; - } - } - //console.log('user1BundleCount: ', user1BundleCount); - expect(bundledVoteNumber).to.greaterThan(0); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - }) + it(`Get bundle count for user1 `, async () => { + const result = await user1.sdk.genericAction('getFioNames', { fioPublicKey: user1.publicKey }) + //console.log('Result: ', result) + user1BundleCount = result.fio_addresses[0].remaining_bundled_tx; + expect(user1BundleCount).to.be.greaterThan(0) + }) it(`(${testType}) Add bundles with ${bundleSets} sets for FIO Address owned by other user (fixed in BD-2308)`, async () => { if (testType == 'sdk') { @@ -173,31 +155,13 @@ describe('************************** addbundles.js ************************** \n } }) - it(`Confirm bundle count was increased by ${bundleSets} set`, async () => { + it(`Get bundle count for user1 `, async () => { let prevBundleCount = user1BundleCount; - try { - const json = { - json: true, - code: 'fio.address', - scope: 'fio.address', - table: 'fionames', - limit: 100, - reverse: true, - show_payer: false - } - fionames = await callFioApi("get_table_rows", json); - for (fioname in fionames.rows) { - if (fionames.rows[fioname].name == user1.address) { - user1BundleCount = fionames.rows[fioname].bundleeligiblecountdown; - } - } - //console.log('user1BundleCount: ', user1BundleCount); - expect(user1BundleCount).to.equal(prevBundleCount + (bundleSets * bundledVoteNumber)); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - }) + const result = await user1.sdk.genericAction('getFioNames', { fioPublicKey: user1.publicKey }) + //console.log('Result: ', result) + user1BundleCount = result.fio_addresses[0].remaining_bundled_tx; + expect(user1BundleCount).to.equal(prevBundleCount + (bundleSets * bundledVoteNumber)); + }) }) @@ -285,54 +249,18 @@ describe('B. Add 3 sets of bundled transactions for FIO Address owned by other u } }) - it(`Get bundle count for user1 from fionames table`, async () => { - try { - const json = { - json: true, - code: 'fio.address', - scope: 'fio.address', - table: 'fionames', - limit: 100, - reverse: true, - show_payer: false - } - fionames = await callFioApi("get_table_rows", json); - for (fioname in fionames.rows) { - if (fionames.rows[fioname].name == user1.address) { - user1BundleCount = fionames.rows[fioname].bundleeligiblecountdown; - } - } - //console.log('user1BundleCount: ', user1BundleCount); - expect(user1BundleCount).to.greaterThan(0); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } + it(`Get bundle count for user1 `, async () => { + const result = await user1.sdk.genericAction('getFioNames', { fioPublicKey: user1.publicKey }) + //console.log('Result: ', result) + user1BundleCount = result.fio_addresses[0].remaining_bundled_tx; + expect(user1BundleCount).to.be.greaterThan(0); }) - it(`Get bundle count for user2 from fionames table`, async () => { - try { - const json = { - json: true, - code: 'fio.address', - scope: 'fio.address', - table: 'fionames', - limit: 100, - reverse: true, - show_payer: false - } - fionames = await callFioApi("get_table_rows", json); - for (fioname in fionames.rows) { - if (fionames.rows[fioname].name == user2.address) { - user2BundleCount = fionames.rows[fioname].bundleeligiblecountdown; - } - } - //console.log('user1BundleCount: ', user1BundleCount); - expect(user2BundleCount).to.greaterThan(0); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } + it(`Get bundle count for user2 `, async () => { + const result = await user2.sdk.genericAction('getFioNames', { fioPublicKey: user2.publicKey }) + //console.log('Result: ', result) + user2BundleCount = result.fio_addresses[0].remaining_bundled_tx; + expect(user2BundleCount).to.be.greaterThan(0); }) it(`(${testType}) user1 run addbundles with ${bundleSets} sets for FIO Address owned by user2 (fixed in BD-2308)`, async () => { @@ -419,54 +347,18 @@ describe('B. Add 3 sets of bundled transactions for FIO Address owned by other u it(`Confirm user1 bundle count is unchanged`, async () => { let prevBundleCount = user1BundleCount; - try { - const json = { - json: true, - code: 'fio.address', - scope: 'fio.address', - table: 'fionames', - limit: 100, - reverse: true, - show_payer: false - } - fionames = await callFioApi("get_table_rows", json); - for (fioname in fionames.rows) { - if (fionames.rows[fioname].name == user1.address) { - user1BundleCount = fionames.rows[fioname].bundleeligiblecountdown; - } - } - //console.log('user1BundleCount: ', user1BundleCount); - expect(user1BundleCount).to.equal(prevBundleCount); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } + const result = await user1.sdk.genericAction('getFioNames', { fioPublicKey: user1.publicKey }) + //console.log('Result: ', result) + user1BundleCount = result.fio_addresses[0].remaining_bundled_tx; + expect(user1BundleCount).to.equal(prevBundleCount); }) it(`Confirm user2 bundle count was increased by ${bundleSets} sets`, async () => { let prevBundleCount = user2BundleCount; - try { - const json = { - json: true, - code: 'fio.address', - scope: 'fio.address', - table: 'fionames', - limit: 100, - reverse: true, - show_payer: false - } - fionames = await callFioApi("get_table_rows", json); - for (fioname in fionames.rows) { - if (fionames.rows[fioname].name == user2.address) { - user2BundleCount = fionames.rows[fioname].bundleeligiblecountdown; - } - } - //console.log('user2BundleCount: ', user2BundleCount); - expect(user2BundleCount).to.equal(prevBundleCount + (bundleSets * bundledVoteNumber)); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } + const result = await user2.sdk.genericAction('getFioNames', { fioPublicKey: user2.publicKey }) + //console.log('Result: ', result) + user2BundleCount = result.fio_addresses[0].remaining_bundled_tx; + expect(user2BundleCount).to.equal(prevBundleCount + (bundleSets * bundledVoteNumber)); }) }) @@ -681,31 +573,12 @@ describe('C. Error testing', () => { } }) - it('Call get_table_rows from fionames to get bundles remaining for user1. Verify 0 bundles', async () => { - let bundleCount - try { - const json = { - json: true, // Get the response as json - code: 'fio.address', // Contract that we target - scope: 'fio.address', // Account that owns the data - table: 'fionames', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - fionames = await callFioApi("get_table_rows", json); - //console.log('fionames: ', fionames); - for (fioname in fionames.rows) { - if (fionames.rows[fioname].name == user1.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); - bundleCount = fionames.rows[fioname].bundleeligiblecountdown; - } - } - expect(bundleCount).to.equal(0); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } + it(`Get bundle count for user1. Verify 0 bundles`, async () => { + let bundleCount; + const result = await user1.sdk.genericAction('getFioNames', { fioPublicKey: user1.publicKey }) + //console.log('Result: ', result) + bundleCount = result.fio_addresses[0].remaining_bundled_tx; + expect(bundleCount).to.equal(0); }) it(`Attempt addbundles with fee lower than actual fee amount and no bundled transactions left. Expect error type ${config.error2.feeExceedsMax.statusCode}: ${config.error2.feeExceedsMax.message}`, async () => { diff --git a/tests/vote.js b/tests/vote.js index aad86b43..c0bcc669 100644 --- a/tests/vote.js +++ b/tests/vote.js @@ -1286,32 +1286,13 @@ describe('E.2 Test vote_producer with and without FIO Address (FIP-9)', () => { //console.log('Error', err) expect(err).to.equal(null) } -}) + }) - it('Get initial bundle count for voterG3. ', async () => { - try { - const json = { - json: true, // Get the response as json - code: 'fio.address', // Contract that we target - scope: 'fio.address', // Account that owns the data - table: 'fionames', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - fionames = await callFioApi("get_table_rows", json); - //console.log('fionames: ', fionames); - for (fioname in fionames.rows) { - if (fionames.rows[fioname].name == voterG3.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); - bundleCount = fionames.rows[fioname].bundleeligiblecountdown; - } - } - expect(bundleCount).to.be.greaterThan(0); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } + it(`Get bundle count for voterG3 `, async () => { + const result = await voterG3.sdk.genericAction('getFioNames', { fioPublicKey: voterG3.publicKey }) + //console.log('Result: ', result) + bundleCount = result.fio_addresses[0].remaining_bundled_tx; + expect(bundleCount).to.be.greaterThan(0); }) it(`Execute vote_producer WITH FIO Address (with bundled tx left), confirm fee_collected = 0`, async () => { @@ -1336,31 +1317,12 @@ describe('E.2 Test vote_producer with and without FIO Address (FIP-9)', () => { } }) - it('Get bundle count for voterG3. Confirm bundle count was decremented by 1.', async () => { + it(`Get bundle count for voterG3 `, async () => { prevBundleCount = bundleCount; - try { - const json = { - json: true, // Get the response as json - code: 'fio.address', // Contract that we target - scope: 'fio.address', // Account that owns the data - table: 'fionames', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - fionames = await callFioApi("get_table_rows", json); - //console.log('fionames: ', fionames); - for (fioname in fionames.rows) { - if (fionames.rows[fioname].name == voterG3.address) { - //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); - bundleCount = fionames.rows[fioname].bundleeligiblecountdown; - } - } - expect(bundleCount).to.equal(prevBundleCount - 1); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } + const result = await voterG3.sdk.genericAction('getFioNames', { fioPublicKey: voterG3.publicKey }) + //console.log('Result: ', result) + bundleCount = result.fio_addresses[0].remaining_bundled_tx; + expect(bundleCount).to.equal(prevBundleCount - 1); }) it('Confirm no fee was deducted from voterG3 account', async () => { From bef2e49a8f5f5c36a41d0a840d1fd8aa63990f9e Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Fri, 19 Feb 2021 08:52:11 -0700 Subject: [PATCH 53/76] get_received_fio_requests error condition tests --- config.js | 5 +- index.js | 2 - tests/fio-request.js | 123 +++++++++++++++++++++++++++++--- tests/transfer-locked-tokens.js | 6 +- 4 files changed, 118 insertions(+), 18 deletions(-) diff --git a/config.js b/config.js index 6a796ee2..9e9a5a85 100644 --- a/config.js +++ b/config.js @@ -1,8 +1,7 @@ -const TESTURL = 'http://localhost:8889' // Localhost -//const TESTURL = 'http://44.234.45.7:8889' // DEV1 +const TESTURL = 'http://localhost:8889' // Localhost +//const TESTURL = 'http://dev1.fio.dev:8888' // DEV1 //const TESTURL = 'http://44.238.153.162:8889' // Devnet //const TESTURL = 'http://testnet.fioprotocol.io' // Testnet -//const TESTURL = 'http://dev1.fio.dev:8888' // Testnet Bahamas //const TESTURL = 'https://fio.greymass.com' // Mainnet diff --git a/index.js b/index.js index 4a60ded7..9046b340 100644 --- a/index.js +++ b/index.js @@ -3,8 +3,6 @@ const {expect} = require('chai') describe('TEST SUITE', () => { - - require('./tests/bravo-migr-test.js'); //This is required when testing 2.3.0 (bravo) with fio bahamas (need to do the full table migration). //require('./tests/history.js'); // Only run against history node. diff --git a/tests/fio-request.js b/tests/fio-request.js index 762361e6..ebb6f22d 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -2631,26 +2631,26 @@ describe(`I. reject_funds_request: Check all getters after`, () => { } }) - it.skip('Call get_table_rows from fiotrxtss (NEW table) and confirm request is in table', async () => { + it('Call get_table_rows from fiotrxtss (NEW table) and confirm request is in table', async () => { try { const json = { - json: true, // Get the response as json - code: 'fio.reqobt', // Contract that we target - scope: 'fio.reqobt', // Account that owns the data - table: 'fiotrxtss', // Table name - limit: 2, // Maximum number of rows that we want to get - reverse: true, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'fiotrxtss', + limit: 2, + reverse: true, + show_payer: false } requests = await callFioApi("get_table_rows", json); console.log('requests: ', requests); for (request in requests.rows) { if (requests.rows[request].fio_request_id == requestId) { - console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); + //console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); break; } } - expect(requests.rows[request].payer_fio_addr).to.equal(user2.address); + expect(requests.rows[request].payer_fio_addr).to.equal(userA2.address); } catch (err) { console.log('Error', err); expect(err).to.equal(null); @@ -2659,3 +2659,106 @@ describe(`I. reject_funds_request: Check all getters after`, () => { }) +describe(`J. get_received_fio_requests error conditions`, () => { + let userA1, userA2 + const payment = 5000000000 // 5 FIO + const requestMemo = 'Memo in the initial request' + + it(`Create users`, async () => { + userA1 = await newUser(faucet); + userA2 = await newUser(faucet); + }) + + it(`get_received_fio_requests with no requests. Expect: ${config.error.noFioRequests}`, async () => { + try { + const json = { + fio_public_key: userA2.publicKey, + limit: 100, + offset: 0 + } + result = await callFioApi("get_received_fio_requests", json); + console.log('result: ', result.json) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err.error) + expect(err.error.message).to.equal(config.error.noFioRequests) + } + }) + + it(`userA1 requests funds from userA2`, async () => { + try { + const result = await userA1.sdk.genericAction('requestFunds', { + payerFioAddress: userA2.address, + payeeFioAddress: userA1.address, + payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', + amount: payment, + chainCode: 'BTC', + tokenCode: 'BTC', + memo: requestMemo, + maxFee: config.api.new_funds_request.fee, + payerFioPublicKey: userA2.publicKey, + technologyProviderId: '', + hash: '', + offLineUrl: '' + }) + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`get_received_fio_requests with invalid public key. Expect: ${config.error.invalidKey}`, async () => { + try { + const json = { + fio_public_key: 'FIOXXXLGcmXLCw87pqNMFurd23SqqEDbCUirr7vwuwuzfaySxQ9w6', + limit: 100, + offset: 0 + } + result = await callFioApi("get_received_fio_requests", json); + console.log('result: ', result.json) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err.error) + expect(err.error.fields[0].error).to.equal(config.error.invalidKey) + } + }) + + it(`get_received_fio_requests with invalid limit. Expect: ${config.error.invalidLimit}`, async () => { + try { + const json = { + fio_public_key: userA2.publicKey, + limit: -1, + offset: 0 + } + result = await callFioApi("get_received_fio_requests", json); + console.log('result: ', result.json) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err.error) + expect(err.error.fields[0].error).to.equal(config.error.invalidLimit) + } + }) + + it(`get_received_fio_requests with invalid offset. Expect: ${config.error.invalidOffset}`, async () => { + try { + const json = { + fio_public_key: userA2.publicKey, + limit: 100, + offset: -1 + } + result = await callFioApi("get_received_fio_requests", json); + console.log('result: ', result.json) + //console.log('content: ', result.requests[0].content) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err.error) + expect(err.error.fields[0].error).to.equal(config.error.invalidOffset) + } + }) + +}) \ No newline at end of file diff --git a/tests/transfer-locked-tokens.js b/tests/transfer-locked-tokens.js index b63ccb1d..196a73b0 100644 --- a/tests/transfer-locked-tokens.js +++ b/tests/transfer-locked-tokens.js @@ -307,7 +307,7 @@ describe(`B. Parameter tests`, () => { } }) - it(`(${testType}) Failute test, Transfer locked tokens, pub key account pre exists`, async () => { + it(`(${testType}) Failure test, Transfer locked tokens, pub key account pre exists`, async () => { if (testType == 'sdk') { try { const result = await userA1.sdk.genericAction('transferLockedTokens', { @@ -367,7 +367,7 @@ describe(`B. Parameter tests`, () => { } }) - it(`(${testType}) Failute test, Too many lock periods`, async () => { + it(`(${testType}) Failure test, Too many lock periods`, async () => { if (testType == 'sdk') { try { const result = await userA4.sdk.genericAction('transferLockedTokens', { @@ -1113,7 +1113,7 @@ describe(`B. transfer with 2 unlock periods, canvote = false`, () => { } }) - it(`[BD-2244] Register domain: succeeds`, async () => { + it(`Register domain: succeeds (BD-2244)`, async () => { try { domsdk = new FIOSDK(transferdomainkey.privateKey, transferdomainkey.publicKey, config.BASE_URL, fetchJson); domsdk.domain2 = generateFioDomain(8) From bc25ee17abf935b34d688c7789dbf3d17d823517 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Fri, 19 Feb 2021 11:16:27 -0700 Subject: [PATCH 54/76] Add tests for migr2 and migr3 --- tests/bravo-migr-test.js | 90 ++++++++++++++++++++++++++++++++++++++-- tests/fio-request.js | 2 +- 2 files changed, 88 insertions(+), 4 deletions(-) diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index c7c10a1e..4e4b3cef 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -2058,7 +2058,7 @@ describe(`Release v2.3.2 - fiotrxtss (NEW table) scripts`, () => { }) }) -describe.skip(`Release delta - remove data from old tables (fioreqctxts, recordobts, fioreqstss)`, () => { +describe.skip(`Release delta (develop - migr2) - remove data from old tables (fioreqctxts, recordobts, fioreqstss)`, () => { let isFinished = 0 it('Echo size of fioreqctxts table', async () => { @@ -2132,7 +2132,7 @@ describe.skip(`Release delta - remove data from old tables (fioreqctxts, recordo actor: bp1.account } }) - console.log('Result: ', result) + //console.log('Result: ', result) expect(result.transaction_id).to.exist } catch (err) { console.log('Error: ', err) @@ -2261,5 +2261,89 @@ describe.skip(`Release delta - remove data from old tables (fioreqctxts, recordo }) -describe.skip(`Release delta - remove migrtrx action, remove references to old tables (fioreqctxts, recordobts, fioreqstss) `, () => { +describe.skip(`Release echo (migr/final-rc1) - remove migrtrx action, remove references to old tables (fioreqctxts, recordobts, fioreqstss) `, () => { + + it(`Call migrtrx. Expect error: Unknown action migrtrx in contract fio.reqobt`, async () => { + try { + const result = await callFioApiSigned('push_transaction', { + action: 'migrtrx', + account: 'fio.reqobt', + actor: bp1.account, + privKey: bp1.privateKey, + data: { + amount: 20, + actor: bp1.account + } + }) + console.log('Result: ', result); + expect(result).to.equal(null); + } catch (err) { + //console.log('Error: ', err.message); + expect(err.message).to.equal('Unknown action migrtrx in contract fio.reqobt') + } + }) + + it('get_table_rows for fioreqctxts. Expect: Table fioreqctxts is not specified in the ABI', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'fioreqctxts', + limit: 10, + reverse: false, + show_payer: false + } + fioreqctxts = await callFioApi("get_table_rows", json); + console.log('fioreqctxts: ', fioreqctxts); + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err.error.error) + expect(err.error.code).to.equal(500) + expect(err.error.error.details[0].message).to.equal('Table fioreqctxts is not specified in the ABI') + } + }) + + it('get_table_rows for recordobts. Expect: Table recordobts is not specified in the ABI', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'recordobts', + limit: 10, + reverse: false, + show_payer: false + } + recordobts = await callFioApi("get_table_rows", json); + console.log('recordobts: ', recordobts); + expect(recordobts.rows.length).to.equal(0); + } catch (err) { + //console.log('Error', err); + expect(err.error.code).to.equal(500) + expect(err.error.error.details[0].message).to.equal('Table recordobts is not specified in the ABI') + } + }) + + it('get_table_rows for fioreqstss. Expect: Table fioreqstss is not specified in the ABI', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'fioreqstss', + limit: 10, + reverse: false, + show_payer: false + } + fioreqstss = await callFioApi("get_table_rows", json); + console.log('fioreqstss: ', fioreqstss); + expect(fioreqstss.rows.length).to.equal(0); + } catch (err) { + //console.log('Error', err); + expect(err.error.code).to.equal(500) + expect(err.error.error.details[0].message).to.equal('Table fioreqstss is not specified in the ABI') + } + }) + }) \ No newline at end of file diff --git a/tests/fio-request.js b/tests/fio-request.js index ebb6f22d..7ecdaa95 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -2643,7 +2643,7 @@ describe(`I. reject_funds_request: Check all getters after`, () => { show_payer: false } requests = await callFioApi("get_table_rows", json); - console.log('requests: ', requests); + //console.log('requests: ', requests); for (request in requests.rows) { if (requests.rows[request].fio_request_id == requestId) { //console.log('payer_fio_addr: ', requests.rows[request].payer_fio_addr); From 728812c7bdb5cfd098d5cdf34d0c0943129eac2d Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Tue, 23 Feb 2021 08:45:07 -0700 Subject: [PATCH 55/76] Add get_obt_data test --- index.js | 1 + tests/clio.js | 818 ++++++++++++++++++++-------------- tests/producer-fee-setting.js | 2 +- tests/record-obt-data.js | 153 +++++++ tests/vote.js | 2 +- 5 files changed, 640 insertions(+), 336 deletions(-) diff --git a/index.js b/index.js index 9046b340..6f754b8a 100644 --- a/index.js +++ b/index.js @@ -31,6 +31,7 @@ describe('TEST SUITE', () => { require('./tests/addbundles.js'); // FIP-11.a require('./tests/tpid.js'); require('./tests/clio.js'); // FIP-16 + //require('./tests/performance-request-obt.js'); require('./tests/testnet-smoketest.js'); // Testnet smoketest. By default runs against local build. diff --git a/tests/clio.js b/tests/clio.js index 322b433d..bb6bbefa 100644 --- a/tests/clio.js +++ b/tests/clio.js @@ -10,284 +10,429 @@ const url = config.URL const max_fee = 900000000000 const tpid = 'tpid@testnet' -const randString = randStr(64) // Content field requires min 64 max 296 size -const content = `"{"content":"one${randString}"}"` -const content2 = `"{"content":"two${randString}"}"` -const content3 = `"{"content":"three${randString}"}"` async function runClio(parms) { - return new Promise(function(resolve, reject) { - command = clio + " -u " + url + " " + parms - //console.log('command = ', command) - //command = "../fio.devtools/bin/clio -u http://localhost:8889 get info" - exec(command, (error, stdout, stderr) => { - if (error) { - reject(error); - return; - } - resolve(stdout.trim()); - }); - }); + return new Promise(function(resolve, reject) { + command = clio + " -u " + url + " " + parms + //console.log('command = ', command) + //command = "../fio.devtools/bin/clio -u http://localhost:8889 get info" + exec(command, (error, stdout, stderr) => { + if (error) { + reject(error); + return; + } + resolve(stdout.trim()); + }); + }); } before(async () => { - faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson) + faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson) - const result = await unlockWallet('fio'); + const result = await unlockWallet('fio'); }) describe(`************************** clio.js ************************** \n A. Test clio`, () => { - it(`get info`, async () => { - const result = await runClio('get info'); - expect(JSON.parse(result).head_block_num).to.be.a('number') - }) + it(`get info`, async () => { + const result = await runClio('get info'); + expect(JSON.parse(result).head_block_num).to.be.a('number') + }) }) describe(`B. Request and OBT Data`, () => { - let fio_request_id, fio_request_id2, fio_request_id3, user1, user2, resultSdk, resultClio, contentSdk, contentClio - - it(`Create users and import private keys`, async () => { - user1 = await newUser(faucet); - await runClio('wallet import -n fio --private-key ' + user1.privateKey); - user2 = await newUser(faucet); - await runClio('wallet import -n fio --private-key ' + user2.privateKey); - - console.log('user1 pub key: ', user1.publicKey) - console.log('user2 pub key: ', user2.publicKey) - }) - - it(`clio: request new (user1 requests funds from user2)`, async () => { - try { - const result = await runClio(`request new -j ${user2.address} ${user1.address} ${content} ${user1.account} ${tpid} ${max_fee} --permission ${user1.account}@active`); - //console.log('Result: ', result) - fio_request_id = JSON.parse(JSON.parse(result).processed.action_traces[0].receipt.response).fio_request_id - //console.log('ID: ', JSON.parse(JSON.parse(result).processed.action_traces[0].receipt.response).fio_request_id) - expect(JSON.parse(result).transaction_id).to.exist - } catch (err) { - console.log('Error', err) + let fio_request_id, fio_request_id2, fio_request_id3, user1, user2, resultSdk, resultClio, contentSdk, contentClio + let content, content2, content3 + + const contentFields = { + payee_public_address: 'btc:thisispayeetokenpublicaddress', + amount: 500000, + chain_code: 'BTC', + token_code: 'BTC', + memo: 'request Memo One' + } + + const content2Fields = { + payee_public_address: 'eth:thisispayeetokenpublicaddress', + amount: 600000, + chain_code: 'ETH', + token_code: 'ETH', + memo: 'request Memo Two' + } + + const content3Fields = { + payee_public_address: 'xrp:thisispayeetokenpublicaddress', + amount: 700000, + chain_code: 'XRP', + token_code: 'XRP', + memo: 'request Memo Three' + } + + it(`Create users and import private keys`, async () => { + user1 = await newUser(faucet); + await runClio('wallet import -n fio --private-key ' + user1.privateKey); + user2 = await newUser(faucet); + await runClio('wallet import -n fio --private-key ' + user2.privateKey); + + //console.log('user1 pub key: ', user1.publicKey) + //console.log('user2 pub key: ', user2.publicKey) + }) + + it(`SDK: user1 requests funds from user2`, async () => { + try { + const result = await user1.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user1.address, + payeeTokenPublicAddress: contentFields.payee_public_address, + amount: contentFields.payee_public_address, + chainCode: contentFields.chain_code, + tokenCode: contentFields.token_code, + memo: contentFields.memo, + maxFee: config.maxFee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '', + }) + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(2000) }) + + it('(api) Call get_sent_fio_requests', async () => { + try { + const result = await callFioApi("get_sent_fio_requests", { + fio_public_key: user1.publicKey, + limit: 10, + offset: 0 + }) + //console.log('Result', result) + content = result.requests[0].content + } catch (err) { + console.log('Error', err) + } + }) + + it(`clio: request new (user1 requests funds from user2). Pass in same content field as previous request. Record request ID.`, async () => { + try { + const result = await runClio(`request new -j ${user2.address} ${user1.address} ${content} ${user1.account} ${tpid} ${max_fee} --permission ${user1.account}@active`); + //console.log('Result: ', result) + fio_request_id = JSON.parse(JSON.parse(result).processed.action_traces[0].receipt.response).fio_request_id + //console.log('ID: ', JSON.parse(JSON.parse(result).processed.action_traces[0].receipt.response).fio_request_id) + expect(JSON.parse(result).transaction_id).to.exist + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`get_sent_fio_requests for user1 (payee). Both clio and SDK requests to return same content.`, async () => { + try { + const result = await user1.sdk.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result); + //console.log('result.requests[0].content: ', result.requests[0].content) + expect(result.requests[0].fio_request_id).to.equal(result.requests[1].fio_request_id - 1); + expect(result.requests[0].payer_fio_address).to.equal(result.requests[1].payer_fio_address); + expect(result.requests[0].payee_fio_address).to.equal(result.requests[1].payee_fio_address); + expect(result.requests[0].payer_fio_public_key).to.equal(result.requests[1].payer_fio_public_key); + expect(result.requests[0].payee_fio_public_key).to.equal(result.requests[1].payee_fio_public_key); + expect(result.requests[0].status).to.equal(result.requests[1].status); + + expect(result.requests[0].content.payee_public_address).to.equal(result.requests[1].content.payee_public_address); + expect(result.requests[0].content.amount).to.equal(result.requests[1].content.amount); + expect(result.requests[0].content.chain_code).to.equal(result.requests[1].content.chain_code); + expect(result.requests[0].content.token_code).to.equal(result.requests[1].content.token_code); + expect(result.requests[0].content.memo).to.equal(result.requests[1].content.memo); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it('(api) Call get_sent_fio_requests', async () => { + try { + const result = await callFioApi("get_sent_fio_requests", { + fio_public_key: user1.publicKey, + limit: 10, + offset: 0 + }) + //console.log('Result', result) + expect(result.requests[0].fio_request_id).to.equal(result.requests[1].fio_request_id - 1); + expect(result.requests[0].payer_fio_address).to.equal(result.requests[1].payer_fio_address); + expect(result.requests[0].payee_fio_address).to.equal(result.requests[1].payee_fio_address); + expect(result.requests[0].payer_fio_public_key).to.equal(result.requests[1].payer_fio_public_key); + expect(result.requests[0].payee_fio_public_key).to.equal(result.requests[1].payee_fio_public_key); + expect(result.requests[0].status).to.equal(result.requests[1].status); + } catch (err) { + console.log('Error', err) + } + }) + + it(`clio: request reject (user2 rejects the 2nd clio request from user1)`, async () => { + try { + result = await runClio(`request reject -j ${fio_request_id} ${user2.account} ${tpid} ${max_fee} --permission ${user2.account}@active`); + //console.log('Result: ', result) + expect(JSON.parse(result).transaction_id).to.exist + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`get_sent_fio_requests for user1 (payee). Expect the 2nd request to have status = 'rejected'`, async () => { + try { + const result = await user1.sdk.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result); + expect(result.requests[1].status).to.equal('rejected'); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`SDK: user2 requests funds from user1`, async () => { + try { + const result = await user2.sdk.genericAction('requestFunds', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payeeTokenPublicAddress: contentFields.payee_public_address, + amount: contentFields.amount, + chainCode: contentFields.chain_code, + tokenCode: contentFields.token_code, + memo: contentFields.memo, + maxFee: config.maxFee, + payerFioPublicKey: user1.publicKey, + technologyProviderId: '', + }) + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error: ', err) expect(err).to.equal(null) - } - }) - - it(`SDK: user1 requests funds from user2`, async () => { - try { - const result = await user1.sdk.genericAction('requestFunds', { - payerFioAddress: user2.address, - payeeFioAddress: user1.address, - payeeTokenPublicAddress: 'thisispayeetokenpublicaddress', - amount: 500000, - chainCode: 'BTC', - tokenCode: 'BTC', - memo: 'requestMemo', - maxFee: config.maxFee, - payerFioPublicKey: user2.publicKey, - technologyProviderId: '', - }) - requestId = result.fio_request_id - //console.log('Result: ', result) - expect(result.status).to.equal('requested') - } catch (err) { - console.log('Error: ', err) - expect(err).to.equal(null) - } - }) + } + }) - it(`Wait a few seconds.`, async () => { await timeout(2000) }) + it(`Wait a few seconds.`, async () => { await timeout(2000) }) - it.skip(`(BUG BD-2358) get_sent_fio_requests for user1 (payee). Both clio and SDK requests to return same content.`, async () => { - try { - const result = await user1.sdk.genericAction('getSentFioRequests', { - limit: '', - offset: '' - }) - //console.log('result: ', result); - //console.log('fio_request_id: ', fio_request_id) - expect(result.requests[0].fio_request_id).to.equal(result.requests[1].fio_request_id); - expect(result.requests[0].payer_fio_address).to.equal(result.requests[1].payer_fio_address); - expect(result.requests[0].payee_fio_address).to.equal(result.requests[1].payee_fio_address); - expect(result.requests[0].payer_fio_public_key).to.equal(result.requests[1].payer_fio_public_key); - expect(result.requests[0].payee_fio_public_key).to.equal(result.requests[1].payee_fio_public_key); - expect(result.requests[0].status).to.equal(result.requests[1].status); - } catch (err) { - console.log('Error: ', err) - expect(err).to.equal(null) - } - }) - - it('(api) Call get_sent_fio_requests', async () => { - try { - const result = await callFioApi("get_sent_fio_requests", { - fio_public_key: user1.publicKey, - limit: 10, - offset: 0 - }) - //console.log('Result', result) - expect(result.requests[0].fio_request_id).to.equal(result.requests[1].fio_request_id - 1); - expect(result.requests[0].payer_fio_address).to.equal(result.requests[1].payer_fio_address); - expect(result.requests[0].payee_fio_address).to.equal(result.requests[1].payee_fio_address); - expect(result.requests[0].payer_fio_public_key).to.equal(result.requests[1].payer_fio_public_key); - expect(result.requests[0].payee_fio_public_key).to.equal(result.requests[1].payee_fio_public_key); - expect(result.requests[0].status).to.equal(result.requests[1].status); - } catch (err) { - console.log('Error', err) - } - }) - - it(`clio: request reject (user2 rejects request from user1)`, async () => { - try { - result = await runClio(`request reject -j ${fio_request_id} ${user2.account} ${tpid} ${max_fee} --permission ${user2.account}@active`); - //console.log('Result: ', result) - expect(JSON.parse(result).transaction_id).to.exist - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } - }) - - it.skip(`(BUG BD-2358) get_sent_fio_requests for user1 (payee). Expect one request with status = 'rejected'`, async () => { - try { - const result = await user1.sdk.genericAction('getSentFioRequests', { - limit: '', - offset: '' - }) - console.log('result: ', result); - //console.log('content: ', result.requests[0].content); - //expect(result.requests[0].fio_request_id).to.equal(fio_request_id); - //expect(result.requests[0].payer_fio_address).to.equal(user2.address); - //expect(result.requests[0].payee_fio_address).to.equal(user1.address); - //expect(result.requests[0].payer_fio_public_key).to.equal(user2.publicKey); - //expect(result.requests[0].payee_fio_public_key).to.equal(user1.publicKey); - //expect(result.requests[0].status).to.equal('rejected'); - } catch (err) { - console.log('Error: ', err) - expect(err).to.equal(null) - } - }) - - it(`clio: request new (user2 requests funds from user1)`, async () => { - try { - result = await runClio(`request new -j ${user1.address} ${user2.address} ${content} ${user2.account} ${tpid} ${max_fee} --permission ${user2.account}@active`); - //console.log('Result: ', result) - fio_request_id2 = JSON.parse(JSON.parse(result).processed.action_traces[0].receipt.response).fio_request_id - expect(JSON.parse(result).transaction_id).to.exist - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } - }) - - it.skip(`(BUG BD-2358) get_pending_fio_requests for user1 (payer). Expect one request with status = 'pending'`, async () => { - try { - const result = await user1.sdk.genericAction('getPendingFioRequests', { - limit: '', - offset: '' - }) - console.log('result: ', result) - //console.log('content: ', result.requests[0].content) - expect(result.requests[0].fio_request_id).to.equal(fio_request_id2); - expect(result.requests[0].payer_fio_address).to.equal(user1.address); - expect(result.requests[0].payee_fio_address).to.equal(user2.address); - expect(result.requests[0].payer_fio_public_key).to.equal(user1.publicKey); - expect(result.requests[0].payee_fio_public_key).to.equal(user2.publicKey); - } catch (err) { - console.log('Error: ', err) - expect(err).to.equal(null) - } - }) - - it(`clio: request cancel (user2 cancels sent request)`, async () => { - try { - result = await runClio(`request cancel -j ${fio_request_id2} ${user2.account} ${tpid} ${max_fee} --permission ${user2.account}@active`); - //console.log('Result: ', result) - expect(JSON.parse(result).transaction_id).to.exist - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } - }) - - it.skip(`(BUG BD-2358) get_pending_fio_requests for user1 (payer). Expect one request with status = 'cancelled'`, async () => { - try { - const result = await user1.sdk.genericAction('getPendingFioRequests', { - limit: '', - offset: '' - }) - console.log('result: ', result) - //console.log('content: ', result.requests[0].content) - expect(result.requests[0].fio_request_id).to.equal(fio_request_id2); - expect(result.requests[0].payer_fio_address).to.equal(user1.address); - expect(result.requests[0].payee_fio_address).to.equal(user2.address); - expect(result.requests[0].payer_fio_public_key).to.equal(user1.publicKey); - expect(result.requests[0].payee_fio_public_key).to.equal(user2.publicKey); - } catch (err) { - console.log('Error: ', err) - expect(err).to.equal(null) - } - }) - - it(`clio: request new (user1 requests funds from user2)`, async () => { - try { - result = await runClio(`request new -j ${user2.address} ${user1.address} ${content2} ${user1.account} ${tpid} ${max_fee} --permission ${user1.account}@active`); - //console.log('Result: ', result) - fio_request_id3 = JSON.parse(JSON.parse(result).processed.action_traces[0].receipt.response).fio_request_id - expect(JSON.parse(result).transaction_id).to.exist - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } - }) - - it(`clio: record (user2 records obt record in response to request)`, async () => { - try { - result = await runClio(`data record -j ${fio_request_id3} ${user2.address} ${user1.address} ${content3} ${user2.account} ${tpid} ${max_fee} --permission ${user2.account}@active`); - //console.log('Result: ', result) - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } - }) - - it(`getObtData for user2. Expect one record with status = 'sent_to_blockchain'`, async () => { - try { - const result = await user2.sdk.genericAction('getObtData', { - limit: '', - offset: '', - tokenCode: 'BTC' - }) - //console.log('result: ', result) - //console.log('content: ', result.obt_data_records[0].content) - expect(result.obt_data_records[0].fio_request_id).to.equal(fio_request_id3); - expect(result.obt_data_records[0].payer_fio_address).to.equal(user2.address); - expect(result.obt_data_records[0].payee_fio_address).to.equal(user1.address); - expect(result.obt_data_records[0].payer_fio_public_key).to.equal(user2.publicKey); - expect(result.obt_data_records[0].payee_fio_public_key).to.equal(user1.publicKey); - expect(result.obt_data_records[0].status).to.equal('sent_to_blockchain'); - } catch (err) { - console.log('Error: ', err) - expect(err).to.equal(null) - } + it('(api) Call get_sent_fio_requests', async () => { + try { + const result = await callFioApi("get_sent_fio_requests", { + fio_public_key: user1.publicKey, + limit: 10, + offset: 0 }) - - it.skip(`(BUG BD-2358) get_sent_fio_requests for user1 (payee). Expect one request with status = 'sent_to_blockchain'`, async () => { - try { - const result = await user1.sdk.genericAction('getSentFioRequests', { - limit: '', - offset: '' - }) - console.log('result: ', result); - //console.log('content: ', result.requests[0].content); - expect(result.requests[0].fio_request_id).to.equal(fio_request_id); - expect(result.requests[0].payer_fio_address).to.equal(user2.address); - expect(result.requests[0].payee_fio_address).to.equal(user1.address); - expect(result.requests[0].payer_fio_public_key).to.equal(user2.publicKey); - expect(result.requests[0].payee_fio_public_key).to.equal(user1.publicKey); - expect(result.requests[0].status).to.equal('sent_to_blockchain'); - } catch (err) { - console.log('Error: ', err) - expect(err).to.equal(null) - } - }) + //console.log('Result', result) + content = result.requests[0].content + } catch (err) { + console.log('Error', err) + } + }) + + it(`clio: request new (user2 requests funds from user1)`, async () => { + try { + result = await runClio(`request new -j ${user1.address} ${user2.address} ${content} ${user2.account} ${tpid} ${max_fee} --permission ${user2.account}@active`); + //console.log('Result: ', result) + fio_request_id2 = JSON.parse(JSON.parse(result).processed.action_traces[0].receipt.response).fio_request_id + expect(JSON.parse(result).transaction_id).to.exist + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`get_pending_fio_requests for user1 (payer). Expect 2 requests from user2`, async () => { + try { + const result = await user1.sdk.genericAction('getPendingFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result) + //console.log('content: ', result.requests[0].content) + expect(result.requests.length).to.equal(2); + expect(result.requests[1].fio_request_id).to.equal(fio_request_id2); + expect(result.requests[1].payer_fio_address).to.equal(user1.address); + expect(result.requests[1].payee_fio_address).to.equal(user2.address); + expect(result.requests[1].payer_fio_public_key).to.equal(user1.publicKey); + expect(result.requests[1].payee_fio_public_key).to.equal(user2.publicKey); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`clio: request cancel (user2 cancels request sent to user1)`, async () => { + try { + result = await runClio(`request cancel -j ${fio_request_id2} ${user2.account} ${tpid} ${max_fee} --permission ${user2.account}@active`); + //console.log('Result: ', result) + expect(JSON.parse(result).transaction_id).to.exist + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`get_sent_fio_requests for user2 (payer). Expect request #2 to have status = 'cancelled'`, async () => { + try { + const result = await user2.sdk.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result) + expect(result.requests[1].status).to.equal('cancelled'); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`SDK: user1 requests funds from user2`, async () => { + try { + const result = await user1.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user1.address, + payeeTokenPublicAddress: content2Fields.payee_public_address, + amount: content2Fields.amount, + chainCode: content2Fields.chain_code, + tokenCode: content2Fields.token_code, + memo: content2Fields.memo, + maxFee: config.maxFee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '', + }) + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(2000) }) + + it('(api) Call get_sent_fio_requests', async () => { + try { + const result = await callFioApi("get_sent_fio_requests", { + fio_public_key: user1.publicKey, + limit: 10, + offset: 0 + }) + //console.log('Result', result) + content2 = result.requests[0].content + } catch (err) { + console.log('Error', err) + } + }) + + it(`clio: request new (user1 requests funds from user2)`, async () => { + try { + result = await runClio(`request new -j ${user2.address} ${user1.address} ${content2} ${user1.account} ${tpid} ${max_fee} --permission ${user1.account}@active`); + //console.log('Result: ', result) + fio_request_id3 = JSON.parse(JSON.parse(result).processed.action_traces[0].receipt.response).fio_request_id + expect(JSON.parse(result).transaction_id).to.exist + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`SDK: user1 recordObtData to get a formatted OBT content field`, async () => { + try { + const result = await user1.sdk.genericAction('recordObtData', { + payerFioAddress: user1.address, + payeeFioAddress: user2.address, + payerTokenPublicAddress: user1.publicKey, + payeeTokenPublicAddress: user2.publicKey, + amount: content3Fields.amount, + chainCode: content3Fields.chain_code, + tokenCode: content3Fields.token_code, + memo: content3Fields.memo, + maxFee: config.maxFee, + technologyProviderId: '', + payeeFioPublicKey: user2.publicKey + }) + //console.log('Result: ', result) + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(5000) }) + + it(`Call get_obt_data for user1 to get the content field`, async () => { + try { + const json = { + fio_public_key: user1.publicKey + } + result = await callFioApi("get_obt_data", json); + //console.log('Result: ', result); + //console.log('content: ', result.obt_data_records[0].content); + content3 = result.obt_data_records[0].content; + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`clio: record (user2 records obt record in response to request)`, async () => { + try { + result = await runClio(`data record -j ${fio_request_id3} ${user2.address} ${user1.address} ${content3} ${user2.account} ${tpid} ${max_fee} --permission ${user2.account}@active`); + //console.log('Result: ', result) + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`getObtData for user2. Expect status = 'sent_to_blockchain'`, async () => { + try { + const result = await user2.sdk.genericAction('getObtData', { + limit: '', + offset: '' + }) + //console.log('result: ', result) + //console.log('content: ', result.obt_data_records[0].content) + expect(result.obt_data_records[0].fio_request_id).to.equal(fio_request_id3); + expect(result.obt_data_records[0].payer_fio_address).to.equal(user2.address); + expect(result.obt_data_records[0].payee_fio_address).to.equal(user1.address); + expect(result.obt_data_records[0].payer_fio_public_key).to.equal(user2.publicKey); + expect(result.obt_data_records[0].payee_fio_public_key).to.equal(user1.publicKey); + expect(result.obt_data_records[0].status).to.equal('sent_to_blockchain'); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`get_sent_fio_requests for user1 (payee). Expect one request with status = 'sent_to_blockchain' (BD-2358) `, async () => { + try { + const result = await user1.sdk.genericAction('getSentFioRequests', { + limit: '', + offset: '' + }) + //console.log('result: ', result); + //console.log('content: ', result.requests[0].content); + expect(result.requests[3].fio_request_id).to.equal(fio_request_id3); + expect(result.requests[3].payer_fio_address).to.equal(user2.address); + expect(result.requests[3].payee_fio_address).to.equal(user1.address); + expect(result.requests[3].payer_fio_public_key).to.equal(user2.publicKey); + expect(result.requests[3].payee_fio_public_key).to.equal(user1.publicKey); + expect(result.requests[3].status).to.equal('sent_to_blockchain'); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) }) @@ -755,6 +900,81 @@ describe(`F. Transfer`, () => { }) +describe(`H. clio error testing`, () => { + let user1, user2, fio_request_id + const fundsAmount = 10000000000 + + it(`Create users and import private keys`, async () => { + user1 = await newUser(faucet); + result = await runClio('wallet import -n fio --private-key ' + user1.privateKey); + + user2 = await newUser(faucet); + result = await runClio('wallet import -n fio --private-key ' + user2.privateKey); + }) + + it(`clio: request new (user1 requests funds from user2)`, async () => { + try { + const result = await runClio(`request new -j ${user2.address} ${user1.address} ${content} ${user1.account} ${tpid} ${max_fee} --permission ${user1.account}@active`); + //console.log('Result: ', result) + fio_request_id = JSON.parse(JSON.parse(result).processed.action_traces[0].receipt.response).fio_request_id + //console.log('ID: ', JSON.parse(JSON.parse(result).processed.action_traces[0].receipt.response).fio_request_id) + expect(JSON.parse(result).transaction_id).to.exist + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`clio: request new with account which is not payee. Expect "Missing required authority"`, async () => { + try { + const result = await runClio(`request new -j ${user2.address} ${user1.address} ${content} ${user1.account} ${tpid} ${max_fee} --permission ${user2.account}@active`); + //console.log('Result: ', result) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err) + expect(String(err)).to.include('Missing required authority') + } + }) + + // From FIP-16: max_fee is set to 800000000001 so user does not have to define manually. Any required fee set by the producers under this value will process + it(`clio: request cancel with inadequate fee succeeds`, async () => { + try { + result = await runClio(`request cancel -j ${fio_request_id} ${user1.account} ${tpid} 100 --permission ${user1.account}@active`); + //console.log('Result: ', result) + expect(JSON.parse(result).transaction_id).to.exist + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`clio: request reject with invalid request ID`, async () => { + try { + result = await runClio(`request reject -j 777 ${user2.account} ${tpid} ${max_fee} --permission ${user2.account}@active`); + //console.log('Result: ', result) + expect(result).to.equal(null) + } catch (err) { + //console.log('Error', err) + expect(String(err)).to.include('Error code 400') + } + }) + + it(`clio: domain register with existing domain`, async () => { + try { + result = await runClio(`domain register -j ${user1.domain} ${user1.account} ${user1.publicKey} ${tpid} ${max_fee} --permission ${user1.account}@active`); + //console.log('Result: ', JSON.parse(result)); + expect(result).to.equal(null) + } catch (err) { + //console.log('Error', err) + expect(String(err)).to.include('FIO domain already registered') + } + }) +}) + + +/** + * Commenting out ratios and multipliers tests. Decided to leave these calls out of clio + describe(`G. Set ratios and multipliers`, () => { let multAmount = 5, endpoint1 = "register_fio_domain", ratio1 = 40000000000, @@ -785,7 +1005,7 @@ describe(`G. Set ratios and multipliers`, () => { } }) - it.skip(`(BUG BD-2226) clio: bp1 fee submit_multiplier`, async () => { + it.skip(`clio: bp1 fee submit_multiplier`, async () => { try { result = await runClio(`fee submit_multiplier -j ${multAmount} ${bp1.account} --permission ${bp1.account}@active`); //console.log('Result: ', JSON.parse(result)); @@ -833,7 +1053,7 @@ describe(`G. Set ratios and multipliers`, () => { } }) - it.skip(`(BUG BD-2226) clio: bp1 fee submit_ratios`, async () => { + it.skip(`clio: bp1 fee submit_ratios`, async () => { try { result = await runClio(`fee submit_ratios -j ${bp1.address} ${bp1.account} ${max_fee} ${endpoint1} ${ratio1} --permission ${bp1.account}@active`); //console.log('Result: ', JSON.parse(result)); @@ -864,74 +1084,4 @@ describe(`G. Set ratios and multipliers`, () => { }) -describe(`H. clio error testing`, () => { - let user1, user2, fio_request_id - const fundsAmount = 10000000000 - - it(`Create users and import private keys`, async () => { - user1 = await newUser(faucet); - result = await runClio('wallet import -n fio --private-key ' + user1.privateKey); - - user2 = await newUser(faucet); - result = await runClio('wallet import -n fio --private-key ' + user2.privateKey); - }) - - it(`clio: request new (user1 requests funds from user2)`, async () => { - try { - const result = await runClio(`request new -j ${user2.address} ${user1.address} ${content} ${user1.account} ${tpid} ${max_fee} --permission ${user1.account}@active`); - //console.log('Result: ', result) - fio_request_id = JSON.parse(JSON.parse(result).processed.action_traces[0].receipt.response).fio_request_id - //console.log('ID: ', JSON.parse(JSON.parse(result).processed.action_traces[0].receipt.response).fio_request_id) - expect(JSON.parse(result).transaction_id).to.exist - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } - }) - - it(`clio: request new with account which is not payee. Expect "Missing required authority"`, async () => { - try { - const result = await runClio(`request new -j ${user2.address} ${user1.address} ${content} ${user1.account} ${tpid} ${max_fee} --permission ${user2.account}@active`); - //console.log('Result: ', result) - expect(result).to.equal(null) - } catch (err) { - //console.log('Error: ', err) - expect(String(err)).to.include('Missing required authority') - } - }) - - // From FIP-16: max_fee is set to 800000000001 so user does not have to define manually. Any required fee set by the producers under this value will process - it(`clio: request cancel with inadequate fee succeeds`, async () => { - try { - result = await runClio(`request cancel -j ${fio_request_id} ${user1.account} ${tpid} 100 --permission ${user1.account}@active`); - //console.log('Result: ', result) - expect(JSON.parse(result).transaction_id).to.exist - } catch (err) { - console.log('Error', err) - expect(err).to.equal(null) - } - }) - - it(`clio: request reject with invalid request ID`, async () => { - try { - result = await runClio(`request reject -j 777 ${user2.account} ${tpid} ${max_fee} --permission ${user2.account}@active`); - //console.log('Result: ', result) - expect(result).to.equal(null) - } catch (err) { - //console.log('Error', err) - expect(String(err)).to.include('Error code 400') - } - }) - - it(`clio: domain register with existing domain`, async () => { - try { - result = await runClio(`domain register -j ${user1.domain} ${user1.account} ${user1.publicKey} ${tpid} ${max_fee} --permission ${user1.account}@active`); - //console.log('Result: ', JSON.parse(result)); - expect(result).to.equal(null) - } catch (err) { - //console.log('Error', err) - expect(String(err)).to.include('FIO domain already registered') - } - }) -}) - + */ \ No newline at end of file diff --git a/tests/producer-fee-setting.js b/tests/producer-fee-setting.js index 852a9f7b..3bac3107 100644 --- a/tests/producer-fee-setting.js +++ b/tests/producer-fee-setting.js @@ -797,7 +797,7 @@ describe('C. Test invalid multipliers and ratios (using producer #20)', () => { } }) - it.skip(`Bug: .Set fee ratio to negative number gives error: ${config.error.invalidRatioFeeError}`, async () => { + it.skip(`BUG: .Set fee ratio to negative number gives error: ${config.error.invalidRatioFeeError}`, async () => { try { let endpoint = 'register_fio_domain' let value = -400 diff --git a/tests/record-obt-data.js b/tests/record-obt-data.js index a4c05e8a..3b80a009 100644 --- a/tests/record-obt-data.js +++ b/tests/record-obt-data.js @@ -433,3 +433,156 @@ describe(`B. OBT Data Error Check`, () => { }) }) +describe.skip(`BUG-2305 C. Test get_obt_data`, () => { + + let userA1, userA2, timeStamp + const payment = 5000000000 // 5 FIO + const obtMemo = 'Memo in OBT payment' + + it(`Create users`, async () => { + userA1 = await newUser(faucet); + userA2 = await newUser(faucet); + }) + + it(`get_obt_data for userA1 (payer) when no records exist. limit = '', offset = ''. Expect: ${config.error.noFioRequests}`, async () => { + try { + const result = await userA1.sdk.genericAction('getObtData', { + limit: '', + offset: '' + }) + console.log('result: ', result); + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err.json) + expect(err.json.message).to.equal(config.error.noFioRequests) + } + }) + + it(`get_obt_data for userA1 (payer) when no records exist. limit = 0, offset = 100. Expect: ${config.error.noFioRequests}`, async () => { + try { + const result = await userA1.sdk.genericAction('getObtData', { + limit: 0, + offset: 100 + }) + console.log('result: ', result); + expect(result).to.equal(null) + } catch (err) { + //console.log('Error: ', err.json) + expect(err.json.message).to.equal(config.error.noFioRequests) + } + }) + + it(`get_obt_data for userA1 (payer) when no records exist. limit = -1, offset = 0. Expect: ${config.error.invalidLimit}`, async () => { + try { + const result = await userA1.sdk.genericAction('getObtData', { + limit: -1, + offset: 0 + }) + console.log('result: ', result); + //console.log('content: ', result.obt_data_records[0].content); + expect(result.obt_data_records.length).to.equal(2); + } catch (err) { + //console.log('Error: ', err.json) + expect(err.json.fields[0].error).to.equal(config.error.invalidLimit) + } + }) + + it(`userA1 sends recordObtData to userA2`, async () => { + try { + const result = await userA1.sdk.genericAction('recordObtData', { + payerFioAddress: userA1.address, + payeeFioAddress: userA2.address, + payerTokenPublicAddress: userA1.publicKey, + payeeTokenPublicAddress: userA2.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: userA2.publicKey, + memo: obtMemo, + }) + //console.log('Result: ', result) + timeStamp = result.time_stamp + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`userA1 sends second recordObtData to userA2`, async () => { + try { + const result = await userA1.sdk.genericAction('recordObtData', { + payerFioAddress: userA1.address, + payeeFioAddress: userA2.address, + payerTokenPublicAddress: userA1.publicKey, + payeeTokenPublicAddress: userA2.publicKey, + amount: payment, + chainCode: "FIO", + tokenCode: "FIO", + status: '', + obtId: '', + maxFee: config.api.record_obt_data.fee, + technologyProviderId: '', + payeeFioPublicKey: userA2.publicKey, + memo: "second obt", + }) + //console.log('Result: ', result) + timeStamp = result.time_stamp + expect(result.status).to.equal('sent_to_blockchain') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(5000) }) + + it(`get_obt_data for userA1 (payer)`, async () => { + try { + const result = await userA1.sdk.genericAction('getObtData', { + limit: '', + offset: '' + }) + console.log('result: ', result); + //console.log('content: ', result.obt_data_records[0].content); + expect(result.obt_data_records.length).to.equal(2); + expect(result.obt_data_records[0].fio_request_id).to.equal(0); + expect(result.obt_data_records[0].payer_fio_address).to.equal(userA1.address); + expect(result.obt_data_records[0].payee_fio_address).to.equal(userA2.address); + expect(result.obt_data_records[0].payer_fio_public_key).to.equal(userA1.publicKey); + expect(result.obt_data_records[0].payee_fio_public_key).to.equal(userA2.publicKey); + expect(result.obt_data_records[0].status).to.equal('sent_to_blockchain'); + expect(result.obt_data_records[0].content.memo).to.equal(obtMemo); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`get_obt_data for userA2 (payee)`, async () => { + try { + const result = await userA2.sdk.genericAction('getObtData', { + limit: '', + offset: '' + }) + console.log('result: ', result); + //console.log('content: ', result.obt_data_records[0].content); + expect(result.obt_data_records.length).to.equal(2); + expect(result.obt_data_records[0].fio_request_id).to.equal(0); + expect(result.obt_data_records[0].payer_fio_address).to.equal(userA1.address); + expect(result.obt_data_records[0].payee_fio_address).to.equal(userA2.address); + expect(result.obt_data_records[0].payer_fio_public_key).to.equal(userA1.publicKey); + expect(result.obt_data_records[0].payee_fio_public_key).to.equal(userA2.publicKey); + expect(result.obt_data_records[0].status).to.equal('sent_to_blockchain'); + expect(result.obt_data_records[0].content.memo).to.equal(obtMemo); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + +}) \ No newline at end of file diff --git a/tests/vote.js b/tests/vote.js index c0bcc669..a97caf8d 100644 --- a/tests/vote.js +++ b/tests/vote.js @@ -846,7 +846,7 @@ describe('C. Test proxying to a user who is also proxying (should fail)', () => }) -describe('D. last_voting_weight not updated when paying fee for register/unregister proxy (fixed bug MAS-1539)', () => { +describe('D. last_voting_weight not updated when paying fee for register/unregister proxy (fixed MAS-1539)', () => { let proxyF1, voterF1, original_last_vote_weight it(`Create users`, async () => { From b888f1de0900d3ede417f2fad7d37b3800ca6ac7 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Tue, 23 Feb 2021 09:06:33 -0700 Subject: [PATCH 56/76] clio fix to tests --- tests/clio.js | 64 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/tests/clio.js b/tests/clio.js index bb6bbefa..775baffd 100644 --- a/tests/clio.js +++ b/tests/clio.js @@ -901,16 +901,64 @@ describe(`F. Transfer`, () => { }) describe(`H. clio error testing`, () => { - let user1, user2, fio_request_id - const fundsAmount = 10000000000 + let user1, user2, fio_request_id + const fundsAmount = 10000000000 + let content - it(`Create users and import private keys`, async () => { - user1 = await newUser(faucet); - result = await runClio('wallet import -n fio --private-key ' + user1.privateKey); + const contentFields = { + payee_public_address: 'btc:thisispayeetokenpublicaddress', + amount: 500000, + chain_code: 'BTC', + token_code: 'BTC', + memo: 'request Memo One' + } - user2 = await newUser(faucet); - result = await runClio('wallet import -n fio --private-key ' + user2.privateKey); - }) + it(`Create users and import private keys`, async () => { + user1 = await newUser(faucet); + result = await runClio('wallet import -n fio --private-key ' + user1.privateKey); + + user2 = await newUser(faucet); + result = await runClio('wallet import -n fio --private-key ' + user2.privateKey); + }) + + + it(`SDK: user1 requests funds from user2`, async () => { + try { + const result = await user1.sdk.genericAction('requestFunds', { + payerFioAddress: user2.address, + payeeFioAddress: user1.address, + payeeTokenPublicAddress: contentFields.payee_public_address, + amount: contentFields.payee_public_address, + chainCode: contentFields.chain_code, + tokenCode: contentFields.token_code, + memo: contentFields.memo, + maxFee: config.maxFee, + payerFioPublicKey: user2.publicKey, + technologyProviderId: '', + }) + //console.log('Result: ', result) + expect(result.status).to.equal('requested') + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + }) + + it(`Wait a few seconds.`, async () => { await timeout(2000) }) + + it('(api) Call get_sent_fio_requests to get content field', async () => { + try { + const result = await callFioApi("get_sent_fio_requests", { + fio_public_key: user1.publicKey, + limit: 10, + offset: 0 + }) + //console.log('Result', result) + content = result.requests[0].content + } catch (err) { + console.log('Error', err) + } + }) it(`clio: request new (user1 requests funds from user2)`, async () => { try { From c17266d59a5d543b3ebc78d4bfe090b766a03baa Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Tue, 23 Feb 2021 16:00:37 -0700 Subject: [PATCH 57/76] Cleanup for bahamas and migr testing --- tests/bravo-migr-test.js | 9 +++------ tests/record-obt-data.js | 8 ++++---- tests/transfer-locked-tokens-account-tests.js | 10 +++++----- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index 4e4b3cef..a1848fef 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -2152,8 +2152,7 @@ describe.skip(`Release delta (develop - migr2) - remove data from old tables (fi fioreqctxts = await callFioApi("get_table_rows", json); fioreqctxtsIsFinished = (fioreqctxts.rows.length == 0); //console.log('fioreqctxts: ', fioreqctxts) - console.log('Table rows count: ', fioreqctxts.rows.length) - console.log('isFinished: ', isFinished); + console.log('\nfioreqctxts table rows count: ', fioreqctxts.rows.length) } catch (err) { console.log('Error', err); expect(err).to.equal(null); @@ -2171,8 +2170,7 @@ describe.skip(`Release delta (develop - migr2) - remove data from old tables (fi recordobts = await callFioApi("get_table_rows", json); recordobtsIsFinished = (recordobts.rows.length == 0); //console.log('recordobts: ', recordobts) - console.log('Table rows count: ', recordobts.rows.length) - console.log('isFinished: ', isFinished); + console.log('recordobts table rows count: ', recordobts.rows.length) } catch (err) { console.log('Error', err); expect(err).to.equal(null); @@ -2190,8 +2188,7 @@ describe.skip(`Release delta (develop - migr2) - remove data from old tables (fi fioreqstss = await callFioApi("get_table_rows", json); fioreqstssIsFinished = (fioreqstss.rows.length == 0); //console.log('fioreqstss: ', fioreqstss) - console.log('Table rows count: ', fioreqstss.rows.length) - console.log('isFinished: ', isFinished); + console.log('fioreqstss table rows count: ', fioreqstss.rows.length) } catch (err) { console.log('Error', err); expect(err).to.equal(null); diff --git a/tests/record-obt-data.js b/tests/record-obt-data.js index 3b80a009..e3e15bde 100644 --- a/tests/record-obt-data.js +++ b/tests/record-obt-data.js @@ -433,7 +433,7 @@ describe(`B. OBT Data Error Check`, () => { }) }) -describe.skip(`BUG-2305 C. Test get_obt_data`, () => { +describe(`C. Test get_obt_data`, () => { let userA1, userA2, timeStamp const payment = 5000000000 // 5 FIO @@ -547,7 +547,7 @@ describe.skip(`BUG-2305 C. Test get_obt_data`, () => { limit: '', offset: '' }) - console.log('result: ', result); + //console.log('result: ', result); //console.log('content: ', result.obt_data_records[0].content); expect(result.obt_data_records.length).to.equal(2); expect(result.obt_data_records[0].fio_request_id).to.equal(0); @@ -563,13 +563,13 @@ describe.skip(`BUG-2305 C. Test get_obt_data`, () => { } }) - it(`get_obt_data for userA2 (payee)`, async () => { + it(`get_obt_data for userA2 (payee) (BD-2305)`, async () => { try { const result = await userA2.sdk.genericAction('getObtData', { limit: '', offset: '' }) - console.log('result: ', result); + //console.log('result: ', result); //console.log('content: ', result.obt_data_records[0].content); expect(result.obt_data_records.length).to.equal(2); expect(result.obt_data_records[0].fio_request_id).to.equal(0); diff --git a/tests/transfer-locked-tokens-account-tests.js b/tests/transfer-locked-tokens-account-tests.js index fe11db40..250b66ae 100644 --- a/tests/transfer-locked-tokens-account-tests.js +++ b/tests/transfer-locked-tokens-account-tests.js @@ -1188,16 +1188,16 @@ describe('G. Record obt data, check getObtData', () => { expect(obtData.payee_fio_address).to.equal(testFioAddressName2) }) - it.skip(`BUG BD-2305 (not all results getting returned) Payee getObtData`, async () => { + it(`Payee getObtData`, async () => { const result = await fioSdk2.genericAction('getObtData', { tokenCode: fioTokenCode }) - console.log('result: ', result) + //console.log('result: ', result) expect(result).to.have.all.keys('obt_data_records', 'more') expect(result.obt_data_records).to.be.a('array') expect(result.more).to.be.a('number') const obtData = result.obt_data_records.find(pr => pr.content.obt_id === obtId) - console.log('obt_data_records[0]: ', result.obt_data_records[0]) - console.log('obtId: ', obtId) - console.log('obtData: ', obtData) + //console.log('obt_data_records[0]: ', result.obt_data_records[0]) + //console.log('obtId: ', obtId) + //console.log('obtData: ', obtData) expect(obtData).to.have.all.keys('fio_request_id', 'payer_fio_address', 'payee_fio_address', 'payee_fio_public_key', 'payer_fio_public_key', 'status', 'time_stamp', 'content') expect(obtData.content.obt_id).to.be.a('string') expect(obtData.content.obt_id).to.equal(obtId) From 2dfd94161dc0835a2820a1d7b69cf8d409c3e218 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Wed, 24 Feb 2021 14:13:45 -0700 Subject: [PATCH 58/76] Update history tests --- config.js | 4 +- index.js | 7 +-- tests/history.js | 137 +++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 126 insertions(+), 22 deletions(-) diff --git a/config.js b/config.js index 9e9a5a85..c8dfed76 100644 --- a/config.js +++ b/config.js @@ -1,9 +1,9 @@ -const TESTURL = 'http://localhost:8889' // Localhost +//const TESTURL = 'http://localhost:8889' // Localhost //const TESTURL = 'http://dev1.fio.dev:8888' // DEV1 //const TESTURL = 'http://44.238.153.162:8889' // Devnet //const TESTURL = 'http://testnet.fioprotocol.io' // Testnet //const TESTURL = 'https://fio.greymass.com' // Mainnet - +const TESTURL = 'http://34.222.201.72:8889' // History const DEVTOOLSDIR = '../fio.devtools' diff --git a/index.js b/index.js index 6f754b8a..8b861ced 100644 --- a/index.js +++ b/index.js @@ -2,10 +2,11 @@ require('mocha') const {expect} = require('chai') describe('TEST SUITE', () => { - + require('./tests/history.js'); // Only run against history node. + /* require('./tests/bravo-migr-test.js'); //This is required when testing 2.3.0 (bravo) with fio bahamas (need to do the full table migration). - //require('./tests/history.js'); // Only run against history node. + // require('./tests/addaddress.js'); // v1.0.x Also includes FIP-13 tests. require('./tests/fees.js'); // v1.0.x require('./tests/fio-request.js'); // v1.0.x @@ -34,5 +35,5 @@ describe('TEST SUITE', () => { //require('./tests/performance-request-obt.js'); require('./tests/testnet-smoketest.js'); // Testnet smoketest. By default runs against local build. - + */ }); diff --git a/tests/history.js b/tests/history.js index 0ff6d4bf..4ee26e07 100644 --- a/tests/history.js +++ b/tests/history.js @@ -4,12 +4,14 @@ require('mocha') const {expect} = require('chai') -const {callFioHistoryApi, existingUser, newUser, generateFioDomain, generateFioAddress, createKeypair, fetchJson} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/fiosdk') +const {callFioHistoryApi, callFioApi, callFioApiSigned, unlockWallet, runClio, newUser, existingUser, generateFioDomain, generateFioAddress, createKeypair, fetchJson} = require('../utils.js'); +const {FIOSDK } = require('@fioprotocol/fiosdk'); config = require('../config.js'); before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson) + + //const result = await unlockWallet('fio'); }) describe('************************** history.js ************************** \n A. get_transfers to existing account', () => { @@ -62,28 +64,28 @@ describe('************************** history.js ************************** \n A. }) -describe('B. get_transfers to non-existent account', () => { +describe.only('B. get_transfers to non-existent account', () => { - let userB1, userB2 + let user1, user2 let transferAmount = 33000000000 it(`Create users`, async () => { let keys = await createKeypair(); - userB1 = new FIOSDK(keys.privateKey, keys.publicKey, config.BASE_URL, fetchJson) - userB1.domain = generateFioDomain(8) - userB1.address = generateFioAddress(userB1.domain, 8) + user1 = new FIOSDK(keys.privateKey, keys.publicKey, config.BASE_URL, fetchJson) + user1.domain = generateFioDomain(8) + user1.address = generateFioAddress(user1.domain, 8) - console.log('userB1 Account: ', userB1.account) - console.log('userB1 Public: ', userB1.publicKey) - console.log('userB1 Private: ', userB1.privateKey) + console.log('userB1 Account: ', user1.account) + console.log('userB1 Public: ', user1.publicKey) + console.log('userB1 Private: ', user1.privateKey) - userB2 = await newUser(faucet); + user2 = await newUser(faucet); }) - it(`Transfer 2000000000000 sufs to non-existent account userB1`, async () => { + it(`Transfer 2000000000000 sufs to non-existent account user1`, async () => { try { const result = await faucet.genericAction('transferTokens', { - payeeFioPublicKey: userB1.publicKey, + payeeFioPublicKey: user1.publicKey, amount: 2000000000000, maxFee: config.api.transfer_tokens_pub_key.fee, walletFioAddress: '' @@ -99,12 +101,12 @@ describe('B. get_transfers to non-existent account', () => { it('Confirm single, initial trnsfiopubky transfer', async () => { try { const json = { - "fio_public_key": userB1.publicKey, + "fio_public_key": user1.publicKey, "pos": 0, "offset": 100 } result = await callFioHistoryApi("get_transfers", json); - //console.log('Result: ', result) + console.log('Result: ', result) expect(result.transfers.length).to.equal(1); // Should have the initial transfer as a result. expect(result.transfers[0].action).to.equal('trnsfiopubky'); } catch (err) { @@ -112,7 +114,7 @@ describe('B. get_transfers to non-existent account', () => { expect(err).to.equal(null); } }) - +/* it(`Send ${transferAmount} sufs from userB1 to userB2`, async () => { try { const result = await userB1.genericAction('transferTokens', { @@ -209,7 +211,108 @@ describe('B. get_transfers to non-existent account', () => { expect(err).to.equal(null); } }) - +*/ }) +describe('C. updateauth using key with no associated account', () => { + let userMain, userAuth1, userAuth2 + + it(`Create users and import private keys`, async () => { + userMain = await newUser(faucet); + user1 = await newUser(faucet); + + //User with no existing account + keys2 = await createKeypair(); + + //user2 = await existingUser(account2, keys2.privateKey, keys2.publicKey, '', ''); + user2 = new FIOSDK(keys2.privateKey, keys2.publicKey, config.BASE_URL, fetchJson) + user2.account = FIOSDK.accountHash(user2.publicKey).accountnm; + //user2 = await newUser(faucet); + console.log('user2: ', user2.account) + + //Alphabetical sort by account name for updateauth + if (user1.account < user2.account) { + userAuth1 = user1; + userAuth2 = user2; + } else { + userAuth1 = user2; + userAuth2 = user1; + } + console.log('userAuth1: ', userAuth1.account) + console.log('userAuth2: ', userAuth2.account) + + }) + + it(`Show permissions userMain`, async () => { + try { + const json = { + "account_name": userMain.account + } + result = await callFioApi("get_account", json); + console.log('Result.permissions: ', result.permissions); + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + // Reminder that the accounts under auth need to be in alphabetical order + it(`Updateauth for userMain: threshold = 2, account1 = userAuth1, account2 = userAuth2`, async () => { + try { + const result = await callFioApiSigned('push_transaction', { + action: 'updateauth', + account: 'eosio', + actor: userMain.account, + privKey: userMain.privateKey, + data: { + "account": userMain.account, + "permission": "active", + "parent": "owner", + "auth": { + "threshold": 2, + "keys": [], + "waits": [], + "accounts": [ + { + "permission": { + "actor": userAuth1.account, + "permission": "active" + }, + "weight":1 + }, + { + "permission": { + "actor": userAuth2.account, + "permission": "active" + }, + "weight":1 + } + ] + }, + "max_fee": config.maxFee + } + }) + //console.log('Result: ', result) + //console.log('Result: ', result.error.details) + expect(result.processed.receipt.status).to.equal('executed'); + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Show permissions userMain`, async () => { + try { + const json = { + "account_name": userMain.account + } + result = await callFioApi("get_account", json); + console.log('Result.permissions: ', result.permissions[0].required_auth); + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + +}) \ No newline at end of file From 70f5b481060cdb5c267abac85154bc44f66311f9 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Thu, 25 Feb 2021 11:16:56 -0700 Subject: [PATCH 59/76] Initial action count tests --- config.js | 2 +- index.js | 7 +- tests/history.js | 194 ++++++++++++----------------------------------- 3 files changed, 53 insertions(+), 150 deletions(-) diff --git a/config.js b/config.js index c8dfed76..1c41d381 100644 --- a/config.js +++ b/config.js @@ -3,7 +3,7 @@ //const TESTURL = 'http://44.238.153.162:8889' // Devnet //const TESTURL = 'http://testnet.fioprotocol.io' // Testnet //const TESTURL = 'https://fio.greymass.com' // Mainnet -const TESTURL = 'http://34.222.201.72:8889' // History +const TESTURL = 'http://34.222.201.72:8080' // History const DEVTOOLSDIR = '../fio.devtools' diff --git a/index.js b/index.js index 8b861ced..6f754b8a 100644 --- a/index.js +++ b/index.js @@ -2,11 +2,10 @@ require('mocha') const {expect} = require('chai') describe('TEST SUITE', () => { - require('./tests/history.js'); // Only run against history node. - /* + require('./tests/bravo-migr-test.js'); //This is required when testing 2.3.0 (bravo) with fio bahamas (need to do the full table migration). - // + //require('./tests/history.js'); // Only run against history node. require('./tests/addaddress.js'); // v1.0.x Also includes FIP-13 tests. require('./tests/fees.js'); // v1.0.x require('./tests/fio-request.js'); // v1.0.x @@ -35,5 +34,5 @@ describe('TEST SUITE', () => { //require('./tests/performance-request-obt.js'); require('./tests/testnet-smoketest.js'); // Testnet smoketest. By default runs against local build. - */ + }); diff --git a/tests/history.js b/tests/history.js index 4ee26e07..b74ee276 100644 --- a/tests/history.js +++ b/tests/history.js @@ -14,25 +14,33 @@ before(async () => { //const result = await unlockWallet('fio'); }) -describe('************************** history.js ************************** \n A. get_transfers to existing account', () => { - let userA1, userA2 +describe('************************** history.js ************************** \n A. get_actions after transfer to existing account', () => { + let user1, actionCount it(`Create users`, async () => { - userA1 = await newUser(faucet); + user1 = await newUser(faucet); - console.log('userA1 Account: ', userA1.account) - console.log('userA1 Public: ', userA1.publicKey) - console.log('userA1 Private: ', userA1.privateKey) - console.log('userA1 Private: ', userA1.domain) - console.log('userA1 Private: ', userA1.address) + //console.log('user1 Account: ', user1.account) + //console.log('user1 Public: ', user1.publicKey) + //console.log('user1 Private: ', user1.privateKey) + }) + + it(`get_actions for user1`, async () => { + const json = { + "account_name": user1.account + } + result = await callFioHistoryApi("get_actions", json); + //console.log('Result: ', result) + actionCount = result.actions.length + expect(actionCount).to.equal(7) // All of the setup actions for the account }) it(`Transfer tokens to existing account userA1`, async () => { try { const result = await faucet.genericAction('transferTokens', { - payeeFioPublicKey: userA1.publicKey, + payeeFioPublicKey: user1.publicKey, amount: 123, - maxFee: config.api.transfer_tokens_pub_key.fee, + maxFee: config.maxFee, walletFioAddress: '' }) //console.log('Result: ', result) @@ -43,84 +51,51 @@ describe('************************** history.js ************************** \n A. } }) - it(`get_transfers all`, async () => { + it(`get_actions for user1. Expect 3 additional actions`, async () => { + let prevActionCount = actionCount; const json = { - "fio_public_key": userA1.publicKey + "account_name": user1.account } - result = await callFioHistoryApi("get_transfers", json); + result = await callFioHistoryApi("get_actions", json); //console.log('Result: ', result) - expect(result.transfers.length).to.be.greaterThan(0) + actionCount = result.actions.length + expect(actionCount).to.equal(prevActionCount + 3) // Transfer to user1, fee, and foundation }) - it(`get_transfers pos 1 offset 2`, async () => { - const json = { - "fio_public_key": userA1.publicKey, - "pos": -1, - "offset": -10 - } - result = await callFioHistoryApi("get_transfers", json); - //console.log('Result: ', result.transfers) - }) }) -describe.only('B. get_transfers to non-existent account', () => { +describe('B. get_transfers to non-existent account', () => { - let user1, user2 + let user1, actionCount let transferAmount = 33000000000 it(`Create users`, async () => { let keys = await createKeypair(); user1 = new FIOSDK(keys.privateKey, keys.publicKey, config.BASE_URL, fetchJson) - user1.domain = generateFioDomain(8) - user1.address = generateFioAddress(user1.domain, 8) - - console.log('userB1 Account: ', user1.account) - console.log('userB1 Public: ', user1.publicKey) - console.log('userB1 Private: ', user1.privateKey) + user1.account = FIOSDK.accountHash(user1.publicKey).accountnm; - user2 = await newUser(faucet); + //console.log('user1 Account: ', user1.account) + //console.log('user1 Public: ', user1.publicKey) + //console.log('user1 Private: ', user1.privateKey) }) - it(`Transfer 2000000000000 sufs to non-existent account user1`, async () => { - try { - const result = await faucet.genericAction('transferTokens', { - payeeFioPublicKey: user1.publicKey, - amount: 2000000000000, - maxFee: config.api.transfer_tokens_pub_key.fee, - walletFioAddress: '' - }) - //console.log('Result: ', result) - expect(result).to.have.all.keys('transaction_id', 'block_num', 'status', 'fee_collected') - } catch (err) { - console.log('Error: ', err); - expect(err).to.equal(null); + it(`get_actions for user1. Expect empty array.`, async () => { + const json = { + "account_name": user1.account } + result = await callFioHistoryApi("get_actions", json); + //console.log('Result: ', result) + actionCount = result.actions.length + expect(actionCount).to.equal(0) }) - it('Confirm single, initial trnsfiopubky transfer', async () => { - try { - const json = { - "fio_public_key": user1.publicKey, - "pos": 0, - "offset": 100 - } - result = await callFioHistoryApi("get_transfers", json); - console.log('Result: ', result) - expect(result.transfers.length).to.equal(1); // Should have the initial transfer as a result. - expect(result.transfers[0].action).to.equal('trnsfiopubky'); - } catch (err) { - console.log('Error: ', err); - expect(err).to.equal(null); - } - }) -/* - it(`Send ${transferAmount} sufs from userB1 to userB2`, async () => { + it(`Transfer tokens to non-existant account user1`, async () => { try { - const result = await userB1.genericAction('transferTokens', { - payeeFioPublicKey: userB2.publicKey, + const result = await faucet.genericAction('transferTokens', { + payeeFioPublicKey: user1.publicKey, amount: transferAmount, - maxFee: config.api.transfer_tokens_pub_key.fee, + maxFee: config.maxFee, walletFioAddress: '' }) //console.log('Result: ', result) @@ -131,91 +106,20 @@ describe.only('B. get_transfers to non-existent account', () => { } }) - it(`Confirm there are three transfers (one for transfer and one for fee) and the second is transfer with transfer_amount= ${transferAmount}`, async () => { - try { - const json = { - "fio_public_key": userB1.publicKey, - "pos": 0, - "offset": 100 - } - result = await callFioHistoryApi("get_transfers", json); - //console.log('Result: ', result) - expect(result.transfers.length).to.equal(3); - expect(result.transfers[1].action).to.equal('trnsfiopubky'); - expect(result.transfers[1].transfer_amount).to.equal(transferAmount); - expect(result.transfers[2].action).to.equal('transfer'); - expect(result.transfers[2].fee_amount).to.equal(2000000000); - } catch (err) { - console.log('Error: ', err); - expect(err).to.equal(null); - } - }) - - it('userB1 registerFioDomain', async () => { - try { - const result = await userB1.genericAction('registerFioDomain', { - fioDomain: userB1.domain, - maxFee: config.api.register_fio_domain.fee, - walletFioAddress: '' - }) - //console.log('Result', result) - expect(result).to.have.all.keys('status', 'expiration', 'fee_collected') - } catch (err) { - console.log('Error: ', err.json); - expect(err).to.equal(null); - } - }) - - it(`Confirm there are four transfers and the fourth is transfer is a ${config.api.register_fio_domain.fee} fee for domain registration`, async () => { - try { - const json = { - "fio_public_key": userB1.publicKey, - "pos": 0, - "offset": 100 - } - result = await callFioHistoryApi("get_transfers", json); - //console.log('Result: ', result) - expect(result.transfers.length).to.equal(4); - expect(result.transfers[3].action).to.equal('transfer'); - expect(result.transfers[3].fee_amount).to.equal(config.api.register_fio_domain.fee); - } catch (err) { - console.log('Error: ', err); - expect(err).to.equal(null); + it(`get_actions for user1. Expect 3 additional actions`, async () => { + let prevActionCount = actionCount; + const json = { + "account_name": user1.account } - }) - - it('userB1 registerFioAddress', async () => { - const result = await userB1.genericAction('registerFioAddress', { - fioAddress: userB1.address, - maxFee: config.api.register_fio_address.fee, - walletFioAddress: '' - }) + result = await callFioHistoryApi("get_actions", json); //console.log('Result: ', result) - expect(result.status).to.equal('OK') - }) - - it(`Confirm there are five transfers and the fifth is a ${config.api.register_fio_address.fee} fee for address registration`, async () => { - try { - const json = { - "fio_public_key": userB1.publicKey, - "pos": 0, - "offset": 100 - } - result = await callFioHistoryApi("get_transfers", json); - //console.log('Result: ', result) - expect(result.transfers.length).to.equal(5); - expect(result.transfers[4].action).to.equal('transfer'); - expect(result.transfers[4].fee_amount).to.equal(config.api.register_fio_address.fee); - } catch (err) { - console.log('Error: ', err); - expect(err).to.equal(null); - } + actionCount = result.actions.length + expect(actionCount).to.equal(prevActionCount + 3) // Transfer to user1, fee, and foundation }) -*/ }) -describe('C. updateauth using key with no associated account', () => { +describe.skip('Need to complete. C. updateauth using key with no associated account', () => { let userMain, userAuth1, userAuth2 it(`Create users and import private keys`, async () => { From 2b3f58d99c5108db08e3b05ef0e21c8e65e6ceca Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Thu, 25 Feb 2021 11:18:57 -0700 Subject: [PATCH 60/76] config fix --- config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.js b/config.js index 1c41d381..7fc58613 100644 --- a/config.js +++ b/config.js @@ -1,9 +1,9 @@ -//const TESTURL = 'http://localhost:8889' // Localhost +const TESTURL = 'http://localhost:8889' // Localhost //const TESTURL = 'http://dev1.fio.dev:8888' // DEV1 //const TESTURL = 'http://44.238.153.162:8889' // Devnet //const TESTURL = 'http://testnet.fioprotocol.io' // Testnet //const TESTURL = 'https://fio.greymass.com' // Mainnet -const TESTURL = 'http://34.222.201.72:8080' // History +//const TESTURL = 'http://34.222.201.72:8080' // History const DEVTOOLSDIR = '../fio.devtools' From d82140874850a4274fb1a72fa243a0ff04cc77ba Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Thu, 4 Mar 2021 09:18:50 -0700 Subject: [PATCH 61/76] get_pub_addresses bug --- tests/addaddress.js | 83 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/tests/addaddress.js b/tests/addaddress.js index a31d9ea7..7fdc26ed 100644 --- a/tests/addaddress.js +++ b/tests/addaddress.js @@ -39,7 +39,7 @@ describe(`************************** addaddress.js ************************** \n expect(result.status).to.equal('OK') } catch (err) { console.log('Error', err) - //expect(err).to.equal(null) + expect(err).to.equal(null) } }) @@ -71,6 +71,7 @@ describe(`************************** addaddress.js ************************** \n expect(result.public_address).to.equal('bitcoincash:qzf8zha74ahdh9j0xnwlffdn0zuyaslx3c90q7n9g9') } catch (err) { console.log('Error', err) + expect(err).to.equal(null); } }) @@ -133,6 +134,7 @@ describe(`************************** addaddress.js ************************** \n } catch (err) { console.log('Error', err) expect(err).to.equal(null) + expect(err).to.equal(null); } }) @@ -174,6 +176,7 @@ describe(`B. Add the same address twice`, () => { expect(result.public_address).to.equal('bitcoincash:qzf8zha74ahdh9j0xnwlffdn0zuyaslx3c90q7n9g9') } catch (err) { console.log('Error', err) + expect(err).to.equal(null); } }) @@ -195,6 +198,7 @@ describe(`B. Add the same address twice`, () => { expect(result.status).to.equal('OK') } catch (err) { console.log('Error', err) + expect(err).to.equal(null); } }) @@ -209,6 +213,7 @@ describe(`B. Add the same address twice`, () => { expect(result.public_address).to.equal('bitcoincash:qzf8zha74adsfasdf0xnwlffdn0zuyaslx3c90q7n9g9') } catch (err) { console.log('Error', err) + expect(err).to.equal(null); } }) @@ -276,6 +281,81 @@ describe(`C. FIP-13. Get_pub_addresses endpoint`, () => { expect(result.more).to.equal(false); } catch (err) { console.log('Error', err) + expect(err).to.equal(null); + } + }) + + it.skip('(BUG BD-2382)(api) Get all public addresses for userA3 FIO Address (get_pub_addresses) with no limit/offset.', async () => { + try { + const result = await callFioApi("get_pub_addresses", { + fio_address: userA3.address + }) + // console.log('Result', result) + expect(result.public_addresses.length).to.equal(4) + expect(result.public_addresses[0].token_code).to.equal("FIO"); + expect(result.public_addresses[1].public_address).to.equal("bitcoincash:qzf8zha74ahdh9j0xnwlffdn0zuyaslx3c90q7n9g9"); + expect(result.public_addresses[1].token_code).to.equal("BCH"); + expect(result.public_addresses[1].chain_code).to.equal("BCH"); + expect(result.public_addresses[2].public_address).to.equal("XyCyPKzTWvW2XdcYjPaPXGQDCGk946ywEv"); + expect(result.public_addresses[2].token_code).to.equal("DASH"); + expect(result.public_addresses[2].chain_code).to.equal("DASH"); + expect(result.public_addresses[3].public_address).to.equal("EQH6o4xfaR5fbhV8cDbDGRxwJRJn3qeo41"); + expect(result.public_addresses[3].token_code).to.equal("ELA"); + expect(result.public_addresses[3].chain_code).to.equal("ELA"); + expect(result.more).to.equal(false); + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null); + } + }) + + it.skip('(BUG BD-2382)(api) Get all public addresses for userA3 FIO Address (get_pub_addresses) with no offset.', async () => { + try { + const result = await callFioApi("get_pub_addresses", { + fio_address: userA3.address, + limit: 10 + }) + // console.log('Result', result) + expect(result.public_addresses.length).to.equal(4) + expect(result.public_addresses[0].token_code).to.equal("FIO"); + expect(result.public_addresses[1].public_address).to.equal("bitcoincash:qzf8zha74ahdh9j0xnwlffdn0zuyaslx3c90q7n9g9"); + expect(result.public_addresses[1].token_code).to.equal("BCH"); + expect(result.public_addresses[1].chain_code).to.equal("BCH"); + expect(result.public_addresses[2].public_address).to.equal("XyCyPKzTWvW2XdcYjPaPXGQDCGk946ywEv"); + expect(result.public_addresses[2].token_code).to.equal("DASH"); + expect(result.public_addresses[2].chain_code).to.equal("DASH"); + expect(result.public_addresses[3].public_address).to.equal("EQH6o4xfaR5fbhV8cDbDGRxwJRJn3qeo41"); + expect(result.public_addresses[3].token_code).to.equal("ELA"); + expect(result.public_addresses[3].chain_code).to.equal("ELA"); + expect(result.more).to.equal(false); + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null); + } + }) + + it('(api) Get all public addresses for userA3 FIO Address (get_pub_addresses) with no limit', async () => { + try { + const result = await callFioApi("get_pub_addresses", { + fio_address: userA3.address, + offset: 0 + }) + // console.log('Result', result) + expect(result.public_addresses.length).to.equal(4) + expect(result.public_addresses[0].token_code).to.equal("FIO"); + expect(result.public_addresses[1].public_address).to.equal("bitcoincash:qzf8zha74ahdh9j0xnwlffdn0zuyaslx3c90q7n9g9"); + expect(result.public_addresses[1].token_code).to.equal("BCH"); + expect(result.public_addresses[1].chain_code).to.equal("BCH"); + expect(result.public_addresses[2].public_address).to.equal("XyCyPKzTWvW2XdcYjPaPXGQDCGk946ywEv"); + expect(result.public_addresses[2].token_code).to.equal("DASH"); + expect(result.public_addresses[2].chain_code).to.equal("DASH"); + expect(result.public_addresses[3].public_address).to.equal("EQH6o4xfaR5fbhV8cDbDGRxwJRJn3qeo41"); + expect(result.public_addresses[3].token_code).to.equal("ELA"); + expect(result.public_addresses[3].chain_code).to.equal("ELA"); + expect(result.more).to.equal(false); + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null); } }) @@ -569,6 +649,7 @@ describe(`FIP18. Chain-level addressing`, () => { expect(result.public_address).to.equal(addressA) } catch (err) { console.log('Error', err) + expect(err).to.equal(null); } }) From ed4d01800421eeabef93da3f52427e370c7d4857 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Fri, 5 Mar 2021 07:59:13 -0700 Subject: [PATCH 62/76] addaddress bug fix --- tests/addaddress.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/tests/addaddress.js b/tests/addaddress.js index 7fdc26ed..7f69e7d8 100644 --- a/tests/addaddress.js +++ b/tests/addaddress.js @@ -285,7 +285,33 @@ describe(`C. FIP-13. Get_pub_addresses endpoint`, () => { } }) - it.skip('(BUG BD-2382)(api) Get all public addresses for userA3 FIO Address (get_pub_addresses) with no limit/offset.', async () => { + it('(api) Get all public addresses for userA3 FIO Address (get_pub_addresses) with no limit=0, offset=0. Should return all.', async () => { + try { + const result = await callFioApi("get_pub_addresses", { + fio_address: userA3.address, + limit: 0, + offset: 0 + }) + // console.log('Result', result) + expect(result.public_addresses.length).to.equal(4) + expect(result.public_addresses[0].token_code).to.equal("FIO"); + expect(result.public_addresses[1].public_address).to.equal("bitcoincash:qzf8zha74ahdh9j0xnwlffdn0zuyaslx3c90q7n9g9"); + expect(result.public_addresses[1].token_code).to.equal("BCH"); + expect(result.public_addresses[1].chain_code).to.equal("BCH"); + expect(result.public_addresses[2].public_address).to.equal("XyCyPKzTWvW2XdcYjPaPXGQDCGk946ywEv"); + expect(result.public_addresses[2].token_code).to.equal("DASH"); + expect(result.public_addresses[2].chain_code).to.equal("DASH"); + expect(result.public_addresses[3].public_address).to.equal("EQH6o4xfaR5fbhV8cDbDGRxwJRJn3qeo41"); + expect(result.public_addresses[3].token_code).to.equal("ELA"); + expect(result.public_addresses[3].chain_code).to.equal("ELA"); + expect(result.more).to.equal(false); + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null); + } + }) + + it('(api) Get all public addresses for userA3 FIO Address (get_pub_addresses) with no limit/offset. (BD-2382)', async () => { try { const result = await callFioApi("get_pub_addresses", { fio_address: userA3.address @@ -309,7 +335,7 @@ describe(`C. FIP-13. Get_pub_addresses endpoint`, () => { } }) - it.skip('(BUG BD-2382)(api) Get all public addresses for userA3 FIO Address (get_pub_addresses) with no offset.', async () => { + it('(api) Get all public addresses for userA3 FIO Address (get_pub_addresses) with no offset. (BD-2382)', async () => { try { const result = await callFioApi("get_pub_addresses", { fio_address: userA3.address, From eccaf530b04c0e7a7af34388ca85c17c31f941ad Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Tue, 9 Mar 2021 15:37:02 -0700 Subject: [PATCH 63/76] Add check for bundle deduction --- tests/burn-address.js | 55 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/tests/burn-address.js b/tests/burn-address.js index f88e59eb..4bff8a4d 100644 --- a/tests/burn-address.js +++ b/tests/burn-address.js @@ -10,7 +10,7 @@ before(async () => { describe('************************** burn-address.js ************************** \n A. Test Burn FIO Address using push_transaction with burnaddress action ', () => { - let walletA1, walletA1FioNames, balance, walletA1OrigBalance, burn_fio_address_fee, feeCollected + let walletA1, walletA1FioNames, balance, prevBundleCount, walletA1OrigBalance, burn_fio_address_fee, feeCollected it(`Create users`, async () => { walletA1 = await newUser(faucet); @@ -44,6 +44,32 @@ describe('************************** burn-address.js ************************** } }) + it('Call get_table_rows from fionames to get bundles remaining for walletA1. Verify NNN bundles', async () => { + try { + const json = { + json: true, // Get the response as json + code: 'fio.address', // Contract that we target + scope: 'fio.address', // Account that owns the data + table: 'fionames', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + fionames = await callFioApi("get_table_rows", json); + //console.log('fionames: ', fionames); + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == walletA1.address) { + //console.log('bundleeligiblecountdown: ', fionames.rows[fioname].bundleeligiblecountdown); + prevBundleCount = fionames.rows[fioname].bundleeligiblecountdown; + } + } + expect(prevBundleCount).to.equal(100); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + it('Confirm burn_fio_address fee for walletA1 is zero (bundles remaining)', async () => { try { result = await walletA1.sdk.getFee('burn_fio_address', walletA1.address); @@ -78,6 +104,33 @@ describe('************************** burn-address.js ************************** } }) + it('(BUG BD-2386) Call get_table_rows from fionames to get bundles remaining for walletA1. Expect bundleCount = prevBundleCount - 1', async () => { + try { + let bundleCount; + const json = { + json: true, // Get the response as json + code: 'fio.address', // Contract that we target + scope: 'fio.address', // Account that owns the data + table: 'fionames', // Table name + limit: 1000, // Maximum number of rows that we want to get + reverse: false, // Optional: Get reversed data + show_payer: false // Optional: Show ram payer + } + fionames = await callFioApi("get_table_rows", json); + //console.log('fionames: ', fionames); + for (fioname in fionames.rows) { + if (fionames.rows[fioname].name == walletA1.address) { + //console.log('bundleCount: ', fionames.rows[fioname].bundleeligiblecountdown); + bundleCount = fionames.rows[fioname].bundleeligiblecountdown; + } + } + expect(bundleCount).to.equal(prevBundleCount - 1); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + it(`getFioNames for walletA1 and confirm it now only owns 1 address`, async () => { try { walletA1FioNames = await walletA1.sdk.genericAction('getFioNames', { From ba2fa55eb810a74452e6055864625a1b66faccf3 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Tue, 9 Mar 2021 16:55:26 -0700 Subject: [PATCH 64/76] Fix burn test --- tests/burn-address.js | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/tests/burn-address.js b/tests/burn-address.js index 4bff8a4d..f0038c08 100644 --- a/tests/burn-address.js +++ b/tests/burn-address.js @@ -104,33 +104,6 @@ describe('************************** burn-address.js ************************** } }) - it('(BUG BD-2386) Call get_table_rows from fionames to get bundles remaining for walletA1. Expect bundleCount = prevBundleCount - 1', async () => { - try { - let bundleCount; - const json = { - json: true, // Get the response as json - code: 'fio.address', // Contract that we target - scope: 'fio.address', // Account that owns the data - table: 'fionames', // Table name - limit: 1000, // Maximum number of rows that we want to get - reverse: false, // Optional: Get reversed data - show_payer: false // Optional: Show ram payer - } - fionames = await callFioApi("get_table_rows", json); - //console.log('fionames: ', fionames); - for (fioname in fionames.rows) { - if (fionames.rows[fioname].name == walletA1.address) { - //console.log('bundleCount: ', fionames.rows[fioname].bundleeligiblecountdown); - bundleCount = fionames.rows[fioname].bundleeligiblecountdown; - } - } - expect(bundleCount).to.equal(prevBundleCount - 1); - } catch (err) { - console.log('Error', err); - expect(err).to.equal(null); - } - }) - it(`getFioNames for walletA1 and confirm it now only owns 1 address`, async () => { try { walletA1FioNames = await walletA1.sdk.genericAction('getFioNames', { From ce6aef835538561398ceb43574fac3dbc0309396 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Thu, 8 Apr 2021 09:06:51 -0600 Subject: [PATCH 65/76] Fixes for delta contract release --- tests/bravo-migr-test.js | 4 ++-- tests/transfer-address.js | 29 +++++++++++++---------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index a1848fef..c65b4895 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -1103,7 +1103,7 @@ describe.skip(`NUKE Bravo: Call migrtrx until table data is nuked`, () => { }) -describe(`Release v2.3.2 - fiotrxtss (NEW table) scripts`, () => { +describe.skip(`Release v2.3.2 - fiotrxtss (NEW table) scripts`, () => { describe(`A. Load Requests and OBTs`, () => { let user1, user2, user3; @@ -2058,7 +2058,7 @@ describe(`Release v2.3.2 - fiotrxtss (NEW table) scripts`, () => { }) }) -describe.skip(`Release delta (develop - migr2) - remove data from old tables (fioreqctxts, recordobts, fioreqstss)`, () => { +describe(`(Only works in environments with both tables. Need to update contract) Release delta (develop - migr2) - remove data from old tables (fioreqctxts, recordobts, fioreqstss)`, () => { let isFinished = 0 it('Echo size of fioreqctxts table', async () => { diff --git a/tests/transfer-address.js b/tests/transfer-address.js index 991a2a86..e8016b2d 100644 --- a/tests/transfer-address.js +++ b/tests/transfer-address.js @@ -999,7 +999,7 @@ describe('E. Confirm active producers and proxy cannot transfer address', () => }) -describe('F. BRAVO ONLY: Confirm users with OBT records or Requests cannot transfer addresses', () => { +describe('F. Confirm users with OBT records or Requests CAN transfer addresses (delta release FIP-1.b part 2)', () => { let user1, user2, user3, user4, transfer_fio_address_fee @@ -1044,7 +1044,7 @@ describe('F. BRAVO ONLY: Confirm users with OBT records or Requests cannot trans it(`Wait a few seconds.`, async () => { await timeout(5000) }) - it(`Transfer user1.address to user2. Expect error 500 - assertion failure with message: Transfering a FIO address is currently disabled for some fio.addresses `, async () => { + it(`Transfer user1.address to user2. Expect success.`, async () => { try { const result = await user1.sdk.genericAction('transferFioAddress', { fioAddress: user1.address, @@ -1053,15 +1053,14 @@ describe('F. BRAVO ONLY: Confirm users with OBT records or Requests cannot trans technologyProviderId: '' }) //console.log('Result: ', result) - expect(result).to.equal(null) + expect(result.status).to.equal('OK') } catch (err) { - //console.log('Error: ', err.json.error.details) - expect(err.json.error.details[0].message).to.equal('assertion failure with message: Transfering a FIO address is currently disabled for some fio.addresses') - expect(err.errorCode).to.equal(500) + console.log('Error: ', err) + expect(err).to.equal(null) } }) - it(`Transfer user2.address to user1. Expect error 500 - assertion failure with message: Transfering a FIO address is currently disabled for some fio.addresses`, async () => { + it(`Transfer user2.address to user1. Expect success.`, async () => { try { const result = await user2.sdk.genericAction('transferFioAddress', { fioAddress: user2.address, @@ -1070,11 +1069,10 @@ describe('F. BRAVO ONLY: Confirm users with OBT records or Requests cannot trans technologyProviderId: '' }) //console.log('Result: ', result) - expect(result).to.equal(null) + expect(result.status).to.equal('OK') } catch (err) { - //console.log('Error: ', err) - expect(err.json.error.details[0].message).to.equal('assertion failure with message: Transfering a FIO address is currently disabled for some fio.addresses') - expect(err.errorCode).to.equal(500) + console.log('Error: ', err) + expect(err).to.equal(null) } }) @@ -1102,7 +1100,7 @@ describe('F. BRAVO ONLY: Confirm users with OBT records or Requests cannot trans } }) - it(`Transfer user3.address to user4. Expect error 500 - assertion failure with message: Transfering a FIO address is currently disabled for some fio.addresses`, async () => { + it(`Transfer user3.address to user4. Expect success.`, async () => { try { const result = await user3.sdk.genericAction('transferFioAddress', { fioAddress: user3.address, @@ -1111,11 +1109,10 @@ describe('F. BRAVO ONLY: Confirm users with OBT records or Requests cannot trans technologyProviderId: '' }) //console.log('Result: ', result) - expect(result).to.equal(null) + expect(result.status).to.equal('OK') } catch (err) { - //console.log('Error: ', err) - expect(err.json.error.details[0].message).to.equal('assertion failure with message: Transfering a FIO address is currently disabled for some fio.addresses') - expect(err.errorCode).to.equal(500) + console.log('Error: ', err) + expect(err).to.equal(null) } }) From b3ccbc263a058222d4190d75b4a8aa4b020d6913 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Fri, 9 Apr 2021 14:22:29 -0600 Subject: [PATCH 66/76] Updates to test check_avail --- index.js | 4 +- tests/Archive/expired-domains.js | 36 ------- tests/bravo-migr-test.js | 4 +- tests/burn-address.js | 2 +- tests/expired-address-domain.js | 172 +++++++++++++++++++++++++++++++ 5 files changed, 178 insertions(+), 40 deletions(-) delete mode 100644 tests/Archive/expired-domains.js create mode 100644 tests/expired-address-domain.js diff --git a/index.js b/index.js index 6f754b8a..1e83a5ff 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ describe('TEST SUITE', () => { require('./tests/bravo-migr-test.js'); //This is required when testing 2.3.0 (bravo) with fio bahamas (need to do the full table migration). - //require('./tests/history.js'); // Only run against history node. + require('./tests/addaddress.js'); // v1.0.x Also includes FIP-13 tests. require('./tests/fees.js'); // v1.0.x require('./tests/fio-request.js'); // v1.0.x @@ -35,4 +35,6 @@ describe('TEST SUITE', () => { require('./tests/testnet-smoketest.js'); // Testnet smoketest. By default runs against local build. + require('./tests/expired-address-domain.js'); // Requires manual updates to contracts to shorten expiration timing + //require('./tests/history.js'); // Only run against history node. }); diff --git a/tests/Archive/expired-domains.js b/tests/Archive/expired-domains.js deleted file mode 100644 index 402bcff0..00000000 --- a/tests/Archive/expired-domains.js +++ /dev/null @@ -1,36 +0,0 @@ -require('mocha') -const {expect} = require('chai') -const {newUser, generateFioAddress, generateFioDomain, fetchJson} = require('../../utils.js'); -const {FIOSDK } = require('@fioprotocol/fiosdk') -config = require('../../config.js'); - -before(async () => { - faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson) -}) - -describe('************************** expired-domains.js ************************** \n A. General testing for expired domains.', () => { - - let userA1, userA2 - - it(`Create users`, async () => { - userA1 = await newUser(faucet); - userA2 = await newUser(faucet); - }) - - it.skip(`Transfer expired domain. Expect error type 400: ${config.error.fioDomainNeedsRenew}`, async () => { - try { - const result = await userA1.sdk.genericAction('transferFioDomain', { - fioDomain: userA1.domain, - newOwnerKey: userA2.publicKey, - maxFee: config.api.transfer_fio_domain.fee, - technologyProviderId: '' - }) - expect(result.status).to.equal(null); - } catch (err) { - console.log('Error: ', err) - expect(err.json.fields[0].error).to.equal(config.error.fioDomainNeedsRenew); - expect(err.statusCode).to.equal(400); - } - }) - -}) diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index c65b4895..e7c9b441 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -1103,7 +1103,7 @@ describe.skip(`NUKE Bravo: Call migrtrx until table data is nuked`, () => { }) -describe.skip(`Release v2.3.2 - fiotrxtss (NEW table) scripts`, () => { +describe(`Release v2.3.2 - fiotrxtss (NEW table) scripts`, () => { describe(`A. Load Requests and OBTs`, () => { let user1, user2, user3; @@ -2058,7 +2058,7 @@ describe.skip(`Release v2.3.2 - fiotrxtss (NEW table) scripts`, () => { }) }) -describe(`(Only works in environments with both tables. Need to update contract) Release delta (develop - migr2) - remove data from old tables (fioreqctxts, recordobts, fioreqstss)`, () => { +describe.skip(`(Only works in environments with both tables. Need to update contract) Release delta (develop - migr2) - remove data from old tables (fioreqctxts, recordobts, fioreqstss)`, () => { let isFinished = 0 it('Echo size of fioreqctxts table', async () => { diff --git a/tests/burn-address.js b/tests/burn-address.js index f0038c08..e26ead2c 100644 --- a/tests/burn-address.js +++ b/tests/burn-address.js @@ -144,7 +144,7 @@ describe('************************** burn-address.js ************************** console.log('Error', err); expect(err).to.equal(null); } - }) + }) it(`Use up all of walletA1's bundles with 51 record_obt_data transactions`, async () => { for (i = 0; i < 51; i++) { diff --git a/tests/expired-address-domain.js b/tests/expired-address-domain.js new file mode 100644 index 00000000..7cd0520b --- /dev/null +++ b/tests/expired-address-domain.js @@ -0,0 +1,172 @@ +/** + * This test requires manually updating xyz contract to shorten the expiration for domains and addresses + * to 2 minutes. + * + * In fio.address.cpp: + * + * For Addresses: Line 162, change: + * const uint32_t expiration_time = get_now_plus_one_year(); + * to + * const uint32_t expiration_time = now() + 120; + * + * For Domains: Line 245, change: + * expiration_time = get_now_plus_one_year(); + * to + * expiration_time = now() + 120; + * + * Once updated: + * - Rebuild the contracts with the fix + * - cd into fio.test directory + * - run node tests/expired-address-domain.js + */ + +require('mocha') +const {expect} = require('chai') +const {newUser, fetchJson, timeout, callFioApi, callFioApiSigned} = require('../utils.js'); +const {FIOSDK } = require('@fioprotocol/fiosdk') +config = require('../config.js'); + +before(async () => { + faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson) +}) + +describe('************************** expired-address-domain.js ************************** \n A. General testing for expired domains and addresses', () => { + + let userA1, userA2 + + it(`Create users`, async () => { + userA1 = await newUser(faucet); + userA2 = await newUser(faucet); + }) + + it(`getFioNames for userA1 and confirm the address and domain are NOT expired`, async () => { + try { + curdate = new Date() + var utcSeconds = (curdate.getTime() + curdate.getTimezoneOffset()*60*1000)/1000; // Convert to UTC + const result = await userA1.sdk.genericAction('getFioNames', { + fioPublicKey: userA1.publicKey + }) + expect(result.fio_domains[0].fio_domain).to.equal(userA1.domain); + expect(Date.parse(result.fio_domains[0].expiration)/1000).to.be.greaterThan(utcSeconds); + expect(result.fio_addresses[0].fio_address).to.equal(userA1.address); + expect(Date.parse(result.fio_addresses[0].expiration)/1000).to.be.greaterThan(utcSeconds); + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Check isAvailable for domain. Expect is_registered = 1`, async () => { + try { + const result = await userA1.sdk.genericAction('isAvailable', { + fioName: userA1.domain, + }) + //console.log('Result: ', result); + expect(result.is_registered).to.equal(1); + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } + }) + + it(`Check isAvailable for address. Expect is_registered = 1`, async () => { + try { + const result = await userA1.sdk.genericAction('isAvailable', { + fioName: userA1.address, + }) + //console.log('Result: ', result); + expect(result.is_registered).to.equal(1); + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } + }) + + it(`Wait 2 minutes for the addresses and domains to expire`, async () => { + await timeout(125000); + }) + + it(`getFioNames for userA1 and confirm the address and domain ARE expired`, async () => { + try { + curdate = new Date() + var utcSeconds = (curdate.getTime() + curdate.getTimezoneOffset()*60*1000)/1000; // Convert to UTC + const result = await userA1.sdk.genericAction('getFioNames', { + fioPublicKey: userA1.publicKey + }) + //console.log('getFioNames', result); + expect(result.fio_domains[0].fio_domain).to.equal(userA1.domain); + expect(Date.parse(result.fio_domains[0].expiration)/1000).to.be.lessThan(utcSeconds); + expect(result.fio_addresses[0].fio_address).to.equal(userA1.address); + expect(Date.parse(result.fio_addresses[0].expiration)/1000).to.be.lessThan(utcSeconds); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Check isAvailable for expired domain. Expect is_registered = 1`, async () => { + try { + const result = await userA1.sdk.genericAction('isAvailable', { + fioName: userA1.domain, + }) + //console.log('Result: ', result); + expect(result.is_registered).to.equal(1); + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } + }) + + it(`Check isAvailable for expired (but not burned) address. Expect is_registered = 1`, async () => { + try { + const result = await userA1.sdk.genericAction('isAvailable', { + fioName: userA1.address, + }) + //console.log('Result: ', result); + expect(result.is_registered).to.equal(1); + } catch (err) { + console.log('Error: ', err); + expect(err).to.equal(null); + } + }) + + it(`Transfer expired domain. Expect error type 400: ${config.error.fioDomainNeedsRenew}`, async () => { + try { + const result = await userA1.sdk.genericAction('transferFioDomain', { + fioDomain: userA1.domain, + newOwnerKey: userA2.publicKey, + maxFee: config.api.transfer_fio_domain.fee, + technologyProviderId: '' + }) + expect(result.status).to.equal(null); + } catch (err) { + //console.log('Error: ', err.json); + expect(err.json.fields[0].error).to.equal(config.error.fioDomainNeedsRenew); + expect(err.errorCode).to.equal(400); + } + }) + + it.skip(`(BUG BD-2475) Burn userA1.address. Expect error type 400: ${config.error.fioDomainNeedsRenew}`, async () => { + try { + const result = await callFioApiSigned('push_transaction', { + action: 'burnaddress', + account: 'fio.address', + actor: userA1.account, + privKey: userA1.privateKey, + data: { + "fio_address": userA1.address, + "max_fee": config.maxFee, + "tpid": '', + "actor": userA1.account + } + }) + console.log('Result: ', result); + //expect(result.status).to.equal(null); + } catch (err) { + console.log('Error: ', err); + expect(err.json.fields[0].error).to.equal(config.error.fioDomainNeedsRenew); + expect(err.errorCode).to.equal(400); + } + }) + +}) From f5eccefc5b7586b977d7e50920902376ecb11177 Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Fri, 9 Apr 2021 20:20:52 -0600 Subject: [PATCH 67/76] fix tests to reflect new validation of contract name in addaction fix tests to reflect new validation of contract name in addaction --- config.js | 2 +- tests/action-whitelisting.js | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/config.js b/config.js index 7fc58613..dfbc5519 100644 --- a/config.js +++ b/config.js @@ -118,7 +118,7 @@ const config = { statusCode: 500 }, invalidContract: { - message: 'Invalid Contract', + message: 'Contract name invalid or not found', statusCode: 500 }, invalidActorAuth: { diff --git a/tests/action-whitelisting.js b/tests/action-whitelisting.js index 437ea115..e3dd693d 100644 --- a/tests/action-whitelisting.js +++ b/tests/action-whitelisting.js @@ -206,7 +206,7 @@ describe(`B. General addaction testing with random contracts and domains (can be } }) - it(`addaction with 7 character action and 50 character contract succeeds.`, async () => { + it(`addaction with 7 character action and 50 character contract FAILS.`, async () => { const result = await callFioApiSigned('push_transaction', { action: 'addaction', account: 'eosio', @@ -219,10 +219,10 @@ describe(`B. General addaction testing with random contracts and domains (can be } }) //console.log('Result: ', result) - expect(result.processed.receipt.status).to.equal('executed'); + expect(result.code).to.equal(config.error2.invalidContract.statusCode); }) - it(`addaction with 7 character action and 1000 character contract succeeds.`, async () => { + it(`addaction with 7 character action and 1000 character contract FAILS.`, async () => { const result = await callFioApiSigned('push_transaction', { action: 'addaction', account: 'eosio', @@ -235,7 +235,7 @@ describe(`B. General addaction testing with random contracts and domains (can be } }) //console.log('Result: ', result) - expect(result.processed.receipt.status).to.equal('executed'); + expect(result.code).to.equal(config.error2.invalidContract.statusCode); }) }) @@ -264,7 +264,7 @@ describe(`C. Test addaction error conditions`, () => { actor: fiotoken.account } }) - //console.log('Result: ', result) + // console.log('Result: ', result) expect(result.error.details[0].message).to.equal(config.error2.invalidAction.message); expect(result.code).to.equal(config.error2.invalidAction.statusCode); }) @@ -281,7 +281,7 @@ describe(`C. Test addaction error conditions`, () => { actor: fiotoken.account } }) - //console.log('Result: ', result.error) + // console.log('Result: ', result.error) expect(result.error.details[0].message).to.equal(config.error2.invalidContract.message); expect(result.code).to.equal(config.error2.invalidContract.statusCode); }) From 66c284065ac22fa9a930b43d8032e21a07624ebb Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 12 Apr 2021 08:47:16 -0600 Subject: [PATCH 68/76] Final fixes for expired testing --- index.js | 2 +- tests/expired-address-domain.js | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 1e83a5ff..66e31a61 100644 --- a/index.js +++ b/index.js @@ -35,6 +35,6 @@ describe('TEST SUITE', () => { require('./tests/testnet-smoketest.js'); // Testnet smoketest. By default runs against local build. - require('./tests/expired-address-domain.js'); // Requires manual updates to contracts to shorten expiration timing + //require('./tests/expired-address-domain.js'); // Requires manual updates to contracts to shorten expiration timing //require('./tests/history.js'); // Only run against history node. }); diff --git a/tests/expired-address-domain.js b/tests/expired-address-domain.js index 7cd0520b..64b5993d 100644 --- a/tests/expired-address-domain.js +++ b/tests/expired-address-domain.js @@ -16,8 +16,7 @@ * * Once updated: * - Rebuild the contracts with the fix - * - cd into fio.test directory - * - run node tests/expired-address-domain.js + * - run expired-address-domain.js */ require('mocha') @@ -161,11 +160,11 @@ describe('************************** expired-address-domain.js ***************** } }) console.log('Result: ', result); - //expect(result.status).to.equal(null); + expect(result.fields[0].error).to.equal(config.error.fioDomainNeedsRenew); + //expect(err.errorCode).to.equal(400); } catch (err) { console.log('Error: ', err); - expect(err.json.fields[0].error).to.equal(config.error.fioDomainNeedsRenew); - expect(err.errorCode).to.equal(400); + expect(err).to.equal(null); } }) From 03dd198a878e741f17173c3b3b682e6eaf4bfe39 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 12 Apr 2021 08:51:35 -0600 Subject: [PATCH 69/76] fix for migration test --- tests/bravo-migr-test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index e7c9b441..c65b4895 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -1103,7 +1103,7 @@ describe.skip(`NUKE Bravo: Call migrtrx until table data is nuked`, () => { }) -describe(`Release v2.3.2 - fiotrxtss (NEW table) scripts`, () => { +describe.skip(`Release v2.3.2 - fiotrxtss (NEW table) scripts`, () => { describe(`A. Load Requests and OBTs`, () => { let user1, user2, user3; @@ -2058,7 +2058,7 @@ describe(`Release v2.3.2 - fiotrxtss (NEW table) scripts`, () => { }) }) -describe.skip(`(Only works in environments with both tables. Need to update contract) Release delta (develop - migr2) - remove data from old tables (fioreqctxts, recordobts, fioreqstss)`, () => { +describe(`(Only works in environments with both tables. Need to update contract) Release delta (develop - migr2) - remove data from old tables (fioreqctxts, recordobts, fioreqstss)`, () => { let isFinished = 0 it('Echo size of fioreqctxts table', async () => { From 20cca502e8664ca18b5a332a4396dc8270ca5933 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Wed, 14 Apr 2021 11:00:26 -0600 Subject: [PATCH 70/76] Merge devnet timeout fixes from 3.0.x branch --- index.js | 2 +- tests/action-whitelisting.js | 13 +++++++++++-- tests/addbundles.js | 2 ++ tests/bravo-migr-test.js | 4 ++-- tests/fio-request.js | 12 ++++++++---- tests/record-obt-data.js | 2 ++ tests/vote.js | 10 ++++++++-- 7 files changed, 34 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 66e31a61..9c0ab49e 100644 --- a/index.js +++ b/index.js @@ -30,7 +30,7 @@ describe('TEST SUITE', () => { require('./tests/transfer-locked-tokens-account-tests.js'); // FIP-6 tests of generic account functionality require('./tests/addbundles.js'); // FIP-11.a require('./tests/tpid.js'); - require('./tests/clio.js'); // FIP-16 + //require('./tests/clio.js'); // FIP-16 //Only works with local testing //require('./tests/performance-request-obt.js'); require('./tests/testnet-smoketest.js'); // Testnet smoketest. By default runs against local build. diff --git a/tests/action-whitelisting.js b/tests/action-whitelisting.js index e3dd693d..bafe68f1 100644 --- a/tests/action-whitelisting.js +++ b/tests/action-whitelisting.js @@ -106,8 +106,17 @@ describe(`************************** action-whitelisting.js ******************** } }) + it('Wait a few seconds.', async () => { + await timeout(5000); + }) + it(`Confirm create users works`, async () => { - userA2 = await newUser(faucet); + try { + userA2 = await newUser(faucet); + } catch (err) { + console.log("err ", err); + expect(err).to.equal(null); + } }) }) @@ -146,7 +155,7 @@ describe('A.2. Add random action hoses up the SDK session. Non recoverable. So, await timeout(5000); }) - it(`Create users`, async () => { + it(`Confirm create users works`, async () => { try { user2 = await newUser(faucet); } catch (err) { diff --git a/tests/addbundles.js b/tests/addbundles.js index da4728b0..e90896ee 100644 --- a/tests/addbundles.js +++ b/tests/addbundles.js @@ -572,6 +572,8 @@ describe('C. Error testing', () => { expect(err).to.equal(null) } }) + + it(`Wait a few seconds.`, async () => { await timeout(3000) }) it(`Get bundle count for user1. Verify 0 bundles`, async () => { let bundleCount; diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index c65b4895..cfe039d4 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -1198,7 +1198,7 @@ describe.skip(`Release v2.3.2 - fiotrxtss (NEW table) scripts`, () => { console.log('Error', err.json) expect(err).to.equal(null) } - + await timeout(2000); try { const result = await user2.sdk.genericAction('pushTransaction', { action: 'rejectfndreq', @@ -1244,7 +1244,7 @@ describe.skip(`Release v2.3.2 - fiotrxtss (NEW table) scripts`, () => { console.log('Error', err.json) expect(err).to.equal(null) } - + await timeout(2000); try { const result = await user1.sdk.genericAction('recordObtData', { payerFioAddress: user1.address, diff --git a/tests/fio-request.js b/tests/fio-request.js index 7ecdaa95..85b4b015 100644 --- a/tests/fio-request.js +++ b/tests/fio-request.js @@ -43,7 +43,7 @@ describe(`************************** fio-request.js ************************** \ } }) - it(`Wait a few seconds.`, async () => { await timeout(2000) }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) it(`userA1 requests funds from userA2`, async () => { try { @@ -1567,6 +1567,8 @@ describe(`E. Test cancel_funds_request error conditions`, () => { userC1 = await newUser(faucet); userC2 = await newUser(faucet); }) + + it(`Wait a few seconds.`, async () => { await timeout(2000) }) it(`Run get_cancelled_fio_requests when no request have been cancelled. Expect error type 404: ${config.error.noFioRequests}`, async () => { try { @@ -1956,6 +1958,8 @@ describe(`F. get_cancelled_fio_requests paging: Cancel multiple FIO requests and } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Make ${requestCount} requests for userC1`, async () => { for (i = 0; i < requestCount; i++) { try { @@ -2237,7 +2241,7 @@ describe(`G. Test rejection of FIO Requests`, () => { } }) - it('Wait a few seconds to avoid duplicate transaction.', async () => { await timeout(3000); }) + it('Wait a few seconds to avoid duplicate transaction.', async () => { await timeout(5000); }) it(`user2 rejects first funds request`, async () => { try{ @@ -2259,7 +2263,7 @@ describe(`G. Test rejection of FIO Requests`, () => { } }) - it('Wait a few seconds...', async () => { await timeout(3000); }) + it('Wait a few seconds...', async () => { await timeout(5000); }) it(`get_pending_fio_requests for user2, expect 9 results`, async () => { try { @@ -2452,7 +2456,7 @@ describe(`I. reject_funds_request: Check all getters after`, () => { } }) - it(`Wait a few seconds.`, async () => { await timeout(2000) }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) it(`get_sent_fio_requests for userA1 (payee) BEFORE Reject`, async () => { try { diff --git a/tests/record-obt-data.js b/tests/record-obt-data.js index e3e15bde..80a6e553 100644 --- a/tests/record-obt-data.js +++ b/tests/record-obt-data.js @@ -444,6 +444,8 @@ describe(`C. Test get_obt_data`, () => { userA2 = await newUser(faucet); }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`get_obt_data for userA1 (payer) when no records exist. limit = '', offset = ''. Expect: ${config.error.noFioRequests}`, async () => { try { const result = await userA1.sdk.genericAction('getObtData', { diff --git a/tests/vote.js b/tests/vote.js index a97caf8d..d2e31f34 100644 --- a/tests/vote.js +++ b/tests/vote.js @@ -765,6 +765,8 @@ describe('C. Test proxying to a user who is also proxying (should fail)', () => } }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`proxyE1 votes for bp1@dapixdev`, async () => { try { const result = await proxyE1.sdk.genericAction('pushTransaction', { @@ -1255,6 +1257,8 @@ describe('E.2 Test vote_producer with and without FIO Address (FIP-9)', () => { voterG6 = await newUser(faucet); }) + it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Get bp1@dapixdev total_votes`, async () => { try { total_bp_votes = await getProdVoteTotal('bp1@dapixdev'); @@ -1939,7 +1943,7 @@ describe('E.3 Test proxy_vote with and without FIO Address (FIP-9)', () => { }) it('Wait a few seconds.', async () => { - await timeout(3000); + await timeout(5000); }) it(`Confirm proxy_vote fee for voterG8 = ${config.api.proxy_vote.fee}`, async () => { @@ -2797,7 +2801,7 @@ describe(`J. Test total_voted_fio when user votes for proxy`, () => { proxyA1 = await newUser(faucet); }) - it(`Wait a few seconds.`, async () => { await timeout(3000) }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) it(`Get initial total_voted_fio`, async () => { total_voted_fio = await getTotalVotedFio(); @@ -2921,6 +2925,8 @@ describe(`J. Test total_voted_fio when user votes for proxy`, () => { } }) + it(`Wait a few seconds.`, async () => { await timeout(5000) }) + it(`Proxy user1 votes to proxyA1`, async () => { try { const result = await user1.sdk.genericAction('pushTransaction', { From 4376f98f7b79bf0c31b0b1582c5128804eac351e Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Fri, 16 Apr 2021 13:34:37 -0600 Subject: [PATCH 71/76] Load wallet with multiple keys --- tests/clio.js | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/tests/clio.js b/tests/clio.js index 775baffd..dd2f5cfd 100644 --- a/tests/clio.js +++ b/tests/clio.js @@ -1,6 +1,6 @@ require('mocha') const {expect} = require('chai') -const {newUser, existingUser, randStr, generateFioDomain, generateFioAddress, unlockWallet, callFioApi, timeout, fetchJson} = require('../utils.js'); +const {newUser, existingUser, randStr, createKeypair, generateFioDomain, generateFioAddress, unlockWallet, callFioApi, timeout, fetchJson} = require('../utils.js'); const {FIOSDK } = require('@fioprotocol/fiosdk') config = require('../config.js'); @@ -26,6 +26,21 @@ async function runClio(parms) { }); } +async function runClioWallet(parms) { + return new Promise(function(resolve, reject) { + command = clio + " " + parms + //console.log('command = ', command) + //command = "../fio.devtools/bin/clio -u http://localhost:8889 get info" + exec(command, (error, stdout, stderr) => { + if (error) { + reject(error); + return; + } + resolve(stdout.trim()); + }); + }); +} + before(async () => { faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson) @@ -34,10 +49,13 @@ before(async () => { describe(`************************** clio.js ************************** \n A. Test clio`, () => { + let keypair; + it(`get info`, async () => { const result = await runClio('get info'); expect(JSON.parse(result).head_block_num).to.be.a('number') }) + }) describe(`B. Request and OBT Data`, () => { @@ -1019,6 +1037,30 @@ describe(`H. clio error testing`, () => { }) }) +describe.skip(`Load wallet test`, () => { + + let keypair; + + it(`add keys`, async () => { + for (i = 0; i < 10; i++) { + keypair = await createKeypair(); + //console.log('keypair.privateKey: ', keypair.privateKey); + const result = await runClioWallet('wallet import -n fio --private-key ' + keypair.privateKey); + //console.log('Result: ', result); + } + }) + + it(`clio: trnsfiopubky with print`, async () => { + try { + result = await runClio(`--print-response push action fio.token trnsfiopubky '{"payee_public_key": "FIO5hVsGrqf4Rwxyv2Q6zqv9ARL7Q1oXnV2id4sx6HWvUMQdHk9JA","amount": 2,"max_fee": 10000000000,"tpid": "","actor": "qhh25sqpktwh"}' --permission qhh25sqpktwh@active`); + //console.log('Result: ', result) + } catch (err) { + console.log('Error', err) + expect(err).to.equal(null) + } + }) + +}) /** * Commenting out ratios and multipliers tests. Decided to leave these calls out of clio From de6d4e81b48bac28ce625916b1823eb8294ddfac Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Tue, 4 May 2021 18:14:38 -0600 Subject: [PATCH 72/76] Fixes to get tests running with develop contracts --- index.js | 2 +- tests/bravo-migr-test.js | 268 ++++++++++++++++++++++++++++++++++++++- tests/clio.js | 7 +- 3 files changed, 272 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 9c0ab49e..e08bebba 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ const {expect} = require('chai') describe('TEST SUITE', () => { - require('./tests/bravo-migr-test.js'); //This is required when testing 2.3.0 (bravo) with fio bahamas (need to do the full table migration). + //require('./tests/bravo-migr-test.js'); //This is required when testing 2.3.0 (bravo) with fio bahamas (need to do the full table migration). require('./tests/addaddress.js'); // v1.0.x Also includes FIP-13 tests. diff --git a/tests/bravo-migr-test.js b/tests/bravo-migr-test.js index cfe039d4..bf1e0f4c 100644 --- a/tests/bravo-migr-test.js +++ b/tests/bravo-migr-test.js @@ -9,7 +9,7 @@ require('mocha') const {expect} = require('chai') const {newUser, fetchJson, existingUser, callFioApiSigned, callFioApi, timeout} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/fiosdk') +const {FIOSDK } = require('@fioprotocol/fiosdk'); config = require('../config.js'); /* @@ -54,6 +54,11 @@ describe.skip(`************************** bravo-migr-test.js ******************* user1 = await newUser(faucet); user2 = await newUser(faucet); user3 = await newUser(faucet); + + //user2 = await existingUser('eyadddduu5a3', '5KVMKehpRVZ5pFHZ8TUjZQLcMBmkM85RnUhxw6V9XFCcBN5EPzP', 'FIO7eFQHnbtq3cGntFKdXsKcBkxtCb69rYaGZaV9JVDJ2CYgMGV8R', 'fiotestnet', 'requests@fiotestnet'); + //user1 = await existingUser('ifnxuprs2uxv', '5KNMbAhXGTt2Leit3z5JdqqtTbLhxWNf6ypm4r3pZQusNHHKV7a', 'FIO6TWRA6o5UNeMVwG8oGxedvhizd8UpfGbnGKaXEiPH2kUWEPiEb', 'fiotestnet', 'etest6@fiotestnet'); + //user3 = await existingUser('v2lgwcdkb5gn', '5Jw78NzS2QMvjcyemCgJ9XQv8SMSEvTEuLxF8TcKf27xWcX5fmw', 'FIO8k7N7jU9eyj57AfazGxMuvPGZG5hvXNUyxt9pBchnkXXx9KUuD', 'fiotestnet', 'ebtest1@fiotestnet'); + //console.log('user1: ' + user1.account + ', ' + user1.privateKey + ', ' + user1.publicKey) //console.log('user2: ' + user2.account + ', ' + user2.privateKey + ', ' + user2.publicKey) @@ -2058,7 +2063,266 @@ describe.skip(`Release v2.3.2 - fiotrxtss (NEW table) scripts`, () => { }) }) -describe(`(Only works in environments with both tables. Need to update contract) Release delta (develop - migr2) - remove data from old tables (fioreqctxts, recordobts, fioreqstss)`, () => { +describe.skip(`OBT time_stamp fix validation (fioreqctxts, recordobts, fioreqstss)`, () => { + let isFinished = 0 + let user1PubKey, user2PubKey, user3PubKey, requestId + + it('Get request id from fioreqstss', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'fioreqstss', + limit: 1000, + reverse: false, + show_payer: false + } + fioreqstss = await callFioApi("get_table_rows", json); + //console.log('fioreqstss: ', fioreqstss.rows.length); + //console.log('fioreqstss: ', fioreqstss); + requestId = fioreqstss.rows[0].fio_request_id; + //console.log('requestId: ', requestId); + expect(fioreqstss.rows[0].time_stamp.toString().length).to.equal(16); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it('Echo size of fioreqctxts table', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'fioreqctxts', + limit: 1000, + reverse: false, + show_payer: false + } + fioreqctxts = await callFioApi("get_table_rows", json); + console.log('fioreqctxts: ', fioreqctxts.rows.length); + //console.log('fioreqctxts: ', fioreqctxts); + console.log('requestId: ', requestId); + for (request in fioreqctxts.rows) { + console.log('fioreqctxts.rows[request].fio_request_id: ', fioreqctxts.rows[request].fio_request_id) + if (fioreqctxts.rows[request].fio_request_id == requestId) { + user3PubKey = fioreqctxts.rows[request].payer_key; + console.log('user3PubKey: ', user3PubKey) + } + } + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Call get_obt_data for user3`, async () => { + try { + const json = { + fio_public_key: user3PubKey + } + result = await callFioApi("get_obt_data", json); + console.log('Result: ', result); + expect(result.obt_data_records[0].time_stamp).to.equal('1970-01-01T00:00:00'); + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it('Echo size of recordobts table and get user1 and user2 Public Key', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'recordobts', + limit: 1000, + reverse: false, + show_payer: false + } + recordobts = await callFioApi("get_table_rows", json); + console.log('recordobts.length: ', recordobts.rows.length); + user1PubKey = recordobts.rows[0].payer_key + user2PubKey = recordobts.rows[0].payee_key + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Call get_obt_data for user1`, async () => { + try { + const json = { + fio_public_key: user1PubKey + } + result = await callFioApi("get_obt_data", json); + console.log('Result: ', result); + expect(result.obt_data_records[0].time_stamp).to.equal('1970-01-01T00:00:00'); + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + it(`Call get_obt_data for user2`, async () => { + try { + const json = { + fio_public_key: user2PubKey + } + result = await callFioApi("get_obt_data", json); + console.log('Result: ', result); + expect(result.obt_data_records[0].time_stamp).to.equal('1970-01-01T00:00:00'); + } catch (err) { + //console.log('Error', err) + expect(err).to.equal(null) + } + }) + + + it.skip(`Call migrtrx (bp1) with amount = 20 until (fioreqctxts, recordobts, fioreqstss) are empty`, async () => { + let fioreqctxtsIsFinished = false, recordobtsIsFinished = false, fioreqstssIsFinished = false; + while (!fioreqctxtsIsFinished || !recordobtsIsFinished || !fioreqstssIsFinished) { + try { + const result = await callFioApiSigned('push_transaction', { + action: 'migrtrx', + account: 'fio.reqobt', + actor: bp1.account, + privKey: bp1.privateKey, + data: { + amount: 20, + actor: bp1.account + } + }) + //console.log('Result: ', result) + expect(result.transaction_id).to.exist + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null) + } + await timeout(2000); + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'fioreqctxts', + limit: 1000, + reverse: false, + show_payer: false + } + fioreqctxts = await callFioApi("get_table_rows", json); + fioreqctxtsIsFinished = (fioreqctxts.rows.length == 0); + //console.log('fioreqctxts: ', fioreqctxts) + console.log('\nfioreqctxts table rows count: ', fioreqctxts.rows.length) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'recordobts', + limit: 1000, + reverse: false, + show_payer: false + } + recordobts = await callFioApi("get_table_rows", json); + recordobtsIsFinished = (recordobts.rows.length == 0); + //console.log('recordobts: ', recordobts) + console.log('recordobts table rows count: ', recordobts.rows.length) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'fioreqstss', + limit: 1000, + reverse: false, + show_payer: false + } + fioreqstss = await callFioApi("get_table_rows", json); + fioreqstssIsFinished = (fioreqstss.rows.length == 0); + //console.log('fioreqstss: ', fioreqstss) + console.log('fioreqstss table rows count: ', fioreqstss.rows.length) + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + } + }) + + it.skip('Confirm fioreqctxts table is empty', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'fioreqctxts', + limit: 10, + reverse: false, + show_payer: false + } + fioreqctxts = await callFioApi("get_table_rows", json); + console.log('fioreqctxts: ', fioreqctxts); + expect(fioreqctxts.rows.length).to.equal(0); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it.skip('Confirm recordobts table is empty', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'recordobts', + limit: 10, + reverse: false, + show_payer: false + } + recordobts = await callFioApi("get_table_rows", json); + console.log('recordobts: ', recordobts); + expect(recordobts.rows.length).to.equal(0); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it.skip('Confirm fioreqstss table is empty', async () => { + try { + const json = { + json: true, + code: 'fio.reqobt', + scope: 'fio.reqobt', + table: 'fioreqstss', + limit: 10, + reverse: false, + show_payer: false + } + fioreqstss = await callFioApi("get_table_rows", json); + console.log('fioreqstss: ', fioreqstss); + expect(fioreqstss.rows.length).to.equal(0); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) + +describe.skip(`(Only works in environments with both tables. Need to update contract) Release delta (develop - migr2) - remove data from old tables (fioreqctxts, recordobts, fioreqstss)`, () => { let isFinished = 0 it('Echo size of fioreqctxts table', async () => { diff --git a/tests/clio.js b/tests/clio.js index dd2f5cfd..a90c9726 100644 --- a/tests/clio.js +++ b/tests/clio.js @@ -1040,13 +1040,16 @@ describe(`H. clio error testing`, () => { describe.skip(`Load wallet test`, () => { let keypair; + let total = 0; it(`add keys`, async () => { for (i = 0; i < 10; i++) { + keypair = await createKeypair(); - //console.log('keypair.privateKey: ', keypair.privateKey); + total++ + console.log('keypair.privateKey: ', keypair.privateKey); const result = await runClioWallet('wallet import -n fio --private-key ' + keypair.privateKey); - //console.log('Result: ', result); + console.log('Result: ', result); } }) From 48722d77ff10a05cf6a6d4dbdbb64a3c213394f8 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Tue, 15 Jun 2021 15:14:44 -0600 Subject: [PATCH 73/76] Clean up and enable xfer address tests --- tests/expired-address-domain.js | 2 +- tests/testnet-smoketest.js | 64 +++++++++++++++++---------------- tests/transfer-address.js | 6 ++-- 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/tests/expired-address-domain.js b/tests/expired-address-domain.js index 64b5993d..1a07948e 100644 --- a/tests/expired-address-domain.js +++ b/tests/expired-address-domain.js @@ -145,7 +145,7 @@ describe('************************** expired-address-domain.js ***************** } }) - it.skip(`(BUG BD-2475) Burn userA1.address. Expect error type 400: ${config.error.fioDomainNeedsRenew}`, async () => { + it(`Burn userA1.address. Expect error type 400: ${config.error.fioDomainNeedsRenew} (BD-2475)`, async () => { try { const result = await callFioApiSigned('push_transaction', { action: 'burnaddress', diff --git a/tests/testnet-smoketest.js b/tests/testnet-smoketest.js index 124dcaa8..7c7c88eb 100644 --- a/tests/testnet-smoketest.js +++ b/tests/testnet-smoketest.js @@ -350,27 +350,6 @@ describe('B. Testing domain actions', () => { expect(result.fee_collected).to.be.a('number') }) - it(`getFee for transferFioAddress`, async () => { - const result = await fioSdk2.sdk.genericAction('getFeeForTransferFioAddress', { - fioAddress: newFioAddress - }) - - expect(result).to.have.all.keys('fee') - expect(result.fee).to.be.a('number') - }) - - it.skip(`Need to move: Transfer fio address`, async () => { - const result = await fioSdk2.sdk.genericAction('transferFioAddress', { - fioAddress: newFioAddress, - newOwnerKey: pubKeyForTransfer, - maxFee: defaultFee - }) - - expect(result).to.have.all.keys('status', 'fee_collected') - expect(result.snew-funtatus).to.be.a('string') - expect(result.fee_collected).to.be.a('number') - }) - it(`getFee for transferFioDomain`, async () => { const result = await fioSdk2.sdk.genericAction('getFeeForTransferFioDomain', { fioAddress: newFioAddress @@ -637,7 +616,7 @@ describe('B. Testing domain actions', () => { expect(result.public_address).to.be.a('string') }) - it(`getFee`, async () => { + it(`getFee for register_fio_address`, async () => { const result = await fioSdk2.sdk.genericAction('getFee', { endPoint: 'register_fio_address', fioAddress: '' @@ -653,26 +632,49 @@ describe('B. Testing domain actions', () => { expect(result).to.be.a('number') }) - it(`getFee for BurnFioAddress`, async () => { - const result = await fioSdk2.sdk.genericAction('getFeeForBurnFioAddress', { - fioAddress: newFioAddress + it(`getFee for transferFioAddress`, async () => { + const result = await fioSdk2.sdk.genericAction('getFeeForTransferFioAddress', { + fioAddress: newFioAddress }) expect(result).to.have.all.keys('fee') expect(result.fee).to.be.a('number') }) - it(`Burn fio address`, async () => { - const result = await fioSdk2.sdk.genericAction('burnFioAddress', { - fioAddress: newFioAddress, - maxFee: defaultFee + it(`Need to move: Transfer fio address to fioSdk`, async () => { + const result = await fioSdk2.sdk.genericAction('transferFioAddress', { + fioAddress: newFioAddress, + newOwnerKey: fioSdk.publicKey, + maxFee: defaultFee }) - expect(result).to.have.all.keys('status', 'fee_collected') - expect(result.status).to.be.a('string') + expect(result.status).to.equal('OK') expect(result.fee_collected).to.be.a('number') }) + it(`getFee for BurnFioAddress`, async () => { + const result = await fioSdk.sdk.genericAction('getFeeForBurnFioAddress', { + fioAddress: newFioAddress + }) + + expect(result).to.have.all.keys('fee') + expect(result.fee).to.be.a('number') + }) + + it(`Burn fio address`, async () => { + try { + const result = await fioSdk.sdk.genericAction('burnFioAddress', { + fioAddress: newFioAddress, + maxFee: defaultFee + }) + expect(result).to.have.all.keys('status', 'fee_collected') + expect(result.status).to.be.a('string') + expect(result.fee_collected).to.be.a('number') + } catch (e) { + console.log(e); + } + }) + }) describe('C. Request funds, approve and send', () => { diff --git a/tests/transfer-address.js b/tests/transfer-address.js index e8016b2d..965677a9 100644 --- a/tests/transfer-address.js +++ b/tests/transfer-address.js @@ -854,7 +854,7 @@ describe('D. transferFioAddress Error testing', () => { } }) - it.skip(`(For Bravo/v2.3.0 contracts, transferring the address will fail because userD3 has OBT transactions. Will need to fix when all xferaddress are enabled.) Transfer address with insufficient funds and no bundled transactions. Expect error type 400: ${config.error.insufficientFunds}`, async () => { + it(`Transfer address with insufficient funds and no bundled transactions. Expect error type 400: ${config.error.insufficientFunds}`, async () => { try { const result = await userD3.sdk.genericAction('transferFioAddress', { fioAddress: userD3.address, @@ -864,9 +864,9 @@ describe('D. transferFioAddress Error testing', () => { }) expect(result.status).to.equal(null); } catch (err) { - //console.log('Error: ', err.json.error) + //console.log('Error: ', err.json.fields[0]) expect(err.json.fields[0].error).to.equal(config.error.insufficientFunds) - expect(err.json.code).to.equal(400); + expect(err.errorCode).to.equal(400); } }) From f32d8ea670155571a5cd09ad7b4f279b2e525f9d Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Thu, 8 Jul 2021 10:23:53 -0600 Subject: [PATCH 74/76] add tests for mainnet-locked-tokens add tests for mainnet locked tokens. --- tests/mainnet-locked-tokens.js | 1356 ++++++++++++++++++++++++++++++++ 1 file changed, 1356 insertions(+) create mode 100644 tests/mainnet-locked-tokens.js diff --git a/tests/mainnet-locked-tokens.js b/tests/mainnet-locked-tokens.js new file mode 100644 index 00000000..ff45438e --- /dev/null +++ b/tests/mainnet-locked-tokens.js @@ -0,0 +1,1356 @@ +require('mocha') +const {expect} = require('chai') +const {newUser, existingUser,callFioApi,fetchJson, generateFioDomain, getAccountFromKey, generateFioAddress, createKeypair} = require('../utils.js'); +const {FIOSDK } = require('@fioprotocol/fiosdk') +config = require('../config.js'); + +before(async () => { + faucet = new FIOSDK(config.FAUCET_PRIV_KEY, config.FAUCET_PUB_KEY, config.BASE_URL, fetchJson); +}) + +function wait(ms){ + var start = new Date().getTime(); + var end = start; + while(end < start + ms) { + end = new Date().getTime(); + } +} +// To test genesis locks. please modify the following 2 files in the fio.contracts repository, to enable them +// to be placed into "test mode" +// +// First, shorten the main net locking period to become 1 minute, +// do this by commenting out the following lines in the fio.token.hpp computeremaininglockedtokens method. + +// TESTING ONLY!!! comment out genesis locking periods..DO NOT DELIVER THIS +/* uint32_t daysSinceGrant = (int) ((present_time - lockiter->timestamp) / SECONDSPERDAY); + uint32_t firstPayPeriod = 90; + uint32_t payoutTimePeriod = 180; + */ + +// then add the following code beneath what you commented out. + +//TEST LOCKED TOKENS +// TESTING ONLY!!! shorten genesis locking periods..DO NOT DELIVER THIS +// uint32_t daysSinceGrant = (int)((present_time - lockiter->timestamp) / 60); +// uint32_t firstPayPeriod = 1; +// uint32_t payoutTimePeriod = 1; + +//next permit anyone to call the addlocked action in the system contract. +// do this by commenting out the following line in the addlocked action of the fio.system.cpp file + +// // require_auth(_self); + +//add a return status, so that tests can run successfully at the end of the action. +// const string response_string = string("{"status": "OK"}"); +// send_response(response_string.c_str()); + + +//next modify the faucet to have more tokens +//08_token_issue.sh – modify the amount of tokens in the faucet to permit large grants. +// ./clio -u http://localhost:8879 push action -j fio.token issue '["qhh25sqpktwh","100000000.000000000 FIO","memo"]' -p eosio@active + +// after making these modifications rebuild the contracts locally and restart your chain. +// hou may then proceed with genesis locks testing. + +// + + +describe(`************************** mainet-locked-tokens.js ************************** \n A. Create large grant verify unlocking using voting \n also test error cant transfer more than unlocked amount\n also test multiple calls to voting do not have effect.`, () => { + + let userA1, prevFundsAmount, locksdk, keys, accountnm,newFioDomain, newFioAddress + const fundsAmount = 1000000000000 + const lockdurationseconds = 60 + + + it(`Create users`, async () => { + userA1 = await newUser(faucet); + + keys = await createKeypair(); + + accountnm = await getAccountFromKey(keys.publicKey); + console.log("priv key ", keys.privateKey); + console.log("pub key ", keys.publicKey); + console.log(" account ",accountnm); + + + const result = await faucet.genericAction('transferTokens', { + payeeFioPublicKey: keys.publicKey, + amount: 7075065123456789, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + expect(result.status).to.equal('OK') + + + const result1 = await userA1.sdk.genericAction('pushTransaction', { + action: 'addlocked', + account: 'eosio', + data: { + owner : accountnm, + amount: 7075065123456789, + locktype: 1 + } + }) + expect(result1.status).to.equal('OK') + + locksdk = new FIOSDK(keys.privateKey, keys.publicKey, config.BASE_URL, fetchJson); + + }) + + it(`getFioBalance for genesis lock token holder, available balance 0 `, async () => { + const result = await locksdk.genericAction('getFioBalance', { }) + prevFundsAmount = result.balance + expect(result.available).to.equal(7075065123456789) + }) + + it(`Failure test Transfer 700 FIO to userA1 FIO public key, insufficient balance tokens locked`, async () => { + try { + const result = await locksdk.genericAction('transferTokens', { + payeeFioPublicKey: userA1.publicKey, + amount: 700000000000, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + expect(result.status).to.not.equal('OK') + } catch (err) { + // console.log('Error: ', err) + expect(err.json.fields[0].error).to.contain(config.error.insufficientBalance) + } + }) + + //wait for unlock 1 + it(`Waiting for unlock 1 of 6`, async () => { + console.log(" waiting ",lockdurationseconds," seconds") + }) + + it(` wait for lock period`, async () => { + try { + wait(lockdurationseconds * 1000) + } catch (err) { + console.log('Error', err) + } + }) + + it(`Success, vote for producers.`, async () => { + + try { + const result = await locksdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + producers: ["bp1@dapixdev"], + fio_address: newFioAddress, + actor: accountnm, + max_fee: config.maxFee + } + }) + // console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log("ERROR: ", err) + } + }) + + //check that 6% was unlocked. + it(`Call get_table_rows from lockedtokens and confirm: unlocked amount`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'lockedtokens', + lower_bound: accountnm, + upper_bound: accountnm, + key_type: 'i64', + index_position: '1' + } + result = await callFioApi("get_table_rows", json); + // console.log('Result: ', result); + + expect(result.rows[0].unlocked_period_count).to.equal(1); + expect(result.rows[0].remaining_locked_amount).to.equal(6650561216049387); + + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Success, vote for producers.`, async () => { + + try { + const result = await locksdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + producers: ["bp2@dapixdev"], + fio_address: newFioAddress, + actor: accountnm, + max_fee: config.maxFee + } + }) + // console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log("ERROR: ", err) + } + }) + + //check that 6% was unlocked. + it(`Call get_table_rows from lockedtokens and confirm: unlocked amount unchangd with multiple calls`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'lockedtokens', + lower_bound: accountnm, + upper_bound: accountnm, + key_type: 'i64', + index_position: '1' + } + result = await callFioApi("get_table_rows", json); + // console.log('Result: ', result); + + expect(result.rows[0].unlocked_period_count).to.equal(1); + expect(result.rows[0].remaining_locked_amount).to.equal(6650561216049387); + + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Failure, Transfer 1M FIO to userA1 FIO public key`, async () => { + + try { + const result = await locksdk.genericAction('transferTokens', { + payeeFioPublicKey: userA1.publicKey, + amount: 1000000000, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + expect(result.status).to.equal('OK') + }catch (err){ + //console.log("ERROR: ", err) + expect(err.json.fields[0].error).to.contain(config.error.insufficientBalance) + } + }) + + //wait for unlock 2 + it(`Waiting for unlock 2 of 6`, async () => { + console.log(" waiting ",lockdurationseconds," seconds") + }) + + it(` wait for lock period`, async () => { + try { + wait(lockdurationseconds * 1000) + } catch (err) { + console.log('Error', err) + } + }) + + it(`Success, vote for producers.`, async () => { + + try { + const result = await locksdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + producers: ["bp1@dapixdev"], + fio_address: newFioAddress, + actor: accountnm, + max_fee: config.maxFee + } + }) + // console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log("ERROR: ", err) + } + }) + + //check that 18.8% was unlocked. + it(`Call get_table_rows from lockedtokens and confirm: unlocked amount`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'lockedtokens', + lower_bound: accountnm, + upper_bound: accountnm, + key_type: 'i64', + index_position: '1' + } + result = await callFioApi("get_table_rows", json); + // console.log('Result: ', result); + + expect(result.rows[0].unlocked_period_count).to.equal(2); + expect(result.rows[0].remaining_locked_amount).to.equal(5320448972849387); + + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + //wait for unlock 3 + it(`Waiting for unlock 3 of 6`, async () => { + console.log(" waiting ",lockdurationseconds," seconds") + }) + + it(` wait for lock period`, async () => { + try { + wait(lockdurationseconds * 1000) + } catch (err) { + console.log('Error', err) + } + }) + + it(`Success, vote for producers.`, async () => { + + try { + const result = await locksdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + producers: ["bp1@dapixdev"], + fio_address: newFioAddress, + actor: accountnm, + max_fee: config.maxFee + } + }) + // console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log("ERROR: ", err) + } + }) + + //check that 18.8% was unlocked. + it(`Call get_table_rows from lockedtokens and confirm: unlocked amount`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'lockedtokens', + lower_bound: accountnm, + upper_bound: accountnm, + key_type: 'i64', + index_position: '1' + } + result = await callFioApi("get_table_rows", json); + // console.log('Result: ', result); + + expect(result.rows[0].unlocked_period_count).to.equal(3); + expect(result.rows[0].remaining_locked_amount).to.equal(3990336729649387); + + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + //wait for unlock 4 + it(`Waiting for unlock 4 of 6`, async () => { + console.log(" waiting ",lockdurationseconds," seconds") + }) + + it(` wait for lock period`, async () => { + try { + wait(lockdurationseconds * 1000) + } catch (err) { + console.log('Error', err) + } + }) + + it(`Success, vote for producers.`, async () => { + + try { + const result = await locksdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + producers: ["bp1@dapixdev"], + fio_address: newFioAddress, + actor: accountnm, + max_fee: config.maxFee + } + }) + // console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log("ERROR: ", err) + } + }) + + //check that 18.8% was unlocked. + it(`Call get_table_rows from lockedtokens and confirm: unlocked amount`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'lockedtokens', + lower_bound: accountnm, + upper_bound: accountnm, + key_type: 'i64', + index_position: '1' + } + result = await callFioApi("get_table_rows", json); + // console.log('Result: ', result); + + expect(result.rows[0].unlocked_period_count).to.equal(4); + expect(result.rows[0].remaining_locked_amount).to.equal(2660224486449387); + + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + //wait for unlock 5 + it(`Waiting for unlock 5 of 6`, async () => { + console.log(" waiting ",lockdurationseconds," seconds") + }) + + it(` wait for lock period`, async () => { + try { + wait(lockdurationseconds * 1000) + } catch (err) { + console.log('Error', err) + } + }) + + it(`Success, vote for producers.`, async () => { + + try { + const result = await locksdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + producers: ["bp1@dapixdev"], + fio_address: newFioAddress, + actor: accountnm, + max_fee: config.maxFee + } + }) + // console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log("ERROR: ", err) + } + }) + + //check that 18.8% was unlocked. + it(`Call get_table_rows from lockedtokens and confirm: unlocked amount`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'lockedtokens', + lower_bound: accountnm, + upper_bound: accountnm, + key_type: 'i64', + index_position: '1' + } + result = await callFioApi("get_table_rows", json); + // console.log('Result: ', result); + + expect(result.rows[0].unlocked_period_count).to.equal(5); + expect(result.rows[0].remaining_locked_amount).to.equal(1330112243249387); + + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + //wait for unlock 6 + it(`Waiting for unlock 6 of 6`, async () => { + console.log(" waiting ",lockdurationseconds," seconds") + }) + + it(` wait for lock period`, async () => { + try { + wait(lockdurationseconds * 1000) + } catch (err) { + console.log('Error', err) + } + }) + + it(`Success, vote for producers.`, async () => { + + try { + const result = await locksdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + producers: ["bp1@dapixdev"], + fio_address: newFioAddress, + actor: accountnm, + max_fee: config.maxFee + } + }) + // console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log("ERROR: ", err) + } + }) + + //check that 18.8% was unlocked. + it(`Call get_table_rows from lockedtokens and confirm: unlocked amount`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'lockedtokens', + lower_bound: accountnm, + upper_bound: accountnm, + key_type: 'i64', + index_position: '1' + } + result = await callFioApi("get_table_rows", json); + // console.log('Result: ', result); + + expect(result.rows[0].unlocked_period_count).to.equal(6); + expect(result.rows[0].remaining_locked_amount).to.equal(49387); + + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Success, vote for producers.`, async () => { + + try { + const result = await locksdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + producers: ["bp2@dapixdev"], + fio_address: newFioAddress, + actor: accountnm, + max_fee: config.maxFee + } + }) + // console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log("ERROR: ", err) + } + }) + + it(`Call get_table_rows from lockedtokens and confirm: unlocked amount doesnt change`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'lockedtokens', + lower_bound: accountnm, + upper_bound: accountnm, + key_type: 'i64', + index_position: '1' + } + result = await callFioApi("get_table_rows", json); + // console.log('Result: ', result); + + expect(result.rows[0].unlocked_period_count).to.equal(6); + expect(result.rows[0].remaining_locked_amount).to.equal(49387); + + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + +}) + +describe(`************************** stake-mainet-locked-tokens.js ************************** \n A. Create large grant verify unlocking with skipped periods using voting \n also verify voting power is correct after 3rd unlock period`, () => { + + let userA1, prevFundsAmount, locksdk, keys, accountnm,newFioDomain, newFioAddress + const fundsAmount = 1000000000000 + const lockdurationseconds = 60 + + + it(`Create users`, async () => { + try { + userA1 = await newUser(faucet); + + keys = await createKeypair(); + console.log("priv key ", keys.privateKey); + console.log("pub key ", keys.publicKey); + accountnm = await getAccountFromKey(keys.publicKey); + console.log(" account ",accountnm); + let accountnm1 = await getAccountFromKey(faucet.publicKey); + //console.log("faucet account ", accountnm1 ); + + + const result = await faucet.genericAction('transferTokens', { + payeeFioPublicKey: keys.publicKey, + amount: 7075065123456789, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + + // console.log(result) + + expect(result.status).to.equal('OK') + + + const result1 = await userA1.sdk.genericAction('pushTransaction', { + action: 'addlocked', + account: 'eosio', + data: { + owner : accountnm, + amount: 7075065123456789, + locktype: 1 + } + }) + //console.log(result1) + expect(result1.status).to.equal('OK') + + locksdk = new FIOSDK(keys.privateKey, keys.publicKey, config.BASE_URL, fetchJson); + } catch (err) { + console.log('Error setting up lock account: ', err) + //expect(err.json.fields[0].error).to.contain(config.error.insufficientBalance) + } + + }) + + it(`getFioBalance for genesis lock token holder, available balance bug `, async () => { + try { + const result = await locksdk.genericAction('getFioBalance', { }) + prevFundsAmount = result.balance + //console.log(result) + expect(result.available).to.equal(7075065123456789) + } catch (err) { + // console.log(' Error: ', err) + expect(err.json.fields[0].error).to.contain(config.error.insufficientBalance) + } + }) + + it(`Failure test Transfer 700 FIO to userA1 FIO public key, insufficient balance tokens locked`, async () => { + try { + const result = await locksdk.genericAction('transferTokens', { + payeeFioPublicKey: userA1.publicKey, + amount: 700000000000, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + expect(result.status).to.not.equal('OK') + } catch (err) { + // console.log('Error: ', err) + expect(err.json.fields[0].error).to.contain(config.error.insufficientBalance) + } + }) + + //wait for unlock 3 + it(`Waiting for unlock 3 of 6, this is 3 minutes`, async () => { + console.log(" waiting ",lockdurationseconds * 3," seconds") + }) + + it(` wait for lock period`, async () => { + try { + wait(lockdurationseconds * 1000 * 3) + } catch (err) { + console.log('Error', err) + } + }) + + it(`Success, vote for producers.`, async () => { + + try { + const result = await locksdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + producers: ["bp1@dapixdev"], + fio_address: newFioAddress, + actor: accountnm, + max_fee: config.maxFee + } + }) + // console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log("ERROR: ", err) + } + }) + + it(`Call get_table_rows from locked tokens and confirm: unlocked amount`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'lockedtokens', + lower_bound: accountnm, + upper_bound: accountnm, + key_type: 'i64', + index_position: '1' + } + result = await callFioApi("get_table_rows", json); + // console.log('Result: ', result); + + expect(result.rows[0].unlocked_period_count).to.equal(3); + expect(result.rows[0].remaining_locked_amount).to.equal(3990336729639387); + + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + + it('Confirm voters record: ', async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + limit: 1000, + reverse: false, + show_payer: false + } + voters = await callFioApi("get_table_rows", json); + //console.log('voters: ', voters); + for (voter in voters.rows) { + if (voters.rows[voter].owner == accountnm) { + // console.log('voters.rows[voter]: ', voters.rows[voter]); + break; + } + } + + + expect(voters.rows[voter].last_vote_weight).to.equal('3084728393817402.00000000000000000'); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + + //wait for unlock 6 + it(`Waiting for unlock 6 of 6, 3 minutes`, async () => { + console.log(" waiting ",lockdurationseconds * 3," seconds") + }) + + it(` wait for lock period`, async () => { + try { + wait(lockdurationseconds * 1000 * 3) + } catch (err) { + console.log('Error', err) + } + }) + + it(`Success, vote for producers.`, async () => { + + try { + const result = await locksdk.genericAction('pushTransaction', { + action: 'voteproducer', + account: 'eosio', + data: { + producers: ["bp1@dapixdev"], + fio_address: newFioAddress, + actor: accountnm, + max_fee: config.maxFee + } + }) + // console.log('Result: ', result) + expect(result.status).to.equal('OK') + } catch (err) { + console.log("ERROR: ", err) + } + }) + + //check that 18.8% was unlocked. + it(`Call get_table_rows from lockedtokens and confirm: unlocked amount has dust bug`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'lockedtokens', + lower_bound: accountnm, + upper_bound: accountnm, + key_type: 'i64', + index_position: '1' + } + result = await callFioApi("get_table_rows", json); + // console.log('Result: ', result); + + expect(result.rows[0].unlocked_period_count).to.equal(6); + expect(result.rows[0].remaining_locked_amount).to.equal(19387); + + } catch (err) { + // console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) + +describe(`************************** stake-mainet-locked-tokens.js ************************** \n A. Create large grant verify unlocking using transfer`, () => { + + let userA1, prevFundsAmount, locksdk, keys, accountnm,newFioDomain, newFioAddress + const fundsAmount = 1000000000000 + const lockdurationseconds = 60 + + + it(`Create users`, async () => { + userA1 = await newUser(faucet); + + keys = await createKeypair(); + console.log("priv key ", keys.privateKey); + console.log("pub key ", keys.publicKey); + accountnm = await getAccountFromKey(keys.publicKey); + console.log(" account ",accountnm); + + + const result = await faucet.genericAction('transferTokens', { + payeeFioPublicKey: keys.publicKey, + amount: 7075065123456789, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + expect(result.status).to.equal('OK') + + + const result1 = await userA1.sdk.genericAction('pushTransaction', { + action: 'addlocked', + account: 'eosio', + data: { + owner : accountnm, + amount: 7075065123456789, + locktype: 1 + } + }) + expect(result1.status).to.equal('OK') + + locksdk = new FIOSDK(keys.privateKey, keys.publicKey, config.BASE_URL, fetchJson); + + }) + + it(`getFioBalance for genesis lock token holder, available balance bug `, async () => { + const result = await locksdk.genericAction('getFioBalance', { }) + prevFundsAmount = result.balance + expect(result.available).to.equal(7075065123456789) + }) + + it(`Failure test Transfer 700 FIO to userA1 FIO public key, insufficient balance tokens locked`, async () => { + try { + const result = await locksdk.genericAction('transferTokens', { + payeeFioPublicKey: userA1.publicKey, + amount: 700000000000, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + expect(result.status).to.not.equal('OK') + } catch (err) { + // console.log('Error: ', err) + expect(err.json.fields[0].error).to.contain(config.error.insufficientBalance) + } + }) + + //wait for unlock 1 + it(`Waiting for unlock 1 of 6`, async () => { + console.log(" waiting ",lockdurationseconds," seconds") + }) + + it(` wait for lock period`, async () => { + try { + wait(lockdurationseconds * 1000) + } catch (err) { + console.log('Error', err) + } + }) + + it(`Success, Transfer 1 FIO to userA1 FIO public key`, async () => { + + try { + const result = await locksdk.genericAction('transferTokens', { + payeeFioPublicKey: userA1.publicKey, + amount: 1000000000, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + expect(result.status).to.equal('OK') + }catch (err){ + console.log("ERROR: ", err) + } + }) + + //check that 6% was unlocked. + it(`Call get_table_rows from lockedtokens and confirm: unlocked amount`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'lockedtokens', + lower_bound: accountnm, + upper_bound: accountnm, + key_type: 'i64', + index_position: '1' + } + result = await callFioApi("get_table_rows", json); + // console.log('Result: ', result); + + expect(result.rows[0].unlocked_period_count).to.equal(1); + expect(result.rows[0].remaining_locked_amount).to.equal(6650559216049387); + + + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + + //wait for unlock 2 + it(`Waiting for unlock 2 of 6`, async () => { + console.log(" waiting ",lockdurationseconds," seconds") + }) + + it(` wait for lock period`, async () => { + try { + wait(lockdurationseconds * 1000) + } catch (err) { + console.log('Error', err) + } + }) + + it(`Success, Transfer 1 FIO to userA1 FIO public key`, async () => { + + try { + const result = await locksdk.genericAction('transferTokens', { + payeeFioPublicKey: userA1.publicKey, + amount: 1000000000, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + expect(result.status).to.equal('OK') + }catch (err){ + console.log("ERROR: ", err) + } + }) + + //check that 18.8% was unlocked. + it(`Call get_table_rows from lockedtokens and confirm: unlocked amount`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'lockedtokens', + lower_bound: accountnm, + upper_bound: accountnm, + key_type: 'i64', + index_position: '1' + } + result = await callFioApi("get_table_rows", json); + // console.log('Result: ', result); + + expect(result.rows[0].unlocked_period_count).to.equal(2); + expect(result.rows[0].remaining_locked_amount).to.equal(5320446972849387); + + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + //wait for unlock 3 + it(`Waiting for unlock 3 of 6`, async () => { + console.log(" waiting ",lockdurationseconds," seconds") + }) + + it(` wait for lock period`, async () => { + try { + wait(lockdurationseconds * 1000) + } catch (err) { + console.log('Error', err) + } + }) + + it(`Success, Transfer 1 FIO to userA1 FIO public key`, async () => { + + try { + const result = await locksdk.genericAction('transferTokens', { + payeeFioPublicKey: userA1.publicKey, + amount: 1000000000, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + expect(result.status).to.equal('OK') + }catch (err){ + console.log("ERROR: ", err) + } + }) + + //check that 18.8% was unlocked. + it(`Call get_table_rows from lockedtokens and confirm: unlocked amount`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'lockedtokens', + lower_bound: accountnm, + upper_bound: accountnm, + key_type: 'i64', + index_position: '1' + } + result = await callFioApi("get_table_rows", json); + //console.log('Result: ', result); + + expect(result.rows[0].unlocked_period_count).to.equal(3); + expect(result.rows[0].remaining_locked_amount).to.equal(3990334729649387); + + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + //wait for unlock 4 + it(`Waiting for unlock 4 of 6`, async () => { + console.log(" waiting ",lockdurationseconds," seconds") + }) + + it(` wait for lock period`, async () => { + try { + wait(lockdurationseconds * 1000) + } catch (err) { + console.log('Error', err) + } + }) + + it(`Success, Transfer 1 FIO to userA1 FIO public key`, async () => { + + try { + const result = await locksdk.genericAction('transferTokens', { + payeeFioPublicKey: userA1.publicKey, + amount: 1000000000, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + expect(result.status).to.equal('OK') + }catch (err){ + console.log("ERROR: ", err) + } + }) + + //check that 18.8% was unlocked. + it(`Call get_table_rows from lockedtokens and confirm: unlocked amount`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'lockedtokens', + lower_bound: accountnm, + upper_bound: accountnm, + key_type: 'i64', + index_position: '1' + } + result = await callFioApi("get_table_rows", json); + // console.log('Result: ', result); + + expect(result.rows[0].unlocked_period_count).to.equal(4); + expect(result.rows[0].remaining_locked_amount).to.equal(2660222486449387); + + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + //wait for unlock 5 + it(`Waiting for unlock 5 of 6`, async () => { + console.log(" waiting ",lockdurationseconds," seconds") + }) + + it(` wait for lock period`, async () => { + try { + wait(lockdurationseconds * 1000) + } catch (err) { + console.log('Error', err) + } + }) + + it(`Success, Transfer 1 FIO to userA1 FIO public key`, async () => { + + try { + const result = await locksdk.genericAction('transferTokens', { + payeeFioPublicKey: userA1.publicKey, + amount: 1000000000, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + expect(result.status).to.equal('OK') + }catch (err){ + console.log("ERROR: ", err) + } + }) + + //check that 18.8% was unlocked. + it(`Call get_table_rows from lockedtokens and confirm: unlocked amount`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'lockedtokens', + lower_bound: accountnm, + upper_bound: accountnm, + key_type: 'i64', + index_position: '1' + } + result = await callFioApi("get_table_rows", json); + // console.log('Result: ', result); + + expect(result.rows[0].unlocked_period_count).to.equal(5); + expect(result.rows[0].remaining_locked_amount).to.equal(1330110243249387); + + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + //wait for unlock 6 + it(`Waiting for unlock 6 of 6`, async () => { + console.log(" waiting ",lockdurationseconds," seconds") + }) + + it(` wait for lock period`, async () => { + try { + wait(lockdurationseconds * 1000) + } catch (err) { + console.log('Error', err) + } + }) + + it(`Success, Transfer 1 FIO to userA1 FIO public key`, async () => { + + try { + const result = await locksdk.genericAction('transferTokens', { + payeeFioPublicKey: userA1.publicKey, + amount: 1000000000, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + expect(result.status).to.equal('OK') + }catch (err){ + console.log("ERROR: ", err) + } + }) + + //check that 18.8% was unlocked. + it(`Call get_table_rows from lockedtokens and confirm: unlocked amount`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'lockedtokens', + lower_bound: accountnm, + upper_bound: accountnm, + key_type: 'i64', + index_position: '1' + } + result = await callFioApi("get_table_rows", json); + // console.log('Result: ', result); + + expect(result.rows[0].unlocked_period_count).to.equal(6); + expect(result.rows[0].remaining_locked_amount).to.equal(0); + + } catch (err) { + // console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) + +describe(`************************** stake-mainet-locked-tokens.js ************************** \n A. Create large grant verify unlocking with skipped periods using transfer`, () => { + + let userA1, prevFundsAmount, locksdk, keys, accountnm,newFioDomain, newFioAddress + const fundsAmount = 1000000000000 + const lockdurationseconds = 60 + + + it(`Create users`, async () => { + userA1 = await newUser(faucet); + + keys = await createKeypair(); + console.log("priv key ", keys.privateKey); + console.log("pub key ", keys.publicKey); + accountnm = await getAccountFromKey(keys.publicKey); + console.log(" account ",accountnm); + + + const result = await faucet.genericAction('transferTokens', { + payeeFioPublicKey: keys.publicKey, + amount: 7075065123456789, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + expect(result.status).to.equal('OK') + + + const result1 = await userA1.sdk.genericAction('pushTransaction', { + action: 'addlocked', + account: 'eosio', + data: { + owner : accountnm, + amount: 7075065123456789, + locktype: 1 + } + }) + expect(result1.status).to.equal('OK') + + locksdk = new FIOSDK(keys.privateKey, keys.publicKey, config.BASE_URL, fetchJson); + + }) + + it(`getFioBalance for genesis lock token holder, available balance 0 `, async () => { + const result = await locksdk.genericAction('getFioBalance', { }) + prevFundsAmount = result.balance + expect(result.available).to.equal(7075065123456789) + }) + + it(`Failure test Transfer 700 FIO to userA1 FIO public key, insufficient balance tokens locked`, async () => { + try { + const result = await locksdk.genericAction('transferTokens', { + payeeFioPublicKey: userA1.publicKey, + amount: 700000000000, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + expect(result.status).to.not.equal('OK') + } catch (err) { + // console.log('Error: ', err) + expect(err.json.fields[0].error).to.contain(config.error.insufficientBalance) + } + }) + + //wait for unlock 3 + it(`Waiting for unlock 3 of 6`, async () => { + console.log(" waiting ",lockdurationseconds * 3," seconds") + }) + + it(` wait for lock period`, async () => { + try { + wait(lockdurationseconds * 1000 * 3) + } catch (err) { + console.log('Error', err) + } + }) + + it(`Success, Transfer 1 FIO to userA1 FIO public key`, async () => { + + try { + const result = await locksdk.genericAction('transferTokens', { + payeeFioPublicKey: userA1.publicKey, + amount: 1000000000, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + expect(result.status).to.equal('OK') + }catch (err){ + console.log("ERROR: ", err) + } + }) + + //check that 18.8% was unlocked. + it(`Call get_table_rows from lockedtokens and confirm: unlocked amount`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'lockedtokens', + lower_bound: accountnm, + upper_bound: accountnm, + key_type: 'i64', + index_position: '1' + } + result = await callFioApi("get_table_rows", json); + //console.log('Result: ', result); + + expect(result.rows[0].unlocked_period_count).to.equal(3); + expect(result.rows[0].remaining_locked_amount).to.equal(3990334729639387); + + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + + //wait for unlock 6 + it(`Waiting for unlock 6 of 6`, async () => { + console.log(" waiting ",lockdurationseconds * 3," seconds") + }) + + it(` wait for lock period`, async () => { + try { + wait(lockdurationseconds * 1000 * 3) + } catch (err) { + console.log('Error', err) + } + }) + + it(`Success, Transfer 1 FIO to userA1 FIO public key`, async () => { + + try { + const result = await locksdk.genericAction('transferTokens', { + payeeFioPublicKey: userA1.publicKey, + amount: 1000000000, + maxFee: config.api.transfer_tokens_pub_key.fee, + technologyProviderId: '' + }) + expect(result.status).to.equal('OK') + }catch (err){ + console.log("ERROR: ", err) + } + }) + + //check that 18.8% was unlocked. + it(`Call get_table_rows from lockedtokens and confirm: unlocked amount with dust bug`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'lockedtokens', + lower_bound: accountnm, + upper_bound: accountnm, + key_type: 'i64', + index_position: '1' + } + result = await callFioApi("get_table_rows", json); + // console.log('Result: ', result); + + expect(result.rows[0].unlocked_period_count).to.equal(6); + expect(result.rows[0].remaining_locked_amount).to.equal(0); + + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + +}) From 803ab650c7742ac28b137d4b1a31de32ea589710 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Fri, 9 Jul 2021 06:55:04 -0600 Subject: [PATCH 75/76] Genesis lock test updates --- tests/mainnet-locked-tokens.js | 462 +++++++++++++++++++-------------- 1 file changed, 270 insertions(+), 192 deletions(-) diff --git a/tests/mainnet-locked-tokens.js b/tests/mainnet-locked-tokens.js index ff45438e..5842289b 100644 --- a/tests/mainnet-locked-tokens.js +++ b/tests/mainnet-locked-tokens.js @@ -1,7 +1,8 @@ require('mocha') const {expect} = require('chai') const {newUser, existingUser,callFioApi,fetchJson, generateFioDomain, getAccountFromKey, generateFioAddress, createKeypair} = require('../utils.js'); -const {FIOSDK } = require('@fioprotocol/fiosdk') +const {FIOSDK } = require('@fioprotocol/fiosdk'); +const { createNull } = require('typescript'); config = require('../config.js'); before(async () => { @@ -15,109 +16,191 @@ function wait(ms){ end = new Date().getTime(); } } -// To test genesis locks. please modify the following 2 files in the fio.contracts repository, to enable them -// to be placed into "test mode" -// -// First, shorten the main net locking period to become 1 minute, -// do this by commenting out the following lines in the fio.token.hpp computeremaininglockedtokens method. +/* + To test genesis locks. please modify the following 2 files in the fio.contracts repository, to enable them + to be placed into "test mode" -// TESTING ONLY!!! comment out genesis locking periods..DO NOT DELIVER THIS -/* uint32_t daysSinceGrant = (int) ((present_time - lockiter->timestamp) / SECONDSPERDAY); - uint32_t firstPayPeriod = 90; - uint32_t payoutTimePeriod = 180; - */ + 1. Shorten the main net locking period to become 1 minute + + In: fio.token.hpp + + Comment out the following lines in the computeremaininglockedtokens method: -// then add the following code beneath what you commented out. + //uint32_t daysSinceGrant = (int) ((present_time - lockiter->timestamp) / SECONDSPERDAY); + //uint32_t firstPayPeriod = 90; + //uint32_t payoutTimePeriod = 180; -//TEST LOCKED TOKENS -// TESTING ONLY!!! shorten genesis locking periods..DO NOT DELIVER THIS -// uint32_t daysSinceGrant = (int)((present_time - lockiter->timestamp) / 60); -// uint32_t firstPayPeriod = 1; -// uint32_t payoutTimePeriod = 1; + Then add the following code beneath what you commented out. -//next permit anyone to call the addlocked action in the system contract. -// do this by commenting out the following line in the addlocked action of the fio.system.cpp file + // TESTING ONLY!!! shorten genesis locking periods..DO NOT DELIVER THIS + uint32_t daysSinceGrant = (int)((present_time - lockiter->timestamp) / 60); + uint32_t firstPayPeriod = 1; + uint32_t payoutTimePeriod = 1; -// // require_auth(_self); + 2. Permit anyone to call the addlocked action in the system contract. -//add a return status, so that tests can run successfully at the end of the action. -// const string response_string = string("{"status": "OK"}"); -// send_response(response_string.c_str()); + In: fio.system.cpp + Comment out the following line in the addlocked action of the fio.system.cpp file -//next modify the faucet to have more tokens -//08_token_issue.sh – modify the amount of tokens in the faucet to permit large grants. -// ./clio -u http://localhost:8879 push action -j fio.token issue '["qhh25sqpktwh","100000000.000000000 FIO","memo"]' -p eosio@active + // require_auth(_self); -// after making these modifications rebuild the contracts locally and restart your chain. -// hou may then proceed with genesis locks testing. + Next, add the following to the end of the addlocked action. This creates a return status + so that tests can run successfully. -// + const string response_string = string("{\"status\": \"OK\"}"); + send_response(response_string.c_str()); -describe(`************************** mainet-locked-tokens.js ************************** \n A. Create large grant verify unlocking using voting \n also test error cant transfer more than unlocked amount\n also test multiple calls to voting do not have effect.`, () => { + 3. Modify the faucet to have more tokens. - let userA1, prevFundsAmount, locksdk, keys, accountnm,newFioDomain, newFioAddress - const fundsAmount = 1000000000000 - const lockdurationseconds = 60 + In: fio.devtools 08_token_issue.sh + + Modify the following line to increase the amount of tokens in the faucet to permit large grants. + ./clio -u http://localhost:8879 push action -j fio.token issue '["qhh25sqpktwh","100000000.000000000 FIO","memo"]' -p eosio@active - it(`Create users`, async () => { - userA1 = await newUser(faucet); - keys = await createKeypair(); + 4. After making these modifications rebuild the contracts and restart your chain. - accountnm = await getAccountFromKey(keys.publicKey); - console.log("priv key ", keys.privateKey); - console.log("pub key ", keys.publicKey); - console.log(" account ",accountnm); + The token unlock schedule for Type 1 mainnet/genesis tokens: - const result = await faucet.genericAction('transferTokens', { - payeeFioPublicKey: keys.publicKey, - amount: 7075065123456789, - maxFee: config.api.transfer_tokens_pub_key.fee, - technologyProviderId: '' - }) - expect(result.status).to.equal('OK') + Day 0: 0.00% + Day 90: 6.00% (period 1) + Day 270: 18.80% (period 2) + Day 450: 18.80% (period 3) + Day 630: 18.80% (period 4) + Day 810: 18.80% (period 5) + Day 990: 18.80% (period 1) +*/ - const result1 = await userA1.sdk.genericAction('pushTransaction', { - action: 'addlocked', - account: 'eosio', - data: { - owner : accountnm, - amount: 7075065123456789, - locktype: 1 +describe.only(`************************** mainet-locked-tokens.js ************************** \n A. Create large grant verify unlocking using voting \n also test error cant transfer more than unlocked amount\n also test multiple calls to voting do not have effect.`, () => { + + let userA1, prevFundsAmount, lockAccount, newFioAddress + const lockdurationseconds = 60, + //lockAmount = 7075065123456789 + lockAmount = 100000000000, // 100 FIO + testTransferAmount = 50000000000, // 10 FIO + unlock1Amount = lockAmount * 0.06, + unlock2Amount = lockAmount * (0.06 + .188), + unlock3Amount = lockAmount * (0.06 + .188 + 188), + unlock4Amount = lockAmount * (0.06 + .188 + 188 + .188), + unlock5Amount = lockAmount * (0.06 + .188 + 188 + .188 + .188), + unlock6Amount = lockAmount * (0.06 + .188 + 188 + .188 + .188 + .188) + + + + it(`Create lockAccount user`, async () => { + userA1 = await newUser(faucet); + + lockAccount = await createKeypair(); + + lockAccount.account = await getAccountFromKey(keys.publicKey); + console.log("lockAccount priv key: ", lockAccount.privateKey); + console.log("lockAccount pub key: ", lockAccount.publicKey); + console.log("lockAccount account: ", lockAccount.account); + + lockAccount.sdk = new FIOSDK(lockAccount.privateKey, lockAccount.publicKey, config.BASE_URL, fetchJson); + }) + + it(`Transfer ${lockAmount} SUFs to lockAccount `, async () => { + try { + const result = await faucet.genericAction('transferTokens', { + payeeFioPublicKey: lockAccount.publicKey, + amount: lockAmount, + maxFee: config.maxFee, + technologyProviderId: '' + }) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error', err.json); + expect(err).to.equal(null); + } + }) + + it(`Add ${lockAmount} Type 1 locked tokens to lockAccount `, async () => { + try { + const result1 = await userA1.sdk.genericAction('pushTransaction', { + action: 'addlocked', + account: 'eosio', + data: { + owner : lockAccount.account, + amount: lockAmount, + locktype: 1 + } + }) + expect(result1.status).to.equal('OK') + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Call get_table_rows from lockedtokens. Expect: remaining_locked_amount = ${lockAmount}`, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'lockedtokens', + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, + key_type: 'i64', + index_position: '1' } - }) - expect(result1.status).to.equal('OK') + result = await callFioApi("get_table_rows", json); + console.log('Result: ', result); - locksdk = new FIOSDK(keys.privateKey, keys.publicKey, config.BASE_URL, fetchJson); + expect(result.rows[0].unlocked_period_count).to.equal(0); + expect(result.rows[0].remaining_locked_amount).to.equal(lockAmount); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } }) - it(`getFioBalance for genesis lock token holder, available balance 0 `, async () => { - const result = await locksdk.genericAction('getFioBalance', { }) + it(`getFioBalance for lockAccount genesis lock token holder. Expect: available balance = 0 `, async () => { + try { + const result = await lockAccount.sdk.genericAction('getFioBalance', {}) + console.log('Result: ', result); prevFundsAmount = result.balance - expect(result.available).to.equal(7075065123456789) + expect(result.balance).to.equal(lockAmount); + //expect(result.available).to.equal(0); // Known bug in 3.0.1 + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null); + } }) - it(`Failure test Transfer 700 FIO to userA1 FIO public key, insufficient balance tokens locked`, async () => { + it(`Failure test - Transfer ${testTransferAmount} SUFs from lockAccount to userA1 FIO public key, insufficient balance tokens locked`, async () => { try { - const result = await locksdk.genericAction('transferTokens', { + const result = await lockAccount.sdk.genericAction('transferTokens', { payeeFioPublicKey: userA1.publicKey, - amount: 700000000000, - maxFee: config.api.transfer_tokens_pub_key.fee, + amount: testTransferAmount, + maxFee: config.maxFee, technologyProviderId: '' }) expect(result.status).to.not.equal('OK') } catch (err) { - // console.log('Error: ', err) + console.log('Error: ', err) expect(err.json.fields[0].error).to.contain(config.error.insufficientBalance) } }) + it(`getFioBalance for lockAccount genesis lock token holder. Expect: balance = ${lockAmount} `, async () => { + try { + const result = await lockAccount.sdk.genericAction('getFioBalance', {}) + console.log('Result: ', result); + expect(result.balance).to.equal(lockAmount); + } catch (err) { + console.log('Error: ', err) + expect(err).to.equal(null); + } + }) + //wait for unlock 1 it(`Waiting for unlock 1 of 6`, async () => { console.log(" waiting ",lockdurationseconds," seconds") @@ -127,27 +210,28 @@ describe(`************************** mainet-locked-tokens.js ******************* try { wait(lockdurationseconds * 1000) } catch (err) { - console.log('Error', err) + console.log('Error', err); + expect(err).to.equal(null); } }) it(`Success, vote for producers.`, async () => { - try { - const result = await locksdk.genericAction('pushTransaction', { + const result = await lockAccount.sdk.genericAction('pushTransaction', { action: 'voteproducer', account: 'eosio', data: { producers: ["bp1@dapixdev"], fio_address: newFioAddress, - actor: accountnm, + actor: lockAccount.account, max_fee: config.maxFee } }) - // console.log('Result: ', result) + console.log('Result: ', result) expect(result.status).to.equal('OK') } catch (err) { - console.log("ERROR: ", err) + console.log("ERROR: ", err); + expect(err).to.equal(null); } }) @@ -159,16 +243,16 @@ describe(`************************** mainet-locked-tokens.js ******************* code: 'eosio', scope: 'eosio', table: 'lockedtokens', - lower_bound: accountnm, - upper_bound: accountnm, + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, key_type: 'i64', index_position: '1' } result = await callFioApi("get_table_rows", json); - // console.log('Result: ', result); + console.log('Result: ', result); expect(result.rows[0].unlocked_period_count).to.equal(1); - expect(result.rows[0].remaining_locked_amount).to.equal(6650561216049387); + expect(result.rows[0].remaining_locked_amount).to.equal(lockAmount - unlock1Amount); } catch (err) { console.log('Error', err); @@ -177,19 +261,18 @@ describe(`************************** mainet-locked-tokens.js ******************* }) it(`Success, vote for producers.`, async () => { - try { - const result = await locksdk.genericAction('pushTransaction', { + const result = await lockAccount.sdk.genericAction('pushTransaction', { action: 'voteproducer', account: 'eosio', data: { producers: ["bp2@dapixdev"], fio_address: newFioAddress, - actor: accountnm, + actor: lockAccount.account, max_fee: config.maxFee } }) - // console.log('Result: ', result) + console.log('Result: ', result) expect(result.status).to.equal('OK') } catch (err) { console.log("ERROR: ", err) @@ -204,16 +287,16 @@ describe(`************************** mainet-locked-tokens.js ******************* code: 'eosio', scope: 'eosio', table: 'lockedtokens', - lower_bound: accountnm, - upper_bound: accountnm, + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, key_type: 'i64', index_position: '1' } result = await callFioApi("get_table_rows", json); - // console.log('Result: ', result); + console.log('Result: ', result); expect(result.rows[0].unlocked_period_count).to.equal(1); - expect(result.rows[0].remaining_locked_amount).to.equal(6650561216049387); + expect(result.rows[0].remaining_locked_amount).to.equal(lockAmount - unlock1Amount); } catch (err) { console.log('Error', err); @@ -224,16 +307,16 @@ describe(`************************** mainet-locked-tokens.js ******************* it(`Failure, Transfer 1M FIO to userA1 FIO public key`, async () => { try { - const result = await locksdk.genericAction('transferTokens', { + const result = await lockAccount.sdk.genericAction('transferTokens', { payeeFioPublicKey: userA1.publicKey, amount: 1000000000, - maxFee: config.api.transfer_tokens_pub_key.fee, + maxFee: config.maxFee, technologyProviderId: '' }) - expect(result.status).to.equal('OK') - }catch (err){ - //console.log("ERROR: ", err) - expect(err.json.fields[0].error).to.contain(config.error.insufficientBalance) + expect(result.status).to.equal(null); + } catch (err) { + console.log("ERROR: ", err); + expect(err.json.fields[0].error).to.contain(config.error.insufficientBalance); } }) @@ -253,13 +336,13 @@ describe(`************************** mainet-locked-tokens.js ******************* it(`Success, vote for producers.`, async () => { try { - const result = await locksdk.genericAction('pushTransaction', { + const result = await lockAccount.sdk.genericAction('pushTransaction', { action: 'voteproducer', account: 'eosio', data: { producers: ["bp1@dapixdev"], fio_address: newFioAddress, - actor: accountnm, + actor: lockAccount.account, max_fee: config.maxFee } }) @@ -278,16 +361,16 @@ describe(`************************** mainet-locked-tokens.js ******************* code: 'eosio', scope: 'eosio', table: 'lockedtokens', - lower_bound: accountnm, - upper_bound: accountnm, + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, key_type: 'i64', index_position: '1' } result = await callFioApi("get_table_rows", json); - // console.log('Result: ', result); + console.log('Result: ', result); expect(result.rows[0].unlocked_period_count).to.equal(2); - expect(result.rows[0].remaining_locked_amount).to.equal(5320448972849387); + expect(result.rows[0].remaining_locked_amount).to.equal(lockAmount - unlock2Amount); } catch (err) { console.log('Error', err); @@ -311,13 +394,13 @@ describe(`************************** mainet-locked-tokens.js ******************* it(`Success, vote for producers.`, async () => { try { - const result = await locksdk.genericAction('pushTransaction', { + const result = await lockAccount.sdk.genericAction('pushTransaction', { action: 'voteproducer', account: 'eosio', data: { producers: ["bp1@dapixdev"], fio_address: newFioAddress, - actor: accountnm, + actor: lockAccount.account, max_fee: config.maxFee } }) @@ -336,16 +419,16 @@ describe(`************************** mainet-locked-tokens.js ******************* code: 'eosio', scope: 'eosio', table: 'lockedtokens', - lower_bound: accountnm, - upper_bound: accountnm, + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, key_type: 'i64', index_position: '1' } result = await callFioApi("get_table_rows", json); - // console.log('Result: ', result); + console.log('Result: ', result); expect(result.rows[0].unlocked_period_count).to.equal(3); - expect(result.rows[0].remaining_locked_amount).to.equal(3990336729649387); + expect(result.rows[0].remaining_locked_amount).to.equal(lockAmount - unlock2Amount); } catch (err) { console.log('Error', err); @@ -369,13 +452,13 @@ describe(`************************** mainet-locked-tokens.js ******************* it(`Success, vote for producers.`, async () => { try { - const result = await locksdk.genericAction('pushTransaction', { + const result = await lockAccount.sdk.genericAction('pushTransaction', { action: 'voteproducer', account: 'eosio', data: { producers: ["bp1@dapixdev"], fio_address: newFioAddress, - actor: accountnm, + actor: lockAccount.account, max_fee: config.maxFee } }) @@ -394,8 +477,8 @@ describe(`************************** mainet-locked-tokens.js ******************* code: 'eosio', scope: 'eosio', table: 'lockedtokens', - lower_bound: accountnm, - upper_bound: accountnm, + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, key_type: 'i64', index_position: '1' } @@ -403,7 +486,7 @@ describe(`************************** mainet-locked-tokens.js ******************* // console.log('Result: ', result); expect(result.rows[0].unlocked_period_count).to.equal(4); - expect(result.rows[0].remaining_locked_amount).to.equal(2660224486449387); + expect(result.rows[0].remaining_locked_amount).to.equal(lockAmount - unlock4Amount); } catch (err) { console.log('Error', err); @@ -427,13 +510,13 @@ describe(`************************** mainet-locked-tokens.js ******************* it(`Success, vote for producers.`, async () => { try { - const result = await locksdk.genericAction('pushTransaction', { + const result = await lockAccount.sdk.genericAction('pushTransaction', { action: 'voteproducer', account: 'eosio', data: { producers: ["bp1@dapixdev"], fio_address: newFioAddress, - actor: accountnm, + actor: lockAccount.account, max_fee: config.maxFee } }) @@ -452,8 +535,8 @@ describe(`************************** mainet-locked-tokens.js ******************* code: 'eosio', scope: 'eosio', table: 'lockedtokens', - lower_bound: accountnm, - upper_bound: accountnm, + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, key_type: 'i64', index_position: '1' } @@ -461,7 +544,7 @@ describe(`************************** mainet-locked-tokens.js ******************* // console.log('Result: ', result); expect(result.rows[0].unlocked_period_count).to.equal(5); - expect(result.rows[0].remaining_locked_amount).to.equal(1330112243249387); + expect(result.rows[0].remaining_locked_amount).to.equal(lockAmount - unlock5Amount); } catch (err) { console.log('Error', err); @@ -485,13 +568,13 @@ describe(`************************** mainet-locked-tokens.js ******************* it(`Success, vote for producers.`, async () => { try { - const result = await locksdk.genericAction('pushTransaction', { + const result = await lockAccount.sdk.genericAction('pushTransaction', { action: 'voteproducer', account: 'eosio', data: { producers: ["bp1@dapixdev"], fio_address: newFioAddress, - actor: accountnm, + actor: lockAccount.account, max_fee: config.maxFee } }) @@ -510,8 +593,8 @@ describe(`************************** mainet-locked-tokens.js ******************* code: 'eosio', scope: 'eosio', table: 'lockedtokens', - lower_bound: accountnm, - upper_bound: accountnm, + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, key_type: 'i64', index_position: '1' } @@ -519,7 +602,7 @@ describe(`************************** mainet-locked-tokens.js ******************* // console.log('Result: ', result); expect(result.rows[0].unlocked_period_count).to.equal(6); - expect(result.rows[0].remaining_locked_amount).to.equal(49387); + expect(result.rows[0].remaining_locked_amount).to.equal(lockAmount - unlock6Amount); } catch (err) { console.log('Error', err); @@ -530,13 +613,13 @@ describe(`************************** mainet-locked-tokens.js ******************* it(`Success, vote for producers.`, async () => { try { - const result = await locksdk.genericAction('pushTransaction', { + const result = await lockAccount.sdk.genericAction('pushTransaction', { action: 'voteproducer', account: 'eosio', data: { producers: ["bp2@dapixdev"], fio_address: newFioAddress, - actor: accountnm, + actor: lockAccount.account, max_fee: config.maxFee } }) @@ -554,8 +637,8 @@ describe(`************************** mainet-locked-tokens.js ******************* code: 'eosio', scope: 'eosio', table: 'lockedtokens', - lower_bound: accountnm, - upper_bound: accountnm, + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, key_type: 'i64', index_position: '1' } @@ -563,7 +646,7 @@ describe(`************************** mainet-locked-tokens.js ******************* // console.log('Result: ', result); expect(result.rows[0].unlocked_period_count).to.equal(6); - expect(result.rows[0].remaining_locked_amount).to.equal(49387); + expect(result.rows[0].remaining_locked_amount).to.equal(lockAmount - unlock6Amount); } catch (err) { console.log('Error', err); @@ -574,9 +657,10 @@ describe(`************************** mainet-locked-tokens.js ******************* }) -describe(`************************** stake-mainet-locked-tokens.js ************************** \n A. Create large grant verify unlocking with skipped periods using voting \n also verify voting power is correct after 3rd unlock period`, () => { +/* +describe(`B. Create large grant verify unlocking with skipped periods using voting \n also verify voting power is correct after 3rd unlock period`, () => { - let userA1, prevFundsAmount, locksdk, keys, accountnm,newFioDomain, newFioAddress + let userA1, prevFundsAmount, lockAccount, keys, newFioAddress const fundsAmount = 1000000000000 const lockdurationseconds = 60 @@ -588,14 +672,14 @@ describe(`************************** stake-mainet-locked-tokens.js ************* keys = await createKeypair(); console.log("priv key ", keys.privateKey); console.log("pub key ", keys.publicKey); - accountnm = await getAccountFromKey(keys.publicKey); - console.log(" account ",accountnm); - let accountnm1 = await getAccountFromKey(faucet.publicKey); - //console.log("faucet account ", accountnm1 ); + lockAccount.account = await getAccountFromKey(keys.publicKey); + console.log(" account ",lockAccount.account); + let lockAccount.account1 = await getAccountFromKey(faucet.publicKey); + //console.log("faucet account ", lockAccount.account1 ); const result = await faucet.genericAction('transferTokens', { - payeeFioPublicKey: keys.publicKey, + payeeFioPublicKey: lockAccount.publicKey, amount: 7075065123456789, maxFee: config.api.transfer_tokens_pub_key.fee, technologyProviderId: '' @@ -610,7 +694,7 @@ describe(`************************** stake-mainet-locked-tokens.js ************* action: 'addlocked', account: 'eosio', data: { - owner : accountnm, + owner : lockAccount.account, amount: 7075065123456789, locktype: 1 } @@ -618,7 +702,7 @@ describe(`************************** stake-mainet-locked-tokens.js ************* //console.log(result1) expect(result1.status).to.equal('OK') - locksdk = new FIOSDK(keys.privateKey, keys.publicKey, config.BASE_URL, fetchJson); + lockAccount.sdk = new FIOSDK(lockAccount.privateKey, lockAccount.publicKey, config.BASE_URL, fetchJson); } catch (err) { console.log('Error setting up lock account: ', err) //expect(err.json.fields[0].error).to.contain(config.error.insufficientBalance) @@ -628,7 +712,7 @@ describe(`************************** stake-mainet-locked-tokens.js ************* it(`getFioBalance for genesis lock token holder, available balance bug `, async () => { try { - const result = await locksdk.genericAction('getFioBalance', { }) + const result = await lockAccount.sdk.genericAction('getFioBalance', { }) prevFundsAmount = result.balance //console.log(result) expect(result.available).to.equal(7075065123456789) @@ -640,7 +724,7 @@ describe(`************************** stake-mainet-locked-tokens.js ************* it(`Failure test Transfer 700 FIO to userA1 FIO public key, insufficient balance tokens locked`, async () => { try { - const result = await locksdk.genericAction('transferTokens', { + const result = await lockAccount.sdk.genericAction('transferTokens', { payeeFioPublicKey: userA1.publicKey, amount: 700000000000, maxFee: config.api.transfer_tokens_pub_key.fee, @@ -669,13 +753,13 @@ describe(`************************** stake-mainet-locked-tokens.js ************* it(`Success, vote for producers.`, async () => { try { - const result = await locksdk.genericAction('pushTransaction', { + const result = await lockAccount.sdk.genericAction('pushTransaction', { action: 'voteproducer', account: 'eosio', data: { producers: ["bp1@dapixdev"], fio_address: newFioAddress, - actor: accountnm, + actor: lockAccount.account, max_fee: config.maxFee } }) @@ -693,8 +777,8 @@ describe(`************************** stake-mainet-locked-tokens.js ************* code: 'eosio', scope: 'eosio', table: 'lockedtokens', - lower_bound: accountnm, - upper_bound: accountnm, + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, key_type: 'i64', index_position: '1' } @@ -718,21 +802,14 @@ describe(`************************** stake-mainet-locked-tokens.js ************* code: 'eosio', scope: 'eosio', table: 'voters', - limit: 1000, - reverse: false, - show_payer: false + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, + key_type: "name", + index_position: "3", } voters = await callFioApi("get_table_rows", json); - //console.log('voters: ', voters); - for (voter in voters.rows) { - if (voters.rows[voter].owner == accountnm) { - // console.log('voters.rows[voter]: ', voters.rows[voter]); - break; - } - } - - expect(voters.rows[voter].last_vote_weight).to.equal('3084728393817402.00000000000000000'); + expect(voters.rows[0].last_vote_weight).to.equal('3084728393817402.00000000000000000'); } catch (err) { console.log('Error', err); expect(err).to.equal(null); @@ -756,13 +833,13 @@ describe(`************************** stake-mainet-locked-tokens.js ************* it(`Success, vote for producers.`, async () => { try { - const result = await locksdk.genericAction('pushTransaction', { + const result = await lockAccount.sdk.genericAction('pushTransaction', { action: 'voteproducer', account: 'eosio', data: { producers: ["bp1@dapixdev"], fio_address: newFioAddress, - actor: accountnm, + actor: lockAccount.account, max_fee: config.maxFee } }) @@ -781,8 +858,8 @@ describe(`************************** stake-mainet-locked-tokens.js ************* code: 'eosio', scope: 'eosio', table: 'lockedtokens', - lower_bound: accountnm, - upper_bound: accountnm, + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, key_type: 'i64', index_position: '1' } @@ -800,9 +877,9 @@ describe(`************************** stake-mainet-locked-tokens.js ************* }) -describe(`************************** stake-mainet-locked-tokens.js ************************** \n A. Create large grant verify unlocking using transfer`, () => { +describe(`C. Create large grant verify unlocking using transfer`, () => { - let userA1, prevFundsAmount, locksdk, keys, accountnm,newFioDomain, newFioAddress + let userA1, prevFundsAmount, lockAccount.sdk, keys, lockAccount.account,newFioDomain, newFioAddress const fundsAmount = 1000000000000 const lockdurationseconds = 60 @@ -813,8 +890,8 @@ describe(`************************** stake-mainet-locked-tokens.js ************* keys = await createKeypair(); console.log("priv key ", keys.privateKey); console.log("pub key ", keys.publicKey); - accountnm = await getAccountFromKey(keys.publicKey); - console.log(" account ",accountnm); + lockAccount.account = await getAccountFromKey(keys.publicKey); + console.log(" account ",lockAccount.account); const result = await faucet.genericAction('transferTokens', { @@ -830,26 +907,26 @@ describe(`************************** stake-mainet-locked-tokens.js ************* action: 'addlocked', account: 'eosio', data: { - owner : accountnm, + owner : lockAccount.account, amount: 7075065123456789, locktype: 1 } }) expect(result1.status).to.equal('OK') - locksdk = new FIOSDK(keys.privateKey, keys.publicKey, config.BASE_URL, fetchJson); + lockAccount.sdk = new FIOSDK(keys.privateKey, keys.publicKey, config.BASE_URL, fetchJson); }) it(`getFioBalance for genesis lock token holder, available balance bug `, async () => { - const result = await locksdk.genericAction('getFioBalance', { }) + const result = await lockAccount.sdk.genericAction('getFioBalance', { }) prevFundsAmount = result.balance expect(result.available).to.equal(7075065123456789) }) it(`Failure test Transfer 700 FIO to userA1 FIO public key, insufficient balance tokens locked`, async () => { try { - const result = await locksdk.genericAction('transferTokens', { + const result = await lockAccount.sdk.genericAction('transferTokens', { payeeFioPublicKey: userA1.publicKey, amount: 700000000000, maxFee: config.api.transfer_tokens_pub_key.fee, @@ -878,7 +955,7 @@ describe(`************************** stake-mainet-locked-tokens.js ************* it(`Success, Transfer 1 FIO to userA1 FIO public key`, async () => { try { - const result = await locksdk.genericAction('transferTokens', { + const result = await lockAccount.sdk.genericAction('transferTokens', { payeeFioPublicKey: userA1.publicKey, amount: 1000000000, maxFee: config.api.transfer_tokens_pub_key.fee, @@ -898,8 +975,8 @@ describe(`************************** stake-mainet-locked-tokens.js ************* code: 'eosio', scope: 'eosio', table: 'lockedtokens', - lower_bound: accountnm, - upper_bound: accountnm, + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, key_type: 'i64', index_position: '1' } @@ -933,7 +1010,7 @@ describe(`************************** stake-mainet-locked-tokens.js ************* it(`Success, Transfer 1 FIO to userA1 FIO public key`, async () => { try { - const result = await locksdk.genericAction('transferTokens', { + const result = await lockAccount.sdk.genericAction('transferTokens', { payeeFioPublicKey: userA1.publicKey, amount: 1000000000, maxFee: config.api.transfer_tokens_pub_key.fee, @@ -953,8 +1030,8 @@ describe(`************************** stake-mainet-locked-tokens.js ************* code: 'eosio', scope: 'eosio', table: 'lockedtokens', - lower_bound: accountnm, - upper_bound: accountnm, + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, key_type: 'i64', index_position: '1' } @@ -986,7 +1063,7 @@ describe(`************************** stake-mainet-locked-tokens.js ************* it(`Success, Transfer 1 FIO to userA1 FIO public key`, async () => { try { - const result = await locksdk.genericAction('transferTokens', { + const result = await lockAccount.sdk.genericAction('transferTokens', { payeeFioPublicKey: userA1.publicKey, amount: 1000000000, maxFee: config.api.transfer_tokens_pub_key.fee, @@ -1006,8 +1083,8 @@ describe(`************************** stake-mainet-locked-tokens.js ************* code: 'eosio', scope: 'eosio', table: 'lockedtokens', - lower_bound: accountnm, - upper_bound: accountnm, + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, key_type: 'i64', index_position: '1' } @@ -1039,7 +1116,7 @@ describe(`************************** stake-mainet-locked-tokens.js ************* it(`Success, Transfer 1 FIO to userA1 FIO public key`, async () => { try { - const result = await locksdk.genericAction('transferTokens', { + const result = await lockAccount.sdk.genericAction('transferTokens', { payeeFioPublicKey: userA1.publicKey, amount: 1000000000, maxFee: config.api.transfer_tokens_pub_key.fee, @@ -1059,8 +1136,8 @@ describe(`************************** stake-mainet-locked-tokens.js ************* code: 'eosio', scope: 'eosio', table: 'lockedtokens', - lower_bound: accountnm, - upper_bound: accountnm, + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, key_type: 'i64', index_position: '1' } @@ -1092,7 +1169,7 @@ describe(`************************** stake-mainet-locked-tokens.js ************* it(`Success, Transfer 1 FIO to userA1 FIO public key`, async () => { try { - const result = await locksdk.genericAction('transferTokens', { + const result = await lockAccount.sdk.genericAction('transferTokens', { payeeFioPublicKey: userA1.publicKey, amount: 1000000000, maxFee: config.api.transfer_tokens_pub_key.fee, @@ -1112,8 +1189,8 @@ describe(`************************** stake-mainet-locked-tokens.js ************* code: 'eosio', scope: 'eosio', table: 'lockedtokens', - lower_bound: accountnm, - upper_bound: accountnm, + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, key_type: 'i64', index_position: '1' } @@ -1145,7 +1222,7 @@ describe(`************************** stake-mainet-locked-tokens.js ************* it(`Success, Transfer 1 FIO to userA1 FIO public key`, async () => { try { - const result = await locksdk.genericAction('transferTokens', { + const result = await lockAccount.sdk.genericAction('transferTokens', { payeeFioPublicKey: userA1.publicKey, amount: 1000000000, maxFee: config.api.transfer_tokens_pub_key.fee, @@ -1165,8 +1242,8 @@ describe(`************************** stake-mainet-locked-tokens.js ************* code: 'eosio', scope: 'eosio', table: 'lockedtokens', - lower_bound: accountnm, - upper_bound: accountnm, + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, key_type: 'i64', index_position: '1' } @@ -1184,9 +1261,9 @@ describe(`************************** stake-mainet-locked-tokens.js ************* }) -describe(`************************** stake-mainet-locked-tokens.js ************************** \n A. Create large grant verify unlocking with skipped periods using transfer`, () => { +describe(`D. Create large grant verify unlocking with skipped periods using transfer`, () => { - let userA1, prevFundsAmount, locksdk, keys, accountnm,newFioDomain, newFioAddress + let userA1, prevFundsAmount, lockAccount.sdk, keys, lockAccount.account,newFioDomain, newFioAddress const fundsAmount = 1000000000000 const lockdurationseconds = 60 @@ -1197,8 +1274,8 @@ describe(`************************** stake-mainet-locked-tokens.js ************* keys = await createKeypair(); console.log("priv key ", keys.privateKey); console.log("pub key ", keys.publicKey); - accountnm = await getAccountFromKey(keys.publicKey); - console.log(" account ",accountnm); + lockAccount.account = await getAccountFromKey(keys.publicKey); + console.log(" account ",lockAccount.account); const result = await faucet.genericAction('transferTokens', { @@ -1214,26 +1291,26 @@ describe(`************************** stake-mainet-locked-tokens.js ************* action: 'addlocked', account: 'eosio', data: { - owner : accountnm, + owner : lockAccount.account, amount: 7075065123456789, locktype: 1 } }) expect(result1.status).to.equal('OK') - locksdk = new FIOSDK(keys.privateKey, keys.publicKey, config.BASE_URL, fetchJson); + lockAccount.sdk = new FIOSDK(keys.privateKey, keys.publicKey, config.BASE_URL, fetchJson); }) it(`getFioBalance for genesis lock token holder, available balance 0 `, async () => { - const result = await locksdk.genericAction('getFioBalance', { }) + const result = await lockAccount.sdk.genericAction('getFioBalance', { }) prevFundsAmount = result.balance expect(result.available).to.equal(7075065123456789) }) it(`Failure test Transfer 700 FIO to userA1 FIO public key, insufficient balance tokens locked`, async () => { try { - const result = await locksdk.genericAction('transferTokens', { + const result = await lockAccount.sdk.genericAction('transferTokens', { payeeFioPublicKey: userA1.publicKey, amount: 700000000000, maxFee: config.api.transfer_tokens_pub_key.fee, @@ -1262,7 +1339,7 @@ describe(`************************** stake-mainet-locked-tokens.js ************* it(`Success, Transfer 1 FIO to userA1 FIO public key`, async () => { try { - const result = await locksdk.genericAction('transferTokens', { + const result = await lockAccount.sdk.genericAction('transferTokens', { payeeFioPublicKey: userA1.publicKey, amount: 1000000000, maxFee: config.api.transfer_tokens_pub_key.fee, @@ -1282,8 +1359,8 @@ describe(`************************** stake-mainet-locked-tokens.js ************* code: 'eosio', scope: 'eosio', table: 'lockedtokens', - lower_bound: accountnm, - upper_bound: accountnm, + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, key_type: 'i64', index_position: '1' } @@ -1316,7 +1393,7 @@ describe(`************************** stake-mainet-locked-tokens.js ************* it(`Success, Transfer 1 FIO to userA1 FIO public key`, async () => { try { - const result = await locksdk.genericAction('transferTokens', { + const result = await lockAccount.sdk.genericAction('transferTokens', { payeeFioPublicKey: userA1.publicKey, amount: 1000000000, maxFee: config.api.transfer_tokens_pub_key.fee, @@ -1336,8 +1413,8 @@ describe(`************************** stake-mainet-locked-tokens.js ************* code: 'eosio', scope: 'eosio', table: 'lockedtokens', - lower_bound: accountnm, - upper_bound: accountnm, + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, key_type: 'i64', index_position: '1' } @@ -1354,3 +1431,4 @@ describe(`************************** stake-mainet-locked-tokens.js ************* }) }) +*/ \ No newline at end of file From 13ce4b55771596425e2cc49398d19568250bbba5 Mon Sep 17 00:00:00 2001 From: Eric Butz Date: Mon, 12 Jul 2021 08:20:43 -0600 Subject: [PATCH 76/76] Updates to lock testing --- tests/mainnet-locked-tokens.js | 454 +++++++++++++++++++++++---------- 1 file changed, 323 insertions(+), 131 deletions(-) diff --git a/tests/mainnet-locked-tokens.js b/tests/mainnet-locked-tokens.js index 5842289b..dc2c516a 100644 --- a/tests/mainnet-locked-tokens.js +++ b/tests/mainnet-locked-tokens.js @@ -75,29 +75,38 @@ function wait(ms){ Day 990: 18.80% (period 1) */ +const unlock1Percent = 0.06, + unlock2Percent = 0.06 + .188, + unlock3Percent = 0.06 + .188 + .188, + unlock4Percent = 0.06 + .188 + .188 + .188, + unlock5Percent = 0.06 + .188 + .188 + .188 + .188, + unlock6Percent = 0.06 + .188 + .188 + .188 + .188 + .188 -describe.only(`************************** mainet-locked-tokens.js ************************** \n A. Create large grant verify unlocking using voting \n also test error cant transfer more than unlocked amount\n also test multiple calls to voting do not have effect.`, () => { + +describe(`************************** mainet-locked-tokens.js ************************** \n A. Create large grant verify unlocking using voting \n also test error cant transfer more than unlocked amount\n also test multiple calls to voting do not have effect.`, () => { let userA1, prevFundsAmount, lockAccount, newFioAddress + let numberOfVotes = 0 + + voteProdFee = config.api.vote_producer.fee + const lockdurationseconds = 60, //lockAmount = 7075065123456789 lockAmount = 100000000000, // 100 FIO - testTransferAmount = 50000000000, // 10 FIO - unlock1Amount = lockAmount * 0.06, - unlock2Amount = lockAmount * (0.06 + .188), - unlock3Amount = lockAmount * (0.06 + .188 + 188), - unlock4Amount = lockAmount * (0.06 + .188 + 188 + .188), - unlock5Amount = lockAmount * (0.06 + .188 + 188 + .188 + .188), - unlock6Amount = lockAmount * (0.06 + .188 + 188 + .188 + .188 + .188) - - + testTransferAmount = 50000000000, // 50 FIO + unlock1Amount = lockAmount * unlock1Percent, + unlock2Amount = lockAmount * unlock2Percent, + unlock3Amount = lockAmount * unlock3Percent, + unlock4Amount = lockAmount * unlock4Percent, + unlock5Amount = lockAmount * unlock5Percent, + unlock6Amount = lockAmount * unlock6Percent it(`Create lockAccount user`, async () => { userA1 = await newUser(faucet); lockAccount = await createKeypair(); - lockAccount.account = await getAccountFromKey(keys.publicKey); + lockAccount.account = await getAccountFromKey(lockAccount.publicKey); console.log("lockAccount priv key: ", lockAccount.privateKey); console.log("lockAccount pub key: ", lockAccount.publicKey); console.log("lockAccount account: ", lockAccount.account); @@ -151,7 +160,7 @@ describe.only(`************************** mainet-locked-tokens.js ************** index_position: '1' } result = await callFioApi("get_table_rows", json); - console.log('Result: ', result); + //console.log('Result: ', result); expect(result.rows[0].unlocked_period_count).to.equal(0); expect(result.rows[0].remaining_locked_amount).to.equal(lockAmount); @@ -165,7 +174,7 @@ describe.only(`************************** mainet-locked-tokens.js ************** it(`getFioBalance for lockAccount genesis lock token holder. Expect: available balance = 0 `, async () => { try { const result = await lockAccount.sdk.genericAction('getFioBalance', {}) - console.log('Result: ', result); + //console.log('Result: ', result); prevFundsAmount = result.balance expect(result.balance).to.equal(lockAmount); //expect(result.available).to.equal(0); // Known bug in 3.0.1 @@ -185,7 +194,7 @@ describe.only(`************************** mainet-locked-tokens.js ************** }) expect(result.status).to.not.equal('OK') } catch (err) { - console.log('Error: ', err) + //console.log('Error: ', err) expect(err.json.fields[0].error).to.contain(config.error.insufficientBalance) } }) @@ -193,8 +202,9 @@ describe.only(`************************** mainet-locked-tokens.js ************** it(`getFioBalance for lockAccount genesis lock token holder. Expect: balance = ${lockAmount} `, async () => { try { const result = await lockAccount.sdk.genericAction('getFioBalance', {}) - console.log('Result: ', result); + //console.log('Result: ', result); expect(result.balance).to.equal(lockAmount); + //console.log('Fee: ', voteProdFee) } catch (err) { console.log('Error: ', err) expect(err).to.equal(null); @@ -227,7 +237,8 @@ describe.only(`************************** mainet-locked-tokens.js ************** max_fee: config.maxFee } }) - console.log('Result: ', result) + //console.log('Result: ', result) + numberOfVotes += 1; expect(result.status).to.equal('OK') } catch (err) { console.log("ERROR: ", err); @@ -236,7 +247,7 @@ describe.only(`************************** mainet-locked-tokens.js ************** }) //check that 6% was unlocked. - it(`Call get_table_rows from lockedtokens and confirm: unlocked amount`, async () => { + it(`Call get_table_rows from lockedtokens. Confirm: unlocked = ${unlock1Percent}, remaining unlocked = ${lockAmount - unlock1Amount}`, async () => { try { const json = { json: true, @@ -249,7 +260,7 @@ describe.only(`************************** mainet-locked-tokens.js ************** index_position: '1' } result = await callFioApi("get_table_rows", json); - console.log('Result: ', result); + //console.log('Result: ', result); expect(result.rows[0].unlocked_period_count).to.equal(1); expect(result.rows[0].remaining_locked_amount).to.equal(lockAmount - unlock1Amount); @@ -272,7 +283,8 @@ describe.only(`************************** mainet-locked-tokens.js ************** max_fee: config.maxFee } }) - console.log('Result: ', result) + //console.log('Result: ', result) + numberOfVotes += 1; expect(result.status).to.equal('OK') } catch (err) { console.log("ERROR: ", err) @@ -293,7 +305,7 @@ describe.only(`************************** mainet-locked-tokens.js ************** index_position: '1' } result = await callFioApi("get_table_rows", json); - console.log('Result: ', result); + //console.log('Result: ', result); expect(result.rows[0].unlocked_period_count).to.equal(1); expect(result.rows[0].remaining_locked_amount).to.equal(lockAmount - unlock1Amount); @@ -304,22 +316,46 @@ describe.only(`************************** mainet-locked-tokens.js ************** } }) - it(`Failure, Transfer 1M FIO to userA1 FIO public key`, async () => { + it(`Failure, Transfer unlock1Amount + 10 FIO to userA1 FIO public key`, async () => { try { const result = await lockAccount.sdk.genericAction('transferTokens', { payeeFioPublicKey: userA1.publicKey, - amount: 1000000000, + amount: unlock1Amount + 10000000000, maxFee: config.maxFee, technologyProviderId: '' }) expect(result.status).to.equal(null); } catch (err) { - console.log("ERROR: ", err); + //console.log("ERROR: ", err); expect(err.json.fields[0].error).to.contain(config.error.insufficientBalance); } }) + it(`Confirm last_vote_weight = ${lockAmount * 0.3} (30%) `, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, + key_type: "name", + index_position: "3", + } + voters = await callFioApi("get_table_rows", json); + //console.log('Voters: ', voters); + voteWeight = Math.trunc(parseInt(voters.rows[0].last_vote_weight)); + //console.log('voteWeight: ', voteWeight); + + expect(voteWeight).to.equal(lockAmount * 0.3); // + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + //wait for unlock 2 it(`Waiting for unlock 2 of 6`, async () => { console.log(" waiting ",lockdurationseconds," seconds") @@ -347,6 +383,7 @@ describe.only(`************************** mainet-locked-tokens.js ************** } }) // console.log('Result: ', result) + numberOfVotes += 1; expect(result.status).to.equal('OK') } catch (err) { console.log("ERROR: ", err) @@ -354,7 +391,7 @@ describe.only(`************************** mainet-locked-tokens.js ************** }) //check that 18.8% was unlocked. - it(`Call get_table_rows from lockedtokens and confirm: unlocked amount`, async () => { + it(`Call get_table_rows from lockedtokens. Confirm: unlocked = ${unlock2Percent}, remaining unlocked = ${lockAmount - unlock2Amount}`, async () => { try { const json = { json: true, @@ -367,7 +404,7 @@ describe.only(`************************** mainet-locked-tokens.js ************** index_position: '1' } result = await callFioApi("get_table_rows", json); - console.log('Result: ', result); + //console.log('Result: ', result); expect(result.rows[0].unlocked_period_count).to.equal(2); expect(result.rows[0].remaining_locked_amount).to.equal(lockAmount - unlock2Amount); @@ -378,6 +415,29 @@ describe.only(`************************** mainet-locked-tokens.js ************** } }) + it(`Confirm last_vote_weight = ${lockAmount * 0.3} (30%) `, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, + key_type: "name", + index_position: "3", + } + voters = await callFioApi("get_table_rows", json); + voteWeight = Math.trunc(parseInt(voters.rows[0].last_vote_weight)); + //console.log('Voters: ', voters); + + expect(voteWeight).to.equal(lockAmount * 0.3); // + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + //wait for unlock 3 it(`Waiting for unlock 3 of 6`, async () => { console.log(" waiting ",lockdurationseconds," seconds") @@ -405,6 +465,7 @@ describe.only(`************************** mainet-locked-tokens.js ************** } }) // console.log('Result: ', result) + numberOfVotes += 1; expect(result.status).to.equal('OK') } catch (err) { console.log("ERROR: ", err) @@ -412,7 +473,7 @@ describe.only(`************************** mainet-locked-tokens.js ************** }) //check that 18.8% was unlocked. - it(`Call get_table_rows from lockedtokens and confirm: unlocked amount`, async () => { + it(`Call get_table_rows from lockedtokens. Confirm: unlocked = ${unlock3Percent}, remaining unlocked = ${lockAmount - unlock3Amount}`, async () => { try { const json = { json: true, @@ -425,11 +486,35 @@ describe.only(`************************** mainet-locked-tokens.js ************** index_position: '1' } result = await callFioApi("get_table_rows", json); - console.log('Result: ', result); + //console.log('Result: ', result); expect(result.rows[0].unlocked_period_count).to.equal(3); - expect(result.rows[0].remaining_locked_amount).to.equal(lockAmount - unlock2Amount); + expect(result.rows[0].remaining_locked_amount).to.equal(lockAmount - unlock3Amount); + + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + + it(`Confirm last_vote_weight = ${unlock3Amount} minus regprod fees? `, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, + key_type: "name", + index_position: "3", + } + voters = await callFioApi("get_table_rows", json); + voteWeight = Math.trunc(parseInt(voters.rows[0].last_vote_weight)); + //console.log('Voters: ', voters); + //console.log('fee: ', voteProdFee * numberOfVotes) + expect(voteWeight).to.equal(unlock3Amount - voteProdFee * (numberOfVotes-1)); //Not sure why it did not include all votes... } catch (err) { console.log('Error', err); expect(err).to.equal(null); @@ -463,6 +548,7 @@ describe.only(`************************** mainet-locked-tokens.js ************** } }) // console.log('Result: ', result) + numberOfVotes += 1; expect(result.status).to.equal('OK') } catch (err) { console.log("ERROR: ", err) @@ -470,7 +556,7 @@ describe.only(`************************** mainet-locked-tokens.js ************** }) //check that 18.8% was unlocked. - it(`Call get_table_rows from lockedtokens and confirm: unlocked amount`, async () => { + it(`Call get_table_rows from lockedtokens. Confirm: unlocked = ${unlock4Percent}, remaining unlocked = ${lockAmount - unlock4Amount}`, async () => { try { const json = { json: true, @@ -494,6 +580,30 @@ describe.only(`************************** mainet-locked-tokens.js ************** } }) + it(`Confirm last_vote_weight = ${unlock4Amount} minus regprod fees `, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, + key_type: "name", + index_position: "3", + } + voters = await callFioApi("get_table_rows", json); + voteWeight = Math.trunc(parseInt(voters.rows[0].last_vote_weight)); + //console.log('Voters: ', voters); + //console.log('fee: ', voteProdFee * numberOfVotes) + + expect(voteWeight).to.equal(unlock4Amount - voteProdFee * (numberOfVotes - 1)); // + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + //wait for unlock 5 it(`Waiting for unlock 5 of 6`, async () => { console.log(" waiting ",lockdurationseconds," seconds") @@ -521,6 +631,7 @@ describe.only(`************************** mainet-locked-tokens.js ************** } }) // console.log('Result: ', result) + numberOfVotes += 1; expect(result.status).to.equal('OK') } catch (err) { console.log("ERROR: ", err) @@ -528,7 +639,7 @@ describe.only(`************************** mainet-locked-tokens.js ************** }) //check that 18.8% was unlocked. - it(`Call get_table_rows from lockedtokens and confirm: unlocked amount`, async () => { + it(`Call get_table_rows from lockedtokens. Confirm: unlocked = ${unlock5Percent}, remaining unlocked = ${lockAmount - unlock5Amount}`, async () => { try { const json = { json: true, @@ -552,6 +663,30 @@ describe.only(`************************** mainet-locked-tokens.js ************** } }) + it(`Confirm last_vote_weight = ${unlock5Amount} minus regprod fees `, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, + key_type: "name", + index_position: "3", + } + voters = await callFioApi("get_table_rows", json); + voteWeight = Math.trunc(parseInt(voters.rows[0].last_vote_weight)); + //console.log('Voters: ', voters); + //console.log('fee: ', voteProdFee * numberOfVotes) + + expect(voteWeight).to.equal(unlock5Amount - voteProdFee * (numberOfVotes - 1)); + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + //wait for unlock 6 it(`Waiting for unlock 6 of 6`, async () => { console.log(" waiting ",lockdurationseconds," seconds") @@ -579,6 +714,7 @@ describe.only(`************************** mainet-locked-tokens.js ************** } }) // console.log('Result: ', result) + numberOfVotes += 1; expect(result.status).to.equal('OK') } catch (err) { console.log("ERROR: ", err) @@ -586,7 +722,7 @@ describe.only(`************************** mainet-locked-tokens.js ************** }) //check that 18.8% was unlocked. - it(`Call get_table_rows from lockedtokens and confirm: unlocked amount`, async () => { + it(`Call get_table_rows from lockedtokens. Confirm: unlocked = ${unlock6Percent}, remaining unlocked = ${lockAmount - unlock6Amount}`, async () => { try { const json = { json: true, @@ -624,6 +760,7 @@ describe.only(`************************** mainet-locked-tokens.js ************** } }) // console.log('Result: ', result) + numberOfVotes += 1; expect(result.status).to.equal('OK') } catch (err) { console.log("ERROR: ", err) @@ -654,68 +791,92 @@ describe.only(`************************** mainet-locked-tokens.js ************** } }) + it(`Confirm last_vote_weight = ${unlock6Amount} minus regprod fees `, async () => { + try { + const json = { + json: true, + code: 'eosio', + scope: 'eosio', + table: 'voters', + lower_bound: lockAccount.account, + upper_bound: lockAccount.account, + key_type: "name", + index_position: "3", + } + voters = await callFioApi("get_table_rows", json); + voteWeight = Math.trunc(parseInt(voters.rows[0].last_vote_weight)); + //console.log('Voters: ', voters); + + expect(voteWeight).to.equal(unlock6Amount - voteProdFee * (numberOfVotes - 1)); // + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } + }) + }) -/* -describe(`B. Create large grant verify unlocking with skipped periods using voting \n also verify voting power is correct after 3rd unlock period`, () => { - let userA1, prevFundsAmount, lockAccount, keys, newFioAddress - const fundsAmount = 1000000000000 - const lockdurationseconds = 60 +describe(`B. Create large grant verify unlocking with skipped periods using voting also verify voting power is correct after 3rd unlock period`, () => { + let userA1, lockAccount, newFioAddress + const lockdurationseconds = 60, + lockAmount = 7075065123456789, + //lockAmount = 100000000000, // 100 FIO + testTransferAmount = 700000000000 // 50 FIO - it(`Create users`, async () => { - try { - userA1 = await newUser(faucet); + it(`Create lockAccount user`, async () => { + userA1 = await newUser(faucet); - keys = await createKeypair(); - console.log("priv key ", keys.privateKey); - console.log("pub key ", keys.publicKey); - lockAccount.account = await getAccountFromKey(keys.publicKey); - console.log(" account ",lockAccount.account); - let lockAccount.account1 = await getAccountFromKey(faucet.publicKey); - //console.log("faucet account ", lockAccount.account1 ); + lockAccount = await createKeypair(); + lockAccount.account = await getAccountFromKey(lockAccount.publicKey); + console.log("lockAccount priv key: ", lockAccount.privateKey); + console.log("lockAccount pub key: ", lockAccount.publicKey); + console.log("lockAccount account: ", lockAccount.account); + lockAccount.sdk = new FIOSDK(lockAccount.privateKey, lockAccount.publicKey, config.BASE_URL, fetchJson); + }) + + it(`Transfer ${lockAmount} SUFs to lockAccount `, async () => { + try { const result = await faucet.genericAction('transferTokens', { payeeFioPublicKey: lockAccount.publicKey, - amount: 7075065123456789, - maxFee: config.api.transfer_tokens_pub_key.fee, + amount: lockAmount, + maxFee: config.maxFee, technologyProviderId: '' }) - - // console.log(result) - expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error', err.json); + expect(err).to.equal(null); + } + }) - + it(`Add ${lockAmount} Type 1 locked tokens to lockAccount `, async () => { + try { const result1 = await userA1.sdk.genericAction('pushTransaction', { action: 'addlocked', account: 'eosio', data: { - owner : lockAccount.account, - amount: 7075065123456789, + owner: lockAccount.account, + amount: lockAmount, locktype: 1 } }) - //console.log(result1) expect(result1.status).to.equal('OK') - - lockAccount.sdk = new FIOSDK(lockAccount.privateKey, lockAccount.publicKey, config.BASE_URL, fetchJson); } catch (err) { - console.log('Error setting up lock account: ', err) - //expect(err.json.fields[0].error).to.contain(config.error.insufficientBalance) + console.log('Error', err); + expect(err).to.equal(null); } - }) it(`getFioBalance for genesis lock token holder, available balance bug `, async () => { try { const result = await lockAccount.sdk.genericAction('getFioBalance', { }) - prevFundsAmount = result.balance //console.log(result) - expect(result.available).to.equal(7075065123456789) + expect(result.available).to.equal(lockAmount) } catch (err) { // console.log(' Error: ', err) expect(err.json.fields[0].error).to.contain(config.error.insufficientBalance) @@ -726,7 +887,7 @@ describe(`B. Create large grant verify unlocking with skipped periods using voti try { const result = await lockAccount.sdk.genericAction('transferTokens', { payeeFioPublicKey: userA1.publicKey, - amount: 700000000000, + amount: testTransferAmount, maxFee: config.api.transfer_tokens_pub_key.fee, technologyProviderId: '' }) @@ -786,7 +947,7 @@ describe(`B. Create large grant verify unlocking with skipped periods using voti // console.log('Result: ', result); expect(result.rows[0].unlocked_period_count).to.equal(3); - expect(result.rows[0].remaining_locked_amount).to.equal(3990336729639387); + expect(result.rows[0].remaining_locked_amount).to.equal(3990336729639387); // Includes dust } catch (err) { console.log('Error', err); @@ -809,7 +970,7 @@ describe(`B. Create large grant verify unlocking with skipped periods using voti } voters = await callFioApi("get_table_rows", json); - expect(voters.rows[0].last_vote_weight).to.equal('3084728393817402.00000000000000000'); + expect(voters.rows[0].last_vote_weight).to.equal('3084728393817402.00000000000000000'); // } catch (err) { console.log('Error', err); expect(err).to.equal(null); @@ -864,7 +1025,7 @@ describe(`B. Create large grant verify unlocking with skipped periods using voti index_position: '1' } result = await callFioApi("get_table_rows", json); - // console.log('Result: ', result); + //console.log('Result: ', result); expect(result.rows[0].unlocked_period_count).to.equal(6); expect(result.rows[0].remaining_locked_amount).to.equal(19387); @@ -879,56 +1040,75 @@ describe(`B. Create large grant verify unlocking with skipped periods using voti describe(`C. Create large grant verify unlocking using transfer`, () => { - let userA1, prevFundsAmount, lockAccount.sdk, keys, lockAccount.account,newFioDomain, newFioAddress - const fundsAmount = 1000000000000 - const lockdurationseconds = 60 - + let userA1, lockAccount, newFioAddress + const lockdurationseconds = 60, + lockAmount = 7075065123456789, + //lockAmount = 100000000000, // 100 FIO + testTransferAmount = 700000000000, // 50 FIO + unlock1Amount = lockAmount * unlock1Percent, + unlock2Amount = lockAmount * unlock2Percent, + unlock3Amount = lockAmount * unlock3Percent, + unlock4Amount = lockAmount * unlock4Percent, + unlock5Amount = lockAmount * unlock5Percent, + unlock6Amount = lockAmount * unlock6Percent - it(`Create users`, async () => { + it(`Create lockAccount user`, async () => { userA1 = await newUser(faucet); - keys = await createKeypair(); - console.log("priv key ", keys.privateKey); - console.log("pub key ", keys.publicKey); - lockAccount.account = await getAccountFromKey(keys.publicKey); - console.log(" account ",lockAccount.account); - - - const result = await faucet.genericAction('transferTokens', { - payeeFioPublicKey: keys.publicKey, - amount: 7075065123456789, - maxFee: config.api.transfer_tokens_pub_key.fee, - technologyProviderId: '' - }) - expect(result.status).to.equal('OK') + lockAccount = await createKeypair(); + lockAccount.account = await getAccountFromKey(lockAccount.publicKey); + console.log("lockAccount priv key: ", lockAccount.privateKey); + console.log("lockAccount pub key: ", lockAccount.publicKey); + console.log("lockAccount account: ", lockAccount.account); - const result1 = await userA1.sdk.genericAction('pushTransaction', { - action: 'addlocked', - account: 'eosio', - data: { - owner : lockAccount.account, - amount: 7075065123456789, - locktype: 1 - } - }) - expect(result1.status).to.equal('OK') + lockAccount.sdk = new FIOSDK(lockAccount.privateKey, lockAccount.publicKey, config.BASE_URL, fetchJson); + }) - lockAccount.sdk = new FIOSDK(keys.privateKey, keys.publicKey, config.BASE_URL, fetchJson); + it(`Transfer ${lockAmount} SUFs to lockAccount `, async () => { + try { + const result = await faucet.genericAction('transferTokens', { + payeeFioPublicKey: lockAccount.publicKey, + amount: lockAmount, + maxFee: config.maxFee, + technologyProviderId: '' + }) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error', err.json); + expect(err).to.equal(null); + } + }) + it(`Add ${lockAmount} Type 1 locked tokens to lockAccount `, async () => { + try { + const result1 = await userA1.sdk.genericAction('pushTransaction', { + action: 'addlocked', + account: 'eosio', + data: { + owner: lockAccount.account, + amount: lockAmount, + locktype: 1 + } + }) + expect(result1.status).to.equal('OK') + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } }) it(`getFioBalance for genesis lock token holder, available balance bug `, async () => { const result = await lockAccount.sdk.genericAction('getFioBalance', { }) prevFundsAmount = result.balance - expect(result.available).to.equal(7075065123456789) + expect(result.available).to.equal(lockAmount) }) it(`Failure test Transfer 700 FIO to userA1 FIO public key, insufficient balance tokens locked`, async () => { try { const result = await lockAccount.sdk.genericAction('transferTokens', { payeeFioPublicKey: userA1.publicKey, - amount: 700000000000, + amount: testTransferAmount, maxFee: config.api.transfer_tokens_pub_key.fee, technologyProviderId: '' }) @@ -1263,56 +1443,69 @@ describe(`C. Create large grant verify unlocking using transfer`, () => { describe(`D. Create large grant verify unlocking with skipped periods using transfer`, () => { - let userA1, prevFundsAmount, lockAccount.sdk, keys, lockAccount.account,newFioDomain, newFioAddress - const fundsAmount = 1000000000000 - const lockdurationseconds = 60 - + let userA1, lockAccount, newFioAddress + const lockdurationseconds = 60, + lockAmount = 7075065123456789, + //lockAmount = 100000000000, // 100 FIO + testTransferAmount = 700000000000 // 50 FIO - it(`Create users`, async () => { + it(`Create lockAccount user`, async () => { userA1 = await newUser(faucet); - keys = await createKeypair(); - console.log("priv key ", keys.privateKey); - console.log("pub key ", keys.publicKey); - lockAccount.account = await getAccountFromKey(keys.publicKey); - console.log(" account ",lockAccount.account); - - - const result = await faucet.genericAction('transferTokens', { - payeeFioPublicKey: keys.publicKey, - amount: 7075065123456789, - maxFee: config.api.transfer_tokens_pub_key.fee, - technologyProviderId: '' - }) - expect(result.status).to.equal('OK') + lockAccount = await createKeypair(); + lockAccount.account = await getAccountFromKey(lockAccount.publicKey); + console.log("lockAccount priv key: ", lockAccount.privateKey); + console.log("lockAccount pub key: ", lockAccount.publicKey); + console.log("lockAccount account: ", lockAccount.account); - const result1 = await userA1.sdk.genericAction('pushTransaction', { - action: 'addlocked', - account: 'eosio', - data: { - owner : lockAccount.account, - amount: 7075065123456789, - locktype: 1 - } - }) - expect(result1.status).to.equal('OK') + lockAccount.sdk = new FIOSDK(lockAccount.privateKey, lockAccount.publicKey, config.BASE_URL, fetchJson); + }) - lockAccount.sdk = new FIOSDK(keys.privateKey, keys.publicKey, config.BASE_URL, fetchJson); + it(`Transfer ${lockAmount} SUFs to lockAccount `, async () => { + try { + const result = await faucet.genericAction('transferTokens', { + payeeFioPublicKey: lockAccount.publicKey, + amount: lockAmount, + maxFee: config.maxFee, + technologyProviderId: '' + }) + expect(result.status).to.equal('OK') + } catch (err) { + console.log('Error', err.json); + expect(err).to.equal(null); + } + }) + it(`Add ${lockAmount} Type 1 locked tokens to lockAccount `, async () => { + try { + const result1 = await userA1.sdk.genericAction('pushTransaction', { + action: 'addlocked', + account: 'eosio', + data: { + owner: lockAccount.account, + amount: lockAmount, + locktype: 1 + } + }) + expect(result1.status).to.equal('OK') + } catch (err) { + console.log('Error', err); + expect(err).to.equal(null); + } }) it(`getFioBalance for genesis lock token holder, available balance 0 `, async () => { const result = await lockAccount.sdk.genericAction('getFioBalance', { }) prevFundsAmount = result.balance - expect(result.available).to.equal(7075065123456789) + expect(result.available).to.equal(lockAmount) }) it(`Failure test Transfer 700 FIO to userA1 FIO public key, insufficient balance tokens locked`, async () => { try { const result = await lockAccount.sdk.genericAction('transferTokens', { payeeFioPublicKey: userA1.publicKey, - amount: 700000000000, + amount: testTransferAmount, maxFee: config.api.transfer_tokens_pub_key.fee, technologyProviderId: '' }) @@ -1431,4 +1624,3 @@ describe(`D. Create large grant verify unlocking with skipped periods using tran }) }) -*/ \ No newline at end of file