Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

primitives.ts 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { RippleAPI } from 'ripple-lib'
  2. import { 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))
  18. })
  19. before(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. after(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(1500)
  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(3000)
  69. const data = await treeRead(api, [treeRoot])
  70. expect(data).to.be.equal(longText)
  71. })
  72. it("can r/w binary", async function () {
  73. this.timeout(10000);
  74. const bytes = utf8.encode(TEST_DATA)
  75. const encoded = base64.encode(bytes)
  76. const txHash = await treeWrite(api, encoded, sendWallet, receiveWallet.address)
  77. const res = await treeRead(api, [txHash])
  78. const decoded_bytes = base64.decode(res)
  79. const text = utf8.decode(decoded_bytes)
  80. expect(text).to.be.equal(TEST_DATA)
  81. })
  82. })
  83. })