您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

primitives.ts 5.2KB

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