1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import { RippleAPI } from 'ripple-lib'
- import { longText, makeTestnetWallet, TEST_CONFIG, TEST_DATA } from './CONSTANTS'
- import { getLatestSequence, sendPayment, treeRead, treeWrite } from '../src/xrpIO/ripple-binding'
- import * as chai from 'chai';
- import { Wallet } from '../src/util/types';
- const utf8 = require('utf8')
- const base64 = require('base-64')
- const expect = chai.expect
-
- let sendWallet:Wallet
- let receiveWallet:Wallet
- let api: RippleAPI
-
- describe('XRPIO', () => {
- before(async function () {
- this.timeout(15000)
- sendWallet = await makeTestnetWallet()
- receiveWallet = await makeTestnetWallet()
- await new Promise((res, rej) => setTimeout(res, 10000))
- })
-
- before(async () => {
- try{
- api = new RippleAPI({ server: TEST_CONFIG.rippleNode })
- return await api.connect()
- }catch(e){
- console.log(e)
- throw e
- }
- })
-
- after(async function () {
- try{
- return await api.disconnect()
- }catch(e){
- console.log(e)
- }
- })
-
- let latestSeq
- describe('plumbing', () => {
- it('getLatestSequence', async () => {
- latestSeq = await getLatestSequence(api, sendWallet.address)
- expect(latestSeq).to.exist
- expect(latestSeq).to.be.a('number')
- expect(latestSeq).to.be.greaterThan(0)
- })
- })
-
- describe('payment', () => {
- it('sendPayment', async function (){
- this.timeout(10000)
- const result = await sendPayment(api, [{data: "123"}], sendWallet.address, receiveWallet.address, sendWallet.secret, latestSeq+1)
- expect(result).to.exist
- expect(result.resultCode).to.be.equal('tesSUCCESS')
- })
- })
-
- describe('I/O', () => {
- let treeRoot
- it(`can tree write (${TEST_DATA.length} bytes)`, async function (){
- this.timeout(10000)
- treeRoot = await treeWrite(api, TEST_DATA, sendWallet, receiveWallet.address)
- })
-
- it('can tree read', async function() {
- this.timeout(1500)
- const data = await treeRead(api, [treeRoot])
- expect(data).to.be.equal(TEST_DATA)
- })
-
- it(`can tree write large (${longText.length} bytes)`, async function (){
- this.timeout(30000)
- treeRoot = await treeWrite(api, longText, sendWallet, receiveWallet.address)
- })
-
- it('can tree read large', async function() {
- this.timeout(3000)
- const data = await treeRead(api, [treeRoot])
- expect(data).to.be.equal(longText)
- })
-
- it("can r/w binary", async function () {
- this.timeout(10000);
-
- const bytes = utf8.encode(TEST_DATA)
- const encoded = base64.encode(bytes)
- const txHash = await treeWrite(api, encoded, sendWallet, receiveWallet.address)
- const res = await treeRead(api, [txHash])
- const decoded_bytes = base64.decode(res)
- const text = utf8.decode(decoded_bytes)
- expect(text).to.be.equal(TEST_DATA)
- })
- })
- })
|