You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

primitives.ts 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. var wtf = require('wtfnode');
  2. import { htmlTxt, longText, makeTestnetWallet, TEST_CONFIG, TEST_DATA } from './CONSTANTS'
  3. import { xrpIO } from '../src/xrpIO/xrpl-binding'
  4. import * as chai from 'chai';
  5. import { Wallet } from '../src/util/types';
  6. const expect = chai.expect
  7. let sendWallet: Wallet
  8. let receiveWallet: Wallet
  9. let api: xrpIO
  10. describe('XRPIO', () => {
  11. before(async function(){
  12. this.timeout(15000)
  13. sendWallet = await makeTestnetWallet()
  14. receiveWallet = await makeTestnetWallet()
  15. await new Promise((res, rej) => setTimeout(res, 10000)) //it takes a moment for the wallets to become active
  16. })
  17. beforeEach(async () => {
  18. try {
  19. api = new xrpIO(TEST_CONFIG.rippleNode, {debug: false, connectionTimeout: 100000})
  20. return await api.connect()
  21. } catch (e) {
  22. console.log(e)
  23. throw e
  24. }
  25. })
  26. afterEach(async function () {
  27. try {
  28. return await api.disconnect()
  29. } catch (e) {
  30. console.log(e)
  31. }
  32. })
  33. it('getAccountSequence', async function(){
  34. //this.skip()
  35. this.timeout(10000)
  36. const seq = await api.getAccountSequence(sendWallet.address)
  37. expect(seq).to.exist
  38. expect(seq).to.be.a('number')
  39. })
  40. it('estimateFee', async function () {
  41. this.timeout(2000)
  42. const cost = await api.estimateFee(longText)
  43. expect(cost).to.be.a('number')
  44. expect(cost).to.be.lessThan(50)
  45. expect(cost).to.be.greaterThan(30)
  46. })
  47. let txHash
  48. it('writeRaw', async function(){
  49. //this.skip()
  50. this.timeout(15000)
  51. txHash = await api.writeRaw({data: TEST_DATA}, receiveWallet.address, sendWallet.secret);
  52. expect(txHash).to.exist
  53. expect(txHash).to.be.a('string')
  54. })
  55. it('readRaw', async function () {
  56. //this.skip()
  57. this.timeout(15000)
  58. const memo = await api.readRaw(txHash)
  59. expect(memo).to.exist
  60. expect(memo.data).to.be.equal(TEST_DATA)
  61. })
  62. it('readRaw bad hash', function (done){
  63. this.timeout(150000)
  64. api.readRaw("123")
  65. .then(_ => done(new Error('Expected error but succeeded')))
  66. .catch(_ => done())
  67. })
  68. it('treeWrite', async function(){
  69. // this.skip()
  70. this.timeout(45000)
  71. txHash = await api.treeWrite(longText, receiveWallet.address, sendWallet.secret)
  72. expect(txHash).to.exist
  73. expect(txHash).to.be.a('string')
  74. })
  75. it('treeRead', async function(){
  76. // this.skip()
  77. this.timeout(45000)
  78. txHash = await api.treeRead([txHash])
  79. expect(txHash).to.exist
  80. expect(txHash).to.be.equal(longText)
  81. })
  82. it('treeWrite XL', async function(){
  83. //this.skip()
  84. this.timeout(450000)
  85. txHash = await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
  86. expect(txHash).to.exist
  87. expect(txHash).to.be.a('string')
  88. })
  89. it('treeRead XL', async function(){
  90. //this.skip()
  91. this.timeout(450000)
  92. const data = await api.treeRead([txHash])
  93. expect(data).to.exist
  94. expect(data).to.be.equal(htmlTxt)
  95. })
  96. it('print open handles', function(){
  97. api.disconnect().then(_ => {
  98. wtf.dump()
  99. })
  100. })
  101. })