mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-03 10:35:49 +00:00
Rename RippleAPI client to Client (#1520)
* rename RippleAPI -> XrplClient * more renames * move API stuff to client folder * rename all api -> client * fix tests * make tests run * fix integ tests * fix urls * fix merge issues * XrplClient -> Client * fix merge issues * rename xrpl-client npm symlink to xrpl-local
This commit is contained in:
65
test/setup-client-web.ts
Normal file
65
test/setup-client-web.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import {Client, ClientBroadcast} from 'xrpl-local'
|
||||
import ledgerClosed from './fixtures/rippled/ledger-close.json'
|
||||
|
||||
const port = 34371
|
||||
const baseUrl = 'ws://testripple.circleci.com:'
|
||||
|
||||
function setup(this: any, port_ = port) {
|
||||
const tclient = new Client({server: baseUrl + port_})
|
||||
return tclient
|
||||
.connect()
|
||||
.then(() => {
|
||||
return tclient.connection.request({
|
||||
command: 'test_command',
|
||||
data: {openOnOtherPort: true}
|
||||
})
|
||||
})
|
||||
.then((got) => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
this.client = new Client({server: baseUrl + got.port})
|
||||
this.client
|
||||
.connect()
|
||||
.then(() => {
|
||||
this.client.once('ledger', () => resolve())
|
||||
this.client.connection._ws.emit(
|
||||
'message',
|
||||
JSON.stringify(ledgerClosed)
|
||||
)
|
||||
})
|
||||
.catch(reject)
|
||||
})
|
||||
})
|
||||
.then(() => {
|
||||
return tclient.disconnect()
|
||||
})
|
||||
}
|
||||
|
||||
function setupBroadcast(this: any) {
|
||||
const servers = [port, port + 1].map((port_) => baseUrl + port_)
|
||||
this.client = new ClientBroadcast(servers)
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
this.client
|
||||
.connect()
|
||||
.then(() => {
|
||||
this.client.once('ledger', () => resolve())
|
||||
this.client._clients[0].connection._ws.emit(
|
||||
'message',
|
||||
JSON.stringify(ledgerClosed)
|
||||
)
|
||||
})
|
||||
.catch(reject)
|
||||
})
|
||||
}
|
||||
|
||||
function teardown(this: any) {
|
||||
if (this.client.isConnected()) {
|
||||
return this.client.disconnect()
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
export default {
|
||||
setup: setup,
|
||||
teardown: teardown,
|
||||
setupBroadcast: setupBroadcast
|
||||
}
|
||||
Reference in New Issue
Block a user