123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- var wtf = require('wtfnode');
- import { htmlTxt, longText, makeTestnetWallet, TEST_CONFIG, TEST_DATA } from './CONSTANTS'
- import { xrpIO } from '../src/xrpIO/xrpl-binding'
- import * as chai from 'chai';
- import { Wallet } from '../src/util/types';
- const expect = chai.expect
-
- let sendWallet: Wallet
- let receiveWallet: Wallet
- let poorWallet: Wallet
- let api: xrpIO
-
- describe('XRPIO', () => {
- before(async function(){
- this.timeout(15000)
- sendWallet = await makeTestnetWallet()
- receiveWallet = await makeTestnetWallet()
- poorWallet = await makeTestnetWallet()
- await new Promise((res, rej) => setTimeout(res, 10000)) //it takes a moment for the wallets to become active
- })
-
- beforeEach(async () => {
- try {
- api = new xrpIO(TEST_CONFIG.rippleNode, {debug: false, connectionTimeout: 100000})
- return await api.connect()
- } catch (e) {
- console.log(e)
- throw e
- }
- })
-
- afterEach(async function () {
- try {
- return await api.disconnect()
- } catch (e) {
- console.log(e)
- }
- })
-
-
- it('treeRead spc', async function(){
- this.timeout(450000)
- const data = await api.treeRead(["1481F8DD37C2D3AE3CE60B25264B902BD9E0377AAA1AEDB924D05049F36DFB15"], undefined)
- expect(data).to.exist
- })
-
-
- it('throws error if not enough funds', function(done){
- this.timeout(15000)
- console.log(poorWallet)
- api.sendPayment({}, receiveWallet.address, poorWallet.secret, undefined, String(1000000 * 10001))
- .then(_ => done(new Error('Expected error but succeeded')))
- .catch(_ => done())
- })
-
- it('getTransaction with bad hash', function(done){
- this.timeout(10000)
- api.getTransaction('73FECDA37ABBB2FC17460C5C2467BE6A0A8E1F4EB081FFFFFFFFFFFFFFFFFFFF') //technically this hash could exist, but probably never will
- .then(_ => done(new Error('Expected error but succeeded')))
- .catch(_ => done())
- })
-
- it('sendPayment errors on bad request sequence', function(done){
- api.sendPayment({}, receiveWallet.address, sendWallet.secret, -12)
- .then(_ => done(new Error('Expected error but succeeded')))
- .catch(_ => done())
- })
-
- it('getAccountSequence', async function(){
- this.timeout(10000)
- const seq = await api.getAccountSequence(sendWallet.address)
- expect(seq).to.exist
- expect(seq).to.be.a('number')
- })
-
- it('estimateFee', async function () {
- this.timeout(10000)
- const cost = await api.estimateFee(longText)
- expect(cost).to.be.a('number')
- expect(cost).to.be.lessThan(50)
- expect(cost).to.be.greaterThan(30)
- })
-
-
-
- let txHash
- it('writeRaw', async function(){
- this.timeout(15000)
- txHash = await api.writeRaw({data: TEST_DATA}, receiveWallet.address, sendWallet.secret);
- expect(txHash).to.exist
- expect(txHash).to.be.a('string')
- })
-
- it('readRaw', async function () {
- this.timeout(15000)
- const memo = await api.readRaw(txHash)
- expect(memo).to.exist
- expect(memo.data).to.be.equal(TEST_DATA)
- })
-
- it('verifyOwner readRaw', async function (){
- this.timeout(15000)
- const memo = await api.readRaw(txHash, sendWallet.address)
- expect(memo).to.exist
- expect(memo.data).to.be.equal(TEST_DATA)
- })
-
- it('verifyOwner readRaw bad owner', function (done){
- this.timeout(15000)
- api.readRaw(txHash, "not the owner")
- .then(_ => done(new Error('Expected error but succeeded')))
- .catch(_ => done())
- })
-
- it('readRaw bad hash', function (done){
- this.timeout(150000)
- api.readRaw("123")
- .then(_ => done(new Error('Expected error but succeeded')))
- .catch(_ => done())
- })
-
- it('treeWrite', async function(){
- this.timeout(45000)
- txHash = await api.treeWrite(longText, receiveWallet.address, sendWallet.secret)
- expect(txHash).to.exist
- expect(txHash).to.be.a('string')
- })
-
- it('treeRead', async function(){
- this.timeout(45000)
- const data = await api.treeRead([txHash], undefined)
- expect(data).to.exist
- expect(data).to.be.equal(longText)
- })
-
- it('treeRead verify owner', async function(){
- this.timeout(45000)
- const data = await api.treeRead([txHash], sendWallet.address)
- expect(data).to.exist
- expect(data).to.be.equal(longText)
- })
-
- it('verifyOwner treeRead bad owner', function(done){
- this.timeout(45000)
- api.treeRead([txHash], "not the owner")
- .then(_ => done(new Error('Expected error but succeeded')))
- .catch(_ => done())
- })
-
- it('treeWrite XL', async function(){
- this.timeout(450000)
- txHash = await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
- expect(txHash).to.exist
- expect(txHash).to.be.a('string')
- })
-
- it('treeRead XL', async function(){
- this.timeout(450000)
- const data = await api.treeRead([txHash])
- expect(data).to.exist
- expect(data).to.be.equal(htmlTxt)
- })
-
- it('sends even if rate limit exceeded', async function(){
- this.timeout(100 * 60 * 1000) //100m
- console.log("Testing if sending past rate limits correctly recovers and finishes. This may take a while.")
- await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
- console.log("1/7")
- await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
- console.log("2/7")
- await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
- console.log("3/7")
- await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
- console.log("4/7")
- await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
- console.log("5/7")
- await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
- console.log("6/7")
- await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
- })
-
- it('print open handles', function(){
- api.disconnect().then(_ => {
- wtf.dump()
- })
- })
- })
|