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.6KB

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