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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 poorWallet: Wallet
  10. let api: xrpIO
  11. describe('XRPIO', () => {
  12. before(async function(){
  13. this.timeout(15000)
  14. sendWallet = await makeTestnetWallet()
  15. receiveWallet = await makeTestnetWallet()
  16. poorWallet = await makeTestnetWallet()
  17. await new Promise((res, rej) => setTimeout(res, 10000)) //it takes a moment for the wallets to become active
  18. })
  19. beforeEach(async () => {
  20. try {
  21. api = new xrpIO(TEST_CONFIG.rippleNode, {debug: false, connectionTimeout: 100000})
  22. return await api.connect()
  23. } catch (e) {
  24. console.log(e)
  25. throw e
  26. }
  27. })
  28. afterEach(async function () {
  29. try {
  30. return await api.disconnect()
  31. } catch (e) {
  32. console.log(e)
  33. }
  34. })
  35. it('throws error if not enough funds', function(done){
  36. this.timeout(15000)
  37. console.log(poorWallet)
  38. api.sendPayment({}, receiveWallet.address, poorWallet.secret, undefined, String(1000000 * 10001))
  39. .then(_ => done(new Error('Expected error but succeeded')))
  40. .catch(_ => done())
  41. })
  42. it('getTransaction with bad hash', function(done){
  43. this.timeout(10000)
  44. api.getTransaction('73FECDA37ABBB2FC17460C5C2467BE6A0A8E1F4EB081FFFFFFFFFFFFFFFFFFFF') //technically this hash could exist, but probably never will
  45. .then(_ => done(new Error('Expected error but succeeded')))
  46. .catch(_ => done())
  47. })
  48. it('sendPayment errors on bad request sequence', function(done){
  49. api.sendPayment({}, receiveWallet.address, sendWallet.secret, -12)
  50. .then(_ => done(new Error('Expected error but succeeded')))
  51. .catch(_ => done())
  52. })
  53. it('getAccountSequence', async function(){
  54. this.timeout(10000)
  55. const seq = await api.getAccountSequence(sendWallet.address)
  56. expect(seq).to.exist
  57. expect(seq).to.be.a('number')
  58. })
  59. it('estimateFee', async function () {
  60. this.timeout(10000)
  61. const cost = await api.estimateFee(longText)
  62. expect(cost).to.be.a('number')
  63. expect(cost).to.be.lessThan(50)
  64. expect(cost).to.be.greaterThan(30)
  65. })
  66. let txHash
  67. it('writeRaw', async function(){
  68. this.timeout(15000)
  69. txHash = await api.writeRaw({data: TEST_DATA}, receiveWallet.address, sendWallet.secret);
  70. expect(txHash).to.exist
  71. expect(txHash).to.be.a('string')
  72. })
  73. it('readRaw', async function () {
  74. this.timeout(15000)
  75. const memo = await api.readRaw(txHash)
  76. expect(memo).to.exist
  77. expect(memo.data).to.be.equal(TEST_DATA)
  78. })
  79. it('verifyOwner readRaw', async function (){
  80. this.timeout(15000)
  81. const memo = await api.readRaw(txHash, sendWallet.address)
  82. expect(memo).to.exist
  83. expect(memo.data).to.be.equal(TEST_DATA)
  84. })
  85. it('verifyOwner readRaw bad owner', function (done){
  86. this.timeout(15000)
  87. api.readRaw(txHash, "not the owner")
  88. .then(_ => done(new Error('Expected error but succeeded')))
  89. .catch(_ => done())
  90. })
  91. it('readRaw bad hash', function (done){
  92. this.timeout(150000)
  93. api.readRaw("123")
  94. .then(_ => done(new Error('Expected error but succeeded')))
  95. .catch(_ => done())
  96. })
  97. it('treeWrite', async function(){
  98. this.timeout(45000)
  99. txHash = await api.treeWrite(longText, receiveWallet.address, sendWallet.secret)
  100. expect(txHash).to.exist
  101. expect(txHash).to.be.a('string')
  102. })
  103. it('treeRead', async function(){
  104. this.timeout(45000)
  105. const data = await api.treeRead([txHash])
  106. expect(data).to.exist
  107. expect(data).to.be.equal(longText)
  108. })
  109. it('treeRead verify owner', async function(){
  110. this.timeout(45000)
  111. const data = await api.treeRead([txHash], sendWallet.address)
  112. expect(data).to.exist
  113. expect(data).to.be.equal(longText)
  114. })
  115. it('verifyOwner treeRead bad owner', function(done){
  116. this.timeout(45000)
  117. api.treeRead([txHash], "not the owner")
  118. .then(_ => done(new Error('Expected error but succeeded')))
  119. .catch(_ => done())
  120. })
  121. it('treeWrite XL', async function(){
  122. this.timeout(450000)
  123. txHash = await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
  124. expect(txHash).to.exist
  125. expect(txHash).to.be.a('string')
  126. })
  127. it('treeRead XL', async function(){
  128. this.timeout(450000)
  129. const data = await api.treeRead([txHash])
  130. expect(data).to.exist
  131. expect(data).to.be.equal(htmlTxt)
  132. })
  133. it('sends even if rate limit exceeded', async function(){
  134. this.timeout(10 * 60 * 1000) //10m
  135. console.log("Testing if sending past rate limits correctly recovers and finishes. This may take a while.")
  136. await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
  137. console.log("1/7")
  138. await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
  139. console.log("2/7")
  140. await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
  141. console.log("3/7")
  142. await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
  143. console.log("4/7")
  144. await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
  145. console.log("5/7")
  146. await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
  147. console.log("6/7")
  148. await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
  149. })
  150. it('print open handles', function(){
  151. api.disconnect().then(_ => {
  152. wtf.dump()
  153. })
  154. })
  155. })