UNPKG

@mcchadwick/fiosdk

Version:

The Foundation for Interwallet Operability (FIO) is a consortium of leading blockchain wallets, exchanges and payments providers that seeks to accelerate blockchain adoption by reducing the risk, complexity, and inconvenience of sending and receiving cryp

102 lines (78 loc) 2.52 kB
require('mocha') const { expect } = require('chai') const { FIOSDK } = require('../lib/FIOSDK') fetch = require('node-fetch') const fetchJson = async (uri, opts = {}) => { return fetch(uri, opts) } // Transfers FIO tokens from privatekey to publicKey2 // Can be used to fund accounts for testing purposes /** * Please set your private/public keys and existing fioAddresses */ let privateKey = '5Je48oZC1padEGbWWqmjdSuoHG1evP8bVQ3iHUegBW19UhaB48Y', publicKey = 'FIO7MpYCsLfjPGgXg8Sv7usGAw6RnFV3W6HTz1UP6HvodNXSAZiDp', privateKey2 = '5Jahp6vCHB7e8fpykR7KqjYmATTJyFeau49E8RaDcHFkY66ZXuN', publicKey2 = 'FIO8T361AdCuVrzuLWe9nJcx1UXVD22E8XM4PLtBUYbSNR69B6ajA' const baseUrl = 'https://testnet.fioprotocol.io:443/v1/' const fioTestnetDomain = 'fiotestnet' const fioTokenCode = 'FIO' const fioChainCode = 'FIO' const defaultFee = 800 * FIOSDK.SUFUnit const transferAmount = 900 * FIOSDK.SUFUnit let fioSdk, fioSdk2 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 () => { fioSdk = new FIOSDK( privateKey, publicKey, baseUrl, fetchJson ) await timeout(1000) fioSdk2 = new FIOSDK( privateKey2, publicKey2, baseUrl, fetchJson ) }) describe('Transfer tokens', () => { const fundsAmount = transferAmount let fioBalance = 0 let fioBalanceAfter = 0 it(`Check balance before transfer`, async () => { const result = await fioSdk2.genericAction('getFioBalance', {}) fioBalance = result.balance }) it(`Transfer tokens`, async () => { const result = await fioSdk.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.genericAction('getFioBalance', {}) console.log ("FIO Token balance: " + result.balance/FIOSDK.SUFUnit) }) })