Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

primitives.ts 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { RippleAPI } from 'ripple-lib'
  2. import { htmlTxt, longText, makeTestnetWallet, TEST_CONFIG, TEST_DATA } from './CONSTANTS'
  3. import { getLatestSequence, sendPayment, treeRead, treeWrite } from '../src/xrpIO/ripple-binding'
  4. import * as chai from 'chai';
  5. import { Wallet } from '../src/util/types';
  6. const utf8 = require('utf8')
  7. const base64 = require('base-64')
  8. const expect = chai.expect
  9. let sendWallet: Wallet
  10. let receiveWallet: Wallet
  11. let api: RippleAPI
  12. describe('XRPIO', () => {
  13. before(async function () {
  14. this.timeout(15000)
  15. sendWallet = await makeTestnetWallet()
  16. receiveWallet = 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 RippleAPI({ server: TEST_CONFIG.rippleNode })
  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. let latestSeq
  36. describe('plumbing', () => {
  37. it('getLatestSequence', async () => {
  38. latestSeq = await getLatestSequence(api, sendWallet.address)
  39. expect(latestSeq).to.exist
  40. expect(latestSeq).to.be.a('number')
  41. expect(latestSeq).to.be.greaterThan(0)
  42. })
  43. })
  44. describe('payment', () => {
  45. it('sendPayment', async function () {
  46. this.timeout(10000)
  47. const result = await sendPayment(api, [{ data: "123" }], sendWallet.address, receiveWallet.address, sendWallet.secret, latestSeq + 1)
  48. expect(result).to.exist
  49. expect(result.resultCode).to.be.equal('tesSUCCESS')
  50. })
  51. })
  52. describe('I/O', () => {
  53. let treeRoot
  54. it(`can tree write (${TEST_DATA.length} bytes)`, async function () {
  55. this.timeout(10000)
  56. treeRoot = await treeWrite(api, TEST_DATA, sendWallet, receiveWallet.address)
  57. })
  58. it('can tree read', async function () {
  59. this.timeout(15000)
  60. const data = await treeRead(api, [treeRoot])
  61. expect(data).to.be.equal(TEST_DATA)
  62. })
  63. it(`can tree write large (${longText.length} bytes)`, async function () {
  64. this.timeout(30000)
  65. treeRoot = await treeWrite(api, longText, sendWallet, receiveWallet.address)
  66. })
  67. it('can tree read large', async function () {
  68. this.timeout(30000)
  69. const data = await treeRead(api, [treeRoot])
  70. expect(data).to.be.equal(longText)
  71. })
  72. it(`can tree write extra large (${htmlTxt.length} bytes)`, async function () {
  73. this.timeout(300000)
  74. treeRoot = await treeWrite(api, htmlTxt, sendWallet, receiveWallet.address)
  75. })
  76. it('can tree read extra large', async function () {
  77. this.timeout(300000)
  78. const data = await treeRead(api, [treeRoot])
  79. expect(data).to.be.equal(htmlTxt)
  80. })
  81. it("can r/w binary", async function () {
  82. this.timeout(10000);
  83. const bytes = utf8.encode(TEST_DATA)
  84. const encoded = base64.encode(bytes)
  85. const txHash = await treeWrite(api, encoded, sendWallet, receiveWallet.address)
  86. const res = await treeRead(api, [txHash])
  87. const decoded_bytes = base64.decode(res)
  88. const text = utf8.decode(decoded_bytes)
  89. expect(text).to.be.equal(TEST_DATA)
  90. })
  91. })
  92. })