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 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.timeout(10000)
  35. const seq = await api.getAccountSequence(sendWallet.address)
  36. expect(seq).to.exist
  37. expect(seq).to.be.a('number')
  38. })
  39. it('estimateFee', async function () {
  40. this.timeout(10000)
  41. const cost = await api.estimateFee(longText)
  42. expect(cost).to.be.a('number')
  43. expect(cost).to.be.lessThan(50)
  44. expect(cost).to.be.greaterThan(30)
  45. })
  46. let txHash
  47. it('writeRaw', async function(){
  48. this.timeout(15000)
  49. txHash = await api.writeRaw({data: TEST_DATA}, receiveWallet.address, sendWallet.secret);
  50. expect(txHash).to.exist
  51. expect(txHash).to.be.a('string')
  52. })
  53. it('readRaw', async function () {
  54. this.timeout(15000)
  55. const memo = await api.readRaw(txHash)
  56. expect(memo).to.exist
  57. expect(memo.data).to.be.equal(TEST_DATA)
  58. })
  59. it('verifyOwner readRaw', async function (){
  60. this.timeout(15000)
  61. const memo = await api.readRaw(txHash, sendWallet.address)
  62. expect(memo).to.exist
  63. expect(memo.data).to.be.equal(TEST_DATA)
  64. })
  65. it('verifyOwner readRaw bad owner', function (done){
  66. this.timeout(15000)
  67. api.readRaw(txHash, "not the owner")
  68. .then(_ => done(new Error('Expected error but succeeded')))
  69. .catch(_ => done())
  70. })
  71. it('readRaw bad hash', function (done){
  72. this.timeout(150000)
  73. api.readRaw("123")
  74. .then(_ => done(new Error('Expected error but succeeded')))
  75. .catch(_ => done())
  76. })
  77. it('treeWrite', async function(){
  78. this.timeout(45000)
  79. txHash = await api.treeWrite(longText, receiveWallet.address, sendWallet.secret)
  80. expect(txHash).to.exist
  81. expect(txHash).to.be.a('string')
  82. })
  83. it('treeRead', async function(){
  84. this.timeout(45000)
  85. const data = await api.treeRead([txHash])
  86. expect(data).to.exist
  87. expect(data).to.be.equal(longText)
  88. })
  89. it('treeRead verify owner', async function(){
  90. this.timeout(45000)
  91. const data = await api.treeRead([txHash], sendWallet.address)
  92. expect(data).to.exist
  93. expect(data).to.be.equal(longText)
  94. })
  95. it('verifyOwner treeRead bad owner', function(done){
  96. this.timeout(45000)
  97. api.treeRead([txHash], "not the owner")
  98. .then(_ => done(new Error('Expected error but succeeded')))
  99. .catch(_ => done())
  100. })
  101. it('treeWrite XL', async function(){
  102. this.timeout(450000)
  103. txHash = await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
  104. expect(txHash).to.exist
  105. expect(txHash).to.be.a('string')
  106. })
  107. it('treeRead XL', async function(){
  108. this.timeout(450000)
  109. const data = await api.treeRead([txHash])
  110. expect(data).to.exist
  111. expect(data).to.be.equal(htmlTxt)
  112. })
  113. it('print open handles', function(){
  114. api.disconnect().then(_ => {
  115. wtf.dump()
  116. })
  117. })
  118. })